JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
LinRegBevPeb Class Reference

Online linear regression with incremental covariance updates. More...

#include <LinReg_Bevington_Pebay.h>

Public Member Functions

 LinRegBevPeb ()
 
 LinRegBevPeb (const LinRegBevPeb &source)
 
virtual ~LinRegBevPeb ()
 
void solve ()
 
bool failed ()
 
void printSummaryP () const
 
void printSummaryY () const
 
void printSummaryYP () const
 
void printSummaryAlphas () const
 
void printSummaryMeansWithUnc () const
 
void printSummaryMeansWithUncCorrected () const
 
void print ()
 
void init ()
 
void clear ()
 
void setDims (int a, int b)
 
Int_t getMeanP (const int i, Double_t &mean) const
 Get mean value of a variable, returns error code.
 
Int_t getMeanY (const int i, Double_t &mean) const
 
Int_t getMeanYprime (const int i, Double_t &mean) const
 
Int_t getSigmaP (const int i, Double_t &sigma) const
 Get mean value of a variable, returns error code.
 
Int_t getSigmaY (const int i, Double_t &sigma) const
 
Int_t getSigmaYprime (const int i, Double_t &sigma) const
 
Int_t getCovarianceP (int i, int j, Double_t &covar) const
 Get mean value of a variable, returns error code.
 
Int_t getCovariancePY (int ip, int iy, Double_t &covar) const
 
Int_t getCovarianceY (int i, int j, Double_t &covar) const
 
double getUsedEve () const
 
LinRegBevPeboperator+= (const std::pair< TVectorD, TVectorD > &rhs)
 
LinRegBevPeboperator+= (const LinRegBevPeb &rhs)
 

Private Attributes

int nP
 
int nY
 
Int_t fErrorFlag
 is information valid
 
Long64_t fGoodEventNumber
 accumulated so far
 
TMatrixD mRPY
 correlations
 
TMatrixD mRYP
 
TMatrixD mRPP
 
TMatrixD mRYY
 
TMatrixD mRYYp
 
TMatrixD mVPY
 unnormalized covariances
 
TMatrixD mVYP
 
TMatrixD mVPP
 
TMatrixD mVYY
 
TMatrixD mVYYp
 
TVectorD mVP
 variances
 
TVectorD mVY
 
TVectorD mVYp
 
TMatrixD mSPY
 normalized covariances
 
TMatrixD mSYP
 
TMatrixD mSPP
 
TMatrixD mSYY
 
TMatrixD mSYYp
 
TVectorD mSP
 sigmas
 
TVectorD mSY
 
TVectorD mSYp
 
TVectorD mMP
 mean values
 
TVectorD mMY
 
TVectorD mMYp
 
TMatrixD Axy
 slopes
 
TMatrixD Ayx
 
TMatrixD dAxy
 
TMatrixD dAyx
 

Friends

class QwCorrelator
 Friend class with correlator for ROOT tree output.
 
LinRegBevPeb operator+ (LinRegBevPeb lhs, const LinRegBevPeb &rhs)
 
std::ostream & operator<< (std::ostream &stream, const LinRegBevPeb &h)
 Output stream operator.
 

Detailed Description

Online linear regression with incremental covariance updates.

Definition at line 30 of file LinReg_Bevington_Pebay.h.

Constructor & Destructor Documentation

◆ LinRegBevPeb() [1/2]

LinRegBevPeb::LinRegBevPeb ( )

Definition at line 19 of file LinReg_Bevington_Pebay.cc.

20: nP(0),nY(0),
21 fErrorFlag(-1),
23{ }
Long64_t fGoodEventNumber
accumulated so far
Int_t fErrorFlag
is information valid

References fErrorFlag, fGoodEventNumber, nP, and nY.

Referenced by LinRegBevPeb(), operator+, operator+=(), operator+=(), and operator<<.

+ Here is the caller graph for this function:

◆ LinRegBevPeb() [2/2]

LinRegBevPeb::LinRegBevPeb ( const LinRegBevPeb & source)

Definition at line 27 of file LinReg_Bevington_Pebay.cc.

28: nP(source.nP),nY(source.nY),
29 fErrorFlag(-1),
31{
33}
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297

References QwLog::endl(), fErrorFlag, fGoodEventNumber, LinRegBevPeb(), nP, nY, and QwMessage.

+ Here is the call graph for this function:

◆ ~LinRegBevPeb()

