Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:02

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