StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dominatrackInfo.cc
1 //
2 // $Id: dominatrackInfo.cc,v 1.4 2018/01/03 18:18:10 genevb Exp $
3 //
4 // $Log: dominatrackInfo.cc,v $
5 // Revision 1.4 2018/01/03 18:18:10 genevb
6 // idTruths and keys moved from short to int
7 //
8 // Revision 1.3 2007/02/23 17:07:41 fisyak
9 // Resolve bug #682
10 //
11 // Revision 1.2 2005/07/19 22:05:19 perev
12 // MultiVertex
13 //
14 // Revision 1.1 2004/03/31 23:44:36 calderon
15 // Function to find the dominatrack, the number of hits belonging to the
16 // dominatrack and the average hit quality of those hits (based on idTruth and
17 // quality of StHit).
18 //
19 //
20 #include <map>
21 #include <set>
22 #include "Stiostream.h"
23 #include "StTrack.h"
24 #include "StContainers.h"
25 #include "StTrackDetectorInfo.h"
26 #include "StEnumerations.h"
27 #include "StHit.h"
28 
29 void dominatrackInfo(const StTrack* recTrack,int& dominatrackKey ,short& dominatrackHits,float& avgQuality) {
30  // initialize return values.
31  // dominatrack key initialized to nonsense, quality initialized to 0.
32  // Note, I'm using shorts, which should be ok up to 32768, but if we
33  // ever have track keys above this in an event, there will be trouble.
34  static short DetectorList[kMaxDetectorId];
35  dominatrackKey = -999;
36  dominatrackHits = 0;
37  avgQuality = 0;
38  multimap<int,float> idTruths;
39  set<int> uniqueIdTruths;
40  if (!recTrack) return;
41  StPtrVecHit recHits = recTrack->detectorInfo()->hits();//(kTpcId);
42  // loop to store all the mc track keys and quality of every reco hit on the track.
43  for (StHitIterator hi=recHits.begin();
44  hi!=recHits.end(); hi++) {
45  StHit* rHit = *hi;
46  idTruths.insert( multimap<int,float>::value_type(rHit->idTruth(),rHit->qaTruth()));
47  uniqueIdTruths.insert(static_cast<int>(rHit->idTruth()));
48  }
49  // find the dominatrix track!
50  for (set<int>::iterator si=uniqueIdTruths.begin(); si!=uniqueIdTruths.end(); ++si) {
51  int currentNHitsIdTruth = idTruths.count(*si);
52  if (currentNHitsIdTruth>dominatrackHits) {
53  dominatrackKey = *si;
54  dominatrackHits = currentNHitsIdTruth;
55  }
56  }
57  //calculate average track quality for the dominatrix track
58  pair<multimap<int,float>::iterator,multimap<int,float>::iterator> dominatrackRange = idTruths.equal_range(dominatrackKey);
59  for (multimap<int,float>::iterator mi=dominatrackRange.first; mi!=dominatrackRange.second; ++mi) {
60  avgQuality+=mi->second;
61  }
62  avgQuality/=dominatrackHits;
63  memset (DetectorList, 0, kMaxDetectorId*sizeof(short));
64  for (StHitIterator hi=recHits.begin();
65  hi!=recHits.end(); hi++) {
66  StHit* rHit = *hi;
67  if (rHit->idTruth() == dominatrackKey) {
68  DetectorList[rHit->detector()]++;
69  }
70 #if 0
71  else cout << "Not Matched hit " << *rHit << endl;
72 #endif
73  }
74  if (DetectorList[kTpcId] > 99) DetectorList[kTpcId] = 99;
75  if (DetectorList[kSvtId] > 9) DetectorList[kSvtId] = 9;
76  if (DetectorList[kSsdId] > 9) DetectorList[kSsdId] = 9;
77  dominatrackHits = DetectorList[kTpcId] + 100*(DetectorList[kSvtId] + 10*DetectorList[kSsdId]);
78  return;
79 }
Definition: StHit.h:125