CovarianceMatrix.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <memory>
5 #include <vector>
6 #include <tuple>
7 
8 #include "CAFAna/Core/Sample.h"
12 
13 #include "OscLib/IOscCalc.h"
14 #include "OscLib/OscCalcSterile.h"
15 
16 #include "TH2D.h"
17 #include "TObjString.h"
18 
19 #include <Eigen/Dense>
20 
21 namespace ana
22 {
23  namespace covmx {
24 
25  typedef std::tuple<Flavors::Flavors_t, Current::Current_t, Sign::Sign_t> Component;
26  std::vector<Component> GetComponents(Sample sample);
27 
28  /// A class for generating a covariance matrices as a function of oscillation parameters and systematics as nuisance parameters
30  {
31  public:
32  virtual ~CovarianceMatrix(){}
33 
34  CovarianceMatrix(std::vector<Sample> samples, std::vector<const ISyst*> systs,
35  int nUniverses=1e5);
36 
37  CovarianceMatrix(Eigen::MatrixXd fullCovMx, Eigen::MatrixXd covMxAbsolute,
38  std::vector<std::pair<Binning, unsigned int>> bins);
39 
40  CovarianceMatrix(Eigen::MatrixXd fullCovMx, std::vector<Sample> samples);
41 
42  CovarianceMatrix(std::vector<Sample> samples);
43 
44  Eigen::MatrixXd Predict(std::vector<Sample> samples,
46  const SystShifts& systs=SystShifts::Nominal());
47 
48  Eigen::MatrixXd Predict(std::vector<double> vBetaMu);
49 
50  // Add matrices together
51  void AddMatrix(CovarianceMatrix* gen);
52 
53  static Eigen::MatrixXd ForcePosDef(Eigen::MatrixXd mx, double epsilon=0.1);
54  static TMatrixD ForcePosDefROOT(Eigen::MatrixXd mx, double epsilon=0.1);
55 
56  // Throw a Feldman-Cousins shifted universe
57  std::vector<Spectrum> GetUniverse(osc::OscCalcSterile* calc,
58  std::vector<covmx::Sample> samples);
59 
60  // So many different types of matrix...
61  Eigen::MatrixXd GetFullCovMx() { return fFullCovMx; }
62  Eigen::MatrixXd GetCovMxAbsolute() { return fCovMxAbsolute; }
63  Eigen::MatrixXd GetCovMxRelative(std::vector<Sample>& samples,
65  Eigen::MatrixXd GetFullCorrMx();
66 
68  std::string GetName() { return fName; }
69 
70  std::vector<covmx::Sample> GetSamples();
71  std::vector<Binning> GetBinnings();
74  std::vector<unsigned int> GetNBins();
75  std::vector<unsigned int> GetNComponents();
76 
77  void SetNUniverses(unsigned int i) { fNUniverses = i; }
78 
79  // Full covariance matrix
80  TH2D* GetFullCovMxTH2();
81 
82  // Oscillated covariance matrix
83  TH2D* GetCovMxAbsoluteTH2();
84  TH2D* GetCovMxRelativeTH2(std::vector<Sample>& samples,
86 
87  TH2D* GetCorrMxTH2();
88  TH2D* GetFullCorrMxTH2();
89 
90  virtual void SaveTo(TDirectory* dir, const std::string& name) const;
91  static std::unique_ptr<CovarianceMatrix> LoadFrom(TDirectory* dir, const std::string& name);
92 
93  CovarianceMatrix() = delete;
94 
95  protected:
96 
97  CovarianceMatrix(Eigen::MatrixXd fullCovMx, Eigen::MatrixXd covMxAbsolute,
98  std::vector<std::vector<double>> edges, std::vector<unsigned int> comps);
99 
100  void BuildFullCovMx(std::vector<Sample> samples,
101  std::vector<const ISyst*> systs);
102 
103  void SetBinning(std::vector<Sample> samples);
104 
105  std::string fName; ///< String name identifier
106  std::vector<std::pair<Binning, unsigned int>> fBins;
107 
108  Eigen::MatrixXd fFullCovMx; ///< Full covariance matrix
109  Eigen::MatrixXd fCovMxAbsolute; ///< Oscillated absolute covariance matrix
110 
111  unsigned int fNUniverses; ///< Number of universes to simulate
112 
113  private:
114 
115  friend class CovMxManager;
116 
117  };
118  } // namespace covmx
119 } // namespace ana
TH2D * GetCovMxRelativeTH2(std::vector< Sample > &samples, osc::IOscCalcAdjustable *calc)
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
vector< Component > GetComponents(Sample sample)
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
Eigen::MatrixXd GetFullCovMx()
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Eigen::MatrixXd fCovMxAbsolute
Oscillated absolute covariance matrix.
Adapt the PMNS_Sterile calculator to standard interface.
Eigen::MatrixXd GetCovMxAbsolute()
void AddMatrix(CovarianceMatrix *gen)
std::string fName
String name identifier.
static SystShifts Nominal()
Definition: SystShifts.h:34
osc::OscCalcDumb calc
std::tuple< Flavors::Flavors_t, Current::Current_t, Sign::Sign_t > Component
Eigen::MatrixXd fFullCovMx
Full covariance matrix.
std::vector< Binning > GetBinnings()
Eigen::MatrixXd GetCovMxRelative(std::vector< Sample > &samples, osc::IOscCalcAdjustable *calc)
static Eigen::MatrixXd ForcePosDef(Eigen::MatrixXd mx, double epsilon=0.1)
void SetNUniverses(unsigned int i)
std::vector< std::string > comps
std::vector< unsigned int > GetNComponents()
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< covmx::Sample > GetSamples()
std::vector< std::pair< Binning, unsigned int > > fBins
void SetName(std::string name)
TDirectory * dir
Definition: macro.C:5
static TMatrixD ForcePosDefROOT(Eigen::MatrixXd mx, double epsilon=0.1)
std::vector< unsigned int > GetNBins()
double epsilon
void SetBinning(std::vector< Sample > samples)
static std::unique_ptr< CovarianceMatrix > LoadFrom(TDirectory *dir, const std::string &name)
virtual void SaveTo(TDirectory *dir, const std::string &name) const
void BuildFullCovMx(std::vector< Sample > samples, std::vector< const ISyst * > systs)
Eigen::MatrixXd Predict(std::vector< Sample > samples, osc::IOscCalcAdjustable *calc, const SystShifts &systs=SystShifts::Nominal())
unsigned int fNUniverses
Number of universes to simulate.
std::vector< Spectrum > GetUniverse(osc::OscCalcSterile *calc, std::vector< covmx::Sample > samples)
A class for generating a covariance matrices as a function of oscillation parameters and systematics ...
enum BeamMode string