ATLAS Offline Software
Loading...
Searching...
No Matches
PunchThroughG4Tool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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//libXML
23#include <libxml/xmlmemory.h>
24#include <libxml/parser.h>
25#include <libxml/tree.h>
26#include <libxml/xmlreader.h>
27#include <libxml/xpath.h>
28#include <libxml/xpathInternals.h>
29
30//Geant4
31#include "G4ParticleTable.hh"
32#include "G4Track.hh"
33#include "G4TrackVector.hh"
34#include "G4FastTrack.hh"
35#include "G4FastStep.hh"
36
37
45
46class TFile;
49
50class PunchThroughG4Tool : virtual public extends<AthAlgTool, IPunchThroughG4Tool, IPhysicsInitializationTool>
51{
52 public:
53 PunchThroughG4Tool(const std::string&, const std::string&, const IInterface*);
54
55 virtual ~PunchThroughG4Tool () = default;
56
58 virtual StatusCode initialize() override;
60 virtual StatusCode finalize() override;
61
62 StatusCode initializePhysics() override;
63
65 //virtual const G4TrackVector* computePunchThroughParticles(G4ParticleTable &ptable, const G4FastTrack& fastTrack, G4FastStep& fastStep, const TFCSSimulationState& simulstate, CLHEP::HepRandomEngine* rndmEngine);
66 virtual std::vector<std::map<std::string, double>> computePunchThroughParticles(const G4FastTrack& fastTrack, CLHEP::HepRandomEngine* rndmEngine, double punchThroughProbability, double punchThroughClassifierRand) override;
67
69 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;
70
71 /*helpers*/
72 virtual std::vector<double> getCaloMSVars() override;
73
74 private:
75 /*---------------------------------------------------------------------
76 * Private member functions
77 *---------------------------------------------------------------------*/
78 // Check initialization order and whether G4ParticleTable is accessible already
79 void checkParticleTable(G4ParticleTable &ptable, int secondarySignedPDG);
80
82 StatusCode registerPunchThroughParticle(G4ParticleTable &ptable,
83 int pdg, bool doAntiparticle = false,
84 double minEnergy = 0.,
85 int maxNumParticles = -1,
86 double numParticlesFactor = 1.,
87 double energyFactor = 1.,
88 double posAngleFactor = 1.,
89 double momAngleFactor = 1.);
90
93
96 StatusCode registerCorrelation(int pdgID1, int pdgID2,double minCorrEnergy = 0., double fullCorrEnergy = 0.);
97
100
102 std::unique_ptr<PunchThroughPDFCreator> readLookuptablePDF(int pdgID, TFile* fileLookupTable, const std::string& folderName);
103
105 //--------------------------------------------------------------------------------
106 // get the calo-MS border coordinates. Look at calo and MS geometry definitions,
107 // if same R and Z -> boundary surface
108 // std::vector<RZPair> returned by m_envDefSvc is std::vector<std::pair<double,double>>
109 // inside: AtlasGeometryCommon/SubDetectorEnvelopes/SubDetectorEnvelopes/IEnvelopeDefSvc.h
110 StatusCode checkCaloMSBoundaries(const std::vector<std::pair<double, double>>* rzMS,
111 const std::vector<std::pair<double, double>>* rzCalo);
112
118 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);
119
121 G4ThreeVector punchTroughPosPropagator(double theta, double phi, double R1, double R2, double z1, double z2) const;
123 std::vector<std::map<std::string, double>> checkEnergySumFromSecondaries(double mainEnergyInit, std::vector<std::map<std::string, double>> &secKinematicsMapVect);
125 G4Track* createSecondaryTrack( G4ParticleTable &ptable, G4FastStep& fastStep, double currentTime, int secondarySignedPDG,
126 double energy, double theta, double phi,double momTheta, double momPhi, const std::vector<double> &caloMSVars);
127
131 int getCorrelatedParticles(const G4Track& g4PrimaryTrack, std::vector<std::map<std::string, double>> &secKinematicsMapVect, int pdg, int corrParticles, CLHEP::HepRandomEngine* rndmEngine, double interpEnergy, double interpEta);
132
134 std::map<std::string, double> getOneParticleKinematics(CLHEP::HepRandomEngine* rndmEngine, int secondaryPDG, float initParticleTheta, float initParticlePhi, double interpEnergy, double interpEta) const;
135
137 double getFloatAfterPatternInStr(const char *str, const char *pattern);
138
139 //apply the inverse PCA transform
140 std::vector<double> inversePCA(int pcaCdfIterator, std::vector<double> &variables) const;
141
142 //apply the inverse CDF trainsform
143 static double inverseCdfTransform(double variable, const std::map<double, double> &inverse_cdf_map) ;
144
145 //dot product between matrix and vector, used to inverse PCA
146 static std::vector<double> dotProduct(const std::vector<std::vector<double>> &m, const std::vector<double> &v) ;
147
148 //returns normal cdf based on normal gaussian value
149 static double normal_cdf(double x) ;
150
151 //apply energy interpolation
152 double interpolateEnergy(const double &energy, CLHEP::HepRandomEngine* rndmEngine) const;
153
154 //apply eta interpolation
155 double interpolateEta(const double &eta, CLHEP::HepRandomEngine* rndmEngine) const;
156
157 //get the infoMap from xml file based on the xmlpathname and also name of mainNode
158 std::vector<std::map<std::string,std::string>> getInfoMap(const std::string& mainNode, const std::string &xmlFilePath);
159
160 //decide the pca / cdf part to read based on pdgId and eta
161 int passedParamIterator(int pid, double eta, const std::vector<std::map<std::string,std::string>> &mapvect) const;
162
163 //load inverse quantile transformer from XML
164 StatusCode initializeInverseCDF(const std::string & quantileTransformerConfigFile);
165
166 //get CDF mapping for individual XML node
167 static std::map<double, double> getVariableCDFmappings(xmlNodePtr& nodeParent);
168
169 //load inverse PCA from XML
170 StatusCode initializeInversePCA(const std::string & inversePCAConfigFile);
171
172 /*---------------------------------------------------------------------
173 * Private members
174 *---------------------------------------------------------------------*/
176 std::vector<double> m_energyPoints;
177 std::vector<double> m_etaPoints;
178
180 double m_R1{0.};
181 double m_R2{0.};
182 double m_z1{0.};
183 double m_z2{0.};
184
186 TFile* m_fileLookupTable{nullptr};
187
189 std::map<int, PunchThroughParticle*> m_particles;
190
191 /*---------------------------------------------------------------------
192 * Properties
193 *---------------------------------------------------------------------*/
194 StringProperty m_filenameLookupTable{this, "FilenameLookupTable", "CaloPunchThroughParametrisation.root", "holds the filename of the lookup table"};
195 StringProperty m_filenameInverseCDF{this, "FilenameInverseCdf", "", "holds the filename of inverse quantile transformer config"};
196 StringProperty m_filenameInversePCA{this, "FilenameInversePca", "", "holds the filename of inverse PCA config"};
197
198 IntegerArrayProperty m_pdgInitiators{this, "PunchThroughInitiators", {}, "vector of punch-through initiator pgds"};
199 IntegerArrayProperty m_initiatorsMinEnergy{this, "InitiatorsMinEnergy", {}, "vector of punch-through initiator min energies to create punch through"};
200 DoubleArrayProperty m_initiatorsEtaRange{this, "InitiatorsEtaRange", {}, "vector of min and max abs eta range to allow punch through initiators"};
201 IntegerArrayProperty m_punchThroughParticles{this, "PunchThroughParticles", {}, "vector of pdgs of the particles produced in punch-throughs"};
202 BooleanArrayProperty m_doAntiParticles{this, "DoAntiParticles", {}, "vector of bools to determine if anti-particles are created for each punch-through particle type"};
203 IntegerArrayProperty m_correlatedParticle{this, "CorrelatedParticle", {}, "holds the pdg of the correlated particle for each given pdg"};
204 DoubleArrayProperty m_minCorrEnergy{this, "MinCorrelationEnergy", {}, "holds the energy threshold below which no particle correlation is computed"};
205 DoubleArrayProperty m_fullCorrEnergy{this, "FullCorrelationEnergy", {}, "holds the energy threshold above which a particle correlation is fully developed"};
206 DoubleArrayProperty m_posAngleFactor{this, "ScalePosDeflectionAngles", {}, "tuning parameter to scale the position deflection angles"};
207 DoubleArrayProperty m_momAngleFactor{this, "ScaleMomDeflectionAngles", {}, "tuning parameter to scale the momentum deflection angles"};
208 DoubleArrayProperty m_minEnergy{this, "MinEnergy", {}, "punch-through particles minimum energies"};
209 IntegerArrayProperty m_maxNumParticles{this, "MaxNumParticles", {}, "maximum number of punch-through particles for each particle type"};
210 DoubleArrayProperty m_numParticlesFactor{this, "NumParticlesFactor", {}, "scale the number of punch-through particles"};
211 DoubleArrayProperty m_energyFactor{this, "EnergyFactor", {}, "scale the energy of the punch-through particles"};
212
213 /*---------------------------------------------------------------------
214 * ServiceHandles
215 *---------------------------------------------------------------------*/
216 ServiceHandle<ISF::IGeoIDSvc> m_geoIDSvc{this, "GeoIDSvc", "ISF::GeoIDSvc"};
217 ServiceHandle<IEnvelopeDefSvc> m_envDefSvc{this, "EnvelopeDefSvc", "AtlasGeometry_EnvelopeDefSvc"};
218
220 DoubleProperty m_beamPipe{this, "BeamPipeRadius", 500.};
221
223 std::vector<std::vector<std::vector<double>>> m_inverse_PCA_matrix;
224 std::vector<std::vector<double>> m_PCA_means;
225
227 std::vector<std::map<std::string, std::string>> m_xml_info_pca;
228 std::vector<std::map<std::string, std::string>> m_xml_info_cdf;
229
231 std::vector<std::map<double, double>> m_variable0_inverse_cdf;
232 std::vector<std::map<double, double>> m_variable1_inverse_cdf;
233 std::vector<std::map<double, double>> m_variable2_inverse_cdf;
234 std::vector<std::map<double, double>> m_variable3_inverse_cdf;
235 std::vector<std::map<double, double>> m_variable4_inverse_cdf;
236}; // class PunchThroughG4Tool
237
238
239#endif // G4ATLASTOOLS_PUNCHTHROUGHG4TOOL_H
240
241
242
243
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define x
std::vector< std::map< std::string, std::string > > m_xml_info_cdf
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)
std::vector< std::map< std::string, std::string > > getInfoMap(const std::string &mainNode, const std::string &xmlFilePath)
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
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::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...
static std::map< double, double > getVariableCDFmappings(xmlNodePtr &nodeParent)
int passedParamIterator(int pid, double eta, const std::vector< std::map< std::string, std::string > > &mapvect) const
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
std::vector< std::map< std::string, std::string > > m_xml_info_pca
infoMaps
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< 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,...