CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibFormats/SiStripObjects/interface/SiStripRegionCabling.h

Go to the documentation of this file.
00001 #ifndef CalibTracker_SiStripConnectivity_SiStripRegionCabling_H
00002 #define CalibTracker_SiStripConnectivity_SiStripRegionCabling_H
00003 #define _USE_MATH_DEFINES
00004 
00005 #include <boost/cstdint.hpp>
00006 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00007 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00008 #include "DataFormats/Common/interface/RefGetter.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include <sstream>
00011 #include <vector>
00012 #include <map>
00013 #include <cmath>
00014 
00025 class SiStripRegionCabling {
00026 
00027  public:
00028 
00030   enum SubDet {TIB = 0, TOB = 1, TID = 2, TEC = 3, ALLSUBDETS = 4}; 
00031   enum Layer {TIBLAYERS = 4, TOBLAYERS = 6, TIDLAYERS = 3, TECLAYERS = 9, ALLLAYERS = 10}; 
00032 
00034   typedef std::map< uint32_t, std::vector<FedChannelConnection> > ElementCabling;
00035   typedef std::vector< ElementCabling > WedgeCabling;
00036   typedef std::vector< WedgeCabling > RegionCabling;
00037   typedef std::vector< RegionCabling > Cabling;
00038 
00041   typedef std::pair<double,double> Position;
00042   typedef std::pair<uint32_t,uint32_t> PositionIndex;
00043 
00046   typedef uint32_t ElementIndex;
00047 
00048   SiStripRegionCabling(const uint32_t,const uint32_t, const double);
00049 
00050   ~SiStripRegionCabling() {}
00051 
00054   inline void setRegionCabling(const Cabling&);
00055 
00056   inline const Cabling& getRegionCabling() const;
00057 
00058   inline const uint32_t etadivisions() const;
00059 
00060   inline const uint32_t phidivisions() const;
00061 
00065   inline const std::pair<double,double> regionDimensions() const;
00066 
00067   inline const Position position(const uint32_t) const;
00068 
00069   inline const Position position(const PositionIndex) const;
00070 
00071   inline const PositionIndex positionIndex(const uint32_t) const;
00072 
00073   const PositionIndex positionIndex(const Position) const;
00074 
00075   const uint32_t region(const Position) const;
00076   
00077   inline const uint32_t region(const PositionIndex) const;
00078 
00081   PositionIndex increment(const PositionIndex, int, int) const;
00082 
00086   inline static const ElementIndex elementIndex(const uint32_t region, const SubDet, const uint32_t layer);
00087 
00088   inline const ElementIndex elementIndex(const PositionIndex, const SubDet, const uint32_t layer) const;
00089 
00090   inline const ElementIndex elementIndex(const Position, const SubDet, const uint32_t layer) const;
00091 
00092   inline static const uint32_t layer(const ElementIndex);
00093   
00094   inline static const SubDet subdet(const ElementIndex);
00095   
00096   inline static const uint32_t region(const ElementIndex);
00097  
00100   static const SubDet subdetFromDetId(const uint32_t detid);
00101 
00102   static const uint32_t layerFromDetId(const uint32_t detid);
00103 
00104   static const uint32_t physicalLayerFromDetId(const uint32_t detid);
00105 
00106   static const uint32_t physicalLayer(const SubDet, const uint32_t layer);
00107 
00111   template <class T>
00112     void updateSiStripRefGetter(edm::RefGetter<T>& refgetter, 
00113                                 const edm::Handle< edm::LazyGetter<T> >& lazygetter, 
00114                                 const ElementIndex) const;
00115   
00116   template <class T>
00117     void updateSiStripRefGetter(edm::RefGetter<T>& refgetter, 
00118                                 const edm::Handle< edm::LazyGetter<T> >& lazygetter,
00119                                 const Position position, 
00120                                 const double deltaeta, 
00121                                 const double deltaphi, 
00122                                 const SubDet subdet, 
00123                                 const uint32_t layer) const;
00124   
00126   void print( std::stringstream& ) const;
00127   
00128  private:
00129  
00130  SiStripRegionCabling() {;}
00131  
00133  int etadivisions_;
00134  int phidivisions_;
00135  
00137  double etamax_;
00138  
00140  Cabling regioncabling_;
00141 }; 
00142 
00143 inline void SiStripRegionCabling::setRegionCabling(const Cabling& regioncabling) {
00144   regioncabling_ = regioncabling;
00145 }
00146 
00147 inline const SiStripRegionCabling::Cabling& SiStripRegionCabling::getRegionCabling() const {
00148   return regioncabling_;
00149 }
00150 
00151 inline const uint32_t SiStripRegionCabling::etadivisions() const {
00152   return static_cast<uint32_t>(etadivisions_);
00153 }
00154 
00155 inline const uint32_t SiStripRegionCabling::phidivisions() const {
00156   return static_cast<uint32_t>(phidivisions_);
00157 }
00158 
00159 inline const std::pair<double,double> SiStripRegionCabling::regionDimensions() const {
00160   return std::pair<double,double>((2.*etamax_)/etadivisions_,2.*M_PI/phidivisions_);
00161 }
00162 
00163 inline const SiStripRegionCabling::Position SiStripRegionCabling::position(const uint32_t region) const {
00164   PositionIndex index = positionIndex(region); 
00165   return position(index);
00166 }
00167 
00168 inline const SiStripRegionCabling::Position SiStripRegionCabling::position(const PositionIndex index) const {
00169   return Position(regionDimensions().first*(index.first+.5) - etamax_, regionDimensions().second*(index.second+.5)- M_PI);
00170 }
00171 
00172 inline const SiStripRegionCabling::PositionIndex SiStripRegionCabling::positionIndex(const uint32_t region) const {
00173   return PositionIndex(region/phidivisions_,region%phidivisions_);
00174 }
00175 
00176 inline const uint32_t SiStripRegionCabling::region(const PositionIndex index) const {
00177   return index.first*phidivisions_ + index.second;
00178 }
00179   
00180 inline const uint32_t SiStripRegionCabling::elementIndex(const uint32_t region, const SubDet subdet, const uint32_t layer) {
00181   return region*ALLSUBDETS*ALLLAYERS + subdet*ALLLAYERS + layer;
00182 }
00183 
00184 inline const uint32_t SiStripRegionCabling::elementIndex(const PositionIndex index, const SubDet subdet, const uint32_t layer) const {
00185   return elementIndex(region(index),subdet,layer);
00186 }
00187 
00188 inline const uint32_t SiStripRegionCabling::elementIndex(const Position position, const SubDet subdet, const uint32_t layer) const {
00189   return elementIndex(region(position),subdet,layer);
00190 }
00191 
00192 inline const uint32_t SiStripRegionCabling::layer(const uint32_t index) {
00193   return index%ALLLAYERS;
00194 }
00195   
00196 inline const SiStripRegionCabling::SubDet SiStripRegionCabling::subdet(const uint32_t index) {
00197   return static_cast<SiStripRegionCabling::SubDet>((index/ALLLAYERS)%ALLSUBDETS);
00198 }
00199   
00200 inline const uint32_t SiStripRegionCabling::region(const uint32_t index) {
00201   return index/(ALLSUBDETS*ALLLAYERS);
00202 }
00203 
00204 template <class T>
00205 void SiStripRegionCabling::updateSiStripRefGetter(edm::RefGetter<T>& refgetter, const edm::Handle< edm::LazyGetter<T> >& lazygetter, const uint32_t index) const {
00206   if (!refgetter.find(index)) refgetter.push_back(lazygetter,index);
00207 }
00208 
00209 template <class T>
00210 void SiStripRegionCabling::updateSiStripRefGetter(edm::RefGetter<T>& refgetter, const edm::Handle< edm::LazyGetter<T> >& lazygetter, const SiStripRegionCabling::Position pos, const double deltaeta, const double deltaphi, const SubDet sub, const uint32_t layer) const {
00211 
00212   PositionIndex index = positionIndex(pos);
00213   Position center = position(index);
00214   double offeta = pos.first-center.first;
00215   double offphi = pos.second-center.second;
00216   double toteta = deltaeta/regionDimensions().first;
00217   double totphi = deltaphi/regionDimensions().second; 
00218   uint32_t plueta = static_cast<uint32_t>(offeta+.5+toteta);
00219   uint32_t pluphi = static_cast<uint32_t>(offphi+.5+totphi);
00220   uint32_t mineta = static_cast<uint32_t>(-offeta+.5+toteta);
00221   uint32_t minphi = static_cast<uint32_t>(-offphi+.5+totphi);
00222  
00223   for (uint32_t i=0;i<mineta+plueta+1;i++) {
00224     for (uint32_t j=0;j<minphi+pluphi+1;j++) {
00225       const uint32_t k=elementIndex(increment(index,i-mineta,j-minphi),sub,layer);
00226       updateSiStripRefGetter<T>(refgetter,lazygetter,k);
00227     }
00228   } 
00229 }
00230 
00231 #endif