CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/RecoLocalTracker/SiStripZeroSuppression/src/TT6CMNSubtractor.cc

Go to the documentation of this file.
00001 #include "RecoLocalTracker/SiStripZeroSuppression/interface/TT6CMNSubtractor.h"
00002 
00003 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00004 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00005 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00006 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00007 #include <cmath>
00008 
00009 void TT6CMNSubtractor::init(const edm::EventSetup& es){
00010   uint32_t n_cache_id = es.get<SiStripNoisesRcd>().cacheIdentifier();
00011   uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
00012 
00013   if(n_cache_id != noise_cache_id) {
00014     es.get<SiStripNoisesRcd>().get( noiseHandle );
00015     noise_cache_id = n_cache_id;
00016   }
00017   if(q_cache_id != quality_cache_id) {
00018     es.get<SiStripQualityRcd>().get( qualityHandle );
00019     quality_cache_id = q_cache_id;
00020   }
00021 }
00022 
00023 void TT6CMNSubtractor::subtract(const uint32_t& detId, const uint16_t& firstAPV,  std::vector<int16_t>& digis){ subtract_(detId, firstAPV, digis);}
00024 void TT6CMNSubtractor::subtract(const uint32_t& detId, const uint16_t& firstAPV, std::vector<float>& digis){ subtract_(detId,firstAPV, digis);}
00025 
00026 template<typename T>
00027 inline
00028 void TT6CMNSubtractor::
00029 subtract_(const uint32_t& detId,const uint16_t& firstAPV, std::vector<T>& digis){
00030 
00031   short FixedBias=128;
00032   SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId);
00033   SiStripQuality::Range detQualityRange = qualityHandle->getRange(detId);
00034 
00035   typename std::vector<T>::iterator fs,ls;
00036   double sumVal = 0.0;
00037   double sumWt =  0.0;
00038   
00039   for (uint16_t istrip=0; istrip<digis.size(); ++istrip){
00040 
00041     if ( !qualityHandle->IsStripBad(detQualityRange,istrip+firstAPV*128) ) {
00042       float stripNoise=noiseHandle->getNoiseFast(istrip+firstAPV*128,detNoiseRange);
00043 
00044       if( fabs(digis[istrip]-FixedBias) < cut_to_avoid_signal_*stripNoise ) { 
00045         double nWeight = 1/(stripNoise*stripNoise);
00046         sumVal += (digis[istrip]-FixedBias)*nWeight;
00047         sumWt += nWeight;
00048       }
00049     }
00050 
00051     if (istrip%128 == 127){
00052       double CM = (sumWt) ? sumVal/sumWt :0.0;
00053       
00054       fs = digis.begin()+istrip-127;
00055       ls = digis.begin()+istrip+1;
00056       
00057       while (fs < ls) {
00058         *fs = static_cast<T>(*fs-FixedBias-CM);
00059         fs++;
00060       }
00061 
00062       sumVal = 0.0;
00063       sumWt =  0.0;
00064     }
00065   }
00066 }
00067