forked from uwcms/UCT2015
/
plotEfficiency.C
194 lines (141 loc) · 5.02 KB
/
plotEfficiency.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
/*******************************************************************
* Project: CMS detector at the CERN
*
* Package: Presently in the user code
*
*
* Authors:
*
* Kalanand Mishra, Fermilab - kalanand@fnal.gov
*
* Description:
* Plots muon Level-1 trigger efficiency
*
* Implementation details:
* Simple ROOT macro to plot L1 efficiency.
* Match L1 muon to UCT15 calo deposit to compute isolation.
*
* History:
*
*
* Copyright (C) 2012 FNAL
********************************************************************/
void plotEfficiency()
{
// plotEfficiency("Pt", 0., 120.);
// plotEfficiency("Eta", -2.5, 2.5);
plotEfficiency("Pt", 0., 120., 12);
// plotEfficiency("Pt", 0., 120., 18);
// plotEfficiency("Pt", 0., 120., 24);
plotEfficiency("Eta", -2.5, 2.5, 12);
// plotEfficiency("Eta", -2.5, 2.5, 18);
// plotEfficiency("Eta", -2.5, 2.5, 24);
}
void plotEfficiency(char* var, double min, double max, int l1PtMin=0) {
TFile*f1 = TFile::Open("efficiency_tree_Zmumu_merged.root");
f1->cd("muonEfficiency");
TTree* tree1 = (TTree*) gDirectory->Get("Ntuple");
int nBins = 100;
if(var=="Pt") nBins = (int) ((max - min) / 5);
if(var=="Eta") nBins = (int) ((max - min) / 0.2);
///// ----- Define your cuts ----------
char l1PtMinStr[100];
sprintf(l1PtMinStr, "l1Pt>%d", l1PtMin);
TCut l1PtMinCut(l1PtMinStr);
TCut cutNPV0("(nPVs>-1)");
TCut cutNPV1("(nPVs>=0 && nPVs<15)");
TCut cutNPV2("(nPVs>=15 && nPVs<25)");
TCut cutNPV3("(nPVs>=25 && nPVs<200)");
TCut l1isoCut("(abs(l1gDR)>0.2 || (l1gRegionEt/l1Pt<0.5))");
///// ----- Create all the histograms ----------
TH1D* allReco = new TH1D("allReco", "", nBins, min, max);
allReco->SetLineWidth(2);
allReco->Sumw2();
TH1D* allRecoNPV1 = allReco->Clone("allRecoNPV1");
TH1D* allRecoNPV2 = allReco->Clone("allRecoNPV2");
TH1D* allRecoNPV3 = allReco->Clone("allRecoNPV3");
TH1D* l1iso = allReco->Clone("l1iso");
TH1D* l1isoNPV1 = allReco->Clone("l1isoNPV1");
TH1D* l1isoNPV2 = allReco->Clone("l1isoNPV2");
TH1D* l1isoNPV3 = allReco->Clone("l1isoNPV3");
l1isoNPV1->SetLineColor(4);
l1isoNPV1->SetMarkerColor(4);
l1isoNPV2->SetLineColor(6);
l1isoNPV2->SetMarkerColor(6);
l1isoNPV3->SetLineColor(2);
l1isoNPV3->SetMarkerColor(2);
l1iso->GetYaxis()->SetRangeUser(0.5, 1.1);
l1iso->GetYaxis()->SetTitle("L1 Efficiency");
char* xtitle = var;
if(var=="Pt") xtitle = "Offline muon p_{T} (GeV)";
if(var=="Eta") xtitle = "Offline muon #eta";
l1iso->GetXaxis()->SetTitle(xtitle);
///// ----- Draw from tree ----------
TString varName = TString("reco") + TString(var);
tree1->Draw(varName+TString(">>allReco"),cutNPV0,"goff");
tree1->Draw(varName+TString(">>allRecoNPV1"),cutNPV1,"goff");
tree1->Draw(varName+TString(">>allRecoNPV2"),cutNPV2,"goff");
tree1->Draw(varName+TString(">>allRecoNPV3"),cutNPV3,"goff");
tree1->Draw(varName+TString(">>l1iso"),l1PtMinCut && cutNPV0 && l1isoCut,"goff");
tree1->Draw(varName+TString(">>l1isoNPV1"),l1PtMinCut && cutNPV1 && l1isoCut,"goff");
tree1->Draw(varName+TString(">>l1isoNPV2"),l1PtMinCut && cutNPV2 && l1isoCut,"goff");
tree1->Draw(varName+TString(">>l1isoNPV3"),l1PtMinCut && cutNPV3 && l1isoCut,"goff");
//// ---- Now divide by allReco histogram to obtain efficiency ----
l1iso->Divide(allReco);
l1isoNPV1->Divide(allRecoNPV1);
l1isoNPV2->Divide(allRecoNPV2);
l1isoNPV3->Divide(allRecoNPV3);
// --- plot the efficiency histograms ------
gROOT->ProcessLine(".L ~/tdrstyle.C");
setTDRStyle();
tdrStyle->SetErrorX(0.5);
tdrStyle->SetPadLeftMargin(0.18);
tdrStyle->SetPadRightMargin(0.08);
tdrStyle->SetLegendBorderSize(0);
tdrStyle->SetTitleYOffset(1.3);
TCanvas* canEffIso = new TCanvas("canEffIso","",500,500);
l1iso->SetFillColor(5);
l1iso->Draw("e3");
l1iso->Draw("esame");
l1isoNPV1->Draw("psame");
l1isoNPV2->Draw("psame");
l1isoNPV3->Draw("psame");
l1iso->Draw("esame");
TLegend* legend = new TLegend(0.45,0.15,0.9,0.45);
legend->SetFillColor(0);
legend->AddEntry(l1iso, "All NPV", "PLE");
legend->AddEntry(l1isoNPV1, "NPV: 0-15", "PLE");
legend->AddEntry(l1isoNPV2, "NPV: 15-25", "PLE");
legend->AddEntry(l1isoNPV3, "NPV: 25-above", "PLE");
legend->Draw();
cmsPrelim();
TString plotname = TString("muonEfficiency_")+TString(var);
char tempst[100];
sprintf(tempst, "_l1Pt_%d", l1PtMin);
plotname += TString(tempst);
canEffIso->SetGridy();
canEffIso->SaveAs(plotname+TString(".png"));
canEffIso->SaveAs(plotname+TString(".pdf"));
//--------- Finally clean up the memory -------
delete allReco;
delete allRecoNPV1;
delete allRecoNPV2;
delete allRecoNPV3;
delete l1iso;
delete l1isoNPV1;
delete l1isoNPV2;
delete l1isoNPV3;
delete canEffIso;
delete legend;
}
////CMS Preliminary label and lumu
void cmsPrelim()
{
TLatex latex;
latex.SetNDC();
latex.SetTextSize(0.04);
latex.SetTextAlign(31); // align right
latex.DrawLatex(0.90,0.96,"#sqrt{s} = 8 TeV");
latex.SetTextAlign(11); // align left
latex.DrawLatex(0.18,0.96,"CMS preliminary 2012");
}