ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSEnergyAndHitGAN.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13#include "TFile.h"
14
15#include "HepPDT/ParticleData.hh"
16#include "HepPDT/ParticleDataTable.hh"
17
18#include "CLHEP/Random/RandGauss.h"
19#include "CLHEP/Random/RandFlat.h"
20
21#if defined(__FastCaloSimStandAlone__)
22#include "CLHEP/Random/TRandomEngine.h"
23#else
24#include <CLHEP/Random/RanluxEngine.h>
25#endif
26
27#include <iostream>
28#include <fstream>
29#include <limits>
30#include <cassert>
31
32// LWTNN
33#include "lwtnn/LightweightGraph.hh"
34#include "lwtnn/parse_json.hh"
35
38
39
40//=============================================
41//======= TFCSEnergyAndHitGAN =========
42//=============================================
43
44TFCSEnergyAndHitGAN::TFCSEnergyAndHitGAN(const char *name, const char *title)
45 : TFCSParametrizationBinnedChain(name, title) {
47}
48
50 if (m_input != nullptr) {
51 delete m_input;
52 }
53 if (m_graph != nullptr) {
54 delete m_graph;
55 }
56}
57
58bool TFCSEnergyAndHitGAN::is_match_calosample(int calosample) const {
59 if (get_Binning().find(calosample) == get_Binning().cend())
60 return false;
61 if (get_Binning().at(calosample).GetNbinsX() == 1)
62 return false;
63 return true;
64}
65
66unsigned int TFCSEnergyAndHitGAN::get_nr_of_init(unsigned int bin) const {
67 if (bin >= m_bin_ninit.size())
68 return 0;
69 return m_bin_ninit[bin];
70}
71
72void TFCSEnergyAndHitGAN::set_nr_of_init(unsigned int bin, unsigned int ninit) {
73 if (bin >= m_bin_ninit.size()) {
74 m_bin_ninit.resize(bin + 1, 0);
75 m_bin_ninit.shrink_to_fit();
76 }
77 m_bin_ninit[bin] = ninit;
78}
79
80// initialize lwtnn network
82 int pid, int etaMin, const std::string &FastCaloGANInputFolderName) {
83
84 // initialize all necessary constants
85 // FIXME eventually all these could be stored in the .json file
86
88 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
89 // get neural net JSON file as an std::istream object
90 int etaMax = etaMin + 5;
91
93 set_pdgid(pid);
94 if (pid == 11)
95 add_pdgid(-pid);
96 if (pid == 211)
97 add_pdgid(-pid);
98 set_eta_min(etaMin / 100.0);
99 set_eta_max(etaMax / 100.0);
100 set_eta_nominal((etaMin + etaMax) / 200.0);
101
102 std::string inputFile = std::format("{}/neural_net_{}_eta_{}_{}.json",
103 FastCaloGANInputFolderName, pid, etaMin, etaMax);
104 ATH_MSG_INFO("For pid: " << pid << " and eta " << etaMin << "-" << etaMax
105 << ", loading json file " << inputFile);
106 std::ifstream input(inputFile);
107 if (!input.is_open()) { // check: verify the file actually exists and opened
108 ATH_MSG_ERROR(std::format("Could not open json file: {}", inputFile));
109 return false;
110 }
111 std::stringstream sin;
112 sin << input.rdbuf();
113 input.close();
114 // build the graph
115 auto config = lwt::parse_json_graph(sin);
116 m_graph = new lwt::LightweightGraph(config);
117 assert(m_graph!=nullptr);
118 if (m_input != nullptr) {
119 delete m_input;
120 }
121 m_input = new std::string(sin.str());
122
123 m_GANLatentSize = 50;
124
125 // Get all Binning histograms to store in memory
126 GetBinning(pid, (etaMin + etaMax) / 2, FastCaloGANInputFolderName);
127
128 if (m_GANLatentSize == 0) {
129 ATH_MSG_ERROR("m_GANLatentSize uninitialized!");
130 return false;
131 }
132
133 return true;
134}
135
137 int pid, int etaMid, const std::string &FastCaloGANInputFolderName) {
138 const std::string xmlFullFileName = std::format("{}/binning.xml", FastCaloGANInputFolderName);
139 ATH_MSG_DEBUG("Opening XML file in " << xmlFullFileName);
140
141 std::vector<Binning> AllBinning;
142 std::vector<int> EtaMaxList;
143
145 std::unique_ptr<XMLCoreNode> doc = p.parse (xmlFullFileName);
146 for (const XMLCoreNode* bin : doc->get_children ("Bins/Bin")) {
147 int nodePid = bin->get_int_attrib ("pid");
148 int nodeEtaMax = bin->get_int_attrib ("etaMax");
149
150 Binning binsInLayer;
151 bool correctentry = true;
152 if (nodePid != pid)
153 correctentry = false;
154
155 for (const XMLCoreNode* nodeLayer : bin->get_children ("Layer")) {
156 std::vector<double> edges;
157 std::string s = nodeLayer->get_attrib ("r_edges");
158 std::istringstream ss(s);
159 std::string token;
160
161 while (std::getline(ss, token, ',')) {
162 edges.push_back(atof(token.c_str()));
163 }
164
165 int binsInAlpha = nodeLayer->get_int_attrib ("n_bin_alpha");
166 int layer = nodeLayer->get_int_attrib ("id");
167
168 if (correctentry)
169 ATH_MSG_DEBUG("nodepid=" << nodePid << " nodeEtaMax="
170 << nodeEtaMax << " Layer: " << layer
171 << " binsInAlpha: " << binsInAlpha
172 << " edges: " << s);
173
174 std::string name = "hist_pid_" + std::to_string(nodePid) +
175 "_etaSliceNumber_" +
176 std::to_string(EtaMaxList.size()) + "_layer_" +
177 std::to_string(layer);
178 int xBins = edges.size() - 1;
179 if (xBins == 0) {
180 xBins = 1; // remove warning
181 edges.push_back(0);
182 edges.push_back(1);
183 }
184 binsInLayer[layer] =
185 TH2D(name.c_str(), name.c_str(), xBins, &edges[0],
186 binsInAlpha, -TMath::Pi(), TMath::Pi());
187 binsInLayer[layer].SetDirectory(nullptr);
188 }
189
190 if (!correctentry)
191 continue;
192 AllBinning.push_back(std::move(binsInLayer));
193 EtaMaxList.push_back(nodeEtaMax);
194 }
195
196 int index = 0;
197 for (int etaMax : EtaMaxList) {
198 if (etaMid < etaMax) {
199 m_Binning = AllBinning[index];
200 break;
201 }
202 index++;
203 }
204 ATH_MSG_DEBUG("Done XML file");
205}
206
207const std::string
209 const TFCSTruthState *,
210 const TFCSExtrapolationState *) const {
211 return std::string(
212 Form("layer=%d", simulstate.getAuxInfo<int>("GANlayer"_FCShash)));
213}
214
216 TFCSSimulationState &simulstate, const TFCSTruthState *truth,
217 NetworkInputs &inputs, double &trueEnergy) const {
218 // fill randomize latent space
219 // FIXME: should this really be momentum
220 trueEnergy = truth->P();
221 double randUniformZ = 0.;
222 // FIXME: make dependency on input particle eta, pdgid and energy
223 for (int i = 0; i < m_GANLatentSize; i++) {
224 randUniformZ = CLHEP::RandFlat::shoot(simulstate.randomEngine(), -1., 1.);
225 inputs["node_0"].insert(
226 std::pair<std::string, double>(std::to_string(i), randUniformZ));
227 }
228
229 // ATH_MSG_INFO( "Check label: " <<trueEnergy <<" "<<std::pow(2,22)<<"
230 // "<<trueEnergy/std::pow(2,22));
231 inputs["node_1"].insert(
232 std::pair<std::string, double>("0", trueEnergy / (std::pow(2, 22))));
233
234 return true;
235}
236
238 const TFCSTruthState *truth,
239 const TFCSExtrapolationState *extrapol,
240 NetworkInputs inputs) const {
241 const int pdgId = truth->pdgid();
242 const float charge = HepPDT::ParticleID(pdgId).charge();
243
244 float Einit;
245 const float Ekin = truth->Ekin();
246 if (OnlyScaleEnergy())
247 Einit = simulstate.E();
248 else
249 Einit = Ekin;
250
251 ATH_MSG_VERBOSE("Momentum " << truth->P() << " pdgId " << truth->pdgid());
252
253 // compute the network output values
254 // ATH_MSG_VERBOSE("neural network input = "<<inputs);
255 ATH_MSG_VERBOSE("input size " << inputs["node_0"].size());
256 NetworkOutputs outputs = m_graph->compute(inputs);
257 // ATH_MSG_VERBOSE("neural network output = "<<outputs);
258
259 ATH_MSG_VERBOSE("neural network output size = " << outputs.size());
260
261 const Binning &binsInLayers = m_Binning;
262 ATH_MSG_VERBOSE("Get binning");
263
264 simulstate.set_E(0);
265
266 int vox = 0;
267 for (const auto& element : binsInLayers) {
268 int layer = element.first;
269
270 const TH2D *h = &element.second;
271 int xBinNum = h->GetNbinsX();
272 // If only one bin in r means layer is empty, no value should be added
273 if (xBinNum == 1) {
274 ATH_MSG_VERBOSE(" Layer "
275 << layer
276 << " has only one bin in r, this means is it not used, "
277 "skipping (this is needed to keep correct "
278 "syncronisation of voxel and layers)");
279 // delete h;
280 continue;
281 }
282
283 ATH_MSG_VERBOSE(" Getting energy for Layer " << layer);
284
285 int yBinNum = h->GetNbinsY();
286
287 // First fill energies
288 for (int iy = 1; iy <= yBinNum; ++iy) {
289 for (int ix = 1; ix <= xBinNum; ++ix) {
290 double energyInVoxel = outputs["out_" + std::to_string(vox)];
291 ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
292 << " binx " << ix << " biny " << iy);
293
294 if (energyInVoxel == 0) {
295 vox++;
296 continue;
297 }
298
299 simulstate.add_E(layer, Einit * energyInVoxel);
300 vox++;
301 }
302 }
303 }
304
305 for (unsigned int ichain = m_bin_start.back(); ichain < size(); ++ichain) {
306 ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
307 if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
308 FCSSuccess) {
309 return FCSFatal;
310 }
311 }
312
313 vox = 0;
314 for (const auto& element : binsInLayers) {
315 int layer = element.first;
316 simulstate.setAuxInfo<int>("GANlayer"_FCShash, layer);
318
319 const TH2D *h = &element.second;
320 int xBinNum = h->GetNbinsX();
321 // If only one bin in r means layer is empty, no value should be added
322 if (xBinNum == 1) {
323 ATH_MSG_VERBOSE(" Layer "
324 << layer
325 << " has only one bin in r, this means is it not used, "
326 "skipping (this is needed to keep correct "
327 "syncronisation of voxel and layers)");
328 // delete h;
329 continue;
330 }
331
332 if (get_number_of_bins() > 0) {
333 const int bin = get_bin(simulstate, truth, extrapol);
334 if (bin >= 0 && bin < (int)get_number_of_bins()) {
335 for (unsigned int ichain = m_bin_start[bin];
336 ichain < TMath::Min(m_bin_start[bin] + get_nr_of_init(bin),
337 m_bin_start[bin + 1]);
338 ++ichain) {
339 ATH_MSG_DEBUG("for " << get_variable_text(simulstate, truth, extrapol)
340 << " run init " << get_bin_text(bin) << ": "
341 << chain()[ichain]->GetName());
342 if (chain()[ichain]->InheritsFrom(
343 TFCSLateralShapeParametrizationHitBase::Class())) {
345 static_cast<TFCSLateralShapeParametrizationHitBase *>(chain()[ichain]);
346 if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
347 FCSSuccess) {
348 ATH_MSG_ERROR("error for "
349 << get_variable_text(simulstate, truth, extrapol)
350 << " run init " << get_bin_text(bin) << ": "
351 << chain()[ichain]->GetName());
352 return false;
353 }
354 } else {
355 ATH_MSG_ERROR("for "
356 << get_variable_text(simulstate, truth, extrapol)
357 << " run init " << get_bin_text(bin) << ": "
358 << chain()[ichain]->GetName()
359 << " does not inherit from "
360 "TFCSLateralShapeParametrizationHitBase");
361 return false;
362 }
363 }
364 } else {
365 ATH_MSG_WARNING("nothing to init for "
366 << get_variable_text(simulstate, truth, extrapol)
367 << ": " << get_bin_text(bin));
368 }
369 }
370
371 int binResolution = 5;
372 if (layer == 1 || layer == 5) {
373 binResolution = 1;
374 }
375
376 const double center_eta = hit.center_eta();
377 const double center_phi = hit.center_phi();
378 const double center_r = hit.center_r();
379 const double center_z = hit.center_z();
380
381 ATH_MSG_VERBOSE(" Layer " << layer << " Extrap eta " << center_eta
382 << " phi " << center_phi << " R " << center_r);
383
384 const float dist000 =
385 TMath::Sqrt(center_r * center_r + center_z * center_z);
386 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
387 (1.0 + TMath::Exp(-2 * center_eta)));
388
389 int nHitsAlpha;
390 int nHitsR;
391
392 int yBinNum = h->GetNbinsY();
393
394 // Now create hits
395 for (int iy = 1; iy <= yBinNum; ++iy) {
396 for (int ix = 1; ix <= xBinNum; ++ix) {
397
398 double energyInVoxel = outputs["out_" + std::to_string(vox)];
399 ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
400 << " binx " << ix << " biny " << iy);
401
402 if (energyInVoxel == 0) {
403 vox++;
404 continue;
405 }
406
407 const TAxis *x = h->GetXaxis();
408 nHitsR = x->GetBinUpEdge(ix) - x->GetBinLowEdge(ix);
409 if (yBinNum == 1) {
410 // nbins in alpha depend on circumference lenght
411 double r = x->GetBinUpEdge(ix);
412 nHitsAlpha = ceil(2 * TMath::Pi() * r / binResolution);
413 } else {
414 // d = 2*r*sin (a/2r) this distance at the upper r must be 1mm for
415 // layer 1 or 5, 5mm otherwise.
416 const TAxis *y = h->GetYaxis();
417 double angle = y->GetBinUpEdge(iy) - y->GetBinLowEdge(iy);
418 double r = x->GetBinUpEdge(ix);
419 double d = 2 * r * sin(angle / 2 * r);
420 nHitsAlpha = ceil(d / binResolution);
421 }
422
423 nHitsAlpha = std::min(10, std::max(1, nHitsAlpha));
424 nHitsR = std::min(10, std::max(1, nHitsR));
425
426 for (int ir = 0; ir < nHitsR; ++ir) {
427 const TAxis *x = h->GetXaxis();
428 double r =
429 x->GetBinLowEdge(ix) + x->GetBinWidth(ix) / (nHitsR + 1) * ir;
430
431 for (int ialpha = 0; ialpha < nHitsAlpha; ++ialpha) {
432 double alpha;
433 if (yBinNum == 1) {
434 alpha = CLHEP::RandFlat::shoot(simulstate.randomEngine(), -M_PI,
435 M_PI);
436 } else {
437 const TAxis *y = h->GetYaxis();
438 alpha = y->GetBinLowEdge(iy) +
439 y->GetBinWidth(iy) / (nHitsAlpha + 1) * ialpha;
440 }
441
442 hit.reset();
443 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
444
445 if (layer <= 20) {
446 float delta_eta_mm = r * cos(alpha);
447 float delta_phi_mm = r * sin(alpha);
448
449 ATH_MSG_VERBOSE("delta_eta_mm " << delta_eta_mm
450 << " delta_phi_mm "
451 << delta_phi_mm);
452
453 // Particles with negative eta are expected to have the same shape
454 // as those with positive eta after transformation: delta_eta -->
455 // -delta_eta
456 if (center_eta < 0.)
457 delta_eta_mm = -delta_eta_mm;
458 // We derive the shower shapes for electrons and positively charged hadrons.
459 // Particle with the opposite charge are expected to have the same shower shape
460 // after the transformation: delta_phi --> -delta_phi
461 if ((charge < 0. && pdgId!=11) || pdgId==-11)
462 delta_phi_mm = -delta_phi_mm;
463
464 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
465 const float delta_phi = delta_phi_mm / center_r;
466
467 hit.eta() = center_eta + delta_eta;
468 hit.phi() = center_phi + delta_phi;
469
470 ATH_MSG_VERBOSE(" Hit eta " << hit.eta() << " phi " << hit.phi()
471 << " layer " << layer);
472 } else { // FCAL is in (x,y,z)
473 const float hit_r = r * cos(alpha) + center_r;
474 float delta_phi = r * sin(alpha) / center_r;
475
476 // We derive the shower shapes for electrons and positively charged hadrons.
477 // Particle with the opposite charge are expected to have the same shower shape
478 // after the transformation: delta_phi --> -delta_phi
479 if ((charge < 0. && pdgId!=11) || pdgId==-11)
480 delta_phi = -delta_phi;
481 const float hit_phi = delta_phi + center_phi;
482 hit.x() = hit_r * cos(hit_phi);
483 hit.y() = hit_r * sin(hit_phi);
484 hit.z() = center_z;
485 ATH_MSG_VERBOSE(" Hit x " << hit.x() << " y " << hit.y()
486 << " layer " << layer);
487 }
488
489 if (get_number_of_bins() > 0) {
490 const int bin = get_bin(simulstate, truth, extrapol);
491 if (bin >= 0 && bin < (int)get_number_of_bins()) {
492 for (unsigned int ichain =
494 ichain < m_bin_start[bin + 1]; ++ichain) {
496 "for " << get_variable_text(simulstate, truth, extrapol)
497 << " run " << get_bin_text(bin) << ": "
498 << chain()[ichain]->GetName());
499 if (chain()[ichain]->InheritsFrom(
500 TFCSLateralShapeParametrizationHitBase::Class())) {
503 *>(chain()[ichain]);
504 if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
505 FCSSuccess) {
507 "error for "
508 << get_variable_text(simulstate, truth, extrapol)
509 << " run init " << get_bin_text(bin) << ": "
510 << chain()[ichain]->GetName());
511 return false;
512 }
513 } else {
515 "for " << get_variable_text(simulstate, truth, extrapol)
516 << " run init " << get_bin_text(bin) << ": "
517 << chain()[ichain]->GetName()
518 << " does not inherit from "
519 "TFCSLateralShapeParametrizationHitBase");
520 return false;
521 }
522 }
523 } else {
525 "nothing to do for "
526 << get_variable_text(simulstate, truth, extrapol) << ": "
527 << get_bin_text(bin));
528 }
529 } else {
530 ATH_MSG_WARNING("no bins defined, is this intended?");
531 }
532 }
533 }
534 vox++;
535 }
536 }
537
538 ATH_MSG_VERBOSE("Number of voxels " << vox);
539
540 // delete h;
541 ATH_MSG_VERBOSE("Done layer " << layer);
542 }
543 if (simulstate.E() > std::numeric_limits<double>::epsilon()) {
544 for (int ilayer = 0; ilayer < CaloCell_ID_FCS::MaxSample; ++ilayer) {
545 simulstate.set_Efrac(ilayer, simulstate.E(ilayer) / simulstate.E());
546 }
547 }
548
549 ATH_MSG_VERBOSE("Done particle");
550
551 return true;
552}
553
556 const TFCSTruthState *truth,
557 const TFCSExtrapolationState *extrapol) const {
558 for (unsigned int ichain = 0; ichain < m_bin_start[0]; ++ichain) {
559 ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
560 if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
561 FCSSuccess) {
562 return FCSFatal;
563 }
564 }
565
566 // Compute all inputs to the network
567 NetworkInputs inputs;
568 double trueEnergy;
569 ATH_MSG_VERBOSE("Get Inputs");
570 if (!fillFastCaloGanNetworkInputs(simulstate, truth, inputs, trueEnergy)) {
571 ATH_MSG_WARNING("Could not initialize network ");
572 // bail out but do not stop the job
573 return FCSSuccess;
574 }
575
576 ATH_MSG_VERBOSE("Fill Energies");
577 if (!fillEnergy(simulstate, truth, extrapol, std::move(inputs))) {
578 ATH_MSG_WARNING("Could not fill energies ");
579 // bail out but do not stop the job
580 return FCSSuccess;
581 }
582
583 return FCSSuccess;
584}
585
586void TFCSEnergyAndHitGAN::Print(Option_t *option) const {
588 TString opt(option);
589 bool shortprint = opt.Index("short") >= 0;
590 bool longprint = msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
591 TString optprint = opt;
592 optprint.ReplaceAll("short", "");
593
594 if (longprint) {
595 ATH_MSG_INFO(optprint << " "
596 << "Graph=" << CxxUtils::as_const_ptr(m_graph)
597 << "; json input=" << CxxUtils::as_const_ptr(m_input)
598 << "; free mem=" << GANfreemem()
599 << "; latent space=" << m_GANLatentSize
600 << "; Binning size=" << m_Binning.size());
601 for (const auto &l : m_Binning)
602 if (is_match_calosample(l.first)) {
603 ATH_MSG_INFO(optprint << " "
604 << "layer=" << l.first
605 << " nR=" << l.second.GetNbinsX()
606 << " nalpha=" << l.second.GetNbinsY());
607 }
608 }
609
610 TString prefix = "- ";
611 for (unsigned int ichain = 0; ichain < size(); ++ichain) {
612 if (ichain == 0 && ichain != m_bin_start.front()) {
613 prefix = "> ";
614 if (longprint)
615 ATH_MSG_INFO(optprint << prefix << "Run for all bins");
616 }
617 for (unsigned int ibin = 0; ibin < get_number_of_bins(); ++ibin) {
618 if (ichain == m_bin_start[ibin]) {
619 if (ibin < get_number_of_bins() - 1)
620 if (ichain == m_bin_start[ibin + 1])
621 continue;
622 prefix = Form("%-2d", ibin);
623 if (longprint)
624 ATH_MSG_INFO(optprint << prefix << "Run for " << get_bin_text(ibin));
625 }
626 }
627 if (ichain == m_bin_start.back()) {
628 prefix = "< ";
629 if (longprint)
630 ATH_MSG_INFO(optprint << prefix << "Run for all bins");
631 }
632 chain()[ichain]->Print(opt + prefix);
633 }
634}
635
636void TFCSEnergyAndHitGAN::Streamer(TBuffer &R__b) {
637 // Stream an object of class TFCSEnergyAndHitGAN
638
639 if (R__b.IsReading()) {
640 R__b.ReadClassBuffer(TFCSEnergyAndHitGAN::Class(), this);
641 if (m_graph != nullptr) {
642 delete m_graph;
643 m_graph = nullptr;
644 }
645 if (m_input) {
646 std::stringstream sin;
647 sin.str(*m_input);
648 auto config = lwt::parse_json_graph(sin);
649 m_graph = new lwt::LightweightGraph(config);
650 }
651#ifndef __FastCaloSimStandAlone__
652 // When running inside Athena, delete config to free the memory
653 if (GANfreemem()) {
654 delete m_input;
655 m_input = nullptr;
656 }
657#endif
658 } else {
659 R__b.WriteClassBuffer(TFCSEnergyAndHitGAN::Class(), this);
660 }
661}
662
664 const TFCSTruthState *truth,
665 const TFCSExtrapolationState *extrapol) {
666 if (!simulstate) {
667 simulstate = new TFCSSimulationState();
668#if defined(__FastCaloSimStandAlone__)
669 simulstate->setRandomEngine(new CLHEP::TRandomEngine());
670#else
671 simulstate->setRandomEngine(new CLHEP::RanluxEngine());
672#endif
673 }
674 if (!truth) {
676 t->SetPtEtaPhiM(20000, 0.225, 0, 130);
677 t->set_pdgid(211);
678 truth = t;
679 }
680 if (!extrapol) {
682 e->set_IDCaloBoundary_eta(truth->Eta());
683 for (int i = 0; i < 24; ++i) {
684 e->set_eta(i, TFCSExtrapolationState::SUBPOS_ENT, truth->Eta());
685 e->set_eta(i, TFCSExtrapolationState::SUBPOS_EXT, truth->Eta());
686 e->set_eta(i, TFCSExtrapolationState::SUBPOS_MID, truth->Eta());
687 e->set_phi(i, TFCSExtrapolationState::SUBPOS_ENT, 0);
688 e->set_phi(i, TFCSExtrapolationState::SUBPOS_EXT, 0);
689 e->set_phi(i, TFCSExtrapolationState::SUBPOS_MID, 0);
690 e->set_r(i, TFCSExtrapolationState::SUBPOS_ENT, 1500 + i * 10);
691 e->set_r(i, TFCSExtrapolationState::SUBPOS_EXT, 1510 + i * 10);
692 e->set_r(i, TFCSExtrapolationState::SUBPOS_MID, 1505 + i * 10);
693 e->set_z(i, TFCSExtrapolationState::SUBPOS_ENT, 3500 + i * 10);
694 e->set_z(i, TFCSExtrapolationState::SUBPOS_EXT, 3510 + i * 10);
695 e->set_z(i, TFCSExtrapolationState::SUBPOS_MID, 3505 + i * 10);
696 }
697 extrapol = e;
698 }
699
700 TFCSEnergyAndHitGAN GAN("GAN", "GAN");
701 GAN.setLevel(MSG::VERBOSE);
702 static constexpr int pid = 211;
703 int etaMin = 20;
704 int etaMax = etaMin + 5;
706 pid, etaMin,
707 "/eos/atlas/atlascerngroupdisk/proj-simul/VoxalisationOutputs/nominal/"
708 "GAN_michele_normE_MaxE/input_for_service_new");
709 for (int i = 0; i < 24; ++i)
710 if (GAN.is_match_calosample(i)) {
712 Form("center%d", i), Form("center layer %d", i));
713 c->set_calosample(i);
714 c->setExtrapWeight(0.5);
715 c->setLevel(MSG::VERBOSE);
716 c->set_pdgid(pid);
717 if (pid == 11)
718 //pid was set to 211
719 //coverity[DEADCODE]
720 c->add_pdgid(-pid);
721 if (pid == 211)
722 c->add_pdgid(-pid);
723 c->set_eta_min(etaMin / 100.0);
724 c->set_eta_max(etaMax / 100.0);
725 c->set_eta_nominal((etaMin + etaMax) / 200.0);
726
727 GAN.push_back_in_bin(c, i);
728 GAN.set_nr_of_init(i, 1);
729 }
730
731 GAN.Print();
732
733 TFile *fGAN = TFile::Open("FCSGANtest.root", "recreate");
734 GAN.Write();
735 fGAN->ls();
736 fGAN->Close();
737 delete fGAN;
738 fGAN = TFile::Open("FCSGANtest.root");
739 TFCSEnergyAndHitGAN *GAN2 = (TFCSEnergyAndHitGAN *)(fGAN->Get("GAN"));
740 GAN2->Print();
741
742 GAN2->setLevel(MSG::DEBUG);
743 GAN2->simulate(*simulstate, truth, extrapol);
744 simulstate->Print();
745 delete fGAN;
746}
#define M_PI
#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:997
static Double_t ss
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
Simple DOM-like node structure to hold the result of XML parsing.
Helper for getting a const version of a pointer.
Header file for AthHistogramAlgorithm.
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
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
unsigned int get_nr_of_init(unsigned int bin) const
lwt::LightweightGraph * m_graph
void set_nr_of_init(unsigned int bin, unsigned int ninit)
virtual void Print(Option_t *option="") const override
virtual int get_bin(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
use the layer to be done as binning of the GAN chain
Binning m_Binning
Do not persistify.
TFCSEnergyAndHitGAN(const char *name=nullptr, const char *title=nullptr)
bool fillEnergy(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol, NetworkInputs inputs) const
const Binning & get_Binning() const
std::map< std::string, double > NetworkOutputs
virtual const std::string get_variable_text(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
std::map< std::string, std::map< std::string, double > > NetworkInputs
std::map< int, TH2D > Binning
void GetBinning(int pid, int etaMax, const std::string &FastCaloGANInputFolderName)
virtual bool is_match_calosample(int calosample) const override
bool initializeNetwork(int pid, int etaMin, const std::string &FastCaloGANInputFolderName)
std::vector< int > m_bin_ninit
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
bool fillFastCaloGanNetworkInputs(TFCSSimulationState &simulstate, const TFCSTruthState *truth, NetworkInputs &inputs, double &trueEnergy) const
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
Simple DOM-like node structure to hold the result of XML parsing.
Definition XMLCoreNode.h:45
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:138
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.
Definition index.py:1