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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-28/NuXAna/Analysis/SystMaker.h"

Inheritance diagram for ana::SystMakerShift:
ana::SystMakerLoaderShift ana::SystMakerSystShift ana::SystMakerWeightShift

Public Member Functions

 SystMakerShift (std::string name, std::string label)
 
virtual ~SystMakerShift ()
 Default destructor. More...
 
std::string GetName ()
 
std::string GetLabel ()
 
std::vector< intGetSigmas ()
 
void PrintShift (std::ostream &os=std::cout)
 
bool CheckShifts ()
 
TCanvas * DrawSig (TH1 *nominal)
 
TCanvas * DrawBkg (TH1 *nominal)
 
void DrawShift (TDirectory *outDir, std::pair< TH1 *, TH1 * > &nominal)
 
std::string WriteTable (std::pair< TH1 *, TH1 * > nominal, std::string name)
 
std::pair< TH1 *, TH1 * > GetShiftedSpectrum (int sigma)
 
void ProcessShift (std::pair< TH1 *, TH1 * > &nominal_spectrum, const covmx::Sample sample, osc::IOscCalc *calc)
 
virtual void MakePredictions (SystPredType predType, const HistAxis *axis, const HistAxis *numuAxis, const Cut *fd_cut, const Cut *nd_cut, const Cut *numu_cut, const Var *weight, Loaders *loaders)
 Base class implementation of MakePredictions, which just throws an error. More...
 
void SaveTo (TDirectory *dir) const
 SaveTo implementation for SystMakerShift. More...
 

Static Public Member Functions

static std::unique_ptr< SystMakerShiftLoadFrom (TDirectory *dir)
 LoadFrom implementation for SystMakerShift. More...
 

Protected Attributes

std::string fName
 
std::string fLabel
 
std::map< int, SystMakerShiftSigma * > fSigmas
 

Detailed Description

Definition at line 93 of file SystMaker.h.

Constructor & Destructor Documentation

ana::SystMakerShift::SystMakerShift ( std::string  name,
std::string  label 
)

Definition at line 240 of file SystMaker.cxx.

240  :
241  fName(name),
242  fLabel(label)
243  {}
const XML_Char * name
Definition: expat.h:151
const char * label
std::string fName
Definition: SystMaker.h:126
std::string fLabel
Definition: SystMaker.h:127
ana::SystMakerShift::~SystMakerShift ( )
virtual

Default destructor.

Definition at line 247 of file SystMaker.cxx.

References fSigmas.

248  {
249  for (auto sigma : fSigmas) {
250  if (sigma.second) delete sigma.second;
251  }
252  }
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
double sigma(TH1F *hist, double percentile)

Member Function Documentation

bool ana::SystMakerShift::CheckShifts ( )

Definition at line 271 of file SystMaker.cxx.

References fSigmas, and update_sam_good_runs_metadata::good.

271  {
272  // Require -1, +1 shifts
273  bool good = true;
274  if (!fSigmas.count(-1) or !fSigmas.count(+1))
275  good = false;
276  return good;
277  }
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
TCanvas * ana::SystMakerShift::DrawBkg ( TH1 *  nominal)

Definition at line 365 of file SystMaker.cxx.

References abs(), bin, canv, stan::math::fabs(), fSigmas, MECModelEnuComparisons::i, it, MECModelEnuComparisons::leg, sigma(), and febshutoff_auto::val.