virtual LinRegBevPeb::~LinRegBevPeb ( )
inlinevirtual

Definition at line 70 of file LinReg_Bevington_Pebay.h.

70{ };

Member Function Documentation

◆ clear()

void LinRegBevPeb::clear ( )

Definition at line 76 of file LinReg_Bevington_Pebay.cc.

77{
78 mMP.Zero();
79 mMY.Zero();
80 mMYp.Zero();
81
82 mVPP.Zero();
83 mVPY.Zero();
84 mVYP.Zero();
85 mVYY.Zero();
86 mVYYp.Zero();
87 mVP.Zero();
88 mVY.Zero();
89 mVYp.Zero();
90
91 mSPP.Zero();
92 mSPY.Zero();
93 mSYP.Zero();
94 mSYY.Zero();
95 mSYYp.Zero();
96
97 Axy.Zero();
98 Ayx.Zero();
99 dAxy.Zero();
100 dAyx.Zero();
101
102 mSP.Zero();
103 mSY.Zero();
104 mSYp.Zero();
105
106 mRPP.Zero();
107 mRPY.Zero();
108 mRYP.Zero();
109 mRYY.Zero();
110 mRYYp.Zero();
111
112 fErrorFlag = -1;
114}
TMatrixD mVPY
unnormalized covariances
TMatrixD mRPY
correlations
TMatrixD mSPY
normalized covariances
TVectorD mVP
variances
TVectorD mMP
mean values

References Axy, Ayx, dAxy, dAyx, fErrorFlag, fGoodEventNumber, mMP, mMY, mMYp, mRPP, mRPY, mRYP, mRYY, mRYYp, mSP, mSPP, mSPY, mSY, mSYP, mSYp, mSYY, mSYYp, mVP, mVPP, mVPY, mVY, mVYP, mVYp, mVYY, and mVYYp.

◆ failed()

bool LinRegBevPeb::failed ( )
inline

Definition at line 73 of file LinReg_Bevington_Pebay.h.

73{ return fGoodEventNumber < nP + 1; }

References fGoodEventNumber, and nP.

◆ getCovarianceP()

Int_t LinRegBevPeb::getCovarianceP ( int i,
int j,
Double_t & covar ) const

Get mean value of a variable, returns error code.

Definition at line 280 of file LinReg_Bevington_Pebay.cc.

281{
282 covar=-1e50;
283 if( i>j) { int k=i; i=j; j=k; }//swap i & j
284 //... now we need only upper right triangle
285 if(i<0 || i >= nP ) return -11;
286 if( fGoodEventNumber<2) return -14;
287 covar=mVPP(i,j)/(fGoodEventNumber-1.);
288 return 0;
289}

References fGoodEventNumber, mVPP, and nP.

Referenced by printSummaryP().

+ Here is the caller graph for this function:

◆ getCovariancePY()

Int_t LinRegBevPeb::getCovariancePY ( int ip,
int iy,
Double_t & covar ) const

Definition at line 293 of file LinReg_Bevington_Pebay.cc.

294{
295 covar=-1e50;
296 //... now we need only upper right triangle
297 if(ip<0 || ip >= nP ) return -11;
298 if(iy<0 || iy >= nY ) return -12;
299 if( fGoodEventNumber<2) return -14;
300 covar=mVPY(ip,iy)/(fGoodEventNumber-1.);
301 return 0;
302}

References fGoodEventNumber, mVPY, nP, and nY.

Referenced by printSummaryYP().

+ Here is the caller graph for this function:

◆ getCovarianceY()

Int_t LinRegBevPeb::getCovarianceY ( int i,
int j,
Double_t & covar ) const

Definition at line 306 of file LinReg_Bevington_Pebay.cc.

307{
308 covar=-1e50;
309 if( i>j) { int k=i; i=j; j=k; }//swap i & j
310 //... now we need only upper right triangle
311 if(i<0 || i >= nY ) return -11;
312 if( fGoodEventNumber<2) return -14;
313 covar=mVYY(i,j)/(fGoodEventNumber-1.);
314 return 0;
315}

References fGoodEventNumber, mVYY, and nY.

◆ getMeanP()

Int_t LinRegBevPeb::getMeanP ( const int i,
Double_t & mean ) const

Get mean value of a variable, returns error code.

Definition at line 213 of file LinReg_Bevington_Pebay.cc.

