ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LArSamples::Chi2Calc Class Reference

#include <Chi2Calc.h>

Inheritance diagram for LArSamples::Chi2Calc:
Collaboration diagram for LArSamples::Chi2Calc:

Public Member Functions

 Chi2Calc (int pars=0)
 Constructor (takes ownership of LArCellInfo object) More...
 
virtual ~Chi2Calc ()
 
TVectorD deltas (const AbsShape &data, const AbsShape &reference, CovMatrix &errors, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1, bool noDataError=false)
 
double chi2 (const AbsShape &data, const AbsShape &reference, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1)
 
double scalarProduct (const TVectorD &values1, const TVectorD &values2, const CovMatrix &invCovMat) const
 
int lwb () const
 
int upb () const
 
unsigned int nDof () const
 
bool bestRescale (const AbsShape &data, const AbsShape &reference, double &k, double &chi2, double deltaT=0, const ScaledErrorData *sed=0, unsigned int minNDof=0) const
 
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
 

Private Member Functions

bool useCorrs () const
 

Private Attributes

int m_pars
 
int m_lwb
 
int m_upb
 

Detailed Description

Definition at line 26 of file Chi2Calc.h.

Constructor & Destructor Documentation

◆ Chi2Calc()

LArSamples::Chi2Calc::Chi2Calc ( int  pars = 0)
inline

Constructor (takes ownership of LArCellInfo object)

Definition at line 31 of file Chi2Calc.h.

32  : m_pars(pars), m_lwb(-1), m_upb(-1) { }

◆ ~Chi2Calc()

virtual LArSamples::Chi2Calc::~Chi2Calc ( )
inlinevirtual

Definition at line 34 of file Chi2Calc.h.

34 { }

Member Function Documentation

◆ bestRescale()

bool Chi2Calc::bestRescale ( const AbsShape data,
const AbsShape reference,
double &  k,
double &  chi2,
double  deltaT = 0,
const ScaledErrorData sed = 0,
unsigned int  minNDof = 0 
) const

Definition at line 88 of file Chi2Calc.cxx.

90 {
91  k = 1;
92  chi2 = -1;
93  ScaledShiftedShape shiftedData(data, 1, -deltaT);
94  TVectorD r;
96  bool result = reference.interpolate(shiftedData, r, errors, -1, -1); // lwb and upb will come from data
97  if (!result || r.GetNrows() < (int)minNDof) {
98  k = 0;
99  chi2 = 1E99;
100  return true;
101  }
102 
103  if (sed) {
104  ScaledErrorData sed2(*sed, sed->scale(), sed->time() + deltaT);
105  if (sed2.providesRange(r)) r += sed2.offsets(r.GetLwb(), r.GetUpb());
106  }
107 
108  TVectorD v = data.values(r.GetLwb(), r.GetUpb());
109  CovMatrix invCovMat = data.invCovarianceMatrix(r.GetLwb(), r.GetUpb(), errors, useCorrs());
110  double sumR2 = scalarProduct(r, r, invCovMat);
111  double sumRV = scalarProduct(r, v, invCovMat);
112  double sumV2 = scalarProduct(v, v, invCovMat);
113  k = sumRV/sumR2; // optimal K-factor
114  chi2 = sumV2 - 2*k*sumRV + k*k*sumR2; // chi2
115 
116  return true;
117 }

◆ 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 }

◆ chi2()

double Chi2Calc::chi2 ( const AbsShape data,
const AbsShape reference,
const ScaledErrorData shapeError = 0,
int  lwb = -1,
int  upb = -1 
)

Definition at line 60 of file Chi2Calc.cxx.

