Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:45

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <cmath>
0012 #include <string>
0013 #include <utility>
0014 
0015 #include "TEfficiency.h"
0016 #include "TProfile.h"
0017 
0018 class TEfficiency;
0019 class TH1D;
0020 class TH1F;
0021 class TH2F;
0022 class TProfile;
0023 
0024 namespace ActsExamples::PlotHelpers {
0025 
0026 /// @brief Nested binning struct for booking plots
0027 class Binning {
0028  public:
0029   static Binning Uniform(std::string title, const std::size_t bins,
0030                          const double bMin, const double bMax) {
0031     std::vector<double> binEdges(bins + 1);
0032     const double step = (bMax - bMin) / bins;
0033     std::generate(binEdges.begin(), binEdges.end(), [&, v = bMin]() mutable {
0034       const double r = v;
0035       v += step;
0036       return r;
0037     });
0038     return Binning(std::move(title), std::move(binEdges));
0039   }
0040   static Binning Variable(std::string title, std::vector<double> binEdges) {
0041     return Binning(std::move(title), std::move(binEdges));
0042   }
0043   static Binning Logarithmic(std::string title, const std::size_t bins,
0044                              const double bMin, const double bMax) {
0045     std::vector<double> binEdges(bins + 1);
0046     const double logMin = std::log10(bMin);
0047     const double logMax = std::log10(bMax);
0048     const double step = (logMax - logMin) / bins;
0049     for (std::size_t i = 0; i <= bins; ++i) {
0050       binEdges[i] = std::pow(10, logMin + i * step);
0051     }
0052     return Binning(std::move(title), std::move(binEdges));
0053   }
0054 
0055   Binning(std::string title, std::vector<double> binEdges)
0056       : m_title(std::move(title)), m_binEdges(std::move(binEdges)) {}
0057 
0058   const std::string& title() const { return m_title; }
0059   std::size_t nBins() const { return m_binEdges.size() - 1; }
0060   const double* binEdges() const { return m_binEdges.data(); }
0061   double low() const { return m_binEdges.front(); }
0062   double high() const { return m_binEdges.back(); }
0063 
0064  private:
0065   std::string m_title;
0066   std::vector<double> m_binEdges;
0067 };
0068 
0069 /// @brief book a 1D histogram
0070 /// @param histName the name of histogram
0071 /// @param histTitle the title of histogram
0072 /// @param varBinning the binning info of variable
0073 /// @return histogram pointer
0074 TH1F* bookHisto(const std::string& histName, const std::string& histTitle,
0075                 const Binning& varBinning);
0076 
0077 /// @brief book a 2D histogram
0078 /// @param histName the name of histogram
0079 /// @param histTitle the title of histogram
0080 /// @param varXBinning the binning info of variable at x axis
0081 /// @param varYBinning the binning info of variable at y axis
0082 /// @return histogram pointer
0083 TH2F* bookHisto(const std::string& histName, const std::string& histTitle,
0084                 const Binning& varXBinning, const Binning& varYBinning);
0085 
0086 /// @brief fill a 1D histogram
0087 /// @param hist histogram to fill
0088 /// @param value value to fill
0089 /// @param weight weight to fill
0090 void fillHisto(TH1F* hist, float value, float weight = 1.0);
0091 
0092 /// @brief fill a 2D histogram
0093 /// @param hist histogram to fill
0094 /// @param xValue x value to fill
0095 /// @param yValue y value to fill
0096 /// @param weight weight to fill
0097 void fillHisto(TH2F* hist, float xValue, float yValue, float weight = 1.0);
0098 
0099 /// @brief extract details, i.e. mean and width of a 1D histogram and fill
0100 /// them into histograms
0101 /// @param inputHist histogram to investigate
0102 /// @param j  which bin number of meanHist and widthHist to fill
0103 /// @param meanHist histogram to fill the mean value of inputHist
0104 /// @param widthHist  histogram to fill the width value of inputHist
0105 ///
0106 /// @todo  write specialized helper class to extract details of hists
0107 void anaHisto(TH1D* inputHist, int j, TH1F* meanHist, TH1F* widthHist);
0108 
0109 /// @brief book a 1D efficiency plot
0110 /// @param effName the name of plot
0111 /// @param effTitle the title of plot
0112 /// @param varBinning the binning info of variable
0113 /// @return TEfficiency pointer
0114 TEfficiency* bookEff(const std::string& effName, const std::string& effTitle,
0115                      const Binning& varBinning);
0116 
0117 /// @brief book a 2D efficiency plot
0118 /// @param effName the name of plot
0119 /// @param effTitle the title of plot
0120 /// @param varXBinning the binning info of variable at x axis
0121 /// @param varYBinning the binning info of variable at y axis
0122 /// @return TEfficiency pointer
0123 TEfficiency* bookEff(const std::string& effName, const std::string& effTitle,
0124                      const Binning& varXBinning, const Binning& varYBinning);
0125 
0126 /// @brief fill a 1D efficiency plot
0127 /// @param efficiency plot to fill
0128 /// @param value value to fill
0129 /// @param status bool to denote passed or not
0130 void fillEff(TEfficiency* efficiency, float value, bool status);
0131 
0132 /// @brief fill a 2D efficiency plot
0133 /// @param efficiency plot to fill
0134 /// @param xValue x value to fill
0135 /// @param yValue y value to fill
0136 /// @param status bool to denote passed or not
0137 void fillEff(TEfficiency* efficiency, float xValue, float yValue, bool status);
0138 
0139 /// @brief book a TProfile plot
0140 /// @param profName the name of plot
0141 /// @param profTitle the title of plot
0142 /// @param varXBinning the binning info of variable at x axis
0143 /// @param varYBinning the binning info of variable at y axis
0144 /// @return TProfile pointer
0145 TProfile* bookProf(const std::string& profName, const std::string& profTitle,
0146                    const Binning& varXBinning, const Binning& varYBinning);
0147 
0148 /// @brief fill a TProfile plot
0149 /// @param profile plot to fill
0150 /// @param xValue  xvalue to fill
0151 /// @param yValue  yvalue to fill
0152 /// @param weight weight to fill
0153 void fillProf(TProfile* profile, float xValue, float yValue,
0154               float weight = 1.0);
0155 
0156 }  // namespace ActsExamples::PlotHelpers