00001 00002 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" 00003 00004 SiStripCluster::SiStripCluster( uint32_t detid, const SiStripDigiRange& range) : 00005 detId_(detid), firstStrip_(range.first->strip()) 00006 { 00007 00008 amplitudes_.reserve( range.second - range.first); 00009 00010 uint16_t lastStrip=0; 00011 bool firstInloop = true; 00012 for (SiStripDigiIter i=range.first; i!=range.second; i++) { 00013 00015 if (!firstInloop && i->strip() != lastStrip + 1) { 00016 for (int j=0; j < i->strip()-(lastStrip+1); j++) { 00017 amplitudes_.push_back( 0); 00018 } 00019 } 00020 lastStrip = i->strip(); 00021 firstInloop = false; 00022 00023 amplitudes_.push_back(i->adc()); 00024 } 00025 } 00026 00027 SiStripCluster::SiStripCluster(const uint32_t& detid, 00028 const uint16_t& firstStrip, 00029 std::vector<uint16_t>::const_iterator begin, 00030 std::vector<uint16_t>::const_iterator end) : 00031 00032 detId_(detid), 00033 firstStrip_(firstStrip), 00034 amplitudes_(begin,end) 00035 {} 00036 00037 float SiStripCluster::barycenter() const{ 00038 int sumx = 0; 00039 int suma = 0; 00040 size_t asize = amplitudes_.size(); 00041 for (size_t i=0;i<asize;++i) { 00042 sumx += (firstStrip_+i)*(amplitudes_[i]); 00043 suma += amplitudes_[i]; 00044 } 00045 00046 // strip centers are offcet by half pitch w.r.t. strip numbers, 00047 // so one has to add 0.5 to get the correct barycenter position 00048 return sumx / static_cast<float>(suma) + 0.5; 00049 }