Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0002 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0003 #include <algorithm>
0004 #include <cmath>
0005 
0006 SiStripApproximateCluster::SiStripApproximateCluster(const SiStripCluster& cluster,
0007                                                      unsigned int maxNSat,
0008                                                      float hitPredPos,
0009                                                      bool peakFilter) {
0010   barycenter_ = std::round(cluster.barycenter() * 10);
0011   width_ = cluster.size();
0012   avgCharge_ = cluster.charge() / cluster.size();
0013   filter_ = false;
0014   isSaturated_ = false;
0015   peakFilter_ = peakFilter;
0016 
0017   //mimicing the algorithm used in StripSubClusterShapeTrajectoryFilter...
0018   //Looks for 3 adjacent saturated strips (ADC>=254)
0019   const auto& ampls = cluster.amplitudes();
0020   unsigned int thisSat = (ampls[0] >= 254), maxSat = thisSat;
0021   for (unsigned int i = 1, n = ampls.size(); i < n; ++i) {
0022     if (ampls[i] >= 254) {
0023       thisSat++;
0024     } else if (thisSat > 0) {
0025       maxSat = std::max<int>(maxSat, thisSat);
0026       thisSat = 0;
0027     }
0028   }
0029   if (thisSat > 0) {
0030     maxSat = std::max<int>(maxSat, thisSat);
0031   }
0032   if (maxSat >= maxNSat) {
0033     filter_ = true;
0034     isSaturated_ = true;
0035   }
0036 
0037   unsigned int hitStripsTrim = ampls.size();
0038   int sum = std::accumulate(ampls.begin(), ampls.end(), 0);
0039   uint8_t trimCut = std::min<uint8_t>(trimMaxADC_, std::floor(trimMaxFracTotal_ * sum));
0040   auto begin = ampls.begin();
0041   auto last = ampls.end() - 1;
0042   while (hitStripsTrim > 1 && (*begin < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(begin + 1))))) {
0043     hitStripsTrim--;
0044     ++begin;
0045   }
0046   while (hitStripsTrim > 1 && (*last < std::max<uint8_t>(trimCut, trimMaxFracNeigh_ * (*(last - 1))))) {
0047     hitStripsTrim--;
0048     --last;
0049   }
0050   if (hitStripsTrim < std::floor(std::abs(hitPredPos) - maxTrimmedSizeDiffNeg_)) {
0051     filter_ = false;
0052   } else if (hitStripsTrim <= std::ceil(std::abs(hitPredPos) + maxTrimmedSizeDiffPos_)) {
0053     filter_ = true;
0054   } else {
0055     filter_ = peakFilter_;
0056   }
0057 }