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
32 try
33 {
34 std::regex expr (m_regex.value());
35 } catch (const std::regex_error& e)
36 {
37 ANA_MSG_ERROR ("invalid systematics regex '" << m_regex.value() << "': " << e.what());
38 return StatusCode::FAILURE;
39 }
40
42
43 return StatusCode::SUCCESS;
44 }
45
46
47
48 StatusCode SysListDumperAlg ::
49 execute (const EventContext& /*ctx*/)
50 {
51 if (!m_firstEvent)
52 {
53 return StatusCode::SUCCESS;
54 }
55
56 m_firstEvent = false;
57
58 const std::vector<CP::SystematicSet> systematics = makeSystematicsVector (m_regex);
59 if (systematics.empty()) {
60 return StatusCode::SUCCESS;
61 }
62
63 ANA_CHECK (book (TH1F (m_histogramName.value().c_str(), "systematics", systematics.size(), 0, systematics.size())));
65
66 int i = 1;
67 const std::string sysSignatureStr{"%SYS%"};
68 for (const SystematicSet& sys : systematics)
69 {
70 std::string name;
71 ANA_CHECK (m_systematicsService->makeSystematicsName (name, sysSignatureStr, sys));
72
73 histogram->GetXaxis()->SetBinLabel(i, name.c_str());
74 i++;
75 }
76
77 return StatusCode::SUCCESS;
78 }
79
80
81
82 std::vector<CP::SystematicSet> SysListDumperAlg ::
83 makeSystematicsVector (const std::string &regex) const
84 {
85 std::vector<CP::SystematicSet> inputVector = m_systematicsService->makeSystematicsVector ();
86 if (regex.empty())
87 {
88 return inputVector;
89 }
90
91 std::vector<CP::SystematicSet> systematicsVector;
92 std::regex expr (regex);
93 for (const CP::SystematicSet& sys : inputVector)
94 {
95 if (regex_match (sys.name(), expr))
96 {
97 systematicsVector.push_back (sys);
98 }
99 }
100 return systematicsVector;
101 }
102
103
104 StatusCode SysListDumperAlg ::
105 finalize ()
106 {
107 const std::vector<CP::SystematicSet> systematics = makeSystematicsVector (m_regex);
108 if (systematics.empty()) {
109 ANA_MSG_INFO ("systematics regex '" << m_regex.value() << "' did not match any systematics");
110 return StatusCode::SUCCESS;
111 }
112
113 ANA_MSG_INFO("Systematics regex '" << m_regex.value() << "' matched:");
114 for(const CP::SystematicSet& mysys : systematics) {
115 ANA_MSG_INFO (" '" << mysys.name() << "'");
116 }
117 return StatusCode::SUCCESS;
118 }
119}
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_INFO(xmsg,...)
Macro printing info 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
TH1 * hist(std::string_view histName, std::string_view tDir="", std::string_view stream="")
Simplify the retrieval of registered histograms of any type.
StatusCode book(const TH1 &hist, std::string_view tDir="", std::string_view stream="")
Simplify the booking and registering (into THistSvc) of histograms.
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.