NDExtrapComponent.cxx
Go to the documentation of this file.
3 
4 #include <utility>
5 
7 #include "CAFAna/Core/Loaders.h"
9 #include "CAFAna/Cuts/Cuts.h"
10 
11 #include "TDirectory.h"
12 #include "TH1D.h"
13 #include "TObject.h"
14 #include "TObjString.h"
15 #include <cassert>
16 
17 namespace ana
18 {
19  //---------------------------------------------------------------------------
21  const HistAxis& axis,
22  const Cut& selection,
23  const SystShifts& shiftMC,
24  const Var& weight)
25  : fKaonComponent(new NDExtrapBeamComponent(loader, axis, selection, 0, shiftMC, weight)),
26  fPionComponent(new NDExtrapBeamComponent(loader, axis, selection, 1, shiftMC, weight)),
27  fMuonComponent(new NDExtrapBeamComponent(loader, axis, selection, 2, shiftMC, weight))
28  {
29  }
30 
31  //---------------------------------------------------------------------------
32  NDOscillatableSpectrum NDExtrapComponent::ExtrapComponent(double KaonScale, double PionScale, double MuonScale)
33  {
34 
35  NDOscillatableSpectrum totalSpec = fKaonComponent->Component();
36  totalSpec.Scale(KaonScale);
37  NDOscillatableSpectrum frompion = fPionComponent->Component();
38  frompion.Scale(PionScale);
39  totalSpec += frompion;
40  NDOscillatableSpectrum frommuon = fMuonComponent->Component();
41  frommuon.Scale(MuonScale);
42  totalSpec +=frommuon;
43 
44  return totalSpec;
45  }
46 
47  //---------------------------------------------------------------------------
48  void NDExtrapComponent::SaveTo(TDirectory* dir, const std::string& name) const
49  {
50  TDirectory* tmp = gDirectory;
51 
52  dir = dir->mkdir(name.c_str()); // switch to subdir
53  dir->cd();
54 
55  TObjString("NDExtrapComponent").Write("type");
56 
57  fKaonComponent->SaveTo(dir, "ndextrapbeamcompkaon");
58  fPionComponent->SaveTo(dir, "ndextrapbeamcomppion");
59  fMuonComponent->SaveTo(dir, "ndextrapbeamcompmuon");
60 
61  dir->Write();
62  delete dir;
63 
64  tmp->cd();
65  }
66 
67  //---------------------------------------------------------------------------
68 
69  std::unique_ptr<NDExtrapComponent> NDExtrapComponent::LoadFrom(TDirectory* dir, const std::string& name)
70  {
71  dir = dir->GetDirectory(name.c_str()); // switch to subdir
72  assert(dir);
73 
74  std::unique_ptr<NDExtrapComponent> ret(new NDExtrapComponent);
75 
76  ret->fKaonComponent = ana::LoadFrom<NDExtrapBeamComponent>(dir, "ndextrapbeamcompkaon");
77 
78  ret->fPionComponent = ana::LoadFrom<NDExtrapBeamComponent>(dir, "ndextrapbeamcomppion");
79 
80  ret->fMuonComponent = ana::LoadFrom<NDExtrapBeamComponent>(dir, "ndextrapbeamcompmuon");
81 
82  delete dir;
83 
84  return ret;
85  }
86 
87 } ///// end of namespace ana //
const XML_Char * name
Definition: expat.h:151
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
std::unique_ptr< NDExtrapBeamComponent > fKaonComponent
NDOscillatableSpectrum ExtrapComponent(double KaonScale, double PionScale, double MuonScale)
std::unique_ptr< NDExtrapBeamComponent > fPionComponent
Float_t tmp
Definition: plot.C:36
static std::unique_ptr< NDExtrapComponent > LoadFrom(TDirectory *dir, const std::string &name)
virtual void SaveTo(TDirectory *dir, const std::string &name) const
loader
Definition: demo0.py:10
Base class for the various types of spectrum loader.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
std::unique_ptr< NDExtrapBeamComponent > fMuonComponent
Spectrum with true L/E information, allowing it to be oscillated