StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcStripClusterFinderMorhac.cxx
1 
9 #include <list>
10 #include <TMath.h>
11 #include <TH1.h>
12 
13 #include "StRoot/St_base/StMessMgr.h"
14 #include "StRoot/St_base/Stypes.h"
15 
16 #include "StEEmcStripClusterFinderMorhac.h"
17 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
18 
19 //#define DEBUG
20 //#define DEBUG2
21 //#define DEBUG3
22 
23 StEEmcStripClusterFinderMorhac_t::StEEmcStripClusterFinderMorhac_t( Int_t maxNumPoints, Float_t resolution ) :
24  mRemoveBkg( 1 ),
25  mDoMarkov( 1 ),
26  mMaxNumPoints( maxNumPoints ),
27  mMinStripsPerCluster( 5 ),
28  mNumDeconIters( 3 ),
29  mAverWindow( 3 ),
30  mNumSmoothIters( 10 ),
31  mWidth( 3 ),
32  mThreshold( 5 ),
33  mMinPeakEnergy( 0.01 ),
34  mMinClusterEnergy( 0.01 )
35 {
36  peakFinderPtr = new TSpectrum( maxNumPoints, resolution );
37 
38  // initialize a few parent variables
39  mLayer = U_LAYER;
40  mSector = 0;
41  mIsReady = 1;
42 };
43 
44 StEEmcStripClusterFinderMorhac_t::~StEEmcStripClusterFinderMorhac_t(){
45  delete peakFinderPtr;
46 };
47 
48 
50 Int_t StEEmcStripClusterFinderMorhac_t::find( const ESmdLayer_t& stripArray, StSimpleClusterVec_t& clusters ){
51  clusters.clear();
52  Int_t ierr = kStOk;
53 
54  if( mThreshold > 100 ){
55  LOG_WARN << "Must specificy a threshold below 100. Resetting to 99.9" << endm;
56  mThreshold = 99.9;
57  };
58 
59  if( mThreshold <= 0 ){
60  LOG_WARN << "Must specificy a positive threshold. Resetting to 1" << endm;
61  mThreshold = 1;
62  };
63 
64  // skip if not enough strips hit
65  if( stripArray.nStrips < mMinStripsPerCluster )
66  return ierr;
67 
68  // clear array
69  for( Float_t *p = mStripEnergyArray, *p2 = mSmoothedEnergyArray; p != &mStripEnergyArray[kEEmcNumStrips]; ++p, ++p2 )
70  (*p) = (*p2) = 0;
71 
72  // copy
73  Int_t stripIdx = 0;
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;
78 
79 #ifdef DEBUG_INPUT
80  cout << "ccc " << iter->index() << ' ' << iter->energy() << endl;
81 #endif
82  };
83  };
84 
85  // copied from TSpectrum::Search function, so set OK sigma
86  Float_t sigma = mWidth;
87  if( mWidth < 1 ) {
88  sigma = kEEmcNumStrips/mMaxNumPoints;
89  if (sigma < 1)
90  sigma = 1;
91  if (sigma > 8)
92  sigma = 8;
93  };
94 
95  // smooth, if requested
96  if( mNumSmoothIters ){
97  Float_t *fPtr;
98  Double_t *dPtr;
99 
100  // copy
101  for( fPtr = mSmoothedEnergyArray, dPtr = mStripEnergyArrayTemp; fPtr != &mSmoothedEnergyArray[kEEmcNumStrips]; ++fPtr, ++dPtr )
102  (*dPtr) = (*fPtr);
103 
104  // smooth
105  TH1::SmoothArray( kEEmcNumStrips, mStripEnergyArrayTemp, mNumSmoothIters );
106 
107  // copy back
108  for( fPtr = mSmoothedEnergyArray, dPtr = mStripEnergyArrayTemp; fPtr != &mSmoothedEnergyArray[kEEmcNumStrips]; ++fPtr, ++dPtr )
109  (*fPtr) = (*dPtr);
110 
111  // std::copy( mStripEnergyArrayTemp, mStripEnergyArrayTemp+kEEmcNumStrips, mSmoothedEnergyArray );
112  };
113 
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 );
117 #else
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 );
124 #endif
125 
126 #ifdef DEBUG
127  LOG_INFO << getEventNum() << " sector " << mSector << " layer " << mLayer << " found " << nPeaks << " peaks." << endm;
128 #endif
129 
130  // assign strips to nearest peak
131  // should do this more intelligently in the future
132 
133 #ifdef DEBUG4
134  if( nPeaks ){
135  Float_t *peakX = peakFinderPtr->GetPositionX();
136  Float_t *peakY = peakFinderPtr->GetPositionY();
137 
138  LOG_INFO << "Morhac results" << endm;
139  for( Int_t i=0; i<nPeaks; ++i ){
140  LOG_INFO << peakX[i] << ' ' << peakY[i] << endm;
141  };
142  };
143 #endif
144 
145  std::vector< Float_t > peakPos;
146  if( nPeaks ){
147 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
148  Float_t *peakPosRAW = peakFinderPtr->GetPositionX();
149 #else
150  Double_t *peakPosRAW = peakFinderPtr->GetPositionX();
151 #endif
152  peakPos.reserve( nPeaks );
153 
154  // estimate energy of peak strip and its adjacent neighbors
155  for( Int_t i=0; i<nPeaks; ++i ){
156  Int_t idx = peakPosRAW[i]+0.5;
157  Float_t energy = mStripEnergyArray[ idx ];
158  if( idx )
159  energy += mStripEnergyArray[ idx-1 ];
160  if( idx+1 < kEEmcNumStrips )
161  energy += mStripEnergyArray[ idx+1 ];
162 
163  if( energy > mMinPeakEnergy )
164  peakPos.push_back( peakPosRAW[i] );
165 
166 #ifdef DEBUG3
167  LOG_INFO << "Morhac peak " << i << " at " << peakPosRAW[i] << ' ' << energy << endm;
168 #endif
169  };
170  nPeaks = peakPos.size();
171  };
172 
173  if( nPeaks ){
174  // rename for the sort
175  std::vector< Float_t >& sortedPeakPos = peakPos;
176  std::sort( sortedPeakPos.begin(), sortedPeakPos.end() );
177 
178  std::vector< Float_t > midPoints;
179  midPoints.reserve( nPeaks - 1 );
180 
181  clusters.reserve( nPeaks );
182  std::vector< Int_t > stripsPerClus;
183  stripsPerClus.reserve( kEEmcNumStrips );
184 
185  for( Int_t i=0; i<nPeaks; ++i ){
186  stripsPerClus.clear();
187 
188  clusters.push_back( StSimpleCluster_t( ++mLastClusterID ) );
189  StSimpleCluster_t& clus = clusters.back();
190  clus.setMeanX( sortedPeakPos[i] );
191 
192  Float_t pos1 = 0, pos2 = kEEmcNumStrips;
193  if( i != 0 )
194  pos1 = 0.5*(sortedPeakPos[i-1] + sortedPeakPos[i]) + 0.5;
195  if( i != nPeaks-1 )
196  pos2 = 0.5*(sortedPeakPos[i+1] + sortedPeakPos[i]) + 0.5;
197 
198  Float_t energy = 0;
199  for( Int_t i=pos1; i<pos2; ++i )
200  if( mStripEnergyArray[i] ){
201  stripsPerClus.push_back( i );
202  energy += mStripEnergyArray[i];
203  };
204 
205  Int_t n = stripsPerClus.size();
206 
207 #ifdef DEBUG2
208  LOG_INFO << "Number of strips " << n << " vs " << mMinStripsPerCluster << " energy " << energy << " vs " << mMinClusterEnergy << endm;
209 #endif
210 
211  if( n >= mMinStripsPerCluster && energy > mMinClusterEnergy ){
212  TArrayS& memArr = clus.getMemberArray();
213  TArrayF& wArr = clus.getWeightArray();
214 
215  memArr.Set( n );
216  wArr.Set( n );
217 
218  Float_t maxStripE = 0;
219  Int_t seedIdx = -1;
220 
221  for( Int_t i = 0; i < n; ++i ){
222  Int_t idx = stripsPerClus.back();
223  stripsPerClus.pop_back();
224 
225  memArr[i] = idx;
226  wArr[i] = 1;
227 
228  const Float_t& thisE = mStripEnergyArray[ idx ];
229  if( thisE > maxStripE ){
230  maxStripE = thisE;
231  seedIdx = i;
232  };
233  };
234 
235  clus.setEnergy( energy );
236  clus.setSeedIdx( seedIdx );
237 
238 #ifdef DEBUG
239  LOG_INFO << "Final results: event " << getEventNum() << " sector/layer " << mSector << '/'
240  << (mLayer ? 'v' : 'u') << ' ' << clus << endm;
241 #endif
242 
243  } else {
244  clusters.pop_back();
245  };
246  };
247  };
248 
249  return ierr;
250 };
251 
253 
254 /*
255  * $Id: StEEmcStripClusterFinderMorhac.cxx,v 1.1 2012/11/26 19:05:55 sgliske Exp $
256  * $Log: StEEmcStripClusterFinderMorhac.cxx,v $
257  * Revision 1.1 2012/11/26 19:05:55 sgliske
258  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcHitMaker to StRoot/StEEmcPool/StEEmcHitMaker
259  *
260  *
261  */
virtual Int_t find(const ESmdLayer_t &stripArray, StSimpleClusterVec_t &cluster)
find some clusters
Definition: Stypes.h:41