NCDecomp.cxx
Go to the documentation of this file.
2 
3 #include "CAFAna/Cuts/Cuts.h"
4 #include "CAFAna/Core/Ratio.h"
6 
7 #include <cassert>
8 #include <iostream>
9 
10 #include "TDirectory.h"
11 #include "TObjString.h"
12 
13 namespace ana
14 {
15  REGISTER_LOADFROM("NCDecomp", IDecomp, NCDecomp);
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  : NCDecomp(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  fNCTot (loaderMC, axis, cut && kIsNC, shiftMC, wei),
42  fNue (loaderMC, axis, cut && kIsBeamNue&&!kIsAntiNu, shiftMC, wei),
43  fAntiNue (loaderMC, axis, cut && kIsBeamNue&& kIsAntiNu, shiftMC, wei),
44  fNumu (loaderMC, axis, cut && kIsNumuCC &&!kIsAntiNu, shiftMC, wei),
45  fAntiNumu(loaderMC, axis, cut && kIsNumuCC && kIsAntiNu, shiftMC, wei),
46  fNotNC (loaderMC, axis, cut && !kIsNC&& kHasNu, shiftMC, wei)
47  {
48  }
49 
50  //----------------------------------------------------------------------
52  const HistAxis& axis,
53  const Cut& cut,
54  const SystShifts& shiftMC,
55  const SystShifts& shiftData,
56  const Var& wei)
57  : NCDecomp(loaders.GetLoader(caf::kNEARDET, Loaders::kMC),
58  loaders.GetLoader(caf::kNEARDET, Loaders::kData),
59  axis, cut, shiftMC, shiftData, wei)
60  {
61  }
62 
63  //----------------------------------------------------------------------
65  {
66  // Subtract backgrounds from data using MC, then split into nu/antinu
67  // components using MC ratio
68  return fData-fNotNC;
69  }
70 
71  Spectrum NCDecomp::NCComponent() const {std::cout << "NCDecomp::NCComponent() not implemented" << std::endl; abort();}
72  Spectrum NCDecomp::NCAntiComponent() const {std::cout << "NCDecomp::NCAntiComponent() not implemented" << std::endl; abort();}
73 
74 
75  //----------------------------------------------------------------------
76  void NCDecomp::SaveTo(TDirectory* dir, const std::string& name) const
77  {
78  TDirectory* tmp = gDirectory;
79 
80  dir = dir->mkdir(name.c_str()); // switch to subdir
81  dir->cd();
82 
83  TObjString("NCDecomp").Write("type");
84  fNCTot.SaveTo(dir, "nc_tot_comp");
85  fData.SaveTo(dir, "data_comp");
86  fNue.SaveTo(dir, "nue_comp");
87  fAntiNue.SaveTo(dir, "antinue_comp");
88  fNumu.SaveTo(dir, "numu_comp");
89  fAntiNumu.SaveTo(dir, "antinumu_comp");
90  fNotNC.SaveTo(dir, "notnc_comp");
91 
92  dir->Write();
93  delete dir;
94 
95  tmp->cd();
96  }
97 
98  //----------------------------------------------------------------------
99  std::unique_ptr<NCDecomp> NCDecomp::LoadFrom(TDirectory* dir, const std::string& name)
100  {
101  dir = dir->GetDirectory(name.c_str()); // switch to subdir
102  assert(dir);
103 
104  std::unique_ptr<NCDecomp> ret(new NCDecomp);
105 
106  ret->fNCTot = *Spectrum::LoadFrom(dir, "nc_tot_comp");
107  ret->fData = *Spectrum::LoadFrom(dir, "data_comp");
108  ret->fNue = *Spectrum::LoadFrom(dir, "nue_comp");
109  ret->fAntiNue = *Spectrum::LoadFrom(dir, "antinue_comp");
110  ret->fNumu = *Spectrum::LoadFrom(dir, "numu_comp");
111  ret->fAntiNumu = *Spectrum::LoadFrom(dir, "antinumu_comp");
112  ret->fNotNC = *Spectrum::LoadFrom(dir, "notnc_comp");
113 
114  delete dir;
115 
116  return ret;
117  }
118 }
Spectrum NCTotalComponent() const override
Definition: NCDecomp.cxx:64
const XML_Char * name
Definition: expat.h:151
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
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
static std::unique_ptr< NCDecomp > LoadFrom(TDirectory *dir, const std::string &name)
Definition: NCDecomp.cxx:99
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
Spectrum fData
Definition: NCDecomp.h:59
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
Spectrum fNumu
Definition: NCDecomp.h:66
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
Spectrum fAntiNumu
Definition: NCDecomp.h:67
const char * label
Uses MC for CC and CC components, assigns remainder of data to NC.
Definition: NCDecomp.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
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
Spectrum NCComponent() const override
Definition: NCDecomp.cxx:71
OStream cout
Definition: OStream.cxx:6
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 fNotNC
Definition: NCDecomp.h:69
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 fNCTot
Definition: NCDecomp.h:62
TDirectory * dir
Definition: macro.C:5
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
std::vector< Loaders * > loaders
Definition: syst_header.h:386
void SaveTo(TDirectory *dir, const std::string &name) const override
Definition: NCDecomp.cxx:76
Spectrum NCAntiComponent() const override
Definition: NCDecomp.cxx:72
assert(nhit_max >=nhit_nbins)
Spectrum fAntiNue
Definition: NCDecomp.h:64
This module creates Common Analysis Files.
Definition: FileReducer.h:10
Spectrum fNue
Definition: NCDecomp.h:63