214{
215 mean=-1e50;
216 if(i<0 || i >= nP ) return -1;
217 if( fGoodEventNumber<1) return -3;
218 mean = mMP(i); return 0;
219}

References fGoodEventNumber, mMP, and nP.

Referenced by printSummaryP().

+ Here is the caller graph for this function:

◆ getMeanY()

Int_t LinRegBevPeb::getMeanY ( const int i,
Double_t & mean ) const

Definition at line 224 of file LinReg_Bevington_Pebay.cc.

225{
226 mean=-1e50;
227 if(i<0 || i >= nY ) return -1;
228 if( fGoodEventNumber<1) return -3;
229 mean = mMY(i); return 0;
230}

References fGoodEventNumber, mMY, and nY.

Referenced by printSummaryY(), and printSummaryYP().

+ Here is the caller graph for this function:

◆ getMeanYprime()

Int_t LinRegBevPeb::getMeanYprime ( const int i,
Double_t & mean ) const

Definition at line 235 of file LinReg_Bevington_Pebay.cc.

236{
237 mean=-1e50;
238 if(i<0 || i >= nY ) return -1;
239 if( fGoodEventNumber<1) return -3;
240 mean = mMYp(i); return 0;
241}

References fGoodEventNumber, mMYp, and nY.

◆ getSigmaP()

Int_t LinRegBevPeb::getSigmaP ( const int i,
Double_t & sigma ) const

Get mean value of a variable, returns error code.

Definition at line 246 of file LinReg_Bevington_Pebay.cc.

247{
248 sigma=-1e50;
249 if(i<0 || i >= nP ) return -1;
250 if( fGoodEventNumber<2) return -3;
251 sigma=sqrt(mVPP(i,i)/(fGoodEventNumber-1.));
252 return 0;
253}

References fGoodEventNumber, mVPP, and nP.

Referenced by printSummaryP(), and printSummaryYP().

+ Here is the caller graph for this function:

◆ getSigmaY()

Int_t LinRegBevPeb::getSigmaY ( const int i,
Double_t & sigma ) const

Definition at line 258 of file LinReg_Bevington_Pebay.cc.

259{
260 sigma=-1e50;
261 if(i<0 || i >= nY ) return -1;
262 if( fGoodEventNumber<2) return -3;
263 sigma=sqrt(mVYY(i,i)/(fGoodEventNumber-1.));
264 return 0;
265}

References fGoodEventNumber, mVYY, and nY.

Referenced by printSummaryY(), and printSummaryYP().

+ Here is the caller graph for this function:

◆ getSigmaYprime()

Int_t LinRegBevPeb::getSigmaYprime ( const int i,
Double_t & sigma ) const

Definition at line 269 of file LinReg_Bevington_Pebay.cc.

270{
271 sigma=-1e50;
272 if(i<0 || i >= nY ) return -1;
273 if( fGoodEventNumber<2) return -3;
274 sigma=sqrt(mVYYp(i,i)/(fGoodEventNumber-1.));
275 return 0;
276}

References fGoodEventNumber, mVYYp, and nY.

◆ getUsedEve()

double LinRegBevPeb::getUsedEve ( ) const
inline

Definition at line 103 of file LinReg_Bevington_Pebay.h.

103{ return fGoodEventNumber; };

References fGoodEventNumber.

◆ init()

void LinRegBevPeb::init ( )

Definition at line 37 of file LinReg_Bevington_Pebay.cc.

38{
39 mMP.ResizeTo(nP);
40 mMY.ResizeTo(nY);
41 mMYp.ResizeTo(nY);
42
43 mVPP.ResizeTo(nP,nP);
44 mVPY.ResizeTo(nP,nY);
45 mVYP.ResizeTo(nY,nP);
46 mVYY.ResizeTo(nY,nY);
47 mVYYp.ResizeTo(nY,nY);
48 mVP.ResizeTo(nP);
49 mVY.ResizeTo(nY);
50 mVYp.ResizeTo(nY);
51
52 mSPP.ResizeTo(mVPP);
53 mSPY.ResizeTo(mVPY);
54 mSYP.ResizeTo(mVYP);
55 mSYY.ResizeTo(mVYY);
56 mSYYp.ResizeTo(mVYYp);
57
58 Axy.ResizeTo(nP,nY);
59 Ayx.ResizeTo(nY,nP);
60 dAxy.ResizeTo(Axy);
61 dAyx.ResizeTo(Ayx);
62
63 mSP.ResizeTo(nP);
64 mSY.ResizeTo(nY);
65 mSYp.ResizeTo(nY);
66
67 mRPP.ResizeTo(mVPP);
68 mRPY.ResizeTo(mVPY);
69 mRYP.ResizeTo(mVYP);
70 mRYY.ResizeTo(mVYY);
71 mRYYp.ResizeTo(mVYYp);
72
74}

References Axy, Ayx, dAxy, dAyx, fGoodEventNumber, mMP, mMY, mMYp, mRPP, mRPY, mRYP, mRYY, mRYYp, mSP, mSPP, mSPY, mSY, mSYP, mSYp, mSYY, mSYYp, mVP, mVPP, mVPY, mVY, mVYP, mVYp, mVYY, mVYYp, nP, and nY.

◆ operator+=() [1/2]

LinRegBevPeb & LinRegBevPeb::operator+= ( const LinRegBevPeb & rhs)

Definition at line 172 of file LinReg_Bevington_Pebay.cc.

173{
174 // If set X = A + B, then
175 // Cov[X] = Cov[A] + Cov[B]
176 // + (E[x_A] - E[x_B]) * (E[y_A] - E[y_B]) * n_A * n_B / n_X
177 // Ref: E. Schubert, M. Gertz (9 July 2018).
178 // "Numerically stable parallel computation of (co-)variance".
179 // SSDBM '18 Proceedings of the 30th International Conference
180 // on Scientific and Statistical Database Management.
181 // https://doi.org/10.1145/3221269.3223036
182
184 return *this;
185
186 // Deviations from mean
187 TVectorD delta_y(mMY - rhs.mMY);
188 TVectorD delta_p(mMP - rhs.mMP);
189
190 // Update covariances
191 Double_t alpha = fGoodEventNumber * rhs.fGoodEventNumber
193 mVYY += rhs.mVYY;
194 mVYY.Rank1Update(delta_y, alpha);
195 mVPY += rhs.mVPY;
196 mVPY.Rank1Update(delta_p, delta_y, alpha);
197 mVPP += rhs.mVPP;
198 mVPP.Rank1Update(delta_p, alpha);
199
200 // Update means
201 Double_t beta = rhs.fGoodEventNumber / (fGoodEventNumber + rhs.fGoodEventNumber);
202 mMY += delta_y * beta;
203 mMP += delta_p * beta;
204
206
207 return *this;
208}

References fGoodEventNumber, LinRegBevPeb(), mMP, mMY, mVPP, mVPY, and mVYY.

+ Here is the call graph for this function:

◆ operator+=() [2/2]

LinRegBevPeb & LinRegBevPeb::operator+= ( const std::pair< TVectorD, TVectorD > & rhs)

Definition at line 133 of file LinReg_Bevington_Pebay.cc.

134{
135 // Get independent and dependent components
136 const TVectorD& P = rhs.first;
137 const TVectorD& Y = rhs.second;
138
139 // Update number of events
141
142 if (fGoodEventNumber <= 1) {
143 // First event, set covariances to zero and means to first value
144 mVPP.Zero();
145 mVPY.Zero();
146 mVYY.Zero();
147 mMP = P;
148 mMY = Y;
149 } else {
150 // Deviations from mean
151 TVectorD delta_y(Y - mMY);
152 TVectorD delta_p(P - mMP);
153
154 // Update covariances
155 Double_t alpha = (fGoodEventNumber - 1.0) / fGoodEventNumber;
156 mVPP.Rank1Update(delta_p, alpha);
157 mVPY.Rank1Update(delta_p, delta_y, alpha);
158 mVYY.Rank1Update(delta_y, alpha);
159
160 // Update means
161 Double_t beta = 1.0 / fGoodEventNumber;
162 mMP += delta_p * beta;
163 mMY += delta_y * beta;
164 }
165
166 return *this;
167}

References fGoodEventNumber, LinRegBevPeb(), mMP, mMY, mVPP, mVPY, and mVYY.

+ Here is the call graph for this function:

◆ print()

void LinRegBevPeb::print ( )

Definition at line 118 of file LinReg_Bevington_Pebay.cc.

