Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:30

0001 #ifndef CalibFormats_SiStripObjects_StripClusterizerConditions_h
0002 #define CalibFormats_SiStripObjects_StripClusterizerConditions_h
0003 
0004 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0005 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0006 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0007 
0008 /**
0009  * Cache of the noise and quality ranges per module, and the 1/gain value for each APV, for fast access by the clusterizer
0010  */
0011 class SiStripClusterizerConditions {
0012 public:
0013   static constexpr unsigned short invalidI = std::numeric_limits<unsigned short>::max();
0014 
0015   struct Det {
0016     bool valid() const { return ind != invalidI; }
0017     uint16_t rawNoise(const uint16_t strip) const { return SiStripNoises::getRawNoise(strip, noiseRange); }
0018     float noise(const uint16_t strip) const { return SiStripNoises::getNoise(strip, noiseRange); }
0019     float weight(const uint16_t strip) const { return m_weight[strip / 128]; }
0020     bool bad(const uint16_t strip) const { return quality->IsStripBad(qualityRange, strip); }
0021     bool allBadBetween(uint16_t L, const uint16_t& R) const {
0022       while (++L < R && bad(L)) {
0023       };
0024       return L == R;
0025     }
0026     SiStripQuality const* quality;
0027     SiStripNoises::Range noiseRange;
0028     SiStripQuality::Range qualityRange;
0029     float m_weight[6];
0030     uint32_t detId = 0;
0031     unsigned short ind = invalidI;
0032   };
0033 
0034   explicit SiStripClusterizerConditions(const SiStripQuality* quality) : m_quality(quality) {}
0035 
0036   std::vector<uint32_t> const& allDetIds() const { return m_detIds; }
0037   auto const& allDets() const { return m_dets; }
0038 
0039   std::vector<const FedChannelConnection*> const& currentConnection(const Det& det) const {
0040     return m_connections[det.ind];
0041   }
0042 
0043   Det const& findDetId(const uint32_t id) const {
0044     auto b = m_detIds.begin();
0045     auto e = m_detIds.end();
0046     auto p = std::lower_bound(b, e, id);
0047     if (p == e || id != (*p)) {
0048 #ifdef NOT_ON_MONTECARLO
0049       edm::LogWarning("StripClusterizerAlgorithm")
0050           << "id " << id << " not connected. this is impossible on data " << std::endl;
0051 #endif
0052       static const Det dummy = Det();
0053       return dummy;
0054     }
0055     return m_dets[p - m_detIds.begin()];
0056   }
0057   bool isModuleBad(const uint32_t id) const { return m_quality->IsModuleBad(id); }
0058   bool isModuleUsable(const uint32_t id) const { return m_quality->IsModuleUsable(id); }
0059 
0060   void reserve(std::size_t length) {
0061     m_detIds.reserve(length);
0062     m_dets.reserve(length);
0063     m_connections.reserve(length);
0064   }
0065   void emplace_back(uint32_t id,
0066                     SiStripQuality::Range qualityRange,
0067                     SiStripNoises::Range noiseRange,
0068                     const std::vector<float>& invGains,
0069                     const std::vector<const FedChannelConnection*>& connections) {
0070     const unsigned short index = m_detIds.size();
0071     m_detIds.push_back(id);
0072     auto& det = m_dets.emplace_back();
0073     det.quality = m_quality;
0074     det.qualityRange = qualityRange;
0075     det.noiseRange = noiseRange;
0076     for (uint32_t i = 0; i != invGains.size(); ++i) {
0077       det.m_weight[i] = invGains[i];
0078     }
0079     det.detId = id;
0080     det.ind = index;
0081     m_connections.push_back(connections);
0082   }
0083 
0084 private:
0085   const SiStripQuality* m_quality;
0086   std::vector<uint32_t> m_detIds;
0087   std::vector<Det> m_dets;
0088   std::vector<std::vector<const FedChannelConnection*>> m_connections;
0089 };
0090 
0091 #endif  // CalibFormats_SiStripObjects_StripClusterizerConditions_h