bdt_com.C
Go to the documentation of this file.
1 {
2  const int nhists=7;
3  TString hists[nhists]={"efrac_2sig","emaxfrac_6plane","Efrac_sumplane9","efrac_plane2","efrac_plane3","efrac_plane4","BDT7ratio"};
4  TString hists_name[nhists]={"Fraction of energy in 2#sigma road","Maximum fraction of energy in 6-continuous planes","Fraction of energy in frist 10 planes","Fraction of energy in 2nd plane","Fraction of energy in 3rd plane","Fraction energy in 4th plane","BDT7 output"};
5 
6  double minXbin[nhists]={0.9,0,0,0,0,0,-0.3};
7  double maxXbin[nhists]={1.01,0.2,0.2,0.025,0.025,0.025,0.3};
8 
9  int nxbins[nhists]={120,20,40,200,200,200,50};
10  double lxbins[nhists]={0,0,0,0,0,0,-1};
11  double hxbins[nhists]={1.2,0.2,0.2,0.2,0.2,0.2,1};
12 
13  TFile *fd = new TFile("data_results.root");
14  TFile *fmc = new TFile("makeplots_LID02/data_results.root");
15 
16  gStyle->SetOptStat(0);
17 
18  for( int ih=0; ih<nhists; ++ih ){
19 
20  TH1F *hmc = (TH1F*)fmc->Get(hists[ih]);
21  TH1F *hd = (TH1F*)fd->Get(hists[ih]);
22 
23  TString ratio_name="ratio_"+nhists[ih];
24  TH1F *hratio=new TH1F(ratio_name,"",nxbins[ih],lxbins[ih],hxbins[ih]);
25  hratio->Sumw2();
26  for( int ibin=1; ibin<hratio->GetNbinsX()+1; ++ibin ){
27  double bin_data=hd->GetBinContent(ibin);
28  double err_data=hd->GetBinError(ibin);
29  double bin_mc=hmc->GetBinContent(ibin);
30  double err_mc=hmc->GetBinError(ibin);
31  double bin_con=0.;
32  double bin_err=0.;
33  if( bin_data>0. && bin_mc>0. ){
34  bin_con=bin_data/bin_mc;
35  bin_err = sqrt((err_mc/bin_mc)**2+(err_data/bin_data)**2);
36  }
37  hratio->SetBinContent(ibin,bin_con);
38  hratio->SetBinError(ibin,bin_con*bin_err);
39  }
40 
41 
42  //create canvas
43  TString can_name="variable_"+hists[ih];
44  TCanvas *c1 = new TCanvas(can_name,"",700,600);
45  c1->cd();
46 
47  pad1 = new TPad("pad1", "",0,0,0.99,0.99);
48  pad1->Draw();
49  pad1->cd();
50  pad1->Range(-1.081083,0.6027835,104.4476,1.087781);
51  pad1->SetFillColor(0);
52  pad1->SetBorderMode(0);
53  pad1->SetBorderSize(2);
54  pad1->SetLeftMargin(0.1523859);
55  pad1->SetRightMargin(0.04214559);
56  pad1->SetTopMargin(0.07790022);
57  pad1->SetBottomMargin(0.3035405);
58  pad1->SetFrameBorderMode(0);
59  pad1->SetFrameBorderMode(0);
60 
61  //2D hist template
62  TString h2f_name="h2f_"+hists[ih];
63  TH2F *h2f = new TH2F(h2f_name,"Rock muons",100,minXbin[ih],maxXbin[ih],100,0.5,8000);
64  //h2f->SetXTitle(hists_name[ih]);
65  //h2f->SetYTitle(ytitles[ih]);
66  //h2f->GetYaxis()->SetTitleOffset(2.0);
67  h2f->Draw();
68 
69  hmc->SetLineColor(4);
70  hmc->SetMarkerColor(4);
71  hmc->SetMarkerStyle(24);
72  hmc->Draw("E0 same");
73 
74  hd->SetMarkerStyle(8);
75  hd->SetLineColor(1);
76  hd->Draw("E0 same");
77 
78  TLegend *leg = new TLegend(0.6,0.6,0.89,0.89);
79  leg->SetLineColor(0);
80  leg->SetFillColor(0);
81  leg->AddEntry(hd,"new","p");
82  leg->AddEntry(hmc,"old","p");
83  leg->Draw("same");
84 
85  //TString gifname="gif/"+can_name+".gif";
86  //c1->Print(gifname);
87 
88  pad2 = new TPad("pad2", "",0,0,0.99,0.3);
89  pad2->Draw();
90  pad2->cd();
91  pad2->Range(-1.081081,0.6526316,103.3923,1.202863);
92  pad2->SetFillColor(0);
93  pad2->SetBorderMode(0);
94  pad2->SetBorderSize(2);
95  pad2->SetLeftMargin(0.1539252);
96  pad2->SetRightMargin(0.0324703);
97  pad2->SetTopMargin(0.005203551);
98  pad2->SetBottomMargin(0.2678298);
99  pad2->SetFrameBorderMode(0);
100  pad2->SetFrameBorderMode(0);
101  pad2->SetGridy();
102 
103  TString h2f2_name="h2f2_"+hists[ih];
104  TH2F *h2f2 = new TH2F(h2f2_name,"",100,minXbin[ih],maxXbin[ih],100,0.01,1.99);
105  h2f2->SetXTitle(hists_name[ih]);
106  h2f2->SetYTitle("data/MC");
107  h2f2->GetXaxis()->SetLabelSize(0.1);
108  h2f2->GetXaxis()->SetTitleSize(0.13);
109  h2f2->GetXaxis()->SetTitleOffset(0.85);
110  h2f2->GetYaxis()->SetLabelSize(0.12);
111  h2f2->GetYaxis()->SetTitleSize(0.13);
112  h2f2->GetYaxis()->SetTitleOffset(0.5);
113  h2f2->GetYaxis()->SetNdivisions(011);
114  h2f2->Draw();
115 
116  hratio->SetMarkerStyle(24);
117  hratio->SetLineColor(2);
118  hratio->SetMarkerColor(2);
119  hratio->Draw("E0 same");
120  }
121 
122 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
double hxbins[nhists]
Definition: bdt_com.C:11
TFile * fmc
Definition: bdt_com.C:14
TString hists[nhists]
Definition: bdt_com.C:3
double maxXbin[nhists]
Definition: bdt_com.C:7
TString hists_name[nhists]
Definition: bdt_com.C:4
TH2F * h2f2
Definition: plots_total.C:74
double minXbin[nhists]
Definition: bdt_com.C:6
c1
Definition: demo5.py:24
TFile * fd
Definition: bdt_com.C:13
TPad * pad2
Definition: analysis.C:13
TH2F * h2f
Definition: plots_total.C:62
int nxbins[nhists]
Definition: bdt_com.C:9
TH1F * hd
Definition: Xdiff_gwt.C:57
TPad * pad1
Definition: analysis.C:13
double lxbins[nhists]
Definition: bdt_com.C:10