Go to the documentation of this file.00001 #include "RecoLocalTracker/SiStripClusterizer/interface/SiStripApvShotCleaner.h"
00002 #include <algorithm>
00003 #include <boost/foreach.hpp>
00004
00005
00006
00007
00008 SiStripApvShotCleaner::
00009 SiStripApvShotCleaner():
00010 pDetSet(0),
00011 maxNumOfApvs(6),
00012 stripsPerApv(128),
00013 stripsForMedian(64){}
00014
00015
00016
00017 bool SiStripApvShotCleaner::
00018 clean(const edm::DetSet<SiStripDigi>& in, edm::DetSet<SiStripDigi>::const_iterator& scan, edm::DetSet<SiStripDigi>::const_iterator& end){
00019 if(in.size()<64)
00020 return false;
00021
00022 if(loop(in)){
00023 reset(scan,end);
00024 return true;
00025 }
00026 return false;
00027 }
00028
00029 bool SiStripApvShotCleaner::
00030 loop(const edm::DetSet<SiStripDigi>& in){
00031
00032 #ifdef DEBUGME
00033 std::stringstream ss;
00034 ss << __func__ << " working on detid " << in.detId() << " for a digi.size=" << in.size();
00035 #endif
00036
00037 shots_=false;
00038 BOOST_FOREACH(bool& val,shotApv_)
00039 val=false;
00040
00041 cacheDetId=in.detId();
00042
00043
00044
00045 for(size_t i=0;i<=maxNumOfApvs;++i){
00046
00047 SiStripDigi d(i*stripsPerApv,0);
00048 pFirstDigiOfApv[i] = std::lower_bound(in.begin(),in.end(),d);
00049
00050
00051 if(i>0 && pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1]>stripsForMedian){
00052 shots_=true;
00053 shotApv_[i-1]=true;
00054 #ifdef DEBUGME
00055 ss << " found an apv shot of " << pFirstDigiOfApv[i]-pFirstDigiOfApv[i-1] << " digis in detid " << in.detId() << " apv " << i << std::endl;
00056 #endif
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 }
00076
00077 #ifdef DEBUGME
00078 edm::LogInfo("ApvShot") << ss.str();
00079 #endif
00080
00081 if(!shots_)
00082 return false;
00083
00084 dumpInVector(pFirstDigiOfApv,maxNumOfApvs);
00085 return true;
00086 }
00087
00088 void SiStripApvShotCleaner::
00089 dumpInVector(edm::DetSet<SiStripDigi>::const_iterator* pFirstDigiOfApv,size_t maxNumOfApvs){
00090 vdigis.clear();
00091
00092 for(size_t i=0;i<maxNumOfApvs;++i){
00093 apvDigis.clear();
00094
00095 if(shotApv_[i]){
00096 apvDigis.insert(apvDigis.end(),pFirstDigiOfApv[i],pFirstDigiOfApv[i+1]);
00097 subtractCM();
00098 stable_sort(apvDigis.begin(),apvDigis.end());
00099 vdigis.insert(vdigis.end(),apvDigis.begin(),apvDigis.end());
00100 }else{
00101 vdigis.insert(vdigis.end(),pFirstDigiOfApv[i],pFirstDigiOfApv[i+1]);
00102 }
00103 }
00104
00105 #ifdef DEBUGME
00106 std::stringstream ss;
00107 ss <<"detid " << cacheDetId << " new digi.size " << vdigis.size() << "\n";
00108 for(size_t i=0;i<vdigis.size();++i)
00109 ss << "\t " << i << " strip " << vdigis[i].strip() << " adc " << vdigis[i].adc() ;
00110 edm::LogInfo("ApvShot") << ss.str() << std::endl;
00111 #endif
00112 }
00113
00114 void SiStripApvShotCleaner::subtractCM(){
00115
00116
00117 stable_sort(apvDigis.begin(),apvDigis.end(),orderingByCharge());
00118
00119
00120 if(apvDigis[stripsForMedian].adc()==0){
00121 #ifdef DEBUGME
00122 std::stringstream ss;
00123 ss << "case with strip64=0 --> detid= "<<cacheDetId<< "\n";
00124 edm::LogInfo("ApvShot") << ss.str();
00125 #endif
00126 return;
00127 }
00128
00129
00130 float CM = .5*(apvDigis[stripsForMedian].adc()+apvDigis[stripsForMedian-1].adc());
00131
00132
00133 if(CM<=0)
00134 return;
00135
00136
00137 size_t i=0;
00138 for(;i<stripsForMedian&&apvDigis[i].adc()>CM;++i){
00139 uint16_t adc=apvDigis[i].adc()>253?apvDigis[i].adc():(uint16_t)(apvDigis[i].adc()-CM);
00140 apvDigis[i]=SiStripDigi(apvDigis[i].strip(),adc);
00141 }
00142 apvDigis.resize(i);
00143
00144 #ifdef DEBUGME
00145 std::stringstream ss;
00146 ss << "[subtractCM] detid " << cacheDetId << " CM is " << CM << " the remaining strips after CM subtraction are " << i;
00147 edm::LogInfo("ApvShot") << ss.str();
00148 #endif
00149 }
00150
00151
00152 void SiStripApvShotCleaner::
00153 reset(edm::DetSet<SiStripDigi>::const_iterator& a, edm::DetSet<SiStripDigi>::const_iterator& b){
00154 refresh();
00155 pDetSet = new edm::DetSet<SiStripDigi>(cacheDetId);
00156 pDetSet->data.swap(vdigis);
00157 a=pDetSet->begin();
00158 b=pDetSet->end();
00159 }
00160
00161 void SiStripApvShotCleaner::
00162 refresh(){
00163 if(pDetSet!=NULL)
00164 delete pDetSet;
00165 }