forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh1analysisTreeReader.C
More file actions
242 lines (206 loc) · 7.85 KB
/
Copy pathh1analysisTreeReader.C
File metadata and controls
242 lines (206 loc) · 7.85 KB
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
#include "h1analysisTreeReader.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TPaveStats.h"
#include "TLine.h"
#include "TMath.h"
#include "TFile.h"
#include "TROOT.h"
const Double_t dxbin = (0.17-0.13)/40; // Bin-width
const Double_t sigma = 0.0012;
//_____________________________________________________________________
Double_t fdm5(Double_t *xx, Double_t *par)
{
Double_t x = xx[0];
if (x <= 0.13957) return 0;
Double_t xp3 = (x-par[3])*(x-par[3]);
Double_t res = dxbin*(par[0]*TMath::Power(x-0.13957, par[1])
+ par[2] / 2.5066/par[4]*TMath::Exp(-xp3/2/par[4]/par[4]));
return res;
}
//_____________________________________________________________________
Double_t fdm2(Double_t *xx, Double_t *par)
{
Double_t x = xx[0];
if (x <= 0.13957) return 0;
Double_t xp3 = (x-0.1454)*(x-0.1454);
Double_t res = dxbin*(par[0]*TMath::Power(x-0.13957, 0.25)
+ par[1] / 2.5066/sigma*TMath::Exp(-xp3/2/sigma/sigma));
return res;
}
//_____________________________________________________________________
Bool_t h1analysisTreeReader::Process(Long64_t entry){
// entry is the entry number in the current Tree
// Selection function to select D* and D0.
myTreeReader.SetLocalEntry(entry);
fProcessed++;
//in case one entry list is given in input, the selection has already been done.
if (!useList) {
// Return as soon as a bad entry is detected
if (TMath::Abs(*fMd0_d-1.8646) >= 0.04) return kFALSE;
if (*fPtds_d <= 2.5) return kFALSE;
if (TMath::Abs(*fEtads_d) >= 1.5) return kFALSE;
(*fIk)--; //original fIk used f77 convention starting at 1
(*fIpi)--;
if (fNhitrp.At(*fIk)* fNhitrp.At(*fIpi) <= 1) return kFALSE;
if (fRend.At(*fIk) -fRstart.At(*fIk) <= 22) return kFALSE;
if (fRend.At(*fIpi)-fRstart.At(*fIpi) <= 22) return kFALSE;
if (fNlhk.At(*fIk) <= 0.1) return kFALSE;
if (fNlhpi.At(*fIpi) <= 0.1) return kFALSE;
(*fIpis)--; if (fNlhpi.At(*fIpis) <= 0.1) return kFALSE;
if (*fNjets < 1) return kFALSE;
}
// if option fillList, fill the entry list
if (fillList) elist->Enter(entry);
//fill some histograms
hdmd->Fill(*fDm_d);
h2->Fill(*fDm_d,*fRpd0_t/0.029979*1.8646/ *fPtd0_d);
return kTRUE;
}
void h1analysisTreeReader::Begin(TTree* /*myTree*/) {
// function called before starting the event loop
// -it performs some cleanup
// -it creates histograms
// -it sets some initialisation for the entry list
Reset();
//print the option specified in the Process function.
TString option = GetOption();
Info("Begin", "starting h1analysis with process option: %s", option.Data());
delete gDirectory->GetList()->FindObject("elist");
// case when one creates/fills the entry list
if (option.Contains("fillList")) {
fillList = kTRUE;
elist = new TEntryList("elist", "H1 selection from Cut");
// Add to the input list for processing in PROOF, if needed
if (fInput) {
fInput->Add(new TNamed("fillList",""));
// We send a clone to avoid double deletes when importing the result
fInput->Add(elist);
// This is needed to avoid warnings from output-to-members mapping
elist = 0;
}
Info("Begin", "creating an entry-list");
}
// case when one uses the entry list generated in a previous call
if (option.Contains("useList")) {
useList = kTRUE;
if (fInput) {
// In PROOF option "useList" is processed in SlaveBegin and we do not need
// to do anything here
} else {
TFile f("elist.root");
elist = (TEntryList*)f.Get("elist");
if (elist) elist->SetDirectory(0); //otherwise the file destructor will delete elist
}
}
}
void h1analysisTreeReader::SlaveBegin(TTree *myTree){
// function called before starting the event loop
// -it performs some cleanup
// -it creates histograms
// -it sets some initialisation for the entry list
Init(myTree);
//print the option specified in the Process function.
TString option = GetOption();
Info("SlaveBegin",
"starting h1analysis with process option: %s (tree: %p)", option.Data(), myTree);
//create histograms
hdmd = new TH1F("hdmd","Dm_d",40,0.13,0.17);
h2 = new TH2F("h2","ptD0 vs Dm_d",30,0.135,0.165,30,-3,6);
fOutput->Add(hdmd);
fOutput->Add(h2);
// Entry list stuff (re-parse option because on PROOF only SlaveBegin is called)
if (option.Contains("fillList")) {
fillList = kTRUE;
// Get the list
if (fInput) {
if ((elist = (TEntryList *) fInput->FindObject("elist")))
// Need to clone to avoid problems when destroying the selector
elist = (TEntryList *) elist->Clone();
if (elist)
fOutput->Add(elist);
else
fillList = kFALSE;
}
}
if (fillList) Info("SlaveBegin", "creating an entry-list");
if (option.Contains("useList")) useList = kTRUE;
}
void h1analysisTreeReader::Terminate() {
// function called at the end of the event loop
hdmd = dynamic_cast<TH1F*>(fOutput->FindObject("hdmd"));
h2 = dynamic_cast<TH2F*>(fOutput->FindObject("h2"));
if (hdmd == 0 || h2 == 0) {
Error("Terminate", "hdmd = %p , h2 = %p", hdmd, h2);
return;
}
//create the canvas for the h1analysis fit
gStyle->SetOptFit();
TCanvas *c1 = new TCanvas("c1","h1analysis analysis",10,10,800,600);
c1->SetBottomMargin(0.15);
hdmd->GetXaxis()->SetTitle("m_{K#pi#pi} - m_{K#pi}[GeV/c^{2}]");
hdmd->GetXaxis()->SetTitleOffset(1.4);
//fit histogram hdmd with function f5 using the loglfIkelihood option
if (gROOT->GetListOfFunctions()->FindObject("f5"))
delete gROOT->GetFunction("f5");
TF1 *f5 = new TF1("f5",fdm5,0.139,0.17,5);
f5->SetParameters(1000000, .25, 2000, .1454, .001);
hdmd->Fit("f5","lr");
//create the canvas for tau d0
gStyle->SetOptFit(0);
gStyle->SetOptStat(1100);
TCanvas *c2 = new TCanvas("c2","tauD0",100,100,800,600);
c2->SetGrid();
c2->SetBottomMargin(0.15);
// Project slices of 2-d histogram h2 along X , then fit each slice
// with function f2 and make a histogram for each fit parameter
// Note that the generated histograms are added to the list of objects
// in the current directory.
if (gROOT->GetListOfFunctions()->FindObject("f2"))
delete gROOT->GetFunction("f2");
TF1 *f2 = new TF1("f2",fdm2,0.139,0.17,2);
f2->SetParameters(10000, 10);
h2->FitSlicesX(f2,0,-1,1,"qln");
TH1D *h2_1 = (TH1D*)gDirectory->Get("h2_1");
h2_1->GetXaxis()->SetTitle("#tau[ps]");
h2_1->SetMarkerStyle(21);
h2_1->Draw();
c2->Update();
TLine *line = new TLine(0,0,0,c2->GetUymax());
line->Draw();
// Have the number of entries on the first histogram (to cross check when running
// with entry lists)
TPaveStats *psdmd = (TPaveStats *)hdmd->GetListOfFunctions()->FindObject("stats");
psdmd->SetOptStat(1110);
c1->Modified();
//save the entry list to a Root file if one was produced
if (fillList) {
if (!elist)
elist = dynamic_cast<TEntryList*>(fOutput->FindObject("elist"));
if (elist) {
Printf("Entry list 'elist' created:");
elist->Print();
TFile efile("elist.root","recreate");
elist->Write();
} else {
Error("Terminate", "entry list requested but not found in output");
}
}
// Notify the amount of processed events
if (!fInput) Info("Terminate", "processed %lld events", fProcessed);
}
void h1analysisTreeReader::SlaveTerminate(){
}
Bool_t h1analysisTreeReader::Notify() {
// called when loading a new file
// get branch pointers
Info("Notify","processing file: %s",myTreeReader.GetTree()->GetCurrentFile()->GetName());
if (elist && myTreeReader.GetTree()) {
if (fillList) {
elist->SetTree(myTreeReader.GetTree());
} else if (useList) {
myTreeReader.GetTree()->SetEntryList(elist);
}
}
return kTRUE;
}