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

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

Public Member Functions

 SystMaker (std::string name, std::string label, std::string sample_name="")
 SystMaker constructor. More...
 
 ~SystMaker ()
 SystMaker destructor. More...
 
std::string GetName ()
 
std::string GetLabel ()
 
SystMakerShiftGetShift (std::string shift_name)
 Get the shift for a given name. More...
 
std::map< std::string, SystMakerShift * > GetShifts ()
 
std::map< int, std::pair< double, double > > GetTotalShift ()
 
std::pair< double, double > GetTotalShift (int sigma)
 Get the total shifts for a given sigma (sig+bkg) More...
 
double GetTotalShift (int sigma, bool signal)
 Get the total shift for a given sigma and channel selection (sig/bkg) More...
 
std::vector< intGetSigmas ()
 Get the sigmas for a given systematic shift. More...
 
std::map< int, std::pair< TH1 *, TH1 * > > GetSpectra ()
 
IPredictionGetNominal ()
 
void AddShift (SystMakerShift *shift)
 Add SystMakerShift to this syst maker. More...
 
void PrintSyst (std::ostream &os=std::cout)
 Print the total shifts for each shift owned by this syst maker. More...
 
TCanvas * DrawSig ()
 Make plots of all the shifted spectra and ratios for this systmaker. More...
 
TCanvas * DrawBkg ()
 Make plots of all the shifted spectra and ratios for this systmaker. More...
 
void DrawSyst (TDirectory *outDir)
 Make plots of all the shifted spectra and ratios for this systmaker. More...
 
std::string WriteTable (std::string name)
 Write a table with up & down shifts for this systematic. More...
 
void MakePredictions (SystPredType predType)
 Make predictions for all the SystMakerShift objects owned by this syst maker. More...
 
void ProcessSyst (const covmx::Sample sample, osc::IOscCalc *calc)
 
NuISystMakeISyst (covmx::Sample sample)
 Function to make ISyst for this SystMaker. More...
 
void SetAxes (const HistAxis *axis, const HistAxis *numuAxis=nullptr)
 
void SetCuts (const Cut *fd_cut, const Cut *nd_cut, const Cut *numu_cut=nullptr)
 
void SetNominalLoaders (Loaders *loaders)
 
void SetNominalWeight (const Var *weight)
 
void SaveTo (TDirectory *dir) const
 SaveTo implementation for SystMaker. More...
 

Static Public Member Functions

static std::unique_ptr< SystMakerLoadFrom (TDirectory *dir)
 LoadFrom implementation for SystMaker. More...
 

Private Attributes

std::string fName
 
std::string fLabel
 
std::string fSampleName
 
std::map< std::string, SystMakerShift * > fShifts
 
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
 
std::map< int, std::pair< double, double > > fTotalShifts
 
const HistAxisfAxis
 
const HistAxisfNuMuAxis
 
const CutfNDCut
 
const CutfFDCut
 
const CutfNuMuCut
 
LoadersfLoaders
 
const VarfWeight
 
IPredictionfNominalPred
 

Detailed Description

Definition at line 196 of file SystMaker.h.

Constructor & Destructor Documentation

ana::SystMaker::SystMaker ( std::string  name,
std::string  label,
std::string  sample_name = "" 
)

SystMaker constructor.

Definition at line 930 of file SystMaker.cxx.

930  :
931  fName(name),
932  fLabel(label),
933  fSampleName(sampleName),
934  fAxis(nullptr),
935  fNuMuAxis(nullptr),
936  fNDCut(nullptr),
937  fFDCut(nullptr),
938  fNuMuCut(nullptr),
939  fLoaders(nullptr),
940  fWeight(nullptr),
941  fNominalPred(nullptr) {
942 
943  } // SystMaker constructor
const XML_Char * name
Definition: expat.h:151
const HistAxis * fNuMuAxis
Definition: SystMaker.h:245
IPrediction * fNominalPred
Definition: SystMaker.h:250
const Cut * fFDCut
Definition: SystMaker.h:246
const HistAxis * fAxis
Definition: SystMaker.h:245
std::string fSampleName
Definition: SystMaker.h:239
const char * label
const Cut * fNDCut
Definition: SystMaker.h:246
std::string fName
Definition: SystMaker.h:237
const Var * fWeight
Definition: SystMaker.h:248
const Cut * fNuMuCut
Definition: SystMaker.h:246
Loaders * fLoaders
Definition: SystMaker.h:247
std::string fLabel
Definition: SystMaker.h:238
ana::SystMaker::~SystMaker ( )

SystMaker destructor.

Definition at line 947 of file SystMaker.cxx.

References fNominalPred, and fShifts.

947  {
948 
949  for (auto shift : fShifts) {
950  if (shift.second) delete shift.second;
951  }
952  if (fNominalPred) delete fNominalPred;
953 
954  } // SystMaker destructor
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
IPrediction * fNominalPred
Definition: SystMaker.h:250

Member Function Documentation

void ana::SystMaker::AddShift ( SystMakerShift shift)

Add SystMakerShift to this syst maker.

Definition at line 1022 of file SystMaker.cxx.

References fShifts, and ana::SystMakerShift::GetName().

Referenced by MakeSysts().

1022  {
1023 
1024  fShifts[shift->GetName()] = shift;
1025 
1026  } // function SystMaker::AddShift
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
TCanvas * ana::SystMaker::DrawBkg ( )

Make plots of all the shifted spectra and ratios for this systmaker.

Definition at line 1116 of file SystMaker.cxx.

