GetHistsFD.C
Go to the documentation of this file.
1 // Fills spectra for systematic error band
2 #ifdef __CINT__
3 void GetHistsFD()
4 {
5  std::cout << "Sorry, you must run in compiled mode" << std::endl;
6 }
7 #else
8 
9 #include "CAFAna/Core/Binning.h"
10 #include "CAFAna/Core/Loaders.h"
11 #include "CAFAna/Core/Spectrum.h"
13 #include "CAFAna/Core/Var.h"
14 #include "CAFAna/Cuts/Cuts.h"
15 #include "CAFAna/Cuts/NumuCuts.h"
16 #include "CAFAna/Cuts/SpillCuts.h"
18 #include "CAFAna/Vars/NumuVars.h"
20 
21 #include "TCanvas.h"
22 #include "TFile.h"
23 #include "TH1.h"
24 #include "TH2.h"
25 #include "TStyle.h"
26 
27 using namespace ana;
28 
29 void GetHistsFD()
30 {
31 
32  std::string fd_nonswap = "/pnfs/nova/persistent/production/concat/R16-03-03-prod2reco.f/epoch*/prod_decaf_R16-03-03-prod2reco.f_fd_genie_nonswap_fhc_nova_v08_epoch*_numu_contain_v1_prod2-snapshot.root";
33  SpectrumLoader loader(fd_nonswap);
35 
36  struct Plot2D
37  {
39  std::string labelx;
40  Binning binsx;
41  Var varx;
42  std::string labely;
43  Binning binsy;
44  Var vary;
45  Cut cut;
46  };
47 
48  const Cut kTrueEbelow5({"mc.nnu","mc.nu.E"},
49  [](const caf::StandardRecord* sr)
50  {
51  if (sr->mc.nnu < 1) return false;
52  else return (sr->mc.nu[0].E <= 5.0);
53  });
54 
55  const Cut kHasTrueMuon({"energy.numusimp.mc.truegoodmuon","energy.numusimp.mc.truemuonE"},
56  [](const caf::StandardRecord* sr)
57  {
58  if (sr->energy.numusimp.mc.truegoodmuon < 1) return false;
59  else return (sr->energy.numusimp.mc.truemuonE > 0);
60  });
61 
62  const Cut kCut = kTrueEbelow5 && kIsNumuCC && kHasTrueMuon && kNumuFD;
63 
64  //// ------ Now the binnings and variables ------ /////
65 
66  const Binning kMuonEnergyBinning = Binning::Simple(150,0,5);
67  const Binning kHadEnergyBinning = Binning::Simple(150,0,5);
68  const Binning kRToverTBinning = Binning::Simple(150, -1.0, 1.0);
69  const Binning kTrackLengthBinning = Binning::Simple(150, 0, 15);
70 
71  std::vector<double> hadronBins;
72  double hadronAxis = 0.0;
73  for(int i = 0; i < 116; ++i){
74  hadronBins.push_back(hadronAxis);
75  if (hadronAxis < 1.0){hadronAxis = hadronAxis + 0.01;}
76  else if (hadronAxis < 1.5){hadronAxis = hadronAxis + 0.05;}
77  else {hadronAxis = hadronAxis + 0.1;}
78  }
79 
80  const Binning kHadEBinning = Binning::Custom(hadronBins);
81 
82  const Var kTrueHadE = kTrueE - kTrueMuonE;
83 
84  const Var kHadE1 = SIMPLEVAR(energy.numusimp.hadtrkE);
85  const Var kHadE2 = SIMPLEVAR(energy.numusimp.hadcalE);
86  const Var kHadCalE = kHadE1 + kHadE2;
87 
88  const int kNumPlots2D = 2;
89 
90  Plot2D plots2D[kNumPlots2D] = {
91 
92  {"MuonE_hist","Reco muon track length (m)", kTrackLengthBinning, kTrkLength, "True muon energy (GeV)" , kMuonEnergyBinning, kTrueMuonE, kCut},
93 
94  {"HadE_hist","Visible hadronic energy (GeV)", kHadEBinning, kHadCalE, "True hadronic energy (GeV)" , kHadEnergyBinning, kTrueHadE, kCut}
95  };
96 
97  Spectrum* sSpect2D[kNumPlots2D];
98 
99  for(int i = 0; i < kNumPlots2D; i++)
100  {
101  Plot2D p = plots2D[i];
102  // sSpect2D[i] = new Spectrum(p.labelx, p.labely, loader, p.binsx, p.varx, p.binsy, p.vary, p.cut, kNoShift, kTuftsWeightCC * kPPFXFluxCVWgt ); // for miniproduction
103  sSpect2D[i] = new Spectrum(p.labelx, p.labely, loader, p.binsx, p.varx, p.binsy, p.vary, p.cut, kNoShift, kTuftsWeightCC );
104  } // loop over 1D plots
105 
106  loader.Go();
107 
108  TFile f("2DPlotsForFittingFD.root","RECREATE");
109 
110  for(int i = 0; i < kNumPlots2D; i++)
111  {
112  Plot2D p = plots2D[i];
113  TH2* h = sSpect2D[i]->ToTH2(sSpect2D[i]->POT());
114  h->SetName(p.name.c_str());
115  h->Write();
116  } // loop over 1D plots
117 
118 }
119 
120 #endif
const XML_Char * name
Definition: expat.h:151
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:193
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 char * p
Definition: xmltok.h:285
#define SIMPLEVAR(CAFNAME)
Definition: Var.h:11
std::vector< double > Spectrum
Definition: Constants.h:746
void Plot2D(TH1 *total, std::map< std::string, TH1 * > systs, std::vector< std::string > to_plot, std::string basename)
const Cut kNumuFD
Definition: NumuCuts.h:53
void SetSpillCut(const SpillCut &cut)
const Var kTrkLength([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;return sr->trk.kalman.tracks[0].len/100;})
Definition: NumuVars.h:65
const Var kHadCalE([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return float(sr->slc.calE);if(sr->vtx.elastic.fuzzyk.nshwlid< 1) return float(sr->slc.calE);return((sr->slc.calE- sr->vtx.elastic.fuzzyk.png[0].shwlid.calE));})
Definition: NueVarsExtra.h:40
const Binning kHadEnergyBinning
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:39
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
double energy
Definition: plottest35.C:25
void GetHistsFD()
Definition: GetHistsFD.C:29
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
loader
Definition: demo0.py:10
short nnu
Number of neutrinos in nu vector (0 or 1)
Definition: SRTruthBranch.h:37
static Binning Custom(const std::vector< double > &edges)
Definition: Binning.cxx:145
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
std::vector< double > POT
The StandardRecord is the primary top-level object in the Common Analysis File trees.
const Cut cut
Definition: exporter_fd.C:30
const Var kTuftsWeightCC
Definition: XsecTunes.h:30
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const Var kTrueMuonE([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.f;if(sr->mc.nu[0].prim.empty()) return 0.f;if(std::abs(sr->mc.nu[0].prim[0].pdg)!=13) return 0.f;return float(sr->mc.nu[0].prim[0].p.E);})
Definition: NumuVars.h:107
const Var kTrueHadE
const Cut kCut
Definition: VarsAndCuts.h:36
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
SREnergyBranch energy
Energy estimator branch.
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
std::vector< SRNeutrino > nu
implemented as a vector to maintain mc.nu structure, i.e. not a pointer, but with 0 or 1 entries...
Definition: SRTruthBranch.h:25
enum BeamMode string