CMS 3D CMS Logo

HitExtractorSTRP.cc
Go to the documentation of this file.
1 #include "HitExtractorSTRP.h"
3 
6 
8 
10 
14 
15 #include <tuple>
16 
17 #include <iostream>
18 
19 using namespace ctfseeding;
20 using namespace std;
21 using namespace edm;
22 
25  int idLayer,
26  float iminGoodCharge,
28  : theLayerSubDet(subdet),
29  theSide(side),
30  theIdLayer(idLayer),
31  minAbsZ(0),
32  theMinRing(1),
33  theMaxRing(0),
34  theTtopo(iC.esConsumes()),
35  hasMatchedHits(false),
36  hasRPhiHits(false),
37  hasStereoHits(false),
38  hasVectorHits(false),
39  hasRingSelector(false),
40  hasSimpleRphiHitsCleaner(true) {
41  minGoodCharge = iminGoodCharge;
42  if (minGoodCharge > 0)
43  skipClusters = true;
44 }
45 
49 }
50 
52  hasRingSelector = true;
55 }
56 
58  if (!hasRingSelector)
59  return true;
60  return (ring >= theMinRing) & (ring <= theMaxRing);
61 }
62 
64  DetId id,
65  OmniClusterRef const& clus,
67  if (maskCluster && (stripClusterMask->mask(clus.key())))
68  return true;
69 
70  if UNLIKELY (minGoodCharge <= 0)
71  return false;
73 }
74 
75 std::pair<bool, ProjectedSiStripRecHit2D*> HitExtractorSTRP::skipThis(
76  const TkTransientTrackingRecHitBuilder& ttrhBuilder,
80 
81  assert(dynamic_cast<SiStripMatchedRecHit2D const*>(&matched));
82 
83  auto id = hit.geographicalId();
84  ProjectedSiStripRecHit2D* replaceMe = nullptr;
85  bool rejectSt = skipThis(id, hit.stereoClusterRef(), stripClusterMask);
86  bool rejectMono = skipThis(id, hit.monoClusterRef(), stripClusterMask);
87 
88  if ((!rejectSt) & (!rejectMono)) {
89  // keepit
90  return std::make_pair(false, replaceMe);
91  }
92 
93  if (failProjection || (rejectSt & rejectMono)) {
94  //only skip if both hits are done
95  return std::make_pair(true, replaceMe);
96  }
97 
98  // replace with one
99 
100  auto cloner = ttrhBuilder.cloner();
101  replaceMe = cloner.project(hit, rejectSt, TrajectoryStateOnSurface()).release();
102  if (rejectSt)
103  LogDebug("HitExtractorSTRP") << "a matched hit is partially masked, and the mono hit got projected onto: "
104  << replaceMe->geographicalId().rawId() << " key: " << hit.monoClusterRef().key();
105  else
106  LogDebug("HitExtractorSTRP") << "a matched hit is partially masked, and the stereo hit got projected onto: "
107  << replaceMe->geographicalId().rawId() << " key: " << hit.stereoClusterRef().key();
108 
109  return std::make_pair(true, replaceMe);
110 }
111 
113  const edm::Event& ev,
115  bool matched,
116  unsigned int cleanFrom) const {
117  unsigned int skipped = 0;
118  unsigned int projected = 0;
120  LogTrace("HitExtractorSTRP") << "getting " << hits.size() << " strip hit in input.";
121  edm::Handle<SkipClustersCollection> stripClusterMask;
122  if (maskCluster)
123  ev.getByToken(theSkipClusters, stripClusterMask);
124  for (unsigned int iH = cleanFrom; iH < hits.size(); ++iH) {
125  assert(hits[iH]->isValid());
126  auto id = hits[iH]->geographicalId();
127  if (matched) {
128  auto [replace, replaceMe] = skipThis(ttrhBuilder, *hits[iH], stripClusterMask);
129  if (replace) {
130  if (!replaceMe) {
131  LogTrace("HitExtractorSTRP") << "skipping a matched hit on :" << hits[iH]->geographicalId().rawId();
132  skipped++;
133  } else {
134  projected++;
135  }
136  hits[iH].reset(replaceMe);
137  if (replaceMe == nullptr)
138  assert(hits[iH].empty());
139  else
140  assert(hits[iH].isOwn());
141  }
142  } else if (skipThis(id, hits[iH]->firstClusterRef(), stripClusterMask)) {
143  LogTrace("HitExtractorSTRP") << "skipping a hit on :" << hits[iH]->geographicalId().rawId() << " key: ";
144  skipped++;
145  hits[iH].reset();
146  }
147  }
148  }
149  if (hasVectorHits) {
150  LogTrace("HitExtractorSTRP") << "getting " << hits.size() << " vector hit in input.";
152  if (maskCluster)
153  ev.getByToken(theSkipPhase2Clusters, ph2ClusterMask);
154  for (unsigned int iH = cleanFrom; iH < hits.size(); ++iH) {
155  LogTrace("HitExtractorSTRP") << "analizing hit on :" << hits[iH]->geographicalId().rawId();
156  assert(hits[iH]->isValid());
157  const VectorHit& vhit = dynamic_cast<VectorHit const&>(*hits[iH]);
158  LogTrace("HitExtractorSTRP") << " key lower: " << vhit.lowerClusterRef().key()
159  << " and key upper: " << vhit.upperClusterRef().key();
160  LogTrace("HitExtractorSTRP") << " key lower: " << hits[iH]->firstClusterRef().key();
161 
162  //FIXME:: introduce a "projected" version later?
163  if (maskCluster &&
164  (ph2ClusterMask->mask(vhit.lowerClusterRef().key()) || ph2ClusterMask->mask(vhit.upperClusterRef().key()))) {
165  LogTrace("HitExtractorSTRP") << "skipping a vector hit on :" << hits[iH]->geographicalId().rawId()
166  << " key lower: " << vhit.lowerClusterRef().key()
167  << " and key upper: " << vhit.upperClusterRef().key();
168  skipped++;
169  hits[iH].reset();
170  }
171  }
172  }
173 
174  // remove empty elements...
175  auto last = std::remove_if(hits.begin() + cleanFrom, hits.end(), [](HitPointer const& p) { return p.empty(); });
176  hits.resize(last - hits.begin());
177 
178  LogTrace("HitExtractorSTRP") << "skipped :" << skipped << " rechits because of clusters and projected: " << projected;
179 }
180 
182  const edm::Event& ev,
183  const edm::EventSetup& es) const {
184  LogDebug("HitExtractorSTRP") << "HitExtractorSTRP::hits";
186  unsigned int cleanFrom = 0;
187 
188  //Retrieve tracker topology from geometry
189  const TrackerTopology* const tTopo = &es.getData(theTtopo);
190 
191  //
192  // TIB
193  //
195  LogTrace("HitExtractorSTRP") << "Getting hits into the TIB";
196  if (hasMatchedHits) {
198  ev.getByToken(theMatchedHits, matchedHits);
199  if (skipClusters)
200  cleanFrom = result.size();
202  if (skipClusters)
203  cleanedOfClusters(ttrhBuilder, ev, result, true, cleanFrom);
204  }
205  if (hasRPhiHits) {
207  ev.getByToken(theRPhiHits, rphiHits);
208  if (hasMatchedHits) {
209  if (!hasSimpleRphiHitsCleaner) { // this is a brutal "cleaning". Add something smarter in the future
210  if (skipClusters)
211  cleanFrom = result.size();
213  if (skipClusters)
214  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
215  }
216  } else {
217  if (skipClusters)
218  cleanFrom = result.size();
220  if (skipClusters)
221  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
222  }
223  }
224  if (hasStereoHits) {
226  ev.getByToken(theStereoHits, stereoHits);
227  if (skipClusters)
228  cleanFrom = result.size();
230  if (skipClusters)
231  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
232  }
233  if (hasVectorHits) {
234  LogError("HitExtractorSTRP") << "TIB is not supposed to be in Phase2 TRK detector configuration. What follows "
235  "have never been checked before! ";
236  auto const& vectorHits = ev.get(theVectorHits);
237  if (skipClusters)
238  cleanFrom = result.size();
240  if (skipClusters)
241  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
242  }
243 
244  }
245 
246  //
247  // TID
248  //
250  LogTrace("HitExtractorSTRP") << "Getting hits into the TID";
251  if (hasMatchedHits) {
253  ev.getByToken(theMatchedHits, matchedHits);
254  if (skipClusters)
255  cleanFrom = result.size();
256  auto getter = tTopo->tidDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
257  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
259  int ring = tTopo->tidRing(it->detId());
260  if (!ringRange(ring))
261  continue;
262  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end;
263  ++hit) {
264  result.emplace_back(*hit);
265  }
266  }
267  if (skipClusters)
268  cleanedOfClusters(ttrhBuilder, ev, result, true, cleanFrom);
269  }
270  if (hasRPhiHits) {
272  ev.getByToken(theRPhiHits, rphiHits);
273  if (skipClusters)
274  cleanFrom = result.size();
275  auto getter = tTopo->tidDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
276  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
277  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
278  int ring = tTopo->tidRing(it->detId());
279  if (!ringRange(ring))
280  continue;
281  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner)
282  continue; // this is a brutal "cleaning". Add something smarter in the future
283  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
284  result.emplace_back(*hit);
285  }
286  }
287  if (skipClusters)
288  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
289  }
290  if (hasStereoHits) {
292  ev.getByToken(theStereoHits, stereoHits);
293  if (skipClusters)
294  cleanFrom = result.size();
295  auto getter = tTopo->tidDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
296  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
297  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
298  int ring = tTopo->tidRing(it->detId());
299  if (!ringRange(ring))
300  continue;
301  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
302  result.emplace_back(*hit);
303  }
304  }
305  if (skipClusters)
306  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
307  }
308  if (hasVectorHits) {
309  LogTrace("HitExtractorSTRP") << "Getting vector hits for IdLayer " << theIdLayer;
310  auto const& vectorHits = ev.get(theVectorHits);
311  //FIXME: check the skipClusters with VHits
312  if (skipClusters)
313  cleanFrom = result.size();
314  auto getter = tTopo->tidDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
315  VectorHitCollection::Range range = vectorHits.equal_range(getter.first, getter.second);
316  for (VectorHitCollection::const_iterator it = range.first; it != range.second; ++it) {
317  int ring = tTopo->tidRing(it->detId());
318  if (!ringRange(ring))
319  continue;
320  for (VectorHitCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
321  result.emplace_back(*hit);
322  }
323  }
324  LogTrace("HitExtractorSTRP") << "result size value:" << result.size();
325  if (skipClusters)
326  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
327  }
328  }
329  //
330  // TOB
331  //
333  LogTrace("HitExtractorSTRP") << "Getting hits into the TOB";
334  if (hasMatchedHits) {
336  ev.getByToken(theMatchedHits, matchedHits);
337  if (skipClusters)
338  cleanFrom = result.size();
339  if (minAbsZ > 0.) {
340  auto getter = tTopo->tobDetIdLayerComparator(theIdLayer);
341  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
343  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end;
344  ++hit) {
345  if (fabs(hit->globalPosition().z()) >= minAbsZ)
346  result.emplace_back(*hit);
347  }
348  }
349  } else {
351  }
352  if (skipClusters)
353  cleanedOfClusters(ttrhBuilder, ev, result, true, cleanFrom);
354  }
355  if (hasRPhiHits) {
357  ev.getByToken(theRPhiHits, rphiHits);
358  if (hasMatchedHits) {
359  if (!hasSimpleRphiHitsCleaner) { // this is a brutal "cleaning". Add something smarter in the future
360  if (skipClusters)
361  cleanFrom = result.size();
363  if (skipClusters)
364  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
365  }
366  } else {
367  if (skipClusters)
368  cleanFrom = result.size();
370  if (skipClusters)
371  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
372  }
373  }
374  if (hasStereoHits) {
376  ev.getByToken(theStereoHits, stereoHits);
377  if (skipClusters)
378  cleanFrom = result.size();
380  if (skipClusters)
381  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
382  }
383  if (hasVectorHits) {
384  LogTrace("HitExtractorSTRP") << "Getting vector hits for IdLayer " << theIdLayer;
386  ev.getByToken(theVectorHits, vectorHits);
387  //FIXME: check the skipClusters with VHits
388  if (skipClusters)
389  cleanFrom = result.size();
391  if (skipClusters)
392  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
393  }
394 
395  }
396 
397  //
398  // TEC
399  //
401  LogTrace("HitExtractorSTRP") << "Getting hits into the TEC";
402  if (hasMatchedHits) {
404  ev.getByToken(theMatchedHits, matchedHits);
405  if (skipClusters)
406  cleanFrom = result.size();
407  auto getter = tTopo->tecDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
408  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
410  int ring = tTopo->tecRing(it->detId());
411  if (!ringRange(ring))
412  continue;
413  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end;
414  ++hit) {
415  result.emplace_back(*hit);
416  }
417  }
418  if (skipClusters)
419  cleanedOfClusters(ttrhBuilder, ev, result, true, cleanFrom);
420  }
421  if (hasRPhiHits) {
423  ev.getByToken(theRPhiHits, rphiHits);
424  if (skipClusters)
425  cleanFrom = result.size();
426  auto getter = tTopo->tecDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
427  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
428  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
429  int ring = tTopo->tecRing(it->detId());
430  if (!ringRange(ring))
431  continue;
432  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner)
433  continue; // this is a brutal "cleaning". Add something smarter in the future
434  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
435  result.emplace_back(*hit);
436  }
437  }
438  if (skipClusters)
439  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
440  }
441  if (hasStereoHits) {
443  ev.getByToken(theStereoHits, stereoHits);
444  if (skipClusters)
445  cleanFrom = result.size();
446  auto getter = tTopo->tecDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
447  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
448  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
449  int ring = tTopo->tecRing(it->detId());
450  if (!ringRange(ring))
451  continue;
452  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
453  result.emplace_back(*hit);
454  }
455  }
456  if (skipClusters)
457  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
458  }
459  if (hasVectorHits) {
460  LogError("HitExtractorSTRP") << "TEC is not supposed to be in Phase2 TRK detector configuration. What follows "
461  "have never been checked before! ";
463  ev.getByToken(theVectorHits, vectorHits);
464  if (skipClusters)
465  cleanFrom = result.size();
466  auto getter = tTopo->tidDetIdWheelComparator(static_cast<unsigned int>(theSide), theIdLayer);
467  VectorHitCollection::Range range = vectorHits->equal_range(getter.first, getter.second);
468  for (VectorHitCollection::const_iterator it = range.first; it != range.second; ++it) {
469  int ring = tTopo->tidRing(it->detId());
470  if (!ringRange(ring))
471  continue;
472  for (VectorHitCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
473  result.emplace_back(*hit);
474  }
475  }
476  if (skipClusters)
477  cleanedOfClusters(ttrhBuilder, ev, result, false, cleanFrom);
478  }
479  }
480 
481  LogDebug("HitExtractorSTRP") << " giving: " << result.size() << " out for charge cut " << minGoodCharge;
482  return result;
483 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::pair< DetId, SameLayerComparator > tecDetIdWheelComparator(uint32_t side, uint32_t wheel) const
void range2SeedingHits(DSTV const &dstv, HitExtractor::Hits &v, std::pair< A, B > const &sel)
Definition: HitExtractor.h:54
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::EDGetTokenT< SkipPhase2ClustersCollection > theSkipPhase2Clusters
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
std::vector< HitPointer > Hits
Definition: HitExtractor.h:28
std::pair< const_iterator, const_iterator > Range
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > theTtopo
OmniClusterRef const upperClusterRef() const
Definition: VectorHit.h:94
TrackerDetSide
Definition: TrackerDetSide.h:4
float chargePerCM(DetId detid, Iter a, Iter b)
def replace(string, replacements)
Log< level::Error, false > LogError
assert(be >=bs)
unsigned int tecRing(const DetId &id) const
ring id
std::pair< bool, ProjectedSiStripRecHit2D * > skipThis(const TkTransientTrackingRecHitBuilder &ttrhBuilder, TkHitRef matched, edm::Handle< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > &stripClusterMask) const
BaseTrackerRecHit const & TkHitRef
Definition: HitExtractor.h:26
#define LogTrace(id)
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > theMatchedHits
std::pair< DetId, SameLayerComparator > tobDetIdLayerComparator(uint32_t layer) const
const GeomDetEnumerators::SubDetector theLayerSubDet
edm::EDGetTokenT< SiStripRecHit2DCollection > theStereoHits
edm::EDGetTokenT< VectorHitCollection > theVectorHits
HitExtractor::Hits hits(const TkTransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &, const edm::EventSetup &) const override
bool ringRange(int ring) const
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
DetId geographicalId() const
edm::EDGetTokenT< SiStripRecHit2DCollection > theRPhiHits
OmniClusterRef const lowerClusterRef() const
Definition: VectorHit.h:93
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HitExtractorSTRP(GeomDetEnumerators::SubDetector subdet, TrackerDetSide side, int idLayer, float iminGoodCharge, edm::ConsumesCollector &iC)
HLT enums.
std::pair< DetId, SameLayerComparator > tidDetIdWheelComparator(uint32_t side, uint32_t wheel) const
void cleanedOfClusters(const TkTransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &ev, HitExtractor::Hits &hits, bool matched, unsigned int cleanFrom=0) const
unsigned int tidRing(const DetId &id) const
ClusterStripRef cluster_strip() const
std::pair< DetId, SameLayerComparator > tibDetIdLayerComparator(uint32_t layer) const
bool mask(unsigned int iIndex) const
Definition: ContainerMask.h:43
unsigned int key() const
#define UNLIKELY(x)
Definition: Likely.h:21
void useSkipClusters_(const edm::InputTag &m, edm::ConsumesCollector &iC) override
edm::EDGetTokenT< SkipClustersCollection > theSkipClusters
Range equal_range(id_type i, CMP cmp, bool update=false) const
#define LogDebug(id)