1#include "CgemDigitizerSvc/SamplingGar.h"
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"
35 m_magConfig = magConfig;
41 for(
int i=0; i<3; i++){
42 sprintf(funname,
"funPolya%d", i);
43 m_funPolya[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);
44 m_funPolya[i]->SetParameter(0, m_gain_gem[i][0]);
45 m_funPolya[i]->SetParameter(1, m_gain_gem[i][1]);
46 m_funPolya[i]->SetParameter(2, m_gain_gem[i][2]);
50void SamplingGar::setIonElectrons(
int layer,
int nElectrons, std::vector<double> x, std::vector<double> y, std::vector<double> z, std::vector<double>
t){
54 for(
int i=0; i<nElectrons; i++){
55 double r = sqrt(
x[i]*
x[i] + y[i]*y[i]);
57 if(y[i] >= 0) phi = acos(
x[i] / r);
58 else phi = CLHEP::twopi - acos(
x[i] / r);
59 m_vecIonR.push_back(r);
60 m_vecIonPhi.push_back(phi);
61 m_vecIonZ.push_back(z[i]);
62 m_vecIonT.push_back(
t[i]);
69 double driftD = radii_gem1 - r;
71 samplingDrift(driftD, i);
74 for(
int i=0; i<m_nEgem1; i++) samplingTransfer(1, i);
76 for(
int i=0; i<m_nEgem2; i++) samplingTransfer(2, i);
81void SamplingGar::clear(){
113bool SamplingGar::readSmearPar(){
114 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
116 if(m_magConfig<0.05) fileName = filePath +
"/dat/par_SamplingGar_0T.txt";
117 else fileName = filePath +
"/dat/par_SamplingGar_1T.txt";
118 ifstream fin(fileName.c_str(), ios::in);
119 cout <<
"fileName: " << fileName << endl;
123 if( ! fin.is_open() ){
124 cout <<
"ERROR: can not open file " << fileName << endl;
127 while(fin >> strpar){
128 if(
'#' == strpar[0]){
129 getline(fin, strline);
130 }
else if(
"Mean_X_function" == strpar){
131 fin >> m_meanXpar[0] >> m_meanXpar[1];
132 }
else if(
"Sigma_X_function" == strpar){
133 fin >> m_sigmaXpar[0] >> m_sigmaXpar[1] >> m_sigmaXpar[2] >> m_sigmaXpar[3];
134 }
else if(
"Mean_Z_function" == strpar){
136 }
else if(
"Sigma_Z_function" == strpar){
137 fin >> m_sigmaZpar[0] >> m_sigmaZpar[1] >> m_sigmaZpar[2] >> m_sigmaZpar[3];
138 }
else if(
"Mean_T_function" == strpar){
139 fin >> m_meanTpar[0] >> m_meanTpar[1];
140 }
else if(
"Sigma_T_function" == strpar){
141 fin >> m_sigmaTpar[0] >> m_sigmaTpar[1] >> m_sigmaTpar[2] >> m_sigmaTpar[3];
142 }
else if(
"Transparency_Gem1" == strpar){
143 fin >> m_transparency_gem1;
144 }
else if(
"Gain_Gem1" == strpar){
145 fin >> m_gain_gem[0][0] >> m_gain_gem[0][1] >> m_gain_gem[0][2];
147 }
else if(
"MeanX_Transf1" == strpar){
148 fin >> m_meanX_transf[0];
149 }
else if(
"SigmaX_Transf1" == strpar){
150 fin >> m_sigmaX_transf[0];
151 }
else if(
"MeanZ_Transf1" == strpar){
152 fin >> m_meanZ_transf[0];
153 }
else if(
"SigmaZ_Transf1" == strpar){
154 fin >> m_sigmaZ_transf[0];
155 }
else if(
"MeanT_Transf1" == strpar){
156 fin >> m_meanT_transf[0];
157 }
else if(
"SigmaT_Transf1" == strpar){
158 fin >> m_sigmaT_transf[0];
159 }
else if(
"Transparency_Gem2" == strpar){
160 fin >> m_transparency_gem2;
161 }
else if(
"Gain_Gem2" == strpar){
162 fin >> m_gain_gem[1][0] >> m_gain_gem[1][1] >> m_gain_gem[1][2];
164 }
else if(
"MeanX_Transf2" == strpar){
165 fin >> m_meanX_transf[1];
166 }
else if(
"SigmaX_Transf2" == strpar){
167 fin >> m_sigmaX_transf[1];
168 }
else if(
"MeanZ_Transf2" == strpar){
169 fin >> m_meanZ_transf[1];
170 }
else if(
"SigmaZ_Transf2" == strpar){
171 fin >> m_sigmaZ_transf[1];
172 }
else if(
"MeanT_Transf2" == strpar){
173 fin >> m_meanT_transf[1];
174 }
else if(
"SigmaT_Transf2" == strpar){
175 fin >> m_sigmaT_transf[1];
176 }
else if(
"Transparency_Gem3" == strpar){
177 fin >> m_transparency_gem3;
178 }
else if(
"Gain_Gem3" == strpar){
179 fin >> m_gain_gem[2][0] >> m_gain_gem[2][1] >> m_gain_gem[2][2];
181 }
else if(
"MeanX_Induc" == strpar){
182 fin >> m_meanX_induc;
183 }
else if(
"SigmaX_Induc" == strpar){
184 fin >> m_sigmaX_induc;
185 }
else if(
"MeanZ_Induc" == strpar){
186 fin >> m_meanZ_induc;
187 }
else if(
"SigmaZ_Induc" == strpar){
188 fin >> m_sigmaZ_induc;
189 }
else if(
"MeanT_Induc" == strpar){
190 fin >> m_meanT_induc;
191 }
else if(
"SigmaT_Induc" == strpar){
192 fin >> m_sigmaT_induc;
199bool SamplingGar::samplingDrift(
double driftD,
int idIon){
200 G4double frandom = G4UniformRand();
202 if(frandom > m_transparency_gem1)
return false;
203 int n = samplingGain(0);
204 double meanPhi = m_meanXpar[0] + m_meanXpar[1]*driftD;
205 double sigmaPhi = m_sigmaXpar[0] + m_sigmaXpar[1]*driftD + m_sigmaXpar[2]*driftD*driftD + m_sigmaXpar[3]*driftD*driftD*driftD;
207 double sigmaZ = m_sigmaZpar[0] + m_sigmaZpar[1]*driftD + m_sigmaZpar[2]*driftD*driftD + m_sigmaZpar[3]*driftD*driftD*driftD;
208 double meanT = m_meanTpar[0] + m_meanTpar[1]*driftD;
209 double sigmaT = m_sigmaTpar[0] + m_sigmaTpar[1]*driftD + m_sigmaTpar[2]*driftD*driftD + m_sigmaTpar[3]*driftD*driftD*driftD;
212 for(
int i=0; i<
n; i++){
213 double dphi = G4RandGauss::shoot(meanPhi, sigmaPhi);
214 double dz = G4RandGauss::shoot(meanZ, sigmaZ);
215 double dt = G4RandGauss::shoot(meanT, sigmaT);
217 m_idIon.push_back(idIon);
218 m_vecGem1dX.push_back(-1.0*dphi);
219 m_vecGem1dZ.push_back(dz);
220 m_vecGem1dT.push_back(
dt);
226bool SamplingGar::samplingTransfer(
int region,
int idLastStep){
228 if(1==region) transp = m_transparency_gem2;
229 else transp = m_transparency_gem3;
230 G4double frandom = G4UniformRand();
231 if(frandom > transp)
return false;
232 int n = samplingGain(region);
234 for(
int i=0; i<
n; i++){
235 double dphi = G4RandGauss::shoot(m_meanX_transf[region-1], m_sigmaX_transf[region-1]);
236 double dz = G4RandGauss::shoot(m_meanZ_transf[region-1], m_sigmaZ_transf[region-1]);
237 double dt = G4RandGauss::shoot(m_meanT_transf[region-1], m_sigmaT_transf[region-1]);
240 m_idGem1.push_back(idLastStep);
241 m_vecGem2dX.push_back(-1.0*dphi);
242 m_vecGem2dZ.push_back(dz);
243 m_vecGem2dT.push_back(
dt);
245 m_idGem2.push_back(idLastStep);
246 m_vecGem3dX.push_back(-1.0*dphi);
247 m_vecGem3dZ.push_back(dz);
248 m_vecGem3dT.push_back(
dt);
251 if(1==region) m_nEgem2 +=
n;
256int SamplingGar::samplingGain(
int region){
257 double xRand = m_funPolya[region]->GetRandom(1, 500);
258 int gain = (int)xRand;
262bool SamplingGar::calMultiE(
int layer){
263 for(
int i=0; i<m_nEgem3; i++){
264 double dphiInduc = -1.0 * G4RandGauss::shoot(m_meanX_induc, m_sigmaX_induc);
265 double dzInduc = G4RandGauss::shoot(m_meanZ_induc, m_sigmaZ_induc);
266 double dtInduc = G4RandGauss::shoot(m_meanT_induc, m_sigmaT_induc);
268 double dphiGem3 = m_vecGem3dX[i];
269 double dzGem3 = m_vecGem3dZ[i];
270 double dtGem3 = m_vecGem3dT[i];
272 int idGem2 = m_idGem2[i];
273 double dphiGem2 = m_vecGem2dX[idGem2];
274 double dzGem2 = m_vecGem2dZ[idGem2];
275 double dtGem2 = m_vecGem2dT[idGem2];
277 int idGem1 = m_idGem1[idGem2];
278 double dphiGem1 = m_vecGem1dX[idGem1];
279 double dzGem1 = m_vecGem1dZ[idGem1];
280 double dtGem1 = m_vecGem1dT[idGem1];
282 int idIon = m_idIon[idGem1];
283 double rini = m_vecIonR[idIon];
284 double phiini = m_vecIonPhi[idIon];
285 double zini = m_vecIonZ[idIon];
286 double tini = m_vecIonT[idIon];
289 double dphiTot = dphiGem1 + dphiGem2 + dphiGem3;
290 double xNew = rNew * phiini + dphiTot;
293 phiOut = xNew/rNew + CLHEP::twopi;
294 }
else if(xNew > (rNew * CLHEP::twopi)){
295 phiOut = xNew/rNew - CLHEP::twopi;
297 phiOut = xNew / rNew;
300 m_eX.push_back(rNew *
cos(phiOut));
301 m_eY.push_back(rNew *
sin(phiOut));
302 m_eZ.push_back(zini + dzGem1 + dzGem2 + dzGem3);
303 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)