ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSGANXMLParameters.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// TFCSGANXMLParameters.cxx, (c) ATLAS Detector software //
8
9// Class header include
11
14
15#include "CxxUtils/hexdump.h"
17#include <format>
18
20
22
24 int pid, int etaMid, const std::string& FastCaloGANInputFolderName) {
25
26 m_fastCaloGANInputFolderName = FastCaloGANInputFolderName;
27 std::string xmlFullFileName = FastCaloGANInputFolderName + "/binning.xml";
28
29 // Parse the XML file
31 std::unique_ptr<XMLCoreNode> doc = p.parse (xmlFullFileName);
32
33 if (!doc) {
34 ATH_MSG_WARNING("Failed to parse XML file: " << xmlFullFileName);
35 return;
36 }
37
38 for (const XMLCoreNode* nodeParticle : doc->get_children ("Bins/Particle")) {
39 if (nodeParticle->get_int_attrib ("pid") == pid) {
40 for (const XMLCoreNode* nodeBin : nodeParticle->get_children ("Bin")) {
41 int nodeEtaMin = nodeBin->get_int_attrib ("etaMin");
42 int nodeEtaMax = nodeBin->get_int_attrib ("etaMax");
43 int regionId = nodeBin->get_int_attrib ("regionId");
44
45 if (std::abs(etaMid) > nodeEtaMin &&
46 std::abs(etaMid) < nodeEtaMax)
47 {
48 m_symmetrisedAlpha = nodeBin->has_attrib ("symmetriseAlpha") &&
49 nodeBin->get_attrib ("symmetriseAlpha") == "true";
50 m_ganVersion = nodeBin->get_int_attrib ("ganVersion");
51 m_latentDim = nodeParticle->get_int_attrib ("latentDim");
52
53 for (const XMLCoreNode* nodeLayer : nodeBin->get_children ("Layer")) {
54 const std::string &rEdgesStr = nodeLayer->get_attrib("r_edges");
55 std::vector<double> edges = CxxUtils::tokenizeDouble(rEdgesStr, ",");
56
57 int binsInAlpha = nodeLayer->get_int_attrib ("n_bin_alpha");
58 int layer = nodeLayer->get_int_attrib ("id");
59
60 const std::string name = std::format("hist_pid_{}_region_{}_layer_{}", pid, regionId, layer);
61 int xBins = static_cast<int>(edges.size()) - 1;
62
63 if (xBins <= 0) {
65 "No bins defined in r for layer "
66 << layer
67 << ", setting to 1 bin to avoid empty histogram");
68 xBins = 1; // Remove warning and set a default bin
69 edges.push_back (edges.back()+1);
70 } else {
71 m_relevantlayers.push_back(layer);
72 }
73
74 double minAlpha = -M_PI;
75 if (m_symmetrisedAlpha && binsInAlpha > 1) {
76 minAlpha = 0;
77 }
78 // Create histogram and add to binning map
79 auto itr = m_binning.emplace(
80 layer,
81 TH2D(name.c_str(), name.c_str(), xBins, edges.data(),
82 binsInAlpha, minAlpha, M_PI));
83 itr.first->second.SetDirectory(nullptr);
84 ROOT::Internal::MarkTObjectAsNotOnHeap(itr.first->second);
85 }
86 }
87 }
88 }
89 }
90}
91
93 ATH_MSG_INFO("Parameters taken from XML");
94 ATH_MSG_INFO(" symmetrisedAlpha: " << m_symmetrisedAlpha);
95 ATH_MSG_INFO(" ganVersion:" << m_ganVersion);
96 ATH_MSG_INFO(" latentDim: " << m_latentDim);
97 ATH_MSG(INFO) << " relevantlayers: ";
98 for (const auto& l : m_relevantlayers) {
99 ATH_MSG(INFO) << l << " ";
100 }
101 ATH_MSG(INFO) << END_MSG(INFO);
102
103 for (const auto& element : m_binning) {
104 int layer = element.first;
105 const TH2D* h = &element.second;
106
107 int xBinNum = h->GetNbinsX();
108 const TAxis* x = h->GetXaxis();
109
110 if (xBinNum == 1) {
111 ATH_MSG_INFO("layer " << layer << " not used");
112 continue;
113 }
114 ATH_MSG_INFO("Binning along r for layer " << layer);
115 ATH_MSG(INFO) << "0,";
116 // First fill energies
117 for (int ix = 1; ix <= xBinNum; ++ix) {
118 ATH_MSG(INFO) << x->GetBinUpEdge(ix) << ",";
119 }
120 ATH_MSG(INFO) << END_MSG(INFO);
121 }
122}
123
124
126{
127 for (auto &[layer, h] : m_binning) {
128 // The histograms we've read in are in an STL container.
129 // Rarely, ROOT can falsely set the kIsOnHeap flag on one of them.
130 // In that case, it will try to delete the histogram when the
131 // file is closed, which will lead to a crash later on.
132 // Make sure kIsOnHeap is clear, and also make sure that nobody else
133 // thinks that they own one of these histograms.
134 // See ATLASSIM-7031.
135 h.SetDirectory (nullptr);
136 h.ResetBit (TObject::kIsOnHeap);
137 }
138}
#define M_PI
#define ATH_MSG(lvl)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define END_MSG(lvl)
Definition MLogging.h:171
#define x
Simple DOM-like node structure to hold the result of XML parsing.
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
Simple DOM-like node structure to hold the result of XML parsing.
Definition XMLCoreNode.h:46
std::vector< const XMLCoreNode * > get_children(const std::string &path="*") const
Return all children matching a pattern.
Helpers to make a nice dump of a region of memory.
std::vector< double > tokenizeDouble(std::string_view the_str, std::string_view delimiter)