Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ana::DataMCPair Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CAFAna/Analysis/DataMCPair.h"

Public Member Functions

 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 More...
 
 DataMCPair (Cut cut, HistAxis axis, SpectrumLoaderBase &loaderData, SpectrumLoaderBase &loaderMC, const ana::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 This version simply takes a Cut and Var, leaving the ShortName and Blurb blank for both. More...
 
 DataMCPair (const Spectrum &data, const SpectrumComponents &MC, const std::vector< Spectrum > &ups, const std::vector< Spectrum > &downs, const std::string &shortName)
 Constructor from copies. More...
 
 DataMCPair (Spectrum &&data, SpectrumComponents &&MC, std::vector< Spectrum > &&ups, std::vector< Spectrum > &&downs, std::string shortName)
 Constructor for use in LoadFrom() More...
 
std::string ShortName () const
 
const char * CName () const
 
void DrawMCSyst (const int iSyst=-1, EBinType bintype=kBinContent) const
 Draw MC with error band. More...
 
void OverlayDataMCSyst (const int iSyst=-1, bool drawMCBreakdown=true, EBinType bintype=kBinContent, bool drawLegend=true) const
 Draw data and MC with error band. More...
 
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 differences. More...
 
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 shape differences. More...
 
TLegend * DrawLegend (const int dataColor=kBlack, bool includeComponents=true, double drawThreshold=-1) const
 Draw legend on plots, mostly for internal use. More...
 
void AddExposure () const
 Write exposure on plots, used internally. More...
 
void DrawData (const int color=kBlack, EBinType bintype=kBinContent) const
 Draw data on plots, mostly for internal use. More...
 
void DrawMCComponents (bool stacked=true, EBinType bintype=kBinContent) const
 Draw MC components distribution. More...
 
float Purity (const std::set< std::string > &signalCatNames={}) const
 Purity of the MC selection based on the MC subcategories. More...
 
void CreateSystTable (const std::string &fname) const
 Write LaTeX table of syst means: |par|mean up(%)|mean down(%)|. More...
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
unsigned int NDimensions () const
 
std::vector< std::stringGetLabels () const
 
std::vector< BinningGetBinnings () const
 
void SetComponentColor (const std::string &name, int color)
 
void SetComponentBlurb (const std::string &name, const std::string &blurb)
 

Static Public Member Functions

static std::unique_ptr< DataMCPairLoadFrom (TDirectory *dir, const std::string &name)
 

Public Attributes

Selection fSel
 
Spectrum fData
 
SpectrumComponents fMC
 
std::vector< SpectrumfUps
 
std::vector< SpectrumfDowns
 
std::string fShortName
 
const std::vector< const ISyst * > fSysts
 

Detailed Description

Definition at line 55 of file DataMCPair.h.

Constructor & Destructor Documentation

DataMCPair::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

Parameters
selSelection object (cut, blurb, name) for cuts
tanAxisTangibleAxis object (HistAxis, blurb, name)
loaderDataSpectrumLoader for data
loaderMCSpectrumLoader for MC
weiWeight to apply to events
systsstd::vector of ISyst* for drawing plots with syst bands
bkgCut object to define background

Definition at line 48 of file DataMCPair.cxx.

References fDowns, ana::Tangible< T >::fObj, fSel, and fUps.

54  :
55  fSel(sel),
56  fData(loaderData, tanAxis.fObj, fSel.fObj, kNoShift),
57  fMC(fSel.fObj, tanAxis.fObj, loaderMC, wei, mcCategories),
58  fShortName(tanAxis.fShortName + "_" + fSel.fShortName),
59  fSysts(systs)
60  {
61  fUps.reserve(systs.size());
62  fDowns.reserve(systs.size());
63  for(const auto& syst:systs){
64  fUps.emplace_back(loaderMC, tanAxis.fObj, fSel.fObj, SystShifts(syst,+1), wei);
65  fDowns.emplace_back(loaderMC, tanAxis.fObj, fSel.fObj, SystShifts(syst,-1), wei);
66  }
67  }
std::string fShortName
Definition: DataMCPair.h:187
Spectrum fData
Definition: DataMCPair.h:183
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
std::string fShortName
Definition: DataMCPair.h:47
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
const std::vector< const ISyst * > fSysts
Definition: DataMCPair.h:188
const SystShifts kNoShift
Definition: SystShifts.cxx:22
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
std::string fShortName
Selection fSel
Definition: DataMCPair.h:182
SpectrumComponents fMC
Definition: DataMCPair.h:184
DataMCPair::DataMCPair ( Cut  cut,
HistAxis  axis,
SpectrumLoaderBase loaderData,
SpectrumLoaderBase loaderMC,
const ana::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 This version simply takes a Cut and Var, leaving the ShortName and Blurb blank for both.

Parameters
cutCut object to define selection
axisHistAxis object to set up histograms
loaderDataSpectrumLoader for data
loaderMCSpectrumLoader for MC
weiWeight to apply to events
systsstd::vector of ISyst* for drawing plots with syst bands
bkgCut object to define background

Definition at line 71 of file DataMCPair.cxx.

77  : DataMCPair(Selection(cut, "", ""), TangibleAxis(axis, "", ""),
78  loaderData, loaderMC, wei, systs, mcCategories)
79  {
80  }
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
Tangible< Cut > Selection
Definition: DataMCPair.h:52
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
Definition: DataMCPair.cxx:48
Tangible< HistAxis > TangibleAxis
Definition: DataMCPair.h:53
const Cut cut
Definition: exporter_fd.C:30
ana::DataMCPair::DataMCPair ( const Spectrum data,
const SpectrumComponents MC,
const std::vector< Spectrum > &  ups,
const std::vector< Spectrum > &  downs,
const std::string shortName 
)
inline

Constructor from copies.

Definition at line 92 of file DataMCPair.h.

97  : fSel(kNoCut, "", ""),
98  fData(data), fMC(MC),
99  fUps(ups), fDowns(downs),
101  {}
std::string fShortName
Definition: DataMCPair.h:187
Spectrum fData
Definition: DataMCPair.h:183
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
const XML_Char const XML_Char * data
Definition: expat.h:268
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
Selection fSel
Definition: DataMCPair.h:182
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
SpectrumComponents fMC
Definition: DataMCPair.h:184
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
ana::DataMCPair::DataMCPair ( Spectrum &&  data,
SpectrumComponents &&  MC,
std::vector< Spectrum > &&  ups,
std::vector< Spectrum > &&  downs,
std::string  shortName 
)
inline

Constructor for use in LoadFrom()

Definition at line 104 of file DataMCPair.h.

109  : fSel(kNoCut, "", ""),
110  fData(data), fMC(MC),
111  fUps(ups), fDowns(downs),
113  {}
std::string fShortName
Definition: DataMCPair.h:187
Spectrum fData
Definition: DataMCPair.h:183
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
const XML_Char const XML_Char * data
Definition: expat.h:268
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
Selection fSel
Definition: DataMCPair.h:182
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
SpectrumComponents fMC
Definition: DataMCPair.h:184
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109

Member Function Documentation

void DataMCPair::AddExposure ( ) const

Write exposure on plots, used internally.

Definition at line 200 of file DataMCPair.cxx.

References fData, genie::utils::style::Format(), pot, ana::Spectrum::POT(), and MakeMiniprodValidationCuts::text.

201  {
202  std::stringstream expo;
203  float pot = fData.POT();
204  expo.precision(2);
205  expo << "ND, "
206  << TString::Format("%.02lf#times10^{20}", pot/1e20) << " POT";
207  TLatex text;
208  text.SetTextAlign(12);
209 
210  text.DrawLatexNDC(0.2, 0.95, expo.str().c_str());
211  }
Spectrum fData
Definition: DataMCPair.h:183
#define pot
double POT() const
Definition: Spectrum.h:227
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const char* ana::DataMCPair::CName ( ) const
inline
void DataMCPair::CreateSystTable ( const std::string fname) const

Write LaTeX table of syst means: |par|mean up(%)|mean down(%)|.

/param fname Path where output file will be written

Definition at line 234 of file DataMCPair.cxx.

References allTimeWatchdog::endl, fDowns, fMC, fShortName, fSysts, fUps, ana::Spectrum::Mean(), ana::replaceAll(), getGoodRuns4SAM::table, ana::TableNum(), and ana::SpectrumComponents::Tot().

235  {
236 
237  std::ofstream table(fname);
238  table <<
239  "\\documentclass[12pt]{article}\n"
240  "\\usepackage{longtable}\n"
241  "\\begin{document}\n"
242  << fShortName <<
243  "\\begin{longtable}\n"
244  "{|p{0.4\\textwidth}|p{0.3\\textwidth}|p{0.3\\textwidth}|}\n"
245  "\\hline\n"
246  "Parameter & $+1 \\sigma$ Mean & $-1 \\sigma$ Mean \\\\\n"
247  "\\hline \\hline\n"
248  "\\endfirsthead\n"
249  "\\multicolumn{3}{l}\n"
250  "{{\\bfseries\\tablename\\ \\thetable{} -- "
251  "continued from previous page}}\\\\\n"
252  "\\hline\n"
253  "Parameter & $+1 \\sigma$ Mean & $-1 \\sigma$ Mean \\\\\n"
254  "\\hline \\hline\n"
255  "\\endhead\n"
256  "\\hline \\hline \\multicolumn{3}{|r|}{{Continued on next page}}"
257  " \\\\ \\hline\n"
258  "\\endfoot\n"
259  "\\hline\n"
260  "\\endlastfoot\n"
261  "\\hline\n"
262  << std::endl;
263 
264  float meanNom = fMC.Tot().Mean();
265  for(size_t iSyst = 0; iSyst < fSysts.size(); ++ iSyst)
266  {
267 
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;
272 
273  table << replaceAll(fSysts[iSyst]->LatexName(), "_", "\\_") << " & "
274  << TableNum(meanUp) << " (" << TableNum(percUp) << "\\%) &"
275  << TableNum(meanDown) << " (" << TableNum(percDown) << "\\%) "
276  << " \\\\ \\hline" << std::endl;
277  }
278  table << "\\end{longtable}\n\\end{document}" << std::endl;
279  }
TString TableNum(float num)
Format numbers for tables, with two nice digits after decimal.
Definition: DataMCPair.cxx:42
std::string fShortName
Definition: DataMCPair.h:187
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
const std::vector< const ISyst * > fSysts
Definition: DataMCPair.h:188
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
std::string replaceAll(const std::string &str, const std::string &from, const std::string &to)
Definition: DataMCPair.cxx:27
SpectrumComponents fMC
Definition: DataMCPair.h:184
double Mean() const
Return mean of 1D histogram.
Definition: Spectrum.cxx:267
void DataMCPair::DrawData ( const int  color = kBlack,
EBinType  bintype = kBinContent 
) const

Draw data on plots, mostly for internal use.

Parameters
colorcolor of data for legend points

Definition at line 214 of file DataMCPair.cxx.

References plot_validation_datamc_2018::color, fData, ana::kPOT, ana::Spectrum::POT(), and ana::Spectrum::ToTH1().

Referenced by OverlayDataMCSyst(), DataMCPair::OverlayDataMCSystExtraData(), OverlayDataMCSystNorm(), and DataMCPair::OverlayDataMCSystNormExtraData().

215  {
216  TH1D* hData = fData.ToTH1(fData.POT(), color, kFullCircle, kPOT, bintype);
217 
218  hData->Draw("SAME");
219  }
Spectrum fData
Definition: DataMCPair.h:183
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.
Definition: Spectrum.cxx:148
double POT() const
Definition: Spectrum.h:227
TLegend * DataMCPair::DrawLegend ( const int  dataColor = kBlack,
bool  includeComponents = true,
double  drawThreshold = -1 
) const

Draw legend on plots, mostly for internal use.

Parameters
includeComponentsAdd legend entries for MC subcomponents?
drawThresholdOnly draw MC components that are larger than this fraction of the total MC

Definition at line 160 of file DataMCPair.cxx.

References ana::AutoPlaceLegend(), ana::SpectrumComponents::ComponentDescrs(), ana::SpectrumComponents::DrawLegend(), fMC, ana::kFullPredColor, ana::kTotalBkgColor, and MECModelEnuComparisons::leg.

Referenced by OverlayDataMCSyst(), and OverlayDataMCSystNorm().

161  {
162  TLegend* leg;
163  if (includeComponents)
164  // needs to be a bit smaller if components included
165  leg = AutoPlaceLegend(0.25, 0.18 + 0.04*fMC.ComponentDescrs().size());
166  else
167  leg = AutoPlaceLegend(0.36, 0.18, 0.67);
168  //TLegend* leg = new TLegend(0.6, 0.7, 0.85, 0.85);
169  TH1F* colMC = new TH1F();
170  colMC->SetLineColor(kFullPredColor);
171  TH1F* colMCBkg = new TH1F();
172  colMCBkg->SetLineColor(kTotalBkgColor);
173  TH1F* colData = new TH1F();
174  colData->SetLineColor(dataColor);
175  colData->SetMarkerColor(dataColor);
176 
177  leg->AddEntry((TObject*)colData, "Data", "ple");
178  leg->AddEntry((TObject*)colMC, (includeComponents ? "Total Simulation" : "Simulation"), "l");
179 
180  if (includeComponents)
181  fMC.DrawLegend(drawThreshold, leg);
182 
183 
184  leg->SetFillColor(0);
185  leg->SetFillStyle(0);
186 
187  for(const auto& obj:*leg->GetListOfPrimitives())
188  {
189  if(obj->InheritsFrom("TAttFill")){
190  ((TAttFill*)obj)->SetFillStyle(0);
191  //((TAttFill*)obj)->SetFillColor(0);
192  }
193 
194  }
195  leg->Draw();
196  return leg;
197  }
const Color_t kFullPredColor
Definition: Style.h:36
TLegend * DrawLegend(double drawThreshold=0, TLegend *leg=nullptr) const
Draw legend on plots.
const Color_t kTotalBkgColor
Definition: Style.h:39
TLegend * AutoPlaceLegend(double dx, double dy, double yPin)
Create a legend, maximizing distance from all histograms.
Definition: Plots.cxx:715
SpectrumComponents fMC
Definition: DataMCPair.h:184
const std::map< std::string, Component > & ComponentDescrs() const
void DataMCPair::DrawMCComponents ( bool  stacked = true,
EBinType  bintype = kBinContent 
) const

Draw MC components distribution.

Parameters
stackBy default components will be shown stacked. Pass false to show them unstacked instead.

Definition at line 222 of file DataMCPair.cxx.

References ana::SpectrumComponents::DrawComponents(), fData, fMC, and ana::Spectrum::POT().

Referenced by OverlayDataMCSyst(), and OverlayDataMCSystNorm().

223  {
224  fMC.DrawComponents(stacked, bintype, fData.POT());
225  }
Spectrum fData
Definition: DataMCPair.h:183
void DrawComponents(bool stacked=true, EBinType bintype=kBinContent, double POT=0, bool sameAll=true) const
Draw MC components distribution.
double POT() const
Definition: Spectrum.h:227
SpectrumComponents fMC
Definition: DataMCPair.h:184
void DataMCPair::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 differences.

Parameters
iSystindex of syst in the syst vector

Definition at line 110 of file DataMCPair.cxx.

References fData, fDowns, fMC, fUps, MECModelEnuComparisons::i, ana::Spectrum::Integral(), ana::kFullPredColor, ana::kPredErrColor, norm, ana::Spectrum::OverridePOT(), ana::PlotWithSystErrorBand(), ana::Spectrum::POT(), and ana::SpectrumComponents::Tot().

Referenced by OverlayDataMCSystNorm().

111  {
112  // New vectors for area normalized systs
113  std::vector<Spectrum> normUps;
114  std::vector<Spectrum> normDowns;
115 
116  if (iSyst >= 0)
117  {
118  // We'll have one entry if there's just one syst to plot.
119  normUps.reserve(1);
120  normDowns.reserve(1);
121  }
122  else
123  {
124  // Otherwise we need all systs.
125  normUps.reserve(fUps.size());
126  normDowns.reserve(fUps.size());
127  }
128  for(size_t i = 0; i < fUps.size(); ++i)
129  {
130  // bail if we want a particular syst and it's not the one we want.
131  if(iSyst >= 0 && (int)i != iSyst) continue;
132  normUps.emplace_back(fUps[i]);
133  Spectrum& norm = normUps.back();
134  norm.OverridePOT(norm.POT() * norm.Integral(1) / fMC.Tot().Integral(1));
135  }
136  for(size_t i = 0; i < fDowns.size(); ++i)
137  {
138  // bail if we want a particular syst and it's not the one we want.
139  if(iSyst >= 0 && (int)i != iSyst) continue;
140  normDowns.emplace_back(fDowns[i]);
141  Spectrum& norm = normDowns.back();
142  norm.OverridePOT(norm.POT() * norm.Integral(1) / fMC.Tot().Integral(1));
143  }
144  PlotWithSystErrorBand(fMC.Tot(), normUps, normDowns, fData.POT(),
145  kFullPredColor, kPredErrColor, 1.5,true, bintype);
146  }
Spectrum fData
Definition: DataMCPair.h:183
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
Definition: Spectrum.cxx:249
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)
Plot prediction with +/-1sigma error band.
Definition: Plots.cxx:304
const Color_t kFullPredColor
Definition: Style.h:36
const Color_t kPredErrColor
Definition: Style.h:37
std::vector< float > Spectrum
Definition: Constants.h:610
double POT() const
Definition: Spectrum.h:227
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
Float_t norm
SpectrumComponents fMC
Definition: DataMCPair.h:184
void DataMCPair::DrawMCSyst ( const int  iSyst = -1,
EBinType  bintype = kBinContent 
) const

Draw MC with error band.

Parameters
iSystindex of syst in the syst vector

Definition at line 84 of file DataMCPair.cxx.

References ana::assert(), fData, fDowns, fMC, fUps, ana::kFullPredColor, ana::kPredErrColor, ana::PlotWithSystErrorBand(), ana::Spectrum::POT(), and ana::SpectrumComponents::Tot().

Referenced by OverlayDataMCSyst().

85  {
86 
87  if(iSyst < 0)
89  kFullPredColor, kPredErrColor, 1.5, true, bintype);
90  else
91  {
92  assert(iSyst < (int)fUps.size());
93  PlotWithSystErrorBand(fMC.Tot(), {fUps[iSyst]}, {fDowns[iSyst]}, fData.POT(),
94  kFullPredColor, kPredErrColor, 1.5, true, bintype);
95  }
96  }
Spectrum fData
Definition: DataMCPair.h:183
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
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)
Plot prediction with +/-1sigma error band.
Definition: Plots.cxx:304
const Color_t kFullPredColor
Definition: Style.h:36
const Color_t kPredErrColor
Definition: Style.h:37
double POT() const
Definition: Spectrum.h:227
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
assert(nhit_max >=nhit_nbins)
SpectrumComponents fMC
Definition: DataMCPair.h:184
std::vector<Binning> ana::DataMCPair::GetBinnings ( ) const
inline