365  {
366 
367  // Drawing tools ------------
368  TCanvas* canv = new TCanvas("canv", "", 800, 800);
369  TPad* padSpecBkgTotal = new TPad("padSpecBkgTotal", "", 0., 0.375, 1., 1.);
370  TPad* padRatioBkgTotal = new TPad("padRatioBkgTotal", "", 0., 0., 1., 0.375);
371  TLegend* leg = new TLegend(0.5, 0.5, 0.88, 0.88);
372  map<int, TLegendEntry*> legEntries;
373 
374  // Draw nominal ------------
375  TH1* hNom = (TH1*)nominal->Clone("hNom");
376  for (size_t bin = 1; bin <= size_t(hNom->GetNbinsX()); ++bin)
377  hNom->SetBinContent(bin, hNom->GetBinContent(bin)/hNom->GetBinWidth(bin));
378  hNom->GetYaxis()->SetTitle("Events / GeV");
379  nominal->SetLineStyle(kSolid);
380  nominal->SetLineColor(kBlack);
381  nominal->SetLineWidth(2);
382  padSpecBkgTotal->cd();
383  nominal->Draw("hist");
384 
385  // ratio
386  TH1* nomRatio = (TH1*)nominal->Clone("nomRatio");
387  nomRatio->GetYaxis()->SetTitle("Shifted / Nominal");
388  for (Int_t bin = 0; bin <= nomRatio->GetNbinsX(); ++bin)
389  nomRatio->SetBinContent(bin, 1.);
390  padRatioBkgTotal->cd();
391  nomRatio->Draw("hist");
392  legEntries[0] = new TLegendEntry(nominal, "Nominal", "l");
393  double ymaxRatio = 0;
394 
395  // Draw shifts ------------
396  int it = 0;
397  for (map<int, SystMakerShiftSigma*>::const_iterator sigma = fSigmas.begin();
398  sigma != fSigmas.end(); ++sigma, ++it) {
399  if (sigma->second->fSigma == 0)
400  continue;
401  // Total ------------
402  TH1* sigmaBkg = (TH1*)sigma->second->fShiftedSpectrum.second->Clone();
403  for (size_t bin = 1; bin <= size_t(sigmaBkg->GetNbinsX()); ++bin)
404  sigmaBkg->SetBinContent(bin, sigmaBkg->GetBinContent(bin)/sigmaBkg->GetBinWidth(bin));
405  sigmaBkg->GetYaxis()->SetTitle("Events / GeV");
406  sigmaBkg->SetLineStyle(kDashed);
407  sigmaBkg->SetLineColor(abs(sigma->second->fSigma)+1);
408  sigmaBkg->SetLineWidth(2);
409  padSpecBkgTotal->cd();
410  sigmaBkg->DrawClone("hist same");
411  TH1* sigmaRatioBkg = (TH1*)sigmaBkg->Clone("sigmaRatioBkg");
412  sigmaRatioBkg->Divide(hNom);
413  sigmaRatioBkg->SetBinContent(0, 1);
414  for (size_t i = 1; i <= (size_t)sigmaRatioBkg->GetNbinsX(); ++i) {
415  double val = sigmaRatioBkg->GetBinContent(i);
416  if (val == 0) {
417  sigmaRatioBkg->SetBinContent(i, 1);
418  val = 1;
419  }
420  if (fabs(val-1) > ymaxRatio)
421  ymaxRatio = fabs(val-1);
422  }
423  padRatioBkgTotal->cd();
424  sigmaRatioBkg->DrawClone("hist same");
425  legEntries[abs(sigma->second->fSigma)]
426  = new TLegendEntry(sigmaBkg->Clone(), Form("+/-%d#sigma",
427  sigma->second->fSigma), "l");
428  }
429 
430  // Draw legend ------------
431  for (const auto& legEntry : legEntries)
432  leg->AddEntry(legEntry.second->GetObject(),
433  legEntry.second->GetLabel(),
434  legEntry.second->GetOption());
435  padSpecBkgTotal->cd();
436  leg->Draw();
437 
438  nomRatio->SetMinimum(1-(1.1*ymaxRatio));
439  nomRatio->SetMaximum(1+(1.1*ymaxRatio));
440 
441  // Draw all together ------------
442  canv->cd();
443  canv->Clear();
444  padSpecBkgTotal->Draw();
445  padRatioBkgTotal->Draw();
446 
447  return canv;
448 
449  } // function SystMakerShift::DrawBkg
set< int >::iterator it
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
TCanvas * canv
void abs(TH1 *hist)
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
void ana::SystMakerShift::DrawShift ( TDirectory *  outDir,
std::pair< TH1 *, TH1 * > &  nominal 
)

Definition at line 452 of file SystMaker.cxx.

References abs(), bin, canv, fName, fSigmas, it, kRed, MECModelEnuComparisons::leg, and sigma().

