-
Notifications
You must be signed in to change notification settings - Fork 1
/
defineSmall.C
207 lines (138 loc) · 4.54 KB
/
defineSmall.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef DEFINESMALL_CXX
#define DEFINESMALL_CXX
#include "TMath.h"
#include "TH1D.h"
#include "TRandom2.h"
#include "stats.C"
//////////////////////////////////////////////////////////////
// Define a "small" variation for standard FOM using MC
double defineSmallSignificance(double Ns, double Nb, int npts){
// make random generator
TRandom2* randgen = new TRandom2(npts);
// array fo values
const int N = npts;
double signif[N];
// fill array
for (int i=0; i<npts; i++){
// get random signal
double ss = randgen->PoissonD(Ns);
// cout<<"ss: "<<ss<<endl;
// get random bg
double bg = randgen->PoissonD(Nb);
// cout<<"bg: "<<bg<<endl;
double sig = 0.;
if (ss+bg > 0.) sig = (ss*ss)/(ss+bg);
// cout<<"sig: "<<sig<<endl;
// fill array
signif[i] = sig;
}
// get variance
double var = arrayvarD(signif,npts);
return TMath::Sqrt(var);
}
/*
//////////////////////////////////////////////////////////////
// Define a "small" variation for FOM using MC in a single bin
double defineSmall(double Ns, double Nb, double avgpow, double avgsigsys, double avgbgsys, int npts=10000){
// make random generator
TRandom2* randgen = new TRandom2(npts);
// array fo values
const int N = npts;
double signif[N];
// fill array
for (int i=0; i<npts; i++){
// get random signal
double ss = randgen->PoissonD(Ns);
double pow = avgpow*ss;
// get random bg
double bg = randgen->PoissonD(Nb);
// get systematic component
double sys_ss = avgsigsys*ss;
double sys_bg = avgbgsys*bg;
double numer = (pow*pow);
double denom = (ss + bg + ((sys_ss + sys_bg)*(sys_ss*sys_bg)));
double fom = 0.;
if (denom > 0.) fom = numer/denom;
// fill array
signif[i] = fom;
}
// get variance
float var = arrayvarD(signif,npts);
return TMath::Sqrt(var);
}
*/
float getVariation(float pow, float nev, float sys, float powavg, float sysavg){
float fom0 = (pow*pow)/(nev + (sys*sys));
// float fom1 = ((pow-1.)*(pow-1.))/((nev-1.) + ((sys-0.5)*(sys-0.5)));
// float fom2 = ((pow+1.)*(pow+1.))/((nev+1.) + ((sys+0.5)*(sys+0.5)));
// float powavg = 0.5;
// float fom1 = ((pow-powavg)*(pow-powavg))/((nev-1) + ((sys-sysavg)*(sys-sysavg)));
// float fom2 = ((pow+powavg)*(pow+powavg))/((nev+1) + ((sys+sysavg)*(sys+sysavg)));
float fom1 = ((pow-powavg)*(pow-powavg))/((nev) + ((sys)*(sys)));
float fom2 = ((pow+powavg)*(pow+powavg))/((nev) + ((sys)*(sys)));
return TMath::Abs((fom2-fom1))/2.;
}
float getSysVariation(float pow, float nev, float sys){
float scaleup = 1.025;
float scaledown = 0.975;
float fom1 = ((pow)*(pow))/((nev) + ((sys*scaleup)*(sys*scaleup)));
float fom2 = ((pow)*(pow))/((nev) + ((sys*scaledown)*(sys*scaledown)));
return TMath::Abs((fom2-fom1))/1.;
}
///////////////////////////////////////////////////////////////////////
// one way to define small
float defineSmall(int nbins, float* pow, float* nev, float* sys){
// first find maximum of figure of merit
float fomax = 0.;
int maxbin = -1;
for (int i=0; i<nbins; i++){
float fom = 0.;
if ((nev[i]+sys[i])>0.){
fom = (pow[i]*pow[i])/(nev[i] + (sys[i]*sys[i]) );
}
if (fom>fomax){
fomax = fom;
maxbin = i;
}
}
cout<<"maxbin: "<<maxbin<<endl;
cout<<"fomax: "<<fomax<<endl;
// now, get average power estimate in that bin
float powavg = TMath::Abs(pow[maxbin])/nev[maxbin];
float sysavg = TMath::Abs(sys[maxbin])/nev[maxbin];
cout<<"powavg: "<<powavg<<endl;
// see how much a variation changes
float var = getVariation(pow[maxbin],nev[maxbin],sys[maxbin],powavg,sysavg);
return var;
}
///////////////////////////////////////////////////////////////////////
// anothe rway to define small
float defineSmall2(int nbins, float* pow, float* nev, float* sys){
// first find maximum of figure of merit
float fomax = 0.;
int maxbin = -1;
for (int i=0; i<nbins; i++){
float fom = 0.;
if ((nev[i]+sys[i])>0.){
fom = (pow[i]*pow[i])/(nev[i] + (sys[i]*sys[i]) );
}
if (fom>fomax){
fomax = fom;
maxbin = i;
}
}
// see how much a variation changes
float var = getSysVariation(pow[maxbin],nev[maxbin],sys[maxbin]);
return var;
}
double getAbsDifference(TH1D* h1, TH1D* h2){
int nbins = h1->GetNbinsX();
double diffsum = 0.;
for (int i=0; i<=nbins; i++){
// double absdiff = TMath::Abs(h1->GetBinContent(i) - h2->GetBinContent(i) );
double absdiff = (h2->GetBinContent(i) - h1->GetBinContent(i) );
diffsum += absdiff;
}
return diffsum;
}
#endif