ATLAS Offline Software
Loading...
Searching...
No Matches
LArSamples::Averager Class Reference

storage of the time histories of all the cells More...

#include <Averager.h>

Inheritance diagram for LArSamples::Averager:
Collaboration diagram for LArSamples::Averager:

Public Member Functions

 Averager (unsigned int n=0)
 Constructor.
 Averager (unsigned int lwb, unsigned int upb)
 Averager (const Averager &)=default
virtual ~Averager ()
bool add (double xMin=-DBL_MAX, double xMax=DBL_MAX)
bool fill (const TVectorD &values, double w=1)
bool append (const Averager &other)
double mean (unsigned int i) const
double meanError (unsigned int i) const
double rms (unsigned int i) const
double covariance (unsigned int i, unsigned j) const
double covarianceError (unsigned int i, unsigned j) const
TVectorD means () const
TVectorD meanErrors () const
CovMatrix meanErrorMatrix () const
CovMatrix covarianceMatrix () const
CovMatrix covarianceMatrixErrors () const
unsigned int nVariables () const
int lwb () const
int upb () const
unsigned int nEntries () const
double totalWeight () const
const TVectorD & sum1 () const
const TVectorD & sum2 () const
const TMatrixD & sum11Matrix () const
const TMatrixD & sum21Matrix () const
const TMatrixD & sum22Matrix () const
Averageroperator= (const Averager &other)
bool isInRange (int i) const
bool hasSameRange (int lw, int up) const
bool hasSameRange (const IndexRange &other) const
bool hasSameRange (const TVectorD &v) const
bool providesRange (int lw, int up) const
bool providesRange (const IndexRange &other) const
bool providesRange (const TVectorD &v) const
TString rangeStr () const
int commonLwb (const IndexRange &other) const
int commonUpb (const IndexRange &other) const
bool checkRange (int &l, int &h) const

Static Public Member Functions

static double safeSqrt (double x)

Private Member Functions

bool prepare ()

Private Attributes

unsigned int m_n
double m_wTot
int m_lwb
std::vector< double > m_xMin
std::vector< double > m_xMax
TVectorD m_sum1
TVectorD m_sum2
TMatrixD m_sum11Matrix
TMatrixD m_sum21Matrix
TMatrixD m_sum22Matrix

Detailed Description

storage of the time histories of all the cells

Definition at line 22 of file Averager.h.

Constructor & Destructor Documentation

◆ Averager() [1/3]

Averager::Averager ( unsigned int n = 0)

Constructor.

Definition at line 15 of file Averager.cxx.

16 : m_n(0), m_wTot(0), m_lwb(0)
17{
18 for (unsigned int i = 0; i < n; i++) add();
19}
bool add(double xMin=-DBL_MAX, double xMax=DBL_MAX)
Definition Averager.cxx:46
unsigned int m_n
Definition Averager.h:73

◆ Averager() [2/3]

Averager::Averager ( unsigned int lwb,
unsigned int upb )

Definition at line 22 of file Averager.cxx.

23 : m_n(0), m_wTot(0), m_lwb(lwb)
24{
25 for (unsigned int i = lwb; i <= upb; i++) add();
26}
int lwb() const
Definition Averager.h:54
int upb() const
Definition Averager.h:55

◆ Averager() [3/3]

LArSamples::Averager::Averager ( const Averager & )
default

◆ ~Averager()

virtual LArSamples::Averager::~Averager ( )
inlinevirtual

Definition at line 32 of file Averager.h.

32{ }

Member Function Documentation

◆ add()

bool Averager::add ( double xMin = -DBL_MAX,
double xMax = DBL_MAX )

Definition at line 46 of file Averager.cxx.

47{
48 if (m_n > 0) {
49 cout << "Cannot add more variables to the Averager, data filling has started already." << endl;
50 return false;
51 }
52 m_xMin.push_back(xMin);
53 m_xMax.push_back(xMax);
54 return true;
55}
std::vector< double > m_xMax
Definition Averager.h:77
std::vector< double > m_xMin
Definition Averager.h:77

