-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathres.c
128 lines (109 loc) · 3.13 KB
/
res.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
//TCanvas *c1;
//TCanvas *c2;
//TCanvas *c3;
void res(const char *fname = "./results/no/nodigi_gun_k0L_20GeV_iso_5000evt_ILD_l5_v02_FTFP_BERT.root", const char *fOutName = "no_out.root") {
//
// Some common variables
//
const char *treeName = "Tree";
const int nBins = 1000;
const float binLo = 0.0;
const float binHi = 100.0;
// if ( gROOT->GetListOfCanvases()->FindObject("c1") == NULL ) c1 = new TCanvas("c1", "c1", 1);
// if ( gROOT->GetListOfCanvases()->FindObject("c2") == NULL ) c2 = new TCanvas("c2", "c2", 1);
//z if ( gROOT->GetListOfCanvases()->FindObject("c3") == NULL ) c3 = new TCanvas("c3", "c3", 1);
// gStyle->SetOptStat(0);
//
// Open file
//
std::cout << "Trying to open file... ";
TFile *file = new TFile(fname, "READ");
if (!file) { // if error occure then exit
std::cout << "[FAIL]" << std::endl;
return;
}
std::cout << "[OK]" << std::endl;
//
// Create an output file
//
std::cout << "Trying to create output file... ";
TFile *fOut = new TFile(fOutName, "RECREATE");
if (!fOut) {
file->Close();
std::cout << "[FAIL]" << std::endl;
return;
}
std::cout << "[OK]" << std::endl;
//
// Setup a TTree
//
std::cout << "Setup a tree... ";
TTree *tree = (TTree *)file->Get(treeName);
if (!tree) {
std::cout << "[FAIL]" << std::endl;
file->Close();
return;
}
std::cout << "[OK]" << std::endl;
unsigned int nEvents = tree->GetEntries();
//
// Setup a branch
//
Float_t Energy = 0;
Float_t feta = 0;
Float_t eecal = 0;
Float_t ehcal = 0;
tree->SetBranchAddress("Energy", &Energy);
tree->SetBranchAddress("feta", &feta);
tree->SetBranchAddress("eecal", &eecal);
tree->SetBranchAddress("ehcal", &ehcal);
//
// Create a histogram and random generator
//
TH1F *hb = new TH1F("hb", "hb", nBins, binLo, binHi);
TH1F *he = new TH1F("he", "he", nBins, binLo, binHi);
TH1F *hr = new TH1F("hr", "hr", nBins, binLo, binHi);
for (unsigned int i = 0; i <nEvents; i++) {
tree -> GetEntry(i);
if ( eecal < 0.02 ) {
if ( ( feta < 1.3 ) && ( feta > -1.3 ) ) hb -> Fill( Energy );
if ( ( ( feta < 2.5 ) && ( feta > 1.5 ) ) || ( ( feta < -1.5 ) && ( feta > -2.5 ) ) ) he -> Fill( Energy );
if ( ( ( feta < 1.5 ) && ( feta > 1.3 ) ) || ( ( feta < -1.3 ) && ( feta > -1.5 ) ) ) hr -> Fill( Energy );
}
}
//hb->Rebin();
//hb->GetXaxis()->SetRangeUser(0, 200);
//--- Plot
/* c1->cd();
hb->Draw();
c2->cd();
he->Draw();
c3->cd();
hr->Draw();
ehcal1->SetMarkerStyle(20);
ehcal1->SetMarkerColor(kRed);
ehcal1->DrawCopy("p e");
fitFunc1->SetLineColor(kRed);
fitFunc1->SetLineWidth(2);
fitFunc1->Draw("SAME");
ehcal2->SetMarkerStyle(21);
ehcal2->SetMarkerColor(kBlue);
ehcal2->DrawCopy("p e SAME");
fitFunc2->SetLineColor(kBlue);
fitFunc3->SetLineWidth(2);
fitFunc2->Draw("SAME");
ehcal3->SetMarkerStyle(22);
ehcal3->SetMarkerColor(kGreen);
ehcal3->DrawCopy("p e SAME");
fitFunc3->SetLineColor(kGreen);
fitFunc3->SetLineWidth(2);
fitFunc3->Draw("SAME");
*/
fOut->cd();
hb->Write();
he->Write();
hr->Write();
fOut->Write();
fOut->Close();
file->Close();
}