Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:02:37

0001 #ifndef _Common_
0002 #define _Common_
0003 
0004 #include "TString.h"
0005 #include "TColor.h"
0006 #include "TStyle.h"
0007 #include "TFile.h"
0008 #include "TGraphErrors.h"
0009 #include "TCanvas.h"
0010 #include "TLegend.h"
0011 #include "TMarker.h"
0012 #include "TAxis.h"
0013 #include "TH1F.h"
0014 #include "TF1.h"
0015 #include "TSystem.h"
0016 
0017 #include <iostream>
0018 #include <vector>
0019 #include <algorithm>
0020 
0021 namespace {
0022   void setupStyle() {
0023     gStyle->SetOptStat(0);
0024     gStyle->SetPadTickX(1);
0025     gStyle->SetPadTickY(1);
0026   }
0027 };  // namespace
0028 
0029 enum ArchEnum { SNB, KNL, SKL, LNXG, LNXS };
0030 
0031 namespace {
0032   ArchEnum ARCH;
0033   void setupARCHEnum(const TString& arch) {
0034     if (arch.Contains("SNB"))
0035       ARCH = SNB;
0036     else if (arch.Contains("KNL"))
0037       ARCH = KNL;
0038     else if (arch.Contains("SKL"))
0039       ARCH = SKL;
0040     else if (arch.Contains("LNX-S"))
0041       ARCH = LNXS;
0042     else if (arch.Contains("LNX-G"))
0043       ARCH = LNXG;
0044     else {
0045       std::cerr << arch.Data() << " is not an allowed architecture! Exiting... " << std::endl;
0046       exit(1);
0047     }
0048   }
0049 };  // namespace
0050 
0051 struct ArchOpts {
0052   Int_t vumin;
0053   Int_t vumax;
0054 
0055   Int_t thmin;
0056   Int_t thmax;
0057 
0058   Double_t vutimemin;
0059   Double_t vutimemax;
0060 
0061   Double_t thtimemin;
0062   Double_t thtimemax;
0063 
0064   Double_t vuspeedupmin;
0065   Double_t vuspeedupmax;
0066 
0067   Double_t thspeedupmin;
0068   Double_t thspeedupmax;
0069 
0070   Double_t thmeiftimemin;
0071   Double_t thmeiftimemax;
0072 
0073   Double_t thmeifspeedupmin;
0074   Double_t thmeifspeedupmax;
0075 };
0076 
0077 namespace {
0078   ArchOpts arch_opt;
0079   void setupArch() {
0080     if (ARCH == SNB) {
0081       arch_opt.vumin = 1;
0082       arch_opt.vumax = 8;
0083 
0084       arch_opt.thmin = 1;
0085       arch_opt.thmax = 24;
0086 
0087       arch_opt.vutimemin = 0.;
0088       arch_opt.vutimemax = 0.5;
0089 
0090       arch_opt.thtimemin = 0.001;
0091       arch_opt.thtimemax = 1.;
0092 
0093       arch_opt.vuspeedupmin = 0.;
0094       arch_opt.vuspeedupmax = arch_opt.vumax;
0095 
0096       arch_opt.thspeedupmin = 0.;
0097       arch_opt.thspeedupmax = arch_opt.thmax;
0098 
0099       arch_opt.thmeiftimemin = 0.01;
0100       arch_opt.thmeiftimemax = 0.5;
0101 
0102       arch_opt.thmeifspeedupmin = 0.;
0103       arch_opt.thmeifspeedupmax = arch_opt.thmax;
0104     } else if (ARCH == KNL) {
0105       arch_opt.vumin = 1;
0106       arch_opt.vumax = 16;
0107 
0108       arch_opt.thmin = 1;
0109       arch_opt.thmax = 256;
0110 
0111       arch_opt.vutimemin = 0.;
0112       arch_opt.vutimemax = 1.5;
0113 
0114       arch_opt.thtimemin = 0.001;
0115       arch_opt.thtimemax = 1.;
0116 
0117       arch_opt.vuspeedupmin = 0.;
0118       arch_opt.vuspeedupmax = arch_opt.vumax;
0119 
0120       arch_opt.thspeedupmin = 0.;
0121       arch_opt.thspeedupmax = 80.;
0122 
0123       arch_opt.thmeiftimemin = 0.001;
0124       arch_opt.thmeiftimemax = arch_opt.thtimemax;
0125 
0126       arch_opt.thmeifspeedupmin = 0.;
0127       arch_opt.thmeifspeedupmax = arch_opt.thspeedupmax;
0128     } else if (ARCH == SKL) {
0129       arch_opt.vumin = 1;
0130       arch_opt.vumax = 16;
0131 
0132       arch_opt.thmin = 1;
0133       arch_opt.thmax = 64;
0134 
0135       arch_opt.vutimemin = 0.;
0136       arch_opt.vutimemax = 0.25;
0137 
0138       arch_opt.thtimemin = 0.0001;
0139       arch_opt.thtimemax = 1.;
0140 
0141       arch_opt.vuspeedupmin = 0.;
0142       arch_opt.vuspeedupmax = arch_opt.vumax;
0143 
0144       arch_opt.thspeedupmin = 0.;
0145       arch_opt.thspeedupmax = arch_opt.thmax / 2;
0146 
0147       arch_opt.thmeiftimemin = 0.001;
0148       arch_opt.thmeiftimemax = arch_opt.thtimemax;
0149 
0150       arch_opt.thmeifspeedupmin = 0.;
0151       arch_opt.thmeifspeedupmax = arch_opt.thspeedupmax;
0152     } else if (ARCH == LNXG) {
0153       arch_opt.vumin = 1;
0154       arch_opt.vumax = 16;
0155 
0156       arch_opt.thmin = 1;
0157       arch_opt.thmax = 64;
0158 
0159       arch_opt.vutimemin = 0.;
0160       arch_opt.vutimemax = 0.25;
0161 
0162       arch_opt.thtimemin = 0.0001;
0163       arch_opt.thtimemax = 1.;
0164 
0165       arch_opt.vuspeedupmin = 0.;
0166       arch_opt.vuspeedupmax = arch_opt.vumax;
0167 
0168       arch_opt.thspeedupmin = 0.;
0169       arch_opt.thspeedupmax = arch_opt.thmax / 2;
0170 
0171       arch_opt.thmeiftimemin = 0.001;
0172       arch_opt.thmeiftimemax = arch_opt.thtimemax;
0173 
0174       arch_opt.thmeifspeedupmin = 0.;
0175       arch_opt.thmeifspeedupmax = arch_opt.thspeedupmax;
0176     } else if (ARCH == LNXS) {
0177       arch_opt.vumin = 1;
0178       arch_opt.vumax = 16;
0179 
0180       arch_opt.thmin = 1;
0181       arch_opt.thmax = 64;
0182 
0183       arch_opt.vutimemin = 0.;
0184       arch_opt.vutimemax = 0.25;
0185 
0186       arch_opt.thtimemin = 0.0001;
0187       arch_opt.thtimemax = 1.;
0188 
0189       arch_opt.vuspeedupmin = 0.;
0190       arch_opt.vuspeedupmax = arch_opt.vumax;
0191 
0192       arch_opt.thspeedupmin = 0.;
0193       arch_opt.thspeedupmax = arch_opt.thmax / 2;
0194 
0195       arch_opt.thmeiftimemin = 0.001;
0196       arch_opt.thmeiftimemax = arch_opt.thtimemax;
0197 
0198       arch_opt.thmeifspeedupmin = 0.;
0199       arch_opt.thmeifspeedupmax = arch_opt.thspeedupmax;
0200     } else {
0201       std::cerr << "How did this happen?? You did not specify one of the allowed ARCHs!" << std::endl;
0202       exit(1);
0203     }
0204   }
0205 };  // namespace
0206 
0207 enum SuiteEnum { full, forPR, forConf, val };
0208 
0209 namespace {
0210   SuiteEnum SUITE;
0211   void setupSUITEEnum(const TString& suite) {
0212     if (suite.Contains("full"))
0213       SUITE = full;
0214     else if (suite.Contains("forPR"))
0215       SUITE = forPR;
0216     else if (suite.Contains("forConf"))
0217       SUITE = forConf;
0218     else if (suite.Contains("val"))
0219       SUITE = val;
0220     else {
0221       std::cerr << suite.Data() << " is not an allowed validation suite! Exiting... " << std::endl;
0222       exit(1);
0223     }
0224   }
0225 };  // namespace
0226 
0227 struct BuildOpts {
0228   BuildOpts() {}
0229   BuildOpts(const TString& name, const Color_t color, const TString& label) : name(name), color(color), label(label) {}
0230 
0231   TString name;
0232   Color_t color;
0233   TString label;
0234 };
0235 typedef std::vector<BuildOpts> BOVec;
0236 typedef std::map<TString, BuildOpts> BOMap;
0237 
0238 namespace {
0239   BOVec builds;
0240   UInt_t nbuilds;
0241   void setupBuilds(const Bool_t isBenchmark, const Bool_t includeCMSSW) {
0242     // tmp map to fill builds vector
0243     BOMap buildsMap;
0244     buildsMap["BH"] = {"BH", kBlue, "Best Hit"};
0245     buildsMap["STD"] = {"STD", kGreen + 1, "Standard"};
0246     buildsMap["CE"] = {"CE", kRed, "Clone Engine"};
0247     buildsMap["FV"] = {"FV", kMagenta, "Full Vector"};
0248     buildsMap["CMSSW"] = {"CMSSW", kBlack, "CMSSW"};
0249 
0250     // KPM: Consult ./xeon_scripts/common-variables.sh to match routines to suite
0251     if (SUITE == full) {
0252       builds.emplace_back(buildsMap["BH"]);
0253       builds.emplace_back(buildsMap["STD"]);
0254       builds.emplace_back(buildsMap["CE"]);
0255       builds.emplace_back(buildsMap["FV"]);
0256     } else if (SUITE == forPR) {
0257       if (isBenchmark) {
0258         builds.emplace_back(buildsMap["BH"]);
0259         builds.emplace_back(buildsMap["CE"]);
0260       } else {
0261         if (!gSystem->Getenv("MKFIT_MIMI"))  // MIMI does not support STD
0262           builds.emplace_back(buildsMap["STD"]);
0263         builds.emplace_back(buildsMap["CE"]);
0264       }
0265     } else if (SUITE == forConf) {
0266       builds.emplace_back(buildsMap["CE"]);
0267       builds.back().label = "mkFit";  // change label in legend for conference
0268     } else if (SUITE == val) {
0269       if (isBenchmark) {
0270         std::cout << "INFO: val mode has an empty set for isBenchmark" << std::endl;
0271       } else {
0272         builds.emplace_back(buildsMap["STD"]);
0273         builds.emplace_back(buildsMap["CE"]);
0274       }
0275     } else {
0276       std::cerr << "How did this happen?? You did not specify one of the allowed SUITEs!" << std::endl;
0277       exit(1);
0278     }
0279 
0280     // always check for adding in CMSSW --> never true for isBenchmark
0281     if (includeCMSSW)
0282       builds.emplace_back(buildsMap["CMSSW"]);
0283 
0284     // set nbuilds
0285     nbuilds = builds.size();
0286   }
0287 
0288 };  // namespace
0289 
0290 void GetMinMaxHist(const TH1F* hist, Double_t& min, Double_t& max) {
0291   for (auto ibin = 1; ibin <= hist->GetNbinsX(); ibin++) {
0292     const auto content = hist->GetBinContent(ibin);
0293 
0294     if (content < min && content != 0.0)
0295       min = content;
0296     if (content > max)
0297       max = content;
0298   }
0299 }
0300 
0301 void SetMinMaxHist(TH1F* hist, const Double_t min, const Double_t max, const Bool_t isLogy) {
0302   hist->SetMinimum(isLogy ? min / 2.0 : min / 1.05);
0303   hist->SetMaximum(isLogy ? max * 2.0 : max * 1.05);
0304 }
0305 
0306 #endif