All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoosterFluxSysts.cxx
Go to the documentation of this file.
2 
4 
5 #include "sbnanaobj/StandardRecord/Proxy/SRProxy.h"
6 
7 #include "TFile.h"
8 #include "TH1.h"
9 
10 #include <cassert>
11 
12 namespace ana {
13 
14 //----------------------------------------------------------------------
16 {
17  for(int i = 0; i < 3; ++i) delete fScale[i];
18 }
19 
20 //----------------------------------------------------------------------
21 void BoosterFluxHadronSyst::Shift(double sigma, caf::SRSliceProxy* slc, double &weight) const
22 {
23  // Only implemented for numus so far
24  if(/*sr->mc.nnu == 0 ||*/ slc->truth.initpdg != 14) return;
25 
26  if(!fScale[0]){
27  TFile f((FindCAFAnaDir() + "/Systs/booster_flux_shifts.root").c_str());
28  assert(!f.IsZombie());
29 
30  for(int det = 0; det < 3; ++det){
31  std::string detStr;
32  if(det == 0) detStr = "nd";
33  if(det == 1) detStr = "ub";
34  if(det == 2) detStr = "fd";
35 
36  TH1*& h = fScale[det];
37 
38  h = (TH1*)f.Get(TString::Format("syst%d/%s_numu", fIdx, detStr.c_str()).Data());
39  h = (TH1*)h->Clone(UniqueName().c_str());
40  assert(h);
41  h->SetDirectory(0);
42  }
43  } // end if
44 
45  // TODO use the regular detector flag as soon as it's filled reliably
46  int det;
47  const double L = slc->truth.baseline;
48  if(L < 150) det = 0;
49  else if(L < 500) det = 1;
50  else det = 2;
51 
52  TH1* h = fScale[det];
53  assert(h);
54 
55  const int bin = h->FindBin(slc->truth.E);
56 
57  if(bin == 0 || bin == h->GetNbinsX()+1) return;
58 
59  weight *= exp(sigma*h->GetBinContent(bin));
60 }
61 
62 //----------------------------------------------------------------------
64 {
65  // Make sure we always give the same one back
66  static std::vector<const BoosterFluxHadronSyst*> cache;
67 
68  if(i >= cache.size()) cache.resize(i+1);
69 
70  if(!cache[i]) cache[i] = new BoosterFluxHadronSyst(i);
71 
72  return cache[i];
73 }
74 
75 //----------------------------------------------------------------------
77 {
79  for(unsigned int i = 0; i < N; ++i)
80  ret.push_back(GetBoosterFluxHadronSyst(i));
81 
82  return ret;
83 }
84 
85 } // namespace ana
const BoosterFluxHadronSyst * GetBoosterFluxHadronSyst(unsigned int i)
void Shift(double sigma, caf::SRSliceProxy *slc, double &weight) const override
Perform the systematic shift.
process_name opflashCryoW ana
caf::Proxy< caf::SRSlice > SRSliceProxy
Definition: EpilogFwd.h:2
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
while getopts h
BoosterFluxHadronSystVector GetBoosterFluxHadronSysts(unsigned int N)
process_name largeant stream1 can override from command line with o or output physics producers generator N
std::string UniqueName()
Return a different string each time, for creating histograms.