Definition at line 177 of file DataMCPair.h.

References plot_validation_datamc_2018::color, and string.

177 { return fMC.GetBinnings(); }
std::vector< Binning > GetBinnings() const
SpectrumComponents fMC
Definition: DataMCPair.h:184
std::vector<std::string> ana::DataMCPair::GetLabels ( ) const
inline

Definition at line 176 of file DataMCPair.h.

176 { return fMC.GetLabels(); }
std::vector< std::string > GetLabels() const
SpectrumComponents fMC
Definition: DataMCPair.h:184
std::unique_ptr< DataMCPair > DataMCPair::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 315 of file DataMCPair.cxx.

References ana::assert(), dir, findDuplicateFiles::key, ana::SpectrumComponents::LoadFrom(), ana::Spectrum::LoadFrom(), mc, runNovaSAM::release, runNovaSAM::ret, and PandAna.Demos.tute_pid_validation::specs.

Referenced by plot_ND_DataMC().

316  {
317  dir = dir->GetDirectory(name.c_str()); // switch to subdir
318  assert(dir);
319 
320  Spectrum data = *Spectrum::LoadFrom(dir, "data");
321  SpectrumComponents mc = *SpectrumComponents::LoadFrom(dir, "MC");
322 
323  std::map<std::string, std::vector<Spectrum>> specs;
324  for (const auto & shift : {"up", "down"})
325  {
326  TDirectory * shiftsDir = dynamic_cast<TDirectory*>(dir->Get(Form("%sShifts", shift)));
327  // maybe there weren't any shifts, and a hadd didn't create the empty dir?
328  if (!shiftsDir)
329  continue;
330 
331  for ( TObject * obj : *(shiftsDir->GetListOfKeys()) )
332  {
333  TKey * key = dynamic_cast<TKey*>(obj);
334 
335  // pray that they're read out in the same order they went in
336  specs[shift].emplace_back( *(Spectrum::LoadFrom(shiftsDir, key->GetName()).release()) );
337  }
338  }
339  auto ret = std::make_unique<DataMCPair>(
340  std::move(data),
341  std::move(mc),
342  std::move(specs["up"]),
343  std::move(specs["down"]),
344  dynamic_cast<TObjString*>(dir->Get("shortName"))->String().Data()
345  );
346 
347  delete dir;
348 
349  return std::move(ret);
350  }
const XML_Char * name
Definition: expat.h:151
static std::unique_ptr< SpectrumComponents > LoadFrom(TDirectory *dir, const std::string &name)
const XML_Char const XML_Char * data
Definition: expat.h:268
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
std::vector< float > Spectrum
Definition: Constants.h:610
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
unsigned int ana::DataMCPair::NDimensions ( ) const
inline

