FairRoot/PandaRoot
InteractionPoint.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 "FitParams.h"
9 #include "InteractionPoint.h"
10 #include "RecoTrack.h"
11 //#include "Event/Particle.h"
12 //#include "Event/VertexBase.h"
13 #include <assert.h>
14 //#include <vector>
15 #include "TVector3.h"
16 #include "TMath.h"
17 #include "RhoVector3Err.h"
18 #include "RhoCalculationTools.h"
19 #include "SortTool.h"
20 
21 using namespace DecayTreeFitter;
22 
23 extern int vtxverbose ;
25 
27 : InternalParticle(cand,0,config), m_ipPosCov(3), m_ipPosCovInv(3), m_ipMomCov(4), m_ipMomCovInv(4), m_hasposcon(false), m_hasmomcon(false)
28 {
29  if(vtxverbose>=2) std::cout << "InteractionPoint: start"<<std::endl;
30  //addDaughter( cand, config ) ;
31  //if(vtxverbose>=2) std::cout << "InteractionPoint: daughters done"<<std::endl;
32 
33  m_hasmomcov = false;
34  m_hasposcov = false;
35 
36  if(vtxverbose>=2) {
37  std::cout << "InteractionPoint: without initial beam spot" <<std::endl ;
38  std::cout << "daughter: " << daughters().front()->name() << std::endl ;
39  }
40 }
41 
43 : InternalParticle(cand,0,config), m_ipPosCov(3), m_ipPosCovInv(3), m_ipMomCov(4), m_ipMomCovInv(4), m_hasposcon(true), m_hasmomcon(false)
44 {
45  if(vtxverbose>=2) std::cout << "InteractionPoint: start"<<std::endl;
46  //addDaughter( cand, config ) ;
47  //if(vtxverbose>=2) std::cout << "InteractionPoint: daughters done"<<std::endl;
48 
49  m_ipPos(0) = ipvertex.x() ;
50  m_ipPos(1) = ipvertex.y() ;
51  m_ipPos(2) = ipvertex.z() ;
52  for(int ii=0;ii<3;ii++) for(int jj=0;jj<3;jj++){
53  m_ipPosCov(ii,jj) = ipvertex.CovMatrix()(ii,jj);
54  }
55  m_hasmomcov = false;
56  m_hasposcov = (0!=m_ipPosCov.NonZeros()); // a zero protection flag
57  if(m_hasposcov)
58  {
59  double ierr;
60  if(vtxverbose>=2) std::cout << "InteractionPoint: inverting matrix"<<std::endl;
62  m_ipPosCovInv.Invert(&ierr) ;
63  }
64  if(vtxverbose>=2) {
65  std::cout << "InteractionPoint: initial beam spot = ("
66  <<m_ipPos(0) << "," << m_ipPos(1) << "," << m_ipPos(2) << ") " <<std::endl ;
67  if(vtxverbose>=5){
68  std::cout<<"m_ipPosCov"; RhoCalculationTools::PrintMatrix(m_ipPosCov);
69  }
70  std::cout << "daughter: " << daughters().front()->name() << std::endl ;
71  }
72 }
73 
75 : InternalParticle(cand,0,config), m_ipPosCov(3), m_ipPosCovInv(3), m_ipMomCov(4), m_ipMomCovInv(4), m_hasposcon(false), m_hasmomcon(true)
76 {
77  if(vtxverbose>=2) std::cout << "InteractionPoint: start"<<std::endl;
78  //addDaughter( cand, config ) ;
79  //if(vtxverbose>=2) std::cout << "InteractionPoint: daughters done"<<std::endl;
80 
81  m_ipMom(0) = ipmom.X();
82  m_ipMom(1) = ipmom.Y();
83  m_ipMom(2) = ipmom.Z();
84  m_ipMom(3) = ipmom.E();
85  for(int ii=0;ii<4;ii++) for(int jj=0;jj<4;jj++){
86  m_ipMomCov(ii,jj) = ipmom.CovMatrix()(ii,jj);
87  }
88 
89  m_hasposcov = false;
90  m_hasmomcov = (0!=m_ipMomCov.NonZeros()); // a zero protection flag
91  if(m_hasmomcov)
92  {
93  double ierr;
94  if(vtxverbose>=2) std::cout << "InteractionPoint: inverting matrix"<<std::endl;
96  m_ipMomCovInv.Invert(&ierr) ;
97  }
98 
99  if (particle())
100  {
101  RhoVector3Err vtx = particle()->PosWCov();
102  if(vtx.Mag()>0){
103  if(vtxverbose>=3) std::cout << "InteractionPoint: Found a vertex in RhoCandidate"<<std::endl;
104  m_ipPos(0) = vtx.x() ;
105  m_ipPos(1) = vtx.y() ;
106  m_ipPos(2) = vtx.z() ;
107  m_hasposcon=true;
108  for(int ii=0;ii<3;ii++) for(int jj=0;jj<3;jj++){
109  m_ipPosCov(ii,jj) = vtx.CovMatrix()(ii,jj);
110  }
111  m_hasposcov = (0!=m_ipPosCov.NonZeros()); // a zero protection flag
112  }
113  }
114 
115  if(vtxverbose>=2) {
116  std::cout << "InteractionPoint: initial mom = (" <<m_ipMom(0) << "," << m_ipMom(1) << "," << m_ipMom(2)<< "," << m_ipMom(3) << ")" <<std::endl ;
117  if(vtxverbose>=5){
118  std::cout<<"m_ipMomCov"; RhoCalculationTools::PrintMatrix(m_ipMomCov);
119  }
120  std::cout << "daughter: " << daughters().front()->name() << std::endl ;
121  }
122 }
123 
125 : InternalParticle(cand,0,config), m_ipPosCov(3), m_ipPosCovInv(3), m_ipMomCov(4), m_ipMomCovInv(4), m_hasposcon(true), m_hasmomcon(true)
126 {
127  if(vtxverbose>=2) std::cout << "InteractionPoint: start"<<std::endl;
128  //addDaughter( cand, config ) ;
129  //if(vtxverbose>=2) std::cout << "InteractionPoint: daughters done"<<std::endl;
130 
131  m_ipPos(0) = ipvertex.x() ;
132  m_ipPos(1) = ipvertex.y() ;
133  m_ipPos(2) = ipvertex.z() ;
134  for(int ii=0;ii<3;ii++) for(int jj=0;jj<3;jj++){
135  m_ipPosCov(ii,jj) = ipvertex.CovMatrix()(ii,jj);
136  }
137 
138  m_ipMom(0) = ipmom.X();
139  m_ipMom(1) = ipmom.Y();
140  m_ipMom(2) = ipmom.Z();
141  m_ipMom(3) = ipmom.E();
142  for(int ii=0;ii<4;ii++) for(int jj=0;jj<4;jj++){
143  m_ipMomCov(ii,jj) = ipmom.CovMatrix()(ii,jj);
144  }
145 
146  m_hasposcov = (0!=m_ipPosCov.NonZeros()); // a zero protection flag
147  if(m_hasposcov)
148  {
149  double ierr;
150  if(vtxverbose>=2) std::cout << "InteractionPoint: inverting matrix"<<std::endl;
152  m_ipPosCovInv.Invert(&ierr) ;
153  }
154  m_hasmomcov = (0!=m_ipMomCov.NonZeros()); // a zero protection flag
155  if(m_hasmomcov)
156  {
157  double ierr;
158  if(vtxverbose>=2) std::cout << "InteractionPoint: inverting matrix"<<std::endl;
160  m_ipMomCovInv.Invert(&ierr) ;
161  }
162  if(vtxverbose>=2) {
163  std::cout << "InteractionPoint: initial beam spot = ("
164  <<m_ipPos(0) << "," << m_ipPos(1) << "," << m_ipPos(2) << ") "
165  << "mom = (" <<m_ipMom(0) << "," << m_ipMom(1) << "," << m_ipMom(2)<< "," << m_ipMom(3) << ")" <<std::endl ;
166  if(vtxverbose>=5){
167  std::cout<<"m_ipPosCov"; RhoCalculationTools::PrintMatrix(m_ipPosCov);
168  std::cout<<"m_ipMomCov"; RhoCalculationTools::PrintMatrix(m_ipMomCov);
169  }
170  std::cout << "daughter: " << daughters().front()->name() << std::endl ;
171  }
172 }
173 
174 ErrCode
176 {
177  ErrCode status ;
178  if(vtxverbose>5){std::cout<<"InteractionPoint::initPar1: - start"<<std::endl;}
179 
180  // initialize our IP measurement if there
181  int posindex = posIndex() ;
182  if(m_hasposcon)
183  {
184  for(int row=0; row<3; row++)
185  fitparams->par()(posindex+row) = m_ipPos(row) ;
186  }
187 
188  InternalParticle::initPar1(fitparams);
189 
190  return status ;
191 }
192 
193 ErrCode
195 {
197  int posindex = posIndex();
198  for(int row=0; row<3; row++)
199  {
200  if(m_hasposcov)
201  { // when we know an external IP we put it here as initial values
202  for(int col=0;col<3;col++)
203  fitpar->cov()(posindex+row,posindex+col) = m_ipPosCov(row,col) ;
204  }
205  }
206 return status;
207 
208 }
209 
210 ErrCode
212  Projection& p) const
213 {
214  int posindex = posIndex() ;
215  if(vtxverbose>6){std::cout<<"InteractionPoint::projectIPConstraint(): posindex="<<posindex<<std::endl;}
216  if(m_hasposcon){
217  for(int row=0; row<3; ++row) {
218  p.r(row) = fitparams->par()(posindex+row) - m_ipPos(row);
219  p.H(row,posindex+row) = 1 ;
220  if(m_hasposcov)
221  for(int col=0; col<3; ++col)
222  p.Vfast(row,col) = m_ipPosCov(row,col) ;
223  }
224  }
225  if(vtxverbose>6){
226  std::cout<<"InteractionPoint::projectIPConstraint(): projection is:"<<posindex<<std::endl;
227  std::cout<<"r "; p.r().Print();
228  std::cout<<"V "; p.V().Print();
229  std::cout<<"H "; RhoCalculationTools::PrintMatrix(p.H());
230  }
231  return ErrCode::success ;
232 }
233 
234 ErrCode
236  Projection& p) const
237 {
238  int momindex = momIndex() ; // get momentum part of the only daughter (head of tree)
239  if(vtxverbose>6){std::cout<<"InteractionPoint::projectIPConstraint(): daumomindex="<<momindex<<std::endl;}
240  if(m_hasmomcon){
241  for(int row=0; row<4; ++row) {
242  p.r(row) = fitparams->par()(momindex+row) - m_ipMom(row);
243  p.H(row,momindex+row) = 1 ;
244  if(m_hasmomcov)
245  for(int col=0; col<4; ++col)
246  p.Vfast(row,col) = m_ipMomCov(row,col) ;
247  }
248  }
249  if(vtxverbose>6){
250  std::cout<<"InteractionPoint::projectBeamConstraint(): projection is:"<<momindex<<std::endl;
251  std::cout<<"r "; p.r().Print();
252  std::cout<<"V "; p.V().Print();
253  std::cout<<"H "; RhoCalculationTools::PrintMatrix(p.H());
254  }
255  return ErrCode::success ;
256 }
257 
258 ErrCode
260  const FitParams* fitparams,
261  Projection& p) const
262 {
263  ErrCode status;
264  switch(aType) {
266  status |= projectIPConstraint(fitparams,p) ;
267  break ;
269  status |= projectBeamConstraint(fitparams,p) ;
270  break ;
271  default:
272  status |= InternalParticle::projectConstraint(aType,fitparams,p) ;
273  }
274  return status ;
275 }
276 
277 double
279 {
280  std::cout<<" Marke 2" <<std::endl;
281  double chisq=0.;
282  //if(m_hasposcon&&m_hasposcov)
283  //{ // no covariance, no chi2 contribution!
284  //Projection pPos(fitparams->dim(),3) ;
285  //projectIPConstraint(fitparams,pPos) ;
286  //chisq+=pPos.chiSquare();
287  //}
288  if(m_hasmomcon&&m_hasmomcov)
289  { // no covariance, no chi2 contribution!
290  Projection pMom(fitparams->dim(),4) ;
291  projectBeamConstraint(fitparams,pMom) ;
292  chisq+=pMom.chiSquare();
293  }
294  return chisq ;
295 }
296 
297 //double
298 //DecayTreeFitter::InteractionPoint::chiSquare(const FitParams* fitparams) const
299 //{
300  //double chisq=0.;
301  //if(m_hasposcon&&m_hasposcov)
302  //{ // no covariance, no chi2 contribution!
303  //int posindex = posIndex() ;
304  //TVectorD residualpos(3) ;
305  //for(int row=0; row<3; ++row)
306  //residualpos(row) = fitparams->par()(posindex+row) - m_ipPos(row) ;
307  //chisq += m_ipPosCovInv.Similarity(residualpos);
308  //}
309  //if(m_hasmomcon&&m_hasmomcov)
310  //{ // no covariance, no chi2 contribution!
311  //int momindex = momIndex() ;
312  //TVectorD residualmom(4) ;
313  //for(int row=0; row<4; ++row)
314  //residualmom(row) = m_ipMom(row) - fitparams->par()(momindex+row) ;
315  //chisq += m_ipMomCovInv.Similarity(residualmom);
316  //}
318  //chisq += ParticleBase::chiSquareD(fitparams) ;
319 
320  //return chisq ;
321 //}
322 
324 {
326 
327  //the beamspot
328  if(m_hasposcon && m_hasposcov) alist.push_back(Constraint(this,Constraint::beamspot,depth,3)) ;
329  if(m_hasmomcon) alist.push_back(Constraint(this,Constraint::beamenergy,depth,4)) ;
330 }
331 
332 
333 //std::string DecayTreeFitter::InteractionPoint::parname(int thisindex) const
334 //{
335  //int id = thisindex ;
337  //if(id>=3) ++id ;
338  //return ParticleBase::parname(id) ;
339 //}
int row
Definition: anaLmdDigi.C:67
virtual ErrCode initPar1(FitParams *)
Double_t p
Definition: anasim.C:58
const RhoError & CovMatrix() const
std::vector< DecayTreeFitter::Constraint > constraintlist
Definition: ParticleBase.h:110
const TVectorD & r() const
Definition: Projection.h:37
RhoCandidate * particle() const
Definition: ParticleBase.h:57
int col
Definition: anaLmdDigi.C:67
virtual ErrCode projectConstraint(Constraint::Type type, const FitParams *fitparams, Projection &p) const
virtual ErrCode initCov(FitParams *) const
const TMatrixD & H() const
Definition: Projection.h:28
virtual ErrCode initPar1(FitParams *)
const TMatrixDSym & V() const
Definition: Projection.h:47
int vtxverbose
ErrCode projectIPConstraint(const FitParams *fitpar, Projection &) const
virtual double chiSquare(const FitParams *par) const
virtual ErrCode initCov(FitParams *) const
static void PrintMatrix(TMatrixT< double > m)
InteractionPoint(RhoCandidate *daughter, const Configuration &config)
virtual void addToConstraintList(constraintlist &alist, int depth) const
RhoVector3Err PosWCov() const
virtual ErrCode projectConstraint(Constraint::Type, const FitParams *, Projection &) const
ClassImp(PndAnaContFact)
const daucontainer & daughters() const
Definition: ParticleBase.h:99
const RhoError & CovMatrix() const
Definition: RhoVector3Err.h:68
virtual void addToConstraintList(constraintlist &alist, int depth) const
ErrCode projectBeamConstraint(const FitParams *fitpar, Projection &) const
TMatrixDSym & cov()
Definition: FitParams.h:34
int status[10]
Definition: f_Init.h:28
double & Vfast(int row, int col)
Definition: Projection.h:50