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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-02-24/NuXAna/Systs/NusSysts.h"

Inheritance diagram for ana::NusSystFromHist:
ana::ISyst

Public Member Functions

 NusSystFromHist (const std::string &fname, const std::string &det, const std::string &shortname, const std::string &latexname)
 
 ~NusSystFromHist ()
 
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 18 of file NusSysts.h.

Constructor & Destructor Documentation

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

Definition at line 46 of file NusSysts.cxx.

50  : ISyst(shortname, latexname),
52  fDet(det)
53  {
54  }
std::string fFileName
Definition: NusSysts.h:31
ISyst(const std::string &shortName, const std::string &latexName)
Definition: ISyst.cxx:10
std::string fDet
Definition: NusSysts.h:32
ana::NusSystFromHist::~NusSystFromHist ( )

Definition at line 57 of file NusSysts.cxx.

58  {
59  }

Member Function Documentation

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

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

108  {
109  if(sr->mc.nnu == 0) { return NusChannel::kNC; }
110  if(!sr->mc.nu[0].iscc) { return NusChannel::kNC; }
111  if( sr->mc.nu[0].iscc) { return NusChannel::kBG; }
112  assert(0 && "Unknown Oscillation Channel");
113  }
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::NusSystFromHist::LoadHists ( ) const
private

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

63  {
64  // Someone already called us
65  if(!fHists.empty()) return;
66 
67  TFile fin(fFileName.c_str(), "read");
68  if(fin.IsZombie()) {
69  std::cout << "Warning: couldn't open " << fFileName
70  << ". Crashing" << std::endl;
71  abort();
72  }
73 
74  std::vector<std::string> channels = {"NC", "BG"};
75 
76  const std::vector<int> sigmas = {-1, 0, +1};
77  const std::vector<std::string> sigstr = {"-1", "0", "+1"};
78 
79  for(int i_chan = 0; i_chan < (int)channels.size(); ++i_chan) {
80  std::vector< std::pair<int,TH1D*> > curHists;
81 
82  for(int i_sig = 0; i_sig < (int)sigmas.size(); ++i_sig) {
83  // Find histogram for given NusChannel at given sigma
84  std::string hName = TString::Format("h%s_%s_%s_%s",
85  channels[i_chan].c_str(),
86  fDet.c_str(),
87  ShortName().c_str(),
88  sigstr[i_sig].c_str()).Data();
89  TH1D* h = (TH1D*)fin.Get(hName.c_str());
90  if(!h) {
91  // Surely it's a bad thing if we can't find nom, +-1 sigma hists
92  std::cout << "Error: can't find necessary " << hName
93  << " histogram in file " << fFileName
94  << ". Crashing" << std::endl;
95  abort();
96  }
97 
98  h->SetDirectory(0);
99  curHists.emplace_back(sigmas[i_sig], h);
100  }
101 
102  fHists.push_back(curHists);
103  }
104  }
TString fin
Definition: Style.C:24
std::string fFileName
Definition: NusSysts.h:31
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: NusSysts.h:40
std::map< ToFCounter, std::vector< unsigned int > > channels
OStream cout
Definition: OStream.cxx:6
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::string fDet
Definition: NusSysts.h:32
enum BeamMode string
void ana::NusSystFromHist::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 150 of file NusSysts.cxx.

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

152  {
153  if(sr->hdr.det == caf::kFARDET &&
154  fDet.compare("FD") != 0 &&
155  fDet.compare("EX") != 0) { return; }
156  if(sr->hdr.det == caf::kNEARDET &&
157  fDet.compare("ND") != 0) { return; }
158 
159  // Find the energy estimate for this slice
160  double calE = kCaloE(sr);
161 
162  // Find the signal or background oscillation channel
164 
165  weight *= WeightFor(chan, sigma, calE);
166  }
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
const Var kCaloE
Summed calorimetric energy of all hits in slice, uncorrected.
Definition: Vars.cxx:52
double sigma(TH1F *hist, double percentile)
NusChannel
Definition: NusSysts.h:13
double WeightFor(NusChannel chan, double sigma, double nueenergy) const
Definition: NusSysts.cxx:116
std::string fDet
Definition: NusSysts.h:32
NusChannel GetNusChannel(caf::SRProxy *sr) const
Definition: NusSysts.cxx:107
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 ana::BeamSyst, demo::DemoSyst1, ana::GenericSystComponentScale< T >, ana::GenericSystComponentScale< T >, ana::GenericSystComponentScale< T >, ana::ReinteractionSyst, 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::NusSystFromHist::WeightFor ( NusChannel  chan,
double  sigma,
double  nueenergy 
) const

Definition at line 116 of file NusSysts.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_hdf5record::size.

Referenced by Shift().

119  {
120  LoadHists();
121 
122  const int bin = fHists[chan][0].second->FindBin(calE);
123 
124  int LowIdx = 0;
125  if (sigma < fHists[chan].front().first)
126  LowIdx = 0;
127  else if (sigma >= fHists[chan].back().first)
128  LowIdx = fHists[chan].size()-2;
129  else{
130  for (int i = 0; i < (int)fHists[chan].size()-1; i++){
131  if (sigma >= fHists[chan][i].first){
132  LowIdx = i;
133  break;
134  }
135  }
136  }
137 
138  // Why would we have templates differing by more than 1 sigma?
139  // fracpart below assumes this
140  assert(fHists[chan][LowIdx+1].first - fHists[chan][LowIdx].first == 1);
141 
142  const double fracpart = sigma - fHists[chan][LowIdx].first;
143  const double ret = fracpart* fHists[chan][LowIdx+1].second->GetBinContent(bin) +
144  (1-fracpart)*fHists[chan][LowIdx] .second->GetBinContent(bin);
145 
146  return std::max(0., ret); // Keep the LL from blowing up
147  }
T max(const caf::Proxy< T > &a, T b)
std::vector< std::vector< std::pair< int, TH1D * > > > fHists
Definition: NusSysts.h:40
void LoadHists() const
Definition: NusSysts.cxx:62
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
assert(nhit_max >=nhit_nbins)

Member Data Documentation

std::string ana::NusSystFromHist::fDet
private

Definition at line 32 of file NusSysts.h.

Referenced by LoadHists(), and Shift().

std::string ana::NusSystFromHist::fFileName
private

Definition at line 31 of file NusSysts.h.

Referenced by LoadHists().

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

Definition at line 40 of file NusSysts.h.

Referenced by LoadHists(), and WeightFor().


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