ProportionalDecomp.cxx
Go to the documentation of this file.
2 
5 #include "CAFAna/Core/HistAxis.h"
6 #include "CAFAna/Core/Loaders.h"
7 #include "CAFAna/Core/Ratio.h"
8 #include "TDirectory.h"
9 #include "TObjString.h"
10 #include <cassert>
11 
12 namespace ana
13 {
14  REGISTER_LOADFROM("ProportionalDecomp", IDecomp, ProportionalDecomp);
15 
16  //----------------------------------------------------------------------
18  SpectrumLoaderBase& loaderData,
19  const std::string& label,
20  const Binning& bins,
21  const Var& var,
22  const Cut& cut,
23  const SystShifts& shiftMC,
24  const SystShifts& shiftData,
25  const Var& wei)
26  : ProportionalDecomp(loaderMC,
27  loaderData,
28  HistAxis(label, bins, var),
29  cut,
30  shiftMC,
31  shiftData,
32  wei)
33  {}
34 
35  //----------------------------------------------------------------------
37  SpectrumLoaderBase& loaderData,
38  const HistAxis& axis,
39  const Cut& cut,
40  const SystShifts& shiftMC,
41  const SystShifts& shiftData,
42  const Var& wei)
43  : fData (loaderData, axis, cut, shiftData, wei),
44  // nc
45  fNCTot (loaderMC, axis, cut && kIsNC, shiftMC, wei),
46  fNC (loaderMC, axis, cut && kIsNC && !kIsAntiNu, shiftMC, wei),
47  fNCAnti (loaderMC, axis, cut && kIsNC && kIsAntiNu, shiftMC, wei),
48  //end nc
49  fNue (loaderMC, axis, cut && kIsBeamNue&&!kIsAntiNu, shiftMC, wei),
50  fAntiNue (loaderMC, axis, cut && kIsBeamNue&& kIsAntiNu, shiftMC, wei),
51  fNumu (loaderMC, axis, cut && kIsNumuCC &&!kIsAntiNu, shiftMC, wei),
52  fAntiNumu(loaderMC, axis, cut && kIsNumuCC && kIsAntiNu, shiftMC, wei),
53  fTotal (loaderMC, axis, cut && kHasNu, shiftMC, wei)
54  {}
55 
56  //----------------------------------------------------------------------
58  const HistAxis& axis,
59  const Cut& cut,
60  const SystShifts& shiftMC,
61  const SystShifts& shiftData,
62  const Var& wei)
63  : ProportionalDecomp(loaders.GetLoader(caf::kNEARDET, Loaders::kMC),
64  loaders.GetLoader(caf::kNEARDET, Loaders::kData),
65  axis,
66  cut,
67  shiftMC,
68  shiftData,
69  wei)
70  {}
71 
72  //----------------------------------------------------------------------
74  {
75  return (fNumu/fTotal)*fData;
76  }
77 
78  //----------------------------------------------------------------------
80  {
81  return (fAntiNumu/fTotal)*fData;
82  }
83 
84  //----------------------------------------------------------------------
85  // nc
87  {
88  return (fNCTot/fTotal)*fData;
89  }
90 
92  {
93  return (fNC/fTotal)*fData;
94  }
95 
97  {
98  return (fNCAnti/fTotal)*fData;
99  }
100  //end nc
101  //----------------------------------------------------------------------
103  {
104  return (fNue/fTotal)*fData;
105  }
106 
107  //----------------------------------------------------------------------
109  {
110  return (fAntiNue/fTotal)*fData;
111  }
112 
113  //----------------------------------------------------------------------
114  void ProportionalDecomp::SaveTo(TDirectory* dir, const std::string& name) const
115  {
116  TDirectory* tmp = gDirectory;
117 
118  dir = dir->mkdir(name.c_str()); // switch to subdir
119  dir->cd();
120 
121  TObjString("ProportionalDecomp").Write("type");
122 
123  fData.SaveTo(dir, "data_comp");
124  //nc
125  fNCTot.SaveTo(dir, "nc_tot_comp");
126  fNC.SaveTo(dir, "nc_comp");
127  fNCAnti.SaveTo(dir, "nc_anti_comp");
128  //end nc
129  fNue.SaveTo(dir, "nue_comp");
130  fAntiNue.SaveTo(dir, "antinue_comp");
131  fNumu.SaveTo(dir, "numu_comp");
132  fAntiNumu.SaveTo(dir, "antinumu_comp");
133  fTotal.SaveTo(dir, "total_comp");
134 
135  dir->Write();
136  delete dir;
137 
138  tmp->cd();
139  }
140 
141  //----------------------------------------------------------------------
142  std::unique_ptr<ProportionalDecomp>
144  {
145  dir = dir->GetDirectory(name.c_str()); // switch to subdir
146  assert(dir);
147 
148  std::unique_ptr<ProportionalDecomp> ret(new ProportionalDecomp);
149 
150  // nc
151  ret->fNCTot = *Spectrum::LoadFrom(dir, "nc_tot_comp");
152  ret->fNC = *Spectrum::LoadFrom(dir, "nc_comp");
153  ret->fNCAnti = *Spectrum::LoadFrom(dir, "nc_anti_comp");
154  //end nc
155  ret->fData = *Spectrum::LoadFrom(dir, "data_comp");
156  ret->fNue = *Spectrum::LoadFrom(dir, "nue_comp");
157  ret->fAntiNue = *Spectrum::LoadFrom(dir, "antinue_comp");
158  ret->fNumu = *Spectrum::LoadFrom(dir, "numu_comp");
159  ret->fAntiNumu = *Spectrum::LoadFrom(dir, "antinumu_comp");
160  ret->fTotal = *Spectrum::LoadFrom(dir, "total_comp");
161 
162  delete dir;
163 
164  return ret;
165  }
166 
167 }
const XML_Char * name
Definition: expat.h:151
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
Spectrum AntiNueComponent() const override
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 NCAntiComponent() const override
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
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 .
Float_t tmp
Definition: plot.C:36
static std::unique_ptr< ProportionalDecomp > LoadFrom(TDirectory *dir, const std::string &name)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
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 AntiNumuComponent() const override
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
void SaveTo(TDirectory *dir, const std::string &name) const override
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
Splits Data proportionally according to MC.
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
Spectrum NCTotalComponent() const override
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
std::vector< Loaders * > loaders
Definition: syst_header.h:386
Spectrum NumuComponent() const override
assert(nhit_max >=nhit_nbins)
This module creates Common Analysis Files.
Definition: FileReducer.h:10
Spectrum NCComponent() const override
Spectrum NueComponent() const override