Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:12

0001 #include "FWCore/Utilities/interface/Likely.h"
0002 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0003 
0004 SiStripCluster::SiStripCluster(const SiStripDigiRange& range) : firstStrip_(range.first->strip()), error_x(-99999.9) {
0005   std::vector<uint8_t> v;
0006   v.reserve(range.second - range.first);
0007 
0008   uint16_t lastStrip = 0;
0009   bool firstInloop = true;
0010   for (SiStripDigiIter i = range.first; i != range.second; i++) {
0011     /// check if digis consecutive
0012     if (!firstInloop && i->strip() != lastStrip + 1) {
0013       for (int j = 0; j < i->strip() - (lastStrip + 1); j++) {
0014         v.push_back(0);
0015       }
0016     }
0017     lastStrip = i->strip();
0018     firstInloop = false;
0019 
0020     v.push_back(i->adc());
0021   }
0022   amplitudes_ = v;
0023 }
0024 
0025 SiStripCluster::SiStripCluster(const SiStripApproximateCluster cluster, const uint16_t maxStrips) : error_x(-99999.9) {
0026   barycenter_ = cluster.barycenter() / 10.0;
0027   charge_ = cluster.width() * cluster.avgCharge();
0028   amplitudes_.resize(cluster.width(), cluster.avgCharge());
0029   filter_ = cluster.filter();
0030 
0031   float halfwidth_ = 0.5f * float(cluster.width());
0032 
0033   //initialize firstStrip_
0034   firstStrip_ = std::max(barycenter_ - halfwidth_, 0.f);
0035 
0036   if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) {
0037     firstStrip_ = maxStrips - cluster.width();
0038   }
0039 }
0040 
0041 int SiStripCluster::charge() const {
0042   if (barycenter_ > 0)
0043     return charge_;
0044   return std::accumulate(begin(), end(), int(0));
0045 }
0046 
0047 float SiStripCluster::barycenter() const {
0048   if (barycenter_ > 0)
0049     return barycenter_;
0050 
0051   int sumx = 0;
0052   int suma = 0;
0053   auto asize = size();
0054   for (auto i = 0U; i < asize; ++i) {
0055     sumx += i * amplitudes_[i];
0056     suma += amplitudes_[i];
0057   }
0058 
0059   // strip centers are offcet by half pitch w.r.t. strip numbers,
0060   // so one has to add 0.5 to get the correct barycenter position.
0061   // Need to mask off the high bit of firstStrip_, which contains the merged status.
0062   return float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
0063 }
0064 bool SiStripCluster::filter() const {
0065   if (barycenter_ > 0)
0066     return filter_;
0067   return false;
0068 }
0069 
0070 bool SiStripCluster::isFromApprox() const { return (barycenter_ > 0); }