ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSEnergyAndHitGANV2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CLHEP/Random/RandFlat.h"
8#include "CLHEP/Random/RandGauss.h"
16#include "TF1.h"
17#include "TFile.h"
18#include "TH2D.h"
19
20#include "CxxUtils/hexdump.h"
21
22#if defined(__FastCaloSimStandAlone__)
23#include "CLHEP/Random/TRandomEngine.h"
24#else
25#include <CLHEP/Random/RanluxEngine.h>
26#endif
27
28#include <fstream>
29#include <iostream>
30#include <limits>
31
32//=============================================
33//======= TFCSEnergyAndHitGANV2 =========
34//=============================================
35
37 const char *title)
38 : TFCSParametrizationBinnedChain(name, title) {
40}
41
43 if (m_slice != nullptr) {
44 delete m_slice;
45 }
46}
47
49 if (get_Binning().find(calosample) == get_Binning().cend())
50 return false;
51 if (get_Binning().at(calosample).GetNbinsX() == 1)
52 return false;
53 return true;
54}
55
56unsigned int TFCSEnergyAndHitGANV2::get_nr_of_init(unsigned int bin) const {
57 if (bin >= m_bin_ninit.size())
58 return 0;
59 return m_bin_ninit[bin];
60}
61
63 unsigned int ninit) {
64 if (bin >= m_bin_ninit.size()) {
65 m_bin_ninit.resize(bin + 1, 0);
66 m_bin_ninit.shrink_to_fit();
67 }
68 m_bin_ninit[bin] = ninit;
69}
70
71// initialize lwtnn network
73 int const &pid, int const &etaMin,
74 const std::string &FastCaloGANInputFolderName) {
75
76 // initialize all necessary constants
77 // FIXME eventually all these could be stored in the .json file
78
80 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
81 // get neural net JSON file as an std::istream object
82 const int etaMax = etaMin + 5;
83
85 set_pdgid(pid);
86 if (pid == 11)
87 add_pdgid(-pid);
88 if (pid == 211)
89 add_pdgid(-pid);
90 set_eta_min(etaMin / 100.0);
91 set_eta_max(etaMax / 100.0);
92 set_eta_nominal((etaMin + etaMax) / 200.0);
93
94 int pidForXml = pid;
95 if (pid != 22 && pid != 11) {
96 pidForXml = 211;
97 }
98
99 const int etaMid = (etaMin + etaMax) / 2;
100 m_param.InitialiseFromXML(pidForXml, etaMid, FastCaloGANInputFolderName);
101 m_param.Print();
102 m_slice = new TFCSGANEtaSlice(pid, etaMin, etaMax, m_param);
103 m_slice->Print();
104 return m_slice->LoadGAN();
105}
106
108 TFCSSimulationState &simulstate, const TFCSTruthState *,
109 const TFCSExtrapolationState *) const {
110 return std::string(
111 Form("layer=%d", simulstate.getAuxInfo<int>("GANlayer"_FCShash)));
112}
113
115 TFCSSimulationState &simulstate, const TFCSTruthState *truth,
116 const TFCSExtrapolationState *extrapol) const {
117 if (!truth) {
118 ATH_MSG_ERROR("Invalid truth pointer");
119 return false;
120 }
121
122 if (!extrapol) {
123 ATH_MSG_ERROR("Invalid extrapolation pointer");
124 return false;
125 }
126
127 const int pdgId = truth->pdgid();
128 const float charge = MC::charge(pdgId);
129
130 float Einit;
131 const float Ekin = truth->Ekin();
132 if (OnlyScaleEnergy())
133 Einit = simulstate.E();
134 else
135 Einit = Ekin;
136
137 ATH_MSG_VERBOSE("Momentum " << truth->P() << " pdgId " << truth->pdgid());
138 // check that the network exists
139 if (!m_slice->IsGanCorrectlyLoaded()) {
140 ATH_MSG_WARNING("GAN not loaded correctly.");
141 return false;
142 }
144 m_slice->GetNetworkOutputs(truth, extrapol, simulstate);
145 ATH_MSG_VERBOSE("network outputs size: " << outputs.size());
146
147 const TFCSGANXMLParameters::Binning &binsInLayers = m_param.GetBinning();
148 const auto ganVersion = m_param.GetGANVersion();
149 const TFCSGANEtaSlice::FitResultsPerLayer &fitResults =
150 m_slice->GetFitResults(); // used only if GAN version > 1
151
152 ATH_MSG_DEBUG("energy voxels size = " << outputs.size());
153
154 double totalEnergy = 0;
155 for (const auto & output : outputs) {
156 totalEnergy += output.second;
157 }
158 if (totalEnergy < 0) {
159 ATH_MSG_WARNING("Energy from GAN is negative, skipping particle");
160 return false;
161 }
162
163 ATH_MSG_VERBOSE("Get binning");
164
165 simulstate.set_E(0);
166
167 int vox = 0;
168 for (const auto &[layer, h] : binsInLayers) {
169 const int xBinNum = h.GetNbinsX();
170 const int yBinNum = h.GetNbinsY();
171 const TAxis *x = h.GetXaxis();
172
173 // If only one bin in r means layer is empty, no value should be added
174 if (xBinNum == 1) {
175 ATH_MSG_VERBOSE(" Layer "
176 << layer
177 << " has only one bin in r, this means is it not used, "
178 "skipping (this is needed to keep correct "
179 "syncronisation of voxel and layers)");
180 // delete h;
181 continue;
182 }
183
184 ATH_MSG_VERBOSE(" Getting energy for Layer " << layer);
185
186 // First fill energies
187 for (int ix = 1; ix <= xBinNum; ++ix) {
188 double binsInAlphaInRBin = GetAlphaBinsForRBin(x, ix, yBinNum);
189 for (int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
190 const double energyInVoxel = outputs.at(std::to_string(vox));
191 ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
192 << " binx " << ix << " biny " << iy);
193
194 if (energyInVoxel <= 0) {
195 vox++;
196 continue;
197 }
198
199 simulstate.add_E(layer, Einit * energyInVoxel);
200 vox++;
201 }
202 }
203 }
204
205 for (unsigned int ichain = m_bin_start.back(); ichain < size(); ++ichain) {
206 ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
207 if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
208 FCSSuccess) {
209 return FCSFatal;
210 }
211 }
212
213 vox = 0;
214 for (const auto &[layer, h] : binsInLayers) {
215 const int xBinNum = h.GetNbinsX();
216 const int yBinNum = h.GetNbinsY();
217 const TAxis *x = h.GetXaxis();
218 const TAxis *y = h.GetYaxis();
219
220 simulstate.setAuxInfo<int>("GANlayer"_FCShash, layer);
222
223 // If only one bin in r means layer is empty, no value should be added
224 if (xBinNum == 1) {
225 ATH_MSG_VERBOSE(" Layer "
226 << layer
227 << " has only one bin in r, this means is it not used, "
228 "skipping (this is needed to keep correct "
229 "syncronisation of voxel and layers)");
230 // delete h;
231 continue;
232 }
233
234 if (get_number_of_bins() > 0) {
235 const int bin = get_bin(simulstate, truth, extrapol);
236 if (bin >= 0 && bin < (int)get_number_of_bins()) {
237 for (unsigned int ichain = m_bin_start[bin];
238 ichain < TMath::Min(m_bin_start[bin] + get_nr_of_init(bin),
239 m_bin_start[bin + 1]);
240 ++ichain) {
241 ATH_MSG_DEBUG("for " << get_variable_text(simulstate, truth, extrapol)
242 << " run init " << get_bin_text(bin) << ": "
243 << chain()[ichain]->GetName());
244 if (chain()[ichain]->InheritsFrom(
245 TFCSLateralShapeParametrizationHitBase::Class())) {
247 static_cast<TFCSLateralShapeParametrizationHitBase *>(chain()[ichain]);
248 if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
249 FCSSuccess) {
250 ATH_MSG_ERROR("error for "
251 << get_variable_text(simulstate, truth, extrapol)
252 << " run init " << get_bin_text(bin) << ": "
253 << chain()[ichain]->GetName());
254 return false;
255 }
256 } else {
257 ATH_MSG_ERROR("for "
258 << get_variable_text(simulstate, truth, extrapol)
259 << " run init " << get_bin_text(bin) << ": "
260 << chain()[ichain]->GetName()
261 << " does not inherit from "
262 "TFCSLateralShapeParametrizationHitBase");
263 return false;
264 }
265 }
266 } else {
267 ATH_MSG_WARNING("nothing to init for "
268 << get_variable_text(simulstate, truth, extrapol)
269 << ": " << get_bin_text(bin));
270 }
271 }
272
273 int binResolution = 5;
274 if (layer == 1 || layer == 5) {
275 binResolution = 1;
276 }
277
278 const double center_eta = hit.center_eta();
279 const double center_phi = hit.center_phi();
280 const double center_r = hit.center_r();
281 const double center_z = hit.center_z();
282
283 ATH_MSG_VERBOSE(" Layer " << layer << " Extrap eta " << center_eta
284 << " phi " << center_phi << " R " << center_r);
285
286 const float dist000 =
287 TMath::Sqrt(center_r * center_r + center_z * center_z);
288 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
289 (1.0 + TMath::Exp(-2 * center_eta)));
290
291 int nHitsAlpha{};
292 int nHitsR{};
293
294 // Now create hits
295 for (int ix = 1; ix <= xBinNum; ++ix) {
296 const int binsInAlphaInRBin = GetAlphaBinsForRBin(x, ix, yBinNum);
297
298 // Horrible work around for variable # of bins along alpha direction
299 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
300 for (int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
301 const double energyInVoxel = outputs.at(std::to_string(vox));
302 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
303
304 ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
305 << " binx " << ix << " biny " << iy);
306
307 if (energyInVoxel <= 0) {
308 vox++;
309 continue;
310 }
311
312 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
313 // maximum 10 MeV per hit, equaly distributed in alpha and r
314 int maxHitsInVoxel = energyInVoxel * truth->Ekin() / 10;
315 if (maxHitsInVoxel < 1)
316 maxHitsInVoxel = 1;
317 nHitsAlpha = std::sqrt(maxHitsInVoxel);
318 nHitsR = std::sqrt(maxHitsInVoxel);
319 } else {
320 // One hit per mm along r
321 nHitsR = x->GetBinUpEdge(ix) - x->GetBinLowEdge(ix);
322 if (yBinNum == 1) {
323 // nbins in alpha depend on circumference lenght
324 const double r = x->GetBinUpEdge(ix);
325 nHitsAlpha = ceil(2 * TMath::Pi() * r / binResolution);
326 } else {
327 // d = 2*r*sin (a/2r) this distance at the upper r must be 1mm for
328 // layer 1 or 5, 5mm otherwise.
329 const double angle = y->GetBinUpEdge(iy) - y->GetBinLowEdge(iy);
330 const double r = x->GetBinUpEdge(ix);
331 const double d = 2 * r * sin(angle / 2 * r);
332 nHitsAlpha = ceil(d / binResolution);
333 }
334
335 if (layer != 1 && layer != 5) {
336 // For layers that are not EMB1 or EMEC1 use a maximum of 10 hits
337 // per direction, a higher granularity is needed for the other
338 // layers
339 const int maxNhits = 10;
340 nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
341 nHitsR = std::min(maxNhits, std::max(1, nHitsR));
342 }
343 }
344
345 for (int ir = 0; ir < nHitsR; ++ir) {
346 double r =
347 x->GetBinLowEdge(ix) + x->GetBinWidth(ix) / (nHitsR + 1) * ir;
348
349 for (int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
350 if (ganVersion > 1) {
351 if (fitResults.at(layer)[ix - 1] != 0) {
352 int tries = 0;
353 double a = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
354 x->GetBinLowEdge(ix),
355 x->GetBinUpEdge(ix));
356 double rand_r =
357 log((a - x->GetBinLowEdge(ix)) / (x->GetBinWidth(ix))) /
358 fitResults.at(layer)[ix - 1];
359 while ((rand_r < x->GetBinLowEdge(ix) ||
360 rand_r > x->GetBinUpEdge(ix)) &&
361 tries < 100) {
362 a = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
363 x->GetBinLowEdge(ix),
364 x->GetBinUpEdge(ix));
365 rand_r =
366 log((a - x->GetBinLowEdge(ix)) / (x->GetBinWidth(ix))) /
367 fitResults.at(layer)[ix - 1];
368 tries++;
369 }
370 if (tries >= 100) {
371 ATH_MSG_VERBOSE(" Too many tries for bin ["
372 << x->GetBinLowEdge(ix) << "-"
373 << x->GetBinUpEdge(ix) << "] having slope "
374 << fitResults.at(layer)[ix - 1]
375 << " will use grid (old method)");
376 } else {
377 r = rand_r;
378 }
379 }
380 }
381
382 double alpha;
383 if (binsInAlphaInRBin == 1) {
384 alpha = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
385 -TMath::Pi(), TMath::Pi());
386 } else {
387 alpha =
388 y->GetBinLowEdge(lowEdgeIndex) +
389 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
390
391 if (m_param.IsSymmetrisedAlpha()) {
392 if (CLHEP::RandFlat::shoot(simulstate.randomEngine(),
393 -TMath::Pi(), TMath::Pi()) < 0) {
394 alpha = -alpha;
395 }
396 }
397 }
398
399 hit.reset();
400 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
401
402 if (layer <= 20) {
403 float delta_eta_mm = r * cos(alpha);
404 float delta_phi_mm = r * sin(alpha);
405
406 ATH_MSG_VERBOSE("delta_eta_mm " << delta_eta_mm
407 << " delta_phi_mm "
408 << delta_phi_mm);
409
410 // Particles with negative eta are expected to have the same shape
411 // as those with positive eta after transformation: delta_eta -->
412 // -delta_eta
413 if (center_eta < 0.)
414 delta_eta_mm = -delta_eta_mm;
415 // We derive the shower shapes for electrons and positively
416 // charged hadrons. Particle with the opposite charge are expected
417 // to have the same shower shape after the transformation:
418 // delta_phi --> -delta_phi
419 if ((charge < 0. && pdgId != 11) || pdgId == -11)
420 delta_phi_mm = -delta_phi_mm;
421
422 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
423 const float delta_phi = delta_phi_mm / center_r;
424
425 hit.eta() = center_eta + delta_eta;
426 hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
427
428 ATH_MSG_VERBOSE(" Hit eta " << hit.eta() << " phi " << hit.phi()
429 << " layer " << layer);
430 } else { // FCAL is in (x,y,z)
431 const float hit_r = r * cos(alpha) + center_r;
432 float delta_phi = r * sin(alpha) / center_r;
433 // We derive the shower shapes for electrons and positively
434 // charged hadrons. Particle with the opposite charge are expected
435 // to have the same shower shape after the transformation:
436 // delta_phi --> -delta_phi
437 if ((charge < 0. && pdgId != 11) || pdgId == -11)
438 delta_phi = -delta_phi;
439 const float hit_phi =
440 TVector2::Phi_mpi_pi(center_phi + delta_phi);
441 hit.x() = hit_r * cos(hit_phi);
442 hit.y() = hit_r * sin(hit_phi);
443 hit.z() = center_z;
444 ATH_MSG_VERBOSE(" Hit x " << hit.x() << " y " << hit.y()
445 << " layer " << layer);
446 }
447
448 if (get_number_of_bins() > 0) {
449 const int bin = get_bin(simulstate, truth, extrapol);
450 if (bin >= 0 && bin < (int)get_number_of_bins()) {
451 for (unsigned int ichain =
453 ichain < m_bin_start[bin + 1]; ++ichain) {
455 "for " << get_variable_text(simulstate, truth, extrapol)
456 << " run " << get_bin_text(bin) << ": "
457 << chain()[ichain]->GetName());
458 if (chain()[ichain]->InheritsFrom(
459 TFCSLateralShapeParametrizationHitBase::Class())) {
462 *>(chain()[ichain]);
463 if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
464 FCSSuccess) {
466 "error for "
467 << get_variable_text(simulstate, truth, extrapol)
468 << " run init " << get_bin_text(bin) << ": "
469 << chain()[ichain]->GetName());
470 return false;
471 }
472 } else {
474 "for " << get_variable_text(simulstate, truth, extrapol)
475 << " run init " << get_bin_text(bin) << ": "
476 << chain()[ichain]->GetName()
477 << " does not inherit from "
478 "TFCSLateralShapeParametrizationHitBase");
479 return false;
480 }
481 }
482 } else {
484 "nothing to do for "
485 << get_variable_text(simulstate, truth, extrapol) << ": "
486 << get_bin_text(bin));
487 }
488 } else {
489 ATH_MSG_WARNING("no bins defined, is this intended?");
490 }
491 }
492 }
493 vox++;
494 }
495 }
496
497 ATH_MSG_VERBOSE("Number of voxels " << vox);
498 ATH_MSG_VERBOSE("Done layer " << layer);
499 }
500
501 if (simulstate.E() > std::numeric_limits<double>::epsilon()) {
502 for (int ilayer = 0; ilayer < CaloCell_ID_FCS::MaxSample; ++ilayer) {
503 simulstate.set_Efrac(ilayer, simulstate.E(ilayer) / simulstate.E());
504 }
505 }
506
507 ATH_MSG_VERBOSE("Done particle");
508 return true;
509}
510
512 TFCSSimulationState &simulstate, const TFCSTruthState *truth,
513 const TFCSExtrapolationState *extrapol) const {
514 for (unsigned int ichain = 0; ichain < m_bin_start[0]; ++ichain) {
515 ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
516 if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
517 FCSSuccess) {
518 return FCSFatal;
519 }
520 }
521
522 ATH_MSG_VERBOSE("Fill Energies");
523 if (!fillEnergy(simulstate, truth, extrapol)) {
524 ATH_MSG_WARNING("Could not fill energies ");
525 // bail out but do not stop the job
526 return FCSSuccess;
527 }
528
529 return FCSSuccess;
530}
531
532void TFCSEnergyAndHitGANV2::Print(Option_t *option) const {
534 TString opt(option);
535 const bool shortprint = opt.Index("short") >= 0;
536 const bool longprint =
537 msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
538 TString optprint = opt;
539 optprint.ReplaceAll("short", "");
540
541 TString prefix = "- ";
542 for (unsigned int ichain = 0; ichain < size(); ++ichain) {
543 if (ichain == 0 && ichain != m_bin_start.front()) {
544 prefix = "> ";
545 if (longprint)
546 ATH_MSG_INFO(optprint << prefix << "Run for all bins");
547 }
548 for (unsigned int ibin = 0; ibin < get_number_of_bins(); ++ibin) {
549 if (ichain == m_bin_start[ibin]) {
550 if (ibin < get_number_of_bins() - 1)
551 if (ichain == m_bin_start[ibin + 1])
552 continue;
553 prefix = Form("%-2d", ibin);
554 if (longprint)
555 ATH_MSG_INFO(optprint << prefix << "Run for " << get_bin_text(ibin));
556 }
557 }
558 if (ichain == m_bin_start.back()) {
559 prefix = "< ";
560 if (longprint)
561 ATH_MSG_INFO(optprint << prefix << "Run for all bins");
562 }
563 chain()[ichain]->Print(opt + prefix);
564 }
565}
566
568 const TFCSTruthState *truth,
569 const TFCSExtrapolationState *extrapol) {
571 ATH_MSG_NOCLASS(logger, "Start lwtnn test" << std::endl);
572 std::string path =
573 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
574 "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
575 test_path(path, simulstate, truth, extrapol, "lwtnn");
576
577 ATH_MSG_NOCLASS(logger, "Start onnx test" << std::endl);
578 path =
579 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
580 "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
581 test_path(path, simulstate, truth, extrapol, "onnx");
582 ATH_MSG_NOCLASS(logger, "Finish all tests" << std::endl);
583}
584
585void TFCSEnergyAndHitGANV2::test_path(const std::string &path,
586 TFCSSimulationState *simulstate,
587 const TFCSTruthState *truth,
588 const TFCSExtrapolationState *extrapol,
589 const std::string &outputname, int pid) {
591 ATH_MSG_NOCLASS(logger, "Running test on " << path << std::endl);
592 if (!simulstate) {
593 simulstate = new TFCSSimulationState();
594#if defined(__FastCaloSimStandAlone__)
595 simulstate->setRandomEngine(new CLHEP::TRandomEngine());
596#else
597 simulstate->setRandomEngine(new CLHEP::RanluxEngine());
598#endif
599 }
600 if (!truth) {
601 ATH_MSG_NOCLASS(logger, "New particle");
603 t->SetPtEtaPhiM(65536, 0, 0, ParticleConstants::chargedPionMassInMeV);
604 t->set_pdgid(pid);
605 truth = t;
606 }
607 if (!extrapol) {
609 e->set_IDCaloBoundary_eta(truth->Eta());
610 for (int i = 0; i < 24; ++i) {
611 e->set_eta(i, TFCSExtrapolationState::SUBPOS_ENT, truth->Eta());
612 e->set_eta(i, TFCSExtrapolationState::SUBPOS_EXT, truth->Eta());
613 e->set_eta(i, TFCSExtrapolationState::SUBPOS_MID, truth->Eta());
614 e->set_phi(i, TFCSExtrapolationState::SUBPOS_ENT, 0);
615 e->set_phi(i, TFCSExtrapolationState::SUBPOS_EXT, 0);
616 e->set_phi(i, TFCSExtrapolationState::SUBPOS_MID, 0);
617 e->set_r(i, TFCSExtrapolationState::SUBPOS_ENT, 1500 + i * 10);
618 e->set_r(i, TFCSExtrapolationState::SUBPOS_EXT, 1510 + i * 10);
619 e->set_r(i, TFCSExtrapolationState::SUBPOS_MID, 1505 + i * 10);
620 e->set_z(i, TFCSExtrapolationState::SUBPOS_ENT, 3500 + i * 10);
621 e->set_z(i, TFCSExtrapolationState::SUBPOS_EXT, 3510 + i * 10);
622 e->set_z(i, TFCSExtrapolationState::SUBPOS_MID, 3505 + i * 10);
623 }
624 extrapol = e;
625 }
626
627 TFCSEnergyAndHitGANV2 GAN("GAN", "GAN");
628 GAN.setLevel(MSG::INFO);
629 const int etaMin = 20;
630 const int etaMax = etaMin + 5;
631 ATH_MSG_NOCLASS(logger, "Initialize Networks");
632 GAN.initializeNetwork(pid, etaMin, path);
633 for (int i = 0; i < 24; ++i)
634 if (GAN.is_match_calosample(i)) {
636 Form("center%d", i), Form("center layer %d", i));
637 c->set_calosample(i);
638 c->setExtrapWeight(0.5);
639 c->setLevel(MSG::INFO);
640 c->set_pdgid(pid);
641 if (pid == 11)
642 c->add_pdgid(-pid);
643 if (pid == 211)
644 c->add_pdgid(-pid);
645 c->set_eta_min(etaMin / 100.0);
646 c->set_eta_max(etaMax / 100.0);
647 c->set_eta_nominal((etaMin + etaMax) / 200.0);
648
649 GAN.push_back_in_bin(c, i);
650 GAN.set_nr_of_init(i, 1);
651 }
652
653 GAN.Print();
654
655 ATH_MSG_NOCLASS(logger, "Writing GAN to " << outputname);
656 const std::string outname = "FCSGANtest_" + outputname + ".root";
657 TFile *fGAN = TFile::Open(outname.c_str(), "recreate");
658 fGAN->cd();
659 // GAN.Write();
660 fGAN->WriteObjectAny(&GAN, "TFCSEnergyAndHitGANV2", "GAN");
661
662 fGAN->ls();
663 fGAN->Close();
664 delete fGAN;
665
666 ATH_MSG_NOCLASS(logger, "Open " << outname);
667 fGAN = TFile::Open(outname.c_str());
668 TFCSEnergyAndHitGANV2 *GAN2 = (TFCSEnergyAndHitGANV2 *)(fGAN->Get("GAN"));
669 GAN2->setLevel(MSG::INFO);
670 GAN2->Print();
671
672 ATH_MSG_NOCLASS(logger, "Before running GAN2->simulate()");
673 GAN2->simulate(*simulstate, truth, extrapol);
674 simulstate->Print();
675 delete fGAN;
676}
677
679 if (bins < 4)
680 return 4;
681 else if (bins < 8)
682 return 8;
683 else if (bins < 16)
684 return 16;
685 else
686 return 32;
687}
688
690 int yBinNum) const {
691 double binsInAlphaInRBin = yBinNum;
692 if (yBinNum == 32) {
693 ATH_MSG_DEBUG("yBinNum is special value 32");
694 const double widthX = x->GetBinWidth(ix);
695 const double radious = x->GetBinCenter(ix);
696 double circumference = radious * 2. * TMath::Pi();
697 if (m_param.IsSymmetrisedAlpha()) {
698 circumference = radious * TMath::Pi();
699 }
700
701 const double bins = circumference / widthX;
702 binsInAlphaInRBin = GetBinsInFours(bins);
703 ATH_MSG_DEBUG("Bin in alpha: " << binsInAlphaInRBin << " for r bin: " << ix
704 << " (" << x->GetBinLowEdge(ix) << "-"
705 << x->GetBinUpEdge(ix) << ")");
706 }
707 return binsInAlphaInRBin;
708}
709
710
712{
713 m_param.fixHists();
714}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:1003
ATLAS-specific HepMC functions.
bool hit(const Container &ids, int pdgId)
static Double_t a
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
static const std::vector< std::string > bins
A number of constexpr particle constants to avoid hardcoding them directly in various places.
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
#define y
#define x
Header file for AthHistogramAlgorithm.
Cut down AthMessaging.
Definition MLogging.h:176
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
std::vector< int > m_bin_ninit
bool initializeNetwork(int const &pid, int const &etaMin, const std::string &FastCaloGANInputFolderName)
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
unsigned int get_nr_of_init(unsigned int bin) const
virtual int get_bin(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
use the layer to be done as binning of the GAN chain
static void test_path(const std::string &path, TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, const std::string &outputname="unnamed", int pid=211)
virtual const std::string get_variable_text(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
int GetAlphaBinsForRBin(const TAxis *x, int ix, int yBinNum) const
static int GetBinsInFours(double const bins)
virtual void Print(Option_t *option="") const override
virtual void fixHists() override
const TFCSGANXMLParameters::Binning & get_Binning() const
virtual bool is_match_calosample(int calosample) const override
TFCSEnergyAndHitGANV2(const char *name=nullptr, const char *title=nullptr)
bool fillEnergy(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
void set_nr_of_init(unsigned int bin, unsigned int ninit)
TFCSGANXMLParameters m_param
std::map< int, std::vector< double > > FitResultsPerLayer
std::map< std::string, double > NetworkOutputs
std::map< int, TH2D > Binning
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol)
simulated one hit position with some energy.
void Print(Option_t *option="") const
Print object information.
virtual unsigned int get_number_of_bins() const
TFCSParametrizationBinnedChain(const char *name=nullptr, const char *title=nullptr)
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
virtual const std::string get_bin_text(int bin) const
print the range of a bin; for bin -1, print the allowed range
FCSReturnCode simulate_and_retry(TFCSParametrizationBase *parametrization, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
const Chain_t & chain() const
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
virtual void set_eta_max(double max)
virtual void add_pdgid(int id)
virtual void set_eta_nominal(double min)
virtual void set_pdgid(int id)
virtual void set_eta_min(double min)
void Print(Option_t *option="") const
void set_E(int sample, double Esample)
const T getAuxInfo(std::uint32_t index) const
void add_E(int sample, double Esample)
void set_Efrac(int sample, double Efracsample)
void setAuxInfo(std::uint32_t index, const T &val)
CLHEP::HepRandomEngine * randomEngine()
void setRandomEngine(CLHEP::HepRandomEngine *engine)
int pdgid() const
double Ekin() const
int ir
counter of the current depth
Definition fastadd.cxx:49
int r
Definition globals.cxx:22
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
Helpers to make a nice dump of a region of memory.
static Root::TMsgLogger logger("iLumiCalc")
double charge(const T &p)
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)