References abs(), bin, canv, stan::math::fabs(), fSpectra, GetSigmas(), MECModelEnuComparisons::i, moon_position_table_new3::second, and febshutoff_auto::val.

Referenced by DrawSyst().

1116  {
1117 
1118  // Nominal
1119  TH1* nomBkg = (TH1*)fSpectra[0].second->Clone();
1120  for (size_t bin = 1; bin <= size_t(nomBkg->GetNbinsX()); ++bin)
1121  nomBkg->SetBinContent(bin, nomBkg->GetBinContent(bin)/nomBkg->GetBinWidth(bin));
1122  nomBkg->GetYaxis()->SetTitle("Events / GeV");
1123  nomBkg->SetLineColor(kBlack);
1124  nomBkg->SetLineStyle(kSolid);
1125  nomBkg->SetLineWidth(2);
1126  TH1* nomRatio = (TH1*)nomBkg->Clone();
1127  nomRatio->GetYaxis()->SetTitle("Shifted / Nominal");
1128  for (size_t bin = 0; bin <= (size_t)nomRatio->GetNbinsX(); ++bin)
1129  nomRatio->SetBinContent(bin, 1.);
1130 
1131  // Draw total shifts -- all sigmas
1132  TCanvas* canv = new TCanvas("canvBkg", "", 800, 800);
1133  TPad* padSpec = new TPad("padSpecBkg", "", 0., 0.375, 1., 1. );
1134  TPad* padRatio = new TPad("padRatio_bkg", "", 0., 0., 1., 0.375);
1135  map<int, TLegendEntry*> legEntrySigma;
1136  padSpec->cd();
1137  nomBkg->Draw("hist");
1138  padRatio->cd();
1139  nomRatio->Draw("hist");
1140  legEntrySigma[0] = new TLegendEntry(nomBkg, "Nominal", "l");
1141  double ymaxRatio = 0;
1142 
1143  // Loop over each sigma
1144  for (const auto& sigma : this->GetSigmas()) {
1145  if (sigma == 0)
1146  continue;
1147 
1148  // Draw the spectrum
1149  TH1* sigmaBkg = (TH1*)fSpectra[sigma].second->Clone();
1150  for (size_t bin = 1; bin <= size_t(sigmaBkg->GetNbinsX()); ++bin)
1151  sigmaBkg->SetBinContent(bin, sigmaBkg->GetBinContent(bin)/sigmaBkg->GetBinWidth(bin));
1152  sigmaBkg->GetYaxis()->SetTitle("Events / GeV");
1153  double hmax = nomBkg->GetMaximum() > sigmaBkg->GetMaximum() ?
1154  nomBkg->GetMaximum() : sigmaBkg->GetMaximum();
1155  nomBkg->SetMaximum(1.1*hmax);
1156  sigmaBkg->SetLineColor(abs(sigma)+1);
1157  sigmaBkg->SetLineStyle(kDashed);
1158  sigmaBkg->SetLineWidth(2);
1159  padSpec->cd();
1160  sigmaBkg->Draw("hist same");
1161  if (!legEntrySigma.count(abs(sigma)))
1162  legEntrySigma[abs(sigma)] = new TLegendEntry(sigmaBkg, Form("+/-%d #sigma", abs(sigma)), "l");
1163 
1164  // Draw the ratio
1165  TH1* ratioBkg = (TH1*)sigmaBkg->Clone();
1166  ratioBkg->Divide(nomBkg);
1167  ratioBkg->SetBinContent(0, 1);
1168  for (size_t i = 1; i <= (size_t)ratioBkg->GetNbinsX(); ++i) {
1169  double val = ratioBkg->GetBinContent(i);
1170  if (val == 0) {
1171  ratioBkg->SetBinContent(i, 1);
1172  val = 1;
1173  }
1174  if (fabs(1-val) > ymaxRatio)
1175  ymaxRatio = fabs(1-val);
1176  }
1177  padRatio->cd();
1178  ratioBkg->Draw("hist same");
1179  }
1180  TLegend* legSigma = new TLegend(0.5, 0.5, 0.88, 0.88);
1181  for (const auto& legEntry : legEntrySigma)
1182  legSigma->AddEntry(legEntry.second->GetObject(),
1183  legEntry.second->GetLabel(),
1184  legEntry.second->GetOption());
1185  padSpec->cd();
1186  legSigma->Draw("same");
1187 
1188  nomRatio->SetMinimum(1-(1.1*ymaxRatio));
1189  nomRatio->SetMaximum(1+(1.1*ymaxRatio));
1190 
1191  canv->cd();
1192  canv->Clear();
1193  padSpec->Draw();
1194  padRatio->Draw();
1195 
1196  return canv;
1197 
1198  } // function SystMaker::DrawBkg
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
std::vector< int > GetSigmas()
Get the sigmas for a given systematic shift.
Definition: SystMaker.cxx:989
TCanvas * canv
void abs(TH1 *hist)
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
TCanvas * ana::SystMaker::DrawSig ( )

Make plots of all the shifted spectra and ratios for this systmaker.

Definition at line 1030 of file SystMaker.cxx.

References abs(), bin, canv, stan::math::fabs(), fSpectra, GetSigmas(), MECModelEnuComparisons::i, and febshutoff_auto::val.

Referenced by DrawSyst().

