ATLAS Offline Software
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"
9 #include "LArCafJobs/AbsShape.h"
10 #include "LArSamplesMon/Data.h"
13 
14 #include <iostream>
15 using std::cout;
16 using std::endl;
17 
18 using namespace LArSamples;
19 
20 
21 OFC::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 
30 OFC::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 
41 {
43 }
44 
45 
46 bool OFC::initGValues(const AbsShape& shape, const AbsShape& data, const ShapeErrorData* sed)
47 {
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 
71 bool 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 
145 double 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 
156 double 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 
167 TVectorD OFC::residual(const TVectorD& v) const
168 {
169  return v + (-1)*dot(a(), v)*g() + (-1)*dot(b(), v)*gp();
170 }
171 
172 
173 double 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 
LArSamples::OFC::m_Gpp
double m_Gpp
Definition: OFC.h:88
LArSamples::OFC::m_gp
TVectorD m_gp
Definition: OFC.h:87
LArSamples::OFC::initGValues
bool initGValues(const AbsShape &shape, const AbsShape &data, const ShapeErrorData *sed)
Definition: OFC.cxx:46
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArSamples::OFC::residual
TVectorD residual(const TVectorD &v) const
Definition: OFC.cxx:167
AbsShape.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
LArSamples::OFC::initRVectors
bool initRVectors()
Definition: OFC.cxx:131
LArSamples::OFC::m_Gamma
CovMatrix m_Gamma
Definition: OFC.h:89
LArSamples::CovMatrix
TMatrixTSym< double > CovMatrix
Definition: Definitions.h:11
python.LumiCalcWorking.lw
lw
Definition: LumiCalcWorking.py:112
LArSamples::OFC::b
const TVectorD & b() const
Definition: OFC.h:68
LArSamples::OFC::a
const TVectorD & a() const
Definition: OFC.h:67
ClassCounts.h
OFC.h
LArSamples::OFC::Gpp
double Gpp() const
Definition: OFC.h:62
LArSamples
Definition: AbsShape.h:24
LArSamples::OFC::Gp
double Gp() const
Definition: OFC.h:61
LArSamples::AbsShape::interpolate
int interpolate(double time, double &value, double &error) const
Definition: AbsShape.cxx:83
LArSamples::OFC::~OFC
virtual ~OFC()
Definition: OFC.cxx:40
LArSamples::OFC::A
double A(const AbsShape &data) const
Definition: OFC.cxx:145
LArSamples::OFC::m_resProj
TMatrixD m_resProj
Definition: OFC.h:90
LArSamples::OFC::m_Gp
double m_Gp
Definition: OFC.h:88
LArSamples::ShapeErrorData::xip
const TVectorD & xip() const
Definition: ShapeErrorData.h:41
LArSamples::OFC::dot
double dot(const TVectorD &form, const TVectorD &v) const
Definition: OFC.cxx:173
LArSamples::OFC::upb
int upb() const
Definition: OFC.h:52
LArSamples::OFC::m_G
double m_G
Definition: OFC.h:88
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArSamples::OFC::nSamples
unsigned int nSamples() const
Definition: OFC.h:49
LArSamples::ClassCounts::decrementInstanceCount
void decrementInstanceCount() const
Definition: LArCafJobs/LArCafJobs/ClassCounts.h:33
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
LArSamples::OFC::G
double G() const
Definition: OFC.h:60
python.BunchSpacingUtils.rn
rn
Definition: BunchSpacingUtils.py:87
LArSamples::OFC::gp
const TVectorD & gp() const
Definition: OFC.h:58
LArSamples::OFC::g
const TVectorD & g() const
Definition: OFC.h:57
LArSamples::OFC::OFC
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
compute_lumi.denom
denom
Definition: compute_lumi.py:76
LArSamples::OFC::m_a
TVectorD m_a
Definition: OFC.h:87
LArSamples::OFC::lwb
int lwb() const
Definition: OFC.h:51
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
LArSamples::ClassCounts::incrementInstanceCount
void incrementInstanceCount() const
Definition: LArCafJobs/LArCafJobs/ClassCounts.h:32
LArSamples::OFC::m_rIdx
std::vector< unsigned int > m_rIdx
Definition: OFC.h:92
python.PyAthena.v
v
Definition: PyAthena.py:157
LArSamples::OFC::m_g
TVectorD m_g
Definition: OFC.h:87
LArSamples::OFC::initOFCs
bool initOFCs(const AbsShape &data, const CovMatrix &refErr, bool useCorrs)
Definition: OFC.cxx:71
LArSamples::OFC::m_r
std::vector< TVectorD > m_r
Definition: OFC.h:91
LArSamples::AbsShape
Definition: AbsShape.h:28
Data.h
ShapeErrorData.h
LArSamples::OFC::m_b
TVectorD m_b
Definition: OFC.h:87
LArSamples::ShapeErrorData
Definition: ShapeErrorData.h:19
LArSamples::OFC::B
double B(const AbsShape &data) const
Definition: OFC.cxx:156
LArSamples::ShapeErrorData::xi
const TVectorD & xi() const
Definition: ShapeErrorData.h:40
LArSamples::FitterData::sed
const ScaledErrorData * sed
Definition: ShapeFitter.cxx:26
LArSamples::OFC::m_invGamma
CovMatrix m_invGamma
Definition: OFC.h:89
LArSamples::AbsShape::interpolateDiff
int interpolateDiff(double time, double &diff) const
Definition: AbsShape.cxx:108
fitman.k
k
Definition: fitman.py:528
PlotCalibFromCool.vals
vals
Definition: PlotCalibFromCool.py:474