-
Notifications
You must be signed in to change notification settings - Fork 0
/
_STARlight_NewPtShapes.C
executable file
·517 lines (457 loc) · 18 KB
/
_STARlight_NewPtShapes.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
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
// _STARlight_NewPtShapes.C
// David Grund, Mar 12, 2022
// cpp headers
#include <fstream>
#include <stdio.h>
// root headers
#include "TFile.h"
#include "TList.h"
#include "TH1.h"
#include "TAxis.h"
#include "TString.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TLorentzVector.h"
#include "TClonesArray.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TLegend.h"
// my headers
#include "AnalysisManager.h"
#include "AnalysisConfig.h" // to be able to use SetReducedRunList()
Bool_t drawCheck(kFALSE);
TString strMCArr[4] = {"CohJ","IncJ","CohP","IncP"};
TString strMCFilesArr[4] = {"kCohJpsiToMu","kIncohJpsiToMu","kCohPsi2sToMuPi","kIncohPsi2sToMuPi"};
Double_t fPtCutLowArr[4] = {0.0, 0.0, 0.0, 0.0}; // GeV/c
Double_t fPtCutUppArr[4] = {0.4, 1.4, 0.6, 1.4}; // GeV/c
Int_t nBinsArr[4] = {80, 280, 120, 280};
TString strMC;
TString strMCFiles;
Double_t fPtCutLow;
Double_t fPtCutUpp;
Int_t nBins;
Double_t fPtGenerated;
TLorentzVector *parent;
TClonesArray *daughters;
TH1D *hRecOld = NULL;
TH1D *hRatios = NULL;
TH1D *hRecNew = NULL;
void InitAnalysis(Int_t iMC, Bool_t pass3);
void FillTreeGen(const char* folder_in, Double_t R_A);
TTree* GetTreeRec();
void CalcAndPlotRatios(const char* subfolder_out, Double_t R_A);
void ConnectTreeVariables_tSL(TTree *tSL);
void _STARlight_NewPtShapes()
{
// no title in plots
gStyle->SetOptTitle(0);
gStyle->SetOptStat(0);
// to study which R_A is optimal for CohJ to describe the measured pT distribution
if(kTRUE){
// CohJ, 6.000.000 gen events,
// R_A = 6.624 vs. 6.600-7.800 fm (step = 0.100 fm)
for(Int_t i = 0; i < 13; i++){
Double_t R_A = 6.600 + i*0.100; // fm
InitAnalysis(0,kTRUE);
FillTreeGen("Trees/STARlight/CohJ_6.624/",6.624);
FillTreeGen(Form("Trees/STARlight/CohJ_%.3f/", R_A),R_A);
CalcAndPlotRatios("",R_A);
}
}
if(kTRUE){
// CohJ, R_A = 6.624 vs. 7.350 fm, 6.000.000 gen events
InitAnalysis(0,kTRUE);
FillTreeGen("Trees/STARlight/CohJ_6.624/",6.624);
FillTreeGen("Trees/STARlight/CohJ_7.350/",7.350);
CalcAndPlotRatios("",7.350);
// IncJ, R_A = 6.624 vs. 7.350 fm, 6.000.000 gen events
InitAnalysis(1,kTRUE);
FillTreeGen("Trees/STARlight/IncJ_6.624/",6.624);
FillTreeGen("Trees/STARlight/IncJ_7.350/",7.350);
CalcAndPlotRatios("",7.350);
// CohP, R_A = 6.624 vs. 7.350 fm, 6.000.000 gen events
InitAnalysis(2,kTRUE);
FillTreeGen("Trees/STARlight/CohP_6.624/",6.624);
FillTreeGen("Trees/STARlight/CohP_7.350/",7.350);
CalcAndPlotRatios("",7.350);
// IncP, R_A = 6.624 vs. 7.350 fm, 6.000.000 gen events
InitAnalysis(3,kTRUE);
FillTreeGen("Trees/STARlight/IncP_6.624/",6.624);
FillTreeGen("Trees/STARlight/IncP_7.350/",7.350);
CalcAndPlotRatios("",7.350);
}
if(kFALSE){
// CohJ, R_A = 6.624 vs. 7.330 fm, 6.000.000 gen events
InitAnalysis(0,kTRUE);
FillTreeGen("Trees/STARlight/CohJ_6.624/",6.624);
FillTreeGen("Trees/STARlight/CohJ_7.330/",7.330);
CalcAndPlotRatios("",7.330);
// IncJ, R_A = 6.624 vs. 7.330 fm, 6.000.000 gen events
InitAnalysis(1,kTRUE);
FillTreeGen("Trees/STARlight/IncJ_6.624/",6.624);
FillTreeGen("Trees/STARlight/IncJ_7.330/",7.330);
CalcAndPlotRatios("",7.330);
// CohP, R_A = 6.624 vs. 7.330 fm, 6.000.000 gen events
InitAnalysis(2,kTRUE);
FillTreeGen("Trees/STARlight/CohP_6.624/",6.624);
FillTreeGen("Trees/STARlight/CohP_7.330/",7.330);
CalcAndPlotRatios("",7.330);
// IncP, R_A = 6.624 vs. 7.330 fm, 6.000.000 gen events
InitAnalysis(3,kTRUE);
FillTreeGen("Trees/STARlight/IncP_6.624/",6.624);
FillTreeGen("Trees/STARlight/IncP_7.330/",7.330);
CalcAndPlotRatios("",7.330);
}
return;
}
// #############################################################################################
void InitAnalysis(Int_t iMC, Bool_t pass3)
{
// iMC == 0 => CohJ
// iMC == 1 => IncJ
// iMC == 2 => CohP
// iMC == 3 => IncP
isPass3 = pass3;
SetReducedRunList(isPass3);
strMC = strMCArr[iMC];
strMCFiles = strMCFilesArr[iMC];
fPtCutLow = fPtCutLowArr[iMC];
fPtCutUpp = fPtCutUppArr[iMC];
nBins = nBinsArr[iMC];
hRecOld = new TH1D("hRecOld","hRecOld",nBins,fPtCutLow,fPtCutUpp);
return;
}
// #############################################################################################
void FillTreeGen(const char* folder_in, Double_t R_A)
{
Printf("*****");
Printf("Process: %s", strMC.Data());
Printf("Input folder: %s", folder_in);
Printf("Filling the tree and histogram (generator level).");
Double_t nEvOld = 0;
Double_t nEvNew = 0;
// open the starlight file and starlight tree
TFile *fSL = TFile::Open(Form("%stree_STARlight.root", folder_in), "read");
if(fSL) Printf("File %s loaded.", fSL->GetName());
// get the SL tree
TTree *tSL = dynamic_cast<TTree*> (fSL->Get("starlightTree"));
if(tSL) Printf("Tree %s loaded.", tSL->GetName());
ConnectTreeVariables_tSL(tSL);
// check if the output trees already created, if not, create them
TString str_f_out = Form("Trees/STARlight/tGen_%s_RA_%.3f.root", strMC.Data(), R_A);
TFile *fGen = TFile::Open(str_f_out.Data(),"read");
if(fGen)
{
Printf("File %s already created.", str_f_out.Data());
}
else
{
TH1D *hGen = new TH1D("hGen","hGen",nBins,fPtCutLow,fPtCutUpp);
gROOT->cd();
TTree *tGen = new TTree("tGen","tGen");
tGen->Branch("fPtGen",&fPtGenerated,"fPtGen/D");
Printf("Filling tGen and hGen.");
Printf("tSL contains %lli entries.", tSL->GetEntries());
// Loop over entries in tSL
Int_t nEntriesAnalysed = 0;
Int_t nEntriesProgress = (Double_t)tSL->GetEntries() / 20.;
Int_t nPercent = 0;
for(Int_t iEntry = 0; iEntry < tSL->GetEntries(); iEntry++)
{
tSL->GetEntry(iEntry);
if(TMath::Abs(fYGen) < 1.0)
{
nEvOld++;
fPtGenerated = parent->Pt();
hGen->Fill(fPtGenerated);
tGen->Fill();
}
// Update progress bar
if((iEntry+1) % nEntriesProgress == 0)
{
nPercent += 5;
nEntriesAnalysed += nEntriesProgress;
Printf("[%i%%] %i entries analysed.", nPercent, nEntriesAnalysed);
}
}
Printf("No. of events with |y| < 1.0: %.0f", nEvOld);
fGen = new TFile(str_f_out.Data(),"RECREATE");
// open the file
fGen->cd();
// write the histogram and tree to this directory
hGen->Write("hGen", TObject::kSingleKey);
tGen->Write("tGen",TObject::kSingleKey);
// list the contents of the file
fGen->ls();
// close the file
fGen->Close();
}
Printf("Done.");
Printf("*****");
Printf("\n");
return;
}
// #############################################################################################
void CalcAndPlotRatios(const char* subfolder_out, Double_t R_A)
{
Printf("*****");
Printf("Process: %s", strMC.Data());
Printf("Calculating ratios of nGenNew/nGenOld.");
// Load tGen with R_A = 6.624
TString str_fGenOld = Form("Trees/STARlight/tGen_%s_RA_6.624.root", strMC.Data());
TFile *fGenOld = fGenOld = TFile::Open(str_fGenOld.Data(), "read");
if(fGenOld) Printf("File %s loaded.", fGenOld->GetName());
TTree *tGenOld = (TTree*) fGenOld->Get("tGen");
if(tGenOld) Printf("Tree %s loaded.", tGenOld->GetName());
tGenOld->SetBranchAddress("fPtGen", &fPtGenerated);
// Load tGen with new R_A
TString str_fGenNew = Form("Trees/STARlight/tGen_%s_RA_%.3f.root", strMC.Data(), R_A);
TFile *fGenNew = TFile::Open(str_fGenNew.Data(),"read");
if(fGenNew) Printf("File %s loaded.", fGenNew->GetName());
TTree *tGenNew = (TTree*) fGenNew->Get("tGen");
if(tGenNew) Printf("Tree %s loaded.", tGenNew->GetName());
tGenNew->SetBranchAddress("fPtGen", &fPtGenerated);
// Load histograms with generated events
TH1D *hGenOld = (TH1D*)fGenOld->Get("hGen");
if(hGenOld) Printf("Histogram %sOld loaded.", hGenOld->GetName());
TH1D *hGenNew = (TH1D*)fGenNew->Get("hGen");
if(hGenNew) Printf("Histogram %sNew loaded.", hGenNew->GetName());
// Draw loaded histograms
if(drawCheck)
{
TCanvas *cGenOld = new TCanvas("cGenOld","cGenOld",900,600);
hGenOld->Draw();
TCanvas *cGenNew = new TCanvas("cGenNew","cGenNew",900,600);
hGenNew->Draw();
}
// Calculate ratios
hRatios = (TH1D*)hGenNew->Clone("hRatios");
hRatios->SetTitle("hRatios");
hRatios->Sumw2();
hRatios->Divide(hGenOld);
// Print the ratios to the text file
TString str_folder_out = Form("Results/_STARlight_NewPtShapes/%s/", subfolder_out);
gSystem->Exec("mkdir -p " + str_folder_out);
TString str_file_out = Form("%s%s_RA_%.3f.txt", str_folder_out.Data(), strMC.Data(), R_A);
ofstream outfile(str_file_out.Data());
outfile << "pT_low\tpT_upp\tnEvOld\tnEvNew\tratio\n";
for(Int_t iBin = 1; iBin <= nBins; iBin++)
{
outfile << Form("%.3f\t%.3f\t%.0f\t%.0f\t%.3f\n",
hRatios->GetBinLowEdge(iBin), hRatios->GetBinLowEdge(iBin+1),
hGenOld->GetBinContent(iBin), hGenNew->GetBinContent(iBin), hRatios->GetBinContent(iBin));
}
outfile.close();
// define the tRec tree
TTree *tRec = GetTreeRec();
// define the integers showing the progress bar
Int_t nEntriesAnalysed = 0;
Int_t nEntriesProgress = (Double_t)tRec->GetEntries() / 20.;
Int_t nPercent = 0;
// if J/psi datasets
if (strncmp(strMC.Data(),"CohJ",4) == 0 || strncmp(strMC.Data(),"IncJ",4) == 0)
{
// run over reconstructed events
for(Int_t iEntry = 0; iEntry < tRec->GetEntries(); iEntry++)
{
tRec->GetEntry(iEntry);
// m between 3.0 and 3.2 GeV/c^2, pT cut: all
if(EventPassedMCRec(1, 2))
{
// fill the histogram hRecOld
hRecOld->Fill(fPt);
}
if((iEntry+1) % nEntriesProgress == 0)
{
nPercent += 5;
nEntriesAnalysed += nEntriesProgress;
Printf("[%i%%] %i entries analysed.", nPercent, nEntriesAnalysed);
}
}
// draw hRecOld
if(drawCheck)
{
TCanvas *cRecOld2 = new TCanvas("cRecOld2","cRecOld2",900,600);
hRecOld->Draw();
}
// create hRecNew by scaling hRecOld with ratios
hRecNew = (TH1D*)hRecOld->Clone("hRecNew");
hRecNew->SetTitle("hRecNew");
hRecNew->Multiply(hRatios);
}
// if Psi(2s) datasets
else if (strncmp(strMC.Data(),"CohP",4) == 0 || strncmp(strMC.Data(),"IncP",4) == 0)
{
hRecNew = new TH1D("hRecNew","hRecNew",nBins,fPtCutLow,fPtCutUpp);
TAxis *xAxis = hRatios->GetXaxis();
// run over reconstructed events
Int_t iBinP = 0;
Int_t iBinJ = 0;
Double_t fJpsi = 0;
//Printf("iBinP\tPtGenP\tiBinJ\tPtGenJ\tfJpsi\toldVal\tnewVal");
for(Int_t iEntry = 0; iEntry < tRec->GetEntries(); iEntry++)
{
tRec->GetEntry(iEntry);
// m between 3.0 and 3.2 GeV/c^2, pT cut: all
if(EventPassedMCRec(1, 2))
{
// find index of the bin to which the current fPtGen_Psi2s corresponds
iBinP = xAxis->FindBin(fPtGen_Psi2s);
// find index of the bin to which the current fPt corresponds
iBinJ = xAxis->FindBin(fPt);
// scale the J/psi entry by the ratio with the index iBinPsi2s
fJpsi = hRatios->GetBinContent(iBinP);
// add the entry to hRecNew
hRecNew->SetBinContent(iBinJ,hRecNew->GetBinContent(iBinJ)+fJpsi);
// print the values to the console
//Printf("%i\t%.3f\t%i\t%.3f\t%.3f\t%.3f\t%.3f", iBinP, fPtGen_Psi2s, iBinJ, fPtGen, fJpsi, hRecNew->GetBinContent(iBinJ), hRecNew->GetBinContent(iBinJ)+fJpsi);
// fill the histogram hRecOld
hRecOld->Fill(fPt);
}
if((iEntry+1) % nEntriesProgress == 0)
{
nPercent += 5;
nEntriesAnalysed += nEntriesProgress;
Printf("[%i%%] %i entries analysed.", nPercent, nEntriesAnalysed);
}
}
// draw hRecOld
if(drawCheck)
{
TCanvas *cRecOld2 = new TCanvas("cRecOld2","cRecOld2",900,600);
hRecOld->Draw();
}
}
else
{
Printf("This option is not supported. Terminating...");
return;
}
// Plot the results
TCanvas *cRatios = new TCanvas("cRatios", "cRatios", 900, 600);
// Canvas settings
cRatios->SetTopMargin(0.04);
cRatios->SetBottomMargin(0.15);
cRatios->SetRightMargin(0.04);
cRatios->SetLeftMargin(0.1);
// Vertical axis
hRatios->GetYaxis()->SetTitle(Form("#it{N}_{gen}(#it{R}_{A} = %.3f fm) / #it{N}_{gen}(#it{R}_{A} = 6.624 fm)", R_A));
hRatios->GetYaxis()->SetTitleSize(0.05);
hRatios->GetYaxis()->SetTitleOffset(0.9);
hRatios->GetYaxis()->SetLabelSize(0.05);
hRatios->GetYaxis()->SetDecimals(1);
hRatios->GetYaxis()->SetRangeUser(0.0,5.0);
// Horizontal axis
if (strncmp(strMC.Data(),"CohP",4) == 0 || strncmp(strMC.Data(),"IncP",4) == 0) hRatios->GetXaxis()->SetTitle("#it{p}_{T,#psi(2S)}^{gen} (GeV/#it{c})");
else hRatios->GetXaxis()->SetTitle("#it{p}_{T,J/#psi}^{gen} (GeV/#it{c})");
hRatios->GetXaxis()->SetTitleSize(0.05);
hRatios->GetXaxis()->SetTitleOffset(1.2);
hRatios->GetXaxis()->SetLabelSize(0.05);
// Draw
hRatios->SetLineColor(215);
hRatios->Draw("E1");
TCanvas *cRec = new TCanvas("cRec", "cRec", 900, 600);
cRec->SetTopMargin(0.04);
cRec->SetBottomMargin(0.15);
cRec->SetRightMargin(0.04);
cRec->SetLeftMargin(0.1);
cRec->SetLogy();
// Vertical axis
hRecOld->GetYaxis()->SetTitle("#it{N}_{rec} (after selections)");
hRecOld->GetYaxis()->SetTitleSize(0.05);
hRecOld->GetYaxis()->SetTitleOffset(0.9);
hRecOld->GetYaxis()->SetLabelSize(0.05);
hRecOld->GetYaxis()->SetRangeUser(0.1,1e5);
// Horizontal axis
hRecOld->GetXaxis()->SetTitle("#it{p}_{T,J/#psi}^{gen} (GeV/#it{c})");
hRecOld->GetXaxis()->SetTitleSize(0.05);
hRecOld->GetXaxis()->SetTitleOffset(1.2);
hRecOld->GetXaxis()->SetLabelSize(0.05);
// Draw
hRecOld->SetLineColor(kRed);
hRecOld->Draw("E1");
hRecNew->SetLineColor(215);
hRecNew->Draw("E1 SAME");
TLegend *l = new TLegend(0.50,0.85,0.90,0.95);
l->AddEntry(hRecOld,Form("rec. events with #it{R}_{A} = 6.624 fm"),"L");
l->AddEntry(hRecNew,Form("rec. events with #it{R}_{A} = %.3f fm", R_A),"L");
l->SetTextSize(0.04);
l->SetBorderSize(0); // no border
l->SetFillStyle(0); // legend is transparent
l->Draw();
// Print plots
cRatios->Print(Form("%s%s_RA_%.3f_ratios.pdf", str_folder_out.Data(), strMC.Data(), R_A));
cRatios->Print(Form("%s%s_RA_%.3f_ratios.png", str_folder_out.Data(), strMC.Data(), R_A));
cRec->Print(Form("%s%s_RA_%.3f_recSpectra.pdf", str_folder_out.Data(), strMC.Data(), R_A));
cRec->Print(Form("%s%s_RA_%.3f_recSpectra.png", str_folder_out.Data(), strMC.Data(), R_A));
Printf("Done.");
Printf("*****");
Printf("\n");
return;
}
// #############################################################################################
TTree* GetTreeRec()
{
Printf("*****");
Printf("Process: %s", strMC.Data());
Printf("Getting the tRec.");
// define fRec and tRec
TFile *fRec = NULL;
TTree *tRec = NULL;
// define the paths to the file and tRec
TString str_f_in = "Trees/";
TString str_t_in = "AnalysisOutput/";
// if pass3 or not
if(!isPass3) str_f_in += "AnalysisDataMC_pass1/";
else str_f_in += "AnalysisDataMC_pass3/";
// choose MC dataset
Bool_t isPsi2sDataset = kFALSE;
// if CohJ or IncJ
if(strncmp(strMC.Data(),"CohJ",4) == 0 || strncmp(strMC.Data(),"IncJ",4) == 0)
{
str_f_in += "AnalysisResults_MC_" + strMCFiles + ".root";
if(!isPass3) str_t_in += "fTreeJPsiMCRec";
else str_t_in += "fTreeJpsi";
// open the input file
fRec = TFile::Open(str_f_in.Data(), "read");
if(fRec) Printf("File %s loaded.", fRec->GetName());
// get the MCRec tree
tRec = dynamic_cast<TTree*> (fRec->Get(str_t_in.Data()));
if(tRec) Printf("Tree %s loaded.", tRec->GetName());
}
// if CohP or IncP
if(strncmp(strMC.Data(),"CohP",4) == 0 || strncmp(strMC.Data(),"IncP",4) == 0)
{
isPsi2sDataset = kTRUE;
str_f_in += "AnalysisResults_MC_" + strMCFiles + "_2.root";
if(!isPass3)
{
Printf("This option is not supported. Terminating...");
return NULL;
}
// open the input file
fRec = TFile::Open(str_f_in.Data(), "read");
if(fRec) Printf("File %s loaded.", fRec->GetName());
// get fOutputList
TList *l = (TList*) fRec->Get("AnalysisOutput/fOutputListcharged");
if(l) Printf("List %s loaded.", l->GetName());
// get the MCRec tree
tRec = (TTree*)l->FindObject("fTreeJpsi");
if(tRec) Printf("Tree %s loaded.", tRec->GetName());
}
// connect tree varibles
ConnectTreeVariablesMCRec(tRec, isPsi2sDataset);
Printf("Done.");
Printf("*****");
Printf("\n");
return tRec;
}
// #############################################################################################
void ConnectTreeVariables_tSL(TTree *tSL)
{
tSL->SetBranchAddress("parent", &parent);
tSL->SetBranchAddress("daughters", &daughters);
Printf("Variables from %s connected.", tSL->GetName());
return;
}
// #############################################################################################