Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Helpers.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Helpers.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2023 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 
9 #pragma once
10 
11 #include <string>
12 #include <utility>
13 
14 #include "TEfficiency.h"
15 #include "TFitResult.h"
16 #include "TFitResultPtr.h"
17 #include "TH1F.h"
18 #include "TH2F.h"
19 #include "TProfile.h"
20 #include "TROOT.h"
21 
22 class TEfficiency;
23 class TH1D;
24 class TH1F;
25 class TH2F;
26 class TProfile;
27 
28 namespace ActsExamples {
29 
30 namespace PlotHelpers {
32 class Binning {
33  public:
34  Binning() : m_bins({0.0}) {}
35 
36  Binning(std::string title, int bins, double bMin, double bMax)
37  : m_title(std::move(title)) {
38  const auto step = (bMax - bMin) / bins;
39  m_bins.resize(bins + 1);
40  std::generate(m_bins.begin(), m_bins.end(), [&, v = bMin]() mutable {
41  auto r = v;
42  v += step;
43  return r;
44  });
45  }
46 
47  Binning(std::string title, std::vector<double> bins)
48  : m_title(std::move(title)), m_bins(std::move(bins)) {}
49 
50  const auto& title() const { return m_title; }
51  auto nBins() const { return m_bins.size() - 1; }
52  const double* data() const { return m_bins.data(); }
53  auto low() const { return m_bins.front(); }
54  auto high() const { return m_bins.back(); }
55 
56  private:
58  std::vector<double> m_bins;
59 };
60 
66 TH1F* bookHisto(const char* histName, const char* histTitle,
67  const Binning& varBinning);
68 
75 TH2F* bookHisto(const char* histName, const char* histTitle,
76  const Binning& varXBinning, const Binning& varYBinning);
77 
82 void fillHisto(TH1F* hist, float value, float weight = 1.0);
83 
89 void fillHisto(TH2F* hist, float xValue, float yValue, float weight = 1.0);
90 
99 void anaHisto(TH1D* inputHist, int j, TH1F* meanHist, TH1F* widthHist);
100 
106 TEfficiency* bookEff(const char* effName, const char* effTitle,
107  const Binning& varBinning);
108 
115 TEfficiency* bookEff(const char* effName, const char* effTitle,
116  const Binning& varXBinning, const Binning& varYBinning);
117 
122 void fillEff(TEfficiency* efficiency, float value, bool status);
123 
129 void fillEff(TEfficiency* efficiency, float xValue, float yValue, bool status);
130 
137 TProfile* bookProf(const char* profName, const char* profTitle,
138  const Binning& varXBinning, const Binning& varYBinning);
139 
145 void fillProf(TProfile* profile, float xValue, float yValue,
146  float weight = 1.0);
147 
148 } // namespace PlotHelpers
149 
150 } // namespace ActsExamples