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 
6 
7 #include <vector>
8 #include<array>
9 
16 public:
17 
18  typedef BaseTrackerRecHit const * Hit;
19 
20  // A RecHit extension that caches the phi angle for fast access
21  class HitWithPhi {
22  public:
23  HitWithPhi( const Hit & hit) : theHit(hit), thePhi(hit->globalPosition().phi()) {}
24  HitWithPhi( const Hit & hit,float phi) : theHit(hit), thePhi(phi) {}
25  HitWithPhi( float phi) : theHit(0), thePhi(phi) {}
26  float phi() const {return thePhi;}
27  Hit const & hit() const { return theHit;}
28  private:
30  float thePhi;
31  };
32 
33  struct HitLessPhi {
34  bool operator()( const HitWithPhi& a, const HitWithPhi& b) { return a.phi() < b.phi(); }
35  };
36  typedef std::vector<HitWithPhi>::const_iterator HitIter;
37  typedef std::pair<HitIter,HitIter> Range;
38 
39  using DoubleRange = std::array<int,4>;
40 
41  RecHitsSortedInPhi(const std::vector<Hit>& hits, GlobalPoint const & origin, DetLayer const * il);
42 
43  bool empty() const { return theHits.empty(); }
44  std::size_t size() const { return theHits.size();}
45 
46 
47  // Returns the hits in the phi range (phi in radians).
48  // The phi interval ( phiMin, phiMax) defined as the signed path along the
49  // trigonometric circle from the point at phiMin to the point at phiMax
50  // must be positive and smaller than pi.
51  // At least one of phiMin, phiMax must be in (-pi,pi) range.
52  // Examples of correct intervals: (-3,-2), (-4,-3), (3.1,3.2), (3,-3).
53  // Examples of WRONG intervals: (-5,-4),(3,2), (4,3), (3.2,3.1), (-3,3), (4,5).
54  // Example of use: myHits = recHitsSortedInPhi( phi-deltaPhi, phi+deltaPhi);
55  //
56  std::vector<Hit> hits( float phiMin, float phiMax) const;
57 
58  // Same as above but the result is allocated by the caller and passed by reference.
59  // The caller is responsible for clearing of the container "result".
60  // This interface is not nice and not safe, but is much faster, since the
61  // dominant CPU time of the "nice" method hits(phimin,phimax) is spent in
62  // memory allocation of the result!
63  //
64  void hits( float phiMin, float phiMax, std::vector<Hit>& result) const;
65 
66  // some above, just double range of indeces..
67  DoubleRange doubleRange(float phiMin, float phiMax) const;
68 
69  // Fast access to the hits in the phi interval (phi in radians).
70  // The arguments must satisfy -pi <= phiMin < phiMax <= pi
71  // No check is made for this.
72  //
73  Range unsafeRange( float phiMin, float phiMax) const;
74 
75  std::vector<Hit> hits() const {
76  std::vector<Hit> result; result.reserve(theHits.size());
77  for (HitIter i=theHits.begin(); i!=theHits.end(); i++) result.push_back(i->hit());
78  return result;
79  }
80 
81 
82  Range all() const {
83  return Range(theHits.begin(), theHits.end());
84  }
85 
86 public:
87  float phi(int i) const { return theHits[i].phi();}
88  float gv(int i) const { return isBarrel ? z[i] : gp(i).perp();} // global v
89  float rv(int i) const { return isBarrel ? u[i] : v[i];} // dispaced r
90  GlobalPoint gp(int i) const { return GlobalPoint(x[i],y[i],z[i]);}
91 
92 public:
93 
95 
96  std::vector<HitWithPhi> theHits;
97 
98  DetLayer const * layer;
99  bool isBarrel;
100 
101  std::vector<float> x;
102  std::vector<float> y;
103  std::vector<float> z;
104  std::vector<float> drphi;
105 
106  // barrel: u=r, v=z, forward the opposite...
107  std::vector<float> u;
108  std::vector<float> v;
109  std::vector<float> du;
110  std::vector<float> dv;
111  std::vector<float> lphi;
112 
113  static void copyResult( const Range& range, std::vector<Hit>& result) {
114  result.reserve(result.size()+(range.second-range.first));
115  for (HitIter i = range.first; i != range.second; i++) result.push_back( i->hit());
116  }
117 
118 };
119 
120 
121 
122 /*
123  * a collection of hit pairs issued by a doublet search
124  * replace HitPairs as a communication mean between doublet and triplet search algos
125  *
126  */
127 class HitDoublets {
128 public:
129  enum layer { inner=0, outer=1};
130 
132 
133 
135  RecHitsSortedInPhi const & out) :
136  layers{{&in,&out}}{}
137 
138  HitDoublets(HitDoublets && rh) : layers(std::move(rh.layers)), indeces(std::move(rh.indeces)){}
139 
140  void reserve(std::size_t s) { indeces.reserve(2*s);}
141  std::size_t size() const { return indeces.size()/2;}
142  bool empty() const { return indeces.empty();}
143  void clear() { indeces.clear();}
144  void shrink_to_fit() { indeces.shrink_to_fit();}
145 
146  void add (int il, int ol) { indeces.push_back(il);indeces.push_back(ol);}
147 
148  DetLayer const * detLayer(layer l) const { return layers[l]->layer; }
149 
150  Hit const & hit(int i, layer l) const { return layers[l]->theHits[indeces[2*i+l]].hit();}
151  float phi(int i, layer l) const { return layers[l]->phi(indeces[2*i+l]);}
152  float rv(int i, layer l) const { return layers[l]->rv(indeces[2*i+l]);}
153  float z(int i, layer l) const { return layers[l]->z[indeces[2*i+l]];}
154  float x(int i, layer l) const { return layers[l]->x[indeces[2*i+l]];}
155  float y(int i, layer l) const { return layers[l]->y[indeces[2*i+l]];}
156  GlobalPoint gp(int i, layer l) const { return GlobalPoint(x(i,l),y(i,l),z(i,l));}
157 
158 private:
159 
160  std::array<RecHitsSortedInPhi const *,2> layers;
161 
162 
163  std::vector<int> indeces;
164 
165 };
166 
167 #endif
std::vector< HitWithPhi > theHits
int i
Definition: DBlmapReader.cc:9
std::size_t size() const
std::vector< float > drphi
T perp() const
Definition: PV3DBase.h:72
Range unsafeRange(float phiMin, float phiMax) const
bool operator()(const HitWithPhi &a, const HitWithPhi &b)
DetLayer const * layer
std::vector< float > z
std::array< int, 4 > DoubleRange
float x(int i, layer l) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::array< RecHitsSortedInPhi const *, 2 > layers
bool empty() const
float phi(int i) const
std::vector< Hit > hits() const
std::vector< float > x
DoubleRange doubleRange(float phiMin, float phiMax) const
void reserve(std::size_t s)
std::vector< float > lphi
float z(int i, layer l) const
std::pair< HitIter, HitIter > Range
HitDoublets(RecHitsSortedInPhi const &in, RecHitsSortedInPhi const &out)
std::vector< HitWithPhi >::const_iterator HitIter
tuple result
Definition: query.py:137
def move
Definition: eostools.py:510
GlobalPoint gp(int i, layer l) const
GlobalPoint gp(int i) const
std::vector< float > y
float y(int i, layer l) const
std::vector< float > v
float gv(int i) const
std::size_t size() const
BaseTrackerRecHit const * Hit
tuple out
Definition: dbtoconf.py:99
float phi(int i, layer l) const
double b
Definition: hdecay.h:120
std::vector< float > dv
Hit const & hit(int i, layer l) const
static void copyResult(const Range &range, std::vector< Hit > &result)
double a
Definition: hdecay.h:121
float rv(int i) const
RecHitsSortedInPhi(const std::vector< Hit > &hits, GlobalPoint const &origin, DetLayer const *il)
std::vector< float > u
HitWithPhi(const Hit &hit, float phi)
std::vector< int > indeces
std::vector< float > du
void add(int il, int ol)
DetLayer const * detLayer(layer l) const
float rv(int i, layer l) const