CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoTracker/RingRecord/interface/Ring.h

Go to the documentation of this file.
00001 #ifndef RECOTRACKER_RING_H
00002 #define RECOTRACKER_RING_H
00003 
00004 //
00005 // Package:         RecoTracker/RingRecord
00006 // Class:           Ring
00007 // 
00008 // Description:     A Ring represents all DetId's
00009 //                  at a given radius and z
00010 //                  summed over phi
00011 //
00012 // Original Author: Oliver Gutsche, gutsche@fnal.gov
00013 // Created:         Thu Jan 12 21:00:00 UTC 2006
00014 //
00015 // $Author: gutsche $
00016 // $Date: 2007/03/07 21:46:48 $
00017 // $Revision: 1.2 $
00018 //
00019 
00020 #include <iostream>
00021 #include <map>
00022 #include <sstream>
00023 #include <fstream>
00024 #include <utility>
00025 
00026 #include "DataFormats/DetId/interface/DetId.h"
00027 
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 #include "DataFormats/GeometryVector/interface/Pi.h"
00030 
00031 class Ring {
00032   
00033  public:
00034 
00035   typedef std::multimap<double,DetId> DetIdMap;
00036   typedef DetIdMap::iterator iterator;
00037   typedef DetIdMap::const_iterator const_iterator;
00038   typedef std::pair<iterator,iterator> IteratorRange;
00039   typedef std::pair<const_iterator,const_iterator> ConstIteratorRange;
00040 
00041   enum type {
00042     TIBRing,
00043     TOBRing,
00044     TIDRing,
00045     TECRing,
00046     PXBRing,
00047     PXFRing,
00048     Unspecified
00049   };
00050 
00051   Ring() : initialized_(false), 
00052            rmin_(0.), 
00053            rmax_(0.), 
00054            zmin_(0.), 
00055            zmax_(0.), 
00056            type_(Unspecified), 
00057            index_(0) {}
00058 
00059   Ring(type input) : initialized_(false), 
00060                      rmin_(0.), 
00061                      rmax_(0.), 
00062                      zmin_(0.), 
00063                      zmax_(0.), 
00064                      type_(input), 
00065                      index_(0) {}
00066 
00067   Ring(unsigned int index, 
00068        float rmin, 
00069        float rmax, 
00070        float zmin, 
00071        float zmax, 
00072        unsigned int type) : initialized_(true), 
00073                             rmin_(rmin), 
00074                             rmax_(rmax), 
00075                             zmin_(zmin), 
00076                             zmax_(zmax), 
00077                             index_(index) {
00078     if ( type == 0 ) {
00079       type_ = TIBRing;
00080     } else if ( type == 1 ) {
00081       type_ = TOBRing;
00082     } else if ( type == 2 ) {
00083       type_ = TIDRing;
00084     } else if ( type == 3 ) {
00085       type_ = TECRing;
00086     } else if ( type == 4 ) {
00087       type_ = PXBRing;
00088     } else if ( type == 5 ) {
00089       type_ = PXFRing;
00090     } else {
00091       type_ = Unspecified;
00092     } 
00093   }
00094   
00095   Ring(Ring* input) : detids_(input->getDetIdMap()), 
00096                       initialized_(input->isInitialized()), 
00097                       rmin_(input->getrmin()), 
00098                       rmax_(input->getrmax()), 
00099                       zmin_(input->getzmin()), 
00100                       zmax_(input->getzmax()), 
00101                       type_(input->getType()), 
00102                       index_(input->getindex()) {}
00103 
00104   ~Ring() {}
00105   
00106   inline void addId(double phi, DetId id) { detids_.insert(std::make_pair(phi,id)); }
00107 
00108   inline int getNumDetIds() const { return detids_.size(); }
00109   
00110   inline bool containsDetId(DetId id, double phi = 999999.,
00111                             double dphi_scalefactor = 1.5) const {
00112     // calculate window around given phi (if phi == 999999. set window to [-pi,pi])
00113     // determine phi segmentation from number of detids in ring
00114     // window is += 1.5 times the phi segmentation
00115     double phi_inner = -Geom::pi();
00116     double phi_outer =  Geom::pi();
00117     double delta_phi = Geom::twoPi() / detids_.size();
00118     if ( phi != 999999. ) {
00119       phi_inner = map_phi(phi - dphi_scalefactor*delta_phi);
00120       phi_outer = map_phi(phi + dphi_scalefactor*delta_phi);
00121     }
00122 
00123     // check for out of bounds of [0,2pi]
00124     if ( phi_inner > phi_outer ) {
00125       // double loop
00126       for ( const_iterator ring = detids_.lower_bound(phi_inner); ring != detids_.end(); ++ring ) {
00127         if ( id == ring->second ) {
00128           return true;
00129         }
00130       }
00131       for ( const_iterator ring = detids_.begin(); ring != detids_.upper_bound(phi_outer); ++ring ) {
00132         if ( id == ring->second ) {
00133           return true;
00134         }
00135       }
00136     } else {
00137       for ( const_iterator ring = detids_.lower_bound(phi_inner); ring != detids_.upper_bound(phi_outer); ++ring ) {
00138         if ( id == ring->second ) {
00139           return true;
00140         }
00141       }
00142     }
00143 
00144     return false;
00145   }
00146 
00147   inline const_iterator begin() const { return detids_.begin(); }
00148   inline const_iterator end()  const  { return detids_.end();   }
00149 
00150   inline iterator begin() { return detids_.begin(); }
00151   inline iterator end()  { return detids_.end();   }
00152 
00153   inline bool isInitialized() const { return initialized_; }
00154 
00155   inline float getrmin() const { if ( !isInitialized() ) notInitializedMsg(); return rmin_; }
00156   inline float getrmax() const { if ( !isInitialized() ) notInitializedMsg(); return rmax_; }
00157   inline float getzmin() const { if ( !isInitialized() ) notInitializedMsg(); return zmin_; }
00158   inline float getzmax() const { if ( !isInitialized() ) notInitializedMsg(); return zmax_; }
00159 
00160   inline void setrmin(float input) { rmin_ = input; }
00161   inline void setrmax(float input) { rmax_ = input; }
00162   inline void setzmin(float input) { zmin_ = input; }
00163   inline void setzmax(float input) { zmax_ = input; }
00164   
00165   inline void setInitialized(bool input) { initialized_ = input; }
00166   
00167   inline void initialize(float rmin, float rmax, float zmin, float zmax) { 
00168     rmin_ = rmin; 
00169     rmax_ = rmax; 
00170     zmin_ = zmin; 
00171     zmax_ = zmax; 
00172     initialized_ = true; }
00173 
00174   inline void notInitializedMsg() const { 
00175     edm::LogWarning("RoadSearch") << "Ring " << index_ << " does not have initialized values for r_min, r_max, z_min, z_max! Using default value of 0. !"; }
00176 
00177   inline void setType(type input) { type_ = input; }
00178 
00179   inline type getType() const { return type_; }
00180 
00181   inline DetId getFirst() const { return detids_.begin()->second; }
00182   
00183   inline void setindex(unsigned int input) { index_ = input; }
00184 
00185   inline unsigned int getindex() const { return index_; }
00186 
00187   inline DetIdMap getDetIdMap() const { return detids_; }
00188   
00190   int operator==(const Ring& ring) const { return index_==ring.getindex(); }
00192   int operator!=(const Ring& ring) const { return index_!=ring.getindex(); }
00194   int operator<(const Ring& ring) const { return index_<ring.getindex(); }
00195 
00196   inline std::string print() const {
00197     std::ostringstream stream;
00198     stream << "Ring: " << index_
00199            << " rmin: " << rmin_
00200            << " rmax: " << rmax_
00201            << " zmin: " << zmin_
00202            << " zmax: " << zmax_
00203            << " number of DetUnits: " << detids_.size();
00204     return stream.str();
00205   }
00206 
00207   inline std::string dump() const {
00208     std::ostringstream stream;
00209     stream << "### Ring with index: " << index_ << " ###" << std::endl;
00210     stream << index_
00211            << " " << rmin_
00212            << " " << rmax_
00213            << " " << zmin_
00214            << " " << zmax_ 
00215            << " " << type_ << std::endl;
00216     stream << detids_.size() << std::endl;
00217     for ( const_iterator entry = detids_.begin(); entry != detids_.end(); ++entry ) {
00218       stream << entry->first << " " << entry->second.rawId() << std::endl;
00219     }
00220     return stream.str();
00221   }
00222 
00223   inline const_iterator lower_bound(double phi) const { return detids_.lower_bound(phi); }
00224   inline const_iterator upper_bound(double phi) const { return detids_.upper_bound(phi); }
00225 
00226   inline double map_phi(double phi) const {
00227     // map phi to [-pi,pi]
00228     double result = phi;
00229     if ( result < -Geom::pi()) result += Geom::twoPi();
00230     if ( result >  Geom::pi()) result -= Geom::twoPi();
00231     return result;
00232   }
00233 
00234  private:
00235   
00236   DetIdMap detids_;
00237   
00238   bool initialized_;
00239 
00240   float rmin_;
00241   float rmax_;
00242   float zmin_;
00243   float zmax_;
00244 
00245   type type_;
00246 
00247   unsigned int index_;
00248 
00249 };
00250 
00251 #endif