Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:13

0001 #include "include/HistoData.h"
0002 
0003 #include <iostream>
0004 
0005 #include <TFile.h>
0006 #include <TH1.h>
0007 #include <TLine.h>
0008 #include <TNamed.h>
0009 #include <TPave.h>
0010 
0011 using namespace std;
0012 
0013 HistoData::HistoData(
0014     std::string Name, int Type, int Bin, string NewPath, TFile *NewFile, string RefPath, TFile *RefFile) {
0015   name = Name;
0016   type = Type;
0017   bin = Bin;
0018 
0019   newHisto = dynamic_cast<TH1 *>(NewFile->Get(NewPath.c_str()));
0020   refHisto = dynamic_cast<TH1 *>(RefFile->Get(RefPath.c_str()));
0021 
0022   initialize();
0023 }
0024 
0025 HistoData::HistoData(std::string Name, int Type, int Bin, TH1 *NewHisto, TH1 *RefHisto) {
0026   name = Name;
0027   type = Type;
0028   bin = Bin;
0029   newHisto = NewHisto;
0030   refHisto = RefHisto;
0031 
0032   initialize();
0033 }
0034 
0035 void HistoData::initialize() {
0036   // scores/tests initialization
0037   lowScore = 10.0;
0038   highScore = 0.0;
0039   ksScore = 0.0;
0040   chi2Score = 0.0;
0041   result = true;
0042   isEmpty = true;
0043 
0044   // for HTML display
0045   // resultImage = "NoData_Results.gif";
0046   // resultTarget = "NoData_Results.gif";
0047   resultImage = "";
0048   resultTarget = "";
0049 
0050   // rebinning/projections, etc.
0051   doDrawErrorBars = false;
0052   doAllow1DRebinning = false;
0053   doAllow2DRebinningX = true;
0054   doAllow2DRebinningY = true;
0055   doProjectionsX = false;
0056   doProjectionsY = true;
0057   maxProjectionsX = 20;
0058   maxProjectionsY = 20;
0059 
0060   // test result color conventions
0061   passColor = kGreen;
0062   failColor = kRed;
0063   errorColor = 16;  // kGray
0064 
0065   // default color and style scheme
0066   lineUseFillColor = true;
0067   solidLineColor = kWhite;
0068   solidFillColor = kWhite;
0069   solidFillStyle = 1001;
0070   shadedLineColor = errorColor;
0071   shadedFillColor = errorColor;
0072   shadedFillStyle = 3001;
0073 }
0074 
0075 void HistoData::setResult(bool Result) {
0076   // set the test result
0077   result = Result;
0078 
0079   // set the color scheme
0080   solidFillColor = result ? passColor : failColor;
0081   shadedFillColor = result ? passColor : failColor;
0082 }
0083 
0084 void HistoData::dump() {
0085   cout << "name      = " << name << endl
0086        << "type      = " << type << endl
0087        << "bin       = " << bin << endl
0088        << "ksScore   = " << ksScore << endl
0089        << "chi2Score = " << chi2Score << endl
0090        << "result    = " << (result ? "pass" : "fail") << endl;
0091 }
0092 
0093 void HistoData::drawResult(TH1 *Summary, bool Vertical, bool SetBinLabel) {
0094   // add label to the summary if desired
0095   if (SetBinLabel) {
0096     Summary->GetXaxis()->SetBinLabel(bin, getRefHisto()->GetTitle());
0097     // Summary->GetXaxis()->SetBinLabel(bin,name.c_str());
0098   } else
0099     Summary->GetXaxis()->SetBinLabel(bin, name.c_str());
0100 
0101   double minimum = Summary->GetMinimum();
0102   // determine where to draw the result (score axis)
0103   //   1: solid bar starts
0104   //   2: solid bar ends, hatched bar starts
0105   //   3: hatched bar ends
0106   double score1 = minimum;
0107   double score2 = (lowScore == 10. || lowScore < minimum) ? minimum : lowScore;
0108   double score3 = (lowScore == 10.) ? 1 : ((highScore < minimum) ? minimum : highScore);
0109 
0110   // determine where to draw the result (binning axis)
0111   double binCenter = Summary->GetBinCenter(bin);
0112   double binWidth = Summary->GetBinWidth(bin);
0113   double bin1 = binCenter - binWidth / 3;
0114   double bin2 = binCenter + binWidth / 3;
0115 
0116   // set coordinates of display based on plot alignment
0117   double solidX1, solidY1, solidX2, solidY2;
0118   double hatchedX1, hatchedY1, hatchedX2, hatchedY2;
0119   double axisX1, axisY1, axisX2, axisY2;
0120   if (Vertical) {
0121     solidX1 = bin1;
0122     solidX2 = bin2;
0123     solidY1 = score1;
0124     solidY2 = score2;
0125     hatchedX1 = bin1;
0126     hatchedX2 = bin2;
0127     hatchedY1 = score2;
0128     hatchedY2 = score3;
0129     axisX1 = bin1;
0130     axisX2 = bin2;
0131     axisY1 = minimum;
0132     axisY2 = minimum;
0133   } else {
0134     solidX1 = score1;
0135     solidX2 = score2;
0136     solidY1 = bin1;
0137     solidY2 = bin2;
0138     hatchedX1 = score2;
0139     hatchedX2 = score3;
0140     hatchedY1 = bin1;
0141     hatchedY2 = bin2;
0142     axisX1 = minimum;
0143     axisX2 = minimum;
0144     axisY1 = bin1;
0145     axisY2 = bin2;
0146   }
0147 
0148   // a solid bar is drawn from zero to the lowest score
0149   if (lowScore > minimum && lowScore != 10.) {
0150     TPave *solidBar = new TPave(solidX1, solidY1, solidX2, solidY2, 1, "");
0151     solidBar->SetBit(kCanDelete);
0152     solidBar->SetLineColor(lineUseFillColor ? solidFillColor : solidLineColor);
0153     solidBar->SetFillColor(solidFillColor);
0154     solidBar->SetFillStyle(solidFillStyle);
0155     solidBar->Draw();
0156   }
0157 
0158   // a hatched bar is drawn from the lowest score to the highest score
0159   if ((lowScore != highScore && highScore > minimum) || lowScore == 10.) {
0160     TPave *hatchedBar = new TPave(hatchedX1, hatchedY1, hatchedX2, hatchedY2, 1, "");
0161     hatchedBar->SetBit(kCanDelete);
0162     hatchedBar->SetLineColor(lineUseFillColor ? shadedFillColor : shadedLineColor);
0163     hatchedBar->SetFillColor(shadedFillColor);
0164     hatchedBar->SetFillStyle(3004);
0165     hatchedBar->Draw();
0166   }
0167 
0168   // paste a line over the base axis to fix border color artifacts
0169   TLine *axisLine = new TLine(axisX1, axisY1, axisX2, axisY2);
0170   if (Vertical)
0171     axisLine->SetLineColor(Summary->GetAxisColor("X"));
0172   else
0173     axisLine->SetLineColor(Summary->GetAxisColor("Y"));
0174   axisLine->SetBit(kCanDelete);
0175   axisLine->Draw("SAME");
0176 
0177   // paste a line before (in this proceeding that means after) Barrel and Endcap
0178   // Plots
0179   if (name == "ERPt" || name == "BRPt") {
0180     axisY1 = axisY2 = binCenter + binWidth / 2;
0181     axisX2 = Summary->GetMaximum();
0182     axisX1 = Summary->GetMinimum() - 200;
0183     TLine *regionLine = new TLine(axisX1, axisY1, axisX2, axisY2);
0184     regionLine->SetLineColor(Summary->GetAxisColor("X"));
0185     regionLine->SetBit(kCanDelete);
0186     regionLine->SetLineWidth(3);
0187     regionLine->Draw();
0188   }
0189 }