CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterShapeHitFilter.h
Go to the documentation of this file.
1 #ifndef _ClusterShapeHitFilter_h_
2 #define _ClusterShapeHitFilter_h_
3 
5 
8 
11 
13 
14 
15 #include <utility>
16 #include <unordered_map>
17 #include <vector>
18 #include <cstring>
19 
20 
21 /*****************************************************************************/
22 class PixelKeys {
23 public:
24  PixelKeys(int part, int dx, int dy) : key( (part==0) ? barrelPacking(dx,dy) : endcapPacking(dx,dy)) {}
25 
26  operator unsigned int() const { return key;}
27 
28  static unsigned char endcapPacking(int dx, int dy) {
29  if ( dx<0 || dy<0 ) return N;
30  if ( dx>10 || dy>4 ) return N;
31  return N_barrel + dx*offset_endcap_dy+dy; // max 11*5 = 55
32  }
33 
34  static unsigned char barrelPacking(int dx, int dy) {
35  if ( dx<0 || dy<0 ) return N;
36  if ( dx>10 || dy>15 ) return N;
37  if (dx<8) return dx*16+dy; // max 8*16=128
38  if (dy>2) return N;
39  return 128 + (dx-8)*3+dy; // max = 128+9 = 137
40  }
41 
42  bool isValid() const { return key<N;}
43 
44 
45  static const int offset_endcap_dy=5;
46  static const int offset_endcap_dx=10;
47  static const int N_endcap=55;
48  static const int N_barrel=137;
49  static const int N = N_barrel+N_endcap;
50 
51  bool operator<(const PixelKeys & right) const{ return key< right.key; }
52 
53  private:
54  unsigned char key;
55 };
56 
57 class StripKeys
58 {
59  public:
60 
61  static const int N=40;
62 
63  StripKeys(int width) : key(width>0 ? width-1 : N) {}
64 
65  operator unsigned int() const { return key;}
66 
67  bool isValid() const { return key<N;}
68 
69  bool operator<(const StripKeys & right) const
70  {
71  return key < right.key;
72  }
73 
74  private:
75  unsigned char key; // max 40;
76 };
77 
78 struct PixelLimits {
80  // init to make sure inside is true;
81  auto limit = data[0];
82  limit[0][0] = -10e10;
83  limit[0][1] = 10e10;
84  limit[1][0] = -10e10;
85  limit[1][1] = 10e10;
86  limit = data[1];
87  limit[0][0] = -10e10;
88  limit[0][1] = 10e10;
89  limit[1][0] = -10e10;
90  limit[1][1] = 10e10;
91  }
92 
93  float data[2][2][2];
94 
95  bool isInside( const std::pair<float,float> & pred) const {
96  auto limit = data[0];
97  bool one = (pred.first > limit[0][0]) && ( pred.first < limit[0][1] )
98  && (pred.second > limit[1][0]) && (pred.second < limit[1][1]);
99 
100  limit = data[1];
101  bool two = (pred.first > limit[0][0]) && ( pred.first < limit[0][1] )
102  && (pred.second > limit[1][0]) && (pred.second < limit[1][1]);
103 
104  return one || two;
105  }
106 
107 
108 };
109 
110 
111 struct StripLimits {
113  data[0][0] = -10e10;
114  data[0][1] = 10e10;
115  data[1][0] = -10e10;
116  data[1][1] = 10e10;
117  }
118 
119  float data[2][2];
120 
121  bool isInside( float pred) const {
122  float const * limit = data[0];
123  bool one = pred > limit[0] && pred < limit[1];
124  limit = data[1];
125  bool two = pred > limit[0] && pred < limit[1];
126 
127  return one || two;
128 
129  }
130 };
131 
132 
133 /*****************************************************************************/
134 namespace edm { class EventSetup; }
135 
136 class TrackerGeometry;
137 class MagneticField;
138 class SiPixelLorentzAngle;
139 class SiStripLorentzAngle;
140 class PixelGeomDetUnit;
141 class StripGeomDetUnit;
142 
144 {
145  public:
146 
147  struct PixelData {
149  unsigned int part;
150  std::pair<float,float> drift;
151  std::pair<float,float> cotangent;
152 
153  };
154 
156  // typedef CkfComponentsRecord Record;
157 
158  ClusterShapeHitFilter(const TrackerGeometry * theTracker_,
159  const MagneticField * theMagneticField_,
160  const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
161  const SiStripLorentzAngle * theSiStripLorentzAngle_);
162 
164 
165  bool getSizes
166  (const SiPixelRecHit & recHit, const LocalVector & ldir,
167  int & part, std::vector<std::pair<int,int> > & meas,
168  std::pair<float,float> & predr,
169  PixelData const * pd=nullptr) const;
170  bool isCompatible(const SiPixelRecHit & recHit,
171  const LocalVector & ldir,
172  PixelData const * pd=nullptr) const;
173  bool isCompatible(const SiPixelRecHit & recHit,
174  const GlobalVector & gdir,
175  PixelData const * pd=nullptr ) const;
176 
177 
178  bool getSizes(DetId detId, const SiStripCluster & cluster, const LocalVector & ldir,
179  int & meas, float & pred) const;
180  bool getSizes(const SiStripRecHit2D & recHit, const LocalVector & ldir,
181  int & meas, float & pred) const {
182  return getSizes(recHit.geographicalId(), recHit.stripCluster(), ldir, meas, pred);
183  }
184  bool isCompatible(DetId detId,
185  const SiStripCluster & cluster,
186  const LocalVector & ldir) const;
187  bool isCompatible(DetId detId,
188  const SiStripCluster & cluster,
189  const GlobalVector & gdir ) const;
190  bool isCompatible(const SiStripRecHit2D & recHit,
191  const LocalVector & ldir) const {
192  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), ldir);
193  }
194  bool isCompatible(const SiStripRecHit2D & recHit,
195  const GlobalVector & gdir ) const {
196  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), gdir);
197  }
198 
199 
200  private:
201  // for testing purposes only
203 
204  const PixelData & getpd(const SiPixelRecHit & recHit, PixelData const * pd=nullptr) const{
205  if (pd) return *pd;
206  // Get detector
207  DetId id = recHit.geographicalId();
208  auto p = pixelData.find(id);
209  return (*p).second;
210  }
211 
212  void loadPixelLimits();
213  void loadStripLimits();
214  void fillPixelData();
215 
216  std::pair<float,float> getCotangent(const PixelGeomDetUnit * pixelDet) const;
217  float getCotangent(const StripGeomDetUnit * stripDet) const;
218 
219  std::pair<float,float> getDrift(const PixelGeomDetUnit * pixelDet) const;
220  float getDrift(const StripGeomDetUnit * stripDet) const;
221 
222  bool isNormalOriented(const GeomDetUnit * geomDet) const;
223 
226 
229 
230  std::unordered_map<unsigned int, PixelData> pixelData;
231 
233 
235 
236  float theAngle[6];
237 };
238 
239 #endif
240 
StripKeys(int width)
const MagneticField * theMagneticField
const SiStripLorentzAngle * theSiStripLorentzAngle
const PixelData & getpd(const SiPixelRecHit &recHit, PixelData const *pd=0) const
bool operator<(const PixelKeys &right) const
static unsigned char barrelPacking(int dx, int dy)
std::pair< float, float > cotangent
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, PixelData const *pd=0) const
bool isCompatible(const SiStripRecHit2D &recHit, const GlobalVector &gdir) const
bool isValid() const
bool isInside(const std::pair< float, float > &pred) const
static const int N_endcap
static const int N_barrel
bool isValid() const
PixelLimits pixelLimits[PixelKeys::N+1]
std::unordered_map< unsigned int, PixelData > pixelData
const TrackerGeometry * theTracker
std::pair< float, float > getCotangent(const PixelGeomDetUnit *pixelDet) const
StripLimits stripLimits[StripKeys::N+1]
static unsigned char endcapPacking(int dx, int dy)
bool isInside(float pred) const
static const int offset_endcap_dx
const SiPixelLorentzAngle * theSiPixelLorentzAngle
bool isCompatible(const SiStripRecHit2D &recHit, const LocalVector &ldir) const
bool isNormalOriented(const GeomDetUnit *geomDet) const
static const int N
Definition: DetId.h:20
bool getSizes(const SiStripRecHit2D &recHit, const LocalVector &ldir, int &meas, float &pred) const
std::pair< float, float > getDrift(const PixelGeomDetUnit *pixelDet) const
part
Definition: HCALResponse.h:21
SiStripCluster const & stripCluster() const
TrajectoryFilter::Record Record
float data[2][2][2]
unsigned char key
bool getSizes(const SiPixelRecHit &recHit, const LocalVector &ldir, int &part, std::vector< std::pair< int, int > > &meas, std::pair< float, float > &predr, PixelData const *pd=0) const
PixelKeys(int part, int dx, int dy)
static const int N
unsigned char key
DetId geographicalId() const
bool operator<(const StripKeys &right) const
Our base class.
Definition: SiPixelRecHit.h:22
static const int offset_endcap_dy