ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSGANXMLParameters.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TFCSGANXMLParameters.cxx, (c) ATLAS Detector software //
8
9// Class header include
11
13
15
17 int pid, int etaMid, const std::string& FastCaloGANInputFolderName) {
18
19 m_fastCaloGANInputFolderName = FastCaloGANInputFolderName;
20 std::string xmlFullFileName = FastCaloGANInputFolderName + "/binning.xml";
21
22 // Parse the XML file
23 xmlDocPtr doc = xmlParseFile(xmlFullFileName.c_str());
24 if (!doc) {
25 ATH_MSG_WARNING("Failed to parse XML file: " << xmlFullFileName);
26 return;
27 }
28
29 for (xmlNodePtr nodeRoot = doc->children; nodeRoot != nullptr;
30 nodeRoot = nodeRoot->next) {
31 if (xmlStrEqual(nodeRoot->name, BAD_CAST "Bins")) {
32 for (xmlNodePtr nodeParticle = nodeRoot->children;
33 nodeParticle != nullptr; nodeParticle = nodeParticle->next) {
34 if (xmlStrEqual(nodeParticle->name, BAD_CAST "Particle")) {
35 int nodePid = std::stoi(reinterpret_cast<const char*>(
36 xmlGetProp(nodeParticle, BAD_CAST "pid")));
37
38 if (nodePid == pid) {
39 for (xmlNodePtr nodeBin = nodeParticle->children;
40 nodeBin != nullptr; nodeBin = nodeBin->next) {
41 if (xmlStrEqual(nodeBin->name, BAD_CAST "Bin")) {
42 int nodeEtaMin = std::stoi(reinterpret_cast<const char*>(
43 xmlGetProp(nodeBin, BAD_CAST "etaMin")));
44 int nodeEtaMax = std::stoi(reinterpret_cast<const char*>(
45 xmlGetProp(nodeBin, BAD_CAST "etaMax")));
46 int regionId = std::stoi(reinterpret_cast<const char*>(
47 xmlGetProp(nodeBin, BAD_CAST "regionId")));
48
49 if (std::abs(etaMid) > nodeEtaMin &&
50 std::abs(etaMid) < nodeEtaMax) {
51
53 ReadBooleanAttribute("symmetriseAlpha", nodeParticle);
54 m_ganVersion = std::stod(reinterpret_cast<const char*>(
55 xmlGetProp(nodeBin, BAD_CAST "ganVersion")));
56 m_latentDim = std::stod(reinterpret_cast<const char*>(
57 xmlGetProp(nodeParticle, BAD_CAST "latentDim")));
58
59 for (xmlNodePtr nodeLayer = nodeBin->children;
60 nodeLayer != nullptr; nodeLayer = nodeLayer->next) {
61 if (xmlStrEqual(nodeLayer->name, BAD_CAST "Layer")) {
62 std::vector<double> edges;
63 std::string s(reinterpret_cast<const char*>(
64 xmlGetProp(nodeLayer, BAD_CAST "r_edges")));
65
66 std::istringstream ss(s);
67 std::string token;
68
69 while (std::getline(ss, token, ',')) {
70 edges.push_back(std::stod(token));
71 }
72
73 int binsInAlpha = std::stoi(reinterpret_cast<const char*>(
74 xmlGetProp(nodeLayer, BAD_CAST "n_bin_alpha")));
75 int layer = std::stoi(reinterpret_cast<const char*>(
76 xmlGetProp(nodeLayer, BAD_CAST "id")));
77
78 std::string name = "hist_pid_" + std::to_string(nodePid) +
79 "_region_" + std::to_string(regionId) +
80 "_layer_" + std::to_string(layer);
81 int xBins = static_cast<int>(edges.size()) - 1;
82
83 if (xBins <= 0) {
85 "No bins defined in r for layer "
86 << layer
87 << ", setting to 1 bin to avoid empty histogram");
88 xBins = 1; // Remove warning and set a default bin
89 edges.push_back (edges.back()+1);
90 } else {
91 m_relevantlayers.push_back(layer);
92 }
93
94 double minAlpha = -M_PI;
95 if (m_symmetrisedAlpha && binsInAlpha > 1) {
96 minAlpha = 0;
97 }
98 // Create histogram and add to binning map
99 auto itr = m_binning.emplace(
100 layer,
101 TH2D(name.c_str(), name.c_str(), xBins, edges.data(),
102 binsInAlpha, minAlpha, M_PI));
103 itr.first->second.SetDirectory(nullptr);
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 }
112 }
113 }
114
115 // Free XML document after parsing
116 xmlFreeDoc(doc);
117}
118
120 xmlNodePtr node) {
121 std::string attribute =
122 reinterpret_cast<const char*>(xmlGetProp(node, BAD_CAST name.c_str()));
123 return attribute == "true";
124}
125
127 ATH_MSG_INFO("Parameters taken from XML");
128 ATH_MSG_INFO(" symmetrisedAlpha: " << m_symmetrisedAlpha);
129 ATH_MSG_INFO(" ganVersion:" << m_ganVersion);
130 ATH_MSG_INFO(" latentDim: " << m_latentDim);
131 ATH_MSG(INFO) << " relevantlayers: ";
132 for (const auto& l : m_relevantlayers) {
133 ATH_MSG(INFO) << l << " ";
134 }
135 ATH_MSG(INFO) << END_MSG(INFO);
136
137 for (const auto& element : m_binning) {
138 int layer = element.first;
139 const TH2D* h = &element.second;
140
141 // attempt to debug intermittent ci issues described in
142 // https://its.cern.ch/jira/browse/ATLASSIM-7031
143 if (h->IsZombie()) {
144 ATH_MSG_WARNING("Histogram pointer for layer "
145 << layer << " is broken. Skipping.");
146 continue;
147 }
148
149 int xBinNum = h->GetNbinsX();
150 const TAxis* x = h->GetXaxis();
151
152 if (xBinNum == 1) {
153 ATH_MSG_INFO("layer " << layer << " not used");
154 continue;
155 }
156 ATH_MSG_INFO("Binning along r for layer " << layer);
157 ATH_MSG(INFO) << "0,";
158 // First fill energies
159 for (int ix = 1; ix <= xBinNum; ++ix) {
160 ATH_MSG(INFO) << x->GetBinUpEdge(ix) << ",";
161 }
162 ATH_MSG(INFO) << END_MSG(INFO);
163 }
164}
#define M_PI
#define ATH_MSG(lvl)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t ss
#define END_MSG(lvl)
Definition MLogging.h:171
#define x
Header file for AthHistogramAlgorithm.
virtual ~TFCSGANXMLParameters()
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
std::string m_fastCaloGANInputFolderName
std::vector< int > m_relevantlayers
static bool ReadBooleanAttribute(const std::string &name, xmlNodePtr node)
Definition node.h:24