FairRoot/PandaRoot
GeaneTrackRep.cxx
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 // File and Version Information:
3 // $Id$
4 //
5 // Description:
6 // Implementation of class GeaneTrackRep
7 // see GeaneTrackRep.hh for details
8 //
9 // Environment:
10 // Software developed for the PANDA Detector at FAIR.
11 //
12 // Author List:
13 // Sebastian Neubert TUM (original author)
14 //
15 //
16 //-----------------------------------------------------------
17 
18 // Panda Headers ----------------------
19 
20 // This Class' Header ------------------
21 #include "GeaneTrackRep.h"
22 #include "FairGeaneUtil.h"
23 #include "FairTrackParH.h"
24 
25 // C/C++ Headers ----------------------
26 #include <iostream>
27 #include <cmath>
28 
29 // Collaborating Class Headers --------
30 #include "GFAbsRecoHit.h"
31 #include "GFException.h"
32 #include "FairGeanePro.h"
33 
34 // Class Member definitions -----------
35 
36 #define THETACUT 0.4
37 #define EPSILON 1E-4
38 
40  : GFAbsTrackRep(5), _pdg(211),_backw(0), _spu(1)
41 {
42 
43 }
44 
45 GeaneTrackRep::GeaneTrackRep(FairGeanePro* geane,
46  const GFDetPlane& plane,
47  const TVector3& mom,
48  const TVector3& poserr,
49  const TVector3& momerr,
50  double q,
51  int PDGCode)
52  : GFAbsTrackRep(5), _geane(geane), _pdg(PDGCode), _backw(0), _spu(1)
53 {
54  FairTrackParP par(plane.getO(),mom,poserr,momerr,(int)TMath::Sign(1.0, q),plane.getO(),plane.getU(),plane.getV());
55 
56  _spu=par.GetSPU(); // direction of the momentum
57 
58  fState[0][0]=par.GetQp();
59  fState[1][0]=par.GetTV();
60  fState[2][0]=par.GetTW();
61  fState[3][0]=par.GetV();
62  fState[4][0]=par.GetW();
63 
64  // blow up cov-array: ROOT does not support init with symmetric data
65  // See ROOT docu source-file for TMatrixTSym
66  // i=row, j=collumn
67  double* covarray=par.GetCov();
68  int count=0;
69  for(int i=0;i<5;++i){
70  for(int j=i;j<5;++j){
71  fCov[i][j]=covarray[count];
72  if(i!=j)fCov[j][i]=covarray[count];
73  ++count;
74  }
75  }
76  fRefPlane=plane;
77 }
78 
79 GeaneTrackRep::GeaneTrackRep(FairGeanePro* geane,
80  const GFDetPlane& plane,
81  const TVector3& mom,
82  const TVector3& poserr,
83  const TVector3& momerr,
84  int q,
85  int PDGCode)
86  : GFAbsTrackRep(5), _geane(geane), _pdg(PDGCode), _backw(0), _spu(1)
87 {
88  FairTrackParP par(plane.getO(),mom,poserr,momerr,q,plane.getO(),plane.getU(),plane.getV());
89 
90  _spu=par.GetSPU(); // direction of the momentum
91 
92  fState[0][0]=par.GetQp();
93  fState[1][0]=par.GetTV();
94  fState[2][0]=par.GetTW();
95  fState[3][0]=par.GetV();
96  fState[4][0]=par.GetW();
97 
98  // blow up cov-array: ROOT does not support init with symmetric data
99  // See ROOT docu source-file for TMatrixTSym
100  // i=row, j=collumn
101  double* covarray=par.GetCov();
102  int count=0;
103  for(int i=0;i<5;++i){
104  for(int j=i;j<5;++j){
105  fCov[i][j]=covarray[count];
106  if(i!=j)fCov[j][i]=covarray[count];
107  ++count;
108  }
109  }
110  fRefPlane=plane;
111 }
112 
113 // GeaneTrackRep::GeaneTrackRep(const GeaneTrackRep& rep)
114 // : GFAbsTrackRep(rep)
115 // {
116 // _geane=rep._geane;
117 // }
118 
119 
121 {
122 
123 }
124 
125 
126 
127 
128 double
130  TMatrixT<double>& statePred)
131 {
132  TMatrixT<double> covPred(5,5);
133  return extrapolate(pl,statePred,covPred);
135 }
136 
137 
138 double
140  TMatrixT<double>& statePred,
141  TMatrixT<double>& covPred)
142 {
143  if(fabs(getMom(fRefPlane).Theta()/TMath::Pi()*180.) < THETACUT){
144  GFException exc("GEANE propagation not possible for p.theta<THETACUT",__LINE__,__FILE__);
145  exc.setFatal();
146  throw exc;
147  }
148  statePred.ResizeTo(fDimension,1);
149  covPred.ResizeTo(fDimension,fDimension);
150  TVector3 o=pl.getO();
151  TVector3 u=pl.getU();
152  TVector3 v=pl.getV();
153 
154  TVector3 ofrom=fRefPlane.getO();
155  TVector3 ufrom=fRefPlane.getU();
156  TVector3 vfrom=fRefPlane.getV();
157 
158  _geane->PropagateFromPlane(ufrom,vfrom);
159  _geane->PropagateToPlane(o,u,v);
160 
161  FairTrackParP result;
162  FairTrackParH result2;
163 
164  //std::cout<<"Before prop:"<<std::endl;
165  //Print();
166 
167 
168 
169  double cova[15];
170  int count=0;;
171  for(int i=0; i<5;++i){
172  for(int j=i;j<5;++j){
173  cova[count++]=fCov[i][j];
174  }
175  }
176  //protect against low momentum:
177  if(fabs(fState[0][0])>200){
178  GFException exc("GeaneTrackRep: PROTECT AGAINST LOW MOMENTA",__LINE__,__FILE__);
179  exc.setFatal();
180  throw exc;
181  }
182 
183  checkState();
184 
185 
186  FairTrackParP par(fState[3][0],fState[4][0],fState[1][0],fState[2][0],fState[0][0],cova,ofrom,ufrom,vfrom,_spu);
187  bool backprop=_backw<0;
188  if(_backw==0){
189  //Try to guess if we are doing a forward or backward step:
190  TVector3 pos(par.GetX(),par.GetY(),par.GetZ());
191  TVector3 dir=pl.dist(pos); // direction from pos to plane;
192  //Assume B=(0,0,BZ) -> compare signs of dir.Z and mom.Z:
193  //backprop= (dir.Z()*par.GetPz())<0 ? true : false;
194  backprop= (dir*getMom(fRefPlane))<0;
195  }
196  if(backprop){
197  _geane->setBackProp();
198  //std::cout<<"GEANETRACKREP: USING BACKPROPAGATION!" << std::endl;
199  }
200 
201  Bool_t prop = kTRUE;
202  prop = _geane->Propagate(&par,&result,_pdg); //211
203  if (prop==kFALSE){
204  GFException exc("GEANE propagation failed",__LINE__,__FILE__);
205  //exc.setFatal();
206  throw exc;
207  }
208 
209 
210  double l=_geane->GetLengthAtPCA();
211 
212  statePred[0][0]=result.GetQp();
213  statePred[1][0]=result.GetTV();
214  statePred[2][0]=result.GetTW();
215  statePred[3][0]=result.GetV();
216  statePred[4][0]=result.GetW();
217 
218 
219 
220  double* rescov=result.GetCov();
221  count=0;
222  for(int i=0;i<5;++i){
223  for(int j=i;j<5;++j){
224  covPred[i][j]=rescov[count];
225  if(i!=j)covPred[j][i]=rescov[count];
226  ++count;
227  }
228  }
229 
230  // if(result.GetSPU()!=_spu)std::cout<<"SPU HAS CHANGED! "<<_spu<<" --> "<<result.GetSPU()<<std::endl;
231  _spu=result.GetSPU();
232 
233  //std::cout<<"AFTER EXTRAPOLATE:"<<std::endl;
234  //result.Print();
235  //pl.Print();
236  //statePred.Print();
237  //covPred.Print();
238 
239 
240 
241  return l;
242 }
243 
244 
245 
246 void
248  TVector3& poca,
249  TVector3& dirInPoca){
250  if(fabs(getMom(fRefPlane).Theta()/TMath::Pi()*180.) < THETACUT){
251  GFException exc("GEANE propagation not possible for p.theta<THETACUT",__LINE__,__FILE__);
252  exc.setFatal();
253  throw exc;
254  }
255  int dim = getDim();
256  TMatrixT<double> statePred(dim,1);
257  TMatrixT<double> covPred(dim,dim);
258  //std::cout<<"GeaneTrackRep::extrapolateToPoint"<<std::endl;
259  //fRefPlane.Print();
260 
261  TVector3 ofrom=fRefPlane.getO();
262  TVector3 ufrom=fRefPlane.getU();
263  TVector3 vfrom=fRefPlane.getV();
264 
265  _geane->SetPoint(pos);
266  _geane->PropagateFromPlane(ufrom,vfrom);
267 
268  double cova[15];
269  int count=0;;
270  for(int i=0; i<5;++i){
271  for(int j=i;j<5;++j){
272  cova[count++]=fCov[i][j];
273  }
274  }
275  //protect against low momentum:
276  if(fabs(fState[0][0])>200){
277  GFException exc("GeaneTrackRep: PROTECT AGAINST LOW MOMENTA",__LINE__,__FILE__);
278  exc.setFatal();
279  throw exc;
280  }
281 
282  checkState();
283 
284  FairTrackParP par(fState[3][0],fState[4][0],fState[1][0],fState[2][0],fState[0][0],cova,ofrom,ufrom,vfrom,_spu);
285  //par.Print();
286  bool backprop=_backw<0;
287  if(_backw==0){
288  // check if new point is after or before my position
289  TVector3 dir=fRefPlane.dist(pos); // direction from pos to plane;
290  backprop= (dir*getMom(fRefPlane))>0;
291  }
292  if(!backprop){ // point lies in same direction of flight as momentum
293  //std::cout<<" Propagate in flight direction"<<std::endl;
294  _geane->PropagateToVirtualPlaneAtPCA(1);
295  }
296  else{
297  //std::cout<<" backPropagate"<<std::endl;
298  _geane->BackTrackToVirtualPlaneAtPCA(1);
299  }
300 
301  FairTrackParP result;
302  Bool_t prop = kTRUE;
303  prop = _geane->Propagate(&par,&result,_pdg); //211
304  if (prop==kFALSE) {
305  GFException exc("GEANE propagation failed",__LINE__,__FILE__);
306  //exc.setFatal();
307  throw exc;
308  //pl=fRefPlane;
309  //return pos;
310  }
311 
312  statePred[0][0]=result.GetQp();
313  statePred[1][0]=result.GetTV();
314  statePred[2][0]=result.GetTW();
315  statePred[3][0]=result.GetV();
316  statePred[4][0]=result.GetW();
317 
318  double* rescov=result.GetCov();
319  count=0;
320  for(int i=0;i<5;++i){
321  for(int j=i;j<5;++j){
322  covPred[i][j]=rescov[count];
323  if(i!=j)covPred[j][i]=rescov[count];
324  ++count;
325  }
326  }
327 
328  poca.SetXYZ(result.GetX(),result.GetY(),result.GetZ());
329  dirInPoca = result.GetJVer().Cross( result.GetKVer() );
330 }
331 
332 
333 void
334 GeaneTrackRep::extrapolateToLine(const TVector3& point1,
335  const TVector3& point2,
336  TVector3& poca,
337  TVector3& dirInPoca,
338  TVector3& poca_onwire)
339 {
340  if(fabs(getMom(fRefPlane).Theta()/TMath::Pi()*180.) < THETACUT){
341  GFException exc("GEANE propagation not possible for p.theta<THETACUT",__LINE__,__FILE__);
342  exc.setFatal();
343  throw exc;
344  }
345 
346  // call propagation to closest approach to a wire
347  Int_t pca = 2;
348 
349  // calculate a very large track length
350  TVector3 start = getPos(fRefPlane);
351  Double_t distance1, distance2;
352  distance1 = (point1 - start).Mag();
353  distance2 = (point2 - start).Mag();
354  Double_t maxdistance;
355  if(distance1 < distance2) maxdistance = distance2;
356  else maxdistance = distance1;
357  maxdistance *= 2.;
358 
359  // variables for FindPCA:
360  TVector3 point(0,0,0);
361  Double_t Rad = 0.;
362  // poca = vpf = point of closest approach on track
363  // poca_onwire = vwi = point of closest approach on wire
364  Double_t Di = 0.;
365  Float_t trklength = 0.;
366 
367  // covariance matrix
368  FairGeaneUtil util;
369  Double_t cov55[5][5];
370  for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) cov55[i][j] = fCov[i][j];
371  Double_t cova[15];
372  util.FromMat25ToVec15(cov55, cova);
373 
374  TVector3 o = fRefPlane.getO();
375  TVector3 dj = fRefPlane.getU();
376  TVector3 dk = fRefPlane.getV();
377 
378  FairTrackParP par(fState[3][0],fState[4][0],fState[1][0],fState[2][0],fState[0][0],cova,o,dj,dk,_spu);
379 
380  // get propagation direction
381  Int_t direction = getPropDir();
382 
383  _geane->ActualFindPCA(pca, &par, direction);
384  Int_t findpca = _geane->FindPCA(pca, _pdg, point, point1, point2, maxdistance, Rad, poca, poca_onwire, Di, trklength);
385 
386  if(findpca != 0) {
387  GFException exc("findpca failure", __LINE__,__FILE__);
388  throw exc;
389  }
390 
391  // dir in poca not filled now
392  dirInPoca.SetXYZ(0., 0., 0.);
393 
394 }
395 
396 
397 
398 
399 
400 
401 TVector3
402 GeaneTrackRep::getPocaOnLine(const TVector3& p1, const TVector3& p2, bool back){
403 
404  //std::cout<<"GeaneTrackRep::getPocaToWire"<<std::endl;
405 
406  TVector3 ofrom=fRefPlane.getO();
407  TVector3 ufrom=fRefPlane.getU();
408  TVector3 vfrom=fRefPlane.getV();
409 
410  _geane->SetWire(p1,p2);
411  _geane->PropagateFromPlane(ufrom,vfrom);
412  double cova[15];
413  int count=0;;
414  for(int i=0; i<5;++i){
415  for(int j=i;j<5;++j){
416  cova[count++]=fCov[i][j];
417  }
418  }
419  // protect against low momentum:
420  if(fabs(fState[0][0])>200){
421  GFException exc("GeaneTrackRep: PROTECT AGAINST LOW MOMENTA",__LINE__,__FILE__);
422  exc.setFatal();
423  throw exc;
424  }
425 
426  checkState();
427 
428  FairTrackParP par(fState[3][0],fState[4][0],fState[1][0],fState[2][0],fState[0][0],cova,ofrom,ufrom,vfrom,_spu);
429 
430 
431  if(!back){ // point lies in same direction of flight as momentum
432  //std::cout<<" Propagate in flight direction"<<std::endl;
433  _geane->PropagateToVirtualPlaneAtPCA(2); // option 2 means wire!
434  }
435  else{
436  //std::cout<<" backPropagate"<<std::endl;
437  _geane->BackTrackToVirtualPlaneAtPCA(2);
438  }
439 
440  FairTrackParP result;
441  Bool_t prop = kTRUE;
442 
443  prop = _geane->Propagate(&par,&result,_pdg);
444  if (prop==kFALSE) {
445  GFException exc("GEANE propagation failed",__LINE__,__FILE__);
446  //exc.setFatal();
447  throw exc;
448  }
449 
450  return _geane->GetPCAOnWire();
451 }
452 
453 
454 
455 
456 
457 
458 TVector3
460 {
461  TMatrixT<double> statePred(fState);
462  if(pl!=fRefPlane)extrapolate(pl,statePred);
463  return pl.getO()+(statePred[3][0]*pl.getU())+(statePred[4][0]*pl.getV());
464 }
465 
466 TVector3
468 {
469  TMatrixT<double> statePred(fState);
470  if(pl!=fRefPlane)extrapolate(pl,statePred);
471  double fSPU = _spu;
472  TVector3 mom = fSPU*pl.getNormal()+fSPU*statePred[1][0]*pl.getU()+fSPU*statePred[2][0]*pl.getV();
473  mom.SetMag(1./fabs(statePred[0][0]));
474  return mom;
475 }
476 void
477 GeaneTrackRep::getPosMom(const GFDetPlane& pl,TVector3& pos, TVector3& mom)
478 {
479  TMatrixT<double> statePred(fState);
480  if(pl!=fRefPlane)extrapolate(pl,statePred);
481  mom = pl.getNormal()+statePred[1][0]*pl.getU()+statePred[2][0]*pl.getV();
482 
483  mom.SetMag(1./fabs(statePred[0][0]));
484  pos = pl.getO()+(statePred[3][0]*pl.getU())+(statePred[4][0]*pl.getV());
485 }
486 
487 
488 void
489 GeaneTrackRep::getPosMomCov(const GFDetPlane& pl,TVector3& pos,TVector3& mom,TMatrixT<double>& cov){
490  cov.ResizeTo(6,6);
491 
492  TMatrixT<double> statePred(fState), covPred(fCov);
493  if(pl!=fRefPlane)extrapolate(pl, statePred, covPred);
494 
495  // position
496  pos = pl.getO()+(statePred[3][0]*pl.getU())+(statePred[4][0]*pl.getV());
497 
498  // momentum
499  double fSPU = _spu;
500  mom = fSPU*pl.getNormal()+fSPU*statePred[1][0]*pl.getU()+fSPU*statePred[2][0]*pl.getV();
501  mom.SetMag(1./fabs(statePred[0][0]));
502 
503  // covariance matrix
504  FairGeaneUtil util;
505  // covPred 5 X 5 ==> cov55[5][5]
506  double cov55[5][5];
507  for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) cov55[i][j] = covPred[i][j];
508  // cov55[5][5] ==> cov15[15]
509  double cov15[15];
510  util.FromMat25ToVec15(cov55, cov15);
511 
512  FairTrackParP parPred(statePred[3][0],
513  statePred[4][0], statePred[1][0],
514  statePred[2][0], statePred[0][0],
515  cov15,
516  pl.getO(), pl.getU(), pl.getV(),
517  _spu);
518  double cov66[6][6];
519  parPred.GetMARSCov(cov66);
520  for(int i = 0; i < 6; i++) for(int j = 0; j < 6; j++) cov[i][j] = cov66[i][j];
521 
522 }
523 
524 
525 void
527  if(fabs(fState[3][0])<1.E-4)fState[3][0]=1.E-4;
528  if(fabs(fState[4][0])<1.E-4)fState[4][0]=1.E-4;
529 
530  //if (!(fState.Abs()>1.E-15) || !(fState.Abs()<1.E50)){
531  // GFException exc("fState out of numerical bounds",__LINE__,__FILE__);
532  // exc.setFatal();
533  // throw exc;
534  //}
535 }
536 
537 
539 
TVector3 getMom()
TVector3 pos
virtual void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
method which gets position, momentum and 6x6 covariance matrix
virtual double extrapolate(const GFDetPlane &, TMatrixT< double > &statePred)
returns the tracklength spanned in this extrapolation
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:80
TVector3 getV() const
Definition: GFDetPlane.h:77
Int_t i
Definition: run_full.C:25
Detector plane genfit geometry class.
Definition: GFDetPlane.h:59
FairGeanePro * _geane
Double_t par[3]
void extrapolateToLine(const TVector3 &point1, const TVector3 &point2, TVector3 &poca, TVector3 &dirInPoca, TVector3 &poca_onwire)
This method extrapolates to the point of closest approach to a line.
Double_t mom
Definition: plot_dirc.C:14
__m128 v
Definition: P4_F32vec4.h:4
unsigned int fDimension
Dimensionality of track representation.
Definition: GFAbsTrackRep.h:85
virtual ~GeaneTrackRep()
void extrapolateToPoint(const TVector3 &pos, TVector3 &poca, TVector3 &dirInPoca)
This method is to extrapolate the track to point of closest approach to a point in space...
unsigned int getDim() const
returns dimension of state vector
virtual void getPosMom(const GFDetPlane &, TVector3 &pos, TVector3 &mom)
Double_t
GFDetPlane fRefPlane
TVector3 getPos()
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TPad * p2
Definition: hist-t7.C:117
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:45
TVector3 getU() const
Definition: GFDetPlane.h:76
#define THETACUT
ClassImp(PndAnaContFact)
TPad * p1
Definition: hist-t7.C:116
void setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:77
int count
TMatrixT< double > fState
The vector of track parameters.
Definition: GFAbsTrackRep.h:88
Double_t Pi
TVector3 getNormal() const
Definition: GFDetPlane.cxx:138
TVector3 getPocaOnLine(const TVector3 &p1, const TVector3 &p2, bool back=false)
TVector3 getO() const
Definition: GFDetPlane.h:75
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72
TMatrixT< double > fCov
The covariance matrix.
Definition: GFAbsTrackRep.h:91
TVector3 dist(const TVector3 &point) const
Definition: GFDetPlane.cxx:207