test
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"
5 
8 
11 
13 
20 
21 #include<tuple>
22 
23 #include<iostream>
24 
25 using namespace ctfseeding;
26 using namespace std;
27 using namespace edm;
28 
30  theLayerSubDet(subdet), theSide(side), theIdLayer(idLayer),
31  minAbsZ(0), theMinRing(1), theMaxRing(0),
32  hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
33  hasRingSelector(false), hasSimpleRphiHitsCleaner(true)
34 { minGoodCharge=iminGoodCharge; if (minGoodCharge>0) skipClusters=true; }
35 
38 }
39 
41 {
42  hasRingSelector=true;
45 }
46 
48 {
49  if (!hasRingSelector) return true;
50  return (ring >= theMinRing) & (ring <= theMaxRing);
51 }
52 
55 
56  if (maskCluster && (stripClusterMask->mask(clus.key())) ) return true;
57 
58  if unlikely(minGoodCharge<=0) return false;
60 }
61 
62 
63 
64 std::pair<bool,ProjectedSiStripRecHit2D *>
66  TkHitRef matched,
68  const SiStripMatchedRecHit2D & hit = (SiStripMatchedRecHit2D const&)(matched);
69 
70  assert(dynamic_cast<SiStripMatchedRecHit2D const*>(&matched));
71 
72  auto id = hit.geographicalId();
73  ProjectedSiStripRecHit2D * replaceMe = nullptr;
74  bool rejectSt = skipThis(id,hit.stereoClusterRef(), stripClusterMask);
75  bool rejectMono = skipThis(id, hit.monoClusterRef(), stripClusterMask);
76 
77  if ((!rejectSt)&(!rejectMono)){
78  // keepit
79  return std::make_pair(false,replaceMe);
80  }
81 
82  if (failProjection || (rejectSt&rejectMono) ){
83  //only skip if both hits are done
84  return std::make_pair(true,replaceMe);
85  }
86 
87  // replace with one
88 
89  auto cloner = ttrhBuilder.cloner();
90  replaceMe = cloner.project(hit, rejectSt, TrajectoryStateOnSurface()).release();
91  if (rejectSt)
92  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.monoClusterRef().key();
93  else
94  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->geographicalId().rawId()<<" key: "<<hit.stereoClusterRef().key();
95 
96  return std::make_pair(true,replaceMe);
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  if (maskCluster) ev.getByToken(theSkipClusters,stripClusterMask);
107  unsigned int skipped=0;
108  unsigned int projected=0;
109  for (unsigned int iH=cleanFrom;iH<hits.size();++iH){
110  assert(hits[iH]->isValid());
111  auto id = hits[iH]->geographicalId();
112  if (matched) {
113  bool replace; ProjectedSiStripRecHit2D * replaceMe; std::tie(replace,replaceMe) = skipThis(ttrhBuilder, *hits[iH],stripClusterMask);
114  if (replace) {
115  if (!replaceMe) {
116  LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->geographicalId().rawId();
117  skipped++;
118  } else projected++;
119  hits[iH].reset(replaceMe);
120  if (replaceMe==nullptr) assert(hits[iH].empty());
121  else assert(hits[iH].isOwn());
122  }
123  }
124  else if (skipThis(id, hits[iH]->firstClusterRef(),stripClusterMask)){
125  LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->geographicalId().rawId()<<" key: ";
126  skipped++;
127  hits[iH].reset();
128  }
129  }
130  // remove empty elements...
131  auto last = std::remove_if(hits.begin()+cleanFrom,hits.end(),[]( HitPointer const & p) {return p.empty();});
132  hits.resize(last-hits.begin());
133 
134  // std::cout << "HitExtractorSTRP " <<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected << std::endl;
135  LogDebug("HitExtractorSTRP")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
136 }
137 
139 {
141  unsigned int cleanFrom=0;
142 
143  //Retrieve tracker topology from geometry
144  edm::ESHandle<TrackerTopology> tTopoHandle;
145  es.get<TrackerTopologyRcd>().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, tTopo->tibDetIdLayerComparator(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, tTopo->tibDetIdLayerComparator(theIdLayer));
166  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
167  }
168  } else {
169  if (skipClusters) cleanFrom=result.size();
170  range2SeedingHits( *rphiHits, result, tTopo->tibDetIdLayerComparator(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, tTopo->tibDetIdLayerComparator(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  auto getter = tTopo->tidDetIdWheelComparator(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  auto getter = tTopo->tidDetIdWheelComparator(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  auto getter = tTopo->tidDetIdWheelComparator(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  auto getter = tTopo->tobDetIdLayerComparator(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, tTopo->tobDetIdLayerComparator(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, tTopo->tobDetIdLayerComparator(theIdLayer));
259  if (skipClusters) cleanedOfClusters(ttrhBuilder, ev,result,false,cleanFrom);
260  }
261  } else {
262  if (skipClusters) cleanFrom=result.size();
263  range2SeedingHits( *rphiHits, result, tTopo->tobDetIdLayerComparator(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, tTopo->tobDetIdLayerComparator(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  auto getter = tTopo->tecDetIdWheelComparator(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  auto getter = tTopo->tecDetIdWheelComparator(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  auto getter = tTopo->tecDetIdWheelComparator(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::vector< HitPointer > Hits
Definition: HitExtractor.h:25
bool ringRange(int ring) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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)
bool ev
std::pair< const_iterator, const_iterator > Range
std::pair< DetId, SameLayerComparator > tidDetIdWheelComparator(uint32_t side, uint32_t wheel) const
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > theMatchedHits
tuple result
Definition: mps_fire.py:84
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, SameLayerComparator > tobDetIdLayerComparator(uint32_t layer) const
const GeomDetEnumerators::SubDetector theLayerSubDet
edm::EDGetTokenT< SiStripRecHit2DCollection > theStereoHits
std::pair< DetId, SameLayerComparator > tibDetIdLayerComparator(uint32_t layer) const
ClusterStripRef cluster_strip() const
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
std::pair< DetId, SameLayerComparator > tecDetIdWheelComparator(uint32_t side, uint32_t wheel) 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:56
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