-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractRF.C
175 lines (147 loc) · 5.34 KB
/
ExtractRF.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
// Macro for Rejection Factor (by EMcal cluster numbers)
// Input : AnalysisResults.root generated by C. Jahnke's task
// Structure
// * PWGDQ_dielectron_EMCal - TDirectoryFile*
// - cjahnke_QA_[trigger_index]_cent0 - TList
// -- [Cut_Definition] - THashList (histogram classed)
// --- Track_ev1+/- - THashList (histograms)
// ---- EMCal_E - TH1 (for rejection factor)
// --- Pair_ev1+/-_ev1+/-
// --- Track_Legs_ev1+/-_ev1+/-
// --- Event - ONLY in RAW
// ---- VtxZ - TH1 (for event numbers)
#include "TFile.h"
#include "TString.h"
// Trigger_index : MB=100, EG1=3, EG2=4
// Cut definition: TPC, EMCal, EMCal_loose, EMCal_strict, RAW
Int_t GetEventNumber(TFile* resultFile, Int_t trigger_index){
TString rootDir = "PWGDQ_dielectron_EMCal";
TDirectoryFile* rootDirObj = (TDirectoryFile*)(resultFile->Get(rootDir));
TString triggerDir = Form("cjahnke_QA_%d_cent0", trigger_index);
TList* triggerDirObj = (TList*)(rootDirObj->FindKey(triggerDir)->ReadObj());
TH1* vtxz = (TH1*)(triggerDirObj
->FindObject("RAW")
->FindObject("Event")
->FindObject("VtxZ"));
if(!vtxz){
cout << "[X] ERROR - Object not found : " << rootDir << "/" << triggerDir << "/RAW/Event/VtxZ" << endl;
return 0;
}
else
return vtxz->GetEntries();
return 0;
}
TH1* GetEMCalE(TFile* resultFile, Int_t trigger_index, TString cutDef){
TString rootDir = "PWGDQ_dielectron_EMCal";
TDirectoryFile* rootDirObj = (TDirectoryFile*)(resultFile->Get(rootDir));
TString triggerDir = Form("cjahnke_QA_%d_cent0", trigger_index);
TList* triggerDirObj = (TList*)(rootDirObj->FindKey(triggerDir)->ReadObj());
TH1* hEMCalE = (TH1*)(triggerDirObj
->FindObject(cutDef)
->FindObject("Track_ev1+")->FindObject("EMCal_E"));
TH1* hEMCalE_minus = (TH1*)(triggerDirObj
->FindObject(cutDef)
->FindObject("Track_ev1-")->FindObject("EMCal_E"));
if(!hEMCalE && !hEMCalE_minus){
cout << "[X] ERROR - Object not found : " << rootDir << "/" << triggerDir << "/" + cutDef << "/Track_ev1+/EMCal_E" << endl;
return NULL;
}
else{
hEMCalE->Add(hEMCalE_minus);
return hEMCalE;
}
return NULL;
}
int ExtractRF(TFile* resultFile, TString cutDef = "RAW"){
if(!resultFile){
cout << "[X] ERROR - Result file is NULL" << endl;
return -1;
}
// N_event for normalization
Int_t nMB = GetEventNumber(resultFile, 100);
Int_t nEG1 = GetEventNumber(resultFile, 3);
Int_t nEG2 = GetEventNumber(resultFile, 4);
// EMCal_E histogram
TH1* hMB = GetEMCalE(resultFile, 100, cutDef);
TH1* hEG1 = GetEMCalE(resultFile, 3, cutDef);
TH1* hEG2 = GetEMCalE(resultFile, 4, cutDef);
if(!nMB || !nEG1 || !nEG2 || !hMB || !hEG1 || !hEG2){
return -1;
}
// Global style
gStyle->SetOptFit(0000);
gStyle->SetOptStat(0);
// Function for event normalization
TF1* fcn = new TF1("fNev","[0]",0, 50);
// Normalized EMCal cluster energy
fcn->SetParameter(0, nMB * hMB->GetBinWidth(1));
hMB->SetName("hMB");
hMB->SetLineColor(kRed);
hMB->Divide(fcn);
fcn->SetParameter(0, nEG1 * hEG1->GetBinWidth(1));
hEG1->SetName("hEG1");
hEG1->SetLineColor(kBlue);
hEG1->Divide(fcn);
fcn->SetParameter(0, nEG2 * hEG2->GetBinWidth(1));
hEG2->SetName("hEG2");
hEG2->SetLineColor(kGreen);
hEG2->Divide(fcn);
TCanvas* cEMCalE = new TCanvas("c1", "EMCal cluster energy", 800, 600);
cEMCalE->SetLogy(1);
hMB->Draw();
hMB->GetYaxis()->SetRangeUser(1e-8, 1);
hMB->GetYaxis()->SetTitle("Number of EMCal clusters / N_{event}");
hMB->GetYaxis()->SetTimeOffset(1.20);
hEG1->Draw("same");
hEG2->Draw("same");
auto yLgd= new TLegend(0.13,0.60,0.49, 0.88, "", "brNDC");
yLgd->SetName("eclsLgd");
yLgd->SetBorderSize(0);
yLgd->SetTextAlign(12);
yLgd->SetTextFont(42);
yLgd->SetTextSize(0.04);
yLgd->AddEntry(hMB, Form("MB (kINT7) - %.1f M", nMB/1e6));
yLgd->AddEntry(hEG1, Form("EG1 (7 GeV) - %.1f M", nEG1/1e6));
yLgd->AddEntry(hEG2, Form("EG2 (5 GeV) - %.1f M", nEG2/1e6));
yLgd->Draw("same");
// Calculate Rejection Factor
TH1* rf1 = (TH1*)(hEG1->Clone());
rf1->SetName("hRF1");
rf1->SetMarkerStyle(2);
rf1->SetMarkerColor(kBlue);
rf1->Divide(hMB);
TH1* rf2 = (TH1*)(hEG2->Clone());
rf2->SetName("hRF2");
rf2->SetMarkerStyle(4);
rf2->SetMarkerColor(kGreen);
rf2->Divide(hMB);
cEMCalE = new TCanvas("c2", "Rejection Factor", 800, 600);
cEMCalE->SetLogy(1);
cEMCalE->SetGridx(1);
cEMCalE->SetGridy(1);
rf1->Draw("EP");
rf1->GetYaxis()->SetMoreLogLabels(kTRUE);
rf1->GetYaxis()->SetTitle("Rejection Factor");
rf1->GetYaxis()->SetTimeOffset(1.50);
rf2->Draw("same EP");
yLgd= new TLegend(0.13,0.60,0.49, 0.88, "", "brNDC");
yLgd->SetName("rfLgd");
yLgd->SetBorderSize(0);
yLgd->SetTextAlign(12);
yLgd->SetTextFont(42);
yLgd->SetTextSize(0.04);
yLgd->AddEntry(rf1, "EG1 / MB");
yLgd->AddEntry(rf2, "EG2 / MB");
yLgd->Draw("same");
return 0;
}
int ExtractRF(TString resultPath = "AnalysisResults.root", TString cutDef = "RAW"){
TFile* resultFile = new TFile(resultPath);
if(resultFile->IsOpen())
return ExtractRF(resultFile, cutDef);
else{
cout << "[X] ERROR - File not found : " << resultPath << endl;
return -1;
}
return 0;
}