ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSBinnedShower.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_TFCSBinnedShower_h
6#define ISF_FASTCALOSIMEVENT_TFCSBinnedShower_h
7
8#include <RtypesCore.h>
9#include <TMath.h>
10#include <hdf5.h>
11
12#include <fstream>
13#include <tuple>
14#include <vector>
15
20
21class ICaloGeometry;
22
24 public:
25 typedef struct {
26 std::vector<unsigned int> bin_index_vector;
27 std::vector<float> E_vector;
28 } layer_t;
29
30 typedef struct {
31 std::vector<layer_t> event_data;
32 float phi_mod;
34 float e_init; // Initial energy of the event
35 } event_t;
36
37 typedef std::vector<event_t> eventvector_t;
38
39 typedef struct {
40 std::vector<float> R_lower;
41 std::vector<float> R_size;
42 std::vector<float> alpha_lower;
43 std::vector<float> alpha_size;
45
46 typedef std::vector<layer_bins_t> event_bins_t;
47
48 TFCSBinnedShower(const char *name = nullptr, const char *title = nullptr);
49
50 virtual ~TFCSBinnedShower();
51
52 virtual bool is_match_Ekin_bin(int /*Ekin_bin*/) const override {
53 return true;
54 };
55
61
63
69
71
77
79
82
83 void set_default_hit_energy(float energy) { m_default_hit_energy = energy; }
85 void set_max_hits_per_voxel(int max_hits) { m_max_hits_per_voxel = max_hits; }
87
88 // Loads all required data from the given HDF5 file
89 // TODO: Define HDF5 file format somewhere
90 void load_event_library(const std::string &filename,
91 std::vector<long unsigned int> &layers,
92 bool only_load_meta_data = false);
93
94 void load_sub_bin_distribution(const std::string &filename);
95
96 // If the HDF5 file path is set, the event library will be loaded
97 // automatically at the beginning of the simulation.
98 // If this class is used, it would be better to use load_event_library()
99 // during the param file creation. In this case, the event library
100 // is stored and not loaded on the fly.
101 void set_hdf5_path(const std::string &filename) { m_hdf5_file = filename; }
102 void delete_hdf5_path() { m_hdf5_file.clear(); }
103 const std::string& get_hdf5_path() const { return m_hdf5_file; }
104
105 // Allows to set the layer energy for the given layer and event manually.
106 void set_layer_energy(long unsigned int event_index,
107 long unsigned int layer_index,
108 const std::vector<unsigned int>& bin_index_vector,
109 const std::vector<float>& E_vector);
110
111 // Allows to set the voxel boundaries for the given layer manually.
112 void set_bin_boundaries(long unsigned int layer_index,
113 std::vector<float>& R_lower, std::vector<float>& R_size,
114 std::vector<float>& alpha_lower,
115 std::vector<float>& alpha_size);
116
117 // Allows to set the shower center for the given event manually.
118 // The layer is needed as reference for the phi modulation calculation.
119 // For eta > 1.4 it should be layer 6, otherwise layer 2.
120 void set_shower_center_information(long unsigned int event_index,
121 long unsigned int reference_layer_index,
122 float eta_center, float phi_center);
123
125
126 void set_event_library(eventvector_t& eventlibrary) {
127 m_eventlibrary = eventlibrary;
128 }
129
131
132 void set_coordinates(event_bins_t& coordinates) {
133 m_coordinates = coordinates;
134 }
135
136 const std::vector<std::vector<std::vector<std::vector<float>>>>&
140
141 const std::vector<float>& get_upscaling_energies() const {
143 }
144
146 std::vector<std::vector<std::vector<std::vector<float>>>> &
147 sub_bin_distribution,
148 std::vector<float>& upscaling_energies) {
149 m_sub_bin_distribution = sub_bin_distribution;
150 m_upscaling_energies = upscaling_energies;
151 m_use_upscaling = true;
152 }
153
154 protected:
155 // Returns the event to be used
156 virtual void get_event(
157 TFCSSimulationState &simulstate, float eta_center, float phi_center,
158 float e_init, long unsigned int reference_layer_index) const override;
159
160 // Returns the number of hits that are going to be simulated in the given
161 // layer.
162 virtual long unsigned int get_n_hits(
163 TFCSSimulationState &simulstate,
164 long unsigned int layer_index) const override;
165
166 // Used to precompute the number of hits for all layers in the event.
167 virtual void compute_n_hits_and_elayer(TFCSSimulationState &simulstate) const;
168
169 // Returns the position and energy of the corresponding hit in the given
170 // event, layer and bin
171 virtual float get_layer_energy(TFCSSimulationState &simulstate,
172 long unsigned int layer_index) const override;
173
174 // Returns the position and energy of the corresponding hit in the given
175 // event, layer and bin
176 virtual std::tuple<float, float, float> get_hit_position_and_energy(
177 TFCSSimulationState &simulstate, long unsigned int layer_index,
178 long unsigned int hit_index) const override;
179
180 // Delete all pointers that were created in get_event()
181 virtual void delete_event(TFCSSimulationState &simulstate) const override;
182
183 private:
184 // Number of calorimeter layers
185 const long unsigned int m_n_layers =
187
188 // What should be the average energy per hit in the library
190 // What is the mamimum number of hits per voxel (for runtime reasons)
192
193 // Enables to load the event library from an HDF5 file on the fly.
194 std::string m_hdf5_file;
195
196 // Store the used event library
199
200 // Event matching flag. Ensures that the chose event
201 // from the event library is the same as the one taken
202 // from the EVNT file. Prevents any bias due to position
203 // mismatch. The simulation's event file must be identical
204 // to the one used for the event library generation.
206
207 // Event cherry picking flag. Allows select a individual
208 // event from the event library based on the shower center.
209 // Needed to prevent phi-modulation effects and to artificially
210 // shrink the eta slices
212
213 // Eta matching toggle. Uses the event from the event library that has the
214 // most similar eta to the event from the event file. For this setup the event
215 // file of the shower extraction and the simulation should NOT be the same!
216 bool m_use_eta_matching = false;
217
218 long unsigned int find_best_match(float eta_center, float phi_center,
219 float e_init,
220 long unsigned int reference_layer_index,
221 bool phi_mod_matching) const;
222
223 std::tuple<float, float> get_coordinates(TFCSSimulationState &simulstate,
224 long unsigned int layer_index,
225 int bin_index) const;
226
227 // If true, the sub-cell distribution is used to upscale the energy deposition
228 bool m_use_upscaling = false;
229
230 // Can be used to interpolate the individual voxels according to a higher
231 // resolution average shower
232 std::vector<std::vector<std::vector<std::vector<float>>>>
234 std::vector<float> m_upscaling_energies; // energies of the avg showers
235
236 void upscale(TFCSSimulationState &simulstate, float &R_min, float &R_max,
237 float &alpha_min, float &alpha_max,
238 long unsigned int layer_index, int bin_index) const;
239
240 long unsigned int get_energy_index(TFCSSimulationState &simulstate,
241 long unsigned int layer_index,
242 long unsigned int hit_index) const;
243
244 // Helper functions to load the HDF5 dataset
245 std::tuple<std::vector<float>, std::vector<hsize_t>, bool> load_hdf5_dataset(
246 const std::string &filename, const std::string &datasetname);
247
248 void load_layer_energy(const std::string &filename,
249 long unsigned int layer_index);
250
251 void load_bin_boundaries(const std::string &filename,
252 long unsigned int layer_index);
253
254 void load_shower_center_information(const std::string &filename);
255
256 ClassDefOverride(TFCSBinnedShower, 1) // TFCSBinnedShower
257};
258
259#endif
TFCSBinnedShowerBase(const char *name=nullptr, const char *title=nullptr)
void set_sub_bin_distribution_and_energies(std::vector< std::vector< std::vector< std::vector< float > > > > &sub_bin_distribution, std::vector< float > &upscaling_energies)
const std::vector< std::vector< std::vector< std::vector< float > > > > & get_sub_bin_distribution() const
virtual long unsigned int get_n_hits(TFCSSimulationState &simulstate, long unsigned int layer_index) const override
void load_event_library(const std::string &filename, std::vector< long unsigned int > &layers, bool only_load_meta_data=false)
virtual bool is_match_Ekin_bin(int) const override
void set_default_hit_energy(float energy)
void set_bin_boundaries(long unsigned int layer_index, std::vector< float > &R_lower, std::vector< float > &R_size, std::vector< float > &alpha_lower, std::vector< float > &alpha_size)
const std::vector< float > & get_upscaling_energies() const
virtual float get_layer_energy(TFCSSimulationState &simulstate, long unsigned int layer_index) const override
const long unsigned int m_n_layers
void load_sub_bin_distribution(const std::string &filename)
long unsigned int get_energy_index(TFCSSimulationState &simulstate, long unsigned int layer_index, long unsigned int hit_index) const
void enable_event_cherry_picking()
TFCSBinnedShower(const char *name=nullptr, const char *title=nullptr)
std::vector< layer_bins_t > event_bins_t
void set_hdf5_path(const std::string &filename)
event_bins_t m_coordinates
float get_default_hit_energy() const
void upscale(TFCSSimulationState &simulstate, float &R_min, float &R_max, float &alpha_min, float &alpha_max, long unsigned int layer_index, int bin_index) const
int get_max_hits_per_voxel() const
void load_layer_energy(const std::string &filename, long unsigned int layer_index)
std::vector< std::vector< std::vector< std::vector< float > > > > m_sub_bin_distribution
void load_shower_center_information(const std::string &filename)
virtual void delete_event(TFCSSimulationState &simulstate) const override
virtual std::tuple< float, float, float > get_hit_position_and_energy(TFCSSimulationState &simulstate, long unsigned int layer_index, long unsigned int hit_index) const override
void set_max_hits_per_voxel(int max_hits)
const eventvector_t & get_eventlibrary()
void set_event_library(eventvector_t &eventlibrary)
void set_coordinates(event_bins_t &coordinates)
std::string m_hdf5_file
void disable_event_cherry_picking()
const event_bins_t & get_coordinates()
void set_shower_center_information(long unsigned int event_index, long unsigned int reference_layer_index, float eta_center, float phi_center)
void set_layer_energy(long unsigned int event_index, long unsigned int layer_index, const std::vector< unsigned int > &bin_index_vector, const std::vector< float > &E_vector)
virtual void get_event(TFCSSimulationState &simulstate, float eta_center, float phi_center, float e_init, long unsigned int reference_layer_index) const override
do not persistify
std::tuple< std::vector< float >, std::vector< hsize_t >, bool > load_hdf5_dataset(const std::string &filename, const std::string &datasetname)
virtual void compute_n_hits_and_elayer(TFCSSimulationState &simulstate) const
std::vector< event_t > eventvector_t
void load_bin_boundaries(const std::string &filename, long unsigned int layer_index)
const std::string & get_hdf5_path() const
eventvector_t m_eventlibrary
std::vector< float > m_upscaling_energies
long unsigned int find_best_match(float eta_center, float phi_center, float e_init, long unsigned int reference_layer_index, bool phi_mod_matching) const
std::vector< layer_t > event_data
std::vector< float > alpha_size
std::vector< float > alpha_lower
std::vector< unsigned int > bin_index_vector
std::vector< float > E_vector