Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
mp_H1_lambdas.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_legacy
3/// Lambdas used to check and fit the result of the H1 analysis.
4/// Used by mp104_processH1.C and roottest/root/multicore/tProcessExecutorH1Test.cpp
5///
6/// \macro_code
7///
8/// \author Gerardo Ganis
9
10// This function is used to check the result of the H1 analysis
11auto out) {
12
13 // Make sure the output list is there
14 if (!out) {
15 std::cout << "checkH1 >>> Test failure: output list not found\n";
16 return -1;
17 }
18
19 // Check the 'hdmd' histo
20 auto hdmd = dynamic_cast<out->FindObject("hdmd"));
21 if (!hdmd) {
22 std::cout << "checkH1 >>> Test failure: 'hdmd' histo not found\n";
23 return -1;
24 }
25 if ((Int_t)(hdmd->GetEntries()) != 7525) {
26 std::cout << "checkH1 >>> Test failure: 'hdmd' histo: wrong number"
27 " of entries ("
28 << (Int_t)(hdmd->GetEntries()) << ": expected 7525) \n";
29 return -1;
30 }
31 if (TMath::Abs((hdmd->GetMean() - 0.15512023) / 0.15512023) > 0.001) {
32 std::cout << "checkH1 >>> Test failure: 'hdmd' histo: wrong mean (" << hdmd->GetMean()
33 << ": expected 0.15512023) \n";
34 return -1;
35 }
36
37 auto out->FindObject("h2"));
38 if (!h2) {
39 std::cout << "checkH1 >>> Test failure: 'h2' histo not found\n";
40 return -1;
41 }
42 if ((h2->GetEntries()) != 7525) {
43 std::cout << "checkH1 >>> Test failure: 'h2' histo: wrong number"
44 " of entries ("
45 << (h2->GetEntries()) << ": expected 7525) \n";
46 return -1;
47 }
48 if (h2->GetMean() - 0.15245688) / 0.15245688) > 0.001) {
49 std::cout << "checkH1 >>> Test failure: 'h2' histo: wrong mean (" << h2->GetMean() << ": expected 0.15245688) \n";
50 return -1;
51 }
52
53 // Done
54 return 0;
55};
56
57// This function is used to fit the result of the analysis with graphics
58auto doFit = [](Int_t {
59
61 if (lfn)
63
64 auto hdmd = dynamic_cast<out->FindObject("hdmd"));
65 auto out->FindObject("h2"));
66
67 // function called at the end of the event loop
68 if (hdmd == 0 || h2 == 0) {
69 std::cout << "doFit: hdmd = " << hdmd << " , h2 = " << h2 << "\n";
70 return -1;
71 if (lfn)
73 }
74
75 // create the canvas for the h1analysis fit
77 TCanvas *c1 = new TCanvas("c1", "h1analysis analysis", 10, 10, 800, 600);
78 c1->SetBottomMargin(0.15);
79 hdmd->GetXaxis()->SetTitle("m_{K#pi#pi} - m_{K#pi}[GeV/c^{2}]");
80 hdmd->GetXaxis()->SetTitleOffset(1.4);
81
82 // fit histogram hdmd with function f5 using the log-likelihood option
83 if (gROOT->GetListOfFunctions()->FindObject("f5"))
84 delete gROOT->GetFunction("f5");
85
86 auto fdm5 = [](Double_t *xx, Double_t *par) -> Double_t {
87 const Double_t dxbin = (0.17 - 0.13) / 40; // Bin-width
88 Double_t x = xx[0];
89 if (x <= 0.13957)
90 return 0;
91 Double_t xp3 = (x - par[3]) * (x - par[3]);
92 Double_t res = dxbin * (par[0] * TMath::Power(x - 0.13957, par[1]) +
93 par[2] / 2.5066 / par[4] * TMath::Exp(-xp3 / 2 / par[4] / par[4]));
94 return res;
95 };
96
97 auto f5 = new TF1("f5", fdm5, 0.139, 0.17, 5);
98 f5->SetParameters(1000000, .25, 2000, .1454, .001);
99 hdmd->Fit("f5", "lr");
100
101 // Check the result of the fit
102 Double_t ref_f5[4] = {959915.0, 0.351114, 1185.03, 0.145569};
103 for (int i : {0, 1, 2, 3}) {
104 if ((TMath::Abs((f5->GetParameters())[i] - ref_f5[i]) / ref_f5[i]) > 0.001) {
105 std::cout << "\n >>> Test failure: fit to 'f5': parameter '" << f5->GetParName(i) << "' has wrong value ("
106 << (f5->GetParameters())[i] << ": expected" << ref_f5[i] << ") \n";
107 if (lfn)
108 gSystem->RedirectOutput(0, 0, &redH);
109 return -1;
110 }
111 }
112
113 // create the canvas for tau d0
114 gStyle->SetOptFit(0);
115 gStyle->SetOptStat(1100);
116 auto c2 = new TCanvas("c2", "tauD0", 100, 100, 800, 600);
117 c2->SetGrid();
118 c2->SetBottomMargin(0.15);
119
120 // Project slices of 2-d histogram h2 along X , then fit each slice
121 // with function f2 and make a histogram for each fit parameter
122 // Note that the generated histograms are added to the list of objects
123 // in the current directory.
124 if (gROOT->GetListOfFunctions()->FindObject("f2"))
125 delete gROOT->GetFunction("f2");
126
127 auto fdm2 = [](Double_t *xx, Double_t *par) -> Double_t {
128 const auto dxbin = (0.17 - 0.13) / 40; // Bin-width
129 const auto sigma = 0.0012;
130 auto x = xx[0];
131 if (x <= 0.13957)
132 return 0;
133 auto xp3 = (x - 0.1454) * (x - 0.1454);
134 auto res = dxbin * (par[0] * TMath::Power(x - 0.13957, 0.25) +
135 par[1] / 2.5066 / sigma * TMath::Exp(-xp3 / 2 / sigma / sigma));
136 return res;
137 };
138
139 auto f2 = new TF1("f2", fdm2, 0.139, 0.17, 2);
140 f2->SetParameters(10000, 10);
141
142 // Restrict to three bins in this example
143 std::cout << "doFit: restricting fit to two bins only in this example...\n";
144
145 h2->FitSlicesX(f2, 10, 20, 10, "g5 l");
146
147 // Check the result of the fit
148 Double_t ref_f2[2] = {52432.2, 105.481};
149 for (int i : {0, 1}) {
150 if ((TMath::Abs((f2->GetParameters())[i] - ref_f2[i]) / ref_f2[i]) > 0.001) {
151 std::cout << "\n >>> Test failure: fit to 'f2': parameter '" << f2->GetParName(i) << "' has wrong value ("
152 << (f2->GetParameters())[i] << ": expected" << ref_f2[i] << ") \n";
153 if (lfn)
154 gSystem->RedirectOutput(0, 0, &redH);
155 return -1;
156 }
157 }
158
159 auto h2_1 = (TH1D *)gDirectory->Get("h2_1");
160 h2_1->GetXaxis()->SetTitle("#tau[ps]");
161 h2_1->SetMarkerStyle(21);
162 h2_1->Draw();
163 c2->Update();
164 auto line = new TLine(0, 0, 0, c2->GetUymax());
165 line->Draw();
166
167 // Have the number of entries on the first histogram (to cross check when running
168 // with entry lists)
169 auto psdmd = (TPaveStats *)hdmd->GetListOfFunctions()->FindObject("stats");
170 psdmd->SetOptStat(1110);
171 c1->Modified();
172
173 if (lfn)
174 gSystem->RedirectOutput(0, 0, &redH);
175
176 return 0;
177};
178
179// This is the function invoked during the processing of the trees.
180auto doH1 = [](TTreeReader &reader) {
181
182 // Histograms
183 auto hdmd = new TH1F("hdmd", "Dm_d", 40, 0.13, 0.17);
184 auto TH2F("h2", "ptD0 vs Dm_d", 30, 0.135, 0.165, 30, -3, 6);
185
186 TTreeReaderValue<Float_t> fPtds_d(reader, "ptds_d");
187 TTreeReaderValue<Float_t> fEtads_d(reader, "etads_d");
188 TTreeReaderValue<Float_t> fDm_d(reader, "dm_d");
190 TTreeReaderValue<Int_t> fIpi(reader, "ipi");
191 TTreeReaderValue<Int_t> fIpis(reader, "ipis");
192 TTreeReaderValue<Float_t> fPtd0_d(reader, "ptd0_d");
193 TTreeReaderValue<Float_t> fMd0_d(reader, "md0_d");
194 TTreeReaderValue<Float_t> fRpd0_t(reader, "rpd0_t");
195 TTreeReaderArray<Int_t> fNhitrp(reader, "nhitrp");
196 TTreeReaderArray<Float_t> fRstart(reader, "rstart");
197 TTreeReaderArray<Float_t> fRend(reader, "rend");
198 TTreeReaderArray<Float_t> fNlhk(reader, "nlhk");
199 TTreeReaderArray<Float_t> fNlhpi(reader, "nlhpi");
200 TTreeReaderValue<Int_t> fNjets(reader, "njets");
201
202 while (reader.Next()) {
203
204 // Return as soon as a bad entry is detected
205 if (TMath::Abs(*fMd0_d - 1.8646) >= 0.04)
206 continue;
207 if (*fPtds_d <= 2.5)
208 continue;
209 if (TMath::Abs(*fEtads_d) >= 1.5)
210 continue;
211 (*fIk)--; // original fIk used f77 convention starting at 1
212 (*fIpi)--;
213
214 if (fNhitrp.At(*fIk) * fNhitrp.At(*fIpi) <= 1)
215 continue;
216
217 if (fRend.At(*fIk) - fRstart.At(*fIk) <= 22)
218 continue;
219 if (fRend.At(*fIpi) - fRstart.At(*fIpi) <= 22)
220 continue;
221 if (fNlhk.At(*fIk) <= 0.1)
222 continue;
223 if (fNlhpi.At(*fIpi) <= 0.1)
224 continue;
225 (*fIpis)--;
226 if (fNlhpi.At(*fIpis) <= 0.1)
227 continue;
228 if (*fNjets < 1)
229 continue;
230
231 // Fill the histograms
232 hdmd->Fill(*fDm_d);
233 h2->Fill(*fDm_d, *fRpd0_t / 0.029979 * 1.8646 / *fPtd0_d);
234 }
235
236 // Return a list
237 auto l = new TList;
238 l->Add(hdmd);
239 l->Add(h2);
240 l->SetOwner(kFALSE);
241
242 return l;
243};
244
245// This is the function invoked during the processing of the trees to create a TEntryList
246auto doH1fillList = [](TTreeReader &reader) {
247
248 // Entry list
249 auto elist = new TEntryList("elist", "H1 selection from Cut");
250
251 TTreeReaderValue<Float_t> fPtds_d(reader, "ptds_d");
252 TTreeReaderValue<Float_t> fEtads_d(reader, "etads_d");
254 TTreeReaderValue<Int_t> fIpi(reader, "ipi");
255 TTreeReaderValue<Int_t> fIpis(reader, "ipis");
256 TTreeReaderValue<Float_t> fMd0_d(reader, "md0_d");
257 TTreeReaderArray<Int_t> fNhitrp(reader, "nhitrp");
258 TTreeReaderArray<Float_t> fRstart(reader, "rstart");
259 TTreeReaderArray<Float_t> fRend(reader, "rend");
260 TTreeReaderArray<Float_t> fNlhk(reader, "nlhk");
261 TTreeReaderArray<Float_t> fNlhpi(reader, "nlhpi");
262 TTreeReaderValue<Int_t> fNjets(reader, "njets");
263
264 while (reader.Next()) {
265
266 // Return as soon as a bad entry is detected
267 if (TMath::Abs(*fMd0_d - 1.8646) >= 0.04)
268 continue;
269 if (*fPtds_d <= 2.5)
270 continue;
271 if (TMath::Abs(*fEtads_d) >= 1.5)
272 continue;
273 (*fIk)--; // original fIk used f77 convention starting at 1
274 (*fIpi)--;
275
276 if (fNhitrp.At(*fIk) * fNhitrp.At(*fIpi) <= 1)
277 continue;
278
279 if (fRend.At(*fIk) - fRstart.At(*fIk) <= 22)
280 continue;
281 if (fRend.At(*fIpi) - fRstart.At(*fIpi) <= 22)
282 continue;
283 if (fNlhk.At(*fIk) <= 0.1)
284 continue;
285 if (fNlhpi.At(*fIpi) <= 0.1)
286 continue;
287 (*fIpis)--;
288 if (fNlhpi.At(*fIpis) <= 0.1)
289 continue;
290 if (*fNjets < 1)
291 continue;
292
293 // Fill the entry list
294 elist->Enter(reader.GetCurrentEntry(), reader.GetTree());
295 }
296
297 return elist;
298};
299
300// This is the function invoked during the processing of the trees using a TEntryList
301auto doH1useList = [](TTreeReader &reader) {
302
303 // Histograms
304 auto hdmd = new TH1F("hdmd", "Dm_d", 40, 0.13, 0.17);
305 auto TH2F("h2", "ptD0 vs Dm_d", 30, 0.135, 0.165, 30, -3, 6);
306
307 TTreeReaderValue<Float_t> fDm_d(reader, "dm_d");
308 TTreeReaderValue<Float_t> fPtd0_d(reader, "ptd0_d");
309 TTreeReaderValue<Float_t> fRpd0_t(reader, "rpd0_t");
310
311 while (reader.Next()) {
312 // Fill the histograms
313 hdmd->Fill(*fDm_d);
314 h2->Fill(*fDm_d, *fRpd0_t / 0.029979 * 1.8646 / *fPtd0_d);
315 }
316
317 // Return a list
318 auto l = new TList;
319 l->Add(hdmd);
320 l->Add(h2);
321 l->SetOwner(kFALSE);
322
323 return l;
324};
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:384
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
The Canvas class.
Definition TCanvas.h:23
A List of entry numbers in a TTree or TChain.
Definition TEntryList.h:26
1-Dim function class
Definition TF1.h:234
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:698
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:650
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition TH1.cxx:7526
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
Use the TLine constructor to create a simple line.
Definition TLine.h:22
A doubly linked list.
Definition TList.h:38
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:293
The histogram statistics painter class.
Definition TPaveStats.h:18
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1642
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
Definition TStyle.cxx:1595
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr)
Redirect standard output (stdout, stderr) to the specified file.
Definition TSystem.cxx:1727
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
TLine * line
Double_t fdm5(Double_t *xx, Double_t *par)
const Double_t sigma
const Double_t dxbin
Double_t fdm2(Double_t *xx, Double_t *par)
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
return c2
Definition legend2.C:14
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:713
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:725
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
TLine l
Definition textangle.C:4