Go to the documentation of this file.00001 #include "RecoLocalTracker/SiStripClusterizer/interface/SiStripClusterInfo.h"
00002
00003 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00004 #include "CalibTracker/Records/interface/SiStripGainRcd.h"
00005 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithmFactory.h"
00008 #include "RecoLocalTracker/SiStripClusterizer/interface/StripClusterizerAlgorithm.h"
00009 #include <cmath>
00010
00011
00012
00013 SiStripClusterInfo::SiStripClusterInfo(const SiStripCluster& cluster,
00014 const edm::EventSetup& setup,
00015 const int detId,
00016 const std::string & quality)
00017 : cluster_ptr(&cluster),
00018 es(setup),
00019 qualityLabel(quality),
00020 detId_(detId) {
00021 es.get<SiStripNoisesRcd>().get(noiseHandle);
00022 es.get<SiStripGainRcd>().get(gainHandle);
00023 es.get<SiStripQualityRcd>().get(qualityLabel,qualityHandle);
00024 }
00025
00026 std::pair<uint16_t,uint16_t > SiStripClusterInfo::
00027 chargeLR() const {
00028 std::vector<uint8_t>::const_iterator
00029 begin( stripCharges().begin() ),
00030 end( stripCharges().end() ),
00031 max; max = max_element(begin,end);
00032 return std::make_pair( accumulate(begin, max, uint16_t(0) ),
00033 accumulate(max+1, end, uint16_t(0) ) );
00034 }
00035
00036
00037 float SiStripClusterInfo::
00038 variance() const {
00039 float q(0), x1(0), x2(0);
00040 for(std::vector<uint8_t>::const_iterator
00041 begin(stripCharges().begin()), end(stripCharges().end()), it(begin);
00042 it!=end; ++it) {
00043 unsigned i = it-begin;
00044 q += (*it);
00045 x1 += (*it) * (i+0.5);
00046 x2 += (*it) * (i*i+i+1./3);
00047 }
00048 return (x2 - x1*x1/q ) / q;
00049 }
00050
00051 std::vector<float> SiStripClusterInfo::
00052 stripNoisesRescaledByGain() const {
00053 SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId_);
00054 SiStripApvGain::Range detGainRange = gainHandle->getRange(detId_);
00055
00056 std::vector<float> results;
00057 results.reserve(width());
00058 for(size_t i = 0, e = width(); i < e; i++){
00059 results.push_back(noiseHandle->getNoise(firstStrip()+i, detNoiseRange) / gainHandle->getStripGain( firstStrip()+i, detGainRange));
00060 }
00061 return results;
00062 }
00063
00064 std::vector<float> SiStripClusterInfo::
00065 stripNoises() const {
00066 SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId_);
00067
00068 std::vector<float> noises;
00069 noises.reserve(width());
00070 for(size_t i=0; i < width(); i++){
00071 noises.push_back( noiseHandle->getNoise( firstStrip()+i, detNoiseRange) );
00072 }
00073 return noises;
00074 }
00075
00076 std::vector<float> SiStripClusterInfo::
00077 stripGains() const {
00078 SiStripApvGain::Range detGainRange = gainHandle->getRange(detId_);
00079
00080 std::vector<float> gains;
00081 gains.reserve(width());
00082 for(size_t i=0; i< width(); i++){
00083 gains.push_back( gainHandle->getStripGain( firstStrip()+i, detGainRange) );
00084 }
00085 return gains;
00086 }
00087
00088 std::vector<bool> SiStripClusterInfo::
00089 stripQualitiesBad() const {
00090 std::vector<bool> isBad;
00091 isBad.reserve(width());
00092 for(int i=0; i< width(); i++) {
00093 isBad.push_back( qualityHandle->IsStripBad( detId_,
00094 firstStrip()+i) );
00095 }
00096 return isBad;
00097 }
00098
00099 float SiStripClusterInfo::
00100 calculate_noise(const std::vector<float>& noise) const {
00101 float noiseSumInQuadrature = 0;
00102 int numberStripsOverThreshold = 0;
00103 for(int i=0;i<width();i++) {
00104 if(stripCharges().at(i)!=0) {
00105 noiseSumInQuadrature += noise.at(i) * noise.at(i);
00106 numberStripsOverThreshold++;
00107 }
00108 }
00109 return std::sqrt( noiseSumInQuadrature / numberStripsOverThreshold );
00110 }
00111
00112
00113 bool SiStripClusterInfo::
00114 IsAnythingBad() const {
00115 std::vector<bool> stripBad = stripQualitiesBad();
00116 return
00117 IsApvBad() ||
00118 IsFiberBad() ||
00119 IsModuleBad() ||
00120 accumulate(stripBad.begin(), stripBad.end(),
00121 false,
00122 std::logical_or<bool>());
00123 }
00124
00125 bool SiStripClusterInfo::
00126 IsApvBad() const {
00127 return
00128 qualityHandle->IsApvBad( detId_, firstStrip()/128 ) ||
00129 qualityHandle->IsApvBad( detId_, (firstStrip()+width())/128 ) ;
00130 }
00131
00132 bool SiStripClusterInfo::
00133 IsFiberBad() const {
00134 return
00135 qualityHandle->IsFiberBad( detId_, firstStrip()/256 ) ||
00136 qualityHandle->IsFiberBad( detId_, (firstStrip()+width())/256 ) ;
00137 }
00138
00139 bool SiStripClusterInfo::
00140 IsModuleBad() const {
00141 return qualityHandle->IsModuleBad( detId_ );
00142 }
00143
00144 bool SiStripClusterInfo::
00145 IsModuleUsable() const {
00146 return qualityHandle->IsModuleUsable( detId_ );
00147 }
00148
00149 std::vector<SiStripCluster> SiStripClusterInfo::
00150 reclusterize(const edm::ParameterSet& conf) const {
00151
00152 std::vector<SiStripCluster> clusters;
00153
00154 std::vector<uint8_t> charges = stripCharges();
00155 std::vector<float> gains = stripGains();
00156 for(unsigned i=0; i < charges.size(); i++)
00157 charges[i] = (charges[i] < 254)
00158 ? static_cast<uint8_t>(charges[i] * gains[i])
00159 : charges[i];
00160
00161 std::auto_ptr<StripClusterizerAlgorithm>
00162 algorithm = StripClusterizerAlgorithmFactory::create(conf);
00163 algorithm->initialize(es);
00164
00165 if( algorithm->stripByStripBegin( detId_ )) {
00166 for(unsigned i = 0; i<width(); i++)
00167 algorithm->stripByStripAdd( firstStrip()+i, charges[i], clusters );
00168 algorithm->stripByStripEnd( clusters );
00169 }
00170
00171 return clusters;
00172 }
00173