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