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/N21-02-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...
 
std::string SampleName () const
 
std::string BaseName () const
 Return base name of systematic. More...
 
virtual void SaveTo (TDirectory *dir, std::string type) const
 SaveTo implementation for NuISyst. 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 24 of file CovMxSysts.cxx.

26  : NuISyst(name, label, sampleName, shifts)
27  {}
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 67 of file CovMxSysts.cxx.

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

Referenced by ana::LoadSystsFromFile().

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

SaveTo implementation for NuISyst.

Definition at line 51 of file CovMxSysts.cxx.

References om::cout, allTimeWatchdog::endl, ana::NuISyst::fSampleName, ana::NuISyst::fShifts, ana::ISyst::LatexName(), ana::ISyst::ShortName(), sigma(), tmp, and Write().

51  {
52 
53  cout << "NuISyst::SaveTo implementation is a temporary hack that should be replaced once CommonAna migration is complete." << endl;
54 
55  TDirectory* tmp = gDirectory;
56  dir->cd();
57  TObjString(type.c_str()).Write("type");
58  TObjString(ShortName().c_str()).Write("name");
59  TObjString(LatexName().c_str()).Write("label");
60  TObjString(fSampleName.c_str()).Write("samplename");
61  TDirectory* sigmasDir = dir->mkdir("Sigmas");
62 
63  // Save each shift
64  for (auto const& sigma : fShifts) {
65 
66  TDirectory* sigmaDir = sigmasDir->mkdir(Form("Sigma%d", sigma.first));
67 
68  // Save sigma value
69  TVectorD vSigma(1);
70  vSigma[0] = sigma.first;
71  sigmaDir->WriteTObject(&vSigma, "sigma");
72 
73  // Save shift histograms
74  sigmaDir->WriteTObject(sigma.second.first, "sig");
75  sigmaDir->WriteTObject(sigma.second.second, "bkg");
76  }
77  tmp->cd();
78 
79  } // function NuISyst::SaveTo
virtual const std::string & ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:27
Float_t tmp
Definition: plot.C:36
std::string fSampleName
Definition: CovMxSysts.h:31
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
virtual const std::string & LatexName() const final
The name used on plots (ROOT&#39;s TLatex syntax)
Definition: ISyst.h:30
TDirectory * dir
Definition: macro.C:5
std::map< int, std::pair< TH1 *, TH1 * > > fShifts
Definition: CovMxSysts.h:32
gm Write()
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 31 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().

31  {
32 
33  // Find the energy estimate for this slice
34  double calE = kNus20Energy(sr);
35 
36  // Find the signal or background oscillation channel
38  if (sr->mc.nnu == 0)
39  chan = SystChannel::kBkg;
40  else if (!sr->mc.nu[0].iscc)
41  chan = SystChannel::kSig;
42  else if (sr->mc.nu[0].iscc)
43  chan = SystChannel::kBkg;
44  if (chan == SystChannel::kUnknown) {
45  cout << "Error: Unknown oscillation channel." << endl;
46  abort();
47  }
48 
49  weight *= WeightFor(chan, sigma, calE);
50 
51  } // 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:618
virtual double WeightFor(SystChannel channel, double sigma, double calE) const
Get weight for a given energy, channel and sigma shift.
Definition: CovMxSysts.cxx:83
caf::Proxy< short int > nnu
Definition: SRProxy.h:617
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:2138
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::NuISyst::WeightFor ( SystChannel  channel,
double  sigma,
double  calE 
) const
protectedvirtualinherited

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

Definition at line 83 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().

83  {
84 
85  // If it's a one-sided shift (ie. no -1 sigma weights) then we want to return
86  // 1 for a negative sigma
87  if (sigma < 0 and not fShifts.count(-1)) return 1;
88  const int bin = fShifts.at(0).first->FindBin(calE);
89 
90  auto low = fShifts.begin();
91  auto end = fShifts.end();
92  std::advance(end, -2);
93  if (sigma < fShifts.begin()->first)
94  low = fShifts.begin();
95  else if (sigma >= end->first)
96  low = end;
97  else {
98  for (auto it = fShifts.begin(); it != end; ++it) {
99  if (sigma >= it->first) {
100  low = it;
101  break;
102  }
103  }
104  }
105 
106  auto high = low;
107  ++high;
108 
109  // // Why would we have templates differing by more than 1 sigma?
110  // // fracpart below assumes this
111  assert(high->first - low->first == 1);
112 
113  TH1* hLow = nullptr;
114  TH1* hHigh = nullptr;
115 
116  if (channel == SystChannel::kSig) {
117  hLow = low->second.first;
118  hHigh = high->second.first;
119  }
120  else {
121  hLow = low->second.second;
122  hHigh = high->second.second;
123  }
124 
125  const double fracpart = sigma - low->first;
126  const double ret = (fracpart*hHigh->GetBinContent(bin)) +
127  ((1-fracpart)*hLow->GetBinContent(bin));
128 
129  return std::max(0., ret); // Keep the LL from blowing up
130 
131  } // 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: