JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
LinReg_Bevington_Pebay.h
Go to the documentation of this file.
1/*!
2 * \file LinReg_Bevington_Pebay.h
3 * \brief Linear regression utility class based on Bevington and Pebay algorithms
4 * \author Jan Balewski, MIT
5 * \date 2010
6 *
7 * References:
8 * "Data reduction and error analysis for the physical sciences"
9 * Philip R. Bevington, D. Keith Robinson. Bevington, Philip R., 1933- Boston : McGraw-Hill, c2003.
10 *
11 * "Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments"
12 * Philippe Pebay, SANDIA REPORT SAND2008-6212, Unlimited Release, Printed September 2008
13 */
14
15#pragma once
16
17// System headers
18#include <utility>
19
20// ROOT headers
21#include <TVectorD.h>
22#include <TMatrixD.h>
23
24//-----------------------------------------
25/**
26 * \class LinRegBevPeb
27 * \ingroup QwAnalysis_BL
28 * \brief Online linear regression with incremental covariance updates
29 */
31 int nP; // number of independent variables
32 int nY; // number of dependent variables
33
34 private:
35 Int_t fErrorFlag; ///< is information valid
36 Long64_t fGoodEventNumber; ///< accumulated so far
37
38 /// correlations
39 TMatrixD mRPY, mRYP;
40 TMatrixD mRPP, mRYY;
41 TMatrixD mRYYp;
42
43 /// unnormalized covariances
44 TMatrixD mVPY, mVYP;
45 TMatrixD mVPP, mVYY;
46 TMatrixD mVYYp;
47 /// variances
48 TVectorD mVP, mVY;
49 TVectorD mVYp;
50
51 /// normalized covariances
52 TMatrixD mSPY, mSYP;
53 TMatrixD mSPP, mSYY;
54 TMatrixD mSYYp;
55 /// sigmas
56 TVectorD mSP, mSY;
57 TVectorD mSYp;
58
59 /// mean values
60 TVectorD mMP, mMY, mMYp;
61
62
63 /// slopes
64 TMatrixD Axy, Ayx, dAxy, dAyx; // found slopes and their standard errors
65
66 public:
67
69 LinRegBevPeb(const LinRegBevPeb& source);
70 virtual ~LinRegBevPeb() { };
71
72 void solve();
73 bool failed() { return fGoodEventNumber < nP + 1; }
74
75 // after last event
76 void printSummaryP() const;
77 void printSummaryY() const;
78 void printSummaryYP() const;
79 void printSummaryAlphas() const;
80 void printSummaryMeansWithUnc() const;
82
83 void print();
84 void init();
85 void clear();
86 void setDims(int a, int b){ nP = a; nY = b;}
87
88 /// Get mean value of a variable, returns error code
89 Int_t getMeanP(const int i, Double_t &mean) const;
90 Int_t getMeanY(const int i, Double_t &mean) const;
91 Int_t getMeanYprime(const int i, Double_t &mean) const;
92
93 /// Get mean value of a variable, returns error code
94 Int_t getSigmaP(const int i, Double_t &sigma) const;
95 Int_t getSigmaY(const int i, Double_t &sigma) const;
96 Int_t getSigmaYprime(const int i, Double_t &sigma) const;
97
98 /// Get mean value of a variable, returns error code
99 Int_t getCovarianceP (int i, int j, Double_t &covar) const;
100 Int_t getCovariancePY(int ip, int iy, Double_t &covar) const;
101 Int_t getCovarianceY (int i, int j, Double_t &covar) const;
102
103 double getUsedEve() const { return fGoodEventNumber; };
104
105 // Addition-assignment
106 LinRegBevPeb& operator+=(const std::pair<TVectorD,TVectorD>& rhs);
108 // Addition using addition-assignment
109 friend // friends defined inside class body are inline and are hidden from non-ADL lookup
110 LinRegBevPeb operator+(LinRegBevPeb lhs, // passing lhs by value helps optimize chained a+b+c
111 const LinRegBevPeb& rhs) // otherwise, both parameters may be const references
112 {
113 lhs += rhs; // reuse compound assignment
114 return lhs; // return the result by value (uses move constructor)
115 }
116
117 /// \brief Output stream operator
118 friend std::ostream& operator<< (std::ostream& stream, const LinRegBevPeb& h);
119
120 /// Friend class with correlator for ROOT tree output
121 friend class QwCorrelator;
122};
123
124/// Output stream operator
125inline std::ostream& operator<< (std::ostream& stream, const LinRegBevPeb& h)
126{
127 stream << "LRB: " << h.fGoodEventNumber << " events";
128 return stream;
129}
std::ostream & operator<<(std::ostream &stream, const LinRegBevPeb &h)
Output stream operator.
Online linear regression with incremental covariance updates.
Int_t getCovarianceP(int i, int j, Double_t &covar) const
Get mean value of a variable, returns error code.
void printSummaryYP() const
Int_t getCovarianceY(int i, int j, Double_t &covar) const
Int_t getSigmaY(const int i, Double_t &sigma) const
friend std::ostream & operator<<(std::ostream &stream, const LinRegBevPeb &h)
Output stream operator.
void setDims(int a, int b)
TMatrixD mVPY
unnormalized covariances
void printSummaryMeansWithUncCorrected() const
void printSummaryAlphas() const
TMatrixD mRPY
correlations
Int_t getMeanY(const int i, Double_t &mean) const
Int_t getMeanYprime(const int i, Double_t &mean) const
double getUsedEve() const
Int_t getMeanP(const int i, Double_t &mean) const
Get mean value of a variable, returns error code.
friend class QwCorrelator
Friend class with correlator for ROOT tree output.
Int_t getCovariancePY(int ip, int iy, Double_t &covar) const
Long64_t fGoodEventNumber
accumulated so far
void printSummaryMeansWithUnc() const
Int_t getSigmaYprime(const int i, Double_t &sigma) const
friend LinRegBevPeb operator+(LinRegBevPeb lhs, const LinRegBevPeb &rhs)
TMatrixD mSPY
normalized covariances
Int_t fErrorFlag
is information valid
Int_t getSigmaP(const int i, Double_t &sigma) const
Get mean value of a variable, returns error code.
TVectorD mVP
variances
LinRegBevPeb & operator+=(const std::pair< TVectorD, TVectorD > &rhs)
TVectorD mMP
mean values