ATLAS Offline Software
Loading...
Searching...
No Matches
OFC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArSamplesMon/OFC.h"
6
7#include "TMath.h"
8#include "TMatrixTSym.h"
10#include "LArSamplesMon/Data.h"
13
14#include <iostream>
15using std::cout;
16using std::endl;
17
18using namespace LArSamples;
19
20
21OFC::OFC(const AbsShape& shape, const AbsShape& data, int lw, int up, const ShapeErrorData* sed, bool withAutoCorr)
22 : m_g(lw, up), m_gp(lw, up)
23{
25 if (!initGValues(shape, data, sed)) return;
26 if (!initOFCs(data, CovMatrix(), withAutoCorr)) return;
27}
28
29
30OFC::OFC(const AbsShape& shape, const AbsShape& data, const CovMatrix& refErr,
31 int lw, int up, const ShapeErrorData* sed, bool withAutoCorr)
32 : m_g(lw, up), m_gp(lw, up)
33{
35 if (!initGValues(shape, data, sed)) return;
36 if (!initOFCs(data, refErr, withAutoCorr)) return;
37}
38
39
44
45
46bool OFC::initGValues(const AbsShape& shape, const AbsShape& data, const ShapeErrorData* sed)
47{
48 CovMatrix errors;
49 if (!shape.interpolate(data, m_g, errors, lwb(), upb())) {
50 cout <<"ERROR in OFC::initGValues : indices were invalid!" << endl;
51 m_g.ResizeTo(0);
52 return false;
53 }
54 if (!shape.interpolateDiff(data, m_gp, lwb(), upb())) { // lwb and upb come from g, so set above correctly...
55 cout <<"ERROR in OFC::initGValues : (diff) indices were invalid!" << endl;
56 m_g.ResizeTo(0);
57 m_gp.ResizeTo(0);
58 return false;
59 }
60 m_g.ResizeTo(m_gp.GetLwb(), m_gp.GetUpb()); // in case gp was more restricted
61 if (sed) {
62 TVectorD xi = sed->xi(m_gp.GetLwb(), m_gp.GetUpb());
63 TVectorD xip = sed->xip(m_gp.GetLwb(), m_gp.GetUpb());
64 m_g += xi;
65 m_gp += xip;
66 }
67 return true;
68}
69
70
71bool OFC::initOFCs(const AbsShape& data, const CovMatrix& refErr, bool withAutoCorr)
72{
73 m_a.ResizeTo(lwb(), upb());
74 m_b.ResizeTo(lwb(), upb());
75
76 //cout << nSamples() << endl;
77 //data.covarianceMatrix().Print();
78
79 CovMatrix noiseCov = data.covarianceMatrix(lwb(), upb(), refErr, withAutoCorr);
80 CovMatrix noiseInvCov = data.invCovarianceMatrix(lwb(), upb(), refErr, withAutoCorr);
81 //noiseCov.Print();
82
83 TVectorD gam = m_g;
84 TVectorD gamp = m_gp;
85 gam *= noiseInvCov;
86 gamp *= noiseInvCov;
87
88 m_G = m_g*gam;
89 m_Gp = m_g*gamp;
90 m_Gpp = m_gp*gamp;
91
92 double denom = G()*Gpp() - Gp()*Gp();
93 //cout << m_G << " " << m_g*gam << endl;
94 //cout << m_Gp << " " << m_g*gamp << " " << m_gp*gam << endl;
95 //cout << m_Gpp << " " << m_gp*gamp << endl;
96
97 for (int i = lwb(); i <= upb(); i++) {
98 m_a(i) = (Gpp()*gam(i) - Gp()*gamp(i))/denom;
99 m_b(i) = (Gp()*gam(i) - G()*gamp(i))/denom;
100 }
101
102 m_resProj.ResizeTo(lwb(), upb(), lwb(), upb());
103 for (int i = lwb(); i <= upb(); i++) {
104 for (int j = lwb(); j <= upb(); j++) {
105 m_resProj(i,j) = (i == j ? 1 : 0) - g(i)*a(j) + gp(i)*b(j);
106 }
107 }
108
109 //m_a.Print();
110 //cout << m_a*m_g << " " << m_a*m_gp << " " << m_b*m_g << " "<< m_b*m_gp << endl;
111
112 CovMatrix resNorm(lwb(), upb());
113 for (int i = lwb(); i <= upb(); i++) {
114 for (int j = lwb(); j <= upb(); j++) {
115 double rn = noiseCov(i, j) - (Gpp()*g(i)*g(j) - Gp()*(g(i)*gp(j) + g(j)*gp(i)) + G()*gp(i)*gp(j))/denom;
116 resNorm(i, j) = rn;
117 }
118 }
119
120 m_Gamma.ResizeTo(lwb(), upb(), lwb(), upb());
121 m_Gamma = noiseCov;
122 m_Gamma.Similarity(m_resProj);
123
124 m_invGamma.ResizeTo(lwb(), upb(), lwb(), upb());
125 m_invGamma = noiseInvCov;
126 m_invGamma.Similarity(m_resProj);
127 return true;
128}
129
130
132{
133 m_r.clear();
134 m_rIdx.clear();
135 for (unsigned int k = 0; k < nSamples() - 2; k++) {
136 TVectorD res(nSamples());
137 res[k] = 1;
138 m_r.push_back(residual(res));
139 m_rIdx.push_back(k);
140 }
141 return true;
142}
143
144
145double OFC::A(const AbsShape& data) const
146{
147 TVectorD vals(lwb(), upb());
148
149 for (int i = lwb(); i <= upb(); i++)
150 vals[i] = data.value(i);
151
152 return dot(a(), vals);
153}
154
155
156double OFC::B(const AbsShape& data) const
157{
158 TVectorD vals(lwb(), upb());
159
160 for (int i = lwb(); i <= upb(); i++)
161 vals[i] = data.value(i);
162
163 return dot(b(), vals);
164}
165
166
167TVectorD OFC::residual(const TVectorD& v) const
168{
169 return v + (-1)*dot(a(), v)*g() + (-1)*dot(b(), v)*gp();
170}
171
172
173double OFC::dot(const TVectorD& form, const TVectorD& v) const
174{
175 double s = 0;
176 for (int i = lwb(); i <= upb(); i++) s += form[i]*v[i];
177 return s;
178}
179
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::pair< std::vector< unsigned int >, bool > res
int interpolate(double time, double &value, double &error) const
Definition AbsShape.cxx:83
int interpolateDiff(double time, double &diff) const
Definition AbsShape.cxx:108
const TVectorD & b() const
Definition OFC.h:68
double m_Gp
Definition OFC.h:91
double Gp() const
Definition OFC.h:61
TVectorD residual(const TVectorD &v) const
Definition OFC.cxx:167
const TVectorD & a() const
Definition OFC.h:67
double Gpp() const
Definition OFC.h:62
const TVectorD & gp() const
Definition OFC.h:58
TVectorD m_gp
Definition OFC.h:90
OFC(const AbsShape &shape, const AbsShape &data, int lwb=-1, int upb=-1, const ShapeErrorData *sed=0, bool withAutoCorr=true)
Constructor.
Definition OFC.cxx:21
int upb() const
Definition OFC.h:52
int lwb() const
Definition OFC.h:51
bool initOFCs(const AbsShape &data, const CovMatrix &refErr, bool useCorrs)
Definition OFC.cxx:71
double B(const AbsShape &data) const
Definition OFC.cxx:156
unsigned int nSamples() const
Definition OFC.h:49
double G() const
Definition OFC.h:60
bool initGValues(const AbsShape &shape, const AbsShape &data, const ShapeErrorData *sed)
Definition OFC.cxx:46
virtual ~OFC()
Definition OFC.cxx:40
std::vector< unsigned int > m_rIdx
Definition OFC.h:95
TVectorD m_b
Definition OFC.h:90
const TVectorD & g() const
Definition OFC.h:57
bool initRVectors()
Definition OFC.cxx:131
TVectorD m_g
Definition OFC.h:90
double A(const AbsShape &data) const
Definition OFC.cxx:145
TMatrixD m_resProj
Definition OFC.h:93
std::vector< TVectorD > m_r
Definition OFC.h:94
double m_G
Definition OFC.h:91
double m_Gpp
Definition OFC.h:91
double dot(const TVectorD &form, const TVectorD &v) const
Definition OFC.cxx:173
CovMatrix m_invGamma
Definition OFC.h:92
CovMatrix m_Gamma
Definition OFC.h:92
TVectorD m_a
Definition OFC.h:90
const TVectorD & xi() const
const TVectorD & xip() const
Definition dot.py:1