StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTrack.cxx
1 /***************************************************************************
2  *
3  * $Id: StTrack.cxx,v 2.47 2017/05/04 01:00:30 perev Exp $
4  *
5  * Author: Thomas Ullrich, Sep 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTrack.cxx,v $
13  * Revision 2.47 2017/05/04 01:00:30 perev
14  * Add Fts
15  *
16  * Revision 2.46 2016/11/28 21:00:24 ullrich
17  * Added StExtGeometry features.
18  *
19  * Revision 2.45 2015/05/13 17:06:14 ullrich
20  * Added hooks and interfaces to Sst detector (part of HFT).
21  *
22  * Revision 2.44 2013/07/23 11:21:49 jeromel
23  * Undo past week changes
24  *
25  * Revision 2.42 2013/04/10 19:15:53 jeromel
26  * Step back from StEvent changes - previous change recoverable [Thomas OK-ed]
27  *
28  * Revision 2.40 2013/01/15 23:21:06 fisyak
29  * improve printouts
30  *
31  * Revision 2.39 2012/05/07 14:42:58 fisyak
32  * Add handilings for Track to Fast Detectors Matching
33  *
34  * Revision 2.38 2011/10/17 00:13:49 fisyak
35  * Add handles for IdTruth info
36  *
37  * Revision 2.37 2011/10/13 21:25:27 perev
38  * setting IdTruth from the hits is added
39  *
40  * Revision 2.36 2011/04/26 21:41:29 fisyak
41  * Make mKey Int_t instead of UShort_t (no. of tracks might be more that 64k)
42  *
43  * Revision 2.35 2011/03/31 19:29:01 fisyak
44  * Add IdTruth information for tracks and vertices
45  *
46  * Revision 2.34 2010/08/31 20:00:09 fisyak
47  * Clean up, add mSeedQuality
48  *
49  * Revision 2.33 2009/11/23 16:34:07 fisyak
50  * Cleanup, remove dependence on dst tables, clean up software monitors
51  *
52  * Revision 2.32 2009/04/29 23:02:36 perev
53  * check for big lenght added
54  *
55  * Revision 2.31 2007/10/11 21:51:40 ullrich
56  * Added member to handle number of possible points fpr PXL and IST.
57  *
58  * Revision 2.30 2006/08/28 17:04:46 fisyak
59  * Don't check StPhysicalHelixD quality for Beam Background tracks (flag() == 901)
60  *
61  * Revision 2.29 2005/07/06 19:00:52 fisyak
62  * Add include of StThreeVectorD.hh
63  *
64  * Revision 2.28 2004/11/08 22:25:38 perev
65  * Remove StTrack test for wrong length. TPT only
66  *
67  * Revision 2.27 2004/10/20 18:55:13 ullrich
68  * Name of enum changed: StStarMaxR(Z) now StStarMaxTrackRangeR(Z).
69  *
70  * Revision 2.26 2004/10/17 03:35:10 perev
71  * Error check improved
72  *
73  * Revision 2.25 2004/08/13 18:15:08 ullrich
74  * Added +1 to the number of possible points when primary track.
75  *
76  * Revision 2.24 2004/08/10 14:20:21 calderon
77  * Putting the streamers back in. They should not be needed, but
78  * apparently removing them causes more problems. Yuri tested that
79  * putting them back in allows reading files again.
80  *
81  * Revision 2.23 2004/08/05 22:24:51 ullrich
82  * Changes to the handling of numberOfPoints() to allow ITTF more flexibility.
83  *
84  * Revision 2.22 2004/01/26 22:56:28 perev
85  * Add Finite for float
86  *
87  * Revision 2.21 2003/12/04 03:53:14 perev
88  * Set empty, instead of crazy outer geometry
89  *
90  * Revision 2.20 2003/10/31 16:00:04 ullrich
91  * Added setKey() method.
92  *
93  * Revision 2.19 2003/10/30 20:07:32 perev
94  * Check of quality added
95  *
96  * Revision 2.18 2003/04/25 23:48:18 calderon
97  * fittingMethod member function was missing case for kITKalmanFitId.
98  *
99  * Revision 2.17 2002/03/14 17:42:31 ullrich
100  * Added method to set mNumberOfPossiblePoints.
101  *
102  * Revision 2.16 2002/02/27 19:09:22 ullrich
103  * Updated fittingMethod(): L3 added.
104  *
105  * Revision 2.15 2001/09/28 22:20:49 ullrich
106  * Added helix geometry at last point.
107  *
108  * Revision 2.14 2001/05/30 17:45:54 perev
109  * StEvent branching
110  *
111  * Revision 2.13 2001/04/05 04:00:57 ullrich
112  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
113  *
114  * Revision 2.12 2001/03/16 20:56:45 ullrich
115  * Added non-const version of fitTraits().
116  *
117  * Revision 2.11 2000/04/20 13:49:07 ullrich
118  * Removed redundant line in operator=().
119  *
120  * Revision 2.10 2000/01/20 14:42:40 ullrich
121  * Fixed bug in numberOfPossiblePoints(). Sum was wrong.
122  *
123  * Revision 2.9 1999/12/01 15:58:08 ullrich
124  * New decoding for dst_track::method. New enum added.
125  *
126  * Revision 2.8 1999/12/01 00:15:27 didenko
127  * temporary solution to compile the library
128  *
129  * Revision 2.7 1999/11/29 17:32:42 ullrich
130  * Added non-const method pidTraits().
131  *
132  * Revision 2.6 1999/11/15 18:48:20 ullrich
133  * Adapted new enums for dedx and track reco methods.
134  *
135  * Revision 2.5 1999/11/09 15:44:14 ullrich
136  * Removed method unlink() and all calls to it.
137  *
138  * Revision 2.4 1999/11/05 15:27:04 ullrich
139  * Added non-const versions of several methods
140  *
141  * Revision 2.3 1999/11/04 13:32:00 ullrich
142  * Added non-const versions of some methods
143  *
144  * Revision 2.2 1999/11/01 12:45:02 ullrich
145  * Modified unpacking of point counter
146  *
147  * Revision 2.1 1999/10/28 22:27:21 ullrich
148  * Adapted new StArray version. First version to compile on Linux and Sun.
149  *
150  * Revision 2.0 1999/10/12 18:42:54 ullrich
151  * Completely Revised for New Version
152  *
153  **************************************************************************/
154 #include <map>
155 #include "TClass.h"
156 #include "StMath.hh"
157 #include "StTrack.h"
158 #include "StParticleDefinition.hh"
159 #include "StVertex.h"
160 #include "StTrackGeometry.h"
161 #include "StTrackDetectorInfo.h"
162 #include "StTrackPidTraits.h"
163 #include "StTrackNode.h"
164 #include "StThreeVectorD.hh"
165 #include "StHit.h"
166 #include "StG2TrackVertexMap.h"
167 #include "StExtGeometry.h"
168 ClassImp(StTrack)
169 
170 static const char rcsid[] = "$Id: StTrack.cxx,v 2.47 2017/05/04 01:00:30 perev Exp $";
171 
172 StTrack::StTrack()
173 {
174  memset(mBeg, 0, mEnd-mBeg+1);
175 }
176 
177 
178 StTrack::StTrack(const StTrack& track) {
179  for (int bit = 14; bit < 23; bit++) if (track.TestBit(BIT(bit))) SetBit(BIT(bit));
180  memcpy (mBeg, track.mBeg, mEnd-mBeg+1);
181  mTopologyMap = track.mTopologyMap;
182  mFitTraits = track.mFitTraits;
183  if (track.mGeometry)
184  mGeometry = track.mGeometry->copy();
185  else
186  mGeometry = 0;
187  if (track.mOuterGeometry)
188  mOuterGeometry = track.mOuterGeometry->copy();
189  else
190  mOuterGeometry = 0;
191  mDetectorInfo = track.mDetectorInfo; // not owner anyhow
192  mPidTraitsVec = track.mPidTraitsVec;
193  mNode = 0; // do not assume any context here
194 }
195 
196 StTrack&
197 StTrack::operator=(const StTrack& track) {
198  if (this != &track) {
199  for (int bit = 14; bit < 23; bit++) if (track.TestBit(BIT(bit))) SetBit(BIT(bit));
200  memcpy (mBeg, track.mBeg, mEnd-mBeg+1);
201  mTopologyMap = track.mTopologyMap;
202  mFitTraits = track.mFitTraits;
203  if (mGeometry) delete mGeometry;
204  if (track.mGeometry)
205  mGeometry = track.mGeometry->copy();
206  else
207  mGeometry = 0;
208  if (mOuterGeometry) delete mOuterGeometry;
209  if (track.mOuterGeometry)
210  mOuterGeometry = track.mOuterGeometry->copy();
211  else
212  mOuterGeometry = 0;
213  mDetectorInfo = track.mDetectorInfo; // not owner anyhow
214  mPidTraitsVec = track.mPidTraitsVec;
215  }
216  return *this;
217 }
218 
219 StTrack::~StTrack()
220 {
221  delete mGeometry;
222  delete mOuterGeometry;
223 }
224 
225 short
226 StTrack::flag() const { return mFlag; }
227 
228 
229 unsigned short
230 StTrack::encodedMethod() const { return mEncodedMethod; }
231 
232 bool
233 StTrack::finderMethod(StTrackFinderMethod bit) const
234 {
235  return mEncodedMethod & (1<<bit);
236 }
237 
238 StTrackFittingMethod
239 StTrack::fittingMethod() const
240 {
241  int method = mEncodedMethod & 0xf;
242  switch(method) {
243  case kHelix2StepId:
244  return kHelix2StepId;
245  break;
246  case kHelix3DId:
247  return kHelix3DId;
248  break;
249  case kKalmanFitId:
250  return kKalmanFitId;
251  break;
252  case kLine2StepId:
253  return kLine2StepId;
254  break;
255  case kLine3DId:
256  return kLine3DId;
257  break;
258  case kL3FitId:
259  return kL3FitId;
260  break;
261  case kITKalmanFitId:
262  return kITKalmanFitId;
263  break;
264  default:
265  case kUndefinedFitterId:
266  return kUndefinedFitterId;
267  break;
268  }
269 }
270 
271 float
272 StTrack::impactParameter() const { return mImpactParameter; }
273 
274 float
275 StTrack::length() const { return mLength; }
276 
277 unsigned short
278 StTrack::numberOfPossiblePoints() const
279 {
280  unsigned short result;
281  result = numberOfPossiblePoints(kTpcId) +
282  numberOfPossiblePoints(kFtpcWestId) +
283  numberOfPossiblePoints(kFtpcEastId) +
284  numberOfPossiblePoints(kSvtId) +
285  numberOfPossiblePoints(kSsdId) +
286  numberOfPossiblePoints(kSstId) +
287  numberOfPossiblePoints(kPxlId) +
288  numberOfPossiblePoints(kIstId) +
289  numberOfPossiblePoints(kFtsId);
290  if (type() == primary || type() == estPrimary) result++;
291  return result;
292 }
293 
294 unsigned short
295 StTrack::numberOfPossiblePoints(StDetectorId det) const
296 {
297  switch (det) {
298  case kFtpcWestId:
299  return mNumberOfPossiblePointsFtpcWest;
300  case kFtpcEastId:
301  return mNumberOfPossiblePointsFtpcEast;
302  case kTpcId:
303  return mNumberOfPossiblePointsTpc;
304  case kSvtId:
305  return mNumberOfPossiblePointsSvt;
306  case kSsdId:
307  return mNumberOfPossiblePointsSsd;
308  case kSstId:
309  return mNumberOfPossiblePointsSst;
310  case kPxlId:
311  return mNumberOfPossiblePointsPxl;
312  case kIstId:
313  return mNumberOfPossiblePointsIst;
314  case kFtsId:
315  return mNumberOfPossiblePointsFts;
316  default:
317  return 0;
318  }
319 }
320 
321 const StTrackTopologyMap&
322 StTrack::topologyMap() const { return mTopologyMap; }
323 
324 const StTrackGeometry*
325 StTrack::geometry() const { return mGeometry; }
326 
328 StTrack::geometry() { return mGeometry; }
329 
330 const StTrackGeometry*
331 StTrack::outerGeometry() const { return mOuterGeometry; }
332 
334 StTrack::outerGeometry() { return mOuterGeometry; }
335 
337 StTrack::fitTraits() { return mFitTraits; }
338 
339 const StTrackFitTraits&
340 StTrack::fitTraits() const { return mFitTraits; }
341 
343 StTrack::detectorInfo() { return mDetectorInfo; }
344 
345 const StTrackDetectorInfo*
346 StTrack::detectorInfo() const { return mDetectorInfo; }
347 
348 const StSPtrVecTrackPidTraits&
349 StTrack::pidTraits() const { return mPidTraitsVec; }
350 
351 StSPtrVecTrackPidTraits&
352 StTrack::pidTraits() { return mPidTraitsVec; }
353 
354 StPtrVecTrackPidTraits
355 StTrack::pidTraits(StDetectorId det) const
356 {
357  StPtrVecTrackPidTraits vec;
358  for (unsigned int i=0; i<mPidTraitsVec.size(); i++)
359  if (mPidTraitsVec[i]->detector() == det)
360  vec.push_back(mPidTraitsVec[i]);
361  return vec;
362 }
363 
365 StTrack::pidTraits(StPidAlgorithm& pid) const
366 {
367  return pid(*this, mPidTraitsVec);
368 }
369 
370 const StTrackNode*
371 StTrack::node() const { return mNode; }
372 
374 StTrack::node() { return mNode; }
375 
376 void
377 StTrack::setFlag(short val) { mFlag = val; }
378 
379 
380 void
381 StTrack::setEncodedMethod(unsigned short val) { mEncodedMethod = val; }
382 
383 void
384 StTrack::setImpactParameter(float val) { mImpactParameter = val; }
385 
386 void
387 StTrack::setLength(float val) { mLength = val; }
388 
389 void
390 StTrack::setTopologyMap(const StTrackTopologyMap& val) { mTopologyMap = val; }
391 
392 void
393 StTrack::setGeometry(StTrackGeometry* val)
394 {
395  if (mGeometry) delete mGeometry;
396  mGeometry = val;
397 }
398 
399 void
400 StTrack::setOuterGeometry(StTrackGeometry* val)
401 {
402  if (mOuterGeometry) delete mOuterGeometry;
403  mOuterGeometry = val;
404 }
405 
406 void
407 StTrack::setFitTraits(const StTrackFitTraits& val) { mFitTraits = val; }
408 
409 void
410 StTrack::addPidTraits(StTrackPidTraits* val) { mPidTraitsVec.push_back(val); }
411 
412 void
413 StTrack::setDetectorInfo(StTrackDetectorInfo* val) { mDetectorInfo = val; }
414 
415 
416 void
417 StTrack::setNumberOfPossiblePoints(unsigned char val, StDetectorId det)
418 {
419  switch (det) {
420  case kFtpcWestId:
421  mNumberOfPossiblePointsFtpcWest = val;
422  break;
423  case kFtpcEastId:
424  mNumberOfPossiblePointsFtpcEast = val;
425  break;
426  case kTpcId:
427  mNumberOfPossiblePointsTpc = val;
428  break;
429  case kSvtId:
430  mNumberOfPossiblePointsSvt = val;
431  break;
432  case kSsdId:
433  mNumberOfPossiblePointsSsd = val;
434  break;
435  case kSstId:
436  mNumberOfPossiblePointsSst = val;
437  break;
438  case kPxlId:
439  mNumberOfPossiblePointsPxl = val;
440  break;
441  case kIstId:
442  mNumberOfPossiblePointsIst = val;
443  break;
444  case kFtsId:
445  mNumberOfPossiblePointsFts = val;
446  break;
447  default:
448  break;
449  }
450 }
451 
452 void
453 StTrack::setNode(StTrackNode* val) { mNode = val; }
454 
455 #include "StHelixModel.h"
456 int StTrack::bad() const
457 {
458  static const double world = 1.e+5;
459  int ierr;
460  if (!StMath::Finite(mImpactParameter)) return 12;
461  if (!StMath::Finite(mLength) ) return 13;
462  if (mFlag <0 ) return 21;
463  if (mFlag ==0 ) return 31;
464  if (::fabs(mImpactParameter)>world ) return 22;
465  if (::fabs(mLength) >world ) return 23;
466  if (mLength <1./world ) return 33;
467  if (mLength > world ) return 34;
468  if (!mGeometry ) return 24;
469  ierr = mGeometry->bad();
470  if (ierr ) return 4+100*ierr;
471  if (!mOuterGeometry ) return 25;
472  ierr = mOuterGeometry->bad();
473  if (ierr ) return 5+100*ierr;
474 
475  const StTrackDetectorInfo *di = mDetectorInfo;
476  if (!di ) return 26;
477  ierr = di->bad();
478  if (ierr ) return 6+100*ierr;
479  if ((flag()/100)%10 == 9) return 0; // don't check Helix for Beam Background tracks
480  StPhysicalHelixD hlx1 = mGeometry->helix();
481  StThreeVectorD ori2 = mOuterGeometry->origin();
482  double len12 = hlx1.pathLength(ori2);
483  double per = hlx1.period();
484  while (len12< 0) len12+=per;
485  while (len12>per) len12-=per;
486  double tol = (len12)*0.2; if (tol<1) tol =1;
487  //VP ignor for TPT if (fabs(mLength-len12)>tol) return 43;
488 
489  if (fabs(hlx1.z(mLength))>kStarMaxTrackRangeZ) return 53;
490  double qwe = pow(hlx1.x(mLength),2)+pow(hlx1.y(mLength),2);
491  if (sqrt(qwe)>kStarMaxTrackRangeR) return 63;
492  return 0;
493 }
494 
495 void StTrack::Streamer(TBuffer &R__b)
496 {
497  // Stream an object of class .
498 
499  if (R__b.IsReading()) {
500  unsigned int R__s, R__c;
501  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
502  if (R__v > 1) {
503  Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
504  return;
505  }
506  //====process old versions before automatic schema evolution
507  StObject::Streamer(R__b);
508  R__b >> mKey;
509  R__b >> mFlag;
510 
511  // R__b >> mEncodedMethod;
512  UChar_t oldEncodedMethod;
513  R__b >> oldEncodedMethod;
514  mEncodedMethod=oldEncodedMethod;
515 
516  R__b >> mImpactParameter;
517  R__b >> mLength;
518  R__b >> mSeedQuality;
519  mTopologyMap.Streamer(R__b);
520  mFitTraits.Streamer(R__b);
521  R__b >> mGeometry;
522 
523  // R__b >> mDetectorInfo;
524  R__b >> (StTrackDetectorInfo*&)mDetectorInfo;
525 
526  // R__b >> mNode;
527  R__b >> (StTrackNode*&)mNode;
528 
529 
530  mPidTraitsVec.Streamer(R__b);
531 
532  R__b.CheckByteCount(R__s, R__c, Class());
533  //====end of old versions
534 
535  } else {
536  Class()->WriteBuffer(R__b,this);
537  }
538 }
539 
540 
541 void StTrack::setIdTruth() // match with IdTruth
542 {
543 
544  const StTrackDetectorInfo* di = detectorInfo();
545  if (!di) return;
546  const StPtrVecHit& vh = di->hits();
547 
548  typedef std::map< int,float> myMap_t;
549  typedef std::pair<int,float> myPair_t;
550  typedef myMap_t::const_iterator myIter_t;
551  myMap_t idTruths;
552 
553  // Loop to store all the mc track keys and quality of every reco hit on the track.
554  int nHits = vh.size(),id=0,qa=0;
555  for (int hi=0;hi<nHits; hi++) {
556  const StHit* rHit = vh[hi];
557  id = rHit->idTruth(); if (!id) continue;
558  qa = rHit->qaTruth(); if (!qa) qa = 1;
559  idTruths[id]+=qa;
560  }
561  if (! idTruths.size()) return; //no simu hits
562  int tkBest=-1; float qaBest=0,qaSum=0;
563  for (myIter_t it=idTruths.begin(); it!=idTruths.end();++it) {
564  qaSum+=(*it).second;
565  if ((*it).second<qaBest) continue;
566  tkBest=(*it).first; qaBest=(*it).second;
567  }
568  if (tkBest < 0 || tkBest> 0xffff) return;
569  int avgQua= 100*qaBest/(qaSum+1e-10)+0.5;
570  setIdTruth(tkBest,avgQua);
571  int IdVx = StG2TrackVertexMap::instance()->IdVertex(tkBest);
572  setIdParentVx(IdVx);
573 }
574 //________________________________________________________________________________
575 ostream& operator<<(ostream& os, const StTrack& track) {
576  os << Form("%4i ",track.key());
577  if (track.type() == global) os << "global";
578  else os << "primary";
579  os << Form(" %4i",track.flag());
580  if (track.isPostXTrack()) os << "C";
581  else if (track.isPromptTrack()) os << "P";
582  else os << " ";
583  if (track.isCtbMatched() || track.isToFMatched()) os << "T";
584  else os << " ";
585  if (track.isBemcMatched() || track.isEemcMatched()) {
586  if (track.isBemcMatched()) os << "b";
587  else os << "e";
588  unsigned int fext = track.flagExtension() & 07;
589  switch (fext) {
590  case 0: os << " "; break;
591  case 1: os << "M"; break;
592  case 2: os << "H"; break;
593  case 3: os << "E"; break;
594  case 4: os << "T"; break;
595  case 5: os << "W"; break;
596  case 6: os << "Z"; break;
597  default: os << "?"; break;
598  }
599  } else os << " ";
600  if (track.isMembraneCrossingTrack()) os << "X";
601  else if (track.isWestTpcOnly()) os << "W";
602  else if (track.isEastTpcOnly()) os << "E";
603  else os << " ";
604  if (track.isShortTrack2EMC()) os << "S";
605  else os << " ";
606  if (track.isRejected()) os << "R";
607  else os << " ";
608  double length = track.length();
609  if (length > 9999.) length = 9999.;
610  os << Form(" NP %2d L %8.3f", track.numberOfPossiblePoints(),length);
611  os << Form(" IdT: %4i Q:%3i", track.idTruth(), track.qaTruth());
612  return os;
613 }
614 //________________________________________________________________________________
615 void StTrack::addExtGeometry(StExtGeometry *exg)
616 {
617  StExtGeometry ** kexg = &mExtGeometry;
618  for (; *kexg; kexg = &((*kexg)->mNext)) {}
619  *kexg = exg;
620 }
Definition: StHit.h:125
double x(double s) const
coordinates of helix at point s
Definition: StHelix.hh:182
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
double period() const
returns period length of helix
Definition: StHelix.cc:339