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 
17 
20 
21 using namespace ctfseeding;
22 using namespace std;
23 using namespace edm;
24 
26  SeedingLayer::Side & side, int idLayer)
27  : theLayer(detLayer), theSide(side), theIdLayer(idLayer),
28  hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
29  hasRingSelector(false), theMinRing(1), theMaxRing(0), hasSimpleRphiHitsCleaner(true)
30 { }
31 
32 void HitExtractorSTRP::useRingSelector(int minRing, int maxRing)
33 {
34  hasRingSelector=true;
35  theMinRing=minRing;
36  theMaxRing=maxRing;
37 }
38 
40 {
41  if (!hasRingSelector) return true;
42  else if ( ring >= theMinRing && ring <= theMaxRing) return true;
43  else return false;
44 }
45 
47  edm::Handle<edmNew::DetSetVector<SiStripClusterRef> > & stripClusterRefs) const {
48  static DetId lastId=hit->geographicalId();
49  static edmNew::DetSetVector<SiStripClusterRef>::const_iterator f=stripClusterRefs->find(lastId.rawId());
50  if (hit->geographicalId()!=lastId){
51  lastId=hit->geographicalId();
52  f=stripClusterRefs->find(lastId.rawId());
53  }
54  if (f==stripClusterRefs->end()) return false;
55  if (!hit->isValid()) return false;
56 
57  bool skipping=(find(f->begin(),f->end(),hit->cluster())!=f->end());
58  //if (skipping) LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hit->geographicalId().rawId()<<" key: "<<hit->cluster().key();
59  return skipping;
60 }
61 
62 
64  const SiStripRecHit2D * hit,
66 
67  if (failProjection) {replaceMe=0; return;}
70  replaceMe=proj.project( *sHit, *ptr->det());
71  if (!replaceMe) LogDebug("HitExtractorSTRP")<<"projection failed.";
72 }
73 
77  const SiStripMatchedRecHit2D * hit = (SiStripMatchedRecHit2D *) ptr->hit();
78 
79  bool rejectSt=false,rejectMono=false;
80  if (skipThis(hit->stereoHit(),stripClusterRefs)) rejectSt=true;
81  if (skipThis(hit->monoHit(),stripClusterRefs)) rejectMono=true;
82 
83  if (rejectSt&&rejectMono){
84  //only skip if both hits are done
85  return true;
86  }
87  else{
88  if (rejectSt) project(ptr,hit->stereoHit(),replaceMe);
89  else if (rejectMono) project(ptr,hit->monoHit(),replaceMe);
90  if (!replaceMe) return true; //means that the projection failed, and needs to be skipped
91  if (rejectSt)
92  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->monoHit()->cluster().key();
93  else if (rejectMono)
94  LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->stereoHit()->cluster().key();
95  return false; //means the projection succeeded or nothing to be masked, no need to skip and replaceMe is going to be used anyways.
96  }
97  return false;
98 }
99 
100 
102  bool matched)const{
103  LogDebug("HitExtractorPIX")<<"getting: "<<hits.size()<<" in input.";
105  ev.getByLabel(theSkipClusters,stripClusterRefs);
106  HitExtractor::Hits newHits;
107  uint skipped=0;
108  uint projected=0;
109  newHits.reserve(hits.size());
111  for (unsigned int iH=0;iH!=hits.size();++iH){
112  replaceMe=hits[iH];
113  if (matched && skipThis(hits[iH],stripClusterRefs,replaceMe)){
114  LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->hit()->geographicalId().rawId();
115  skipped++;
116  continue;
117  }
118  if (!matched && skipThis((SiStripRecHit2D*) hits[iH]->hit(),stripClusterRefs)){
119  LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->hit()->geographicalId().rawId()<<" key: ";
120  skipped++;
121  continue;
122  }
123  if (replaceMe!=hits[iH]) projected++;
124  newHits.push_back(replaceMe);
125  }
126  LogDebug("HitExtractorPIX")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
127  hits.swap(newHits);
128 }
129 
131 {
133  TrackerLayerIdAccessor accessor;
134  theSLayer=&sl;
135  //
136  // TIB
137  //
139  if (hasMatchedHits) {
141  ev.getByLabel( theMatchedHits, matchedHits);
142  range2SeedingHits( *matchedHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
143  if (skipClusters) cleanedOfClusters(ev,result,true);
144  }
145  if (hasRPhiHits) {
147  ev.getByLabel( theRPhiHits, rphiHits);
148  if (hasMatchedHits){
149  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
150  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
151  if (skipClusters) cleanedOfClusters(ev,result,false);
152  }
153  } else {
154  range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
155  if (skipClusters) cleanedOfClusters(ev,result,false);
156  }
157  }
158  if (hasStereoHits) {
160  ev.getByLabel( theStereoHits, stereoHits);
161  range2SeedingHits( *stereoHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
162  if (skipClusters) cleanedOfClusters(ev,result,false);
163  }
164  }
165 
166  //
167  // TID
168  //
170  if (hasMatchedHits) {
172  ev.getByLabel( theMatchedHits, matchedHits);
173  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
174  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
175  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
176  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
177  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
178  result.push_back( sl.hitBuilder()->build(hit) );
179  }
180  }
181  if (skipClusters) cleanedOfClusters(ev,result,true);
182  }
183  if (hasRPhiHits) {
185  ev.getByLabel( theRPhiHits, rphiHits);
186  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
187  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
188  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
189  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
190  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
191  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
192  result.push_back( sl.hitBuilder()->build(hit) );
193  }
194  }
195  if (skipClusters) cleanedOfClusters(ev,result,false);
196  }
197  if (hasStereoHits) {
199  ev.getByLabel( theStereoHits, stereoHits);
200  std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
201  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
202  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
203  int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
204  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
205  result.push_back( sl.hitBuilder()->build(hit) );
206  }
207  }
208  if (skipClusters) cleanedOfClusters(ev,result,false);
209  }
210  }
211  //
212  // TOB
213  //
215  if (hasMatchedHits) {
217  ev.getByLabel( theMatchedHits, matchedHits);
218  range2SeedingHits( *matchedHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
219  if (skipClusters) cleanedOfClusters(ev,result,true);
220  }
221  if (hasRPhiHits) {
223  ev.getByLabel( theRPhiHits, rphiHits);
224  if (hasMatchedHits){
225  if (!hasSimpleRphiHitsCleaner){ // this is a brutal "cleaning". Add something smarter in the future
226  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
227  if (skipClusters) cleanedOfClusters(ev,result,false);
228  }
229  } else {
230  range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
231  if (skipClusters) cleanedOfClusters(ev,result,false);
232  }
233  }
234  if (hasStereoHits) {
236  ev.getByLabel( theStereoHits, stereoHits);
237  range2SeedingHits( *stereoHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
238  if (skipClusters) cleanedOfClusters(ev,result,false);
239  }
240  }
241 
242  //
243  // TEC
244  //
246  if (hasMatchedHits) {
248  ev.getByLabel( theMatchedHits, matchedHits);
249  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
250  SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
251  for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
252  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
253  for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
254  result.push_back( sl.hitBuilder()->build(hit) );
255  }
256  }
257  if (skipClusters) cleanedOfClusters(ev,result,true);
258  }
259  if (hasRPhiHits) {
261  ev.getByLabel( theRPhiHits, rphiHits);
262  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
263  SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
264  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
265  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
266  if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue; // this is a brutal "cleaning". Add something smarter in the future
267  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
268  result.push_back( sl.hitBuilder()->build(hit) );
269  }
270  }
271  if (skipClusters) cleanedOfClusters(ev,result,false);
272 
273  }
274  if (hasStereoHits) {
276  ev.getByLabel( theStereoHits, stereoHits);
277  std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
278  SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
279  for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
280  int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
281  for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
282  result.push_back( sl.hitBuilder()->build(hit) );
283  }
284  }
285  if (skipClusters) cleanedOfClusters(ev,result,false);
286  }
287  }
288  LogDebug("HitExtractorSTRP")<<" giving: "<<result.size()<<" out";
289  return result;
290 }
291 
292 
#define LogDebug(id)
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin() const
HitExtractorSTRP(const DetLayer *detLayer, SeedingLayer::Side &side, int idLayer)
std::pair< DetId, DetIdTIDSameDiskComparator > stripTIDDisk(int side, int disk)
bool ringRange(int ring) const
const SiStripRecHit2D * stereoHit() const
void cleanedOfClusters(const edm::Event &ev, HitExtractor::Hits &hits, bool matched) 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
const_iterator find(id_type i) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
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
bool skipThis(TransientTrackingRecHit::ConstRecHitPointer &ptr, edm::Handle< edmNew::DetSetVector< SiStripClusterRef > > &stripClusterRefs, TransientTrackingRecHit::ConstRecHitPointer &replaceMe) const
std::pair< DetId, DetIdTECSameDiskComparator > stripTECDisk(int side, int disk)
double f[11][100]
#define end
Definition: vmac.h:38
const_iterator end() const
const SeedingLayer * theSLayer
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
void useRingSelector(int minRing, int maxRing)
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:20
const TransientTrackingRecHitBuilder * hitBuilder() const
Definition: SeedingLayer.cc:85
void project(TransientTrackingRecHit::ConstRecHitPointer &ptr, const SiStripRecHit2D *hit, TransientTrackingRecHit::ConstRecHitPointer &replaceMe) const
ClusterRef const & cluster() const
key_type key() const
Accessor for product key.
Definition: Ref.h:265
bool isValid() const
edm::InputTag theSkipClusters
Definition: HitExtractor.h:28
DetId geographicalId() const
const SiStripRecHit2D * monoHit() const
std::vector< TransientTrackingRecHit::ConstRecHitPointer > Hits
Definition: HitExtractor.h:16