452  {
453 
454  // Out directories ------------
455  string dirSigShift = Form("Signal/Shifts/%s", fName.c_str());
456  string dirBkgShift = Form("Background/Shifts/%s", fName.c_str());
457  string dirSigShift_sigmas = dirSigShift+"/Sigmas/";
458  string dirBkgShiftSigmas = dirBkgShift+"/Sigmas/";
459  outDir->mkdir(dirSigShift.c_str());
460  outDir->mkdir(dirBkgShift.c_str());
461  outDir->mkdir(dirSigShift_sigmas.c_str());
462  outDir->mkdir(dirBkgShiftSigmas.c_str());
463 
464  // Drawing tools ------------
465  TCanvas* canv = new TCanvas("canv", "", 800, 800);
466  TPad* padSpecSig = new TPad("padSpecSig", "", 0., 0.375, 1., 1.);
467  TPad* padRatioSig = new TPad("padRatioSig", "", 0., 0., 1., 0.375);
468  TPad* padSpec_bg = new TPad("padSpec_bg", "", 0., 0.375, 1., 1.);
469  TPad* padRatio_bg = new TPad("padRatio_bg", "", 0., 0., 1., 0.375);
470  TPad* padSpecSigTotal = new TPad("padSpecSigTotal", "", 0., 0.375, 1., 1.);
471  TPad* padRatioSigTotal = new TPad("padRatioSigTotal", "", 0., 0., 1., 0.375);
472  TPad* padSpecBkgTotal = new TPad("padSpecBkgTotal", "", 0., 0.375, 1., 1.);
473  TPad* padRatioBkgTotal = new TPad("padRatioBkgTotal", "", 0., 0., 1., 0.375);
474  TLegend* leg = new TLegend(0.5, 0.5, 0.88, 0.88);
475  map<int, TLegendEntry*> legEntries;
476 
477  // Draw nominal ------------
478  // signal
479  TH1* nomSig = (TH1*)nominal.first->Clone("nomSig");
480  for (size_t bin = 1; bin <= size_t(nomSig->GetNbinsX()); ++bin)
481  nomSig->SetBinContent(bin, nomSig->GetBinContent(bin)/nomSig->GetBinWidth(bin));
482  nomSig->GetYaxis()->SetTitle("Events / GeV");
483  nomSig->SetLineStyle(kSolid);
484  nomSig->SetLineColor(kBlack);
485  nomSig->SetLineWidth(2);
486  padSpecSigTotal->cd();
487  nomSig->Draw("hist");
488  // background
489  TH1* nomBkg = (TH1*)nominal.second->Clone("nomBkg");
490  for (size_t bin = 1; bin <= size_t(nomBkg->GetNbinsX()); ++bin)
491  nomBkg->SetBinContent(bin, nomBkg->GetBinContent(bin)/nomBkg->GetBinWidth(bin));
492  nomBkg->GetYaxis()->SetTitle("Events / GeV");
493  nomBkg->SetLineStyle(kSolid);
494  nomBkg->SetLineColor(kBlack);
495  nomBkg->SetLineWidth(2);
496  padSpecBkgTotal->cd();
497  nomBkg->Draw("hist");
498  // ratio
499  TH1* nomRatio = (TH1*)nomSig->Clone("nomRatio");
500  nomRatio->GetYaxis()->SetTitle("Shifted / Nominal");
501  for (Int_t bin = 1; bin <= nomRatio->GetNbinsX(); ++bin)
502  nomRatio->SetBinContent(bin, 1.);
503  padRatioSigTotal->cd();
504  nomRatio->Draw("hist");
505  padRatioBkgTotal->cd();
506  nomRatio->Draw("hist");
507  legEntries[0] = new TLegendEntry(nomSig, "Nominal", "l");
508 
509  // Draw shifts ------------
510  int it = 0;
511  for (map<int, SystMakerShiftSigma*>::const_iterator sigma = fSigmas.begin(); sigma != fSigmas.end(); ++sigma, ++it) {
512  if (sigma->second->fSigma == 0)
513  continue;
514  // Total ------------
515  // signal
516  TH1* sigmaSig = (TH1*)sigma->second->fShiftedSpectrum.first->Clone();
517  for (size_t bin = 1; bin <= size_t(sigmaSig->GetNbinsX()); ++bin)
518  sigmaSig->SetBinContent(bin, sigmaSig->GetBinContent(bin)/sigmaSig->GetBinWidth(bin));
519  sigmaSig->GetYaxis()->SetTitle("Events / GeV");
520  sigmaSig->SetLineStyle(kDashed);
521  sigmaSig->SetLineColor(abs(sigma->second->fSigma)+1);
522  sigmaSig->SetLineWidth(2);
523  padSpecSigTotal->cd();
524  sigmaSig->DrawClone("hist same");
525  TH1* sigmaRatioSig = (TH1*)sigmaSig->Clone("sigmaRatioSig");
526  sigmaRatioSig->Divide(nomSig);
527  padRatioSigTotal->cd();
528  sigmaRatioSig->DrawClone("hist same");
529  // background
530  TH1* sigmaBkg = (TH1*)sigma->second->fShiftedSpectrum.second->Clone();
531  for (size_t bin = 1; bin <= size_t(sigmaBkg->GetNbinsX()); ++bin)
532  sigmaBkg->SetBinContent(bin, sigmaBkg->GetBinContent(bin)/sigmaBkg->GetBinWidth(bin));
533  sigmaBkg->GetYaxis()->SetTitle("Events / GeV");
534  sigmaBkg->SetLineStyle(kDashed);
535  sigmaBkg->SetLineColor(abs(sigma->second->fSigma)+1);
536  sigmaBkg->SetLineWidth(2);
537  padSpecBkgTotal->cd();
538  sigmaBkg->DrawClone("hist same");
539  TH1* sigmaRatioBkg = (TH1*)sigmaBkg->Clone("sigmaRatioBkg");
540  sigmaRatioBkg->Divide(nomBkg);
541  padRatioBkgTotal->cd();
542  sigmaRatioBkg->DrawClone("hist same");
543  legEntries[abs(sigma->second->fSigma)]
544  = new TLegendEntry(sigmaSig->Clone(), Form("+/-%d#sigma", sigma->second->fSigma), "l");
545  // Individual ------------
546  // signal
547  padSpecSig->cd();
548  padSpecSig->Clear();
549  nomSig->Draw("hist");
550  sigmaSig->SetLineColor(kRed);
551  sigmaSig->Draw("hist same");
552  padRatioSig->cd();
553  padRatioSig->Clear();
554  nomRatio->Draw("hist");
555  sigmaRatioSig->SetLineColor(kRed);
556  sigmaRatioSig->Draw("hist same");
557  canv->cd();
558  canv->Clear();
559  padSpecSig->DrawClone();
560  padRatioSig->DrawClone();
561  outDir->cd(dirSigShift_sigmas.c_str());
562  canv->Write(Form("%s%dSigma", fName.c_str(), sigma->second->fSigma));
563  // background
564  padSpec_bg->cd();
565  padSpec_bg->Clear();
566  nomBkg->Draw("hist");
567  sigmaBkg->SetLineColor(kRed);
568  sigmaBkg->Draw("hist same");
569  padRatio_bg->cd();
570  padRatio_bg->Clear();
571  nomRatio->Draw("hist");
572  sigmaRatioBkg->SetLineColor(kRed);
573  sigmaRatioBkg->Draw("hist same");
574  canv->cd();
575  canv->Clear();
576  padSpec_bg->DrawClone();
577  padRatio_bg->DrawClone();
578  outDir->cd(dirBkgShiftSigmas.c_str());
579  canv->Write(Form("%s%dSigma", fName.c_str(), sigma->second->fSigma));
580 
581  }
582 
583  // Draw legend ------------
584  for (const auto& legEntry : legEntries)
585  leg->AddEntry(legEntry.second->GetObject(),
586  legEntry.second->GetLabel(),
587  legEntry.second->GetOption());
588  padSpecSigTotal->cd();
589  leg->Draw();
590  padSpecBkgTotal->cd();
591  leg->Draw();
592 
593  // Draw all together ------------
594  // signal
595  canv->cd();
596  canv->Clear();
597  padSpecSigTotal->Draw();
598  padRatioSigTotal->Draw();
599  outDir->cd(dirSigShift.c_str());
600  canv->Write(Form("%sSigAllSigmas", fName.c_str()));
601  // background
602  canv->cd();
603  canv->Clear();
604  padSpecBkgTotal->Draw();
605  padRatioBkgTotal->Draw();
606  outDir->cd(dirBkgShift.c_str());
607  canv->Write(Form("%sBgAllSigmas", fName.c_str()));
608 
609  // clean up
610  // need to figure out what needs to be deleted
611  delete canv;
612 
613  } // function SystMakerShift::DrawShift
enum BeamMode kRed
set< int >::iterator it
TCanvas * canv
void abs(TH1 *hist)
std::string outDir
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
std::string fName
Definition: SystMaker.h:126
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
TCanvas * ana::SystMakerShift::DrawSig ( TH1 *  nominal)

