3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/DataSvc.h"
9#include "CLHEP/Units/PhysicalConstants.h"
11#include "G4DigiManager.hh"
12#include "Randomize.hh"
15#include "CLHEP/Units/PhysicalConstants.h"
28 m_GainMultiplier[0]=1.60;
29 m_GainMultiplier[1]=1.60;
30 m_GainMultiplier[2]=1.60;
38 m_magConfig = magConfig;
44 for(
int l=0; l<3;l++){
45 for(
int i=0; i<3; i++){
46 sprintf(funname,
"funPolya%d%d", l, i);
47 m_funPolya[l][i] =
new TF1(funname,
"[0]*pow(1+[2],1+[2])*pow(x/[1],[2])*exp(-(1+[2])*x/[1])/TMath::Gamma(1+[2])", 1, 500);
48 m_funPolya[l][i]->SetParameter(0, m_gain_gem[i][0]);
49 m_funPolya[l][i]->SetParameter(1, m_gain_gem[i][1]*m_GainMultiplier[l]);
50 m_funPolya[l][i]->SetParameter(2, m_gain_gem[i][2]);
55void SamplingGar::setIonElectrons(
int layer,
int nElectrons, std::vector<double> x, std::vector<double> y, std::vector<double> z, std::vector<double>
t){
59 for(
int i=0; i<nElectrons; i++){
60 double r = sqrt(
x[i]*
x[i] + y[i]*y[i]);
62 if(y[i] >= 0) phi = acos(
x[i] / r);
63 else phi = CLHEP::twopi - acos(
x[i] / r);
64 m_vecIonR.push_back(r);
65 m_vecIonPhi.push_back(phi);
66 m_vecIonZ.push_back(z[i]);
67 m_vecIonT.push_back(
t[i]);
74 double driftD = radii_gem1 - r;
76 samplingDrift(layer,driftD, i);
79 for(
int i=0; i<m_nEgem1; i++) samplingTransfer(layer,1, i);
81 for(
int i=0; i<m_nEgem2; i++) samplingTransfer(layer,2, i);
86void SamplingGar::clear(){
118bool SamplingGar::readSmearPar(){
119 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
121 if(m_magConfig<0.05) fileName = filePath +
"/dat/par_SamplingGar_0T.txt";
122 else fileName = filePath +
"/dat/par_SamplingGar_1T.txt";
123 ifstream fin(fileName.c_str(), ios::in);
124 cout <<
"fileName: " << fileName << endl;
128 if( ! fin.is_open() ){
129 cout <<
"ERROR: can not open file " << fileName << endl;
132 while(fin >> strpar){
133 if(
'#' == strpar[0]){
134 getline(fin, strline);
135 }
else if(
"Mean_X_function" == strpar){
136 fin >> m_meanXpar[0] >> m_meanXpar[1];
137 }
else if(
"Sigma_X_function" == strpar){
138 fin >> m_sigmaXpar[0] >> m_sigmaXpar[1] >> m_sigmaXpar[2] >> m_sigmaXpar[3];
139 }
else if(
"Mean_Z_function" == strpar){
141 }
else if(
"Sigma_Z_function" == strpar){
142 fin >> m_sigmaZpar[0] >> m_sigmaZpar[1] >> m_sigmaZpar[2] >> m_sigmaZpar[3];
143 }
else if(
"Mean_T_function" == strpar){
144 fin >> m_meanTpar[0] >> m_meanTpar[1];
145 }
else if(
"Sigma_T_function" == strpar){
146 fin >> m_sigmaTpar[0] >> m_sigmaTpar[1] >> m_sigmaTpar[2] >> m_sigmaTpar[3];
147 }
else if(
"Transparency_Gem1" == strpar){
148 fin >> m_transparency_gem1;
149 m_transparency_gem1=1-(1-m_transparency_gem1)*m_TransMultiplier;
150 }
else if(
"Gain_Gem1" == strpar){
151 fin >> m_gain_gem[0][0] >> m_gain_gem[0][1] >> m_gain_gem[0][2];
154 }
else if(
"MeanX_Transf1" == strpar){
155 fin >> m_meanX_transf[0];
156 }
else if(
"SigmaX_Transf1" == strpar){
157 fin >> m_sigmaX_transf[0];
158 }
else if(
"MeanZ_Transf1" == strpar){
159 fin >> m_meanZ_transf[0];
160 }
else if(
"SigmaZ_Transf1" == strpar){
161 fin >> m_sigmaZ_transf[0];
162 }
else if(
"MeanT_Transf1" == strpar){
163 fin >> m_meanT_transf[0];
164 }
else if(
"SigmaT_Transf1" == strpar){
165 fin >> m_sigmaT_transf[0];
166 }
else if(
"Transparency_Gem2" == strpar){
167 fin >> m_transparency_gem2;
168 m_transparency_gem2=1-(1-m_transparency_gem2)*m_TransMultiplier;
169 }
else if(
"Gain_Gem2" == strpar){
170 fin >> m_gain_gem[1][0] >> m_gain_gem[1][1] >> m_gain_gem[1][2];
173 }
else if(
"MeanX_Transf2" == strpar){
174 fin >> m_meanX_transf[1];
175 }
else if(
"SigmaX_Transf2" == strpar){
176 fin >> m_sigmaX_transf[1];
177 }
else if(
"MeanZ_Transf2" == strpar){
178 fin >> m_meanZ_transf[1];
179 }
else if(
"SigmaZ_Transf2" == strpar){
180 fin >> m_sigmaZ_transf[1];
181 }
else if(
"MeanT_Transf2" == strpar){
182 fin >> m_meanT_transf[1];
183 }
else if(
"SigmaT_Transf2" == strpar){
184 fin >> m_sigmaT_transf[1];
185 }
else if(
"Transparency_Gem3" == strpar){
186 fin >> m_transparency_gem3;
187 m_transparency_gem3=1-(1-m_transparency_gem3)*m_TransMultiplier;
188 }
else if(
"Gain_Gem3" == strpar){
189 fin >> m_gain_gem[2][0] >> m_gain_gem[2][1] >> m_gain_gem[2][2];
192 }
else if(
"MeanX_Induc" == strpar){
193 fin >> m_meanX_induc;
194 }
else if(
"SigmaX_Induc" == strpar){
195 fin >> m_sigmaX_induc;
196 }
else if(
"MeanZ_Induc" == strpar){
197 fin >> m_meanZ_induc;
198 }
else if(
"SigmaZ_Induc" == strpar){
199 fin >> m_sigmaZ_induc;
200 }
else if(
"MeanT_Induc" == strpar){
201 fin >> m_meanT_induc;
202 }
else if(
"SigmaT_Induc" == strpar){
203 fin >> m_sigmaT_induc;
210bool SamplingGar::samplingDrift(
int layer,
double driftD,
int idIon){
211 G4double frandom = G4UniformRand();
213 if(frandom > m_transparency_gem1)
return false;
214 int n = samplingGain(layer,0);
215 double meanPhi = m_meanXpar[0] + m_meanXpar[1]*driftD;
216 double sigmaPhi = m_sigmaXpar[0] + m_sigmaXpar[1]*driftD + m_sigmaXpar[2]*driftD*driftD + m_sigmaXpar[3]*driftD*driftD*driftD;
218 double sigmaZ = m_sigmaZpar[0] + m_sigmaZpar[1]*driftD + m_sigmaZpar[2]*driftD*driftD + m_sigmaZpar[3]*driftD*driftD*driftD;
219 double meanT = m_meanTpar[0] + m_meanTpar[1]*driftD;
220 double sigmaT = m_sigmaTpar[0] + m_sigmaTpar[1]*driftD + m_sigmaTpar[2]*driftD*driftD + m_sigmaTpar[3]*driftD*driftD*driftD;
223 for(
int i=0; i<
n; i++){
224 double dphi = G4RandGauss::shoot(meanPhi, sigmaPhi*m_DiffuMultiplier);
225 double dz = G4RandGauss::shoot(meanZ, sigmaZ*m_DiffuMultiplier);
226 double dt = G4RandGauss::shoot(meanT, sigmaT);
228 m_idIon.push_back(idIon);
229 m_vecGem1dX.push_back(-1.0*dphi);
230 m_vecGem1dZ.push_back(dz);
231 m_vecGem1dT.push_back(
dt);
237bool SamplingGar::samplingTransfer(
int layer,
int region,
int idLastStep){
239 if(1==region) transp = m_transparency_gem2;
240 else transp = m_transparency_gem3;
241 G4double frandom = G4UniformRand();
242 if(frandom > transp)
return false;
243 int n = samplingGain(layer,region);
245 for(
int i=0; i<
n; i++){
246 double dphi = G4RandGauss::shoot(m_meanX_transf[region-1], m_sigmaX_transf[region-1]*m_DiffuMultiplier);
247 double dz = G4RandGauss::shoot(m_meanZ_transf[region-1], m_sigmaZ_transf[region-1]*m_DiffuMultiplier);
248 double dt = G4RandGauss::shoot(m_meanT_transf[region-1], m_sigmaT_transf[region-1]);
251 m_idGem1.push_back(idLastStep);
252 m_vecGem2dX.push_back(-1.0*dphi);
253 m_vecGem2dZ.push_back(dz);
254 m_vecGem2dT.push_back(
dt);
256 m_idGem2.push_back(idLastStep);
257 m_vecGem3dX.push_back(-1.0*dphi);
258 m_vecGem3dZ.push_back(dz);
259 m_vecGem3dT.push_back(
dt);
262 if(1==region) m_nEgem2 +=
n;
267int SamplingGar::samplingGain(
int layer ,
int region){
268 double xRand = m_funPolya[layer][region]->GetRandom(1, 500);
269 int gain = (int)xRand;
273bool SamplingGar::calMultiE(
int layer){
274 for(
int i=0; i<m_nEgem3; i++){
279 double dphiGem3 = m_vecGem3dX[i];
280 double dzGem3 = m_vecGem3dZ[i];
281 double dtGem3 = m_vecGem3dT[i];
283 int idGem2 = m_idGem2[i];
284 double dphiGem2 = m_vecGem2dX[idGem2];
285 double dzGem2 = m_vecGem2dZ[idGem2];
286 double dtGem2 = m_vecGem2dT[idGem2];
288 int idGem1 = m_idGem1[idGem2];
289 double dphiGem1 = m_vecGem1dX[idGem1];
290 double dzGem1 = m_vecGem1dZ[idGem1];
291 double dtGem1 = m_vecGem1dT[idGem1];
293 int idIon = m_idIon[idGem1];
294 double rini = m_vecIonR[idIon];
295 double phiini = m_vecIonPhi[idIon];
296 double zini = m_vecIonZ[idIon];
297 double tini = m_vecIonT[idIon];
300 double dphiTot = dphiGem1 + dphiGem2 + dphiGem3;
301 double xNew = rNew * phiini + dphiTot;
304 phiOut = xNew/rNew + CLHEP::twopi;
305 }
else if(xNew > (rNew * CLHEP::twopi)){
306 phiOut = xNew/rNew - CLHEP::twopi;
308 phiOut = xNew / rNew;
311 m_eX.push_back(rNew *
cos(phiOut));
312 m_eY.push_back(rNew *
sin(phiOut));
313 m_eZ.push_back(zini + dzGem1 + dzGem2 + dzGem3);
314 m_eT.push_back(tini + dtGem1 + dtGem2 + dtGem3);
double sin(const BesAngle a)
double cos(const BesAngle a)
double getInnerROfCgemFoil() const
CgemGeoFoil * getCgemFoil(int i) const
double getInnerROfGapI() const
virtual CgemGeoLayer * getCgemLayer(int i) const =0
void init(ICgemGeomSvc *geomSvc, double magConfig)
void setIonElectrons(int layer, int nElectrons, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > t)