CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

IteratedMedianCMNSubtractor Class Reference

#include <IteratedMedianCMNSubtractor.h>

Inheritance diagram for IteratedMedianCMNSubtractor:
SiStripCommonModeNoiseSubtractor

List of all members.

Public Member Functions

void init (const edm::EventSetup &es)
void subtract (const uint32_t &, const uint16_t &, std::vector< float > &)
void subtract (const uint32_t &, const uint16_t &, std::vector< int16_t > &)

Private Member Functions

 IteratedMedianCMNSubtractor (double sigma, int iterations)
float pairMedian (std::vector< std::pair< float, float > > &sample)
template<typename T >
void subtract_ (const uint32_t &, const uint16_t &, std::vector< T > &)

Private Attributes

double cut_to_avoid_signal_
int iterations_
uint32_t noise_cache_id
edm::ESHandle< SiStripNoisesnoiseHandle
uint32_t quality_cache_id
edm::ESHandle< SiStripQualityqualityHandle

Friends

class SiStripRawProcessingFactory

Detailed Description

Definition at line 11 of file IteratedMedianCMNSubtractor.h.


Constructor & Destructor Documentation

IteratedMedianCMNSubtractor::IteratedMedianCMNSubtractor ( double  sigma,
int  iterations 
) [inline, private]

Definition at line 26 of file IteratedMedianCMNSubtractor.h.


Member Function Documentation

void IteratedMedianCMNSubtractor::init ( const edm::EventSetup es) [virtual]

Reimplemented from SiStripCommonModeNoiseSubtractor.

Definition at line 9 of file IteratedMedianCMNSubtractor.cc.

References edm::EventSetup::get(), noise_cache_id, noiseHandle, quality_cache_id, and qualityHandle.

                                                             {
  uint32_t n_cache_id = es.get<SiStripNoisesRcd>().cacheIdentifier();
  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();

  if(n_cache_id != noise_cache_id) {
    es.get<SiStripNoisesRcd>().get( noiseHandle );
    noise_cache_id = n_cache_id;
  }
  if(q_cache_id != quality_cache_id) {
    es.get<SiStripQualityRcd>().get( qualityHandle );
    quality_cache_id = q_cache_id;
  }
}
float IteratedMedianCMNSubtractor::pairMedian ( std::vector< std::pair< float, float > > &  sample) [inline, private]

Definition at line 90 of file IteratedMedianCMNSubtractor.cc.

Referenced by subtract_().

                                                                                              {
  std::vector<std::pair<float,float> >::iterator mid = sample.begin() + sample.size()/2;
  std::nth_element(sample.begin(), mid, sample.end());
  if( sample.size() & 1 ) //odd size
    return (*mid).first;
  return ( (*std::max_element(sample.begin(), mid)).first + (*mid).first ) / 2.;
}
void IteratedMedianCMNSubtractor::subtract ( const uint32_t &  detId,
const uint16_t &  firstAPV,
std::vector< int16_t > &  digis 
) [virtual]

Implements SiStripCommonModeNoiseSubtractor.

Definition at line 23 of file IteratedMedianCMNSubtractor.cc.

References subtract_().

{ subtract_(detId, firstAPV, digis);}
void IteratedMedianCMNSubtractor::subtract ( const uint32_t &  detId,
const uint16_t &  firstAPV,
std::vector< float > &  digis 
) [virtual]

Implements SiStripCommonModeNoiseSubtractor.

Definition at line 24 of file IteratedMedianCMNSubtractor.cc.

References subtract_().

{ subtract_(detId,firstAPV, digis);}
template<typename T >
void IteratedMedianCMNSubtractor::subtract_ ( const uint32_t &  detId,
const uint16_t &  firstAPV,
std::vector< T > &  digis 
) [inline, private]

Definition at line 29 of file IteratedMedianCMNSubtractor.cc.

References SiStripCommonModeNoiseSubtractor::_vmedians, sistrip::APV, cut_to_avoid_signal_, iterations_, python::rootplot::utilities::ls(), noiseHandle, evf::evtn::offset(), pairMedian(), and qualityHandle.

Referenced by subtract().

                                                                               {

  SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId);
  SiStripQuality::Range detQualityRange = qualityHandle->getRange(detId);

  typename std::vector<T>::iterator fs,ls;
  float offset = 0;  
  std::vector< std::pair<float,float> > subset;
  subset.reserve(128);

  _vmedians.clear(); 
  
  uint16_t APV=firstAPV;
  for( ; APV< digis.size()/128+firstAPV; ++APV)
  {
    subset.clear();
    // fill subset vector with all good strips and their noises
    for (uint16_t istrip=APV*128; istrip<(APV+1)*128; ++istrip)
    {
      if ( !qualityHandle->IsStripBad(detQualityRange,istrip) )
      {
        std::pair<float,float> pin((float)digis[istrip-firstAPV*128], (float)noiseHandle->getNoiseFast(istrip,detNoiseRange));
        subset.push_back( pin );
      }
    }

    // caluate offset for all good strips (first iteration)
    if (subset.size() != 0)
      offset = pairMedian(subset);

    // for second, third... iterations, remove strips over threshold
    // and recalculate offset on remaining strips
    for ( int ii = 0; ii<iterations_-1; ++ii )
    {
      std::vector< std::pair<float,float> >::iterator si = subset.begin();
      while(  si != subset.end() )
      {
        if( si->first-offset > cut_to_avoid_signal_*si->second )  
          si = subset.erase(si);
        else
          ++si;
      }
      if ( subset.size() == 0 ) break;
      offset = pairMedian(subset);
    }        

    _vmedians.push_back(std::pair<short,float>(APV,offset));
    
    // remove offset
    fs = digis.begin()+(APV-firstAPV)*128;
    ls = digis.begin()+(APV-firstAPV+1)*128;
    while (fs < ls) {
      *fs = static_cast<T>(*fs-offset);
      fs++;
    }

  }
}

Friends And Related Function Documentation

friend class SiStripRawProcessingFactory [friend]

Reimplemented from SiStripCommonModeNoiseSubtractor.

Definition at line 13 of file IteratedMedianCMNSubtractor.h.


Member Data Documentation

Definition at line 30 of file IteratedMedianCMNSubtractor.h.

Referenced by subtract_().

Definition at line 32 of file IteratedMedianCMNSubtractor.h.

Referenced by subtract_().

Definition at line 35 of file IteratedMedianCMNSubtractor.h.

Referenced by init().

Definition at line 33 of file IteratedMedianCMNSubtractor.h.

Referenced by init(), and subtract_().

Definition at line 35 of file IteratedMedianCMNSubtractor.h.

Referenced by init().

Definition at line 34 of file IteratedMedianCMNSubtractor.h.

Referenced by init(), and subtract_().