Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:23

0001 #include "PlotsFromDump.hh"
0002 
0003 PlotsFromDump::PlotsFromDump(const TString& sample, const TString& build, const TString& suite, const int useARCH)
0004     : sample(sample), build(build), suite(suite), useARCH(useARCH) {
0005   // setup style for plotting
0006   setupStyle();
0007 
0008   // setup suite enum
0009   setupSUITEEnum(suite);
0010 
0011   // setup build options : true for isBenchmark-type plots, false for no CMSSW
0012   setupBuilds(true, false);
0013 
0014   // get the right build label
0015   label =
0016       std::find_if(builds.begin(), builds.end(), [&](const auto& ibuild) { return build.EqualTo(ibuild.name); })->label;
0017   if (label == "") {
0018     std::cerr << build.Data() << " build routine not specified in list of builds! Exiting..." << std::endl;
0019     exit(1);
0020   }
0021 
0022   // Setup test opts
0023   setupTests(useARCH);
0024 
0025   // Setup plot opts
0026   setupPlots();
0027 }
0028 
0029 PlotsFromDump::~PlotsFromDump() {}
0030 
0031 void PlotsFromDump::RunPlotsFromDump() {
0032   // Open ROOT files first
0033   std::vector<TFile*> files(ntests);
0034   for (auto t = 0U; t < ntests; t++) {
0035     const auto& test = tests[t];
0036     auto& file = files[t];
0037 
0038     file = TFile::Open("test_" + test.arch + "_" + sample + "_" + build + "_" + test.suffix + ".root");
0039   }
0040 
0041   // Outer loop over all overplots
0042   for (auto p = 0U; p < nplots; p++) {
0043     const auto& plot = plots[p];
0044 
0045     // declare standard stuff
0046     const Bool_t isLogy =
0047         !(plot.name.Contains("MXPHI", TString::kExact) || plot.name.Contains("MXETA", TString::kExact));
0048     auto canv = new TCanvas();
0049     canv->cd();
0050     canv->SetLogy(isLogy);
0051 
0052     auto leg = new TLegend(0.7, 0.68, 0.98, 0.92);
0053 
0054     Double_t min = 1e9;
0055     Double_t max = -1e9;
0056 
0057     std::vector<TH1F*> hists(ntests);
0058     for (auto t = 0U; t < ntests; t++) {
0059       const auto& test = tests[t];
0060       auto& file = files[t];
0061       auto& hist = hists[t];
0062 
0063       hist = (TH1F*)file->Get(plot.name + "_" + test.suffix);
0064       const TString title = hist->GetTitle();
0065       hist->SetTitle(title + " [" + label + " - " + sample + "]");
0066       hist->GetXaxis()->SetTitle(plot.xtitle.Data());
0067       hist->GetYaxis()->SetTitle(plot.ytitle.Data());
0068 
0069       hist->SetLineColor(test.color);
0070       hist->SetMarkerColor(test.color);
0071       hist->SetMarkerStyle(test.marker);
0072 
0073       hist->Scale(1.f / hist->Integral());
0074       GetMinMaxHist(hist, min, max);
0075     }
0076 
0077     for (auto t = 0U; t < ntests; t++) {
0078       const auto& test = tests[t];
0079       auto& hist = hists[t];
0080 
0081       SetMinMaxHist(hist, min, max, isLogy);
0082       hist->Draw(t > 0 ? "P SAME" : "P");
0083 
0084       const TString mean = Form("%4.1f", hist->GetMean());
0085       leg->AddEntry(hist, test.arch + " " + test.suffix + " [#mu = " + mean + "]", "p");
0086     }
0087 
0088     // draw legend and save plot
0089     leg->Draw("SAME");
0090     canv->SaveAs(sample + "_" + build + "_" + plot.outname + ".png");
0091 
0092     // delete temps
0093     for (auto& hist : hists)
0094       delete hist;
0095     delete leg;
0096     delete canv;
0097   }
0098 
0099   // delete files
0100   for (auto& file : files)
0101     delete file;
0102 }