File indexing completed on 2024-04-06 12:33:13
0001 #ifndef PLOT_1D__H
0002 #define PLOT_1D__H
0003
0004 #include "PlotCompareUtility.h"
0005 #include "PlotTypes.h"
0006
0007 #include <TCanvas.h>
0008 #include <TH1F.h>
0009 #include <TLegend.h>
0010 #include <TString.h>
0011 #include <TText.h>
0012
0013 #include <fstream>
0014 #include <iostream>
0015 #include <string>
0016
0017 template <>
0018 inline bool PlotCompareUtility::compare<Plot1D>(HistoData *HD) {
0019
0020 TH1F *href = (TH1F *)HD->getRefHisto();
0021 TH1F *hnew = (TH1F *)HD->getNewHisto();
0022
0023
0024 if (hnew == nullptr || href == nullptr || hnew->GetEntries() <= 1 || href->GetEntries() <= 1) {
0025
0026
0027 HD->setIsEmpty(true);
0028 return false;
0029 }
0030
0031
0032 if (HD->getDoAllow1DRebinning())
0033 centerRebin(href, hnew);
0034
0035
0036 double ksScore = hnew->KolmogorovTest(href, "D");
0037 double chi2Score = hnew->Chi2Test(href, "uup");
0038
0039
0040 renormalize(href, hnew);
0041
0042
0043 HD->setKSScore(ksScore);
0044 HD->setChi2Score(chi2Score);
0045 if (ksThreshold > 0 && chi2Threshold > 0) {
0046 HD->setLowScore(ksScore < chi2Score ? ksScore : chi2Score);
0047 HD->setHighScore(ksScore > chi2Score ? ksScore : chi2Score);
0048 } else if (ksThreshold > 0) {
0049 HD->setLowScore(ksScore);
0050 HD->setHighScore(ksScore);
0051 } else if (chi2Threshold > 0) {
0052 HD->setLowScore(chi2Score);
0053 HD->setHighScore(chi2Score);
0054 } else
0055 std::cerr << "error: no test performed? chi2Threshold and ksThreshold <= 0\n";
0056
0057
0058 bool passed = (ksScore >= ksThreshold && chi2Score >= chi2Threshold);
0059 HD->setResult(passed);
0060
0061
0062 HD->setIsEmpty(false);
0063 return passed;
0064 }
0065
0066 template <>
0067 inline void PlotCompareUtility::makePlots<Plot1D>(HistoData *HD) {
0068 std::cerr << HD->getName() << "makePlots<Plot1D>\n";
0069
0070
0071 if (HD->getIsEmpty()) {
0072 HD->setResultImage("NoData_Results.gif");
0073 HD->setResultTarget("NoData_Results.gif");
0074 return;
0075 }
0076
0077
0078 TH1F *href = (TH1F *)HD->getRefHisto();
0079 TH1F *hnew = (TH1F *)HD->getNewHisto();
0080
0081
0082 href->SetStats(false);
0083 href->SetLineWidth(2);
0084 href->SetLineColor(14);
0085 href->SetMarkerColor(14);
0086 href->SetFillColor(18);
0087
0088
0089 hnew->SetStats(false);
0090 hnew->SetLineWidth(2);
0091 hnew->SetLineColor(HD->getShadedLineColor());
0092 hnew->SetFillStyle(HD->getShadedFillStyle());
0093 hnew->SetFillColor(HD->getShadedFillColor());
0094
0095
0096 TString title = HD->getName();
0097 if (ksThreshold > 0) {
0098 title += " KS Score = ";
0099 title += HD->getKSScore();
0100 }
0101 if (chi2Threshold > 0) {
0102 title += " Chi^2 Score = ";
0103 title += HD->getChi2Score();
0104 }
0105
0106
0107
0108 int plotsCanvasWidth = plotsWidth + 4;
0109 int plotsCanvasHeight = plotsHeight + 28;
0110
0111
0112 TCanvas hCanvas("hCanvas", "hCanvas", plotsCanvasWidth, plotsCanvasHeight);
0113 hCanvas.SetTopMargin(float(plotsTopMargin) / plotsHeight);
0114 hCanvas.SetLeftMargin(float(plotsLeftMargin) / plotsWidth);
0115 hCanvas.SetRightMargin(float(plotsRightMargin) / plotsWidth);
0116 hCanvas.SetBottomMargin(float(plotsBottomMargin) / plotsHeight);
0117 hCanvas.SetFrameFillColor(10);
0118 hCanvas.SetGrid();
0119 hCanvas.SetLogy(1);
0120 hCanvas.Draw();
0121
0122 TText canvasTitle(0.1, 0.97, title.Data());
0123 canvasTitle.Draw("SAME");
0124
0125
0126 href->Draw();
0127 hnew->Draw("SAME");
0128 if (HD->getDoDrawErrorBars())
0129 hnew->Draw("E1SAME");
0130
0131
0132 TLegend legend(0.15, 0.01, 0.3, 0.08);
0133 legend.AddEntry(hnew, "New", "lF");
0134 legend.AddEntry(href, "Reference", "lF");
0135 legend.SetFillColor(kNone);
0136 legend.Draw("SAME");
0137
0138
0139 std::string gifName = HD->getName() + "_Results.gif";
0140 if (HD->getResultImage().empty())
0141 HD->setResultImage(gifName);
0142 if (HD->getResultTarget().empty())
0143 HD->setResultTarget(gifName);
0144 std::cerr << "About to print" << gifName << "\n";
0145 hCanvas.Print(gifName.c_str());
0146 }
0147
0148 template <>
0149 inline void PlotCompareUtility::makeHTML<Plot1D>(HistoData *HD) {
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 }
0166
0167 #endif