32 #include "StSpaListNoise.hh"
33 #include "StSstStrip.hh"
34 #include "StSstStripList.hh"
35 StSpaListNoise::StSpaListNoise()
42 StSpaListNoise::~StSpaListNoise()
59 {
return ptr->getNextNoise(); }
62 {
return ptr->getPrevNoise(); }
67 Int_t StSpaListNoise::getSize()
68 {
return mListLength; }
73 Int_t StSpaListNoise::addNewNoise(
StSpaNoise *ptr)
75 if (ptr->getNStrip() == 0)
return 0;
85 ptr->setPrevNoise(mLastS);
87 mLastS->setNextNoise(ptr);
94 void StSpaListNoise::setIsActive(Int_t rIsActive, Int_t rNStrip)
96 if (!(this->getSize()))
return;
98 while ((ptr)&&(ptr->getNStrip() != rNStrip))
100 ptr = this->next(ptr);
102 if (ptr) ptr->setIsActive(rIsActive);
106 Int_t StSpaListNoise::removeNoise(
StSpaNoise *ptr)
108 if (!this->getSize())
return 0;
118 this->mListLength = 0;
124 this->mFirstS = ptAfter;
125 ptAfter->setPrevNoise(0);
135 this->mLastS = ptBefore;
136 ptBefore->setNextNoise(0);
143 ptBefore->setNextNoise(ptAfter);
144 ptAfter->setPrevNoise(ptBefore);
154 Int_t size2 = list->getSize();
155 if (!size2)
return this;
161 st1 = st2->giveCopy();
162 this->addNewNoise(st1);
163 st2 = list->next(st2);
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());
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());
187 void StSpaListNoise::sortStrip()
189 Int_t localSize=this->getSize();
191 if (localSize<2)
return;
194 ptCurr = this->next(ptCurr);
195 for ( ; ptCurr!=0 ; )
200 while ((ptB1 != this->first())&&(isCont))
202 ptB2 = this->prev(ptB1);
203 if (ptB2->getNStrip() > ptB1->getNStrip())
205 this->exchangeTwoNoise(ptB1,ptB2);
213 ptCurr = this->next(ptCurr);
220 long nElectronInAMip,
long adcDynamic)
222 const Int_t NSaturationSignal = (int)adcDynamic*nElectronInAMip;
223 Int_t size1 = this->getSize();
229 Int_t tmpNoiseValue = 0;
233 while((ptr1)&&(ptr2->getNStrip() != ptr1->getNStrip()))
235 ptr1 = this->next(ptr1);
239 tmpNoiseValue = ptr1->getNoiseValue();
240 ptr1->setNoiseValue(ptr2->getDigitSig() + tmpNoiseValue);
241 ptr2 = ptr->next(ptr2);
246 cout<<
"signal and noise not matched !"<<endl;
248 ptr2 = ptr->next(ptr2);
251 ptr1 = this->first();
254 if(ptr1->getIsActive())
256 if (ptr1->getNoiseValue() > NSaturationSignal)
257 ptr1->setNoiseValue(NSaturationSignal);
261 ptr1->setNoiseValue(0);
263 tmpNoiseValue = ptr1->getNoiseValue();
264 ptr1->setNoiseValue(ptr1->getPedestal() + tmpNoiseValue);
265 ptr1 = this->next(ptr1);
269 void StSpaListNoise::substractPedestal()
271 if ((this->getSize())==0)
return;
273 Int_t tmpNoiseValue = 0;
276 tmpNoiseValue = ptr->getNoiseValue();
277 ptr->setNoiseValue(tmpNoiseValue - ptr->getPedestal()) ;
278 ptr = this->next(ptr);
282 void StSpaListNoise::convertAnalogToDigit(
long nElectronInAMip,
long adcDynamic,
283 long nbitEncoding, Float_t daqCutValue)
285 const Int_t NAdcChannel = (int)pow(2.0,nbitEncoding*1.0);
286 const Float_t conversionFactor = (float)(NAdcChannel)/(adcDynamic*nElectronInAMip);
288 Int_t localSize = this->getSize();
289 if (!localSize)
return;
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);
300 curr = this->next(curr);
304 void StSpaListNoise::zeroSubstraction()
306 Int_t localSize = this->getSize();
307 if (!localSize)
return;
314 ptr = this->next(ptr);
315 if (tmp->getNoiseValue()<= tmp->getSigma())
316 { this->removeNoise(tmp); }