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 
17 
20 
21 using namespace ctfseeding;
22 using namespace std;
23 using namespace edm;
24 
26  theLayerSubDet(subdet), theSide(side), theIdLayer(idLayer),
27  minAbsZ(0), theMinRing(1), theMaxRing(0),
28  hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
29  hasRingSelector(false), hasSimpleRphiHitsCleaner(true)
30 {}
31 
34 }
35 
36 void HitExtractorSTRP::useRingSelector(int minRing, int maxRing)
37 {
38  hasRingSelector=true;
39  theMinRing=minRing;
40  theMaxRing=maxRing;
41 }
42 
44 {
45  if (!hasRingSelector) return true;
46  else if ( ring >= theMinRing && ring <= theMaxRing) return true;
47  else return false;
48 }
49 
52  // if (!hit->isValid()) return false;
53 
54  return stripClusterMask->mask(clus.key());
55 }
56 
57 
60  const SiStripRecHit2D * hit,
62 
63  if (failProjection) {replaceMe=0; return;}
65  TransientTrackingRecHit::RecHitPointer sHit=ttrhBuilder.build(hit);
66  replaceMe=proj.project( *sHit, *ptr->det());
67  if (!replaceMe) LogDebug("HitExtractorSTRP")<<"projection failed.";
68 }
69 
74  const SiStripMatchedRecHit2D * hit = (SiStripMatchedRecHit2D *) ptr->hit();
75 
76  bool rejectSt = skipThis(hit->stereoClusterRef(), stripClusterMask);
77  bool rejectMono = skipThis(hit->monoClusterRef(), stripClusterMask);
78 
79  if (rejectSt&&rejectMono){
80  //only skip if both hits are done
81  return true;
82  }
83  else{
84  //FIX use clusters directly
85  auto const & s= hit->stereoHit();
86  auto const & m= hit->monoHit();
87  if (rejectSt) project(ttrhBuilder, ptr,&s,replaceMe);
88  else if (rejectMono) project(ttrhBuilder, ptr,&m,replaceMe);
89  if (!replaceMe) return true; //means that the projection failed, and needs to be skipped
90  if (rejectSt)
91  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->monoClusterRef().key();
92  else if (rejectMono)
93  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->stereoClusterRef().key();
94  return false; //means the projection succeeded or nothing to be masked, no need to skip and replaceMe is going to be used anyways.
95  }
96  return false;
97 }
98 
99 
101  const edm::Event& ev, HitExtractor::Hits & hits,
102  bool matched,
103  unsigned int cleanFrom)const{
104  LogDebug("HitExtractorPIX")<<"getting: "<<hits.size()<<" in input.";
105  edm::Handle<SkipClustersCollection> stripClusterMask;
106  ev.getByToken(theSkipClusters,stripClusterMask);
107  HitExtractor::Hits newHits;
108  unsigned int skipped=0;
109  unsigned int projected=0;
110  newHits.reserve(hits.size());
112  for (unsigned int iH=0;iH<hits.size();++iH){
113  if (!hits[iH]->isValid()) continue;
114  replaceMe=hits[iH];
115  if (iH<cleanFrom) {
116  newHits.push_back(replaceMe);
117  continue;
118  }
119  if (matched && skipThis(ttrhBuilder, hits[iH],stripClusterMask,replaceMe)){
120  LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->hit()->geographicalId().rawId();
121  skipped++;
122  continue;
123  }
124  if (!matched && skipThis( ((TrackerSingleRecHit const *)(hits[iH]->hit()))->omniClusterRef(),stripClusterMask)){
125  LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->hit()->geographicalId().rawId()<<" key: ";
126  skipped++;
127  continue;
128  }
129  if (replaceMe!=hits[iH]) projected++;
130  newHits.push_back(replaceMe);
131  }
132  LogDebug("HitExtractorPIX")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
133  hits.swap(newHits);
134 }
135 
137 {
139  TrackerLayerIdAccessor accessor;
140  unsigned int cleanFrom=0;
141  //
142  // TIB
143  //
145  if (hasMatchedHits) {
147  ev.getByToken( theMatchedHits, matchedHits);
148  if (skipClusters) cleanFrom=result.size();
149  range2SeedingHits( *matchedHits, result, accessor.stripTIBLayer(theIdLayer), ttrhBuilder, es);
150  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
151  }
152  if (hasRPhiHits) {
154  ev.getByToken( theRPhiHits, rphiHits);
155  if (hasMatchedHits){
156  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
157  if (skipClusters) cleanFrom=result.size();
158  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), ttrhBuilder, es);
159  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
160  }
161  } else {
162  if (skipClusters) cleanFrom=result.size();
163  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), ttrhBuilder, es);
164  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
165  }
166  }
167  if (hasStereoHits) {
169  ev.getByToken( theStereoHits, stereoHits);
170  if (skipClusters) cleanFrom=result.size();
171  range2SeedingHits( *stereoHits, result, accessor.stripTIBLayer(theIdLayer), ttrhBuilder, es);
172  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
173  }
174  }
175 
176  //
177  // TID
178  //
180  if (hasMatchedHits) {
182  ev.getByToken( theMatchedHits, matchedHits);
183  if (skipClusters) cleanFrom=result.size();
184  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
185  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
186  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
187  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
188  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
189  result.push_back( ttrhBuilder.build(hit) );
190  }
191  }
192  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
193  }
194  if (hasRPhiHits) {
196  ev.getByToken( theRPhiHits, rphiHits);
197  if (skipClusters) cleanFrom=result.size();
198  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
199  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
200  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
201  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
202  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
203  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
204  result.push_back( ttrhBuilder.build(hit) );
205  }
206  }
207  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
208  }
209  if (hasStereoHits) {
211  ev.getByToken( theStereoHits, stereoHits);
212  if (skipClusters) cleanFrom=result.size();
213  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
214  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
215  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
216  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
217  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
218  result.push_back( ttrhBuilder.build(hit) );
219  }
220  }
221  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
222  }
223  }
224  //
225  // TOB
226  //
228  if (hasMatchedHits) {
230  ev.getByToken( theMatchedHits, matchedHits);
231  if (skipClusters) cleanFrom=result.size();
232  if (minAbsZ>0.) {
233  std::pair<DetId,DetIdTOBSameLayerComparator> getter = accessor.stripTOBLayer(theIdLayer);
234  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
235  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
236  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
238  if (fabs(ttrh->globalPosition().z())>=minAbsZ) result.push_back( ttrh );
239  }
240  }
241  } else {
242  range2SeedingHits( *matchedHits, result, accessor.stripTOBLayer(theIdLayer), ttrhBuilder, es);
243  }
244  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
245  }
246  if (hasRPhiHits) {
248  ev.getByToken( theRPhiHits, rphiHits);
249  if (hasMatchedHits){
250  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
251  if (skipClusters) cleanFrom=result.size();
252  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), ttrhBuilder, es);
253  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
254  }
255  } else {
256  if (skipClusters) cleanFrom=result.size();
257  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), ttrhBuilder, es);
258  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
259  }
260  }
261  if (hasStereoHits) {
263  ev.getByToken( theStereoHits, stereoHits);
264  if (skipClusters) cleanFrom=result.size();
265  range2SeedingHits( *stereoHits, result, accessor.stripTOBLayer(theIdLayer), ttrhBuilder, es);
266  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
267  }
268  }
269 
270  //
271  // TEC
272  //
274  if (hasMatchedHits) {
276  ev.getByToken( theMatchedHits, matchedHits);
277  if (skipClusters) cleanFrom=result.size();
278  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
279  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
280  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
281  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
282  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
283  result.push_back( ttrhBuilder.build(hit) );
284  }
285  }
286  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
287  }
288  if (hasRPhiHits) {
290  ev.getByToken( theRPhiHits, rphiHits);
291  if (skipClusters) cleanFrom=result.size();
292  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
293  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
294  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
295  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
296  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
297  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
298  result.push_back( ttrhBuilder.build(hit) );
299  }
300  }
301  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
302 
303  }
304  if (hasStereoHits) {
306  ev.getByToken( theStereoHits, stereoHits);
307  if (skipClusters) cleanFrom=result.size();
308  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
309  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
310  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
311  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
312  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
313  result.push_back( ttrhBuilder.build(hit) );
314  }
315  }
316  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
317  }
318  }
319  LogDebug("HitExtractorSTRP")<<" giving: "<<result.size()<<" out";
320  return result;
321 }
322 
323 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
HitExtractorSTRP(GeomDetEnumerators::SubDetector subdet, SeedingLayer::Side &side, int idLayer)
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
virtual HitExtractor::Hits hits(const TransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &, const edm::EventSetup &) const
std::pair< DetId, DetIdTIDSameDiskComparator > stripTIDDisk(int side, int disk)
bool ringRange(int ring) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
void cleanedOfClusters(const TransientTrackingRecHitBuilder &ttrhBuilder, const edm::Event &ev, HitExtractor::Hits &hits, bool matched, unsigned int cleanFrom=0) const
std::pair< DetId, DetIdTIBSameLayerComparator > stripTIBLayer(int layer)
std::pair< const_iterator, const_iterator > Range
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > theMatchedHits
RecHitPointer project(const TransientTrackingRecHit &hit, const GeomDet &det, const TrajectoryStateOnSurface &ts) const
std::pair< DetId, DetIdTOBSameLayerComparator > stripTOBLayer(int layer)
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const GeomDetEnumerators::SubDetector theLayerSubDet
edm::EDGetTokenT< SiStripRecHit2DCollection > theStereoHits
tuple result
Definition: query.py:137
std::pair< DetId, DetIdTECSameDiskComparator > stripTECDisk(int side, int disk)
#define end
Definition: vmac.h:37
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
void range2SeedingHits(DSTV const &dstv, HitExtractor::Hits &v, std::pair< A, B > const &sel, const TransientTrackingRecHitBuilder &ttrhBuilder, const edm::EventSetup &es)
Definition: HitExtractor.h:51
edm::EDGetTokenT< SiStripRecHit2DCollection > theRPhiHits
bool skipThis(const TransientTrackingRecHitBuilder &ttrhBuilder, TransientTrackingRecHit::ConstRecHitPointer &ptr, edm::Handle< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > &stripClusterMask, TransientTrackingRecHit::ConstRecHitPointer &replaceMe) const
void project(const TransientTrackingRecHitBuilder &ttrhBuilder, TransientTrackingRecHit::ConstRecHitPointer &ptr, const SiStripRecHit2D *hit, TransientTrackingRecHit::ConstRecHitPointer &replaceMe) 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
std::vector< TransientTrackingRecHit::ConstRecHitPointer > Hits
Definition: HitExtractor.h:20