ATLAS Offline Software
Loading...
Searching...
No Matches
FastCaloSim Class Reference

#include <FastCaloSim.h>

Inheritance diagram for FastCaloSim:
Collaboration diagram for FastCaloSim:

Public Member Functions

 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)
 ~FastCaloSim ()
G4bool IsApplicable (const G4ParticleDefinition &) override final
void DoIt (const G4FastTrack &, G4FastStep &) override final
G4bool ModelTrigger (const G4FastTrack &) override final
 Determines the applicability of the fast sim model to this particular track.
CaloCellContainerSDgetCaloCellContainerSD ()
 Retrieves the associated sensitive detector responsible for writing out the CaloCellContainer.
G4bool passedIDCaloBoundary (const G4FastTrack &fastTrack)
 Check if the particle is located at the proper ID-Calo parametrization boundary and is travelling outwards from the ID to the CALO.

Private Attributes

PublicToolHandle< IFastCaloSimCaloTransportationm_FastCaloSimCaloTransportation
PublicToolHandle< IFastCaloSimCaloExtrapolationm_FastCaloSimCaloExtrapolation
PublicToolHandle< IG4CaloTransportToolm_G4CaloTransportTool
PublicToolHandle< IPunchThroughSimWrapperm_PunchThroughSimWrapper
ServiceHandle< ISF::IFastCaloSimParamSvcm_FastCaloSimSvc
std::string m_CaloCellContainerSDName
bool m_doG4Transport
bool m_doPunchThrough

Detailed Description

Definition at line 31 of file FastCaloSim.h.

Constructor & Destructor Documentation

◆ FastCaloSim()

FastCaloSim::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 )

Definition at line 33 of file FastCaloSim.cxx.

45: G4VFastSimulationModel(name, region),
46 m_FastCaloSimCaloTransportation(FastCaloSimCaloTransportation),
47 m_FastCaloSimCaloExtrapolation(FastCaloSimCaloExtrapolation),
48 m_G4CaloTransportTool(G4CaloTransportTool),
49 m_PunchThroughSimWrapper(PunchThroughSimWrapper),
50 m_FastCaloSimSvc(FastCaloSimSvc),
51 m_CaloCellContainerSDName(CaloCellContainerSDName),
52 m_doG4Transport(doG4Transport),
53 m_doPunchThrough(doPunchThrough)
54{
55}
std::string m_CaloCellContainerSDName
Definition FastCaloSim.h:75
PublicToolHandle< IFastCaloSimCaloExtrapolation > m_FastCaloSimCaloExtrapolation
Definition FastCaloSim.h:66
PublicToolHandle< IG4CaloTransportTool > m_G4CaloTransportTool
Definition FastCaloSim.h:68
bool m_doG4Transport
Definition FastCaloSim.h:77
ServiceHandle< ISF::IFastCaloSimParamSvc > m_FastCaloSimSvc
Definition FastCaloSim.h:73
bool m_doPunchThrough
Definition FastCaloSim.h:80
PublicToolHandle< IFastCaloSimCaloTransportation > m_FastCaloSimCaloTransportation
Definition FastCaloSim.h:64
PublicToolHandle< IPunchThroughSimWrapper > m_PunchThroughSimWrapper
Definition FastCaloSim.h:70

◆ ~FastCaloSim()

FastCaloSim::~FastCaloSim ( )
inline

Definition at line 46 of file FastCaloSim.h.

46{}

Member Function Documentation

◆ DoIt()

void FastCaloSim::DoIt ( const G4FastTrack & fastTrack,
G4FastStep & fastStep )
finaloverride

Definition at line 162 of file FastCaloSim.cxx.

