Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
ana::ModularExtrapComponent Class Referenceabstract

Base class for component extrapolation. More...

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

Inheritance diagram for ana::ModularExtrapComponent:
ana::FluxReweight ana::NoReweight ana::RecoReweight ana::TruthReweight

Classes

class  DivByZeroCounter
 

Public Member Functions

 ModularExtrapComponent ()
 
virtual ~ModularExtrapComponent ()
 
virtual void SaveTo (TDirectory *dir, const std::string &name) const =0
 
virtual void SavePlots (TDirectory *dir, double potFD) const =0
 
const OscillatableSpectrumReturn () const
 Interface so that result of Eval() is called only once and cached. More...
 
virtual const IDecompGetDecomp () const =0
 

Static Public Member Functions

static void SetQuiet (bool quiet=true)
 

Protected Member Functions

virtual OscillatableSpectrum Eval () const =0
 Core extrapolation math. More...
 

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 Attributes

bool fEvaluated
 
OscillatableSpectrum fCache
 

Static Private Attributes

static bool fQuiet = false
 

Detailed Description

Base class for component extrapolation.

Definition at line 21 of file ModularExtrapComponent.h.

Constructor & Destructor Documentation

ana::ModularExtrapComponent::ModularExtrapComponent ( )
inline
virtual ana::ModularExtrapComponent::~ModularExtrapComponent ( )
inlinevirtual

Definition at line 26 of file ModularExtrapComponent.h.

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

26 {};

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 
)
staticprotected

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)
staticprotected

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)
virtual OscillatableSpectrum ana::ModularExtrapComponent::Eval ( ) const
protectedpure virtual

Core extrapolation math.

Implemented in ana::RecoReweight, ana::TruthReweight, ana::NoReweight, and ana::FluxReweight.

Referenced by Return().

Ratio ana::ModularExtrapComponent::FormSmartRatio ( const Spectrum num,
const Spectrum denom,
std::string  component,
std::string  location,
const Spectrum mult 
)
staticprotected

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, 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)
virtual const IDecomp* ana::ModularExtrapComponent::GetDecomp ( ) const
pure virtual
Spectrum ana::ModularExtrapComponent::GetDecompResult ( const IDecomp decomp,
DecompResult  dr 
)
staticprotected
const OscillatableSpectrum & ana::ModularExtrapComponent::Return ( ) const

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

Definition at line 68 of file ModularExtrapComponent.cxx.

References Eval(), fCache, and 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.
virtual void ana::ModularExtrapComponent::SavePlots ( TDirectory *  dir,
double  potFD 
) const
pure virtual
virtual void ana::ModularExtrapComponent::SaveTo ( TDirectory *  dir,
const std::string name 
) const
pure virtual
static void ana::ModularExtrapComponent::SetQuiet ( bool  quiet = true)
inlinestatic
DecompResult ana::ModularExtrapComponent::StringToDR ( std::string  str)
staticprotected

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::ModularExtrapComponent::fCache
mutableprivate

Definition at line 77 of file ModularExtrapComponent.h.

Referenced by Return().

bool ana::ModularExtrapComponent::fEvaluated
mutableprivate

Definition at line 76 of file ModularExtrapComponent.h.

Referenced by Return().

bool ana::ModularExtrapComponent::fQuiet = false
staticprivate

Definition at line 78 of file ModularExtrapComponent.h.

Referenced by FormSmartRatio().


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