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