ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Helpers.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Helpers.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 namespace FW {
12 
13 namespace PlotHelpers {
14 TH1F* bookHisto(const char* histName, const char* histTitle,
15  const Binning& varBinning) {
16  TH1F* hist = new TH1F(histName, histTitle, varBinning.nBins, varBinning.min,
17  varBinning.max);
18  hist->GetXaxis()->SetTitle(varBinning.title.c_str());
19  hist->GetYaxis()->SetTitle("Entries");
20  hist->Sumw2();
21  return hist;
22 }
23 
24 TH2F* bookHisto(const char* histName, const char* histTitle,
25  const Binning& varXBinning, const Binning& varYBinning) {
26  TH2F* hist = new TH2F(histName, histTitle, varXBinning.nBins, varXBinning.min,
27  varXBinning.max, varYBinning.nBins, varYBinning.min,
28  varYBinning.max);
29  hist->GetXaxis()->SetTitle(varXBinning.title.c_str());
30  hist->GetYaxis()->SetTitle(varYBinning.title.c_str());
31  hist->Sumw2();
32  return hist;
33 }
34 
35 void fillHisto(TH1F* hist, float value, float weight) {
36  assert(hist != nullptr);
37  hist->Fill(value, weight);
38 }
39 
40 void fillHisto(TH2F* hist, float xValue, float yValue, float weight) {
41  assert(hist != nullptr);
42  hist->Fill(xValue, yValue, weight);
43 }
44 
45 void anaHisto(TH1D* inputHist, int j, TH1F* meanHist, TH1F* widthHist) {
46  // evaluate mean and width via the Gauss fit
47  assert(inputHist != nullptr);
48  if (inputHist->GetEntries() > 0) {
49  TFitResultPtr r = inputHist->Fit("gaus", "QS0");
50  if (r.Get() and ((r->Status() % 1000) == 0)) {
51  // fill the mean and width into 'j'th bin of the meanHist and widthHist,
52  // respectively
53  meanHist->SetBinContent(j, r->Parameter(1));
54  meanHist->SetBinError(j, r->ParError(1));
55  widthHist->SetBinContent(j, r->Parameter(2));
56  widthHist->SetBinError(j, r->ParError(2));
57  }
58  }
59 }
60 
61 TEfficiency* bookEff(const char* effName, const char* effTitle,
62  const Binning& varBinning) {
63  TEfficiency* efficiency = new TEfficiency(effName, effTitle, varBinning.nBins,
64  varBinning.min, varBinning.max);
65  return efficiency;
66 }
67 
68 TEfficiency* bookEff(const char* effName, const char* effTitle,
69  const Binning& varXBinning, const Binning& varYBinning) {
70  TEfficiency* efficiency = new TEfficiency(
71  effName, effTitle, varXBinning.nBins, varXBinning.min, varXBinning.max,
72  varYBinning.nBins, varYBinning.min, varYBinning.max);
73  return efficiency;
74 }
75 
76 void fillEff(TEfficiency* efficiency, float value, bool status) {
77  assert(efficiency != nullptr);
78  efficiency->Fill(status, value);
79 }
80 
81 void fillEff(TEfficiency* efficiency, float xValue, float yValue, bool status) {
82  assert(efficiency != nullptr);
83  efficiency->Fill(status, xValue, yValue);
84 }
85 
86 TProfile* bookProf(const char* profName, const char* profTitle,
87  const Binning& varXBinning, const Binning& varYBinning) {
88  TProfile* prof =
89  new TProfile(profName, profTitle, varXBinning.nBins, varXBinning.min,
90  varXBinning.max, varYBinning.min, varYBinning.max);
91  prof->GetXaxis()->SetTitle(varXBinning.title.c_str());
92  prof->GetYaxis()->SetTitle(varYBinning.title.c_str());
93  return prof;
94 }
95 
96 void fillProf(TProfile* profile, float xValue, float yValue, float weight) {
97  assert(profile != nullptr);
98  profile->Fill(xValue, yValue, weight);
99 }
100 
101 } // namespace PlotHelpers
102 
103 } // namespace FW