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 
21 
22 #include<tuple>
23 
24 #include<iostream>
25 
26 using namespace ctfseeding;
27 using namespace std;
28 using namespace edm;
29 
31  theLayerSubDet(subdet), theSide(side), theIdLayer(idLayer),
32  minAbsZ(0), theMinRing(1), theMaxRing(0),
33  hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
34  hasRingSelector(false), hasSimpleRphiHitsCleaner(true)
35 { minGoodCharge=iminGoodCharge; if (minGoodCharge>0) skipClusters=true; }
36 
39 }
40 
42 {
43  hasRingSelector=true;
46 }
47 
49 {
50  if (!hasRingSelector) return true;
51  return (ring >= theMinRing) & (ring <= theMaxRing);
52 }
53 
56 
57  if (maskCluster && (stripClusterMask->mask(clus.key())) ) return true;
58 
59  if unlikely(minGoodCharge<=0) return false;
61 }
62 
63 
64 
65 std::pair<bool,ProjectedSiStripRecHit2D *>
67  TkHitRef matched,
69  const SiStripMatchedRecHit2D & hit = (SiStripMatchedRecHit2D const&)(matched);
70 
71  assert(dynamic_cast<SiStripMatchedRecHit2D const*>(&matched));
72 
73  auto id = hit.geographicalId();
74  ProjectedSiStripRecHit2D * replaceMe = nullptr;
75  bool rejectSt = skipThis(id,hit.stereoClusterRef(), stripClusterMask);
76  bool rejectMono = skipThis(id, hit.monoClusterRef(), stripClusterMask);
77 
78  if ((!rejectSt)&(!rejectMono)){
79  // keepit
80  return std::make_pair(false,replaceMe);
81  }
82 
83  if (failProjection || (rejectSt&rejectMono) ){
84  //only skip if both hits are done
85  return std::make_pair(true,replaceMe);
86  }
87 
88  // replace with one
89 
90  auto cloner = ttrhBuilder.cloner();
91  replaceMe = cloner.project(hit, rejectSt, TrajectoryStateOnSurface()).release();
92  if (rejectSt)
93  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.monoClusterRef().key();
94  else
95  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.stereoClusterRef().key();
96 
97  return std::make_pair(true,replaceMe);
98 }
99 
100 
102  const edm::Event& ev, HitExtractor::Hits & hits,
103  bool matched,
104  unsigned int cleanFrom) const{
105  LogDebug("HitExtractorPIX")<<"getting: "<<hits.size()<<" in input.";
106  edm::Handle<SkipClustersCollection> stripClusterMask;
107  if (maskCluster) ev.getByToken(theSkipClusters,stripClusterMask);
108  unsigned int skipped=0;
109  unsigned int projected=0;
110  for (unsigned int iH=cleanFrom;iH<hits.size();++iH){
111  assert(hits[iH]->isValid());
112  auto id = hits[iH]->geographicalId();
113  if (matched) {
114  bool replace; ProjectedSiStripRecHit2D * replaceMe; std::tie(replace,replaceMe) = skipThis(ttrhBuilder, *hits[iH],stripClusterMask);
115  if (replace) {
116  if (!replaceMe) {
117  LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->geographicalId().rawId();
118  skipped++;
119  } else projected++;
120  hits[iH].reset(replaceMe);
121  if (replaceMe==nullptr) assert(hits[iH].empty());
122  else assert(hits[iH].isOwn());
123  }
124  }
125  else if (skipThis(id, hits[iH]->firstClusterRef(),stripClusterMask)){
126  LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->geographicalId().rawId()<<" key: ";
127  skipped++;
128  hits[iH].reset();
129  }
130  }
131  // remove empty elements...
132  auto last = std::remove_if(hits.begin()+cleanFrom,hits.end(),[]( HitPointer const & p) {return p.empty();});
133  hits.resize(last-hits.begin());
134 
135  // std::cout << "HitExtractorSTRP " <<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected << std::endl;
136  LogDebug("HitExtractorSTRP")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
137 }
138 
140 {
142  TrackerLayerIdAccessor accessor;
143  unsigned int cleanFrom=0;
144  //
145  // TIB
146  //
148  if (hasMatchedHits) {
150  ev.getByToken( theMatchedHits, matchedHits);
151  if (skipClusters) cleanFrom=result.size();
152  range2SeedingHits( *matchedHits, result, accessor.stripTIBLayer(theIdLayer));
153  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
154  }
155  if (hasRPhiHits) {
157  ev.getByToken( theRPhiHits, rphiHits);
158  if (hasMatchedHits){
159  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
160  if (skipClusters) cleanFrom=result.size();
161  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer));
162  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
163  }
164  } else {
165  if (skipClusters) cleanFrom=result.size();
166  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer));
167  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
168  }
169  }
170  if (hasStereoHits) {
172  ev.getByToken( theStereoHits, stereoHits);
173  if (skipClusters) cleanFrom=result.size();
174  range2SeedingHits( *stereoHits, result, accessor.stripTIBLayer(theIdLayer));
175  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
176  }
177  }
178 
179  //
180  // TID
181  //
183  if (hasMatchedHits) {
185  ev.getByToken( theMatchedHits, matchedHits);
186  if (skipClusters) cleanFrom=result.size();
187  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
188  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
189  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
190  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
191  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
192  result.emplace_back(*hit);
193  }
194  }
195  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
196  }
197  if (hasRPhiHits) {
199  ev.getByToken( theRPhiHits, rphiHits);
200  if (skipClusters) cleanFrom=result.size();
201  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
202  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
203  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
204  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
205  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
206  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
207  result.emplace_back(*hit);
208  }
209  }
210  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
211  }
212  if (hasStereoHits) {
214  ev.getByToken( theStereoHits, stereoHits);
215  if (skipClusters) cleanFrom=result.size();
216  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
217  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
218  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
219  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
220  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
221  result.emplace_back(*hit);
222  }
223  }
224  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
225  }
226  }
227  //
228  // TOB
229  //
231  if (hasMatchedHits) {
233  ev.getByToken( theMatchedHits, matchedHits);
234  if (skipClusters) cleanFrom=result.size();
235  if (minAbsZ>0.) {
236  std::pair<DetId,DetIdTOBSameLayerComparator> getter = accessor.stripTOBLayer(theIdLayer);
237  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
238  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
239  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
240  if (fabs(hit->globalPosition().z())>=minAbsZ) result.emplace_back(*hit);
241  }
242  }
243  } else {
244  range2SeedingHits( *matchedHits, result, accessor.stripTOBLayer(theIdLayer));
245  }
246  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
247  }
248  if (hasRPhiHits) {
250  ev.getByToken( theRPhiHits, rphiHits);
251  if (hasMatchedHits){
252  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
253  if (skipClusters) cleanFrom=result.size();
254  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer));
255  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
256  }
257  } else {
258  if (skipClusters) cleanFrom=result.size();
259  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer));
260  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
261  }
262  }
263  if (hasStereoHits) {
265  ev.getByToken( theStereoHits, stereoHits);
266  if (skipClusters) cleanFrom=result.size();
267  range2SeedingHits( *stereoHits, result, accessor.stripTOBLayer(theIdLayer));
268  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
269  }
270  }
271 
272  //
273  // TEC
274  //
276  if (hasMatchedHits) {
278  ev.getByToken( theMatchedHits, matchedHits);
279  if (skipClusters) cleanFrom=result.size();
280  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
281  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
282  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
283  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
284  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
285  result.emplace_back(*hit);
286  }
287  }
288  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,true,cleanFrom);
289  }
290  if (hasRPhiHits) {
292  ev.getByToken( theRPhiHits, rphiHits);
293  if (skipClusters) cleanFrom=result.size();
294  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
295  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
296  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
297  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
298  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
299  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
300  result.emplace_back(*hit);
301  }
302  }
303  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
304 
305  }
306  if (hasStereoHits) {
308  ev.getByToken( theStereoHits, stereoHits);
309  if (skipClusters) cleanFrom=result.size();
310  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
311  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
312  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
313  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
314  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
315  result.emplace_back(*hit);
316  }
317  }
318  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
319  }
320  }
321 
322  LogDebug("HitExtractorSTRP")<<" giving: "<<result.size()<<" out";
323  // std::cout << "HitExtractorSTRP "<<" giving: "<<result.size() << " for charge cut " << minGoodCharge << std::endl;
324  return result;
325 }
326 
327 
#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
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:446
BaseTrackerRecHit const & TkHitRef
Definition: HitExtractor.h:23
OmniClusterRef const & stereoClusterRef() const
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)
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