23 #include "StSstUtil/StSstClusterList.hh"
24 #include "StSstUtil/StSstClusterControl.h"
25 #include "StSstUtil/StSstCluster.hh"
26 #include "StSstStripList.hh"
30 StSstClusterList::StSstClusterList()
37 StSstClusterList::~StSstClusterList()
54 {
return ptr->getNextCluster(); }
57 {
return ptr->getPrevCluster(); }
60 {
return mFirstCluster; }
63 {
return mLastCluster; }
70 ptr->setPrevCluster(0);
71 ptr->setNextCluster(0);
77 ptr->setPrevCluster(mLastCluster);
78 ptr->setNextCluster(0);
79 mLastCluster->setNextCluster(ptr);
89 ptr1->copyTo(ptrTemp);
91 ptrTemp->copyTo(ptr2);
95 void StSstClusterList::sortCluster()
97 Int_t localSize=this->getSize();
98 if (localSize<2)
return;
101 ptCurr = this->next(ptCurr);
102 for ( ; ptCurr!=0 ; )
107 while ((ptB1 != this->first())&&(isCont))
109 ptB2 = this->prev(ptB1);
110 if (ptB2->getFirstStrip() > ptB1->getFirstStrip())
112 this->exchangeTwoClusters(ptB1,ptB2);
120 ptCurr = this->next(ptCurr);
126 void StSstClusterList::renumCluster()
128 Int_t CurrentListSize = this->getSize();
129 if (!CurrentListSize)
return;
131 for (Int_t i = 0; i < CurrentListSize; i++)
133 CurrCluster->setNCluster(i);
134 CurrCluster = this->next(CurrCluster);
139 Int_t StSstClusterList::removeCluster(
StSstCluster *ptr)
141 if (!this->getSize())
return 0;
150 this->mFirstCluster = 0;
151 this->mLastCluster = 0;
152 this->mListLength = 0;
158 this->mFirstCluster = ptAfter;
159 ptAfter->setPrevCluster(0);
169 this->mLastCluster = ptBefore;
170 ptBefore->setNextCluster(0);
177 ptBefore->setNextCluster(ptAfter);
178 ptAfter->setPrevCluster(ptBefore);
186 Int_t StSstClusterList::getSize()
187 {
return mListLength; }
191 Int_t CurrentClusterSize = CurrentCluster->getClusterSize();
192 if (CurrentClusterSize<3)
return 0;
193 Int_t nSubCluster = 0;
194 Int_t isClimbOrFall = 0;
196 Float_t testTolerance = clusterControl->getTestTolerance();
197 std::vector<int> minima(CurrentClusterSize,0);
198 std::vector<int> maxima(CurrentClusterSize,0);
199 std::vector<int> keyToIdStrip(CurrentClusterSize,0);
204 keyToIdStrip[0] = CurrentCluster->getFirstStrip();
206 for(iStrip = 1; iStrip<CurrentClusterSize; iStrip++)
208 keyToIdStrip[iStrip] = keyToIdStrip[iStrip-1]+1;
213 for (iStrip = 0; iStrip<CurrentClusterSize-1; iStrip++)
215 if (ListAdc[iStrip]<ListAdc[iStrip+1])
217 if ((isClimbOrFall == -1) || (isClimbOrFall == 0))
220 minima[nMinima] = iStrip;
223 if ((isClimbOrFall == 1) && (iStrip+2 == CurrentClusterSize))
225 maxima[nMaxima] = iStrip+1;
229 if (ListAdc[iStrip]>ListAdc[iStrip+1])
231 if ((isClimbOrFall == 1) || (isClimbOrFall == 0))
234 maxima[nMaxima] = iStrip;
237 if ((isClimbOrFall == -1) && (iStrip+2 == CurrentClusterSize))
239 minima[nMinima] = iStrip+1;
246 if(maxima.size()>0) maxima.clear();
247 if(minima.size()>0) minima.clear();
248 if(keyToIdStrip.size()>0) keyToIdStrip.clear();
254 Int_t localFirstStrip = CurrentCluster->getFirstStrip();
256 Int_t strip_offset = 0;
257 Int_t strip_diff = 0;
258 for (iMaxima = 0; iMaxima<nMaxima-1 ; iMaxima++)
260 maxLeft = maxima[iMaxima];
261 maxRight = maxima[iMaxima+1];
263 while (!(minima[iMinima]>maxLeft && minima[iMinima]<maxRight) && iMinima<nMinima) iMinima++;
265 if (iMinima == nMinima)
267 cout<<
"Big Bug in StSstClusterList -> I do not find any minima between the two maxima !"<<endl;
273 Int_t iStripLeft = minima[iMinima]-1;
274 Int_t iStripRight = minima[iMinima]+1;
278 Int_t nStripInTheGroup = 1;
279 Float_t meanAdc = (float)ListAdc[minima[iMinima]];
280 localFirstStrip = CurrentCluster->getFirstStrip()+strip_offset;
285 if (fabs(((
float)ListAdc[iStripLeft]-meanAdc)/meanAdc)<testTolerance)
287 if (iStripLeft > maxLeft)
297 if (fabs(((
float)ListAdc[iStripRight]-meanAdc)/meanAdc)<testTolerance)
299 if (iStripRight < maxRight)
310 if ((!addLeft)&&(!addRight)) theEnd =1;
313 meanAdc = (((float)nStripInTheGroup)*meanAdc + (float)ListAdc[iStripLeft])/((float)(nStripInTheGroup+1));
320 meanAdc = (((float)nStripInTheGroup)*meanAdc + (float)ListAdc[iStripRight])/((float)(nStripInTheGroup+1));
329 if (nStripInTheGroup%2==0)
332 newCluster->setFlag(1);
333 Int_t currentStrip = localFirstStrip;
334 for (currentStrip = localFirstStrip; currentStrip<=(keyToIdStrip[iStripLeft]+(nStripInTheGroup/2)); currentStrip++)
336 newCluster->update(currentStripList->getStrip(currentStrip),weight);
338 localFirstStrip=currentStrip+1;
341 this->addNewCluster(newCluster);
346 newCluster->setFlag(1);
347 Int_t currentStrip = localFirstStrip;
348 for (currentStrip = localFirstStrip; currentStrip<=(keyToIdStrip[iStripLeft]+(int)(nStripInTheGroup/2)); currentStrip++)
350 newCluster->update(currentStripList->getStrip(currentStrip),weight);
352 localFirstStrip=currentStrip+1;
356 newCluster->update(currentStripList->getStrip(localFirstStrip),weight);
357 this->addNewCluster(newCluster);
361 strip_offset = strip_diff;
367 newCluster->setFlag(1);
368 Int_t currentStrip = localFirstStrip;
369 for (currentStrip = localFirstStrip; currentStrip<(CurrentCluster->getFirstStrip()+CurrentCluster->getClusterSize()); currentStrip++)
371 newCluster->update(currentStripList->getStrip(currentStrip),weight);
374 this->addNewCluster(newCluster);
377 if(maxima.size()>0) maxima.clear();
378 if(minima.size()>0) minima.clear();
379 if(keyToIdStrip.size()>0) keyToIdStrip.clear();
384 Int_t StSstClusterList::isSorted()
389 while(ptr1 != this->last())
391 ptr2 = this->next(ptr1);
392 if (ptr1->getFirstStrip()>ptr2->getFirstStrip())
return 0;
393 ptr1 = this->next(ptr1);
398 StSstClusterList::StSstClusterList(
const StSstClusterList & originalClusterList)
400 mListLength = originalClusterList.mListLength;
401 mFirstCluster = originalClusterList.mFirstCluster;
402 mLastCluster = originalClusterList.mLastCluster;
407 mListLength = originalClusterList.mListLength;
408 mFirstCluster = originalClusterList.mFirstCluster;
409 mLastCluster = originalClusterList.mLastCluster;