◆ append()

bool Averager::append ( const Averager & other)

Definition at line 94 of file Averager.cxx.

95{
96 if (nEntries() == 0) {
97 *this = other;
98 return true;
99 }
100 if (!hasSameRange(other)) return false;
101 m_sum1 += other.sum1();
102 m_sum2 += other.sum2();
103 m_sum11Matrix += other.sum11Matrix();
104 m_sum21Matrix += other.sum21Matrix();
105 m_sum22Matrix += other.sum22Matrix();
106 m_n += other.nEntries();
107 m_wTot += other.totalWeight();
108 return true;
109}
TMatrixD m_sum21Matrix
Definition Averager.h:79
unsigned int nEntries() const
Definition Averager.h:57
TMatrixD m_sum11Matrix
Definition Averager.h:79
TMatrixD m_sum22Matrix
Definition Averager.h:79
bool hasSameRange(int lw, int up) const
Definition IndexRange.h:29

◆ checkRange()

bool IndexRange::checkRange ( int & l,
int & h ) const
inherited

Definition at line 14 of file IndexRange.cxx.

15{
16 if (l < 0)
17 l = lwb();
18 else if (!isInRange(l)) {
19 cout << "IndexRange::checkRange : lower bound " << l << " is out of bounds" << endl;
20 return false;
21 }
22
23 if (h < 0)
24 h = upb();
25 else if (!isInRange(h)) {
26 cout << "IndexRange::checkRange : upper bound " << h << " is out of bounds" << endl;
27 return false;
28 }
29
30 return true;
31}
virtual int lwb() const =0
bool isInRange(int i) const
Definition IndexRange.h:27
virtual int upb() const =0
l
Printing final latex table to .tex output file.

◆ commonLwb()

int LArSamples::IndexRange::commonLwb ( const IndexRange & other) const
inlineinherited

Definition at line 39 of file IndexRange.h.

39{ return (other.lwb() > lwb() ? other.lwb() : lwb()); }

◆ commonUpb()

int LArSamples::IndexRange::commonUpb ( const IndexRange & other) const
inlineinherited

Definition at line 40 of file IndexRange.h.

40{ return (other.upb() < upb() ? other.upb() : upb()); }

◆ covariance()

double Averager::covariance ( unsigned int i,
unsigned j ) const

Definition at line 221 of file Averager.cxx.

222{
223 if (!isInRange(i) || !isInRange(j)) {
224 cout << "Indices (" << i << ", " << j << ") out of range" << endl;
225 return 0;
226 }
227 return covarianceMatrix()(i, j);
228}
CovMatrix covarianceMatrix() const
Definition Averager.cxx:153

◆ covarianceError()

double Averager::covarianceError ( unsigned int i,
unsigned j ) const

Definition at line 231 of file Averager.cxx.

232{
233 if (!isInRange(i) || !isInRange(j)) {
234 cout << "Indices (" << i << ", " << j << ") out of range" << endl;
235 return 0;
236 }
237 return covarianceMatrixErrors()(i, j);
238}
CovMatrix covarianceMatrixErrors() const
Definition Averager.cxx:167

◆ covarianceMatrix()

CovMatrix Averager::covarianceMatrix ( ) const

Definition at line 153 of file Averager.cxx.

154{
155 CovMatrix cm(lwb(), upb());
156 if (m_n == 0) {
157 cout << "No entries filled yet!" << endl;
158 return cm;
159 }
160 for (int i1 = lwb(); i1 <= upb(); i1++)
161 for (int i2 = lwb(); i2 <= upb(); i2++)
162 cm(i1, i2) = (m_sum11Matrix(i1, i2)/m_wTot) - (m_sum1(i1)/m_wTot)*(m_sum1(i2)/m_wTot);
163 return cm;
164}

◆ covarianceMatrixErrors()

