18 #include "G4Electron.hh"
19 #include "G4Positron.hh"
20 #include "G4PionPlus.hh"
21 #include "G4PionMinus.hh"
27 #include "G4SDManager.hh"
36 const Gaudi::Property<std::string>& randomEngineName,
41 const Gaudi::Property<std::string>& CaloCellContainerSDName,
42 const Gaudi::Property<bool>& doG4Transport,
43 const Gaudi::Property<bool>& doPhotons,
44 const Gaudi::Property<bool>& doElectrons,
45 const Gaudi::Property<bool>& doHadrons,
46 const Gaudi::Property<float>& AbsEtaMin,
47 const Gaudi::Property<float>& AbsEtaMax,
48 const Gaudi::Property<float>& EkinMin,
49 const Gaudi::Property<float>& EkinMax,
50 const Gaudi::Property<bool>& doEMECFCS,
53 : G4VFastSimulationModel(
name),
54 m_rndmGenSvc(rndmGenSvc), m_randomEngineName(randomEngineName),
58 m_FastCaloSimSvc(FastCaloSimSvc),
59 m_CaloCellContainerSDName(CaloCellContainerSDName),
60 m_doG4Transport(doG4Transport),
61 m_doPhotons(doPhotons),
62 m_doElectrons(doElectrons),
63 m_doHadrons(doHadrons),
64 m_AbsEtaMin(AbsEtaMin),
65 m_AbsEtaMax(AbsEtaMax),
68 m_doEMECFCS(doEMECFCS),
94 bool isPositron = &
particleType == G4Positron::PositronDefinition();
101 const std::string pName =
particleType.GetParticleName();
102 G4cout<<
"[FastCaloSim::IsApplicable] Got " << pName <<G4endl;
103 if(isApplicable) G4cout<<
"[FastCaloSim::IsApplicable] APPLICABLE"<<G4endl;
104 else G4cout<<
"[FastCaloSim::IsApplicable] NOT APPLICABLE"<<G4endl;
115 G4cout<<
"[FastCaloSim::ModelTrigger] Got particle with " <<
"\n"
116 <<
" pdg=" <<fastTrack.GetPrimaryTrack() -> GetDefinition()->GetPDGEncoding() <<
"\n"
117 <<
" Ekin="<<fastTrack.GetPrimaryTrack() -> GetKineticEnergy() <<
"\n"
118 <<
" p=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().mag() <<
"\n"
119 <<
" x=" <<fastTrack.GetPrimaryTrack() -> GetPosition().x() <<
"\n"
120 <<
" y=" <<fastTrack.GetPrimaryTrack() -> GetPosition().y() <<
"\n"
121 <<
" z=" <<fastTrack.GetPrimaryTrack() -> GetPosition().z() <<
"\n"
122 <<
" r=" <<fastTrack.GetPrimaryTrack() -> GetPosition().perp() <<
"\n"
123 <<
" eta=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().eta() <<
"\n"
124 <<
" phi=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().phi() <<
"\n"
129 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
131 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
133 const float eta_pos = (fastTrack.GetPrimaryTrack() -> GetPosition()).
eta();
136 bool isPhoton = G4Particle == G4Gamma::Definition();
137 bool isElectron = G4Particle == G4Electron::Definition();
138 bool isPositron = G4Particle == G4Positron::Definition();
139 bool isPionPlus = G4Particle == G4PionPlus::Definition();
140 bool isPionMinus = G4Particle == G4PionMinus::Definition();
147 if (!(withinEtaRange && withinEkinRange)) {
149 G4cout<<
"[FastCaloSim::ModelTrigger] Model not triggered"<<G4endl;
155 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
157 G4cout<<
"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
165 G4cout<<
"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<
" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
171 float minEkinPions = 200;
172 float minEkinOtherHadrons = 400;
177 G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
183 if (isPionPlus || isPionMinus){
184 bool passMinEkinPions = Ekin > minEkinPions;
187 if(passMinEkinPions) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
188 else G4cout<<
"[FastCaloSim::ModelTrigger] Pion with Ekin="<<Ekin<<
" below the minimum "<<minEkinPions<<
" MeV threshold. Model not triggered."<<G4endl;
191 return passMinEkinPions;
196 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
199 if(passMinEkinOtherHadrons) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
200 else G4cout<<
"[FastCaloSim::ModelTrigger] Other hadron with Ekin="<<Ekin<<
" below the minimum "<<minEkinOtherHadrons<<
" MeV threshold. Model not triggered."<<G4endl;
203 return passMinEkinOtherHadrons;
214 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
216 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
218 signed int pdgID = G4Particle -> GetPDGEncoding();
221 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
223 G4cout<<
"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<
" MeV. Below the 10 MeV threshold"<<G4endl;
225 fastStep.KillPrimaryTrack();
229 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
236 truthState.
set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
240 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().
perp(),
241 G4PrimaryTrack -> GetMomentum().
eta(),
242 G4PrimaryTrack -> GetMomentum().
phi(),
243 G4Particle -> GetPDGMass());
246 truthState.
set_vertex(G4PrimaryTrack -> GetPosition().
x(),
247 G4PrimaryTrack -> GetPosition().
y(),
248 G4PrimaryTrack -> GetPosition().
z());
254 if(pdgID == -2212 || pdgID == -2112) truthState.
set_Ekin_off(2 * G4Particle -> GetPDGMass());
269 G4cout<<
"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
271 fastStep.KillPrimaryTrack();
275 if(
m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
276 G4Exception(
"FastCaloSimSvc",
"FailedSimulationCall", FatalException,
"FastCaloSimSvc: Simulation call failed.");
281 G4cout<<
"[FastCaloSim::DoIt] Energy returned: " << simState.
E() << G4endl;
282 G4cout<<
"[FastCaloSim::DoIt] Energy fraction for layer: " << G4endl;
283 for (
int s = 0;
s < 24;
s++) G4cout<<
"[FastCaloSim::DoIt] Sampling " <<
s <<
" energy " << simState.
E(
s) << G4endl;
295 fastStep.KillPrimaryTrack();
296 fastStep.SetPrimaryTrackPathLength(0.0);
302 G4SDManager *sdm = G4SDManager::GetSDMpointer();
306 G4Exception(
"FastCaloSimSvc",
"FailedFindSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed getting CaloCellContainer SD.");
312 if (!caloCellContainerSD){
313 G4Exception(
"FastCaloSimSvc",
"FailedCastSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed casting G4VSensitiveDetector.");
316 return caloCellContainerSD;
333 const float barrelR = 1148;
334 const float barrelZ = 3549.5;
336 const float innerBeamPipeR = 120;
337 const float innerBeamPipeZ = 4587;
339 const float outerBeamPipeR = 41;
340 const float outerBeamPipeZ = 6783;
343 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
345 const float r = particlePosition.perp();
346 const float z = particlePosition.z();
348 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
350 const G4ThreeVector helperLine = particlePosition + particleDirection;
354 const float triggerTolerance = 50;
357 if (std::abs(
z) <= barrelZ + triggerTolerance) {
358 if (
r >= barrelR &&
r < barrelR + triggerTolerance)
return helperLine.perp() >= barrelR;
361 if (std::abs(
z) >= barrelZ && std::abs(
z) <= innerBeamPipeZ + triggerTolerance){
362 if (
r >= innerBeamPipeR &&
r < innerBeamPipeR + triggerTolerance)
return helperLine.perp() >= innerBeamPipeR;
364 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) <= outerBeamPipeZ){
365 if (
r >= outerBeamPipeR &&
r < outerBeamPipeR + triggerTolerance)
return helperLine.perp() >= outerBeamPipeR;
368 if (
r >= outerBeamPipeR &&
r<= innerBeamPipeR){
369 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) < innerBeamPipeZ + triggerTolerance)
return std::abs(helperLine.z()) >= innerBeamPipeZ;
372 if (
r >= innerBeamPipeR &&
r <= barrelR){
373 if (std::abs(
z) >= barrelZ && std::abs(
z) < barrelZ + triggerTolerance)
return std::abs(helperLine.z()) >= barrelZ;