15 #include "G4Electron.hh"
16 #include "G4Positron.hh"
17 #include "G4PionPlus.hh"
18 #include "G4PionMinus.hh"
21 #include "G4ParticleTable.hh"
22 #include "Randomize.hh"
28 #include "G4SDManager.hh"
40 const std::string& CaloCellContainerSDName,
45 : G4VFastSimulationModel(
name, region),
50 m_FastCaloSimSvc(FastCaloSimSvc),
51 m_CaloCellContainerSDName(CaloCellContainerSDName),
52 m_doG4Transport(doG4Transport),
53 m_doPunchThrough(doPunchThrough)
63 bool isPositron = &
particleType == G4Positron::PositronDefinition();
70 const std::string pName =
particleType.GetParticleName();
71 G4cout<<
"[FastCaloSim::IsApplicable] Got " << pName <<G4endl;
72 if(isApplicable) G4cout<<
"[FastCaloSim::IsApplicable] APPLICABLE"<<G4endl;
73 else G4cout<<
"[FastCaloSim::IsApplicable] NOT APPLICABLE"<<G4endl;
84 G4cout<<
"[FastCaloSim::ModelTrigger] Got particle with " <<
"\n"
85 <<
" pdg=" <<fastTrack.GetPrimaryTrack() -> GetDefinition()->GetPDGEncoding() <<
"\n"
86 <<
" Ekin="<<fastTrack.GetPrimaryTrack() -> GetKineticEnergy() <<
"\n"
87 <<
" p=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().mag() <<
"\n"
88 <<
" x=" <<fastTrack.GetPrimaryTrack() -> GetPosition().x() <<
"\n"
89 <<
" y=" <<fastTrack.GetPrimaryTrack() -> GetPosition().y() <<
"\n"
90 <<
" z=" <<fastTrack.GetPrimaryTrack() -> GetPosition().z() <<
"\n"
91 <<
" r=" <<fastTrack.GetPrimaryTrack() -> GetPosition().perp() <<
"\n"
92 <<
" eta=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().eta() <<
"\n"
93 <<
" phi=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().phi() <<
"\n"
99 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
101 G4cout<<
"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
109 G4cout<<
"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<
" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
115 float minEkinPions = 200;
116 float minEkinOtherHadrons = 400;
119 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
121 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
124 bool isPhoton = G4Particle == G4Gamma::Definition();
125 bool isElectron = G4Particle == G4Electron::Definition();
126 bool isPositron = G4Particle == G4Positron::Definition();
127 bool isPionPlus = G4Particle == G4PionPlus::Definition();
128 bool isPionMinus = G4Particle == G4PionMinus::Definition();
133 G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
139 if (isPionPlus || isPionMinus){
140 bool passMinEkinPions = Ekin > minEkinPions;
143 if(passMinEkinPions) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
144 else G4cout<<
"[FastCaloSim::ModelTrigger] Pion with Ekin="<<Ekin<<
" below the minimum "<<minEkinPions<<
" MeV threshold. Model not triggered."<<G4endl;
147 return passMinEkinPions;
152 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
155 if(passMinEkinOtherHadrons) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
156 else G4cout<<
"[FastCaloSim::ModelTrigger] Other hadron with Ekin="<<Ekin<<
" below the minimum "<<minEkinOtherHadrons<<
" MeV threshold. Model not triggered."<<G4endl;
159 return passMinEkinOtherHadrons;
170 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
172 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
174 signed int pdgID = G4Particle -> GetPDGEncoding();
177 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
179 G4cout<<
"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<
" MeV. Below the 10 MeV threshold"<<G4endl;
181 fastStep.KillPrimaryTrack();
185 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
192 truthState.
set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
196 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().
perp(),
197 G4PrimaryTrack -> GetMomentum().
eta(),
198 G4PrimaryTrack -> GetMomentum().
phi(),
199 G4Particle -> GetPDGMass());
202 truthState.
set_vertex(G4PrimaryTrack -> GetPosition().
x(),
203 G4PrimaryTrack -> GetPosition().
y(),
204 G4PrimaryTrack -> GetPosition().
z());
210 if(pdgID == -2212 || pdgID == -2112) truthState.
set_Ekin_off(2 * G4Particle -> GetPDGMass());
223 G4cout<<
"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
225 fastStep.KillPrimaryTrack();
229 if(
m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
230 G4Exception(
"FastCaloSimSvc",
"FailedSimulationCall", FatalException,
"FastCaloSimSvc: Simulation call failed.");
235 G4cout<<
"[FastCaloSim::DoIt] pdgID of G4PrimaryTrack: " << pdgID << G4endl;
236 G4cout<<
"[FastCaloSim::DoIt] Energy returned: " << simState.
E() << G4endl;
237 G4cout<<
"[FastCaloSim::DoIt] Energy fraction for layer: " << G4endl;
238 for (
int s = 0;
s < 24;
s++) G4cout<<
"[FastCaloSim::DoIt] Sampling " <<
s <<
" energy " << simState.
E(
s) << G4endl;
249 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
252 const double simE = simState.
E();
255 std::vector<double> simEfrac;
256 for (
unsigned int i = 0;
i < 24;
i++){simEfrac.push_back(simState.
Efrac(
i));}
259 m_PunchThroughSimWrapper->DoPunchThroughSim(*ptable, G4Random::getTheEngine(), simE, std::move(simEfrac), fastTrack, fastStep);
266 fastStep.KillPrimaryTrack();
267 fastStep.ProposePrimaryTrackPathLength(0.0);
272 G4SDManager *sdm = G4SDManager::GetSDMpointer();
276 G4Exception(
"FastCaloSimSvc",
"FailedFindSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed getting CaloCellContainer SD.");
282 if (!caloCellContainerSD){
283 G4Exception(
"FastCaloSimSvc",
"FailedCastSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed casting G4VSensitiveDetector.");
286 return caloCellContainerSD;
303 const float barrelR = 1148;
304 const float barrelZ = 3549.5;
306 const float innerBeamPipeR = 120;
307 const float innerBeamPipeZ = 4587;
309 const float outerBeamPipeR = 41;
310 const float outerBeamPipeZ = 6783;
313 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
315 const float r = particlePosition.perp();
316 const float z = particlePosition.z();
318 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
320 const G4ThreeVector helperLine = particlePosition + particleDirection;
324 const float triggerTolerance = 50;
327 if (std::abs(
z) <= barrelZ + triggerTolerance) {
328 if (
r >= barrelR &&
r < barrelR + triggerTolerance)
return helperLine.perp() >= barrelR;
331 if (std::abs(
z) >= barrelZ && std::abs(
z) <= innerBeamPipeZ + triggerTolerance){
332 if (
r >= innerBeamPipeR &&
r < innerBeamPipeR + triggerTolerance)
return helperLine.perp() >= innerBeamPipeR;
334 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) <= outerBeamPipeZ){
335 if (
r >= outerBeamPipeR &&
r < outerBeamPipeR + triggerTolerance)
return helperLine.perp() >= outerBeamPipeR;
338 if (
r >= outerBeamPipeR &&
r<= innerBeamPipeR){
339 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) < innerBeamPipeZ + triggerTolerance)
return std::abs(helperLine.z()) >= innerBeamPipeZ;
342 if (
r >= innerBeamPipeR &&
r <= barrelR){
343 if (std::abs(
z) >= barrelZ && std::abs(
z) < barrelZ + triggerTolerance)
return std::abs(helperLine.z()) >= barrelZ;