ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSSimulationState.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
25namespace CLHEP {
26class HepRandomEngine;
27}
28
29constexpr std::uint32_t operator""_FCShash(char const *s, std::size_t count);
30
31
32class TFCSSimulationState : public TObject, public ISF_FCS::MLogging {
33public:
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
95private:
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
106 double m_Etot;
107 // TO BE CLEANED UP! SHOULD ONLY STORE EITHER E OR EFRAC!!!
110
112
113public:
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
155 bool hasAuxInfo(std::uint32_t index) const {
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
173 void DoAuxInfoCleanup();
174
175private:
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);
185inline void
189template <> inline void TFCSSimulationState::AuxInfo_t::set<bool>(bool val) {
190 b = val;
191}
192template <> inline void TFCSSimulationState::AuxInfo_t::set<char>(char val) {
193 c = val;
194}
195template <> inline void TFCSSimulationState::AuxInfo_t::set<int>(int val) {
196 i = val;
197}
198template <> inline void TFCSSimulationState::AuxInfo_t::set<float>(float val) {
199 f = val;
200}
201template <>
203 d = val;
204}
205template <> 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
211constexpr std::uint32_t operator""_FCShash(char const *s, std::size_t count) {
213}
214
215#endif
static Double_t a
This class groups all DetDescr information related to a CaloCell.
Cut down AthMessaging.
Definition MLogging.h:176
double Efrac(int sample) const
static constexpr std::uint32_t fnv1a_32(char const *s, std::size_t count)
void Print(Option_t *option="") const
void set_SF(double mysf)
static std::uint32_t getAuxIndex(const std::string &s)
double E(int sample) const
const Cellmap_t & cells() const
void set_E(int sample, double Esample)
void AddAuxInfoCleanup(const TFCSParametrizationBase *para)
bool hasAuxInfo(std::uint32_t index) const
std::set< const TFCSParametrizationBase * > m_AuxInfoCleanup
Do not persistify.
std::unordered_map< std::uint32_t, AuxInfo_t > m_AuxInfo
TFCSSimulationState(CLHEP::HepRandomEngine *randomEngine=nullptr)
const T getAuxInfo(std::uint32_t index) const
double m_Efrac[CaloCell_ID_FCS::MaxSample]
void add_E(int sample, double Esample)
void deposit(const CaloDetDescrElement *cellele, float E)
void set_Efrac(int sample, double Efracsample)
void setAuxInfo(std::uint32_t index, const T &val)
double m_E[CaloCell_ID_FCS::MaxSample]
std::map< const CaloDetDescrElement *, float > Cellmap_t
CLHEP::HepRandomEngine * m_randomEngine
CLHEP::HepRandomEngine * randomEngine()
void setRandomEngine(CLHEP::HepRandomEngine *engine)
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Definition index.py:1