CovMatrix Averager::covarianceMatrixErrors ( ) const

Definition at line 167 of file Averager.cxx.

168{
169 CovMatrix dcm(lwb(), upb());
170 if (m_n == 0) {
171 cout << "No entries filled yet!" << endl;
172 return dcm;
173 }
174
175 for (int i1 = lwb(); i1 <= upb(); i1++)
176 for (int i2 = lwb(); i2 <= upb(); i2++) {
177 dcm(i1, i2) = safeSqrt((
178 (m_sum22Matrix(i1, i2)/m_wTot)
179 - 2*(m_sum21Matrix(i1, i2)/m_wTot)*(m_sum1(i2)/m_wTot) - 2*(m_sum21Matrix(i2, i1)/m_wTot)*(m_sum1(i1)/m_wTot)
180 + (m_sum11Matrix(i1, i1)/m_wTot)*(m_sum1(i2)/m_wTot)*(m_sum1(i2)/m_wTot) + (m_sum11Matrix(i2, i2)/m_wTot)*(m_sum1(i1)/m_wTot)*(m_sum1(i1)/m_wTot)
181 - (m_sum11Matrix(i1, i2)/m_wTot)*(m_sum11Matrix(i1, i2)/m_wTot)
182 + 6*(m_sum11Matrix(i1, i2)/m_wTot)*(m_sum1(i1)/m_wTot)*(m_sum1(i2)/m_wTot)
183 - 4*(m_sum1(i1)/m_wTot)*(m_sum1(i1)/m_wTot)*(m_sum1(i2)/m_wTot)*(m_sum1(i2)/m_wTot)
184 )/m_wTot);
185 }
186
187 return dcm;
188}
static double safeSqrt(double x)
Definition Averager.cxx:241

◆ fill()

bool Averager::fill ( const TVectorD & values,
double w = 1 )

Definition at line 69 of file Averager.cxx.

70{
71 if (!hasSameRange(values)) {
72 cout << "Filling with wrong indices!" << endl;
73 return false;
74 }
75 if (m_n == 0 && !prepare()) return false;
76
77 for (int i1 = lwb(); i1 <= upb(); i1++) {
78 double val1 = values(i1);
79 m_sum1(i1) += val1*w;
80 m_sum2(i1) += val1*val1*w;
81 for (int i2 = lwb(); i2 <= upb(); i2++) {
82 double val2 = values(i2);
83 m_sum11Matrix(i1, i2) += val1*val2*w;
84 m_sum21Matrix(i1, i2) += val1*val1*val2*w;
85 m_sum22Matrix(i1, i2) += val1*val1*val2*val2*w;
86 }
87 }
88 m_n++;
89 m_wTot += w;
90 return true;
91}

◆ hasSameRange() [1/3]

bool LArSamples::IndexRange::hasSameRange ( const IndexRange & other) const
inlineinherited

Definition at line 30 of file IndexRange.h.

30{ return hasSameRange(other.lwb(), other.upb()); }

◆ hasSameRange() [2/3]

bool LArSamples::IndexRange::hasSameRange ( const TVectorD & v) const
inlineinherited

Definition at line 31 of file IndexRange.h.

31{ return hasSameRange(v.GetLwb(), v.GetUpb()); }

◆ hasSameRange() [3/3]

bool LArSamples::IndexRange::hasSameRange ( int lw,
int up ) const
inlineinherited

Definition at line 29 of file IndexRange.h.

29{ return (lwb() == lw && upb() == up); }

◆ isInRange()

bool LArSamples::IndexRange::isInRange ( int i) const
inlineinherited

Definition at line 27 of file IndexRange.h.

27{ return (i >= lwb() && i <= upb()); }

◆ lwb()

int LArSamples::Averager::lwb ( ) const
inlinevirtual

Implements LArSamples::IndexRange.

Definition at line 54 of file Averager.h.

54{ return m_lwb; }

◆ mean()