1030  {
1031 
1032  // Nominal
1033  TH1* nomSig = (TH1*)fSpectra[0].first->Clone();
1034  for (size_t bin = 1; bin <= size_t(nomSig->GetNbinsX()); ++bin)
1035  nomSig->SetBinContent(bin, nomSig->GetBinContent(bin)/nomSig->GetBinWidth(bin));
1036  nomSig->GetYaxis()->SetTitle("Events / GeV");
1037  nomSig->SetLineColor(kBlack);
1038  nomSig->SetLineStyle(kSolid);
1039  nomSig->SetLineWidth(2);
1040  TH1* nomRatio = (TH1*)nomSig->Clone();
1041  nomRatio->GetYaxis()->SetTitle("Shifted / Nominal");
1042  for (size_t bin = 0; bin <= (size_t)nomRatio->GetNbinsX(); ++bin)
1043  nomRatio->SetBinContent(bin, 1.);
1044 
1045  // Draw total shifts -- all sigmas
1046  TCanvas* canv = new TCanvas("canvSig", "", 800, 800);
1047  TPad* padSpec = new TPad("padSpecSig", "", 0., 0.375, 1., 1. );
1048  TPad* padRatio = new TPad("padRatioSig", "", 0., 0., 1., 0.375);
1049  map<int, TLegendEntry*> legEntrySigma;
1050  padSpec->cd();
1051  nomSig->Draw("hist");
1052  padRatio->cd();
1053  nomRatio->Draw("hist");
1054  legEntrySigma[0] = new TLegendEntry(nomSig, "Nominal", "l");
1055  double ymaxRatio = 0;
1056 
1057  // Loop over each sigma
1058  for (const auto& sigma : this->GetSigmas()) {
1059  if (sigma == 0)
1060  continue;
1061 
1062  // Draw the spectrum
1063  TH1* sigmaSig = (TH1*)fSpectra[sigma].first->Clone();
1064  for (size_t bin = 1; bin <= size_t(sigmaSig->GetNbinsX()); ++bin)
1065  sigmaSig->SetBinContent(bin, sigmaSig->GetBinContent(bin)/sigmaSig->GetBinWidth(bin));
1066  sigmaSig->GetYaxis()->SetTitle("Events / GeV");
1067  double hmax = nomSig->GetMaximum() > sigmaSig->GetMaximum() ?
1068  nomSig->GetMaximum() : sigmaSig->GetMaximum();
1069  nomSig->SetMaximum(1.1*hmax);
1070  sigmaSig->SetLineColor(abs(sigma)+1);
1071  sigmaSig->SetLineStyle(kDashed);
1072  sigmaSig->SetLineWidth(2);
1073  padSpec->cd();
1074  sigmaSig->Draw("hist same");
1075  if (!legEntrySigma.count(abs(sigma)))
1076  legEntrySigma[abs(sigma)] = new TLegendEntry(sigmaSig, Form("+/-%d #sigma", abs(sigma)), "l");
1077 
1078  // Draw the ratio
1079  TH1* ratioSig = (TH1*)sigmaSig->Clone();
1080  ratioSig->Divide(nomSig);
1081  ratioSig->SetBinContent(0, 1);
1082  for (size_t i = 1; i <= (size_t)ratioSig->GetNbinsX(); ++i) {
1083  double val = ratioSig->GetBinContent(i);
1084  if (val == 0) {
1085  ratioSig->SetBinContent(i, 1);
1086  val = 1;
1087  }
1088  if (fabs(1-val) > ymaxRatio)
1089  ymaxRatio = fabs(1-val);
1090  }
1091  padRatio->cd();
1092  ratioSig->Draw("hist same");
1093  }
1094  TLegend* legSigma = new TLegend(0.5, 0.5, 0.88, 0.88);
1095  for (const auto& legEntry : legEntrySigma)
1096  legSigma->AddEntry(legEntry.second->GetObject(),
1097  legEntry.second->GetLabel(),
1098  legEntry.second->GetOption());
1099  padSpec->cd();
1100  legSigma->Draw("same");
1101 
1102  nomRatio->SetMinimum(1-(1.1*ymaxRatio));
1103  nomRatio->SetMaximum(1+(1.1*ymaxRatio));
1104 
1105  canv->cd();
1106  canv->Clear();
1107  padSpec->Draw();
1108  padRatio->Draw();
1109 
1110  return canv;
1111 
1112  } // function SystMaker::DrawSig
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
std::vector< int > GetSigmas()
Get the sigmas for a given systematic shift.
Definition: SystMaker.cxx:989
TCanvas * canv
void abs(TH1 *hist)
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
void ana::SystMaker::DrawSyst ( TDirectory *  outDir)

Make plots of all the shifted spectra and ratios for this systmaker.

Definition at line 1202 of file SystMaker.cxx.

References DrawBkg(), DrawSig(), fName, fShifts, and fSpectra.

1202  {
1203 
1204  string dirTop = fName;
1205  string dirSignal = dirTop+"/Signal/";
1206  string dirBackground = dirTop+"/Background/";
1207  string dirSigShifts = dirSignal+"/Shifts/";
1208  string dirBkgShifts = dirBackground+"/Shifts/";
1209  outDir->mkdir(dirTop.c_str());
1210  outDir->mkdir(dirSignal.c_str());
1211  outDir->mkdir(dirBackground.c_str());
1212  outDir->mkdir(dirSigShifts.c_str());
1213  outDir->mkdir(dirBkgShifts.c_str());
1214 
1215  TCanvas* canvSig = DrawSig();
1216  TCanvas* canvBkg = DrawBkg();
1217  outDir->cd(dirSignal.c_str());
1218  canvSig->Write("TotalShiftSig");
1219  outDir->cd(dirBackground.c_str());
1220  canvBkg->Write("TotalShiftBg");
1221 
1222  // Draw total shifts -- +1/-1 sigma
1223 
1224  // Draw individual shifts
1225  for (const auto& shift : fShifts)
1226  shift.second->DrawShift(outDir->GetDirectory(dirTop.c_str()), fSpectra[0]);
1227 
1228  // clean up
1229  delete canvSig;
1230  delete canvBkg;
1231 
1232  } // function SystMaker::DrawSyst
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
std::string outDir
TCanvas * DrawBkg()
Make plots of all the shifted spectra and ratios for this systmaker.
Definition: SystMaker.cxx:1116
std::string fName
Definition: SystMaker.h:237
TCanvas * DrawSig()
Make plots of all the shifted spectra and ratios for this systmaker.
Definition: SystMaker.cxx:1030
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
std::string ana::SystMaker::GetLabel ( )
inline

