00001 #include "CommonTools/SiStripClusterization/interface/SiStripThreeThresholdAlgo.h"
00002 #include <vector>
00003 #include <algorithm>
00004 #include <cmath>
00005
00006
00007
00008 SiStripThreeThresholdAlgo::SiStripThreeThresholdAlgo( const edm::ParameterSet& pset ) :
00009
00010 SiStripClusterizerAlgo(pset),
00011 stripThr_(pset.getUntrackedParameter<double>("ChannelThreshold",2.)),
00012 seedThr_(pset.getUntrackedParameter<double>("SeedThreshold",3.)),
00013 clustThr_(pset.getUntrackedParameter<double>("ClusterThreshold",5.)),
00014 maxHoles_(pset.getUntrackedParameter<uint32_t>("MaxHolesInCluster",0)),
00015 charge_(0),
00016 seed_(false),
00017 sigmanoise2_(0.),
00018 strip_(0),
00019 first_(0),
00020 amps_(),
00021 digis_()
00022
00023 {
00024 LogTrace("UNDEFINED_CATEGORY")
00025 << "[SiStripThreeThresholdAlgo::" << __func__ << "]";
00026
00027 amps_.reserve(768);
00028 digis_.reserve(768);
00029 }
00030
00031
00032
00033 SiStripThreeThresholdAlgo::~SiStripThreeThresholdAlgo() {
00034
00035 LogTrace("UNDEFINED_CATEGORY")
00036 << "[SiStripThreeThresholdAlgo::" << __func__ << "]";
00037 }
00038
00039
00040
00041 void SiStripThreeThresholdAlgo::clusterize( const edm::DetSet<SiStripDigi>& digis, edm::DetSetVector<SiStripCluster>& clusters ) {
00042
00043 LogTrace("UNDEFINED_CATEGORY")
00044 << "[SiStripThreeThresholdAlgo::" << __func__ << "]";
00045
00046 edm::DetSet<SiStripCluster>& out = clusters.find_or_insert(digis.id);
00047 edm::DetSet<SiStripDigi>::const_iterator idigi = digis.begin();
00048 for (; idigi != digis.end(); idigi++) {
00049 add(out.data,out.id,idigi->strip(),idigi->adc());}
00050 endDet(out.data,out.id);
00051 }
00052
00053
00054
00055 void SiStripThreeThresholdAlgo::add(std::vector<SiStripCluster>& data, const uint32_t& id, const uint16_t& istrip, const uint16_t& adc) {
00056
00057 bool disable = quality()->IsStripBad(quality()->getRange(id),istrip);
00058 double stripnoise = noise()->getNoise(istrip,noise()->getRange(id));
00059 double stripgain = gain()->getStripGain(istrip,gain()->getRange(id));
00060 bool thresh = threshold(adc,stripnoise,disable);
00061 bool prox = proximity(istrip);
00062
00063
00064 if (adc && disable) digis_.push_back(istrip);
00065
00066 if (thresh && prox) {strip(istrip,adc,stripnoise,stripgain);}
00067
00068 else if (thresh && !prox) {endCluster(data,id);strip(istrip,adc,stripnoise,stripgain);}
00069
00070 else if (!thresh && !prox) {endCluster(data,id);}
00071
00072
00073
00074 }
00075
00076 void SiStripThreeThresholdAlgo::endDet(std::vector<SiStripCluster>& data, const uint32_t& id) {
00077 endCluster(data,id); digis_.clear();
00078 }
00079
00080 bool SiStripThreeThresholdAlgo::proximity(const uint16_t& istrip) const {
00081 if (amps_.empty()) return true;
00082 return (istrip <= maxHoles_+strip_+1);
00083 }
00084
00085 bool SiStripThreeThresholdAlgo::threshold(const uint16_t& adc, const double& noise, const bool disable) const {
00086 return (!disable && (adc >= static_cast<uint32_t>(noise * stripThr_)));
00087 }
00088
00089 void SiStripThreeThresholdAlgo::pad(const uint16_t& left, const uint16_t& right) {
00090 for (uint16_t i=0;i<left;i++) {amps_.insert(amps_.begin(),0);first_--;}
00091 for (uint16_t k=0;k<right;k++) {amps_.push_back(0);}
00092 }
00093
00094 void SiStripThreeThresholdAlgo::strip(const uint16_t& istrip, const uint16_t& adc, const double& noise, const double& gain) {
00095
00096
00097 if (adc >= noise*seedThr_) seed_ = true;
00098 if (amps_.empty()) first_ = istrip;
00099 else if (istrip - strip_ -1 > 0) {pad(0,istrip - strip_ -1);}
00100
00101
00102 float stripCharge=(static_cast<float>(adc));
00103 if(stripCharge<254){
00104 stripCharge /= gain;
00105 if(stripCharge>511.5){stripCharge=255;}
00106 else if(stripCharge>253.5){stripCharge=254;}
00107 }
00108 amps_.push_back(static_cast<uint16_t>(stripCharge+0.5));
00109 strip_ = istrip;
00110
00111 charge_+=stripCharge;
00112 sigmanoise2_+=noise*noise/(gain*gain);
00113 }
00114
00115 void SiStripThreeThresholdAlgo::endCluster(std::vector<SiStripCluster>& data, const uint32_t& id) {
00116 if (seed_ && (charge_ >= sqrt(sigmanoise2_) * clustThr_)) {
00117 if (find(digis_.begin(),digis_.end(),first_ -1) != digis_.end()) pad(1,0);
00118 if (find(digis_.begin(),digis_.end(),strip_+1) != digis_.end()) pad(0,1);
00119 data.push_back(SiStripCluster(id, first_, amps_.begin(),amps_.end()));
00120 }
00121 charge_ = 0.; sigmanoise2_ = 0.; seed_ = false; amps_.clear();
00122 }