11 quality_cache_id(-1), noise_cache_id(-1),
12 ForceNoRestore_(conf.getParameter<bool>(
"ForceNoRestore")),
13 SelfSelectRestoreAlgo_(conf.getParameter<bool>(
"SelfSelectRestoreAlgo")),
14 InspectAlgo_(conf.getParameter<std::string>(
"APVInspectMode")),
15 RestoreAlgo_(conf.getParameter<std::string>(
"APVRestoreMode")),
16 useRealMeanCM_(conf.getParameter<bool>(
"useRealMeanCM")),
17 fraction_(conf.getParameter<double>(
"Fraction")),
18 deviation_(conf.getParameter<uint32_t>(
"Deviation")),
19 restoreThreshold_(conf.getParameter<double>(
"restoreThreshold")),
20 DeltaCMThreshold_(conf.getParameter<uint32_t>(
"DeltaCMThreshold")),
21 nSigmaNoiseDerTh_(conf.getParameter<uint32_t>(
"nSigmaNoiseDerTh")),
22 consecThreshold_(conf.getParameter<uint32_t>(
"consecThreshold")),
23 hitStripThreshold_(conf.getParameter<uint32_t>(
"hitStripThreshold")),
24 nSmooth_(conf.getParameter<uint32_t>(
"nSmooth")),
25 minStripsToFit_(conf.getParameter<uint32_t>(
"minStripsToFit")),
26 distortionThreshold_(conf.getParameter<uint32_t>(
"distortionThreshold")),
27 CutToAvoidSignal_(conf.getParameter<double>(
"CutToAvoidSignal")),
28 nSaturatedStrip_(conf.getParameter<uint32_t>(
"nSaturatedStrip"))
60 int16_t
SiStripAPVRestorer::inspect(
const uint32_t& detId,std::vector<int16_t>& digis,
const std::vector< std::pair<short,float> >& vmedians) {
69 for(
size_t i=0;
i< vmedians.size(); ++
i)
median_.push_back(vmedians[
i].second);
75 throw cms::Exception(
"Unregistered Inspect Algorithm") <<
"SiStripAPVRestorer possibilities: (Null), (AbnormalBaseline),(BaselineFollower)";
84 for( uint16_t
APV=0;
APV< digis.size()/128; ++
APV){
87 if ( algoToUse !=
""){
90 if(algoToUse==
"Flat"){
92 }
else if(algoToUse==
"BaselineFollower"){
98 throw cms::Exception(
"Unregistered Restore Algorithm") <<
"SiStripAPVRestorer possibilities: (Flat), (BaselineFollower)";
113 std::vector<T> singleAPVdigi;
114 singleAPVdigi.clear();
117 int16_t nAPVflagged = 0;
119 CMMap::iterator itCMMap;
122 for( uint16_t
APV=0;
APV< digis.size()/128; ++
APV){
127 singleAPVdigi.clear();
129 singleAPVdigi.push_back(digis[
strip]);
145 apvFlags_.push_back(
"BaselineFollower" );
167 std::vector<T> singleAPVdigi;
168 singleAPVdigi.clear();
171 int16_t nAPVflagged = 0;
173 CMMap::iterator itCMMap;
176 for( uint16_t
APV=0;
APV< digis.size()/128; ++
APV){
181 singleAPVdigi.clear();
183 uint16_t nSatStrip =0;
185 singleAPVdigi.push_back(digis[
strip]);
186 if(digis[strip] >=1023) ++nSatStrip;
212 typename std::vector<T>::iterator fs;
214 int16_t nAPVflagged=0;
216 CMMap::iterator itCMMap;
220 int devCount = 0, qualityCount = 0, minstrip = 0;
221 for( uint16_t
APV=0;
APV< digis.size()/128; ++
APV){
224 for (uint16_t istrip=
APV*128; istrip<(
APV+1)*128; ++istrip){
225 fs = digis.begin() + istrip;
229 minstrip =
std::min((
int) *fs, minstrip);
233 if( devCount >
fraction_ * qualityCount ) {
254 typename std::vector<T>::iterator fs;
256 int16_t nAPVflagged = 0;
258 for( uint16_t
APV=0;
APV< digis.size()/128; ++
APV){
259 int zeroCount = 0, qualityCount = 0;
260 for (uint16_t istrip=
APV*128; istrip<(
APV+1)*128; ++istrip){
261 fs = digis.begin() + istrip;
264 if ( (
int) *fs < 1 ) zeroCount++;
290 typename std::vector<T>::iterator firstStrip(digis.begin() + APVn*128), lastStrip(firstStrip + 128), actualStrip;
292 std::vector<int16_t> baseline;
294 baseline.insert(baseline.begin(),128, 0);
296 std::vector<int16_t> adcs;
301 for(actualStrip= firstStrip; actualStrip < lastStrip; ++actualStrip ) adcs.push_back(*actualStrip);
325 for(int16_t itStrip= 0 ; itStrip< 128; ++itStrip){
328 digis[itStrip+APVn*128] -= baseline[itStrip] - median;
343 std::vector<int16_t> baseline;
345 baseline.insert(baseline.begin(),128, 150);
346 baseline[0]=0; baseline[127]=0;
349 typename std::vector<T>::iterator
strip(digis.begin() + APVn*128), lastStrip(
strip + 128);
352 while (strip < lastStrip) {
370 consecpoints.erase(consecpoints.begin(), consecpoints.end());
371 smoothedpoints.erase(smoothedpoints.begin(), smoothedpoints.end());
376 std::vector<float> adcsLocalMinSubtracted;
377 adcsLocalMinSubtracted.clear();
378 adcsLocalMinSubtracted.insert(adcsLocalMinSubtracted.begin(), 128,0);
379 for(uint32_t istrip=0; istrip<128; ++istrip) {
380 float localmin = 999.9;
382 float nextvalue = adcs[jstrip];
383 if(nextvalue < localmin) localmin=nextvalue;
385 adcsLocalMinSubtracted[istrip] = adcs[istrip] - localmin;
390 std::vector<uint16_t> nConsStrip;
394 uint16_t consecStrips=0;
395 for(uint32_t istrip=0; istrip<128; ++istrip) {
396 int16_t
adc = adcs[istrip];
402 consecpoints.insert(consecpoints.end(), std::pair<uint16_t, int16_t >(istrip,
adc));
405 }
else if (consecStrips >0){
406 nConsStrip.push_back(consecStrips);
414 if(consecStrips >0) nConsStrip.push_back(consecStrips);
418 itConsecpoints = consecpoints.begin();
419 float MinSmoothValue=2000., MaxSmoothValue=0.;
420 for(std::vector<uint16_t>::iterator itnConsStrip = nConsStrip.begin(); itnConsStrip < nConsStrip.end(); ++itnConsStrip){
422 consecStrips = *itnConsStrip;
425 uint16_t nFirstStrip = itConsecpoints->first;
427 float smoothValue = 0.0;
429 for(uint16_t
n =0;
n < consecStrips-2; ++
n){
430 smoothValue += itConsecpoints->second;
432 smoothValue /= (float)stripCount;
433 nLastStrip = nFirstStrip + stripCount -1;
434 smoothedpoints.insert(smoothedpoints.end(), std::pair<uint16_t, int16_t >(nFirstStrip, smoothValue));
435 smoothedpoints.insert(smoothedpoints.end(), std::pair<uint16_t, int16_t >(nLastStrip, smoothValue));
436 if(smoothValue > MaxSmoothValue) MaxSmoothValue = smoothValue;
437 if(smoothValue < MinSmoothValue) MinSmoothValue = smoothValue;
438 nFirstStrip = nLastStrip+1;
449 smoothValue /= (float)(stripCount);
450 nLastStrip = nFirstStrip + stripCount -1;
451 smoothedpoints.insert(smoothedpoints.end(), std::pair<uint16_t, int16_t >(nFirstStrip, smoothValue));
452 smoothedpoints.insert(smoothedpoints.end(), std::pair<uint16_t, int16_t >(nLastStrip, smoothValue));
453 if(smoothValue > MaxSmoothValue) MaxSmoothValue = smoothValue;
454 if(smoothValue < MinSmoothValue) MinSmoothValue = smoothValue;
457 for(
int n =0;
n< consecStrips ; ++
n) ++itConsecpoints;
475 baseline.insert(baseline.begin(),128, median);
477 baseline.insert(baseline.begin(),128, 0);
479 DigiMapIter itSmoothedpointsBegin, itSmoothedpointsEnd;
480 itSmoothedpointsBegin = smoothedpoints.begin();
481 itSmoothedpointsEnd = --(smoothedpoints.end());
484 uint16_t firstStripFlat = itSmoothedpointsBegin->first;
485 uint16_t lastStripFlat = itSmoothedpointsEnd->first;
486 int16_t firstStipFlatADC= itSmoothedpointsBegin->second;
487 int16_t lastStipFlatADC= itSmoothedpointsEnd->second;
490 baseline.erase(baseline.begin(), baseline.begin()+firstStripFlat);
491 baseline.insert(baseline.begin(), firstStripFlat, firstStipFlatADC);
493 baseline.erase(baseline.begin()+lastStripFlat, baseline.end());
494 baseline.insert(baseline.end(), 128 - lastStripFlat, lastStipFlatADC);
498 for(itSmoothedpoints = itSmoothedpointsBegin; itSmoothedpoints != itSmoothedpointsEnd; ++itSmoothedpoints){
499 DigiMapIter itSmoothedpointsNext = itSmoothedpoints;
500 ++itSmoothedpointsNext;
501 float strip1 = itSmoothedpoints->first;
502 float strip2 = itSmoothedpointsNext->first;
503 float adc1 = itSmoothedpoints->second;
504 float adc2 = itSmoothedpointsNext->second;
506 baseline[strip1] = adc1;
507 baseline[strip2] = adc2;
508 float m = (adc2 -adc1)/(strip2 -strip1);
509 uint16_t itStrip = strip1 +1;
510 float stripadc = adc1 +
m;
511 while(itStrip < strip2){
512 baseline[itStrip] = stripadc;
554 std::vector<std::string>::const_iterator apvf_iter =
apvFlags_.begin();
560 std::vector<float> cmvalues;
561 for( ; cm_iter != cmdigis.
end(); ++cm_iter ) cmvalues.push_back( (*cm_iter).adc() );
564 std::vector<float>::const_iterator cmv_iter = cmvalues.begin();
566 if( *apvf_iter !=
"") {
593 std::vector<float> MeanCMNValue;
595 for(itInput = Input.
begin(); itInput != Input.
end(); ++itInput){
596 detId_ = itInput->id;
597 MeanCMNValue.clear();
598 for(itCM = itInput->
begin(); itCM != itInput->
end(); ++itCM) MeanCMNValue.push_back(itCM->adc());
599 MeanCMmap_.insert(std::pair<uint32_t, std::vector<float> >(detId_,MeanCMNValue));
int adc(sample_type sample)
get the ADC sample (12 bits)
void BaselineFollowerRestore(std::vector< T > &, uint16_t, float)
int16_t AbnormalBaselineInspect(std::vector< T > &)
uint32_t nSaturatedStrip_
void CreateCMMap(const edm::DetSetVector< SiStripProcessedRawDigi > &)
void push_back(const T &t)
void init(const edm::EventSetup &es)
collection_type::iterator iterator
void restore(std::vector< int16_t > &)
std::vector< DigiMap > SmoothedMaps_
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
int16_t NullInspect(std::vector< T > &)
uint32_t nSigmaNoiseDerTh_
uint32_t quality_cache_id
std::map< uint16_t, int16_t > DigiMap
void fixAPVsCM(edm::DetSet< SiStripProcessedRawDigi > &)
std::vector< std::string > apvFlags_
edm::ESHandle< SiStripQuality > qualityHandle
const T & max(const T &a, const T &b)
int16_t BaselineFollowerInspect(std::vector< T > &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
iterator end()
Return the off-the-end iterator.
bool SelfSelectRestoreAlgo_
uint32_t consecThreshold_
int16_t BaselineAndSaturationInspect(std::vector< T > &)
void LoadMeanCMMap(edm::Event &)
edm::ESHandle< SiStripNoises > noiseHandle
bool FlatRegionsFinder(std::vector< int16_t > &, DigiMap &, float, uint16_t)
std::map< uint16_t, int16_t >::iterator DigiMapIter
uint32_t DeltaCMThreshold_
void BaselineFollower(DigiMap &, std::vector< int16_t > &, float)
std::pair< ContainerIterator, ContainerIterator > Range
int16_t inspect(const uint32_t &, std::vector< int16_t > &, const std::vector< std::pair< short, float > > &)
std::vector< float > median_
uint32_t distortionThreshold_
iterator begin()
Return an iterator to the first DetSet.
uint32_t hitStripThreshold_
std::pair< ContainerIterator, ContainerIterator > Range
collection_type::const_iterator const_iterator
collection_type::const_iterator const_iterator
SiStripAPVRestorer(const edm::ParameterSet &conf)
void FlatRestore(std::vector< T > &, uint16_t)