119{
120 QwMessage << "LinReg dims: nP=" << nP << " nY=" << nY << QwLog::endl;
121
122 QwMessage << "MP:"; mMP.Print();
123 QwMessage << "MY:"; mMY.Print();
124 QwMessage << "VPP:"; mVPP.Print();
125 QwMessage << "VPY:"; mVPY.Print();
126 QwMessage << "VYY:"; mVYY.Print();
127 QwMessage << "VYYprime:"; mVYYp.Print();
128}

References QwLog::endl(), mMP, mMY, mVPP, mVPY, mVYY, mVYYp, nP, nY, and QwMessage.

+ Here is the call graph for this function:

◆ printSummaryAlphas()

void LinRegBevPeb::printSummaryAlphas ( ) const

Definition at line 376 of file LinReg_Bevington_Pebay.cc.

377{
378 QwMessage << Form("\nLinRegBevPeb::printSummaryAlphas seen good eve=%lld",fGoodEventNumber)<<QwLog::endl;
379 QwMessage << Form("\n j slope sigma mean/sigma\n");
380 for (int iy = 0; iy <nY; iy++) {
381 QwMessage << Form("dv=Y%d: ",iy)<<QwLog::endl;
382 for (int j = 0; j < nP; j++) {
383 double val=Axy(j,iy);
384 double err=dAxy(j,iy);
385 double nSig=val/err;
386 char x=' ';
387 if(fabs(nSig)>3.) x='*';
388 QwMessage << Form(" slope_%d = %11.3g +/-%11.3g (nSig=%.2f) %c\n",j,val, err,nSig,x);
389 }
390 }
391}

References Axy, dAxy, QwLog::endl(), fGoodEventNumber, nP, nY, and QwMessage.

+ Here is the call graph for this function:

◆ printSummaryMeansWithUnc()

void LinRegBevPeb::printSummaryMeansWithUnc ( ) const

Definition at line 426 of file LinReg_Bevington_Pebay.cc.

427{
428 QwMessage << "Uncorrected Y values:" << QwLog::endl;
429 QwMessage << " mean sig" << QwLog::endl;
430 for (int i = 0; i < nY; i++){
431 QwMessage << "Y" << i << ": " << mMY(i) << " +- " << mSY(i) << QwLog::endl;
432 }
434}

References QwLog::endl(), mMY, mSY, nY, and QwMessage.

+ Here is the call graph for this function:

◆ printSummaryMeansWithUncCorrected()

void LinRegBevPeb::printSummaryMeansWithUncCorrected ( ) const

Definition at line 439 of file LinReg_Bevington_Pebay.cc.

440{
441 QwMessage << "Corrected Y values:" << QwLog::endl;
442 QwMessage << " mean sig" << QwLog::endl;
443 for (int i = 0; i < nY; i++){
444 QwMessage << "Y" << i << ": " << mMYp(i) << " +- " << mSYp(i) << QwLog::endl;
445 }
447}

References QwLog::endl(), mMYp, mSYp, nY, and QwMessage.

+ Here is the call graph for this function:

◆ printSummaryP()

void LinRegBevPeb::printSummaryP ( ) const

Definition at line 319 of file LinReg_Bevington_Pebay.cc.

320{
321 QwMessage << Form("\nLinRegBevPeb::printSummaryP seen good eve=%lld",fGoodEventNumber)<<QwLog::endl;
322
323 size_t dim=nP;
324 if(fGoodEventNumber>2) { // print full matrix
325 QwMessage << Form("\nname: ");
326 for (size_t i = 1; i <dim; i++) {
327 QwMessage << Form("P%d%11s",(int)i," ");
328 }
329 QwMessage << Form("\n mean sig(distrib) nSig(mean) correlation-matrix ....\n");
330 for (size_t i = 0; i <dim; i++) {
331 double meanI,sigI;
332 if (getMeanP(i,meanI) < 0) QwWarning << "LRB::getMeanP failed" << QwLog::endl;
333 if (getSigmaP(i,sigI) < 0) QwWarning << "LRB::getSigmaP failed" << QwLog::endl;
334 double nSig=-1;
335 double err=sigI/sqrt(fGoodEventNumber);
336 if(sigI>0.) nSig=meanI/err;
337
338 QwMessage << Form("P%d: %+12.4g %12.3g %.1f ",(int)i,meanI,sigI,nSig);
339 for (size_t j = 1; j <dim; j++) {
340 if( j<=i) { QwMessage << Form(" %12s","._._._."); continue;}
341 double sigJ,cov;
342 if (getSigmaP(j,sigJ) < 0) QwWarning << "LRB::getSigmaP failed" << QwLog::endl;
343 if (getCovarianceP(i,j,cov) < 0) QwWarning << "LRB::getCovarianceP failed" << QwLog::endl;
344 double corel=cov / sigI / sigJ;
345
346 QwMessage << Form(" %12.3g",corel);
347 }
348 QwMessage << Form("\n");
349 }
350 }
351}
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
Int_t getCovarianceP(int i, int j, Double_t &covar) const
Get mean value of a variable, returns error code.
Int_t getMeanP(const int i, Double_t &mean) const
Get mean value of a variable, returns error code.
Int_t getSigmaP(const int i, Double_t &sigma) const
Get mean value of a variable, returns error code.

