-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedianCalc.C
70 lines (55 loc) · 1.77 KB
/
medianCalc.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
#include "TTree.h"
#include "TROOT.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TFile.h"
#include <algorithm>
void medianCalc(std::string name,TTree *tree,double *lim,double *up68,double *dn68
,double *up95,double *dn95){
TH1F hist_r(Form("hist_r_%s",name.c_str()),";r;",100,0.,30.);
double r;
int nLimits = tree->GetEntriesFast();
tree->SetBranchAddress("limit",&r);
std::vector<double> limitHistory;
for (int i=0;i<nLimits;i++){
tree->GetEntry(i);
limitHistory.push_back(r);
hist_r.Fill(r);
}
sort(limitHistory.begin(), limitHistory.end());
if (nLimits > 0) {
double medianLimit = (nLimits % 2 == 0 ? 0.5*(limitHistory[nLimits/2-1]
+limitHistory[nLimits/2]) : limitHistory[nLimits/2]);
double hi68 = limitHistory[min<int>(nLimits-1, ceil(0.84 * nLimits))];
double lo68 = limitHistory[min<int>(nLimits-1, floor(0.16 * nLimits))];
double hi95 = limitHistory[min<int>(nLimits-1, ceil(0.975 * nLimits))];
double lo95 = limitHistory[min<int>(nLimits-1, floor(0.025 * nLimits))];
*lim = medianLimit;
*up68 = hi68;
*dn68 = lo68;
*up95 = hi95;
*dn95 = lo95;
} else {
*lim = 0;
*up68 = 0;
*dn68 = 0;
*up95 = 0;
*dn95 = 0;
}
gROOT->SetStyle("Plain");
TCanvas *can = new TCanvas();
can->SetLogy();
hist_r.SetFillStyle(1001);
hist_r.SetFillColor(kBlue);
hist_r.Draw();
can->SaveAs(Form("%s.pdf",name.c_str()));
can->SaveAs(Form("%s.gif",name.c_str()));
}
double FrequentistLimits(std::string filename) {
double r=-9999;
TFile *LimitFile = TFile::Open(filename.c_str());
TTree *LimitTree = (TTree*) LimitFile->Get("limit");
LimitTree->SetBranchAddress("limit",&r);
LimitTree->GetEntry(0);
return r;
}