Definition at line 280 of file SystMaker.cxx.

References abs(), bin, canv, stan::math::fabs(), fSigmas, MECModelEnuComparisons::i, it, MECModelEnuComparisons::leg, sigma(), and febshutoff_auto::val.

280  {
281 
282  // Drawing tools ------------
283  TCanvas* canv = new TCanvas("canv", "", 800, 800);
284  TPad* padSpecSigTotal = new TPad("padSpecSigTotal", "", 0., 0.375, 1., 1.);
285  TPad* padRatioSigTotal = new TPad("padRatioSigTotal", "", 0., 0., 1., 0.375);
286  TLegend* leg = new TLegend(0.5, 0.5, 0.88, 0.88);
287  map<int, TLegendEntry*> legEntries;
288 
289  // Draw nominal ------------
290  TH1* hNom = (TH1*)nominal->Clone("hNom");
291  for (size_t bin = 1; bin <= size_t(hNom->GetNbinsX()); ++bin)
292  hNom->SetBinContent(bin, hNom->GetBinContent(bin)/hNom->GetBinWidth(bin));
293  hNom->GetYaxis()->SetTitle("Events / GeV");
294  hNom->SetLineStyle(kSolid);
295  hNom->SetLineColor(kBlack);
296  hNom->SetLineWidth(2);
297  padSpecSigTotal->cd();
298  hNom->Draw("hist");
299 
300  // ratio
301  TH1* nomRatio = (TH1*)nominal->Clone("nomRatio");
302  nomRatio->GetYaxis()->SetTitle("Shifted / Nominal");
303  for (Int_t bin = 0; bin <= nomRatio->GetNbinsX(); ++bin)
304  nomRatio->SetBinContent(bin, 1.);
305  padRatioSigTotal->cd();
306  nomRatio->Draw("hist");
307  legEntries[0] = new TLegendEntry(nominal, "Nominal", "l");
308  double ymaxRatio = 0;
309 
310  // Draw shifts ------------
311  int it = 0;
312  for (map<int, SystMakerShiftSigma*>::const_iterator sigma = fSigmas.begin(); sigma != fSigmas.end(); ++sigma, ++it) {
313  if (sigma->second->fSigma == 0)
314  continue;
315  // Total ------------
316  TH1* sigmaSig = (TH1*)sigma->second->fShiftedSpectrum.first->Clone();
317  for (size_t bin = 1; bin <= size_t(sigmaSig->GetNbinsX()); ++bin)
318  sigmaSig->SetBinContent(bin, sigmaSig->GetBinContent(bin)/sigmaSig->GetBinWidth(bin));
319  sigmaSig->GetYaxis()->SetTitle("Events / GeV");
320  sigmaSig->SetLineStyle(kDashed);
321  sigmaSig->SetLineColor(abs(sigma->second->fSigma)+1);
322  sigmaSig->SetLineWidth(2);
323  padSpecSigTotal->cd();
324  sigmaSig->DrawClone("hist same");
325  TH1* sigmaRatioSig = (TH1*)sigmaSig->Clone("sigmaRatioSig");
326  sigmaRatioSig->Divide(hNom);
327  sigmaRatioSig->SetBinContent(0, 1);
328  for (size_t i = 1; i <= (size_t)sigmaRatioSig->GetNbinsX(); ++i) {
329  double val = sigmaRatioSig->GetBinContent(i);
330  if (val == 0) {
331  sigmaRatioSig->SetBinContent(i, 1);
332  val = 1;
333  }
334  if (fabs(val-1) > ymaxRatio)
335  ymaxRatio = fabs(val-1);
336  }
337  padRatioSigTotal->cd();
338  sigmaRatioSig->DrawClone("hist same");
339  legEntries[abs(sigma->second->fSigma)]
340  = new TLegendEntry(sigmaSig->Clone(), Form("+/-%d#sigma", sigma->second->fSigma), "l");
341  }
342 
343  // Draw legend ------------
344  for (const auto& legEntry : legEntries)
345  leg->AddEntry(legEntry.second->GetObject(),
346  legEntry.second->GetLabel(),
347  legEntry.second->GetOption());
348  padSpecSigTotal->cd();
349  leg->Draw();
350 
351  nomRatio->SetMinimum(1-(1.1*ymaxRatio));
352  nomRatio->SetMaximum(1+(1.1*ymaxRatio));
353 
354  // Draw all together ------------
355  canv->cd();
356  canv->Clear();
357  padSpecSigTotal->Draw();
358  padRatioSigTotal->Draw();
359 
360  return canv;
361 
362  } // function SystMakerShift::DrawSig
set< int >::iterator it
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
TCanvas * canv
void abs(TH1 *hist)
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::string ana::SystMakerShift::GetLabel ( )
inline

