ATLAS Offline Software
Loading...
Searching...
No Matches
SysListDumperAlg.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
7
8//
9// includes
10//
11
12#include <regex>
14#include <TH1.h>
15
16//
17// method implementations
18//
19
20namespace CP
21{
22
23 StatusCode SysListDumperAlg ::
24 initialize ()
25 {
26 if (m_histogramName.empty())
27 {
28 ANA_MSG_ERROR ("histogram name should not be empty");
29 return StatusCode::FAILURE;
30 }
31
33
34 return StatusCode::SUCCESS;
35 }
36
37
38
39 StatusCode SysListDumperAlg ::
40 execute ()
41 {
42 if (!m_firstEvent)
43 {
44 return StatusCode::SUCCESS;
45 }
46
47 m_firstEvent = false;
48
49 const std::vector<CP::SystematicSet> systematics = makeSystematicsVector (m_regex);
50 if (systematics.empty()) {
51 return StatusCode::SUCCESS;
52 }
53
54 ANA_CHECK (book (TH1F (m_histogramName.value().c_str(), "systematics", systematics.size(), 0, systematics.size())));
56
57 int i = 1;
58 const std::string sysSignatureStr{"%SYS%"};
59 for (const SystematicSet& sys : systematics)
60 {
61 std::string name;
62 ANA_CHECK (m_systematicsService->makeSystematicsName (name, sysSignatureStr, sys));
63
64 histogram->GetXaxis()->SetBinLabel(i, name.c_str());
65 i++;
66 }
67
68 return StatusCode::SUCCESS;
69 }
70
71
72
73 std::vector<CP::SystematicSet> SysListDumperAlg ::
74 makeSystematicsVector (const std::string &regex) const
75 {
76 std::vector<CP::SystematicSet> inputVector = m_systematicsService->makeSystematicsVector ();
77 if (regex.empty())
78 {
79 return inputVector;
80 }
81
82 std::vector<CP::SystematicSet> systematicsVector;
83 std::regex expr (regex);
84 for (const CP::SystematicSet& sys : inputVector)
85 {
86 if (regex_match (sys.name(), expr))
87 {
88 systematicsVector.push_back (sys);
89 }
90 }
91 return systematicsVector;
92 }
93
94
95 StatusCode SysListDumperAlg ::
96 finalize ()
97 {
98 const std::vector<CP::SystematicSet> systematics = makeSystematicsVector (m_regex);
99 if (systematics.empty()) {
100 ANA_MSG_INFO ("systematics regex '" << m_regex.value() << "' did not match any systematics");
101 return StatusCode::SUCCESS;
102 }
103
104 ANA_MSG_INFO("Systematics regex '" << m_regex.value() << "' matched:");
105 for(const CP::SystematicSet& mysys : systematics) {
106 ANA_MSG_INFO (" '" << mysys.name() << "'");
107 }
108 return StatusCode::SUCCESS;
109 }
110}
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
static const std::vector< std::string > systematics
std::string histogram
Definition chains.cxx:52
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
bool m_firstEvent
whether the next event will be the first event
Gaudi::Property< std::string > m_regex
the regex
std::vector< CP::SystematicSet > makeSystematicsVector(const std::string &regex) const
make the systematics vector using a regex
ServiceHandle< ISystematicsSvc > m_systematicsService
the handle for the systematics service
Gaudi::Property< std::string > m_histogramName
the name of the histogram to use
Class to wrap a set of SystematicVariations.
Select isolated Photons, Electrons and Muons.