CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTracker/TkHitPairs/interface/RecHitsSortedInPhi.h

Go to the documentation of this file.
00001 #ifndef RecHitsSortedInPhi_H
00002 #define RecHitsSortedInPhi_H
00003 
00004 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00005 
00006 #include <vector>
00007 
00013 class RecHitsSortedInPhi {
00014 public:
00015 
00016   typedef TransientTrackingRecHit::ConstRecHitPointer Hit;
00017 
00018   // A RecHit extension that caches the phi angle for fast access
00019   class HitWithPhi {
00020   public:
00021     HitWithPhi( const Hit & hit) : theHit(hit), thePhi(hit->globalPosition().phi()) {}
00022     HitWithPhi( float phi) : theHit(0), thePhi(phi) {}
00023     float phi() const {return thePhi;}
00024     const Hit hit() const { return theHit;}
00025   private:
00026     Hit   theHit;
00027     float thePhi;
00028   };
00029 
00030   struct HitLessPhi {
00031     bool operator()( const HitWithPhi& a, const HitWithPhi& b) { return a.phi() < b.phi(); }
00032   };
00033   typedef std::vector<HitWithPhi>::const_iterator      HitIter;
00034   typedef std::pair<HitIter,HitIter>            Range;
00035 
00036   RecHitsSortedInPhi( const std::vector<Hit>& hits);
00037 
00038   bool empty() const { return theHits.empty(); }
00039 
00040   // Returns the hits in the phi range (phi in radians).
00041   //  The phi interval ( phiMin, phiMax) defined as the signed path along the 
00042   //  trigonometric circle from the point at phiMin to the point at phiMax
00043   //  must be positive and smaller than pi.
00044   //  At least one of phiMin, phiMax must be in (-pi,pi) range.
00045   //  Examples of correct intervals: (-3,-2), (-4,-3), (3.1,3.2), (3,-3).
00046   //  Examples of WRONG intervals: (-5,-4),(3,2), (4,3), (3.2,3.1), (-3,3), (4,5).
00047   //  Example of use: myHits = recHitsSortedInPhi( phi-deltaPhi, phi+deltaPhi);
00048   //
00049   std::vector<Hit> hits( float phiMin, float phiMax) const;
00050 
00051   // Same as above but the result is allocated by the caller and passed by reference.
00052   //  The caller is responsible for clearing of the container "result".
00053   //  This interface is not nice and not safe, but is much faster, since the
00054   //  dominant CPU time of the "nice" method hits(phimin,phimax) is spent in
00055   //  memory allocation of the result!
00056   //
00057   void hits( float phiMin, float phiMax, std::vector<Hit>& result) const;
00058 
00059   // Fast access to the hits in the phi interval (phi in radians).
00060   //  The arguments must satisfy -pi <= phiMin < phiMax <= pi
00061   //  No check is made for this.
00062   //
00063   Range unsafeRange( float phiMin, float phiMax) const;
00064 
00065   std::vector<Hit> hits() const {
00066     std::vector<Hit> result; result.reserve(theHits.size());
00067     for (HitIter i=theHits.begin(); i!=theHits.end(); i++) result.push_back(i->hit());
00068     return result;
00069   }
00070 
00071 
00072   Range all() const {
00073     return Range(theHits.begin(), theHits.end());
00074   }
00075 
00076 private:
00077 
00078   std::vector<HitWithPhi> theHits;
00079 
00080   static void copyResult( const Range& range, std::vector<Hit>& result) {
00081     result.reserve(result.size()+(range.second-range.first));
00082     for (HitIter i = range.first; i != range.second; i++) result.push_back( i->hit());
00083   }
00084 
00085 };
00086 
00087 #endif