Definition at line 101 of file SystMaker.h.

References om::cout, dir, ana::LoadFrom(), outDir, ana::SaveTo(), sigma(), string, and WriteTable().

101 { return fLabel; }
std::string fLabel
Definition: SystMaker.h:127
std::string ana::SystMakerShift::GetName ( )
inline

Definition at line 100 of file SystMaker.h.

Referenced by ana::SystMaker::AddShift(), and ana::SystMaker::LoadFrom().

100 { return fName; }
std::string fName
Definition: SystMaker.h:126
pair< TH1 *, TH1 * > ana::SystMakerShift::GetShiftedSpectrum ( int  sigma)

Definition at line 683 of file SystMaker.cxx.

References om::cout, allTimeWatchdog::endl, fName, fSigmas, and sigma().

Referenced by WriteTable().

683  {
684  if (!fSigmas.count(sigma)) {
685  cout << "Error: attempting to retrieve " << sigma << " sigma shift from "
686  << fName << "; does not exist. Aborting..." << endl;
687  abort();
688  }
689  return fSigmas[sigma]->fShiftedSpectrum;
690  }
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
std::string fName
Definition: SystMaker.h:126
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
vector< int > ana::SystMakerShift::GetSigmas ( )

Definition at line 255 of file SystMaker.cxx.

