ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/jbabb/ScriptsAndMacros/EfficiencyPlotter.C
Revision: 1.1
Committed: Sat Sep 3 21:22:22 2011 UTC (13 years, 8 months ago) by jbabb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 //Plots efficiencies...
2
3 //ROOT includes
4 #include "TFile.h"
5 #include "TH1F.h"
6 #include "TGraph.h"
7
8
9 //System includes
10 #include <TObject.h>
11 #include <TMinuit.h>
12 #include <TLorentzVector.h>
13 #include <TMath.h>
14 #include <TString.h>
15 #include <TStyle.h>
16 #include <TLegend.h>
17 #include <TCanvas.h>
18 #include <TPad.h>
19 #include <TGraphErrors.h>
20 #include <TSystem.h>
21 #include <vector>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <iostream>
25 #include <string>
26
27
28 void EfficiencyPlotter() {
29
30 TFile *f = new TFile("efficiencyPlots_data.root", "recreate");
31 TFile *inputFile1 = new TFile("./files/TagAndProbe/tnp_MC_noJetReq_noTrigReq_AltBin.root", "open");
32 //TFile *inputFile2 = new TFile("./files/TagAndProbe/tnp_DATA_noJetReq_noTrigReq2_AltBin.root", "open");
33 //TFile *inputFile3 = new TFile("./files/TagAndProbe/tnp_DATA_noJetReq_noTrigReq3_AltBin.root", "open");
34 //TFile *inputFile4 = new TFile("./files/TagAndProbe/tnp_DATA_noJetReq_noTrigReq4_AltBin.root", "open");
35 //TFile *inputFile5 = new TFile("./files/TagAndProbe/tnp_DATA_noJetReq_noTrigReq5_AltBin.root", "open");
36 TString PlotType = "_MC_AltBin.png";
37
38 //List the variables that we want plots of
39 int nVariables = 4;
40 int nBins[4] = { 5, 5, 5, 5};
41 TString VariableList[4] = { "drMin", "eta", "pt", "relPt" };
42 //double VariableMax[4] = { 5., 2.1, 200., 200. };
43 //double VariableMin[4] = { 0., -2.1, 0., 0.};
44
45
46 //Loop over all of the variables we want to plot
47 for ( int i = 0; i < nVariables; i++ ) {
48
49 probePlot1 = (TH1F *)inputFile1->Get(VariableList[i]+"_probe");
50 passPlot1 = (TH1F *)inputFile1->Get(VariableList[i]+"_pass");
51
52 //probePlot2 = (TH1F *)inputFile2->Get(VariableList[i]+"_probe");
53 //passPlot2 = (TH1F *)inputFile2->Get(VariableList[i]+"_pass");
54
55 //probePlot3 = (TH1F *)inputFile3->Get(VariableList[i]+"_probe");
56 //passPlot3 = (TH1F *)inputFile3->Get(VariableList[i]+"_pass");
57
58 //probePlot4 = (TH1F *)inputFile4->Get(VariableList[i]+"_probe");
59 //passPlot4 = (TH1F *)inputFile4->Get(VariableList[i]+"_pass");
60
61 //probePlot5 = (TH1F *)inputFile5->Get(VariableList[i]+"_probe");
62 //passPlot5 = (TH1F *)inputFile5->Get(VariableList[i]+"_pass");
63
64
65 TCanvas* c1 = new TCanvas("c1","", 600, 600);
66 c1->cd();
67
68 const int n = 5;
69 const int m = 5;
70
71
72 Float_t x[n];
73 Float_t y[n];
74
75 Float_t ex[n];
76 Float_t ey[n];
77
78
79 for ( int j = 0; j < nBins[i]; j++ ) {
80
81
82 float nPass1 = passPlot1->GetBinContent(j+1);
83 float nProbe1 = probePlot1->GetBinContent(j+1);
84
85 //float nPass2 = passPlot2->GetBinContent(j+1);
86 //float nProbe2 = probePlot2->GetBinContent(j+1);
87
88 //float nPass3 = passPlot3->GetBinContent(j+1);
89 //float nProbe3 = probePlot3->GetBinContent(j+1);
90
91 //float nPass4 = passPlot4->GetBinContent(j+1);
92 //float nProbe4 = probePlot4->GetBinContent(j+1);
93
94 //float nPass5 = passPlot5->GetBinContent(j+1);
95 //float nProbe5 = probePlot5->GetBinContent(j+1);
96
97
98 //float sumPass = (float) nPass1+nPass2+nPass3+nPass4+nPass5;
99 //float sumProbe = (float) nProbe1+nProbe2+nProbe3+nProbe4+nProbe5;
100
101 float sumPass = (float) nPass1;
102 float sumProbe = (float) nProbe1;
103
104 float efficiency = 0.;
105 if (sumProbe > 0.99) efficiency = (sumPass) / (sumProbe);
106
107 float error = 0.;
108
109 //if (nPass >= 10) {
110
111 //If > 10 per bin use gaussian errors
112 if (sumProbe > 0.99 && sumPass > 0.99) error = efficiency * sqrt ( 1./(float)sumPass + 1./(float)sumProbe );
113
114 //}
115
116 //take info from histos and put them in graphs
117 x[j] = passPlot1->GetBinCenter(j+1);
118 y[j] = efficiency;
119 //ex[j] = passPlot->GetBinWidth(j+1) / 2.;
120 ex[j] = 0.;
121 ey[j] = error;
122
123 }
124
125
126 gr = new TGraphErrors(n,x,y,ex,ey);
127 gr->SetTitle(VariableList[i]);
128 gr->SetMarkerColor(4);
129 gr->SetMarkerStyle(21);
130 gr->GetYaxis()->SetRangeUser(0.1, 1.5);
131 gr->GetYaxis()->SetTitle("Efficiency");
132 if (i == 0) gr->GetXaxis()->SetTitle("#Delta R_{min} (#mu, jet)");
133 else if (i == 1) gr->GetXaxis()->SetTitle("eta");
134 else if (i == 2) gr->GetXaxis()->SetTitle("p_{T}");
135 else if (i == 3) gr->GetXaxis()->SetTitle("p_{T}^{rel} (#mu, jet)");
136 gr->Draw("AP");
137
138 c1->Update();
139 c1->Print( VariableList[i]+PlotType );
140 delete c1;
141
142 f->cd();
143
144 gr->Write();
145
146 }//for nVariables
147
148
149
150 f->cd();
151 f->Write();
152 f->Close();
153
154
155 }//EfficiencyPlotter()