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