mcTruthPredictions.C
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////
2 /// \brief Macro to create the Monte Carlo truth histograms on
3 /// all useful weights
4 /// \author Connor Johnson
5 /// \date Jan 2020
6 //////////////////////////////////////////////////////////////////
7 
8 #include "CAFAna/Vars/Vars.h"
9 #include "CAFAna/Core/Binning.h"
10 #include "CAFAna/Cuts/Cuts.h"
11 #include "CAFAna/Cuts/SpillCuts.h"
12 #include "CAFAna/Core/Spectrum.h"
16 #include "CAFAna/Systs/Systs.h"
18 #include "CAFAna/Systs/BeamSysts.h"
19 #include "CAFAna/Systs/EnergySysts2018.h"
21 
24 
31 
32 #include "TFile.h"
33 #include "TH1.h"
34 #include "TH2.h"
35 
36 #include <iostream>
37 #include <cmath>
38 #include <sstream>
39 #include <string>
40 #include <fstream>
41 #include <iomanip>
42 #include <map>
43 #include <algorithm>
44 
45 using namespace ana;
46 
49 const NuTruthVar wgtST = wgt_ppfxST * wgt_xsST;
50 
51 // Bins
52 const Binning mukebins_fine = Binning::Simple(200, 0.5, 2.5);
54  mukebins_fine.NBins()*
56  eavailbins.NBins(),
57  0,
58  mukebins_fine.NBins()*
60  eavailbins.NBins());
62  mukebins_fine.NBins()*
64  0,
65  mukebins_fine.NBins()*
67 const Binning q2bins_fine = Binning::Simple(500, 0.0, 5.0);
68 const Binning enubins_fine = Binning::Simple(400, 0.0, 10.0);
69 
74  mukebins_fine,
76  eavailbins);
77 
82  mukebins_fine);
83 
85  "True Muon Kinematics",
86  angvsmukevseavailbins_fine,
87  kTrueMuKEVsCosVsEavail_FineST
88  );
89 
91  "True Muon Kinematics",
92  angvsmukebins_fine,
93  kTrueMuKEVsCos_FineST
94  );
95 
97  "True Neutrino Energy (GeV)",
98  enubins_fine,
99  kTrueEST);
100 
102  "True Q2 (GeV)",
103  q2bins_fine,
104  kTrueQ2_NT
105  );
106 
107 map<string, NuTruthVar> weights {
108  {"unweight", kNuTruthUnweighted},
109  {"ppfx", wgt_ppfxST},
110  {"xsec", wgt_xsST},
111  {"both", wgtST}
112 };
113 
114 void mcTruthPredictions(string filename = "mcPredictions.root")
115 {
116  // Define the spectrum
117  SpectrumLoader * loader = new SpectrumLoader("dataset_def_name_newest_snapshot nd_fhc_remid-hotfix_caf_minus_muonid_training_minus_fakedata");
118 
119  map<string, map<string, Spectrum* > > specmap;
120 
121  for (pair<string, NuTruthVar> weight : weights)
122  {
123  map<string, Spectrum*> specs;
124  specs["EAvail"] = new Spectrum(*loader, kTrueMuKEVsCosVsEavail_FineStandardAxisST, kIsTrueSigST, kNoShift, weight.second);
125  specs["MuKin"] = new Spectrum(*loader, kTrueMuKEVsCos_FineStandardAxisST, kIsTrueSigST, kNoShift, weight.second);
126  specs["ENu"] = new Spectrum(*loader, kTrueE_FineStandardAxisST, kIsTrueSig1DST, kNoShift, weight.second);
127  specs["Q2"] = new Spectrum(*loader, kTrueQ2_FineStandardAxisST, kIsTrueSig1DST, kNoShift, weight.second);
128 
129  specmap[weight.first] = specs;
130  }
131 
132  // Go
133  loader->Go();
134 
135  // Story the outputs
136  TFile * outFile = TFile::Open(filename.c_str(), "RECREATE");
137  TDirectory * predDir = outFile->mkdir("geniePrediction");
138  for(pair<string, map<string, Spectrum* > > weightSpecs : specmap)
139  {
140  TDirectory * weightDir = predDir->mkdir(weightSpecs.first.c_str());
141  for(pair<string, Spectrum*> spec : weightSpecs.second)
142  spec.second->SaveTo(weightDir->mkdir(spec.first.c_str()));
143  }
144  outFile->Close();
145 }
void mcTruthPredictions(string filename="mcPredictions.root")
const Binning enubins_fine
const NuTruthCut kIsTrueSigST
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
const NuTruthVar kTrueMuCosthetaST([](const caf::SRNeutrinoProxy *nu){if(abs(nu->pdg)!=14||!nu->iscc) return-5.0;int nprims=nu->prim.size();for(int iprim=0;iprim< nprims;iprim++){if(abs(nu->prim[iprim].pdg)==13){TVector3 mudir=nu->prim[iprim].p.Vect();TVector3 beamdir=NuMIBeamDirection(caf::kNEARDET);return mudir.Unit().Dot(beamdir.Unit());}}return-5.0;})
const Var weight
const NuTruthCut kIsTrueSig1DST
const Binning q2bins_fine
_Var< T > Var2D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb)
Variable formed from two input variables.
Definition: Var.cxx:247
const NuTruthVar kTrueMuKEST([](const caf::SRNeutrinoProxy *nu){float ke=-5;if(abs(nu->pdg)!=14||!nu->iscc) return ke;int nprims=nu->prim.size();for(int iprim=0;iprim< nprims;iprim++){if(abs(nu->prim[iprim].pdg)==13){double E=nu->prim[iprim].p.T();ke=E-MuonMass();}}return ke;})
string filename
Definition: shutoffs.py:106
const Binning eavailbins
const NuTruthVar wgt_xsST
_Var< T > Var3D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb, const _Var< T > &c, const Binning &binsc)
This is just like a Var2D, but useful for 3D Spectra.
Definition: Var.cxx:273
const NuTruthVar kTrueEST([](const caf::SRNeutrinoProxy *nu){return nu->E;})
const NuTruthVar wgt_ppfxST
TFile * outFile
Definition: PlotXSec.C:135
const NuTruthVar kTrueMuKEVsCos_FineST
const Binning angvsmukevseavailbins_fine
const NuTruthVar wgtST
virtual void Go() override
Load all the registered spectra.
map< string, NuTruthVar > weights
const NuTruthVar kXSecCVWgt2018_smallerDISScale_NT
Definition: XsecTunes.h:47
loader
Definition: demo0.py:10
std::vector< float > Spectrum
Definition: Constants.h:759
const SystShifts kNoShift
Definition: SystShifts.cxx:22
const NuTruthHistAxis kTrueMuKEVsCos_FineStandardAxisST("True Muon Kinematics", angvsmukebins_fine, kTrueMuKEVsCos_FineST)
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
int NBins() const
Definition: Binning.h:29
const NuTruthVar kNuTruthUnweighted
Definition: Var.h:100
const NuTruthHistAxis kTrueE_FineStandardAxisST("True Neutrino Energy (GeV)", enubins_fine, kTrueEST)
const NuTruthHistAxis kTrueQ2_FineStandardAxisST("True Q2 (GeV)", q2bins_fine, kTrueQ2_NT)
const NuTruthVar kTrueMuKEVsCosVsEavail_FineST
const NuTruthVar kTrueEavailST
Template for Var and SpillVar.
const Binning angbinsCustom
Definition: NumuCCIncBins.h:72
const Binning angvsmukebins_fine
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
const NuTruthHistAxis kTrueMuKEVsCosVsEavail_FineStandardAxisST("True Muon Kinematics", angvsmukevseavailbins_fine, kTrueMuKEVsCosVsEavail_FineST)
const NuTruthVar kPPFXFluxCVWgtST([](const caf::SRNeutrinoProxy *nu){ if(nu->rwgt.ppfx.cv!=nu->rwgt.ppfx.cv){return 1.f;}if(nu->rwgt.ppfx.cv >90){return 1.f;}return float(nu->rwgt.ppfx.cv);})
weight events with the flux PPFX Central value correction.
Definition: PPFXWeights.h:12
const NuTruthVar kTrueQ2_NT([](const caf::SRNeutrinoProxy *nu){return nu->q2;})
True square of four-momentum transfer.
Definition: TruthVars.h:26
const Binning mukebins_fine