ATLAS Offline Software
SysListDumperAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
20 namespace CP
21 {
22 
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  ANA_CHECK (m_systematicsService.retrieve());
33 
34  return StatusCode::SUCCESS;
35  }
36 
37 
38 
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 
51  ANA_CHECK (book (TH1F (m_histogramName.value().c_str(), "systematics", systematics.size(), 0, systematics.size())));
53 
54  int i = 1;
55  for (const auto& sys : systematics)
56  {
57  std::string name;
58  ANA_CHECK (m_systematicsService->makeSystematicsName (name, "%SYS%", sys));
59 
60  histogram->GetXaxis()->SetBinLabel(i, name.c_str());
61  i++;
62  }
63 
64  return StatusCode::SUCCESS;
65  }
66 
67 
68 
69  std::vector<CP::SystematicSet> SysListDumperAlg ::
70  makeSystematicsVector (const std::string &regex) const
71  {
72  std::vector<CP::SystematicSet> inputVector = m_systematicsService->makeSystematicsVector ();
73  if (regex.empty())
74  {
75  return inputVector;
76  }
77 
78  std::vector<CP::SystematicSet> systematicsVector;
79  std::regex expr (regex);
80  for (const CP::SystematicSet& sys : inputVector)
81  {
82  if (regex_match (sys.name(), expr))
83  {
84  systematicsVector.push_back (sys);
85  }
86  }
87  return systematicsVector;
88  }
89 
90 
92  finalize ()
93  {
94  ANA_MSG_INFO("Systematics regex '" << m_regex << "' matched:");
95  for(const CP::SystematicSet& mysys : makeSystematicsVector(m_regex)) {
96  ANA_MSG_INFO (" '" << mysys.name() << "'");
97  }
98  return StatusCode::SUCCESS;
99  }
100 }
AthHistogramming::book
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition: AthHistogramming.h:303
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP::SysListDumperAlg::execute
virtual ::StatusCode execute() override
Definition: SysListDumperAlg.cxx:40
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::SysListDumperAlg::m_regex
Gaudi::Property< std::string > m_regex
the regex
Definition: SysListDumperAlg.h:43
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::SysListDumperAlg::initialize
virtual ::StatusCode initialize() override
Definition: SysListDumperAlg.cxx:24
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
CP::SysListDumperAlg::makeSystematicsVector
std::vector< CP::SystematicSet > makeSystematicsVector(const std::string &regex) const
make the systematics vector using a regex
Definition: SysListDumperAlg.cxx:70
CP::SysListDumperAlg::m_firstEvent
bool m_firstEvent
whether the next event will be the first event
Definition: SysListDumperAlg.h:51
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::SysListDumperAlg::m_histogramName
Gaudi::Property< std::string > m_histogramName
the name of the histogram to use
Definition: SysListDumperAlg.h:47
CP::SysListDumperAlg::m_systematicsService
ServiceHandle< ISystematicsSvc > m_systematicsService
the handle for the systematics service
Definition: SysListDumperAlg.h:39
TH1F
Definition: rootspy.cxx:320
TH1
Definition: rootspy.cxx:268
AthHistogramming::hist
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
Definition: AthHistogramming.cxx:198
CP::SysListDumperAlg::finalize
virtual ::StatusCode finalize() override
Definition: SysListDumperAlg.cxx:92
histogram
std::string histogram
Definition: chains.cxx:52
SysListDumperAlg.h