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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/NuXAna/Systs/Nus17Systs.h"

Inheritance diagram for ana::Nus17SystFromHist:
ana::ISyst

Public Member Functions

 Nus17SystFromHist (const std::string &fname, const std::string &det, const std::string &shortname, const std::string &latexname)
 
 ~Nus17SystFromHist ()
 
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::vector< std::vector< std::pair< int, TH1D * > > > fHists
 

Detailed Description

Definition at line 16 of file Nus17Systs.h.

Constructor & Destructor Documentation

ana::Nus17SystFromHist::Nus17SystFromHist ( const std::string fname,
const std::string det,
const std::string shortname,
const std::string latexname 
)

Definition at line 67 of file Nus17Systs.cxx.

71  : ISyst(shortname, latexname),
73  fDet(det)
74  {
75  }
ISyst(const std::string &shortName, const std::string &latexName)
Definition: ISyst.cxx:10
std::string fFileName
Definition: Nus17Systs.h:29
ana::Nus17SystFromHist::~Nus17SystFromHist ( )

Definition at line 78 of file Nus17Systs.cxx.

79  {
80  }

Member Function Documentation

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

Definition at line 128 of file Nus17Systs.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().

129  {
130  if(sr->mc.nnu == 0) { return NusChannel::kNC; }
131  if(!sr->mc.nu[0].iscc) { return NusChannel::kNC; }
132  if( sr->mc.nu[0].iscc) { return NusChannel::kBG; }
133  assert(0 && "Unknown Oscillation Channel");
134  }
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::Nus17SystFromHist::LoadHists ( ) const
private

Definition at line 83 of file Nus17Systs.cxx.

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

Referenced by WeightFor().

84  {
85  // Someone already called us
86  if(!fHists.empty()) return;
87 
88  TFile fin(fFileName.c_str(), "read");
89  if(fin.IsZombie()) {
90  std::cout << "Warning: couldn't open " << fFileName
91  << ". Crashing" << std::endl;
92  abort();
93  }
94 
95  std::vector<std::string> channels = {"NC", "BG"};
96 
97  const std::vector<int> sigmas = {-1, 0, +1};
98  const std::vector<std::string> sigstr = {"-1", "0", "+1"};
99 
100  for(int i_chan = 0; i_chan < (int)channels.size(); ++i_chan) {
101  std::vector< std::pair<int,TH1D*> > curHists;
102 
103  for(int i_sig = 0; i_sig < (int)sigmas.size(); ++i_sig) {
104  // Find histogram for given NusChannel at given sigma
105  std::string hName = TString::Format("h%s_%s_%s_%s",
106  channels[i_chan].c_str(),
107  fDet.c_str(),
108  ShortName().c_str(),
109  sigstr[i_sig].c_str()).Data();
110  TH1D* h = (TH1D*)fin.Get(hName.c_str());
111  if(!h) {
112  // Surely it's a bad thing if we can't find nom, +-1 sigma hists
113  std::cout << "Error: can't find necessary " << hName
114  << " histogram in file " << fFileName
115  << ". Crashing" << std::endl;
116  abort();
117  }
118 
119  h->SetDirectory(0);
120  curHists.emplace_back(sigmas[i_sig], h);
121  }
122 
123  fHists.push_back(curHists);
124  }
125  }
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::map< ToFCounter, std::vector< unsigned int > > channels
OStream cout
Definition: OStream.cxx:6
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
Definition: Nus17Systs.h:38
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::string fFileName
Definition: Nus17Systs.h:29
enum BeamMode string
void ana::Nus17SystFromHist::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 171 of file Nus17Systs.cxx.

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

173  {
174  if(sr->hdr.det == caf::kFARDET &&
175  fDet.compare("FD") != 0 &&
176  fDet.compare("EX") != 0) { return; }
177  if(sr->hdr.det == caf::kNEARDET &&
178  fDet.compare("ND") != 0) { return; }
179 
180  // Find the energy estimate for this slice
181  double calE = kNus17Energy(sr);
182 
183 
184  // Find the signal or background oscillation channel
186 
187  weight *= WeightFor(chan, sigma, calE);
188  }
Near Detector underground.
Definition: SREnums.h:10
Far Detector at Ash River.
Definition: SREnums.h:11
const Var weight
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2137
NusChannel GetNusChannel(caf::SRProxy *sr) const
Definition: Nus17Systs.cxx:128
const Var kNus17Energy([](const caf::SRProxy *sr){double cale=sr->slc.calE;double recoE=0.;if(sr->hdr.det==caf::kFARDET) recoE=FDscaleCalE17 *cale;if(sr->hdr.det==caf::kNEARDET) recoE=NDscaleCalE17 *cale;return recoE;})
Definition: NusVars.h:62
double WeightFor(NusChannel chan, double sigma, double nueenergy) const
Definition: Nus17Systs.cxx:137
double sigma(TH1F *hist, double percentile)
NusChannel
Definition: NusSysts.h:13
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::Nus17SystFromHist::WeightFor ( NusChannel  chan,
double  sigma,
double  nueenergy 
) const

Definition at line 137 of file Nus17Systs.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().

140  {
141  LoadHists();
142 
143  const int bin = fHists[chan][0].second->FindBin(calE);
144 
145  int LowIdx = 0;
146  if (sigma < fHists[chan].front().first)
147  LowIdx = 0;
148  else if (sigma >= fHists[chan].back().first)
149  LowIdx = fHists[chan].size()-2;
150  else{
151  for (int i = 0; i < (int)fHists[chan].size()-1; i++){
152  if (sigma >= fHists[chan][i].first){
153  LowIdx = i;
154  break;
155  }
156  }
157  }
158 
159  // Why would we have templates differing by more than 1 sigma?
160  // fracpart below assumes this
161  assert(fHists[chan][LowIdx+1].first - fHists[chan][LowIdx].first == 1);
162 
163  const double fracpart = sigma - fHists[chan][LowIdx].first;
164  const double ret = fracpart* fHists[chan][LowIdx+1].second->GetBinContent(bin) +
165  (1-fracpart)*fHists[chan][LowIdx] .second->GetBinContent(bin);
166 
167  return std::max(0., ret); // Keep the LL from blowing up
168  }
T max(const caf::Proxy< T > &a, T b)
void LoadHists() const
Definition: Nus17Systs.cxx:83
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
Definition: Nus17Systs.h:38
assert(nhit_max >=nhit_nbins)

Member Data Documentation

std::string ana::Nus17SystFromHist::fDet
private

Definition at line 30 of file Nus17Systs.h.

Referenced by LoadHists(), and Shift().

std::string ana::Nus17SystFromHist::fFileName
private

Definition at line 29 of file Nus17Systs.h.

Referenced by LoadHists().

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

Definition at line 38 of file Nus17Systs.h.

Referenced by LoadHists(), and WeightFor().


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