ATLAS Offline Software
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 
21 class 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;
33  float center_eta;
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;
44  } layer_bins_t;
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 
57  m_use_event_matching = true;
59  m_use_eta_matching = false;
60  };
61 
63 
66  m_use_event_matching = false;
67  m_use_eta_matching = false;
68  };
69 
71 
73  m_use_eta_matching = true;
74  m_use_event_matching = false;
76  };
77 
79 
80  void enable_upscaling() { m_use_upscaling = true; };
81  void disable_upscaling() { m_use_upscaling = false; };
82 
84  float get_default_hit_energy() const { return m_default_hit_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>>>>&
138  return m_sub_bin_distribution;
139  }
140 
141  const std::vector<float>& get_upscaling_energies() const {
142  return m_upscaling_energies;
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.
205  bool m_use_event_matching = false;
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
TFCSBinnedShower::get_n_hits
virtual long unsigned int get_n_hits(TFCSSimulationState &simulstate, long unsigned int layer_index) const override
Definition: TFCSBinnedShower.cxx:267
TFCSBinnedShower::disable_upscaling
void disable_upscaling()
Definition: TFCSBinnedShower.h:81
TFCSBinnedShower::set_hdf5_path
void set_hdf5_path(const std::string &filename)
Definition: TFCSBinnedShower.h:101
TFCSBinnedShower::layer_t
Definition: TFCSBinnedShower.h:25
TFCSBinnedShower::m_max_hits_per_voxel
int m_max_hits_per_voxel
Definition: TFCSBinnedShower.h:191
TFCSBinnedShower::load_shower_center_information
void load_shower_center_information(const std::string &filename)
Definition: TFCSBinnedShower.cxx:697
TFCSBinnedShower::enable_upscaling
void enable_upscaling()
Definition: TFCSBinnedShower.h:80
TFCSBinnedShower::load_sub_bin_distribution
void load_sub_bin_distribution(const std::string &filename)
Definition: TFCSBinnedShower.cxx:776
TFCSBinnedShower::load_event_library
void load_event_library(const std::string &filename, std::vector< long unsigned int > &layers, bool only_load_meta_data=false)
Definition: TFCSBinnedShower.cxx:539
TFCSBinnedShower::event_bins_t
std::vector< layer_bins_t > event_bins_t
Definition: TFCSBinnedShower.h:46
TFCSBinnedShower::m_upscaling_energies
std::vector< float > m_upscaling_energies
Definition: TFCSBinnedShower.h:234
TFCSBinnedShower::enable_event_cherry_picking
void enable_event_cherry_picking()
Definition: TFCSBinnedShower.h:64
TFCSBinnedShower::~TFCSBinnedShower
virtual ~TFCSBinnedShower()
Definition: TFCSBinnedShower.cxx:53
TFCSBinnedShower::load_bin_boundaries
void load_bin_boundaries(const std::string &filename, long unsigned int layer_index)
Definition: TFCSBinnedShower.cxx:652
TFCSBinnedShower::get_sub_bin_distribution
const std::vector< std::vector< std::vector< std::vector< float > > > > & get_sub_bin_distribution() const
Definition: TFCSBinnedShower.h:137
TFCSBinnedShower::find_best_match
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
Definition: TFCSBinnedShower.cxx:115
TFCSBinnedShower::set_layer_energy
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)
Definition: TFCSBinnedShower.cxx:55
module_driven_slicing.layers
layers
Definition: module_driven_slicing.py:113
TFCSBinnedShower::set_event_library
void set_event_library(eventvector_t &eventlibrary)
Definition: TFCSBinnedShower.h:126
TFCSBinnedShower::m_use_upscaling
bool m_use_upscaling
Definition: TFCSBinnedShower.h:228
TFCSBinnedShower
Definition: TFCSBinnedShower.h:23
TFCSBinnedShower::disable_eta_matching
void disable_eta_matching()
Definition: TFCSBinnedShower.h:78
TFCSBinnedShower::event_t
Definition: TFCSBinnedShower.h:30
TFCSBinnedShower::get_layer_energy
virtual float get_layer_energy(TFCSSimulationState &simulstate, long unsigned int layer_index) const override
Definition: TFCSBinnedShower.cxx:282
TFCSBinnedShower::get_default_hit_energy
float get_default_hit_energy() const
Definition: TFCSBinnedShower.h:84
TFCSBinnedShower::set_sub_bin_distribution_and_energies
void set_sub_bin_distribution_and_energies(std::vector< std::vector< std::vector< std::vector< float >>>> &sub_bin_distribution, std::vector< float > &upscaling_energies)
Definition: TFCSBinnedShower.h:145
TFCSBinnedShower::layer_t::bin_index_vector
std::vector< unsigned int > bin_index_vector
Definition: TFCSBinnedShower.h:26
TFCSBinnedShower::set_max_hits_per_voxel
void set_max_hits_per_voxel(int max_hits)
Definition: TFCSBinnedShower.h:85
TFCSBinnedShower::upscale
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
Definition: TFCSBinnedShower.cxx:360
TFCSBinnedShower::delete_event
virtual void delete_event(TFCSSimulationState &simulstate) const override
Definition: TFCSBinnedShower.cxx:509
TFCSBinnedShower::set_bin_boundaries
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)
Definition: TFCSBinnedShower.cxx:76
TFCSBinnedShower::delete_hdf5_path
void delete_hdf5_path()
Definition: TFCSBinnedShower.h:102
TFCSBinnedShower::m_n_layers
const long unsigned int m_n_layers
Definition: TFCSBinnedShower.h:185
TFCSBinnedShower::eventvector_t
std::vector< event_t > eventvector_t
Definition: TFCSBinnedShower.h:37
TFCSBinnedShowerBase.h
TFCSLateralShapeParametrizationHitBase.h
TFCSBinnedShower::get_event
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
Definition: TFCSBinnedShower.cxx:179
LArNewCalib_PedestalAutoCorr.MaxSample
int MaxSample
Definition: LArNewCalib_PedestalAutoCorr.py:15
TFCSBinnedShower::m_use_eta_matching
bool m_use_eta_matching
Definition: TFCSBinnedShower.h:216
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
TFCSBinnedShower::get_upscaling_energies
const std::vector< float > & get_upscaling_energies() const
Definition: TFCSBinnedShower.h:141
TFCSParametrizationBinnedChain.h
TFCSBinnedShower::get_hit_position_and_energy
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
Definition: TFCSBinnedShower.cxx:467
ICaloGeometry
Definition: ICaloGeometry.h:14
covarianceTool.title
title
Definition: covarianceTool.py:542
TFCSBinnedShower::compute_n_hits_and_elayer
virtual void compute_n_hits_and_elayer(TFCSSimulationState &simulstate) const
Definition: TFCSBinnedShower.cxx:221
TFCSBinnedShower::layer_bins_t::R_size
std::vector< float > R_size
Definition: TFCSBinnedShower.h:41
TFCSBinnedShower::layer_bins_t::R_lower
std::vector< float > R_lower
Definition: TFCSBinnedShower.h:40
TFCSBinnedShower::get_coordinates
const event_bins_t & get_coordinates()
Definition: TFCSBinnedShower.h:130
TFCSBinnedShower::layer_t::E_vector
std::vector< float > E_vector
Definition: TFCSBinnedShower.h:27
TFCSBinnedShower::load_layer_energy
void load_layer_energy(const std::string &filename, long unsigned int layer_index)
Definition: TFCSBinnedShower.cxx:611
TFCSBinnedShower::event_t::center_eta
float center_eta
Definition: TFCSBinnedShower.h:33
TFCSBinnedShowerBase
Definition: TFCSBinnedShowerBase.h:17
TFCSBinnedShower::m_eventlibrary
eventvector_t m_eventlibrary
Definition: TFCSBinnedShower.h:197
TFCSBinnedShower::layer_bins_t::alpha_lower
std::vector< float > alpha_lower
Definition: TFCSBinnedShower.h:42
TFCSBinnedShower::set_coordinates
void set_coordinates(event_bins_t &coordinates)
Definition: TFCSBinnedShower.h:132
TFCSBinnedShower::event_t::phi_mod
float phi_mod
Definition: TFCSBinnedShower.h:32
TFCSBinnedShower::get_eventlibrary
const eventvector_t & get_eventlibrary()
Definition: TFCSBinnedShower.h:124
TFCSBinnedShower::m_hdf5_file
std::string m_hdf5_file
Definition: TFCSBinnedShower.h:194
TFCSBinnedShower::set_shower_center_information
void set_shower_center_information(long unsigned int event_index, long unsigned int reference_layer_index, float eta_center, float phi_center)
Definition: TFCSBinnedShower.cxx:90
TFCSBinnedShower::disable_event_cherry_picking
void disable_event_cherry_picking()
Definition: TFCSBinnedShower.h:70
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TFCSBinnedShower::layer_bins_t::alpha_size
std::vector< float > alpha_size
Definition: TFCSBinnedShower.h:43
TFCSBinnedShower::enable_eta_matching
void enable_eta_matching()
Definition: TFCSBinnedShower.h:72
TFCSBinnedShower::is_match_Ekin_bin
virtual bool is_match_Ekin_bin(int) const override
Definition: TFCSBinnedShower.h:52
TFCSBinnedShower::get_max_hits_per_voxel
int get_max_hits_per_voxel() const
Definition: TFCSBinnedShower.h:86
TFCSBinnedShower::load_hdf5_dataset
std::tuple< std::vector< float >, std::vector< hsize_t >, bool > load_hdf5_dataset(const std::string &filename, const std::string &datasetname)
Definition: TFCSBinnedShower.cxx:577
TFCSBinnedShower::disable_event_matching
void disable_event_matching()
Definition: TFCSBinnedShower.h:62
TFCSBinnedShower::m_sub_bin_distribution
std::vector< std::vector< std::vector< std::vector< float > > > > m_sub_bin_distribution
Definition: TFCSBinnedShower.h:233
TFCSBinnedShower::m_use_event_matching
bool m_use_event_matching
Definition: TFCSBinnedShower.h:205
TFCSBinnedShower::event_t::event_data
std::vector< layer_t > event_data
Definition: TFCSBinnedShower.h:31
TFCSBinnedShower::m_default_hit_energy
float m_default_hit_energy
Definition: TFCSBinnedShower.h:189
TFCSBinnedShower::m_coordinates
event_bins_t m_coordinates
Definition: TFCSBinnedShower.h:198
TFCSBinnedShower::set_default_hit_energy
void set_default_hit_energy(float energy)
Definition: TFCSBinnedShower.h:83
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
TFCSBinnedShower::event_t::e_init
float e_init
Definition: TFCSBinnedShower.h:34
TFCSBinnedShower::m_use_event_cherry_picking
bool m_use_event_cherry_picking
Definition: TFCSBinnedShower.h:211
TFCSSimulationState.h
TFCSBinnedShower::TFCSBinnedShower
TFCSBinnedShower(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSBinnedShower.cxx:50
TFCSSimulationState
Definition: TFCSSimulationState.h:32
TFCSBinnedShower::enable_event_matching
void enable_event_matching()
Definition: TFCSBinnedShower.h:56
TFCSBinnedShower::get_hdf5_path
const std::string & get_hdf5_path() const
Definition: TFCSBinnedShower.h:103
TFCSBinnedShower::get_energy_index
long unsigned int get_energy_index(TFCSSimulationState &simulstate, long unsigned int layer_index, long unsigned int hit_index) const
Definition: TFCSBinnedShower.cxx:296
TFCSBinnedShower::layer_bins_t
Definition: TFCSBinnedShower.h:39