62 {
63  double chi2Val = 0;
65  TVectorD dv = deltas(data, reference, errors, shapeError, lw, up, true);
66  if (dv.GetNrows() == 0) return -1;
67 
68  // OFC version (gives correct error terms for individual samplings after OFC fit is performed
69  if (m_pars & OFCChi2) {
70  OFC ofc(reference, data, errors, lwb(), upb(), shapeError, useCorrs());
71  return scalarProduct(dv, dv, ofc.invGamma());
72  }
73  // Basic version --- fast, simple
74  if (m_pars & BasicChi2) {
75  for (int k = lwb(); k < upb(); k++)
76  chi2Val += dv(k)*dv(k)/(TMath::Power(data.error(k),2) + errors(k,k));
77  return chi2Val;
78  }
79  // Default version :
80  CovMatrix invCovMat = data.invCovarianceMatrix(lwb(), upb(), errors, useCorrs());
81 /* dv.Print();
82  data.covarianceMatrix(lwb(), upb()).Print();
83  data.covarianceMatrix(lwb(), upb(), errors, useCorrs()).Print();*/
84  return scalarProduct(dv, dv, invCovMat);
85 }

◆ 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()); }

◆ deltas()

TVectorD Chi2Calc::deltas ( const AbsShape data,
const AbsShape reference,
CovMatrix errors,
const ScaledErrorData shapeError = 0,
int  lwb = -1,
int  upb = -1,
bool  noDataError = false 
)

Definition at line 36 of file Chi2Calc.cxx.

38 {
39  TVectorD refVals;
40  if (!reference.interpolate(data, refVals, errors, lw, up)) {
41  cout << "Chi2Calc::deltas : Could not find overlap region between data and reference in [" << lw << ", " << up << "]." << endl;
42  return TVectorD();
43  }
44  m_lwb = refVals.GetLwb();
45  m_upb = refVals.GetUpb();
46 
47  TVectorD deltas = data.values(lwb(), upb());
48  deltas -= refVals;
49  if (shapeError && shapeError->providesRange(*this)) {
50  TVectorD offsets = shapeError->offsets(lwb(), upb());
51  deltas -= offsets;
52  errors += shapeError->errors(lwb(), upb());
53  }
54 
55  if (!noDataError) errors = data.covarianceMatrix(lwb(), upb(), errors, useCorrs());
56  return deltas;
57 }

◆ 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::Chi2Calc::lwb ( ) const
inlinevirtual

Implements LArSamples::IndexRange.

Definition at line 45 of file Chi2Calc.h.

45 { return m_lwb; }

◆ nDof()

unsigned int LArSamples::Chi2Calc::nDof ( ) const
inline

Definition at line 47 of file Chi2Calc.h.

47 { return upb() - lwb() + 1; }

◆ 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()); }

◆ 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()); }

◆ scalarProduct()

double Chi2Calc::scalarProduct ( const TVectorD &  values1,
const TVectorD &  values2,
const CovMatrix invCovMat 
) const

Definition at line 19 of file Chi2Calc.cxx.

21 {
22  if (values1.GetLwb() != invCovMat.GetRowLwb() || values1.GetUpb() != invCovMat.GetRowUpb()) return -1;
23  if (values2.GetLwb() != invCovMat.GetColLwb() || values2.GetUpb() != invCovMat.GetColUpb()) return -1;
24 
25  double chi2Val = 0;
26 
27  for (int i = values1.GetLwb(); i <= values1.GetUpb(); i++) {
28  for (int j = values2.GetLwb(); j <= values2.GetUpb(); j++) {
29  chi2Val += invCovMat(i, j)*values1(i)*values2(j);
30  }
31  }
32  return chi2Val;
33 }

◆ upb()

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

Implements LArSamples::IndexRange.

Definition at line 46 of file Chi2Calc.h.

46 { return m_upb; }

◆ useCorrs()

bool LArSamples::Chi2Calc::useCorrs ( ) const
inlineprivate

Definition at line 54 of file Chi2Calc.h.

54 { return !(m_pars & NoCorrs); }

Member Data Documentation

◆ m_lwb

int LArSamples::Chi2Calc::m_lwb
private

Definition at line 58 of file Chi2Calc.h.

