ATLAS Offline Software
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 
11 
12 #include "TFile.h"
13 #include "TF1.h"
14 #include "TH2D.h"
15 
16 #include "HepPDT/ParticleData.hh"
17 #include "HepPDT/ParticleDataTable.hh"
18 
19 #include "CLHEP/Random/RandGauss.h"
20 #include "CLHEP/Random/RandFlat.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 <iostream>
29 #include <fstream>
30 #include <limits>
31 
32 //=============================================
33 //======= TFCSEnergyAndHitGANV2 =========
34 //=============================================
35 
37  const char *title)
40 }
41 
43  if (m_slice != nullptr) {
44  delete m_slice;
45  }
46 }
47 
48 bool TFCSEnergyAndHitGANV2::is_match_calosample(int calosample) const {
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 
56 unsigned 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();
103  m_slice->Print();
104  return m_slice->LoadGAN();
105 }
106 
107 const std::string
109  const TFCSTruthState *,
110  const TFCSExtrapolationState *) const {
111  return std::string(
112  Form("layer=%d", simulstate.getAuxInfo<int>("GANlayer"_FCShash)));
113 }
114 
116  TFCSSimulationState &simulstate, const TFCSTruthState *truth,
117  const TFCSExtrapolationState *extrapol) const {
118  if (!truth) {
119  ATH_MSG_ERROR("Invalid truth pointer");
120  return false;
121  }
122 
123  if (!extrapol) {
124  ATH_MSG_ERROR("Invalid extrapolation pointer");
125  return false;
126  }
127 
128  const int pdgId = truth->pdgid();
129  const float charge = HepPDT::ParticleID(pdgId).charge();
130 
131  float Einit;
132  const float Ekin = truth->Ekin();
133  if (OnlyScaleEnergy())
134  Einit = simulstate.E();
135  else
136  Einit = Ekin;
137 
138  ATH_MSG_VERBOSE("Momentum " << truth->P() << " pdgId " << truth->pdgid());
139  // check that the network exists
140  if (!m_slice->IsGanCorrectlyLoaded()) {
141  ATH_MSG_WARNING("GAN not loaded correctly.");
142  return false;
143  }
144 
146  m_slice->GetNetworkOutputs(truth, extrapol, simulstate);
147  ATH_MSG_VERBOSE("network outputs size: " << outputs.size());
148 
149  const TFCSGANXMLParameters::Binning &binsInLayers = m_param.GetBinning();
150  const auto ganVersion = m_param.GetGANVersion();
151  const TFCSGANEtaSlice::FitResultsPerLayer &fitResults =
152  m_slice->GetFitResults(); // used only if GAN version > 1
153 
154  ATH_MSG_DEBUG("energy voxels size = " << outputs.size());
155 
156  double totalEnergy = 0;
157  for (auto output : outputs) {
158  totalEnergy += output.second;
159  }
160  if (totalEnergy < 0) {
161  ATH_MSG_WARNING("Energy from GAN is negative, skipping particle");
162  return false;
163  }
164 
165  ATH_MSG_VERBOSE("Get binning");
166 
167  simulstate.set_E(0);
168 
169  int vox = 0;
170  for (const auto &element : binsInLayers) {
171  const int layer = element.first;
172  const TH2D *h = &element.second;
173 
174  const int xBinNum = h->GetNbinsX();
175  const int yBinNum = h->GetNbinsY();
176  const TAxis *x = h->GetXaxis();
177 
178  // If only one bin in r means layer is empty, no value should be added
179  if (xBinNum == 1) {
180  ATH_MSG_VERBOSE(" Layer "
181  << layer
182  << " has only one bin in r, this means is it not used, "
183  "skipping (this is needed to keep correct "
184  "syncronisation of voxel and layers)");
185  // delete h;
186  continue;
187  }
188 
189  ATH_MSG_VERBOSE(" Getting energy for Layer " << layer);
190 
191  // First fill energies
192  for (int ix = 1; ix <= xBinNum; ++ix) {
193  double binsInAlphaInRBin = GetAlphaBinsForRBin(x, ix, yBinNum);
194  for (int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
195  const double energyInVoxel = outputs.at(std::to_string(vox));
196  ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
197  << " binx " << ix << " biny " << iy);
198 
199  if (energyInVoxel <= 0) {
200  vox++;
201  continue;
202  }
203 
204  simulstate.add_E(layer, Einit * energyInVoxel);
205  vox++;
206  }
207  }
208  }
209 
210  for (unsigned int ichain = m_bin_start.back(); ichain < size(); ++ichain) {
211  ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
212  if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
213  FCSSuccess) {
214  return FCSFatal;
215  }
216  }
217 
218  vox = 0;
219  for (const auto &element : binsInLayers) {
220  const int layer = element.first;
221  const TH2D *h = &element.second;
222  const int xBinNum = h->GetNbinsX();
223  const int yBinNum = h->GetNbinsY();
224  const TAxis *x = h->GetXaxis();
225  const TAxis *y = h->GetYaxis();
226 
227  simulstate.setAuxInfo<int>("GANlayer"_FCShash, layer);
229 
230  // If only one bin in r means layer is empty, no value should be added
231  if (xBinNum == 1) {
232  ATH_MSG_VERBOSE(" Layer "
233  << layer
234  << " has only one bin in r, this means is it not used, "
235  "skipping (this is needed to keep correct "
236  "syncronisation of voxel and layers)");
237  // delete h;
238  continue;
239  }
240 
241  if (get_number_of_bins() > 0) {
242  const int bin = get_bin(simulstate, truth, extrapol);
243  if (bin >= 0 && bin < (int)get_number_of_bins()) {
244  for (unsigned int ichain = m_bin_start[bin];
245  ichain < TMath::Min(m_bin_start[bin] + get_nr_of_init(bin),
246  m_bin_start[bin + 1]);
247  ++ichain) {
248  ATH_MSG_DEBUG("for " << get_variable_text(simulstate, truth, extrapol)
249  << " run init " << get_bin_text(bin) << ": "
250  << chain()[ichain]->GetName());
251  if (chain()[ichain]->InheritsFrom(
252  TFCSLateralShapeParametrizationHitBase::Class())) {
255  if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
256  FCSSuccess) {
257  ATH_MSG_ERROR("error for "
258  << get_variable_text(simulstate, truth, extrapol)
259  << " run init " << get_bin_text(bin) << ": "
260  << chain()[ichain]->GetName());
261  return false;
262  }
263  } else {
264  ATH_MSG_ERROR("for "
265  << get_variable_text(simulstate, truth, extrapol)
266  << " run init " << get_bin_text(bin) << ": "
267  << chain()[ichain]->GetName()
268  << " does not inherit from "
269  "TFCSLateralShapeParametrizationHitBase");
270  return false;
271  }
272  }
273  } else {
274  ATH_MSG_WARNING("nothing to init for "
275  << get_variable_text(simulstate, truth, extrapol)
276  << ": " << get_bin_text(bin));
277  }
278  }
279 
280  int binResolution = 5;
281  if (layer == 1 || layer == 5) {
282  binResolution = 1;
283  }
284 
285  const double center_eta = hit.center_eta();
286  const double center_phi = hit.center_phi();
287  const double center_r = hit.center_r();
288  const double center_z = hit.center_z();
289 
290  ATH_MSG_VERBOSE(" Layer " << layer << " Extrap eta " << center_eta
291  << " phi " << center_phi << " R " << center_r);
292 
293  const float dist000 =
294  TMath::Sqrt(center_r * center_r + center_z * center_z);
295  const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
296  (1.0 + TMath::Exp(-2 * center_eta)));
297 
298  int nHitsAlpha;
299  int nHitsR;
300 
301  // Now create hits
302  for (int ix = 1; ix <= xBinNum; ++ix) {
303  const int binsInAlphaInRBin = GetAlphaBinsForRBin(x, ix, yBinNum);
304 
305  // Horrible work around for variable # of bins along alpha direction
306  const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
307  for (int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
308  const double energyInVoxel = outputs.at(std::to_string(vox));
309  const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
310 
311  ATH_MSG_VERBOSE(" Vox " << vox << " energy " << energyInVoxel
312  << " binx " << ix << " biny " << iy);
313 
314  if (energyInVoxel <= 0) {
315  vox++;
316  continue;
317  }
318 
319  if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
320  // maximum 10 MeV per hit, equaly distributed in alpha and r
321  int maxHitsInVoxel = energyInVoxel * truth->Ekin() / 10;
322  if (maxHitsInVoxel < 1)
323  maxHitsInVoxel = 1;
324  nHitsAlpha = std::sqrt(maxHitsInVoxel);
325  nHitsR = std::sqrt(maxHitsInVoxel);
326  } else {
327  // One hit per mm along r
328  nHitsR = x->GetBinUpEdge(ix) - x->GetBinLowEdge(ix);
329  if (yBinNum == 1) {
330  // nbins in alpha depend on circumference lenght
331  const double r = x->GetBinUpEdge(ix);
332  nHitsAlpha = ceil(2 * TMath::Pi() * r / binResolution);
333  } else {
334  // d = 2*r*sin (a/2r) this distance at the upper r must be 1mm for
335  // layer 1 or 5, 5mm otherwise.
336  const TAxis *y = h->GetYaxis();
337  const double angle = y->GetBinUpEdge(iy) - y->GetBinLowEdge(iy);
338  const double r = x->GetBinUpEdge(ix);
339  const double d = 2 * r * sin(angle / 2 * r);
340  nHitsAlpha = ceil(d / binResolution);
341  }
342 
343  if (layer != 1 && layer != 5) {
344  // For layers that are not EMB1 or EMEC1 use a maximum of 10 hits
345  // per direction, a higher granularity is needed for the other
346  // layers
347  const int maxNhits = 10;
348  nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
349  nHitsR = std::min(maxNhits, std::max(1, nHitsR));
350  }
351  }
352 
353  for (int ir = 0; ir < nHitsR; ++ir) {
354  double r =
355  x->GetBinLowEdge(ix) + x->GetBinWidth(ix) / (nHitsR + 1) * ir;
356 
357  for (int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
358  if (ganVersion > 1) {
359  if (fitResults.at(layer)[ix - 1] != 0) {
360  int tries = 0;
361  double a = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
362  x->GetBinLowEdge(ix),
363  x->GetBinUpEdge(ix));
364  double rand_r =
365  log((a - x->GetBinLowEdge(ix)) / (x->GetBinWidth(ix))) /
366  fitResults.at(layer)[ix - 1];
367  while ((rand_r < x->GetBinLowEdge(ix) ||
368  rand_r > x->GetBinUpEdge(ix)) &&
369  tries < 100) {
370  a = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
371  x->GetBinLowEdge(ix),
372  x->GetBinUpEdge(ix));
373  rand_r =
374  log((a - x->GetBinLowEdge(ix)) / (x->GetBinWidth(ix))) /
375  fitResults.at(layer)[ix - 1];
376  tries++;
377  }
378  if (tries >= 100) {
379  ATH_MSG_VERBOSE(" Too many tries for bin ["
380  << x->GetBinLowEdge(ix) << "-"
381  << x->GetBinUpEdge(ix) << "] having slope "
382  << fitResults.at(layer)[ix - 1]
383  << " will use grid (old method)");
384  } else {
385  r = rand_r;
386  }
387  }
388  }
389 
390  double alpha;
391  if (binsInAlphaInRBin == 1) {
392  alpha = CLHEP::RandFlat::shoot(simulstate.randomEngine(),
393  -TMath::Pi(), TMath::Pi());
394  } else {
395  alpha =
396  y->GetBinLowEdge(lowEdgeIndex) +
397  y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
398 
399  if (m_param.IsSymmetrisedAlpha()) {
400  if (CLHEP::RandFlat::shoot(simulstate.randomEngine(),
401  -TMath::Pi(), TMath::Pi()) < 0) {
402  alpha = -alpha;
403  }
404  }
405  }
406 
407  hit.reset();
408  hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
409 
410  if (layer <= 20) {
411  float delta_eta_mm = r * cos(alpha);
412  float delta_phi_mm = r * sin(alpha);
413 
414  ATH_MSG_VERBOSE("delta_eta_mm " << delta_eta_mm
415  << " delta_phi_mm "
416  << delta_phi_mm);
417 
418  // Particles with negative eta are expected to have the same shape
419  // as those with positive eta after transformation: delta_eta -->
420  // -delta_eta
421  if (center_eta < 0.)
422  delta_eta_mm = -delta_eta_mm;
423  // We derive the shower shapes for electrons and positively charged hadrons.
424  // Particle with the opposite charge are expected to have the same shower shape
425  // after the transformation: delta_phi --> -delta_phi
426  if ((charge < 0. && pdgId!=11) || pdgId==-11)
427  delta_phi_mm = -delta_phi_mm;
428 
429  const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
430  const float delta_phi = delta_phi_mm / center_r;
431 
432  hit.eta() = center_eta + delta_eta;
433  hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
434 
435  ATH_MSG_VERBOSE(" Hit eta " << hit.eta() << " phi " << hit.phi()
436  << " layer " << layer);
437  } else { // FCAL is in (x,y,z)
438  const float hit_r = r * cos(alpha) + center_r;
439  float delta_phi = r * sin(alpha) / center_r;
440  // We derive the shower shapes for electrons and positively charged hadrons.
441  // Particle with the opposite charge are expected to have the same shower shape
442  // after the transformation: delta_phi --> -delta_phi
443  if ((charge < 0. && pdgId!=11) || pdgId==-11)
444  delta_phi = -delta_phi;
445  const float hit_phi =
446  TVector2::Phi_mpi_pi(center_phi + delta_phi);
447  hit.x() = hit_r * cos(hit_phi);
448  hit.y() = hit_r * sin(hit_phi);
449  hit.z() = center_z;
450  ATH_MSG_VERBOSE(" Hit x " << hit.x() << " y " << hit.y()
451  << " layer " << layer);
452  }
453 
454  if (get_number_of_bins() > 0) {
455  const int bin = get_bin(simulstate, truth, extrapol);
456  if (bin >= 0 && bin < (int)get_number_of_bins()) {
457  for (unsigned int ichain =
459  ichain < m_bin_start[bin + 1]; ++ichain) {
461  "for " << get_variable_text(simulstate, truth, extrapol)
462  << " run " << get_bin_text(bin) << ": "
463  << chain()[ichain]->GetName());
464  if (chain()[ichain]->InheritsFrom(
465  TFCSLateralShapeParametrizationHitBase::Class())) {
468  *)(chain()[ichain]);
469  if (sim->simulate_hit(hit, simulstate, truth, extrapol) !=
470  FCSSuccess) {
472  "error for "
473  << get_variable_text(simulstate, truth, extrapol)
474  << " run init " << get_bin_text(bin) << ": "
475  << chain()[ichain]->GetName());
476  return false;
477  }
478  } else {
480  "for " << get_variable_text(simulstate, truth, extrapol)
481  << " run init " << get_bin_text(bin) << ": "
482  << chain()[ichain]->GetName()
483  << " does not inherit from "
484  "TFCSLateralShapeParametrizationHitBase");
485  return false;
486  }
487  }
488  } else {
490  "nothing to do for "
491  << get_variable_text(simulstate, truth, extrapol) << ": "
492  << get_bin_text(bin));
493  }
494  } else {
495  ATH_MSG_WARNING("no bins defined, is this intended?");
496  }
497  }
498  }
499  vox++;
500  }
501  }
502 
503  ATH_MSG_VERBOSE("Number of voxels " << vox);
504  ATH_MSG_VERBOSE("Done layer " << layer);
505  }
506 
507  if (simulstate.E() > std::numeric_limits<double>::epsilon()) {
508  for (int ilayer = 0; ilayer < CaloCell_ID_FCS::MaxSample; ++ilayer) {
509  simulstate.set_Efrac(ilayer, simulstate.E(ilayer) / simulstate.E());
510  }
511  }
512 
513  ATH_MSG_VERBOSE("Done particle");
514  return true;
515 }
516 
519  const TFCSTruthState *truth,
520  const TFCSExtrapolationState *extrapol) const {
521  for (unsigned int ichain = 0; ichain < m_bin_start[0]; ++ichain) {
522  ATH_MSG_DEBUG("now run for all bins: " << chain()[ichain]->GetName());
523  if (simulate_and_retry(chain()[ichain], simulstate, truth, extrapol) !=
524  FCSSuccess) {
525  return FCSFatal;
526  }
527  }
528 
529  ATH_MSG_VERBOSE("Fill Energies");
530  if (!fillEnergy(simulstate, truth, extrapol)) {
531  ATH_MSG_WARNING("Could not fill energies ");
532  // bail out but do not stop the job
533  return FCSSuccess;
534  }
535 
536  return FCSSuccess;
537 }
538 
539 void TFCSEnergyAndHitGANV2::Print(Option_t *option) const {
541  TString opt(option);
542  const bool shortprint = opt.Index("short") >= 0;
543  const bool longprint =
544  msgLvl(MSG::DEBUG) || (msgLvl(MSG::INFO) && !shortprint);
545  TString optprint = opt;
546  optprint.ReplaceAll("short", "");
547 
548  TString prefix = "- ";
549  for (unsigned int ichain = 0; ichain < size(); ++ichain) {
550  if (ichain == 0 && ichain != m_bin_start.front()) {
551  prefix = "> ";
552  if (longprint)
553  ATH_MSG_INFO(optprint << prefix << "Run for all bins");
554  }
555  for (unsigned int ibin = 0; ibin < get_number_of_bins(); ++ibin) {
556  if (ichain == m_bin_start[ibin]) {
557  if (ibin < get_number_of_bins() - 1)
558  if (ichain == m_bin_start[ibin + 1])
559  continue;
560  prefix = Form("%-2d", ibin);
561  if (longprint)
562  ATH_MSG_INFO(optprint << prefix << "Run for " << get_bin_text(ibin));
563  }
564  }
565  if (ichain == m_bin_start.back()) {
566  prefix = "< ";
567  if (longprint)
568  ATH_MSG_INFO(optprint << prefix << "Run for all bins");
569  }
570  chain()[ichain]->Print(opt + prefix);
571  }
572 }
573 
575  const TFCSTruthState *truth,
578  ATH_MSG_NOCLASS(logger, "Start lwtnn test" << std::endl);
579  std::string path = "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
580  "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
581  test_path(path, simulstate, truth, extrapol, "lwtnn");
582 
583  ATH_MSG_NOCLASS(logger, "Start onnx test" << std::endl);
584  path = "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
585  "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
586  test_path(path, simulstate, truth, extrapol, "onnx");
587  ATH_MSG_NOCLASS(logger, "Finish all tests" << std::endl);
588 }
589 
590 void TFCSEnergyAndHitGANV2::test_path(const std::string& path,
591  TFCSSimulationState *simulstate,
592  const TFCSTruthState *truth,
594  const std::string& outputname, int pid) {
596  ATH_MSG_NOCLASS(logger, "Running test on " << path << std::endl);
597  if (!simulstate) {
598  simulstate = new TFCSSimulationState();
599 #if defined(__FastCaloSimStandAlone__)
600  simulstate->setRandomEngine(new CLHEP::TRandomEngine());
601 #else
602  simulstate->setRandomEngine(new CLHEP::RanluxEngine());
603 #endif
604  }
605  if (!truth) {
606  ATH_MSG_NOCLASS(logger, "New particle");
608  t->SetPtEtaPhiM(65536, 0, 0, 139.6);
609  t->set_pdgid(pid);
610  truth = t;
611  }
612  if (!extrapol) {
614  e->set_IDCaloBoundary_eta(truth->Eta());
615  for (int i = 0; i < 24; ++i) {
616  e->set_eta(i, TFCSExtrapolationState::SUBPOS_ENT, truth->Eta());
617  e->set_eta(i, TFCSExtrapolationState::SUBPOS_EXT, truth->Eta());
618  e->set_eta(i, TFCSExtrapolationState::SUBPOS_MID, truth->Eta());
619  e->set_phi(i, TFCSExtrapolationState::SUBPOS_ENT, 0);
620  e->set_phi(i, TFCSExtrapolationState::SUBPOS_EXT, 0);
621  e->set_phi(i, TFCSExtrapolationState::SUBPOS_MID, 0);
622  e->set_r(i, TFCSExtrapolationState::SUBPOS_ENT, 1500 + i * 10);
623  e->set_r(i, TFCSExtrapolationState::SUBPOS_EXT, 1510 + i * 10);
624  e->set_r(i, TFCSExtrapolationState::SUBPOS_MID, 1505 + i * 10);
625  e->set_z(i, TFCSExtrapolationState::SUBPOS_ENT, 3500 + i * 10);
626  e->set_z(i, TFCSExtrapolationState::SUBPOS_EXT, 3510 + i * 10);
627  e->set_z(i, TFCSExtrapolationState::SUBPOS_MID, 3505 + i * 10);
628  }
629  extrapol = e;
630  }
631 
632  TFCSEnergyAndHitGANV2 GAN("GAN", "GAN");
633  GAN.setLevel(MSG::INFO);
634  const int etaMin = 20;
635  const int etaMax = etaMin + 5;
636  ATH_MSG_NOCLASS(logger, "Initialize Networks");
638  for (int i = 0; i < 24; ++i)
639  if (GAN.is_match_calosample(i)) {
641  Form("center%d", i), Form("center layer %d", i));
642  c->set_calosample(i);
643  c->setExtrapWeight(0.5);
644  c->setLevel(MSG::INFO);
645  c->set_pdgid(pid);
646  if (pid == 11)
647  c->add_pdgid(-pid);
648  if (pid == 211)
649  c->add_pdgid(-pid);
650  c->set_eta_min(etaMin / 100.0);
651  c->set_eta_max(etaMax / 100.0);
652  c->set_eta_nominal((etaMin + etaMax) / 200.0);
653 
654  GAN.push_back_in_bin(c, i);
655  GAN.set_nr_of_init(i, 1);
656  }
657 
658  GAN.Print();
659 
660  ATH_MSG_NOCLASS(logger, "Writing GAN to " << outputname);
661  const std::string outname = "FCSGANtest_" + outputname + ".root";
662  TFile *fGAN = TFile::Open(outname.c_str(), "recreate");
663  fGAN->cd();
664  // GAN.Write();
665  fGAN->WriteObjectAny(&GAN, "TFCSEnergyAndHitGANV2", "GAN");
666 
667  fGAN->ls();
668  fGAN->Close();
669 
670  ATH_MSG_NOCLASS(logger, "Open " << outname);
671  fGAN = TFile::Open(outname.c_str());
672  TFCSEnergyAndHitGANV2 *GAN2 = (TFCSEnergyAndHitGANV2 *)(fGAN->Get("GAN"));
673  GAN2->setLevel(MSG::INFO);
674  GAN2->Print();
675 
676  ATH_MSG_NOCLASS(logger, "Before running GAN2->simulate()");
677  GAN2->simulate(*simulstate, truth, extrapol);
678  simulstate->Print();
679 }
680 
682  if (bins < 4)
683  return 4;
684  else if (bins < 8)
685  return 8;
686  else if (bins < 16)
687  return 16;
688  else
689  return 32;
690 }
691 
693  int yBinNum) const {
694  double binsInAlphaInRBin = yBinNum;
695  if (yBinNum == 32) {
696  ATH_MSG_DEBUG("yBinNum is special value 32");
697  const double widthX = x->GetBinWidth(ix);
698  const double radious = x->GetBinCenter(ix);
699  double circumference = radious * 2 * TMath::Pi();
700  if (m_param.IsSymmetrisedAlpha()) {
701  circumference = radious * TMath::Pi();
702  }
703 
704  const double bins = circumference / widthX;
705  binsInAlphaInRBin = GetBinsInFours(bins);
706  ATH_MSG_DEBUG("Bin in alpha: " << binsInAlphaInRBin << " for r bin: " << ix
707  << " (" << x->GetBinLowEdge(ix) << "-"
708  << x->GetBinUpEdge(ix) << ")");
709  }
710  return binsInAlphaInRBin;
711 }
TFCSCenterPositionCalculation.h
TFCSGANXMLParameters::Print
void Print() const
Definition: TFCSGANXMLParameters.cxx:107
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
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
max
#define max(a, b)
Definition: cfImp.cxx:41
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
TFCSEnergyAndHitGANV2::initializeNetwork
bool initializeNetwork(int const &pid, int const &etaMin, const std::string &FastCaloGANInputFolderName)
Definition: TFCSEnergyAndHitGANV2.cxx:72
python.App.bins
bins
Definition: App.py:410
TFCSGANXMLParameters::InitialiseFromXML
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
Definition: TFCSGANXMLParameters.cxx:19
hist_file_dump.d
d
Definition: hist_file_dump.py:137
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
TFCSEnergyAndHitGANV2::GetBinsInFours
static int GetBinsInFours(double const &bins)
Definition: TFCSEnergyAndHitGANV2.cxx:681
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:29
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:90
TFCSEnergyAndHitGANV2::set_nr_of_init
void set_nr_of_init(unsigned int bin, unsigned int ninit)
Definition: TFCSEnergyAndHitGANV2.cxx:62
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TFCSEnergyAndHitGANV2.h
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
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
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:92
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:42
TFCSGANEtaSlice
Definition: TFCSGANEtaSlice.h:30
TFCSEnergyAndHitGANV2::GetAlphaBinsForRBin
int GetAlphaBinsForRBin(const TAxis *x, int ix, int yBinNum) const
Definition: TFCSEnergyAndHitGANV2.cxx:692
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
TH2D
Definition: rootspy.cxx:430
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
python.CreateTierZeroArgdict.outputs
outputs
Definition: CreateTierZeroArgdict.py:189
min
#define min(a, b)
Definition: cfImp.cxx:40
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:195
pmontree.opt
opt
Definition: pmontree.py:16
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:494
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:574
TFCSGANXMLParameters::GetGANVersion
int GetGANVersion() const
Definition: TFCSGANXMLParameters.h:41
TFCSGANEtaSlice::GetFitResults
FitResultsPerLayer GetFitResults() const
Definition: TFCSGANEtaSlice.h:51
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:518
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
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
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:48
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:115
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:56
TFCSTruthState
Definition: TFCSTruthState.h:13
TFCSEnergyAndHitGANV2::TFCSEnergyAndHitGANV2
TFCSEnergyAndHitGANV2(const char *name=nullptr, const char *title=nullptr)
Definition: TFCSEnergyAndHitGANV2.cxx:36
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:590
TFCSEnergyAndHitGANV2::Print
virtual void Print(Option_t *option="") const override
Definition: TFCSEnergyAndHitGANV2.cxx:539
TFCSSimulationState
Definition: TFCSSimulationState.h:32
TFCSGANXMLParameters::IsSymmetrisedAlpha
bool IsSymmetrisedAlpha() const
Definition: TFCSGANXMLParameters.h:42
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:39
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:108
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