QuantileCuts.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "CAFAna/Core/Spectrum.h"
5 #include "CAFAna/Core/HistAxis.h"
6 #include "CAFAna/Core/Cut.h"
7 #include "CAFAna/Core/Var.h"
9 #include "CAFAna/Core/Var.h"
10 #include "CAFAna/Cuts/SpillCuts.h"
12 
13 class TH2;
14 
15 namespace ana{
16  /// \brief Returns a TH2D with xAxis as independentAxis and yAxis as quantileAxis
17  /// Quantiles in yAxis can be calculated from this using \ref ana::GetQuantileBins
18  TH2* MakeQuantileHistogram(SpectrumLoader& loader,
19  const HistAxis& independentAxis,
20  const HistAxis& quantileAxis,
21  const Cut& cut,
22  const SpillCut& spillCut = kStandardSpillCuts,
23  const SystShifts& shift = kNoShift,
24  const Var& wei = kUnweighted);
25  /// \brief Returns a 2D vector
26  /// First index is the independentAxis bin number
27  /// Second index is the high bin edge for a quantile
28  /// [i][j-1] is jth quantile's low edge for ith independentAxis bin
29  /// [i][j] is jth quantile's high edge for ith independentAxis bin
30  std::vector<std::vector<double>> GetQuantileBins(TH2* quantileHist,
31  const HistAxis& independentAxis,
32  const HistAxis& quantileAxis,
33  const unsigned int& numQuantiles,
34  const bool verbose = true);
35  /// \brief Returns a 2D vector
36  /// First index is the independentAxis bin number
37  /// Second index is the high bin edge for a quantile
38  /// [i][j-1] is jth quantile's low edge for ith independentAxis bin
39  /// [i][j] is jth quantile's high edge for ith independentAxis bin
40  std::vector<std::vector<double>> GetQuantileBins(SpectrumLoader& loader,
41  const HistAxis& independentAxis,
42  const HistAxis& quantileAxis,
43  const Cut& cut,
44  const unsigned int& numQuantiles,
45  const SpillCut& spillCut = kStandardSpillCuts,
46  const SystShifts& shift = kNoShift,
47  const Var& wei = kUnweighted,
48  const bool verbose = true);
49 
50  /// \brief Class to Generate a \ref ana::Cut that passes events that fall into the requested quantile in quantile axis. It is specialised via the constructor arguments
51  /// \param independentAxis - each bin on this axis will be treated independently (i.e. quantiles will be calculated for each independentAxis bin)
52  /// \param quantileAxis - the axis to split into quantiles. This is done separately for each independentAxis bin
53  /// \param quantile - the quantile to pass, other quantiles fail. The first quantile is 1
54  /// \param quantileBins - 2D array specifying quantileAxis quantile edges. 1st index is over independentAxis, second over quantile
55 
57  public:
58 
59  QuantileCutGenerator(const HistAxis& independentAxis,
60  const HistAxis& quantileAxis,
61  const unsigned int& quantile,
62  const std::vector<std::vector<double>>& quantileBins);
63 
64  /// \brief Defines the Cut this Instance generates. Returns true if the slice is in the quantile set in quantile
65  bool operator() (const caf::SRProxy* sr) const;
66  protected:
69  unsigned int fQuantile;
70  std::vector<std::vector<double>> fQuantileBins;
71  };
72 
73  /// \brief Returns a Cut that will only pass events falling into a particular quantile of quantileAxis, where quantiles have been calculated for each independentAxis bin
74  /// Quantiles have been precalculated in 'quantileBins' (number of quantiles, bin edges etc.)
75  const Cut QuantileCut(const std::vector<std::vector<double>>& quantileBins,
76  const HistAxis& independentAxis,
77  const HistAxis& quantileAxis,
78  const unsigned int& quantile);
79 
80  /// \brief Returns a vector of Cuts, each one for a different quantile
81  /// An individual cut will only pass events falling into a particular quantile of quantileAxis, where quantiles have been calculated for each independentAxis bin
82  std::vector<Cut> QuantileCuts(SpectrumLoader& loader,
83  const HistAxis& independentAxis,
84  const HistAxis& quantileAxis,
85  const Cut& cut,
86  const unsigned int& numQuantiles,
87  const SpillCut& spillCut = kStandardSpillCuts,
88  const SystShifts& shift = kNoShift,
89  const Var& wei = kUnweighted,
90  const bool verbose = true);
91 
92  /// \brief Returns a vector of Cuts, each one for a different quantile
93  /// An individual cut will only pass events falling into a particular quantile of quantileAxis, where quantiles have been calculated for each independentAxis bin
94  /// This function takes in a 2D FD spectra which has already been filled (by whatever means.)
95  std::vector<Cut> QuantileCutsFromTH2(
96  TH2* quantileHist,
97  const HistAxis& independentAxis,
98  const HistAxis& quantileAxis,
99  const unsigned int& numQuantiles,
100  const bool verbose = true
101  );
102 
103  std::vector<Cut> QuantileAndPIDCutsFromTH2(
104  TH2* quantileHist,
105  const HistAxis& independentAxis,
106  const HistAxis& quantileAxis,
107  const unsigned int& numQuantiles,
108  const bool rhc = true,
109  const bool verbose = true
110  );
111 
112 
113 }//namespace
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const Cut QuantileCut(const std::vector< std::vector< double >> &quantileBins, const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &quantile)
Returns a Cut that will only pass events falling into a particular quantile of quantileAxis, where quantiles have been calculated for each independentAxis bin Quantiles have been precalculated in &#39;quantileBins&#39; (number of quantiles, bin edges etc.)
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
std::vector< std::vector< double > > GetQuantileBins(TH2 *quantileHist, const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &numQuantiles, const bool verbose)
Returns a 2D vector First index is the independentAxis bin number Second index is the high bin edge f...
std::vector< Cut > QuantileCuts(SpectrumLoader &loader, const HistAxis &independentAxis, const HistAxis &quantileAxis, const Cut &cut, const unsigned int &numQuantiles, const SpillCut &spillCut, const SystShifts &shift, const Var &wei, const bool verbose)
Returns a vector of Cuts, each one for a different quantile An individual cut will only pass events f...
_Var< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:74
std::vector< std::vector< double > > fQuantileBins
Definition: QuantileCuts.h:70
_Cut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
caf::StandardRecord * sr
loader
Definition: demo0.py:10
_Cut< caf::SRSpillProxy > SpillCut
Equivalent of Cut acting on caf::SRSpill. For use in spill-by-spill data quality cuts.
Definition: Cut.h:100
unsigned int quantile(std::vector< std::vector< double >> v, float E, float hadEfrac)
Definition: Toy_analyses.C:480
TH2 * MakeQuantileHistogram(SpectrumLoader &loader, const HistAxis &independentAxis, const HistAxis &quantileAxis, const Cut &cut, const SpillCut &spillCut, const SystShifts &shift, const Var &wei)
Returns a TH2D with xAxis as independentAxis and yAxis as quantileAxis Quantiles in yAxis can be calc...
const SystShifts kNoShift
Definition: SystShifts.cxx:22
const Cut cut
Definition: exporter_fd.C:30
bool operator()(const caf::SRProxy *sr) const
Defines the Cut this Instance generates. Returns true if the slice is in the quantile set in quantile...
std::vector< Cut > QuantileAndPIDCutsFromTH2(TH2 *quantileHist, const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &numQuantiles, const bool rhc, const bool verbose)
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::vector< Cut > QuantileCutsFromTH2(TH2 *quantileHist, const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &numQuantiles, const bool verbose)
: Do the same as the QuantileCuts function but taking in the TH2 instead of making it...
QuantileCutGenerator(const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &quantile, const std::vector< std::vector< double >> &quantileBins)
Class to Generate a Quantile ana::Cut that is specialised via the constructor arguments.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Class to Generate a ana::Cut that passes events that fall into the requested quantile in quantile axi...
Definition: QuantileCuts.h:56
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96