LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
GFTrack.h
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
24 #ifndef GFTRACK_H
25 #define GFTRACK_H
26 
27 #include<map>
28 
32 
33 #include "TClonesArray.h"
34 #include "TObjArray.h"
35 
38 
39 class TVirtualGeoTrack;
40 
61 namespace genf {
62 
63 class GFTrack : public TObject {
64 private:
65 
66 
76  TObjArray* fTrackReps; //->
77 
80  std::vector<GFAbsRecoHit*> fHits;
82 
86  std::vector< GFBookkeeping* > fBookkeeping;
87 
91  std::vector<int> fRepAtHit;
92 
96  GFTrackCand fCand; // list of hits
97  // Cov and Updates at each step (on last iteration!) as calculated
98  // in GFKalman.cxx.
99  std::vector < TMatrixT<Double_t> > fHitMeasCov;
100  std::vector < TMatrixT<Double_t> > fHitUpdate;
101  std::vector < TMatrixT<Double_t> > fHitState;
102  std::vector < Double_t > fHitChi2;
103  std::vector < TMatrixT<Double_t> > fHitCov7x7;
104  std::vector < TMatrixT<Double_t> > fHitCov;
105  std::vector < TVector3 > fHitPlaneXYZ;
106  std::vector < TVector3 > fHitPlaneUxUyUz;
107  std::vector < TVector3 > fHitPlaneU;
108  std::vector < TVector3 > fHitPlaneV;
109 
110  int fPDG;
111 
112  static const int fDefNumTrackReps = 10;
113  unsigned int fCardinal_rep; // THE selected rep, default=0;
114 
115  unsigned int fNextHitToFit;
116 
117 public:
118 
120  GFTrack();
121 
123  GFTrack(const GFTrack&);
124 
126  GFTrack& operator=(const GFTrack&);
127 
134 
135  virtual ~GFTrack();
136 
137  // -----------------------
138  // Accessors
139  // -----------------------
140 
143  void reset(); // deletes the RecoHits!
144 
148  int getFailedHits(int repId=-1){
149  int theRep;
150  if(repId==-1) theRep=fCardinal_rep;
151  else theRep = repId;
152  return fBookkeeping.at(theRep)->getNumFailed();
153  }
154 
155  std::vector<GFAbsRecoHit*> getHits() {return fHits;}
156 
157  const GFTrackCand& getCand() const {return fCand;}
158 
159  GFAbsRecoHit* getHit(int id) const {
160  return fHits.at(id);
161  }
162 
163  unsigned int getNumHits() const {
164  return fHits.size();
165  }
166 
177  void mergeHits(GFTrack* trk);
178 
183  void releaseHits(){fHits.clear();}
184 
187  unsigned int getNextHitToFit() const {return fNextHitToFit;}
188 
191  void setNextHitToFit(unsigned int i) {fNextHitToFit=i;}
192 
195  GFAbsTrackRep* getTrackRep(int id) const {
196  return reinterpret_cast<GFAbsTrackRep*>(fTrackReps->At(id));
197  }
198 
201  unsigned int getNumReps() const {
202  return fTrackReps->GetEntriesFast();
203  }
204 
211  GFAbsTrackRep* getCardinalRep() const {return ((GFAbsTrackRep*)fTrackReps->At(fCardinal_rep));}
212 
213 
218  TVector3 getMom() const {return getCardinalRep()->getMom();}
219 
225  TVector3 getMom(const GFDetPlane& pl) const {return getCardinalRep()->getMom(pl);}
226 
231  TVector3 getPos() const {return getCardinalRep()->getPos();}
232 
238  TVector3 getPos(const GFDetPlane& pl) const {return getCardinalRep()->getPos(pl);}
239 
244  void getPosMomCov(TVector3& pos,TVector3& mom,TMatrixT<Double_t>& cov){
245  getCardinalRep()->getPosMomCov(pos,mom,cov);
246  }
247 
253  void getPosMomCov(const GFDetPlane& pl,TVector3& pos,TVector3& mom,TMatrixT<Double_t>& cov){
254  getCardinalRep()->getPosMomCov(pl,pos,mom,cov);
255  }
256 
261  double getChiSqu() const {return getCardinalRep()->getChiSqu();}
262 
267  unsigned int getNDF() const {return getCardinalRep()->getNDF();}
268 
273  double getRedChiSqu() const {return getCardinalRep()->getRedChiSqu();}
274 
279  double getCharge() const {return getCardinalRep()->getCharge();}
280 
283  void fillGeoTrack(TVirtualGeoTrack* tr) const {fillGeoTrack(tr,fCardinal_rep);}
284 
287  void fillGeoTrack(TVirtualGeoTrack* tr,unsigned int repid) const;
288 
289  // ---------------------
290  // Modifiers
291  // ---------------------
292 
293  void addFailedHit(unsigned int irep,unsigned int id){
294  fBookkeeping.at(irep)->addFailedHit(id);
295  }
296 
299  inline void addHit(GFAbsRecoHit* theHit) {
300  fHits.push_back(theHit);
301  }
302 
305  void addHit(GFAbsRecoHit* theHit,
306  unsigned int detId,
307  unsigned int hitId,
308  double rho=0.,
309  unsigned int planeId=0){
310  fHits.push_back(theHit);
311  fCand.addHit(detId,hitId,rho,planeId);
312  }
313 
318  void addHitVector(std::vector<GFAbsRecoHit*> hits) {
319  fHits = hits;
320  }
321 
326  void addTrackRep(GFAbsTrackRep* theTrackRep) {
327  if(fTrackReps==NULL)fTrackReps=new TObjArray(fDefNumTrackReps);
328  fTrackReps->Add(theTrackRep);
329  fBookkeeping.push_back( new GFBookkeeping() );
330  fRepAtHit.push_back(-1);
331  }
332 
334  GFBookkeeping* getBK(int index=-1){
335  if(index==-1) return fBookkeeping.at(fCardinal_rep);
336  if ((unsigned int)index >= getNumReps())
337  throw GFException("genf::GFTrack::getBK(): index out of range", __LINE__, __FILE__).setFatal();
338  return fBookkeeping.at(index);
339  }
340 
342  void setCandidate(const GFTrackCand& cand, bool doreset=false);
343 
348  void setCardinalRep(unsigned int r){if((int)r<fTrackReps->GetEntriesFast())fCardinal_rep=r;}
349 
350  void setHitMeasuredCov(TMatrixT<Double_t> mat) {fHitMeasCov.push_back(mat);}
351  void setHitUpdate(TMatrixT<Double_t> mat) {fHitUpdate.push_back(mat);}
352  void setHitChi2(Double_t mat) {fHitChi2.push_back(mat);}
353  void setHitState(TMatrixT<Double_t> mat) {fHitState.push_back(mat);}
354  void setHitCov(TMatrixT<Double_t> mat) {fHitCov.push_back(mat);}
355  void setHitCov7x7(TMatrixT<Double_t> mat) {fHitCov7x7.push_back(mat);}
356  void setHitPlaneXYZ(TVector3 pl) { fHitPlaneXYZ.push_back(pl);}
357  void setHitPlaneUxUyUz(TVector3 pl) { fHitPlaneUxUyUz.push_back(pl);}
358  void setHitPlaneU(TVector3 pl) { fHitPlaneU.push_back(pl);}
359  void setHitPlaneV(TVector3 pl) { fHitPlaneV.push_back(pl);}
360  void setPDG(int pdgt) {fPDG = pdgt;}
361  std::vector < TMatrixT<Double_t> > getHitMeasuredCov() {return fHitMeasCov;}
362  std::vector < TMatrixT<Double_t> > getHitUpdate() {return fHitUpdate;}
363  std::vector < Double_t > getHitChi2() {return fHitChi2;}
364  std::vector < TMatrixT<Double_t> > getHitState() {return fHitState;}
365  std::vector < TMatrixT<Double_t> > getHitCov() {return fHitCov;}
366  std::vector < TMatrixT<Double_t> > getHitCov7x7() {return fHitCov;}
367  std::vector < TVector3 > getHitPlaneXYZ() {return fHitPlaneXYZ;}
368  std::vector < TVector3 > getHitPlaneUxUyUz() {return fHitPlaneUxUyUz;}
369  std::vector < TVector3 > getHitPlaneU() {return fHitPlaneU;}
370  std::vector < TVector3 > getHitPlaneV() {return fHitPlaneV;}
371 
372  int getPDG() {return fPDG;}
380  void getResiduals(unsigned int detId, // which detector?
381  unsigned int dim, // which projection?
382  unsigned int rep, // which trackrep ?
383  std::vector<double>& result);
384 
385 
388  void setRepAtHit(unsigned int irep,int ihit){
389  if (irep >= getNumReps())
390  throw GFException("genf::GFTrack::setRepAtHit(): index out of range", __LINE__, __FILE__).setFatal();
391  fRepAtHit.at(irep) = ihit;
392  }
393 
396  int getRepAtHit(unsigned int irep){
397  if (irep >= getNumReps())
398  throw GFException("genf::GFTrack::getRepAtHit(): index out of range", __LINE__, __FILE__).setFatal();
399  return fRepAtHit.at(irep);
400  }
401 
405  for(unsigned int i=0;i<getNumReps();++i){
406  fRepAtHit.at(i)=-1;
407  }
408  }
409 
412  void printBookkeeping(std::ostream& out = std::cout) const;
413 
414  void Print(std::ostream& out = std::cout) const;
415 
417  for(unsigned int i=0;i<getNumReps();++i){
418  fBookkeeping.at(i)->clearAll();
419  }
420  }
421 
423  for(unsigned int i=0;i<getNumReps();++i){
424  fBookkeeping.at(i)->clearFailedHits();
425  }
426  }
427 
430  void getHitsByPlane(std::vector<std::vector<int>*>& retVal);
431 
432 
433 private:
434  virtual void Print(Option_t*) const
435  { throw std::logic_error(std::string(__func__) + "::Print(Option_t*) not available"); }
436 
437  //public:
438  //ClassDef(GFTrack,1)
439 };
440 } // namespace genf
441 
442 #endif
443 
void clearRepAtHit()
clear the hit indices at which plane,state&cov of reps are defined
Definition: GFTrack.h:404
unsigned int getNDF() const
std::vector< TVector3 > getHitPlaneUxUyUz()
Definition: GFTrack.h:368
std::vector< TMatrixT< Double_t > > getHitUpdate()
Definition: GFTrack.h:362
std::vector< Double_t > fHitChi2
Definition: GFTrack.h:102
void printBookkeeping(std::ostream &out=std::cout) const
print bookkeeping
Definition: GFTrack.cxx:200
GFTrack & operator=(const GFTrack &)
assignement operator
Definition: GFTrack.cxx:71
std::vector< TMatrixT< Double_t > > getHitState()
Definition: GFTrack.h:364
void setNextHitToFit(unsigned int i)
Set next hit to be used in a fit.
Definition: GFTrack.h:191
TObjArray * fTrackReps
Collection of track representations.
Definition: GFTrack.h:76
void setRepAtHit(unsigned int irep, int ihit)
set the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:388
Generic Interface to magnetic fields in GENFIT.
TVector3 getPos(const GFDetPlane &pl) const
Get position at GFDetPlane.
Definition: GFTrack.h:238
virtual TVector3 getPos(const GFDetPlane &pl)=0
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:195
std::vector< TVector3 > getHitPlaneXYZ()
Definition: GFTrack.h:367
std::vector< TMatrixT< Double_t > > fHitUpdate
Definition: GFTrack.h:100
std::vector< TMatrixT< Double_t > > getHitCov()
Definition: GFTrack.h:365
std::vector< TMatrixT< Double_t > > fHitState
Definition: GFTrack.h:101
virtual void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &cov)
method which gets position, momentum and 6x6 covariance matrix
unsigned int fNextHitToFit
Definition: GFTrack.h:115
std::vector< int > fRepAtHit
repAtHit keeps track of at which hit index which rep is currently defined, to avoid null extrapolatio...
Definition: GFTrack.h:91
std::vector< TMatrixT< Double_t > > fHitCov7x7
Definition: GFTrack.h:103
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:85
std::vector< TVector3 > fHitPlaneV
Definition: GFTrack.h:108
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void fillGeoTrack(TVirtualGeoTrack *tr) const
Fill TVirtualGeoTrack object Cardinal representation is used.
Definition: GFTrack.h:283
void setCardinalRep(unsigned int r)
Choose cardinal track represenatation.
Definition: GFTrack.h:348
void setHitState(TMatrixT< Double_t > mat)
Definition: GFTrack.h:353
TVector3 getPos() const
Get present position.
Definition: GFTrack.h:231
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:211
void hits()
Definition: readHits.C:15
GFTrackCand fCand
Helper to store the indices of the hits in the track. See GFTrackCand for details.
Definition: GFTrack.h:96
std::vector< TVector3 > getHitPlaneV()
Definition: GFTrack.h:370
virtual TVector3 getMom(const GFDetPlane &pl)=0
std::vector< Double_t > getHitChi2()
Definition: GFTrack.h:363
unsigned int getNumReps() const
Get number of track represenatations.
Definition: GFTrack.h:201
void setHitMeasuredCov(TMatrixT< Double_t > mat)
Definition: GFTrack.h:350
void addFailedHit(unsigned int irep, unsigned int id)
Definition: GFTrack.h:293
GFTrack()
Default constructor – needed for compatibility with ROOT.
Definition: GFTrack.cxx:30
virtual ~GFTrack()
Definition: GFTrack.cxx:36
void setPDG(int pdgt)
Definition: GFTrack.h:360
GFAbsRecoHit * getHit(int id) const
Definition: GFTrack.h:159
int getRepAtHit(unsigned int irep)
get the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:396
void setHitPlaneV(TVector3 pl)
Definition: GFTrack.h:359
void releaseHits()
Clear hit vector. Note that hits will not be deleted!
Definition: GFTrack.h:183
int getFailedHits(int repId=-1)
return the number of failed Hits in track fit repId == -1 will use cardinal rep
Definition: GFTrack.h:148
unsigned int fCardinal_rep
Definition: GFTrack.h:113
void setHitPlaneUxUyUz(TVector3 pl)
Definition: GFTrack.h:357
void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &cov)
Get position, momentum, and 6x6 covariance at GFDetPlane.
Definition: GFTrack.h:253
double getChiSqu() const
Get chi2.
Definition: GFTrack.h:261
void setHitChi2(Double_t mat)
Definition: GFTrack.h:352
double getRedChiSqu() const
Get chi2/NDF.
Definition: GFTrack.h:273
Float_t mat
Definition: plot.C:40
void Print(std::ostream &out=std::cout) const
Definition: GFTrack.cxx:209
std::vector< GFAbsRecoHit * > getHits()
Definition: GFTrack.h:155
virtual double getCharge() const =0
void getResiduals(unsigned int detId, unsigned int dim, unsigned int rep, std::vector< double > &result)
Get residuals.
Definition: GFTrack.cxx:168
GFBookkeeping * getBK(int index=-1)
get GFBookKeeping object for particular track rep (default is cardinal rep)
Definition: GFTrack.h:334
std::vector< TVector3 > getHitPlaneU()
Definition: GFTrack.h:369
void setHitCov7x7(TMatrixT< Double_t > mat)
Definition: GFTrack.h:355
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &cov)
Get position, momentum, and 6x6 covariance at current position.
Definition: GFTrack.h:244
void mergeHits(GFTrack *trk)
Merge two GFTracks. Only hits will be merged.
Definition: GFTrack.cxx:125
std::vector< TMatrixT< Double_t > > fHitCov
Definition: GFTrack.h:104
unsigned int getNumHits() const
Definition: GFTrack.h:163
std::vector< TMatrixT< Double_t > > getHitCov7x7()
Definition: GFTrack.h:366
std::vector< TMatrixT< Double_t > > fHitMeasCov
Definition: GFTrack.h:99
std::vector< TVector3 > fHitPlaneXYZ
Definition: GFTrack.h:105
void addHitVector(std::vector< GFAbsRecoHit * > hits)
Add collection of hits.
Definition: GFTrack.h:318
void clearFailedHits()
Definition: GFTrack.h:422
unsigned int getNDF() const
Get NDF.
Definition: GFTrack.h:267
std::vector< TVector3 > fHitPlaneU
Definition: GFTrack.h:107
void setHitCov(TMatrixT< Double_t > mat)
Definition: GFTrack.h:354
void reset()
Resets the GFTrack – deletes RecoHits!
Definition: GFTrack.cxx:110
std::vector< GFAbsRecoHit * > fHits
Collection of RecoHits.
Definition: GFTrack.h:80
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:50
TVector3 getMom(const GFDetPlane &pl) const
Get momentum at GFDetPlane.
Definition: GFTrack.h:225
void setHitUpdate(TMatrixT< Double_t > mat)
Definition: GFTrack.h:351
virtual void Print(Option_t *) const
Definition: GFTrack.h:434
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:80
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Definition: GFTrackCand.cxx:48
void getHitsByPlane(std::vector< std::vector< int > * > &retVal)
Definition: GFTrack.cxx:219
const GFTrackCand & getCand() const
Definition: GFTrack.h:157
double getChiSqu() const
void addHit(GFAbsRecoHit *theHit)
deprecated!
Definition: GFTrack.h:299
double getCharge() const
Get charge from fit.
Definition: GFTrack.h:279
std::vector< TVector3 > fHitPlaneUxUyUz
Definition: GFTrack.h:106
void setHitPlaneXYZ(TVector3 pl)
Definition: GFTrack.h:356
void addHit(GFAbsRecoHit *theHit, unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Add single hit. Updates the GFTrackCand.
Definition: GFTrack.h:305
int getPDG()
Definition: GFTrack.h:372
std::vector< GFBookkeeping * > fBookkeeping
Collection of Bookeeping objects for failed hits in every trackrep.
Definition: GFTrack.h:86
unsigned int getNextHitToFit() const
Accessor for fNextHitToFit.
Definition: GFTrack.h:187
static const int fDefNumTrackReps
Definition: GFTrack.h:112
void addTrackRep(GFAbsTrackRep *theTrackRep)
Add track represenation.
Definition: GFTrack.h:326
void setHitPlaneU(TVector3 pl)
Definition: GFTrack.h:358
double getRedChiSqu() const
returns chi2/ndf
void clearBookkeeping()
Definition: GFTrack.h:416
void setCandidate(const GFTrackCand &cand, bool doreset=false)
set track candidate
Definition: GFTrack.cxx:139
std::vector< TMatrixT< Double_t > > getHitMeasuredCov()
Definition: GFTrack.h:361
TVector3 getMom() const
Get momentum at the present position.
Definition: GFTrack.h:218