TwoSampleDecomp.h
Go to the documentation of this file.
1  #pragma once
2 
4 #include "CAFAna/Core/Cut.h"
6 #include "CAFAna/Core/Spectrum.h"
7 #include "CAFAna/Core/Binning.h"
8 
9 
10 class TDirectory;
11 class TH1D;
12 
13 namespace ana
14 {
15 
16  /*! \brief Class for data driven decomposition of signal and background
17  * using two different samples with slightly different spectra.
18  *
19  *
20  */
21  class TwoSampleDecomp: public IDecomp
22  {
23  public:
24  /*! \brief Constructor for creating spectra from a SpectrumLoader.
25  * Must supply cuts to define samples, first or second. For instance
26  * first: left side, second: right side. Also must define cut to specefiy
27  * signal/background. Analysis cuts are optional, but likely necessary.
28  *
29  * Detailed description starts here.
30  */
32  SpectrumLoaderBase& loaderMC, ///< Spectrum loader for MC
33  SpectrumLoaderBase& loaderData,///< Spectrum loader for data
34  std::string label, ///< Name of the thing
35  const Binning& bins, ///< Desired binning for spectra
36  const Var& var, ///< Variable to be plotted in spectra
37  const Cut& firstSample, ///< Cut to define samples,
38  ///< true: first, false: second
39  const Cut& isSignal = kNoCut, ///< Signal or not? true: sig, false: bkg
40  const Cut& anaCut = kNoCut, ///< Cut to define selection(e.g. numu CC)
41  const SystShifts& shift = kNoShift,
42  const Var& weight = kUnweighted ///< Weight for events in spectrum
43  );
44 
46  SpectrumLoaderBase& loaderMC, ///< Spectrum loader for MC
47  SpectrumLoaderBase& loaderData,///< Spectrum loader for data
48  const HistAxis& axis, ///< Variable to be plotted in spectra
49  const Cut& firstSample, ///< Cut to define samples,
50  ///< true: first, false: second
51  const Cut& isSignal = kNoCut, ///< Signal or not? true: sig, false: bkg
52  const Cut& anaCut = kNoCut, ///< Cut to define selection(e.g. numu CC)
53  const SystShifts& shift = kNoShift,
54  const Var& weight = kUnweighted ///< Weight for events in spectrum
55  );
56 
57  virtual ~TwoSampleDecomp(){};
58 
59 
60  /// \brief Returns the decomposed NC component
61  // nc
62  virtual Spectrum NCTotalComponent() const override {Decomp(); return fBkg;};
63  virtual Spectrum NCComponent() const override;
64  virtual Spectrum NCAntiComponent() const override;
65  // nc end
66 
67  /// \brief Returns the decomposed numu CC component
68  virtual Spectrum NumuComponent() const override {Decomp(); return fSig;};
69 
70  /// \brief Could return the nue CC component, but not implemented for two
71  /// sample decomposition
72  virtual Spectrum NueComponent() const override {Decomp(); return fBkg;};
73 
74  virtual Spectrum AntiNumuComponent() const override {Decomp(); return fBkg;}
75  virtual Spectrum AntiNueComponent() const override {Decomp(); return fBkg;}
76 
77  /// Preform the decomposition using the ratios in the MC sample.
78  void Decomp() const;
79 
80  /// \brief Calculate the ratios for the signal and background, second/first.
81  void RatioCalc()const;
82 
83  void SaveTo(TDirectory* dir, const std::string& name) const override;
84  static std::unique_ptr<TwoSampleDecomp> LoadFrom(TDirectory* dir, const std::string& name);
85 
86  void DrawSigBkgOverlay();
87 
89 
90  void DrawRatios();
91 
94 
95  const HistAxis* fAxis;///< Axis used for spectra
96  Spectrum fFirstSig; ///< Spectrum for first sample, signal
97  Spectrum fSecondSig; ///< Spectrum for second sample, signal
98  Spectrum fFirstBkg; ///< Spectrum for first sample, background
99  Spectrum fSecondBkg; ///< Spectrum for second sample, background
100 
101  Spectrum fTrueSig; ///< True signal spectrum
102  Spectrum fTrueBkg; ///< True backgroundh spectrum
103 
104  Spectrum fFirst; ///< Spectrum of events that pass the firstSample cut
105  Spectrum fSecond; ///< Spectrum of events that fail the firstSample cut
106 
107  mutable Spectrum fSig; ///< Decomposed spectrum of signal events
108  mutable Spectrum fBkg; ///< Decomposed spectrum of signal events
109 
110 
111  mutable TH1D* fSigRatio; ///< Ratio of second/first spectra for signal
112  mutable TH1D* fBkgRatio; ///< Ratio of second/first spectra for bkg
113  mutable bool fDecomposed; ///< Indicates whether decomposition was done
114 
115  protected:
116  TwoSampleDecomp();
117 
118 
119 
120  };
121 
122  /*! \brief Given a numerator and denominator, this class calculates the
123  * ratio and associated error
124  * on that ratio, assuming the errors are gaussian counting errors,
125  * i.e. sqrt(n).
126  */
128  {
129 
130  public:
131  RatioError(double numerator, double denominator);
132  double fRatio;
133  double fError;
134 
135  };
136 
137 }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
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 NCComponent() const override
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Spectrum fTrueSig
True signal spectrum.
virtual Spectrum AntiNumuComponent() const override
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
Spectrum fFirstSig
Spectrum for first sample, signal.
virtual Spectrum NCAntiComponent() const override
bool fDecomposed
Indicates whether decomposition was done.
Class for data driven decomposition of signal and background using two different samples with slightl...
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
Given a numerator and denominator, this class calculates the ratio and associated error on that ratio...
virtual Spectrum NueComponent() const override
Could return the nue CC component, but not implemented for two sample decomposition.
Spectrum fSecondSig
Spectrum for second sample, signal.
TH1D * fSigRatio
Ratio of second/first spectra for signal.
const SpectrumLoaderBase & fLoaderData
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
const HistAxis * fAxis
Axis used for spectra.
Spectrum fTrueBkg
True backgroundh spectrum.
virtual Spectrum NCTotalComponent() const override
Returns the decomposed NC component.
const SystShifts kNoShift
Definition: SystShifts.cxx:22
Base class for the various types of spectrum loader.
const Binning bins
Definition: NumuCC_CPiBin.h:8
virtual Spectrum AntiNueComponent() const override
const SpectrumLoaderBase & fLoaderMC
TDirectory * dir
Definition: macro.C:5
static std::unique_ptr< TwoSampleDecomp > LoadFrom(TDirectory *dir, const std::string &name)
Standard interface to all decomposition techniques.
Definition: IDecomp.h:13
void RatioCalc() const
Calculate the ratios for the signal and background, second/first.
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
void SaveTo(TDirectory *dir, const std::string &name) const override
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
virtual Spectrum NumuComponent() const override
Returns the decomposed numu CC component.
enum BeamMode string