FairRoot/PandaRoot
FitParams.cxx
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 #include <iostream>
9 #include <iomanip>
10 #include "FitParams.h"
11 
12 using namespace DecayTreeFitter;
14 
16 : m_dim(adim),m_par(adim),m_cov(adim),//m_scale(adim),
17 m_chiSquare(0),m_nConstraints(0),m_nConstraintsVec(adim,0)
18 {
20  //for(int i=0;i<adim;i++) m_scale[i][i]=1.;
21 }
23 : m_dim(fpar.dim()),m_par(fpar.dim()),m_cov(fpar.dim()),
24 m_chiSquare(0),m_nConstraints(0),m_nConstraintsVec(fpar.dim(),0)
25 {
26  m_par = fpar.par();
27  m_cov = fpar.cov();
28  //FIXME don't copy constraintsvector etc? Those are cleared anyways. I guess
29 }
30 
32  //std::cout<<"FitParams::~FitParams A ("<<&m_nConstraintsVec<<"); n="<<m_nConstraintsVec.size()<<" c="<<m_nConstraintsVec.capacity() <<std::endl;
33  //m_nConstraintsVec.clear();
34  //std::cout<<"FitParams::~FitParams B; n="<<m_nConstraintsVec.size()<<" c="<<m_nConstraintsVec.capacity() <<std::endl;
35  //m_chiSquareMap.clear() ;
36 }
37 
39  for(int row=0; row<m_dim; row++)
40  m_par(row) = 0 ;
41 }
42 
44 
45  if(aScale > 0)
46  {
47  for(int row=0; row<m_dim; row++) {
48  for(int col=0; col<row; col++) {
49  m_cov(row,col) = 0 ;
50  m_cov(col,row) = 0 ;
51  }
52  m_cov(row,row) *= aScale ;
53  if(m_cov(row,row) < 0 ) m_cov(row,row)*=-1 ;
54  if(m_cov(row,row) == 0 ) m_cov(row,row)=aScale ;
55  }
56  }
57  m_chiSquare=0 ;
58  m_nConstraints=0 ;
59  for(int row=0; row<m_dim; row++) {
60  nConstraintsVec(row) = 0 ;
61  }
62  m_chiSquareMap.clear() ;
63 }
64 
66  bool okay=true ;
67  for(int row=0; row<m_dim && okay; row++)
68  okay = m_cov(row,row)>=0 ;
69  return okay ;
70 }
71 
73  std::cout << std::setw(3) << "index" << std::setw(15) << "val" << std::setw(15) << "err" << std::endl ;
74  std::cout << std::setprecision(5) ;
75  for(int row=0; row<m_dim; row++)
76  std::cout << std::setw(3) << row
77  << std::setw(15) << m_par(row)
78  << std::setw(15) << sqrt(m_cov(row,row)) << std::endl ;
79  std::cout << std::setprecision(10) ;
80 } ;
81 
82 TMatrixDSym DecayTreeFitter::FitParams::cov(const std::vector<int>& indexVec) const {
83  int nrow = indexVec.size() ;
84  TMatrixDSym thecov(nrow) ;
85  for(int row=0; row<nrow; row++)
86  //for(int col=0; col<=row ; col++)//fix for TmatrixDSym (which is not really symmetric)
87  for(int col=0; col<nrow ; col++)
88  thecov(row,col) = m_cov(indexVec[row],indexVec[col]) ;
89  return thecov ;
90 }
91 
92 TVectorD DecayTreeFitter::FitParams::par(const std::vector<int>& indexVec) const {
93  int nrow = indexVec.size() ;
94  TVectorD thepar(nrow) ;
95  for(int row=0; row<nrow; row++)
96  thepar(row) = m_par(indexVec[row]) ;
97  return thepar ;
98 }
99 
101 {
102  resetPar();
103  resetCov();
104  if( newdim != m_dim )
105  {
106  m_par.ResizeTo(newdim);
107  m_cov.ResizeTo(newdim,newdim);
108  m_nConstraintsVec.resize(newdim,0) ;
109  }
110 }
111 
113 {
114  if( newdim > m_dim ) {
115  m_dim = newdim ;
116  // very expensive, but okay ...
117  // TVectorD newpar(newdim) ;
118  // newpar.sub(1,m_par);
119  //
120  // TMatrixDSym newcov(newdim) ;
121  // newcov.sub(1,m_cov) ;
122  //
123  // // HepVector newpar(newdim,0) ;
124  // // HepSymMatrix newcov(newdim,0) ;
125  // // std::cout << newpar << std::endl ;
126  // // for(int row=0; row<m_dim ; row++) {
127  // // newpar(row) = m_par(row) ;
128  // // for(int col=0; col<=row; col++)
129  // // // newcov(row,col) = m_cov(row,col) ;
130  // // }
131  // // std::cout << m_par << " " << newpar << std::endl ;
132  //
133  // m_par = newpar ;
134  // m_cov = newcov ;
135  m_par.ResizeTo(newdim);
136  m_cov.ResizeTo(newdim,newdim);
137  m_nConstraintsVec.resize(newdim,0) ;
138  }
139 }
140 
141 void DecayTreeFitter::FitParams::addChiSquare( double chisq, int nconstraints, const ParticleBase* p)
142 {
143  m_chiSquare += chisq;
144  m_nConstraints += nconstraints ;
145  if( p ) m_chiSquareMap[ p ] += ChiSquare(chisq,nconstraints) ;
146 }
147 
149 {
150  std::map<const ParticleBase*, ChiSquare>::const_iterator it = m_chiSquareMap.find( &p ) ;
151  return it != m_chiSquareMap.end() ? it->second : ChiSquare() ;
152 }
153 
154 // void DecayTreeFitter::FitParams::copy(const FitParams& rhs,
155 // const indexmap& anindexmap)
156 // {
157 // for(indexmap::const_iterator it = anindexmap.begin() ;
158 // it != anindexmap.end(); ++it) {
159 // int idim = it->first->dim() ;
160 // int indexrhs = it->second ;
161 // int indexlhs = it->first->index() ;
162 // for(int i=0; i<idim; i++)
163 // m_par(indexlhs+i) = rhs.m_par(indexrhs+i) ;
164 // for(indexmap::const_iterator it2 = it ;
165 // it2 != anindexmap.end(); ++it2) {
166 // int jdim = it2->first->dim() ;
167 // int jndexrhs = it2->second ;
168 // int jndexlhs = it2->first->index() ;
169 // for(int i=0; i<idim; i++)
170 // for(int j=0; j<jdim ; j++)
171 // m_cov( indexlhs+i, jndexlhs+j) = rhs.m_cov( indexrhs+i, jndexrhs+j) ;
172 // }
173 // }
174 // }
int row
Definition: anaLmdDigi.C:67
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
int col
Definition: anaLmdDigi.C:67
void addChiSquare(double chi2, int nconstraints, const ParticleBase *p)
Definition: FitParams.cxx:141
Double_t p
Definition: anasim.C:58
void resize(int newdim)
Definition: FitParams.cxx:112
double chiSquare() const
Definition: FitParams.h:51
void resetCov(double scale=100)
Definition: FitParams.cxx:43
TFile * fpar
Definition: bump_analys.C:22
void reset(int newdim)
Definition: FitParams.cxx:100
ClassImp(FitParams)
TMatrixDSym & cov()
Definition: FitParams.h:34