ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoringFile_IDEnhancedPrimaryVertex.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5// **********************************************************************
6// $Id: MonitoringFile_IDEnhancedPrimaryVertex.cxx,v 1.1 2009-04-03 08:48:00 ponyisi Exp $
7// **********************************************************************
8
10
11#include <vector>
12
13#include <TGraph.h>
14#include <TGraphErrors.h>
15#include <TGraphAsymmErrors.h>
16#include <TCanvas.h>
17#include <TF1.h>
18#include <TFile.h>
19#include <TH1.h>
20#include <TH2.h>
21#include <TKey.h>
22#include <TProfile.h>
23#include <TMath.h>
24
25namespace dqutils {
26// define helper methods here rather then in this central MonitoringFile.h "beast"
27 void plotResolution(const std::string& coordinate, const std::string& versus);
28 void plotEfficiency();
29 double error_func(float x, const Double_t* par);
30 double scaleFactorFitFcn(double* x, double* par);
31 std::vector<float> stableGaussianFit(TH1* histo);
32
34 bool /* isIncremental */) {
35
36
37 TFile* f = TFile::Open(inFilename.c_str(), "UPDATE");
38
39 if (f == 0 || !f->IsOpen()) {
40
41 delete f;
42 return;
43 }
44 if (f->GetSize() < 1000.) {
45
46 delete f;
47 return;
48 }
49
50 bool dirExists = false;
51 std::string run_dir;
52 TIter next_run(f->GetListOfKeys());
53 TKey* key_run(0);
54 while ((key_run = dynamic_cast<TKey*>(next_run())) != 0) {
55 TObject* obj_run = key_run->ReadObj();
56 TDirectory* tdir_run = dynamic_cast<TDirectory*>(obj_run);
57 if (tdir_run != 0) {
58 std::string tdir_run_name(tdir_run->GetName());
59 if (tdir_run_name.find("run") != std::string::npos) {
60 run_dir = std::move(tdir_run_name);
61
62 dirExists = f->GetDirectory((run_dir + "/InDetGlobal/PrimaryVertex").c_str());
63 if (dirExists) {
64 f->cd((run_dir + "/InDetGlobal/PrimaryVertex").c_str());
65 }
66 }
67 } else {
68 delete obj_run;
69 }
70 }
71
72 if (!dirExists) {
73
74 dirExists = f->GetDirectory("InDetGlobal/PrimaryVertex");
75 if (dirExists) f->cd("InDetGlobal/PrimaryVertex");
76 }
77
78 if (dirExists) {
79 // create histos
80 plotResolution("X", "Ntrk");
81 plotResolution("Y", "Ntrk");
82 plotResolution("Z", "Ntrk");
83
84 plotResolution("X", "SumPt2");
85 plotResolution("Y", "SumPt2");
86 plotResolution("Z", "SumPt2");
87
89 }
90
91 f->Close();
92 delete f;
93// std::cout << "\n";
94// std::cout << "Finish Inner-Detector primary vertex monitoring analysis"<<std::endl;
95 return;
96 }
97
98 void
99 plotResolution(const std::string& coordinate = "Z", const std::string& versus = "Ntrk") {
100// cout << "Creating and writing histos for resolution " << coordinate << " versus " << versus << endl;
101
102 TH2F* h_Vrt_pullVsSomething_split(0);
103 TH2F* h_Vrt_err_vs_Something(0);
104// TH2F* h_Vrt_Tag_err_vs_Something(0);
105 std::string xAxisLabel("");
106
107 if (versus == "Ntrk") {
108 h_Vrt_pullVsSomething_split = (TH2F*) gDirectory->Get(("Vrt_" + coordinate + "pullVsNtrkAverage_split").c_str());
109 h_Vrt_err_vs_Something = (TH2F*) gDirectory->Get(("Vrt_" + coordinate + "err_vs_ntrk").c_str());
110// h_Vrt_Tag_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_Tag_"+coordinate+"err_vs_ntrk");
111 xAxisLabel = "Number of fitted tracks";
112 } else if (versus == "SumPt2") {
113 h_Vrt_pullVsSomething_split = (TH2F*) gDirectory->Get(("Vrt_" + coordinate + "pullVsPt2Average_split").c_str());
114 h_Vrt_err_vs_Something = (TH2F*) gDirectory->Get(("Vrt_" + coordinate + "err_vs_pt2").c_str());
115// h_Vrt_Tag_err_vs_Something = (TH2F*)gDirectory->Get("Vrt_Tag_"+coordinate+"err_vs_pt2");
116 xAxisLabel = "#sqrt{#sum p_{T}^{2}} [GeV]";
117 } else return;
118
119 //if (h_Vrt_pullVsSomething_split == 0) std::cout << "h_Vrt_pullVsSomething_split has zero pointer!" << std::endl;
120 //if (h_Vrt_err_vs_Something == 0) std::cout << "h_Vrt_err_vs_Something has zero pointer!" << std::endl;
121 if (h_Vrt_pullVsSomething_split == 0 or h_Vrt_err_vs_Something == 0) return;
122
123 int n_bins = h_Vrt_pullVsSomething_split->GetNbinsX();
124 std::vector<float> rms_z;
125 std::vector<float> rms_z_er;
126 std::vector<float> sigma_z;
127 std::vector<float> sigma_z_er;
128 std::vector<float> bins_z_nt;
129 std::vector<float> bins_z_nt_er;
130
131// root starts counting the bins at 1, i.e. bin 1 holds NTrk = 0. or sqrt(sumpt2) = 0. - 0.25. GeV
132// std::cout << "n bins: " << n_bins << "\tTotal entries: " << h_Vrt_pullVsSomething_split->GetEntries() << std::endl;
133// TH1D * nTrksPerVertex = h_Vrt_pullVsSomething_split->ProjectionX("projectionNTrks_"+coordinate+"_"+versus);
134
135// TH1D * profileZFull = h_Vrt_pullVsSomething_split->ProjectionY("projectionPullsFull_"+coordinate+"_"+versus);
136
137 Int_t startBin = 0;
138 TH1D* profileZ = 0;
139 const Int_t minEntriesForKFactorBin = 1000;
140 for (int bin_count = 1; bin_count < n_bins + 1; bin_count++) {
141 //Fixed binning
142// TH1D *profileZ = h_Vrt_pullVsSomething_split->ProjectionY("projectionPulls", bin_count, bin_count,"e");
143// Double_t binCenter = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinCenter(bin_count);
144// Double_t binWidth = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinWidth(bin_count)/2.;
145
146 //Variable binning
147 TH1D* profileZTmp = h_Vrt_pullVsSomething_split->ProjectionY("projectionPulls", bin_count, bin_count, "e");
148 //cout << "Bin: " << bin_count << ", Entries: " << profileZTmp->GetEntries() << endl;
149 if (profileZ == 0) {
150 startBin = bin_count;
151 profileZ = (TH1D*) profileZTmp->Clone("projectionPulls_Integrated");
152 //cout << "StartBin = " << startBin << endl;
153 } else {
154 profileZ->Add(profileZTmp);
155 }
156 delete profileZTmp;
157 profileZTmp = 0;
158 if ((profileZ->GetEntries() < minEntriesForKFactorBin) && (bin_count < n_bins)) //not enough entries, not last bin
159 continue;
160
161 Double_t lowEdge = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinLowEdge(startBin);
162 Double_t highEdge = h_Vrt_pullVsSomething_split->GetXaxis()->GetBinLowEdge(bin_count) +
163 h_Vrt_pullVsSomething_split->GetXaxis()->GetBinWidth(bin_count);
164 Double_t binCenter = (lowEdge + highEdge) / 2;
165 Double_t binWidth = (highEdge - lowEdge) / 2; //half of the bin width
166 //cout << "Bin done: " << binCenter << " +/- " << binWidth << ", Entries: " << profileZ->GetEntries() << endl;
167 // variable binning end
168
169 bins_z_nt.push_back(binCenter);
170 bins_z_nt_er.push_back(binWidth); // dummy error of binwidth for now
171
172 rms_z.push_back(profileZ->GetRMS());
173 rms_z_er.push_back(profileZ->GetRMSError());
174
175 //making a gaussian fit if there is anough entries
176 if (profileZ->GetEntries() > 100.) {
177 std::vector<float> fit_res = stableGaussianFit(profileZ);
178 sigma_z.push_back(fit_res[0]);
179 sigma_z_er.push_back(fit_res[1]);
180 } else {
181 sigma_z.push_back(0.);
182 sigma_z_er.push_back(0.);
183 }//end of good number of bins selection
184
185 delete profileZ; // must keep this to delete the projection from memory (next one has same name!)
186 profileZ = 0;
187 }//end of loop over all the ntrk bins
188
189 TGraphErrors* krms_z_vs_ntrk = new TGraphErrors(
190 bins_z_nt.size(), &(bins_z_nt[0]), &(rms_z[0]), &(bins_z_nt_er[0]), &(rms_z_er[0]));
191 krms_z_vs_ntrk->GetYaxis()->SetTitle((coordinate + " scale factor from RMS").c_str());
192 krms_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel.c_str());
193 krms_z_vs_ntrk->SetTitle(("scaleFactor" + coordinate + "_RMS").c_str());
194 krms_z_vs_ntrk->SetName(("scaleFactor" + coordinate + "_" + versus + "_RMS").c_str());
195
196 TGraphErrors* kgs_z_vs_ntrk = new TGraphErrors(
197 bins_z_nt.size(), &(bins_z_nt[0]), &(sigma_z[0]), &(bins_z_nt_er[0]), &(sigma_z_er[0]));
198 kgs_z_vs_ntrk->GetYaxis()->SetTitle((coordinate + " scale factor from gauss fit").c_str());
199 kgs_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel.c_str());
200 kgs_z_vs_ntrk->SetTitle(("scaleFactor" + coordinate + "_Fit").c_str());
201 kgs_z_vs_ntrk->SetName(("scaleFactor_" + coordinate + "_" + versus + "_Fit").c_str());
202
203// approximating the graph with 2nd order polynomial.
204 float maxFitRange(100.);
205 float minFitRange(2.);
206 if (versus == "SumPt2") {
207 minFitRange = 0.5;
208 maxFitRange = 20.;
209 }
210 TF1* kgs_z_ntrk_fit;
211 const Double_t* kgs_z_ntrk_fit_er;
212 int fitResKFactorMethod = 2; // set by hand for now
213 if (fitResKFactorMethod == 1) {
214 //Fit with a pol2
215 //coverity[DEADCODE]
216 kgs_z_vs_ntrk->Fit("pol2", "Q", "", minFitRange, maxFitRange);
217 kgs_z_vs_ntrk->GetFunction("pol2")->SetLineColor(kRed);
218 kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol2");
219 kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors();
220 } else if (fitResKFactorMethod == 2) {
221 //Fit with a pol1
222 kgs_z_vs_ntrk->Fit("pol1", "Q", "", minFitRange, maxFitRange);
223 kgs_z_vs_ntrk->GetFunction("pol1")->SetLineColor(kRed);
224 kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol1");
225 kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors();
226 //coverity[DEADCODE]
227 } else if (fitResKFactorMethod == 3) {
228 TF1* kgsFitFcn = new TF1("kgsFitFcn", scaleFactorFitFcn, minFitRange, maxFitRange, 3);
229 kgsFitFcn->SetParameter(0, minFitRange);
230 kgsFitFcn->SetParameter(1, 1.0);
231 kgsFitFcn->SetParameter(2, 1.0);
232 for (int ifit = 0; ifit < 1; ifit++) //initial estimation of best parameters
233 kgs_z_vs_ntrk->Fit(kgsFitFcn, "Q");
234 kgs_z_vs_ntrk->Fit(kgsFitFcn, "Q"); //perform actual fit
235 kgs_z_ntrk_fit = kgsFitFcn;
236 kgs_z_ntrk_fit_er = kgsFitFcn->GetParErrors();
237/* cout << "ScaleFactor fit for " << coordinate << " vs " << versus << " (method " << fitResKFactorMethod << ")= "
238 << kgsFitFcn->GetParameter(0) << " +/- " << kgsFitFcn->GetParError(0) << " "
239 << kgsFitFcn->GetParameter(1) << " +/- " << kgsFitFcn->GetParError(1) << " "
240 << kgsFitFcn->GetParameter(2) << " +/- " << kgsFitFcn->GetParError(2) << endl; */
241 } else if (fitResKFactorMethod == 4) {
242 //constant fit
243 kgs_z_vs_ntrk->Fit("pol0", "Q", "", minFitRange, maxFitRange);
244 kgs_z_vs_ntrk->GetFunction("pol0")->SetLineColor(kRed);
245 kgs_z_ntrk_fit = kgs_z_vs_ntrk->GetFunction("pol0");
246 kgs_z_ntrk_fit_er = kgs_z_ntrk_fit->GetParErrors();
247/* cout << "ScaleFactor fit for " << coordinate << " vs " << versus << " (method " << fitResKFactorMethod << ")= "
248 << kgs_z_ntrk_fit->GetParameter(0) << " +/- " << kgs_z_ntrk_fit->GetParError(0) << endl; */
249 }
250
251// plotting the fit error of the unconstrained primary vertex and correcting them
252 int nbins_z_err_ntrk = h_Vrt_err_vs_Something->GetNbinsX();
253
254 std::vector<float> av_err_z;
255 std::vector<float> av_err_z_er;
256// std::vector<float> av_err_tag_z;
257// std::vector<float> av_err_tag_z_er;
258 std::vector<float> err_bins_z_nt;
259 std::vector<float> err_bins_z_nt_er;
260 std::vector<float> res_z;
261 std::vector<float> res_z_er;
262// std::vector<float> res_tag_z;
263// std::vector<float> res_tag_z_er;
264
265 for (int bin_count = 1; bin_count <= nbins_z_err_ntrk; ++bin_count) {
266 err_bins_z_nt.push_back(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count));
267 err_bins_z_nt_er.push_back(h_Vrt_err_vs_Something->GetXaxis()->GetBinWidth(bin_count) / 2.);
268
269 TH1D* profileY = h_Vrt_err_vs_Something->ProjectionY("projectionErrors", bin_count, bin_count, "e");
270// TH1D * profileYTag(0);
271// if (h_Vrt_Tag_err_vs_Something)
272// profileYTag = h_Vrt_Tag_err_vs_Something->ProjectionY("projectionErrorsTag",bin_count,bin_count,"e");
273
274 float mean = profileY->GetMean();
275 float mean_error = profileY->GetMeanError();
276// float meanTag(0);
277// float mean_errorTag(0);
278// if (profileYTag) {
279// meanTag = profileYTag->GetMean();
280// mean_errorTag = profileYTag->GetMeanError();
281// }
282 delete profileY;
283// delete profileYTag;
284
285 av_err_z.push_back(mean);
286 av_err_z_er.push_back(mean_error);
287// av_err_tag_z.push_back(meanTag);
288// av_err_tag_z_er.push_back(mean_errorTag);
289
290 //estimating the approximate k-factor and the error value
291 double pr_er = 0.0;
292 float val(0.);
293 if (fitResKFactorMethod == 1) {
294 //coverity[DEADCODE]
295 pr_er = error_func(bin_count, kgs_z_ntrk_fit_er);
296 } else if (fitResKFactorMethod == 2) {
297 val = h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count);
298 pr_er = TMath::Power(kgs_z_ntrk_fit_er[1] * val, 2) + TMath::Power(kgs_z_ntrk_fit_er[0], 2);
299 pr_er = TMath::Sqrt(pr_er);
300// cout << "val = " << val << ", pr_er = " << pr_er << ", p0er = " << kgs_z_ntrk_fit_er[0] << ", p1er = "<<
301// kgs_z_ntrk_fit_er[1] << endl;
302 //coverity[DEADCODE]
303 } else if (fitResKFactorMethod == 3) {
304 val = h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count);
305 //approximately the error on the plateau
306 pr_er = kgs_z_ntrk_fit_er[2];
307 } else if (fitResKFactorMethod == 4) {
308 pr_er = kgs_z_ntrk_fit_er[0];
309 }
310
311 res_z.push_back(mean * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)));
312 res_z_er.push_back(TMath::Sqrt(TMath::Power(mean_error *
313 kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(
314 bin_count)),
315 2) + TMath::Power(pr_er * mean, 2)));
316// res_tag_z.push_back(meanTag * kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)));
317// res_tag_z_er.push_back(TMath::Sqrt(TMath::Power(mean_errorTag *
318// kgs_z_ntrk_fit->Eval(h_Vrt_err_vs_Something->GetXaxis()->GetBinCenter(bin_count)),2) + TMath::Power( pr_er * mean
319// ,2)));
320 }
321 TGraphErrors* res_z_vs_ntrk =
322 new TGraphErrors(err_bins_z_nt.size(), &(err_bins_z_nt[0]), &(res_z[0]), &(err_bins_z_nt_er[0]), &(res_z_er[0]));
323 res_z_vs_ntrk->GetYaxis()->SetTitle((coordinate + " Vertex Resolution [mm]").c_str());
324 res_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel.c_str());
325 res_z_vs_ntrk->SetTitle((coordinate + " Vertex Resolution").c_str());
326 res_z_vs_ntrk->SetName(("resolution_" + coordinate + "_" + versus).c_str());
327
328// TGraphErrors * res_tag_z_vs_ntrk = new TGraphErrors(err_bins_z_nt.size(),
329// &(err_bins_z_nt[0]),&(res_tag_z[0]),&(err_bins_z_nt_er[0]), &(res_tag_z_er[0]) );
330// res_tag_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" Tagged Vertex Resolution [mm]");
331// res_tag_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel);
332// res_tag_z_vs_ntrk->SetTitle(coordinate+" Tagged Vertex Resolution");
333// res_tag_z_vs_ntrk->SetName("resolution_tag_"+coordinate+"_"+versus);
334
335// TGraphErrors * mean_err_z_vs_ntrk = new TGraphErrors(err_bins_z_nt.size(),
336// &(err_bins_z_nt[0]),&(av_err_z[0]),&(err_bins_z_nt_er[0]), &(av_err_z_er[0]) );
337// mean_err_z_vs_ntrk->GetYaxis()->SetTitle(coordinate+" mean vertex error [mm]");
338// mean_err_z_vs_ntrk->GetXaxis()->SetTitle(xAxisLabel);
339// mean_err_z_vs_ntrk->SetTitle(coordinate+" Mean Vertex Error");
340// mean_err_z_vs_ntrk->SetName("resolution_"+coordinate+"_"+versus+"_Uncorrected"); //not corrected with k-factor
341
343 // Writing out
345 if (versus == "Ntrk") res_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 100.);
346 else res_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 20.);
347 res_z_vs_ntrk->GetYaxis()->SetRangeUser(0.0025, 1.);
348 res_z_vs_ntrk->Write("", TObject::kOverwrite);
349 delete res_z_vs_ntrk;
350
351 if (versus == "Ntrk") krms_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 100.);
352 else krms_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 20.);
353 krms_z_vs_ntrk->GetYaxis()->SetRangeUser(0.5, 1.3);
354 krms_z_vs_ntrk->Write("", TObject::kOverwrite);
355 delete krms_z_vs_ntrk;
356
357 if (versus == "Ntrk") kgs_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 100.);
358 else kgs_z_vs_ntrk->GetXaxis()->SetRangeUser(0., 20.);
359 kgs_z_vs_ntrk->GetYaxis()->SetRangeUser(0.5, 1.3);
360 kgs_z_vs_ntrk->Write("", TObject::kOverwrite);
361 delete kgs_z_vs_ntrk;
362
363// nTrksPerVertex->GetYaxis()->SetTitle("Entries");
364// nTrksPerVertex->Draw();
365// nTrksPerVertex->Write("", TObject::kOverwrite);
366
367 return;
368 }
369
370// Reconstruction efficiency
372// cout << "Creating and writing histos for efficiency" << endl;
373
374 // get histos but return if any histo is not there in input
375 TH1F* h_Vrt_split_tag_ntrk = (TH1F*) gDirectory->Get("Vrt_split_tag_ntrk");
376
377 if (h_Vrt_split_tag_ntrk == 0) return;
378
379 TH1F* h_Vrt_split_probe_ntrk = (TH1F*) gDirectory->Get("Vrt_split_probe_ntrk");
380 if (h_Vrt_split_probe_ntrk == 0) return;
381
382 TH1F* h_Vrt_split_matched_tag_ntrk = (TH1F*) gDirectory->Get("Vrt_split_matched_tag_ntrk");
383 if (h_Vrt_split_matched_tag_ntrk == 0) return;
384
385 TH1F* h_Vrt_split_matched_probe_ntrk = (TH1F*) gDirectory->Get("Vrt_split_matched_probe_ntrk");
386 if (h_Vrt_split_matched_probe_ntrk == 0) return;
387
388 TH1F* h_Vrt_split_dist_tag = (TH1F*) gDirectory->Get("Vrt_split_dist_tag");
389 if (h_Vrt_split_dist_tag == 0) return;
390
391 TH1F* h_Vrt_split_dist_probe = (TH1F*) gDirectory->Get("Vrt_split_dist_probe");
392 if (h_Vrt_split_dist_probe == 0) return;
393
394 // Use BayesDivide routing of TGraphAsymmErrors
395 TGraphAsymmErrors* g_Vrt_rec_eff_m1_split_vs_ntrk = new TGraphAsymmErrors();
396
397 g_Vrt_rec_eff_m1_split_vs_ntrk->BayesDivide(h_Vrt_split_probe_ntrk, h_Vrt_split_tag_ntrk);
398 g_Vrt_rec_eff_m1_split_vs_ntrk->SetName("g_RecEff_M1");
399
400 TGraphAsymmErrors* g_Vrt_sel_eff_m1_split_vs_ntrk = new TGraphAsymmErrors();
401 g_Vrt_sel_eff_m1_split_vs_ntrk->BayesDivide(h_Vrt_split_matched_probe_ntrk, h_Vrt_split_matched_tag_ntrk);
402 g_Vrt_sel_eff_m1_split_vs_ntrk->SetName("g_SelEff_M1");
403
404 // formatting and writing out
405 g_Vrt_rec_eff_m1_split_vs_ntrk->GetHistogram()->GetXaxis()->SetTitle("Number of tracks");
406 g_Vrt_rec_eff_m1_split_vs_ntrk->GetHistogram()->GetYaxis()->SetTitle("Reconstruction efficiency");
407 g_Vrt_rec_eff_m1_split_vs_ntrk->SetMarkerStyle(20);
408 g_Vrt_rec_eff_m1_split_vs_ntrk->Write("", TObject::kOverwrite);
409 delete g_Vrt_rec_eff_m1_split_vs_ntrk;
410
411 g_Vrt_sel_eff_m1_split_vs_ntrk->GetHistogram()->GetXaxis()->SetTitle("Number of tracks");
412 g_Vrt_sel_eff_m1_split_vs_ntrk->GetHistogram()->GetYaxis()->SetTitle("Selection Efficiency");
413 g_Vrt_sel_eff_m1_split_vs_ntrk->SetMarkerStyle(20);
414 g_Vrt_sel_eff_m1_split_vs_ntrk->Write("", TObject::kOverwrite);
415 delete g_Vrt_sel_eff_m1_split_vs_ntrk;
416
417 return;
418 }
419
420 std::vector<float> stableGaussianFit(TH1* histo) {
421 std::vector<float> results;
422 if (histo) {
423 double sigmas = 2.;
424
425 histo->Fit("gaus", "Q0", "", -2, 2);
426 TF1* func = histo->GetFunction("gaus");
427 double actualSigma = func->GetParameter(2);
428 double actualSigmaErr = func->GetParError(2);
429
430 for (int u = 0; u < 10; u++) {
431 histo->Fit("gaus", "Q0", "", -sigmas * actualSigma, sigmas * actualSigma);
432 func = histo->GetFunction("gaus");
433 actualSigma = func->GetParameter(2);
434 actualSigmaErr = func->GetParError(2);
435 }//end of the fitting loop
436
437 results.push_back(actualSigma);
438 results.push_back(actualSigmaErr);
439 } else {
440 results.push_back(0.);
441 results.push_back(0.);
442 }//end of protection against an empty histogram
443
444 return results;
445 }//end of stableGaussian Fit function
446
447 double error_func(float x, const Double_t* par) {
448//calculating the square of the propagated error on the fit values
449 return(TMath::Power(par[0], 2) + x * TMath::Power(par[1], 2) + TMath::Power(x * par[2], 2));
450 }
451
452 double scaleFactorFitFcn(double* x, double* par) {
453 // Truncated gaus-smeared step function
454 // par 0: mean of turn-on (and truncation point)
455 // par 1: slope of turn-on
456 // par 2: plateau
457 return (x[0] >= par[0]) * TMath::Erf(par[1] * x[0] - par[0]) * par[2];
458 }
459}
#define x
static void pv_PrimaryVertexMonitoring_calcResoAndEfficiency(const std::string &inFilename, bool isIncremental=false)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
void binWidth(TH1 *h)
Definition listroot.cxx:80
void plotResolution(const std::string &coordinate, const std::string &versus)
std::vector< float > stableGaussianFit(TH1 *histo)
double error_func(float x, const Double_t *par)
double scaleFactorFitFcn(double *x, double *par)