References QwLog::endl(), fGoodEventNumber, getCovarianceP(), getMeanP(), getSigmaP(), nP, QwMessage, and QwWarning.

+ Here is the call graph for this function:

◆ printSummaryY()

void LinRegBevPeb::printSummaryY ( ) const

Definition at line 356 of file LinReg_Bevington_Pebay.cc.

357{
358 QwMessage << Form("\nLinRegBevPeb::printSummaryY seen good eve=%lld (CSV-format)",fGoodEventNumber)<<QwLog::endl;
359 QwMessage << Form(" j, mean, sig(mean), nSig(mean), sig(distribution) \n");
360
361 for (int i = 0; i <nY; i++) {
362 double meanI,sigI;
363 if (getMeanY(i,meanI) < 0) QwWarning << "LRB::getMeanY failed" << QwLog::endl;
364 if (getSigmaY(i,sigI) < 0) QwWarning << "LRB::getSigmaY failed" << QwLog::endl;
365 double err = sigI / sqrt(fGoodEventNumber);
366 double nSigErr = meanI / err;
367 QwMessage << Form("Y%02d, %+11.4g, %12.4g, %8.1f, %12.4g "" ",i,meanI,err,nSigErr,sigI)<<QwLog::endl;
368
369 }
370}
Int_t getSigmaY(const int i, Double_t &sigma) const
Int_t getMeanY(const int i, Double_t &mean) const

References QwLog::endl(), fGoodEventNumber, getMeanY(), getSigmaY(), nY, QwMessage, and QwWarning.

+ Here is the call graph for this function:

◆ printSummaryYP()

void LinRegBevPeb::printSummaryYP ( ) const

Definition at line 396 of file LinReg_Bevington_Pebay.cc.

397{
398 QwMessage << Form("\nLinRegBevPeb::printSummaryYP seen good eve=%lld",fGoodEventNumber)<<QwLog::endl;
399
400 if(fGoodEventNumber<2) { QwMessage<<" too few events, skip"<<QwLog::endl; return;}
401 QwMessage << Form("\n name: ");
402 for (int i = 0; i <nP; i++) {
403 QwMessage << Form(" %10sP%d "," ",i);
404 }
405 QwMessage << Form("\n j meanY sigY correlation with Ps ....\n");
406 for (int iy = 0; iy <nY; iy++) {
407 double meanI,sigI;
408 if (getMeanY(iy,meanI) < 0) QwWarning << "LRB::getMeanY failed" << QwLog::endl;
409 if (getSigmaY(iy,sigI) < 0) QwWarning << "LRB::getSigmaY failed" << QwLog::endl;
410
411 QwMessage << Form(" %3d %6sY%d: %+12.4g %12.4g ",iy," ",iy,meanI,sigI);
412 for (int ip = 0; ip <nP; ip++) {
413 double sigJ,cov;
414 if (getSigmaP(ip,sigJ) < 0) QwWarning << "LRB::getSigmaP failed" << QwLog::endl;
415 if (getCovariancePY(ip,iy,cov) < 0) QwWarning << "LRB::getCovariancePY failed" << QwLog::endl;
416 double corel = cov / sigI / sigJ;
417 QwMessage << Form(" %12.3g",corel);
418 }
419 QwMessage << Form("\n");
420 }
421}
Int_t getCovariancePY(int ip, int iy, Double_t &covar) const

References QwLog::endl(), fGoodEventNumber, getCovariancePY(), getMeanY(), getSigmaP(), getSigmaY(), nP, nY, QwMessage, and QwWarning.

+ Here is the call graph for this function:

◆ setDims()

void LinRegBevPeb::setDims ( int a,
int b )
inline