Definition at line 205 of file SystMaker.h.

References ana::GetShift(), and string.

205 { return fLabel; }
std::string fLabel
Definition: SystMaker.h:238
std::string ana::SystMaker::GetName ( )
inline

Definition at line 204 of file SystMaker.h.

Referenced by ana::SystematicsMaker::AddSystematic(), and ana::SystematicsMaker::LoadFrom().

204 { return fName; }
std::string fName
Definition: SystMaker.h:237
IPrediction* ana::SystMaker::GetNominal ( )
inline

Definition at line 214 of file SystMaker.h.

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

214 { return fNominalPred; };
IPrediction * fNominalPred
Definition: SystMaker.h:250
SystMakerShift * ana::SystMaker::GetShift ( std::string  shift_name)

Get the shift for a given name.

Definition at line 958 of file SystMaker.cxx.

References om::cout, allTimeWatchdog::endl, and fShifts.

958  {
959  if (!fShifts.count(shift_name)) {
960  cout << "Error: requested shift " << shift_name << " does not exist. Aborting..." << endl;
961  abort();
962  }
963  return fShifts[shift_name];
964 
965  } // function SystMaker::GetShift
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
OStream cout
Definition: OStream.cxx:6
std::map<std::string, SystMakerShift*> ana::SystMaker::GetShifts ( )
inline

Definition at line 208 of file SystMaker.h.

References sigma().

208 { return fShifts; };
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
vector< int > ana::SystMaker::GetSigmas ( )

Get the sigmas for a given systematic shift.

Definition at line 989 of file SystMaker.cxx.

References fShifts.

Referenced by DrawBkg(), DrawSig(), ProcessSyst(), and WriteTable().

989  {
990 
991  map<int, vector<string> > shifts_sigmas;
992  for (const auto& shift : fShifts) {
993  vector<int> shiftSigmas = shift.second->GetSigmas();
994  for (const auto& shiftSigma : shiftSigmas)
995  shifts_sigmas[shiftSigma].push_back(shift.second->GetName());
996  }
997  vector<int> sigmas;
998  for (const auto& shiftSigmas : shifts_sigmas)
999  if (shiftSigmas.second.size() == fShifts.size())
1000  sigmas.push_back(shiftSigmas.first);
1001 
1002  return sigmas;
1003 
1004  } // function SystMaker::GetSigmas
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
std::map<int, std::pair<TH1*, TH1*> > ana::SystMaker::GetSpectra ( )
inline

Definition at line 213 of file SystMaker.h.

213 { return fSpectra; };
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
std::map<int, std::pair<double, double> > ana::SystMaker::GetTotalShift ( )

Referenced by GetTotalShift().

pair< double, double > ana::SystMaker::GetTotalShift ( int  sigma)

Get the total shifts for a given sigma (sig+bkg)

Definition at line 969 of file SystMaker.cxx.

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

969  {
970  if (!fTotalShifts.count(sigma)) {
971  cout << "Error: sigma " << sigma << " does not exist. Aborting..." << endl;
972  abort();
973  }
974  return fTotalShifts[sigma];
975 
976  } // function SystMakerShift::GetTotalShift
std::map< int, std::pair< double, double > > fTotalShifts
Definition: SystMaker.h:243
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
double ana::SystMaker::GetTotalShift ( int  sigma,
bool  signal 
)

Get the total shift for a given sigma and channel selection (sig/bkg)

Definition at line 980 of file SystMaker.cxx.

References GetTotalShift().

980  {
981 
982  pair<double, double> totalShift = this->GetTotalShift(sigma);
983  return signal ? totalShift.first : totalShift.second;
984 
985  } // function SystMakerShift::GetTotalShift
double sigma(TH1F *hist, double percentile)
std::map< int, std::pair< double, double > > GetTotalShift()
unique_ptr< SystMaker > ana::SystMaker::LoadFrom ( TDirectory *  dir)
static

LoadFrom implementation for SystMaker.

Definition at line 1477 of file SystMaker.cxx.

References ana::assert(), ana::SystMakerShift::GetName(), label, ana::PredictionSterile::LoadFrom(), ana::FDPredictionSterile::LoadFrom(), ana::NDPredictionSterile::LoadFrom(), ana::SystMakerShift::LoadFrom(), runNovaSAM::release, and getGoodRuns4SAM::tag.

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