Definition at line 175 of file DataMCPair.h.

175 { return fMC.NDimensions(); }
unsigned int NDimensions() const
SpectrumComponents fMC
Definition: DataMCPair.h:184
void DataMCPair::OverlayDataMCSyst ( const int  iSyst = -1,
bool  drawMCBreakdown = true,
EBinType  bintype = kBinContent,
bool  drawLegend = true 
) const

Draw data and MC with error band.

Parameters
iSystindex of syst in the syst vector

Definition at line 99 of file DataMCPair.cxx.

References DrawData(), DrawLegend(), DrawMCComponents(), and DrawMCSyst().

100  {
101  DrawMCSyst(iSyst, bintype);
102  if (drawMCBreakdown)
103  DrawMCComponents(true, bintype);
104  DrawData(kBlack, bintype);
105  if (drawLegend)
106  DrawLegend();
107  }
void DrawMCSyst(const int iSyst=-1, EBinType bintype=kBinContent) const
Draw MC with error band.
Definition: DataMCPair.cxx:84
void DrawMCComponents(bool stacked=true, EBinType bintype=kBinContent) const
Draw MC components distribution.
Definition: DataMCPair.cxx:222
void DrawData(const int color=kBlack, EBinType bintype=kBinContent) const
Draw data on plots, mostly for internal use.
Definition: DataMCPair.cxx:214
TLegend * DrawLegend(const int dataColor=kBlack, bool includeComponents=true, double drawThreshold=-1) const
Draw legend on plots, mostly for internal use.
Definition: DataMCPair.cxx:160
void DataMCPair::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 shape differences.

