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