double Averager::mean ( unsigned int i) const

Definition at line 191 of file Averager.cxx.

192{
193 if (!isInRange(i)) {
194 cout << "Index " << i << " out of range" << endl;
195 return 0;
196 }
197 return means()(i);
198}
TVectorD means() const
Definition Averager.cxx:112

◆ meanError()

double Averager::meanError ( unsigned int i) const

Definition at line 201 of file Averager.cxx.

202{
203 if (!isInRange(i)) {
204 cout << "Index " << i << " out of range" << endl;
205 return 0;
206 }
207 return meanErrors()(i);
208}
TVectorD meanErrors() const
Definition Averager.cxx:124

◆ meanErrorMatrix()

CovMatrix Averager::meanErrorMatrix ( ) const

Definition at line 138 of file Averager.cxx.

139{
140 CovMatrix errs(lwb(), upb());
141 if (m_n == 0) {
142 cout << "No entries filled yet!" << endl;
143 return errs;
144 }
146 for (int i1 = lwb(); i1 <= upb(); i1++)
147 for (int i2 = lwb(); i2 <= upb(); i2++)
148 errs(i1, i2) = cm(i1, i2)/m_wTot;
149 return errs;
150}

◆ meanErrors()

TVectorD Averager::meanErrors ( ) const

Definition at line 124 of file Averager.cxx.

125{
126 TVectorD dm(lwb(), upb());
127 if (m_n == 0) {
128 cout << "No entries filled yet!" << endl;
129 return dm;
130 }
132 for (int i1 = lwb(); i1 <= upb(); i1++)
133 dm(i1) = safeSqrt(cm(i1, i1)/m_wTot);
134 return dm;
135}

◆ means()

TVectorD Averager::means ( ) const

Definition at line 112 of file Averager.cxx.

113{
114 TVectorD m(lwb(), upb());
115 if (m_n == 0) {
116 cout << "No entries filled yet!" << endl;
117 return m;
118 }
119 for (int i = lwb(); i <= upb(); i++) m(i) = m_sum1(i)/m_wTot;
120 return m;
121}

◆ nEntries()

unsigned int LArSamples::Averager::nEntries ( ) const
inline

Definition at line 57 of file Averager.h.

57{ return m_n; }

◆ nVariables()

unsigned int LArSamples::Averager::nVariables ( ) const
inline

Definition at line 53 of file Averager.h.

53{ return m_xMin.size(); }

◆ operator=()

Averager & Averager::operator= ( const Averager & other)

Definition at line 29 of file Averager.cxx.

30{
31 m_n = other.m_n;
32 m_wTot = other.m_wTot;
33 m_lwb = other.lwb();
34 m_xMin = other.m_xMin;
35 m_xMax = other.m_xMax;
36 prepare();
37 m_sum1 = other.sum1();
38 m_sum2 = other.sum2();
39 m_sum11Matrix = other.sum11Matrix();
40 m_sum21Matrix = other.sum21Matrix();
41 m_sum22Matrix = other.sum22Matrix();
42 return *this;
43}

◆ prepare()

bool Averager::prepare ( )
private

Definition at line 58 of file Averager.cxx.

59{
60 m_sum1.ResizeTo(lwb(), upb());
61 m_sum2.ResizeTo(lwb(), upb());
62 m_sum11Matrix.ResizeTo(lwb(), upb(), lwb(), upb());
63 m_sum21Matrix.ResizeTo(lwb(), upb(), lwb(), upb());
64 m_sum22Matrix.ResizeTo(lwb(), upb(), lwb(), upb());
65 return true;
66}

◆ providesRange() [1/3]

bool LArSamples::IndexRange::providesRange ( const IndexRange & other) const
inlineinherited

Definition at line 34 of file IndexRange.h.

34{ return providesRange(other.lwb(), other.upb()); }
bool providesRange(int lw, int up) const
Definition IndexRange.h:33

◆ providesRange() [2/3]