Parameters
iSystindex of syst in the syst vector

Definition at line 149 of file DataMCPair.cxx.

References DrawData(), DrawLegend(), DrawMCComponents(), and DrawMCNormSyst().

150  {
151  DrawMCNormSyst(iSyst, bintype);
152  if (drawMCBreakdown)
153  DrawMCComponents(true, bintype);
154  DrawData(kBlack, bintype);
155  if (drawLegend)
156  DrawLegend();
157  }
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...
Definition: DataMCPair.cxx:110
void DrawMCComponents(bool stacked=true, EBinType bintype=kBinContent) const
Draw MC components distribution.
Definition: DataMCPair.cxx:222
void DrawData(const int color=kBlack, EBinType bintype=kBinContent) const
Draw data on plots, mostly for internal use.
Definition: DataMCPair.cxx:214
TLegend * DrawLegend(const int dataColor=kBlack, bool includeComponents=true, double drawThreshold=-1) const
Draw legend on plots, mostly for internal use.
Definition: DataMCPair.cxx:160
float DataMCPair::Purity ( const std::set< std::string > &  signalCatNames = {}) const

Purity of the MC selection based on the MC subcategories.

Parameters
signalCatNamesIf any of your subcategories are "signal", pass them here to avoid counting them as background

Definition at line 228 of file DataMCPair.cxx.

