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