CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecHitsSortedInPhi.h
Go to the documentation of this file.
1 #ifndef RecHitsSortedInPhi_H
2 #define RecHitsSortedInPhi_H
3 
5 
6 #include <vector>
7 
14 public:
15 
17 
18  // A RecHit extension that caches the phi angle for fast access
19  class HitWithPhi {
20  public:
21  HitWithPhi( const Hit & hit) : theHit(hit), thePhi(hit->globalPosition().phi()) {}
22  HitWithPhi( float phi) : theHit(0), thePhi(phi) {}
23  float phi() const {return thePhi;}
24  const Hit hit() const { return theHit;}
25  private:
27  float thePhi;
28  };
29 
30  struct HitLessPhi {
31  bool operator()( const HitWithPhi& a, const HitWithPhi& b) { return a.phi() < b.phi(); }
32  };
33  typedef std::vector<HitWithPhi>::const_iterator HitIter;
34  typedef std::pair<HitIter,HitIter> Range;
35 
36  RecHitsSortedInPhi( const std::vector<Hit>& hits);
37 
38  bool empty() const { return theHits.empty(); }
39 
40  // Returns the hits in the phi range (phi in radians).
41  // The phi interval ( phiMin, phiMax) defined as the signed path along the
42  // trigonometric circle from the point at phiMin to the point at phiMax
43  // must be positive and smaller than pi.
44  // At least one of phiMin, phiMax must be in (-pi,pi) range.
45  // Examples of correct intervals: (-3,-2), (-4,-3), (3.1,3.2), (3,-3).
46  // Examples of WRONG intervals: (-5,-4),(3,2), (4,3), (3.2,3.1), (-3,3), (4,5).
47  // Example of use: myHits = recHitsSortedInPhi( phi-deltaPhi, phi+deltaPhi);
48  //
49  std::vector<Hit> hits( float phiMin, float phiMax) const;
50 
51  // Same as above but the result is allocated by the caller and passed by reference.
52  // The caller is responsible for clearing of the container "result".
53  // This interface is not nice and not safe, but is much faster, since the
54  // dominant CPU time of the "nice" method hits(phimin,phimax) is spent in
55  // memory allocation of the result!
56  //
57  void hits( float phiMin, float phiMax, std::vector<Hit>& result) const;
58 
59  // Fast access to the hits in the phi interval (phi in radians).
60  // The arguments must satisfy -pi <= phiMin < phiMax <= pi
61  // No check is made for this.
62  //
63  Range unsafeRange( float phiMin, float phiMax) const;
64 
65  std::vector<Hit> hits() const {
66  std::vector<Hit> result; result.reserve(theHits.size());
67  for (HitIter i=theHits.begin(); i!=theHits.end(); i++) result.push_back(i->hit());
68  return result;
69  }
70 
71 
72  Range all() const {
73  return Range(theHits.begin(), theHits.end());
74  }
75 
76 private:
77 
78  std::vector<HitWithPhi> theHits;
79 
80  static void copyResult( const Range& range, std::vector<Hit>& result) {
81  result.reserve(result.size()+(range.second-range.first));
82  for (HitIter i = range.first; i != range.second; i++) result.push_back( i->hit());
83  }
84 
85 };
86 
87 #endif
std::vector< HitWithPhi > theHits
int i
Definition: DBlmapReader.cc:9
Range unsafeRange(float phiMin, float phiMax) const
bool operator()(const HitWithPhi &a, const HitWithPhi &b)
std::vector< Hit > hits() const
std::pair< HitIter, HitIter > Range
TransientTrackingRecHit::ConstRecHitPointer Hit
std::vector< HitWithPhi >::const_iterator HitIter
tuple result
Definition: query.py:137
RecHitsSortedInPhi(const std::vector< Hit > &hits)
double b
Definition: hdecay.h:120
static void copyResult(const Range &range, std::vector< Hit > &result)
double a
Definition: hdecay.h:121