FakeDecomp.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 #include "TH1D.h"
12 
13 #include <iostream>
14 
15 using namespace ana::DecompType;
16 
17 namespace ana
18 {
19  REGISTER_LOADFROM("FakeDecomp", IDecomp, FakeDecomp);
20 
21  //----------------------------------------------------------------------
22  //you dont need any of these constructors, im leaving them here for fun :shrug:
24  SpectrumLoaderBase& loaderData,
25  const std::string& label,
26  const Binning& bins,
27  const Var& var,
28  const Cut& cut,
29  const SystShifts& shiftMC,
30  const SystShifts& shiftData,
31  const Var& wei)
32  : FakeDecomp(loaderMC, loaderData, HistAxis(label, bins, var),
33  cut, shiftMC, shiftData, wei)
34  {
35  }
36 
37  //----------------------------------------------------------------------
39  SpectrumLoaderBase& loaderData,
40  const HistAxis& axis,
41  const Cut& cut,
42  const SystShifts& shiftMC,
43  const SystShifts& shiftData,
44  const Var& wei)
45  : fData (loaderData, axis, cut, shiftData, wei),
46  fTotal (loaderMC, axis, cut && kHasNu, shiftMC, wei),
47  //nc
48  fNCTot (loaderMC, axis, cut && kIsNC, shiftMC, wei),
49  fNC (loaderMC, axis, cut && kIsNC && !kIsAntiNu, shiftMC, wei),
50  fNCAnti (loaderMC, axis, cut && kIsNC && kIsAntiNu, shiftMC, wei),
51  //end nc
52  fNue (loaderMC, axis, cut && kIsBeamNue&&!kIsAntiNu, shiftMC, wei),
53  fAntiNue (loaderMC, axis, cut && kIsBeamNue&& kIsAntiNu, shiftMC, wei),
54  fNumu (loaderMC, axis, cut && kIsNumuCC &&!kIsAntiNu, shiftMC, wei),
55  fAntiNumu(loaderMC, axis, cut && kIsNumuCC && kIsAntiNu, shiftMC, wei),
56  fIsDecomposed(false)
57  {
58  }
59 
60  //----------------------------------------------------------------------
62  const HistAxis& axis,
63  const Cut& cut,
64  const SystShifts& shiftMC,
65  const SystShifts& shiftData,
66  const Var& wei)
67  : FakeDecomp(loaders.GetLoader(caf::kNEARDET, Loaders::kMC),
68  loaders.GetLoader(caf::kNEARDET, Loaders::kData),
69  axis, cut, shiftMC, shiftData, wei)
70  {
71  }
72 
74  {
75  }
76 
77 
78  //---------------------38 North------------------------------------------
79  void FakeDecomp::Decompose() const{
80 
81  if(fIsDecomposed) {std::cout<<"GO AWAY, you already decomposed! Stop calling me!"<< std::endl; return;}
82  if(!fIsSet) {std::cout<< "Warning: Current default as NoDecomp, please SetType() first" << std::endl; fType = kNCTotal;}
83 
84  fDiff.resize(kNum);
85  fDiff[fType] = new Spectrum(fData - fTotal);
86  fIsDecomposed = true;
87 
88  }
89 
90  //----------------------------------------------------------------------
92 
93  if(type >= kNum || type < 0){
94  std::cout<< "Unreasonable Decomp Type, reseting to No Decomp"<<std::endl;
95  fType = kNCTotal;
96  fIsDecomposed = false;
97  fIsSet = true;
98  }
99  else{
100  fType = type;
101  fIsDecomposed = false;
102  fIsSet = true;
103  }
104  }
105 
106  //----------------------------------------------------------------------
108  {
109  if(!fIsDecomposed) Decompose();
110 
111  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
112  return fNue + *fDiff[kNue];
113  }
114 
115 
116  //----------------------------------------------------------------------
118  {
119  if(!fIsDecomposed) Decompose();
120 
121  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
122  return fAntiNue + *fDiff[kAntiNue];
123  }
124 
125  //----------------------------------------------------------------------
127  {
128  if(!fIsDecomposed) Decompose();
129 
130  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
131  return fNumu + *fDiff[kNumu];
132  }
133  //----------------------------------------------------------------------
135  {
136  if(!fIsDecomposed) Decompose();
137 
138  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
139  return fAntiNumu + *fDiff[kAntiNumu];
140  }
141 
142  //----------------------------------------------------------------------
144  {
145  if(!fIsDecomposed) Decompose();
146 
147  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
148  return fNC + *fDiff[kNC];
149  }
150  //----------------------------------------------------------------------
152  {
153  if(!fIsDecomposed) Decompose();
154 
155  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
156  return fNCAnti + *fDiff[kAntiNC];
157  }
158  //----------------------------------------------------------------------
160  {
161  if(!fIsDecomposed) Decompose();
162 
163  assert(fIsDecomposed && "GO AWAY!!! Decompose to a specific type first!!!!!");
164  return fNCTot + *fDiff[kNCTotal];
165  }
166  //----------------------------------------------------------------------
167  //
168 
169  void FakeDecomp::SaveTo(TDirectory* dir, const std::string& name) const
170  {
171  TDirectory* tmp = gDirectory;
172 
173  dir = dir->mkdir(name.c_str()); // switch to subdir
174  dir->cd();
175 
176  TObjString("FakeDecomp").Write("type");
177  //nc
178  fNCTot.SaveTo(dir, "nc_tot_comp");
179  fNC.SaveTo(dir, "nc_comp");
180  fNCAnti.SaveTo(dir, "nc_anti_comp");
181  //end nc
182  fData.SaveTo(dir, "data_comp");
183  fTotal.SaveTo(dir, "total_comp");
184  fNue.SaveTo(dir, "nue_comp");
185  fAntiNue.SaveTo(dir, "antinue_comp");
186  fNumu.SaveTo(dir, "numu_comp");
187  fAntiNumu.SaveTo(dir, "antinumu_comp");
188 
189  dir->Write();
190  delete dir;
191 
192  tmp->cd();
193  }
194 
195  //----------------------------------------------------------------------
196  std::unique_ptr<FakeDecomp> FakeDecomp::LoadFrom(TDirectory* dir, const std::string& name)
197  {
198  dir = dir->GetDirectory(name.c_str()); // switch to subdir
199  assert(dir);
200 
201  std::unique_ptr<FakeDecomp> ret(new FakeDecomp);
202 
203  // nc
204  ret->fNCTot = *Spectrum::LoadFrom(dir, "nc_tot_comp");
205  ret->fNC = *Spectrum::LoadFrom(dir, "nc_comp");
206  ret->fNCAnti = *Spectrum::LoadFrom(dir, "nc_anti_comp");
207  //end nc
208  ret->fData = *Spectrum::LoadFrom(dir, "data_comp");
209  ret->fNue = *Spectrum::LoadFrom(dir, "nue_comp");
210  ret->fAntiNue = *Spectrum::LoadFrom(dir, "antinue_comp");
211  ret->fNumu = *Spectrum::LoadFrom(dir, "numu_comp");
212  ret->fAntiNumu = *Spectrum::LoadFrom(dir, "antinumu_comp");
213  ret->fTotal = *Spectrum::LoadFrom(dir, "total_comp");
214 
215  delete dir;
216 
217  return ret;
218  }
219 }
DecompType::Type fType
Definition: FakeDecomp.h:107
Spectrum NumuComponent() const override
Definition: FakeDecomp.cxx:126
const XML_Char * name
Definition: expat.h:151
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
static std::unique_ptr< FakeDecomp > LoadFrom(TDirectory *dir, const std::string &name)
Definition: FakeDecomp.cxx:196
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 fNC
Definition: FakeDecomp.h:97
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Spectrum NueComponent() const override
Definition: FakeDecomp.cxx:107
Spectrum fNumu
Definition: FakeDecomp.h:103
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
Spectrum fNCTot
Definition: FakeDecomp.h:96
const Color_t kMC
Spectrum fNCAnti
Definition: FakeDecomp.h:98
virtual ~FakeDecomp()
Definition: FakeDecomp.cxx:73
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 AntiNumuComponent() const override
Definition: FakeDecomp.cxx:134
Float_t tmp
Definition: plot.C:36
const Cut kNumu([](const caf::SRProxy *sr){if(sr->vtx.nelastic==0) return false;if(sr->mc.nnu==0) return false;return(sr->mc.nu[0].pdg==14);})
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
Spectrum fAntiNumu
Definition: FakeDecomp.h:104
void Decompose() const
Definition: FakeDecomp.cxx:79
Spectrum AntiNueComponent() const override
Definition: FakeDecomp.cxx:117
Uses MC for CC and NC components, assigns remainder of data to CC.
Definition: FakeDecomp.h:22
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 fData
Definition: FakeDecomp.h:91
std::vector< Spectrum * > fDiff
Definition: FakeDecomp.h:116
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
std::vector< float > Spectrum
Definition: Constants.h:570
void SaveTo(TDirectory *dir, const std::string &name) const override
Definition: FakeDecomp.cxx:169
OStream cout
Definition: OStream.cxx:6
const Cut kNue([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;return(sr->mc.nu[0].iscc && sr->mc.nu[0].pdg==12);})
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
Spectrum NCComponent() const override
Definition: FakeDecomp.cxx:143
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
Spectrum fAntiNue
Definition: FakeDecomp.h:101
TDirectory * dir
Definition: macro.C:5
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
void SetType(DecompType::Type type) const
Definition: FakeDecomp.cxx:91
std::vector< Loaders * > loaders
Definition: syst_header.h:386
Spectrum NCAntiComponent() const override
Definition: FakeDecomp.cxx:151
Spectrum NCTotalComponent() const override
Definition: FakeDecomp.cxx:159
Spectrum fNue
Definition: FakeDecomp.h:100
assert(nhit_max >=nhit_nbins)
This module creates Common Analysis Files.
Definition: FileReducer.h:10
Spectrum fTotal
Definition: FakeDecomp.h:94