4 #include "CAFAna/Core/Binning.h" 5 #include "CAFAna/Core/Var.h" 11 #include "TDirectory.h" 18 #include "TObjString.h" 19 #include "TParameter.h" 34 while((start_pos = ret.find(from, start_pos)) != std::string::npos) {
35 ret.replace(start_pos, from.length(), to);
36 start_pos += to.length();
52 const std::vector<const ISyst*>&
systs,
53 const std::map<std::string, SpectrumComponents::Component>& mcCategories)
56 fData(loaderData, tanAxis.fObj, fSel.fObj,
kNoShift),
57 fMC(fSel.fObj, tanAxis.fObj, loaderMC, wei, mcCategories),
58 fShortName(tanAxis.fShortName +
"_" + fSel.fShortName),
61 fUps.reserve(systs.size());
62 fDowns.reserve(systs.size());
63 for(
const auto& syst:systs){
75 const std::vector<const ISyst*>&
systs,
76 const std::map<std::string, SpectrumComponents::Component>& mcCategories)
78 loaderData, loaderMC, wei, systs, mcCategories)
113 std::vector<Spectrum> normUps;
114 std::vector<Spectrum> normDowns;
120 normDowns.reserve(1);
125 normUps.reserve(
fUps.size());
126 normDowns.reserve(
fUps.size());
128 for(
size_t i = 0;
i <
fUps.size(); ++
i)
131 if(iSyst >= 0 && (
int)
i != iSyst)
continue;
132 normUps.emplace_back(
fUps[
i]);
136 for(
size_t i = 0;
i <
fDowns.size(); ++
i)
139 if(iSyst >= 0 && (
int)
i != iSyst)
continue;
140 normDowns.emplace_back(
fDowns[
i]);
163 if (includeComponents)
169 TH1F* colMC =
new TH1F();
171 TH1F* colMCBkg =
new TH1F();
173 TH1F* colData =
new TH1F();
174 colData->SetLineColor(dataColor);
175 colData->SetMarkerColor(dataColor);
177 leg->AddEntry((TObject*)colData,
"Data",
"ple");
178 leg->AddEntry((TObject*)colMC, (includeComponents ?
"Total Simulation" :
"Simulation"),
"l");
180 if (includeComponents)
184 leg->SetFillColor(0);
185 leg->SetFillStyle(0);
187 for(
const auto& obj:*leg->GetListOfPrimitives())
189 if(obj->InheritsFrom(
"TAttFill")){
190 ((TAttFill*)obj)->SetFillStyle(0);
202 std::stringstream expo;
208 text.SetTextAlign(12);
210 text.DrawLatexNDC(0.2, 0.95, expo.str().c_str());
237 std::ofstream
table(fname);
239 "\\documentclass[12pt]{article}\n" 240 "\\usepackage{longtable}\n" 241 "\\begin{document}\n" 243 "\\begin{longtable}\n" 244 "{|p{0.4\\textwidth}|p{0.3\\textwidth}|p{0.3\\textwidth}|}\n" 246 "Parameter & $+1 \\sigma$ Mean & $-1 \\sigma$ Mean \\\\\n" 249 "\\multicolumn{3}{l}\n" 250 "{{\\bfseries\\tablename\\ \\thetable{} -- " 251 "continued from previous page}}\\\\\n" 253 "Parameter & $+1 \\sigma$ Mean & $-1 \\sigma$ Mean \\\\\n" 256 "\\hline \\hline \\multicolumn{3}{|r|}{{Continued on next page}}" 265 for(
size_t iSyst = 0; iSyst <
fSysts.size(); ++ iSyst)
268 float meanUp =
fUps[iSyst].Mean();
269 float meanDown =
fDowns[iSyst].Mean();
270 float percUp = 100 * (meanUp - meanNom)/meanNom;
271 float percDown = 100 * (meanDown - meanNom)/meanNom;
278 table <<
"\\end{longtable}\n\\end{document}" <<
std::endl;
284 TDirectory*
tmp = gDirectory;
286 dir = dir->mkdir(name.c_str());
293 TDirectory * upsDir = dir->mkdir(
"upShifts");
298 TDirectory * downsDir = dir->mkdir(
"downShifts");
317 dir = dir->GetDirectory(name.c_str());
323 std::map<std::string, std::vector<Spectrum>>
specs;
324 for (
const auto & shift : {
"up",
"down"})
326 TDirectory * shiftsDir =
dynamic_cast<TDirectory*
>(dir->Get(Form(
"%sShifts", shift)));
331 for ( TObject * obj : *(shiftsDir->GetListOfKeys()) )
333 TKey *
key =
dynamic_cast<TKey*
>(obj);
339 auto ret = std::make_unique<DataMCPair>(
342 std::move(specs[
"up"]),
343 std::move(specs[
"down"]),
344 dynamic_cast<TObjString*
>(dir->Get(
"shortName"))->String().Data()
349 return std::move(
ret);
TString TableNum(float num)
Format numbers for tables, with two nice digits after decimal.
Cuts and Vars for the 2020 FD DiF Study.
static std::unique_ptr< SpectrumComponents > LoadFrom(TDirectory *dir, const std::string &name)
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
void DrawMCSyst(const int iSyst=-1, EBinType bintype=kBinContent) const
Draw MC with error band.
Simple record of shifts applied to systematic parameters.
void OverridePOT(double newpot)
DO NOT USE UNLESS YOU ARE 110% CERTAIN THERE ISN'T A BETTER WAY!
void DrawMCNormSyst(const int iSyst=-1, EBinType bintype=kBinContent) const
Draw MC with error band, but with each syst normalized to total area of MC to highlight shape differe...
void SaveTo(TDirectory *dir, const std::string &name) const
TGraphAsymmErrors * PlotWithSystErrorBand(IPrediction *pred, const std::vector< const ISyst * > &systs, osc::IOscCalc *calc, double pot, int col, int errCol, float headroom, bool newaxis, EBinType bintype, double alpha)
Plot prediction with +/-1sigma error band.
void DrawMCComponents(bool stacked=true, EBinType bintype=kBinContent) const
Draw MC components distribution.
void OverlayDataMCSystNorm(const int iSyst=-1, bool drawMCBreakdown=true, EBinType bintype=kBinContent, bool drawLegend=true) const
Draw data and MC with error band, but with each syst normalized to total area of MC to highlight shap...
std::vector< Spectrum > fDowns
float Purity(const std::set< std::string > &signalCatNames={}) const
Purity of the MC selection based on the MC subcategories.
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
void SetComponentColor(const std::string &name, int color)
Representation of a spectrum in any variable, with associated POT.
const std::vector< const ISyst * > fSysts
const XML_Char const XML_Char * data
const Color_t kFullPredColor
DataMCPair(Selection sel, TangibleAxis tanAxis, SpectrumLoaderBase &loaderData, SpectrumLoaderBase &loaderMC, const Var &wei=kUnweighted, const std::vector< const ISyst * > &systs={}, const std::map< std::string, SpectrumComponents::Component > &mcCategories={})
DataMCPair wraps up spectrum creation for data/MC comparison
void DrawData(const int color=kBlack, EBinType bintype=kBinContent) const
Draw data on plots, mostly for internal use.
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
const Color_t kPredErrColor
void AddExposure() const
Write exposure on plots, used internally.
TLegend * DrawLegend(double drawThreshold=0, TLegend *leg=nullptr) const
Draw legend on plots.
const Color_t kTotalBkgColor
void DrawComponents(bool stacked=true, EBinType bintype=kBinContent, double POT=0, bool sameAll=true) const
Draw MC components distribution.
void SaveTo(TDirectory *dir, const std::string &name) const
float Purity(const std::set< std::string > &signalCatNames={}) const
Purity of the MC selection based on the MC subcategories.
void OverlayDataMCSyst(const int iSyst=-1, bool drawMCBreakdown=true, EBinType bintype=kBinContent, bool drawLegend=true) const
Draw data and MC with error band.
const SystShifts kNoShift
void CreateSystTable(const std::string &fname) const
Write LaTeX table of syst means: |par|mean up(%)|mean down(%)|.
Base class for the various types of spectrum loader.
static std::unique_ptr< DataMCPair > LoadFrom(TDirectory *dir, const std::string &name)
std::vector< Spectrum > fUps
TLegend * DrawLegend(const int dataColor=kBlack, bool includeComponents=true, double drawThreshold=-1) const
Draw legend on plots, mostly for internal use.
std::string replaceAll(const std::string &str, const std::string &from, const std::string &to)
assert(nhit_max >=nhit_nbins)
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
TLegend * AutoPlaceLegend(double dx, double dy, double yPin)
Create a legend, maximizing distance from all histograms.
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
std::string to_string(ModuleType mt)
void SetComponentBlurb(const std::string &name, const std::string &blurb)
const std::map< std::string, Component > & ComponentDescrs() const
void SaveTo(TDirectory *dir, const std::string &name) const
double Mean() const
Return mean of 1D histogram.