ATLAS Offline Software
Loading...
Searching...
No Matches
PunchThroughG4Tool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4ATLASTOOLS_PUNCHTHROUGHG4TOOL_H
6#define G4ATLASTOOLS_PUNCHTHROUGHG4TOOL_H
7
8//
12
13//Envelope (Calo-MS boundary)
15//GeoID (From ISF)
17
18// standard C++ libraries
19#include <vector>
20#include <string>
21
22//Geant4
23#include "G4ParticleTable.hh"
24#include "G4Track.hh"
25#include "G4TrackVector.hh"
26#include "G4FastTrack.hh"
27#include "G4FastStep.hh"
28
29class XMLCoreNode;
30
31
39
40class TFile;
43
44class PunchThroughG4Tool : virtual public extends<AthAlgTool, IPunchThroughG4Tool, IPhysicsInitializationTool>
45{
46 public:
47 PunchThroughG4Tool(const std::string&, const std::string&, const IInterface*);
48
49 virtual ~PunchThroughG4Tool () = default;
50
52 virtual StatusCode initialize() override;
54 virtual StatusCode finalize() override;
55
56 StatusCode initializePhysics() override;
57
59 //virtual const G4TrackVector* computePunchThroughParticles(G4ParticleTable &ptable, const G4FastTrack& fastTrack, G4FastStep& fastStep, const TFCSSimulationState& simulstate, CLHEP::HepRandomEngine* rndmEngine);
60 virtual std::vector<std::map<std::string, double>> computePunchThroughParticles(const G4FastTrack& fastTrack, CLHEP::HepRandomEngine* rndmEngine, double punchThroughProbability, double punchThroughClassifierRand) override;
61
63 virtual void createAllSecondaryTracks(G4ParticleTable &ptable, G4FastStep& fastStep, const G4Track& g4PrimaryTrack, std::vector<std::map<std::string, double>> &secKinematicsMapVect, G4TrackVector& secTrackCont, const std::vector<double> &caloMSVars) override;
64
65 /*helpers*/
66 virtual std::vector<double> getCaloMSVars() override;
67
68 private:
69 struct InfoMap
70 {
71 InfoMap (const XMLCoreNode& node);
72
73 std::string name;
74 std::vector<double> etaMins;
75 std::vector<double> etaMaxs;
76 std::vector<int> pidStr;
77 };
78
79 /*---------------------------------------------------------------------
80 * Private member functions
81 *---------------------------------------------------------------------*/
82 // Check initialization order and whether G4ParticleTable is accessible already
83 void checkParticleTable(G4ParticleTable &ptable, int secondarySignedPDG);
84
86 StatusCode registerPunchThroughParticle(G4ParticleTable &ptable,
87 int pdg, bool doAntiparticle = false,
88 double minEnergy = 0.,
89 int maxNumParticles = -1,
90 double numParticlesFactor = 1.,
91 double energyFactor = 1.,
92 double posAngleFactor = 1.,
93 double momAngleFactor = 1.);
94
97
100 StatusCode registerCorrelation(int pdgID1, int pdgID2,double minCorrEnergy = 0., double fullCorrEnergy = 0.);
101
104
106 std::unique_ptr<PunchThroughPDFCreator> readLookuptablePDF(int pdgID, TFile* fileLookupTable, const std::string& folderName);
107
109 //--------------------------------------------------------------------------------
110 // get the calo-MS border coordinates. Look at calo and MS geometry definitions,
111 // if same R and Z -> boundary surface
112 // std::vector<RZPair> returned by m_envDefSvc is std::vector<std::pair<double,double>>
113 // inside: AtlasGeometryCommon/SubDetectorEnvelopes/SubDetectorEnvelopes/IEnvelopeDefSvc.h
114 StatusCode checkCaloMSBoundaries(const std::vector<std::pair<double, double>>* rzMS,
115 const std::vector<std::pair<double, double>>* rzCalo);
116
122 int getAllParticles(const G4Track& g4PrimaryTrack, std::vector<std::map<std::string, double>> &secKinematicsMapVect, CLHEP::HepRandomEngine* rndmEngine, int pdg, double interpEnergy, double interpEta, int numParticles = -1);
123
125 G4ThreeVector punchTroughPosPropagator(double theta, double phi, double R1, double R2, double z1, double z2) const;
127 std::vector<std::map<std::string, double>> checkEnergySumFromSecondaries(double mainEnergyInit, std::vector<std::map<std::string, double>> &secKinematicsMapVect);
129 G4Track* createSecondaryTrack( G4ParticleTable &ptable, G4FastStep& fastStep, double currentTime, int secondarySignedPDG,
130 double energy, double theta, double phi,double momTheta, double momPhi, const std::vector<double> &caloMSVars);
131
135 int getCorrelatedParticles(const G4Track& g4PrimaryTrack, std::vector<std::map<std::string, double>> &secKinematicsMapVect, int pdg, int corrParticles, CLHEP::HepRandomEngine* rndmEngine, double interpEnergy, double interpEta);
136
138 std::map<std::string, double> getOneParticleKinematics(CLHEP::HepRandomEngine* rndmEngine, int secondaryPDG, float initParticleTheta, float initParticlePhi, double interpEnergy, double interpEta) const;
139
141 double getFloatAfterPatternInStr(const char *str, const char *pattern);
142
143 //apply the inverse PCA transform
144 std::vector<double> inversePCA(int pcaCdfIterator, std::vector<double> &variables) const;
145
146 //apply the inverse CDF trainsform
147 static double inverseCdfTransform(double variable, const std::map<double, double> &inverse_cdf_map) ;
148
149 //dot product between matrix and vector, used to inverse PCA
150 static std::vector<double> dotProduct(const std::vector<std::vector<double>> &m, const std::vector<double> &v) ;
151
152 //returns normal cdf based on normal gaussian value
153 static double normal_cdf(double x) ;
154
155 //apply energy interpolation
156 double interpolateEnergy(const double &energy, CLHEP::HepRandomEngine* rndmEngine) const;
157
158 //apply eta interpolation
159 double interpolateEta(const double &eta, CLHEP::HepRandomEngine* rndmEngine) const;
160
161 //get the infoMap from xml file based on the xmlpathname and also name of mainNode
162 std::vector<InfoMap> getInfoMap(const std::string& mainNode, const XMLCoreNode& doc);
163
164 //decide the pca / cdf part to read based on pdgId and eta
165 int passedParamIterator(int pid, double eta, const std::vector<InfoMap> &mapvect) const;
166
167 //load inverse quantile transformer from XML
168 StatusCode initializeInverseCDF(const std::string & quantileTransformerConfigFile);
169
170 //get CDF mapping for individual XML node
171 static std::map<double, double> getVariableCDFmappings(const XMLCoreNode* nodeParent);
172
173 //load inverse PCA from XML
174 StatusCode initializeInversePCA(const std::string & inversePCAConfigFile);
175
176 /*---------------------------------------------------------------------
177 * Private members
178 *---------------------------------------------------------------------*/
180 std::vector<double> m_energyPoints;
181 std::vector<double> m_etaPoints;
182
184 double m_R1{0.};
185 double m_R2{0.};
186 double m_z1{0.};
187 double m_z2{0.};
188
190 TFile* m_fileLookupTable{nullptr};
191
193 std::map<int, PunchThroughParticle*> m_particles;
194
195 /*---------------------------------------------------------------------
196 * Properties
197 *---------------------------------------------------------------------*/
198 StringProperty m_filenameLookupTable{this, "FilenameLookupTable", "CaloPunchThroughParametrisation.root", "holds the filename of the lookup table"};
199 StringProperty m_filenameInverseCDF{this, "FilenameInverseCdf", "", "holds the filename of inverse quantile transformer config"};
200 StringProperty m_filenameInversePCA{this, "FilenameInversePca", "", "holds the filename of inverse PCA config"};
201
202 IntegerArrayProperty m_pdgInitiators{this, "PunchThroughInitiators", {}, "vector of punch-through initiator pgds"};
203 IntegerArrayProperty m_initiatorsMinEnergy{this, "InitiatorsMinEnergy", {}, "vector of punch-through initiator min energies to create punch through"};
204 DoubleArrayProperty m_initiatorsEtaRange{this, "InitiatorsEtaRange", {}, "vector of min and max abs eta range to allow punch through initiators"};
205 IntegerArrayProperty m_punchThroughParticles{this, "PunchThroughParticles", {}, "vector of pdgs of the particles produced in punch-throughs"};
206 BooleanArrayProperty m_doAntiParticles{this, "DoAntiParticles", {}, "vector of bools to determine if anti-particles are created for each punch-through particle type"};
207 IntegerArrayProperty m_correlatedParticle{this, "CorrelatedParticle", {}, "holds the pdg of the correlated particle for each given pdg"};
208 DoubleArrayProperty m_minCorrEnergy{this, "MinCorrelationEnergy", {}, "holds the energy threshold below which no particle correlation is computed"};
209 DoubleArrayProperty m_fullCorrEnergy{this, "FullCorrelationEnergy", {}, "holds the energy threshold above which a particle correlation is fully developed"};
210 DoubleArrayProperty m_posAngleFactor{this, "ScalePosDeflectionAngles", {}, "tuning parameter to scale the position deflection angles"};
211 DoubleArrayProperty m_momAngleFactor{this, "ScaleMomDeflectionAngles", {}, "tuning parameter to scale the momentum deflection angles"};
212 DoubleArrayProperty m_minEnergy{this, "MinEnergy", {}, "punch-through particles minimum energies"};
213 IntegerArrayProperty m_maxNumParticles{this, "MaxNumParticles", {}, "maximum number of punch-through particles for each particle type"};
214 DoubleArrayProperty m_numParticlesFactor{this, "NumParticlesFactor", {}, "scale the number of punch-through particles"};
215 DoubleArrayProperty m_energyFactor{this, "EnergyFactor", {}, "scale the energy of the punch-through particles"};
216
217 /*---------------------------------------------------------------------
218 * ServiceHandles
219 *---------------------------------------------------------------------*/
220 ServiceHandle<ISF::IGeoIDSvc> m_geoIDSvc{this, "GeoIDSvc", "ISF::GeoIDSvc"};
221 ServiceHandle<IEnvelopeDefSvc> m_envDefSvc{this, "EnvelopeDefSvc", "AtlasGeometry_EnvelopeDefSvc"};
222
224 DoubleProperty m_beamPipe{this, "BeamPipeRadius", 500.};
225
227 std::vector<std::vector<std::vector<double>>> m_inverse_PCA_matrix;
228 std::vector<std::vector<double>> m_PCA_means;
229
231 std::vector<InfoMap> m_xml_info_pca;
232 std::vector<InfoMap> m_xml_info_cdf;
233
235 std::vector<std::map<double, double>> m_variable0_inverse_cdf;
236 std::vector<std::map<double, double>> m_variable1_inverse_cdf;
237 std::vector<std::map<double, double>> m_variable2_inverse_cdf;
238 std::vector<std::map<double, double>> m_variable3_inverse_cdf;
239 std::vector<std::map<double, double>> m_variable4_inverse_cdf;
240}; // class PunchThroughG4Tool
241
242
243#endif // G4ATLASTOOLS_PUNCHTHROUGHG4TOOL_H
244
245
246
247
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define x
double getFloatAfterPatternInStr(const char *str, const char *pattern)
get the floating point number in a string, after the given pattern
virtual ~PunchThroughG4Tool()=default
static double normal_cdf(double x)
static std::map< double, double > getVariableCDFmappings(const XMLCoreNode *nodeParent)
virtual StatusCode initialize() override
AlgTool initialize method.
IntegerArrayProperty m_pdgInitiators
DoubleArrayProperty m_minCorrEnergy
static std::vector< double > dotProduct(const std::vector< std::vector< double > > &m, const std::vector< double > &v)
ServiceHandle< IEnvelopeDefSvc > m_envDefSvc
std::vector< InfoMap > m_xml_info_pca
infoMaps
DoubleArrayProperty m_numParticlesFactor
DoubleArrayProperty m_initiatorsEtaRange
StatusCode registerCorrelation(int pdgID1, int pdgID2, double minCorrEnergy=0., double fullCorrEnergy=0.)
register a correlation for the two given types of punch-through particles with a given energy thresho...
std::vector< std::map< double, double > > m_variable2_inverse_cdf
TFile * m_fileLookupTable
ROOT objects.
DoubleArrayProperty m_posAngleFactor
IntegerArrayProperty m_initiatorsMinEnergy
StatusCode initializeRegisterCorrelations()
initialize register all correlations between particles
std::map< int, PunchThroughParticle * > m_particles
needed to initially create punch-through particles with the right distributions
DoubleArrayProperty m_minEnergy
std::vector< std::vector< std::vector< double > > > m_inverse_PCA_matrix
pca vectors
virtual void createAllSecondaryTracks(G4ParticleTable &ptable, G4FastStep &fastStep, const G4Track &g4PrimaryTrack, std::vector< std::map< std::string, double > > &secKinematicsMapVect, G4TrackVector &secTrackCont, const std::vector< double > &caloMSVars) override
create all secondary tracks from kinematics map
static double inverseCdfTransform(double variable, const std::map< double, double > &inverse_cdf_map)
G4Track * createSecondaryTrack(G4ParticleTable &ptable, G4FastStep &fastStep, double currentTime, int secondarySignedPDG, double energy, double theta, double phi, double momTheta, double momPhi, const std::vector< double > &caloMSVars)
create secondary track for each given the kinematics
DoubleArrayProperty m_fullCorrEnergy
std::vector< std::map< std::string, double > > checkEnergySumFromSecondaries(double mainEnergyInit, std::vector< std::map< std::string, double > > &secKinematicsMapVect)
check the energies satisfying energy condition
std::vector< InfoMap > m_xml_info_cdf
std::unique_ptr< PunchThroughPDFCreator > readLookuptablePDF(int pdgID, TFile *fileLookupTable, const std::string &folderName)
reads out the lookuptable for the given type of particle
IntegerArrayProperty m_correlatedParticle
StatusCode initializeInverseCDF(const std::string &quantileTransformerConfigFile)
StatusCode initializeInversePCA(const std::string &inversePCAConfigFile)
void checkParticleTable(G4ParticleTable &ptable, int secondarySignedPDG)
int getCorrelatedParticles(const G4Track &g4PrimaryTrack, std::vector< std::map< std::string, double > > &secKinematicsMapVect, int pdg, int corrParticles, CLHEP::HepRandomEngine *rndmEngine, double interpEnergy, double interpEta)
get the right number of particles for the given pdg while considering the correlation to an other par...
std::vector< std::map< double, double > > m_variable0_inverse_cdf
(vector of map) for CDF mappings
DoubleProperty m_beamPipe
beam pipe radius
std::vector< std::vector< double > > m_PCA_means
int getAllParticles(const G4Track &g4PrimaryTrack, std::vector< std::map< std::string, double > > &secKinematicsMapVect, CLHEP::HepRandomEngine *rndmEngine, int pdg, double interpEnergy, double interpEta, int numParticles=-1)
create the right number of punch-through particles for the given pdg and return the number of particl...
virtual std::vector< double > getCaloMSVars() override
double m_R1
calo-MS borders
StatusCode initializePhysics() override
double interpolateEnergy(const double &energy, CLHEP::HepRandomEngine *rndmEngine) const
StringProperty m_filenameInversePCA
StatusCode checkCaloMSBoundaries(const std::vector< std::pair< double, double > > *rzMS, const std::vector< std::pair< double, double > > *rzCalo)
Check calo-MS boundaries.
IntegerArrayProperty m_maxNumParticles
int passedParamIterator(int pid, double eta, const std::vector< InfoMap > &mapvect) const
ServiceHandle< ISF::IGeoIDSvc > m_geoIDSvc
BooleanArrayProperty m_doAntiParticles
IntegerArrayProperty m_punchThroughParticles
virtual StatusCode finalize() override
AlgTool finalize method.
DoubleArrayProperty m_energyFactor
double interpolateEta(const double &eta, CLHEP::HepRandomEngine *rndmEngine) const
StringProperty m_filenameInverseCDF
std::map< std::string, double > getOneParticleKinematics(CLHEP::HepRandomEngine *rndmEngine, int secondaryPDG, float initParticleTheta, float initParticlePhi, double interpEnergy, double interpEta) const
create exactly one punch-through particle with the given pdg and the given max energy
std::vector< std::map< double, double > > m_variable4_inverse_cdf
StatusCode initializeRegisterPunchThroughParticles()
initialize register all the punch-through particles which will be simulated
virtual std::vector< std::map< std::string, double > > computePunchThroughParticles(const G4FastTrack &fastTrack, CLHEP::HepRandomEngine *rndmEngine, double punchThroughProbability, double punchThroughClassifierRand) override
interface function: fill a vector with the punch-through particles
DoubleArrayProperty m_momAngleFactor
std::vector< InfoMap > getInfoMap(const std::string &mainNode, const XMLCoreNode &doc)
std::vector< double > m_energyPoints
energy and eta points in param
StringProperty m_filenameLookupTable
std::vector< double > inversePCA(int pcaCdfIterator, std::vector< double > &variables) const
std::vector< double > m_etaPoints
PunchThroughG4Tool(const std::string &, const std::string &, const IInterface *)
StatusCode registerPunchThroughParticle(G4ParticleTable &ptable, int pdg, bool doAntiparticle=false, double minEnergy=0., int maxNumParticles=-1, double numParticlesFactor=1., double energyFactor=1., double posAngleFactor=1., double momAngleFactor=1.)
registers a type of punch-through particles which will be simulated
std::vector< std::map< double, double > > m_variable3_inverse_cdf
G4ThreeVector punchTroughPosPropagator(double theta, double phi, double R1, double R2, double z1, double z2) const
get particle through the calorimeter
std::vector< std::map< double, double > > m_variable1_inverse_cdf
Creates random numbers with a distribution given as ROOT TF1.
This class holds information for different properties of a punch-through particle (energy,...
Simple DOM-like node structure to hold the result of XML parsing.
Definition XMLCoreNode.h:45
Definition node.h:24
std::vector< double > etaMins
InfoMap(const XMLCoreNode &node)
std::vector< double > etaMaxs