OscCurve.cxx
Go to the documentation of this file.
1 #include "CAFAna/Core/OscCurve.h"
2 
3 #include "CAFAna/Core/Binning.h"
4 
5 #include "OscLib/IOscCalc.h"
6 
7 #include <cassert>
8 #include <map>
9 
10 #include "TH1.h"
11 
12 namespace ana
13 {
14  //----------------------------------------------------------------------
15  /// Helper for constructors
16  template<class T> Eigen::Array<T, Eigen::Dynamic, 1>
17  ToEigen(osc::_IOscCalc<T>* calc, int from, int to)
18  {
19  const unsigned int N = kTrueEnergyBinCenters.size();
20 
21  // Have to allow for underflow and overflow
22  Eigen::Array<T, Eigen::Dynamic, 1> ret(N+2);
23  ret[0] = 0; // underflow
24  ret[N+1] = (from == to || to == 0) ? 1 : 0; // overflow
25 
26  const Eigen::Array<T, Eigen::Dynamic, 1> Ps = calc->P(from, to, kTrueEnergyBinCenters);
27 
28  // This is clumsy, but hopefully faster than calculating oscillation probs
29  // for two dummy values.
30  for(unsigned int i = 0; i < N; ++i) ret[i+1] = Ps[i];
31 
32  return ret;
33  }
34 
35  //----------------------------------------------------------------------
37  : Ratio(Hist::Adopt(ToEigen(calc, from, to)),
38  std::vector<Binning>(1, kTrueEnergyBins),
39  std::vector<std::string>(1, "True Energy (GeV)")),
40  fFrom(from), fTo(to)
41  {
42  }
43 
44  //----------------------------------------------------------------------
46  : Ratio(Hist::AdoptStan(ToEigen(calc, from, to)),
47  std::vector<Binning>(1, kTrueEnergyBins),
48  std::vector<std::string>(1, "True Energy (GeV)")),
49  fFrom(from), fTo(to)
50  {
51  }
52 
53  //----------------------------------------------------------------------
55  {
56  }
57 
58  //----------------------------------------------------------------------
59  TH1D* OscCurve::ToTH1(bool title) const
60  {
61  // Could have a file temporarily open
62  DontAddDirectory guard;
63 
64  TH1D* ret = Ratio::ToTH1();
65  ret->GetYaxis()->SetTitle("Probability");
66 
67  if(title){
68  // Don't do this work unless it's explicitly requested
69  std::map<int, std::string> nus;
70  nus[12] = nus[-12] = "e";
71  nus[14] = nus[-14] = "#mu";
72  nus[16] = nus[-16] = "#tau";
73  nus[0] = "active";
74  const std::string nu = (fFrom > 0) ? "#nu" : "#bar#nu";
75 
76  ret->SetTitle((nu+"_{"+nus[fFrom]+"}#rightarrow"+nu+"_{"+nus[fTo]+"}").c_str());
77  }
78 
79  return ret;
80  }
81 }
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:67
const std::vector< double > kTrueEnergyBinCenters
No entries for underflow or overflow.
Definition: Binning.h:16
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
Definition: Hist.h:29
Eigen::ArrayXd ToEigen(osc::IOscCalc *calc, int from, int to)
Helper for constructors.
Definition: NDOscCurve.cxx:17
OscCurve(osc::IOscCalc *calc, int from, int to)
Definition: OscCurve.cxx:36
osc::OscCalcDumb calc
virtual ~OscCurve()
Definition: OscCurve.cxx:54
TH1D * ToTH1(bool title=false) const
Definition: OscCurve.cxx:59
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:14
Represent the ratio between two spectra.
Definition: Ratio.h:8
virtual T P(int flavBefore, int flavAfter, double E)=0
E in GeV; flavors as PDG codes (so, neg==>antinu)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Prevent histograms being added to the current directory.
Definition: UtilsExt.h:46