Go to the documentation of this file.00001 #ifndef PLOT_1D__H
00002 #define PLOT_1D__H
00003
00004 #include "PlotCompareUtility.h"
00005 #include "PlotTypes.h"
00006
00007 #include <TString.h>
00008 #include <TCanvas.h>
00009 #include <TLegend.h>
00010 #include <TH1F.h>
00011 #include <TText.h>
00012
00013 #include <iostream>
00014 #include <fstream>
00015 #include <string>
00016
00017 template < >
00018 bool PlotCompareUtility::compare<Plot1D>(HistoData *HD) {
00019
00020
00021 TH1F *href = (TH1F *)HD->getRefHisto();
00022 TH1F *hnew = (TH1F *)HD->getNewHisto();
00023
00024
00025 if (hnew == NULL || href == NULL || hnew->GetEntries() <= 1 || href->GetEntries() <= 1) {
00026
00027 HD->setIsEmpty(true); return false;
00028 }
00029
00030
00031 if (HD->getDoAllow1DRebinning()) centerRebin(href,hnew);
00032
00033
00034 double ksScore = hnew->KolmogorovTest(href,"D");
00035 double chi2Score = hnew->Chi2Test(href,"uup");
00036
00037
00038 renormalize(href,hnew);
00039
00040
00041 HD->setKSScore(ksScore); HD->setChi2Score(chi2Score);
00042 if (ksThreshold > 0 && chi2Threshold > 0) {
00043 HD->setLowScore(ksScore < chi2Score ? ksScore : chi2Score);
00044 HD->setHighScore(ksScore > chi2Score ? ksScore : chi2Score);
00045 }
00046 else if (ksThreshold > 0) { HD->setLowScore(ksScore); HD->setHighScore(ksScore); }
00047 else if (chi2Threshold > 0) { HD->setLowScore(chi2Score); HD->setHighScore(chi2Score); }
00048 else std::cerr << "error: no test performed? chi2Threshold and ksThreshold <= 0\n";
00049
00050
00051 bool passed = (ksScore >= ksThreshold && chi2Score >= chi2Threshold);
00052 HD->setResult(passed);
00053
00054
00055 HD->setIsEmpty(false);
00056 return passed;
00057
00058 }
00059
00060 template < >
00061 void PlotCompareUtility::makePlots<Plot1D>(HistoData *HD) {
00062
00063 std::cerr << HD->getName() << "makePlots<Plot1D>\n";
00064
00065
00066 if (HD->getIsEmpty()) {
00067 HD->setResultImage("NoData_Results.gif");
00068 HD->setResultTarget("NoData_Results.gif");
00069 return;
00070 }
00071
00072
00073 TH1F *href = (TH1F *)HD->getRefHisto();
00074 TH1F *hnew = (TH1F *)HD->getNewHisto();
00075
00076
00077 href->SetStats(0);
00078 href->SetLineWidth(2);
00079 href->SetLineColor(14);
00080 href->SetMarkerColor(14);
00081 href->SetFillColor(18);
00082
00083
00084 hnew->SetStats(0);
00085 hnew->SetLineWidth(2);
00086 hnew->SetLineColor(HD->getShadedLineColor());
00087 hnew->SetFillStyle(HD->getShadedFillStyle());
00088 hnew->SetFillColor(HD->getShadedFillColor());
00089
00090
00091 TString title = HD->getName();
00092 if (ksThreshold > 0) title += " KS Score = "; title += HD->getKSScore();
00093 if (chi2Threshold > 0) title += " Chi^2 Score = "; title += HD->getChi2Score();
00094
00095
00096 int plotsCanvasWidth = plotsWidth + 4;
00097 int plotsCanvasHeight = plotsHeight + 28;
00098
00099
00100 TCanvas hCanvas("hCanvas","hCanvas",plotsCanvasWidth,plotsCanvasHeight);
00101 hCanvas.SetTopMargin(float(plotsTopMargin) / plotsHeight);
00102 hCanvas.SetLeftMargin(float(plotsLeftMargin) / plotsWidth);
00103 hCanvas.SetRightMargin(float(plotsRightMargin) / plotsWidth);
00104 hCanvas.SetBottomMargin(float(plotsBottomMargin) / plotsHeight);
00105 hCanvas.SetFrameFillColor(10);
00106 hCanvas.SetGrid();
00107 hCanvas.SetLogy(1);
00108 hCanvas.Draw();
00109
00110 TText canvasTitle(0.1,0.97,title.Data());
00111 canvasTitle.Draw("SAME");
00112
00113
00114 href->Draw();
00115 hnew->Draw("SAME");
00116 if (HD->getDoDrawErrorBars()) hnew->Draw("E1SAME");
00117
00118
00119 TLegend legend(0.15,0.01,0.3, 0.08);
00120 legend.AddEntry(hnew,"New","lF");
00121 legend.AddEntry(href,"Reference","lF");
00122 legend.SetFillColor(kNone);
00123 legend.Draw("SAME");
00124
00125
00126 std::string gifName = HD->getName() + "_Results.gif";
00127 if (HD->getResultImage() == "") HD->setResultImage(gifName);
00128 if (HD->getResultTarget() == "") HD->setResultTarget(gifName);
00129 std::cerr << "About to print" << gifName << "\n";
00130 hCanvas.Print(gifName.c_str());
00131
00132 }
00133
00134 template < >
00135 void PlotCompareUtility::makeHTML<Plot1D>(HistoData *HD) {
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 }
00154
00155
00156 #endif // PLOT_1D__H