Definition at line 86 of file LinReg_Bevington_Pebay.h.

86{ nP = a; nY = b;}

References nP, and nY.

◆ solve()

void LinRegBevPeb::solve ( )

normalized covariances

Definition at line 452 of file LinReg_Bevington_Pebay.cc.

453{
454 // off-diagonal raw covariance
455 mVYP.Transpose(mVPY);
456
457 // diagonal variances
458 mVP = TMatrixDDiag(mVPP); mVP.Sqrt();
459 mVY = TMatrixDDiag(mVYY); mVY.Sqrt();
460
461 // correlation matrices
462 mRPP = mVPP; mRPP.NormByColumn(mVP); mRPP.NormByRow(mVP);
463 mRYY = mVYY; mRYY.NormByColumn(mVY); mRYY.NormByRow(mVY);
464 mRPY = mVPY; mRPY.NormByColumn(mVP); mRPY.NormByRow(mVY);
465
466 /// normalized covariances
467 mSYY = mVYY * (1.0 / (fGoodEventNumber - 1.));
468 mSPP = mVPP * (1.0 / (fGoodEventNumber - 1.));
469 mSPY = mVPY * (1.0 / (fGoodEventNumber - 1.));
470 mSYP.Transpose(mSPY);
471
472 // uncertainties on the means
473 mSP = TMatrixDDiag(mSPP); mSP.Sqrt();
474 mSY = TMatrixDDiag(mSYY); mSY.Sqrt();
475
476 // Warn if correlation matrix determinant close to zero (heuristic)
477 if (mRPP.Determinant() < std::pow(10,-(2*nP))) {
478 QwWarning << "LRB: correlation matrix nearly singular, "
479 << "determinant = " << mRPP.Determinant()
480 << " (set includes highly correlated variable pairs)"
481 << QwLog::endl;
482 if (fGoodEventNumber > 10*nP) {
483 QwMessage << fGoodEventNumber << " events" << QwLog::endl;
484 QwMessage << "Covariance matrix: " << QwLog::endl; mVPP.Print();
485 QwMessage << "Correlation matrix: " << QwLog::endl; mRPP.Print();
486 }
487 QwWarning << "LRB: solving failed (this happens when only few events)."
488 << QwLog::endl;
489 return;
490 }
491 // slopes
492 TMatrixD invRPP(TMatrixD::kInverted, mRPP);
493 Axy = TMatrixD(invRPP, TMatrixD::kMult, mRPY);
494 Axy.NormByColumn(mSP); // divide
495 Axy.NormByRow(mSY, ""); // mult
496 Ayx.Transpose(Axy);
497
498 // new means
499 mMYp = mMY - Ayx * mMP;
500
501 // new raw covariance
502 mVYYp = mVYY + Ayx * mVPP * Axy - (Ayx * mVPY + mVYP * Axy);
503 // new variances
504 mVYp = TMatrixDDiag(mVYYp); mVYp.Sqrt();
505
506 // new normalized covariance
507 mSYYp = mSYY + Ayx * mSPP * Axy - (Ayx * mSPY + mSYP * Axy);
508 // uncertainties on the new means
509 mSYp = TMatrixDDiag(mSYYp); mSYp.Sqrt();
510
511 // new correlation matrix
512 mRYYp = mVYYp; mRYYp.NormByColumn(mVYp); mRYYp.NormByRow(mVYp);
513
514 // slope uncertainties
515 double norm = 1. / (fGoodEventNumber - nP - 1);
516 dAxy.Zero();
517 dAxy.Rank1Update(TMatrixDDiag(invRPP), TMatrixDDiag(mRYYp), norm); // diag mRYYp = row of ones
518 dAxy.Sqrt();
519 dAxy.NormByColumn(mSP); // divide
520 dAxy.NormByRow(mSYp, ""); // mult
521 dAyx.Transpose(dAxy);
522
523 fErrorFlag = 0;
524}

References Axy, Ayx, dAxy, dAyx, QwLog::endl(), fErrorFlag, fGoodEventNumber, mMP, mMY, mMYp, mRPP, mRPY, mRYY, mRYYp, mSP, mSPP, mSPY, mSY, mSYP, mSYp, mSYY, mSYYp, mVP, mVPP, mVPY, mVY, mVYP, mVYp, mVYY, mVYYp, nP, QwMessage, and QwWarning.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator+

