LikelihoodCovMxExperiment.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "CAFAna/Core/Spectrum.h"
7 
8 #include <Eigen/Core>
9 
10 namespace ana
11 {
12  /// Compare a single data spectrum to the MC + cosmics expectation
14  {
15  public:
16  /// \param samples Source of concatenated oscillated MC beam predictions
17  /// \param covmx Covariance matrix
18  /// \epsilon epsilon value to add onto the diagonal to aid matrix inversion
19  LikelihoodCovMxExperiment(std::vector<covmx::Sample> samples,
20  covmx::CovarianceMatrix* covmx, double epsilon=1e-5,
21  double lambdazero=0, double nu=10);
22 
24 
26  const SystShifts& syst = SystShifts::Nominal()) const override;
27 
28  void Reset() const override;
29 
30  double GetStatChiSq() { return fStatChiSq; };
31  double GetSystChiSq() { return fSystChiSq; };
32  double GetResidual() { return fResidual; };
33  double GetIteration() { return fIteration; };
34 
35  // Debug histograms
36  void SaveHists(bool opt=true);
37  TH1D* GetBetaHist() { return fBetaHist; };
38  TH1D* GetMuHist() { return fMuHist; };
39  TH1D* GetBetaMuHist() { return fBetaMuHist; };
40  TH1D* GetPredShiftedHist() { return fPredShiftedHist; };
42  TH1D* GetDataHist() { return fDataHist; };
43 
44  // Configurable options
45  void SetVerbose(bool opt) { fVerbose = opt; };
46  void SetResetShifts(bool val = false) { fResetShifts = val; };
47 
48  protected:
49 
50  Eigen::ArrayXd GetExpectedSpectrum() const;
51  double GetChiSq(Eigen::ArrayXd e) const;
52 
53  void InitialiseBetas() const;
54  bool MaskBetas() const;
55  void GetGradAndHess() const;
56  void GetReducedGradAndHess() const;
57  double LikelihoodCovMxNewton() const;
58  void EnableLMA() const;
59  void ResetLambda() const;
60  void DecreaseLambda() const;
61  void IncreaseLambda() const;
62 
63  std::vector<covmx::Sample> fSamples;
65  mutable Eigen::ArrayXd fMu;
66  mutable Eigen::ArrayXd fBeta;
67  mutable std::vector<bool> fBetaMask;
68  Eigen::ArrayXd fData;
69  Eigen::ArrayXd fCosmic;
70 
71  mutable Eigen::VectorXd fGrad;
72  mutable Eigen::MatrixXd fHess;
73  mutable Eigen::VectorXd fGradReduced;
74  mutable Eigen::MatrixXd fHessReduced;
75 
76  unsigned int fNBins;
77  unsigned int fNBinsFull;
78  std::vector<unsigned int> fNBinsPerSample;
79  std::vector<std::vector<covmx::Component>> fComps;
80 
81  mutable bool fUseLMA; /// Whether to use LMA
82  double fLambdaZero; /// Levenberg-Marquardt starting lambda
83  double fNu; /// Levenberg-Marquardt nu
84  mutable double fLambda; /// Levenberg-Marquardt lambda
85 
86  TH1D* fBetaHist;
87  TH1D* fMuHist;
88  TH1D* fBetaMuHist;
91  TH1D* fDataHist;
92  Eigen::MatrixXd fMxInv;
94  bool fVerbose;
95 
96  mutable double fStatChiSq;
97  mutable double fSystChiSq;
98  mutable double fResidual;
99  mutable int fIteration;
100 
101  };
102 }
double fLambda
Levenberg-Marquardt nu.
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::vector< std::vector< covmx::Component > > fComps
LikelihoodCovMxExperiment(std::vector< covmx::Sample > samples, covmx::CovarianceMatrix *covmx, double epsilon=1e-5, double lambdazero=0, double nu=10)
double fNu
Levenberg-Marquardt starting lambda.
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
static SystShifts Nominal()
Definition: SystShifts.h:34
TH1D * fBetaHist
Levenberg-Marquardt lambda.
double GetChiSq(Eigen::ArrayXd e) const
Oscillation probability calculators.
Definition: Calcs.h:5
double fLambdaZero
Whether to use LMA.
Compare a single data spectrum to the MC + cosmics expectation.
std::vector< unsigned int > fNBinsPerSample
double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
double epsilon
Base class defining interface for experiments.
Definition: IExperiment.h:14
std::vector< covmx::Sample > fSamples
Float_t e
Definition: plot.C:35
A class for generating a covariance matrices as a function of oscillation parameters and systematics ...