StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFstRawHitCollection.cxx
1 #include "StFstRawHit.h"
2 #include "StFstRawHitCollection.h"
3 #include "St_base/StMessMgr.h"
4 #include <cmath>
5 #include <iostream>
6 
7 
8 StFstRawHitCollection::StFstRawHitCollection( int wedge ) : StObject(), mWedge(wedge), mRawHitVec(), mRawHitElecIdVec(kFstNumElecIds)
9 {
10 }
11 
12 
15 {
16  while (!mRawHitVec.empty()) delete mRawHitVec.back(), mRawHitVec.pop_back();
17 
18  mRawHitElecIdVec.clear();
19 };
20 
21 //sort internal vector by raw hit geometry ID
22 void StFstRawHitCollection::sortByGeoId()
23 {
24  std::sort( mRawHitVec.begin(), mRawHitVec.end(), &StFstRawHitCollection::rawHitIdLessThan );
25 };
26 
27 bool StFstRawHitCollection::rawHitIdLessThan( const StFstRawHit *h1, const StFstRawHit *h2 )
28 {
29  return (h1->getGeoId() < h2->getGeoId());
30 };
31 
32 vector<StFstRawHit *> &StFstRawHitCollection::getRawHitVec()
33 {
34  return mRawHitVec;
35 };
36 
37 const vector<StFstRawHit *> &StFstRawHitCollection::getRawHitVec() const
38 {
39  return mRawHitVec;
40 };
41 
42 size_t StFstRawHitCollection::getNumRawHits() const
43 {
44  return mRawHitVec.size();
45 };
46 
47 void StFstRawHitCollection::setWedge( int wedge )
48 {
49  mWedge = wedge;
50 };
51 
52 unsigned char StFstRawHitCollection::getWedge() const
53 {
54  return mWedge;
55 };
56 
57 void StFstRawHitCollection::Clear( Option_t *opt )
58 {
59  while (!mRawHitVec.empty()) delete mRawHitVec.back(), mRawHitVec.pop_back();
60 
61  //clear the vector for alternate lookups
62  for (unsigned int i = 0; i < mRawHitElecIdVec.size(); i++)
63  mRawHitElecIdVec[i] = 0;
64 };
65 
66 
67 void StFstRawHitCollection::Print(int nTimeBins) const
68 {
69  // The usage of nTimeBins is a bit crazy here but I took it directly from the
70  // former debug output at the end of StFstClusterMaker::Make()
71  int rawHitIdx = 0;
72 
73  for (std::vector<StFstRawHit*>::const_iterator it = mRawHitVec.begin(); it != mRawHitVec.end(); ++it, ++rawHitIdx)
74  {
75  LOG_DEBUG << "raw hit: Idx=" << rawHitIdx << endm;
76  (*it)->Print(nTimeBins);
77  }
78 }
79 
80 
89 {
90  if (!fstRawHit) return;
91 
92  int elecId = fstRawHit->getChannelId();
93 
94  if (elecId < 0 || elecId >= kFstNumElecIds) return;
95 
96  StFstRawHit *fstRawHitCurrent = mRawHitElecIdVec[elecId];
97 
98  // In case channel elecId has been added previously: Remove the existing
99  // hit/channel entry from memory and assign the new one to the same position
100  // in the main container mRawHitVec
101  if (fstRawHitCurrent) {
102  auto hitPtr = std::find(mRawHitVec.begin(), mRawHitVec.end(), fstRawHitCurrent);
103  *hitPtr = fstRawHit;
104 
105  delete fstRawHitCurrent;
106 
107  } else { // Otherwise just push back the new hit
108  mRawHitVec.push_back(fstRawHit);
109  }
110 
111  mRawHitElecIdVec[elecId] = fstRawHit;
112 }
113 
114 
115 StFstRawHit *StFstRawHitCollection::getRawHit( int elecId )
116 {
117  StFstRawHit *&rawHitPtr = mRawHitElecIdVec[elecId];
118 
119  if ( !rawHitPtr ) {
120  rawHitPtr = new StFstRawHit();
121  mRawHitVec.push_back( rawHitPtr );
122  }
123 
124  return rawHitPtr;
125 };
126 
127 
128 ClassImp(StFstRawHitCollection);
int getGeoId() const
0-36863
Definition: StFstRawHit.cxx:51
void addRawHit(StFstRawHit *fstRawHit)
int getChannelId() const
0-36863
Definition: StFstRawHit.cxx:50