File indexing completed on 2025-12-19 08:59:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Utilities/Helpers.hpp"
0010
0011 #include <cassert>
0012
0013 #include <TAxis.h>
0014 #include <TEfficiency.h>
0015 #include <TFitResult.h>
0016 #include <TFitResultPtr.h>
0017 #include <TH1.h>
0018 #include <TH2.h>
0019 #include <TProfile.h>
0020
0021 namespace ActsExamples {
0022
0023 TH1F* PlotHelpers::bookHisto(const std::string& histName,
0024 const std::string& histTitle,
0025 const Binning& varBinning) {
0026 TH1F* hist = new TH1F(histName.c_str(), histTitle.c_str(), varBinning.nBins(),
0027 varBinning.binEdges());
0028 hist->GetXaxis()->SetTitle(varBinning.title().c_str());
0029 hist->GetYaxis()->SetTitle("Entries");
0030 hist->Sumw2();
0031 return hist;
0032 }
0033
0034 TH2F* PlotHelpers::bookHisto(const std::string& histName,
0035 const std::string& histTitle,
0036 const Binning& varXBinning,
0037 const Binning& varYBinning) {
0038 TH2F* hist = new TH2F(histName.c_str(), histTitle.c_str(),
0039 varXBinning.nBins(), varXBinning.binEdges(),
0040 varYBinning.nBins(), varYBinning.binEdges());
0041 hist->GetXaxis()->SetTitle(varXBinning.title().c_str());
0042 hist->GetYaxis()->SetTitle(varYBinning.title().c_str());
0043 hist->Sumw2();
0044 return hist;
0045 }
0046
0047 void PlotHelpers::fillHisto(TH1F* hist, float value, float weight) {
0048 assert(hist != nullptr);
0049 hist->Fill(value, weight);
0050 }
0051
0052 void PlotHelpers::fillHisto(TH2F* hist, float xValue, float yValue,
0053 float weight) {
0054 assert(hist != nullptr);
0055 hist->Fill(xValue, yValue, weight);
0056 }
0057
0058 void PlotHelpers::anaHisto(TH1D* inputHist, int j, TH1F* meanHist,
0059 TH1F* widthHist) {
0060
0061 assert(inputHist != nullptr);
0062 if (inputHist->GetEntries() > 0) {
0063 TFitResultPtr r = inputHist->Fit("gaus", "QS0");
0064 if ((r.Get() != nullptr) && ((r->Status() % 1000) == 0)) {
0065
0066
0067 meanHist->SetBinContent(j, r->Parameter(1));
0068 meanHist->SetBinError(j, r->ParError(1));
0069 widthHist->SetBinContent(j, r->Parameter(2));
0070 widthHist->SetBinError(j, r->ParError(2));
0071 }
0072 }
0073 }
0074
0075 TEfficiency* PlotHelpers::bookEff(const std::string& effName,
0076 const std::string& effTitle,
0077 const Binning& varBinning) {
0078 TEfficiency* efficiency =
0079 new TEfficiency(effName.c_str(), effTitle.c_str(), varBinning.nBins(),
0080 varBinning.binEdges());
0081 return efficiency;
0082 }
0083
0084 TEfficiency* PlotHelpers::bookEff(const std::string& effName,
0085 const std::string& effTitle,
0086 const Binning& varXBinning,
0087 const Binning& varYBinning) {
0088 TEfficiency* efficiency = new TEfficiency(
0089 effName.c_str(), effTitle.c_str(), varXBinning.nBins(),
0090 varXBinning.binEdges(), varYBinning.nBins(), varYBinning.binEdges());
0091 return efficiency;
0092 }
0093
0094 void PlotHelpers::fillEff(TEfficiency* efficiency, float value, bool status) {
0095 assert(efficiency != nullptr);
0096 efficiency->Fill(status, value);
0097 }
0098
0099 void PlotHelpers::fillEff(TEfficiency* efficiency, float xValue, float yValue,
0100 bool status) {
0101 assert(efficiency != nullptr);
0102 efficiency->Fill(status, xValue, yValue);
0103 }
0104
0105 TProfile* PlotHelpers::bookProf(const std::string& profName,
0106 const std::string& profTitle,
0107 const Binning& varXBinning,
0108 const Binning& varYBinning) {
0109 TProfile* prof = new TProfile(profName.c_str(), profTitle.c_str(),
0110 varXBinning.nBins(), varXBinning.binEdges(),
0111 varYBinning.low(), varYBinning.high());
0112 prof->GetXaxis()->SetTitle(varXBinning.title().c_str());
0113 prof->GetYaxis()->SetTitle(varYBinning.title().c_str());
0114 return prof;
0115 }
0116
0117 void PlotHelpers::fillProf(TProfile* profile, float xValue, float yValue,
0118 float weight) {
0119 assert(profile != nullptr);
0120 profile->Fill(xValue, yValue, weight);
0121 }
0122
0123 }