forked from ltikvica/WZanalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnfoldingHistogramFactory.C
179 lines (115 loc) · 3.91 KB
/
UnfoldingHistogramFactory.C
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "UnfoldingHistogramFactory.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
// Global static pointer used to ensure a single instance of the class.
UnfoldingHistogramFactory * UnfoldingHistogramFactory::_instance = NULL;
UnfoldingHistogramFactory * UnfoldingHistogramFactory::GetInstance(){
if (! _instance) { // Only allow one instance of class to be generated.
_instance = new UnfoldingHistogramFactory;
}
return _instance;
}
TH1D * UnfoldingHistogramFactory::createHistogram(std::string key,
std::string hname,
std::string htitle) {
TH1D * h;
// auto it = binLimitsMap.find(key);
map<string,vector<double> >::iterator it = binLimitsMap.find(key);
if (it == binLimitsMap.end()) {
createDefaultBinning(key);
}
int nBins = binLimitsMap[key].size() - 1;
double * bins = new double[nBins+1];
for (int i=0; i< binLimitsMap[key].size(); i++) {
bins[i] = (binLimitsMap[key])[i];
}
h = new TH1D(hname.c_str(),htitle.c_str(), nBins, bins);
delete [] bins;
return h;
}
void UnfoldingHistogramFactory::createDefaultBinning(std::string key) {
std::cout << "CREATE DEFAULT BINNING FOR : " << key << std::endl;
std::vector<double> binLimits;
if (key == "ZPt") {
double value = 0.;
double binSize = 20;
while (value<500.) {
binLimits.push_back(value);
if (value>100) binSize = 25.;
if (value>300) binSize = 40.;
if (value>400) binSize = 50.;
value += binSize;
}
} else if (key == "LeadingJetPt") {
double value = 30.;
double binSize = 40;
while (value<500.) {
binLimits.push_back(value);
if (value>150) binSize = 50.;
if (value>200) binSize = 60.;
if (value>300) binSize = 80.;
if (value>400) binSize = 120.;
value += binSize;
}
}
binLimitsMap[key] = binLimits;
std::cout << key << " ("
<< binLimits.size() - 1 << " bins) : ";
for (int i=0; i<binLimits.size(); i++) {
std::cout << binLimits[i] << " ";
}
std::cout << endl;
}
TH1D * UnfoldingHistogramFactory::createLeadingJetHistogram(std::string hname,
std::string htitle) {
UnfoldingHistogramFactory * instance = UnfoldingHistogramFactory::GetInstance();
return instance->createHistogram("LeadingJetPt",hname,htitle);
}
TH1D * UnfoldingHistogramFactory::createNjetsHistogram(std::string hname,
std::string htitle) {
//UnfoldingHistogramFactory * instance = UnfoldingHistogramFactory::GetInstance();
// return instance->createHistogram("Njets",hname,htitle);
TH1D * h = new TH1D(hname.c_str(),htitle.c_str(),4, 0, 4);
return h;
}
TH1D * UnfoldingHistogramFactory::createZPtHistogram(std::string hname,
std::string htitle) {
UnfoldingHistogramFactory * instance = UnfoldingHistogramFactory::GetInstance();
return instance->createHistogram("ZPt",hname,htitle);
}
TH1D * UnfoldingHistogramFactory::createHistogramForVar(std::string variable,
std::string name, std::string title) {
TH1D * h=0;
if (variable == "Zpt") {
h = createZPtHistogram(name, title);
} else if (variable == "LeadingJetPt") {
h = createLeadingJetHistogram(name, title);
} else if (variable == "Njets") {
h = createNjetsHistogram(name, title);
} else {
std::cout << "HistogramFactory::createHistogram: UNKNOWN VARIABLE = " << variable << std::endl;
}
return h;
}
void UnfoldingHistogramFactory::SetBinning(string file) {
std::cout << "SET BINNING BY HAND " << std::endl;
ifstream infile(file.c_str());
string line;
while (std::getline(infile, line))
{
std::istringstream iss(line);
string key;
double x;
if (!(iss >> key)) { break; } // error
vector<double> limits;
while (iss >> x) {
limits.push_back(x);
}
if (limits.size()>1) {
binLimitsMap.insert(pair<string,vector<double> >(key,limits));
}
}
}