forked from aparikh0694/Residual_Dijet_JEC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
casympp.cpp
363 lines (336 loc) · 16.3 KB
/
casympp.cpp
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#include <math.h>
#include <TMath.h>
#include <TTree.h>
#include <TROOT.h>
#include <TFile.h>
#include <TH1.h>
#include <TH2.h>
#include <TRandom.h>
#include <cstdlib>
#include <Riostream.h>
#include <iostream>
#include <fstream>
#include <TAxis.h>
#include <TVirtualPad.h>
#include <TVirtualX.h>
#include <TStyle.h>
#include <TView.h>
#include <TError.h>
#include <TCanvas.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TLegend.h>
#include <TLatex.h>
#define PI 3.14159265
void casympp() {
for (int filecounter = 0; filecounter < 5; filecounter++) {//FILE LOOP
if (filecounter == 0) {
TFile *montecarlo = new TFile("relativeresponsemc1234.root", "Read"); // 40 TO 60 PT AVERAGE
if (montecarlo->IsOpen()) printf("MonteCarlo File Opened Successfully.\n");
montecarlo->ls();
TGraphErrors *relrespmc = (TGraphErrors *)montecarlo->Get("Graph;1 Relative Response");
TGraphErrors *meanetamc = (TGraphErrors *)montecarlo->Get("Graph;2 Mean Eta Per Bin");
TFile *ppdata = new TFile("relativeresponse1234.root"); // 40 TO 60 PT AVERAGE
if (ppdata->IsOpen()) printf ("PP Data File Opened Successfully.\n");
ppdata->ls();
TGraphErrors *relresp = (TGraphErrors *)ppdata->Get("Graph;1 Relative Response");
TGraphErrors *meaneta = (TGraphErrors *)ppdata->Get("Graph;2 Mean Eta Per Bin");
cout << "File 1 Opened Successfully" << endl;
}
if (filecounter == 1) {
TFile *montecarlo = new TFile("relativeresponsemc123.root", "Read"); // 60 TO 80 PT AVERAGE
if (montecarlo->IsOpen()) printf("MonteCarlo File Opened Successfully.\n");
montecarlo->ls();
TGraphErrors *relrespmc = (TGraphErrors *)montecarlo->Get("Graph;1 Relative Response");
TGraphErrors *meanetamc = (TGraphErrors *)montecarlo->Get("Graph;2 Mean Eta Per Bin");
TFile *ppdata = new TFile("relativeresponse123.root"); // 60 TO 80 PT AVERAGE
if (ppdata->IsOpen()) printf ("PP Data File Opened Successfully.\n");
ppdata->ls();
TGraphErrors *relresp = (TGraphErrors *)ppdata->Get("Graph;1 Relative Response");
TGraphErrors *meaneta = (TGraphErrors *)ppdata->Get("Graph;2 Mean Eta Per Bin");
cout << "File 2 Opened Successfully" << endl;
}
if (filecounter == 2) {
TFile *montecarlo = new TFile("relativeresponsemc1.root", "Read"); // 80 TO 100 PT AVERAGE
if (montecarlo->IsOpen()) printf("MonteCarlo File Opened Successfully.\n");
montecarlo->ls();
TGraphErrors *relrespmc = (TGraphErrors *)montecarlo->Get("Graph;1 Relative Response");
TGraphErrors *meanetamc = (TGraphErrors *)montecarlo->Get("Graph;2 Mean Eta Per Bin");
TFile *ppdata = new TFile("relativeresponse1.root"); // 80 TO 100 PT AVERAGE
if (ppdata->IsOpen()) printf ("PP Data File Opened Successfully.\n");
ppdata->ls();
TGraphErrors *relresp = (TGraphErrors *)ppdata->Get("Graph;1 Relative Response");
TGraphErrors *meaneta = (TGraphErrors *)ppdata->Get("Graph;2 Mean Eta Per Bin");
cout << "File 3 Opened Successfully" << endl;
}
if (filecounter == 3) {
TFile *montecarlo = new TFile("relativeresponsemc.root", "Read"); // 100 TO 140 PT AVERAGE
if (montecarlo->IsOpen()) printf("MonteCarlo File Opened Successfully.\n");
montecarlo->ls();
TGraphErrors *relrespmc = (TGraphErrors *)montecarlo->Get("Graph;1 Relative Response");
TGraphErrors *meanetamc = (TGraphErrors *)montecarlo->Get("Graph;2 Mean Eta Per Bin");
TFile *ppdata = new TFile("relativeresponse.root"); //100 TO 140 PT AVERAGE
if (ppdata->IsOpen()) printf ("PP Data File Opened Successfully.\n");
ppdata->ls();
TGraphErrors *relresp = (TGraphErrors *)ppdata->Get("Graph;1 Relative Response");
TGraphErrors *meaneta = (TGraphErrors *)ppdata->Get("Graph;2 Mean Eta Per Bin");
cout << "File 4 Opened Successfully" << endl;
}
if (filecounter == 4) {
TFile *montecarlo = new TFile("relativeresponsemc12.root", "Read"); // 140 TO 200 PT AVERAGE
if (montecarlo->IsOpen()) printf("MonteCarlo File Opened Successfully.\n");
montecarlo->ls();
TGraphErrors *relrespmc = (TGraphErrors *)montecarlo->Get("Graph;1 Relative Response");
TGraphErrors *meanetamc = (TGraphErrors *)montecarlo->Get("Graph;2 Mean Eta Per Bin");
TFile *ppdata = new TFile("relativeresponse12.root"); // 140 TO 200 PT AVERAGE
if (ppdata->IsOpen()) printf ("PP Data File Opened Successfully.\n");
ppdata->ls();
TGraphErrors *relresp = (TGraphErrors *)ppdata->Get("Graph;1 Relative Response");
TGraphErrors *meaneta = (TGraphErrors *)ppdata->Get("Graph;2 Mean Eta Per Bin");
cout << "File 5 Opened Successfully" << endl;
}
//TGraph *outermc = (TGraph *)montecarlo->Get("Graph;3");
//TGraph *outerdata = (TGraph *)ppdata->Get("Graph;3");
//TFile *myfile = new TFile("overlayrelresponse.root", "Recreate");
Int_t N_pt = relrespmc->GetN();
cout << N_pt << endl;
Float_t casym[83];
for (int ipt = 0; ipt < N_pt; ipt++) {
double x, y, xmc, ymc;
relrespmc->GetPoint(ipt, xmc, ymc);
relresp->GetPoint(ipt, x, y);
casym[ipt] = ymc/y;
cout << casym[ipt] << " and eta average is " << x << endl;
}
//OPEN FILE WITH PP DATA STORED IN MY TREE TO ASSIGN NEW BRANCHES WITH THE CORRECTION FACTOR APPLIED TO THE JETS
if (filecounter == 0) {
TFile *myfile = TFile::Open("outputrelresp1234.root"); // 40 TO 60 PT AVERAGE
if (myfile->IsOpen()) printf("File Containing Tree Opened Successfully.\n");
myfile->ls();
TTree *mytree = (TTree *)myfile->Get("rr");
TFile *outf = new TFile("outputrelrespcasym1234.root", "Recreate"); // 40 TO 60 PT AVERAGE
cout << "File 1" << endl;
}
if (filecounter == 1) {
TFile *myfile = TFile::Open("outputrelresp123.root"); // 60 TO 80 PT AVERAGE
if (myfile->IsOpen()) printf("File Containing Tree Opened Successfully.\n");
myfile->ls();
TTree *mytree = (TTree *)myfile->Get("rr");
TFile *outf = new TFile("outputrelrespcasym123.root", "Recreate"); // 60 TO 80 PT AVERAGE
cout << "File 2" << endl;
}
if (filecounter == 2) {
TFile *myfile = TFile::Open("outputrelresp1.root"); // 80 TO 100 PT AVERAGE
if (myfile->IsOpen()) printf("File Containing Tree Opened Successfully.\n");
myfile->ls();
TTree *mytree = (TTree *)myfile->Get("rr");
TFile *outf = new TFile("outputrelrespcasym1.root", "Recreate"); // 80 TO 100 PT AVERAGE
cout << "File 3" << endl;
}
if (filecounter == 3) {
TFile *myfile = TFile::Open("outputrelresp.root"); // 100 TO 140 PT AVERAGE
if (myfile->IsOpen()) printf("File Containing Tree Opened Successfully.\n");
myfile->ls();
TTree *mytree = (TTree *)myfile->Get("rr");
TFile *outf = new TFile("outputrelrespcasym.root", "Recreate"); // 100 TO 140 PT AVERAGE
cout << "File 4" << endl;
}
if (filecounter == 4) {
TFile *myfile = TFile::Open("outputrelresp12.root"); // 140 TO 200 PT AVERAGE
if (myfile->IsOpen()) printf("File Containing Tree Opened Successfully.\n");
myfile->ls();
TTree *mytree = (TTree *)myfile->Get("rr");
TFile *outf = new TFile("outputrelrespcasym12.root", "Recreate"); // 140 TO 200 PT AVERAGE
cout << "File 5" << endl;
}
//INITIALIZING NECESSARY VARIABLES
const int nEvents = mytree->GetEntries();
Float_t etaprobe;
Float_t ptprobe;
Float_t etaref;
Float_t ptref;
Float_t ptprobecorr = -999;
Float_t ptrefcorr = -999;
Float_t myetaprobe2 = -999;
Float_t myptprobe2 = -999;
Float_t myetaref2 = -999;
Float_t myptref2 = -999;
Float_t myb2 = -999;
//DECLARING BRANCHES
TTree *rr2 = new TTree ("rr2", "rr2");
rr2->Branch("ptprobecorr", &ptprobecorr, "ptprobecorr/F");
rr2->Branch("ptrefcorr", &ptrefcorr, "ptrefcorr/F");
rr2->Branch("myetaprobe2", &myetaprobe2, "myetaprobe2/F");
rr2->Branch("myptprobe2", &myptprobe2, "myptprobe2/F");
rr2->Branch("myetaref2", &myetaref2, "myetaref2/F");
rr2->Branch("myptref2", &myptref2, "myptref2/F");
rr2->Branch("myb2", &myb2, "myb2/F");
cout << "Stage 1 Complete" << endl;
Float_t cms_hcal_edge_pseudorapidity[] = {-5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013, -3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853, -2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830, -1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218, -1.131, -1.044, -0.957, -0.879, -0.783, -0.696, -0.609, -0.522, -0.435, -0.348, -0.261, -0.174, -0.087, 0.000, 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.696, 0.783, 0.879, 0.957, 1.044, 1.131, 1.218, 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830, 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853, 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
cout << "a" << endl;
Int_t bins = sizeof(cms_hcal_edge_pseudorapidity)/sizeof(Float_t);
cout << bins << endl;
cout << "b" << endl;
mytree->SetMakeClass(1);
mytree->SetBranchAddress("myetaprobe", &etaprobe);
cout << "c" << endl;
mytree->SetBranchAddress("myptprobe", &ptprobe);
cout << "d" << endl;
mytree->SetBranchAddress("myptref", &ptref);
cout << "e" << endl;
mytree->SetBranchAddress("myetaref", &etaref);
mytree->Print();
cout << "Stage 2 Complete" << endl;
for (int i = 0; i < nEvents; i++) {
mytree->GetEntry(i);
for (int bb = 0; bb < bins; bb++) {
if (cms_hcal_edge_pseudorapidity[bb] < etaprobe && etaprobe < cms_hcal_edge_pseudorapidity[bb+1]) {
ptprobecorr = ptprobe*casym[bb];
//cout << "Probe pt was " << ptprobe << " and corrected probe pt is " << ptprobecorr << " and my eta is " << etaprobe << " and my correction factor is " << casym[b] << endl;
}
if (cms_hcal_edge_pseudorapidity[bb] < etaref && etaref < cms_hcal_edge_pseudorapidity[bb+1]) {
ptrefcorr = ptref*casym[bb];
//cout << "Refence pt was " << ptref << " and corrected reference pt is " << ptrefcorr << " and my eta is " << etaref << " and my corection factor is " << casym[b] << endl;
}
}
//cout << "Probe pt was " << ptprobe << " and corrected probe pt is " << ptprobecorr << " and my eta is " << etaprobe << endl;
myb2 = 2*(ptprobecorr - ptrefcorr)/(ptprobecorr + ptrefcorr);
myetaprobe2 = etaprobe;
myptprobe2 = ptprobe;
myetaref2 = etaref;
myptref2 = ptref;
rr2->Fill();
}
outf->Write();
outf->Close();
myfile->Close();
montecarlo->Close();
ppdata->Close();
if (filecounter == 0) {
TFile *ab = TFile::Open("outputrelrespcasym1234.root"); // 40 TO 60 PT AVERAGE
TFile *outputf = new TFile("outputrelrespcasymplots1234.root", "Recreate"); // 40 TO 60 PT AVERAGE
cout << "File 1" << endl;
}
if (filecounter == 1) {
TFile *ab = TFile::Open("outputrelrespcasym123.root"); // 60 TO 80 PT AVERAGE
TFile *outputf = new TFile("outputrelrespcasymplots123.root", "Recreate"); // 60 TO 80 PT AVERAGE
cout << "File 2" << endl;
}
if (filecounter == 2) {
TFile *ab = TFile::Open("outputrelrespcasym1.root"); //80 TO 100 PT AVERAGE
TFile *outputf = new TFile("outputrelrespcasymplots1.root", "Recreate"); // 80 TO 100 PT AVERAGE
cout << "File 3" << endl;
}
if (filecounter == 3) {
TFile *ab = TFile::Open("outputrelrespcasym.root"); //100 TO 140 PT AVERAGE
TFile *outputf = new TFile("outputrelrespcasymplots.root", "Recreate"); // 100 TO 140 PT AVERAGE
cout << "File 4" << endl;
}
if (filecounter == 4) {
TFile *ab = TFile::Open("outputrelrespcasym12.root"); // 140 TO 200 PT AVERAGE
TFile *outputf = new TFile("outputrelrespcasymplots12.root", "Recreate"); // 140 TO 200 PT AVERAGE
cout << "File 5" << endl;
}
printf("About to Open Tree.\n");
TTree *mytree2 = (TTree *)ab->Get("rr2");
int nEvents2 = mytree2->GetEntries();
Float_t etaprobe2 = 0;
Float_t b2 = 0;
mytree2->SetBranchAddress("myetaprobe2", &etaprobe2);
mytree2->SetBranchAddress("myb2", &b2);
Float_t bin_edge_y[] = { -1.5, -1.44, -1.38, -1.32, -1.26, -1.2, -1.14, -1.08, -1.02, -0.96, -0.9, -0.84, -0.78, -0.72, -0.66, -0.6, -0.54, -0.48, -0.42, -0.36, -0.3, -0.24, -0.18, -0.12, -0.06, 0, 0.06, 0.12, 0.18, 0.24, 0.3, 0.36, 0.42, 0.48, 0.54, 0.6, 0.66, 0.72, 0.78, 0.84, 0.9, 0.96, 1.02, 1.08, 1.14, 1.2, 1.26, 1.32, 1.38, 1.44, 1.5};
Int_t bins_y = sizeof(bin_edge_y)/sizeof(Float_t) - 1;
cout << bins_y << endl;
//Float_t cms_hcal_edge_pseudorapidity[] = { -5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013, -3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853, -2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830, -1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218, -1.131, -1.044, -0.957, -0.879, -0.783, -0.696, -0.609, -0.522, -0.435, -0.348, -0.261, -0.174, -0.087, 0.000, 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.696, 0.783, 0.879, 0.957, 1.044, 1.131, 1.218, 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830, 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853, 2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
Int_t binnum = sizeof(cms_hcal_edge_pseudorapidity)/sizeof(Float_t) - 1;
cout << binnum << endl;
TH2F*b = new TH2F("b", "B vs. Eta; Eta; B", binnum, cms_hcal_edge_pseudorapidity, bins_y, bin_edge_y);
b->Sumw2();
mytree2->Draw("myb2:myetaprobe2>>b", "", "");
Float_t mean2[83];
Float_t meanerror2[83];
Float_t etacoordinate2[83];
Float_t relativeresponse2[83];
Float_t relativeresponseerror2[83];
Float_t zero2[83];
TH1D*h1[84];
for (int c = 0; c < binnum; c++) {
mean2[c] = -999;
etacoordinate2[c] = -999;
zero2[c] = 0;
}
for (int count = 1; count <= binnum; count++) {
h1[count] = new TH1D(Form("h1_%d_py", count), Form("h1_%d_py", count), bins_y, bin_edge_y);
h1[count] = (TH1D*)b->ProjectionY(Form("h1_%d_py", count), count - 1, count, "e");
h1[count]->Sumw2();
etacoordinate2[count - 1] = b->GetXaxis()->GetBinCenter(count);
mean2[count - 1] = h1[count]->GetMean(1);
meanerror2[count - 1] = h1[count]->GetMeanError(1);
cout << "My etacoordinate is " << etacoordinate2[count - 1] << " and my count is " << count << " and my mean is " << mean2[count - 1] << " and my error is " << meanerror2[count - 1] << endl;
}
for (int counter = 0; counter < binnum; counter++) {
Float_t num = 2 + mean2[counter];
Float_t den = 2 - mean2[counter];
relativeresponse2[counter] = num/den;
Float_t errornum = fabs(meanerror2[counter]/num);
Float_t errorden = fabs(meanerror2[counter]/den);
relativeresponseerror2[counter] = relativeresponse2[counter]*(errornum + errorden);
}
TGraphErrors *meanetaabc = new TGraphErrors(binnum + 1, etacoordinate2, mean2, zero2, meanerror2);
TGraphErrors *rrelabc = new TGraphErrors(binnum + 1, etacoordinate2, relativeresponse2, zero2, relativeresponseerror2);
//THIS IS TO PUT IN THE PLOT FOR C_ASYM FOR EACH RANGE
if (filecounter == 0) {
TFile *casymplotnew = new TFile("casym_output_new_1234.root", "Recreate"); //40 TO 60 PT AVERAGE
cout << "Plot 1" << endl;
}
if (filecounter == 1) {
TFile *casymplotnew = new TFile("casym_output_new_123.root", "Recreate"); //60 TO 80 PT AVERAGE
cout << "Plot 2" << endl;
}
if (filecounter == 2) {
TFile *casymplotnew = new TFile("casym_output_new_1.root", "Recreate"); //80 TO 100 PT AVERAGE
cout << "Plot 3" << endl;
}
if (filecounter == 3) {
TFile *casymplotnew = new TFile("casym_output_new.root", "Recreate"); //100 TO 140 PT AVERAGE
cout << "Plot 4" << endl;
}
if (filecounter == 4) {
TFile *casymplotnew = new TFile("casym_output_new_12.root", "Recreate"); //140 TO 200 PT AVERAGE
cout << "Plot 5" << endl;
}
TGraphErrors *casymabc = new TGraphErrors(binnum + 1, etacoordinate2, casym, zero2, zero2);
casymabc->SetTitle("C_Asym v. Eta");
casymabc->GetXaxis()->SetTitle("Eta");
casymabc->GetYaxis()->SetTitle("R_{mc}/R_{data}");
casymabc->SetMarkerStyle(6);
casymabc->SetLineColor(1);
casymplotnew->cd();
casymabc->Write();
casymplotnew->Close();
//THIS IS THE END OF THE PLOTTING FOR C_ASYM FOR EACH RANGE
meanetaabc->SetTitle("Mean Eta Per Bin");
meanetaabc->GetXaxis()->SetTitle("Eta");
meanetaabc->GetYaxis()->SetTitle("Mean");
meanetaabc->SetMarkerStyle(6);
meanetaabc->SetLineColor(1);
rrelabc->SetTitle("Relative Response");
rrelabc->GetXaxis()->SetTitle("Probe Eta");
rrelabc->GetYaxis()->SetTitle("Relative Response");
rrelabc->SetMarkerStyle(6);
rrelabc->SetLineColor(1);
TCanvas *canvaseta = new TCanvas(1);
canvaseta->cd();
meanetaabc->Draw("AP");
TCanvas *canvasrelresp = new TCanvas(2);
canvasrelresp->cd();
rrelabc->Draw("AP");
outputf->cd();
rrelabc->Write();
meanetaabc->Write();
b->Write();
outputf->Close();
ab->Close();
} //END FILE LOOP
}