112 int rBin, phiBin, zBin;
116 float efficiency0, x[400], y[400];
118 G4String dataPath = getenv(
"TOFSIMROOT" );
121 G4cout <<
"Boss environment is not set!" << G4endl;
126 G4int runId = m_RealizationSvc->getRunId();
127 if ( runId >= -80000 && runId <= -9484 )
130 sprintf( treePath,
"%s/dat/effTree_1600mm.root", dataPath.c_str() );
135 sprintf( treePath,
"%s/dat/effTree_1600mm.root", dataPath.c_str() );
138 TFile*
f =
new TFile( treePath,
"read" );
139 TTree*
t = (TTree*)
f->Get(
"effTree" );
141 t->SetBranchAddress(
"rBin", &rBin );
142 t->SetBranchAddress(
"phiBin", &phiBin );
143 t->SetBranchAddress(
"zBin", &zBin );
144 t->SetBranchAddress(
"efficiency0", &efficiency0 );
145 t->SetBranchAddress(
"x", x );
146 t->SetBranchAddress(
"y", y );
149 for ( Int_t i = 0; i <
nR *
nPhi *
nZ; i++ )
155 eff[r][phi][z] = efficiency0;
156 for ( Int_t j = 0; j < 400; j++ )
158 propTime[r][phi][z][j] = x[j];
159 prob[r][phi][z][j] = y[j];
168 m_beamTime = m_G4Svc->GetBeamTime() *
ns;
171 G4DigiManager* digiManager = G4DigiManager::GetDMpointer();
173 G4int THCID = digiManager->GetHitsCollectionID(
"BesTofHitsCollection" );
176 if ( m_G4Svc->TofRootFlag() )
189 G4int partId, scinNb, nHits;
200 if ( m_G4Svc->TofRootFlag() )
219 for ( G4int j = 0; j < nHits; j++ )
225 if ( m_G4Svc->TofRootFlag() )
241 if ( ( partId != 1 ) && temp0 > 0. )
259 if ( m_G4Svc->TofRootFlag() )
m_tupleTof1->write();
263 if ( m_G4Svc->TofRootFlag() )
m_tupleTof2->write();
309 G4double cvelScint = c_light / m_refIndexEc;
311 G4ThreeVector pos = hit->
GetPos();
314 G4double edep = hit->
GetEdep();
318 G4double timeFlight = hit->
GetTime() - m_beamTime;
326 G4double nx = pDirection.x();
327 G4double ny = pDirection.y();
328 G4double nz = pDirection.z();
332 G4double nMean, nPhoton;
333 nMean = m_phNConstEc *
BirksLaw( hit );
337 G4double resolutionScale = 1.;
338 G4double sigma = resolutionScale * sqrt( nMean );
339 nPhoton = G4int( G4RandGauss::shoot( nMean, sigma ) + 0.5 );
341 else nPhoton = G4int( G4Poisson( nMean ) );
343 NphStep = G4int( nPhoton * 0.66 * m_QEEc * m_CEEc );
347 if ( m_G4Svc->TofRootFlag() )
m_NphAllSteps += G4int( nPhoton * 0.66 * m_QEEc * m_CEEc );
351 for ( G4int i = 0; i < NphStep; i++ )
355 ddS = stepL * G4UniformRand();
356 ddT = deltaT * G4UniformRand();
357 G4ThreeVector emtPos;
358 emtPos.setX( pos.x() + nx * ddS );
359 emtPos.setY( pos.y() + ny * ddS );
360 emtPos.setZ( pos.z() + nz * ddS );
363 G4double radius = sqrt( emtPos.x() * emtPos.x() + emtPos.y() * emtPos.y() ) - m_ecR1;
364 const G4double pie = 2. * asin( 1. );
366 if ( emtPos.x() > 0 && emtPos.y() > 0 ) phi = atan( emtPos.y() / emtPos.x() );
367 else if ( emtPos.x() == 0 && emtPos.y() > 0 ) phi = pie / 2.;
368 else if ( emtPos.x() < 0 ) phi = atan( emtPos.y() / emtPos.x() ) + pie;
369 else if ( emtPos.x() == 0 && emtPos.y() < 0 ) phi = 1.5 * pie;
370 else if ( emtPos.x() > 0 && emtPos.y() < 0 )
371 phi = 2. * pie + atan( emtPos.y() / emtPos.x() );
372 phi = phi * 180. / pie;
373 G4double z = fabs( emtPos.z() );
376 G4int rBin = G4int( radius / 10. );
377 G4double resPhi = phi - ( G4int( phi / 7.5 ) * 7.5 );
378 G4int phiBin = G4int( resPhi / 1.25 );
379 G4int zBin = G4int( ( z - 1332. ) / 8. );
384 G4double transpTime = 0;
386 G4double efficiency1;
387 G4double efficiency2;
388 efficiency1 = G4RandGauss::shoot( 0, 0.004 );
389 if ( rBin >= 0 && rBin <= nR && phiBin >= 0 && phiBin <= nPhi && zBin >= 0 &&
391 efficiency1 += eff[rBin][phiBin][zBin];
392 else efficiency1 = 0;
394 if ( m_attenEc == 0 )
396 G4cout <<
" ERROR: Attenuation Length is null!" << G4endl;
400 if ( G4UniformRand() <= efficiency1 )
402 DirectPh( rBin, phiBin, zBin, transpTime );
410 if ( transpTime > 0 )
413 G4double scinSwim = transpTime;
420 G4double endTime = timeFlight + ddT + scinSwim + scinTime + transitTime;
422 if ( m_G4Svc->TofRootFlag() )
438 if ( m_t1st[forb] > endTime ) m_t1st[forb] = endTime;
439 if ( m_tLast[forb] < endTime ) m_tLast[forb] = endTime;
477 G4double ran = G4UniformRand();
484 if ( p > ran || nth == 400 )
490 p = p + prob[rBin][phiBin][zBin][nth];
493 t = propTime[rBin][phiBin][zBin][
key - 1];
497 G4double tmp_tauRatio, tmp_tau1, tmp_tau2, tmp_tau3;
498 tmp_tauRatio = m_tauRatioEc;
503 G4double UniformR = tmp_tauRatio / ( 1 + tmp_tauRatio );
504 G4double EmissionTime;
505 if ( G4UniformRand() > UniformR )
509 EmissionTime = -tmp_tau2 * log( G4UniformRand() );
510 if ( G4UniformRand() -
exp( EmissionTime / tmp_tau2 - EmissionTime / tmp_tau1 ) > 1.E-8 )
514 else EmissionTime = -tmp_tau3 * log( G4UniformRand() );
538 static G4int istore_snpe = -1;
542 G4double tau = m_riseTimeEc;
543 G4double norma_const = sqrt(
M_PI ) * tau * tau * tau / 4.0;
544 G4double echarge = 1.6e-7;
553 if ( istore_snpe < 0 )
558 t = ( i + 1 ) * m_timeBinSize;
559 snpe[i] = m_CeEc *
t *
t *
exp( -(
t / tau ) * (
t / tau ) ) / norma_const;
565 G4double tmpADC[2] = { 0, 0 };
567 for ( G4int j = 0; j < fb; j++ )
569 if ( m_totalPhot[j] > 0 )
571 n1 = G4int( m_t1st[j] / m_timeBinSize );
572 n2 = G4int( m_tLast[j] / m_timeBinSize );
578 for ( G4int i =
n1; i <
n2; i++ )
580 phtn = m_nPhot[i][j];
586 Npoisson = G4Poisson( 10.0 );
587 if ( Npoisson > 0 )
break;
593 tmpPMTgain = G4RandGauss::shoot( m_PMTgainEc, m_PMTgainEc / sqrt( Npoisson ) );
595 if ( tmpPMTgain > 0 )
break;
597 tmpADC[j] += phtn * tmpPMTgain;
602 if ( ii <
m_profBinNEcV3 ) profPmt[ii][j] += tmpPMTgain * phtn * snpe[ihst];
611 if ( profPmt[i][j] > 0 )
613 m_preGainEc * profPmt[i][j] + G4RandGauss::shoot( 0, m_noiseSigmaEc );
620 if ( profPmt[i][j] >
max )
max = profPmt[i][j];
622 if ( m_G4Svc->TofRootFlag() )
628 G4double tmp_HLthresh, tmp_LLthresh, ratio;
646 G4double adcFactor = 3.35;
662 if (
max >= tmp_HLthresh )
666 if ( profPmt[i][j] >= tmp_LLthresh )
670 G4RandGauss::shoot( 0, 0.025 );
671 G4double NoiseSigma = 0;
672 G4int EndNoiseSwitch = int(
m_tofSimSvc->EndNoiseSwitch() );
674 switch ( EndNoiseSwitch )
676 case 0: NoiseSigma = 0.;
break;
678 if ( partId == 0 ) { NoiseSigma =
m_tofSimSvc->EndNoiseSmear( scinNb ); }
679 if ( partId == 2 ) { NoiseSigma = 0.; }
682 if ( partId == 0 ) { NoiseSigma =
m_tofSimSvc->EndNoiseSmear( scinNb ); }
683 if ( partId == 2 ) { NoiseSigma =
m_tofSimSvc->EndNoiseSmear( scinNb + 48. ); }
689 m_TDC[j] + G4RandGauss::shoot( 0, NoiseSigma );
693 if ( m_G4Svc->TofSaturationFlag() )
695 double x = tmpADC[j] * m_preGainEc * echarge * ratio;
697 if ( partId == 0 ) {
id = scinNb; }
698 if ( partId == 2 ) {
id = scinNb + 48; }
702 else m_ADC[j] = tmpADC[j] * m_preGainEc * echarge * adcFactor;
704 if ( m_G4Svc->TofRootFlag() )