Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-27 01:27:34

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 
0030   float halfwidth_ = 0.5f * float(cluster.width());
0031 
0032   //initialize firstStrip_
0033   firstStrip_ = std::max(barycenter_ - halfwidth_, 0.f);
0034 
0035   if UNLIKELY (firstStrip_ + cluster.width() > maxStrips) {
0036     firstStrip_ = maxStrips - cluster.width();
0037   }
0038 }
0039 
0040 int SiStripCluster::charge() const {
0041   if (barycenter_ > 0)
0042     return charge_;
0043   return std::accumulate(begin(), end(), int(0));
0044 }
0045 
0046 float SiStripCluster::barycenter() const {
0047   if (barycenter_ > 0)
0048     return barycenter_;
0049 
0050   int sumx = 0;
0051   int suma = 0;
0052   auto asize = size();
0053   for (auto i = 0U; i < asize; ++i) {
0054     sumx += i * amplitudes_[i];
0055     suma += amplitudes_[i];
0056   }
0057 
0058   // strip centers are offcet by half pitch w.r.t. strip numbers,
0059   // so one has to add 0.5 to get the correct barycenter position.
0060   // Need to mask off the high bit of firstStrip_, which contains the merged status.
0061   return float((firstStrip_ & stripIndexMask)) + float(sumx) / float(suma) + 0.5f;
0062 }