File indexing completed on 2025-01-18 09:11:48
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::PlotHelpers {
0022 TH1F* bookHisto(const char* histName, const char* histTitle,
0023 const Binning& varBinning) {
0024 TH1F* hist =
0025 new TH1F(histName, histTitle, varBinning.nBins(), varBinning.data());
0026 hist->GetXaxis()->SetTitle(varBinning.title().c_str());
0027 hist->GetYaxis()->SetTitle("Entries");
0028 hist->Sumw2();
0029 return hist;
0030 }
0031
0032 TH2F* bookHisto(const char* histName, const char* histTitle,
0033 const Binning& varXBinning, const Binning& varYBinning) {
0034 TH2F* hist =
0035 new TH2F(histName, histTitle, varXBinning.nBins(), varXBinning.data(),
0036 varYBinning.nBins(), varYBinning.data());
0037 hist->GetXaxis()->SetTitle(varXBinning.title().c_str());
0038 hist->GetYaxis()->SetTitle(varYBinning.title().c_str());
0039 hist->Sumw2();
0040 return hist;
0041 }
0042
0043 void fillHisto(TH1F* hist, float value, float weight) {
0044 assert(hist != nullptr);
0045 hist->Fill(value, weight);
0046 }
0047
0048 void fillHisto(TH2F* hist, float xValue, float yValue, float weight) {
0049 assert(hist != nullptr);
0050 hist->Fill(xValue, yValue, weight);
0051 }
0052
0053 void anaHisto(TH1D* inputHist, int j, TH1F* meanHist, TH1F* widthHist) {
0054
0055 assert(inputHist != nullptr);
0056 if (inputHist->GetEntries() > 0) {
0057 TFitResultPtr r = inputHist->Fit("gaus", "QS0");
0058 if ((r.Get() != nullptr) && ((r->Status() % 1000) == 0)) {
0059
0060
0061 meanHist->SetBinContent(j, r->Parameter(1));
0062 meanHist->SetBinError(j, r->ParError(1));
0063 widthHist->SetBinContent(j, r->Parameter(2));
0064 widthHist->SetBinError(j, r->ParError(2));
0065 }
0066 }
0067 }
0068
0069 TEfficiency* bookEff(const char* effName, const char* effTitle,
0070 const Binning& varBinning) {
0071 TEfficiency* efficiency =
0072 new TEfficiency(effName, effTitle, varBinning.nBins(), varBinning.data());
0073 return efficiency;
0074 }
0075
0076 TEfficiency* bookEff(const char* effName, const char* effTitle,
0077 const Binning& varXBinning, const Binning& varYBinning) {
0078 TEfficiency* efficiency = new TEfficiency(
0079 effName, effTitle, varXBinning.nBins(), varXBinning.data(),
0080 varYBinning.nBins(), varYBinning.data());
0081 return efficiency;
0082 }
0083
0084 void fillEff(TEfficiency* efficiency, float value, bool status) {
0085 assert(efficiency != nullptr);
0086 efficiency->Fill(status, value);
0087 }
0088
0089 void fillEff(TEfficiency* efficiency, float xValue, float yValue, bool status) {
0090 assert(efficiency != nullptr);
0091 efficiency->Fill(status, xValue, yValue);
0092 }
0093
0094 TProfile* bookProf(const char* profName, const char* profTitle,
0095 const Binning& varXBinning, const Binning& varYBinning) {
0096 TProfile* prof =
0097 new TProfile(profName, profTitle, varXBinning.nBins(), varXBinning.data(),
0098 varYBinning.low(), varYBinning.high());
0099 prof->GetXaxis()->SetTitle(varXBinning.title().c_str());
0100 prof->GetYaxis()->SetTitle(varYBinning.title().c_str());
0101 return prof;
0102 }
0103
0104 void fillProf(TProfile* profile, float xValue, float yValue, float weight) {
0105 assert(profile != nullptr);
0106 profile->Fill(xValue, yValue, weight);
0107 }
0108
0109 }