StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGmtStripCollection.cxx
1 /***************************************************************************
2  *
3  * Authors: K.S. Engle and Richard Witt (witt@usna.edu), Jan 2013
4  * based on StFgtStripCollection
5  *
6  ***************************************************************************
7  *
8  * Description: See header file.
9  *
10  ***************************************************************************/
11 
12 #include "St_base/StMessMgr.h"
13 
14 #include "StContainers.h"
15 #include "StGmtStrip.h"
16 #include "StGmtStripCollection.h"
17 
18 #include <cmath>
19 #include <iostream>
20 #include <vector>
21 
22 //________________
24 
25 //________________
26 StGmtStripCollection::StGmtStripCollection( short module ) : StObject(), mModule( module ) {
27  mStripGeoIdVec.resize( kGmtNumGeoIds );
28  for (unsigned int i=0; i<mStripGeoIdVec.size(); i++) {
29  mStripGeoIdVec[i] = static_cast< StGmtStrip* >(0);
30  }
31 };
32 
33 //________________
34 void StGmtStripCollection::removeFlagged(){
35  // remove all hits with negative geoIds or with clusterSeedType set to kGmtDeadStrip
36  if( !mStripVec.empty() ){
37  // container to hold a copy
38  std::vector< StGmtStrip* > copy;
39  copy.reserve( mStripVec.size() );
40  sortByGeoId();
41 
42  // iterators
43  StSPtrVecGmtStripIterator srcIter;
44  StSPtrVecGmtStripIterator lastCopied=mStripVec.begin()-1;
45 
46  // copy all valid events
47  for( srcIter = mStripVec.begin(); srcIter != mStripVec.end(); ++srcIter )
48  if( (*srcIter) && (*srcIter)->getGeoId() >= 0 ) {
49  copy.push_back( new StGmtStrip( *(*srcIter) ) );
50  }
51 
52  if ( copy.size() != mStripVec.size() ){
53  // this deletes the objects
54  mStripVec.clear();
55  // note: ownership of new objects passed to StSPtrVec
56  std::vector< StGmtStrip* >::iterator copyIter;
57  for( copyIter = copy.begin(); copyIter != copy.end(); ++copyIter ) {
58  mStripVec.push_back( *copyIter );
59  }
60  }
61  }
62 }
63 
64 //________________
66  return h1->getGeoId() < h2->getGeoId();
67 };
68 
69 //________________
71  return h1->getCoordNum() < h2->getCoordNum();
72 };
73 
74 //________________
76  return h1->isY() < h2->isY();
77 };
78 
79 //________________
80 void StGmtStripCollection::Clear( Option_t *opt ){
81 
82  // no need to delete the objects in mStripVec, is done within its
83  // clear function.
84 
85  // clear the vector
86  mStripVec.clear();
87 
88  // clear the vector for alternate lookups
89  for (unsigned int i=0; i<mStripElecIdVec.size(); i++) mStripElecIdVec[i] = static_cast< StGmtStrip* >(0);
90 
91  // clear the other vector for alternate lookups
92  for (unsigned int i=0; i<mStripGeoIdVec.size(); i++) mStripGeoIdVec[i] = static_cast< StGmtStrip* >(0);
93 
94 }
95 
96 //________________
97 StGmtStrip* StGmtStripCollection::getStrip( Int_t Id ) {
98  // using geoId now instead of elecId so now using more generic index name
99  StGmtStrip* stripPtr = mStripGeoIdVec[Id];
100  if( !stripPtr ){
101  stripPtr = new StGmtStrip();
102  mStripVec.push_back( stripPtr );
103  }
104  return stripPtr;
105 }
106 
107 //________________
108 StGmtStrip* StGmtStripCollection::getSortedStrip( Int_t Id ) {
109  // using geoId now instead of elecId so now using more generic index name
110  StGmtStrip* stripPtr = mStripVec[Id];
111  if( !stripPtr ){
112  LOG_ERROR << "StGmtStripCollection::getSortedStrip no such Id: " << Id << endm;
113  return 0;
114  }
115  return stripPtr;
116 }
117 
118 // sort by geoId
119 void StGmtStripCollection::sortByGeoId(){
120  std::sort( mStripVec.begin(), mStripVec.end(), &StGmtStripCollection::hitGeoIdLessThan );
121 }
122 
123 // sort by layer (X first then Y)
124 void StGmtStripCollection::sortByLayer(){
125  std::sort( mStripVec.begin(), mStripVec.end(), &StGmtStripCollection::hitLayerLessThan );
126 };
127 
128 // sort by coordinate number
129 void StGmtStripCollection::partialSortByCoord(){
130  std::partial_sort( mStripVec.begin(), mStripVec.begin()+kGmtNumStrips, mStripVec.begin()+kGmtNumStrips, &StGmtStripCollection::hitCoordLessThan );
131 };
132 
133 // sort by coordinate number
134 void StGmtStripCollection::sortByCoord(){
135  std::sort( mStripVec.begin(), mStripVec.end(), &StGmtStripCollection::hitCoordLessThan );
136 };
137 
static bool hitCoordLessThan(const StGmtStrip *h1, const StGmtStrip *h2)
Function used for sorting strips by coordinate number.
Int_t getCoordNum() const
Coordinate (0-127)
Definition: StGmtStrip.h:43
~StGmtStripCollection()
Destructor.
static bool hitGeoIdLessThan(const StGmtStrip *h1, const StGmtStrip *h2)
Function used for sorting strips by geoId.
Int_t isY() const
Is it a pad?
Definition: StGmtStrip.h:45
StPtrVecGmtStrip mStripElecIdVec
StGmtStripCollection(short module=0)
Constructer.
static bool hitLayerLessThan(const StGmtStrip *h1, const StGmtStrip *h2)
Function used for sorting strips by X then Y.
Int_t getGeoId() const
Detector ID (8 modules * 2 APV * 128 channels)
Definition: StGmtStrip.h:39
StPtrVecGmtStrip mStripGeoIdVec
StSPtrVecGmtStrip mStripVec
Vector with strips.
Holds data for the strip in GMT.
Definition: StGmtStrip.h:21