1477  {
1478 
1479  DontAddDirectory guard;
1480 
1481  TObjString* tag = (TObjString*)dir->Get("type");
1482  assert(tag);
1483  assert(tag->GetString() == "SystMaker");
1484 
1485  TObjString* name = (TObjString*)dir->Get("name");
1486  assert(name);
1487 
1488  TObjString* label = (TObjString*)dir->Get("label");
1489  assert(label);
1490 
1491  TObjString* sampleName = (TObjString*)dir->Get("samplename");
1492  assert(sampleName);
1493 
1494  unique_ptr<SystMaker> systMaker
1495  = make_unique<SystMaker>(name->GetString().Data(),
1496  label->GetString().Data(), sampleName->GetString().Data());
1497 
1498  // Load prediction
1499  tag = (TObjString*)dir->Get("nompred/type");
1500  assert(tag);
1501  if (tag->GetString() == "NDPredictionSterile")
1502  systMaker->fNominalPred = NDPredictionSterile::LoadFrom(dir, "nompred").release();
1503  else if (tag->GetString() == "FDPredictionSterile")
1504  systMaker->fNominalPred = FDPredictionSterile::LoadFrom(dir, "nompred").release();
1505  else if (tag->GetString() == "PredictionSterile")
1506  systMaker->fNominalPred = PredictionSterile::LoadFrom(dir, "nompred").release();
1507  else assert(false && "Prediction type not recognised!");
1508 
1509  // Load shift makers
1510  map<string, SystMakerShift*> shifts;
1511 
1512  TIter shift_next(dir->GetDirectory("Shifts")->GetListOfKeys());
1513  TKey* shift_key;
1514  while ((shift_key = (TKey*)shift_next())) {
1515  SystMakerShift* shift = SystMakerShift::LoadFrom(dir->GetDirectory(Form("Shifts/%s",
1516  shift_key->GetName()))).release();
1517  shifts[shift->GetName()] = shift;
1518  }
1519  systMaker->fShifts = shifts;
1520 
1521  return move(systMaker);
1522 
1523  } // function SystMaker::LoadFrom
const XML_Char * name
Definition: expat.h:151
static std::unique_ptr< FDPredictionSterile > LoadFrom(TDirectory *dir, const std::string &name)
static std::unique_ptr< SystMakerShift > LoadFrom(TDirectory *dir)
LoadFrom implementation for SystMakerShift.
Definition: SystMaker.cxx:753
static std::unique_ptr< PredictionSterile > LoadFrom(TDirectory *dir, const std::string &name)
const char * label
static std::unique_ptr< NDPredictionSterile > LoadFrom(TDirectory *dir, const std::string &name)
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
NuISyst * ana::SystMaker::MakeISyst ( covmx::Sample  sample)

Function to make ISyst for this SystMaker.

Definition at line 1401 of file SystMaker.cxx.

References om::cout, den, e, allTimeWatchdog::endl, fLabel, fName, fSampleName, fSpectra, MECModelEnuComparisons::i, make_pair(), num, galleryMaker::shortName, and febshutoff_auto::val.

1401  {
1402 
1403  if (fSpectra.size() == 0) {
1404  cout << "There are no spectra owned by this SystMaker!"
1405  << " Did you forget to call Go()?" << endl;
1406  return nullptr;
1407  }
1408 
1409  // Make ratios from shifted spectra
1410  map<int, pair<TH1*, TH1*>> shifts;
1411  for (const auto& sigma : fSpectra) {
1412  TH1* sigRatio = (TH1*)sigma.second.first->Clone(Form("SigRatioSigma%d", sigma.first));
1413  TH1* bkgRatio = (TH1*)sigma.second.second->Clone(Form("BgRatioSigma%d", sigma.first));
1414  //sigRatio->Divide(fSpectra.at(0).first);
1415  //bkgRatio->Divide(fSpectra.at(0).second);
1416  // BEGIN DEBUG CODE
1417  for (int i = 1; i <= sigRatio->GetNbinsX(); ++i) {
1418  double eps = 1e-3;
1419  double num = sigRatio->GetBinContent(i);
1420  double den = fSpectra.at(0).first->GetBinContent(i);
1421  double val = (num+eps)/(den+eps);
1422  // if (val > 2) {
1423  // cout << "Signal bin " << i << ", dividing thru "
1424  // << num << " by " << den << " to get " << val
1425  // << " - with epsilon it's " << valEps << endl;
1426  // }
1427  sigRatio->SetBinContent(i, val);
1428  num = bkgRatio->GetBinContent(i);
1429  den = fSpectra.at(0).second->GetBinContent(i);
1430  val = (num+eps)/(den+eps);
1431  bkgRatio->SetBinContent(i, val);
1432  // if (val > 2) {
1433  // cout << "Background bin " << i << ", dividing thru "
1434  // << num << " by " << den << " to get " << val
1435  // << " - with epsilon it's " << valEps << endl;
1436  // }
1437  }
1438  // END DEBUG CODE
1439  shifts[sigma.first] = make_pair(sigRatio, bkgRatio);
1440  }
1441 
1442  // Return new ISyst
1443  string shortName = fSampleName.empty() ? fName : fSampleName + "_" + fName;
1444  return new NuISyst(shortName, fLabel, fSampleName, shifts);
1445 
1446  } // function SystMaker::MakeISyst
Float_t den
Definition: plot.C:36
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
std::string fSampleName
Definition: SystMaker.h:239
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
std::string fName
Definition: SystMaker.h:237
int num
Definition: f2_nu.C:119
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
std::string fLabel
Definition: SystMaker.h:238
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
Float_t e
Definition: plot.C:35
void ana::SystMaker::MakePredictions ( SystPredType  predType)

Make predictions for all the SystMakerShift objects owned by this syst maker.

Definition at line 1303 of file SystMaker.cxx.

References fAxis, fFDCut, fLoaders, fNDCut, fNominalPred, fNuMuAxis, fNuMuCut, fShifts, fWeight, ana::GetPrediction(), and ana::kNoShift.

