StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSpaListNoise.cc
1 // $Id: StSpaListNoise.cc,v 1.2 2015/08/06 17:46:54 smirnovd Exp $
2 //
3 // $Log: StSpaListNoise.cc,v $
4 // Revision 1.2 2015/08/06 17:46:54 smirnovd
5 // Removed unused local variables
6 //
7 // Revision 1.1 2015/06/23 16:26:19 jeromel
8 // First version created from the SSD code and reshaped
9 //
10 // Revision 1.1 2015/04/19 17:30:31 bouchet
11 // initial commit ; SST codes
12 //
13 // Revision 1.1 2015/01/29 20:16:36 bouchet
14 // SSD utils for hit reconstruction
15 //
16 // Revision 1.3 2009/02/23 21:10:40 bouchet
17 // increase NSaturationSignal to reflect the energy increase of the GEANT hit
18 //
19 // Revision 1.2 2006/12/01 22:04:12 bouchet
20 // get back to previous daqCutValue
21 //
22 // Revision 1.1 2006/10/16 16:43:29 bouchet
23 // StSstUtil regroups now methods for the classes StSstStrip, StSstCluster and StSstPoint
24 //
25 // Revision 1.3 2006/09/15 21:09:52 bouchet
26 // read the noise and pedestal from ssdStripCalib
27 //
28 // Revision 1.2 2005/05/13 08:39:32 lmartin
29 // CVS tags added
30 //
31 
32 #include "StSpaListNoise.hh"
33 #include "StSstStrip.hh"
34 #include "StSstStripList.hh"
35 StSpaListNoise::StSpaListNoise()
36 {
37  mListLength = 0;
38  mFirstS=0;
39  mLastS=0;
40 }
41 
42 StSpaListNoise::~StSpaListNoise()
43 {
44  if (mListLength)
45  {
46  StSpaNoise *ptr = mLastS;
47  StSpaNoise *toDele;
48  while (mListLength)
49  {
50  toDele = ptr;
51  ptr = prev(ptr);
52  delete toDele;
53  mListLength--;
54  }
55  }
56 }
57 
58 StSpaNoise* StSpaListNoise::next(StSpaNoise *ptr)
59 { return ptr->getNextNoise(); }
60 
61 StSpaNoise* StSpaListNoise::prev(StSpaNoise *ptr)
62 { return ptr->getPrevNoise(); }
63 
64 StSpaNoise* StSpaListNoise::first()
65 { return mFirstS; }
66 
67 Int_t StSpaListNoise::getSize()
68 { return mListLength; }
69 
70 StSpaNoise* StSpaListNoise::last()
71 { return mLastS; }
72 
73 Int_t StSpaListNoise::addNewNoise(StSpaNoise *ptr)
74 {
75  if (ptr->getNStrip() == 0) return 0;
76  if (mListLength == 0)
77  {
78  ptr->setPrevNoise(0);
79  ptr->setNextNoise(0);
80  mFirstS = ptr;
81  mLastS = ptr;
82  }
83  else
84  {
85  ptr->setPrevNoise(mLastS);
86  ptr->setNextNoise(0);
87  mLastS->setNextNoise(ptr);
88  mLastS = ptr;
89  }
90  mListLength++;
91  return 1;
92 }
93 
94 void StSpaListNoise::setIsActive(Int_t rIsActive, Int_t rNStrip)
95 {
96  if (!(this->getSize())) return;
97  StSpaNoise *ptr = this->first();
98  while ((ptr)&&(ptr->getNStrip() != rNStrip))
99  {
100  ptr = this->next(ptr);
101  }
102  if (ptr) ptr->setIsActive(rIsActive);
103 
104 }
105 
106 Int_t StSpaListNoise::removeNoise(StSpaNoise *ptr)
107 {
108  if (!this->getSize()) return 0;
109  StSpaNoise *ptBefore = ptr->getPrevNoise();
110  StSpaNoise *ptAfter = ptr->getNextNoise();
111 
112  if (ptBefore == 0)
113  {
114  if (ptAfter == 0)
115  {
116  this->mFirstS = 0;
117  this->mLastS = 0;
118  this->mListLength = 0;
119  delete ptr;
120  return 1;
121  }
122  else
123  {
124  this->mFirstS = ptAfter;
125  ptAfter->setPrevNoise(0);
126  this->mListLength--;
127  delete ptr;
128  return 1;
129  }
130  }
131  else
132  {
133  if (ptAfter == 0)
134  {
135  this->mLastS = ptBefore;
136  ptBefore->setNextNoise(0);
137  this->mListLength--;
138  delete ptr;
139  return 1;
140  }
141  else
142  {
143  ptBefore->setNextNoise(ptAfter);
144  ptAfter->setPrevNoise(ptBefore);
145  this->mListLength--;
146  delete ptr;
147  return 1;
148  }
149  }
150 }
151 
152 StSpaListNoise* StSpaListNoise::addListNoise(StSpaListNoise *list)
153 {
154  Int_t size2 = list->getSize();
155  if (!size2) return this;
156 
157  StSpaNoise *st1;
158  StSpaNoise *st2 = list->first();
159  while (st2)
160  {
161  st1 = st2->giveCopy();
162  this->addNewNoise(st1);
163  st2 = list->next(st2);
164  }
165  return this;
166 }
167 
168 void StSpaListNoise::exchangeTwoNoise(StSpaNoise *ptr1,StSpaNoise *ptr2)
169 {
170  StSpaNoise *ptrTmp = ptr1->giveCopy();
171 
172  ptr1->setNStrip(ptr2->getNStrip());
173  ptr1->setPedestal(ptr2->getPedestal());
174  ptr1->setSigma(ptr2->getSigma());
175  ptr1->setNoiseValue(ptr2->getNoiseValue());
176  ptr1->setIsActive(ptr2->getIsActive());
177 
178  ptr2->setNStrip(ptrTmp->getNStrip());
179  ptr2->setPedestal(ptrTmp->getPedestal());
180  ptr2->setSigma(ptrTmp->getSigma());
181  ptr2->setNoiseValue(ptrTmp->getNoiseValue());
182  ptr2->setIsActive(ptrTmp->getIsActive());
183 
184  delete ptrTmp;
185 }
186 
187 void StSpaListNoise::sortStrip()
188 {
189  Int_t localSize=this->getSize();
190  Int_t temp = 0;
191  if (localSize<2) return;
192  StSpaNoise *ptCurr = this->first();
193  temp++;
194  ptCurr = this->next(ptCurr);
195  for ( ; ptCurr!=0 ; )
196  {
197  StSpaNoise *ptB1 = ptCurr;
198  StSpaNoise *ptB2;
199  Int_t isCont = 1;
200  while ((ptB1 != this->first())&&(isCont))
201  {
202  ptB2 = this->prev(ptB1);
203  if (ptB2->getNStrip() > ptB1->getNStrip())
204  {
205  this->exchangeTwoNoise(ptB1,ptB2);
206  ptB1 = ptB2;
207  }
208  else
209  {
210  isCont = 0;
211  }
212  }
213  ptCurr = this->next(ptCurr);
214  temp++;
215  }
216  return;
217 }
218 
219 void StSpaListNoise::addSignal(StSstStripList *ptr,
220  long nElectronInAMip,long adcDynamic)
221 {
222  const Int_t NSaturationSignal = (int)adcDynamic*nElectronInAMip;
223  Int_t size1 = this->getSize();
224 
225  if (!size1) return;
226  StSpaNoise *ptr1 = this->first();
227  StSstStrip *ptr2 = ptr->first();
228  //printf("SpaNoise first Id=%d SpaStrip first Id=%d\n",ptr1->getNStrip(),ptr2->getNStrip());
229  Int_t tmpNoiseValue = 0;
230  while (ptr2)
231  {
232  if(!ptr1)return;
233  while((ptr1)&&(ptr2->getNStrip() != ptr1->getNStrip()))
234  {
235  ptr1 = this->next(ptr1);
236  }
237  if(ptr1)
238  {
239  tmpNoiseValue = ptr1->getNoiseValue();
240  ptr1->setNoiseValue(ptr2->getDigitSig() + tmpNoiseValue);
241  ptr2 = ptr->next(ptr2);
242  ptr1=this->first();
243  }
244  else
245  {
246  cout<<"signal and noise not matched !"<<endl;
247  ptr1=this->first();
248  ptr2 = ptr->next(ptr2);
249  }
250  }
251  ptr1 = this->first();
252  while (ptr1)
253  {
254  if(ptr1->getIsActive())
255  {
256  if (ptr1->getNoiseValue() > NSaturationSignal)
257  ptr1->setNoiseValue(NSaturationSignal);
258  }
259  else
260  {
261  ptr1->setNoiseValue(0);
262  }
263  tmpNoiseValue = ptr1->getNoiseValue();
264  ptr1->setNoiseValue(ptr1->getPedestal() + tmpNoiseValue);
265  ptr1 = this->next(ptr1);
266  }
267 }
268 
269 void StSpaListNoise::substractPedestal()
270 {
271  if ((this->getSize())==0) return;
272  StSpaNoise *ptr = this->first();
273  Int_t tmpNoiseValue = 0;
274  while (ptr)
275  {
276  tmpNoiseValue = ptr->getNoiseValue();
277  ptr->setNoiseValue(tmpNoiseValue - ptr->getPedestal()) ;
278  ptr = this->next(ptr);
279  }
280 }
281 
282 void StSpaListNoise::convertAnalogToDigit(long nElectronInAMip,long adcDynamic,
283  long nbitEncoding, Float_t daqCutValue)
284 {
285  const Int_t NAdcChannel = (int)pow(2.0,nbitEncoding*1.0);
286  const Float_t conversionFactor = (float)(NAdcChannel)/(adcDynamic*nElectronInAMip);
287 
288  Int_t localSize = this->getSize();
289  if (!localSize) return;
290  StSpaNoise *curr = this->first();
291  while(curr)
292  {
293  curr->setNoiseValue((int)(curr->getNoiseValue()*conversionFactor));
294  if (curr->getNoiseValue() > (NAdcChannel-1)) curr->setNoiseValue(NAdcChannel-1);
295  curr->setPedestal((int)((curr->getPedestal()*conversionFactor)+0.5));
296  if (curr->getPedestal() > (NAdcChannel-1)) curr->setPedestal(NAdcChannel-1);
297  curr->setSigma((int)(((curr->getSigma()*conversionFactor)*daqCutValue)+0.5));
298  if (curr->getSigma() > (NAdcChannel-1)) curr->setSigma(NAdcChannel-1); //Now sigma is the DAQ cut...
299 
300  curr = this->next(curr);
301  }
302 }
303 
304 void StSpaListNoise::zeroSubstraction()
305 {
306  Int_t localSize = this->getSize();
307  if (!localSize) return;
308  StSpaNoise *ptr = this->first();
309  StSpaNoise *tmp = 0;
310 
311  while(ptr)
312  {
313  tmp = ptr;
314  ptr = this->next(ptr);
315  if (tmp->getNoiseValue()<= tmp->getSigma())
316  { this->removeNoise(tmp); }
317  }
318 }