LinRegBevPeb operator+ ( LinRegBevPeb lhs,
const LinRegBevPeb & rhs )
friend

Definition at line 110 of file LinReg_Bevington_Pebay.h.

112 {
113 lhs += rhs; // reuse compound assignment
114 return lhs; // return the result by value (uses move constructor)
115 }

References LinRegBevPeb().

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const LinRegBevPeb & h )
friend

Output stream operator.

Definition at line 125 of file LinReg_Bevington_Pebay.h.

126{
127 stream << "LRB: " << h.fGoodEventNumber << " events";
128 return stream;
129}

References fGoodEventNumber, and LinRegBevPeb().

◆ QwCorrelator

friend class QwCorrelator
friend

Friend class with correlator for ROOT tree output.

Definition at line 121 of file LinReg_Bevington_Pebay.h.

References QwCorrelator.

Referenced by QwCorrelator.

Field Documentation

◆ Axy

TMatrixD LinRegBevPeb::Axy
private

slopes

Definition at line 64 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), printSummaryAlphas(), and solve().

◆ Ayx

TMatrixD LinRegBevPeb::Ayx
private

Definition at line 64 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ dAxy

TMatrixD LinRegBevPeb::dAxy
private

Definition at line 64 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), printSummaryAlphas(), and solve().

◆ dAyx

TMatrixD LinRegBevPeb::dAyx
private

Definition at line 64 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ fErrorFlag

Int_t LinRegBevPeb::fErrorFlag
private

is information valid

Definition at line 35 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), LinRegBevPeb(), LinRegBevPeb(), and solve().

◆ fGoodEventNumber

◆ mMP

TVectorD LinRegBevPeb::mMP
private

mean values

Definition at line 60 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), getMeanP(), init(), operator+=(), operator+=(), print(), and solve().

◆ mMY

TVectorD LinRegBevPeb::mMY
private

◆ mMYp

TVectorD LinRegBevPeb::mMYp
private

◆ mRPP

TMatrixD LinRegBevPeb::mRPP
private

Definition at line 40 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mRPY

TMatrixD LinRegBevPeb::mRPY
private

correlations

Definition at line 39 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mRYP

TMatrixD LinRegBevPeb::mRYP
private

Definition at line 39 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), and init().

◆ mRYY

TMatrixD LinRegBevPeb::mRYY
private

Definition at line 40 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mRYYp

TMatrixD LinRegBevPeb::mRYYp
private

Definition at line 41 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSP

TVectorD LinRegBevPeb::mSP
private

sigmas

Definition at line 56 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSPP

TMatrixD LinRegBevPeb::mSPP
private

Definition at line 53 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSPY

TMatrixD LinRegBevPeb::mSPY
private

normalized covariances

Definition at line 52 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSY

TVectorD LinRegBevPeb::mSY
private

Definition at line 56 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), printSummaryMeansWithUnc(), and solve().

◆ mSYP

TMatrixD LinRegBevPeb::mSYP
private

Definition at line 52 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSYp

TVectorD LinRegBevPeb::mSYp
private

Definition at line 57 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), printSummaryMeansWithUncCorrected(), and solve().

◆ mSYY

TMatrixD LinRegBevPeb::mSYY
private

Definition at line 53 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mSYYp

TMatrixD LinRegBevPeb::mSYYp
private

Definition at line 54 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mVP

TVectorD LinRegBevPeb::mVP
private

variances

Definition at line 48 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mVPP

TMatrixD LinRegBevPeb::mVPP
private

◆ mVPY

TMatrixD LinRegBevPeb::mVPY
private

unnormalized covariances

Definition at line 44 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), getCovariancePY(), init(), operator+=(), operator+=(), print(), and solve().

◆ mVY

TVectorD LinRegBevPeb::mVY
private

Definition at line 48 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mVYP

TMatrixD LinRegBevPeb::mVYP
private

Definition at line 44 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mVYp

TVectorD LinRegBevPeb::mVYp
private

Definition at line 49 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), init(), and solve().

◆ mVYY

TMatrixD LinRegBevPeb::mVYY
private

◆ mVYYp

TMatrixD LinRegBevPeb::mVYYp
private

Definition at line 46 of file LinReg_Bevington_Pebay.h.

Referenced by clear(), getSigmaYprime(), init(), print(), and solve().

◆ nP

◆ nY


The documentation for this class was generated from the following files: