CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CondFormats/SiStripObjects/interface/SiStripThreshold.h

Go to the documentation of this file.
00001 #ifndef SiStripThreshold_h
00002 #define SiStripThreshold_h
00003 
00004 #include<vector>
00005 #include<map>
00006 #include<iostream>
00007 #include<boost/cstdint.hpp>
00008 #include "DataFormats/SiStripCommon/interface/ConstantsForCondObjects.h"
00009 #include <sstream>
00010 
00038 class SiStripThreshold {
00039 
00040  public:
00041 
00042   struct Data{
00043     //used to create the threshold object for the ZS (that has only 2 thresholds) 
00044     inline void encode (const uint16_t& strip, const float& lTh,const float& hTh) {        
00045       FirstStrip_and_Hth = 
00046         ((strip & sistrip::FirstThStripMask_)<<sistrip::FirstThStripShift_) |
00047         ((uint32_t)(hTh*5.0+0.5) & sistrip::HighThStripMask_);
00048       
00049       lowTh=((uint32_t)(lTh*5.0+0.5) & sistrip::LowThStripMask_);
00050       clusTh=0; //put as default;
00051     }
00052 
00053 
00054     inline void encode (const uint16_t& strip, const float& lTh,const float& hTh, const float& cTh) {        
00055       encode (strip,lTh,hTh);
00056       clusTh=(uint8_t)(cTh*10+.5);
00057     }
00058     
00059     inline uint16_t getFirstStrip() const {return (FirstStrip_and_Hth>>sistrip::FirstThStripShift_);}
00060     inline float  getHth() const {return (FirstStrip_and_Hth& sistrip::HighThStripMask_)/5.0;}
00061     inline float  getLth()const {return (lowTh& sistrip::LowThStripMask_)/5.0;}
00062     inline float  getClusth()const {return clusTh/10.0;} 
00063 
00064     bool operator == (const Data& d) const { return (getHth() == d.getHth()) && (lowTh == d.lowTh) && (clusTh == d.clusTh); } 
00065     bool operator  < (const Data& d) const { return (FirstStrip_and_Hth  < d.FirstStrip_and_Hth); } 
00066 
00067     void print(std::stringstream& ss) const{ ss << "firstStrip: " << getFirstStrip() << " \t"
00068                                           << "lTh: " << " " << getLth() << " \t"
00069                                           << "hTh: " << " " << getHth() << " \t"
00070                                           << "cTh: " << " " << getClusth() << " \t";}
00071     
00072     uint16_t FirstStrip_and_Hth;
00073     uint8_t lowTh;
00074     uint8_t clusTh;
00075   };
00076   
00077   struct DetRegistry{
00078     uint32_t detid;
00079     uint32_t ibegin;
00080     uint32_t iend;
00081   };
00082 
00083 
00084   class StrictWeakOrdering{
00085   public:
00086     bool operator() (const DetRegistry& p,const uint32_t& i) const {return p.detid < i;}
00087   };
00088 
00089   class dataStrictWeakOrdering{
00090   public:
00091     bool operator() (const uint16_t& i, const Data& p) const {return i<p.FirstStrip_and_Hth ;}
00092   };
00093   
00094 
00095   typedef std::vector<Data>                                Container;  
00096   typedef Container::const_iterator                        ContainerIterator;  
00097   typedef std::pair<ContainerIterator, ContainerIterator>  Range;      
00098   typedef std::vector<DetRegistry>                         Registry;
00099   typedef Registry::const_iterator                         RegistryIterator;
00100   typedef Container                                        InputVector;  
00101  
00102   SiStripThreshold(){};
00103   SiStripThreshold(const SiStripThreshold& orig){
00104     v_threshold=orig.v_threshold; 
00105     indexes=orig.indexes;
00106   }
00107   virtual ~SiStripThreshold(){};
00108   
00109   bool put(const uint32_t& detID,InputVector vect);
00110   const Range getRange(const uint32_t& detID) const;
00111   void getDetIds(std::vector<uint32_t>& DetIds_) const;
00112   
00113   
00114   ContainerIterator getDataVectorBegin()     const {return v_threshold.begin();}
00115   ContainerIterator getDataVectorEnd()       const {return v_threshold.end();}
00116   RegistryIterator  getRegistryVectorBegin() const {return indexes.begin();}
00117   RegistryIterator  getRegistryVectorEnd()   const{return indexes.end();}
00118 
00119   void  setData(const uint16_t& strip, const float& lTh,const float& hTh, Container& vthr);
00120   void  setData(const uint16_t& strip, const float& lTh,const float& hTh, const float& cTh, Container& vthr);
00121   SiStripThreshold::Data getData (const uint16_t& strip, const Range& range) const;
00122  
00123   void  allThresholds(std::vector<float> &lowThs, std::vector<float> &highThs, const Range& range)  const; 
00124 
00126   void printSummary(std::stringstream& ss) const;
00128   void printDebug(std::stringstream& ss) const;
00129 
00130  private:
00131   
00132   Container::iterator compact(Container& input);
00133   void addToStat(float value, uint16_t& range, float& sum, float& sum2, float& min, float& max) const;
00134 
00135  private:
00136   Container v_threshold; 
00137   Registry indexes;
00138 };
00139 
00140 #endif