Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:39

0001 #ifndef SiStripThreshold_h
0002 #define SiStripThreshold_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <vector>
0007 #include <map>
0008 #include <iostream>
0009 #include "DataFormats/SiStripCommon/interface/ConstantsForCondObjects.h"
0010 #include <sstream>
0011 #include <cstdint>
0012 
0013 class TrackerTopology;
0014 
0015 /**
0016  * Holds the thresholds:<br>
0017  * - High threshold <br>
0018  * - Low threshold <br>
0019  * - Cluster threshold <br>
0020  * The values are stored as bitsets, in particular:
0021  * - One uint16_t stores the first strip and the high threshold.
0022  * - One uint8_t stores the low threshold.
0023  * - One uint8_t stores the cluster threshold.
0024  * The information are stored in a Data struct, which is also responsible
0025  * for the encoding and decoding. <br>
0026  * To fill the SiStripThreshold object:
0027  * - create and empty vector<Data>: SiStripThreshold::Container theSiStripVector;   
0028  * - use the setData method to fill it with the thresholds
0029  * - use the put method to save the values in the object.
0030  * The put method is used to actually fill the object. It receives the DetId and the vector<Data>
0031  * with the threshold values.<br>
0032  * Before being saved the vector<Data> is sorted in the FirstStrip and consecutive entries having
0033  * all the same thresholds are removed. This way it still stores the same information using less space.<br>
0034  * To retrieve the information:
0035  * - getDetIds: fills a vector with all detIds for which the thresholds have been stored.
0036  * - getDataVectorBegin and getDataVectorEnd: return the begin and end iterators to the vector<Data>.
0037  * - getData can be used to get the thresholds for a single strip.
0038  * The printSummary method prints mean, rms, min and max threshold values for each DetId.
0039  * The printDebug method prints all the thresholds for all DetIds.
0040  */
0041 
0042 class SiStripThreshold {
0043 public:
0044   struct Data {
0045     //used to create the threshold object for the ZS (that has only 2 thresholds)
0046     inline void encode(const uint16_t& strip, const float& lTh, const float& hTh) {
0047       FirstStrip_and_Hth = ((strip & sistrip::FirstThStripMask_) << sistrip::FirstThStripShift_) |
0048                            ((uint32_t)(hTh * 5.0 + 0.5) & sistrip::HighThStripMask_);
0049 
0050       lowTh = ((uint32_t)(lTh * 5.0 + 0.5) & sistrip::LowThStripMask_);
0051       clusTh = 0;  //put as default;
0052     }
0053 
0054     inline void encode(const uint16_t& strip, const float& lTh, const float& hTh, const float& cTh) {
0055       encode(strip, lTh, hTh);
0056       clusTh = (uint8_t)(cTh * 10 + .5);
0057     }
0058 
0059     inline uint16_t getFirstStrip() const { return (FirstStrip_and_Hth >> sistrip::FirstThStripShift_); }
0060     inline float getHth() const { return (FirstStrip_and_Hth & sistrip::HighThStripMask_) / 5.0; }
0061     inline float getLth() const { return (lowTh & sistrip::LowThStripMask_) / 5.0; }
0062     inline float getClusth() const { return clusTh / 10.0; }
0063 
0064     bool operator==(const Data& d) const {
0065       return (getHth() == d.getHth()) && (lowTh == d.lowTh) && (clusTh == d.clusTh);
0066     }
0067     bool operator<(const Data& d) const { return (FirstStrip_and_Hth < d.FirstStrip_and_Hth); }
0068 
0069     void print(std::stringstream& ss) const {
0070       ss << "firstStrip: " << getFirstStrip() << " \t"
0071          << "lTh: "
0072          << " " << getLth() << " \t"
0073          << "hTh: "
0074          << " " << getHth() << " \t"
0075          << "cTh: "
0076          << " " << getClusth() << " \t";
0077     }
0078 
0079     uint16_t FirstStrip_and_Hth;
0080     uint8_t lowTh;
0081     uint8_t clusTh;
0082 
0083     COND_SERIALIZABLE;
0084   };
0085 
0086   struct DetRegistry {
0087     uint32_t detid;
0088     uint32_t ibegin;
0089     uint32_t iend;
0090 
0091     COND_SERIALIZABLE;
0092   };
0093 
0094   class StrictWeakOrdering {
0095   public:
0096     bool operator()(const DetRegistry& p, const uint32_t& i) const { return p.detid < i; }
0097   };
0098 
0099   class dataStrictWeakOrdering {
0100   public:
0101     bool operator()(const uint16_t& i, const Data& p) const { return i < p.FirstStrip_and_Hth; }
0102   };
0103 
0104   typedef std::vector<Data> Container;
0105   typedef Container::const_iterator ContainerIterator;
0106   typedef std::pair<ContainerIterator, ContainerIterator> Range;
0107   typedef std::vector<DetRegistry> Registry;
0108   typedef Registry::const_iterator RegistryIterator;
0109   typedef Container InputVector;
0110 
0111   SiStripThreshold(){};
0112   SiStripThreshold(const SiStripThreshold& orig) {
0113     v_threshold = orig.v_threshold;
0114     indexes = orig.indexes;
0115   }
0116   virtual ~SiStripThreshold(){};
0117 
0118   bool put(const uint32_t& detID, const InputVector& vect);
0119   const Range getRange(const uint32_t& detID) const;
0120   void getDetIds(std::vector<uint32_t>& DetIds_) const;
0121 
0122   ContainerIterator getDataVectorBegin() const { return v_threshold.begin(); }
0123   ContainerIterator getDataVectorEnd() const { return v_threshold.end(); }
0124   RegistryIterator getRegistryVectorBegin() const { return indexes.begin(); }
0125   RegistryIterator getRegistryVectorEnd() const { return indexes.end(); }
0126 
0127   void setData(const uint16_t& strip, const float& lTh, const float& hTh, Container& vthr);
0128   void setData(const uint16_t& strip, const float& lTh, const float& hTh, const float& cTh, Container& vthr);
0129   SiStripThreshold::Data getData(const uint16_t& strip, const Range& range) const;
0130 
0131   void allThresholds(std::vector<float>& lowThs, std::vector<float>& highThs, const Range& range) const;
0132 
0133   /// Prints mean, rms, min and max threshold values for each DetId.
0134   void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0135   /// Prints all the thresholds for all DetIds.
0136   void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0137 
0138 private:
0139   Container::iterator compact(Container& input);
0140   void addToStat(float value, uint16_t& range, float& sum, float& sum2, float& min, float& max) const;
0141 
0142 private:
0143   Container v_threshold;
0144   Registry indexes;
0145 
0146   COND_SERIALIZABLE;
0147 };
0148 
0149 #endif