CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HitExtractorSTRP.cc
Go to the documentation of this file.
1 #include "HitExtractorSTRP.h"
4 
7 
10 
12 
19 
20 #include<tuple>
21 
22 #include<iostream>
23 
24 using namespace ctfseeding;
25 using namespace std;
26 using namespace edm;
27 
29  theLayerSubDet(subdet), theSide(side), theIdLayer(idLayer),
30  minAbsZ(0), theMinRing(1), theMaxRing(0),
31  hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
32  hasRingSelector(false), hasSimpleRphiHitsCleaner(true)
33 { minGoodCharge=iminGoodCharge; if (minGoodCharge>0) skipClusters=true; }
34 
37 }
38 
40 {
41  hasRingSelector=true;
44 }
45 
47 {
48  if (!hasRingSelector) return true;
49  return (ring >= theMinRing) & (ring <= theMaxRing);
50 }
51 
54 
55  if (maskCluster && (stripClusterMask->mask(clus.key())) ) return true;
56 
57  if unlikely(minGoodCharge<=0) return false;
59 }
60 
61 
62 
63 std::pair<bool,ProjectedSiStripRecHit2D *>
65  TkHitRef matched,
67  const SiStripMatchedRecHit2D & hit = (SiStripMatchedRecHit2D const&)(matched);
68 
69  assert(dynamic_cast<SiStripMatchedRecHit2D const*>(&matched));
70 
71  auto id = hit.geographicalId();
72  ProjectedSiStripRecHit2D * replaceMe = nullptr;
73  bool rejectSt = skipThis(id,hit.stereoClusterRef(), stripClusterMask);
74  bool rejectMono = skipThis(id, hit.monoClusterRef(), stripClusterMask);
75 
76  if ((!rejectSt)&(!rejectMono)){
77  // keepit
78  return std::make_pair(false,replaceMe);
79  }
80 
81  if (failProjection || (rejectSt&rejectMono) ){
82  //only skip if both hits are done
83  return std::make_pair(true,replaceMe);
84  }
85 
86  // replace with one
87 
88  auto cloner = ttrhBuilder.cloner();
89  replaceMe = cloner.project(hit, rejectSt, TrajectoryStateOnSurface()).release();
90  if (rejectSt)
91  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.monoClusterRef().key();
92  else
93  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.stereoClusterRef().key();
94 
95  return std::make_pair(true,replaceMe);
96 }
97 
98 
100  const edm::Event& ev, HitExtractor::Hits & hits,
101  bool matched,
102  unsigned int cleanFrom) const{
103  LogDebug("HitExtractorPIX")<<"getting: "<<hits.size()<<" in input.";
104  edm::Handle<SkipClustersCollection> stripClusterMask;
105  if (maskCluster) ev.getByToken(theSkipClusters,stripClusterMask);
106  unsigned int skipped=0;
107  unsigned int projected=0;
108  for (unsigned int iH=cleanFrom;iH<hits.size();++iH){
109  assert(hits[iH]->isValid());
110  auto id = hits[iH]->geographicalId();
111  if (matched) {
112  bool replace; ProjectedSiStripRecHit2D * replaceMe; std::tie(replace,replaceMe) = skipThis(ttrhBuilder, *hits[iH],stripClusterMask);
113  if (replace) {
114  if (!replaceMe) {
115  LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->geographicalId().rawId();
116  skipped++;
117  } else projected++;
118  hits[iH].reset(replaceMe);
119  if (replaceMe==nullptr) assert(hits[iH].empty());
120  else assert(hits[iH].isOwn());
121  }
122  }
123  else if (skipThis(id, hits[iH]->firstClusterRef(),stripClusterMask)){
124  LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->geographicalId().rawId()<<" key: ";
125  skipped++;
126  hits[iH].reset();
127  }
128  }
129  // remove empty elements...
130  auto last = std::remove_if(hits.begin()+cleanFrom,hits.end(),[]( HitPointer const & p) {return p.empty();});
131  hits.resize(last-hits.begin());
132 
133  // std::cout << "HitExtractorSTRP " <<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected << std::endl;
134  LogDebug("HitExtractorSTRP")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
135 }
136 
138 {
140  TrackerLayerIdAccessor accessor;
141  unsigned int cleanFrom=0;
142 
143  //Retrieve tracker topology from geometry
144  edm::ESHandle<TrackerTopology> tTopoHandle;
145  es.get<IdealGeometryRecord>().get(tTopoHandle);
146  const TrackerTopology* const tTopo = tTopoHandle.product();
147 
148  //
149  // TIB
150  //
152  if (hasMatchedHits) {
154  ev.getByToken( theMatchedHits, matchedHits);
155  if (skipClusters) cleanFrom=result.size();
156  range2SeedingHits( *matchedHits, result, accessor.stripTIBLayer(theIdLayer));
157  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
158  }
159  if (hasRPhiHits) {
161  ev.getByToken( theRPhiHits, rphiHits);
162  if (hasMatchedHits){
163  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
164  if (skipClusters) cleanFrom=result.size();
165  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer));
166  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
167  }
168  } else {
169  if (skipClusters) cleanFrom=result.size();
170  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer));
171  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
172  }
173  }
174  if (hasStereoHits) {
176  ev.getByToken( theStereoHits, stereoHits);
177  if (skipClusters) cleanFrom=result.size();
178  range2SeedingHits( *stereoHits, result, accessor.stripTIBLayer(theIdLayer));
179  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
180  }
181  }
182 
183  //
184  // TID
185  //
187  if (hasMatchedHits) {
189  ev.getByToken( theMatchedHits, matchedHits);
190  if (skipClusters) cleanFrom=result.size();
191  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
192  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
193  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
194  int ring = tTopo->tidRing( it->detId() ); if (!ringRange(ring)) continue;
195  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
196  result.emplace_back(*hit);
197  }
198  }
199  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
200  }
201  if (hasRPhiHits) {
203  ev.getByToken( theRPhiHits, rphiHits);
204  if (skipClusters) cleanFrom=result.size();
205  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
206  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
207  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
208  int ring = tTopo->tidRing( it->detId() ); if (!ringRange(ring)) continue;
209  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
210  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
211  result.emplace_back(*hit);
212  }
213  }
214  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
215  }
216  if (hasStereoHits) {
218  ev.getByToken( theStereoHits, stereoHits);
219  if (skipClusters) cleanFrom=result.size();
220  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
221  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
222  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
223  int ring = tTopo->tidRing( it->detId() ); if (!ringRange(ring)) continue;
224  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
225  result.emplace_back(*hit);
226  }
227  }
228  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
229  }
230  }
231  //
232  // TOB
233  //
235  if (hasMatchedHits) {
237  ev.getByToken( theMatchedHits, matchedHits);
238  if (skipClusters) cleanFrom=result.size();
239  if (minAbsZ>0.) {
240  std::pair<DetId,DetIdTOBSameLayerComparator> getter = accessor.stripTOBLayer(theIdLayer);
241  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
242  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
243  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
244  if (fabs(hit->globalPosition().z())>=minAbsZ) result.emplace_back(*hit);
245  }
246  }
247  } else {
248  range2SeedingHits( *matchedHits, result, accessor.stripTOBLayer(theIdLayer));
249  }
250  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
251  }
252  if (hasRPhiHits) {
254  ev.getByToken( theRPhiHits, rphiHits);
255  if (hasMatchedHits){
256  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
257  if (skipClusters) cleanFrom=result.size();
258  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer));
259  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
260  }
261  } else {
262  if (skipClusters) cleanFrom=result.size();
263  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer));
264  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
265  }
266  }
267  if (hasStereoHits) {
269  ev.getByToken( theStereoHits, stereoHits);
270  if (skipClusters) cleanFrom=result.size();
271  range2SeedingHits( *stereoHits, result, accessor.stripTOBLayer(theIdLayer));
272  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
273  }
274  }
275 
276  //
277  // TEC
278  //
280  if (hasMatchedHits) {
282  ev.getByToken( theMatchedHits, matchedHits);
283  if (skipClusters) cleanFrom=result.size();
284  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
285  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
286  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
287  int ring = tTopo->tecRing( it->detId() ); if (!ringRange(ring)) continue;
288  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
289  result.emplace_back(*hit);
290  }
291  }
292  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
293  }
294  if (hasRPhiHits) {
296  ev.getByToken( theRPhiHits, rphiHits);
297  if (skipClusters) cleanFrom=result.size();
298  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
299  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
300  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
301  int ring = tTopo->tecRing( it->detId() ); if (!ringRange(ring)) continue;
302  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
303  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
304  result.emplace_back(*hit);
305  }
306  }
307  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
308 
309  }
310  if (hasStereoHits) {
312  ev.getByToken( theStereoHits, stereoHits);
313  if (skipClusters) cleanFrom=result.size();
314  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
315  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
316  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
317  int ring = tTopo->tecRing( it->detId() ); if (!ringRange(ring)) continue;
318  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
319  result.emplace_back(*hit);
320  }
321  }
322  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
323  }
324  }
325 
326  LogDebug("HitExtractorSTRP")<<" giving: "<<result.size()<<" out";
327  // std::cout << "HitExtractorSTRP "<<" giving: "<<result.size() << " for charge cut " << minGoodCharge << std::endl;
328  return result;
329 }
330 
331 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void range2SeedingHits(DSTV const &dstv, HitExtractor::Hits &v, std::pair< A, B > const &sel)
Definition: HitExtractor.h:49
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
unsigned int tidRing(const DetId &id) const
std::pair< DetId, DetIdTIDSameDiskComparator > stripTIDDisk(int side, int disk)
std::vector< HitPointer > Hits
Definition: HitExtractor.h:25
bool ringRange(int ring) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
BaseTrackerRecHit const & TkHitRef
Definition: HitExtractor.h:23
OmniClusterRef const & stereoClusterRef() const
unsigned int tecRing(const DetId &id) const
ring id
assert(m_qm.get())
float chargePerCM(DetId detid, Iter a, Iter b)
std::pair< DetId, DetIdTIBSameLayerComparator > stripTIBLayer(int layer)
bool ev
std::pair< const_iterator, const_iterator > Range
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > theMatchedHits
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
#define unlikely(x)
std::pair< bool, ProjectedSiStripRecHit2D * > skipThis(const TkTransientTrackingRecHitBuilder &ttrhBuilder, TkHitRef matched, edm::Handle< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > &stripClusterMask) const
std::pair< DetId, DetIdTOBSameLayerComparator > stripTOBLayer(int layer)
const GeomDetEnumerators::SubDetector theLayerSubDet
edm::EDGetTokenT< SiStripRecHit2DCollection > theStereoHits
ClusterStripRef cluster_strip() const
tuple result
Definition: query.py:137
std::pair< DetId, DetIdTECSameDiskComparator > stripTECDisk(int side, int disk)
void cleanedOfClusters(const TkTransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &ev, HitExtractor::Hits &hits, bool matched, unsigned int cleanFrom=0) const
#define end
Definition: vmac.h:37
OmniClusterRef const & monoClusterRef() const
virtual HitExtractor::Hits hits(const TkTransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &, const edm::EventSetup &) const override
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:18
edm::EDGetTokenT< SiStripRecHit2DCollection > theRPhiHits
HitExtractorSTRP(GeomDetEnumerators::SubDetector subdet, SeedingLayer::Side &side, int idLayer, float iminGoodCharge)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
unsigned int key() const
void useSkipClusters_(const edm::InputTag &m, edm::ConsumesCollector &iC) override
edm::EDGetTokenT< SkipClustersCollection > theSkipClusters