14 #include "StSsdUtil/StSsdClusterList.hh"
15 #include "StSsdUtil/StSsdClusterControl.h"
16 #include "StSsdUtil/StSsdCluster.hh"
17 #include "StSsdStripList.hh"
21 StSsdClusterList::StSsdClusterList()
28 StSsdClusterList::~StSsdClusterList()
45 {
return ptr->getNextCluster(); }
48 {
return ptr->getPrevCluster(); }
51 {
return mFirstCluster; }
54 {
return mLastCluster; }
61 ptr->setPrevCluster(0);
62 ptr->setNextCluster(0);
68 ptr->setPrevCluster(mLastCluster);
69 ptr->setNextCluster(0);
70 mLastCluster->setNextCluster(ptr);
80 ptr1->copyTo(ptrTemp);
82 ptrTemp->copyTo(ptr2);
86 void StSsdClusterList::sortCluster()
88 Int_t localSize=this->getSize();
89 if (localSize<2)
return;
92 ptCurr = this->next(ptCurr);
98 while ((ptB1 != this->first())&&(isCont))
100 ptB2 = this->prev(ptB1);
101 if (ptB2->getFirstStrip() > ptB1->getFirstStrip())
103 this->exchangeTwoClusters(ptB1,ptB2);
111 ptCurr = this->next(ptCurr);
117 void StSsdClusterList::renumCluster()
119 Int_t CurrentListSize = this->getSize();
120 if (!CurrentListSize)
return;
122 for (Int_t i = 0; i < CurrentListSize; i++)
124 CurrCluster->setNCluster(i);
125 CurrCluster = this->next(CurrCluster);
130 Int_t StSsdClusterList::removeCluster(
StSsdCluster *ptr)
132 if (!this->getSize())
return 0;
141 this->mFirstCluster = 0;
142 this->mLastCluster = 0;
143 this->mListLength = 0;
149 this->mFirstCluster = ptAfter;
150 ptAfter->setPrevCluster(0);
160 this->mLastCluster = ptBefore;
161 ptBefore->setNextCluster(0);
168 ptBefore->setNextCluster(ptAfter);
169 ptAfter->setPrevCluster(ptBefore);
177 Int_t StSsdClusterList::getSize()
178 {
return mListLength; }
182 Int_t CurrentClusterSize = CurrentCluster->getClusterSize();
183 if (CurrentClusterSize<3)
return 0;
184 Int_t nSubCluster = 0;
185 Int_t isClimbOrFall = 0;
187 Float_t testTolerance = clusterControl->getTestTolerance();
188 Int_t *minima =
new int[CurrentClusterSize];
189 Int_t *maxima =
new int[CurrentClusterSize];
190 Int_t *keyToIdStrip =
new int[CurrentClusterSize];
195 keyToIdStrip[0] = CurrentCluster->getFirstStrip();
197 for(iStrip = 1; iStrip<CurrentClusterSize; iStrip++)
199 keyToIdStrip[iStrip] = keyToIdStrip[iStrip-1]+1;
202 for(iStrip = 0; iStrip<CurrentClusterSize; iStrip++)
209 for (iStrip = 0; iStrip<CurrentClusterSize-1; iStrip++)
211 if (ListAdc[iStrip]<ListAdc[iStrip+1])
213 if ((isClimbOrFall == -1) || (isClimbOrFall == 0))
216 minima[nMinima] = iStrip;
219 if ((isClimbOrFall == 1) && (iStrip+2 == CurrentClusterSize))
221 maxima[nMaxima] = iStrip+1;
225 if (ListAdc[iStrip]>ListAdc[iStrip+1])
227 if ((isClimbOrFall == 1) || (isClimbOrFall == 0))
230 maxima[nMaxima] = iStrip;
233 if ((isClimbOrFall == -1) && (iStrip+2 == CurrentClusterSize))
235 minima[nMinima] = iStrip+1;
245 delete [] keyToIdStrip;
251 Int_t localFirstStrip = CurrentCluster->getFirstStrip();
253 Int_t strip_offset = 0;
254 Int_t strip_diff = 0;
255 for (iMaxima = 0; iMaxima<nMaxima-1 ; iMaxima++)
257 maxLeft = maxima[iMaxima];
258 maxRight = maxima[iMaxima+1];
260 while (!(minima[iMinima]>maxLeft && minima[iMinima]<maxRight) && iMinima<nMinima) iMinima++;
262 if (iMinima == nMinima)
264 cout<<
"Big Bug in StSsdClusterList -> I do not find any minima between the two maxima !"<<endl;
270 Int_t iStripLeft = minima[iMinima]-1;
271 Int_t iStripRight = minima[iMinima]+1;
275 Int_t nStripInTheGroup = 1;
276 Float_t meanAdc = (float)ListAdc[minima[iMinima]];
277 localFirstStrip = CurrentCluster->getFirstStrip()+strip_offset;
282 if (fabs(((
float)ListAdc[iStripLeft]-meanAdc)/meanAdc)<testTolerance)
284 if (iStripLeft > maxLeft)
294 if (fabs(((
float)ListAdc[iStripRight]-meanAdc)/meanAdc)<testTolerance)
296 if (iStripRight < maxRight)
307 if ((!addLeft)&&(!addRight)) theEnd =1;
310 meanAdc = (((float)nStripInTheGroup)*meanAdc + (float)ListAdc[iStripLeft])/((float)(nStripInTheGroup+1));
317 meanAdc = (((float)nStripInTheGroup)*meanAdc + (float)ListAdc[iStripRight])/((float)(nStripInTheGroup+1));
328 if (nStripInTheGroup%2==0)
331 newCluster->setFlag(1);
332 Int_t currentStrip = localFirstStrip;
333 for (currentStrip = localFirstStrip; currentStrip<=(keyToIdStrip[iStripLeft]+(nStripInTheGroup/2)); currentStrip++)
335 newCluster->update(currentStripList->getStrip(currentStrip),weight);
337 localFirstStrip=currentStrip+1;
340 this->addNewCluster(newCluster);
345 newCluster->setFlag(1);
346 Int_t currentStrip = localFirstStrip;
347 for (currentStrip = localFirstStrip; currentStrip<=(keyToIdStrip[iStripLeft]+(int)(nStripInTheGroup/2)); currentStrip++)
349 newCluster->update(currentStripList->getStrip(currentStrip),weight);
351 localFirstStrip=currentStrip+1;
355 newCluster->update(currentStripList->getStrip(localFirstStrip),weight);
356 this->addNewCluster(newCluster);
360 strip_offset = strip_diff;
366 newCluster->setFlag(1);
367 Int_t currentStrip = localFirstStrip;
368 for (currentStrip = localFirstStrip; currentStrip<(CurrentCluster->getFirstStrip()+CurrentCluster->getClusterSize()); currentStrip++)
370 newCluster->update(currentStripList->getStrip(currentStrip),weight);
373 this->addNewCluster(newCluster);
378 delete [] keyToIdStrip;
382 Int_t StSsdClusterList::isSorted()
387 while(ptr1 != this->last())
389 ptr2 = this->next(ptr1);
390 if (ptr1->getFirstStrip()>ptr2->getFirstStrip())
return 0;
391 ptr1 = this->next(ptr1);
396 StSsdClusterList::StSsdClusterList(
const StSsdClusterList & originalClusterList)
398 mListLength = originalClusterList.mListLength;
399 mFirstCluster = originalClusterList.mFirstCluster;
400 mLastCluster = originalClusterList.mLastCluster;
405 mListLength = originalClusterList.mListLength;
406 mFirstCluster = originalClusterList.mFirstCluster;
407 mLastCluster = originalClusterList.mLastCluster;