CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
SamplingGar.cxx
Go to the documentation of this file.
2
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"
8
9#include "CLHEP/Units/PhysicalConstants.h"
10
11#include "G4DigiManager.hh"
12#include "Randomize.hh"
13#include "G4ios.hh"
14
15#include "CLHEP/Units/PhysicalConstants.h"
16
17#include <iomanip>
18#include <iostream>
19#include <fstream>
20#include <cmath>
21
22#include "TRandom.h"
23#include "TMath.h"
24
25using namespace std;
26
28 m_GainMultiplier[0]=1.60;
29 m_GainMultiplier[1]=1.60;
30 m_GainMultiplier[2]=1.60;
31}
32
35
36void SamplingGar::init(ICgemGeomSvc* geomSvc, double magConfig){
37 m_geomSvc = geomSvc;
38 m_magConfig = magConfig;
39
40 readSmearPar();
41
42 // initialize polya functions
43 char funname[10];
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]);
51 }
52 }
53}
54
55void SamplingGar::setIonElectrons(int layer, int nElectrons, std::vector<double> x, std::vector<double> y, std::vector<double> z, std::vector<double> t){
56 clear();
57 m_nIonE = nElectrons;
58 // cout << "nIonE = " << m_nIonE << endl;
59 for(int i=0; i<nElectrons; i++){
60 double r = sqrt(x[i]*x[i] + y[i]*y[i]);
61 double phi;
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]);
68
69 // cout << "check geom layer" << setw(15) << layer << setw(15) << m_geomSvc->getCgemLayer(layer)->getInnerROfGapD()
70 // << setw(15) << m_geomSvc->getCgemLayer(layer)->getOuterROfGapD()
71 // << setw(15) << m_geomSvc->getCgemLayer(layer)->getCgemFoil(0)->getInnerROfCgemFoil() << endl;
72
73 double radii_gem1 = m_geomSvc->getCgemLayer(layer)->getCgemFoil(0)->getInnerROfCgemFoil();
74 double driftD = radii_gem1 - r;
75 // cout << "driftD = " << setw(15) << driftD << setw(15) << radii_gem1 << setw(15) << r << endl;
76 samplingDrift(layer,driftD, i);
77 }
78 // cout << "nMultiGem1 = " << m_nEgem1 << endl;
79 for(int i=0; i<m_nEgem1; i++) samplingTransfer(layer,1, i);
80 // cout << "nMultiGem2 = " << m_nEgem2 << endl;
81 for(int i=0; i<m_nEgem2; i++) samplingTransfer(layer,2, i);
82 // cout << "nMultiGem3 = " << m_nEgem3 << endl;
83 calMultiE(layer);
84}
85
86void SamplingGar::clear(){
87 m_nIonE = 0;
88 m_vecIonR.clear();
89 m_vecIonPhi.clear();
90 m_vecIonZ.clear();
91 m_vecIonT.clear();
92
93 m_nEgem1 = 0;
94 m_idIon.clear();
95 m_vecGem1dX.clear();
96 m_vecGem1dZ.clear();
97 m_vecGem1dT.clear();
98
99 m_nEgem2 = 0;
100 m_idGem1.clear();
101 m_vecGem2dX.clear();
102 m_vecGem2dZ.clear();
103 m_vecGem2dT.clear();
104
105 m_nEgem3 = 0;
106 m_idGem2.clear();
107 m_vecGem3dX.clear();
108 m_vecGem3dZ.clear();
109 m_vecGem3dT.clear();
110
111 m_nMulElec = 0;
112 m_eX.clear();
113 m_eY.clear();
114 m_eZ.clear();
115 m_eT.clear();
116}
117
118bool SamplingGar::readSmearPar(){
119 string filePath = getenv("CGEMDIGITIZERSVCROOT");
120 string fileName;
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;
125
126 string strline;
127 string strpar;
128 if( ! fin.is_open() ){
129 cout << "ERROR: can not open file " << fileName << endl;
130 return false;
131 }
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){
140 fin >> m_meanZpar;
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];
152 //m_gain_gem[0][1]=m_gain_gem[0][1]*m_GainMultiplier;
153
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];
171 //m_gain_gem[1][1]=m_gain_gem[1][1]*m_GainMultiplier;
172
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];
190 //m_gain_gem[2][1]=m_gain_gem[2][1]*m_GainMultiplier;
191
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;
204 }
205 }
206 fin.close();
207 return true;
208}
209
210bool SamplingGar::samplingDrift(int layer, double driftD, int idIon){
211 G4double frandom = G4UniformRand();
212 // cout << "frandom = " << frandom << ", trans = " << m_transparency_gem1 << endl;
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;
217 double meanZ = 0.0;
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;
221 // cout << "debug in samplingDrift: " << setw(15) << driftD << setw(15) << meanPhi << setw(15) << sigmaPhi
222 // << setw(15) << sigmaZ << setw(15) << meanT << setw(15) << sigmaT << endl;
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);
227
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);
232 }
233 m_nEgem1 += n;
234 return true;
235}
236
237bool SamplingGar::samplingTransfer(int layer, int region, int idLastStep){
238 double transp;
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);
244
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]);
249
250 if(1==region){
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);
255 } else{
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);
260 }
261 }
262 if(1==region) m_nEgem2 += n;
263 else m_nEgem3 += n;
264 return true;
265}
266
267int SamplingGar::samplingGain(int layer ,int region){
268 double xRand = m_funPolya[layer][region]->GetRandom(1, 500);
269 int gain = (int)xRand;
270 return gain;
271}
272
273bool SamplingGar::calMultiE(int layer){
274 for(int i=0; i<m_nEgem3; i++){
275 //double dphiInduc = -1.0 * G4RandGauss::shoot(m_meanX_induc, m_sigmaX_induc);
276 //double dzInduc = G4RandGauss::shoot(m_meanZ_induc, m_sigmaZ_induc);
277 //double dtInduc = G4RandGauss::shoot(m_meanT_induc, m_sigmaT_induc);
278
279 double dphiGem3 = m_vecGem3dX[i];
280 double dzGem3 = m_vecGem3dZ[i];
281 double dtGem3 = m_vecGem3dT[i];
282
283 int idGem2 = m_idGem2[i];
284 double dphiGem2 = m_vecGem2dX[idGem2];
285 double dzGem2 = m_vecGem2dZ[idGem2];
286 double dtGem2 = m_vecGem2dT[idGem2];
287
288 int idGem1 = m_idGem1[idGem2];
289 double dphiGem1 = m_vecGem1dX[idGem1];
290 double dzGem1 = m_vecGem1dZ[idGem1];
291 double dtGem1 = m_vecGem1dT[idGem1];
292
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];
298
299 double rNew = m_geomSvc->getCgemLayer(layer)->getInnerROfGapI();
300 double dphiTot = dphiGem1 + dphiGem2 + dphiGem3;
301 double xNew = rNew * phiini + dphiTot;
302 double phiOut; // phi angle
303 if(xNew < 0){
304 phiOut = xNew/rNew + CLHEP::twopi;
305 } else if(xNew > (rNew * CLHEP::twopi)){
306 phiOut = xNew/rNew - CLHEP::twopi;
307 } else{
308 phiOut = xNew / rNew;
309 }
310
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);
315 m_nMulElec++;
316
317 // double rNew = m_geomSvc->getCgemLayer(layer)->getInnerROfAnode();
318 // double dphiTot = dphiGem1 + dphiGem2 + dphiGem3 + dphiInduc;
319 // double xNew = rNew * phiini + dphiTot;
320 // double phiOut; // phi angle
321 // if(xNew < 0){
322 // phiOut = xNew/rNew + CLHEP::twopi;
323 // } else if(xNew > (rNew * CLHEP::twopi)){
324 // phiOut = xNew/rNew - CLHEP::twopi;
325 // } else{
326 // phiOut = xNew / rNew;
327 // }
328
329 // m_eX.push_back(rNew * cos(phiOut));
330 // m_eY.push_back(rNew * sin(phiOut));
331 // m_eZ.push_back(zini + dzGem1 + dzGem2 + dzGem3 + dzInduc);
332 // m_eT.push_back(tini + dtGem1 + dtGem2 + dtGem3 + dtInduc);
333 // m_nMulElec++;
334 }
335 return true;
336}
TGraphErrors * dt
Definition AbsCor.cxx:72
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
const Int_t n
Double_t x[10]
double getInnerROfCgemFoil() const
Definition CgemGeoFoil.h:33
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)
int t()
Definition t.c:1