CMS 3D CMS Logo

ClusterShapeHitFilter.cc
Go to the documentation of this file.
2 
7 
10 
12 
17 
20 
22 
24 
26 
28 
29 #include <fstream>
30 #include<cassert>
31 
32 using namespace std;
33 
34 
35 /*****************************************************************************/
37  (const TrackerGeometry * theTracker_,
38  const TrackerTopology * theTkTopol_,
39  const MagneticField * theMagneticField_,
40  const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
41  const SiStripLorentzAngle * theSiStripLorentzAngle_,
42  const std::string & pixelShapeFile_,
43  const std::string & pixelShapeFileL1_)
44  : theTracker(theTracker_),
45  theTkTopol(theTkTopol_),
46  theMagneticField(theMagneticField_),
47  theSiPixelLorentzAngle(theSiPixelLorentzAngle_),
48  theSiStripLorentzAngle(theSiStripLorentzAngle_)
49 {
50  // Load pixel limits
51  loadPixelLimits(pixelShapeFile_,pixelLimits);
52  loadPixelLimits(pixelShapeFileL1_,pixelLimitsL1);
53  fillPixelData();
54 
55  // Load strip limits
56  loadStripLimits();
57  fillStripData();
58  cutOnPixelCharge_ = cutOnStripCharge_ = false;
59  cutOnPixelShape_ = cutOnStripShape_ = true;
60 }
61 
62 /*****************************************************************************/
64 {
65 }
66 
67 /*****************************************************************************/
69 {
70  edm::FileInPath fileInPath(file.c_str());
71  ifstream inFile(fileInPath.fullPath().c_str());
72 
73 
74  while(inFile.eof() == false)
75  {
76  int part,dx,dy;
77 
78  inFile >> part; // 0or 1
79  inFile >> dx; // 0 to 10
80  inFile >> dy; // 0 to 15 ...
81 
82  const PixelKeys key(part,dx,dy);
83  auto & pl = plim[key];
84 
85  for(int b = 0; b<2 ; b++) // branch
86  for(int d = 0; d<2 ; d++) // direction
87  for(int k = 0; k<2 ; k++) // lower and upper
88  inFile >> pl.data[b][d][k];
89 
90 
91  double f;
92  int d;
93 
94  inFile >> f; // density
95  inFile >> d; // points
96  inFile >> f; // density
97  inFile >> d; // points
98  }
99 
100  inFile.close();
101 
102  LogTrace("MinBiasTracking|ClusterShapeHitFilter")
103  << " [ClusterShapeHitFilter] pixel-cluster-shape filter loaded";
104  }
105 
106 /*****************************************************************************/
108 {
109  // Load strip
111  fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/stripShape.par");
112  ifstream inFile(fileInPath.fullPath().c_str());
113 
114 
115  while(inFile.eof() == false)
116  {
117  int dx;
118  inFile >> dx;
119 
120  StripKeys key(dx);
121  auto & sl = stripLimits[key];
122 
123  for(int b = 0; b<2 ; b++) // branch
124  for(int k = 0; k<2 ; k++) // lower and upper
125  inFile >> sl.data[b][k];
126 
127  }
128 
129  inFile.close();
130 
131  LogTrace("MinBiasTracking|ClusterShapeHitFilter")
132  << " [ClusterShapeHitFilter] strip-cluster-width filter loaded";
133 }
134 
135 
136 
138 
139  //barrel
140  for (auto det : theTracker->detsPXB()) {
141  // better not to fail..
142  const PixelGeomDetUnit * pixelDet =
143  dynamic_cast<const PixelGeomDetUnit*>(det);
144  assert(pixelDet);
145  PixelData & pd = pixelData[pixelDet->geographicalId()];
146  pd.det = pixelDet;
147  pd.part=0;
148  pd.layer = theTkTopol->pxbLayer(pixelDet->geographicalId());
149  pd.cotangent=getCotangent(pixelDet);
150  pd.drift=getDrift(pixelDet);
151  }
152 
153  //endcap
154  for (auto det : theTracker->detsPXF()) {
155  // better not to fail..
156  const PixelGeomDetUnit * pixelDet =
157  dynamic_cast<const PixelGeomDetUnit*>(det);
158  assert(pixelDet);
159  PixelData & pd = pixelData[pixelDet->geographicalId()];
160  pd.det = pixelDet;
161  pd.part=1;
162  pd.layer=0;
163  pd.cotangent=getCotangent(pixelDet);
164  pd.drift=getDrift(pixelDet);
165  }
166 
167 }
168 
169 
171  // copied from StripCPE (FIXME maybe we should move all this in LocalReco)
172  auto const & geom_ = *theTracker;
173  auto const & dus = geom_.detUnits();
174  auto offset=dus.size();
175  for(unsigned int i=1;i<7;++i) {
176  if(geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) != dus.size() &&
177  dus[geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])]->type().isTrackerStrip()) {
178  if(geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) < offset) offset = geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]);
179  }
180  }
181 
182  for (auto i=offset; i!=dus.size();++i) {
183  const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)(dus[i]);
184  assert(stripdet->index()==int(i));
185  assert(stripdet->type().isTrackerStrip()); // not pixel
186  auto const & bounds = stripdet->specificSurface().bounds();
187  auto detid = stripdet->geographicalId();
188  auto & p = stripData[detid];
189  p.det = stripdet;
190  p.topology=(StripTopology*)(&stripdet->topology());
191  p.drift = getDrift(stripdet);
192  p.thickness = bounds.thickness();
193  p.nstrips = p.topology->nstrips();
194  }
195 }
196 
197 /*****************************************************************************/
198 pair<float,float> ClusterShapeHitFilter::getCotangent
199  (const PixelGeomDetUnit * pixelDet) const
200 {
201  pair<float,float> cotangent;
202 
203  cotangent.first = pixelDet->surface().bounds().thickness() /
204  pixelDet->specificTopology().pitch().first;
205  cotangent.second = pixelDet->surface().bounds().thickness() /
206  pixelDet->specificTopology().pitch().second;
207 
208  return cotangent;
209 }
210 
211 /*****************************************************************************/
213  (const StripData & sd, const LocalPoint & pos) const
214 {
215  // FIXME may be problematic in case of RadialStriptolopgy
216  return sd.thickness/sd.topology->localPitch(pos);
217 }
218 
219 /*****************************************************************************/
220 pair<float,float> ClusterShapeHitFilter::getDrift
221  (const PixelGeomDetUnit * pixelDet) const
222 {
223  LocalVector lBfield =
224  (pixelDet->surface()).toLocal(
225  theMagneticField->inTesla(
226  pixelDet->surface().position()));
227 
228  double theTanLorentzAnglePerTesla =
229  theSiPixelLorentzAngle->getLorentzAngle(
230  pixelDet->geographicalId().rawId());
231 
232  pair<float,float> dir;
233  dir.first = - theTanLorentzAnglePerTesla * lBfield.y();
234  dir.second = theTanLorentzAnglePerTesla * lBfield.x();
235 
236  return dir;
237 }
238 
239 /*****************************************************************************/
241 const
242 {
243  LocalVector lBfield =
244  (stripDet->surface()).toLocal(
245  theMagneticField->inTesla(
246  stripDet->surface().position()));
247 
248  double theTanLorentzAnglePerTesla =
249  theSiStripLorentzAngle->getLorentzAngle(
250  stripDet->geographicalId().rawId());
251 
252  float dir = theTanLorentzAnglePerTesla * lBfield.y();
253 
254  return dir;
255 }
256 
257 /*****************************************************************************/
259  (const GeomDetUnit * geomDet) const
260 {
261  if(geomDet->type().isBarrel())
262  { // barrel
263  float perp0 = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).perp();
264  float perp1 = geomDet->toGlobal( Local3DPoint(0.,0.,1.) ).perp();
265  return (perp1 > perp0);
266  }
267  else
268  { // endcap
269  float rot = geomDet->toGlobal( LocalVector (0.,0.,1.) ).z();
270  float pos = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).z();
271  return (rot * pos > 0);
272  }
273 }
274 
275 /*****************************************************************************/
276 /*****************************************************************************/
277 
279  (const SiPixelRecHit & recHit, const LocalVector & ldir,
280  const SiPixelClusterShapeCache& clusterShapeCache,
281  int & part, ClusterData::ArrayType& meas, pair<float,float> & pred,
282  PixelData const * ipd) const
283 {
284  // Get detector
285  const PixelData & pd = getpd(recHit,ipd);
286 
287  // Get shape information
288  const SiPixelClusterShapeData& data = clusterShapeCache.get(recHit.cluster(), pd.det);
289  bool usable = (data.isStraight() && data.isComplete());
290 
291  // Usable?
292  //if(usable)
293  {
294  part = pd.part;
295 
296  // Predicted size
297  pred.first = ldir.x() / ldir.z();
298  pred.second = ldir.y() / ldir.z();
299 
300  SiPixelClusterShapeData::Range sizeRange = data.size();
301  if(sizeRange.first->second < 0)
302  pred.second = - pred.second;
303 
304  meas.clear();
305  assert(meas.capacity() >= std::distance(sizeRange.first, sizeRange.second));
306  for(auto s=sizeRange.first; s != sizeRange.second; ++s) {
307  meas.push_back_unchecked(*s);
308  }
309  if(sizeRange.first->second < 0) {
310  for(auto& s: meas)
311  s.second = -s.second;
312  }
313 
314  // Take out drift
315  std::pair<float,float> const & drift = pd.drift;
316  pred.first += drift.first;
317  pred.second += drift.second;
318 
319  // Apply cotangent
320  std::pair<float,float> const & cotangent = pd.cotangent;
321  pred.first *= cotangent.first;
322  pred.second *= cotangent.second;
323  }
324 
325  // Usable?
326  return usable;
327 }
328 
330  (const SiPixelRecHit & recHit, const LocalVector & ldir,
331  const SiPixelClusterShapeCache& clusterShapeCache,
332  PixelData const * ipd) const
333 {
334  // Get detector
335  if (cutOnPixelCharge_ && (!checkClusterCharge(recHit.geographicalId(), *(recHit.cluster()), ldir))) return false;
336  if (!cutOnPixelShape_) return true;
337 
338  const PixelData & pd = getpd(recHit,ipd);
339 
340  int part;
342  pair<float,float> pred;
343 
344  PixelLimits const * pl = pd.layer==1 ? pixelLimitsL1 : pixelLimits;
345  if(getSizes(recHit, ldir, clusterShapeCache, part,meas, pred,&pd))
346  {
347  for(const auto& m: meas)
348  {
349  PixelKeys key(part, m.first, m.second);
350  if (!key.isValid()) return true; // FIXME original logic
351  if (pl[key].isInside(pred)) return true;
352  }
353  // none of the choices worked
354  return false;
355  }
356  // not usable
357  return true;
358 }
359 
361  (const SiPixelRecHit & recHit, const GlobalVector & gdir,
362  const SiPixelClusterShapeCache& clusterShapeCache,
363  PixelData const * ipd) const
364 {
365  // Get detector
366  const PixelData & pd = getpd(recHit,ipd);
367 
368  LocalVector ldir =pd.det->toLocal(gdir);
369 
370  return isCompatible(recHit, ldir, clusterShapeCache, &pd);
371 }
372 
373 
374 /*****************************************************************************/
375 /*****************************************************************************/
377  (DetId id, const SiStripCluster & cluster, const LocalPoint &lpos, const LocalVector & ldir,
378  int & meas, float & pred) const
379 {
380  // Get detector
381  auto const & p=getsd(id);
382 
383  // Measured width
384  meas = cluster.amplitudes().size();
385 
386  // Usable?
387  int fs = cluster.firstStrip();
388  int ns = p.nstrips;
389  // bool usable = (fs > 1 && fs + meas - 1 < ns);
390  bool usable = (fs >= 1) & (fs + meas <= ns+1);
391 
392  // Usable?
393  //if(usable)
394  {
395  // Predicted width
396  pred = ldir.x() / ldir.z();
397 
398  // Take out drift
399  float drift = p.drift;;
400  pred += drift;
401 
402  // Apply cotangent
403  pred *= getCotangent(p,lpos);
404  }
405 
406  return usable;
407 }
408 
409 
410 /*****************************************************************************/
412  (DetId detId, const SiStripCluster & cluster, const LocalPoint & lpos, const LocalVector & ldir) const
413 {
414  int meas;
415  float pred;
416 
417  if (cutOnStripCharge_ && (!checkClusterCharge(detId, cluster, ldir))) return false;
418  if (!cutOnStripShape_) return true;
419 
420  if(getSizes(detId, cluster, lpos, ldir, meas, pred))
421  {
422  StripKeys key(meas);
423  if (key.isValid())
424  return stripLimits[key].isInside(pred);
425  }
426 
427  // Not usable or no limits
428  return true;
429 }
430 
431 
432 /*****************************************************************************/
434  (DetId detId, const SiStripCluster & cluster, const GlobalPoint &gpos, const GlobalVector & gdir) const
435 {
436  const GeomDet *det = getsd(detId).det;
437  LocalVector ldir = det->toLocal(gdir);
438  LocalPoint lpos = det->toLocal(gpos);
439  // now here we do the transformation
440  lpos -= ldir * lpos.z()/ldir.z();
441  return isCompatible(detId, cluster, lpos, ldir);
442 }
444  (DetId detId, const SiStripCluster & cluster, const GlobalVector & gdir) const
445 {
446  return isCompatible(detId, cluster, getsd(detId).det->toLocal(gdir));
447 }
448 
449 
451 
452 bool ClusterShapeHitFilter::checkClusterCharge(DetId detId, const SiStripCluster& cluster, const LocalVector & ldir) const
453 {
454  return siStripClusterTools::chargePerCM(detId, cluster, ldir) > minGoodStripCharge_;
455 }
456 
457 
458 bool ClusterShapeHitFilter::checkClusterCharge(DetId detId, const SiPixelCluster& cluster, const LocalVector & ldir) const
459 {
460  return siStripClusterTools::chargePerCM(detId, cluster, ldir) > minGoodPixelCharge_;
461 }
462 
465 
468 
bool isBarrel() const
Definition: GeomDetType.cc:13
T perp() const
Definition: PV3DBase.h:72
virtual const GeomDetType & type() const
Definition: GeomDet.cc:85
std::pair< float, float > cotangent
bool checkClusterCharge(DetId detId, const SiStripCluster &cluster, const LocalVector &ldir) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
bool isValid() const
float chargePerCM(DetId detid, Iter a, Iter b)
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:37
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T y() const
Definition: PV3DBase.h:63
virtual std::pair< float, float > pitch() const =0
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
const Bounds & bounds() const
Definition: Surface.h:120
uint16_t firstStrip() const
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
bool isValid() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
bool isTrackerStrip() const
Definition: GeomDetType.cc:24
std::pair< float, float > getCotangent(const PixelGeomDetUnit *pixelDet) const
T z() const
Definition: PV3DBase.h:64
void loadPixelLimits(std::string const &file, PixelLimits *plim)
std::pair< const_iterator, const_iterator > Range
void clear()
Definition: VecArray.h:73
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
double f[11][100]
int index() const
Definition: GeomDet.h:99
SubDetector tkDetEnum[8]
#define LogTrace(id)
bool isNormalOriented(const GeomDetUnit *geomDet) const
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, PixelData const *pd=0) const
const GeomDetType & type() const override
int k[5][pyjets_maxn]
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
const Topology & topology() const override
Returns a reference to the strip proxy topology.
Definition: DetId.h:18
std::pair< float, float > getDrift(const PixelGeomDetUnit *pixelDet) const
virtual float thickness() const =0
double sd
part
Definition: HCALResponse.h:20
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
double b
Definition: hdecay.h:120
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]
ClusterShapeHitFilter(const TrackerGeometry *theTracker_, const TrackerTopology *theTkTopol_, const MagneticField *theMagneticField_, const SiPixelLorentzAngle *theSiPixelLorentzAngle_, const SiStripLorentzAngle *theSiStripLorentzAngle_, const std::string &pixelShapeFile_, const std::string &pixelShapeFileL1_)
virtual float localPitch(const LocalPoint &) const =0
Pixel cluster – collection of neighboring pixels above threshold.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void push_back_unchecked(const T &value)
Definition: VecArray.h:83
SiPixelClusterShapeData get(const ClusterRef &cluster, const PixelGeomDetUnit *pixDet) const
std::string fullPath() const
Definition: FileInPath.cc:163
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
static constexpr size_type capacity() noexcept
Definition: VecArray.h:71
const std::vector< uint8_t > & amplitudes() const
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
Definition: GeomDet.h:45
Our base class.
Definition: SiPixelRecHit.h:23