References fMC, and ana::SpectrumComponents::Purity().

229  {
230  return fMC.Purity(signalCatNames);
231  }
float Purity(const std::set< std::string > &signalCatNames={}) const
Purity of the MC selection based on the MC subcategories.
SpectrumComponents fMC
Definition: DataMCPair.h:184
void DataMCPair::SaveTo ( TDirectory *  dir,
const std::string name 
) const

Definition at line 282 of file DataMCPair.cxx.

References dir, fData, fDowns, fMC, fShortName, fUps, compare_h5_caf::idx, ana::SpectrumComponents::SaveTo(), ana::Spectrum::SaveTo(), galleryMaker::shortName, tmp, and art::to_string().

Referenced by ND_DataMC().

283  {
284  TDirectory* tmp = gDirectory;
285 
286  dir = dir->mkdir(name.c_str()); // switch to subdir
287  dir->cd();
288 
289  fData.SaveTo(dir, "data");
290 
291  fMC.SaveTo(dir, "MC");
292 
293  TDirectory * upsDir = dir->mkdir("upShifts");
294  for (std::size_t idx = 0; idx < fUps.size(); idx++)
295  {
296  fUps[idx].SaveTo(upsDir, std::to_string(idx));
297  }
298  TDirectory * downsDir = dir->mkdir("downShifts");
299  for (std::size_t idx = 0; idx < fDowns.size(); idx++)
300  {
301  fDowns[idx].SaveTo(downsDir, std::to_string(idx));
302  }
303 
304  dir->cd();
305  TObjString shortName(fShortName.c_str());
306  shortName.Write("shortName");
307 
308  dir->Write();
309  delete dir;
310 
311  tmp->cd();
312  }
const XML_Char * name
Definition: expat.h:151
std::string fShortName
Definition: DataMCPair.h:187
Spectrum fData
Definition: DataMCPair.h:183
std::vector< Spectrum > fDowns
Definition: DataMCPair.h:186
Float_t tmp
Definition: plot.C:36
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
std::vector< Spectrum > fUps
Definition: DataMCPair.h:185
TDirectory * dir
Definition: macro.C:5
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
SpectrumComponents fMC
Definition: DataMCPair.h:184
void SaveTo(TDirectory *dir, const std::string &name) const
void DataMCPair::SetComponentBlurb ( const std::string name,
const std::string blurb 
)

