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"
34 m_timeBinSize = 0.005;
43 ISvcLocator* svcLocator = Gaudi::svcLocator();
45 StatusCode sc = svcLocator->service(
"G4Svc", tmpSvc);
48 std::cout <<
" Could not initialize Realization Service in BesTofDigitizerBrV2" << std::endl;
52 m_G4Svc =
dynamic_cast<G4Svc *
>(tmpSvc);
57 StatusCode scReal = svcLocator->service(
"RealizationSvc",tmpReal);
58 if (!scReal.isSuccess())
60 std::cout <<
" Could not initialize Realization Service in BesTofDigitizerEcV3" << std::endl;
75 for(
int m=0;m<
num1;m++)
78 propTime[i][j][k][m] = 0;
87 G4cout <<
"ETofSim: Reading nTuples of is completed." << G4endl;
125 int rBin,phiBin,zBin;
129 float efficiency0,
x[400],
y[400];
132 G4String dataPath = getenv(
"TOFSIMROOT");
135 G4Exception(
"Boss environment is not set!");
139 G4int runId = m_RealizationSvc->
getRunId();
140 if(runId>=-80000 && runId<=-9484)
143 sprintf(treePath,
"%s/dat/effTree_1600mm.root",dataPath.c_str());
148 sprintf(treePath,
"%s/dat/effTree_1600mm.root",dataPath.c_str());
151 TFile *
f =
new TFile(treePath,
"read");
152 TTree *
t = (TTree*)
f->Get(
"effTree");
154 t->SetBranchAddress(
"rBin", &rBin);
155 t->SetBranchAddress(
"phiBin", &phiBin);
156 t->SetBranchAddress(
"zBin", &zBin);
157 t->SetBranchAddress(
"efficiency0", &efficiency0);
158 t->SetBranchAddress(
"x",
x);
159 t->SetBranchAddress(
"y",
y);
162 for (Int_t i = 0; i <
nR*
nPhi*
nZ; i++){
167 eff[r][phi][z] = efficiency0;
168 for (Int_t j = 0; j < 400; j++){
169 propTime[r][phi][z][j] =
x[j];
170 prob[r][phi][z][j] =
y[j];
185 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
187 G4int THCID = digiManager->GetHitsCollectionID(
"BesTofHitsCollection");
203 G4int partId, scinNb, nHits;
233 for (G4int j=0;j<nHits;j++)
255 if ( (partId!=1) && temp0>0. )
301 for (G4int i=0;i<2;i++)
330 G4double cvelScint = c_light/m_refIndexEc;
332 G4ThreeVector pos = hit->
GetPos();
335 G4double edep = hit->
GetEdep();
339 G4double timeFlight=hit->
GetTime()-m_beamTime;
347 G4double nx=pDirection.x();
348 G4double ny=pDirection.y();
349 G4double nz=pDirection.z();
354 G4double nMean, nPhoton;
359 G4double resolutionScale=1.;
360 G4double
sigma=resolutionScale*sqrt(nMean);
361 nPhoton=G4int(G4RandGauss::shoot(nMean,
sigma)+0.5);
364 nPhoton=G4int(G4Poisson(nMean));
367 NphStep=G4int(nPhoton*0.66*m_QEEc*m_CEEc);
376 for (G4int i=0;i<NphStep;i++)
380 ddS=stepL*G4UniformRand();
381 ddT=deltaT*G4UniformRand();
382 G4ThreeVector emtPos;
383 emtPos.setX(pos.x() + nx*ddS);
384 emtPos.setY(pos.y() + ny*ddS);
385 emtPos.setZ(pos.z() + nz*ddS);
388 G4double radius = sqrt(emtPos.x()*emtPos.x()+emtPos.y()*emtPos.y())-m_ecR1;
389 const G4double pie = 2.*asin(1.);
391 if(emtPos.x()>0 && emtPos.y()>0)
392 phi = atan(emtPos.y()/emtPos.x());
393 else if(emtPos.x()==0 && emtPos.y()>0)
395 else if(emtPos.x()<0)
396 phi = atan(emtPos.y()/emtPos.x())+pie;
397 else if(emtPos.x()==0 && emtPos.y()<0)
399 else if(emtPos.x()>0 && emtPos.y()<0)
400 phi = 2.*pie+atan(emtPos.y()/emtPos.x());
402 G4double z = fabs(emtPos.z());
405 G4int rBin = G4int(radius/10.);
406 G4double resPhi = phi-(G4int(phi/7.5)*7.5);
407 G4int phiBin = G4int(resPhi/1.25);
408 G4int zBin = G4int((z-1332.)/8.);
413 G4double transpTime = 0;
415 G4double efficiency1;
416 G4double efficiency2;
417 efficiency1 = G4RandGauss::shoot(0,0.004);
418 if(rBin>=0&&rBin<=nR && phiBin>=0&& phiBin<=nPhi && zBin>=0&&zBin<=
nZ)
419 efficiency1 += eff[rBin][phiBin][zBin];
425 G4cout <<
" ERROR: Attenuation Length is null!" << G4endl;
429 if(G4UniformRand() <= efficiency1)
431 DirectPh(rBin, phiBin, zBin, transpTime);
442 G4double scinSwim = transpTime;
449 G4double endTime = timeFlight + ddT + scinSwim + scinTime + transitTime;
467 if (m_t1st[forb]>endTime) m_t1st[forb] = endTime;
468 if (m_tLast[forb]<endTime) m_tLast[forb]= endTime;
478 const G4double kappa = 0.015*cm/MeV;
479 const G4String brMaterial =
"BC404";
485 G4double cor_dE = dE;
489 cor_dE = dE/(1+kappa*dE/dX);
509 G4double ran = G4UniformRand();
522 p = p + prob[rBin][phiBin][zBin][nth];
525 t = propTime[rBin][phiBin][zBin][
key-1];
530 G4double tmp_tauRatio,tmp_tau1,tmp_tau2,tmp_tau3;
531 tmp_tauRatio = m_tauRatioEc;
536 G4double UniformR = tmp_tauRatio/(1+tmp_tauRatio);
537 G4double EmissionTime;
538 if (G4UniformRand()>UniformR) {
540 EmissionTime = -tmp_tau2*log( G4UniformRand() );
541 if (G4UniformRand()-
exp(EmissionTime/tmp_tau2-EmissionTime/tmp_tau1)>1.E-8)
545 else EmissionTime = -tmp_tau3*log( G4UniformRand() );
553 return G4RandGauss::shoot(m_ttsMeanEc,m_ttsSigmaEc);
559 ihst=G4int(endTime/m_timeBinSize);
562 m_nPhot[ihst][forb]=m_nPhot[ihst][forb]+1;
563 m_totalPhot[forb]=m_totalPhot[forb]+1;
572 static G4int istore_snpe=-1;
576 G4double tau = m_riseTimeEc;
577 G4double norma_const=sqrt(
M_PI)*tau*tau*tau/4.0;
578 G4double echarge=1.6e-7;
592 t=(i+1)*m_timeBinSize;
593 snpe[i]=m_CeEc*
t*
t*
exp(- (
t/tau) * (
t/tau) )/norma_const;
599 G4double tmpADC[2] = {0,0};
601 for (G4int j=0; j<fb; j++)
603 if (m_totalPhot[j] > 0)
605 n1=G4int(m_t1st[j]/m_timeBinSize);
606 n2=G4int(m_tLast[j]/m_timeBinSize);
613 for (G4int i=
n1;i<
n2;i++)
620 Npoisson=G4Poisson(10.0);
621 if(Npoisson>0)
break;
626 tmpPMTgain=G4RandGauss::shoot(m_PMTgainEc,m_PMTgainEc/sqrt(Npoisson));
628 if(tmpPMTgain>0)
break;
630 tmpADC[j]+=phtn*tmpPMTgain;
636 profPmt[ii][j] += tmpPMTgain*phtn*snpe[ihst];
647 profPmt[i][j] = m_preGainEc*profPmt[i][j]+G4RandGauss::shoot(0,m_noiseSigmaEc);
654 if (profPmt[i][j]>
max)
664 G4double tmp_HLthresh, tmp_LLthresh, ratio;
682 G4double adcFactor = 3.35;
698 if (
max>=tmp_HLthresh)
702 if ( profPmt[i][j] >= tmp_LLthresh )
704 m_TDC[j] = i*m_timeBinSize + G4RandGauss::shoot(0,0.025);
708 switch (EndNoiseSwitch) {
714 if (partId==2) { NoiseSigma = 0.; }
722 m_TDC[j] =
m_TDC[j] + G4RandGauss::shoot(0,NoiseSigma);
728 double x = tmpADC[j]*m_preGainEc*echarge*ratio;
730 if (partId==0) {
id = scinNb;}
731 if (partId==2) {
id = scinNb+48;}
736 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")
*************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
EvtComplex exp(const EvtComplex &c)
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()