ATLAS Offline Software
PunchThroughTool.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 ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHTOOL_H
6 #define ISF_PUNCHTHROUGHTOOLS_SRC_PUNCHTHROUGHTOOL_H 1
7 
9 #include <string>
10 
12 
13 // Athena Base
15 
16 //Geometry
18 
20 
21 // Gaudi & StoreGate
22 #include "GaudiKernel/IPartPropSvc.h"
23 
25 
27 
29 
30 //libXML
31 #include <libxml/xmlmemory.h>
32 #include <libxml/parser.h>
33 #include <libxml/tree.h>
34 #include <libxml/xmlreader.h>
35 #include <libxml/xpath.h>
36 #include <libxml/xpathInternals.h>
37 
38 /*-------------------------------------------------------------------------
39  * Forward declarations
40  *-------------------------------------------------------------------------*/
41 
42 class TFile;
43 
44 namespace HepPDT {
45  class ParticleDataTable;
46 }
47 
48 namespace ISF {
49  class PunchThroughParticle;
50  class PDFcreator;
51 }
52 
53 namespace ISF {
54 
55  class PunchThroughTool : public extends<AthAlgTool, IPunchThroughTool>
56  {
57  public:
59  PunchThroughTool(const std::string&,const std::string&,const IInterface*);
60 
62  virtual ~PunchThroughTool () = default;
63 
65  virtual StatusCode initialize();
67  virtual StatusCode finalize ();
69  const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp, const TFCSSimulationState& simulstate, CLHEP::HepRandomEngine* rndmEngine) const;
70 
71  private:
72  /*---------------------------------------------------------------------
73  * Private member functions
74  *---------------------------------------------------------------------*/
76  StatusCode registerParticle(int pdgID, bool doAntiparticle = false,
77  double minEnergy = 0., int maxNumParticles = -1,
78  double numParticlesFactor = 1., double energyFactor = 1.,
79  double posAngleFactor = 1.,
80  double momAngleFactor = 1.);
83  StatusCode registerCorrelation(int pdgID1, int pdgID2,double minCorrEnergy = 0., double fullCorrEnergy = 0.);
84 
86  std::unique_ptr<ISF::PDFcreator> readLookuptablePDF(int pdgID, const std::string& folderName);
87 
93  int getAllParticles(const ISF::ISFParticle &isfp, ISFParticleVector& isfpCont, CLHEP::HepRandomEngine* rndmEngine, int pdg, double interpEnergy, double interpEta, int numParticles = -1) const;
94 
98  int getCorrelatedParticles(const ISF::ISFParticle &isfp, ISFParticleVector& isfpCont, int doPdg, int corrParticles, CLHEP::HepRandomEngine* rndmEngine, double interpEnergy, double interpEta) const;
99 
101  ISF::ISFParticle *getOneParticle(const ISF::ISFParticle &isfp, int pdg, CLHEP::HepRandomEngine* rndmEngine, double interpEnergy, double interpEta) const;
102 
104  ISF::ISFParticle *createExitPs(const ISF::ISFParticle &isfp, int PDGcode, double energy, double theta, double phi, double momTheta, double momPhi) const;
105 
107  double getFloatAfterPatternInStr(const char *str, const char *pattern);
109  Amg::Vector3D propagator(double theta, double phi) const;
110 
111  //apply the inverse PCA transform
112  std::vector<double> inversePCA(int pcaCdfIterator, std::vector<double> &variables) const;
113 
114  //apply the inverse CDF trainsform
115  static double inverseCdfTransform(double variable, const std::map<double, double>& inverse_cdf_map) ;
116 
117  //dot product between matrix and vector, used to inverse PCA
118  static std::vector<double> dotProduct(const std::vector<std::vector<double>> &m, const std::vector<double> &v) ;
119 
120  //returns normal cdf based on normal gaussian value
121  static double normal_cdf(double x) ;
122 
123  //apply energy interpolation
124  double interpolateEnergy(const double &energy, CLHEP::HepRandomEngine* rndmEngine) const;
125 
126  //apply eta interpolation
127  double interpolateEta(const double &eta, CLHEP::HepRandomEngine* rndmEngine) const;
128 
129  //get the infoMap from xml file based on the xmlpathname and also name of mainNode
130  std::vector<std::map<std::string,std::string>> getInfoMap(const std::string& mainNode, const std::string &xmlFilePath);
131 
132  //decide the pca / cdf part to read based on pdgId and eta
133  int passedParamIterator(int pid, double eta, const std::vector<std::map<std::string,std::string>> &mapvect) const;
134 
135  //load inverse quantile transformer from XML
136  StatusCode initializeInverseCDF(const std::string & quantileTransformerConfigFile);
137 
138  //get CDF mapping for individual XML node
139  static std::map<double, double> getVariableCDFmappings(xmlNodePtr& nodeParent);
140 
141  //load inverse PCA from XML
142  StatusCode initializeInversePCA(const std::string & inversePCAConfigFile);
143 
144 
145  /*---------------------------------------------------------------------
146  * Private members
147  *---------------------------------------------------------------------*/
148 
150  std::vector<double> m_energyPoints;
151  std::vector<double> m_etaPoints;
152 
154  double m_R1{0.};
155  double m_R2{0.};
156  double m_z1{0.};
157  double m_z2{0.};
158 
160  const HepPDT::ParticleDataTable* m_particleDataTable{nullptr};
161 
163  TFile* m_fileLookupTable{nullptr};
164 
166  std::map<int, PunchThroughParticle*> m_particles;
167 
168  /*---------------------------------------------------------------------
169  * Properties
170  *---------------------------------------------------------------------*/
171 
173  StringProperty m_filenameLookupTable{this, "FilenameLookupTable", "CaloPunchThroughParametrisation.root", "holds the filename of the lookup table"};
174  StringProperty m_filenameInverseCDF{this, "FilenameInverseCdf", "", "holds the filename of inverse quantile transformer config"};
175  StringProperty m_filenameInversePCA{this, "FilenameInversePca", "", "holds the filename of inverse PCA config"};
176 
177  PublicToolHandle<IPunchThroughClassifier> m_punchThroughClassifier{this, "PunchThroughClassifier", "ISF_PunchThroughClassifier", ""};
178  IntegerArrayProperty m_pdgInitiators{this, "PunchThroughInitiators", {}, "vector of punch-through initiator pgds"};
179  IntegerArrayProperty m_initiatorsMinEnergy{this, "InitiatorsMinEnergy", {}, "vector of punch-through initiator min energies to create punch through"};
180  DoubleArrayProperty m_initiatorsEtaRange{this, "InitiatorsEtaRange", {}, "vector of min and max abs eta range to allow punch through initiators"};
181  IntegerArrayProperty m_punchThroughParticles{this, "PunchThroughParticles", {}, "vector of pdgs of the particles produced in punch-throughs"};
182  BooleanArrayProperty m_doAntiParticles{this, "DoAntiParticles", {}, "vector of bools to determine if anti-particles are created for each punch-through particle type"};
183  IntegerArrayProperty m_correlatedParticle{this, "CorrelatedParticle", {}, "holds the pdg of the correlated particle for each given pdg"};
184  DoubleArrayProperty m_minCorrEnergy{this, "MinCorrelationEnergy", {}, "holds the energy threshold below which no particle correlation is computed"};
185  DoubleArrayProperty m_fullCorrEnergy{this, "FullCorrelationEnergy", {}, "holds the energy threshold above which a particle correlation is fully developed"};
186  DoubleArrayProperty m_posAngleFactor{this, "ScalePosDeflectionAngles", {}, "tuning parameter to scale the position deflection angles"};
187  DoubleArrayProperty m_momAngleFactor{this, "ScaleMomDeflectionAngles", {}, "tuning parameter to scale the momentum deflection angles"};
188  DoubleArrayProperty m_minEnergy{this, "MinEnergy", {}, "punch-through particles minimum energies"};
189  IntegerArrayProperty m_maxNumParticles{this, "MaxNumParticles", {}, "maximum number of punch-through particles for each particle type"};
190  DoubleArrayProperty m_numParticlesFactor{this, "NumParticlesFactor", {}, "scale the number of punch-through particles"};
191  DoubleArrayProperty m_energyFactor{this, "EnergyFactor", {}, "scale the energy of the punch-through particles"};
192 
193 
194 
195  /*---------------------------------------------------------------------
196  * ServiceHandles
197  *---------------------------------------------------------------------*/
198  ServiceHandle<IPartPropSvc> m_particlePropSvc{this, "PartPropSvc", "PartPropSvc", "particle properties svc"};
199  ServiceHandle<IGeoIDSvc> m_geoIDSvc{this, "GeoIDSvc", "ISF::GeoIDSvc"};
200  ServiceHandle<IEnvelopeDefSvc> m_envDefSvc{this, "EnvelopeDefSvc", "AtlasGeometry_EnvelopeDefSvc"};
201 
203  DoubleProperty m_beamPipe{this, "BeamPipeRadius", 500.};
204 
206  std::vector<std::vector<std::vector<double>>> m_inverse_PCA_matrix;
207  std::vector<std::vector<double>> m_PCA_means;
208 
210  std::vector<std::map<std::string, std::string>> m_xml_info_pca;
211  std::vector<std::map<std::string, std::string>> m_xml_info_cdf;
212 
214  std::vector<std::map<double, double>> m_variable0_inverse_cdf;
215  std::vector<std::map<double, double>> m_variable1_inverse_cdf;
216  std::vector<std::map<double, double>> m_variable2_inverse_cdf;
217  std::vector<std::map<double, double>> m_variable3_inverse_cdf;
218  std::vector<std::map<double, double>> m_variable4_inverse_cdf;
219  };
220 }
221 
222 #endif
IPunchThroughTool.h
ISF::PunchThroughTool::PunchThroughTool
PunchThroughTool(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: PunchThroughTool.cxx:62
ISF::PunchThroughTool::inverseCdfTransform
static double inverseCdfTransform(double variable, const std::map< double, double > &inverse_cdf_map)
Definition: PunchThroughTool.cxx:962
ISF::PunchThroughTool::m_xml_info_cdf
std::vector< std::map< std::string, std::string > > m_xml_info_cdf
Definition: PunchThroughTool.h:211
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
ISF::PunchThroughTool::~PunchThroughTool
virtual ~PunchThroughTool()=default
Destructor.
ISF::PunchThroughTool::getInfoMap
std::vector< std::map< std::string, std::string > > getInfoMap(const std::string &mainNode, const std::string &xmlFilePath)
Definition: PunchThroughTool.cxx:793
ISF::PunchThroughTool::initialize
virtual StatusCode initialize()
AlgTool initialize method.
Definition: PunchThroughTool.cxx:74
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
checkCoolLatestUpdate.variables
variables
Definition: checkCoolLatestUpdate.py:13
ISF::PunchThroughTool::m_energyPoints
std::vector< double > m_energyPoints
energy and eta points in param
Definition: PunchThroughTool.h:150
ISF::PunchThroughTool::m_maxNumParticles
IntegerArrayProperty m_maxNumParticles
Definition: PunchThroughTool.h:189
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
IEnvelopeDefSvc.h
ISF::PunchThroughTool::readLookuptablePDF
std::unique_ptr< ISF::PDFcreator > readLookuptablePDF(int pdgID, const std::string &folderName)
reads out the lookuptable for the given type of particle
Definition: PunchThroughTool.cxx:1242
ISF::PunchThroughTool::m_doAntiParticles
BooleanArrayProperty m_doAntiParticles
Definition: PunchThroughTool.h:182
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
ISF::PunchThroughTool::m_z1
double m_z1
Definition: PunchThroughTool.h:156
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
ISF::PunchThroughTool::finalize
virtual StatusCode finalize()
AlgTool finalize method.
Definition: PunchThroughTool.cxx:271
ISF::PunchThroughTool::registerCorrelation
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...
Definition: PunchThroughTool.cxx:1187
ISF::PunchThroughTool::m_particlePropSvc
ServiceHandle< IPartPropSvc > m_particlePropSvc
Definition: PunchThroughTool.h:198
ISF::ISFParticle
Definition: ISFParticle.h:42
ISF::PunchThroughTool::m_particleDataTable
const HepPDT::ParticleDataTable * m_particleDataTable
ParticleDataTable needed to get connection pdg_code <-> charge.
Definition: PunchThroughTool.h:160
ISF::PunchThroughTool::m_variable1_inverse_cdf
std::vector< std::map< double, double > > m_variable1_inverse_cdf
Definition: PunchThroughTool.h:215
ISF::PunchThroughTool::m_energyFactor
DoubleArrayProperty m_energyFactor
Definition: PunchThroughTool.h:191
ISF::PunchThroughTool::m_momAngleFactor
DoubleArrayProperty m_momAngleFactor
Definition: PunchThroughTool.h:187
ISF::PunchThroughTool::m_punchThroughParticles
IntegerArrayProperty m_punchThroughParticles
Definition: PunchThroughTool.h:181
ISF::PunchThroughTool::m_geoIDSvc
ServiceHandle< IGeoIDSvc > m_geoIDSvc
Definition: PunchThroughTool.h:199
ISF::PunchThroughTool::m_R1
double m_R1
calo-MS borders
Definition: PunchThroughTool.h:154
x
#define x
ISF::PunchThroughTool::interpolateEnergy
double interpolateEnergy(const double &energy, CLHEP::HepRandomEngine *rndmEngine) const
Definition: PunchThroughTool.cxx:977
ISF::PunchThroughTool::m_correlatedParticle
IntegerArrayProperty m_correlatedParticle
Definition: PunchThroughTool.h:183
ISFParticleContainer.h
ISF::PunchThroughTool::m_fileLookupTable
TFile * m_fileLookupTable
ROOT objects.
Definition: PunchThroughTool.h:163
ISF::PunchThroughTool::getOneParticle
ISF::ISFParticle * getOneParticle(const ISF::ISFParticle &isfp, int pdg, CLHEP::HepRandomEngine *rndmEngine, double interpEnergy, double interpEta) const
create exactly one punch-through particle with the given pdg and the given max energy
Definition: PunchThroughTool.cxx:592
ISF::PunchThroughTool::getVariableCDFmappings
static std::map< double, double > getVariableCDFmappings(xmlNodePtr &nodeParent)
Definition: PunchThroughTool.cxx:944
GeoPrimitives.h
ISF::PunchThroughTool::m_PCA_means
std::vector< std::vector< double > > m_PCA_means
Definition: PunchThroughTool.h:207
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ISF::PunchThroughTool::m_variable3_inverse_cdf
std::vector< std::map< double, double > > m_variable3_inverse_cdf
Definition: PunchThroughTool.h:217
ISF::PunchThroughTool::m_R2
double m_R2
Definition: PunchThroughTool.h:155
ISF::PunchThroughTool
Definition: PunchThroughTool.h:56
ISF::PunchThroughTool::m_etaPoints
std::vector< double > m_etaPoints
Definition: PunchThroughTool.h:151
ISF::PunchThroughTool::m_pdgInitiators
IntegerArrayProperty m_pdgInitiators
Definition: PunchThroughTool.h:178
ISF::PunchThroughTool::inversePCA
std::vector< double > inversePCA(int pcaCdfIterator, std::vector< double > &variables) const
Definition: PunchThroughTool.cxx:821
ISF::PunchThroughTool::m_filenameInverseCDF
StringProperty m_filenameInverseCDF
Definition: PunchThroughTool.h:174
AthAlgTool.h
ISF::ISFParticleVector
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition: ISFParticleContainer.h:26
GenEvent_fwd.h
ISF::PunchThroughTool::m_xml_info_pca
std::vector< std::map< std::string, std::string > > m_xml_info_pca
infoMaps
Definition: PunchThroughTool.h:210
ISF::PunchThroughTool::propagator
Amg::Vector3D propagator(double theta, double phi) const
get particle through the calorimeter
Definition: PunchThroughTool.cxx:1376
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
ISF::PunchThroughTool::getCorrelatedParticles
int getCorrelatedParticles(const ISF::ISFParticle &isfp, ISFParticleVector &isfpCont, int doPdg, int corrParticles, CLHEP::HepRandomEngine *rndmEngine, double interpEnergy, double interpEta) const
get the right number of particles for the given pdg while considering the correlation to an other par...
Definition: PunchThroughTool.cxx:518
ISF::PunchThroughTool::m_variable2_inverse_cdf
std::vector< std::map< double, double > > m_variable2_inverse_cdf
Definition: PunchThroughTool.h:216
python.selection.variable
variable
Definition: selection.py:33
IGeoIDSvc.h
HepPDT
Definition: BeamHaloGenerator.h:13
ISF::PunchThroughTool::m_z2
double m_z2
Definition: PunchThroughTool.h:157
ISF::PunchThroughTool::passedParamIterator
int passedParamIterator(int pid, double eta, const std::vector< std::map< std::string, std::string >> &mapvect) const
Definition: PunchThroughTool.cxx:764
ISF::PunchThroughTool::m_filenameInversePCA
StringProperty m_filenameInversePCA
Definition: PunchThroughTool.h:175
ISF::PunchThroughTool::getAllParticles
int getAllParticles(const ISF::ISFParticle &isfp, ISFParticleVector &isfpCont, CLHEP::HepRandomEngine *rndmEngine, int pdg, double interpEnergy, double interpEta, int numParticles=-1) const
create the right number of punch-through particles for the given pdg and return the number of particl...
Definition: PunchThroughTool.cxx:448
CaloCellTimeCorrFiller.folderName
string folderName
Definition: CaloCellTimeCorrFiller.py:20
ISF::PunchThroughTool::initializeInverseCDF
StatusCode initializeInverseCDF(const std::string &quantileTransformerConfigFile)
Definition: PunchThroughTool.cxx:885
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ISF::PunchThroughTool::normal_cdf
static double normal_cdf(double x)
Definition: PunchThroughTool.cxx:724
ISF::PunchThroughTool::createExitPs
ISF::ISFParticle * createExitPs(const ISF::ISFParticle &isfp, int PDGcode, double energy, double theta, double phi, double momTheta, double momPhi) const
create a ISF Particle state at the MS entrace containing a particle with the given properties
Definition: PunchThroughTool.cxx:1318
ISF::PunchThroughTool::m_punchThroughClassifier
PublicToolHandle< IPunchThroughClassifier > m_punchThroughClassifier
Definition: PunchThroughTool.h:177
python.PyAthena.v
v
Definition: PyAthena.py:157
ISF::PunchThroughTool::initializeInversePCA
StatusCode initializeInversePCA(const std::string &inversePCAConfigFile)
Definition: PunchThroughTool.cxx:830
ISF::PunchThroughTool::computePunchThroughParticles
const ISF::ISFParticleVector * computePunchThroughParticles(const ISF::ISFParticle &isfp, const TFCSSimulationState &simulstate, CLHEP::HepRandomEngine *rndmEngine) const
interface function: fill a vector with the punch-through particles
Definition: PunchThroughTool.cxx:288
ISF
ISFParticleOrderedQueue.
Definition: PrimaryParticleInformation.h:13
ISF::PunchThroughTool::m_filenameLookupTable
StringProperty m_filenameLookupTable
Properties.
Definition: PunchThroughTool.h:173
ISF::PunchThroughTool::m_beamPipe
DoubleProperty m_beamPipe
beam pipe radius
Definition: PunchThroughTool.h:203
ISF::PunchThroughTool::m_variable4_inverse_cdf
std::vector< std::map< double, double > > m_variable4_inverse_cdf
Definition: PunchThroughTool.h:218
ISF::PunchThroughTool::getFloatAfterPatternInStr
double getFloatAfterPatternInStr(const char *str, const char *pattern)
get the floating point number in a string, after the given pattern
Definition: PunchThroughTool.cxx:1358
ISF::PunchThroughTool::m_fullCorrEnergy
DoubleArrayProperty m_fullCorrEnergy
Definition: PunchThroughTool.h:185
ISF::PunchThroughTool::interpolateEta
double interpolateEta(const double &eta, CLHEP::HepRandomEngine *rndmEngine) const
Definition: PunchThroughTool.cxx:1038
str
Definition: BTagTrackIpAccessor.cxx:11
ISF::PunchThroughTool::m_posAngleFactor
DoubleArrayProperty m_posAngleFactor
Definition: PunchThroughTool.h:186
ISF::PunchThroughTool::m_numParticlesFactor
DoubleArrayProperty m_numParticlesFactor
Definition: PunchThroughTool.h:190
ISF::PunchThroughTool::m_minEnergy
DoubleArrayProperty m_minEnergy
Definition: PunchThroughTool.h:188
ISF::PunchThroughTool::m_initiatorsEtaRange
DoubleArrayProperty m_initiatorsEtaRange
Definition: PunchThroughTool.h:180
ISF::PunchThroughTool::m_minCorrEnergy
DoubleArrayProperty m_minCorrEnergy
Definition: PunchThroughTool.h:184
ISF::PunchThroughTool::m_particles
std::map< int, PunchThroughParticle * > m_particles
needed to create punch-through particles with the right distributions
Definition: PunchThroughTool.h:166
IPunchThroughClassifier.h
ISF::PunchThroughTool::registerParticle
StatusCode registerParticle(int pdgID, 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
Definition: PunchThroughTool.cxx:1110
TFCSSimulationState
Definition: TFCSSimulationState.h:32
ISF::PunchThroughTool::m_variable0_inverse_cdf
std::vector< std::map< double, double > > m_variable0_inverse_cdf
(vector of map) for CDF mappings
Definition: PunchThroughTool.h:214
ISF::PunchThroughTool::dotProduct
static std::vector< double > dotProduct(const std::vector< std::vector< double >> &m, const std::vector< double > &v)
Definition: PunchThroughTool.cxx:729
ISF::PunchThroughTool::m_envDefSvc
ServiceHandle< IEnvelopeDefSvc > m_envDefSvc
Definition: PunchThroughTool.h:200
ISF::PunchThroughTool::m_inverse_PCA_matrix
std::vector< std::vector< std::vector< double > > > m_inverse_PCA_matrix
pca vectors
Definition: PunchThroughTool.h:206
ServiceHandle< IPartPropSvc >
ISF::PunchThroughTool::m_initiatorsMinEnergy
IntegerArrayProperty m_initiatorsMinEnergy
Definition: PunchThroughTool.h:179