References fSigmas.

Referenced by WriteTable().

255  {
256  vector<int> sigmas;
257  for (const auto& sigma : fSigmas)
258  sigmas.push_back(sigma.first);
259  return sigmas;
260  }
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
double sigma(TH1F *hist, double percentile)
unique_ptr< SystMakerShift > ana::SystMakerShift::LoadFrom ( TDirectory *  dir)
static

LoadFrom implementation for SystMakerShift.

Definition at line 753 of file SystMaker.cxx.

References ana::assert(), ana::SystMakerShiftSigma::fSigma, findDuplicateFiles::key, label, ana::SystMakerShiftSigma::LoadFrom(), next(), sigma(), and getGoodRuns4SAM::tag.

Referenced by ana::SystMaker::LoadFrom().

753  {
754 
755  DontAddDirectory guard;
756 
757  TObjString* tag = (TObjString*)dir->Get("type");
758  assert(tag);
759  assert(tag->GetString() == "SystMakerShift");
760 
761  TObjString* name = (TObjString*)dir->Get("name");;
762  TObjString* label = (TObjString*)dir->Get("label");;
763  unique_ptr<SystMakerShift> systMakerShift
764  = make_unique<SystMakerShift>(name->GetString().Data(), label->GetString().Data());
765 
766  map<int, SystMakerShiftSigma*> sigmas;
767  TIter next(dir->GetDirectory("Sigmas")->GetListOfKeys());
768  TKey* key;
769  while ((key = (TKey*)next())) {
770  SystMakerShiftSigma* sigma
771  = SystMakerShiftSigma::LoadFrom(dir->GetDirectory(Form("Sigmas/%s", key->GetName())));
772  sigmas[sigma->fSigma] = sigma;
773  }
774  systMakerShift->fSigmas = sigmas;
775 
776  return systMakerShift;
777 
778  } // function SystMakerShift::LoadFrom
const XML_Char * name
Definition: expat.h:151
static SystMakerShiftSigma * LoadFrom(TDirectory *dir)
Definition: SystMaker.cxx:200
const char * label
double sigma(TH1F *hist, double percentile)
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void next()
Definition: show_event.C:84
void ana::SystMakerShift::MakePredictions ( SystPredType  predType,
const HistAxis axis,
const HistAxis numuAxis,
const Cut fd_cut,
const Cut nd_cut,
const Cut numu_cut,
const Var weight,
Loaders loaders 
)
virtual

