ATLAS Offline Software
GenAnalysis.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cassert>
7 #include <cmath>
8 
9 
10 
11 GenAnalysis::GenAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
12  : GenBase(name, pSvcLocator),
13  m_histSvc("THistSvc", name)
14 {
15  declareProperty("HistKey", m_histkey="genanalysis");
16  declareProperty("THistSvc", m_histSvc);
17 }
18 
19 
22  CHECK(m_histSvc.retrieve());
23  return init();
24 }
25 
26 
28  if (events()->empty()) {
29  ATH_MSG_ERROR("No events found in McEventCollection");
30  return StatusCode::FAILURE;
31  }
32  return analyze();
33 }
34 
35 
37 
38 
39 TH1D* GenAnalysis::bookHisto1D(const std::string& path, const std::string& title, const std::vector<double>& binedges,
40  const std::string& xtitle, const std::string& ytitle) {
41  TH1D* h = new TH1D(path.c_str(), title.c_str(), binedges.size()-1, &binedges.front());
42  h->Sumw2();
43  h->SetXTitle(xtitle.c_str());
44  h->SetYTitle(ytitle.c_str());
45  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
46  if (st.isFailure()) return 0;
47  return h;
48 }
49 
50 TH1D* GenAnalysis::bookHisto1D(const std::string& path, const std::string& title, size_t numbins, double low, double high,
51  const std::string& xtitle, const std::string& ytitle) {
52  TH1D* h = new TH1D(path.c_str(), title.c_str(), numbins, low, high);
53  h->Sumw2();
54  h->SetXTitle(xtitle.c_str());
55  h->SetYTitle(ytitle.c_str());
56  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
57  if (st.isFailure()) return 0;
58  return h;
59 }
60 
61 
62 TProfile* GenAnalysis::bookProfile1D(const std::string& path, const std::string& title, const std::vector<double>& binedges,
63  const std::string& xtitle, const std::string& ytitle) {
64  TProfile* h = new TProfile(path.c_str(), title.c_str(), binedges.size()-1, &binedges.front());
65  h->Sumw2();
66  h->SetXTitle(xtitle.c_str());
67  h->SetYTitle(ytitle.c_str());
68  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
69  if (st.isFailure()) return 0;
70  return h;
71 }
72 
73 TProfile* GenAnalysis::bookProfile1D(const std::string& path, const std::string& title, size_t numbins, double low, double high,
74  const std::string& xtitle, const std::string& ytitle) {
75  TProfile* h = new TProfile(path.c_str(), title.c_str(), numbins, low, high);
76  h->Sumw2();
77  h->SetXTitle(xtitle.c_str());
78  h->SetYTitle(ytitle.c_str());
79  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
80  if (st.isFailure()) return 0;
81  return h;
82 }
83 
84 
85 TH2D* GenAnalysis::bookHisto2D(const std::string& path, const std::string& title,
86  const std::vector<double>& binedgesx, const std::vector<double>& binedgesy,
87  const std::string& xtitle, const std::string& ytitle, const std::string& ztitle) {
88  TH2D* h = new TH2D(path.c_str(), title.c_str(), binedgesx.size()-1, &*binedgesx.begin(), binedgesy.size()-1, &binedgesy.front());
89  h->Sumw2();
90  h->SetXTitle(xtitle.c_str());
91  h->SetYTitle(ytitle.c_str());
92  h->SetZTitle(ztitle.c_str());
93  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
94  if (st.isFailure()) return 0;
95  return h;
96 }
97 
98 TH2D* GenAnalysis::bookHisto2D(const std::string& path, const std::string& title,
99  size_t numbinsx, double xlow, double xhigh,
100  size_t numbinsy, double ylow, double yhigh,
101  const std::string& xtitle, const std::string& ytitle, const std::string& ztitle) {
102  TH2D* h = new TH2D(path.c_str(), title.c_str(), numbinsx, xlow, xhigh, numbinsy, ylow, yhigh);
103  h->Sumw2();
104  h->SetXTitle(xtitle.c_str());
105  h->SetYTitle(ytitle.c_str());
106  h->SetZTitle(ztitle.c_str());
107  StatusCode st = histSvc()->regHist(fullhistopath(path), h);
108  if (st.isFailure()) return 0;
109  return h;
110 }
111 
112 
113 
114 TH1* GenAnalysis::histo(const std::string& key) {
115  TH1* h = 0;
116  StatusCode st = histSvc()->getHist(fullhistopath(key), h);
117  if (st.isFailure()) ATH_MSG_WARNING("No histogram with key " << key);
118  return h;
119 }
120 
121 TProfile* GenAnalysis::profile(const std::string& key) {
122  TH1* h = 0;
123  StatusCode st = histSvc()->getHist(fullhistopath(key), h);
124  if (st.isFailure()) ATH_MSG_WARNING("No histogram with key " << key);
125  return dynamic_cast<TProfile*>(h);
126 }
GenAnalysis::histSvc
const ServiceHandle< ITHistSvc > histSvc() const
Directly access the histogram service.
Definition: GenAnalysis.h:83
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GenAnalysis::profile
TProfile * profile(const std::string &key)
Retrieve a profile histogram.
Definition: GenAnalysis.cxx:121
TH1D
Definition: rootspy.cxx:342
GenAnalysis::bookProfile1D
TProfile * bookProfile1D(const std::string &name, const std::string &title, const std::vector< double > &binedges, const std::string &xtitle="", const std::string &ytitle="")
Definition: GenAnalysis.cxx:62
plotting.yearwise_luminosity.ytitle
string ytitle
Definition: yearwise_luminosity.py:76
GenAnalysis::analyze
virtual StatusCode analyze()=0
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
GenAnalysis::GenAnalysis
GenAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GenAnalysis.cxx:11
GenAnalysis::fullhistopath
std::string fullhistopath(const std::string &localpath)
Get a histogram's full path, given the name local to the analysis.
Definition: GenAnalysis.h:72
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
GenBase
Base class for common behaviour of MC truth algorithms.
Definition: GenBase.h:47
GenAnalysis::initialize
StatusCode initialize()
Setup analysis tools and call user-supplied init()
Definition: GenAnalysis.cxx:20
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
covarianceTool.title
title
Definition: covarianceTool.py:542
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
GenAnalysis::histo
TH1 * histo(const std::string &key)
Retrieve a histogram (as TH1* base class pointer)
Definition: GenAnalysis.cxx:114
TH2D
Definition: rootspy.cxx:430
GenAnalysis::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Definition: GenAnalysis.h:94
GenAnalysis::bookHisto1D
TH1D * bookHisto1D(const std::string &name, const std::string &title, const std::vector< double > &binedges, const std::string &xtitle="", const std::string &ytitle="")
Definition: GenAnalysis.cxx:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TProfile
Definition: rootspy.cxx:515
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TH1
Definition: rootspy.cxx:268
plotting.yearwise_efficiency.xtitle
string xtitle
Definition: yearwise_efficiency.py:38
GenAnalysis::m_histkey
std::string m_histkey
Container name for the MC event collection to be analysed.
Definition: GenAnalysis.h:93
GenAnalysis::init
virtual StatusCode init()
Definition: GenAnalysis.h:40
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17
GenAnalysis::execute
StatusCode execute()
Per-event analysis routine: calls user-supplied analyze()
Definition: GenAnalysis.cxx:27
GenAnalysis.h
GenAnalysis::bookHisto2D
TH2D * bookHisto2D(const std::string &name, const std::string &title, const std::vector< double > &binedgesx, const std::vector< double > &binedgesy, const std::string &xtitle="", const std::string &ytitle="", const std::string &ztitle="")
Definition: GenAnalysis.cxx:85
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37