StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcStripClusterFinderTSIU.cxx
1 
9 #include <TH1.h>
10 #include <assert.h>
11 #include <algorithm>
12 
13 #include "StRoot/St_base/StMessMgr.h"
14 #include "StRoot/St_base/Stypes.h"
15 
16 #include "StEEmcStripClusterFinderTSIU.h"
17 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
18 
19 StEEmcStripClusterFinderTSIU_t::StEEmcStripClusterFinderTSIU_t() :
20  mNumSmoothIters( 5 ),
21  mNumStripsPerSide( 2 ),
22  mMinStripsPerCluster( 4 ),
23  mSeedAbsThres( 0.001 ),
24  mSeedRelThres( 0.05 ),
25  mMinEnergyPerCluster( 0.010 )
26 {
27  // initialize a few parent variables
28  mLayer = U_LAYER;
29  mSector = 0;
30  mIsReady = 1;
31 };
32 
33 StEEmcStripClusterFinderTSIU_t::~StEEmcStripClusterFinderTSIU_t(){
34  // nothing to do
35 };
36 
37 
39 Int_t StEEmcStripClusterFinderTSIU_t::find( const ESmdLayer_t& stripArray, StSimpleClusterVec_t& clusters ){
40  clusters.clear();
41  Int_t ierr = kStOk;
42 
43  assert( mNumStripsPerSide > 0 ); // make sure enough side strips
44  assert( mNumStripsPerSide < 0.3*kEEmcNumStrips ); // make sure not too many side strips
45  assert( mMinEnergyPerCluster > 0 ); // make sure a positive (non-zero) threshold
46 
47  // skip if not enough strips hit
48  if( (UInt_t)(stripArray.nStrips) < mMinStripsPerCluster )
49  return ierr;
50 
51  // clear array
52  for( Double_t *p1 = mStripEnergyArray, *p2 = mSmoothedEnergyArray; p1 != &mStripEnergyArray[kEEmcNumStrips]; ++p1, ++p2 )
53  (*p1) = (*p2) = 0;
54 
55  // copy
56  UInt_t smallestIdx = kEEmcNumStrips;
57  UInt_t largestIdx = 0;
58 
59  Bool_t existsStripOverThres = 0;
60 
61  UInt_t stripIdx = 0;
62  for( const EEmcElement_t *strip = stripArray.strip; strip != &stripArray.strip[288]; ++strip, ++stripIdx ){
63  if( !strip->fail && strip->energy ){
64  if( smallestIdx > stripIdx )
65  smallestIdx = stripIdx;
66  if( largestIdx < stripIdx )
67  largestIdx = stripIdx;
68 
69  mStripEnergyArray[ stripIdx ] = strip->energy;
70  mSmoothedEnergyArray[ stripIdx ] = strip->energy;
71 
72  if( strip->energy > mSeedAbsThres )
73  existsStripOverThres = 1;
74  };
75  };
76 
77  if( smallestIdx < largestIdx && existsStripOverThres ){
78  // i.e. there are some strips that do not fail and have non-zero energy
79 
80  // include one extra (empty) strip on either side
81  if( smallestIdx > 0 )
82  --smallestIdx;
83  if( largestIdx < kEEmcNumStrips-1 )
84  ++largestIdx;
85 
86  // make sure not too close to the edge, as then cannot check cluster shape
87  if( smallestIdx < mNumStripsPerSide )
88  smallestIdx = mNumStripsPerSide;
89  if( largestIdx > kEEmcNumStrips-mNumStripsPerSide-1 )
90  largestIdx = kEEmcNumStrips-mNumStripsPerSide-1;
91 
92  // smooth
93  TH1::SmoothArray( kEEmcNumStrips, mSmoothedEnergyArray, mNumSmoothIters );
94 
95  // find largest strip energy and set peek threshold to max of abs and rel thresholds.
96  Double_t thres = mSeedAbsThres;
97  if( mSeedRelThres ){
98  Double_t maxEnergy = *std::max_element( mSmoothedEnergyArray, mSmoothedEnergyArray+kEEmcNumStrips );
99  Double_t newThres = mSeedRelThres*maxEnergy;
100  if( newThres > thres )
101  thres = newThres;
102  };
103 
104  // find all the peeks above threshold and make clusters
105 
106  UInt_t seedPos = smallestIdx;
107  for( Double_t *ePtr = &mSmoothedEnergyArray[smallestIdx]; ePtr != &mSmoothedEnergyArray[largestIdx]; ++ePtr, ++seedPos ){
108  if( *ePtr > thres && *(ePtr-1) < *ePtr && *(ePtr+1) < *ePtr ){
109  // passes energy threshold and part of shape cut
110 
111  // declarations
112  Double_t clusE = *ePtr;
113  Double_t clusPos = seedPos*clusE;
114  Bool_t passes = 1;
115  UInt_t numStrips = 1;
116 
117  // check shape, number of actual strips with energy, and compute energy and position
118 
119  // left side
120  Int_t idx = seedPos - mNumStripsPerSide;
121  for( Double_t *ePtr2 = ePtr-mNumStripsPerSide; ePtr2 < ePtr && passes; ++ePtr2, ++idx ){
122  passes = ( *ePtr2 < *(ePtr2+1) );
123  clusE += *ePtr2;
124  clusPos += *ePtr2 * idx;
125 
126  if( mStripEnergyArray[idx] )
127  ++numStrips;
128  };
129 
130  // right side
131  idx = seedPos + 1;
132  for( Double_t *ePtr2 = ePtr+1; ePtr2 < ePtr+mNumStripsPerSide+1 && passes; ++ePtr2, ++idx ){
133  passes = ( *ePtr2 < *(ePtr2-1) );
134  clusE += *ePtr2;
135  clusPos += *ePtr2 * idx;
136 
137  if( mStripEnergyArray[idx] )
138  ++numStrips;
139  };
140 
141  if( passes && clusE > mMinEnergyPerCluster && numStrips >= mMinStripsPerCluster ){
142  // cluster passes, add a new cluster and set some values
143 
144  clusters.push_back( StSimpleCluster_t( ++mLastClusterID ) );
145  StSimpleCluster_t& clus = clusters.back();
146 
147  // set some values
148  clus.setMeanX( clusPos/clusE );
149  clus.setMeanY( 0 );
150  clus.setEnergy( clusE );
151  clus.setSeedIdx( 0 );
152 
153  // get the array of used (member) strips
154  TArrayS& memArr = clus.getMemberArray();
155  TArrayF& wArr = clus.getWeightArray();
156 
157  memArr.Set( numStrips );
158  wArr.Set( numStrips );
159 
160  // set the seed first
161  memArr[0] = seedPos;
162  wArr[0] = 1;
163 
164  //cout << seedPos << ' ' << mNumStripsPerSide << ' ' << numStrips << endl;
165 
166  // next set the other strips
167  for( UInt_t idx = seedPos - mNumStripsPerSide, i=1; idx <= seedPos + mNumStripsPerSide; ++idx ){
168  if( mStripEnergyArray[idx] && idx != seedPos ){
169  //cout << idx << ' ' << mStripEnergyArray[idx] << ' ' << i << endl;
170 
171  memArr[i] = idx;
172  wArr[i++] = 1;
173  };
174  };
175 
176  }; // adding the cluster
177  }; // potential seeds
178  }; // looping over the energy array
179  }; // non-zero number of valid strips
180 
181  return ierr;
182 };
183 
185 
186 /*
187  * $Id: StEEmcStripClusterFinderTSIU.cxx,v 1.3 2013/02/21 22:00:44 sgliske Exp $
188  * $Log: StEEmcStripClusterFinderTSIU.cxx,v $
189  * Revision 1.3 2013/02/21 22:00:44 sgliske
190  * general update
191  *
192  * Revision 1.2 2013/01/02 20:30:31 sgliske
193  * numStrips >= mMinStripsPerCluster rather than
194  * numStrips > mMinStripsPerCluster
195  *
196  * Revision 1.1 2012/11/26 19:05:55 sgliske
197  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcHitMaker to StRoot/StEEmcPool/StEEmcHitMaker
198  *
199  *
200  */
virtual Int_t find(const ESmdLayer_t &stripArray, StSimpleClusterVec_t &cluster)
find some clusters
Definition: Stypes.h:41