163{
164
165 TFCSSimulationState simState(G4Random::getTheEngine());
166 TFCSTruthState truthState;
167 TFCSExtrapolationState extrapolState;
168
169 // Get Geant4 primary track
170 const G4Track * G4PrimaryTrack = fastTrack.GetPrimaryTrack();
171 // Get Geant4 particle definition
172 const G4ParticleDefinition * G4Particle = G4PrimaryTrack -> GetDefinition();
173 // Get Geant4 particle pdgID
174 signed int pdgID = G4Particle -> GetPDGEncoding();
175
176 // Do not simulate particles below 10 MeV
177 if(G4PrimaryTrack -> GetKineticEnergy() < 10){
178 #ifdef FCS_DEBUG
179 G4cout<<"[FastCaloSim::DoIt] Skipping particle with Ekin: " << G4PrimaryTrack -> GetKineticEnergy() <<" MeV. Below the 10 MeV threshold"<<G4endl;
180 #endif
181 fastStep.KillPrimaryTrack();
182 return;
183 }
184 // Decide on which FastCaloSim parametrization to use (electron, photon or pion)
185 if(G4Particle == G4Electron::Definition() || G4Particle == G4Positron::Definition() || G4Particle == G4Gamma::Definition())
186 {
187 // Use egamma parametrization for simulation of electrons and photons
188 truthState.set_pdgid(pdgID);
189 }
190 else{
191 // Use pion parametrization for simulation of all hadrons
192 truthState.set_pdgid(G4PionPlus::Definition() -> GetPDGEncoding());
193 }
194
195 // Set the kinematics of the FastCaloSim truth state
196 truthState.SetPtEtaPhiM(G4PrimaryTrack -> GetMomentum().perp(),
197 G4PrimaryTrack -> GetMomentum().eta(),
198 G4PrimaryTrack -> GetMomentum().phi(),
199 G4Particle -> GetPDGMass());
200
201 // Set the vertex of the FastCaloSim truth state
202 truthState.set_vertex(G4PrimaryTrack -> GetPosition().x(),
203 G4PrimaryTrack -> GetPosition().y(),
204 G4PrimaryTrack -> GetPosition().z());
205
206
207 /* For anti protons and anti-neutrons the kinetic energy should be
208 calculated as Ekin = E() + M() instead of E() - M() this is
209 achieved by setting an Ekin offset of 2*M() to the truth state */
210 if(pdgID == -2212 || pdgID == -2112) truthState.set_Ekin_off(2 * G4Particle -> GetPDGMass());
211
212
213 // Perform particle transportation through calorimeter system eiher with ATLAS tracking tools or with Geant4
214 std::vector<G4FieldTrack> caloSteps = m_doG4Transport ? m_G4CaloTransportTool -> transport(*G4PrimaryTrack)
215 : m_FastCaloSimCaloTransportation -> transport(&truthState, false);
216
217 // Extrapolate transported stepos to ID-Calo boundary and all layers of the calorimeter system
218 m_FastCaloSimCaloExtrapolation->extrapolate(extrapolState, &truthState, caloSteps);
219
220 // Do not simulate further if extrapolation to ID - Calo boundary fails
221 if(extrapolState.IDCaloBoundary_eta() == -999){
222 #ifdef FCS_DEBUG
223 G4cout<<"[FastCaloSim::DoIt] Killing particle as extrapolation failed"<<G4endl;
224 #endif
225 fastStep.KillPrimaryTrack();
226 return;
227 }
228 // Perform the actual FastCaloSim simulation
229 if(m_FastCaloSimSvc->simulate(simState, &truthState, &extrapolState).isFailure()){
230 G4Exception("FastCaloSimSvc", "FailedSimulationCall", FatalException, "FastCaloSimSvc: Simulation call failed.");
231 abort();
232 }
233
234 #ifdef FCS_DEBUG
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;
239 #endif
240
241 // Retrieve the associated CaloCellContainer sensitive detector
242 CaloCellContainerSD * caloCellContainerSD = getCaloCellContainerSD();
243 // Record the cells
244 caloCellContainerSD->recordCells(simState);
245
246 // Do punchthrough here (secondaries), after the main simulation
247 if (m_doPunchThrough){
248 // necessary for determining particle type and properties (mass etc)
249 G4ParticleTable *ptable = G4ParticleTable::GetParticleTable();
250
251 // Get simulated energy
252 const double simE = simState.E();
253
254 // Get energy fraction in layers into vector
255 std::vector<double> simEfrac;
256 for (unsigned int i = 0; i < 24; i++){simEfrac.push_back(simState.Efrac(i));}
257
258 // run actual method (no return, it will do fastStep.CreateSecondaryTrack(...) under the hood)
259 m_PunchThroughSimWrapper->DoPunchThroughSim(*ptable, G4Random::getTheEngine(), simE, std::move(simEfrac), fastTrack, fastStep);
260 }
261
262 // Clean up the auxiliary info from the simulation state
263 simState.DoAuxInfoCleanup();
264
265 // Finally kill the primary track after all simulation steps done
266 fastStep.KillPrimaryTrack();
267 fastStep.ProposePrimaryTrackPathLength(0.0);
268}
Scalar eta() const
pseudorapidity method
Scalar perp() const
perp method - perpendicular length
Scalar phi() const
phi method
#define y
#define x
#define z
void recordCells(TFCSSimulationState &)
CaloCellContainerSD * getCaloCellContainerSD()
Retrieves the associated sensitive detector responsible for writing out the CaloCellContainer.
void set_pdgid(int val)
void set_vertex(const TLorentzVector &val)
void set_Ekin_off(double val)

