-
Notifications
You must be signed in to change notification settings - Fork 0
/
simc_ana.C
341 lines (256 loc) · 13.6 KB
/
simc_ana.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
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
#include "TFile.h"
#include "TTree.h"
#include "extras.C"
int counter1 = 0;
Float_t Weight [10]; // Weight
Float_t Em [10]; // Missing Energy
Float_t Pm [10]; // Missing Momentum
Float_t PmPar [10]; // Missing Momentum component parallel to q
Float_t Q2 [10]; // Momentum transfer squared
Float_t Normfac[10]; // Normalization factor
Float_t h_ytar [10]; Float_t h_delta [10]; Float_t h_yptar [10]; Float_t h_xptar [10];
Float_t h_ytari[10]; Float_t h_deltai[10]; Float_t h_yptari[10]; Float_t h_xptari[10];
Float_t e_ytar [10]; Float_t e_delta [10]; Float_t e_yptar [10]; Float_t e_xptar [10];
Float_t e_ytari[10]; Float_t e_deltai[10]; Float_t e_yptari[10]; Float_t e_xptari[10];
Float_t h_pf [10]; // Outgoing proton momentum
Float_t h_Thf[10]; // Outgoing proton in-plane angle
// labels
int electron = 0; int hadron = 1; int both = 2;
int ytar = 0; int delta = 1; int yptar = 2;
int xptar = 3; int moment = 4; int pmiss = 5;
int emiss = 6; int Qsq = 7; int theta = 8;
int black = 0;
int red = 1;
int blue = 2;
int yellow = 3;
int entries[10];
ifstream f_fast;
ifstream f_fast_3He;
// #############################################################################################################################################################
void simc_ana(){
gROOT->Macro( "./root/Greetings.C" ); // Load greeting message
gROOT->Macro( "./root/histo_defs.C" ); // Load histograms
Double_t final_weight;
// #############################################################################################################################################################
// OPEN TREE, ACCESS BRANCHES, AND LOAD VARIABLES
TFile** f_file = new TFile*[10];
TTree** t_file = new TTree*[10];
TString filename[10];
filename[0] = "./input/fast_He_bound.root" ; // fast kin root file 3He bound
filename[1] = "./input/fast_He_continuum.root"; // fast kin root file 3He continuum
filename[2] = "./input/fast_deuteron.root" ; // fast kin root file scaled d
filename[3] = "./input/slow_He_bound.root" ; // slow kin root file 3He bound
filename[4] = "./input/slow_He_continuum.root"; // slow kin root file 3He continuum
filename[5] = "./input/slow_deuteron.root" ; // slow kin root file scaled d
TFile *f_file[0] = new TFile( filename[0] ); TTree *t_file[0] = (TTree*)f_file[0] ->Get("SNT");
TFile *f_file[1] = new TFile( filename[1] ); TTree *t_file[1] = (TTree*)f_file[1] ->Get("SNT");
TFile *f_file[2] = new TFile( filename[2] ); TTree *t_file[2] = (TTree*)f_file[2] ->Get("SNT");
TFile *f_file[3] = new TFile( filename[3] ); TTree *t_file[3] = (TTree*)f_file[3] ->Get("SNT");
TFile *f_file[4] = new TFile( filename[4] ); TTree *t_file[4] = (TTree*)f_file[4] ->Get("SNT");
TFile *f_file[5] = new TFile( filename[5] ); TTree *t_file[5] = (TTree*)f_file[5] ->Get("SNT");
for(int i = 0 ; i < 6 ; i++){
cout << "Attaching file: " << filename[i] << endl;
ImportBranch(t_file[i]);
}
// #############################################################################################################################################################
// FILL HISTOGRAMS
// --------------------------------------------------------------------------------
// 1
// FAST KINEMATICS IN 3 HELIUM *** BOUND STATE
int idx = 0;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = Weight[idx]*Normfac[idx]/entries[idx]/3.; // <------- *1/3 to get a quarter of a day
if(event_passes_cuts(idx)){h1_fast_He -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// --------------------------------------------------------------------------------
// 2
// FAST KINEMATICS IN 3 HELIUM *** CONTINUUM STATE
int idx = 1;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = Weight[idx]*Normfac[idx]/entries[idx]/3.; // <------- *1/3 to get a quarter of a day
if(event_passes_cuts(idx)){h1_fast_He -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// --------------------------------------------------------------------------------
// 3
// FAST KINEMATICS IN DEUTERON
int idx = 2;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = 4./3.*Weight[idx]*Normfac[idx]/entries[idx]/3.; // <---------------------------------------
if(event_passes_cuts(idx)){h1_fast_H2 -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// --------------------------------------------------------------------------------
// 4
// SLOW KINEMATICS IN 3 HELIUM *** BOUND STATE
int idx = 3;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = Weight[idx]*Normfac[idx]/entries[idx]*4; // <------- *4 to get 4 days
if(event_passes_cuts(idx)){h1_slow_He -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// --------------------------------------------------------------------------------
// 5
// SLOW KINEMATICS IN 3 HELIUM *** CONTINUUM STATE
int idx = 4;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = Weight[idx]*Normfac[idx]/entries[idx]*4; // <-------- *4 to get 4 days
if(event_passes_cuts(idx)){h1_slow_He -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// --------------------------------------------------------------------------------
// 6
// SLOW KINEMATICS IN DEUTERON
int idx = 5;
for (int i = 0 ; i < entries[idx] ; i++){
t_file[idx]->GetEntry(i);
final_weight = 4./3.*Weight[idx]*Normfac[idx]/entries[idx]*4; // <-------- *4 to get 4 days
if(event_passes_cuts(idx)){h1_slow_H2 -> Fill( Pm[idx] , final_weight );}
} //End loop over entries
// #############################################################################################################################################################
// SOME CALCULATIONS
double integral_fast;
cout << "" << endl;
integral_fast = h1_slow_H2 ->Integral(); cout << "Pm slow scaled d integral = " << integral_fast <<endl;
integral_fast = h1_slow_He ->Integral(); cout << "Pm slow scaled He integral = " << integral_fast <<endl;
// #############################################################################################################################################################
// FORMAT AND EDIT HISTOGRAMS
Pretty1D( h1_fast_H2, black , hadron , pmiss);
Pretty1D( h1_fast_He, yellow , hadron , pmiss);
Pretty1D( h1_slow_H2, blue , hadron , pmiss);
Pretty1D( h1_slow_He, red , hadron , pmiss);
Pretty1D( h1_total_H2, blue , hadron , pmiss);
Pretty1D( h1_total_He, red , hadron , pmiss);
// #############################################################################################################################################################
// PLOT HISTOGRAMS
gStyle->SetOptStat(0);
// ===================================================================
// MISSING MOMENTUM
TCanvas *c1 = new TCanvas("c1","",1200,800);
c1 -> SetBottomMargin(0.12);
h1_fast_H2 -> Draw();
h1_fast_He -> Draw("same");
h1_slow_He -> Draw("same");
h1_slow_H2 -> Draw("same");
leg = new TLegend(0.6,0.6,0.85,0.85);
leg->AddEntry(h1_fast_H2,"d fast kinematics 1/3-day");
leg->AddEntry(h1_fast_He,"He fast kinematics 1/3-day");
leg->AddEntry(h1_slow_H2,"d slow kinematics 4-day");
leg->AddEntry(h1_slow_He,"He slow kinematics 4-day");
leg->Draw("same");
// ===================================================================
// MISSING MOMENTUM TOTAL (Added by Or, Sept. 20 2016)
TCanvas *c2 = new TCanvas("c2","",1200,800);
c2 -> SetBottomMargin(0.12);
h1_total_H2->Add(h1_total_H2,h1_fast_H2);
h1_total_H2->Add(h1_total_H2,h1_slow_H2);
h1_total_H2->Rebin(5);
h1_total_He->Add(h1_total_He,h1_fast_He);
h1_total_He->Add(h1_total_He,h1_slow_He);
h1_total_He->Rebin(5);
h1_total_H2->Draw();
h1_total_He->Draw("same");
leg1 = new TLegend(0.6,0.6,0.85,0.85);
leg1->AddEntry(h1_total_H2,"d combined kinematics");
leg1->AddEntry(h1_total_He,"3He combined kinematics");
leg1->Draw("same");
// #############################################################################################################################################################
} //END MAIN FUNCTION
// #############################################################################################################################################################
// ===========================================================================================
// FUNCTION TO EDIT 1D HISTOGRAMS
void Pretty1D(TH1F *gP, int k, int part, int var){
int color; int style; int linestyle;
if( k == 0){ color = 1; style = 3004;}
if( k == 1){ color = 2; style = 3005;}
if( k == 2){ color = 4; style = 3004;}
if( k == 3){ color =92; style = 3007;}
if( k == 4){ color = 7; style = 3006;}
if( k == 5){ color = 6; style = 3005;}
AddLabels1D(gP, part, var);
gP -> SetLineColor(color);
gP -> SetFillColor(color);
gP -> SetFillStyle(style);
gP -> SetMarkerColor(color);
gP -> GetXaxis()->SetTitleSize(0.05);
//gP -> GetXaxis()->SetRangeUser(0,5);
gP -> GetYaxis()->SetLabelSize (0.05);
gP -> GetXaxis()->SetLabelSize (0.05);
//gP -> GetXaxis()->SetNdivisions(505);
}
// ===========================================================================================
// FUNCTION TO EDIT 2D HISTOGRAMS
void Pretty2D(TH2F *gP, int xvar, int yvar, int xpart, int ypart){
AddLabels2D(gP, xvar, yvar, xpart , ypart);
AddTitle2D (gP, xvar, yvar, xpart , ypart);
gP -> GetYaxis() -> SetTitleSize(0.05);
gP -> GetXaxis() -> SetTitleSize(0.05);
gP -> GetYaxis() -> SetLabelSize(0.05);
gP -> GetXaxis() -> SetLabelSize(0.05);
}
// ===========================================================================================
// FUNCTION TO ADD LABELS TO 1D HISTOGRAMS
void AddLabels1D(TH1F *gP, int part, int var){
if(var == ytar ){gP->GetXaxis()->SetTitle("y (target) [cm]");}
if(part == hadron){
if(var == theta ){gP->GetXaxis()->SetTitle("proton in-plane angle [degrees]");}
if(var == moment){gP->GetXaxis()->SetTitle("proton momentum [MeV/c]");}
}
if(var == pmiss ){gP->GetXaxis()->SetTitle("|P_{miss}| [GeV/c]");}
}
// ===========================================================================================
// FUNCTION TO ADD LABELS TO 2D HISTOGRAMS
void AddLabels2D(TH2F *gP, int xvar, int yvar, int xpart, int ypart){
if(xvar == ytar ){gP->GetXaxis()->SetTitle("y (target) [cm]" );}
if(xvar == delta ){gP->GetXaxis()->SetTitle("delta [%]" );}
if(xvar == yptar ){gP->GetXaxis()->SetTitle("in-plane angle [deg]" );}
if(xvar == xptar ){gP->GetXaxis()->SetTitle("out-of-plane angle [deg]" );}
if(xvar == moment){gP->GetXaxis()->SetTitle("Momentum [MeV/c]" );}
if(xvar == pmiss ){gP->GetXaxis()->SetTitle("|P_{miss}| [GeV/c]" );}
if(xvar == emiss ){gP->GetXaxis()->SetTitle("Missing Energy [GeV]" );}
if(yvar == ytar ){gP->GetYaxis()->SetTitle("y (target) [cm]" );}
if(yvar == delta ){gP->GetYaxis()->SetTitle("delta [%]" );}
if(yvar == yptar ){gP->GetYaxis()->SetTitle("in-plane angle [deg]" );}
if(yvar == xptar ){gP->GetYaxis()->SetTitle("out-of-plane angle [deg]" );}
if(yvar == moment){gP->GetYaxis()->SetTitle("Momentum [MeV/c]" );}
if(yvar == pmiss ){gP->GetYaxis()->SetTitle("|P_{miss}| [GeV/c]" );}
if(yvar == emiss ){gP->GetYaxis()->SetTitle("Missing Energy [GeV]" );}
if(yvar == Qsq ){gP->GetYaxis()->SetTitle("Q^{2} [(GeV/c)^{2}]" );}
if(xpart == hadron){
if(xvar == moment){gP->GetXaxis()->SetTitle("p_{p} [MeV/c]" );}
}
if(ypart == hadron){
if(yvar == theta){gP->GetYaxis()->SetTitle("#theta_{p} [degrees]" );}
}
}
// ===========================================================================================
// FUNCTION TO ADD TITLE TO 2D HISTOGRAMS
void AddTitle2D(TH2F *gP, int xvar, int yvar, int xpart, int ypart){
if((xpart==electron) && (ypart==electron)){gP->SetTitle("electron arm" );}
if((xpart==hadron ) && (ypart==hadron )){gP->SetTitle("hadron arm" );}
if((xpart==hadron ) && (ypart==electron)){gP->SetTitle("electron vs. hadron");}
gStyle->SetTitleSize(0.09,"t");
}
// ===========================================================================================
// RETURN TRUE IF H2 IS BIGGER THAN He
bool first_is_bigger( TH1 *d , TH1 *He ){
if( (d->GetMaximum()) > (He->GetMaximum()) ){return 1;}
else return 0;
}
// ===========================================================================================
// TITLES FOR HISTOS WITH CUTS ON MISSING MOMENTUM
void SetThisTitle(TH1 *h, int flag){
if(flag == 0){h -> SetTitle("Total");}
if(flag == 1){h -> SetTitle(" 0 < Pm < 50 [MeV/c]");}
if(flag == 2){h -> SetTitle(" 50 < Pm < 100 [MeV/c]");}
if(flag == 3){h -> SetTitle("100 < Pm < 150 [MeV/c]");}
if(flag == 4){h -> SetTitle("150 < Pm < 200 [MeV/c]");}
if(flag == 5){h -> SetTitle("200 < Pm < 250 [MeV/c]");}
if(flag == 6){h -> SetTitle("250 < Pm < 300 [MeV/c]");}
if(flag == 7){h -> SetTitle("300 < Pm < 350 [MeV/c]");}
}
/*
delta = 100 [p - p(central)] / p(central)
p = p(central)[1 + delta/100]
*/