ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSHitCellMappingWiggle.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <TClass.h>
8
9#include "CLHEP/Random/RandFlat.h"
14#include "TH1.h"
15#include "TMath.h"
16#include "TVector2.h"
17
18//=============================================
19//======= TFCSHitCellMappingWiggle =========
20//=============================================
21
23 const char *title,
24 ICaloGeometry *geo)
25 : TFCSHitCellMapping(name, title, geo) {}
26
30
32 for (auto *&function : m_functions) {
33 if (function) {
34 delete function;
35 function = nullptr;
36 }
37 }
38 m_functions.clear();
39 m_bin_low_edge.clear();
40
41#ifdef USE_GPU
42 delete m_LdFH;
43#endif
44}
45
47 clear();
48 if (!func)
49 return;
50 for (const auto *function : m_functions)
51 if (function)
52 delete function;
53
54 m_functions.resize(1);
55 m_functions[0] = func;
56
57 m_bin_low_edge.resize(2);
58 m_bin_low_edge[0] = 0;
60}
61
63 const std::vector<const TFCS1DFunction *> &functions,
64 const std::vector<float> &bin_low_edges) {
65 clear();
66 if (functions.size() + 1 != bin_low_edges.size()) {
67 ATH_MSG_ERROR("Using " << functions.size() << " functions needs "
68 << functions.size() + 1 << " bin low edges, but got "
69 << bin_low_edges.size() << "bins");
70 return;
71 }
72 for (const auto *function : m_functions)
73 if (function)
74 delete function;
75 m_functions = functions;
76 m_bin_low_edge = bin_low_edges;
77}
78
80 clear();
81 if (!histogram)
82 return;
85 if (xscale != 1) {
86 for (auto &ele : func->get_HistoBordersx())
87 ele *= xscale;
88 }
89 initialize(func);
90}
91
93 const std::vector<const TH1 *> &histograms,
94 const std::vector<float> &bin_low_edges, float xscale) {
95 clear();
96 if (histograms.size() + 1 != bin_low_edges.size()) {
97 ATH_MSG_ERROR("Using " << histograms.size() << " histograms needs "
98 << histograms.size() + 1 << " bins, but got "
99 << bin_low_edges.size() << "bins");
100 return;
101 }
102 std::vector<const TFCS1DFunction *> functions(histograms.size());
103 for (unsigned int i = 0; i < histograms.size(); ++i) {
104 if (histograms[i]) {
106 new TFCS1DFunctionInt32Histogram(histograms[i]);
107 if (xscale != 1) {
108 for (auto &ele : func->get_HistoBordersx())
109 ele *= xscale;
110 }
111 functions[i] = func;
112 } else {
113 functions[i] = nullptr;
114 }
115 }
116
117 initialize(functions, bin_low_edges);
118}
119
121 Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth,
122 const TFCSExtrapolationState *extrapol) {
123 if (!simulstate.randomEngine()) {
124 return FCSFatal;
125 }
126
127 float eta = fabs(hit.eta());
129 return TFCSHitCellMapping::simulate_hit(hit, simulstate, truth, extrapol);
130 }
131
132 auto it = std::upper_bound(m_bin_low_edge.begin(), m_bin_low_edge.end(), eta);
133 int bin = std::distance(m_bin_low_edge.begin(), it) - 1;
134
135 const TFCS1DFunction *func = get_function(bin);
136 if (func) {
137 double rnd = CLHEP::RandFlat::shoot(simulstate.randomEngine());
138
139 double wiggle = func->rnd_to_fct(rnd);
140
141 ATH_MSG_DEBUG("HIT: E=" << hit.E() << " cs=" << calosample()
142 << " eta=" << hit.eta() << " phi=" << hit.phi()
143 << " wiggle=" << wiggle << " bin=" << bin << " ["
144 << get_bin_low_edge(bin) << ","
145 << get_bin_up_edge(bin) << "] func=" << func);
146
147 double hit_phi_shifted = hit.phi() + wiggle;
148 hit.phi() = TVector2::Phi_mpi_pi(hit_phi_shifted);
149 }
150
151 return TFCSHitCellMapping::simulate_hit(hit, simulstate, truth, extrapol);
152}
153
155 const TFCSParametrizationBase &ref) const {
157 return true;
159 return false;
161 return false;
163 return false;
164
165 return true;
166}
167
168void TFCSHitCellMappingWiggle::Print(Option_t *option) const {
170 TString opt(option);
171 bool shortprint = opt.Index("short") >= 0;
172 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
173 TString optprint = opt;
174 optprint.ReplaceAll("short", "");
175
176 if (longprint) {
177 ATH_MSG(INFO) << optprint << " " << get_number_of_bins()
178 << " functions : ";
179 for (unsigned int i = 0; i < get_number_of_bins(); ++i)
180 ATH_MSG(INFO) << get_bin_low_edge(i) << " < (" << get_function(i)
181 << ") < ";
182 ATH_MSG(INFO) << get_bin_up_edge(get_number_of_bins() - 1) << END_MSG(INFO);
183 }
184}
185
187 const TFCSParametrizationBase &ref) const {
188 if (IsA() != ref.IsA()) {
189 ATH_MSG_DEBUG("compare(): different class types "
190 << IsA()->GetName() << " != " << ref.IsA()->GetName());
191 return false;
192 }
193 const TFCSHitCellMappingWiggle &ref_typed =
194 static_cast<const TFCSHitCellMappingWiggle &>(ref);
195
196 if (m_bin_low_edge != ref_typed.m_bin_low_edge) {
197 ATH_MSG_DEBUG("operator==(): different bin edges");
198 return false;
199 }
200
201 for (unsigned int i = 0; i < get_number_of_bins(); ++i) {
202 const TFCS1DFunction *f1 = get_function(i);
203 const TFCS1DFunction *f2 = ref_typed.get_function(i);
204 if (!f1 && !f2)
205 continue;
206 if ((f1 && !f2) || (!f1 && f2)) {
208 "compare(): different only one function pointer is nullptr");
209 return false;
210 }
211 if (f1->IsA() != f2->IsA()) {
212 ATH_MSG_DEBUG("compare(): different class types for function "
213 << i << ": " << f1->IsA()->GetName()
214 << " != " << f2->IsA()->GetName());
215 return false;
216 }
217 if (!(*f1 == *f2)) {
218 ATH_MSG_DEBUG("compare(): difference in functions " << i);
219 return false;
220 }
221 }
222
223 return true;
224}
225
226void TFCSHitCellMappingWiggle::unit_test ATLAS_NOT_THREAD_SAFE(
227 TFCSSimulationState *simulstate, TFCSTruthState *truth,
228 TFCSExtrapolationState *extrapol) {
229 if (!simulstate)
230 simulstate = new TFCSSimulationState();
231 if (!truth)
232 truth = new TFCSTruthState();
233 if (!extrapol)
234 extrapol = new TFCSExtrapolationState();
235
236 int nbin = 10;
237 float maxeta = 5.0;
238 std::vector<const TFCS1DFunction *> functions;
239 std::vector<float> bin_low_edges;
240
241 TFCSHitCellMappingWiggle wiggle_test("WiggleTest", "WiggleTest");
242
243 for (float eta = 0; eta < maxeta; eta += maxeta / nbin) {
244 TH1 *hist = TFCS1DFunction::generate_histogram_random_gauss(
245 16, 100000, -0.0125, 0.0125, 0, 0.005);
246 bin_low_edges.push_back(eta);
247 functions.push_back(new TFCS1DFunctionInt32Histogram(hist));
248 delete hist;
249 }
250 bin_low_edges.push_back(100);
251 wiggle_test.initialize(functions, bin_low_edges);
252 wiggle_test.set_calosample(2);
253 wiggle_test.setLevel(MSG::DEBUG);
254 wiggle_test.Print();
255
256#if 0 // defined(__FastCaloSimStandAlone__)
258
259// * load geometry files
260 geo->LoadGeometryFromFile("/afs/cern.ch/atlas/groups/Simulation/FastCaloSimV2/Geometry-ATLAS-R2-2016-01-00-01.root", "ATLAS-R2-2016-01-00-01");
261 TString path_to_fcal_geo_files = "/afs/cern.ch/atlas/groups/Simulation/FastCaloSimV2/";
262 geo->LoadFCalGeometryFromFiles(path_to_fcal_geo_files + "FCal1-electrodes.sorted.HV.09Nov2007.dat", path_to_fcal_geo_files + "FCal2-electrodes.sorted.HV.April2011.dat", path_to_fcal_geo_files + "FCal3-electrodes.sorted.HV.09Nov2007.dat");
263
264 wiggle_test.set_geometry(geo);
265 for(float eta=-maxeta+0.01;eta<maxeta;eta+=maxeta/nbin) {
266 Hit hit;
267 hit.eta()=eta;
268 hit.phi()=0;
269 hit.E()=1;
270 wiggle_test.simulate_hit(hit,*simulstate,truth,extrapol);
271 }
272#endif
273}
274
275#ifdef USE_GPU
276// copy the hist functions to GPU
277void TFCSHitCellMappingWiggle::LoadHistFuncs() {
278
279 if (m_LdFH) {
280 return;
281 }
282 m_LdFH = new LoadGpuFuncHist();
283 FHs fhs;
284
286 fhs.nhist = m_functions.size();
287 fhs.low_edge = &(m_bin_low_edge[0]);
288 fhs.h_szs = (unsigned int *)malloc(fhs.nhist * sizeof(unsigned int));
289 fhs.h_contents = (uint32_t **)malloc(fhs.nhist * sizeof(uint32_t *));
290 fhs.h_borders = (float **)malloc(fhs.nhist * sizeof(float *));
291
292 for (size_t i = 0; i < fhs.nhist; ++i) {
293 fhs.h_szs[i] = ((TFCS1DFunctionInt32Histogram *)(m_functions[i]))
294 ->get_HistoContents()
295 .size();
296 fhs.h_contents[i] = &(((TFCS1DFunctionInt32Histogram *)(m_functions[i]))
297 ->get_HistoContents()[0]);
298 fhs.h_borders[i] = &(((TFCS1DFunctionInt32Histogram *)(m_functions[i]))
299 ->get_HistoBordersx()[0]);
300 fhs.mxsz = std::max(fhs.mxsz, fhs.h_szs[i]);
301 }
302
303 m_LdFH->set_hf(&fhs);
304 m_LdFH->LD();
305
306 return;
307}
308#endif
const boost::regex ref(r_ef)
Scalar eta() const
pseudorapidity method
#define ATH_MSG_ERROR(x)
#define ATH_MSG(lvl)
#define ATH_MSG_DEBUG(x)
struct FHs FHs
static TRandom * rnd
#define END_MSG(lvl)
Definition MLogging.h:171
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
std::string histogram
Definition chains.cxx:52
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition MLogging.h:222
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition MLogging.cxx:105
const std::vector< float > & get_HistoBordersx() const
static const HistoContent_t s_MaxValue
virtual void rnd_to_fct(float value[], const float rnd[]) const
Function gets array of random numbers rnd[] in the range [0,1) as arguments and returns function valu...
void initialize(TFCS1DFunction *func)
const TFCS1DFunction * get_function(int bin) const
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
modify one hit position to emulate the LAr accordeon shape and then fills all hits into calorimeter c...
bool compare(const TFCSParametrizationBase &ref) const
void Print(Option_t *option="") const override
double get_bin_low_edge(int bin) const
double get_bin_up_edge(int bin) const
std::vector< const TFCS1DFunction * > m_functions
unsigned int get_number_of_bins() const
std::vector< float > m_bin_low_edge
TFCSHitCellMappingWiggle(const char *name=nullptr, const char *title=nullptr, ICaloGeometry *geo=nullptr)
virtual bool operator==(const TFCSParametrizationBase &ref) const override
The == operator compares the content of instances.
virtual void set_geometry(ICaloGeometry *geo) override
Method to set the geometry access pointer.
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
fills all hits into calorimeter cells
void Print(Option_t *option) const override
TFCSHitCellMapping(const char *name=nullptr, const char *title=nullptr, ICaloGeometry *geo=nullptr)
bool compare(const TFCSParametrizationBase &ref) const
static constexpr double init_eta_max
Do not persistify!
bool compare(const TFCSParametrizationBase &ref) const
Do not persistify!
bool compare(const TFCSParametrizationBase &ref) const
CLHEP::HepRandomEngine * randomEngine()
setEventNumber uint32_t
void initialize()
unsigned int * h_szs
Definition FH_structs.h:15
unsigned int nhist
Definition FH_structs.h:13
float ** h_borders
Definition FH_structs.h:17
unsigned int mxsz
Definition FH_structs.h:14
uint32_t ** h_contents
Definition FH_structs.h:16
float * low_edge
Definition FH_structs.h:12
uint32_t s_MaxValue
Definition FH_structs.h:11
#define IsA
Declare the TObject style functions.