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