Base class implementation of MakePredictions, which just throws an error.

Reimplemented in ana::SystMakerSystShift, ana::SystMakerWeightShift, and ana::SystMakerLoaderShift.

Definition at line 715 of file SystMaker.cxx.

References ana::assert().

718  {
719 
720  // This function has to be defined in the base class for <reasons> but the
721  // user should never actually call it so it just throws an error
722 
723  assert(false and "Base class version of MakePredictions should never be called!");
724 
725  } // function SystMakerShift::MakePredictions
assert(nhit_max >=nhit_nbins)
void ana::SystMakerShift::PrintShift ( std::ostream &  os = std::cout)

Definition at line 263 of file SystMaker.cxx.

References allTimeWatchdog::endl, fLabel, and fSigmas.

263  {
264  os << endl << " " << fLabel << " shifts:" << endl;
265  for (const auto& sigma : fSigmas)
266  sigma.second->PrintSigma(os);
267  return;
268  }
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
std::string fLabel
Definition: SystMaker.h:127
double sigma(TH1F *hist, double percentile)
void ana::SystMakerShift::ProcessShift ( std::pair< TH1 *, TH1 * > &  nominal_spectrum,
const covmx::Sample  sample,
osc::IOscCalc calc 
)

Definition at line 693 of file SystMaker.cxx.

References abs(), fSigmas, ana::GetSpectrum(), and make_pair().

694  {
695  for (auto& sigma : fSigmas) {
696  TH1* hShiftSig = GetSpectrum(sigma.second->fPrediction, true, sample, calc);
697  TH1* hShiftBg = GetSpectrum(sigma.second->fPrediction, false, sample, calc);
698  TH1* hShiftRatioSig = (TH1*)hShiftSig->Clone("shiftRatSig");
699  hShiftRatioSig->Divide(nominal_spectrum.first);
700  TH1* hShiftRatioBg = (TH1*)hShiftBg->Clone("shiftRatBkg");
701  hShiftRatioBg->Divide(nominal_spectrum.second);
702  double shiftSig = abs(hShiftSig->Integral() - nominal_spectrum.first->Integral()) /
703  nominal_spectrum.first->Integral();
704  double shiftBg = abs(hShiftBg->Integral() - nominal_spectrum.second->Integral()) /
705  nominal_spectrum.second->Integral();
706  sigma.second->fShiftedSpectrum = make_pair(hShiftSig, hShiftBg);
707  sigma.second->fShiftedRatio = make_pair(hShiftRatioSig, hShiftRatioBg);
708  sigma.second->fShift = make_pair(shiftSig, shiftBg);
709  }
710  return;
711  }
void abs(TH1 *hist)
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
TH1 * GetSpectrum(IPrediction *pred, bool signal, const Sample sample, IOscCalc *calc)
Definition: SystMaker.cxx:78
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
double sigma(TH1F *hist, double percentile)
void ana::SystMakerShift::SaveTo ( TDirectory *  dir) const

SaveTo implementation for SystMakerShift.

Definition at line 729 of file SystMaker.cxx.

References fLabel, fName, fSigmas, tmp, and Write().

729  {
730 
731  TDirectory* tmp = gDirectory;
732 
733  dir->cd();
734  TObjString("SystMakerShift").Write("type");
735 
736  TObjString(fName.c_str()).Write("name");
737  TObjString(fLabel.c_str()).Write("label");
738 
739  const char* sigmaDir = "Sigmas";
740  dir->mkdir(sigmaDir);
741  for (const auto& sigma : fSigmas) {
742  const char* sigmaSubdir = Form("%s/Sigma%d", sigmaDir, sigma.second->fSigma);
743  dir->mkdir(sigmaSubdir);
744  sigma.second->SaveTo(dir->GetDirectory(sigmaSubdir));
745  }
746 
747  tmp->cd();
748 
749  } // function SystMakerShift::SaveTo
Float_t tmp
Definition: plot.C:36
std::map< int, SystMakerShiftSigma * > fSigmas
Definition: SystMaker.h:129
std::string fName
Definition: SystMaker.h:126
std::string fLabel
Definition: SystMaker.h:127
double sigma(TH1F *hist, double percentile)
TDirectory * dir
Definition: macro.C:5
gm Write()
string ana::SystMakerShift::WriteTable ( std::pair< TH1 *, TH1 * >  nominal,
std::string  name 
)

