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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/3FlavorAna/Systs/CovMxSysts.h"

Inheritance diagram for ana::NumuSyst:
ana::NuISyst ana::ISyst

Public Member Functions

 NumuSyst (std::string name, std::string label, std::string sample_name="", std::map< int, std::pair< TH1 *, TH1 * > > shifts={})
 NumuSyst basic constructor. More...
 
virtual void Shift (double sigma, caf::SRProxy *sr, double &weight) const override
 Implementation of standard ISyst::Shift function for NumuSyst. More...
 
virtual void SaveTo (TDirectory *dir) const override
 SaveTo implementation for NumuSyst. More...
 
std::string SampleName () const
 
std::string BaseName () const
 Return base name of systematic. More...
 
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...
 

Static Public Member Functions

static std::unique_ptr< NumuSystLoadFrom (TDirectory *dir)
 LoadFrom implementation for NumuSyst. More...
 

Protected Member Functions

virtual double WeightFor (SystChannel channel, double sigma, double calE) const
 Get weight for a given energy, channel and sigma shift. More...
 

Protected Attributes

std::string fSampleName
 
std::map< int, std::pair< TH1 *, TH1 * > > fShifts
 

Detailed Description

Definition at line 7 of file CovMxSysts.h.

Constructor & Destructor Documentation

ana::NumuSyst::NumuSyst ( std::string  name,
std::string  label,
std::string  sample_name = "",
std::map< int, std::pair< TH1 *, TH1 * > >  shifts = {} 
)

NumuSyst basic constructor.

Definition at line 26 of file CovMxSysts.cxx.

28  : NuISyst(name, label, sampleName, shifts)
29  {}
const XML_Char * name
Definition: expat.h:151
NuISyst(std::string name, std::string label, std::string sample_name="", std::map< int, std::pair< TH1 *, TH1 * > > shifts={})
Definition: CovMxSysts.cxx:24
const char * label

Member Function Documentation

string ana::NuISyst::BaseName ( ) const
inherited

Return base name of systematic.

Definition at line 44 of file CovMxSysts.cxx.

References ana::NuISyst::fSampleName, and ana::ISyst::ShortName().

44  {
45  if (fSampleName.empty()) return ShortName(); // If there's no sample prefix to remove
46  return ShortName().substr(fSampleName.size()+1);
47  }
virtual const std::string & ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:27
std::string fSampleName
Definition: CovMxSysts.h:31
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
unique_ptr< NumuSyst > ana::NumuSyst::LoadFrom ( TDirectory *  dir)
static

LoadFrom implementation for NumuSyst.

Definition at line 77 of file CovMxSysts.cxx.

References ana::assert(), findDuplicateFiles::key, label, make_pair(), next(), and getGoodRuns4SAM::tag.

77  {
78 
79  DontAddDirectory guard;
80 
81  // Check this is a NumuSyst
82  TObjString* tag = (TObjString*)dir->Get("type");
83  assert(tag);
84  string sTag = tag->GetString().Data();
85  assert(sTag == "NumuSyst");
86 
87  // Load names
88  TObjString* name = (TObjString*)dir->Get("name");
89  assert(name);
90  string sName = name->GetString().Data();
91  TObjString* label = (TObjString*)dir->Get("label");
92  assert(label);
93  string sLabel = label->GetString().Data();
94  TObjString* sampleName = (TObjString*)dir->Get("samplename");
95  assert(sampleName);
96  string sSampleName = sampleName->GetString().Data();
97 
98  map<int, pair<TH1*, TH1*>> shifts;
99 
100  // Load all shifts
101  TIter next(dir->GetDirectory("Sigmas")->GetListOfKeys());
102  TKey* key;
103  while ((key = (TKey*)next())) {
104  TDirectory* sigmaDir = (TDirectory*)key->ReadObj();
105  const TVectorD vSigma = *(TVectorD*)sigmaDir->Get("sigma");
106  TH1* hSignal = (TH1*)sigmaDir->Get("sig");
107  TH1* hBackground = (TH1*)sigmaDir->Get("bkg");
108  shifts[vSigma[0]] = make_pair(hSignal, hBackground);
109  }
110 
111  return make_unique<NumuSyst>(sName, sLabel, sSampleName, shifts);
112 
113  } // function NumuSyst::SaveTo
const XML_Char * name
Definition: expat.h:151
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
const char * label
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void next()
Definition: show_event.C:84
std::string ana::NuISyst::SampleName ( ) const
inlineinherited

Definition at line 25 of file CovMxSysts.h.

References dir, ana::SaveTo(), sigma(), and string.

25 { return fSampleName; };
std::string fSampleName
Definition: CovMxSysts.h:31
void ana::NumuSyst::SaveTo ( TDirectory *  dir) const
overridevirtual

SaveTo implementation for NumuSyst.

Reimplemented from ana::NuISyst.

Definition at line 65 of file CovMxSysts.cxx.

References ana::NuISyst::SaveTo(), and tmp.

65  {
66 
67  TDirectory* tmp = gDirectory;
68  dir->cd();
69  TObjString("NumuSyst").Write("type");
70  tmp->cd();
72 
73  } // function NumuSyst::SaveTo
Float_t tmp
Definition: plot.C:36
TDirectory * dir
Definition: macro.C:5
virtual void SaveTo(TDirectory *dir) const
SaveTo implementation for NuISyst.
Definition: CovMxSysts.cxx:51
void ana::NumuSyst::Shift ( double  sigma,
caf::SRProxy sr,
double &  weight 
) const
overridevirtual

Implementation of standard ISyst::Shift function for NumuSyst.

Reimplemented from ana::ISyst.

Definition at line 33 of file CovMxSysts.cxx.

References febshutoff_auto::chan, om::cout, allTimeWatchdog::endl, caf::Proxy< caf::SRSpill >::isFHC, caf::Proxy< caf::SRSpill >::isRHC, ana::kBkg, ana::kNumuE2020, ana::kSig, ana::kUnknown, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, caf::Proxy< caf::SRTruthBranch >::nu, canMan::sign(), caf::Proxy< caf::StandardRecord >::spill, and ana::NuISyst::WeightFor().

33  {
34 
35  // Find the energy estimate for this slice
36  double calE = kNumuE2020(sr);
37 
38  // Find the signal or background oscillation channel
40  int sign;
41  if (sr->spill.isFHC) sign = 1;
42  else if (sr->spill.isRHC) sign = -1;
43  else throw runtime_error("Event is neither FHC nor RHC!");
44 
45  if (sr->mc.nnu == 0) {
46  chan = SystChannel::kBkg;
47  }
48  else if (sr->mc.nu[0].iscc && sr->mc.nu[0].pdg == sign*14 && sr->mc.nu[0].pdgorig == sign*14) {
49  chan = SystChannel::kSig;
50  }
51  else if (!sr->mc.nu[0].iscc || sr->mc.nu[0].pdg != sign*14 || sr->mc.nu[0].pdgorig != sign*14) {
52  chan = SystChannel::kBkg;
53  }
54  if (chan == SystChannel::kUnknown) {
55  cout << "Error: Unknown oscillation channel." << endl;
56  abort();
57  }
58 
59  weight *= WeightFor(chan, sigma, calE);
60 
61  } // function NumuSyst::Shift
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:2143
const Var weight
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:618
virtual double WeightFor(SystChannel channel, double sigma, double calE) const
Get weight for a given energy, channel and sigma shift.
Definition: CovMxSysts.cxx:80
caf::Proxy< short int > nnu
Definition: SRProxy.h:617
SystChannel
Definition: CovMxSysts.h:12
const Var kNumuE2020
Definition: NumuEFxs.h:217
caf::Proxy< bool > isFHC
Definition: SRProxy.h:1375
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2138
caf::Proxy< bool > isRHC
Definition: SRProxy.h:1376
def sign(x)
Definition: canMan.py:197
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::NuISyst::WeightFor ( SystChannel  channel,
double  sigma,
double  calE 
) const
protectedvirtualinherited

Get weight for a given energy, channel and sigma shift.

Definition at line 80 of file CovMxSysts.cxx.

References ana::assert(), bin, febshutoff_auto::end, ana::NuISyst::fShifts, it, ana::kSig, std::max(), and runNovaSAM::ret.

Referenced by Shift(), ana::NCSyst::Shift(), and ana::NueSyst::Shift().

80  {
81 
82  // If it's a one-sided shift (ie. no -1 sigma weights) then we want to return
83  // 1 for a negative sigma
84  if (sigma < 0 and not fShifts.count(-1)) return 1;
85  const int bin = fShifts.at(0).first->FindBin(calE);
86 
87  auto low = fShifts.begin();
88  auto end = fShifts.end();
89  std::advance(end, -2);
90  if (sigma < fShifts.begin()->first)
91  low = fShifts.begin();
92  else if (sigma >= end->first)
93  low = end;
94  else {
95  for (auto it = fShifts.begin(); it != end; ++it) {
96  if (sigma >= it->first) {
97  low = it;
98  break;
99  }
100  }
101  }
102 
103  auto high = low;
104  ++high;
105 
106  // // Why would we have templates differing by more than 1 sigma?
107  // // fracpart below assumes this
108  assert(high->first - low->first == 1);
109 
110  TH1* hLow = nullptr;
111  TH1* hHigh = nullptr;
112 
113  if (channel == SystChannel::kSig) {
114  hLow = low->second.first;
115  hHigh = high->second.first;
116  }
117  else {
118  hLow = low->second.second;
119  hHigh = high->second.second;
120  }
121 
122  const double fracpart = sigma - low->first;
123  const double ret = (fracpart*hHigh->GetBinContent(bin)) +
124  ((1-fracpart)*hLow->GetBinContent(bin));
125 
126  return std::max(0., ret); // Keep the LL from blowing up
127 
128  } // function NuISyst::WeightFor
T max(const caf::Proxy< T > &a, T b)
set< int >::iterator it
float bin[41]
Definition: plottest35.C:14
double sigma(TH1F *hist, double percentile)
std::map< int, std::pair< TH1 *, TH1 * > > fShifts
Definition: CovMxSysts.h:32
assert(nhit_max >=nhit_nbins)

Member Data Documentation

std::string ana::NuISyst::fSampleName
protectedinherited

Definition at line 31 of file CovMxSysts.h.

Referenced by ana::NuISyst::BaseName(), and ana::NuISyst::SaveTo().

std::map<int, std::pair<TH1*, TH1*> > ana::NuISyst::fShifts
protectedinherited

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