LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 */
23 #ifndef GFTRACK_H
24 #define GFTRACK_H
25 
26 #include <vector>
27 
30 
31 #include "TObjArray.h"
32 
36 
37 class TVirtualGeoTrack;
38 
39 namespace genf {
40  class GFAbsRecoHit;
41 }
42 
63 namespace genf {
64 
65  class GFTrack : public TObject {
66  private:
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:
119  GFTrack();
120 
122  GFTrack(const GFTrack&);
123 
125  GFTrack& operator=(const GFTrack&);
126 
133 
134  virtual ~GFTrack();
135 
136  // -----------------------
137  // Accessors
138  // -----------------------
139 
142  void reset(); // deletes the RecoHits!
143 
147  int getFailedHits(int repId = -1)
148  {
149  int theRep;
150  if (repId == -1)
151  theRep = fCardinal_rep;
152  else
153  theRep = repId;
154  return fBookkeeping.at(theRep)->getNumFailed();
155  }
156 
157  std::vector<GFAbsRecoHit*> getHits() { return fHits; }
158 
159  const GFTrackCand& getCand() const { return fCand; }
160 
161  GFAbsRecoHit* getHit(int id) const { return fHits.at(id); }
162 
163  unsigned int getNumHits() const { return fHits.size(); }
164 
175  void mergeHits(GFTrack* trk);
176 
181  void releaseHits() { fHits.clear(); }
182 
185  unsigned int getNextHitToFit() const { return fNextHitToFit; }
186 
189  void setNextHitToFit(unsigned int i) { fNextHitToFit = i; }
190 
193  GFAbsTrackRep* getTrackRep(int id) const
194  {
195  return reinterpret_cast<GFAbsTrackRep*>(fTrackReps->At(id));
196  }
197 
200  unsigned int getNumReps() const { return fTrackReps->GetEntriesFast(); }
201 
209  {
210  return ((GFAbsTrackRep*)fTrackReps->At(fCardinal_rep));
211  }
212 
217  TVector3 getMom() const { return getCardinalRep()->getMom(); }
218 
224  TVector3 getMom(const GFDetPlane& pl) const { return getCardinalRep()->getMom(pl); }
225 
230  TVector3 getPos() const { return getCardinalRep()->getPos(); }
231 
237  TVector3 getPos(const GFDetPlane& pl) const { return getCardinalRep()->getPos(pl); }
238 
243  void getPosMomCov(TVector3& pos, TVector3& mom, TMatrixT<Double_t>& cov)
244  {
245  getCardinalRep()->getPosMomCov(pos, mom, cov);
246  }
247 
253  void getPosMomCov(const GFDetPlane& pl, TVector3& pos, TVector3& mom, TMatrixT<Double_t>& cov)
254  {
255  getCardinalRep()->getPosMomCov(pl, pos, mom, cov);
256  }
257 
262  double getChiSqu() const { return getCardinalRep()->getChiSqu(); }
263 
268  unsigned int getNDF() const { return getCardinalRep()->getNDF(); }
269 
274  double getRedChiSqu() const { return getCardinalRep()->getRedChiSqu(); }
275 
280  double getCharge() const { return getCardinalRep()->getCharge(); }
281 
284  void fillGeoTrack(TVirtualGeoTrack* tr) const { fillGeoTrack(tr, fCardinal_rep); }
285 
288  void fillGeoTrack(TVirtualGeoTrack* tr, unsigned int repid) const;
289 
290  // ---------------------
291  // Modifiers
292  // ---------------------
293 
294  void addFailedHit(unsigned int irep, unsigned int id)
295  {
296  fBookkeeping.at(irep)->addFailedHit(id);
297  }
298 
301  inline void addHit(GFAbsRecoHit* theHit) { fHits.push_back(theHit); }
302 
305  void addHit(GFAbsRecoHit* theHit,
306  unsigned int detId,
307  unsigned int hitId,
308  double rho = 0.,
309  unsigned int planeId = 0)
310  {
311  fHits.push_back(theHit);
312  fCand.addHit(detId, hitId, rho, planeId);
313  }
314 
319  void addHitVector(std::vector<GFAbsRecoHit*> hits) { fHits = hits; }
320 
325  void addTrackRep(GFAbsTrackRep* theTrackRep)
326  {
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  {
336  if (index == -1) return fBookkeeping.at(fCardinal_rep);
337  if ((unsigned int)index >= getNumReps())
338  throw GFException("genf::GFTrack::getBK(): index out of range", __LINE__, __FILE__)
339  .setFatal();
340  return fBookkeeping.at(index);
341  }
342 
344  void setCandidate(const GFTrackCand& cand, bool doreset = false);
345 
350  void setCardinalRep(unsigned int r)
351  {
352  if ((int)r < fTrackReps->GetEntriesFast()) fCardinal_rep = r;
353  }
354 
355  void setHitMeasuredCov(TMatrixT<Double_t> mat) { fHitMeasCov.push_back(mat); }
356  void setHitUpdate(TMatrixT<Double_t> mat) { fHitUpdate.push_back(mat); }
357  void setHitChi2(Double_t mat) { fHitChi2.push_back(mat); }
358  void setHitState(TMatrixT<Double_t> mat) { fHitState.push_back(mat); }
359  void setHitCov(TMatrixT<Double_t> mat) { fHitCov.push_back(mat); }
360  void setHitCov7x7(TMatrixT<Double_t> mat) { fHitCov7x7.push_back(mat); }
361  void setHitPlaneXYZ(TVector3 pl) { fHitPlaneXYZ.push_back(pl); }
362  void setHitPlaneUxUyUz(TVector3 pl) { fHitPlaneUxUyUz.push_back(pl); }
363  void setHitPlaneU(TVector3 pl) { fHitPlaneU.push_back(pl); }
364  void setHitPlaneV(TVector3 pl) { fHitPlaneV.push_back(pl); }
365  void setPDG(int pdgt) { fPDG = pdgt; }
366  std::vector<TMatrixT<Double_t>> getHitMeasuredCov() { return fHitMeasCov; }
367  std::vector<TMatrixT<Double_t>> getHitUpdate() { return fHitUpdate; }
368  std::vector<Double_t> getHitChi2() { return fHitChi2; }
369  std::vector<TMatrixT<Double_t>> getHitState() { return fHitState; }
370  std::vector<TMatrixT<Double_t>> getHitCov() { return fHitCov; }
371  std::vector<TMatrixT<Double_t>> getHitCov7x7() { return fHitCov; }
372  std::vector<TVector3> getHitPlaneXYZ() { return fHitPlaneXYZ; }
373  std::vector<TVector3> getHitPlaneUxUyUz() { return fHitPlaneUxUyUz; }
374  std::vector<TVector3> getHitPlaneU() { return fHitPlaneU; }
375  std::vector<TVector3> getHitPlaneV() { return fHitPlaneV; }
376 
377  int getPDG() { return fPDG; }
385  void getResiduals(unsigned int detId, // which detector?
386  unsigned int dim, // which projection?
387  unsigned int rep, // which trackrep ?
388  std::vector<double>& result);
389 
392  void setRepAtHit(unsigned int irep, int ihit)
393  {
394  if (irep >= getNumReps())
395  throw GFException("genf::GFTrack::setRepAtHit(): index out of range", __LINE__, __FILE__)
396  .setFatal();
397  fRepAtHit.at(irep) = ihit;
398  }
399 
402  int getRepAtHit(unsigned int irep)
403  {
404  if (irep >= getNumReps())
405  throw GFException("genf::GFTrack::getRepAtHit(): index out of range", __LINE__, __FILE__)
406  .setFatal();
407  return fRepAtHit.at(irep);
408  }
409 
413  {
414  for (unsigned int i = 0; i < getNumReps(); ++i) {
415  fRepAtHit.at(i) = -1;
416  }
417  }
418 
421  void printBookkeeping(std::ostream& out = std::cout) const;
422 
423  void Print(std::ostream& out = std::cout) const;
424 
426  {
427  for (unsigned int i = 0; i < getNumReps(); ++i) {
428  fBookkeeping.at(i)->clearAll();
429  }
430  }
431 
433  {
434  for (unsigned int i = 0; i < getNumReps(); ++i) {
435  fBookkeeping.at(i)->clearFailedHits();
436  }
437  }
438 
441  void getHitsByPlane(std::vector<std::vector<int>*>& retVal);
442 
443  private:
444  virtual void Print(Option_t*) const
445  {
446  throw std::logic_error(std::string(__func__) + "::Print(Option_t*) not available");
447  }
448 
449  //public:
450  //ClassDef(GFTrack,1)
451  };
452 } // namespace genf
453 
454 #endif
455 
TRandom r
Definition: spectrum.C:23
void clearRepAtHit()
clear the hit indices at which plane,state&cov of reps are defined
Definition: GFTrack.h:412
unsigned int getNDF() const
std::vector< Double_t > fHitChi2
Definition: GFTrack.h:102
std::vector< TVector3 > getHitPlaneUxUyUz()
Definition: GFTrack.h:373
void printBookkeeping(std::ostream &out=std::cout) const
print bookkeeping
Definition: GFTrack.cxx:197
GFTrack & operator=(const GFTrack &)
assignement operator
Definition: GFTrack.cxx:74
std::vector< TVector3 > fHitPlaneXYZ
Definition: GFTrack.h:105
std::vector< TMatrixT< Double_t > > fHitCov
Definition: GFTrack.h:104
void setNextHitToFit(unsigned int i)
Set next hit to be used in a fit.
Definition: GFTrack.h:189
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:392
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:34
TVector3 getPos(const GFDetPlane &pl) const
Get position at GFDetPlane.
Definition: GFTrack.h:237
std::vector< GFBookkeeping * > fBookkeeping
Collection of Bookeeping objects for failed hits in every trackrep.
Definition: GFTrack.h:86
virtual TVector3 getPos(const GFDetPlane &pl)=0
std::vector< Double_t > getHitChi2()
Definition: GFTrack.h:368
std::vector< TMatrixT< Double_t > > fHitCov7x7
Definition: GFTrack.h:103
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:193
std::vector< TMatrixT< Double_t > > getHitCov7x7()
Definition: GFTrack.h:371
std::vector< TMatrixT< Double_t > > getHitState()
Definition: GFTrack.h:369
std::vector< TVector3 > getHitPlaneU()
Definition: GFTrack.h:374
std::vector< TMatrixT< Double_t > > fHitMeasCov
Definition: GFTrack.h:99
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
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:81
std::vector< TMatrixT< Double_t > > fHitUpdate
Definition: GFTrack.h:100
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void fillGeoTrack(TVirtualGeoTrack *tr) const
Fill TVirtualGeoTrack object Cardinal representation is used.
Definition: GFTrack.h:284
void setCardinalRep(unsigned int r)
Choose cardinal track represenatation.
Definition: GFTrack.h:350
void setHitState(TMatrixT< Double_t > mat)
Definition: GFTrack.h:358
TVector3 getPos() const
Get present position.
Definition: GFTrack.h:230
std::vector< TVector3 > fHitPlaneU
Definition: GFTrack.h:107
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:208
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
virtual TVector3 getMom(const GFDetPlane &pl)=0
unsigned int getNumReps() const
Get number of track represenatations.
Definition: GFTrack.h:200
void setHitMeasuredCov(TMatrixT< Double_t > mat)
Definition: GFTrack.h:355
void addFailedHit(unsigned int irep, unsigned int id)
Definition: GFTrack.h:294
GFTrack()
Default constructor – needed for compatibility with ROOT.
Definition: GFTrack.cxx:31
virtual ~GFTrack()
Definition: GFTrack.cxx:36
void setPDG(int pdgt)
Definition: GFTrack.h:365
GFAbsRecoHit * getHit(int id) const
Definition: GFTrack.h:161
int getRepAtHit(unsigned int irep)
get the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:402
void setHitPlaneV(TVector3 pl)
Definition: GFTrack.h:364
void releaseHits()
Clear hit vector. Note that hits will not be deleted!
Definition: GFTrack.h:181
int getFailedHits(int repId=-1)
return the number of failed Hits in track fit repId == -1 will use cardinal rep
Definition: GFTrack.h:147
unsigned int fCardinal_rep
Definition: GFTrack.h:113
void setHitPlaneUxUyUz(TVector3 pl)
Definition: GFTrack.h:362
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:262
void setHitChi2(Double_t mat)
Definition: GFTrack.h:357
double getRedChiSqu() const
Get chi2/NDF.
Definition: GFTrack.h:274
Float_t mat
Definition: plot.C:38
void Print(std::ostream &out=std::cout) const
Definition: GFTrack.cxx:206
std::vector< GFAbsRecoHit * > getHits()
Definition: GFTrack.h:157
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:166
GFBookkeeping * getBK(int index=-1)
get GFBookKeeping object for particular track rep (default is cardinal rep)
Definition: GFTrack.h:334
std::vector< TVector3 > getHitPlaneV()
Definition: GFTrack.h:375
void setHitCov7x7(TMatrixT< Double_t > mat)
Definition: GFTrack.h:360
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &cov)
Get position, momentum, and 6x6 covariance at current position.
Definition: GFTrack.h:243
void mergeHits(GFTrack *trk)
Merge two GFTracks. Only hits will be merged.
Definition: GFTrack.cxx:127
unsigned int getNumHits() const
Definition: GFTrack.h:163
void addHitVector(std::vector< GFAbsRecoHit * > hits)
Add collection of hits.
Definition: GFTrack.h:319
void clearFailedHits()
Definition: GFTrack.h:432
unsigned int getNDF() const
Get NDF.
Definition: GFTrack.h:268
void setHitCov(TMatrixT< Double_t > mat)
Definition: GFTrack.h:359
void reset()
Resets the GFTrack – deletes RecoHits!
Definition: GFTrack.cxx:112
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:47
TVector3 getMom(const GFDetPlane &pl) const
Get momentum at GFDetPlane.
Definition: GFTrack.h:224
void setHitUpdate(TMatrixT< Double_t > mat)
Definition: GFTrack.h:356
virtual void Print(Option_t *) const
Definition: GFTrack.h:444
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:75
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
Definition: GFTrackCand.cxx:74
std::vector< TVector3 > fHitPlaneV
Definition: GFTrack.h:108
void getHitsByPlane(std::vector< std::vector< int > * > &retVal)
Definition: GFTrack.cxx:215
std::vector< TMatrixT< Double_t > > getHitUpdate()
Definition: GFTrack.h:367
const GFTrackCand & getCand() const
Definition: GFTrack.h:159
double getChiSqu() const
void addHit(GFAbsRecoHit *theHit)
deprecated!
Definition: GFTrack.h:301
double getCharge() const
Get charge from fit.
Definition: GFTrack.h:280
void setHitPlaneXYZ(TVector3 pl)
Definition: GFTrack.h:361
std::vector< TMatrixT< Double_t > > getHitCov()
Definition: GFTrack.h:370
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:377
std::vector< TMatrixT< Double_t > > getHitMeasuredCov()
Definition: GFTrack.h:366
std::vector< TMatrixT< Double_t > > fHitState
Definition: GFTrack.h:101
unsigned int getNextHitToFit() const
Accessor for fNextHitToFit.
Definition: GFTrack.h:185
std::vector< TVector3 > fHitPlaneUxUyUz
Definition: GFTrack.h:106
static const int fDefNumTrackReps
Definition: GFTrack.h:112
void addTrackRep(GFAbsTrackRep *theTrackRep)
Add track represenation.
Definition: GFTrack.h:325
void setHitPlaneU(TVector3 pl)
Definition: GFTrack.h:363
double getRedChiSqu() const
returns chi2/ndf
void clearBookkeeping()
Definition: GFTrack.h:425
void setCandidate(const GFTrackCand &cand, bool doreset=false)
set track candidate
Definition: GFTrack.cxx:140
std::vector< TVector3 > getHitPlaneXYZ()
Definition: GFTrack.h:372
TVector3 getMom() const
Get momentum at the present position.
Definition: GFTrack.h:217