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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-30/NuXAna/Systs/Nus18Systs.h"

Inheritance diagram for ana::Nus18SystFromHist:
ana::ISyst

Public Member Functions

 Nus18SystFromHist (const std::string &fname, const std::string &det, const std::string &polarity, const std::string &systname, const std::string &latexname)
 
 ~Nus18SystFromHist ()
 
void Shift (double sigma, caf::SRProxy *sr, double &weight) const override
 Perform the systematic shift. More...
 
double WeightFor (NusChannel chan, double sigma, double nueenergy) const
 
virtual const std::stringShortName () const final
 The name printed out to the screen. More...
 
virtual const std::stringLatexName () const final
 The name used on plots (ROOT's TLatex syntax) More...
 
virtual void TruthShift (double sigma, caf::SRNeutrinoProxy *nu, double &weight) const
 
virtual bool IsGenieReweight () const
 GENIE reweights can only provide +/-1,2sigma. More...
 

Private Member Functions

void LoadHists () const
 
NusChannel GetNusChannel (caf::SRProxy *sr) const
 

Private Attributes

std::string fFileName
 
std::string fDet
 
std::string fPolarity
 
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
 

Detailed Description

Nus group systematic applied as a shape shift, with shape information loaded from input histograms

Definition at line 40 of file Nus18Systs.h.

Constructor & Destructor Documentation

ana::Nus18SystFromHist::Nus18SystFromHist ( const std::string fname,
const std::string det,
const std::string polarity,
const std::string systname,
const std::string latexname 
)

Definition at line 227 of file Nus18Systs.cxx.

232  : ISyst(std::string(polarity)+std::string("_")+std::string(det)+std::string("_")+systname, latexname),
233  fFileName(fname),
234  fDet(det),
235  fPolarity(polarity) {
236  }
std::string fFileName
Definition: Nus18Systs.h:53
ISyst(const std::string &shortName, const std::string &latexName)
Definition: ISyst.cxx:10
std::string fPolarity
Definition: Nus18Systs.h:55
enum BeamMode string
ana::Nus18SystFromHist::~Nus18SystFromHist ( )

Definition at line 239 of file Nus18Systs.cxx.

239  {
240  }

Member Function Documentation

NusChannel ana::Nus18SystFromHist::GetNusChannel ( caf::SRProxy sr) const
private

Definition at line 293 of file Nus18Systs.cxx.

References ana::assert(), ana::kBG, ana::covmx::kNC, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, and caf::Proxy< caf::SRTruthBranch >::nu.

Referenced by Shift().

293  {
294  if (sr->mc.nnu == 0)
295  return NusChannel::kNC;
296  if (!sr->mc.nu[0].iscc)
297  return NusChannel::kNC;
298  if (sr->mc.nu[0].iscc)
299  return NusChannel::kBG;
300  assert(0 && "Unknown Oscillation Channel");
301  }
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:618
caf::Proxy< short int > nnu
Definition: SRProxy.h:617
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2138
assert(nhit_max >=nhit_nbins)
virtual bool ana::ISyst::IsGenieReweight ( ) const
inlinevirtualinherited

GENIE reweights can only provide +/-1,2sigma.

Reimplemented in ana::SummedSyst.

Definition at line 56 of file ISyst.h.

56 {return false;}
virtual const std::string& ana::ISyst::LatexName ( ) const
inlinefinalvirtualinherited

The name used on plots (ROOT's TLatex syntax)

Definition at line 30 of file ISyst.h.

References ana::ISyst::fLatexName, ana::ISyst::Shift(), sigma(), sr, and ana::weight.

Referenced by ana::PredictionInterp::DebugPlotColz(), GetGENIEShiftLabels(), ana::NuISyst::SaveTo(), SystsGENIEAna(), and WriteSystName().

30 {return fLatexName;}
std::string fLatexName
Definition: ISyst.h:60
void ana::Nus18SystFromHist::LoadHists ( ) const
private

Definition at line 243 of file Nus18Systs.cxx.

References channels, om::cout, allTimeWatchdog::endl, fDet, fFileName, fHists, fin, genie::utils::style::Format(), genie::utils::xml::GetString(), make_syst_table_plots::h, makeTrainCVSamples::int, ana::ISyst::ShortName(), and string.

Referenced by WeightFor().

243  {
244 
245  // Someone already called us
246  if (!fHists.empty())
247  return;
248 
249  TFile fin(fFileName.c_str(), "read");
250  if (fin.IsZombie()) {
251  std::cout << "Warning: couldn't open " << fFileName
252  << ". Crashing" << std::endl;
253  abort();
254  }
255 
256  std::vector<std::string> channels = {"NC", "BG"};
257 
258  const std::vector<int> sigmas = {-1, 0, +1};
259  const std::vector<std::string> sigstr = {"-1", "0", "+1"};
260 
261  for (int i_chan = 0; i_chan < (int)channels.size(); ++i_chan) {
262  std::vector< std::pair<int,TH1D*> > curHists;
263 
264  TString systShortName(ShortName().c_str());
265  TObjArray* systShortNames = systShortName.Tokenize("_");
266 
267  for(int i_sig = 0; i_sig < (int)sigmas.size(); ++i_sig) {
268  // Find histogram for given NusChannel at given sigma
269  std::string hName = TString::Format("h%s_%s_%s_%s",
270  channels[i_chan].c_str(),
271  fDet.c_str(),
272  ((TObjString*)systShortNames->At(2))->GetString().Data(),
273  sigstr[i_sig].c_str()).Data();
274  TH1D* h = (TH1D*)fin.Get(hName.c_str());
275  if (!h) {
276  // Surely it's a bad thing if we can't find nom, +-1 sigma hists
277  std::cout << "Error: can't find necessary " << hName
278  << " histogram in file " << fFileName
279  << ". Crashing" << std::endl;
280  abort();
281  }
282 
283  h->SetDirectory(0);
284  curHists.emplace_back(sigmas[i_sig], h);
285  }
286 
287  fHists.push_back(curHists);
288 
289  }
290  }
TString fin
Definition: Style.C:24
virtual const std::string & ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:27
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
Definition: Nus18Systs.h:63
std::map< ToFCounter, std::vector< unsigned int > > channels
OStream cout
Definition: OStream.cxx:6
std::string fFileName
Definition: Nus18Systs.h:53
string GetString(xmlDocPtr xml_doc, string node_path)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
enum BeamMode string
void ana::Nus18SystFromHist::Shift ( double  sigma,
caf::SRProxy sr,
double &  weight 
) const
overridevirtual

Perform the systematic shift.

Override this function if your systematic depends on non-SRNeutrino quantities. If it is SRNeutrino-only, implement the other function, and let this default forward to you when necessary.

Parameters
sigmaNumber of sigma to shift record by
srThe record to inspect and alter
weightScale this weight for reweighting systematics

Reimplemented from ana::ISyst.

Definition at line 337 of file Nus18Systs.cxx.

References febshutoff_auto::chan, caf::Proxy< caf::SRHeader >::det, fDet, GetNusChannel(), caf::Proxy< caf::StandardRecord >::hdr, caf::kFARDET, caf::kNEARDET, ana::kNus18Energy, and WeightFor().

338  {
339 
340  if(sr->hdr.det == caf::kFARDET &&
341  fDet.compare("FD") != 0 &&
342  fDet.compare("EX") != 0) { return; }
343  if(sr->hdr.det == caf::kNEARDET &&
344  fDet.compare("ND") != 0) { return; }
345 
346  // Find the energy estimate for this slice
347  double calE = kNus18Energy(sr);
348 
349  // Find the signal or background oscillation channel
351 
352  weight *= WeightFor(chan, sigma, calE);
353 
354  }
Near Detector underground.
Definition: SREnums.h:10
double WeightFor(NusChannel chan, double sigma, double nueenergy) const
Definition: Nus18Systs.cxx:304
Far Detector at Ash River.
Definition: SREnums.h:11
const Var kNus18Energy([](const caf::SRProxy *sr){bool h_FHC=sr->spill.isFHC;bool h_RHC=sr->spill.isRHC;double cale=sr->slc.calE;double recoE=0.;if(h_FHC &&sr->hdr.det==caf::kFARDET) recoE=FDscaleCalE18 *cale;else if(h_FHC &&sr->hdr.det==caf::kNEARDET) recoE=NDscaleCalE18 *cale;else if(h_RHC &&sr->hdr.det==caf::kFARDET) recoE=FDscaleCalE18RHC *cale;else if(h_RHC &&sr->hdr.det==caf::kNEARDET) recoE=NDscaleCalE18RHC *cale;return recoE;})
Definition: NusVars.h:63
const Var weight
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2137
double sigma(TH1F *hist, double percentile)
NusChannel
Definition: NusSysts.h:13
NusChannel GetNusChannel(caf::SRProxy *sr) const
Definition: Nus18Systs.cxx:293
caf::Proxy< caf::Det_t > det
Definition: SRProxy.h:232
virtual const std::string& ana::ISyst::ShortName ( ) const
inlinefinalvirtualinherited
virtual void ana::ISyst::TruthShift ( double  sigma,
caf::SRNeutrinoProxy nu,
double &  weight 
) const
inlinevirtualinherited

For systematics that deal only with the neutrino truth and not any reconstruction/PID details. Systematics defined this way will work on nuTree-derived spectra too (e.g. denominators of efficiencies).

Reimplemented in demo::DemoSyst1, ana::BeamSyst, ana::GenericSystComponentScale< T >, ana::GenericSystComponentScale< T >, ana::GenericSystComponentScale< T >, and ana::NOvARwgtSyst.

Definition at line 46 of file ISyst.h.

Referenced by ana::ISyst::Shift().

49  {
50  // Implement this function if your systematic depends only
51  // SRNeutrino. Left blank by default, since systematics using other
52  // information can do nothing sensible to the nuTree.
53  }
double ana::Nus18SystFromHist::WeightFor ( NusChannel  chan,
double  sigma,
double  nueenergy 
) const

Definition at line 304 of file Nus18Systs.cxx.

References ana::assert(), bin, febshutoff_auto::chan, fHists, MECModelEnuComparisons::i, makeTrainCVSamples::int, LoadHists(), std::max(), runNovaSAM::ret, moon_position_table_new3::second, and gen_flatrecord::size.

Referenced by Shift().

306  {
307  LoadHists();
308 
309  const int bin = fHists[chan][0].second->FindBin(calE);
310 
311  int LowIdx = 0;
312  if (sigma < fHists[chan].front().first)
313  LowIdx = 0;
314  else if (sigma >= fHists[chan].back().first)
315  LowIdx = fHists[chan].size()-2;
316  else {
317  for (int i = 0; i < (int)fHists[chan].size()-1; i++){
318  if (sigma >= fHists[chan][i].first){
319  LowIdx = i;
320  break;
321  }
322  }
323  }
324 
325  // Why would we have templates differing by more than 1 sigma?
326  // fracpart below assumes this
327  assert(fHists[chan][LowIdx+1].first - fHists[chan][LowIdx].first == 1);
328 
329  const double fracpart = sigma - fHists[chan][LowIdx].first;
330  const double ret = fracpart* fHists[chan][LowIdx+1].second->GetBinContent(bin) +
331  (1-fracpart)*fHists[chan][LowIdx] .second->GetBinContent(bin);
332 
333  return std::max(0., ret); // Keep the LL from blowing up
334  }
T max(const caf::Proxy< T > &a, T b)
void LoadHists() const
Definition: Nus18Systs.cxx:243
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
Definition: Nus18Systs.h:63
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
assert(nhit_max >=nhit_nbins)

Member Data Documentation

std::string ana::Nus18SystFromHist::fDet
private

Definition at line 54 of file Nus18Systs.h.

Referenced by LoadHists(), and Shift().

std::string ana::Nus18SystFromHist::fFileName
private

Definition at line 53 of file Nus18Systs.h.

Referenced by LoadHists().

std::vector< std::vector< std::pair<int, TH1D*> > > ana::Nus18SystFromHist::fHists
mutableprivate

Definition at line 63 of file Nus18Systs.h.

Referenced by LoadHists(), and WeightFor().

std::string ana::Nus18SystFromHist::fPolarity
private

Definition at line 55 of file Nus18Systs.h.


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