00001 #include "HitExtractorSTRP.h"
00002 #include "Geometry/TrackerGeometryBuilder/interface/TrackerLayerIdAccessor.h"
00003 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00004
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00011 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00012
00013 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00014 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00015 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00016 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00017
00018 #include "TrackingTools/TransientTrackingRecHit/interface/TrackingRecHitProjector.h"
00019 #include "RecoTracker/TransientTrackingRecHit/interface/ProjectedRecHit2D.h"
00020
00021 using namespace ctfseeding;
00022 using namespace std;
00023 using namespace edm;
00024
00025 HitExtractorSTRP::HitExtractorSTRP( const DetLayer* detLayer,
00026 SeedingLayer::Side & side, int idLayer)
00027 : theLayer(detLayer), theSide(side), theIdLayer(idLayer),
00028 hasMatchedHits(false), hasRPhiHits(false), hasStereoHits(false),
00029 hasRingSelector(false), theMinRing(1), theMaxRing(0), hasSimpleRphiHitsCleaner(true),
00030 lastId_(0)
00031 { }
00032
00033 void HitExtractorSTRP::useRingSelector(int minRing, int maxRing)
00034 {
00035 hasRingSelector=true;
00036 theMinRing=minRing;
00037 theMaxRing=maxRing;
00038 }
00039
00040 bool HitExtractorSTRP::ringRange(int ring) const
00041 {
00042 if (!hasRingSelector) return true;
00043 else if ( ring >= theMinRing && ring <= theMaxRing) return true;
00044 else return false;
00045 }
00046
00047 bool HitExtractorSTRP::skipThis(const SiStripRecHit2D * hit,
00048 edm::Handle<edmNew::DetSetVector<SiStripClusterRef> > & stripClusterRefs) const {
00049 if (hit->geographicalId()!=lastId_){
00050 lastId_=hit->geographicalId();
00051 f_=stripClusterRefs->find(lastId_.rawId());
00052 }
00053 if (f_==stripClusterRefs->end()) return false;
00054 if (!hit->isValid()) return false;
00055
00056 bool skipping=(find(f_->begin(),f_->end(),hit->cluster())!=f_->end());
00057
00058 return skipping;
00059 }
00060
00061
00062 void HitExtractorSTRP::project(TransientTrackingRecHit::ConstRecHitPointer & ptr,
00063 const SiStripRecHit2D * hit,
00064 TransientTrackingRecHit::ConstRecHitPointer & replaceMe) const{
00065
00066 if (failProjection) {replaceMe=0; return;}
00067 TrackingRecHitProjector<ProjectedRecHit2D> proj;
00068 TransientTrackingRecHit::RecHitPointer sHit=theSLayer->hitBuilder()->build(hit);
00069 replaceMe=proj.project( *sHit, *ptr->det());
00070 if (!replaceMe) LogDebug("HitExtractorSTRP")<<"projection failed.";
00071 }
00072
00073 bool HitExtractorSTRP::skipThis(TransientTrackingRecHit::ConstRecHitPointer & ptr,
00074 edm::Handle<edmNew::DetSetVector<SiStripClusterRef> > & stripClusterRefs,
00075 TransientTrackingRecHit::ConstRecHitPointer & replaceMe) const {
00076 const SiStripMatchedRecHit2D * hit = (SiStripMatchedRecHit2D *) ptr->hit();
00077
00078 bool rejectSt=false,rejectMono=false;
00079 if (skipThis(hit->stereoHit(),stripClusterRefs)) rejectSt=true;
00080 if (skipThis(hit->monoHit(),stripClusterRefs)) rejectMono=true;
00081
00082 if (rejectSt&&rejectMono){
00083
00084 return true;
00085 }
00086 else{
00087 if (rejectSt) project(ptr,hit->stereoHit(),replaceMe);
00088 else if (rejectMono) project(ptr,hit->monoHit(),replaceMe);
00089 if (!replaceMe) return true;
00090 if (rejectSt)
00091 LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the mono hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->monoHit()->cluster().key();
00092 else if (rejectMono)
00093 LogDebug("HitExtractorSTRP")<<"a matched hit is partially masked, and the stereo hit got projected onto: "<<replaceMe->hit()->geographicalId().rawId()<<" key: "<<hit->stereoHit()->cluster().key();
00094 return false;
00095 }
00096 return false;
00097 }
00098
00099
00100 void HitExtractorSTRP::cleanedOfClusters( const edm::Event& ev, HitExtractor::Hits & hits,
00101 bool matched,
00102 unsigned int cleanFrom)const{
00103 LogDebug("HitExtractorPIX")<<"getting: "<<hits.size()<<" in input.";
00104 edm::Handle<edmNew::DetSetVector<SiStripClusterRef> > stripClusterRefs;
00105 ev.getByLabel(theSkipClusters,stripClusterRefs);
00106 lastId_=0;
00107 f_=stripClusterRefs->end();
00108 HitExtractor::Hits newHits;
00109 unsigned int skipped=0;
00110 unsigned int projected=0;
00111 newHits.reserve(hits.size());
00112 TransientTrackingRecHit::ConstRecHitPointer replaceMe;
00113 for (unsigned int iH=cleanFrom;iH<hits.size();++iH){
00114 replaceMe=hits[iH];
00115 if (matched && skipThis(hits[iH],stripClusterRefs,replaceMe)){
00116 LogDebug("HitExtractorSTRP")<<"skipping a matched hit on :"<<hits[iH]->hit()->geographicalId().rawId();
00117 skipped++;
00118 continue;
00119 }
00120 if (!matched && skipThis((const SiStripRecHit2D*) hits[iH]->hit(),stripClusterRefs)){
00121 LogDebug("HitExtractorSTRP")<<"skipping a hit on :"<<hits[iH]->hit()->geographicalId().rawId()<<" key: ";
00122 skipped++;
00123 continue;
00124 }
00125 if (replaceMe!=hits[iH]) projected++;
00126 newHits.push_back(replaceMe);
00127 }
00128 LogDebug("HitExtractorPIX")<<"skipped :"<<skipped<<" strip rechits because of clusters and projected: "<<projected;
00129 hits.swap(newHits);
00130 }
00131
00132 HitExtractor::Hits HitExtractorSTRP::hits(const SeedingLayer & sl, const edm::Event& ev, const edm::EventSetup& es) const
00133 {
00134 HitExtractor::Hits result;
00135 TrackerLayerIdAccessor accessor;
00136 theSLayer=&sl;
00137 unsigned int cleanFrom=0;
00138
00139
00140
00141 if (theLayer->subDetector() == GeomDetEnumerators::TIB) {
00142 if (hasMatchedHits) {
00143 edm::Handle<SiStripMatchedRecHit2DCollection> matchedHits;
00144 ev.getByLabel( theMatchedHits, matchedHits);
00145 if (skipClusters) cleanFrom=result.size();
00146 range2SeedingHits( *matchedHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
00147 if (skipClusters) cleanedOfClusters(ev,result,true,cleanFrom);
00148 }
00149 if (hasRPhiHits) {
00150 edm::Handle<SiStripRecHit2DCollection> rphiHits;
00151 ev.getByLabel( theRPhiHits, rphiHits);
00152 if (hasMatchedHits){
00153 if (!hasSimpleRphiHitsCleaner){
00154 if (skipClusters) cleanFrom=result.size();
00155 range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
00156 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00157 }
00158 } else {
00159 if (skipClusters) cleanFrom=result.size();
00160 range2SeedingHits( *rphiHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
00161 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00162 }
00163 }
00164 if (hasStereoHits) {
00165 edm::Handle<SiStripRecHit2DCollection> stereoHits;
00166 ev.getByLabel( theStereoHits, stereoHits);
00167 if (skipClusters) cleanFrom=result.size();
00168 range2SeedingHits( *stereoHits, result, accessor.stripTIBLayer(theIdLayer), sl, es);
00169 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00170 }
00171 }
00172
00173
00174
00175
00176 else if (theLayer->subDetector() == GeomDetEnumerators::TID) {
00177 if (hasMatchedHits) {
00178 edm::Handle<SiStripMatchedRecHit2DCollection> matchedHits;
00179 ev.getByLabel( theMatchedHits, matchedHits);
00180 if (skipClusters) cleanFrom=result.size();
00181 std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
00182 SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
00183 for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00184 int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00185 for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00186 result.push_back( sl.hitBuilder()->build(hit) );
00187 }
00188 }
00189 if (skipClusters) cleanedOfClusters(ev,result,true,cleanFrom);
00190 }
00191 if (hasRPhiHits) {
00192 edm::Handle<SiStripRecHit2DCollection> rphiHits;
00193 ev.getByLabel( theRPhiHits, rphiHits);
00194 if (skipClusters) cleanFrom=result.size();
00195 std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
00196 SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
00197 for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00198 int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00199 if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue;
00200 for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00201 result.push_back( sl.hitBuilder()->build(hit) );
00202 }
00203 }
00204 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00205 }
00206 if (hasStereoHits) {
00207 edm::Handle<SiStripRecHit2DCollection> stereoHits;
00208 ev.getByLabel( theStereoHits, stereoHits);
00209 if (skipClusters) cleanFrom=result.size();
00210 std::pair<DetId,DetIdTIDSameDiskComparator> getter = accessor.stripTIDDisk(theSide,theIdLayer);
00211 SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
00212 for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00213 int ring = TIDDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00214 for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00215 result.push_back( sl.hitBuilder()->build(hit) );
00216 }
00217 }
00218 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00219 }
00220 }
00221
00222
00223
00224 else if (theLayer->subDetector() == GeomDetEnumerators::TOB) {
00225 if (hasMatchedHits) {
00226 edm::Handle<SiStripMatchedRecHit2DCollection> matchedHits;
00227 ev.getByLabel( theMatchedHits, matchedHits);
00228 if (skipClusters) cleanFrom=result.size();
00229 range2SeedingHits( *matchedHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
00230 if (skipClusters) cleanedOfClusters(ev,result,true,cleanFrom);
00231 }
00232 if (hasRPhiHits) {
00233 edm::Handle<SiStripRecHit2DCollection> rphiHits;
00234 ev.getByLabel( theRPhiHits, rphiHits);
00235 if (hasMatchedHits){
00236 if (!hasSimpleRphiHitsCleaner){
00237 if (skipClusters) cleanFrom=result.size();
00238 range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
00239 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00240 }
00241 } else {
00242 if (skipClusters) cleanFrom=result.size();
00243 range2SeedingHits( *rphiHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
00244 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00245 }
00246 }
00247 if (hasStereoHits) {
00248 edm::Handle<SiStripRecHit2DCollection> stereoHits;
00249 ev.getByLabel( theStereoHits, stereoHits);
00250 if (skipClusters) cleanFrom=result.size();
00251 range2SeedingHits( *stereoHits, result, accessor.stripTOBLayer(theIdLayer), sl, es);
00252 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00253 }
00254 }
00255
00256
00257
00258
00259 else if (theLayer->subDetector() == GeomDetEnumerators::TEC) {
00260 if (hasMatchedHits) {
00261 edm::Handle<SiStripMatchedRecHit2DCollection> matchedHits;
00262 ev.getByLabel( theMatchedHits, matchedHits);
00263 if (skipClusters) cleanFrom=result.size();
00264 std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
00265 SiStripMatchedRecHit2DCollection::Range range = matchedHits->equal_range(getter.first, getter.second);
00266 for (SiStripMatchedRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00267 int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00268 for (SiStripMatchedRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00269 result.push_back( sl.hitBuilder()->build(hit) );
00270 }
00271 }
00272 if (skipClusters) cleanedOfClusters(ev,result,true,cleanFrom);
00273 }
00274 if (hasRPhiHits) {
00275 edm::Handle<SiStripRecHit2DCollection> rphiHits;
00276 ev.getByLabel( theRPhiHits, rphiHits);
00277 if (skipClusters) cleanFrom=result.size();
00278 std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
00279 SiStripRecHit2DCollection::Range range = rphiHits->equal_range(getter.first, getter.second);
00280 for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00281 int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00282 if ((SiStripDetId(it->detId()).partnerDetId() != 0) && hasSimpleRphiHitsCleaner) continue;
00283 for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00284 result.push_back( sl.hitBuilder()->build(hit) );
00285 }
00286 }
00287 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00288
00289 }
00290 if (hasStereoHits) {
00291 edm::Handle<SiStripRecHit2DCollection> stereoHits;
00292 ev.getByLabel( theStereoHits, stereoHits);
00293 if (skipClusters) cleanFrom=result.size();
00294 std::pair<DetId,DetIdTECSameDiskComparator> getter = accessor.stripTECDisk(theSide,theIdLayer);
00295 SiStripRecHit2DCollection::Range range = stereoHits->equal_range(getter.first, getter.second);
00296 for (SiStripRecHit2DCollection::const_iterator it = range.first; it != range.second; ++it) {
00297 int ring = TECDetId( it->detId() ).ring(); if (!ringRange(ring)) continue;
00298 for (SiStripRecHit2DCollection::DetSet::const_iterator hit = it->begin(), end = it->end(); hit != end; ++hit) {
00299 result.push_back( sl.hitBuilder()->build(hit) );
00300 }
00301 }
00302 if (skipClusters) cleanedOfClusters(ev,result,false,cleanFrom);
00303 }
00304 }
00305 LogDebug("HitExtractorSTRP")<<" giving: "<<result.size()<<" out";
00306 return result;
00307 }
00308
00309