Definition at line 616 of file SystMaker.cxx.

References ana::assert(), GetShiftedSpectrum(), GetSigmas(), it, nbins, and getGoodRuns4SAM::table.

616  {
617 
618  ostringstream table;
619 
620  table << "\\newcommand{\\" << name << "}\n";
621  table << "{\\centerline{\n";
622  table << "\\begin{tabular}{ l | r r r | r r }\n";
623  table << " & Nom.&(+)&(-)&\\%(+)&\\%(-) \\\\ \\hline\n";
624 
625  // We write +1 and -1 sigmas to a table. First check they both exist!
626 
627  vector<int> sigmas = this->GetSigmas();
628  if (find(sigmas.begin(), sigmas.end(), 1) == sigmas.end())
629  assert(false and "+1 shift required to call WriteTable()!");
630  bool useDown = find(sigmas.begin(), sigmas.end(), -1) != sigmas.end();
631 
632  // Get nominal event counts for signal and background
633  double sigNom = 0, bkgNom = 0;
634  size_t nbins = nominal.first->GetNbinsX();
635  for (size_t it = 1; it <= nbins; ++it) {
636  sigNom += nominal.first->GetBinContent(it);
637  bkgNom += nominal.second->GetBinContent(it);
638  }
639 
640  // Now calculate the up and down totals
641  double sigUp = sigNom, bkgUp = bkgNom, sigDown = 0, bkgDown = 0;
642  if (useDown) {
643  sigDown = sigNom;
644  bkgDown = bkgNom;
645  }
646 
647  for (size_t it = 1; it <= nbins; ++it) {
648  sigUp += this->GetShiftedSpectrum(1).first->GetBinContent(it)
649  - nominal.first->GetBinContent(it);
650  sigDown += this->GetShiftedSpectrum(-1).first->GetBinContent(it)
651  - nominal.first->GetBinContent(it);
652  bkgUp += this->GetShiftedSpectrum(1).second->GetBinContent(it)
653  - nominal.second->GetBinContent(it);
654  if (useDown) {
655  sigDown += this->GetShiftedSpectrum(-1).first->GetBinContent(it)
656  - nominal.first->GetBinContent(it);
657  bkgDown += this->GetShiftedSpectrum(-1).second->GetBinContent(it)
658  - nominal.second->GetBinContent(it);
659  }
660  }
661 
662  // Write them to the table and return it
663  table << "Signal & " << sigNom << " & " << sigUp << " & ";
664  if (useDown) table << sigDown;
665  else table << "N/A";
666  table << " & " << 100*((sigUp/sigNom)-1) << " & ";
667  if (useDown) table << 100*((sigDown/sigNom)-1);
668  else table << "N/A";
669  table << " \\\\\n";
670  table << "Background & " << bkgNom << " & " << bkgUp << " & ";
671  if (useDown) table << bkgDown;
672  else table << "N/A";
673  table << " & " << 100*((bkgUp/bkgNom)-1) << " & ";
674  if (useDown) table << 100*((bkgDown/bkgNom)-1);
675  else table << "N/A";
676  table << " \\\\\n\\end{tabular}\n}}\n";
677 
678  return table.str();
679 
680  } // function SystMakerShift::WriteTable
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
std::pair< TH1 *, TH1 * > GetShiftedSpectrum(int sigma)
Definition: SystMaker.cxx:683
const int nbins
Definition: cellShifts.C:15
std::vector< int > GetSigmas()
Definition: SystMaker.cxx:255
assert(nhit_max >=nhit_nbins)

Member Data Documentation

std::string ana::SystMakerShift::fLabel
protected

Definition at line 127 of file SystMaker.h.

Referenced by PrintShift(), and SaveTo().

std::string ana::SystMakerShift::fName
protected
std::map<int, SystMakerShiftSigma*> ana::SystMakerShift::fSigmas
protected

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