◆ m_pars

int LArSamples::Chi2Calc::m_pars
private

Definition at line 56 of file Chi2Calc.h.

◆ m_upb

int LArSamples::Chi2Calc::m_upb
private

Definition at line 58 of file Chi2Calc.h.


The documentation for this class was generated from the following files:
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArSamples::IndexRange::upb
virtual int upb() const =0
LArSamples::ScaledShiftedShape
Definition: ScaledShiftedShape.h:17
LArSamples::Chi2Calc::deltas
TVectorD deltas(const AbsShape &data, const AbsShape &reference, CovMatrix &errors, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1, bool noDataError=false)
Definition: Chi2Calc.cxx:36
get_generator_info.result
result
Definition: get_generator_info.py:21
PlotCalibFromCool.dv
dv
Definition: PlotCalibFromCool.py:762
LArSamples::Chi2Calc::m_pars
int m_pars
Definition: Chi2Calc.h:56
LArSamples::CovMatrix
TMatrixTSym< double > CovMatrix
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/Definitions.h:11
python.LumiCalcWorking.lw
lw
Definition: LumiCalcWorking.py:112
LArSamples::IndexRange::hasSameRange
bool hasSameRange(int lw, int up) const
Definition: IndexRange.h:29
LArSamples::Chi2Calc::lwb
int lwb() const
Definition: Chi2Calc.h:45
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
reference
Definition: hcg.cxx:437
LArSamples::Chi2Calc::scalarProduct
double scalarProduct(const TVectorD &values1, const TVectorD &values2, const CovMatrix &invCovMat) const
Definition: Chi2Calc.cxx:19
LArSamples::ScaledErrorData
Definition: ScaledErrorData.h:17
LArSamples::IndexRange::isInRange
bool isInRange(int i) const
Definition: IndexRange.h:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
LArSamples::ScaledErrorData::scale
double scale() const
Definition: ScaledErrorData.h:30
LArSamples::Chi2Calc::m_lwb
int m_lwb
Definition: Chi2Calc.h:58
LArSamples::OFC
Definition: OFC.h:27
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
LArSamples::NoCorrs
@ NoCorrs
Definition: Chi2Calc.h:24
LArSamples::OFCChi2
@ OFCChi2
Definition: Chi2Calc.h:24
LArSamples::IndexRange::lwb
virtual int lwb() const =0
python.PyAthena.v
v
Definition: PyAthena.py:154
LArSamples::BasicChi2
@ BasicChi2
Definition: Chi2Calc.h:24
LArSamples::FitterData::minNDof
unsigned int minNDof
Definition: ShapeFitter.cxx:27
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArSamples::Chi2Calc::useCorrs
bool useCorrs() const
Definition: Chi2Calc.h:54
LArSamples::IndexRange::providesRange
bool providesRange(int lw, int up) const
Definition: IndexRange.h:33
LArSamples::FitterData::sed
const ScaledErrorData * sed
Definition: ShapeFitter.cxx:26
LArSamples::ScaledErrorData::errors
const CovMatrix errors(int first=-1, int last=-1) const
Definition: ScaledErrorData.cxx:31
ReadOfcFromCool.ofc
ofc
Definition: ReadOfcFromCool.py:110
LArSamples::ScaledErrorData::time
double time() const
Definition: ScaledErrorData.h:31
LArSamples::Chi2Calc::upb
int upb() const
Definition: Chi2Calc.h:46
LArSamples::ScaledErrorData::offsets
const TVectorD offsets(int first=-1, int last=-1) const
Definition: ScaledErrorData.cxx:14
fitman.k
k
Definition: fitman.py:528
LArSamples::Chi2Calc::m_upb
int m_upb
Definition: Chi2Calc.h:58
LArSamples::Chi2Calc::chi2
double chi2(const AbsShape &data, const AbsShape &reference, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1)
Definition: Chi2Calc.cxx:60