CorrelationMatrix.cc
Go to the documentation of this file.
1 #include <utl/CorrelationMatrix.h>
2 #include <utl/AugerException.h>
3 #include <utl/ErrorLogger.h>
4 #include <iostream>
5 
6 using namespace std;
7 using namespace utl;
8 
9 inline
10 int CorrelationMatrix::Index(const int iPar, const int jPar) const
11 {
12  // calculates internal storage index for upper triangular matrix without diagonal elements
13  if (iPar >= fNParameter || jPar >= fNParameter)
14  throw OutOfBoundException("iPar or jPar too large");
15 
16  if (iPar<jPar)
17  return ( (fNParameter-1)*(fNParameter-2) -
18  (fNParameter-1-iPar)*(fNParameter-2-iPar) )/2 +
19  jPar - 1;
20  else
21  return ( (fNParameter-1)*(fNParameter-2) -
22  (fNParameter-1-jPar)*(fNParameter-2-jPar) )/2 +
23  iPar - 1;
24 }
25 
26 CorrelationMatrix::CorrelationMatrix(const int nPar)
27  : fNParameter(nPar), fElements(nPar*(nPar-1)/2)
28 {
29  for (Elements::iterator it=fElements.begin();
30  it!=fElements.end();++it)
31  *it = 0.0;
32 }
33 
34 void
35 CorrelationMatrix::Set(const int iPar, const int jPar, const double corr)
36 {
37  if (iPar == jPar)
38  throw DoesNotComputeException("Setting diagonal elements of correlation matrix makes no sense");
39 
40  if (corr < -1 || corr > 1)
41  {
42  ostringstream msg;
43  msg << "Value " << corr << " is invalid (-1 <= correlation <= 1), convert to 0 (!)";
44  ERROR(msg);
45 
46  fElements[Index(iPar,jPar)] = 0;
47  } else
48  fElements[Index(iPar,jPar)] = corr;
49 }
50 
51 double
52 CorrelationMatrix::operator()(const int iPar, const int jPar)
53  const
54 {
55  if (iPar == jPar)
56  return 1.0;
57 
58  return fElements[Index(iPar,jPar)];
59 }
double operator()(const int iPar, const int jPar) const
Exception for reporting variable out of valid range.
void Set(const int iPar, const int jPar, const double corr)
int Index(const int iPar, const int jPar) const
Base class for inconsistency/illogicality exceptions.
const int nPar
Definition: GeomAsym.h:37
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.