ATLAS Offline Software
Loading...
Searching...
No Matches
TFCSGANXMLParameters Class Reference

#include <TFCSGANXMLParameters.h>

Inheritance diagram for TFCSGANXMLParameters:
Collaboration diagram for TFCSGANXMLParameters:

Public Types

typedef std::map< int, TH2D > Binning

Public Member Functions

 TFCSGANXMLParameters ()
virtual ~TFCSGANXMLParameters ()
void InitialiseFromXML (int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
void Print () const
const std::vector< int > & GetRelevantLayers () const
const BinningGetBinning () const
int GetLatentSpaceSize () const
int GetGANVersion () const
bool IsSymmetrisedAlpha () const
const std::string & GetInputFolder () const
void fixHists ()
bool msgLvl (const MSG::Level lvl) const
 Check whether the logging system is active at the provided verbosity level.
MsgStream & msg () const
 Return a stream for sending messages directly (no decoration).
MsgStream & msg (const MSG::Level lvl) const
 Return a decorated starting stream for sending messages.
MSG::Level level () const
 Retrieve output level.
virtual void setLevel (MSG::Level lvl)
 Update outputlevel.

Static Public Member Functions

static std::string startMsg (MSG::Level lvl, const std::string &file, int line)
 Make a message to decorate the start of logging.

Private Attributes

bool m_symmetrisedAlpha {}
Binning m_binning
std::vector< int > m_relevantlayers
int m_ganVersion {}
int m_latentDim {}
std::string m_fastCaloGANInputFolderName
std::string m_nm
 Message source name.

Static Private Attributes

static boost::thread_specific_ptr< MsgStream > m_msg_tls ATLAS_THREAD_SAFE
 Do not persistify!

Detailed Description

Definition at line 19 of file TFCSGANXMLParameters.h.

Member Typedef Documentation

◆ Binning

typedef std::map<int, TH2D> TFCSGANXMLParameters::Binning

Definition at line 21 of file TFCSGANXMLParameters.h.

Constructor & Destructor Documentation

◆ TFCSGANXMLParameters()

TFCSGANXMLParameters::TFCSGANXMLParameters ( )
default

◆ ~TFCSGANXMLParameters()

TFCSGANXMLParameters::~TFCSGANXMLParameters ( )
virtualdefault

Member Function Documentation

◆ fixHists()

void TFCSGANXMLParameters::fixHists ( )

Definition at line 125 of file TFCSGANXMLParameters.cxx.

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}

◆ GetBinning()

const Binning & TFCSGANXMLParameters::GetBinning ( ) const
inline

Definition at line 31 of file TFCSGANXMLParameters.h.

31{ return m_binning; };

◆ GetGANVersion()

int TFCSGANXMLParameters::GetGANVersion ( ) const
inline

Definition at line 33 of file TFCSGANXMLParameters.h.

◆ GetInputFolder()

const std::string & TFCSGANXMLParameters::GetInputFolder ( ) const
inline

Definition at line 35 of file TFCSGANXMLParameters.h.

std::string m_fastCaloGANInputFolderName

◆ GetLatentSpaceSize()

int TFCSGANXMLParameters::GetLatentSpaceSize ( ) const
inline

Definition at line 32 of file TFCSGANXMLParameters.h.

◆ GetRelevantLayers()

const std::vector< int > & TFCSGANXMLParameters::GetRelevantLayers ( ) const
inline

Definition at line 30 of file TFCSGANXMLParameters.h.

30{ return m_relevantlayers; };
std::vector< int > m_relevantlayers

◆ InitialiseFromXML()

void TFCSGANXMLParameters::InitialiseFromXML ( int pid,
int etaMid,
const std::string & FastCaloGANInputFolderName )

Definition at line 23 of file TFCSGANXMLParameters.cxx.

24 {
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) {
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}
#define M_PI
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< double > tokenizeDouble(std::string_view the_str, std::string_view delimiter)
@ layer
Definition HitInfo.h:79

◆ IsSymmetrisedAlpha()

bool TFCSGANXMLParameters::IsSymmetrisedAlpha ( ) const
inline

Definition at line 34 of file TFCSGANXMLParameters.h.

34{ return m_symmetrisedAlpha; };

◆ level()

MSG::Level ISF_FCS::MLogging::level ( ) const
inlineinherited

Retrieve output level.

Definition at line 201 of file MLogging.h.

201{ return msg().level(); }
MsgStream & msg() const
Return a stream for sending messages directly (no decoration).
Definition MLogging.h:231

◆ msg() [1/2]

MsgStream & ISF_FCS::MLogging::msg ( ) const
inlineinherited

Return a stream for sending messages directly (no decoration).

Definition at line 231 of file MLogging.h.

231 {
232 MsgStream *ms = m_msg_tls.get();
233 if (!ms) {
234 ms = new MsgStream(Athena::getMessageSvc(), m_nm);
235 m_msg_tls.reset(ms);
236 }
237 return *ms;
238}
std::string m_nm
Message source name.
Definition MLogging.h:211
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [2/2]

MsgStream & ISF_FCS::MLogging::msg ( const MSG::Level lvl) const
inlineinherited

Return a decorated starting stream for sending messages.

Definition at line 240 of file MLogging.h.

240 {
241 return msg() << lvl;
242}

◆ msgLvl()

bool ISF_FCS::MLogging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Check whether the logging system is active at the provided verbosity level.

Definition at line 222 of file MLogging.h.

222 {
223 if (msg().level() <= lvl) {
224 msg() << lvl;
225 return true;
226 } else {
227 return false;
228 }
229}
MSG::Level level() const
Retrieve output level.
Definition MLogging.h:201

◆ Print()

void TFCSGANXMLParameters::Print ( ) const

Definition at line 92 of file TFCSGANXMLParameters.cxx.

92 {
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}
#define ATH_MSG(lvl)
#define ATH_MSG_INFO(x)
#define END_MSG(lvl)
Definition MLogging.h:171
#define x
l
Printing final latex table to .tex output file.

◆ setLevel()

void ISF_FCS::MLogging::setLevel ( MSG::Level lvl)
virtualinherited

Update outputlevel.

Definition at line 105 of file MLogging.cxx.

105 {
106 lvl = (lvl >= MSG::NUM_LEVELS) ? MSG::ALWAYS
107 : (lvl < MSG::NIL) ? MSG::NIL
108 : lvl;
109 msg().setLevel(lvl);
110}

◆ startMsg()

std::string ISF_FCS::MLogging::startMsg ( MSG::Level lvl,
const std::string & file,
int line )
staticinherited

Make a message to decorate the start of logging.

Print a message for the start of logging.

Definition at line 116 of file MLogging.cxx.

116 {
117 int col1_len = 20;
118 int col2_len = 5;
119 int col3_len = 10;
120 auto last_slash = file.find_last_of('/');
121 int path_len = last_slash == std::string::npos ? 0 : last_slash;
122 int trim_point = path_len;
123 int total_len = file.length();
124 if (total_len - path_len > col1_len)
125 trim_point = total_len - col1_len;
126 std::string trimmed_name = file.substr(trim_point);
127 const char *LevelNames[MSG::NUM_LEVELS] = {
128 "NIL", "VERBOSE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL", "ALWAYS"};
129 std::string level = LevelNames[lvl];
130 std::string level_string = std::string("(") + level + ") ";
131 std::stringstream output;
132 output << std::setw(col1_len) << std::right << trimmed_name << ":"
133 << std::setw(col2_len) << std::left << line << std::setw(col3_len)
134 << std::right << level_string;
135 return output.str();
136}
output
Definition merge.py:16
TFile * file

Member Data Documentation

◆ ATLAS_THREAD_SAFE

boost::thread_specific_ptr<MsgStream> m_msg_tls ISF_FCS::MLogging::ATLAS_THREAD_SAFE
inlinestaticprivateinherited

Do not persistify!

MsgStream instance (a std::cout like with print-out levels)

Definition at line 215 of file MLogging.h.

◆ m_binning

Binning TFCSGANXMLParameters::m_binning
private

Definition at line 43 of file TFCSGANXMLParameters.h.

◆ m_fastCaloGANInputFolderName

std::string TFCSGANXMLParameters::m_fastCaloGANInputFolderName
private

Definition at line 47 of file TFCSGANXMLParameters.h.

◆ m_ganVersion

int TFCSGANXMLParameters::m_ganVersion {}
private

Definition at line 45 of file TFCSGANXMLParameters.h.

45{};

◆ m_latentDim

int TFCSGANXMLParameters::m_latentDim {}
private

Definition at line 46 of file TFCSGANXMLParameters.h.

46{};

◆ m_nm

std::string ISF_FCS::MLogging::m_nm
privateinherited

Message source name.

Definition at line 211 of file MLogging.h.

◆ m_relevantlayers

std::vector<int> TFCSGANXMLParameters::m_relevantlayers
private

Definition at line 44 of file TFCSGANXMLParameters.h.

◆ m_symmetrisedAlpha

bool TFCSGANXMLParameters::m_symmetrisedAlpha {}
private

Definition at line 42 of file TFCSGANXMLParameters.h.

42{};

The documentation for this class was generated from the following files: