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

"Extrapolates" component by returning FD Monte Carlo. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-30/CAFAna/Extrap/ModularExtrapComponent.h"

Inheritance diagram for ana::NoReweight:
ana::ModularExtrapComponent

Public Member Functions

 NoReweight (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &fdcut, const SystShifts &shiftMC, const Var &weight, const Cut &flavors, SpectrumLoaderBase &extraloaderswap=kNullLoader, SpectrumLoaderBase &extraloadertau=kNullLoader)
 
OscillatableSpectrum Eval () const override
 Core extrapolation math. More...
 
void SaveTo (TDirectory *dir, const std::string &name) const override
 
void SavePlots (TDirectory *dir, double potFD) const override
 
const IDecompGetDecomp () const override
 
const OscillatableSpectrumReturn () const
 Interface so that result of Eval() is called only once and cached. More...
 

Static Public Member Functions

static std::unique_ptr< NoReweightLoadFrom (TDirectory *dir, const std::string &name)
 
static void SetQuiet (bool quiet=true)
 

Static Protected Member Functions

static Spectrum GetDecompResult (const IDecomp &, DecompResult)
 Helper function to pick out single Spectrum from a decomposition. More...
 
static std::string DRToString (DecompResult)
 Helper function to turn a DecompResult into a string (for storage). More...
 
static DecompResult StringToDR (std::string)
 Helper function to turn a string into a DecompResult (for loading). More...
 
static Ratio FormSmartRatio (const Spectrum &num, const Spectrum &denom, std::string component, std::string location, const Spectrum &mult)
 Form Ratio, but be aware of zero division. More...
 
static void ComparisonPlot (Spectrum mc, Spectrum notMC, double pot, std::string notMCLabel, int notMCColor, std::string latex, std::string title, std::string saveAs, bool restrictRange=false)
 

Private Member Functions

 NoReweight (const OscillatableSpectrum &recoFD)
 

Private Attributes

OscillatableSpectrum fRecoFD
 

Detailed Description

"Extrapolates" component by returning FD Monte Carlo.

Definition at line 98 of file ModularExtrapComponent.h.

Constructor & Destructor Documentation

ana::NoReweight::NoReweight ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut fdcut,
const SystShifts shiftMC,
const Var weight,
const Cut flavors,
SpectrumLoaderBase extraloaderswap = kNullLoader,
SpectrumLoaderBase extraloadertau = kNullLoader 
)

Definition at line 167 of file ModularExtrapComponent.cxx.

References ana::SpectrumLoaderBase::AddReweightableSpectrum(), ana::flavors, fRecoFD, ana::_HistAxis< T >::GetVar1D(), ana::kTrueE, and ana::weight.

Referenced by LoadFrom().

176  : fRecoFD( loader, axis, fdcut && flavors, shiftMC, weight )
177  {
178  extraloaderswap.AddReweightableSpectrum(
179  fRecoFD, axis.GetVar1D(), kTrueE, fdcut && flavors, shiftMC, weight );
180  extraloadertau.AddReweightableSpectrum(
181  fRecoFD, axis.GetVar1D(), kTrueE, fdcut && flavors, shiftMC, weight );
182  }
const Var weight
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
std::vector< std::string > flavors
loader
Definition: demo0.py:10
OscillatableSpectrum fRecoFD
ana::NoReweight::NoReweight ( const OscillatableSpectrum recoFD)
inlineprivate

Definition at line 119 of file ModularExtrapComponent.h.

119 : fRecoFD(recoFD) {}
OscillatableSpectrum fRecoFD

Member Function Documentation

void ana::ModularExtrapComponent::ComparisonPlot ( Spectrum  mc,
Spectrum  notMC,
double  pot,
std::string  notMCLabel,
int  notMCColor,
std::string  latex,
std::string  title,
std::string  saveAs,
bool  restrictRange = false 
)
staticprotectedinherited

Definition at line 17 of file ModularExtrapComponentPlot.cxx.

References plot_validation_datamc::c, kRed, make_mec_shifts_plots::legend, and ana::Spectrum::ToTH1().

Referenced by ana::FluxReweight::SavePlots(), ana::TruthReweight::SavePlots(), and ana::RecoReweight::SavePlots().

27  {
28  TH1* histMC( mc.ToTH1(pot) );
29  TH1* histNotMC( notMC.ToTH1(pot) );
30  histMC->SetLineColor( kRed );
31  histNotMC->SetLineColor( notMCColor );
32  TCanvas c;
33  histMC->SetMaximum( 1.5 * histMC->GetMaximum() );
34  if (restrictRange) histMC->GetXaxis()->SetRangeUser( 0.5, 3.5);
35  histMC->SetTitle( (latex+" "+title).c_str() );
36  histMC->Draw("hist");
37  histNotMC->Draw("same");
38  TLegend legend( .15, .7, .4, .85 );
39  legend.SetTextSize(0.05);
40  legend.AddEntry( histNotMC, notMCLabel.c_str() );
41  legend.AddEntry( histMC, "MC" );
42  legend.SetFillStyle(0);
43  legend.Draw();
44  histMC->Write( (TString)"MC"+saveAs.c_str());
45  histNotMC->Write( (TString)notMCLabel.c_str() + saveAs.c_str());
46 
47  c.Write( saveAs.c_str() );
48  delete histMC;
49  delete histNotMC;
50  }
void latex(double x, double y, std::string txt, double ang=0, int align=22, double size=0.042)
enum BeamMode kRed
#define pot
std::string ana::ModularExtrapComponent::DRToString ( DecompResult  dr)
staticprotectedinherited

Helper function to turn a DecompResult into a string (for storage).

Definition at line 98 of file ModularExtrapComponent.cxx.

References ana::assert(), ana::NC, ana::NCbar, ana::NCtot, ana::nue, ana::nuebar, ana::numu, and ana::numubar.

Referenced by ana::TruthReweight::SaveTo(), and ana::RecoReweight::SaveTo().

100  {
101  switch (dr){
102  case DecompResult::nue : return "Nue";
103  case DecompResult::numu : return "Numu";
104  case DecompResult::nuebar : return "NueBar";
105  case DecompResult::numubar : return "NumuBar";
106  case DecompResult::NC : return "NC";
107  case DecompResult::NCbar : return "NCbar";
108  case DecompResult::NCtot : return "NCtot";
109  }
110  assert( 0 && "Bad DecompResult" );
111  }
assert(nhit_max >=nhit_nbins)
OscillatableSpectrum ana::NoReweight::Eval ( ) const
overridevirtual

Core extrapolation math.

Implements ana::ModularExtrapComponent.

Definition at line 184 of file ModularExtrapComponent.cxx.

References fRecoFD.

185  {return fRecoFD;}
OscillatableSpectrum fRecoFD
Ratio ana::ModularExtrapComponent::FormSmartRatio ( const Spectrum num,
const Spectrum denom,
std::string  component,
std::string  location,
const Spectrum mult 
)
staticprotectedinherited

Form Ratio, but be aware of zero division.

Necessary because root thinks n/0==0, so we lose events when low stats cause empty bins. If zero division occurs, ratio is set to 1 and warning is issued. If numerator is 0 and ratio will be multiplied by 0 later, the warning is suppressed.

Definition at line 130 of file ModularExtrapComponent.cxx.

References ana::assert(), bin, hadd_many_files::counter, ana::ModularExtrapComponent::DivByZeroCounter::fBins, ana::ModularExtrapComponent::fQuiet, ana::Spectrum::GetBinnings(), ana::Spectrum::GetEigen(), and ana::Spectrum::GetLabels().

Referenced by ana::FluxReweight::Eval(), ana::TruthReweight::Eval(), and ana::RecoReweight::Eval().

136  {
137  const Eigen::ArrayXd numa = num.GetEigen(1e20);
138  const Eigen::ArrayXd denoma = denom.GetEigen(1e20);
139  const Eigen::ArrayXd multa = mult.GetEigen(1e20);
140 
141  Eigen::ArrayXd ratioa = numa;
142  ratioa.setZero();
143 
144  assert( (numa.size() == denoma.size()) && "Bin Mismatch" );
145  assert( (numa.size() == multa.size()) && "Bin Mismatch" );
146 
147  static DivByZeroCounter counter;
148  for (int bin = 0; bin < numa.size(); ++bin)
149  {
150  if ( denoma[bin] != 0 ){
151  ratioa[bin] = numa[bin] / denoma[bin];
152  } else {
153  ratioa[bin] = 1;
154  if ( numa[bin] != 0
155  || multa[bin] != 0 )
156  counter.fBins.insert(std::make_tuple(component, location, bin));
157  }
158  }
159 
160  return Ratio( std::move(ratioa), num.GetLabels(), num.GetBinnings() );
161  }
#define location
float bin[41]
Definition: plottest35.C:14
int num
Definition: f2_nu.C:119
assert(nhit_max >=nhit_nbins)
const IDecomp* ana::NoReweight::GetDecomp ( ) const
inlineoverridevirtual

Implements ana::ModularExtrapComponent.

Definition at line 117 of file ModularExtrapComponent.h.

117 {return 0;}
Spectrum ana::ModularExtrapComponent::GetDecompResult ( const IDecomp decomp,
DecompResult  dr 
)
staticprotectedinherited
std::unique_ptr< NoReweight > ana::NoReweight::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 204 of file ModularExtrapComponent.cxx.

References ana::assert(), dir, ana::OscillatableSpectrum::LoadFrom(), and NoReweight().

Referenced by ana::LoadFrom< ModularExtrapComponent >().

205  {
206  dir = dir->GetDirectory(name.c_str()); // switch to subdir
207  assert(dir);
208 
209  std::unique_ptr<OscillatableSpectrum> s = OscillatableSpectrum::LoadFrom(dir, "RecoFD");
210 
211  delete dir;
212 
213  return std::unique_ptr<NoReweight>(new NoReweight(*s));
214  }
static std::unique_ptr< OscillatableSpectrum > LoadFrom(TDirectory *dir, const std::string &name)
const XML_Char * name
Definition: expat.h:151
const XML_Char * s
Definition: expat.h:262
NoReweight(SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &fdcut, const SystShifts &shiftMC, const Var &weight, const Cut &flavors, SpectrumLoaderBase &extraloaderswap=kNullLoader, SpectrumLoaderBase &extraloadertau=kNullLoader)
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
const OscillatableSpectrum & ana::ModularExtrapComponent::Return ( ) const
inherited

Interface so that result of Eval() is called only once and cached.

Definition at line 68 of file ModularExtrapComponent.cxx.

References ana::ModularExtrapComponent::Eval(), ana::ModularExtrapComponent::fCache, and ana::ModularExtrapComponent::fEvaluated.

Referenced by ana::FluxReweight::SavePlots(), ana::TruthReweight::SavePlots(), and ana::RecoReweight::SavePlots().

69  {
70  if (!fEvaluated)
71  {
72  fCache = Eval();
73  fEvaluated = true;
74  }
75  return fCache;
76  }
virtual OscillatableSpectrum Eval() const =0
Core extrapolation math.
void ana::NoReweight::SavePlots ( TDirectory *  dir,
double  potFD 
) const
overridevirtual

Implements ana::ModularExtrapComponent.

Definition at line 54 of file ModularExtrapComponentPlot.cxx.

References plot_validation_datamc::c, analysePickle::hist, kRed, and tmp.

55  {
56  TDirectory* tmp = gDirectory;
57  dir->cd();
58 
59  TH1* hist( fRecoFD.Unoscillated().ToTH1(potFD) );
60  hist->SetLineColor( kRed );
61  TCanvas c;
62  hist->SetMaximum( 1.5 * hist->GetMaximum() );
63  hist->SetTitle( "FD Reco Spectrum" );
64  hist->Draw("hist");
65  c.Write("MC");
66  delete hist;
67 
68  tmp->cd();
69  }
enum BeamMode kRed
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:148
Float_t tmp
Definition: plot.C:36
OscillatableSpectrum fRecoFD
TDirectory * dir
Definition: macro.C:5
void ana::NoReweight::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Implements ana::ModularExtrapComponent.

Definition at line 187 of file ModularExtrapComponent.cxx.

References dir, fRecoFD, ana::OscillatableSpectrum::SaveTo(), and tmp.

188  {
189  TDirectory* tmp = gDirectory;
190 
191  dir = dir->mkdir(name.c_str()); // switch to subdir
192  dir->cd();
193 
194  TObjString("NoReweight").Write("type");
195  fRecoFD.SaveTo(dir, "RecoFD");
196 
197  dir->Write();
198  delete dir;
199 
200  tmp->cd();
201  }
const XML_Char * name
Definition: expat.h:151
Float_t tmp
Definition: plot.C:36
OscillatableSpectrum fRecoFD
TDirectory * dir
Definition: macro.C:5
void SaveTo(TDirectory *dir, const std::string &name) const
static void ana::ModularExtrapComponent::SetQuiet ( bool  quiet = true)
inlinestaticinherited
DecompResult ana::ModularExtrapComponent::StringToDR ( std::string  str)
staticprotectedinherited

Helper function to turn a string into a DecompResult (for loading).

Definition at line 115 of file ModularExtrapComponent.cxx.

References ana::assert(), ana::NC, ana::NCbar, ana::NCtot, ana::nue, ana::nuebar, ana::numu, and ana::numubar.

Referenced by ana::TruthReweight::LoadFrom(), and ana::RecoReweight::LoadFrom().

117  {
118  if (str=="Nue") return DecompResult::nue;
119  else if (str=="Numu") return DecompResult::numu;
120  else if (str=="NueBar") return DecompResult::nuebar;
121  else if (str=="NumuBar") return DecompResult::numubar;
122  else if (str=="NC") return DecompResult::NC;
123  else if (str=="NCbar") return DecompResult::NCbar;
124  else if (str=="NCtot") return DecompResult::NCtot;
125  else assert( 0 && "Bad DecompResult String" );
126  }
assert(nhit_max >=nhit_nbins)

Member Data Documentation

OscillatableSpectrum ana::NoReweight::fRecoFD
private

Definition at line 121 of file ModularExtrapComponent.h.

Referenced by Eval(), NoReweight(), and SaveTo().


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