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

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

Inheritance diagram for ana::NCSyst:
ana::NuISyst ana::ISyst

Public Member Functions

 NCSyst (std::string name, std::string label, std::string sample_name="", std::map< int, std::pair< TH1 *, TH1 * > > shifts={})
 NCSyst. More...
 
virtual void Shift (double sigma, caf::SRProxy *sr, double &weight) const override
 Implementation of standard ISyst::Shift function for NCSyst. More...
 
virtual void SaveTo (TDirectory *dir) const override
 SaveTo implementation for NCSyst. 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< NCSystLoadFrom (TDirectory *dir)
 LoadFrom implementation for NCSyst. 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 8 of file CovMxSysts.h.

Constructor & Destructor Documentation

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

NCSyst.

Definition at line 22 of file CovMxSysts.cxx.

24  : NuISyst(name, label, sampleName, shifts)
25  {}
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< NCSyst > ana::NCSyst::LoadFrom ( TDirectory *  dir)
static

LoadFrom implementation for NCSyst.

Definition at line 65 of file CovMxSysts.cxx.

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

65  {
66 
67  DontAddDirectory guard;
68 
69  // Check this is a NueSyst
70  TObjString* tag = (TObjString*)dir->Get("type");
71  assert(tag);
72  string sTag = tag->GetString().Data();
73  assert(sTag == "NCSyst");
74 
75  // Load names
76  TObjString* name = (TObjString*)dir->Get("name");
77  assert(name);
78  string sName = name->GetString().Data();
79  TObjString* label = (TObjString*)dir->Get("label");
80  assert(label);
81  string sLabel = label->GetString().Data();
82  TObjString* sampleName = (TObjString*)dir->Get("samplename");
83  assert(sampleName);
84  string sSampleName = sampleName->GetString().Data();
85 
86  map<int, pair<TH1*, TH1*>> shifts;
87 
88  // Load all shifts
89  TIter next(dir->GetDirectory("Sigmas")->GetListOfKeys());
90  TKey* key;
91  while ((key = (TKey*)next())) {
92  TDirectory* sigmaDir = (TDirectory*)key->ReadObj();
93  const TVectorD vSigma = *(TVectorD*)sigmaDir->Get("sigma");
94  TH1* hSignal = (TH1*)sigmaDir->Get("sig");
95  TH1* hBackground = (TH1*)sigmaDir->Get("bkg");
96  shifts[vSigma[0]] = make_pair(hSignal, hBackground);
97  }
98 
99  return make_unique<NCSyst>(sName, sLabel, sSampleName, shifts);
100 
101  } // 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::NCSyst::SaveTo ( TDirectory *  dir) const
overridevirtual

SaveTo implementation for NCSyst.

Reimplemented from ana::NuISyst.

Definition at line 53 of file CovMxSysts.cxx.

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

53  {
54 
55  TDirectory* tmp = gDirectory;
56  dir->cd();
57  TObjString("NCSyst").Write("type");
58  tmp->cd();
60 
61  } // function NCSyst::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::NCSyst::Shift ( double  sigma,
caf::SRProxy sr,
double &  weight 
) const
overridevirtual

Implementation of standard ISyst::Shift function for NCSyst.

Reimplemented from ana::ISyst.

Definition at line 29 of file CovMxSysts.cxx.

References febshutoff_auto::chan, om::cout, allTimeWatchdog::endl, ana::kBkg, ana::kNus20Energy, ana::kSig, ana::kUnknown, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, caf::Proxy< caf::SRTruthBranch >::nu, and ana::NuISyst::WeightFor().

29  {
30 
31  // Find the energy estimate for this slice
32  double calE = kNus20Energy(sr);
33 
34  // Find the signal or background oscillation channel
36  if (sr->mc.nnu == 0)
37  chan = SystChannel::kBkg;
38  else if (!sr->mc.nu[0].iscc)
39  chan = SystChannel::kSig;
40  else if (sr->mc.nu[0].iscc)
41  chan = SystChannel::kBkg;
42  if (chan == SystChannel::kUnknown) {
43  cout << "Error: Unknown oscillation channel." << endl;
44  abort();
45  }
46 
47  weight *= WeightFor(chan, sigma, calE);
48 
49  } // function NCSyst::Shift
const Var weight
const Var kNus20Energy([](const caf::SRProxy *sr){if(sr->hdr.det!=caf::kNEARDET &&sr->hdr.det!=caf::kFARDET) return(double) sr->slc.calE;double pars[4][6]={{1.049, 0.795, 0.8409, 0.17, 0.82,-1.00},{1.025, 0.797, 0.9162, 0.53,-0.26,-1.48},{1.000, 1.000, 1.0000, 0.00, 0.00, 0.00},{1.000, 1.000, 1.0000, 0.00, 0.00, 0.00}};int detCur=(sr->hdr.det==caf::kFARDET)+((sr->spill.isRHC)<< 1);double e_EM=ana::kEME_2020(sr);double e_Had=ana::kHADE_2020(sr);double e_Cal=sr->slc.calE;return(e_EM/pars[detCur][0]+e_Had/pars[detCur][1])/(pars[detCur][2]+pars[detCur][3]*std::pow(e_Cal+pars[detCur][4], 2)*std::exp(pars[detCur][5]*e_Cal));})
Definition: NusVars.h:64
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:617
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:616
SystChannel
Definition: CovMxSysts.h:12
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2137
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 ana::NumuSyst::Shift(), 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: