15 #include "StRoot/St_base/StMessMgr.h"
18 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
20 #include "StEEmcStripClusterFinderIU.h"
21 #include "StSimpleCluster.h"
22 #include "StFinderAlg.h"
26 mIgnoreCorners( true ),
27 mUseNaiveFloorShape( true ),
28 mApplyClusterSplitting( 1 ),
30 mMinStripsPerCluster( 3 ),
31 mMinSeedDistance( 3 ),
33 mNeedsToBeCleared( 1 )
35 mSeedEnergyThres[ U_LAYER ] = 0.003;
36 mSeedEnergyThres[ V_LAYER ] = 0.003;
42 void StEEmcStripClusterFinderIU_t::setMaxExtent( Int_t maxExtent ){
43 mMaxExtent = maxExtent;
46 LOG_WARN <<
"StEEmcStripClusterFinderIU_t::setMaxExtent" << endm;
47 LOG_WARN <<
"\t maxExtent must be >= 2, not " << maxExtent << endm;
48 LOG_WARN <<
"\t defaulting to minimum: maxExtent = 2" << endm;
53 void StEEmcStripClusterFinderIU_t::setMinStripsPerCluster( Int_t min ){
54 mMinStripsPerCluster = min;
56 if( mMinStripsPerCluster < 2 ){
57 LOG_WARN <<
"StEEmcStripClusterFinderIU_t::setMinStripsPerCluster" << endm;
58 LOG_WARN <<
"\t MinStripsPerCluster must be >= 1, not " << mMinStripsPerCluster << endm;
59 LOG_WARN <<
"\t setting to default value of 3" << endm;
60 mMinStripsPerCluster = 3;
66 if( mNeedsToBeCleared ){
69 for( Int_t i = 0; i < kEEmcNumStrips; ++i ){
70 mClosestClusterIDForEachStrip[i] = -i-1;
71 mFirstClusterIDForEachStrip[i] = -i-1;
75 for( Float_t *f_ptr = mSeedFloorArray; f_ptr != mSeedFloorArray + kEEmcNumStrips; ++f_ptr )
78 mNeedsToBeCleared = 0;
85 if( mNeedsToBeCleared ){
93 if( stripArray.nStrips < mMinStripsPerCluster )
99 double floorParam1 = 0;
100 double floorParam2 = 0;
102 if( mSector == 0 || mSector == 3 || mSector == 6 || mSector == 9 ){
103 if( mLayer == U_LAYER ){
111 if( mLayer == U_LAYER ){
125 mNeedsToBeCleared = 1;
129 vector< const EEmcElement_t* > seedStrips;
138 for(
const EEmcElement_t *strip = &stripArray.strip[index]; strip != &stripArray.strip[283]; ++strip, ++index ){
142 Float_t threshold = mSeedEnergyThres[ mLayer ];
144 threshold += mSeedFloor*mSeedFloorArray[ index ];
148 if( !strip->fail && strip->energy > threshold ){
150 seedStrips.push_back( strip );
155 if( mUseNaiveFloorShape ){
158 for ( Int_t i = 0; i < 288; ++i ){
159 Int_t delta = (i > index ? i-index : index-i);
163 mSeedFloorArray[i] += strip->energy;
166 if( delta >= 3 && delta < 5 )
167 mSeedFloorArray[i] += floorParam1*strip->energy;
170 if( delta >= 5 && delta < 11 )
171 mSeedFloorArray[i] += floorParam2*strip->energy;
174 if( delta >= 11 && delta < 21 )
175 mSeedFloorArray[i] += 0.05*strip->energy;
181 Int_t imin = ( index -6 < 0 ? 0 : index - 6 );
182 Int_t imax = ( index + 6 > kEEmcNumStrips ? kEEmcNumStrips : index + 6 );
184 for( Int_t i = imin; i <= imax; ++i ){
187 if ( TMath::Abs(index-i) < 7 )
188 if ( 0.05*strip->energy > mSeedFloorArray[i] )
189 mSeedFloorArray[i] += 0.05*strip->energy;
205 std::sort( seedStrips.begin(), seedStrips.end(), energyGreaterThan );
208 vector< const EEmcElement_t* >::iterator seedStripIter = seedStrips.begin();
209 for( ; seedStripIter != seedStrips.end(); ++seedStripIter ){
210 Int_t index =
static_cast< Int_t
>( (*seedStripIter) - stripArray.strip );
218 if( mClosestClusterIDForEachStrip[ index ] > -1 ){
225 while( i < (Int_t)clusterVec.size() - 1 && !found ){
226 found = (clusterVec[++i].getID() == mClosestClusterIDForEachStrip[ index ] );
232 LOG_WARN <<
"a) Error finding cluster with ID " << mClosestClusterIDForEachStrip[ index ] << endm;
234 Int_t delta = TMath::Abs( index - clusterVec[i].getSeedMember() );
235 ok_seed = ( delta > mMinSeedDistance );
239 if( clusterVec[i].getSeedIdx() > 10 ){
240 LOG_FATAL <<
"Something wierd is going on" << endm;
252 Int_t max = index + mMaxExtent;
253 Int_t min = index - mMaxExtent;
258 if( max > kEEmcNumStrips )
259 max = kEEmcNumStrips;
262 Int_t nStripsInClus = 0;
265 for( Int_t i = min; i <= max; ++i )
266 if( stripArray.strip[i].energy && !stripArray.strip[i].fail )
270 if( nStripsInClus >= mMinStripsPerCluster ){
283 cluster.setEnergy( -999 );
286 TArrayS &member = cluster.getMemberArray();
287 TArrayF &weight = cluster.getWeightArray();
288 member.Set( nStripsInClus );
289 weight.Set( nStripsInClus );
292 Int_t member_idx = -1;
295 member[ ++member_idx ] = index;
296 weight[ member_idx ] = 1;
297 cluster.setSeedIdx( 0 );
304 for( Int_t i = min; i <= max; ++i ){
307 if( i != index && stripArray.strip[i].energy > 0 && !stripArray.strip[i].fail ){
311 member[ ++member_idx ] = i;
312 weight[ member_idx ] = 1;
318 if( mFirstClusterIDForEachStrip[ i ] < 0 ){
320 mFirstClusterIDForEachStrip[ i ] = cluster.getID();
321 mClosestClusterIDForEachStrip[ i ] = cluster.getID();
329 while( j < (Int_t)clusterVec.size() - 1 && !found )
330 found = (clusterVec[++j].getID() == mClosestClusterIDForEachStrip[ i ] );
334 LOG_WARN <<
"b) Error finding cluster with ID " << mClosestClusterIDForEachStrip[ i ] << endm;
337 mClosestClusterIDForEachStrip[ i ] = cluster.getID();
339 Int_t delta_other = TMath::Abs( i - clusterVec[j].getSeedMember() );
340 Int_t delta_this = TMath::Abs( i - cluster.getSeedMember() );
342 if( delta_this < delta_other ){
344 mClosestClusterIDForEachStrip[ i ] = cluster.getID();
363 if( mApplyClusterSplitting ){
368 StSimpleClusterVec_t::iterator clusIter1 = clusterVec.begin();
369 StSimpleClusterVec_t::iterator clusIter2;
371 for( clusIter1 = clusterVec.begin(); clusIter1 != clusterVec.end(); ++clusIter1 ){
372 for( clusIter2 = clusterVec.begin(); clusIter2 < clusIter1; ++clusIter2 ){
380 if( leftClusPtr->getSeedMember() > rightClusPtr->getSeedMember() ){
382 rightClusPtr = &(*clusIter2);
383 leftClusPtr = &(*clusIter1);
387 if( rightClusPtr->getSeedMember() - leftClusPtr->getSeedMember() <= 2*mMaxExtent ){
391 Int_t leftSeedIdx = leftClusPtr->getSeedMember();
392 Int_t rightSeedIdx = rightClusPtr->getSeedMember();
398 Float_t leftEnergy = stripArray.strip[ leftSeedIdx ].energy;
399 Float_t rightEnergy = stripArray.strip[ rightSeedIdx ].energy;
407 TArrayS leftMember = leftClusPtr->getMemberArray();
409 for( Int_t tempIdx = leftMember[ i ]; tempIdx < leftSeedIdx && i < leftMember.GetSize()-1; tempIdx = leftMember[++i] )
410 leftEnergy += stripArray.strip[ tempIdx ].energy;
417 TArrayS rightMember = rightClusPtr->getMemberArray();
418 Int_t i = rightMember.GetSize()-1;
419 for( Int_t tempIdx = rightMember[ i ]; tempIdx > rightSeedIdx && i >-1; tempIdx = rightMember[--i] )
420 rightEnergy += stripArray.strip[ tempIdx ].energy;
439 if( stripArray.strip[ lowerClusPtr->getSeedMember() ].energy >
440 stripArray.strip[ higherClusPtr->getSeedMember() ].energy ){
443 higherClusPtr = &(*clusIter2);
444 lowerClusPtr = &(*clusIter1);
448 TArrayS &lowerMemberArray = lowerClusPtr->getMemberArray();
449 TArrayF &lowerWeightArray = lowerClusPtr->getWeightArray();
450 TArrayS &higherMemberArray = higherClusPtr->getMemberArray();
451 TArrayF &higherWeightArray = higherClusPtr->getWeightArray();
454 Float_t sumOfEnergy = leftEnergy + rightEnergy;
455 Float_t lowerWeight = ( lowerClusPtr == leftClusPtr ? leftEnergy : rightEnergy ) / sumOfEnergy;
456 Float_t higherWeight = ( lowerClusPtr == leftClusPtr ? rightEnergy : leftEnergy ) / sumOfEnergy;
461 for( Int_t i=0; i<lowerMemberArray.GetSize(); ++i ){
465 if( mFirstClusterIDForEachStrip[ lowerMemberArray[i] ] == higherClusPtr->getID() ){
467 lowerWeightArray[i] = lowerWeight;
471 mFirstClusterIDForEachStrip[ lowerMemberArray[i] ] = lowerClusPtr->getID();
480 for( Int_t i=0; i<higherMemberArray.GetSize(); ++i ){
484 if( mFirstClusterIDForEachStrip[ higherMemberArray[i] ] == lowerClusPtr->getID() ){
486 higherWeightArray[i] = higherWeight;
489 mFirstClusterIDForEachStrip[ higherMemberArray[i] ] = higherClusPtr->getID();
513 StSimpleClusterVec_t::iterator clusIter = clusterVec.begin();
516 for( clusIter = clusterVec.begin(); clusIter != clusterVec.end() && !ierr; ++clusIter ){
521 TArrayS &memberArray = clusIter->getMemberArray();
522 TArrayF &weightArray = clusIter->getWeightArray();
524 if( memberArray.GetSize() != weightArray.GetSize() ){
525 LOG_FATAL <<
"SANITY CHECK FAILURE IN StEEmcStripClusterFinderIU.cxx, line " << __LINE__ << endm;
532 for( Int_t i = 0; i < memberArray.GetSize(); ++i ){
533 Float_t stripE = stripArray.strip[ memberArray[ i ] ].energy;
534 if( stripE > 0 && !stripArray.strip[ memberArray[ i ] ].fail ){
536 Float_t thisE = weightArray[i]*stripE;
538 mean += memberArray[i] * thisE;
545 clusIter->setEnergy( E );
546 clusIter->setMeanX( E > 0 ? mean/E : memberArray[ 0 ] + 0.5 );
555 return s1->energy > s2->energy;
virtual void clear()
clear between events
virtual Int_t find(const ESmdLayer_t &smdLayer, StSimpleClusterVec_t &cluster)
find some clusters
StEEmcStripClusterFinderIU_t()
constructor