12#include "BesTofDigitizerEcV2.hh"
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"
32 ISvcLocator* svcLocator = Gaudi::svcLocator();
34 StatusCode sc = svcLocator->service(
"G4Svc", tmpSvc);
35 m_G4Svc =
dynamic_cast<G4Svc *
>(tmpSvc);
78 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
80 G4int THCID = digiManager->GetHitsCollectionID(
"BesTofHitsCollection");
86 G4int partId, scinNb, nHits;
98 for (G4int j=0;j<nHits;j++)
109 if ( (partId==1&&temp0>0&&temp1>0) || ((partId!=1)&&temp0>0) )
141 for (G4int i=0;i<2;i++)
149 G4double cvelScint=c_light/m_refIndexEc;
151 G4ThreeVector pos=hit->
GetPos();
157 G4double timeFlight=hit->
GetTime()-m_beamTime;
165 G4double nx=pDirection.x();
166 G4double ny=pDirection.y();
167 G4double nz=pDirection.z();
174 NphStep=G4int(edep*m_phNConstEc*m_Cpe2pmtEc*0.66*m_QEEc*m_CEEc*m_peCorFacEc);
179 for (G4int i=0;i<NphStep;i++)
182 ddS=stepL*G4UniformRand();
183 ddT=deltaT*G4UniformRand();
184 G4ThreeVector emtPos;
185 emtPos.setX(pos.x() + nx*ddS);
186 emtPos.setY(pos.y() + ny*ddS);
187 emtPos.setZ(pos.z() + nz*ddS);
193 DirectPh(partId, emtPos, pathL, forb);
196 G4double ran=G4UniformRand();
197 if (pathL>0 &&
exp(-pathL/m_attenEc) > ran)
200 G4double scinSwim=pathL/cvelScint;
208 G4double endTime= timeFlight + ddT + scinSwim + scinTime + transitTime;
214 if (m_t1st[forb]>endTime) m_t1st[forb] = endTime;
215 if (m_tLast[forb]<endTime) m_tLast[forb]= endTime;
227 G4double cos_spanEc = 1;
232 G4double dcosEc = cos_spanEc*(ran*2.0-1.0);
233 G4double r2=sqrt(emtPos.x()*emtPos.x()+emtPos.y()*emtPos.y());
234 if (dcosEc > 0.0 && dcosEc != 1)
237 pathL = (r2-m_ecR1)/(1.0-dcosEc);
239 else if (dcosEc < 0 && dcosEc != -1)
242 pathL=(2*838-r2-m_ecR1)/(1.0+dcosEc);
248 G4double tmp_tauRatio,tmp_tau1,tmp_tau2,tmp_tau3;
249 tmp_tauRatio = m_tauRatioEc;
254 G4double UniformR = tmp_tauRatio/(1+tmp_tauRatio);
255 G4double EmissionTime;
256 if (G4UniformRand()>UniformR) {
258 EmissionTime = -tmp_tau2*log( G4UniformRand() );
259 if (G4UniformRand()-
exp(EmissionTime/tmp_tau2-EmissionTime/tmp_tau1)>1.E-8)
263 else EmissionTime = -tmp_tau3*log( G4UniformRand() );
297 return G4RandGauss::shoot(m_ttsMeanEc,m_ttsSigmaEc);
303 ihst=G4int(endTime/m_timeBinSize);
306 m_nPhot[ihst][forb]=m_nPhot[ihst][forb]+1;
307 m_totalPhot[forb]=m_totalPhot[forb]+1;
316 static G4int istore_snpe=-1;
320 G4double tau = m_riseTimeEc;
321 G4double norma_const=sqrt(
M_PI)*tau*tau*tau/4.0;
322 G4double echarge=1.6e-7;
336 t=(i+1)*m_timeBinSize;
337 snpe[i]=m_PMTgainEc*m_CeEc*
t*
t*
exp(- (
t/tau) * (
t/tau) )/norma_const;
343 for (G4int j=0;j<2;j++)
348 for (G4int j=0; j<fb; j++)
350 if (m_totalPhot[j] > 0)
352 n1=G4int(m_t1st[j]/m_timeBinSize);
353 n2=G4int(m_tLast[j]/m_timeBinSize);
360 for (G4int i=
n1;i<
n2;i++)
369 profPmt[ii][j] += phtn*snpe[ihst];
378 profPmt[i][j] = m_preGainEc*profPmt[i][j]+G4RandGauss::shoot(0,m_noiseSigmaEc);
385 if (profPmt[i][j]>max)
389 G4double tmp_HLthresh, tmp_LLthresh;
391 tmp_HLthresh = m_HLthreshEc;
392 tmp_LLthresh = m_LLthreshEc;
395 tmp_HLthresh = m_HLthreshEc;
396 tmp_LLthresh = m_LLthreshEc;
400 if (max>=tmp_HLthresh)
404 if ( profPmt[i][j] >= tmp_LLthresh )
406 m_TDC[j] = i*m_timeBinSize;
407 m_ADC[j] = m_preGainEc*m_totalPhot[j]*echarge*m_PMTgainEc;
EvtComplex exp(const EvtComplex &c)
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
const G4int m_profBinNEcV2
const G4int m_snpeBinNEcV2
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 AccuSignal(G4double, G4int)
G4double Scintillation(G4int)
void DirectPh(G4int, G4ThreeVector, G4double &, G4int &)
virtual void Digitize(ScintSingle *, BesTofDigitsCollection *)
void TofPmtAccum(BesTofHit *)
BesTofHitsCollection * m_THC
BesTofDigitsCollection * m_besTofDigitsCollection
G4double GetNoiseSigmaEc()
static BesTofGeoParameter * GetInstance()
G4ThreeVector GetPDirection()
vector< G4int > * GetHitIndexes()