23 #include "StSpaListNoise.hh"
24 #include "StSsdStrip.hh"
25 #include "StSsdStripList.hh"
26 StSpaListNoise::StSpaListNoise()
33 StSpaListNoise::~StSpaListNoise()
50 {
return ptr->getNextNoise(); }
53 {
return ptr->getPrevNoise(); }
58 Int_t StSpaListNoise::getSize()
59 {
return mListLength; }
64 Int_t StSpaListNoise::addNewNoise(
StSpaNoise *ptr)
66 if (ptr->getNStrip() == 0)
return 0;
76 ptr->setPrevNoise(mLastS);
78 mLastS->setNextNoise(ptr);
85 void StSpaListNoise::setIsActive(Int_t rIsActive, Int_t rNStrip)
87 if (!(this->getSize()))
return;
89 while ((ptr)&&(ptr->getNStrip() != rNStrip))
91 ptr = this->next(ptr);
93 if (ptr) ptr->setIsActive(rIsActive);
97 Int_t StSpaListNoise::removeNoise(
StSpaNoise *ptr)
99 if (!this->getSize())
return 0;
109 this->mListLength = 0;
115 this->mFirstS = ptAfter;
116 ptAfter->setPrevNoise(0);
126 this->mLastS = ptBefore;
127 ptBefore->setNextNoise(0);
134 ptBefore->setNextNoise(ptAfter);
135 ptAfter->setPrevNoise(ptBefore);
145 Int_t size2 = list->getSize();
146 if (!size2)
return this;
152 st1 = st2->giveCopy();
153 this->addNewNoise(st1);
154 st2 = list->next(st2);
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());
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());
178 void StSpaListNoise::sortStrip()
180 Int_t localSize=this->getSize();
182 if (localSize<2)
return;
185 ptCurr = this->next(ptCurr);
186 for ( ; ptCurr!=0 ; )
191 while ((ptB1 != this->first())&&(isCont))
193 ptB2 = this->prev(ptB1);
194 if (ptB2->getNStrip() > ptB1->getNStrip())
196 this->exchangeTwoNoise(ptB1,ptB2);
204 ptCurr = this->next(ptCurr);
211 long nElectronInAMip,
long adcDynamic)
213 const Int_t NSaturationSignal = (int)adcDynamic*nElectronInAMip;
214 Int_t size1 = this->getSize();
220 Int_t tmpNoiseValue = 0;
224 while((ptr1)&&(ptr2->getNStrip() != ptr1->getNStrip()))
226 ptr1 = this->next(ptr1);
230 tmpNoiseValue = ptr1->getNoiseValue();
231 ptr1->setNoiseValue(ptr2->getDigitSig() + tmpNoiseValue);
232 ptr2 = ptr->next(ptr2);
237 cout<<
"signal and noise not matched !"<<endl;
239 ptr2 = ptr->next(ptr2);
242 ptr1 = this->first();
245 if(ptr1->getIsActive())
247 if (ptr1->getNoiseValue() > NSaturationSignal)
248 ptr1->setNoiseValue(NSaturationSignal);
252 ptr1->setNoiseValue(0);
254 tmpNoiseValue = ptr1->getNoiseValue();
255 ptr1->setNoiseValue(ptr1->getPedestal() + tmpNoiseValue);
256 ptr1 = this->next(ptr1);
260 void StSpaListNoise::substractPedestal()
262 if ((this->getSize())==0)
return;
264 Int_t tmpNoiseValue = 0;
267 tmpNoiseValue = ptr->getNoiseValue();
268 ptr->setNoiseValue(tmpNoiseValue - ptr->getPedestal()) ;
269 ptr = this->next(ptr);
273 void StSpaListNoise::convertAnalogToDigit(
long nElectronInAMip,
long adcDynamic,
274 long nbitEncoding, Float_t daqCutValue)
276 const Int_t NAdcChannel = (int)pow(2.0,nbitEncoding*1.0);
277 const Float_t conversionFactor = (float)(NAdcChannel)/(adcDynamic*nElectronInAMip);
279 Int_t localSize = this->getSize();
280 if (!localSize)
return;
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);
291 curr = this->next(curr);
295 void StSpaListNoise::zeroSubstraction()
297 Int_t localSize = this->getSize();
298 if (!localSize)
return;
305 ptr = this->next(ptr);
306 if (tmp->getNoiseValue()<= tmp->getSigma())
307 { this->removeNoise(tmp); }