StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSsdStripList.cc
1 // $Id: StSsdStripList.cc,v 1.3 2008/10/20 19:29:37 bouchet Exp $
2 //
3 // $Log: StSsdStripList.cc,v $
4 // Revision 1.3 2008/10/20 19:29:37 bouchet
5 // Fill only one signal contribution (the higher) of GEANT hit per strip
6 //
7 // Revision 1.2 2008/05/07 22:48:36 bouchet
8 // calculation of quality of hits used embedding
9 //
10 // Revision 1.1 2006/10/16 16:43:30 bouchet
11 // StSsdUtil regroups now methods for the classes StSsdStrip, StSsdCluster and StSsdPoint
12 //
13 // Revision 1.6 2006/09/15 21:03:14 bouchet
14 // id_mctrack is using for setIdTruth and propagated to the hit
15 //
16 // Revision 1.5 2005/03/18 15:02:37 lmartin
17 // setPedestalSigma method added, setSigma removed
18 //
19 // Revision 1.4 2005/03/18 14:17:39 lmartin
20 // missing CVS header added
21 //
22 
23 #include <Stiostream.h>
24 #include "StSsdStripList.hh"
25 #include "StSpaListNoise.hh"
26 
27 
28 StSsdStripList::StSsdStripList()
29 {
30  mListLength = 0;
31  mFirstStrip=0;
32  mLastStrip=0;
33 }
34 
35 StSsdStripList::~StSsdStripList()
36 {
37  if (mListLength)
38  {
39  StSsdStrip *ptr = mLastStrip;
40  StSsdStrip *toDele;
41  while (mListLength)
42  {
43  toDele = ptr;
44  ptr = prev(ptr);
45  delete toDele;
46  mListLength--;
47  }
48  }
49 }
50 
51 
52 StSsdStrip* StSsdStripList::next(StSsdStrip *ptr)
53 { return ptr->getNextStrip(); }
54 
55 StSsdStrip* StSsdStripList::prev(StSsdStrip *ptr)
56 { return ptr->getPrevStrip(); }
57 
58 StSsdStrip* StSsdStripList::first()
59 { return mFirstStrip; }
60 
61 StSsdStrip* StSsdStripList::last()
62 { return mLastStrip; }
63 
64 StSsdStrip* StSsdStripList::getStrip(Int_t idStrip)
65 {
66  StSsdStrip *currentStrip = first();
67  while(currentStrip)
68  {
69  if(currentStrip->getNStrip()==idStrip) return currentStrip;
70  currentStrip=next(currentStrip);
71  }
72  cout<<"No match in getStrip"<<endl;
73  return 0;
74 }
75 
76 Int_t StSsdStripList::getSize()
77 { return mListLength; }
78 
79 Int_t StSsdStripList::addNewStrip(StSsdStrip *ptr)
80 {
81  if (ptr->getNStrip() == 0) return 0;
82  if (mListLength == 0)
83  {
84  ptr->setPrevStrip(0);
85  ptr->setNextStrip(0);
86  mFirstStrip = ptr;
87  mLastStrip = ptr;
88  }
89  else
90  {
91  ptr->setPrevStrip(mLastStrip);
92  ptr->setNextStrip(0);
93  mLastStrip->setNextStrip(ptr);
94  mLastStrip = ptr;
95  }
96  mListLength++;
97  return 1;
98 }
99 
100 Int_t StSsdStripList::removeStrip(StSsdStrip *ptr)
101 {
102  if (!getSize()) return 0;
103  StSsdStrip *ptBefore = ptr->getPrevStrip();
104  StSsdStrip *ptAfter = ptr->getNextStrip();
105 
106  if (ptBefore == 0)
107  {
108  if (ptAfter== 0)
109  {
110  // taille = 1
111  mFirstStrip = 0;
112  mLastStrip = 0;
113  mListLength = 0;
114  delete ptr;
115  return 1;
116  }
117  else
118  {
119  mFirstStrip = ptAfter;
120  ptAfter->setPrevStrip(0);
121  mListLength--;
122  delete ptr;
123  return 1;
124  }
125  }
126  else
127  {
128  if (ptAfter== 0)
129  {
130  mLastStrip = ptBefore;
131  ptBefore->setNextStrip(0);
132  mListLength--;
133  delete ptr;
134  return 1;
135  }
136  else
137  {
138  ptBefore->setNextStrip(ptAfter);
139  ptAfter->setPrevStrip(ptBefore);
140  mListLength--;
141  delete ptr;
142  return 1;
143  }
144  }
145 
146 }
147 
148 void StSsdStripList::exchangeTwoStrips(StSsdStrip *ptr1, StSsdStrip *ptr2)
149 {
150 
151  StSsdStrip *ptrTemp = new StSsdStrip(ptr1->getNStrip(), ptr1->getDigitSig(), ptr1->getSigma(),ptr1->getPedestal());
152  for(Int_t ii=0;ii<5;ii++) {
153  ptrTemp->setIdMcHit(ptr1->getIdMcHit(ii),ii);
154  ptrTemp->setIdMcTrack(ptr1->getIdMcTrack(ii),ii);
155  ptrTemp->setIdHit(ptr1->getIdHit(ii),ii);
156  }
157  /*
158  if(ptr1->getNStrip()){
159  ptrTemp->setPrevStrip(ptr1->getPrevStrip());}
160  else ptrTemp->setPrevStrip(0);
161  */
162 
163  ptr1->setNStrip(ptr2->getNStrip());
164  ptr1->setDigitSig(ptr2->getDigitSig());
165  ptr1->setPedestal(ptr2->getPedestal());
166  ptr1->setSigma(ptr2->getSigma());
167  ptr1->setNHits(ptr2->getNHits());
168  ptr1->setAnalogSig(ptr2->getAnalogSig());
169  ptr1->setMcStrip(ptr2->getMcStrip());
170  for( int i= 0 ;i <5 ; i++)
171  {
172  ptr1->setIdHit(ptr2->getIdHit(i),i);
173  ptr1->setIdMcTrack(ptr2->getIdMcTrack(i),i);
174  ptr1->setIdMcHit(ptr2->getIdMcHit(i),i);
175  }
176  /*
177  if(ptr2->getPrevStrip()){
178  ptr1->setPrevStrip(ptr2->getPrevStrip());}
179  else ptr1->setPrevStrip(0);
180  */
181 
182  ptr2->setNStrip(ptrTemp->getNStrip());
183  ptr2->setDigitSig(ptrTemp->getDigitSig());
184  ptr2->setPedestal(ptrTemp->getPedestal());
185  ptr2->setSigma(ptrTemp->getSigma());
186  ptr2->setNHits(ptrTemp->getNHits());
187  ptr2->setAnalogSig(ptrTemp->getAnalogSig());
188  ptr2->setMcStrip(ptrTemp->getMcStrip());
189  for( int i= 0 ;i <5 ; i++)
190  {
191  ptr2->setIdHit(ptrTemp->getIdHit(i),i);
192  ptr2->setIdMcTrack(ptrTemp->getIdMcTrack(i),i);
193  ptr2->setIdMcHit(ptrTemp->getIdMcHit(i),i);
194  }
195  delete ptrTemp;
196 }
197 
198 void StSsdStripList::sortStrip()
199 {
200  Int_t localSize=getSize();
201  if (localSize<2) return;
202 
203  StSsdStrip *ptCurr = first();
204  ptCurr = next(ptCurr);
205  for ( ; ptCurr!=0 ; )
206 
207  {
208  StSsdStrip *ptB1 = ptCurr;
209  StSsdStrip *ptB2;
210  Int_t is_cont = 1;
211  while ((ptB1 != first())&&(is_cont))
212  {
213  ptB2 = prev(ptB1);
214  if (ptB2->getNStrip() > ptB1->getNStrip())
215  {
216  exchangeTwoStrips(ptB1,ptB2);
217  ptB1 = ptB2;
218  }
219  else
220  {
221  is_cont = 0;
222  }
223  }
224  ptCurr = next(ptCurr);
225 
226  }
227 
228  return;
229 }
230 
231 int* StSsdStripList::getListAdc(Int_t idStrip, Int_t sizeCluster)
232 {
233  StSsdStrip *CurrentStrip = first();
234  int* localListAdc = new int[sizeCluster];
235  while((CurrentStrip->getNStrip()!=idStrip)&&(CurrentStrip)) CurrentStrip = next(CurrentStrip);
236  if (!CurrentStrip) return localListAdc;
237  Int_t iStrip = 0;
238  for (iStrip=0; iStrip<sizeCluster;iStrip++)
239  {
240  localListAdc[iStrip]=CurrentStrip->getDigitSig();
241  CurrentStrip = next(CurrentStrip);
242  }
243  return localListAdc;
244 }
245 
246 
247 void StSsdStripList::setPedestalSigma(Int_t iStrip, Int_t iPedestal, Int_t iSigma, StSsdDynamicControl *dynamicControl)
248 {
249  const Int_t NAdcChannel = 1 << (dynamicControl->getnbitEncoding()); // 1 << x == 2^x
250  // const Float_t conversionFactor = (float)(NAdcChannel)/(dynamicControl->getadcDynamic()*dynamicControl->getnElectronInAMip());
251  const Float_t conversionFactor = 1./16.;
252  StSsdStrip *currentStrip=first();
253  while((currentStrip) && (currentStrip->getNStrip()!=iStrip))
254  currentStrip=next(currentStrip);
255  if(currentStrip)
256  {
257  // Int_t sigmaAdc = (int)(iSigma*conversionFactor);
258  Float_t sigmaAdc = iSigma*conversionFactor;
259  if (sigmaAdc<NAdcChannel) currentStrip->setSigma(sigmaAdc);
260  else currentStrip->setSigma(NAdcChannel-1);
261  if (iPedestal<NAdcChannel) currentStrip->setPedestal(iPedestal);
262  else currentStrip->setPedestal(NAdcChannel-1);
263  }
264  return;
265 }
266 
267 Int_t StSsdStripList::isSorted()
268 {
269  StSsdStrip *ptr1 = first();
270  StSsdStrip *ptr2 = 0;
271 
272  while(ptr1 != last())
273  {
274  ptr2 = next(ptr1);
275  if (ptr1->getNStrip()>ptr2->getNStrip()) return 0;
276  ptr1 = next(ptr1);
277  }
278  return 1;
279 }
280 
281 StSsdStripList::StSsdStripList(const StSsdStripList & originalStripList)
282 {
283  mListLength = originalStripList.mListLength;
284  mFirstStrip = originalStripList.mFirstStrip;
285  mLastStrip = originalStripList.mLastStrip;
286 }
287 
288 StSsdStripList& StSsdStripList::operator=(const StSsdStripList originalStripList)
289 {
290  mListLength = originalStripList.mListLength;
291  mFirstStrip = originalStripList.mFirstStrip;
292  mLastStrip = originalStripList.mLastStrip;
293 
294  return *this;
295 }
296 
297 void StSsdStripList::updateStrip(StSsdStrip *ptr)
298 {
299  Int_t localSize = getSize();
300  if (!localSize)
301  {
302  addNewStrip(ptr);
303  return;
304  }
305  StSsdStrip *stripScan = first();
306  while ((stripScan != last())&&(stripScan->getNStrip()!=ptr->getNStrip())) stripScan = next(stripScan);
307  if (stripScan->getNStrip()!=ptr->getNStrip())
308  {
309  addNewStrip(ptr);
310  return;
311  }
312  else
313  {
314  Int_t dum = stripScan->getNHits();
315  Float_t tmpSig = stripScan->getAnalogSig();
316  stripScan->setNHits(dum+1);
317  stripScan->setAnalogSig(ptr->getAnalogSig()+tmpSig) ;
318  if (dum<5)
319  {
320  if(ptr->getAnalogSig()>tmpSig){
321  stripScan->setIdHit(ptr->getIdHit(0), 0);
322  stripScan->setIdMcHit(ptr->getIdMcHit(0), 0);
323  stripScan->setIdMcTrack(ptr->getIdMcTrack(0), 0);
324  }
325  else{
326  stripScan->setIdMcTrack(stripScan->getIdMcTrack(0), 0);
327  stripScan->setIdHit(stripScan->getIdHit(0),0);
328  stripScan->setIdMcHit(stripScan->getIdMcHit(0),0);
329  }
330  }
331  delete ptr;
332  return;
333  }
334 }
335 
336 StSsdStripList* StSsdStripList::addStripList(StSsdStripList *list)
337 {
338  Int_t size2 = list->getSize();
339  if (!size2) return this;
340 
341  StSsdStrip *st1 =0 ;
342  StSsdStrip *st2 = list->first();
343  Int_t i = 0;
344  for (i=0 ; i < size2 ; i++)
345  {
346  st2->copyTo(st1);
347  addNewStrip(st1);
348  st2 = list->next(st2);
349  }
350  return this;
351 }
352 //________________________________________________________________________________
353 void StSsdStripList::updateStripList(StSpaListNoise *ptr)
354 {
355  StSsdStrip *pt1 = first();
356  StSpaNoise *pt2 = ptr->first();
357  Int_t adcCount = 0;
358 
359  while (pt1)
360  {
361  pt2 = ptr->first();
362  while (pt2&&((pt2->getNStrip())!=(pt1->getNStrip())))
363  {
364  pt2 = ptr->next(pt2);
365  }
366  if (!pt2)
367  {
368  StSsdStrip *tmp = pt1;
369  pt1 = next(pt1);
370  removeStrip(tmp);
371  }
372  else
373  {
374  adcCount = pt2->getNoiseValue();
375  pt1->setDigitSig(adcCount);
376  pt2->setNStrip(-1);
377  pt1 = next(pt1);
378  }
379  }
380  pt2 = ptr->first();
381  while (pt2)
382  {
383  if (pt2->getNStrip() < 0)
384  {
385  StSpaNoise *tmpNoise = pt2;
386  pt2 = ptr->next(pt2);
387  ptr->removeNoise(tmpNoise);
388  }
389  else
390  {
391  StSsdStrip *tmpStrip = new StSsdStrip(pt2->getNStrip(), pt2->getNoiseValue());
392  addNewStrip(tmpStrip);
393  pt2 = ptr->next(pt2);
394  }
395  }
396 }