bool LArSamples::IndexRange::providesRange ( const TVectorD & v) const
inlineinherited

Definition at line 35 of file IndexRange.h.

35{ return providesRange(v.GetLwb(), v.GetUpb()); }

◆ providesRange() [3/3]

bool LArSamples::IndexRange::providesRange ( int lw,
int up ) const
inlineinherited

Definition at line 33 of file IndexRange.h.

33{ return (lwb() <= lw && upb() >= up); }

◆ rangeStr()

TString LArSamples::IndexRange::rangeStr ( ) const
inlineinherited

Definition at line 37 of file IndexRange.h.

37{ return Form("[%d, %d]", lwb(), upb()); }

◆ rms()

double Averager::rms ( unsigned int i) const

Definition at line 211 of file Averager.cxx.

212{
213 if (!isInRange(i)) {
214 cout << "Index " << i << " out of range" << endl;
215 return 0;
216 }
217 return safeSqrt(covarianceMatrix()(i, i));
218}

◆ safeSqrt()

double Averager::safeSqrt ( double x)
static

Definition at line 241 of file Averager.cxx.

242{
243 if (x < 0 && x > -1E-10) return 0;
244 return TMath::Sqrt(x);
245}
#define x

◆ sum1()

const TVectorD & LArSamples::Averager::sum1 ( ) const
inline

Definition at line 60 of file Averager.h.

60{ return m_sum1; }

◆ sum11Matrix()

const TMatrixD & LArSamples::Averager::sum11Matrix ( ) const
inline

Definition at line 62 of file Averager.h.

62{ return m_sum11Matrix; }

◆ sum2()

const TVectorD & LArSamples::Averager::sum2 ( ) const
inline

Definition at line 61 of file Averager.h.

61{ return m_sum2; }

◆ sum21Matrix()

const TMatrixD & LArSamples::Averager::sum21Matrix ( ) const
inline

Definition at line 63 of file Averager.h.

63{ return m_sum21Matrix; }

◆ sum22Matrix()

const TMatrixD & LArSamples::Averager::sum22Matrix ( ) const
inline

Definition at line 64 of file Averager.h.

64{ return m_sum22Matrix; }

◆ totalWeight()

double LArSamples::Averager::totalWeight ( ) const
inline

Definition at line 58 of file Averager.h.

58{ return m_wTot; }

◆ upb()

int LArSamples::Averager::upb ( ) const
inlinevirtual

Implements LArSamples::IndexRange.

Definition at line 55 of file Averager.h.

55{ return m_lwb + nVariables() - 1; }
unsigned int nVariables() const
Definition Averager.h:53

Member Data Documentation

◆ m_lwb

int LArSamples::Averager::m_lwb
private

Definition at line 75 of file Averager.h.

◆ m_n

unsigned int LArSamples::Averager::m_n
private

Definition at line 73 of file Averager.h.

◆ m_sum1

TVectorD LArSamples::Averager::m_sum1
private

Definition at line 78 of file Averager.h.

◆ m_sum11Matrix

TMatrixD LArSamples::Averager::m_sum11Matrix
private

Definition at line 79 of file Averager.h.

◆ m_sum2

TVectorD LArSamples::Averager::m_sum2
private

Definition at line 78 of file Averager.h.

◆ m_sum21Matrix

TMatrixD LArSamples::Averager::m_sum21Matrix
private

Definition at line 79 of file Averager.h.

◆ m_sum22Matrix

TMatrixD LArSamples::Averager::m_sum22Matrix
private

Definition at line 79 of file Averager.h.

◆ m_wTot

double LArSamples::Averager::m_wTot
private

Definition at line 74 of file Averager.h.

◆ m_xMax

std::vector<double> LArSamples::Averager::m_xMax
private

Definition at line 77 of file Averager.h.

◆ m_xMin

std::vector<double> LArSamples::Averager::m_xMin
private

Definition at line 77 of file Averager.h.


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