Referenced by ana::SystematicsMaker::AddSystematic().

1303  {
1304 
1305  fNominalPred = GetPrediction(predType,
1306  fAxis, fNuMuAxis,
1308  &kNoShift, &kNoShift,
1309  fWeight, fLoaders);
1310 
1311  for (const auto& shift : fShifts) {
1312  shift.second->MakePredictions(predType,
1313  fAxis, fNuMuAxis,
1315  fWeight, fLoaders);
1316  }
1317  } // function SystMaker::MakePredictions
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
const HistAxis * fNuMuAxis
Definition: SystMaker.h:245
IPrediction * fNominalPred
Definition: SystMaker.h:250
const Cut * fFDCut
Definition: SystMaker.h:246
const HistAxis * fAxis
Definition: SystMaker.h:245
const SystShifts kNoShift
Definition: SystShifts.cxx:21
const Cut * fNDCut
Definition: SystMaker.h:246
const Var * fWeight
Definition: SystMaker.h:248
const Cut * fNuMuCut
Definition: SystMaker.h:246
IPrediction * GetPrediction(SystPredType predType, const HistAxis *axis, const HistAxis *numuAxis, const Cut *FDCut, const Cut *NDCut, const Cut *numuCut, const SystShifts *shiftData, const SystShifts *shiftMC, const Var *weight, Loaders *loaders, Loaders *loadersND)
Definition: SystMaker.cxx:44
Loaders * fLoaders
Definition: SystMaker.h:247
void ana::SystMaker::PrintSyst ( std::ostream &  os = std::cout)

Print the total shifts for each shift owned by this syst maker.

Definition at line 1008 of file SystMaker.cxx.

References allTimeWatchdog::endl, fLabel, fShifts, and fTotalShifts.

1008  {
1009 
1010  os << endl << endl << showpos
1011  << "Systematic " << fLabel << " has total shift:" << endl
1012  << " -1: " << fTotalShifts[-1].first << " (signal), " << fTotalShifts[-1].second << " (background)" << endl
1013  << " +1: " << fTotalShifts[+1].first << " (signal), " << fTotalShifts[+1].second << " (background)" << endl;
1014  os << endl << "Individual shifts:" << endl;
1015  for (const auto& shift : fShifts)
1016  shift.second->PrintShift(os);
1017 
1018  } // function SystMaker::PrintSyst
std::map< int, std::pair< double, double > > fTotalShifts
Definition: SystMaker.h:243
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
std::string fLabel
Definition: SystMaker.h:238
void ana::SystMaker::ProcessSyst ( const covmx::Sample  sample,
osc::IOscCalc calc 
)

Definition at line 1320 of file SystMaker.cxx.

References bin, fNominalPred, fShifts, fSpectra, fTotalShifts, GetSigmas(), ana::GetSpectrum(), make_pair(), nbins, cet::pow(), moon_position_table_new3::second, sigma(), canMan::sign(), and std::sqrt().

1320  {
1321 
1322  // Get nominal spectrum
1323  fSpectra[0] = make_pair(GetSpectrum(fNominalPred, true, sample, calc),
1324  GetSpectrum(fNominalPred, false, sample, calc));
1325 
1326  // Process all shifts
1327  for (const auto& shift : fShifts) {
1328  shift.second->ProcessShift(fSpectra[0], sample, calc);
1329  SystMakerShift* systShift = static_cast<SystMakerShift*>(shift.second);
1330  fShifts[shift.first] = systShift;
1331  }
1332 
1333  // Get total +1/-1 sigma systematic shift -- required
1334  // Also get total sigma shift for all sigmas in this syst
1335  vector<int> sigmas = this->GetSigmas();
1336  Int_t nbins = fSpectra[0].first->GetNbinsX();
1337  for (const auto& sigma : sigmas) {
1338  vector<double> evtDiffSig(nbins, 0.), evtDiffBg(nbins, 0.);
1339  TH1* shiftSig = (TH1*)fSpectra[0].first->Clone("shiftSig");
1340  TH1* shiftBkg = (TH1*)fSpectra[0].second->Clone("shiftBkg");
1341  double totShiftSig = 0., totShiftBkg = 0.;
1342  for (Int_t bin = 1; bin <= nbins; ++bin) {
1343  double valSig = 0., valBkg = 0.;
1344  // If there's more than one shift, we should add them in quadrature
1345  if (fShifts.size() > 1) {
1346  for (auto& shift : fShifts) {
1347  double binShiftSig = shift.second->GetShiftedSpectrum(sigma).first->GetBinContent(bin) -
1348  fSpectra[0].first->GetBinContent(bin);
1349  double binShiftBkg = shift.second->GetShiftedSpectrum(sigma).second->GetBinContent(bin) -
1350  fSpectra[0].second->GetBinContent(bin);
1351  valSig += pow(binShiftSig,2);
1352  valBkg += pow(binShiftBkg,2);
1353  }
1354  double sign = sigma > 0 ? 1.0 : -1.0;
1355  shiftSig->SetBinContent(bin, fSpectra[0].first->GetBinContent(bin) + (sign * sqrt(valSig)));
1356  shiftBkg->SetBinContent(bin, fSpectra[0].second->GetBinContent(bin) + (sign * sqrt(valBkg)));
1357  }
1358  // If there's only one shift, just use the raw value
1359  else {
1360  valSig = fShifts.begin()->second->GetShiftedSpectrum(sigma).first->GetBinContent(bin)
1361  - fSpectra[0].first->GetBinContent(bin);
1362  valBkg = fShifts.begin()->second->GetShiftedSpectrum(sigma).second->GetBinContent(bin)
1363  - fSpectra[0].second->GetBinContent(bin);
1364  shiftSig->SetBinContent(bin, fShifts.begin()->second->GetShiftedSpectrum(sigma).first->GetBinContent(bin));
1365  shiftBkg->SetBinContent(bin, fShifts.begin()->second->GetShiftedSpectrum(sigma).second->GetBinContent(bin));
1366  }
1367  totShiftSig += valSig;
1368  totShiftBkg += valBkg;
1369  }
1370  fTotalShifts[sigma] = make_pair(totShiftSig, totShiftBkg);
1371  fSpectra[sigma] = make_pair(shiftSig, shiftBkg);
1372  }
1373 
1374  } // function SystMaker::ProcessSyst
std::map< int, std::pair< double, double > > fTotalShifts
Definition: SystMaker.h:243
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
IPrediction * fNominalPred
Definition: SystMaker.h:250
T sqrt(T number)
Definition: d0nt_math.hpp:156
constexpr T pow(T x)
Definition: pow.h:75
std::vector< int > GetSigmas()
Get the sigmas for a given systematic shift.
Definition: SystMaker.cxx:989
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
const int nbins
Definition: cellShifts.C:15
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242
def sign(x)
Definition: canMan.py:197
void ana::SystMaker::SaveTo ( TDirectory *  dir) const

SaveTo implementation for SystMaker.

Definition at line 1450 of file SystMaker.cxx.

References fLabel, fName, fNominalPred, fSampleName, fShifts, ana::IPrediction::SaveTo(), tmp, and Write().

1450  {
1451 
1452  TDirectory* tmp = gDirectory;
1453 
1454  dir->cd();
1455  TObjString("SystMaker").Write("type");
1456 
1457  TObjString(fName.c_str()).Write("name");
1458  TObjString(fLabel.c_str()).Write("label");
1459  TObjString(fSampleName.c_str()).Write("samplename");
1460 
1461  fNominalPred->SaveTo(dir, "nompred");
1462 
1463  const char* shifts_dir = "Shifts";
1464  dir->mkdir("Shifts");
1465  for (const auto& shift : fShifts) {
1466  const char* shiftSubdir = Form("%s/%s", shifts_dir, shift.first.c_str());
1467  dir->mkdir(shiftSubdir);
1468  shift.second->SaveTo(dir->GetDirectory(shiftSubdir));
1469  }
1470 
1471  tmp->cd();
1472 
1473  } // function SystMaker::SaveTo
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
IPrediction * fNominalPred
Definition: SystMaker.h:250
Float_t tmp
Definition: plot.C:36
virtual void SaveTo(TDirectory *dir, const std::string &name) const
std::string fSampleName
Definition: SystMaker.h:239
std::string fName
Definition: SystMaker.h:237
TDirectory * dir
Definition: macro.C:5
std::string fLabel
Definition: SystMaker.h:238
gm Write()
void ana::SystMaker::SetAxes ( const HistAxis axis,
const HistAxis numuAxis = nullptr 
)

Definition at line 1377 of file SystMaker.cxx.

References allInOneTrainingPlots::axis, fAxis, and fNuMuAxis.

Referenced by ana::SystematicsMaker::AddSystematic().

1377  {
1378  fAxis = axis;
1379  fNuMuAxis = axis;
1380  }
const HistAxis * fNuMuAxis
Definition: SystMaker.h:245
const HistAxis * fAxis
Definition: SystMaker.h:245
void ana::SystMaker::SetCuts ( const Cut fd_cut,
const Cut nd_cut,
const Cut numu_cut = nullptr 
)

Definition at line 1383 of file SystMaker.cxx.

References fFDCut, fNDCut, and fNuMuCut.

Referenced by ana::SystematicsMaker::AddSystematic().

1383  {
1384  fNDCut = NDCut;
1385  fFDCut = FDCut;
1386  fNuMuCut = numuCut;
1387  }
const Cut * fFDCut
Definition: SystMaker.h:246
const Cut * fNDCut
Definition: SystMaker.h:246
const Cut * fNuMuCut
Definition: SystMaker.h:246
void ana::SystMaker::SetNominalLoaders ( Loaders loaders)

Definition at line 1390 of file SystMaker.cxx.

References fLoaders, and loaders.

Referenced by ana::SystematicsMaker::AddSystematic().

1390  {
1391  fLoaders = loaders;
1392  }
std::vector< Loaders * > loaders
Definition: syst_header.h:386
Loaders * fLoaders
Definition: SystMaker.h:247
void ana::SystMaker::SetNominalWeight ( const Var weight)

Definition at line 1395 of file SystMaker.cxx.

References fWeight, and ana::weight.

Referenced by ana::SystematicsMaker::AddSystematic().

1395  {
1396  fWeight = weight;
1397  }
const Var weight
const Var * fWeight
Definition: SystMaker.h:248
string ana::SystMaker::WriteTable ( std::string  name)

Write a table with up & down shifts for this systematic.

Definition at line 1236 of file SystMaker.cxx.

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

