-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeAccept.C
executable file
·320 lines (270 loc) · 9.87 KB
/
TimeAccept.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <TFile.h>
#include <TMath.h>
#include <iostream>
#include <TGraphErrors.h>
#include <TGraphAsymmErrors.h>
// define the fitting function
void TimeAccept() {
TString hfolder = "TCuts_GMSB_new/" ;
TString plotname0 = "TimeDist.png" ;
TString plotname1 = "TimeEffAccept.png" ;
TString plotname2 = "TimeEfficiency.png" ;
TString plotname3 = "Time_PtDist.png" ;
TString plotname4 = "Time_GenCTau.png" ;
TString plotname5 = "TimeAccept.png" ;
string xlable = "ECAL Time (ns) " ;
string hName = "h_time" ;
string hName1 = "h_latePt" ;
TString fileName = "TCuts_RunBCD_new/histo_trig_gmsb_" ;
TString names[7] = { "250","500","1000", "2000", "3000", "4000", "6000" } ;
int color[7] = { 1, 2, 4, 5, 6, 7, 8 } ;
TFile* hfile[7] ;
TH1D* hTime[7] ;
TH1D* hPt[7] ;
for ( int i=0 ; i< 7; i++ ) {
hfile[i] = TFile::Open( fileName+names[i]+".root" );
hTime[i] = (TH1D *) hfile[i]->Get( hName.c_str() ) ;
hPt[i] = (TH1D *) hfile[i]->Get( hName1.c_str() ) ;
}
gStyle->SetOptStat("");
// Plots
TCanvas* c0 = new TCanvas("c0","", 800, 700);
c0->SetFillColor(10);
c0->SetFillColor(10);
gPad->SetGridx();
//gPad->SetGridy();
c0->SetLeftMargin(0.15);
c0->SetRightMargin(0.12);
c0->SetTopMargin(0.1);
c0->SetBottomMargin(0.12);
c0->cd();
//gStyle->SetOptStat(kTRUE);
//gStyle->SetOptFit(111);
c0->SetLogy();
TLegend* leg1 = new TLegend(.55, .68, .95, .90 );
leg1->Clear();
char legStr[100] ;
double nGen[7] = { 50112, 50112, 50112, 50112, 50112, 46944, 50112 } ;
double nReco[7] , nObs[7] ;
double eff[7], eff_u[7] , eff_d[7] ;
double reff[7], reff_u[7] , reff_d[7] ;
double ctau[7] = {250,500,1000,2000,3000,4000,6000} ;
double errX[7] = { 0, 0, 0, 0, 0, 0, 0} ;
for ( int i = 0; i < 7; i++ ) {
// calculate the number
nReco[i] = hTime[i]->Integral() ;
nObs[i] = hTime[i]->Integral(33, 100) ;
// Setup color and draw histogram
hTime[i]->Rebin(2) ;
hTime[i]->SetLineColor( color[i] ) ;
if ( i ==0 ) hTime[i]->Draw() ;
else hTime[i]->Draw("SAMES") ;
sprintf( legStr, ": %.0f / %.0f = %.5f ", nObs[i], nReco[i], nObs[i]/ nReco[i] ) ;
leg1->AddEntry( hTime[i], names[i] + legStr, "L");
c0->Update() ;
printf( " nObs:%.1f nReco:% 1.f \n", nObs[i], nReco[i] ) ;
}
leg1->Draw("sames") ;
c0->Update() ;
c0->Print( hfolder + plotname0 );
// Pt spectrum
c0->cd();
c0->SetLogy();
leg1->Clear() ;
for ( int i = 6; i >=0 ; i-- ) {
// Setup color and draw histogram
hPt[i]->Rebin(2) ;
hPt[i]->SetLineColor( color[i] ) ;
if ( i == 6 ) hPt[i]->Draw() ;
else hPt[i]->Draw("SAMES") ;
sprintf( legStr, ": %.0f ", hPt[i]->Integral() ) ;
leg1->AddEntry( hPt[i], names[i] + legStr, "L");
c0->Update() ;
}
leg1->Draw("sames") ;
c0->Update() ;
c0->Print( hfolder + plotname3 );
// Efficiency Plots
TH1D* hObs = new TH1D("hObs", " ", 7, 0, 7 );
TH1D* hRec = new TH1D("hRec", " ", 7, 0, 7 );
TH1D* hGen = new TH1D("hGen", " ", 7, 0, 7 );
for ( int i=0; i< 7 ; i++ ) {
hObs->SetBinContent( i+1 , nObs[i] ) ;
hRec->SetBinContent( i+1 , nReco[i] ) ;
hGen->SetBinContent( i+1 , nGen[i] ) ;
}
TGraphAsymmErrors* acc_x = new TGraphAsymmErrors();
acc_x->BayesDivide( hObs, hGen );
TGraphAsymmErrors* eff_x = new TGraphAsymmErrors();
eff_x->BayesDivide( hRec, hGen );
TGraphAsymmErrors* acp_x = new TGraphAsymmErrors();
acp_x->BayesDivide( hObs, hRec );
/*
for ( int i = 0; i < 7; i++ ) {
// calculate efficiency and errors
pair<double,double> errs = EffError( nGen, nObs[i]*10. ) ;
eff[i] = nObs[i] / nGen ;
eff_u[i] = 100.*errs.first ;
eff_d[i] = 100.*errs.second ;
printf( " Final eff = %.3f , err_d: %.8f , err_u: %.8f \n", eff[i], eff_d[i], eff_u[i] ) ;
pair<double,double> rerrs = EffError( nGen, nReco[i] ) ;
reff[i] = nReco[i] / nGen ;
reff_u[i] = rerrs.first ;
reff_d[i] = rerrs.second ;
printf( " Reco eff = %.3f , err_d: %.8f , err_u: %.8f \n", reff[i], reff_d[i], rerrs.first ) ;
}
*/
//TGraphAsymmErrors* acc_x = new TGraphAsymmErrors( 50, ctau, eff, errX, errX, eff_d, eff_u ); // SC's result !
c0->cd();
c0->SetLogy(0);
acc_x->SetTitle(" Efficiency*Acceptance (t > 3 ns) ") ;
acc_x->SetMaximum( 0.1 );
acc_x->SetMinimum( 0.0 );
acc_x->SetMarkerColor(4);
acc_x->SetMarkerStyle(22);
acc_x->SetMarkerSize(1);
acc_x->SetLineColor(1);
acc_x->SetLineWidth(2);
acc_x->GetXaxis()->SetTitleOffset(1.34);
acc_x->GetYaxis()->SetTitleOffset(1.41);
acc_x->GetXaxis()->SetTitle(" Neutralino c#tau (mm) " ) ;
acc_x->GetYaxis()->SetTitle(" Efficiency*Acceptance ") ;
//acc_x->GetXaxis()->SetLimits( 200, 6500 );
acc_x->Draw("AP");
c0->Update();
c0->Print( hfolder + plotname1 );
acp_x->SetTitle(" Acceptance (t > 3 ns) ") ;
acp_x->SetMaximum( 0.3 );
acp_x->SetMinimum( 0.0 );
acp_x->SetMarkerColor(4);
acp_x->SetMarkerStyle(22);
acp_x->SetMarkerSize(1);
acp_x->SetLineColor(1);
acp_x->SetLineWidth(2);
acp_x->GetXaxis()->SetTitleOffset(1.34);
acp_x->GetYaxis()->SetTitleOffset(1.41);
acp_x->GetXaxis()->SetTitle(" Neutralino c#tau (mm) " ) ;
acp_x->GetYaxis()->SetTitle(" Acceptance ") ;
//acp_x->GetXaxis()->SetLimits( 200, 6500 );
acp_x->Draw("AP");
c0->Update();
c0->Print( hfolder + plotname5 );
eff_x->SetTitle(" Reco Efficiency ( |t|< 25 ns) ") ;
eff_x->SetMaximum( 1.0 );
eff_x->SetMinimum( 0.0 );
eff_x->SetMarkerColor(2);
eff_x->SetMarkerStyle(22);
eff_x->SetMarkerSize(1);
eff_x->SetLineColor(1);
eff_x->SetLineWidth(2);
eff_x->GetXaxis()->SetTitleOffset(1.34);
eff_x->GetYaxis()->SetTitleOffset(1.41);
eff_x->GetXaxis()->SetTitle(" Neutralino c#tau (mm) " ) ;
eff_x->GetYaxis()->SetTitle(" Efficiency ") ;
//eff_x->GetXaxis()->SetLimits( 200, 6500 );
eff_x->Draw("AP");
c0->Update();
c0->Print( hfolder + plotname2 );
/*
eff_gmsb->SetMarkerColor(2);
eff_gmsb->SetMarkerStyle(21);
eff_gmsb->SetMarkerSize(1);
eff_gmsb->SetLineColor(2);
eff_gmsb->SetLineWidth(2);
eff_gmsb->Draw("SAMEP");
c0->Update();
eff_data->SetMarkerColor(4);
eff_data->SetMarkerStyle(20);
eff_data->SetMarkerSize(1);
eff_data->SetLineColor(4);
eff_data->SetLineWidth(2);
eff_data->Draw("SAMEP");
c0->Update();
// Legend
TLegend* leg1 = new TLegend(.65, .5, .85, .7 );
leg1->Clear();
leg1->SetTextSize(0.03) ;
char RStr0[30], RStr1[30], RStr2[30] ;
sprintf( RStr0, "Data" ) ;
sprintf( RStr1, "GMSB" ) ;
sprintf( RStr2, "G+Jets") ;
leg1->AddEntry( eff_data, RStr0, "P");
leg1->AddEntry( eff_gmsb, RStr1, "P");
leg1->AddEntry( eff_gjet, RStr2, "P");
leg1->Draw("SAME") ;
c0->Update();
c0->Print( plotname );
*/
delete c0 ;
}
pair<double, double> EffError( double N_all, double N_pass ) {
if ( N_all < 0.0001 ) {
pair<double,double> noErr = make_pair( 0 , 0 );
printf(" No Error !! \n" ) ;
return noErr ;
}
double eff0 = N_pass / N_all ;
if ( eff0 > 1 ) {
pair<double,double> noErr = make_pair( 0 , 0 );
printf(" No Error !! \n" ) ;
return noErr ;
}
//cout<<" N_All: "<<N_all <<" N_pass: "<< N_pass << endl;
int nStep = 1000 ;
double step = 1. / (double)nStep ;
//cout<<" step = "<< step <<endl;
Double_t par[3] = { 1, N_all, N_pass } ;
Double_t xL[1] = { eff0 } ;
Double_t xR[1] = { eff0 } ;
double IntEff = (N_all+ 1) * step * BinomialErr( xR, par ) ;
//cout<<" Eff 0th : "<< BinomialErr( xR, par ) << endl ;
//printf(" Eff 0th : %.5f \n", eff0 ) ;
bool skipR = false ;
bool skipL = false ;
Double_t pR = 0. ;
Double_t pL = 0. ;
while ( IntEff < 0.683) {
if ( !skipR && xR[0] < 1. ) {
xR[0] += step ;
pR = BinomialErr( xR, par ) ;
IntEff += (pR*step*(N_all+1) ) ;
cout<<" ("<< xR[0] <<") --> R : "<< IntEff <<" pR = "<< pR <<endl ;
}
if ( !skipL && xL[0] > 0. ) {
xL[0] -= step ;
pL = BinomialErr( xL, par ) ;
IntEff += (pL*step*(N_all+1) ) ;
cout<<" ("<< xL[0] <<") <-- L : "<< IntEff <<" pL = "<< pL <<endl;
}
cout<<" ------ "<<endl;
skipR = ( pL > pR ) ? true : false ;
skipL = ( pL < pR ) ? true : false ;
if ( pL == pR ) {
skipR = false ;
skipL = false ;
}
}
//cout<<" ["<< N_pass/N_all <<"] Prob = "<< IntEff <<endl ;
//cout<<" - "<< (N_pass/N_all) - xL[0] <<endl ;
//cout<<" + "<< xR[0] - (N_pass/N_all) <<endl ;
double upErr = xR[0] - eff0 ;
double dnErr = eff0 - xL[0] ;
pair<double,double> theErr = make_pair( upErr, dnErr );
return theErr ;
}
Double_t BinomialErr( Double_t* x, Double_t* par ) {
Double_t N_all = par[1] ;
Double_t N_pass = par[2] ;
//Double_t Bxy = TMath::Beta( ( N_pass + 1 ), ( N_all - N_pass + 1 ) ) ;
//cout<< " Beta(x,y) = "<< Bxy <<endl ;
//Double_t Cnk = pow(x[0], N_pass ) * pow( (1-x[0]) , (N_all - N_pass) ) ;
//Double_t prob = par[0]*Cnk / ( Bxy * (N_all + 1. ) );
double betaPDF = TMath::BetaDist( x[0], (N_pass + 1) , (N_all - N_pass + 1) ) ;
printf(" ( %f,%.1f,%.1f,%.1f ) = %f\n", x[0], par[0], par[1], par[2], betaPDF ) ;
Double_t prob = (par[0] / (N_all + 1.) ) * betaPDF ;
if ( x[0] < 0. || x[0] > 1. ) prob = 0. ;
return prob ;
}