NueDecomp.cxx
Go to the documentation of this file.
2 
3 #include "CAFAna/Cuts/Cuts.h"
5 #include "CAFAna/Core/Ratio.h"
6 
7 #include <cassert>
8 
9 #include "TDirectory.h"
10 #include "TObjString.h"
11 
12 namespace ana
13 {
14  REGISTER_LOADFROM("NueDecomp", IDecomp, NueDecomp);
15 
16  //----------------------------------------------------------------------
17 
19  SpectrumLoaderBase& loaderData,
20  const std::string& label,
21  const Binning& bins,
22  const Var& var,
23  const Cut& cut,
24  const SystShifts& shiftMC,
25  const SystShifts& shiftData,
26  const Var& wei)
27  : NueDecomp(loaderMC, loaderData, HistAxis(label, bins, var),
28  cut, shiftMC, shiftData, wei)
29  {
30  }
31 
32  //----------------------------------------------------------------------
34  SpectrumLoaderBase& loaderData,
35  const HistAxis& axis,
36  const Cut& cut,
37  const SystShifts& shiftMC,
38  const SystShifts& shiftData,
39  const Var& wei)
40  : fData (loaderData, axis, cut, shiftData, wei),
41  //nc
42  fNCTot (loaderMC, axis, cut && kIsNC, shiftMC, wei),
43  fNC (loaderMC, axis, cut && kIsNC && !kIsAntiNu, shiftMC, wei),
44  fNCAnti (loaderMC, axis, cut && kIsNC && kIsAntiNu, shiftMC, wei),
45  //end nc
46  fNue (loaderMC, axis, cut && kIsBeamNue&&!kIsAntiNu, shiftMC, wei),
47  fAntiNue (loaderMC, axis, cut && kIsBeamNue&& kIsAntiNu, shiftMC, wei),
48  fNumu (loaderMC, axis, cut && kIsNumuCC &&!kIsAntiNu, shiftMC, wei),
49  fAntiNumu(loaderMC, axis, cut && kIsNumuCC && kIsAntiNu, shiftMC, wei),
50  fNotNue (loaderMC, axis, cut && !kIsBeamNue&& kHasNu, shiftMC, wei)
51  {
52  }
53 
54  //----------------------------------------------------------------------
56  const HistAxis& axis,
57  const Cut& cut,
58  const SystShifts& shiftMC,
59  const SystShifts& shiftData,
60  const Var& wei)
61  : NueDecomp(loaders.GetLoader(caf::kNEARDET, Loaders::kMC),
62  loaders.GetLoader(caf::kNEARDET, Loaders::kData),
63  axis, cut, shiftMC, shiftData, wei)
64  {
65  }
66 
67  //----------------------------------------------------------------------
69  {
70  // Subtract backgrounds from data using MC, then split into nu/antinu
71  // components using MC ratio
72  return (fNue/(fNue+fAntiNue))*(fData-fNotNue);
73  }
74 
75 
76  //----------------------------------------------------------------------
78  {
79  return (fAntiNue/(fNue+fAntiNue))*(fData-fNotNue);
80  }
81 
82  //----------------------------------------------------------------------
83  void NueDecomp::SaveTo(TDirectory* dir, const std::string& name) const
84  {
85  TDirectory* tmp = gDirectory;
86 
87  dir = dir->mkdir(name.c_str()); // switch to subdir
88  dir->cd();
89 
90  TObjString("NueDecomp").Write("type");
91  //nc
92  fNCTot.SaveTo(dir, "nc_tot_comp");
93  fNC.SaveTo(dir, "nc_comp");
94  fNCAnti.SaveTo(dir, "nc_anti_comp");
95  //end nc
96  fData.SaveTo(dir, "data_comp");
97  fNue.SaveTo(dir, "nue_comp");
98  fAntiNue.SaveTo(dir, "antinue_comp");
99  fNumu.SaveTo(dir, "numu_comp");
100  fAntiNumu.SaveTo(dir, "antinumu_comp");
101  fNotNue.SaveTo(dir, "notnue_comp");
102 
103  dir->Write();
104  delete dir;
105 
106  tmp->cd();
107  }
108 
109  //----------------------------------------------------------------------
110  std::unique_ptr<NueDecomp> NueDecomp::LoadFrom(TDirectory* dir, const std::string& name)
111  {
112  dir = dir->GetDirectory(name.c_str()); // switch to subdir
113  assert(dir);
114 
115  std::unique_ptr<NueDecomp> ret(new NueDecomp);
116 
117  // nc
118  ret->fNCTot = *Spectrum::LoadFrom(dir, "nc_tot_comp");
119  ret->fNC = *Spectrum::LoadFrom(dir, "nc_comp");
120  ret->fNCAnti = *Spectrum::LoadFrom(dir, "nc_anti_comp");
121  //end nc
122  ret->fData = *Spectrum::LoadFrom(dir, "data_comp");
123  ret->fNue = *Spectrum::LoadFrom(dir, "nue_comp");
124  ret->fAntiNue = *Spectrum::LoadFrom(dir, "antinue_comp");
125  ret->fNumu = *Spectrum::LoadFrom(dir, "numu_comp");
126  ret->fAntiNumu = *Spectrum::LoadFrom(dir, "antinumu_comp");
127  ret->fNotNue = *Spectrum::LoadFrom(dir, "notnue_comp");
128 
129  delete dir;
130 
131  return ret;
132  }
133 }
Spectrum fData
Definition: NueDecomp.h:65
const XML_Char * name
Definition: expat.h:151
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
static std::unique_ptr< NueDecomp > LoadFrom(TDirectory *dir, const std::string &name)
Definition: NueDecomp.cxx:110
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
Spectrum fNCTot
Definition: NueDecomp.h:69
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
Spectrum fNCAnti
Definition: NueDecomp.h:71
const Color_t kMC
const Cut kIsAntiNu([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return sr->mc.nu[0].pdg< 0;})
Is this truly an antineutrino?
Definition: TruthCuts.h:53
const Cut kIsBeamNue(CCFlavSel(12, 12))
Select CC .
Spectrum NueComponent() const override
Definition: NueDecomp.cxx:68
Float_t tmp
Definition: plot.C:36
Spectrum fAntiNumu
Definition: NueDecomp.h:78
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
Spectrum fAntiNue
Definition: NueDecomp.h:75
Uses MC for CC and NC components, assigns remainder of data to CC.
Definition: NueDecomp.h:10
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:546
const Cut kIsNC([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return!sr->mc.nu[0].iscc;})
Is this a Neutral Current event?
Definition: TruthCuts.h:8
Spectrum fNumu
Definition: NueDecomp.h:77
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
Spectrum fNue
Definition: NueDecomp.h:74
Spectrum AntiNueComponent() const override
Definition: NueDecomp.cxx:77
Base class for the various types of spectrum loader.
const Binning bins
Definition: NumuCC_CPiBin.h:8
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
const Cut kHasNu([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return true;})
Definition: TruthCuts.h:56
TDirectory * dir
Definition: macro.C:5
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
std::vector< Loaders * > loaders
Definition: syst_header.h:386
assert(nhit_max >=nhit_nbins)
Spectrum fNotNue
Definition: NueDecomp.h:80
This module creates Common Analysis Files.
Definition: FileReducer.h:10
Spectrum fNC
Definition: NueDecomp.h:70
void SaveTo(TDirectory *dir, const std::string &name) const override
Definition: NueDecomp.cxx:83