87 G4cout<<
"[FastCaloSim::ModelTrigger] Got particle with " <<
"\n"
88 <<
" pdg=" <<fastTrack.GetPrimaryTrack() -> GetDefinition()->GetPDGEncoding() <<
"\n"
89 <<
" Ekin="<<fastTrack.GetPrimaryTrack() -> GetKineticEnergy() <<
"\n"
90 <<
" p=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().mag() <<
"\n"
91 <<
" x=" <<fastTrack.GetPrimaryTrack() -> GetPosition().x() <<
"\n"
92 <<
" y=" <<fastTrack.GetPrimaryTrack() -> GetPosition().y() <<
"\n"
93 <<
" z=" <<fastTrack.GetPrimaryTrack() -> GetPosition().z() <<
"\n"
94 <<
" r=" <<fastTrack.GetPrimaryTrack() -> GetPosition().perp() <<
"\n"
95 <<
" eta=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().eta() <<
"\n"
96 <<
" phi=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().phi() <<
"\n"
102 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
104 G4cout<<
"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
112 G4cout<<
"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<
" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
118 float minEkinPions = 200;
119 float minEkinOtherHadrons = 400;
122 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
124 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
127 bool isPhoton = G4Particle == G4Gamma::Definition();
128 bool isElectron = G4Particle == G4Electron::Definition();
129 bool isPositron = G4Particle == G4Positron::Definition();
130 bool isPionPlus = G4Particle == G4PionPlus::Definition();
131 bool isPionMinus = G4Particle == G4PionMinus::Definition();
136 G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
142 if (isPionPlus || isPionMinus){
143 bool passMinEkinPions = Ekin > minEkinPions;
146 if(passMinEkinPions) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
147 else G4cout<<
"[FastCaloSim::ModelTrigger] Pion with Ekin="<<Ekin<<
" below the minimum "<<minEkinPions<<
" MeV threshold. Model not triggered."<<G4endl;
150 return passMinEkinPions;
155 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
158 if(passMinEkinOtherHadrons) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
159 else G4cout<<
"[FastCaloSim::ModelTrigger] Other hadron with Ekin="<<Ekin<<
" below the minimum "<<minEkinOtherHadrons<<
" MeV threshold. Model not triggered."<<G4endl;
162 return passMinEkinOtherHadrons;
168 Gaudi::Hive::setCurrentContext(eventInfo->GetEventContext());
176 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
178 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
180 signed int pdgID = G4Particle -> GetPDGEncoding();
183 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
185 G4cout<<
"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<
" MeV. Below the 10 MeV threshold"<<G4endl;
187 fastStep.KillPrimaryTrack();
191 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
198 truthState.
set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
202 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().
perp(),
203 G4PrimaryTrack -> GetMomentum().
eta(),
204 G4PrimaryTrack -> GetMomentum().
phi(),
205 G4Particle -> GetPDGMass());
208 truthState.
set_vertex(G4PrimaryTrack -> GetPosition().
x(),
209 G4PrimaryTrack -> GetPosition().
y(),
210 G4PrimaryTrack -> GetPosition().
z());
216 if(pdgID == -2212 || pdgID == -2112) truthState.
set_Ekin_off(2 * G4Particle -> GetPDGMass());
229 G4cout<<
"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
231 fastStep.KillPrimaryTrack();
235 if(
m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
236 G4Exception(
"FastCaloSimSvc",
"FailedSimulationCall", FatalException,
"FastCaloSimSvc: Simulation call failed.");
241 G4cout<<
"[FastCaloSim::DoIt] pdgID of G4PrimaryTrack: " << pdgID << G4endl;
242 G4cout<<
"[FastCaloSim::DoIt] Energy returned: " << simState.
E() << G4endl;
243 G4cout<<
"[FastCaloSim::DoIt] Energy fraction for layer: " << G4endl;
244 for (
int s = 0; s < 24; s++) G4cout<<
"[FastCaloSim::DoIt] Sampling " << s <<
" energy " << simState.
E(s) << G4endl;
255 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
258 const double simE = simState.
E();
261 std::vector<double> simEfrac;
262 for (
unsigned int i = 0; i < 24; i++){simEfrac.push_back(simState.
Efrac(i));}
265 m_PunchThroughSimWrapper->DoPunchThroughSim(*ptable, G4Random::getTheEngine(), simE, std::move(simEfrac), fastTrack, fastStep);
272 fastStep.KillPrimaryTrack();
273 fastStep.ProposePrimaryTrackPathLength(0.0);
309 const float barrelR = 1148;
310 const float barrelZ = 3549.5;
312 const float innerBeamPipeR = 120;
313 const float innerBeamPipeZ = 4587;
315 const float outerBeamPipeR = 41;
316 const float outerBeamPipeZ = 6783;
319 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
321 const float r = particlePosition.perp();
322 const float z = particlePosition.z();
324 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
326 const G4ThreeVector helperLine = particlePosition + particleDirection;
330 const float triggerTolerance = 50;
333 if (std::abs(
z) <= barrelZ + triggerTolerance) {
334 if (
r >= barrelR &&
r < barrelR + triggerTolerance)
return helperLine.perp() >= barrelR;
337 if (std::abs(
z) >= barrelZ && std::abs(
z) <= innerBeamPipeZ + triggerTolerance){
338 if (
r >= innerBeamPipeR &&
r < innerBeamPipeR + triggerTolerance)
return helperLine.perp() >= innerBeamPipeR;
340 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) <= outerBeamPipeZ){
341 if (
r >= outerBeamPipeR &&
r < outerBeamPipeR + triggerTolerance)
return helperLine.perp() >= outerBeamPipeR;
344 if (
r >= outerBeamPipeR &&
r<= innerBeamPipeR){
345 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) < innerBeamPipeZ + triggerTolerance)
return std::abs(helperLine.z()) >= innerBeamPipeZ;
348 if (
r >= innerBeamPipeR &&
r <= barrelR){
349 if (std::abs(
z) >= barrelZ && std::abs(
z) < barrelZ + triggerTolerance)
return std::abs(helperLine.z()) >= barrelZ;
FastCaloSim(const std::string &name, G4Region *region, const PublicToolHandle< IFastCaloSimCaloTransportation > &FastCaloSimCaloTransportation, const PublicToolHandle< IFastCaloSimCaloExtrapolation > &FastCaloSimCaloExtrapolation, const PublicToolHandle< IG4CaloTransportTool > &G4CaloTransportTool, const PublicToolHandle< IPunchThroughSimWrapper > &PunchThroughSimWrapper, const ServiceHandle< ISF::IFastCaloSimParamSvc > &FastCaloSimSvc, const std::string &CaloCellContainerSDName, bool doG4Transport, bool doPunchThrough, FastCaloSimTool *FastCaloSimTool)