PandaRoot
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 "assert.h"
27 #include <map>
28 
29 #include "GFAbsTrackRep.h"
30 #include "GFAbsRecoHit.h"
31 
32 #include "TClonesArray.h"
33 #include "TObjArray.h"
34 
35 #include "GFTrackCand.h"
36 #include "GFBookkeeping.h"
37 
38 class TVirtualGeoTrack;
39 
59 class GFTrack : public TObject {
60  private:
70  TObjArray *fTrackReps; //->
71 
74  std::vector<GFAbsRecoHit *> fHits;
76 
80  std::vector<GFBookkeeping *> fBookkeeping;
81 
85  std::vector<int> fRepAtHit;
86 
90  GFTrackCand fCand; // list of hits
91 
92  static const int fDefNumTrackReps = 10;
93  unsigned int fCardinal_rep; // THE selected rep, default=0;
94 
95  unsigned int fNextHitToFit;
96 
97  bool fSmooth;
98 
99  public:
101  GFTrack();
102 
104  GFTrack(const GFTrack &);
105 
107  GFTrack &operator=(const GFTrack &);
108 
114  GFTrack(GFAbsTrackRep *, bool smooth = false);
115 
116  virtual ~GFTrack();
117 
118  // -----------------------
119  // Accessors
120  // -----------------------
121 
124  void reset(); // deletes the RecoHits!
125 
129  int getFailedHits(int repId = -1)
130  {
131  int theRep;
132  if (repId == -1)
133  theRep = fCardinal_rep;
134  else
135  theRep = repId;
136  return fBookkeeping.at(theRep)->getNumFailed();
137  }
138 
139  std::vector<GFAbsRecoHit *> getHits() { return fHits; }
140 
141  const GFTrackCand &getCand() const { return fCand; }
142 
143  GFAbsRecoHit *getHit(int id) const { return fHits.at(id); }
144 
145  unsigned int getNumHits() const { return fHits.size(); }
146 
157  void mergeHits(GFTrack *trk);
158 
163  void releaseHits() { fHits.clear(); }
164 
170  {
171  fTrackReps->SetOwner(kFALSE);
172  fTrackReps->Clear();
173  }
174 
177  unsigned int getNextHitToFit() const { return fNextHitToFit; }
178 
181  void setNextHitToFit(unsigned int i) { fNextHitToFit = i; }
182 
185  GFAbsTrackRep *getTrackRep(int id) const { return reinterpret_cast<GFAbsTrackRep *>(fTrackReps->At(id)); }
186 
189  unsigned int getNumReps() const { return fTrackReps->GetEntriesFast(); }
190 
197  GFAbsTrackRep *getCardinalRep() const { return ((GFAbsTrackRep *)fTrackReps->At(fCardinal_rep)); }
198 
203  TVector3 getMom() const { return getCardinalRep()->getMom(); }
204 
210  TVector3 getMom(const GFDetPlane &pl) const { return getCardinalRep()->getMom(pl); }
211 
216  TVector3 getPos() const { return getCardinalRep()->getPos(); }
217 
223  TVector3 getPos(const GFDetPlane &pl) const { return getCardinalRep()->getPos(pl); }
224 
229  void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT<double> &cov) { getCardinalRep()->getPosMomCov(pos, mom, cov); }
230 
236  void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT<double> &cov) { getCardinalRep()->getPosMomCov(pl, pos, mom, cov); }
237 
242  double getChiSqu() const { return getCardinalRep()->getChiSqu(); }
243 
248  unsigned int getNDF() const { return getCardinalRep()->getNDF(); }
249 
254  double getRedChiSqu() const { return getCardinalRep()->getRedChiSqu(); }
255 
260  double getCharge() const { return getCardinalRep()->getCharge(); }
261 
264  void fillGeoTrack(TVirtualGeoTrack *tr) const { fillGeoTrack(tr, fCardinal_rep); }
265 
268  void fillGeoTrack(TVirtualGeoTrack *tr, unsigned int repid) const;
269 
270  // ---------------------
271  // Modifiers
272  // ---------------------
273 
274  void addFailedHit(unsigned int irep, unsigned int id)
275  {
276  assert(irep < fBookkeeping.size());
277  fBookkeeping.at(irep)->addFailedHit(id);
278  }
279 
282  inline void addHit(GFAbsRecoHit *theHit) { fHits.push_back(theHit); }
283 
286  void addHit(GFAbsRecoHit *theHit, unsigned int detId, unsigned int hitId, double rho = 0., unsigned int planeId = 0)
287  {
288  fHits.push_back(theHit);
289  fCand.addHit(detId, hitId, rho, planeId);
290  }
291 
296  void addHitVector(std::vector<GFAbsRecoHit *> hits) { fHits = hits; }
297 
302  void addTrackRep(GFAbsTrackRep *theTrackRep)
303  {
304  if (fTrackReps == nullptr)
305  fTrackReps = new TObjArray(fDefNumTrackReps);
306  fTrackReps->Add(theTrackRep);
307  fBookkeeping.push_back(new GFBookkeeping());
308  fRepAtHit.push_back(-1);
309  }
310 
312  GFBookkeeping *getBK(int index = -1)
313  {
314  if (index == -1)
315  return fBookkeeping.at(fCardinal_rep);
316  assert((unsigned int)index < getNumReps());
317  return fBookkeeping.at(index);
318  }
319 
321  void setCandidate(const GFTrackCand &cand, bool doreset = false);
322 
327  void setCardinalRep(unsigned int r)
328  {
329  if ((int)r < fTrackReps->GetEntriesFast())
330  fCardinal_rep = r;
331  }
332 
340  void getResiduals(unsigned int detId, // which detector?
341  unsigned int dim, // which projection?
342  unsigned int rep, // which trackrep ?
343  std::vector<double> &result);
344 
347  void setRepAtHit(unsigned int irep, int ihit)
348  {
349  assert(irep < getNumReps());
350  fRepAtHit.at(irep) = ihit;
351  }
352 
355  int getRepAtHit(unsigned int irep)
356  {
357  assert(irep < getNumReps());
358  return fRepAtHit.at(irep);
359  }
360 
364  {
365  for (unsigned int i = 0; i < getNumReps(); ++i) {
366  fRepAtHit.at(i) = -1;
367  }
368  }
369 
372  void printBookkeeping();
373 
374  void Print();
375 
377  {
378  for (unsigned int i = 0; i < getNumReps(); ++i) {
379  fBookkeeping.at(i)->clearAll();
380  }
381  }
382 
384  {
385  for (unsigned int i = 0; i < getNumReps(); ++i) {
386  fBookkeeping.at(i)->clearFailedHits();
387  }
388  }
389 
392  void getHitsByPlane(std::vector<std::vector<int> *> &retVal);
393 
396  void setSmoothing(bool smooth = true) { fSmooth = smooth; }
397 
400  bool getSmoothing() { return fSmooth; }
401 
405  void blowUpCovs(double blowUpFactor);
406 
407  public:
408  ClassDef(GFTrack, 1)
409 };
410 
411 #endif
412 
TVector3 getPos(const GFDetPlane &pl) const
Get position at GFDetPlane.
Definition: GFTrack.h:223
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:80
GFBookkeeping * getBK(int index=-1)
get GFBookKeeping object for particular track rep (default is cardinal rep)
Definition: GFTrack.h:312
void addFailedHit(unsigned int irep, unsigned int id)
Definition: GFTrack.h:274
unsigned int getNumHits() const
Definition: GFTrack.h:145
GFTrack()
Default constructor – needed for compatibility with ROOT.
TVector3 getPos() const
Get present position.
Definition: GFTrack.h:216
void Print()
void addHit(GFAbsRecoHit *theHit)
deprecated!
Definition: GFTrack.h:282
Detector plane genfit geometry class.
Definition: GFDetPlane.h:58
Track object for genfit. genfit algorithms work on these objects.
Definition: GFTrack.h:59
bool getSmoothing()
Read back if smoothing is/was turned on or off for this track.
Definition: GFTrack.h:400
unsigned int getNextHitToFit() const
Accessor for fNextHitToFit.
Definition: GFTrack.h:177
void clearBookkeeping()
Definition: GFTrack.h:376
void setSmoothing(bool smooth=true)
Switch smoothing on or off for this track.
Definition: GFTrack.h:396
TVector3 getMom() const
Get momentum at the present position.
Definition: GFTrack.h:203
void getResiduals(unsigned int detId, unsigned int dim, unsigned int rep, std::vector< double > &result)
Get residuals.
void setCandidate(const GFTrackCand &cand, bool doreset=false)
set track candidate
virtual void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
method which gets position, momentum and 6x6 covariance matrix
unsigned int i
Definition: P4_F32vec4.h:21
void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
Get position, momentum, and 6x6 covariance at GFDetPlane.
Definition: GFTrack.h:236
double getChiSqu() const
Get chi2.
Definition: GFTrack.h:242
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:197
virtual TVector3 getMom(const GFDetPlane &pl)=0
void addHitVector(std::vector< GFAbsRecoHit *> hits)
Add collection of hits.
Definition: GFTrack.h:296
unsigned int getNDF() const
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:185
virtual TVector3 getPos(const GFDetPlane &pl)=0
TVector3 getMom(const GFDetPlane &pl) const
Get momentum at GFDetPlane.
Definition: GFTrack.h:210
void fillGeoTrack(TVirtualGeoTrack *tr) const
Fill TVirtualGeoTrack object Cardinal representation is used.
Definition: GFTrack.h:264
void clearFailedHits()
Definition: GFTrack.h:383
void blowUpCovs(double blowUpFactor)
this is needed to blow up the covariance matrix before a fitting pass drops off-diagonal elements and...
void setRepAtHit(unsigned int irep, int ihit)
set the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:347
void releaseHits()
Clear hit vector. Note that hits will not be deleted!
Definition: GFTrack.h:163
void clearRepAtHit()
clear the hit indices at which plane,state&cov of reps are defined
Definition: GFTrack.h:363
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
Get position, momentum, and 6x6 covariance at current position.
Definition: GFTrack.h:229
unsigned int getNDF() const
Get NDF.
Definition: GFTrack.h:248
double getRedChiSqu() const
Get chi2/NDF.
Definition: GFTrack.h:254
std::vector< GFAbsRecoHit * > getHits()
Definition: GFTrack.h:139
const GFTrackCand & getCand() const
Definition: GFTrack.h:141
void reset()
Resets the GFTrack – deletes RecoHits!
Track candidate – a list of cluster indices.
Definition: GFTrackCand.h:55
virtual ~GFTrack()
int getRepAtHit(unsigned int irep)
get the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:355
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:286
GFAbsRecoHit * getHit(int id) const
Definition: GFTrack.h:143
unsigned int getNumReps() const
Get number of track represenatations.
Definition: GFTrack.h:189
Base Class for representing a Hit in GENFIT.
Definition: GFAbsRecoHit.h:71
int getFailedHits(int repId=-1)
return the number of failed Hits in track fit repId == -1 will use cardinal rep
Definition: GFTrack.h:129
double getRedChiSqu() const
returns chi2/ndf
void releaseTrackReps()
Clear TrackRep vector. Note that the Reps will not be deleted!
Definition: GFTrack.h:169
double getChiSqu() const
double getCharge() const
Get charge from fit.
Definition: GFTrack.h:260
void addTrackRep(GFAbsTrackRep *theTrackRep)
Add track represenation.
Definition: GFTrack.h:302
void addHit(unsigned int detId, unsigned int hitId, double rho=0., unsigned int planeId=0)
void setCardinalRep(unsigned int r)
Choose cardinal track represenatation.
Definition: GFTrack.h:327
void mergeHits(GFTrack *trk)
Merge two GFTracks. Only hits will be merged.
GFTrack & operator=(const GFTrack &)
assignement operator
void getHitsByPlane(std::vector< std::vector< int > *> &retVal)
void printBookkeeping()
print bookkeeping
void setNextHitToFit(unsigned int i)
Set next hit to be used in a fit.
Definition: GFTrack.h:181
virtual double getCharge() const =0