-
Notifications
You must be signed in to change notification settings - Fork 0
/
histoFunc.h
86 lines (54 loc) · 1.41 KB
/
histoFunc.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
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
#ifndef histoFunc_h
#define histoFunc_h
#include "TH1.h"
class histoFunc
{
public:
//! ctor
histoFunc(TH1F* histo)
{
histo_p = histo;
};
//! dtor
~histoFunc()
{};
//! operator()
double operator()(double* x, double* par)
{
double xx = par[2] * (x[0] - par[3]);
double xMin = histo_p -> GetBinCenter(1);
double xMax = histo_p -> GetBinCenter(histo_p -> GetNbinsX());
if( xx < xMin )
return par[0] + par[1] * par[2] * histo_p->GetBinContent(1);
if( xx > xMax )
return par[0] + par[1] * par[2] * histo_p->GetBinContent(histo_p->GetNbinsX());
else
{
int bin = histo_p -> FindBin(xx);
int bin1 = 0;
int bin2 = 0;
if(xx >= histo_p -> GetBinCenter(bin))
{
bin1 = bin;
bin2 = bin+1;
}
else
{
bin1 = bin-1;
bin2 = bin;
}
double x1 = histo_p -> GetBinCenter(bin1);
double y1 = histo_p -> GetBinContent(bin1);
double x2 = histo_p -> GetBinCenter(bin2);
double y2 = histo_p -> GetBinContent(bin2);
double m = 1. * (y2 - y1) / (x2 - x1);
//if( (y1 + m * (xx - x1)) < 1.e-10)
// return 1.e-10;
return par[0] + par[1] * par[2] * (y1 + m * (xx - x1));
}
return 1.e-10;
}
private:
TH1F* histo_p;
};
#endif