CMS 3D CMS Logo

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