14#include "G4DigiManager.hh"
15#include "G4RunManager.hh"
16#include "Randomize.hh"
17#include "G4Poisson.hh"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IDataProviderSvc.h"
30#include "G4SystemOfUnits.hh"
31#include "G4PhysicalConstants.hh"
35 m_timeBinSize = 0.005;
44 ISvcLocator* svcLocator = Gaudi::svcLocator();
46 StatusCode sc = svcLocator->service(
"G4Svc", tmpSvc);
49 std::cout <<
" Could not initialize Realization Service in BesTofDigitizerBrV2" << std::endl;
53 m_G4Svc =
dynamic_cast<G4Svc *
>(tmpSvc);
58 StatusCode scReal = svcLocator->service(
"RealizationSvc",tmpReal);
59 if (!scReal.isSuccess())
61 std::cout <<
" Could not initialize Realization Service in BesTofDigitizerEcV3" << std::endl;
76 for(
int m=0;m<
num1;m++)
79 propTime[i][j][k][m] = 0;
88 G4cout <<
"ETofSim: Reading nTuples of is completed." << G4endl;
126 int rBin,phiBin,zBin;
130 float efficiency0,
x[400],
y[400];
133 G4String dataPath = getenv(
"TOFSIMROOT");
136 G4cout<<
"Boss environment is not set!"<<G4endl;
141 G4int runId = m_RealizationSvc->
getRunId();
142 if(runId>=-1000000 && runId<=-9484)
145 sprintf(treePath,
"%s/dat/effTree_1600mm.root",dataPath.c_str());
150 sprintf(treePath,
"%s/dat/effTree_1600mm.root",dataPath.c_str());
153 TFile *
f =
new TFile(treePath,
"read");
154 TTree *
t = (TTree*)
f->Get(
"effTree");
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);
164 for (Int_t i = 0; i <
nR*
nPhi*
nZ; i++){
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];
187 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
189 G4int THCID = digiManager->GetHitsCollectionID(
"BesTofHitsCollection");
205 G4int partId, scinNb, nHits;
235 for (G4int j=0;j<nHits;j++)
257 if ( (partId!=1) && temp0>0. )
303 for (G4int i=0;i<2;i++)
332 G4double cvelScint = c_light/m_refIndexEc;
334 G4ThreeVector pos = hit->
GetPos();
337 G4double edep = hit->
GetEdep();
341 G4double timeFlight=hit->
GetTime()-m_beamTime;
349 G4double nx=pDirection.x();
350 G4double ny=pDirection.y();
351 G4double nz=pDirection.z();
356 G4double nMean, nPhoton;
361 G4double resolutionScale=1.;
362 G4double
sigma=resolutionScale*sqrt(nMean);
363 nPhoton=G4int(G4RandGauss::shoot(nMean,
sigma)+0.5);
366 nPhoton=G4int(G4Poisson(nMean));
369 NphStep=G4int(nPhoton*0.66*m_QEEc*m_CEEc);
378 for (G4int i=0;i<NphStep;i++)
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);
390 G4double radius = sqrt(emtPos.x()*emtPos.x()+emtPos.y()*emtPos.y())-m_ecR1;
391 const G4double pie = 2.*asin(1.);
393 if(emtPos.x()>0 && emtPos.y()>0)
394 phi = atan(emtPos.y()/emtPos.x());
395 else if(emtPos.x()==0 && emtPos.y()>0)
397 else if(emtPos.x()<0)
398 phi = atan(emtPos.y()/emtPos.x())+pie;
399 else if(emtPos.x()==0 && emtPos.y()<0)
401 else if(emtPos.x()>0 && emtPos.y()<0)
402 phi = 2.*pie+atan(emtPos.y()/emtPos.x());
404 G4double z = fabs(emtPos.z());
407 G4int rBin = G4int(radius/10.);
408 G4double resPhi = phi-(G4int(phi/7.5)*7.5);
409 G4int phiBin = G4int(resPhi/1.25);
410 G4int zBin = G4int((z-1332.)/8.);
415 G4double transpTime = 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];
427 G4cout <<
" ERROR: Attenuation Length is null!" << G4endl;
431 if(G4UniformRand() <= efficiency1)
433 DirectPh(rBin, phiBin, zBin, transpTime);
444 G4double scinSwim = transpTime;
451 G4double endTime = timeFlight + ddT + scinSwim + scinTime + transitTime;
469 if (m_t1st[forb]>endTime) m_t1st[forb] = endTime;
470 if (m_tLast[forb]<endTime) m_tLast[forb]= endTime;
480 const G4double kappa = 0.015*cm/MeV;
481 const G4String brMaterial =
"BC404";
487 G4double cor_dE = dE;
491 cor_dE = dE/(1+kappa*dE/dX);
511 G4double ran = G4UniformRand();
524 p = p + prob[rBin][phiBin][zBin][nth];
527 t = propTime[rBin][phiBin][zBin][
key-1];
532 G4double tmp_tauRatio,tmp_tau1,tmp_tau2,tmp_tau3;
533 tmp_tauRatio = m_tauRatioEc;
538 G4double UniformR = tmp_tauRatio/(1+tmp_tauRatio);
539 G4double EmissionTime;
540 if (G4UniformRand()>UniformR) {
542 EmissionTime = -tmp_tau2*log( G4UniformRand() );
543 if (G4UniformRand()-
exp(EmissionTime/tmp_tau2-EmissionTime/tmp_tau1)>1.E-8)
547 else EmissionTime = -tmp_tau3*log( G4UniformRand() );
555 return G4RandGauss::shoot(m_ttsMeanEc,m_ttsSigmaEc);
561 ihst=G4int(endTime/m_timeBinSize);
564 m_nPhot[ihst][forb]=m_nPhot[ihst][forb]+1;
565 m_totalPhot[forb]=m_totalPhot[forb]+1;
574 static G4int istore_snpe=-1;
578 G4double tau = m_riseTimeEc;
579 G4double norma_const=sqrt(
M_PI)*tau*tau*tau/4.0;
580 G4double echarge=1.6e-7;
594 t=(i+1)*m_timeBinSize;
595 snpe[i]=m_CeEc*
t*
t*
exp(- (
t/tau) * (
t/tau) )/norma_const;
601 G4double tmpADC[2] = {0,0};
603 for (G4int j=0; j<fb; j++)
605 if (m_totalPhot[j] > 0)
607 n1=G4int(m_t1st[j]/m_timeBinSize);
608 n2=G4int(m_tLast[j]/m_timeBinSize);
615 for (G4int i=
n1;i<
n2;i++)
622 Npoisson=G4Poisson(10.0);
623 if(Npoisson>0)
break;
628 tmpPMTgain=G4RandGauss::shoot(m_PMTgainEc,m_PMTgainEc/sqrt(Npoisson));
630 if(tmpPMTgain>0)
break;
632 tmpADC[j]+=phtn*tmpPMTgain;
638 profPmt[ii][j] += tmpPMTgain*phtn*snpe[ihst];
649 profPmt[i][j] = m_preGainEc*profPmt[i][j]+G4RandGauss::shoot(0,m_noiseSigmaEc);
656 if (profPmt[i][j]>
max)
666 G4double tmp_HLthresh, tmp_LLthresh, ratio;
684 G4double adcFactor = 3.35;
700 if (
max>=tmp_HLthresh)
704 if ( profPmt[i][j] >= tmp_LLthresh )
706 m_TDC[j] = i*m_timeBinSize + G4RandGauss::shoot(0,0.025);
710 switch (EndNoiseSwitch) {
716 if (partId==2) { NoiseSigma = 0.; }
724 m_TDC[j] =
m_TDC[j] + G4RandGauss::shoot(0,NoiseSigma);
730 double x = tmpADC[j]*m_preGainEc*echarge*ratio;
732 if (partId==0) {
id = scinNb;}
733 if (partId==2) {
id = scinNb+48;}
738 m_ADC[j] = tmpADC[j]*m_preGainEc*echarge*adcFactor;
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
const G4int m_snpeBinNEcV3
const G4int m_profBinNEcV3
G4THitsCollection< BesTofHit > BesTofHitsCollection
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")
EvtComplex exp(const EvtComplex &c)
*************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
void SetPartId(G4int partId)
void SetForwADC(G4double ADC)
void SetTrackIndex(G4int index)
void SetBackADC(G4double ADC)
void SetForwTDC(G4double TDC)
void SetScinNb(G4int scinNb)
void SetBackTDC(G4double TDC)
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
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
G4double GetNoiseSigmaEc()
static BesTofGeoParameter * GetInstance()
G4ThreeVector GetPDirection()
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
vector< G4int > * GetHitIndexes()