forked from UCATLAS/xAODAnaHelpers
/
HistogramManager.cxx
154 lines (134 loc) · 5.09 KB
/
HistogramManager.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/******************************************
*
* Base class used to book a set of histograms.
* Many sets can be created and compared for
* efficiecny studies or population studies.
*
* G. Facini
* Sep 9 08:58:12 CEST 2014
* G. Stark
* Jan 20 10:29 CEST 2015
*
******************************************/
#include "xAODAnaHelpers/HistogramManager.h"
/* constructors and destructors */
HistogramManager::HistogramManager(std::string name, std::string detailStr):
m_name(name),
m_detailStr(detailStr)
{
// if last character of name is a alphanumeric add a / so that
// in the output file, a TDirectory is created with the histograms inside
if( isalnum( m_name.back() ) && !ispunct( m_name.back() ) ) {
m_name += "/";
//Info("HistogramManager()", "Adding slash to put hists in TDirectories: %s",m_name.c_str());
}
}
HistogramManager::~HistogramManager() {}
/* Main book() functions for 1D, 2D, 3D histograms */
TH1F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, double xlow, double xhigh)
{
TH1F* tmp = new TH1F( (name + title).c_str(), title.c_str(), xbins, xlow, xhigh);
SetLabel(tmp, xlabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH2F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, double xlow, double xhigh,
std::string ylabel, int ybins, double ylow, double yhigh)
{
TH2F* tmp = new TH2F( (name + title).c_str(), title.c_str(), xbins, xlow, xhigh, ybins, ylow, yhigh);
SetLabel(tmp, xlabel, ylabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH3F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, double xlow, double xhigh,
std::string ylabel, int ybins, double ylow, double yhigh,
std::string zlabel, int zbins, double zlow, double zhigh)
{
TH3F* tmp = new TH3F( (name + title).c_str(), title.c_str(), xbins, xlow, xhigh, ybins, ylow, yhigh, zbins, zlow, zhigh);
SetLabel(tmp, xlabel, ylabel, zlabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
/////// Variable Binned Histograms ///////
TH1F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, const Double_t* xbinArr)
{
TH1F* tmp = new TH1F( (name + title).c_str(), title.c_str(), xbins, xbinArr);
SetLabel(tmp, xlabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH2F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, const Double_t* xbinArr,
std::string ylabel, int ybins, double ylow, double yhigh)
{
TH2F* tmp = new TH2F( (name + title).c_str(), title.c_str(), xbins, xbinArr, ybins, ylow, yhigh);
SetLabel(tmp, xlabel, ylabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH2F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, double xlow, double xhigh,
std::string ylabel, int ybins, const Double_t* ybinArr)
{
TH2F* tmp = new TH2F( (name + title).c_str(), title.c_str(), xbins, xlow, xhigh, ybins, ybinArr);
SetLabel(tmp, xlabel, ylabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH2F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, const Double_t* xbinArr,
std::string ylabel, int ybins, const Double_t* ybinArr)
{
TH2F* tmp = new TH2F( (name + title).c_str(), title.c_str(), xbins, xbinArr, ybins, ybinArr);
SetLabel(tmp, xlabel, ylabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
TH3F* HistogramManager::book(std::string name, std::string title,
std::string xlabel, int xbins, const Double_t* xbinArr,
std::string ylabel, int ybins, const Double_t* ybinArr,
std::string zlabel, int zbins, const Double_t* zbinArr)
{
TH3F* tmp = new TH3F( (name + title).c_str(), title.c_str(), xbins, xbinArr, ybins, ybinArr, zbins, zbinArr);
SetLabel(tmp, xlabel, ylabel, zlabel);
this->Sumw2(tmp);
this->record(tmp);
return tmp;
}
/* Helper functions */
void HistogramManager::Sumw2(TH1* hist, bool flag /*=true*/) {
hist->Sumw2(flag);
}
void HistogramManager::record(TH1* hist) {
m_allHists.push_back( hist );
}
void HistogramManager::record(EL::Worker* wk) {
for( auto hist : m_allHists ){
wk->addOutput(hist);
}
}
void HistogramManager::SetLabel(TH1* hist, std::string xlabel)
{
hist->GetXaxis()->SetTitle(xlabel.c_str());
}
void HistogramManager::SetLabel(TH1* hist, std::string xlabel, std::string ylabel)
{
hist->GetYaxis()->SetTitle(ylabel.c_str());
this->SetLabel(hist, xlabel);
}
void HistogramManager::SetLabel(TH1* hist, std::string xlabel, std::string ylabel, std::string zlabel)
{
hist->GetZaxis()->SetTitle(zlabel.c_str());
this->SetLabel(hist, xlabel, ylabel);
}