forked from GooFit/GooFit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfakeTH1F.h
51 lines (44 loc) · 1.22 KB
/
fakeTH1F.h
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
#if !defined(FAKE_TH1F_H)
#define FAKE_TH1F_H 1
template<typename T>
class TH1 {
public:
TH1(string const& name, string const& title, int numbins, int lowerlimit, int upperlimit) :
name_(name), title_(title), numbins_(numbins), lowerlimit_(lowerlimit), upperlimit_(upperlimit),
hist_(numbins + 2), stats_(false)
{
scale_ = (numbins_ - 1)/(upperlimit_ - lowerlimit_);
}
void SetStats(bool const stats) { stats_ = stats; }
void Fill(T const val, T const weight=1.0) {
int ival = (val - lowerlimit_)*scale_;
if (ival < 0) {
ival = 0; // off the left
} else if (ival >= numbins_) {
ival = numbins_ + 1; // off the right
} else {
++ival; // we reserve [0] for underflow
}
hist_[ival] += weight;
}
void SetBinContent(int const i, T const val) {
hist_[i] = val;
}
T GetBinContent(int const i) const {
return hist_[i];
}
T GetBinCenter(int const i) const {
return lowerlimit_ + (i - 1)/scale_;
}
int GetNumbins() const {
return numbins_;
}
private:
std::string name_, title_;
int numbins_, lowerlimit_, upperlimit_;
std::vector<T> hist_;
bool stats_;
float scale_;
};
typedef TH1<float> TH1F;
#endif