◆ getCaloCellContainerSD()

CaloCellContainerSD * FastCaloSim::getCaloCellContainerSD ( )

Retrieves the associated sensitive detector responsible for writing out the CaloCellContainer.

Definition at line 270 of file FastCaloSim.cxx.

270 {
271
272 G4SDManager *sdm = G4SDManager::GetSDMpointer();
273 G4VSensitiveDetector * vsd = sdm->FindSensitiveDetector((G4String)m_CaloCellContainerSDName);
274
275 if (!vsd){
276 G4Exception("FastCaloSimSvc", "FailedFindSensitiveDetector", FatalException, "FastCaloSimSvc: Failed getting CaloCellContainer SD.");
277 abort();
278 }
279 // Cast G4VSensitiveDetector to CaloCellContainerSD
280 CaloCellContainerSD * caloCellContainerSD = dynamic_cast<CaloCellContainerSD*>(vsd);
281
282 if (!caloCellContainerSD){
283 G4Exception("FastCaloSimSvc", "FailedCastSensitiveDetector", FatalException, "FastCaloSimSvc: Failed casting G4VSensitiveDetector.");
284 abort();
285 }
286 return caloCellContainerSD;
287}

◆ IsApplicable()

G4bool FastCaloSim::IsApplicable ( const G4ParticleDefinition & particleType)
finaloverride

Definition at line 58 of file FastCaloSim.cxx.

59{
60 // Check whether we can simulate the particle with FastCaloSim
61 bool isPhoton = &particleType == G4Gamma::GammaDefinition();
62 bool isElectron = &particleType == G4Electron::ElectronDefinition();
63 bool isPositron = &particleType == G4Positron::PositronDefinition();
64 bool isHadron = MC::isHadron(particleType.GetPDGEncoding());
65
66 // FastCaloSim is applicable if it is photon, electron, positron or any hadron
67 bool isApplicable = isPhoton || isElectron || isPositron || isHadron;
68
69 #ifdef FCS_DEBUG
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;
74 #endif
75
76
77 return isApplicable;
78}
bool isElectron(const T &p)
Definition AtlasPID.h:202
bool isPhoton(const T &p)
Definition AtlasPID.h:376
bool isHadron(const T &p)
Definition AtlasPID.h:351
bool isHadron(const T &p)

◆ ModelTrigger()

G4bool FastCaloSim::ModelTrigger ( const G4FastTrack & fastTrack)
finaloverride

Determines the applicability of the fast sim model to this particular track.

Checks that geometric location, energy, and particle type are within bounds. Also checks for containment of the particle's shower within a specific detector region.

Definition at line 80 of file FastCaloSim.cxx.

