Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormats_HcalObjects_HBHELinearMap_h_
0002 #define CondFormats_HcalObjects_HBHELinearMap_h_
0003 
0004 //
0005 // Linearize the channel id in the HBHE
0006 //
0007 // I. Volobouev
0008 // September 2014
0009 //
0010 
0011 #include <vector>
0012 #include <utility>
0013 
0014 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0015 
0016 class HBHELinearMap {
0017 public:
0018   enum { ChannelCount = 5184U };
0019 
0020   HBHELinearMap();
0021 
0022   // Mapping from the depth/ieta/iphi triple which uniquely
0023   // identifies an HBHE channel into a linear index, currently
0024   // from 0 to 5183 (inclusive). This linear index should not
0025   // be treated as anything meaningful -- consider it to be
0026   // just a convenient unique key in a database table.
0027   unsigned linearIndex(unsigned depth, int ieta, unsigned iphi) const;
0028 
0029   // Check whether the given triple is a valid depth/ieta/iphi combination
0030   bool isValidTriple(unsigned depth, int ieta, unsigned iphi) const;
0031 
0032   // Inverse mapping, from a linear index into depth/ieta/iphi triple.
0033   // Any of the argument pointers is allowed to be NULL in which case
0034   // the corresponding variable is simply not filled out.
0035   void getChannelTriple(unsigned index, unsigned* depth, int* ieta, unsigned* iphi) const;
0036 
0037   // The following assumes a valid HBHE depth/ieta combination
0038   static HcalSubdetector getSubdetector(unsigned depth, int ieta);
0039 
0040 private:
0041   class HBHEChannelId {
0042   public:
0043     inline HBHEChannelId() : depth_(1000U), ieta_(1000), iphi_(1000U) {}
0044 
0045     inline HBHEChannelId(const unsigned i_depth, const int i_ieta, const unsigned i_iphi)
0046         : depth_(i_depth), ieta_(i_ieta), iphi_(i_iphi) {}
0047 
0048     // Inspectors
0049     inline unsigned depth() const { return depth_; }
0050     inline int ieta() const { return ieta_; }
0051     inline unsigned iphi() const { return iphi_; }
0052 
0053     inline bool operator<(const HBHEChannelId& r) const {
0054       if (depth_ < r.depth_)
0055         return true;
0056       if (r.depth_ < depth_)
0057         return false;
0058       if (ieta_ < r.ieta_)
0059         return true;
0060       if (r.ieta_ < ieta_)
0061         return false;
0062       return iphi_ < r.iphi_;
0063     }
0064 
0065     inline bool operator==(const HBHEChannelId& r) const {
0066       return depth_ == r.depth_ && ieta_ == r.ieta_ && iphi_ == r.iphi_;
0067     }
0068 
0069     inline bool operator!=(const HBHEChannelId& r) const { return !(*this == r); }
0070 
0071   private:
0072     unsigned depth_;
0073     int ieta_;
0074     unsigned iphi_;
0075   };
0076 
0077   typedef std::pair<HBHEChannelId, unsigned> MapPair;
0078   typedef std::vector<MapPair> ChannelMap;
0079 
0080   unsigned find(unsigned depth, int ieta, unsigned iphi) const;
0081 
0082   HBHEChannelId lookup_[ChannelCount];
0083   ChannelMap inverse_;
0084 };
0085 
0086 // Standard map
0087 const HBHELinearMap& hbheChannelMap();
0088 
0089 #endif  // CondFormats_HcalObjects_HBHELinearMap_h_