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