CMS 3D CMS Logo

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 TrackerTopology;
139 class MagneticField;
140 class SiPixelLorentzAngle;
141 class SiStripLorentzAngle;
142 class PixelGeomDetUnit;
143 class StripGeomDetUnit;
144 class StripTopology;
145 
146 // Function for testing ClusterShapeHitFilter
147 namespace test {
148  namespace ClusterShapeHitFilterTest {
149  int test();
150  }
151 }
152 
154 {
155  // For tests
157 
158  public:
159 
160  struct PixelData {
162  unsigned short part;
163  unsigned short layer;
164  std::pair<float,float> drift;
165  std::pair<float,float> cotangent;
166 
167  };
168 
169  struct StripData {
172  float drift;
173  float thickness;
174  int nstrips;
175  };
176 
178 
179  ClusterShapeHitFilter(const TrackerGeometry * theTracker_,
180  const TrackerTopology * theTkTopol_,
181  const MagneticField * theMagneticField_,
182  const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
183  const SiStripLorentzAngle * theSiStripLorentzAngle_,
184  const std::string & pixelShapeFile_,
185  const std::string & pixelShapeFileL1_);
186 
188 
189  void setShapeCuts(bool cutOnPixelShape, bool cutOnStripShape) {
190  cutOnPixelShape_ = cutOnPixelShape; cutOnStripShape_ = cutOnStripShape;}
191 
192  void setChargeCuts(bool cutOnPixelCharge, float minGoodPixelCharge,
193  bool cutOnStripCharge, float minGoodStripCharge) {
194  cutOnPixelCharge_ = cutOnPixelCharge; minGoodPixelCharge_= minGoodPixelCharge;
195  cutOnStripCharge_ = cutOnStripCharge; minGoodStripCharge_= minGoodStripCharge; }
196 
197  bool getSizes
198  (const SiPixelRecHit & recHit, const LocalVector & ldir,
199  const SiPixelClusterShapeCache& clusterShapeCache,
200  int & part, ClusterData::ArrayType& meas,
201  std::pair<float,float> & predr,
202  PixelData const * pd=nullptr) const;
203  bool isCompatible(const SiPixelRecHit & recHit,
204  const LocalVector & ldir,
205  const SiPixelClusterShapeCache& clusterShapeCache,
206  PixelData const * pd=nullptr) const;
207  bool isCompatible(const SiPixelRecHit & recHit,
208  const GlobalVector & gdir,
209  const SiPixelClusterShapeCache& clusterShapeCache,
210  PixelData const * pd=nullptr ) const;
211 
212 
213  bool getSizes(DetId detId, const SiStripCluster & cluster, const LocalPoint &lpos, const LocalVector & ldir,
214  int & meas, float & pred) const;
215  bool getSizes(const SiStripRecHit2D & recHit, const LocalPoint &lpos, const LocalVector & ldir,
216  int & meas, float & pred) const {
217  return getSizes(recHit.geographicalId(), recHit.stripCluster(), lpos, ldir, meas, pred);
218  }
219  bool isCompatible(DetId detId,
220  const SiStripCluster & cluster,
221  const LocalPoint & lpos,
222  const LocalVector & ldir) const;
223  bool isCompatible(DetId detId,
224  const SiStripCluster & cluster,
225  const LocalVector & ldir) const {
226  return isCompatible(detId, cluster, LocalPoint(0,0,0), ldir);
227  }
228 
229  bool isCompatible(DetId detId,
230  const SiStripCluster & cluster,
231  const GlobalPoint & gpos,
232  const GlobalVector & gdir ) const;
233  bool isCompatible(DetId detId,
234  const SiStripCluster & cluster,
235  const GlobalVector & gdir ) const;
236 
237 
238  bool isCompatible(const SiStripRecHit2D & recHit,
239  const LocalPoint & lpos,
240  const LocalVector & ldir) const {
241  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), lpos, ldir);
242  }
243  bool isCompatible(const SiStripRecHit2D & recHit,
244  const LocalVector & ldir) const {
245  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), ldir);
246  }
247  bool isCompatible(const SiStripRecHit2D & recHit,
248  const GlobalPoint & gpos,
249  const GlobalVector & gdir ) const {
250  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), gpos, gdir);
251  }
252  bool isCompatible(const SiStripRecHit2D & recHit,
253  const GlobalVector & gdir ) const {
254  return isCompatible(recHit.geographicalId(), recHit.stripCluster(), gdir);
255  }
256 
257 
258 
259  private:
260  // for testing purposes only
262  loadPixelLimits(f1,pixelLimits);
263  loadPixelLimits(f2,pixelLimitsL1);
264  loadStripLimits();
265  }
266 
267  const PixelData & getpd(const SiPixelRecHit & recHit, PixelData const * pd=nullptr) const{
268  if (pd) return *pd;
269  // Get detector
270  DetId id = recHit.geographicalId();
271  auto p = pixelData.find(id);
272  return (*p).second;
273  }
274 
275  const StripData & getsd(DetId id) const {return stripData.find(id)->second;}
276 
277  void loadPixelLimits(std::string const & file, PixelLimits *plim);
278  void loadStripLimits();
279  void fillPixelData();
280  void fillStripData();
281 
282 
283  std::pair<float,float> getCotangent(const PixelGeomDetUnit * pixelDet) const;
284  float getCotangent(const ClusterShapeHitFilter::StripData& sd, const LocalPoint &p) const;
285 
286  std::pair<float,float> getDrift(const PixelGeomDetUnit * pixelDet) const;
287  float getDrift(const StripGeomDetUnit * stripDet) const;
288 
289  bool isNormalOriented(const GeomDetUnit * geomDet) const;
290 
294 
297 
298  std::unordered_map<unsigned int, PixelData> pixelData;
299  std::unordered_map<unsigned int, StripData> stripData;
300 
301  PixelLimits pixelLimits[PixelKeys::N+1]; // [2][2][2]
302  PixelLimits pixelLimitsL1[PixelKeys::N+1]; // for BPIX1
303 
304  StripLimits stripLimits[StripKeys::N+1]; // [2][2]
305 
306  float theAngle[6];
307  bool cutOnPixelCharge_, cutOnStripCharge_;
308  float minGoodPixelCharge_, minGoodStripCharge_;
309  bool cutOnPixelShape_, cutOnStripShape_;
310  bool checkClusterCharge(DetId detId, const SiStripCluster& cluster, const LocalVector & ldir) const;
311  bool checkClusterCharge(DetId detId, const SiPixelCluster& cluster, const LocalVector & ldir) const;
312 };
313 
314 #endif
std::unordered_map< unsigned int, StripData > stripData
StripKeys(int width)
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
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 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
const StripData & getsd(DetId id) const
static const int N_endcap
static const int N_barrel
bool isValid() const
std::unordered_map< unsigned int, PixelData > pixelData
bool isCompatible(DetId detId, const SiStripCluster &cluster, const LocalVector &ldir) const
const TrackerGeometry * theTracker
ClusterShapeHitFilter(std::string const &f1, std::string const &f2)
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
static const int N
Definition: DetId.h:18
double sd
part
Definition: HCALResponse.h:20
const TrackerTopology * theTkTopol
SiStripCluster const & stripCluster() const
void setChargeCuts(bool cutOnPixelCharge, float minGoodPixelCharge, bool cutOnStripCharge, float minGoodStripCharge)
TrajectoryFilter::Record Record
unsigned char key
Pixel cluster – collection of neighboring pixels above threshold.
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
PixelKeys(int part, int dx, int dy)
static const int N
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