All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NuMIFluxSysts.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 #include <cstdlib>
12 #include <iostream>
13 
14 namespace ana
15 {
16 
17  //----------------------------------------------------------------------
19  {
20  for(int i = 0; i < 2; ++i)
21  for(int j = 0; j < 2; ++j)
22  for(int k = 0; k < 2; ++k)
23  delete fScale[i][j][k];
24  }
25 
26  //----------------------------------------------------------------------
27  void NuMIFluxSyst::Shift(double sigma, caf::SRSliceProxy* slc, double& weight) const
28  {
29  if(slc->truth.index < 0) return; // No neutrino
30 
31  // TODO switch to regular detector flag as soon as it's filled reliably
32  if(slc->truth.baseline < 500){
33  std::cout << "Using NuMIFluxSyst on what appears not to be an icarus file (baseline = " << slc->truth.baseline << ")!" << std::endl;
34  abort();
35  }
36 
37  if(!fScale[0][0][0]){
38  const char* sbndata = getenv("SBNDATA_DIR");
39  if(!sbndata){
40  std::cout << "NuMIFluxSysts: $SBNDATA_DIR environment variable not set. Please setup the sbndata product." << std::endl;
41  abort();
42  }
43 
44  const std::string fname = std::string(sbndata)+"/beamData/NuMIdata/icarus_numi_flux_syst_ana.root";
45  TFile f(fname.c_str());
46  if(f.IsZombie()){
47  std::cout << "NuMIFluxSysts: Failed to open " << fname << std::endl;
48  abort();
49  }
50 
51  for(int hcIdx: {0, 1}){
52  for(int flavIdx: {0, 1}){
53  for(int signIdx: {0, 1}){
54  std::string hName = fHistName;
55  if(hcIdx == 0) hName += "_fhc"; else hName += "_rhc";
56  if(flavIdx == 0) hName += "_nue"; else hName += "_numu";
57  if(signIdx == 1) hName += "bar";
58 
59  TH1* h = (TH1*)f.Get(hName.c_str());
60  if(!h){
61  std::cout << "NuMIFluxSysts: failed to find " << hName << " in " << f.GetName() << std::endl;
62  abort();
63  }
64  h = (TH1*)h->Clone(UniqueName().c_str());
65  h->SetDirectory(0);
66 
67  fScale[hcIdx][flavIdx][signIdx] = h;
68  }
69  }
70  }
71  } // end if
72 
73  const int flav = abs(slc->truth.initpdg);
74  if(flav != 12 && flav != 14) return;
75 
76  const int hcIdx = 0; // TODO TODO always FHC
77  const int flavIdx = (flav == 12) ? 0 : 1;
78  const int signIdx = (slc->truth.initpdg > 0) ? 0 : 1;
79 
80  TH1* h = fScale[hcIdx][flavIdx][signIdx];
81  assert(h);
82 
83  const int bin = h->FindBin(slc->truth.E);
84 
85  if(bin == 0 || bin == h->GetNbinsX()+1) return;
86 
87  weight *= 1 + sigma*h->GetBinContent(bin);
88  }
89 
90  //----------------------------------------------------------------------
91  const NuMIFluxSyst* GetNuMIFluxSyst(const std::string& dir,
92  const std::string& prefix,
93  const std::string& name)
94  {
95  // Make sure we always give the same one back
96  static std::map<std::string, const NuMIFluxSyst*> cache;
97 
98  const std::string key = dir+"/"+prefix+name;
99  if(cache.count(key) == 0) cache[key] = new NuMIFluxSyst(dir, prefix, name);
100 
101  return cache[key];
102  }
103 
104  //----------------------------------------------------------------------
105  std::vector<const ISyst*> GetNuMIHadronProductionFluxSysts()
106  {
107  const std::vector<std::string> syst_names =
108  {
109  "pCpi",
110  "pCk",
111  "pCnu",
112  "nCpi",
113  "mesinc",
114  "nua",
115  "nuAlFe",
116  "attenuation",
117  "others"
118  };
119 
120  std::vector<const ISyst*> ret;
121  for(std::string name: syst_names)
122  ret.push_back(GetNuMIFluxSyst("fractional_uncertainties/hadron_production", "hfrac_", name));
123  return ret;
124  }
125 
126  //----------------------------------------------------------------------
127  std::vector<const ISyst*> GetNuMIBeamlineFluxSysts()
128  {
129  const std::vector<std::string> syst_names =
130  {
131  "horn_current",
132  "horn1_position_xy",
133  "horn2_position_xy",
134  "beam_shift_xy",
135  "target_position_z",
136  "beam_spot_size",
137  "water_layer",
138  "B_field",
139  "beam_divergence"
140  };
141 
142  std::vector<const ISyst*> ret;
143  for(std::string name: syst_names)
144  ret.push_back(GetNuMIFluxSyst("fractional_uncertainties/beamline", "hfrac_", name));
145  return ret;
146  }
147 
148  //----------------------------------------------------------------------
149  std::vector<const ISyst*> GetNuMIPCAFluxSysts(unsigned int Npcs)
150  {
151  std::vector<const ISyst*> ret;
152  for(unsigned int i = 0; i < Npcs; ++i){
153  ret.push_back(GetNuMIFluxSyst("principal_component_analysis",
154  "h", "pc"+std::to_string(i)));
155  }
156  return ret;
157  }
158 
159  //----------------------------------------------------------------------
160  std::vector<const ISyst*> GetAllNuMIFluxSysts(unsigned int Npcs)
161  {
162  std::vector<const ISyst*> ret = GetNuMIBeamlineFluxSysts();
163  std::vector<const ISyst*> add = GetNuMIPCAFluxSysts(Npcs);
164  ret.insert(ret.end(), add.begin(), add.end());
165  return ret;
166  }
167 } // namespace ana
string fname
Definition: demo.py:5
std::vector< const ISyst * > GetNuMIHadronProductionFluxSysts()
These are envelopes not real systs. TODO make clearer in naming.
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.
const NuMIFluxSyst * GetNuMIFluxSyst(const std::string &dir, const std::string &prefix, const std::string &name)
while getopts h
T abs(T value)
std::vector< const ISyst * > GetAllNuMIFluxSysts(unsigned int Npcs)
Combination of all beamline systs plus Npcs hadron production components.
std::vector< const ISyst * > GetNuMIPCAFluxSysts(unsigned int Npcs)
tuple dir
Definition: dropbox.py:28
void Shift(double sigma, caf::SRSliceProxy *slc, double &weight) const override
Perform the systematic shift.
std::vector< const ISyst * > GetNuMIBeamlineFluxSysts()
TH1 * fScale[2][2][2]
Definition: NuMIFluxSysts.h:34
std::string fHistName
Definition: NuMIFluxSysts.h:32
std::string to_string(WindowPattern const &pattern)
then echo fcl name
pdgs k
Definition: selectors.fcl:22
virtual ~NuMIFluxSyst()
std::string UniqueName()
Return a different string each time, for creating histograms.
BEGIN_PROLOG could also be cout