ATLAS Offline Software
Loading...
Searching...
No Matches
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
11GenAnalysis::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
39TH1D* 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
50TH1D* 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
62TProfile* 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
73TProfile* 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
85TH2D* 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
98TH2D* 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
114TH1* 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
121TProfile* 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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static const Attributes_t empty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Header file for AthHistogramAlgorithm.
const ServiceHandle< ITHistSvc > histSvc() const
Directly access the histogram service.
Definition GenAnalysis.h:83
TProfile * profile(const std::string &key)
Retrieve a profile histogram.
TProfile * bookProfile1D(const std::string &name, const std::string &title, const std::vector< double > &binedges, const std::string &xtitle="", const std::string &ytitle="")
TH1 * histo(const std::string &key)
Retrieve a histogram (as TH1* base class pointer)
TH1D * bookHisto1D(const std::string &name, const std::string &title, const std::vector< double > &binedges, const std::string &xtitle="", const std::string &ytitle="")
virtual StatusCode analyze()=0
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="")
StatusCode execute()
Per-event analysis routine: calls user-supplied analyze()
virtual StatusCode init()
Definition GenAnalysis.h:40
ServiceHandle< ITHistSvc > m_histSvc
Definition GenAnalysis.h:94
std::string m_histkey
Container name for the MC event collection to be analysed.
Definition GenAnalysis.h:93
std::string fullhistopath(const std::string &localpath)
Get a histogram's full path, given the name local to the analysis.
Definition GenAnalysis.h:72
StatusCode initialize()
Setup analysis tools and call user-supplied init()
GenAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
Definition GenBase.cxx:17
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenBase.cxx:11