15 #include "HepPDT/ParticleData.hh"
16 #include "HepPDT/ParticleDataTable.hh"
18 #include "CLHEP/Random/RandGauss.h"
19 #include "CLHEP/Random/RandFlat.h"
21 #if defined(__FastCaloSimStandAlone__)
22 #include "CLHEP/Random/TRandomEngine.h"
24 #include <CLHEP/Random/RanluxEngine.h>
32 #include "lwtnn/LightweightGraph.hh"
33 #include "lwtnn/parse_json.hh"
36 #include <libxml/xmlmemory.h>
37 #include <libxml/parser.h>
38 #include <libxml/tree.h>
39 #include <libxml/xmlreader.h>
40 #include <libxml/xpath.h>
41 #include <libxml/xpathInternals.h>
85 int pid,
int etaMin,
const std::string &FastCaloGANInputFolderName) {
91 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
115 std::stringstream
sin;
144 int pid,
int etaMid,
const std::string &FastCaloGANInputFolderName) {
145 std::string xmlFullFileName = FastCaloGANInputFolderName +
"/binning.xml";
148 std::vector<Binning> AllBinning;
149 std::vector<int> EtaMaxList;
151 xmlDocPtr
doc = xmlParseFile(xmlFullFileName.c_str());
152 for (xmlNodePtr nodeRoot =
doc->children; nodeRoot !=
nullptr;
153 nodeRoot = nodeRoot->next) {
154 if (xmlStrEqual(nodeRoot->name, BAD_CAST
"Bins")) {
155 for (xmlNodePtr nodeBin = nodeRoot->children; nodeBin !=
nullptr;
156 nodeBin = nodeBin->next) {
157 if (xmlStrEqual(nodeBin->name, BAD_CAST
"Bin")) {
158 int nodePid =
atof((
const char *)xmlGetProp(nodeBin, BAD_CAST
"pid"));
162 atof((
const char *)xmlGetProp(nodeBin, BAD_CAST
"etaMax"));
165 bool correctentry =
true;
167 correctentry =
false;
169 for (xmlNodePtr nodeLayer = nodeBin->children; nodeLayer !=
nullptr;
170 nodeLayer = nodeLayer->next) {
171 if (xmlStrEqual(nodeLayer->name, BAD_CAST
"Layer")) {
172 std::vector<double> edges;
174 (
const char *)xmlGetProp(nodeLayer, BAD_CAST
"r_edges"));
176 std::istringstream
ss(
s);
179 while (std::getline(
ss, token,
',')) {
180 edges.push_back(
atof(token.c_str()));
183 int binsInAlpha =
atof(
184 (
const char *)xmlGetProp(nodeLayer, BAD_CAST
"n_bin_alpha"));
186 atof((
const char *)xmlGetProp(nodeLayer, BAD_CAST
"id"));
190 << nodeEtaMax <<
" Layer: " <<
layer
191 <<
" binsInAlpha: " << binsInAlpha
198 int xBins = edges.size() - 1;
206 binsInAlpha, -TMath::Pi(), TMath::Pi());
207 binsInLayer[
layer].SetDirectory(
nullptr);
213 AllBinning.push_back(binsInLayer);
214 EtaMaxList.push_back(nodeEtaMax);
221 for (
int etaMax : EtaMaxList) {
237 Form(
"layer=%d", simulstate.
getAuxInfo<
int>(
"GANlayer"_FCShash)));
245 trueEnergy = truth->P();
246 double randUniformZ = 0.;
249 randUniformZ = CLHEP::RandFlat::shoot(simulstate.
randomEngine(), -1., 1.);
257 std::pair<std::string, double>(
"0", trueEnergy / (
std::pow(2, 22))));
266 const int pdgId = truth->
pdgid();
270 const float Ekin = truth->
Ekin();
272 Einit = simulstate.
E();
292 for (
const auto& element : binsInLayers) {
293 int layer = element.first;
295 const TH2D *
h = &element.second;
296 int xBinNum =
h->GetNbinsX();
301 <<
" has only one bin in r, this means is it not used, "
302 "skipping (this is needed to keep correct "
303 "syncronisation of voxel and layers)");
310 int yBinNum =
h->GetNbinsY();
313 for (
int iy = 1; iy <= yBinNum; ++iy) {
314 for (
int ix = 1; ix <= xBinNum; ++ix) {
317 <<
" binx " << ix <<
" biny " << iy);
319 if (energyInVoxel == 0) {
324 simulstate.
add_E(
layer, Einit * energyInVoxel);
330 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
339 for (
const auto& element : binsInLayers) {
340 int layer = element.first;
344 const TH2D *
h = &element.second;
345 int xBinNum =
h->GetNbinsX();
350 <<
" has only one bin in r, this means is it not used, "
351 "skipping (this is needed to keep correct "
352 "syncronisation of voxel and layers)");
366 <<
chain()[ichain]->GetName());
367 if (
chain()[ichain]->InheritsFrom(
368 TFCSLateralShapeParametrizationHitBase::Class())) {
376 <<
chain()[ichain]->GetName());
383 <<
chain()[ichain]->GetName()
384 <<
" does not inherit from "
385 "TFCSLateralShapeParametrizationHitBase");
396 int binResolution = 5;
401 const double center_eta = hit.center_eta();
402 const double center_phi = hit.center_phi();
403 const double center_r = hit.center_r();
404 const double center_z = hit.center_z();
407 <<
" phi " << center_phi <<
" R " << center_r);
409 const float dist000 =
410 TMath::Sqrt(center_r * center_r + center_z * center_z);
411 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
412 (1.0 + TMath::Exp(-2 * center_eta)));
417 int yBinNum =
h->GetNbinsY();
420 for (
int iy = 1; iy <= yBinNum; ++iy) {
421 for (
int ix = 1; ix <= xBinNum; ++ix) {
425 <<
" binx " << ix <<
" biny " << iy);
427 if (energyInVoxel == 0) {
432 const TAxis *
x =
h->GetXaxis();
433 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
436 double r =
x->GetBinUpEdge(ix);
437 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
441 const TAxis *
y =
h->GetYaxis();
442 double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
443 double r =
x->GetBinUpEdge(ix);
445 nHitsAlpha = ceil(
d / binResolution);
451 for (
int ir = 0;
ir < nHitsR; ++
ir) {
452 const TAxis *
x =
h->GetXaxis();
454 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
456 for (
int ialpha = 0; ialpha < nHitsAlpha; ++ialpha) {
462 const TAxis *
y =
h->GetYaxis();
463 alpha =
y->GetBinLowEdge(iy) +
464 y->GetBinWidth(iy) / (nHitsAlpha + 1) * ialpha;
468 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
471 float delta_eta_mm =
r *
cos(alpha);
472 float delta_phi_mm =
r *
sin(alpha);
482 delta_eta_mm = -delta_eta_mm;
486 if ((
charge < 0. && pdgId!=11) || pdgId==-11)
487 delta_phi_mm = -delta_phi_mm;
489 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
490 const float delta_phi = delta_phi_mm / center_r;
492 hit.eta() = center_eta + delta_eta;
496 <<
" layer " <<
layer);
498 const float hit_r =
r *
cos(alpha) + center_r;
504 if ((
charge < 0. && pdgId!=11) || pdgId==-11)
506 const float hit_phi =
delta_phi + center_phi;
507 hit.x() = hit_r *
cos(hit_phi);
508 hit.y() = hit_r *
sin(hit_phi);
511 <<
" layer " <<
layer);
517 for (
unsigned int ichain =
523 <<
chain()[ichain]->GetName());
524 if (
chain()[ichain]->InheritsFrom(
525 TFCSLateralShapeParametrizationHitBase::Class())) {
535 <<
chain()[ichain]->GetName());
542 <<
chain()[ichain]->GetName()
543 <<
" does not inherit from "
544 "TFCSLateralShapeParametrizationHitBase");
568 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
570 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
583 for (
unsigned int ichain = 0; ichain <
m_bin_start[0]; ++ichain) {
614 bool shortprint =
opt.Index(
"short") >= 0;
616 TString optprint =
opt;
617 optprint.ReplaceAll(
"short",
"");
625 <<
"; Binning size=" <<
m_Binning.size());
629 <<
"layer=" <<
l.first
630 <<
" nR=" <<
l.second.GetNbinsX()
631 <<
" nalpha=" <<
l.second.GetNbinsY());
636 for (
unsigned int ichain = 0; ichain <
size(); ++ichain) {
637 if (ichain == 0 && ichain !=
m_bin_start.front()) {
647 prefix = Form(
"%-2d", ibin);
661 void TFCSEnergyAndHitGAN::Streamer(TBuffer &R__b) {
664 if (R__b.IsReading()) {
665 R__b.ReadClassBuffer(TFCSEnergyAndHitGAN::Class(),
this);
671 std::stringstream
sin;
676 #ifndef __FastCaloSimStandAlone__
684 R__b.WriteClassBuffer(TFCSEnergyAndHitGAN::Class(),
this);
693 #if defined(__FastCaloSimStandAlone__)
701 t->SetPtEtaPhiM(20000, 0.225, 0, 130);
707 e->set_IDCaloBoundary_eta(truth->Eta());
708 for (
int i = 0;
i < 24; ++
i) {
732 "/eos/atlas/atlascerngroupdisk/proj-simul/VoxalisationOutputs/nominal/"
733 "GAN_michele_normE_MaxE/input_for_service_new");
734 for (
int i = 0;
i < 24; ++
i)
737 Form(
"center%d",
i), Form(
"center layer %d",
i));
738 c->set_calosample(
i);
739 c->setExtrapWeight(0.5);
746 c->set_eta_min(
etaMin / 100.0);
747 c->set_eta_max(
etaMax / 100.0);
756 TFile *fGAN = TFile::Open(
"FCSGANtest.root",
"recreate");
761 fGAN = TFile::Open(
"FCSGANtest.root");