Definition at line 363 of file DataMCPair.cxx.

References ana::assert(), ana::SpectrumComponents::ComponentDescrs(), and fMC.

364  {
365  assert (fMC.ComponentDescrs().find(name) != fMC.ComponentDescrs().end());
366 
367  fMC.ComponentDescrs().at(name).blurb = blurb;
368 
369  }
const XML_Char * name
Definition: expat.h:151
assert(nhit_max >=nhit_nbins)
SpectrumComponents fMC
Definition: DataMCPair.h:184
const std::map< std::string, Component > & ComponentDescrs() const
void DataMCPair::SetComponentColor ( const std::string name,
int  color 
)

Definition at line 354 of file DataMCPair.cxx.

References ana::assert(), plot_validation_datamc_2018::color, ana::SpectrumComponents::ComponentDescrs(), and fMC.

355  {
356  assert (fMC.ComponentDescrs().find(name) != fMC.ComponentDescrs().end());
357 
358  fMC.ComponentDescrs().at(name).color = color;
359  }
const XML_Char * name
Definition: expat.h:151
assert(nhit_max >=nhit_nbins)
SpectrumComponents fMC
Definition: DataMCPair.h:184
const std::map< std::string, Component > & ComponentDescrs() const
std::string ana::DataMCPair::ShortName ( ) const
inline

Definition at line 115 of file DataMCPair.h.

References ana::Tangible< T >::fShortName.

116  {return fShortName;};
std::string fShortName
Definition: DataMCPair.h:187

Member Data Documentation

Spectrum DataMCPair::fData
std::vector< Spectrum > DataMCPair::fDowns

Definition at line 186 of file DataMCPair.h.

Referenced by CreateSystTable(), DataMCPair(), DrawMCNormSyst(), DrawMCSyst(), and SaveTo().

Spectrum DataMCPair::fMC
Selection DataMCPair::fSel

Definition at line 182 of file DataMCPair.h.

Referenced by DataMCPair(), and WriteBlurb().

std::string DataMCPair::fShortName

Definition at line 187 of file DataMCPair.h.

Referenced by CreateSystTable(), and SaveTo().

const std::vector<const ISyst*> ana::DataMCPair::fSysts

Definition at line 188 of file DataMCPair.h.

Referenced by CreateSystTable().

std::vector< Spectrum > DataMCPair::fUps

Definition at line 185 of file DataMCPair.h.

Referenced by CreateSystTable(), DataMCPair(), DrawMCNormSyst(), DrawMCSyst(), and SaveTo().


The documentation for this class was generated from the following files: