FairRoot/PandaRoot
GFTrack.cxx
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 */
19 #include <assert.h>
20 #include <iostream>
21 
22 #include "GFTrack.h"
23 #include "TVirtualGeoTrack.h"
24 
25 GFTrack::GFTrack(GFAbsTrackRep* defaultRep, bool smooth)
26  : fTrackReps(NULL),fCardinal_rep(0), fNextHitToFit(0), fSmooth(false)
27 {
28  addTrackRep(defaultRep);
29  fSmooth = smooth;
30 }
31 
33  : fTrackReps(NULL), fCardinal_rep(0), fNextHitToFit(0), fSmooth(false)
34 {
35  //trackReps = new TObjArray(defNumTrackReps);
36 }
37 
39  if(fTrackReps!=NULL){
40  for(unsigned int i=0;i<getNumReps();i++) {
41  delete fTrackReps->At(i);
42  }
43  delete fTrackReps;
44  }
45  for(unsigned int i=0;i<fHits.size();i++) {
46  if(fHits.at(i)!=NULL) delete fHits.at(i);
47  }
48  for(unsigned int i=0;i<fBookkeeping.size();++i){
49  if(fBookkeeping.at(i)!=NULL) delete fBookkeeping.at(i);
50  }
51 }
52 
53 GFTrack::GFTrack(const GFTrack& _tr) :TObject(_tr) {
54  fCand=_tr.fCand;
57  fSmooth=_tr.fSmooth;
58  for(unsigned int i=0;i<_tr.getNumHits();i++) {
59  fHits.push_back((_tr.getHit(i))->clone());
60  }
61  fTrackReps = NULL;
62  for(unsigned int i=0; i<_tr.getNumReps();i++) {
63  addTrackRep( (_tr.getTrackRep(i))->clone() );
64  }
65  for(unsigned int i=0; i<fBookkeeping.size(); ++i) delete fBookkeeping[i];
66  fBookkeeping.clear();
67 
68  for(unsigned int i=0;i<_tr.fBookkeeping.size();++i){
69  assert(_tr.fBookkeeping.at(i)!= NULL) ;
70  fBookkeeping.push_back(new GFBookkeeping(*(_tr.fBookkeeping.at(i))));
71  }
72  fRepAtHit = _tr.fRepAtHit;
73 }
74 
76  if(fTrackReps!=NULL){
77  for(unsigned int i=0;i<getNumReps();i++) {
78  delete fTrackReps->At(i);
79  }
80  delete fTrackReps;
81  fTrackReps=NULL;
82  }
83  for(unsigned int i=0;i<fHits.size();i++) {
84  delete fHits[i];
85  }
86  for(unsigned int i=0;i<fBookkeeping.size();++i){
87  if(fBookkeeping.at(i)!=NULL) delete fBookkeeping.at(i);
88  }
89 
90  for(unsigned int i=0;i<_tr.getNumReps();++i){
91  addTrackRep(_tr.getTrackRep(i)->clone());
92  }
93  fCand=_tr.fCand;
96  fSmooth=_tr.fSmooth;
97  for(unsigned int i=0;i<_tr.getNumHits();i++) {
98  fHits.push_back((_tr.getHit(i))->clone());
99  }
100 
101  //clear the empty bookeeping objs made by addTrackRep and copy the others
102  for(unsigned int i=0; i<fBookkeeping.size(); ++i) delete fBookkeeping[i];
103  fBookkeeping.clear();
104  for(unsigned int i=0;i<_tr.fBookkeeping.size();++i){
105  assert(_tr.fBookkeeping.at(i)!= NULL) ;
106  fBookkeeping.push_back(new GFBookkeeping(*(_tr.fBookkeeping.at(i))));
107  }
108  fRepAtHit = _tr.fRepAtHit;
109 
110 
111  return *this;
112 }
113 
114 
115 void
117  if(fTrackReps!=NULL){
118  for(unsigned int i=0;i<getNumReps();i++) {
119  if(fTrackReps->At(i)!=NULL) delete fTrackReps->At(i);
120  }
121  }
122  for(unsigned int i=0;i<fBookkeeping.size();++i){
123  if(fBookkeeping.at(i)!=NULL) delete fBookkeeping.at(i);
124  }
125  for(unsigned int i=0;i<fHits.size();i++) {
126  if(fHits.at(i)!=NULL) delete fHits.at(i);
127  }
128  fHits.clear();
129  fRepAtHit.clear();
130  fBookkeeping.clear();
131 }
132 
133 void
135  unsigned int nhits=trk->getNumHits();
136  for(unsigned int i=0;i<nhits;++i){
137  unsigned int detId;
138  unsigned int hitId;
139  trk->getCand().getHit(i,detId,hitId);
140  GFAbsRecoHit* hit=trk->getHit(i);
141  addHit(hit,detId,hitId);
142  }
143  trk->fHits.clear();
144 }
145 
146 
147 void
148 GFTrack::setCandidate(const GFTrackCand& cand, bool doreset)
149 {
150  fCand=cand;
151  // reset fits
152  if(doreset) {
153  for(unsigned int i=0;i<getNumReps();i++) {
154  ((GFAbsTrackRep*)fTrackReps->At(i))->reset();
155  }
156  }
157 }
158 
159 void
160 GFTrack::fillGeoTrack(TVirtualGeoTrack* geotrk,unsigned int repid) const
161 {
162  GFAbsTrackRep* rep=getTrackRep(repid);
163  unsigned int n=fCand.getNHits();
164  rep->getState().Print();
165  for(unsigned int i=0; i<n; ++i){// loop over hits
166  GFDetPlane pl=fHits[i]->getDetPlane(rep);
167  TVector3 pos=rep->getPos(pl);
168  std::cout<<pos.X()<<","<<pos.Y()<<","<<pos.Z()<<std::endl;
169  geotrk->AddPoint(pos.X(),pos.Y(),pos.Z(),0);
170  }// end loop over hits
171 }
172 
173 
174 void
175 GFTrack::getResiduals(unsigned int detId, // which detector?
176  unsigned int dim, // which projection?
177  unsigned int repid, // which trackrep ?
178  std::vector<double>& result)
179 {
180  unsigned int nhits=getNumHits();
181  if(repid>=getNumReps())return;
182  GFAbsTrackRep* rep=getTrackRep(repid);//->clone();
183  assert(rep->getState()==getTrackRep(repid)->getState());
184  for(unsigned int ih=0; ih<nhits; ++ih){// loop over hits
185  unsigned int anid;
186  unsigned int dummy;
187  fCand.getHit(ih,anid,dummy); // check if this is a hit we want to look at
188  if(anid==detId){
189  GFAbsRecoHit* hit=getHit(ih);
190  // extrapolate trackrep there
191  int repDim=rep->getDim();
192  TMatrixT<double> state(repDim,1);
193  GFDetPlane pl=hit->getDetPlane(rep);
194 
195  rep->extrapolate(pl,state);
196  //rep->setState(state);
197  //rep->setReferencePlane(pl);
198  double res=hit->residualVector(rep,state,pl)[dim][0];
199 
200  //std::cout<<res<<std::endl;
201 
202  result.push_back(res);
203  }
204  }
205 }
206 
207 
209  std::cout << "GFTrack::printBookkeeping()" << std::endl;
210  for(unsigned int i=0;i<getNumReps();++i){
211  std::cout << "trackRep " << i << ":" << std::endl;
212  fBookkeeping.at(i)->Print();
213  }
214 
215 }
216 
218  for(unsigned int i=0;i<getNumReps();++i){
219  getTrackRep(i)->Print();
220  fBookkeeping.at(i)->Print();
221  }
222  std::cout << "GFTrack has " << getNumHits() << " detector hits." << std::endl;
223 
224 }
225 
226 
227 void GFTrack::getHitsByPlane(std::vector<std::vector<int>*>& retVal){
228  for(int i=0;retVal.size();++i){
229  delete retVal.at(i);
230  }
231  retVal.clear();
232  //this method can only be called when all hits have been loaded
233  assert(fHits.size()==fCand.getNHits());
234  assert(fHits.size()>1);
235  unsigned int detId,hitId,planeId;
236  fCand.getHitWithPlane(0,detId,hitId,planeId);
237  // std::cout << "$$$ " << 0 << " " << detId << " " << hitId << " " << planeId << std::endl;
238  unsigned int lastPlane=planeId;
239  retVal.push_back(new std::vector<int>);
240  retVal.at(0)->push_back(0);
241  for(unsigned int i=1;i<fCand.getNHits();++i){
242  fCand.getHitWithPlane(i,detId,hitId,planeId);
243  //std::cout << "$$$ " << i << " " << detId << " " << hitId << " " << planeId << std::endl;
244  if(lastPlane==planeId){
245  retVal.at(retVal.size()-1)->push_back(i);
246  }
247  else{
248  lastPlane=planeId;
249  retVal.push_back(new std::vector<int>);
250  retVal.at(retVal.size()-1)->push_back(i);
251  }
252  }
253 }
254 
255 
256 void
257 GFTrack::blowUpCovs(double blowUpFactor){
258  int nreps=getNumReps();
259  for(int irep=0; irep<nreps; ++irep){
260  GFAbsTrackRep* arep=getTrackRep(irep);
261 
262  //dont do it for already compromsied reps, since they wont be fitted anyway
263  if(arep->getStatusFlag()==0) {
264  TMatrixT<double> cov = arep->getCov();
265  for(int i=0;i<cov.GetNrows();++i){
266  for(int j=0;j<cov.GetNcols();++j){
267  //if(i!=j){//off diagonal
268  // cov[i][j]=0.;
269  //}
270  //else{//diagonal
271  cov[i][j] = cov[i][j] * blowUpFactor;
272  //}
273  }
274  }
275  arep->setCov(cov);
276  }
277  }
278 }
279 
280 
282 
283 
284 
TVector3 pos
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:80
unsigned int getNumHits() const
Definition: GFTrack.h:148
virtual TMatrixT< double > residualVector(const GFAbsTrackRep *stateVector, const TMatrixT< double > &state, const GFDetPlane &d)
Calculate residual with respect to a track representation.
Definition: GFAbsRecoHit.h:142
TMatrixT< double > getState() const
GFTrack()
Default constructor – needed for compatibility with ROOT.
Definition: GFTrack.cxx:32
void Print()
Definition: GFTrack.cxx:217
Int_t res
Definition: anadigi.C:166
bool fSmooth
Definition: GFTrack.h:100
Int_t i
Definition: run_full.C:25
void addHit(GFAbsRecoHit *theHit)
deprecated!
Definition: GFTrack.h:291
Detector plane genfit geometry class.
Definition: GFDetPlane.h:59
Track object for genfit. genfit algorithms work on these objects.
Definition: GFTrack.h:60
void getHitsByPlane(std::vector< std::vector< int > * > &retVal)
Definition: GFTrack.cxx:227
virtual const GFDetPlane & getDetPlane(GFAbsTrackRep *)=0
Get detector plane for a given track representation.
labels push_back("electron")
unsigned int getNHits() const
Definition: GFTrackCand.h:113
int n
void getResiduals(unsigned int detId, unsigned int dim, unsigned int rep, std::vector< double > &result)
Get residuals.
Definition: GFTrack.cxx:175
void setCandidate(const GFTrackCand &cand, bool doreset=false)
set track candidate
Definition: GFTrack.cxx:148
unsigned int fNextHitToFit
Definition: GFTrack.h:98
std::vector< GFAbsRecoHit * > fHits
Collection of RecoHits.
Definition: GFTrack.h:77
TObjArray * fTrackReps
Collection of track representations.
Definition: GFTrack.h:73
GFTrack & operator=(const GFTrack &)
assignement operator
Definition: GFTrack.cxx:75
unsigned int getNumReps() const
Get number of track represenatations.
Definition: GFTrack.h:192
void getHitWithPlane(unsigned int i, unsigned int &detId, unsigned int &hitId, unsigned int &planeId) const
Get detector ID and cluster index (hitId) for hit number i with plane id.
Definition: GFTrackCand.h:104
virtual TVector3 getPos(const GFDetPlane &pl)=0
GFTrackCand fCand
Helper to store the indices of the hits in the track. See GFTrackCand for details.
Definition: GFTrack.h:93
std::vector< int > fRepAtHit
repAtHit keeps track of at which hit index which rep is currently defined, to avoid null extrapolatio...
Definition: GFTrack.h:88
unsigned int getDim() const
returns dimension of state vector
void setCov(const TMatrixT< double > &aCov)
bool getStatusFlag()
void blowUpCovs(double blowUpFactor)
this is needed to blow up the covariance matrix before a fitting pass drops off-diagonal elements and...
Definition: GFTrack.cxx:257
void getHit(unsigned int i, unsigned int &detId, unsigned int &hitId) const
Get detector ID and cluster index (hitId) for hit number i.
Definition: GFTrackCand.h:84
std::vector< GFBookkeeping * > fBookkeeping
Collection of Bookeeping objects for failed hits in every trackrep.
Definition: GFTrack.h:83
void reset()
Resets the GFTrack – deletes RecoHits!
Definition: GFTrack.cxx:116
Track candidate – a list of cluster indices.
Definition: GFTrackCand.h:55
virtual double extrapolate(const GFDetPlane &plane, TMatrixT< double > &statePred)
returns the tracklength spanned in this extrapolation
Base Class for representing a Hit in GENFIT.
Definition: GFAbsRecoHit.h:73
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
Definition: GFTrack.h:186
GFTrack * trk
Definition: checkgenfit.C:13
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
virtual void Print() const
const GFTrackCand & getCand() const
Definition: GFTrack.h:142
void addTrackRep(GFAbsTrackRep *theTrackRep)
Add track represenation.
Definition: GFTrack.h:318
GFAbsRecoHit * getHit(int id) const
Definition: GFTrack.h:144
virtual ~GFTrack()
Definition: GFTrack.cxx:38
ClassImp(PndAnaContFact)
void fillGeoTrack(TVirtualGeoTrack *tr) const
Fill TVirtualGeoTrack object Cardinal representation is used.
Definition: GFTrack.h:274
void mergeHits(GFTrack *trk)
Merge two GFTracks. Only hits will be merged.
Definition: GFTrack.cxx:134
void printBookkeeping()
print bookkeeping
Definition: GFTrack.cxx:208
virtual GFAbsTrackRep * clone() const =0
TMatrixT< double > getCov() const
unsigned int fCardinal_rep
Definition: GFTrack.h:96