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 
12 
14 
16 
17 #include <utility>
18 #include <unordered_map>
19 #include <cstring>
20 
21 
22 /*****************************************************************************/
23 class PixelKeys {
24 public:
25  PixelKeys(int part, int dx, int dy) : key( (part==0) ? barrelPacking(dx,dy) : endcapPacking(dx,dy)) {}
26 
27  operator unsigned int() const { return key;}
28 
29  static unsigned char endcapPacking(int dx, int dy) {
30  if ( dx<0 || dy<0 ) return N;
31  if ( dx>10 || dy>4 ) return N;
32  return N_barrel + dx*offset_endcap_dy+dy; // max 11*5 = 55
33  }
34 
35  static unsigned char barrelPacking(int dx, int dy) {
36  if ( dx<0 || dy<0 ) return N;
37  if ( dx>10 || dy>15 ) return N;
38  if (dx<8) return dx*16+dy; // max 8*16=128
39  if (dy>2) return N;
40  return 128 + (dx-8)*3+dy; // max = 128+9 = 137
41  }
42 
43  bool isValid() const { return key<N;}
44 
45 
46  static const int offset_endcap_dy=5;
47  static const int offset_endcap_dx=10;
48  static const int N_endcap=55;
49  static const int N_barrel=137;
50  static const int N = N_barrel+N_endcap;
51 
52  bool operator<(const PixelKeys & right) const{ return key< right.key; }
53 
54  private:
55  unsigned char key;
56 };
57 
58 class StripKeys
59 {
60  public:
61 
62  static const int N=40;
63 
64  StripKeys(int width) : key(width>0 ? width-1 : N) {}
65 
66  operator unsigned int() const { return key;}
67 
68  bool isValid() const { return key<N;}
69 
70  bool operator<(const StripKeys & right) const
71  {
72  return key < right.key;
73  }
74 
75  private:
76  unsigned char key; // max 40;
77 };
78 
79 struct PixelLimits {
81  // init to make sure inside is true;
82  auto limit = data[0];
83  limit[0][0] = -10e10;
84  limit[0][1] = 10e10;
85  limit[1][0] = -10e10;
86  limit[1][1] = 10e10;
87  limit = data[1];
88  limit[0][0] = -10e10;
89  limit[0][1] = 10e10;
90  limit[1][0] = -10e10;
91  limit[1][1] = 10e10;
92  }
93 
94  float data[2][2][2];
95 
96  bool isInside( const std::pair<float,float> & pred) const {
97  auto limit = data[0];
98  bool one = (pred.first > limit[0][0]) && ( pred.first < limit[0][1] )
99  && (pred.second > limit[1][0]) && (pred.second < limit[1][1]);
100 
101  limit = data[1];
102  bool two = (pred.first > limit[0][0]) && ( pred.first < limit[0][1] )
103  && (pred.second > limit[1][0]) && (pred.second < limit[1][1]);
104 
105  return one || two;
106  }
107 
108 
109 };
110 
111 
112 struct StripLimits {
114  data[0][0] = -10e10;
115  data[0][1] = 10e10;
116  data[1][0] = -10e10;
117  data[1][1] = 10e10;
118  }
119 
120  float data[2][2];
121 
122  bool isInside( float pred) const {
123  float const * limit = data[0];
124  bool one = pred > limit[0] && pred < limit[1];
125  limit = data[1];
126  bool two = pred > limit[0] && pred < limit[1];
127 
128  return one || two;
129 
130  }
131 };
132 
133 
134 /*****************************************************************************/
135 namespace edm { class EventSetup; }
136 
137 class TrackerGeometry;
138 class MagneticField;
139 class SiPixelLorentzAngle;
140 class SiStripLorentzAngle;
141 class PixelGeomDetUnit;
142 class StripGeomDetUnit;
143 
144 // Function for testing ClusterShapeHitFilter
145 namespace test {
146  namespace ClusterShapeHitFilterTest {
147  int test();
148  }
149 }
150 
152 {
153  // For tests
155 
156  public:
157 
158  struct PixelData {
160  unsigned int part;
161  std::pair<float,float> drift;
162  std::pair<float,float> cotangent;
163 
164  };
165 
167  // typedef CkfComponentsRecord Record;
168 
169  ClusterShapeHitFilter(const TrackerGeometry * theTracker_,
170  const MagneticField * theMagneticField_,
171  const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
172  const SiStripLorentzAngle * theSiStripLorentzAngle_,
173  const std::string * use_PixelShapeFile_);
174 
176 
177  void setShapeCuts(bool cutOnPixelShape, bool cutOnStripShape) {
178  cutOnPixelShape_ = cutOnPixelShape; cutOnStripShape_ = cutOnStripShape;}
179 
180  void setChargeCuts(bool cutOnPixelCharge, float minGoodPixelCharge,
181  bool cutOnStripCharge, float minGoodStripCharge) {
182  cutOnPixelCharge_ = cutOnPixelCharge; minGoodPixelCharge_= minGoodPixelCharge;
183  cutOnStripCharge_ = cutOnStripCharge; minGoodStripCharge_= minGoodStripCharge; }
184 
185  bool getSizes
186  (const SiPixelRecHit & recHit, const LocalVector & ldir,
187  const SiPixelClusterShapeCache& clusterShapeCache,
188  int & part, ClusterData::ArrayType& meas,
189  std::pair<float,float> & predr,
190  PixelData const * pd=nullptr) const;
191  bool isCompatible(const SiPixelRecHit & recHit,
192  const LocalVector & ldir,
193  const SiPixelClusterShapeCache& clusterShapeCache,
194  PixelData const * pd=nullptr) const;
195  bool isCompatible(const SiPixelRecHit & recHit,
196  const GlobalVector & gdir,
197  const SiPixelClusterShapeCache& clusterShapeCache,
198  PixelData const * pd=nullptr ) const;
199 
200 
201  bool getSizes(DetId detId, const SiStripCluster & cluster, const LocalPoint &lpos, const LocalVector & ldir,
202  int & meas, float & pred) const;
203  bool getSizes(const SiStripRecHit2D & recHit, const LocalPoint &lpos, const LocalVector & ldir,
204  int & meas, float & pred) const {
205  return getSizes(recHit.geographicalId(), recHit.stripCluster(), lpos, ldir, meas, pred);
206  }
207  bool isCompatible(DetId detId,
208  const SiStripCluster & cluster,
209  const LocalPoint & lpos,
210  const LocalVector & ldir) const;
211  bool isCompatible(DetId detId,
212  const SiStripCluster & cluster,
213  const LocalVector & ldir) const {
214  return isCompatible(detId, cluster, LocalPoint(0,0,0), ldir);
215  }
216 
217  bool isCompatible(DetId detId,
218  const SiStripCluster & cluster,
219  const GlobalPoint & gpos,
220  const GlobalVector & gdir ) const;
221  bool isCompatible(DetId detId,
222  const SiStripCluster & cluster,
223  const GlobalVector & gdir ) const;
224  bool isCompatible(const SiStripRecHit2D & recHit,
225  const LocalPoint & lpos,
226  const LocalVector & ldir) const {
227  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), lpos, ldir);
228  }
229  bool isCompatible(const SiStripRecHit2D & recHit,
230  const LocalVector & ldir) const {
231  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), ldir);
232  }
233  bool isCompatible(const SiStripRecHit2D & recHit,
234  const GlobalPoint & gpos,
235  const GlobalVector & gdir ) const {
236  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), gpos, gdir);
237  }
238  bool isCompatible(const SiStripRecHit2D & recHit,
239  const GlobalVector & gdir ) const {
240  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), gdir);
241  }
242 
243 
244 
245  private:
246  // for testing purposes only
248 
249  const PixelData & getpd(const SiPixelRecHit & recHit, PixelData const * pd=nullptr) const{
250  if (pd) return *pd;
251  // Get detector
252  DetId id = recHit.geographicalId();
253  auto p = pixelData.find(id);
254  return (*p).second;
255  }
256 
257  void loadPixelLimits();
258  void loadStripLimits();
259  void fillPixelData();
260 
261  std::pair<float,float> getCotangent(const PixelGeomDetUnit * pixelDet) const;
262  float getCotangent(const StripGeomDetUnit * stripDet, const LocalPoint &p = LocalPoint(0,0,0)) const;
263 
264  std::pair<float,float> getDrift(const PixelGeomDetUnit * pixelDet) const;
265  float getDrift(const StripGeomDetUnit * stripDet) const;
266 
267  bool isNormalOriented(const GeomDetUnit * geomDet) const;
268 
271 
274 
276 
277  std::unordered_map<unsigned int, PixelData> pixelData;
278 
280 
282 
283  float theAngle[6];
287  bool checkClusterCharge(DetId detId, const SiStripCluster& cluster, const LocalVector & ldir) const;
288  bool checkClusterCharge(DetId detId, const SiPixelCluster& cluster, const LocalVector & ldir) const;
289 };
290 
291 #endif
292 
StripKeys(int width)
const std::string * PixelShapeFile
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 SiStripRecHit2D &recHit, const LocalPoint &lpos, const LocalVector &ldir) const
bool checkClusterCharge(DetId detId, const SiStripCluster &cluster, const LocalVector &ldir) const
bool isCompatible(const SiStripRecHit2D &recHit, const GlobalVector &gdir) const
bool isValid() const
bool isCompatible(const SiStripRecHit2D &recHit, const GlobalPoint &gpos, const GlobalVector &gdir) 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
bool isCompatible(DetId detId, const SiStripCluster &cluster, const LocalVector &ldir) const
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
void setShapeCuts(bool cutOnPixelShape, bool cutOnStripShape)
const SiPixelLorentzAngle * theSiPixelLorentzAngle
bool isCompatible(const SiStripRecHit2D &recHit, const LocalVector &ldir) const
bool isNormalOriented(const GeomDetUnit *geomDet) const
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, PixelData const *pd=0) const
static const int N
Definition: DetId.h:18
std::pair< float, float > getDrift(const PixelGeomDetUnit *pixelDet) const
part
Definition: HCALResponse.h:20
SiStripCluster const & stripCluster() const
void setChargeCuts(bool cutOnPixelCharge, float minGoodPixelCharge, bool cutOnStripCharge, float minGoodStripCharge)
TrajectoryFilter::Record Record
bool getSizes(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, int &part, ClusterData::ArrayType &meas, std::pair< float, float > &predr, PixelData const *pd=0) const
float data[2][2][2]
unsigned char key
Pixel cluster – collection of neighboring pixels above threshold.
PixelKeys(int part, int dx, int dy)
static const int N
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
bool getSizes(const SiStripRecHit2D &recHit, const LocalPoint &lpos, const LocalVector &ldir, int &meas, float &pred) const
unsigned char key
DetId geographicalId() const
bool operator<(const StripKeys &right) const
Our base class.
Definition: SiPixelRecHit.h:23
static const int offset_endcap_dy