ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_FastCaloSimEvent
src
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
10
#include "
ISF_FastCaloSimEvent/TFCSGANXMLParameters.h
"
11
12
#include "
XMLCoreParser/XMLCoreParser.h
"
13
#include "
XMLCoreParser/XMLCoreNode.h
"
14
15
#include "
CxxUtils/hexdump.h
"
16
#include "
CxxUtils/StringUtils.h
"
17
#include <format>
18
19
TFCSGANXMLParameters::TFCSGANXMLParameters
() =
default
;
20
21
TFCSGANXMLParameters::~TFCSGANXMLParameters
() =
default
;
22
23
void
TFCSGANXMLParameters::InitialiseFromXML
(
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
30
XMLCoreParser
p;
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) {
64
ATH_MSG_DEBUG
(
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
92
void
TFCSGANXMLParameters::Print
()
const
{
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
125
void
TFCSGANXMLParameters::fixHists
()
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
}
M_PI
#define M_PI
Definition
ActiveFraction.h:14
ATH_MSG
#define ATH_MSG(lvl)
Definition
AthMsgStreamMacros.h:38
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
StringUtils.h
END_MSG
#define END_MSG(lvl)
Definition
MLogging.h:171
TFCSGANXMLParameters.h
x
#define x
XMLCoreNode.h
Simple DOM-like node structure to hold the result of XML parsing.
XMLCoreParser.h
h
Header file for AthHistogramAlgorithm.
TFCSGANXMLParameters::Print
void Print() const
Definition
TFCSGANXMLParameters.cxx:92
TFCSGANXMLParameters::~TFCSGANXMLParameters
virtual ~TFCSGANXMLParameters()
TFCSGANXMLParameters::fixHists
void fixHists()
Definition
TFCSGANXMLParameters.cxx:125
TFCSGANXMLParameters::m_symmetrisedAlpha
bool m_symmetrisedAlpha
Definition
TFCSGANXMLParameters.h:42
TFCSGANXMLParameters::m_binning
Binning m_binning
Definition
TFCSGANXMLParameters.h:43
TFCSGANXMLParameters::m_ganVersion
int m_ganVersion
Definition
TFCSGANXMLParameters.h:45
TFCSGANXMLParameters::InitialiseFromXML
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
Definition
TFCSGANXMLParameters.cxx:23
TFCSGANXMLParameters::m_latentDim
int m_latentDim
Definition
TFCSGANXMLParameters.h:46
TFCSGANXMLParameters::m_fastCaloGANInputFolderName
std::string m_fastCaloGANInputFolderName
Definition
TFCSGANXMLParameters.h:47
TFCSGANXMLParameters::m_relevantlayers
std::vector< int > m_relevantlayers
Definition
TFCSGANXMLParameters.h:44
TFCSGANXMLParameters::TFCSGANXMLParameters
TFCSGANXMLParameters()
XMLCoreNode
Simple DOM-like node structure to hold the result of XML parsing.
Definition
XMLCoreNode.h:46
XMLCoreNode::get_children
std::vector< const XMLCoreNode * > get_children(const std::string &path="*") const
Return all children matching a pattern.
Definition
XMLCoreNode.cxx:288
XMLCoreParser
Definition
XMLCoreParser.h:46
hexdump.h
Helpers to make a nice dump of a region of memory.
CxxUtils::tokenizeDouble
std::vector< double > tokenizeDouble(std::string_view the_str, std::string_view delimiter)
Definition
Control/CxxUtils/Root/StringUtils.cxx:23
Generated on
for ATLAS Offline Software by
1.17.0