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),
64 bool isPositron = &
particleType == G4Positron::PositronDefinition();
71 const std::string pName =
particleType.GetParticleName();
72 G4cout<<
"[FastCaloSim::IsApplicable] Got " << pName <<G4endl;
73 if(isApplicable) G4cout<<
"[FastCaloSim::IsApplicable] APPLICABLE"<<G4endl;
74 else G4cout<<
"[FastCaloSim::IsApplicable] NOT APPLICABLE"<<G4endl;
85 G4cout<<
"[FastCaloSim::ModelTrigger] Got particle with " <<
"\n"
86 <<
" pdg=" <<fastTrack.GetPrimaryTrack() -> GetDefinition()->GetPDGEncoding() <<
"\n"
87 <<
" Ekin="<<fastTrack.GetPrimaryTrack() -> GetKineticEnergy() <<
"\n"
88 <<
" p=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().mag() <<
"\n"
89 <<
" x=" <<fastTrack.GetPrimaryTrack() -> GetPosition().x() <<
"\n"
90 <<
" y=" <<fastTrack.GetPrimaryTrack() -> GetPosition().y() <<
"\n"
91 <<
" z=" <<fastTrack.GetPrimaryTrack() -> GetPosition().z() <<
"\n"
92 <<
" r=" <<fastTrack.GetPrimaryTrack() -> GetPosition().perp() <<
"\n"
93 <<
" eta=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().eta() <<
"\n"
94 <<
" phi=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().phi() <<
"\n"
100 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
102 G4cout<<
"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
110 G4cout<<
"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<
" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
116 float minEkinPions = 200;
117 float minEkinOtherHadrons = 400;
120 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
122 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
125 bool isPhoton = G4Particle == G4Gamma::Definition();
126 bool isElectron = G4Particle == G4Electron::Definition();
127 bool isPositron = G4Particle == G4Positron::Definition();
128 bool isPionPlus = G4Particle == G4PionPlus::Definition();
129 bool isPionMinus = G4Particle == G4PionMinus::Definition();
134 G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
140 if (isPionPlus || isPionMinus){
141 bool passMinEkinPions = Ekin > minEkinPions;
144 if(passMinEkinPions) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
145 else G4cout<<
"[FastCaloSim::ModelTrigger] Pion with Ekin="<<Ekin<<
" below the minimum "<<minEkinPions<<
" MeV threshold. Model not triggered."<<G4endl;
148 return passMinEkinPions;
153 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
156 if(passMinEkinOtherHadrons) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
157 else G4cout<<
"[FastCaloSim::ModelTrigger] Other hadron with Ekin="<<Ekin<<
" below the minimum "<<minEkinOtherHadrons<<
" MeV threshold. Model not triggered."<<G4endl;
160 return passMinEkinOtherHadrons;
171 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
173 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
175 signed int pdgID = G4Particle -> GetPDGEncoding();
178 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
180 G4cout<<
"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<
" MeV. Below the 10 MeV threshold"<<G4endl;
182 fastStep.KillPrimaryTrack();
186 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
193 truthState.
set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
197 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().
perp(),
198 G4PrimaryTrack -> GetMomentum().
eta(),
199 G4PrimaryTrack -> GetMomentum().
phi(),
200 G4Particle -> GetPDGMass());
203 truthState.
set_vertex(G4PrimaryTrack -> GetPosition().
x(),
204 G4PrimaryTrack -> GetPosition().
y(),
205 G4PrimaryTrack -> GetPosition().
z());
211 if(pdgID == -2212 || pdgID == -2112) truthState.
set_Ekin_off(2 * G4Particle -> GetPDGMass());
224 G4cout<<
"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
226 fastStep.KillPrimaryTrack();
230 if(
m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
231 G4Exception(
"FastCaloSimSvc",
"FailedSimulationCall", FatalException,
"FastCaloSimSvc: Simulation call failed.");
236 G4cout<<
"[FastCaloSim::DoIt] pdgID of G4PrimaryTrack: " << pdgID << G4endl;
237 G4cout<<
"[FastCaloSim::DoIt] Energy returned: " << simState.
E() << G4endl;
238 G4cout<<
"[FastCaloSim::DoIt] Energy fraction for layer: " << G4endl;
239 for (
int s = 0;
s < 24;
s++) G4cout<<
"[FastCaloSim::DoIt] Sampling " <<
s <<
" energy " << simState.
E(
s) << G4endl;
250 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
253 const double simE = simState.
E();
256 std::vector<double> simEfrac;
257 for (
unsigned int i = 0;
i < 24;
i++){simEfrac.push_back(simState.
Efrac(
i));}
260 m_PunchThroughSimWrapper->DoPunchThroughSim(*ptable, G4Random::getTheEngine(), simE, simEfrac, fastTrack, fastStep);
267 fastStep.KillPrimaryTrack();
268 fastStep.ProposePrimaryTrackPathLength(0.0);
273 G4SDManager *sdm = G4SDManager::GetSDMpointer();
277 G4Exception(
"FastCaloSimSvc",
"FailedFindSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed getting CaloCellContainer SD.");
283 if (!caloCellContainerSD){
284 G4Exception(
"FastCaloSimSvc",
"FailedCastSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed casting G4VSensitiveDetector.");
287 return caloCellContainerSD;
304 const float barrelR = 1148;
305 const float barrelZ = 3549.5;
307 const float innerBeamPipeR = 120;
308 const float innerBeamPipeZ = 4587;
310 const float outerBeamPipeR = 41;
311 const float outerBeamPipeZ = 6783;
314 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
316 const float r = particlePosition.perp();
317 const float z = particlePosition.z();
319 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
321 const G4ThreeVector helperLine = particlePosition + particleDirection;
325 const float triggerTolerance = 50;
328 if (std::abs(
z) <= barrelZ + triggerTolerance) {
329 if (
r >= barrelR &&
r < barrelR + triggerTolerance)
return helperLine.perp() >= barrelR;
332 if (std::abs(
z) >= barrelZ && std::abs(
z) <= innerBeamPipeZ + triggerTolerance){
333 if (
r >= innerBeamPipeR &&
r < innerBeamPipeR + triggerTolerance)
return helperLine.perp() >= innerBeamPipeR;
335 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) <= outerBeamPipeZ){
336 if (
r >= outerBeamPipeR &&
r < outerBeamPipeR + triggerTolerance)
return helperLine.perp() >= outerBeamPipeR;
339 if (
r >= outerBeamPipeR &&
r<= innerBeamPipeR){
340 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) < innerBeamPipeZ + triggerTolerance)
return std::abs(helperLine.z()) >= innerBeamPipeZ;
343 if (
r >= innerBeamPipeR &&
r <= barrelR){
344 if (std::abs(
z) >= barrelZ && std::abs(
z) < barrelZ + triggerTolerance)
return std::abs(helperLine.z()) >= barrelZ;