ATLAS Offline Software
TFCSSimulationState.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ISF_FASTCALOSIMEVENT_TFCSSimulationState_h
6 #define ISF_FASTCALOSIMEVENT_TFCSSimulationState_h
7 
8 #include <TObject.h>
11 #include <map>
12 #include <set>
13 #include <unordered_map>
14 #include <vector>
15 #include <cstdint>
16 
17 #undef FCS_USE_HASH_SORTED_CELLMAP
18 #ifdef FCS_USE_HASH_SORTED_CELLMAP
19 #include "CaloDetDescr/CaloDetDescrElement.h"
20 #else
22 #endif
24 
25 namespace CLHEP {
26 class HepRandomEngine;
27 }
28 
29 constexpr std::uint32_t operator"" _FCShash(char const *s, std::size_t count);
30 
31 
32 class TFCSSimulationState : public TObject, public ISF_FCS::MLogging {
33 public:
34  TFCSSimulationState(CLHEP::HepRandomEngine *randomEngine = nullptr);
35 
36  CLHEP::HepRandomEngine *randomEngine() { return m_randomEngine; }
37  void setRandomEngine(CLHEP::HepRandomEngine *engine) {
38  m_randomEngine = engine;
39  }
40 
41  bool is_valid() const { return m_Ebin >= 0; };
42  double E() const { return m_Etot; };
43  double E(int sample) const { return m_E[sample]; };
44  double Efrac(int sample) const { return m_Efrac[sample]; };
45  int Ebin() const { return m_Ebin; };
46 
47  void set_Ebin(int bin) { m_Ebin = bin; };
48  void set_E(int sample, double Esample) { m_E[sample] = Esample; };
49  void set_Efrac(int sample, double Efracsample) {
50  m_Efrac[sample] = Efracsample;
51  };
52  void set_E(double E) { m_Etot = E; };
53  void add_E(int sample, double Esample) {
54  m_E[sample] += Esample;
55  m_Etot += Esample;
56  };
57 
58 #ifdef FCS_USE_HASH_SORTED_CELLMAP
59  struct hashesCmp {
60  bool operator()(const CaloDetDescrElement *a,
61  const CaloDetDescrElement *b) const {
62  return a->calo_hash() < b->calo_hash();
63  }
64  };
65  // Being able to force the order iteration over the Cellmap_t is very useful
66  // when debugging small differences in output
67  typedef std::map<const CaloDetDescrElement *, float, hashesCmp> Cellmap_t;
68 #else
69  typedef std::map<const CaloDetDescrElement *, float> Cellmap_t;
70 #endif
71 
72  Cellmap_t &cells() { return m_cells; };
73  const Cellmap_t &cells() const { return m_cells; };
74  void deposit(const CaloDetDescrElement *cellele, float E);
75 
76  void Print(Option_t *option = "") const;
77 
78  // TODO: Remove explicit functions for SF here and use
79  // getAuxInfo<double>("SF"_FCShash) and setAuxInfo<double>("SF"_FCShash,mysf)
80  // directly in the energy parametrization
81  void set_SF(double mysf) { setAuxInfo<double>("SF"_FCShash, mysf); };
82  double get_SF() { return getAuxInfo<double>("SF"_FCShash); }
83 
84  void clear();
85 
86 #ifdef USE_GPU
87  // for FastCaloSim-GPU
88  // will not compile by default
89  void *get_gpu_rand() { return m_gpu_rand; };
90  void set_gpu_rand(void *rand) { m_gpu_rand = rand; };
91  void *get_geold() { return m_geold; };
92  void set_geold(void *geold) { m_geold = geold; };
93 #endif
94 
95 private:
96 #ifdef USE_GPU
97  // for FastCaloSim-GPU
98  // will not compile by default
99  void *m_gpu_rand;
100  void *m_geold;
101 #endif
102 
103  CLHEP::HepRandomEngine *m_randomEngine;
104 
105  int m_Ebin;
106  double m_Etot;
107  // TO BE CLEANED UP! SHOULD ONLY STORE EITHER E OR EFRAC!!!
110 
112 
113 public:
114  // Allow to store arbitrary type objects as auxilliary information
115  // Use compile time hashes of strings as index to an unordered map of union
116  // AuxInfo_t Example: TFCSSimulationState s;
117  // s.setAuxInfo<double>("SF"_FCShash,2);
118  //
119  // If pointers are stored, a dedicated cleanup is needed
120  // If a new data type is needed, a cast operator and an explicit template
121  // implementation of the set method has to be added
122  union AuxInfo_t {
123  bool b;
124  char c;
125  int i;
126  float f;
127  double d;
128  void *p;
129 
130  // cast operators
131  operator bool() const { return b; };
132  operator char() const { return c; };
133  operator int() const { return i; };
134  operator float() const { return f; };
135  operator double() const { return d; };
136  operator void *() const { return p; };
137 
138  // template set method. No general implementation exist, only explict
139  // implementations are added after the class definition
140  template <class T> void set(T val);
141  void set(const AuxInfo_t &val);
142  };
143 
144  // FNV-1a 32bit hashing algorithm that is evaluated during compile time
145  // function taken from https://gist.github.com/Lee-R/3839813
146  static constexpr std::uint32_t fnv1a_32(char const *s, std::size_t count) {
147  return ((count ? fnv1a_32(s, count - 1) : 2166136261u) ^ s[count]) *
148  16777619u;
149  }
150  // Run time call for hash function
151  static std::uint32_t getAuxIndex(const std::string &s);
152  static std::uint32_t getAuxIndex(const char *s);
153 
154  // Check if some auxiliary information is stored
156  return m_AuxInfo.find(index) != m_AuxInfo.end();
157  };
158 
159  // Get auxiliary info
160  // Use as TFCSSimulationState::getAuxInfo<int>(index)
161  template <class T> inline const T getAuxInfo(std::uint32_t index) const {
162  return static_cast<T>(m_AuxInfo.at(index));
163  }
164 
165  // Set auxiliary info
166  // Use as TFCSSimulationState::setAuxInfo<double>(7,2.0f)
167  // or TFCSSimulationState::setAuxInfo(7,2.0)
168  template <class T> inline void setAuxInfo(std::uint32_t index, const T &val) {
169  m_AuxInfo[index].set<T>(val);
170  }
171 
172  void AddAuxInfoCleanup(const TFCSParametrizationBase *para);
173  void DoAuxInfoCleanup();
174 
175 private:
176  std::unordered_map<std::uint32_t, AuxInfo_t> m_AuxInfo;
177  std::set<const TFCSParametrizationBase *>
179 
180  ClassDef(TFCSSimulationState, 3) // TFCSSimulationState
181 };
182 
183 // Explicit template implementations for template<class T> void
184 // TFCSSimulationState::AuxInfo_t::set(T val);
185 inline void
187  *this = val;
188 }
189 template <> inline void TFCSSimulationState::AuxInfo_t::set<bool>(bool val) {
190  b = val;
191 }
192 template <> inline void TFCSSimulationState::AuxInfo_t::set<char>(char val) {
193  c = val;
194 }
195 template <> inline void TFCSSimulationState::AuxInfo_t::set<int>(int val) {
196  i = val;
197 }
198 template <> inline void TFCSSimulationState::AuxInfo_t::set<float>(float val) {
199  f = val;
200 }
201 template <>
202 inline void TFCSSimulationState::AuxInfo_t::set<double>(double val) {
203  d = val;
204 }
205 template <> inline void TFCSSimulationState::AuxInfo_t::set<void *>(void *val) {
206  p = val;
207 }
208 
209 // Implementation of the complile time text hash operator that can be used for
210 // human readable indices to the AuxInfo
211 constexpr std::uint32_t operator"" _FCShash(char const *s, std::size_t count) {
213 }
214 
215 #endif
TFCSSimulationState::fnv1a_32
static constexpr std::uint32_t fnv1a_32(char const *s, std::size_t count)
Definition: TFCSSimulationState.h:146
ISF_FCS::MLogging
Cut down AthMessaging.
Definition: MLogging.h:176
TFCSSimulationState::getAuxInfo
const T getAuxInfo(std::uint32_t index) const
Definition: TFCSSimulationState.h:161
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TFCSSimulationState::DoAuxInfoCleanup
void DoAuxInfoCleanup()
Definition: TFCSSimulationState.cxx:79
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
TFCSSimulationState::cells
Cellmap_t & cells()
Definition: TFCSSimulationState.h:72
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TFCSSimulationState::Efrac
double Efrac(int sample) const
Definition: TFCSSimulationState.h:44
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
TFCSSimulationState::m_cells
Cellmap_t m_cells
Definition: TFCSSimulationState.h:111
bin
Definition: BinsDiffFromStripMedian.h:43
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition: TFCSSimulationState.h:36
TFCSSimulationState::get_SF
double get_SF()
Definition: TFCSSimulationState.h:82
TFCSSimulationState::m_randomEngine
CLHEP::HepRandomEngine * m_randomEngine
Definition: TFCSSimulationState.h:103
TFCSSimulationState::getAuxIndex
static std::uint32_t getAuxIndex(const std::string &s)
Definition: TFCSSimulationState.cxx:66
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
TFCSSimulationState::AuxInfo_t::set
void set(T val)
TFCSSimulationState::clear
void clear()
Definition: TFCSSimulationState.cxx:21
TFCSParametrizationBase
Definition: TFCSParametrizationBase.h:46
TFCSSimulationState::add_E
void add_E(int sample, double Esample)
Definition: TFCSSimulationState.h:53
TFCSSimulationState::set_SF
void set_SF(double mysf)
Definition: TFCSSimulationState.h:81
CaloCell_ID_FCS::MaxSample
@ MaxSample
Definition: FastCaloSim_CaloCell_ID.h:47
TFCSSimulationState::set_Ebin
void set_Ebin(int bin)
Definition: TFCSSimulationState.h:47
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
lumiFormat.i
int i
Definition: lumiFormat.py:85
TFCSSimulationState::Ebin
int Ebin() const
Definition: TFCSSimulationState.h:45
TFCSSimulationState::AuxInfo_t::d
double d
Definition: TFCSSimulationState.h:127
TFCSSimulationState::m_Etot
double m_Etot
Definition: TFCSSimulationState.h:106
TFCSSimulationState::m_AuxInfoCleanup
std::set< const TFCSParametrizationBase * > m_AuxInfoCleanup
Do not persistify.
Definition: TFCSSimulationState.h:178
TFCSSimulationState::deposit
void deposit(const CaloDetDescrElement *cellele, float E)
Definition: TFCSSimulationState.cxx:31
CLHEP
STD'S.
Definition: IAtRndmGenSvc.h:19
TFCSSimulationState::AuxInfo_t::b
bool b
Definition: TFCSSimulationState.h:123
TFCSSimulationState::hasAuxInfo
bool hasAuxInfo(std::uint32_t index) const
Definition: TFCSSimulationState.h:155
hist_file_dump.f
f
Definition: hist_file_dump.py:135
TFCSSimulationState::Print
void Print(Option_t *option="") const
Definition: TFCSSimulationState.cxx:40
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
TFCSSimulationState::TFCSSimulationState
TFCSSimulationState(CLHEP::HepRandomEngine *randomEngine=nullptr)
Definition: TFCSSimulationState.cxx:16
TFCSSimulationState::m_E
double m_E[CaloCell_ID_FCS::MaxSample]
Definition: TFCSSimulationState.h:108
TFCSSimulationState::set_E
void set_E(double E)
Definition: TFCSSimulationState.h:52
TFCSSimulationState::m_Ebin
int m_Ebin
Definition: TFCSSimulationState.h:105
TFCSSimulationState::AuxInfo_t::p
void * p
Definition: TFCSSimulationState.h:128
TFCSSimulationState::Cellmap_t
std::map< const CaloDetDescrElement *, float > Cellmap_t
Definition: TFCSSimulationState.h:56
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
TFCSSimulationState::setAuxInfo
void setAuxInfo(std::uint32_t index, const T &val)
Definition: TFCSSimulationState.h:168
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
TFCSSimulationState::set_E
void set_E(int sample, double Esample)
Definition: TFCSSimulationState.h:48
TFCSSimulationState::setRandomEngine
void setRandomEngine(CLHEP::HepRandomEngine *engine)
Definition: TFCSSimulationState.h:37
DeMoScan.index
string index
Definition: DeMoScan.py:364
TFCSSimulationState::cells
const Cellmap_t & cells() const
Definition: TFCSSimulationState.h:73
a
TList * a
Definition: liststreamerinfos.cxx:10
TFCSSimulationState::AddAuxInfoCleanup
void AddAuxInfoCleanup(const TFCSParametrizationBase *para)
Definition: TFCSSimulationState.cxx:74
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TFCSSimulationState::AuxInfo_t::c
char c
Definition: TFCSSimulationState.h:124
TFCSSimulationState::AuxInfo_t::i
int i
Definition: TFCSSimulationState.h:125
TFCSSimulationState::m_Efrac
double m_Efrac[CaloCell_ID_FCS::MaxSample]
Definition: TFCSSimulationState.h:109
TFCSSimulationState::AuxInfo_t
Definition: TFCSSimulationState.h:122
TFCSSimulationState::E
double E() const
Definition: TFCSSimulationState.h:42
TFCSSimulationState::m_AuxInfo
std::unordered_map< std::uint32_t, AuxInfo_t > m_AuxInfo
Definition: TFCSSimulationState.h:176
TFCSSimulationState::E
double E(int sample) const
Definition: TFCSSimulationState.h:43
FastCaloSim_CaloCell_ID.h
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
MLogging.h
python.compressB64.c
def c
Definition: compressB64.py:93
TFCSSimulationState
Definition: TFCSSimulationState.h:32
readCCLHist.float
float
Definition: readCCLHist.py:83
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TFCSSimulationState::is_valid
bool is_valid() const
Definition: TFCSSimulationState.h:41
TFCSSimulationState::AuxInfo_t::f
float f
Definition: TFCSSimulationState.h:126
TFCSSimulationState::set_Efrac
void set_Efrac(int sample, double Efracsample)
Definition: TFCSSimulationState.h:49