-
Notifications
You must be signed in to change notification settings - Fork 0
/
AfbRecoLevel2Dttpt.cxx
234 lines (193 loc) · 7.62 KB
/
AfbRecoLevel2Dttpt.cxx
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
/// Script for plotting Afb variables at the reco level
// S. Jindariani, J.Linacre, Y.Tu
#include <iostream>
using std::cout;
using std::endl;
#include "TRandom3.h"
#include "TH1D.h"
#include "TStyle.h"
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TMatrixD.h"
#include "TChain.h"
#include "TLegend.h"
#include "TColor.h"
#include "THStack.h"
#include "TCut.h"
#include "TText.h"
#include "TPaveText.h"
#include "tdrStyle.C"
#include "RooUnfold/examples/AfbFinalUnfold.h"
std::string formatFloat(double x, const char* formatS) {
std::string xS = Form(Form("%s", formatS),x);
double xB = atof(xS.c_str());
if (x>0 && xB==0){
xS = Form(" %6.1g",x);
}
return xS;
}
//==============================================================================
// Global definitions
//==============================================================================
const Double_t _topScalingFactor=9097.0/9344.0;
void AfbRecoLevel2Dttpt()
{
// setTDRStyle();
gStyle->SetOptFit();
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
cout.precision(3);
TString observablename;
TString xaxislabel;
Float_t observable, ttpt;
Float_t observableMinus;
Double_t weight;
Int_t Nsolns;
int nVars = 8;
for (Int_t iVar= 0; iVar < nVars; iVar++) {
Initialize2DBinningttpt(iVar);
bool combineLepMinus = acceptanceName=="lepCosTheta" ? true : false;
TH1D* hData= new TH1D ("Data", "Data", nbins2D, xbins2D);
TH1D* hBkg = new TH1D ("Background", "Background", nbins2D, xbins2D);
TH1D* hTop = new TH1D ("Top", "Top", nbins2D, xbins2D);
hData->Sumw2();
hTop->Sumw2();
hBkg->Sumw2();
TChain *ch_data = new TChain("tree");
ch_data->Add("data.root");
ch_data->SetBranchAddress(observablename, &observable);
if( combineLepMinus ) ch_data->SetBranchAddress("lepMinus_costheta_cms", &observableMinus);
ch_data->SetBranchAddress("weight",&weight);
ch_data->SetBranchAddress("Nsolns",&Nsolns);
ch_data->SetBranchAddress("ttPt",&ttpt);
for (Int_t i= 0; i<ch_data->GetEntries(); i++) {
ch_data->GetEntry(i);
if ( ttpt > 0 ) {
if(observablename=="lep_azimuthal_asymmetry2") observable = -cos(observable);
fillUnderOverFlow(hData, sign(observable)*ttpt, weight, Nsolns);
if (combineLepMinus) {
fillUnderOverFlow(hData, sign(observableMinus)*ttpt, weight, Nsolns);
}
}
}
TChain *ch_top = new TChain("tree");
ch_top->Add("ttdil.root");
ch_top->SetBranchAddress(observablename, &observable);
if( combineLepMinus ) ch_top->SetBranchAddress("lepMinus_costheta_cms", &observableMinus);
ch_top->SetBranchAddress("weight",&weight);
ch_top->SetBranchAddress("Nsolns",&Nsolns);
ch_top->SetBranchAddress("ttPt",&ttpt);
for (Int_t i= 0; i<ch_top->GetEntries(); i++) {
ch_top->GetEntry(i);
if(observablename=="lep_azimuthal_asymmetry2") observable = -cos(observable);
if ( ttpt > 0 ) {
fillUnderOverFlow(hTop, sign(observable)*ttpt, weight, Nsolns);
if (combineLepMinus) {
fillUnderOverFlow(hTop, sign(observableMinus)*ttpt, weight, Nsolns);
}
}
}
TChain *ch_bkg = new TChain("tree");
ch_bkg->Add("ttotr.root");
ch_bkg->Add("wjets.root");
ch_bkg->Add("DYee.root");
ch_bkg->Add("DYmm.root");
ch_bkg->Add("DYtautau.root");
ch_bkg->Add("tw.root");
ch_bkg->Add("VV.root");
ch_bkg->SetBranchAddress(observablename, &observable);
if( combineLepMinus ) ch_bkg->SetBranchAddress("lepMinus_costheta_cms", &observableMinus);
ch_bkg->SetBranchAddress("weight",&weight);
ch_bkg->SetBranchAddress("Nsolns",&Nsolns);
ch_bkg->SetBranchAddress("ttPt",&ttpt);
for (Int_t i= 0; i<ch_bkg->GetEntries(); i++) {
ch_bkg->GetEntry(i);
if(observablename=="lep_azimuthal_asymmetry2") observable = -cos(observable);
if ( ttpt > 0 ) {
fillUnderOverFlow(hBkg, sign(observable)*ttpt, weight, Nsolns);
if( combineLepMinus ) {
fillUnderOverFlow(hBkg, sign(observableMinus)*ttpt, weight, Nsolns);
}
}
}
hTop->Scale(_topScalingFactor);
TH1D* hTop_bkgAdd= (TH1D*) hTop->Clone();
hTop_bkgAdd->Add(hBkg);
//==================================================================
// ============== Print the assymetry =============================
cout<<"========= Variable:"<<observablename <<" ===================\n";
Float_t Afb, AfbErr;
const char* formatS = "%6.3f";
GetAfb(hData, Afb, AfbErr);
cout<<" Data: "<< formatFloat(Afb,formatS) <<" +/- "<< formatFloat(AfbErr,formatS)<<"\n";
GetAfb(hTop_bkgAdd, Afb, AfbErr);
cout<<" True Top: "<<formatFloat(Afb,formatS) <<" +/- "<< formatFloat(AfbErr,formatS)<<"\n";
// hData->Scale(1./hData->Integral(),"width");
// hTop->Scale(1./(hTop->Integral()+hBkg->Integral()),"width");
// hBkg->Scale(1./(hTop->Integral()+hBkg->Integral()),"width");
for (Int_t i= 1; i<=nbins2D; i++) {
hData->SetBinContent(i, hData->GetBinContent(i)/hData->GetBinWidth(i) );
hData->SetBinError(i, hData->GetBinError(i)/hData->GetBinWidth(i) );
hTop->SetBinContent(i, hTop->GetBinContent(i)/hTop->GetBinWidth(i) );
hTop->SetBinError(i, hTop->GetBinError(i)/hTop->GetBinWidth(i) );
hBkg->SetBinContent(i, hBkg->GetBinContent(i)/hBkg->GetBinWidth(i) );
hBkg->SetBinError(i, hBkg->GetBinError(i)/hBkg->GetBinWidth(i) );
}
TCanvas* c_test = new TCanvas("c_final","c_final",500,500);
c_test->SetLeftMargin(0.2);
hData->SetMinimum(0.0);
hData->SetMaximum( 2.0* hData->GetMaximum());
hData->GetXaxis()->SetTitle(xaxislabel);
hData->GetYaxis()->SetTitle("Events/"+xaxislabel+"");
hData->GetYaxis()->SetTitle("Events/"+xaxislabel+"");
hData->GetYaxis()->SetTitleOffset(1.6);
hData->SetLineWidth(lineWidth);
hTop->SetLineWidth(lineWidth);
hTop->SetMarkerSize(0.0);
hTop->SetLineColor(TColor::GetColorDark(kGreen));
hTop->SetFillColor(TColor::GetColorDark(kGreen));
hTop->SetFillStyle(3353);
hBkg->SetLineWidth(lineWidth);
hBkg->SetMarkerSize(0.0);
hBkg->SetLineColor(kYellow);
hBkg->SetFillColor(kYellow);
THStack *hs = new THStack("hs","Stacked Top+BG");
hs->Add(hBkg);
hs->Add(hTop);
hs->SetMinimum(0.0);
hs->SetMaximum( 2.0* hs->GetMaximum());
hs->Draw("hist");
hs->GetXaxis()->SetTitle(xaxislabel);
hs->GetYaxis()->SetTitle("Events/"+xaxislabel+"");
hs->GetYaxis()->SetTitle("Events/"+xaxislabel+"");
hs->GetYaxis()->SetTitleOffset(1.6);
hData->Draw("E same");
TLegend* leg1=new TLegend(0.6,0.62,0.9,0.838,NULL,"brNDC");
leg1->SetFillStyle(0);
leg1->SetEntrySeparation(100);
leg1->SetBorderSize(0);
leg1->SetTextSize(0.03);
leg1->AddEntry(hData, "Data");
leg1->AddEntry(hTop, "t#bar{t} (dileptonic)");
leg1->AddEntry(hBkg, "Background");
leg1->Draw();
TPaveText *pt1 = new TPaveText(0.19, 0.82, 0.42, 0.86, "brNDC");
pt1->SetName("pt1name");
pt1->SetBorderSize(0);
pt1->SetFillStyle(0);
TText *blah;
blah = pt1->AddText("CMS Preliminary, 5.0 fb^{-1} at #sqrt{s}=7 TeV");
blah->SetTextSize(0.035);
blah->SetTextAlign(11);
pt1->Draw();
c_test->SaveAs("2D_ttpt_reco_"+acceptanceName+".pdf");
delete hData;
delete hBkg;
delete hTop;
delete hTop_bkgAdd;
}
}
#ifndef __CINT__
int main () { AfbRecoLevel(); return 0; } // Main program when run stand-alone
#endif