7 #ifndef CROMBIETOOLS_PLOTTOOLS_PLOTHISTS_H 8 #define CROMBIETOOLS_PLOTTOOLS_PLOTHISTS_H 34 void AddUncertainty ( UInt_t index, TString FileName, TString HistName,
35 Int_t startBin = 1, Int_t endBin = 0 );
37 std::vector<TH1D*>
MakeHists ( Int_t NumXBins, Double_t *XBins );
38 std::vector<TH1D*>
MakeHists ( Int_t NumXBins, Double_t MinX, Double_t MaxX );
41 virtual void MakeCanvas ( TString FileBase, Int_t NumXBins, Double_t *XBins,
42 TString XLabel, TString YLabel, Bool_t logY =
false);
44 virtual void MakeCanvas ( TString FileBase, Int_t NumXBins, Double_t MinX, Double_t MaxX,
45 TString XLabel, TString YLabel, Bool_t logY =
false);
57 void MakeCanvas ( TString FileBase, std::vector<TH1D*> theHists,
58 TString XLabel, TString YLabel, Bool_t logY =
false)
59 {
BaseCanvas(FileBase, theHists, XLabel, YLabel, logY); }
84 Int_t startBin, Int_t endBin )
87 fUncerts.push_back({
"", FileName, HistName, startBin, endBin});
97 std::vector<TH1D*> theHists;
112 "expressions:",
fInExpr.size());
113 Message(
eError,
"Nothing has been initialized in hists plot.");
123 for (UInt_t iPlot = 0; iPlot != NumPlots; ++iPlot) {
132 if (!inTree || inExpr ==
"" || inCut ==
"") {
133 Message(
eError,
"There is a problem with one of these in plot", iPlot);
134 Message(
eError,
"Tree:", inTree,
"Expression:", inExpr.Data(),
"Cut:", inCut.GetTitle());
141 tempHist =
new TH1D(tempName, tempName, NumXBins, XBins);
145 inExpr.Data(), tempName.Data(), inCut.GetTitle());
147 inTree->Draw(inExpr +
">>" + tempName, inCut);
149 if (
fUncExpr !=
"" && tempHist->GetEntries() != 0) {
153 TProfile *uncProfile =
new TProfile(tempName, tempName, NumXBins, XBins);
154 inTree->Draw(
fUncExpr +
":" + inExpr +
">>" + tempName, inCut);
155 for (Int_t iBin = 1; iBin != NumXBins + 1; ++iBin) {
156 Double_t uncSquared = uncProfile->GetBinContent(iBin);
157 if (uncSquared == 0.0)
159 Message(
eDebug,
"About to apply uncertainty %f", TMath::Sqrt(uncSquared));
161 Double_t content = tempHist->GetBinContent(iBin);
163 tempName.Data(), iBin, content, tempHist->GetBinError(iBin));
164 tempHist->SetBinError(iBin,
165 TMath::Sqrt(pow(tempHist->GetBinError(iBin), 2) +
166 content * content * uncSquared));
168 tempName.Data(), iBin, content, tempHist->GetBinError(iBin));
174 (Int_t) tempHist->GetEntries(), tempHist->Integral(
"width"));
176 theHists.push_back(tempHist);
185 tempHist =
new TH1D(tempName, tempName, NumXBins, XBins);
186 for (Int_t iBin = 1; iBin != NumXBins + 1; ++iBin)
187 tempHist->SetBinContent(iBin, tempHist->GetBinWidth(iBin)/
fEventsPer);
190 for (UInt_t iHist = 0; iHist != theHists.size(); ++iHist) {
191 Message(
eDebug,
"Now for %s, number of events: %i, integral: %f",
192 theHists[iHist]->GetName(),
193 (Int_t) tempHist->GetEntries(),
194 tempHist->Integral(
"width"));
196 Division(theHists[iHist], tempHist);
203 Double_t normInt = 1;
207 for (UInt_t iHist = 0; iHist != NumPlots; ++iHist)
208 theHists[iHist]->Scale(normInt/theHists[iHist]->Integral(
"width"));
211 for (UInt_t iUncert = 0; iUncert !=
fSysUncIndices.size(); ++iUncert)
214 for (
auto* hist : theHists)
215 Message(
eInfo,
"Mean: %f, StdDev: %f", hist->GetMean(), hist->GetStdDev());
224 Double_t XBins[NumXBins+1];
232 TString XLabel, TString YLabel, Bool_t logY)
234 std::vector<TH1D*> hists =
MakeHists(NumXBins, XBins);
235 BaseCanvas(FileBase, hists, XLabel, YLabel, logY);
237 for (UInt_t i0 = 0; i0 != hists.size(); ++i0)
244 TString XLabel, TString YLabel, Bool_t logY)
246 Double_t XBins[NumXBins+1];
248 MakeCanvas(FileBase, NumXBins, XBins, XLabel, YLabel, logY);