PandaRoot
Projection.h
Go to the documentation of this file.
1 // ******************************************************
2 // DecayTreeFitter Package
3 // We thank the original author Wouter Hulsbergen
4 // (BaBar, LHCb) for providing the sources.
5 // http://arxiv.org/abs/physics/0503191v1 (2005)
6 // Adaptation & Development for PANDA: Ralf Kliemt (2015)
7 // ******************************************************
8 #ifndef PROJECTION_H
9 #define PROJECTION_H 1
10 #include "Rtypes.h"
11 
12 #include "TVectorD.h"
13 #include "TMatrixDSym.h"
14 #include "TMatrixD.h"
15 #include <string.h> // for memset
16 #include "ParticleBase.h"
17 namespace DecayTreeFitter {
18 
19 class Projection {
20  public:
21  // constructor
22  Projection(int dimP, int dimC) : m_matrixH(dimC, dimP), m_r(dimC), m_matrixV(dimC), m_offset(0), m_particle(nullptr), m_nHidden(0) {}
23  virtual ~Projection(){};
24 
25  // accessors to the projection matrix
26  const TMatrixD &H() const { return m_matrixH; }
27  // HepMatrix& H() { return m_matrixH ; }
28  double &H(int row, int col)
29  {
30 #ifdef VTK_BOUNDSCHECKING
31  assert(m_offset + row > 0 && col > 0 && m_offset + row <= m_matrixH.GetNrows() && col <= m_matrixH.GetNcols());
32 #endif
33  return m_matrixH(m_offset + row, col);
34  }
35 
36  // accessors to the residual (or the 'value' of the constraint)
37  const TVectorD &r() const { return m_r; }
38  TVectorD &r() { return m_r; }
39  // HepVector& r() { return m_r ; }
40  double &r(int row)
41  {
42 #ifdef VTK_BOUNDSCHECKING
43  assert(m_offset + row > 0 && m_offset + row <= m_r.GetNrows());
44 #endif
45  return m_r(m_offset + row);
46  }
47 
48  // accessors to the covariance matrix
49  const TMatrixDSym &V() const { return m_matrixV; }
50  // HepSymMatrix& V() { return m_matrixV ; }
51  double &V(int row, int col) { return m_matrixV(m_offset + row, m_offset + col); }
52  double &Vfast(int row, int col)
53  {
54 #ifdef VTK_BOUNDSCHECKING
55  assert(m_offset + row > 0 && m_offset + col > 0 && m_offset + row <= m_matrixV.GetNrows() && m_offset + col <= m_matrixV.GetNcols() && row >= col);
56 #endif
57  return m_matrixV(m_offset + row, m_offset + col);
58  }
59 
60  // reset
61  // FIXME: Will this work for TMatixD, too?
62  void reset()
63  {
64  // fill everything with '0'. this implementation is kind of
65  // tricky, but it is fast.
66  // int dimC = m_matrixH.GetNrows() ;
67  // int dimP = m_matrixH.GetNcols() ;
68  // memset(&(m_matrixH(1,1)),0,dimP*dimC*sizeof(double));
69  // memset(&(m_r(1)) ,0,dimC*sizeof(double));
70  // memset(&(m_matrixV(1,1)),0,dimC*(dimC+1)/2*sizeof(double));
71  m_matrixH.Zero();
72  m_r.Zero();
73  m_matrixV.Zero();
74  m_offset = 0;
75  }
76 
77  // globalChisq
78  double chiSquare() const
79  {
80  TMatrixDSym W = m_matrixV;
81  double det = 0;
82  W.InvertFast(&det);
83  return W.Similarity(m_r);
84  }
85 
86  void incrementOffset(unsigned int i) { m_offset += i; }
87  unsigned int offset() const { return m_offset; }
88 
89  void setParticle(const ParticleBase &p) { m_particle = &p; }
90  const ParticleBase *particle() const { return m_particle; }
91 
92  private:
93  TMatrixD m_matrixH; // projection matrix
94  TVectorD m_r; // constraint residual
95  TMatrixDSym m_matrixV; // constraint variance (zero for lagrange constraints)
96  unsigned int m_offset; // offset for constraint index. only non-zero for merged constraints.
97  const ParticleBase *m_particle; // particle where chi2 should be added
98  // the number of hidden 'degrees of freedom'. always zero except for the 'photon' constraint
99  unsigned int m_nHidden;
100  ClassDef(Projection, 1)
101 };
102 } // namespace DecayTreeFitter
103 #endif
const TMatrixD & H() const
Definition: Projection.h:26
double & V(int row, int col)
Definition: Projection.h:51
void setParticle(const ParticleBase &p)
Definition: Projection.h:89
unsigned int i
Definition: P4_F32vec4.h:21
void incrementOffset(unsigned int i)
Definition: Projection.h:86
const TMatrixDSym & V() const
Definition: Projection.h:49
double chiSquare() const
Definition: Projection.h:78
Projection(int dimP, int dimC)
Definition: Projection.h:22
unsigned int offset() const
Definition: Projection.h:87
const TVectorD & r() const
Definition: Projection.h:37
double & r(int row)
Definition: Projection.h:40
double & H(int row, int col)
Definition: Projection.h:28
const ParticleBase * particle() const
Definition: Projection.h:90
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
double & Vfast(int row, int col)
Definition: Projection.h:52