StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPxlCluster.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StPxlCluster.cxx,v 1.8 2014/03/18 14:45:29 qiuh Exp $
9  *
10  * Author: Qiu Hao, Jan 2013, according codes from Xiangming Sun
11  ***************************************************************************
12  *
13  * Description:
14  * a group of neighboring pixel raw hits
15  * More information at
16  * https://www.star.bnl.gov/protected/heavy/qiuh/HFT/software/PXL_software.pdf
17  *
18  ***************************************************************************
19  *
20  * $Log: StPxlCluster.cxx,v $
21  * Revision 1.8 2014/03/18 14:45:29 qiuh
22  * *** empty log message ***
23  *
24  * Revision 1.7 2014/02/27 00:44:25 smirnovd
25  * Minor corrections
26  *
27  * Revision 1.6 2014/02/27 00:44:15 smirnovd
28  * Make sorting function static class method
29  *
30  * Revision 1.5 2014/02/27 00:44:08 smirnovd
31  * Use constructor initializer list
32  *
33  * Revision 1.4 2014/02/21 21:11:06 smirnovd
34  * Minor style and empty space adjustments
35  *
36  * Revision 1.3 2014/01/28 19:29:35 qiuh
37  * *** empty log message ***
38  *
39  *
40  **************************************************************************/
41 
42 #include <algorithm>
43 #include <map>
44 
45 #include "StPxlCluster.h"
46 #include "StPxlRawHitMaker/StPxlRawHit.h"
47 
48 using namespace std;
49 
50 ClassImp(StPxlCluster)
51 
52 
53 StPxlCluster::StPxlCluster() : mRawHitVec(),
54  mColumnCenter(-9999),
55  mRowCenter(-9999),
56  mIdTruth(-9999)
57 {
58 }
59 
60 
62 {
63  return mRawHitVec.size();
64 }
65 
66 
68 {
69  mRawHitVec.push_back(rawHit);
70 }
71 
72 
73 bool StPxlCluster::compareSecond(const pair<int, int> &pair1, const pair<int, int> &pair2)
74 {
75  return pair1.second < pair2.second;
76 }
77 
78 
79 void StPxlCluster::summarize(int embeddingShortCut)
80 {
81  // calculate average column and row
82  float columnSum = 0;
83  float rowSum = 0;
84  int nRawHits_ = nRawHits();
85 
86  for (int i = 0; i < nRawHits_; i++) {
87  columnSum += mRawHitVec[i]->column();
88  rowSum += mRawHitVec[i]->row();
89  }
90 
91  mColumnCenter = columnSum / float(nRawHits_);
92  mRowCenter = rowSum / float(nRawHits_);
93 
94  // find the most frequent raw hit idTruth as cluster idTruth
95  mIdTruth = 0;
96  if (embeddingShortCut) {return;}
97  map<int, int> idTruthMap;
98  for (int i = 0; i < nRawHits_; i++) {
99  if (mRawHitVec[i])
100  {
101  if (mRawHitVec[i]->idTruth()) {idTruthMap[mRawHitVec[i]->idTruth()] ++;}
102  }
103  }
104 
105  if (!idTruthMap.empty()) {
106  mIdTruth = max_element(idTruthMap.begin(), idTruthMap.end(), compareSecond)->first;
107  }
108 }
void summarize(int embeddingShortCut=0)
calculate column center, row center, and most frequent idTruth among raw hits
void addRawHit(const StPxlRawHit *rawHit)
add a raw hit to the cluster
Int_t nRawHits() const
number of raw hits