18 #include "G4Electron.hh"
19 #include "G4Positron.hh"
20 #include "G4PionPlus.hh"
21 #include "G4PionMinus.hh"
24 #include "G4ParticleTable.hh"
30 #include "G4SDManager.hh"
38 const std::string& randomEngineName,
44 const std::string& CaloCellContainerSDName,
49 : G4VFastSimulationModel(
name, region),
50 m_rndmGenSvc(rndmGenSvc), m_randomEngineName(randomEngineName),
55 m_FastCaloSimSvc(FastCaloSimSvc),
56 m_CaloCellContainerSDName(CaloCellContainerSDName),
57 m_doG4Transport(doG4Transport),
58 m_doPunchThrough(doPunchThrough),
82 bool isPositron = &
particleType == G4Positron::PositronDefinition();
89 const std::string pName =
particleType.GetParticleName();
90 G4cout<<
"[FastCaloSim::IsApplicable] Got " << pName <<G4endl;
91 if(isApplicable) G4cout<<
"[FastCaloSim::IsApplicable] APPLICABLE"<<G4endl;
92 else G4cout<<
"[FastCaloSim::IsApplicable] NOT APPLICABLE"<<G4endl;
103 G4cout<<
"[FastCaloSim::ModelTrigger] Got particle with " <<
"\n"
104 <<
" pdg=" <<fastTrack.GetPrimaryTrack() -> GetDefinition()->GetPDGEncoding() <<
"\n"
105 <<
" Ekin="<<fastTrack.GetPrimaryTrack() -> GetKineticEnergy() <<
"\n"
106 <<
" p=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().mag() <<
"\n"
107 <<
" x=" <<fastTrack.GetPrimaryTrack() -> GetPosition().x() <<
"\n"
108 <<
" y=" <<fastTrack.GetPrimaryTrack() -> GetPosition().y() <<
"\n"
109 <<
" z=" <<fastTrack.GetPrimaryTrack() -> GetPosition().z() <<
"\n"
110 <<
" r=" <<fastTrack.GetPrimaryTrack() -> GetPosition().perp() <<
"\n"
111 <<
" eta=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().eta() <<
"\n"
112 <<
" phi=" <<fastTrack.GetPrimaryTrack() -> GetMomentum().phi() <<
"\n"
118 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
120 G4cout<<
"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
128 G4cout<<
"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<
" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
134 float minEkinPions = 200;
135 float minEkinOtherHadrons = 400;
138 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
140 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
143 bool isPhoton = G4Particle == G4Gamma::Definition();
144 bool isElectron = G4Particle == G4Electron::Definition();
145 bool isPositron = G4Particle == G4Positron::Definition();
146 bool isPionPlus = G4Particle == G4PionPlus::Definition();
147 bool isPionMinus = G4Particle == G4PionMinus::Definition();
152 G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
158 if (isPionPlus || isPionMinus){
159 bool passMinEkinPions = Ekin > minEkinPions;
162 if(passMinEkinPions) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
163 else G4cout<<
"[FastCaloSim::ModelTrigger] Pion with Ekin="<<Ekin<<
" below the minimum "<<minEkinPions<<
" MeV threshold. Model not triggered."<<G4endl;
166 return passMinEkinPions;
171 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
174 if(passMinEkinOtherHadrons) G4cout<<
"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
175 else G4cout<<
"[FastCaloSim::ModelTrigger] Other hadron with Ekin="<<Ekin<<
" below the minimum "<<minEkinOtherHadrons<<
" MeV threshold. Model not triggered."<<G4endl;
178 return passMinEkinOtherHadrons;
189 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
191 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
193 signed int pdgID = G4Particle -> GetPDGEncoding();
196 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
198 G4cout<<
"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<
" MeV. Below the 10 MeV threshold"<<G4endl;
200 fastStep.KillPrimaryTrack();
204 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
211 truthState.
set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
215 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().
perp(),
216 G4PrimaryTrack -> GetMomentum().
eta(),
217 G4PrimaryTrack -> GetMomentum().
phi(),
218 G4Particle -> GetPDGMass());
221 truthState.
set_vertex(G4PrimaryTrack -> GetPosition().
x(),
222 G4PrimaryTrack -> GetPosition().
y(),
223 G4PrimaryTrack -> GetPosition().
z());
229 if(pdgID == -2212 || pdgID == -2112) truthState.
set_Ekin_off(2 * G4Particle -> GetPDGMass());
242 G4cout<<
"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
244 fastStep.KillPrimaryTrack();
248 if(
m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
249 G4Exception(
"FastCaloSimSvc",
"FailedSimulationCall", FatalException,
"FastCaloSimSvc: Simulation call failed.");
254 G4cout<<
"[FastCaloSim::DoIt] pdgID of G4PrimaryTrack: " << pdgID << G4endl;
255 G4cout<<
"[FastCaloSim::DoIt] Energy returned: " << simState.
E() << G4endl;
256 G4cout<<
"[FastCaloSim::DoIt] Energy fraction for layer: " << G4endl;
257 for (
int s = 0;
s < 24;
s++) G4cout<<
"[FastCaloSim::DoIt] Sampling " <<
s <<
" energy " << simState.
E(
s) << G4endl;
268 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
271 const double simE = simState.
E();
274 std::vector<double> simEfrac;
275 for (
unsigned int i = 0;
i < 24;
i++){simEfrac.push_back(simState.
Efrac(
i));}
285 fastStep.KillPrimaryTrack();
286 fastStep.ProposePrimaryTrackPathLength(0.0);
291 G4SDManager *sdm = G4SDManager::GetSDMpointer();
295 G4Exception(
"FastCaloSimSvc",
"FailedFindSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed getting CaloCellContainer SD.");
301 if (!caloCellContainerSD){
302 G4Exception(
"FastCaloSimSvc",
"FailedCastSensitiveDetector", FatalException,
"FastCaloSimSvc: Failed casting G4VSensitiveDetector.");
305 return caloCellContainerSD;
322 const float barrelR = 1148;
323 const float barrelZ = 3549.5;
325 const float innerBeamPipeR = 120;
326 const float innerBeamPipeZ = 4587;
328 const float outerBeamPipeR = 41;
329 const float outerBeamPipeZ = 6783;
332 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
334 const float r = particlePosition.perp();
335 const float z = particlePosition.z();
337 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
339 const G4ThreeVector helperLine = particlePosition + particleDirection;
343 const float triggerTolerance = 50;
346 if (std::abs(
z) <= barrelZ + triggerTolerance) {
347 if (
r >= barrelR &&
r < barrelR + triggerTolerance)
return helperLine.perp() >= barrelR;
350 if (std::abs(
z) >= barrelZ && std::abs(
z) <= innerBeamPipeZ + triggerTolerance){
351 if (
r >= innerBeamPipeR &&
r < innerBeamPipeR + triggerTolerance)
return helperLine.perp() >= innerBeamPipeR;
353 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) <= outerBeamPipeZ){
354 if (
r >= outerBeamPipeR &&
r < outerBeamPipeR + triggerTolerance)
return helperLine.perp() >= outerBeamPipeR;
357 if (
r >= outerBeamPipeR &&
r<= innerBeamPipeR){
358 if (std::abs(
z) >= innerBeamPipeZ && std::abs(
z) < innerBeamPipeZ + triggerTolerance)
return std::abs(helperLine.z()) >= innerBeamPipeZ;
361 if (
r >= innerBeamPipeR &&
r <= barrelR){
362 if (std::abs(
z) >= barrelZ && std::abs(
z) < barrelZ + triggerTolerance)
return std::abs(helperLine.z()) >= barrelZ;