13 #include "StRoot/St_base/StMessMgr.h"
16 #include "StEEmcStripClusterFinderMorhac.h"
17 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
23 StEEmcStripClusterFinderMorhac_t::StEEmcStripClusterFinderMorhac_t( Int_t maxNumPoints, Float_t resolution ) :
26 mMaxNumPoints( maxNumPoints ),
27 mMinStripsPerCluster( 5 ),
30 mNumSmoothIters( 10 ),
33 mMinPeakEnergy( 0.01 ),
34 mMinClusterEnergy( 0.01 )
36 peakFinderPtr =
new TSpectrum( maxNumPoints, resolution );
44 StEEmcStripClusterFinderMorhac_t::~StEEmcStripClusterFinderMorhac_t(){
54 if( mThreshold > 100 ){
55 LOG_WARN <<
"Must specificy a threshold below 100. Resetting to 99.9" << endm;
59 if( mThreshold <= 0 ){
60 LOG_WARN <<
"Must specificy a positive threshold. Resetting to 1" << endm;
65 if( stripArray.nStrips < mMinStripsPerCluster )
69 for( Float_t *p = mStripEnergyArray, *p2 = mSmoothedEnergyArray; p != &mStripEnergyArray[kEEmcNumStrips]; ++p, ++p2 )
74 for(
const EEmcElement_t *strip = stripArray.strip; strip != &stripArray.strip[288]; ++strip, ++stripIdx ){
75 if( !strip->fail && strip->energy ){
76 mStripEnergyArray[ stripIdx ] = strip->energy;
77 mSmoothedEnergyArray[ stripIdx ] = strip->energy;
80 cout <<
"ccc " << iter->index() <<
' ' << iter->energy() << endl;
86 Float_t sigma = mWidth;
88 sigma = kEEmcNumStrips/mMaxNumPoints;
96 if( mNumSmoothIters ){
101 for( fPtr = mSmoothedEnergyArray, dPtr = mStripEnergyArrayTemp; fPtr != &mSmoothedEnergyArray[kEEmcNumStrips]; ++fPtr, ++dPtr )
105 TH1::SmoothArray( kEEmcNumStrips, mStripEnergyArrayTemp, mNumSmoothIters );
108 for( fPtr = mSmoothedEnergyArray, dPtr = mStripEnergyArrayTemp; fPtr != &mSmoothedEnergyArray[kEEmcNumStrips]; ++fPtr, ++dPtr )
114 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
115 Int_t nPeaks = peakFinderPtr->SearchHighRes( mSmoothedEnergyArray, mDeconvoluted, kEEmcNumStrips, sigma,
116 mThreshold, mRemoveBkg, mNumDeconIters, mDoMarkov, mAverWindow );
118 Double_t mSmoothedEnergyArrayD[kEEmcNumStrips];
119 Double_t mDeconvolutedD[kEEmcNumStrips];
120 std::copy(mSmoothedEnergyArray, mSmoothedEnergyArray + kEEmcNumStrips, mSmoothedEnergyArrayD);
121 std::copy(mDeconvoluted, mDeconvoluted + kEEmcNumStrips, mDeconvolutedD);
122 Int_t nPeaks = peakFinderPtr->SearchHighRes( mSmoothedEnergyArrayD, mDeconvolutedD, kEEmcNumStrips, sigma,
123 mThreshold, mRemoveBkg, mNumDeconIters, mDoMarkov, mAverWindow );
127 LOG_INFO << getEventNum() <<
" sector " << mSector <<
" layer " << mLayer <<
" found " << nPeaks <<
" peaks." << endm;
135 Float_t *peakX = peakFinderPtr->GetPositionX();
136 Float_t *peakY = peakFinderPtr->GetPositionY();
138 LOG_INFO <<
"Morhac results" << endm;
139 for( Int_t i=0; i<nPeaks; ++i ){
140 LOG_INFO << peakX[i] <<
' ' << peakY[i] << endm;
145 std::vector< Float_t > peakPos;
147 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
148 Float_t *peakPosRAW = peakFinderPtr->GetPositionX();
150 Double_t *peakPosRAW = peakFinderPtr->GetPositionX();
152 peakPos.reserve( nPeaks );
155 for( Int_t i=0; i<nPeaks; ++i ){
156 Int_t idx = peakPosRAW[i]+0.5;
157 Float_t energy = mStripEnergyArray[ idx ];
159 energy += mStripEnergyArray[ idx-1 ];
160 if( idx+1 < kEEmcNumStrips )
161 energy += mStripEnergyArray[ idx+1 ];
163 if( energy > mMinPeakEnergy )
164 peakPos.push_back( peakPosRAW[i] );
167 LOG_INFO <<
"Morhac peak " << i <<
" at " << peakPosRAW[i] <<
' ' << energy << endm;
170 nPeaks = peakPos.size();
175 std::vector< Float_t >& sortedPeakPos = peakPos;
176 std::sort( sortedPeakPos.begin(), sortedPeakPos.end() );
178 std::vector< Float_t > midPoints;
179 midPoints.reserve( nPeaks - 1 );
181 clusters.reserve( nPeaks );
182 std::vector< Int_t > stripsPerClus;
183 stripsPerClus.reserve( kEEmcNumStrips );
185 for( Int_t i=0; i<nPeaks; ++i ){
186 stripsPerClus.clear();
190 clus.setMeanX( sortedPeakPos[i] );
192 Float_t pos1 = 0, pos2 = kEEmcNumStrips;
194 pos1 = 0.5*(sortedPeakPos[i-1] + sortedPeakPos[i]) + 0.5;
196 pos2 = 0.5*(sortedPeakPos[i+1] + sortedPeakPos[i]) + 0.5;
199 for( Int_t i=pos1; i<pos2; ++i )
200 if( mStripEnergyArray[i] ){
201 stripsPerClus.push_back( i );
202 energy += mStripEnergyArray[i];
205 Int_t n = stripsPerClus.size();
208 LOG_INFO <<
"Number of strips " << n <<
" vs " << mMinStripsPerCluster <<
" energy " << energy <<
" vs " << mMinClusterEnergy << endm;
211 if( n >= mMinStripsPerCluster && energy > mMinClusterEnergy ){
212 TArrayS& memArr = clus.getMemberArray();
213 TArrayF& wArr = clus.getWeightArray();
218 Float_t maxStripE = 0;
221 for( Int_t i = 0; i < n; ++i ){
222 Int_t idx = stripsPerClus.back();
223 stripsPerClus.pop_back();
228 const Float_t& thisE = mStripEnergyArray[ idx ];
229 if( thisE > maxStripE ){
235 clus.setEnergy( energy );
236 clus.setSeedIdx( seedIdx );
239 LOG_INFO <<
"Final results: event " << getEventNum() <<
" sector/layer " << mSector <<
'/'
240 << (mLayer ?
'v' :
'u') <<
' ' << clus << endm;
virtual Int_t find(const ESmdLayer_t &stripArray, StSimpleClusterVec_t &cluster)
find some clusters