81{
82
83 #ifdef FCS_DEBUG
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"
94 <<G4endl;
95 #endif
96
97
98 // Simulate particles below 50 keV with Geant4 to have same config as ISF implementation
99 if (fastTrack.GetPrimaryTrack() -> GetKineticEnergy() < 0.05) {
100 #ifdef FCS_DEBUG
101 G4cout<<"[FastCaloSim::ModelTrigger] Particle below 50 keV threshold. Passing to G4. "<<G4endl;
102 #endif
103 return false;
104 }
105
106 // Check if triggered particle is really on the ID-Calo (parametrization) boundary
107 if (!passedIDCaloBoundary(fastTrack)) {
108 #ifdef FCS_DEBUG
109 G4cout<<"[FastCaloSim::ModelTrigger] Particle failed passedIDCaloBoundary z="<<fastTrack.GetPrimaryTrack() -> GetPosition().z()<<" r="<<fastTrack.GetPrimaryTrack() -> GetPosition().perp()<<G4endl;
110 #endif
111 return false;
112 }
113
114 // Set minimum kinetic energy of pions and other hadrons required to be passed to FastCaloSim
115 float minEkinPions = 200;
116 float minEkinOtherHadrons = 400;
117
118 // Get particle definition
119 const G4ParticleDefinition * G4Particle = fastTrack.GetPrimaryTrack() -> GetDefinition();
120 // Get particle kinetic energy
121 const float Ekin = fastTrack.GetPrimaryTrack() -> GetKineticEnergy();
122
123 // Check particle type
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();
129
130 // Pass all photons, electrons and positrons to FastCaloSim
131 if (isPhoton || isElectron || isPositron){
132 #ifdef FCS_DEBUG
133 G4cout<<"[FastCaloSim::ModelTrigger] Model triggered"<<G4endl;
134 #endif
135 return true;
136 }
137
138 // Require minimum kinetic energy of pions needed to be passed to FastCaloSim
139 if (isPionPlus || isPionMinus){
140 bool passMinEkinPions = Ekin > minEkinPions;
141
142 #ifdef FCS_DEBUG
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;
145 #endif
146
147 return passMinEkinPions;
148
149 }
150
151 // Require minimum kinetic energy of other hadrons needed to be passed to FastCaloSim
152 bool passMinEkinOtherHadrons = Ekin > minEkinOtherHadrons;
153
154 #ifdef FCS_DEBUG
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;
157 #endif
158
159 return passMinEkinOtherHadrons;
160}
G4bool passedIDCaloBoundary(const G4FastTrack &fastTrack)
Check if the particle is located at the proper ID-Calo parametrization boundary and is travelling out...

◆ passedIDCaloBoundary()

G4bool FastCaloSim::passedIDCaloBoundary ( const G4FastTrack & fastTrack)

Check if the particle is located at the proper ID-Calo parametrization boundary and is travelling outwards from the ID to the CALO.

Definition at line 290 of file FastCaloSim.cxx.

