MichelDecomp.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "CAFAna/Core/Var.h"
6 #include "CAFAna/Core/Cut.h"
8 #include "CAFAna/Core/Binning.h"
9 #include "CAFAna/Vars/Vars.h"
10 
11 #include <vector>
12 
13 class TDirectory;
14 
15 namespace ana
16 {
17  class Loaders;
18 
19  /// This is the Binning scheme used for the # Michel Templates
20  extern const Binning MEBinning;
21  extern const HistAxis MEAxis;
22 
24  {
25  std::vector<double> numuScales;
26  std::vector<double> ncScales;
27  std::vector<double> nueScales;
28  };
29 
30  /// Help reduce verbosity when passing hist values between MichelDecomp funcs
31  struct MDCMPHelper
32  {
33  double fSumData;
34  double fSumNumu;
35  double fSumNC;
36  double fSumNue;
37  double fNueScale;
38 
39  // Other scales from input decomp
40  double fNumuScale;
41  double fNCScale;
42  };
43 
44  class MichelDecomp: public IDecomp
45  {
46  public:
47  MichelDecomp(SpectrumLoaderBase& NDMCloader,
48  SpectrumLoaderBase& NDdataloader,
49  const HistAxis& axis,
50  const Cut& cut,
51  const IDecomp* nNueEstimate,
52  const SystShifts& shiftMC = kNoShift,
53  const SystShifts& shiftData = kNoShift,
54  const Var& wei = kUnweighted);
55 
56  MichelDecomp(SpectrumLoaderBase& NDMCloader,
57  SpectrumLoaderBase& NDdataloader,
59  const Binning& bins,
60  const Var& var,
61  const Cut& cut,
62  const IDecomp* nNueEstimate,
63  const SystShifts& shiftMC = kNoShift,
64  const SystShifts& shiftData = kNoShift,
65  const Var& wei = kUnweighted);
66 
68  const HistAxis& axis,
69  const Cut& cut,
70  const IDecomp* nNueEstimate,
71  const SystShifts& shiftMC = kNoShift,
72  const SystShifts& shiftData = kNoShift,
73  const Var& wei = kUnweighted);
74 
75  ~MichelDecomp();
76 
77  //nc
78  virtual Spectrum NCTotalComponent() const override;
79  virtual Spectrum NCComponent() const override;
80  virtual Spectrum NCAntiComponent() const override;
81  //end nc
82  virtual Spectrum NumuComponent() const override;
83  virtual Spectrum AntiNumuComponent() const override;
84  virtual Spectrum NueComponent() const override;
85  virtual Spectrum AntiNueComponent() const override;
86 
87  virtual Spectrum Data_Component() const override;
88 
89  virtual Spectrum MCTotal() const{return NCAntiComponent() +NCComponent()+NumuComponent()+AntiNumuComponent()+NueComponent()+AntiNueComponent();}
90 
91  // Convenient for making decomposition blessed plots
92  Spectrum MC_NCTotalComponent() const override;
93  Spectrum MC_NCComponent() const override;
94  Spectrum MC_NCAntiComponent() const override;
95  Spectrum MC_NumuComponent() const override;
96  Spectrum MC_AntiNumuComponent() const override;
97  Spectrum MC_NueComponent() const override;
98  Spectrum MC_AntiNueComponent() const override;
99 
100  virtual Spectrum MC_MCTotal() const{return MC_NCTotalComponent() + MC_NumuComponent() + MC_AntiNumuComponent() + MC_NueComponent() + MC_AntiNueComponent();}
101 
102  void SavePlots(TDirectory* dir) const;
103 
104 
105  virtual void SaveTo(TDirectory* dir, const std::string& name) const override;
106  static std::unique_ptr<MichelDecomp> LoadFrom(TDirectory* dir, const std::string& name);
107 
108  const IDecomp* GetNueEstimateDecomp() const {return fNueEstimate;}
109  protected:
111  Spectrum numu, Spectrum antinumu,
112  Spectrum nue, Spectrum antinue, Spectrum data,
113  ReweightableSpectrum michelnc,
114  ReweightableSpectrum michelnumu,
115  ReweightableSpectrum michelnue,
116  ReweightableSpectrum micheldata,
117  const IDecomp* nueestimate)
118  : fNC(nc),
119  fAntiNC(antinc),
120  fNumu(numu),
121  fAntiNumu(antinumu),
122  fNue(nue),
123  fAntiNue(antinue),
124  fData(data),
125  fMichelNC(michelnc),
126  fMichelNumu(michelnumu),
127  fMichelNue(michelnue),
128  fMichelData(micheldata),
129  fNueEstimate(nueestimate),
130  fOwnNueEstimate(false),
131  isDecomposed(false) {}
132 
133  void Decompose() const;
134 
135 
136  // For bins with low stats PropDecomp
137  void SplitByProp(MDCMPHelper hSums,
138  std::vector<double> &numuScales,
139  std::vector<double> &ncScales,
140  std::vector<double> &nueScales) const;
141  // Or scales from input decomp
142  void SplitByNue(MDCMPHelper hSums,
143  std::vector<double> &numuScales,
144  std::vector<double> &ncScales,
145  std::vector<double> &nueScales) const;
146 
147  void SplitByMichels(int EIdx, MDCMPHelper hSums,
148  std::vector<double> &numuScales,
149  std::vector<double> &ncScales,
150  std::vector<double> &nueScales) const;
151 
152 
153  // These functions cover the algebra --->
154  double GetNueScale(int EIdx) const;
155  double GetNumuScale(int EIdx) const;
156  double GetNCScale(int EIdx) const;
157  double GetNumuMCContent(int EIdx) const;
158  double GetNCMCContent(int EIdx) const;
159  double ComputeScaleFactor(int EIdx,
160  MDCMPHelper hSums) const;
161  double CalculateMCMean(double h,
162  double Numu,
163  double NC,
164  double Nue,
165  MDCMPHelper hSums) const;
166  double MDCMPLogLikelihood(double h,
167  int EIdx,
168  MDCMPHelper hSums) const;
169  double ComputeMaxScale(MDCMPHelper hSums) const;
170  double GetSum(ReweightableSpectrum spect, int EIdx) const;
171  double GetTemplateContent (ReweightableSpectrum spect,
172  int EIdx, int mIdx) const;
173  // <---
174 
175  // Apply scale factors from fit to MC spectra
176  virtual Spectrum MCToDCMPComp(std::vector<double>, Spectrum) const;
177 
178  // Called by SavePlots
179  void SaveCompPlots(TDirectory* dir, std::string comp,
180  Spectrum dcmp, Spectrum mc) const;
181  void SaveTempPlots(TDirectory* dir) const;
182 
194 
195  const IDecomp* fNueEstimate; // Fix beam nue's to different decomp
197 
198  mutable bool isDecomposed;
200  };
201 }
std::vector< double > ncScales
Definition: MichelDecomp.h:26
const XML_Char * name
Definition: expat.h:151
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
virtual Spectrum MCTotal() const
Definition: MichelDecomp.h:89
const Binning MEBinning
This is the Binning scheme used for the # Michel Templates.
void SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
MichelDecomp(Spectrum nc, Spectrum antinc, Spectrum numu, Spectrum antinumu, Spectrum nue, Spectrum antinue, Spectrum data, ReweightableSpectrum michelnc, ReweightableSpectrum michelnumu, ReweightableSpectrum michelnue, ReweightableSpectrum micheldata, const IDecomp *nueestimate)
Definition: MichelDecomp.h:110
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
Spectrum with the value of a second variable, allowing for reweighting
const IDecomp * fNueEstimate
Definition: MichelDecomp.h:195
std::unique_ptr< T > LoadFrom(TDirectory *dir, const std::string &label)
Definition: LoadFromFile.h:17
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
const XML_Char const XML_Char * data
Definition: expat.h:268
ReweightableSpectrum fMichelNumu
Definition: MichelDecomp.h:191
ReweightableSpectrum fMichelData
Definition: MichelDecomp.h:193
Help reduce verbosity when passing hist values between MichelDecomp funcs.
Definition: MichelDecomp.h:31
std::vector< double > nueScales
Definition: MichelDecomp.h:27
std::vector< double > numuScales
Definition: MichelDecomp.h:25
ReweightableSpectrum fMichelNue
Definition: MichelDecomp.h:192
const SystShifts kNoShift
Definition: SystShifts.cxx:21
Base class for the various types of spectrum loader.
const Binning bins
Definition: NumuCC_CPiBin.h:8
virtual Spectrum MC_MCTotal() const
Definition: MichelDecomp.h:100
const Cut cut
Definition: exporter_fd.C:30
const IDecomp * GetNueEstimateDecomp() const
Definition: MichelDecomp.h:108
TDirectory * dir
Definition: macro.C:5
std::vector< Loaders * > loaders
Definition: syst_header.h:386
Standard interface to all decomposition techniques.
Definition: IDecomp.h:13
float fNC[pidBins]
enum BeamMode nc
const HistAxis MEAxis("N_{Michels}", MEBinning, kNMichels)
Definition: MichelDecomp.h:21
MDCMPFitResults fFitResult
Definition: MichelDecomp.h:199
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96
ReweightableSpectrum fMichelNC
Definition: MichelDecomp.h:190
enum BeamMode string