BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofDigitizerEcV3.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description: Utilize Geant4 full simulation results
5////Author: liuy
6////Created: Oct, 2008
7////Modified:Dec, 2008
8////Comment:
9////---------------------------------------------------------------------------//
10////$Id: BesTofDigitizerEcV3.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 "TH1F.h"
26#include "TNtuple.h"
27#include "TFile.h"
28#include "TMath.h"
29#include <unistd.h> // Check the file
30#include "G4SystemOfUnits.hh"
31#include "G4PhysicalConstants.hh"
33{
34 ReadData(); //Get some basic data (not Hit data, but information about smearing from electronics,... )
35 m_timeBinSize = 0.005;
36
37
38
39
40 // Simulation/G4Svc/G4Svc-00-01-47/src/G4Svc.cpp
41 //Get the basic parameters from the event: Starttime, Beamposition,...
42
43 //retrieve G4Svc
44 ISvcLocator* svcLocator = Gaudi::svcLocator();
45 IG4Svc* tmpSvc;
46 StatusCode sc = svcLocator->service("G4Svc", tmpSvc);
47 if(!sc.isSuccess())
48 {
49 std::cout << " Could not initialize Realization Service in BesTofDigitizerBrV2" << std::endl;
50 }
51 else
52 {
53 m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
54 }
55
56 //retrieve RealizationSvc
57 IRealizationSvc *tmpReal;
58 StatusCode scReal = svcLocator->service("RealizationSvc",tmpReal);
59 if (!scReal.isSuccess())
60 {
61 std::cout << " Could not initialize Realization Service in BesTofDigitizerEcV3" << std::endl;
62 }
63 else
64 {
65 m_RealizationSvc = dynamic_cast<RealizationSvc*>(tmpReal);
66 }
67
68
69
70 for(int i=0;i<50;i++)
71 {
72 for(int j=0;j<10;j++)
73 {
74 for(int k=0;k<10;k++)
75 {
76 for(int m=0;m<num1;m++) // num1 bin number in histogram is 400 at the moment
77 {
78 //G4cout << "time:" << propTime[i][j][k][m] << "; prob:" << prob[i][j][k][m] << "; eff:" << eff[i][j][k] << G4endl;
79 propTime[i][j][k][m] = 0;
80 prob[i][j][k][m] = 0;
81 eff[i][j][k] = 0;
82 }
83 }
84 }
85 }
86
88 G4cout << "ETofSim: Reading nTuples of is completed." << G4endl;
89}
90
92{
94
95 m_ecR1 = tofPara->GetEcR1();
96 m_tau1Ec = tofPara->GetTau1Ec();
97 m_tau2Ec = tofPara->GetTau2Ec();
98 m_tau3Ec = tofPara->GetTau3Ec();
99 m_tauRatioEc = tofPara->GetTauRatioEc();
100 m_refIndexEc = tofPara->GetRefIndexEc();
101 m_phNConstEc = tofPara->GetPhNConstEc();
102 m_Cpe2pmtEc = tofPara->GetCpe2pmtEc();
103 m_rAngleEc = tofPara->GetRAngleEc();
104 m_QEEc = tofPara->GetQEEc();
105 m_CEEc = tofPara->GetCEEc();
106 m_peCorFacEc = tofPara->GetPeCorFacEc();
107 m_attenEc = tofPara->GetAttenEc();
108
109 m_ttsMeanEc = tofPara->GetTTSmeanEc();
110 m_ttsSigmaEc = tofPara->GetTTSsigmaEc();
111 m_PMTgainEc = tofPara->GetPMTgainEc();
112 m_CeEc = tofPara->GetCeEc();
113 m_riseTimeEc = tofPara->GetRiseTimeEc();
114 m_LLthreshEc = tofPara->GetLLthreshEc();
115 m_HLthreshEc = tofPara->GetHLthreshEc();
116 m_preGainEc = tofPara->GetPreGainEc();
117 m_noiseSigmaEc = tofPara->GetNoiseSigmaEc();
118
119 //G4cout << "m_LLthreshEc:" << m_LLthreshEc << "; m_HLthreshEc:" << m_HLthreshEc << G4endl;
120
121}
122
123//I do not know what the following function read!
125{
126 int rBin,phiBin,zBin;
127 const int nR = 43;
128 const int nPhi = 6;
129 const int nZ = 6;
130 float efficiency0,x[400],y[400];
131
132
133 G4String dataPath = getenv("TOFSIMROOT");
134 if(!dataPath)
135 {
136 G4cout<<"Boss environment is not set!"<<G4endl;
137 exit(-1);
138 }
139
140 char treePath[200];
141 G4int runId = m_RealizationSvc->getRunId();
142 if(runId>=-80000 && runId<=-9484)
143 {
144 // After TOF HV adjustment, endcap attenL was set to 5000mm.
145 sprintf(treePath,"%s/dat/effTree_1600mm.root",dataPath.c_str());
146 }
147 else
148 {
149 //Before TOF HV adjustment, endcap attenL was set to 1600mm.
150 sprintf(treePath,"%s/dat/effTree_1600mm.root",dataPath.c_str());
151 }
152
153 TFile *f = new TFile(treePath, "read");
154 TTree *t = (TTree*)f->Get("effTree");
155
156 t->SetBranchAddress("rBin", &rBin);
157 t->SetBranchAddress("phiBin", &phiBin);
158 t->SetBranchAddress("zBin", &zBin);
159 t->SetBranchAddress("efficiency0", &efficiency0);
160 t->SetBranchAddress("x", x);
161 t->SetBranchAddress("y", y);
162
163 int r,phi,z;
164 for (Int_t i = 0; i < nR*nPhi*nZ; i++){
165 t->GetEntry(i);
166 r = rBin;
167 phi = phiBin;
168 z = zBin;
169 eff[r][phi][z] = efficiency0;
170 for (Int_t j = 0; j < 400; j++){
171 propTime[r][phi][z][j] = x[j];
172 prob[r][phi][z][j] = y[j];
173 //cout << "\n" << propTime[r][phi][z][j] << " " << prob[r][phi][z][j] << endl;
174 }
175 }
176
177}
178
180{;}
181
183{
184 m_beamTime = m_G4Svc->GetBeamTime() * ns;
186
187 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
188
189 G4int THCID = digiManager->GetHitsCollectionID("BesTofHitsCollection");
190 m_THC = (BesTofHitsCollection*) (digiManager->GetHitsCollection(THCID));
191
192 if (m_G4Svc->TofRootFlag())
193 {
194 m_eTotal = 0;
195 m_nDigi = 0;
196 m_partIdMPV = -9;
197 m_scinNbMPV = -9;
198 m_edepMPV = 0;
199 m_nDigiOut = 0;
200 }
201
202 if (m_THC)
203 {
204 //for each digi, compute TDC and ADC
205 G4int partId, scinNb, nHits;
206 G4double edep;
207 BesTofHit* hit;
208 partId=scint->GetPartId();
209 scinNb=scint->GetScinNb();
210 edep = scint->GetEdep();
211 nHits=scint->GetHitIndexes()->size();
212
213 TofPmtInit();
214
215 //fill tof Ntuple
216 if (m_G4Svc->TofRootFlag())
217 {
218 if (edep>m_edepMPV)
219 {
220 m_partIdMPV = partId;
221 m_scinNbMPV = scinNb;
222 m_edepMPV = edep;
223 }
224 m_eTotal += edep;
225 m_nDigi ++;
226
227 m_partId = partId;
228 m_scinNb = scinNb;
229 m_edep = edep;
230 m_nHits = nHits;
231 }
232
233 if (edep>0.01)
234 {
235 for (G4int j=0;j<nHits;j++)
236 {
237 hit= (*m_THC)[( *(scint->GetHitIndexes()) )[j]];
238 TofPmtAccum(hit);
239 }
240
241 if (m_G4Svc->TofRootFlag())
242 {
243 m_time1st0=m_t1st[0];
244 m_time1st1=m_t1st[1];
245 m_timelast0=m_tLast[0];
246 m_timelast1=m_tLast[1];
247 m_totalPhot0=m_totalPhot[0];
248 m_totalPhot1=m_totalPhot[1];
249 }
250
251 //get final tdc and adc
252 TofPmtRspns(partId,scinNb);
253
254 G4double temp0 = m_ADC[0]+m_TDC[0];
255 G4double temp1 = m_ADC[1]+m_TDC[1];
256 //const double MAX_ADC = 8191*0.3; // channel set up to 8192 will lead to overflow.
257 if ( (partId!=1) && temp0>0. )
258 {
259 BesTofDigi* digi = new BesTofDigi;
261 digi->SetPartId(partId);
262 digi->SetScinNb(scinNb);
263 digi->SetForwADC( m_ADC[0]) ;
264 digi->SetBackADC( m_ADC[1]) ;
265 if (m_TDC[0]>0.)
266 m_TDC[0] = m_TDC[0]+m_beamTime;
267 digi->SetForwTDC( m_TDC[0]) ;
268 digi->SetBackTDC( m_TDC[1]) ;
269
270 //G4cout << "BesTofDigitizerEcV3: ForwTDC | BackTDC " << m_TDC[0] << " | " << m_TDC[1] << G4endl;
271 //G4cout<<"endcap\nadc0:"<<m_ADC[0]<<"; adc1:"<<m_ADC[1]<<"; tdc0:"<<m_TDC[0]<<"; tdc1:"<<m_TDC[1]<<G4endl;
272 m_besTofDigitsCollection->insert(digi);
273 if (m_G4Svc->TofRootFlag() )
274 m_nDigiOut++;
275 }
276 if (m_G4Svc->TofRootFlag() )
277 m_tupleTof1->write();
278 //cout << "m_tupleTof1->write()" << endl;
279 }
280
281 }
282 if (m_G4Svc->TofRootFlag())
283 m_tupleTof2->write();
284 //cout << "m_tupleTof2->write()" << endl;
285
286}
287
289{
290 m_ADC[0] = -999.;
291 m_ADC[1] = -999.;
292 m_TDC[0] = -999.;
293 m_TDC[1] = -999.;
294 m_trackIndex = -999;
295 m_globalTime = 9999;
296
297 m_t1st[0]=100;
298 m_t1st[1]=100;
299 m_tLast[0]=0.;
300 m_tLast[1]=0;
301 m_totalPhot[0]=0;
302 m_totalPhot[1]=0;
303 for (G4int i=0;i<2;i++)
304 for (G4int j=0;j<m_profBinNEcV3;j++)
305 m_nPhot[j][i]=0;
306
307 if (m_G4Svc->TofRootFlag())
308 {
309 m_partId = -9;
310 m_scinNb = -9;
311 m_edep = 0;
312 m_nHits = 0;
313 m_time1st0 = 100;
314 m_time1st1 = 100;
315 m_timelast0 = 0;
316 m_timelast1 = 0;
317 m_totalPhot0 = 0;
318 m_totalPhot1 = 0;
319 m_NphAllSteps = 0;
320 m_max0 = 0;
321 m_max1 = 0;
322 m_tdc0 = -999;
323 m_adc0 = -999;
324 m_tdc1 = -999;
325 m_adc1 = -999;
326 }
327
328}
329
331{
332 G4double cvelScint = c_light/m_refIndexEc;
333 //Get information of this step
334 G4ThreeVector pos = hit->GetPos();
335 G4int trackIndex = hit->GetTrackIndex();
336 G4int partId = hit->GetPartId();
337 G4double edep = hit->GetEdep();
338 G4double stepL = hit->GetStepL();
339 //G4String particleName = hit->GetPName();
340 G4double deltaT=hit->GetDeltaT();
341 G4double timeFlight=hit->GetTime()-m_beamTime;
342 if (timeFlight < m_globalTime)
343 {
344 m_globalTime = timeFlight;
345 m_trackIndex = trackIndex;
346 }
347
348 G4ThreeVector pDirection=hit->GetPDirection();
349 G4double nx=pDirection.x();
350 G4double ny=pDirection.y();
351 G4double nz=pDirection.z();
352
353
354 //number of photons generated in this step
355 G4int NphStep;
356 G4double nMean, nPhoton;
357 nMean = m_phNConstEc*BirksLaw(hit);
358
359 if(nMean>10)
360 {
361 G4double resolutionScale=1.;
362 G4double sigma=resolutionScale*sqrt(nMean);
363 nPhoton=G4int(G4RandGauss::shoot(nMean,sigma)+0.5);
364 }
365 else
366 nPhoton=G4int(G4Poisson(nMean));
367
368
369 NphStep=G4int(nPhoton*0.66*m_QEEc*m_CEEc);
370 //G4cout << "\nradius:" << radius << "; phi:" << phi << "; z:" << z << G4endl;
371 //G4cout << "\nrBin:" << rBin << ";phiBin:" << phiBin << ";zBin" << zBin << G4endl;
372
373 if (m_G4Svc->TofRootFlag())
374 m_NphAllSteps += G4int(nPhoton*0.66*m_QEEc*m_CEEc);
375
376 if (NphStep>0)
377 {
378 for (G4int i=0;i<NphStep;i++)
379 {
380 //uniform scintilation in each step
381 G4double ddS, ddT;
382 ddS=stepL*G4UniformRand();
383 ddT=deltaT*G4UniformRand();
384 G4ThreeVector emtPos;
385 emtPos.setX(pos.x() + nx*ddS);
386 emtPos.setY(pos.y() + ny*ddS);
387 emtPos.setZ(pos.z() + nz*ddS);
388
389 //retrieve the histogram info
390 G4double radius = sqrt(emtPos.x()*emtPos.x()+emtPos.y()*emtPos.y())-m_ecR1;
391 const G4double pie = 2.*asin(1.);
392 G4double phi;
393 if(emtPos.x()>0 && emtPos.y()>0)
394 phi = atan(emtPos.y()/emtPos.x());
395 else if(emtPos.x()==0 && emtPos.y()>0)
396 phi = pie/2.;
397 else if(emtPos.x()<0)
398 phi = atan(emtPos.y()/emtPos.x())+pie;
399 else if(emtPos.x()==0 && emtPos.y()<0)
400 phi = 1.5*pie;
401 else if(emtPos.x()>0 && emtPos.y()<0)
402 phi = 2.*pie+atan(emtPos.y()/emtPos.x());
403 phi = phi*180./pie; // in degrees
404 G4double z = fabs(emtPos.z());
405 // Warning: Should obtain absolute value of z to determine zBinNum
406
407 G4int rBin = G4int(radius/10.); // radius bin no.
408 G4double resPhi = phi-(G4int(phi/7.5)*7.5); // residual of phi in period of 7.5
409 G4int phiBin = G4int(resPhi/1.25);
410 G4int zBin = G4int((z-1332.)/8.);
411
412 //check scinillation light whether to hit the pmt or not
413 //forb=0/1 for forward(z>0, east) and backward(z<0, west)
414 G4int forb = 0;
415 G4double transpTime = 0;
416 G4double pathL = 0;
417 G4double efficiency1;
418 G4double efficiency2;
419 efficiency1 = G4RandGauss::shoot(0,0.004);
420 if(rBin>=0&&rBin<=nR && phiBin>=0&& phiBin<=nPhi && zBin>=0&&zBin<=nZ)
421 efficiency1 += eff[rBin][phiBin][zBin];
422 else
423 efficiency1 = 0;
424 //G4cout << "FATAL: The collection efficiency does NOT exist!" << G4endl;
425 if(m_attenEc==0)
426 {
427 G4cout <<" ERROR: Attenuation Length is null!" << G4endl;
428 break;
429 }
430 //efficiency2 = pow(efficiency1,(1600/m_attenEc));
431 if(G4UniformRand() <= efficiency1)
432 {
433 DirectPh(rBin, phiBin, zBin, transpTime);
434 //cout << "transpTime:" << transpTime << endl;
435 }
436
437 //check if photon can reach PMT or not, after attenuation
438 //G4double ran = G4UniformRand();
439 //pathL = transpTime*cvelScint;
440 //if (pathL>0 && exp(-pathL/m_attenEc) > ran) // Note: Do NOT double count attuation!
441 if(transpTime>0)
442 {
443 //propagation time in scintillator
444 G4double scinSwim = transpTime;
445 //scintillation timing
446 G4double scinTime = Scintillation(partId);
447
448 //PMT transit time
449 G4double transitTime = TransitTime();
450 //sum up all time components
451 G4double endTime = timeFlight + ddT + scinSwim + scinTime + transitTime;
452
453 if (m_G4Svc->TofRootFlag())
454 {
455 //m_forb = forb;
456 m_timeFlight = timeFlight+ddT;
457 m_ddT = ddT;
458 m_scinSwim = scinSwim;
459 m_scinTime = scinTime;
460 m_transitTime = transitTime;
461 m_endTime = endTime;
462 m_tupleTof3->write();
463 }
464
465 //store timing into binned buffer
466 AccuSignal(endTime, forb);
467
468 //update 1st and last timings here
469 if (m_t1st[forb]>endTime) m_t1st[forb] = endTime;
470 if (m_tLast[forb]<endTime) m_tLast[forb]= endTime;
471 //if(m_tLast[0]>100)
472 //std::cout<<"endTime: "<<endTime<<std::endl;
473 }
474 }
475 }
476}
477
479{
480 const G4double kappa = 0.015*cm/MeV;
481 const G4String brMaterial = "BC404";
482 G4double dE = hit->GetEdep();
483 //G4cout << "The edep is "<< dE << G4endl;
484 G4double dX = hit->GetStepL();
485 //G4Material* materiral = hit->GetMaterial();
486 G4double charge = hit->GetCharge();
487 G4double cor_dE = dE;
488 //if((materiral->GetName()==brMaterial) && charge!=0.&& dX!=0.)
489 if(charge!=0.&& dX!=0.)
490 {
491 cor_dE = dE/(1+kappa*dE/dX);
492 //if(dE>20)
493 //{
494 // G4cout << "\n dE > 20. Details are below:" << G4endl;
495 // G4cout << "dE/dx:" << dE/dX << G4endl;
496 // G4cout << "dE:" << dE << "; dX:" << dX << G4endl;
497 // G4cout << "It is BC404. cor_dE is " << cor_dE << G4endl;
498 // G4double ratio = cor_dE/dE;
499 // G4cout << "The ratio cor_dE/edep is "<< ratio << G4endl;
500 //}
501 //G4cout << "It is BC408. cor_dE is " << cor_dE << G4endl;
502 //G4double ratio = cor_dE/dE;
503 //G4cout << "The ratio cor_dE/edep is "<< ratio << G4endl;
504 }
505 return cor_dE;
506
507}
508
509void BesTofDigitizerEcV3::DirectPh(G4int rBin, G4int phiBin, G4int zBin, G4double& t)
510{
511 G4double ran = G4UniformRand();
512 G4double p = 0;
513 G4int nth = 1;
514 G4int key = 0;
515 t = 0;
516 while(1)
517 {
518 if(p>ran||nth==400)
519 {
520 key = nth;
521 //G4cout << "Value found!" << G4endl;
522 break;
523 }
524 p = p + prob[rBin][phiBin][zBin][nth];
525 nth++;
526 }
527 t = propTime[rBin][phiBin][zBin][key-1];
528}
529
531{
532 G4double tmp_tauRatio,tmp_tau1,tmp_tau2,tmp_tau3;
533 tmp_tauRatio = m_tauRatioEc;
534 tmp_tau1 = m_tau1Ec;
535 tmp_tau2 = m_tau2Ec;
536 tmp_tau3 = m_tau3Ec;
537
538 G4double UniformR = tmp_tauRatio/(1+tmp_tauRatio);
539 G4double EmissionTime;
540 if (G4UniformRand()>UniformR) {
541 while (1) {
542 EmissionTime = -tmp_tau2*log( G4UniformRand() );
543 if (G4UniformRand()-exp(EmissionTime/tmp_tau2-EmissionTime/tmp_tau1)>1.E-8)
544 break;
545 }
546 }
547 else EmissionTime = -tmp_tau3*log( G4UniformRand() );
548 return EmissionTime;
549}
550
552{
553 //get time transit spread
554 //G4cout << "TTS mean:" << m_ttsMeanEc << "; " << m_ttsSigmaEc << G4endl;
555 return G4RandGauss::shoot(m_ttsMeanEc,m_ttsSigmaEc);
556}
557
558void BesTofDigitizerEcV3::AccuSignal(G4double endTime, G4int forb)
559{
560 G4int ihst;
561 ihst=G4int(endTime/m_timeBinSize);
562 if (ihst>0 &&ihst<m_profBinNEcV3)
563 {
564 m_nPhot[ihst][forb]=m_nPhot[ihst][forb]+1;
565 m_totalPhot[forb]=m_totalPhot[forb]+1;
566 }
567}
568
569void BesTofDigitizerEcV3::TofPmtRspns(G4int partId, G4int scinNb)
570{
571 //to generate PMT signal shape for single photoelectron.
572 //only one time for a job.
573 static G4double snpe[m_snpeBinNEcV3];
574 static G4int istore_snpe=-1;
575
576 //Model: f(t)=Gain*mv_1pe* t**2 * exp-(t/tau)**2/normal-const
577 //normalization const =sqrt(pi)*tau*tau*tau/4.0
578 G4double tau = m_riseTimeEc;
579 G4double norma_const=sqrt(M_PI)*tau*tau*tau/4.0; //in unit of ns**3
580 G4double echarge=1.6e-7; //in unit of PC
581
582 //time profile of pmt signals for Back and Forward PMT.
583 G4double profPmt[m_profBinNEcV3][2];
584
585 G4double t;
586 G4int n1, n2, ii;
587 G4int phtn;
588
589 if (istore_snpe<0)
590 {
591 istore_snpe = 1;
592 for (G4int i=0;i<m_snpeBinNEcV3;i++)
593 {
594 t=(i+1)*m_timeBinSize;
595 snpe[i]=m_CeEc*t*t*exp(- (t/tau) * (t/tau) )/norma_const;
596 }
597 }
598 //for barrel and endcap tof: fb=2 or 1
599 G4int fb=1; // for endcap part
600
601 G4double tmpADC[2] = {0,0};
602
603 for (G4int j=0; j<fb; j++)
604 {
605 if (m_totalPhot[j] > 0)
606 {
607 n1=G4int(m_t1st[j]/m_timeBinSize);
608 n2=G4int(m_tLast[j]/m_timeBinSize);
609
610 for (G4int i=0;i<m_profBinNEcV3;i++)
611 profPmt[i][j]=0.0;
612
613 //generate PMT pulse
615 for (G4int i=n1;i<n2;i++)
616 {
617 phtn=m_nPhot[i][j];
618 if (phtn>0)
619 {
620 G4double Npoisson;
621 while(1) {
622 Npoisson=G4Poisson(10.0);
623 if(Npoisson>0) break;
624 }
625 G4double tmpPMTgain;
626 while(1) {
627 m_PMTgainEc = m_tofSimSvc->EndPMTGain();
628 tmpPMTgain=G4RandGauss::shoot(m_PMTgainEc,m_PMTgainEc/sqrt(Npoisson));
629 //tmpPMTgain = m_PMTgainEc;
630 if(tmpPMTgain>0) break;
631 }
632 tmpADC[j]+=phtn*tmpPMTgain;
633
634 for (G4int ihst=0; ihst<m_snpeBinNEcV3; ihst++)
635 {
636 ii=i+ihst;
637 if (ii<m_profBinNEcV3)
638 profPmt[ii][j] += tmpPMTgain*phtn*snpe[ihst];
639 else
640 break;
641 }
642 }
643 }
644
645 //add preamplifier and noise
646 for (int i=0;i<m_profBinNEcV3;i++)
647 {
648 if (profPmt[i][j]>0)
649 profPmt[i][j] = m_preGainEc*profPmt[i][j]+G4RandGauss::shoot(0,m_noiseSigmaEc);
650 }
651
652 //get pulse height
653 G4double max=0;
654 for (int i=n1;i<m_profBinNEcV3;i++)
655 {
656 if (profPmt[i][j]>max)
657 max=profPmt[i][j];
658 }
659 if (m_G4Svc->TofRootFlag())
660 {
661 if (j==0) m_max0=max;
662 else m_max1=max;
663 }
664
665
666 G4double tmp_HLthresh, tmp_LLthresh, ratio;
667
668// G4int runId = m_RealizationSvc->getRunId();
669// if(runId>=-80000 && runId<=-9484)
670// {
671// // After TOF HV adjustment, PMT Gain of barrel TOF in MC is set to 5.E5
672// // High/Low Threshold for barrel: 500/125 mV
673// tmp_HLthresh = m_HLthreshEc;
674// tmp_LLthresh = m_LLthreshEc;
675// }
676// else
677// {
678// // Before TOF HV adjustment, PMT Gain of barrel TOF in MC is set to 2.5E5
679// // High/Low Threshold for barrel: 600/150 mV
680// tmp_HLthresh = 800;
681// tmp_LLthresh = 200;
682// }
683
684 G4double adcFactor = 3.35;
685// double ratio;
686// if (runId>=-80000 && runId<=-9484)
687// {
688// ratio = 1.22*1354.4/1282.1;
689// }
690// else
691// {
692// ratio = 1.77*2028.8/1931.4;
693// }
694
695 tmp_HLthresh = m_tofSimSvc->EndHighThres();
696 tmp_LLthresh = m_tofSimSvc->EndLowThres();
697 ratio = m_tofSimSvc->EndConstant();
698
699 //get final tdc and adc
700 if (max>=tmp_HLthresh)
701 {
702 for (int i=0;i<m_profBinNEcV3;i++)
703 {
704 if ( profPmt[i][j] >= tmp_LLthresh )
705 {
706 m_TDC[j] = i*m_timeBinSize + G4RandGauss::shoot(0,0.025); // Adding Electronical Uncertainty of 25ps
707 G4double NoiseSigma;
708 G4int EndNoiseSwitch = int(m_tofSimSvc->EndNoiseSwitch());
709 //std::cout << " EndNoiseSwitch = " << EndNoiseSwitch << std::endl;
710 switch (EndNoiseSwitch) {
711 case 0:
712 NoiseSigma = 0.;
713 break;
714 case 1:
715 if (partId==0) { NoiseSigma = m_tofSimSvc->EndNoiseSmear(scinNb); }
716 if (partId==2) { NoiseSigma = 0.; }
717 break;
718 case 2:
719 if (partId==0) { NoiseSigma = m_tofSimSvc->EndNoiseSmear(scinNb); }
720 if (partId==2) { NoiseSigma = m_tofSimSvc->EndNoiseSmear(scinNb+48.); }
721 break;
722 }
723 //std::cout << "ID : " << scinNb + 48.*partId/2. << " Sigma : " << NoiseSigma << std::endl;
724 m_TDC[j] = m_TDC[j] + G4RandGauss::shoot(0,NoiseSigma); // Adding Endcap Noise Smear
725
726 //use the saturation curve
727
728 if( m_G4Svc->TofSaturationFlag())
729 {
730 double x = tmpADC[j]*m_preGainEc*echarge*ratio;
731 int id;
732 if (partId==0) { id = scinNb;}
733 if (partId==2) { id = scinNb+48;}
734
735 m_ADC[j] = m_tofQElecSvc->EQChannel(id,x);
736 }
737 else
738 m_ADC[j] = tmpADC[j]*m_preGainEc*echarge*adcFactor;
739
740 if (m_G4Svc->TofRootFlag())
741 {
742 if (j==0) {
743 m_tdc0 = m_TDC[0];
744 m_adc0 = m_ADC[0];
745 }
746 else {
747 m_tdc1 = m_TDC[1];
748 m_adc1 = m_ADC[1];
749 }
750 }
751 break;
752 }
753 }
754 }
755 }
756 }
757}
758
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
Definition: BesTofDigi.hh:79
const int nPhi
const G4int m_snpeBinNEcV3
const int num1
const int nZ
const int nR
const G4int m_profBinNEcV3
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition: BesTofHit.hh:116
TTree * sigma
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
Double_t x[10]
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
int n2
Definition: SD0Tag.cxx:55
int n1
Definition: SD0Tag.cxx:54
#define M_PI
Definition: TConstant.h:4
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition: Taupair.h:42
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 DirectPh(G4int, G4int, G4int, G4double &)
G4double Scintillation(G4int)
void AccuSignal(G4double, G4int)
void TofPmtRspns(G4int, G4int)
virtual void Digitize(ScintSingle *, BesTofDigitsCollection *)
void TofPmtAccum(BesTofHit *)
G4double BirksLaw(BesTofHit *hit)
static NTuple::Item< double > m_partId
static NTuple::Tuple * m_tupleTof3
static NTuple::Item< double > m_tdc1
static NTuple::Item< double > m_max0
static NTuple::Item< double > m_ddT
static NTuple::Item< double > m_scinTime
static NTuple::Item< double > m_eTotal
static NTuple::Item< double > m_NphAllSteps
static NTuple::Item< double > m_timeFlight
static NTuple::Item< double > m_tdc0
static NTuple::Item< double > m_timelast1
static NTuple::Item< double > m_timelast0
ITofQElecSvc * m_tofQElecSvc
static NTuple::Item< double > m_scinSwim
static NTuple::Item< double > m_scinNb
static NTuple::Item< double > m_adc1
static NTuple::Tuple * m_tupleTof2
static NTuple::Item< double > m_edep
static NTuple::Item< double > m_totalPhot0
static NTuple::Item< double > m_endTime
ITofSimSvc * m_tofSimSvc
static NTuple::Item< double > m_scinNbMPV
static NTuple::Item< double > m_transitTime
static NTuple::Item< double > m_nDigi
BesTofDigitsCollection * m_besTofDigitsCollection
static NTuple::Item< double > m_adc0
static NTuple::Item< double > m_nHits
static NTuple::Item< double > m_partIdMPV
static NTuple::Item< double > m_time1st1
static NTuple::Item< double > m_nDigiOut
BesTofHitsCollection * m_THC
static NTuple::Item< double > m_totalPhot1
static NTuple::Tuple * m_tupleTof1
static NTuple::Item< double > m_edepMPV
static NTuple::Item< double > m_max1
static NTuple::Item< double > m_time1st0
static BesTofGeoParameter * GetInstance()
G4double GetDeltaT()
Definition: BesTofHit.hh:75
G4ThreeVector GetPDirection()
Definition: BesTofHit.hh:76
G4double GetStepL()
Definition: BesTofHit.hh:71
G4double GetCharge()
Definition: BesTofHit.hh:80
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
bool TofRootFlag()
Definition: G4Svc.h:126
bool TofSaturationFlag()
Definition: G4Svc.h:130
Definition: IG4Svc.h:31
virtual const double EQChannel(int id, double q)=0
virtual const double EndConstant()=0
virtual const double EndPMTGain()=0
virtual const double EndNoiseSmear(unsigned int id)=0
virtual const double EndNoiseSwitch()=0
virtual const double EndLowThres()=0
virtual const double EndHighThres()=0
G4int GetPartId()
Definition: ScintSingle.hh:44
vector< G4int > * GetHitIndexes()
Definition: ScintSingle.hh:47
G4int GetScinNb()
Definition: ScintSingle.hh:45
G4double GetEdep()
Definition: ScintSingle.hh:46
double y[1000]
float charge
#define ns(x)
Definition: xmltok.c:1504