make_nueFDprediction_kinematics_FHC_REW_pTExtrap.C
Go to the documentation of this file.
1 // Analysis
6 
7 // Core
8 #include "CAFAna/Core/Binning.h"
9 #include "CAFAna/Core/Cut.h"
10 #include "CAFAna/Core/HistAxis.h"
12 #include "CAFAna/Core/Spectrum.h"
15 
16 // Cuts
17 #include "CAFAna/Cuts/Cuts.h"
20 #include "CAFAna/Cuts/SpillCuts.h"
23 
24 // Predict
27 
28 // Vars
29 #include "CAFAna/Vars/XsecTunes.h"
30 #include "CAFAna/Vars/TruthVars.h"
33 #include "CAFAna/Vars/Vars.h"
35 
37 
38 #include <iostream>
39 #include <iomanip>
40 
41 using namespace ana;
42 
43 //sample : ALL/CORE/PERI and the corresponding Weight file name.
45 {
46  const std::string outfilename = ("FDprediction_kinematics_FHC_REW_pTExtrap"+sample+".root").c_str();
47 
48  //For grid
49  // std::string wfile_name = ("/pnfs/nova/scratch/users/zvallari/AcceptSyst/"+wfile).c_str();
50  // TFile *weight_file = TFile::Open(pnfs2xrootd(wfile_name).c_str() );
51  //For non-grid
52  std::string wfile_name = ("/nova/ana/users/zvallari/AcceptSyst2020/"+wfile).c_str();
53  TFile *weight_file = TFile::Open(wfile_name.c_str());
54 
55  TH1 *h = (TH1*)weight_file->Get(("trueQ2_weight_"+sample).c_str());
56  int nbins = h->GetNbinsX();
57  double bins[nbins], binslow[nbins], binshigh[nbins];
58  for(int i = 1; i <= nbins; ++i){
59  bins[i-1] = h->GetBinContent(i);
60  binslow[i-1] = h->GetBinLowEdge(i);
61  binshigh[i-1] = h->GetBinLowEdge(i) + h->GetBinWidth(i);
62  }
63 
64 const Var kTrueQ2Weight([nbins, &binslow, &binshigh, &bins](const caf::SRProxy *sr){
65  if(sr->hdr.det == caf::kFARDET) return 1.0;
66  for(int i = 0; i < nbins; ++i){
67  if((kRecoQ2(sr) > binslow[i]) && (kRecoQ2(sr) < binshigh[i])){
68  return bins[i];
69  }
70  }
71  return 1.0;
72  }
73  );
74 
75  TH1 *hptp = (TH1*)weight_file->Get(("PtP_weight_"+sample).c_str());
76  int nbins_ptp = hptp->GetNbinsX();
77  double bins_ptp[nbins_ptp], binslow_ptp[nbins_ptp], binshigh_ptp[nbins_ptp];
78  for(int i = 1; i <= nbins_ptp; ++i){
79  bins_ptp[i-1] = hptp->GetBinContent(i);
80  binslow_ptp[i-1] = hptp->GetBinLowEdge(i);
81  binshigh_ptp[i-1] = hptp->GetBinLowEdge(i) + hptp->GetBinWidth(i);
82  }
83 
84  const Var kPtPWeight([nbins_ptp, &binslow_ptp, &binshigh_ptp, &bins_ptp](const caf::SRProxy *sr){
85  if(sr->hdr.det == caf::kFARDET) return 1.0;
86  for(int i = 0; i < nbins_ptp; ++i){
87  if((kPtP(sr) > binslow_ptp[i]) && (kPtP(sr) < binshigh_ptp[i])){return bins_ptp[i];}
88  }
89  return 1.0;
90  }
91  );
92 
93  TH1 *hcos = (TH1*)weight_file->Get(("CosNumi_weight_"+sample).c_str());
94  int nbins_cos = hptp->GetNbinsX();
95  double bins_cos[nbins_cos], binslow_cos[nbins_cos], binshigh_cos[nbins_cos];
96  for(int i = 1; i <= nbins_cos; ++i){
97  bins_cos[i-1] = hcos->GetBinContent(i);
98  binslow_cos[i-1] = hcos->GetBinLowEdge(i);
99  binshigh_cos[i-1] = hcos->GetBinLowEdge(i) + hcos->GetBinWidth(i);
100  }
101 
102  const Var kCosWeight([nbins_cos, &binslow_cos, &binshigh_cos, &bins_cos](const caf::SRProxy *sr){
103  if(sr->hdr.det == caf::kFARDET) return 1.0;
104  for(int i = 0; i < nbins_cos; ++i){
105  if((kCosNumi(sr) > binslow_cos[i]) && (kCosNumi(sr) < binshigh_cos[i])){return bins_cos[i];}
106  }
107  return 1.0;
108  }
109  );
110 
111  // close weights file
112  weight_file->Close();
113 
114  const unsigned int nQuants = 3;
115  bool isRHC = false;
116  std::vector<Cut> PtQuantCutsND = GetNueQuantCuts2020( isRHC, caf::kNEARDET, nQuants, ana::kExtrapPt );
117  std::vector<Cut> PtQuantCutsFD = GetNueQuantCuts2020( isRHC, caf::kFARDET, nQuants, ana::kExtrapPt );
118 
121 
122  struct GenDef{
123  const IPredictionGenerator *gen;
124  const TString cutname;
125  const TString varname;
126  };
127 
128  std::vector <GenDef> gens;
129  std::vector <IPrediction * > predictions;
130 
132  sample.c_str(), "nueAxis_NoExtrap"});
133 
134  //Loop over samples
135  for ( unsigned int quant = 0; quant < nQuants; ++quant ){
138  kNue2020FDAllSamples && PtQuantCutsFD[quant],
139  kNumu2020ND && PtQuantCutsND[quant],
140  kNoShift,
141  kXSecCVWgt2020*kPPFXFluxCVWgt*kTrueQ2Weight),
142  sample.c_str(), Form("nueAxis_NueSignalExtrap_Q2Weight_Quant%i", quant+1)});
143 
146  kNue2020FDAllSamples && PtQuantCutsFD[quant],
147  kNumu2020ND && PtQuantCutsND[quant],
148  kNoShift,
149  kXSecCVWgt2020*kPPFXFluxCVWgt*kCosWeight),
150  sample.c_str(), Form("nueAxis_NueSignalExtrap_CosWeight_Quant%i", quant+1)});
151 
154  kNue2020FDAllSamples && PtQuantCutsFD[quant],
155  kNumu2020ND && PtQuantCutsND[quant],
156  kNoShift,
157  kXSecCVWgt2020*kPPFXFluxCVWgt*kPtPWeight),
158  sample.c_str(), Form("nueAxis_NueSignalExtrap_PtPWeight_Quant%i", quant+1)});
159  }
160 
161  for(auto & gen:gens){
162  predictions.push_back(gen.gen->Generate(loaders).release());
163  }
164 
165  loaders.Go();
166 
167  TFile* file = new TFile(outfilename.c_str(),"RECREATE");
168  for (int i = 0 ; i < (int)gens.size(); ++i){
169  auto dir = file->GetDirectory(gens[i].cutname);
170  if(!dir) dir = file->mkdir(gens[i].cutname);
171  predictions[i]->SaveTo(dir, gens[i].varname);
172  }
173 
174  file->Close();
175 
176 }
Near Detector underground.
Definition: SREnums.h:10
Far Detector at Ash River.
Definition: SREnums.h:11
std::map< TString, IPredictionGenerator * > gens
Definition: syst_header.h:387
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2137
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
const Cut kNumu2020ND
Definition: NumuCuts2020.h:57
const HistAxis kNumuCCOptimisedAxis2020("Reconstructed Neutrino Energy (GeV)", kNumuCCEOptimisedBinning, kNumuE2020)
Definition: HistAxes.h:25
Generates FD-only predictions (no extrapolation)
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
string outfilename
knobs that need extra care
const int nbins
Definition: cellShifts.C:15
For nominal spectra and reweighting systs (xsec/flux)
Definition: Prod5Loaders.h:101
const HistAxis kNue2020Axis("NuE Energy / Analysis Bin", kNue2020Binning, kNue2020AnaBin)
Use this Axis for Ana2020, official Axis.
Definition: NueCuts2020.h:195
Generates extrapolated Nue signal-only predictions.
caf::StandardRecord * sr
std::vector< Cut > GetNueQuantCuts2020(const bool isRHC, const caf::Det_t det, const unsigned int nquants, const ExtrapVar var)
const SystShifts kNoShift
Definition: SystShifts.cxx:21
const Binning bins
Definition: NumuCC_CPiBin.h:8
TDirectory * dir
Definition: macro.C:5
std::vector< Loaders * > loaders
Definition: syst_header.h:386
TFile * file
Definition: cellShifts.C:17
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Given loaders and an MC shift, Generate() generates an IPrediction.
const Cut kNue2020FDAllSamples
Definition: NueCuts2020.h:84
void make_nueFDprediction_kinematics_FHC_REW_pTExtrap(const std::string sample, const std::string wfile)
const Var kXSecCVWgt2020
Definition: XsecTunes.h:106
caf::Proxy< caf::Det_t > det
Definition: SRProxy.h:232
enum BeamMode string