ATLAS Offline Software
TFCSGANXMLParameters.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TFCSGANXMLParameters.cxx, (c) ATLAS Detector software //
8 
9 // class header include
11 #include <sstream>
12 #include "TMath.h"
13 #include <iostream>
14 
16 
18 
20  int pid, int etaMid, const std::string &FastCaloGANInputFolderName) {
21  m_fastCaloGANInputFolderName = FastCaloGANInputFolderName;
22  std::string xmlFullFileName = FastCaloGANInputFolderName + "/binning.xml";
23 
24  xmlDocPtr doc = xmlParseFile(xmlFullFileName.c_str());
25  for (xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr;
26  nodeRoot = nodeRoot->next) {
27  if (xmlStrEqual(nodeRoot->name, BAD_CAST "Bins")) {
28  for (xmlNodePtr nodeParticle = nodeRoot->children;
29  nodeParticle != nullptr; nodeParticle = nodeParticle->next) {
30  if (xmlStrEqual(nodeParticle->name, BAD_CAST "Particle")) {
31  int nodePid =
32  atof((const char *)xmlGetProp(nodeParticle, BAD_CAST "pid"));
33  for (xmlNodePtr nodeBin = nodeParticle->children; nodeBin != nullptr;
34  nodeBin = nodeBin->next) {
35  if (nodePid == pid) {
36  if (xmlStrEqual(nodeBin->name, BAD_CAST "Bin")) {
37  int nodeEtaMin =
38  atof((const char *)xmlGetProp(nodeBin, BAD_CAST "etaMin"));
39  int nodeEtaMax =
40  atof((const char *)xmlGetProp(nodeBin, BAD_CAST "etaMax"));
41  int regionId = atof(
42  (const char *)xmlGetProp(nodeBin, BAD_CAST "regionId"));
43 
44  if (std::abs(etaMid) > nodeEtaMin && std::abs(etaMid) < nodeEtaMax) {
45 
47  ReadBooleanAttribute("symmetriseAlpha", nodeParticle);
49  (const char *)xmlGetProp(nodeBin, BAD_CAST "ganVersion"));
50  m_latentDim = atof((const char *)xmlGetProp(
51  nodeParticle, BAD_CAST "latentDim"));
52 
53  for (xmlNodePtr nodeLayer = nodeBin->children;
54  nodeLayer != nullptr; nodeLayer = nodeLayer->next) {
55  if (xmlStrEqual(nodeLayer->name, BAD_CAST "Layer")) {
56  std::vector<double> edges;
57  std::string s((const char *)xmlGetProp(nodeLayer, BAD_CAST
58  "r_edges"));
59 
60  std::istringstream ss(s);
61  std::string token;
62 
63  while (std::getline(ss, token, ',')) {
64  edges.push_back(atof(token.c_str()));
65  }
66 
67  int binsInAlpha = atof((const char *)xmlGetProp(
68  nodeLayer, BAD_CAST "n_bin_alpha"));
69  int layer = atof(
70  (const char *)xmlGetProp(nodeLayer, BAD_CAST "id"));
71 
72  std::string name = "hist_pid_" + std::to_string(nodePid) +
73  "_region_" + std::to_string(regionId) +
74  "_layer_" + std::to_string(layer);
75  int xBins = edges.size() - 1;
76  if (xBins == 0)
77  xBins = 1; // remove warning
78  else
79  m_relevantlayers.push_back(layer);
80  double minAlpha = -TMath::Pi();
81  if (m_symmetrisedAlpha && binsInAlpha > 1) {
82  minAlpha = 0;
83  }
84  m_binning[layer] =
85  TH2D(name.c_str(), name.c_str(), xBins, &edges[0],
86  binsInAlpha, minAlpha, TMath::Pi());
87  }
88  }
89  }
90  }
91  }
92  }
93  }
94  }
95  }
96  }
97  xmlFreeDoc(doc);
98 }
99 
101  xmlNodePtr node) {
102  std::string attribute = (const char *)xmlGetProp(node, BAD_CAST name.c_str());
103  bool value = attribute == "true" ? true : false;
104  return value;
105 }
106 
108  ATH_MSG_INFO("Parameters taken from XML");
109  ATH_MSG_INFO(" symmetrisedAlpha: " << m_symmetrisedAlpha);
110  ATH_MSG_INFO(" ganVersion:" << m_ganVersion);
111  ATH_MSG_INFO(" latentDim: " << m_latentDim);
112  ATH_MSG(INFO) << " relevantlayers: ";
113  for (auto l : m_relevantlayers) {
114  ATH_MSG(INFO) << l << " ";
115  }
116  ATH_MSG(INFO) << END_MSG(INFO);
117 
118  for (auto element : m_binning) {
119  int layer = element.first;
120  TH2D *h = &element.second;
121 
122  int xBinNum = h->GetNbinsX();
123  TAxis *x = (TAxis *)h->GetXaxis();
124 
125  // If only one bin in r means layer is empty, no value should be added
126  if (xBinNum == 1) {
127  ATH_MSG_INFO("layer " << layer << " not used");
128  continue;
129  }
130  ATH_MSG_INFO("Binning along r for layer " << layer);
131  ATH_MSG(INFO) << "0,";
132  // First fill energies
133  for (int ix = 1; ix <= xBinNum; ++ix) {
134  ATH_MSG(INFO) << x->GetBinUpEdge(ix) << ",";
135  }
136  ATH_MSG(INFO) << END_MSG(INFO);
137  }
138 }
TFCSGANXMLParameters::Print
void Print() const
Definition: TFCSGANXMLParameters.cxx:107
TFCSGANXMLParameters::m_symmetrisedAlpha
bool m_symmetrisedAlpha
Definition: TFCSGANXMLParameters.h:48
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ATH_MSG
#define ATH_MSG(lvl)
Definition: AthMsgStreamMacros.h:38
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TFCSGANXMLParameters::InitialiseFromXML
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
Definition: TFCSGANXMLParameters.cxx:19
TFCSGANXMLParameters.h
athena.value
value
Definition: athena.py:122
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
x
#define x
TFCSGANXMLParameters::m_binning
Binning m_binning
Definition: TFCSGANXMLParameters.h:49
TFCSGANXMLParameters::m_fastCaloGANInputFolderName
std::string m_fastCaloGANInputFolderName
Definition: TFCSGANXMLParameters.h:53
TFCSGANXMLParameters::ReadBooleanAttribute
static bool ReadBooleanAttribute(const std::string &name, xmlNodePtr node)
Definition: TFCSGANXMLParameters.cxx:100
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
TFCSGANXMLParameters::TFCSGANXMLParameters
TFCSGANXMLParameters()
Definition: TFCSGANXMLParameters.cxx:15
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
TFCSGANXMLParameters::~TFCSGANXMLParameters
virtual ~TFCSGANXMLParameters()
Definition: TFCSGANXMLParameters.cxx:17
TH2D
Definition: rootspy.cxx:430
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
merge_scale_histograms.doc
string doc
Definition: merge_scale_histograms.py:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TFCSGANXMLParameters::m_relevantlayers
std::vector< int > m_relevantlayers
Definition: TFCSGANXMLParameters.h:50
END_MSG
#define END_MSG(lvl)
Definition: MLogging.h:171
h
TFCSGANXMLParameters::m_latentDim
int m_latentDim
Definition: TFCSGANXMLParameters.h:52
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:16
MakeTH3DFromTH2Ds.xBins
list xBins
Definition: MakeTH3DFromTH2Ds.py:76
node
Definition: memory_hooks-stdcmalloc.h:74
TFCSGANXMLParameters::m_ganVersion
int m_ganVersion
Definition: TFCSGANXMLParameters.h:51