datamc_ND_numu_kinematics_RHC_pTBins.C
Go to the documentation of this file.
6 
7 // Core
9 #include "CAFAna/Core/Spectrum.h"
11 #include "CAFAna/Core/HistAxis.h"
12 #include "CAFAna/Core/Binning.h"
13 #include "CAFAna/Core/Cut.h"
14 
15 // Cuts
16 #include "CAFAna/Cuts/Cuts.h"
17 #include "CAFAna/Cuts/SpillCuts.h"
22 #include "CAFAna/Cuts/TruthCuts.h"
23 
24 // Vars
25 #include "CAFAna/Vars/Vars.h"
26 #include "CAFAna/Vars/TruthVars.h"
27 #include "CAFAna/Vars/XsecTunes.h"
32 #include "CAFAna/Vars/HistAxes.h"
33 
34 #include "CAFAna/Analysis/Style.h"
35 #include "CAFAna/Core/Utilities.h"
36 
37 #include "TFile.h"
38 #include <fstream>
39 #include <iostream>
40 #include <cmath>
41 #include <string>
42 
43 using namespace ana;
44 
45 #include "Utilities/func/MathUtil.h"
46 
47 
49 {
50 
51  std::string nameData = "prod_caf_R19-11-18-prod5reco.g_nd_numi_rhc_full_v1_goodruns";
52  std::string nameMC = "prod_caf_R19-11-18-prod5reco.d_nd_genie_N1810j0211a_nonswap_rhc_nova_v08_full_v1";
53 
54  SpectrumLoader loaderData(ndData);
55  SpectrumLoader loaderMC(ndMC);
56 
57  loaderData.SetSpillCut(kStandardSpillCuts);
58  loaderMC.SetSpillCut(kStandardDQCuts);
59 
60  //which variables do you want to look at?
61  const int kNumVars = 5;
62 
63  struct HistDef{
65  const HistAxis axis;
66  };
67 
68  const HistDef defs[kNumVars] = {
69  {"numu", kNumuCCAxis},
70  {"Muon pT", {"#mu p_{T}", Binning::Simple(50,0,5), kNumuMuonPt}},
71  {"recoQ2", {"reco Q^{2} (GeV^{2})", Binning::Simple(50, 0, 5), kRecoQ2}},
72  {"PtP", {"p_{t}/p", Binning::Simple(20,0,1), kPtP}},
73  {"CosNumi", {"CosNumi", Binning::Simple(20,0,1), kCosNumi}}
74  };
75 
76  const int kNumSels = 4;
77  const unsigned int nQuants = 3;
78  bool isRHC = true;
79  std::vector<Cut> PtQuantCutsND = GetNueQuantCuts2020( isRHC, caf::kNEARDET, nQuants, ana::kExtrapPt );
80  const Cut sels[kNumSels] = {
82  kNumu2020ND && PtQuantCutsND[0],
83  kNumu2020ND && PtQuantCutsND[1],
84  kNumu2020ND && PtQuantCutsND[2]
85  };
86  const std::string selNames[kNumSels] = {
87  "AllBins",
88  "Quant1",
89  "Quant2",
90  "Quant3"
91  };
92 
93  Spectrum* NDdata[kNumSels][kNumVars];
94  Spectrum* NDmc[kNumSels][kNumVars];
95 
96  //loop over the selectors and variables to create a full selection
97  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
98  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
99  const HistAxis& axis = defs[varIdx].axis;
100  NDdata[selIdx][varIdx] = new Spectrum(loaderData, axis, sels[selIdx], kNoShift);
101  NDmc[selIdx][varIdx] = new Spectrum(loaderMC, axis, sels[selIdx], kNoShift, kXSecCVWgt2020*kPPFXFluxCVWgt);
102 
103  }
104  }
105 
106  loaderMC.Go();
107  loaderData.Go();
108 
109  TString fname = "datamc_ND_numu_kinematics_RHC_pTBins.root";
110  TFile* fout = new TFile(fname, "RECREATE");
111  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
112  TDirectory* d = fout->mkdir(selNames[selIdx].c_str());
113  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
114  const char* name = defs[varIdx].name.c_str();
115  NDdata[selIdx][varIdx]->SaveTo(d, TString::Format("data_%s", name));
116  NDmc[selIdx][varIdx]->SaveTo(d, TString::Format("mc_%s", name));
117  }
118  }
119 }
120 
Near Detector underground.
Definition: SREnums.h:10
const XML_Char * name
Definition: expat.h:151
const ana::Var kRecoQ2([](const caf::SRProxy *sr){const double M_mu_sqrd=util::sqr(0.1056);double E_mu=kMuE(sr);double p_mu=sqrt(util::sqr(E_mu)-M_mu_sqrd);return 2 *kCCE(sr)*(E_mu-p_mu *kCosNumi(sr))-M_mu_sqrd;})
Reconstructed four-momentum transfer invariant (Q^2)
Definition: NumuVars.h:146
const int kNumVars
Definition: vars.h:14
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kNumuMuonPt([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks > 0 &&sr->trk.kalman.idxremid!=999){double pmu=sqrt(util::sqr(kMuE(sr))-util::sqr(0.1056));double Zbeam=kCosNumi(sr);double pt=pmu *sqrt(1-Zbeam *Zbeam);return(float) pt;}return-5.f;})
Definition: NumuVars.h:47
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Cut kNumu2020ND
Definition: NumuCuts2020.h:57
std::string name
Definition: NuePlotLists.h:12
void SetSpillCut(const SpillCut &cut)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Var kPtP
Transverse momentum fraction in slice.
Definition: NueVars.cxx:90
const Cut sels[kNumSels]
Definition: vars.h:44
const HistAxis kNumuCCAxis("Reconstructed Neutrino Energy (GeV)", kNumuEnergyBinning, kCCE)
Definition: HistAxes.h:8
const SpillCut kStandardDQCuts([](const caf::SRSpillProxy *spill){if(spill->dcmedgematchfrac==0 &&spill->fracdcm3hits==0 &&spill->nmissingdcmslg==0) return bool(spill->isgoodspill); if(spill->det==caf::kNEARDET && (spill->fracdcm3hits > 0.45|| spill->nmissingdcms > 0)) return false; if(spill->eventincomplete) return false; if(spill->det==caf::kFARDET && spill->nmissingdcmslg > 0) return false; if(spill->det==caf::kFARDET && !spill->ismc && spill->dcmedgematchfrac<=0.2) return false;return true;})
Cut out events with a noisy detector or with parts missing.
Definition: SpillCuts.h:16
Float_t d
Definition: plot.C:236
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
const HistDef defs[kNumVars]
Definition: vars.h:15
std::vector< Cut > GetNueQuantCuts2020(const bool isRHC, const caf::Det_t det, const unsigned int nquants, const ExtrapVar var)
const int kNumSels
Definition: vars.h:43
std::vector< float > Spectrum
Definition: Constants.h:570
HistAxis axis
Definition: NuePlotLists.h:13
const SystShifts kNoShift
Definition: SystShifts.cxx:21
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
void datamc_ND_numu_kinematics_RHC_pTBins()
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const std::string selNames[kNumSels]
Definition: vars.h:46
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:114
const Var kCosNumi([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks > 0 &&sr->trk.kalman.idxremid!=999){if(sr->hdr.det==1){return sr->trk.kalman.tracks[0].dir.Dot(beamDirND);}if(sr->hdr.det==2){return sr->trk.kalman.tracks[0].dir.Dot(beamDirFD);}}return-5.f;})
Definition: NumuVars.h:43
const Var kXSecCVWgt2020
Definition: XsecTunes.h:106