290 {
291
292
293 /* Method checks if particle has crossed the ID-Calo boundary, defined using three cylinders with pairs of r/z values
294 We also perform a directional check to make sure that the particle does not originate from any backscatter from the MS or CALO */
295
296 // NOTE:
297 // For the inner beam pipe section, innerBeamPipeZ = 4185 corresponds to original AFII boundary, while
298 // innerBeamPipeZ = 4587 corresponds to the CALO::CALO boundary which should be used instead as there
299 // is no triggering volume at this point and we will trigger slightly later than the AFII boundary, so
300 // passedIDCaloBoundary would fail and we would simulate this part with Geant4
301
302 // Barrel
303 const float barrelR = 1148;
304 const float barrelZ = 3549.5;
305 // Inner beam pipe section
306 const float innerBeamPipeR = 120;
307 const float innerBeamPipeZ = 4587;
308 // Outer beam pipe section
309 const float outerBeamPipeR = 41;
310 const float outerBeamPipeZ = 6783;
311
312 // Get particle position
313 const G4ThreeVector particlePosition = fastTrack.GetPrimaryTrack() -> GetPosition();
314 // Get r and z values of position
315 const float r = particlePosition.perp();
316 const float z = particlePosition.z();
317 // Get direction of particle
318 const G4ThreeVector particleDirection = fastTrack.GetPrimaryTrack() -> GetMomentum();
319 // Construct the helper line to decide if particle comes from ID or is backscatter from CALO
320 const G4ThreeVector helperLine = particlePosition + particleDirection;
321
322 // Set 5cm trigger tolerance, i.e. the 'width' of the trigger boundary
323 // be careful not to set this too low, else Geant4 might overjump your trigger boundary and simulate everything with G4
324 const float triggerTolerance = 50;
325
326 // Barrel boundary (horizontal surfaces)
327 if (std::abs(z) <= barrelZ + triggerTolerance) {
328 if (r >= barrelR && r < barrelR + triggerTolerance) return helperLine.perp() >= barrelR;
329 }
330 // Beam pipe boundary (horizontal surfaces)
331 if (std::abs(z) >= barrelZ && std::abs(z) <= innerBeamPipeZ + triggerTolerance){
332 if (r >= innerBeamPipeR && r < innerBeamPipeR + triggerTolerance) return helperLine.perp() >= innerBeamPipeR;
333 }
334 if (std::abs(z) >= innerBeamPipeZ && std::abs(z) <= outerBeamPipeZ){
335 if (r >= outerBeamPipeR && r < outerBeamPipeR + triggerTolerance) return helperLine.perp() >= outerBeamPipeR;
336 }
337 // Barrel boundary (vertical surfaces)
338 if (r >= outerBeamPipeR && r<= innerBeamPipeR){
339 if (std::abs(z) >= innerBeamPipeZ && std::abs(z) < innerBeamPipeZ + triggerTolerance) return std::abs(helperLine.z()) >= innerBeamPipeZ;
340 }
341 // Beam pipe boundary (vertical surfaces)
342 if (r >= innerBeamPipeR && r <= barrelR){
343 if (std::abs(z) >= barrelZ && std::abs(z) < barrelZ + triggerTolerance) return std::abs(helperLine.z()) >= barrelZ;
344 }
345
346 return false;
347
348}
int r
Definition globals.cxx:22

Member Data Documentation

◆ m_CaloCellContainerSDName

std::string FastCaloSim::m_CaloCellContainerSDName
private

Definition at line 75 of file FastCaloSim.h.

◆ m_doG4Transport

bool FastCaloSim::m_doG4Transport
private

Definition at line 77 of file FastCaloSim.h.

◆ m_doPunchThrough

bool FastCaloSim::m_doPunchThrough
private

Definition at line 80 of file FastCaloSim.h.

◆ m_FastCaloSimCaloExtrapolation

PublicToolHandle<IFastCaloSimCaloExtrapolation> FastCaloSim::m_FastCaloSimCaloExtrapolation
private

Definition at line 66 of file FastCaloSim.h.

◆ m_FastCaloSimCaloTransportation

PublicToolHandle<IFastCaloSimCaloTransportation> FastCaloSim::m_FastCaloSimCaloTransportation
private

Definition at line 64 of file FastCaloSim.h.

◆ m_FastCaloSimSvc

ServiceHandle<ISF::IFastCaloSimParamSvc> FastCaloSim::m_FastCaloSimSvc
private

Definition at line 73 of file FastCaloSim.h.

◆ m_G4CaloTransportTool

PublicToolHandle<IG4CaloTransportTool> FastCaloSim::m_G4CaloTransportTool
private

Definition at line 68 of file FastCaloSim.h.

◆ m_PunchThroughSimWrapper

PublicToolHandle<IPunchThroughSimWrapper> FastCaloSim::m_PunchThroughSimWrapper
private

Definition at line 70 of file FastCaloSim.h.


The documentation for this class was generated from the following files: