All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OscCurve.cxx
Go to the documentation of this file.
2 
6 
7 #include "OscLib/IOscCalc.h"
8 
9 #include <cassert>
10 #include <iostream>
11 #include <map>
12 
13 #include "TH1.h"
14 
16 
17 namespace
18 {
19  inline bool IsNoOscillations(const osc::IOscCalc* c)
20  {
21  return dynamic_cast<const osc::NoOscillations*>(c) != 0;
22  }
23 }
24 
25 namespace ana
26 {
27  //----------------------------------------------------------------------
28  OscCurve::OscCurve(osc::IOscCalc* calc, int from, int to, bool LoverE)
29  : fFrom(from), fTo(to)
30  {
31  DontAddDirectory guard;
32 
33  fHist = LoverE ? HistCache::New("True L / E (km / GeV);Probability", kTrueLOverEBins) : HistCache::New(";True Energy (GeV);Probability", kTrueEnergyBins);
34 
35  // We have extra knowledge that calculators of this type have special
36  // modes allowing calculation in L/E and an intrinsic energy smearing.
37  OscCalcSterileApprox* approx = DowncastToSterileApprox(calc, true);
38 
39  if(approx){
40  for(int i = 0; i < fHist->GetNbinsX()+2; ++i){
41  if(LoverE){
42  const double LElo = fHist->GetXaxis()->GetBinLowEdge(i);
43  const double LEhi = fHist->GetXaxis()->GetBinUpEdge(i);
44  fHist->SetBinContent(i, approx->P_LoverE(from, to, LElo, LEhi));
45  }
46  else{
47  const double E = fHist->GetBinCenter(i);
48  const double Elo = fHist->GetXaxis()->GetBinLowEdge(i);
49  const double Ehi = fHist->GetXaxis()->GetBinUpEdge(i);
50  // Use 2% resolution (intended to be << the resolution of any actual
51  // event) or the bin width, whichever is larger
52  fHist->SetBinContent(i, approx->P_range(from, to,
53  std::min(Elo, 0.98*E),
54  std::max(Ehi, 1.02*E)));
55  }
56  fHist->SetBinError(i, 0);
57  }
58  }
59  else{
60  if(LoverE && !IsNoOscillations(calc)){
61  std::cout << "Trying to use a calculator which is not OscCalcSterileApprox with an L/E axis. Will have to code up additional hacks for this to work" << std::endl;
62  abort();
63  }
64 
65  for(int i = 0; i < fHist->GetNbinsX()+2; ++i){
66  const double E = fHist->GetBinCenter(i);
67  fHist->SetBinContent(i, E > 0 ? calc->P(from, to, E) : 0);
68  fHist->SetBinError(i, 0);
69  }
70  }
71  }
72 
73  //----------------------------------------------------------------------
75  {
76  DontAddDirectory guard;
77 
78  const TString className = h->ClassName();
79 
80  if(className == "TH1D"){
81  // Shortcut if types match
82  fHist = HistCache::Copy((TH1D*)h);
83  }
84  else{
85  fHist = HistCache::New("", h->GetXaxis());
86  fHist->Add(h);
87  }
88 
89  fHist->SetTitle(";True Energy (GeV);Probability");
90  }
91 
92  //----------------------------------------------------------------------
94  {
95  if(fHist && fHist->GetDirectory()){
96  static bool once = true;
97  if(once){
98  once = false;
99  std::cerr << "OscCurve's fHist is associated with a directory. How did that happen?" << std::endl;
100  }
101  }
102 
104  }
105 
106  //----------------------------------------------------------------------
108  {
109  DontAddDirectory guard;
110 
111  assert(rhs.fHist);
112  fHist = HistCache::Copy(rhs.fHist);
113  }
114 
115  //----------------------------------------------------------------------
117  {
118  if(&rhs == this) return *this;
119 
120  DontAddDirectory guard;
121 
123  assert(rhs.fHist);
124  fHist = HistCache::Copy(rhs.fHist);
125  return *this;
126  }
127 
128  //----------------------------------------------------------------------
129  TH1D* OscCurve::ToTH1(bool title) const
130  {
131  // Could have a file temporarily open
132  DontAddDirectory guard;
133 
134  TH1D* ret = HistCache::Copy(fHist);
135 
136  if(title){
137  // Don't do this work unless it's explicitly requested
138  std::map<int, std::string> nus;
139  nus[12] = nus[-12] = "e";
140  nus[14] = nus[-14] = "#mu";
141  nus[16] = nus[-16] = "#tau";
142  nus[0] = "active";
143  const std::string nu = (fFrom > 0) ? "#nu" : "#bar#nu";
144 
145  ret->SetTitle((nu+"_{"+nus[fFrom]+"}#rightarrow"+nu+"_{"+nus[fTo]+"}").c_str());
146  }
147 
148  return ret;
149  }
150 }
double P_LoverE(int from, int to, double LElo, double LEhi)
TH1D * fHist
Definition: OscCurve.h:31
const OscCalcSterileApprox * DowncastToSterileApprox(const osc::IOscCalc *calc, bool allowFail)
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
BEGIN_PROLOG could also be cerr
process_name E
const Binning kTrueLOverEBins
Definition: Binning.h:74
process_name opflashCryoW ana
while getopts h
virtual ~OscCurve()
Definition: OscCurve.cxx:93
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
OscCurve(osc::IOscCalc *calc, int from, int to, bool LoverE)
Definition: OscCurve.cxx:28
TH1D * ToTH1(bool title=false) const
Definition: OscCurve.cxx:129
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:71
OscCurve & operator=(const OscCurve &rhs)
Definition: OscCurve.cxx:116
Transition probability for any one channel as a function of energy.
Definition: OscCurve.h:18
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:21
double P_range(int from, int to, double Elo, double Ehi)
Prevent histograms being added to the current directory.
BEGIN_PROLOG SN nu
BEGIN_PROLOG could also be cout