1236  {
1237 
1238  ostringstream table;
1239 
1240  table << "\\newcommand{\\" << name << "}\n";
1241  table << "{\\centerline{\n";
1242  table << "\\begin{tabular}{ l | r r r | r r }\n";
1243  table << " & Nom.&(+)&(-)&\\%(+)&\\%(-) \\\\ \\hline\n";
1244 
1245  // We write +1 and -1 sigmas to a table. First check they both exist!
1246  vector<int> sigmas = this->GetSigmas();
1247  if (find(sigmas.begin(), sigmas.end(), 1) == sigmas.end())
1248  assert(false and "+1 sigma shift required to call WriteTable()!");
1249  bool useDown = find(sigmas.begin(), sigmas.end(), -1) != sigmas.end();
1250 
1251  // Get nominal event counts for signal and background
1252  double sigNom = 0, bkgNom = 0;
1253  size_t nbins = fSpectra[0].first->GetNbinsX();
1254  for (size_t it = 1; it <= nbins; ++it) {
1255  sigNom += fSpectra[0].first->GetBinContent(it);
1256  bkgNom += fSpectra[0].second->GetBinContent(it);
1257  }
1258 
1259  // Now calculate the up and down totals
1260  double sigUp = sigNom, bkgUp = bkgNom, sigDown = 0, bkgDown = 0;
1261  if (useDown) {
1262  sigDown = sigNom;
1263  bkgDown = bkgNom;
1264  }
1265 
1266  for (auto& shift : fShifts) {
1267  for (size_t it = 1; it <= nbins; ++it) {
1268  sigUp += shift.second->GetShiftedSpectrum(1).first->GetBinContent(it)
1269  - fSpectra[0].first->GetBinContent(it);
1270  bkgUp += shift.second->GetShiftedSpectrum(1).second->GetBinContent(it)
1271  - fSpectra[0].second->GetBinContent(it);
1272  if (useDown) {
1273  sigDown += shift.second->GetShiftedSpectrum(-1).first->GetBinContent(it)
1274  - fSpectra[0].first->GetBinContent(it);
1275  bkgDown += shift.second->GetShiftedSpectrum(-1).second->GetBinContent(it)
1276  - fSpectra[0].second->GetBinContent(it);
1277  }
1278  }
1279  }
1280 
1281  // Write them to the table and return it
1282  table << "Signal & " << sigNom << " & " << sigUp << " & ";
1283  if (useDown) table << sigDown;
1284  else table << "N/A";
1285  table << " & " << 100*((sigUp/sigNom)-1) << " & ";
1286  if (useDown) table << 100*((sigDown/sigNom)-1);
1287  else table << "N/A";
1288  table << " \\\\\n";
1289  table << "Background & " << bkgNom << " & " << bkgUp << " & ";
1290  if (useDown) table << bkgDown;
1291  else table << "N/A";
1292  table << " & " << 100*((bkgUp/bkgNom)-1) << " & ";
1293  if (useDown) table << 100*((bkgDown/bkgNom)-1);
1294  else table << "N/A";
1295  table << " \\\\\n\\end{tabular}\n}}\n";
1296 
1297  return table.str();
1298 
1299  } // function SystMaker::WriteTable
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
std::map< std::string, SystMakerShift * > fShifts
Definition: SystMaker.h:241
std::vector< int > GetSigmas()
Get the sigmas for a given systematic shift.
Definition: SystMaker.cxx:989
const int nbins
Definition: cellShifts.C:15
assert(nhit_max >=nhit_nbins)
std::map< int, std::pair< TH1 *, TH1 * > > fSpectra
Definition: SystMaker.h:242

Member Data Documentation

const HistAxis* ana::SystMaker::fAxis
private

Definition at line 245 of file SystMaker.h.

Referenced by MakePredictions(), and SetAxes().

const Cut * ana::SystMaker::fFDCut
private

Definition at line 246 of file SystMaker.h.

Referenced by MakePredictions(), and SetCuts().

std::string ana::SystMaker::fLabel
private

Definition at line 238 of file SystMaker.h.

Referenced by MakeISyst(), PrintSyst(), and SaveTo().

Loaders* ana::SystMaker::fLoaders
private

Definition at line 247 of file SystMaker.h.

Referenced by MakePredictions(), and SetNominalLoaders().

std::string ana::SystMaker::fName
private

Definition at line 237 of file SystMaker.h.

Referenced by DrawSyst(), MakeISyst(), and SaveTo().

const Cut* ana::SystMaker::fNDCut
private

Definition at line 246 of file SystMaker.h.

Referenced by MakePredictions(), and SetCuts().

IPrediction* ana::SystMaker::fNominalPred
private

Definition at line 250 of file SystMaker.h.

Referenced by MakePredictions(), ProcessSyst(), SaveTo(), and ~SystMaker().

const HistAxis * ana::SystMaker::fNuMuAxis
private

Definition at line 245 of file SystMaker.h.

Referenced by MakePredictions(), and SetAxes().

const Cut * ana::SystMaker::fNuMuCut
private

Definition at line 246 of file SystMaker.h.

Referenced by MakePredictions(), and SetCuts().

std::string ana::SystMaker::fSampleName
private

Definition at line 239 of file SystMaker.h.

Referenced by MakeISyst(), and SaveTo().

std::map<std::string, SystMakerShift*> ana::SystMaker::fShifts
private
std::map<int, std::pair<TH1*, TH1*> > ana::SystMaker::fSpectra
private

Definition at line 242 of file SystMaker.h.

Referenced by DrawBkg(), DrawSig(), DrawSyst(), MakeISyst(), ProcessSyst(), and WriteTable().

std::map<int, std::pair<double, double> > ana::SystMaker::fTotalShifts
private

Definition at line 243 of file SystMaker.h.

Referenced by GetTotalShift(), PrintSyst(), and ProcessSyst().

const Var* ana::SystMaker::fWeight
private

Definition at line 248 of file SystMaker.h.

Referenced by MakePredictions(), and SetNominalWeight().


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