CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 MagneticField * theMagneticField_,
39  const SiPixelLorentzAngle * theSiPixelLorentzAngle_,
40  const SiStripLorentzAngle * theSiStripLorentzAngle_,
41  const std::string * use_PixelShapeFile_)
42  : theTracker(theTracker_),
43  theMagneticField(theMagneticField_),
44  theSiPixelLorentzAngle(theSiPixelLorentzAngle_),
45  theSiStripLorentzAngle(theSiStripLorentzAngle_),
46  PixelShapeFile(use_PixelShapeFile_)
47 {
48  // Load pixel limits
49  loadPixelLimits();
50  fillPixelData();
51 
52  // Load strip limits
53  loadStripLimits();
54  cutOnPixelCharge_ = cutOnStripCharge_ = false;
55  cutOnPixelShape_ = cutOnStripShape_ = true;
56 }
57 
58 /*****************************************************************************/
60 {
61 }
62 
63 /*****************************************************************************/
65 {
67  fileInPath(PixelShapeFile->c_str());
68  //fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/pixelShape.par");
69  //fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/pixelShape_Phase1Tk.par");
70  ifstream inFile(fileInPath.fullPath().c_str());
71 
72 
73  while(inFile.eof() == false)
74  {
75  int part,dx,dy;
76 
77  inFile >> part; // 0or 1
78  inFile >> dx; // 0 to 10
79  inFile >> dy; // 0 to 15 ...
80 
81  const PixelKeys key(part,dx,dy);
82  auto & pl = pixelLimits[key];
83 
84  for(int b = 0; b<2 ; b++) // branch
85  for(int d = 0; d<2 ; d++) // direction
86  for(int k = 0; k<2 ; k++) // lower and upper
87  inFile >> pl.data[b][d][k];
88 
89 
90  double f;
91  int d;
92 
93  inFile >> f; // density
94  inFile >> d; // points
95  inFile >> f; // density
96  inFile >> d; // points
97  }
98 
99  inFile.close();
100 
101  LogTrace("MinBiasTracking|ClusterShapeHitFilter")
102  << " [ClusterShapeHitFilter] pixel-cluster-shape filter loaded";
103  }
104 
105 /*****************************************************************************/
107 {
108  // Load strip
110  fileInPath("RecoPixelVertexing/PixelLowPtUtilities/data/stripShape.par");
111  ifstream inFile(fileInPath.fullPath().c_str());
112 
113 
114  while(inFile.eof() == false)
115  {
116  int dx;
117  inFile >> dx;
118 
119  StripKeys key(dx);
120  auto & sl = stripLimits[key];
121 
122  for(int b = 0; b<2 ; b++) // branch
123  for(int k = 0; k<2 ; k++) // lower and upper
124  inFile >> sl.data[b][k];
125 
126  }
127 
128  inFile.close();
129 
130  LogTrace("MinBiasTracking|ClusterShapeHitFilter")
131  << " [ClusterShapeHitFilter] strip-cluster-width filter loaded";
132 }
133 
134 
135 
137 
138  //barrel
139  for (auto det : theTracker->detsPXB()) {
140  // better not to fail..
141  const PixelGeomDetUnit * pixelDet =
142  dynamic_cast<const PixelGeomDetUnit*>(det);
143  assert(pixelDet);
144  PixelData & pd = pixelData[pixelDet->geographicalId()];
145  pd.det = pixelDet;
146  pd.part=0;
147  pd.cotangent=getCotangent(pixelDet);
148  pd.drift=getDrift(pixelDet);
149  }
150 
151  //endcap
152  for (auto det : theTracker->detsPXF()) {
153  // better not to fail..
154  const PixelGeomDetUnit * pixelDet =
155  dynamic_cast<const PixelGeomDetUnit*>(det);
156  assert(pixelDet);
157  PixelData & pd = pixelData[pixelDet->geographicalId()];
158  pd.det = pixelDet;
159  pd.part=1;
160  pd.cotangent=getCotangent(pixelDet);
161  pd.drift=getDrift(pixelDet);
162  }
163 
164 }
165 
166 
167 /*****************************************************************************/
168 pair<float,float> ClusterShapeHitFilter::getCotangent
169  (const PixelGeomDetUnit * pixelDet) const
170 {
171  pair<float,float> cotangent;
172 
173  cotangent.first = pixelDet->surface().bounds().thickness() /
174  pixelDet->specificTopology().pitch().first;
175  cotangent.second = pixelDet->surface().bounds().thickness() /
176  pixelDet->specificTopology().pitch().second;
177 
178  return cotangent;
179 }
180 
181 /*****************************************************************************/
183  (const StripGeomDetUnit * stripDet, const LocalPoint & pos) const
184 {
185  // FIXME may be problematic in case of RadialStriptolopgy
186  return stripDet->surface().bounds().thickness() /
187  stripDet->specificTopology().localPitch(pos);
188 }
189 
190 /*****************************************************************************/
191 pair<float,float> ClusterShapeHitFilter::getDrift
192  (const PixelGeomDetUnit * pixelDet) const
193 {
194  LocalVector lBfield =
195  (pixelDet->surface()).toLocal(
196  theMagneticField->inTesla(
197  pixelDet->surface().position()));
198 
199  double theTanLorentzAnglePerTesla =
200  theSiPixelLorentzAngle->getLorentzAngle(
201  pixelDet->geographicalId().rawId());
202 
203  pair<float,float> dir;
204  dir.first = - theTanLorentzAnglePerTesla * lBfield.y();
205  dir.second = theTanLorentzAnglePerTesla * lBfield.x();
206 
207  return dir;
208 }
209 
210 /*****************************************************************************/
212 const
213 {
214  LocalVector lBfield =
215  (stripDet->surface()).toLocal(
216  theMagneticField->inTesla(
217  stripDet->surface().position()));
218 
219  double theTanLorentzAnglePerTesla =
220  theSiStripLorentzAngle->getLorentzAngle(
221  stripDet->geographicalId().rawId());
222 
223  float dir = theTanLorentzAnglePerTesla * lBfield.y();
224 
225  return dir;
226 }
227 
228 /*****************************************************************************/
230  (const GeomDetUnit * geomDet) const
231 {
232  if(geomDet->type().isBarrel())
233  { // barrel
234  float perp0 = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).perp();
235  float perp1 = geomDet->toGlobal( Local3DPoint(0.,0.,1.) ).perp();
236  return (perp1 > perp0);
237  }
238  else
239  { // endcap
240  float rot = geomDet->toGlobal( LocalVector (0.,0.,1.) ).z();
241  float pos = geomDet->toGlobal( Local3DPoint(0.,0.,0.) ).z();
242  return (rot * pos > 0);
243  }
244 }
245 
246 /*****************************************************************************/
247 /*****************************************************************************/
248 
250  (const SiPixelRecHit & recHit, const LocalVector & ldir,
251  const SiPixelClusterShapeCache& clusterShapeCache,
252  int & part, ClusterData::ArrayType& meas, pair<float,float> & pred,
253  PixelData const * ipd) const
254 {
255  // Get detector
256  const PixelData & pd = getpd(recHit,ipd);
257 
258  // Get shape information
259  const SiPixelClusterShapeData& data = clusterShapeCache.get(recHit.cluster(), pd.det);
260  bool usable = (data.isStraight() && data.isComplete());
261 
262  // Usable?
263  //if(usable)
264  {
265  part = pd.part;
266 
267  // Predicted size
268  pred.first = ldir.x() / ldir.z();
269  pred.second = ldir.y() / ldir.z();
270 
271  SiPixelClusterShapeData::Range sizeRange = data.size();
272  if(sizeRange.first->second < 0)
273  pred.second = - pred.second;
274 
275  meas.clear();
276  assert(meas.capacity() >= std::distance(sizeRange.first, sizeRange.second));
277  for(auto s=sizeRange.first; s != sizeRange.second; ++s) {
278  meas.push_back_unchecked(*s);
279  }
280  if(sizeRange.first->second < 0) {
281  for(auto& s: meas)
282  s.second = -s.second;
283  }
284 
285  // Take out drift
286  std::pair<float,float> const & drift = pd.drift;
287  pred.first += drift.first;
288  pred.second += drift.second;
289 
290  // Apply cotangent
291  std::pair<float,float> const & cotangent = pd.cotangent;
292  pred.first *= cotangent.first;
293  pred.second *= cotangent.second;
294  }
295 
296  // Usable?
297  return usable;
298 }
299 
301  (const SiPixelRecHit & recHit, const LocalVector & ldir,
302  const SiPixelClusterShapeCache& clusterShapeCache,
303  PixelData const * ipd) const
304 {
305  // Get detector
306  if (cutOnPixelCharge_ && (!checkClusterCharge(recHit.geographicalId(), *(recHit.cluster()), ldir))) return false;
307  if (!cutOnPixelShape_) return true;
308 
309  const PixelData & pd = getpd(recHit,ipd);
310 
311  int part;
313  pair<float,float> pred;
314 
315  if(getSizes(recHit, ldir, clusterShapeCache, part,meas, pred,&pd))
316  {
317  for(const auto& m: meas)
318  {
319  PixelKeys key(part, m.first, m.second);
320  if (!key.isValid()) return true; // FIXME original logic
321  if (pixelLimits[key].isInside(pred)) return true;
322  }
323  // none of the choices worked
324  return false;
325  }
326  // not usable
327  return true;
328 }
329 
331  (const SiPixelRecHit & recHit, const GlobalVector & gdir,
332  const SiPixelClusterShapeCache& clusterShapeCache,
333  PixelData const * ipd) const
334 {
335  // Get detector
336  const PixelData & pd = getpd(recHit,ipd);
337 
338  LocalVector ldir =pd.det->toLocal(gdir);
339 
340  return isCompatible(recHit, ldir, clusterShapeCache, &pd);
341 }
342 
343 
344 /*****************************************************************************/
345 /*****************************************************************************/
347  (DetId id, const SiStripCluster & cluster, const LocalPoint &lpos, const LocalVector & ldir,
348  int & meas, float & pred) const
349 {
350  // Get detector
351  const StripGeomDetUnit* stripDet =
352  dynamic_cast<const StripGeomDetUnit*> (theTracker->idToDet(id));
353 
354  // Measured width
355  meas = cluster.amplitudes().size();
356 
357  // Usable?
358  int fs = cluster.firstStrip();
359  int ns = stripDet->specificTopology().nstrips();
360  // bool usable = (fs > 1 && fs + meas - 1 < ns);
361  bool usable = (fs >= 1 && fs + meas - 1 <= ns);
362 
363  // Usable?
364  //if(usable)
365  {
366  // Predicted width
367  pred = ldir.x() / ldir.z();
368 
369  // Take out drift
370  float drift = getDrift(stripDet);
371  pred += drift;
372 
373  // Apply cotangent
374  pred *= getCotangent(stripDet,lpos);
375  }
376 
377  return usable;
378 }
379 
380 
381 /*****************************************************************************/
383  (DetId detId, const SiStripCluster & cluster, const LocalPoint & lpos, const LocalVector & ldir) const
384 {
385  int meas;
386  float pred;
387 
388  if (cutOnStripCharge_ && (!checkClusterCharge(detId, cluster, ldir))) return false;
389  if (!cutOnStripShape_) return true;
390 
391  if(getSizes(detId, cluster, lpos, ldir, meas, pred))
392  {
393  StripKeys key(meas);
394  if (key.isValid())
395  return stripLimits[key].isInside(pred);
396  }
397 
398  // Not usable or no limits
399  return true;
400 }
401 
402 
403 /*****************************************************************************/
405  (DetId detId, const SiStripCluster & cluster, const GlobalPoint &gpos, const GlobalVector & gdir) const
406 {
407  const GeomDet *det = theTracker->idToDet(detId);
408  LocalVector ldir = det->toLocal(gdir);
409  LocalPoint lpos = det->toLocal(gpos);
410  // now here we do the transformation
411  lpos -= ldir * lpos.z()/ldir.z();
412  return isCompatible(detId, cluster, lpos, ldir);
413 }
415  (DetId detId, const SiStripCluster & cluster, const GlobalVector & gdir) const
416 {
417  return isCompatible(detId, cluster, theTracker->idToDet(detId)->toLocal(gdir));
418 }
419 
420 
422 
423 bool ClusterShapeHitFilter::checkClusterCharge(DetId detId, const SiStripCluster& cluster, const LocalVector & ldir) const
424 {
425  return siStripClusterTools::chargePerCM(detId, cluster, ldir) > minGoodStripCharge_;
426 }
427 
428 
429 bool ClusterShapeHitFilter::checkClusterCharge(DetId detId, const SiPixelCluster& cluster, const LocalVector & ldir) const
430 {
431  return siStripClusterTools::chargePerCM(detId, cluster, ldir) > minGoodPixelCharge_;
432 }
433 
436 
439 
virtual int nstrips() const =0
bool isBarrel() const
Definition: GeomDetType.cc:13
T perp() const
Definition: PV3DBase.h:72
virtual const GeomDetType & type() const
Definition: GeomDet.cc:90
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:52
bool isValid() const
assert(m_qm.get())
float chargePerCM(DetId detid, Iter a, Iter b)
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:39
T y() const
Definition: PV3DBase.h:63
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:67
const Bounds & bounds() const
Definition: Surface.h:128
uint16_t firstStrip() const
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
bool isValid() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual float thickness() const =0
tuple d
Definition: ztail.py:151
virtual float localPitch(const LocalPoint &) const =0
std::pair< float, float > getCotangent(const PixelGeomDetUnit *pixelDet) const
T z() const
Definition: PV3DBase.h:64
std::pair< const_iterator, const_iterator > Range
void clear()
Definition: VecArray.h:73
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
double f[11][100]
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#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
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
virtual std::pair< float, float > pitch() const =0
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
Definition: DetId.h:18
std::pair< float, float > getDrift(const PixelGeomDetUnit *pixelDet) const
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
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:85
SiPixelClusterShapeData get(const ClusterRef &cluster, const PixelGeomDetUnit *pixDet) const
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
std::string fullPath() const
Definition: FileInPath.cc:165
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
Our base class.
Definition: SiPixelRecHit.h:23