PandaRoot
GFTrack.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /* Copyright 2008-2010, Technische Universitaet Muenchen,
14  Authors: Christian Hoeppner & Sebastian Neubert
15 
16  This file is part of GENFIT.
17 
18  GENFIT is free software: you can redistribute it and/or modify
19  it under the terms of the GNU Lesser General Public License as published
20  by the Free Software Foundation, either version 3 of the License, or
21  (at your option) any later version.
22 
23  GENFIT is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU Lesser General Public License for more details.
27 
28  You should have received a copy of the GNU Lesser General Public License
29  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
30 */
35 #ifndef GFTRACK_H
36 #define GFTRACK_H
37 
38 #include "assert.h"
39 #include <map>
40 
41 #include "GFAbsTrackRep.h"
42 #include "GFAbsRecoHit.h"
43 
44 #include "TClonesArray.h"
45 #include "TObjArray.h"
46 
47 #include "GFTrackCand.h"
48 #include "GFBookkeeping.h"
49 
50 class TVirtualGeoTrack;
51 
71 class GFTrack : public TObject {
72  private:
82  TObjArray *fTrackReps; //->
83 
86  std::vector<GFAbsRecoHit *> fHits;
88 
92  std::vector<GFBookkeeping *> fBookkeeping;
93 
97  std::vector<int> fRepAtHit;
98 
102  GFTrackCand fCand; // list of hits
103 
104  static const int fDefNumTrackReps = 10;
105  unsigned int fCardinal_rep; // THE selected rep, default=0;
106 
107  unsigned int fNextHitToFit;
108 
109  bool fSmooth;
110 
111  public:
113  GFTrack();
114 
116  GFTrack(const GFTrack &);
117 
119  GFTrack &operator=(const GFTrack &);
120 
126  GFTrack(GFAbsTrackRep *, bool smooth = false);
127 
128  virtual ~GFTrack();
129 
130  // -----------------------
131  // Accessors
132  // -----------------------
133 
136  void reset(); // deletes the RecoHits!
137 
141  int getFailedHits(int repId = -1)
142  {
143  int theRep;
144  if (repId == -1)
145  theRep = fCardinal_rep;
146  else
147  theRep = repId;
148  return fBookkeeping.at(theRep)->getNumFailed();
149  }
150 
151  std::vector<GFAbsRecoHit *> getHits() { return fHits; }
152 
153  const GFTrackCand &getCand() const { return fCand; }
154 
155  GFAbsRecoHit *getHit(int id) const { return fHits.at(id); }
156 
157  unsigned int getNumHits() const { return fHits.size(); }
158 
169  void mergeHits(GFTrack *trk);
170 
175  void releaseHits() { fHits.clear(); }
176 
182  {
183  fTrackReps->SetOwner(kFALSE);
184  fTrackReps->Clear();
185  }
186 
189  unsigned int getNextHitToFit() const { return fNextHitToFit; }
190 
193  void setNextHitToFit(unsigned int i) { fNextHitToFit = i; }
194 
197  GFAbsTrackRep *getTrackRep(int id) const { return reinterpret_cast<GFAbsTrackRep *>(fTrackReps->At(id)); }
198 
201  unsigned int getNumReps() const { return fTrackReps->GetEntriesFast(); }
202 
209  GFAbsTrackRep *getCardinalRep() const { return ((GFAbsTrackRep *)fTrackReps->At(fCardinal_rep)); }
210 
215  TVector3 getMom() const { return getCardinalRep()->getMom(); }
216 
222  TVector3 getMom(const GFDetPlane &pl) const { return getCardinalRep()->getMom(pl); }
223 
228  TVector3 getPos() const { return getCardinalRep()->getPos(); }
229 
235  TVector3 getPos(const GFDetPlane &pl) const { return getCardinalRep()->getPos(pl); }
236 
241  void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT<double> &cov) { getCardinalRep()->getPosMomCov(pos, mom, cov); }
242 
248  void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT<double> &cov) { getCardinalRep()->getPosMomCov(pl, pos, mom, cov); }
249 
254  double getChiSqu() const { return getCardinalRep()->getChiSqu(); }
255 
260  unsigned int getNDF() const { return getCardinalRep()->getNDF(); }
261 
266  double getRedChiSqu() const { return getCardinalRep()->getRedChiSqu(); }
267 
272  double getCharge() const { return getCardinalRep()->getCharge(); }
273 
276  void fillGeoTrack(TVirtualGeoTrack *tr) const { fillGeoTrack(tr, fCardinal_rep); }
277 
280  void fillGeoTrack(TVirtualGeoTrack *tr, unsigned int repid) const;
281 
282  // ---------------------
283  // Modifiers
284  // ---------------------
285 
286  void addFailedHit(unsigned int irep, unsigned int id)
287  {
288  assert(irep < fBookkeeping.size());
289  fBookkeeping.at(irep)->addFailedHit(id);
290  }
291 
294  inline void addHit(GFAbsRecoHit *theHit) { fHits.push_back(theHit); }
295 
298  void addHit(GFAbsRecoHit *theHit, unsigned int detId, unsigned int hitId, double rho = 0., unsigned int planeId = 0)
299  {
300  fHits.push_back(theHit);
301  fCand.addHit(detId, hitId, rho, planeId);
302  }
303 
308  void addHitVector(std::vector<GFAbsRecoHit *> hits) { fHits = hits; }
309 
314  void addTrackRep(GFAbsTrackRep *theTrackRep)
315  {
316  if (fTrackReps == nullptr)
317  fTrackReps = new TObjArray(fDefNumTrackReps);
318  fTrackReps->Add(theTrackRep);
319  fBookkeeping.push_back(new GFBookkeeping());
320  fRepAtHit.push_back(-1);
321  }
322 
324  GFBookkeeping *getBK(int index = -1)
325  {
326  if (index == -1)
327  return fBookkeeping.at(fCardinal_rep);
328  assert((unsigned int)index < getNumReps());
329  return fBookkeeping.at(index);
330  }
331 
333  void setCandidate(const GFTrackCand &cand, bool doreset = false);
334 
339  void setCardinalRep(unsigned int r)
340  {
341  if ((int)r < fTrackReps->GetEntriesFast())
342  fCardinal_rep = r;
343  }
344 
352  void getResiduals(unsigned int detId, // which detector?
353  unsigned int dim, // which projection?
354  unsigned int rep, // which trackrep ?
355  std::vector<double> &result);
356 
359  void setRepAtHit(unsigned int irep, int ihit)
360  {
361  assert(irep < getNumReps());
362  fRepAtHit.at(irep) = ihit;
363  }
364 
367  int getRepAtHit(unsigned int irep)
368  {
369  assert(irep < getNumReps());
370  return fRepAtHit.at(irep);
371  }
372 
376  {
377  for (unsigned int i = 0; i < getNumReps(); ++i) {
378  fRepAtHit.at(i) = -1;
379  }
380  }
381 
384  void printBookkeeping();
385 
386  void Print();
387 
389  {
390  for (unsigned int i = 0; i < getNumReps(); ++i) {
391  fBookkeeping.at(i)->clearAll();
392  }
393  }
394 
396  {
397  for (unsigned int i = 0; i < getNumReps(); ++i) {
398  fBookkeeping.at(i)->clearFailedHits();
399  }
400  }
401 
404  void getHitsByPlane(std::vector<std::vector<int> *> &retVal);
405 
408  void setSmoothing(bool smooth = true) { fSmooth = smooth; }
409 
412  bool getSmoothing() { return fSmooth; }
413 
417  void blowUpCovs(double blowUpFactor);
418 
419  public:
420  ClassDef(GFTrack, 1)
421 };
422 
423 #endif
424 
TVector3 getPos(const GFDetPlane &pl) const
Get position at GFDetPlane.
Definition: GFTrack.h:235
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:92
GFBookkeeping * getBK(int index=-1)
get GFBookKeeping object for particular track rep (default is cardinal rep)
Definition: GFTrack.h:324
void addFailedHit(unsigned int irep, unsigned int id)
Definition: GFTrack.h:286
unsigned int getNumHits() const
Definition: GFTrack.h:157
GFTrack()
Default constructor – needed for compatibility with ROOT.
TVector3 getPos() const
Get present position.
Definition: GFTrack.h:228
void Print()
void addHit(GFAbsRecoHit *theHit)
deprecated!
Definition: GFTrack.h:294
Detector plane genfit geometry class.
Definition: GFDetPlane.h:70
Track object for genfit. genfit algorithms work on these objects.
Definition: GFTrack.h:71
bool getSmoothing()
Read back if smoothing is/was turned on or off for this track.
Definition: GFTrack.h:412
unsigned int getNextHitToFit() const
Accessor for fNextHitToFit.
Definition: GFTrack.h:189
void clearBookkeeping()
Definition: GFTrack.h:388
void setSmoothing(bool smooth=true)
Switch smoothing on or off for this track.
Definition: GFTrack.h:408
TVector3 getMom() const
Get momentum at the present position.
Definition: GFTrack.h:215
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:33
void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
Get position, momentum, and 6x6 covariance at GFDetPlane.
Definition: GFTrack.h:248
double getChiSqu() const
Get chi2.
Definition: GFTrack.h:254
GFAbsTrackRep * getCardinalRep() const
Get cardinal track representation.
Definition: GFTrack.h:209
virtual TVector3 getMom(const GFDetPlane &pl)=0
void addHitVector(std::vector< GFAbsRecoHit *> hits)
Add collection of hits.
Definition: GFTrack.h:308
unsigned int getNDF() const
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:197
virtual TVector3 getPos(const GFDetPlane &pl)=0
TVector3 getMom(const GFDetPlane &pl) const
Get momentum at GFDetPlane.
Definition: GFTrack.h:222
void fillGeoTrack(TVirtualGeoTrack *tr) const
Fill TVirtualGeoTrack object Cardinal representation is used.
Definition: GFTrack.h:276
void clearFailedHits()
Definition: GFTrack.h:395
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:359
void releaseHits()
Clear hit vector. Note that hits will not be deleted!
Definition: GFTrack.h:175
void clearRepAtHit()
clear the hit indices at which plane,state&cov of reps are defined
Definition: GFTrack.h:375
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT< double > &cov)
Get position, momentum, and 6x6 covariance at current position.
Definition: GFTrack.h:241
unsigned int getNDF() const
Get NDF.
Definition: GFTrack.h:260
double getRedChiSqu() const
Get chi2/NDF.
Definition: GFTrack.h:266
std::vector< GFAbsRecoHit * > getHits()
Definition: GFTrack.h:151
const GFTrackCand & getCand() const
Definition: GFTrack.h:153
void reset()
Resets the GFTrack – deletes RecoHits!
Track candidate – a list of cluster indices.
Definition: GFTrackCand.h:67
virtual ~GFTrack()
int getRepAtHit(unsigned int irep)
get the hit index at which plane,state&cov of rep irep is defined
Definition: GFTrack.h:367
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:298
GFAbsRecoHit * getHit(int id) const
Definition: GFTrack.h:155
unsigned int getNumReps() const
Get number of track represenatations.
Definition: GFTrack.h:201
Base Class for representing a Hit in GENFIT.
Definition: GFAbsRecoHit.h:83
int getFailedHits(int repId=-1)
return the number of failed Hits in track fit repId == -1 will use cardinal rep
Definition: GFTrack.h:141
double getRedChiSqu() const
returns chi2/ndf
void releaseTrackReps()
Clear TrackRep vector. Note that the Reps will not be deleted!
Definition: GFTrack.h:181
double getChiSqu() const
double getCharge() const
Get charge from fit.
Definition: GFTrack.h:272
void addTrackRep(GFAbsTrackRep *theTrackRep)
Add track represenation.
Definition: GFTrack.h:314
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:339
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:193
virtual double getCharge() const =0