BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofDigitizerEcV2.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description:
5////Author: Dengzy
6////Created: Mar, 2004
7////Modified:
8////Comment:
9////---------------------------------------------------------------------------//
10////$Id: BesTofDigitizerEcV2.cc
11
13#include "BesTofHit.hh"
14#include "G4DigiManager.hh"
15#include "G4RunManager.hh"
16#include "Randomize.hh"
17#include "G4Poisson.hh"
18#include "BesTofDigi.hh"
19#include "BesTofGeoParameter.hh"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "G4Svc/IG4Svc.h"
24#include "G4Svc/G4Svc.h"
25#include "G4SystemOfUnits.hh"
26#include "G4PhysicalConstants.hh"
27
29{
30 ReadData();
31 m_timeBinSize=0.005;
32
33 //retrieve G4Svc
34 ISvcLocator* svcLocator = Gaudi::svcLocator();
35 IG4Svc* tmpSvc;
36 StatusCode sc = svcLocator->service("G4Svc", tmpSvc);
37 m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
38
39}
40
42{
44
45 m_ecR1 = tofPara->GetEcR1();
46 m_tau1Ec = tofPara->GetTau1Ec();
47 m_tau2Ec = tofPara->GetTau2Ec();
48 m_tau3Ec = tofPara->GetTau3Ec();
49 m_tauRatioEc = tofPara->GetTauRatioEc();
50 m_refIndexEc = tofPara->GetRefIndexEc();
51 m_phNConstEc = tofPara->GetPhNConstEc();
52 m_Cpe2pmtEc = tofPara->GetCpe2pmtEc();
53 m_rAngleEc = tofPara->GetRAngleEc();
54 m_QEEc = tofPara->GetQEEc();
55 m_CEEc = tofPara->GetCEEc();
56 m_peCorFacEc = tofPara->GetPeCorFacEc();
57 m_attenEc = tofPara->GetAttenEc();
58
59 m_ttsMeanEc = tofPara->GetTTSmeanEc();
60 m_ttsSigmaEc = tofPara->GetTTSsigmaEc();
61 m_PMTgainEc = tofPara->GetPMTgainEc();
62 m_CeEc = tofPara->GetCeEc();
63 m_riseTimeEc = tofPara->GetRiseTimeEc();
64 m_LLthreshEc = tofPara->GetLLthreshEc();
65 m_HLthreshEc = tofPara->GetHLthreshEc();
66 m_preGainEc = tofPara->GetPreGainEc();
67 m_noiseSigmaEc = tofPara->GetNoiseSigmaEc();
68}
69
74
76{
77 m_beamTime = m_G4Svc->GetBeamTime() * ns;
79
80 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
81
82 G4int THCID = digiManager->GetHitsCollectionID("BesTofHitsCollection");
83 m_THC = (BesTofHitsCollection*) (digiManager->GetHitsCollection(THCID));
84
85 if (m_THC)
86 {
87 //for each digi, compute TDC and ADC
88 G4int partId, scinNb, nHits;
89 G4double edep;
90 BesTofHit* hit;
91 partId=scint->GetPartId();
92 scinNb=scint->GetScinNb();
93 edep = scint->GetEdep();
94 nHits=scint->GetHitIndexes()->size();
95
96 TofPmtInit();
97
98 if (edep>0.01)
99 {
100 for (G4int j=0;j<nHits;j++)
101 {
102 hit= (*m_THC)[( *(scint->GetHitIndexes()) )[j]];
103 TofPmtAccum(hit);
104 }
105
106 //get final tdc and adc
107 TofPmtRspns(partId);
108
109 G4double temp0 = m_ADC[0]+m_TDC[0];
110 G4double temp1 = m_ADC[1]+m_TDC[1];
111 if ( (partId==1&&temp0>0&&temp1>0) || ((partId!=1)&&temp0>0) )
112 {
113 if (m_ADC[0]>1000) m_ADC[0]=1000;
114 if (m_ADC[1]>1000) m_ADC[1]=1000;
115 BesTofDigi* digi = new BesTofDigi;
117 digi->SetPartId(partId);
118 digi->SetScinNb(scinNb);
119 digi->SetForwADC( m_ADC[0]) ;
120 digi->SetBackADC( m_ADC[1]) ;
121 if (m_TDC[0]!=-999)
122 m_TDC[0] = m_TDC[0]+m_beamTime;
123 if (m_TDC[1]!=-999)
124 m_TDC[1] = m_TDC[1]+m_beamTime;
125 digi->SetForwTDC( m_TDC[0]) ;
126 digi->SetBackTDC( m_TDC[1]) ;
127 m_besTofDigitsCollection->insert(digi);
128 }
129 }
130 }
131}
132
134{
135 m_trackIndex=-999;
136 m_globalTime = 9999;
137 m_t1st[0]=100;
138 m_t1st[1]=100;
139 m_tLast[0]=0.;
140 m_tLast[1]=0;
141 m_totalPhot[0]=0;
142 m_totalPhot[1]=0;
143 for (G4int i=0;i<2;i++)
144 for (G4int j=0;j<m_profBinNEcV2;j++)
145 m_nPhot[j][i]=0;
146
147}
148
150{
151 G4double cvelScint=c_light/m_refIndexEc;
152 //Get information of this step
153 G4ThreeVector pos=hit->GetPos();
154 G4int trackIndex = hit->GetTrackIndex();
155 G4int partId =hit->GetPartId();
156 G4double edep=hit->GetEdep();
157 G4double stepL=hit->GetStepL();
158 G4double deltaT=hit->GetDeltaT();
159 G4double timeFlight=hit->GetTime()-m_beamTime;
160 if (timeFlight < m_globalTime)
161 {
162 m_globalTime = timeFlight;
163 m_trackIndex = trackIndex;
164 }
165
166 G4ThreeVector pDirection=hit->GetPDirection();
167 G4double nx=pDirection.x();
168 G4double ny=pDirection.y();
169 G4double nz=pDirection.z();
170
171 //Cpe2pmt=cathode area/scint area
172 //peCorFac=correction factor for eff. of available Npe
173
174 //number of photons generated in this step
175 G4int NphStep;
176 NphStep=G4int(edep*m_phNConstEc*m_Cpe2pmtEc*0.66*m_QEEc*m_CEEc*m_peCorFacEc);
177
178 G4double ddS, ddT;
179 if (NphStep>0)
180 {
181 for (G4int i=0;i<NphStep;i++)
182 {
183 //uniform scintilation in each step
184 ddS=stepL*G4UniformRand();
185 ddT=deltaT*G4UniformRand();
186 G4ThreeVector emtPos;
187 emtPos.setX(pos.x() + nx*ddS);
188 emtPos.setY(pos.y() + ny*ddS);
189 emtPos.setZ(pos.z() + nz*ddS);
190
191 //check scinillation light whether to hit the pmt or not
192 //forb=0/1 for forward(z>0, east) and backward(z<0, west)
193 G4double pathL=0;
194 G4int forb;
195 DirectPh(partId, emtPos, pathL, forb);
196
197 //check if photon can reach PMT or not, after attenuation
198 G4double ran=G4UniformRand();
199 if (pathL>0 && exp(-pathL/m_attenEc) > ran)
200 {
201 //propagation time in scintillator
202 G4double scinSwim=pathL/cvelScint;
203 //scintillation timing
204 //G4double scinTime=GenPhoton(partId);
205 G4double scinTime=Scintillation(partId);
206
207 //PMT transit time
208 G4double transitTime=TransitTime();
209 //sum up all time components
210 G4double endTime= timeFlight + ddT + scinSwim + scinTime + transitTime;
211
212 //store timing into binned buffer
213 AccuSignal(endTime, forb);
214
215 //update 1st and last timings here
216 if (m_t1st[forb]>endTime) m_t1st[forb] = endTime;
217 if (m_tLast[forb]<endTime) m_tLast[forb]= endTime;
218 }
219 }
220 }
221}
222
223
224void BesTofDigitizerEcV2::DirectPh(G4int partId, G4ThreeVector emtPos, G4double& pathL, G4int& forb)
225{
226 //generation photon have random direction
227 //optical parameters of scintillation simulation
228 //G4double cos_spanEc = 1-1/m_refIndex;
229 G4double cos_spanEc = 1;
230 G4double ran;
231 //dcos=cos_span*(ran*2.0-1.0);
232 ran=G4UniformRand();
233 //assuming uniform phi distribution, simulate cos distr only
234 G4double dcosEc = cos_spanEc*(ran*2.0-1.0);
235 G4double r2=sqrt(emtPos.x()*emtPos.x()+emtPos.y()*emtPos.y());
236 if (dcosEc > 0.0 && dcosEc != 1)
237 {
238 forb=0; //forward
239 pathL = (r2-m_ecR1)/(1.0-dcosEc);
240 }
241 else if (dcosEc < 0 && dcosEc != -1)
242 {
243 forb=0;
244 pathL=(2*838-r2-m_ecR1)/(1.0+dcosEc);
245 }
246}
247
249{
250 G4double tmp_tauRatio,tmp_tau1,tmp_tau2,tmp_tau3;
251 tmp_tauRatio = m_tauRatioEc;
252 tmp_tau1 = m_tau1Ec;
253 tmp_tau2 = m_tau2Ec;
254 tmp_tau3 = m_tau3Ec;
255
256 G4double UniformR = tmp_tauRatio/(1+tmp_tauRatio);
257 G4double EmissionTime;
258 if (G4UniformRand()>UniformR) {
259 while (1) {
260 EmissionTime = -tmp_tau2*log( G4UniformRand() );
261 if (G4UniformRand()-exp(EmissionTime/tmp_tau2-EmissionTime/tmp_tau1)>1.E-8)
262 break;
263 }
264 }
265 else EmissionTime = -tmp_tau3*log( G4UniformRand() );
266 return EmissionTime;
267}
268
269/*G4double BesTofDigitizerEcV2::GenPhoton(G4int partId)
270{
271 //get scintilation time
272 G4double scinTime;
273 static G4double scinA[26000];
274 G4double random[2];
275 G4double inverseRegion, ran1, ran2, problive;
276 static G4int istore=-1;
277 if(istore<0)
278 {
279 istore=1;
280 for(G4int i=0;i<26000;i++)
281 scinA[i]=Scintillation( (i+1) *0.001 , partId);
282 }
283 while(1)
284 {
285 HepRandom::getTheEngine()->flatArray(2, random);
286 inverseRegion=random[0]*2.00975218688231;
287 ran1=-4.5*log(1-inverseRegion/(0.45*4.5));
288 ran2=0.45*exp(-1.*ran1/4.5)*random[1];
289 problive=scinA[G4int(ran1*1000)+1];
290 if(problive>=ran2)
291 { scinTime=ran1; break; }
292 }
293 return scinTime;
294}*/
295
297{
298 //get time transit spread
299 return G4RandGauss::shoot(m_ttsMeanEc,m_ttsSigmaEc);
300}
301
302void BesTofDigitizerEcV2::AccuSignal(G4double endTime, G4int forb)
303{
304 G4int ihst;
305 ihst=G4int(endTime/m_timeBinSize);
306 if (ihst>0 &&ihst<m_profBinNEcV2)
307 {
308 m_nPhot[ihst][forb]=m_nPhot[ihst][forb]+1;
309 m_totalPhot[forb]=m_totalPhot[forb]+1;
310 }
311}
312
314{
315 //to generate PMT signal shape for single photoelectron.
316 //only one time for a job.
317 static G4double snpe[m_snpeBinNEcV2];
318 static G4int istore_snpe=-1;
319
320 //Model: f(t)=Gain*mv_1pe* t**2 * exp-(t/tau)**2/normal-const
321 //normalization const =sqrt(pi)*tau*tau*tau/4.0
322 G4double tau = m_riseTimeEc;
323 G4double norma_const=sqrt(M_PI)*tau*tau*tau/4.0; //in unit of ns**3
324 G4double echarge=1.6e-7; //in unit of PC
325
326 //time profile of pmt signals for Back and Forward PMT.
327 G4double profPmt[m_profBinNEcV2][2];
328
329 G4double t;
330 G4int n1, n2, ii;
331 G4int phtn;
332
333 if (istore_snpe<0)
334 {
335 istore_snpe = 1;
336 for (G4int i=0;i<m_snpeBinNEcV2;i++)
337 {
338 t=(i+1)*m_timeBinSize;
339 snpe[i]=m_PMTgainEc*m_CeEc*t*t*exp(- (t/tau) * (t/tau) )/norma_const;
340 }
341 }
342 //for barrel and endcap tof: fb=2 or 1
343 G4int fb=1;
344
345 for (G4int j=0;j<2;j++)
346 {
347 m_TDC[j]=-999.0;
348 m_ADC[j]=-999.0;
349 }
350 for (G4int j=0; j<fb; j++)
351 {
352 if (m_totalPhot[j] > 0)
353 {
354 n1=G4int(m_t1st[j]/m_timeBinSize);
355 n2=G4int(m_tLast[j]/m_timeBinSize);
356
357 for (G4int i=0;i<m_profBinNEcV2;i++)
358 profPmt[i][j]=0.0;
359
360 //generate PMT pulse
362 for (G4int i=n1;i<n2;i++)
363 {
364 phtn=m_nPhot[i][j];
365 if (phtn>0)
366 {
367 for (G4int ihst=0; ihst<m_snpeBinNEcV2; ihst++)
368 {
369 ii=i+ihst;
370 if (ii<m_profBinNEcV2)
371 profPmt[ii][j] += phtn*snpe[ihst];
372 }
373 }
374 }
375
376 //add preamplifier and noise
377 for (int i=0;i<m_profBinNEcV2;i++)
378 {
379 if (profPmt[i][j]>0)
380 profPmt[i][j] = m_preGainEc*profPmt[i][j]+G4RandGauss::shoot(0,m_noiseSigmaEc);
381 }
382
383 //get pulse height
384 G4double max=0;
385 for (int i=0;i<m_profBinNEcV2;i++)
386 {
387 if (profPmt[i][j]>max)
388 max=profPmt[i][j];
389 }
390
391 G4double tmp_HLthresh, tmp_LLthresh;
392 if (partId==1) {
393 tmp_HLthresh = m_HLthreshEc;
394 tmp_LLthresh = m_LLthreshEc;
395 }
396 else {
397 tmp_HLthresh = m_HLthreshEc;
398 tmp_LLthresh = m_LLthreshEc;
399 }
400
401 //get final tdc and adc
402 if (max>=tmp_HLthresh)
403 {
404 for (int i=0;i<m_profBinNEcV2;i++)
405 {
406 if ( profPmt[i][j] >= tmp_LLthresh )
407 {
408 m_TDC[j] = i*m_timeBinSize;
409 m_ADC[j] = m_preGainEc*m_totalPhot[j]*echarge*m_PMTgainEc;
410 break;
411 }
412 }
413 }
414 }
415 }
416}
417
418
419
420
421
422
423
424
425
426
427
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
Definition BesTofDigi.hh:79
const G4int m_profBinNEcV2
const G4int m_snpeBinNEcV2
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition BesTofHit.hh:116
EvtComplex exp(const EvtComplex &c)
int n2
Definition SD0Tag.cxx:55
int n1
Definition SD0Tag.cxx:54
#define M_PI
Definition TConstant.h:4
TTree * t
Definition binning.cxx:23
void SetPartId(G4int partId)
Definition BesTofDigi.hh:37
void SetForwADC(G4double ADC)
Definition BesTofDigi.hh:40
void SetTrackIndex(G4int index)
Definition BesTofDigi.hh:36
void SetBackADC(G4double ADC)
Definition BesTofDigi.hh:41
void SetForwTDC(G4double TDC)
Definition BesTofDigi.hh:42
void SetScinNb(G4int scinNb)
Definition BesTofDigi.hh:39
void SetBackTDC(G4double TDC)
Definition BesTofDigi.hh:43
void AccuSignal(G4double, G4int)
G4double Scintillation(G4int)
void DirectPh(G4int, G4ThreeVector, G4double &, G4int &)
virtual void Digitize(ScintSingle *, BesTofDigitsCollection *)
void TofPmtAccum(BesTofHit *)
BesTofDigitsCollection * m_besTofDigitsCollection
BesTofHitsCollection * m_THC
static BesTofGeoParameter * GetInstance()
G4double GetDeltaT()
Definition BesTofHit.hh:75
G4ThreeVector GetPDirection()
Definition BesTofHit.hh:76
G4double GetStepL()
Definition BesTofHit.hh:71
G4double GetTime()
Definition BesTofHit.hh:74
G4double GetEdep()
Definition BesTofHit.hh:70
G4ThreeVector GetPos()
Definition BesTofHit.hh:73
G4int GetPartId()
Definition BesTofHit.hh:68
G4int GetTrackIndex()
Definition BesTofHit.hh:66
Definition G4Svc.h:33
double GetBeamTime()
Definition G4Svc.h:93
G4int GetPartId()
vector< G4int > * GetHitIndexes()
G4int GetScinNb()
G4double GetEdep()
#define ns(x)
Definition xmltok.c:1504