Go to the documentation of this file.00001 #include "TrackingTools/RoadSearchHitAccess/interface/DetHitAccess.h"
00002
00004 template<typename T>
00005 inline edmNew::DetSet<T> detSetOrEmpty(const edmNew::DetSetVector<T> &dsv, DetId detid) {
00006 typename edmNew::DetSetVector<T>::const_iterator iter = dsv.find(detid.rawId());
00007 if (iter == dsv.end()) {
00008 return typename edmNew::DetSet<T>(detid.rawId(), static_cast<const T *>(0), size_t(0) );
00009 } else {
00010 return *iter;
00011 }
00012 }
00013
00014
00015 DetHitAccess::DetHitAccess() {
00016
00017 accessMode_ = standard;
00018
00019 use_rphiRecHits_ = true;
00020 use_rphiRecHits_ = true;
00021 }
00022
00023 DetHitAccess::~DetHitAccess(){
00024 }
00025
00026 DetHitAccess::DetHitAccess(const SiStripRecHit2DCollection* rphiRecHits,
00027 const SiStripRecHit2DCollection* stereoRecHits,
00028 const SiStripMatchedRecHit2DCollection* matchedRecHits,
00029 const SiPixelRecHitCollection* pixelRecHits) {
00030
00031
00032 accessMode_ = standard;
00033
00034 use_rphiRecHits_ = true;
00035 use_stereoRecHits_ = true;
00036
00037
00038 setCollections(rphiRecHits,stereoRecHits,matchedRecHits,pixelRecHits);
00039
00040 }
00041
00042 void DetHitAccess::setCollections(const SiStripRecHit2DCollection* rphiRecHits,
00043 const SiStripRecHit2DCollection* stereoRecHits,
00044 const SiStripMatchedRecHit2DCollection* matchedRecHits,
00045 const SiPixelRecHitCollection* pixelRecHits) {
00046
00047 rphiHits_ = rphiRecHits;
00048 stereoHits_ = stereoRecHits;
00049 matchedHits_ = matchedRecHits;
00050 pixelHits_ = pixelRecHits;
00051
00052 }
00053
00054
00055 std::vector<TrackingRecHit*> DetHitAccess::getHitVector(const DetId* detid) {
00056
00057
00058
00059
00060 std::vector<TrackingRecHit*> RecHitVec;
00061
00062 if ( (unsigned int)detid->subdetId() == StripSubdetector::TIB
00063 || (unsigned int)detid->subdetId() == StripSubdetector::TOB
00064 || (unsigned int)detid->subdetId() == StripSubdetector::TID
00065 || (unsigned int)detid->subdetId() == StripSubdetector::TEC ) {
00066
00067 StripSubdetector StripDetId(*detid);
00068
00069
00070 if (accessMode_ == rphi ) {
00071
00072
00073
00074 if( !StripDetId.glued() ) {
00075 if ( rphiHits_ != 0 ) {
00076 SiStripRecHit2DCollection::DetSet rphiDetHits = detSetOrEmpty(*rphiHits_, *detid);
00077 for ( SiStripRecHit2DCollection::DetSet::const_iterator rphiDetHit = rphiDetHits.begin();
00078 rphiDetHit != rphiDetHits.end();
00079 ++rphiDetHit ) {
00080 RecHitVec.push_back((TrackingRecHit*)(&(*rphiDetHit)));
00081 }
00082 } else {
00083 edm::LogWarning("RoadSearch") << "rphi RecHit collection not set properly";
00084 }
00085 } else {
00086 if ( matchedHits_ != 0 ) {
00087 DetId useDetId(StripDetId.glued());
00088 SiStripMatchedRecHit2DCollection::DetSet matchedDetHits = detSetOrEmpty(*matchedHits_, useDetId);
00089 for ( SiStripMatchedRecHit2DCollection::DetSet::const_iterator matchedDetHit = matchedDetHits.begin();
00090 matchedDetHit != matchedDetHits.end(); ++matchedDetHit ) {
00091 bool add = true;
00092 TrackingRecHit *rphi = (TrackingRecHit*)matchedDetHit->monoHit();
00093 for ( std::vector<TrackingRecHit*>::iterator hit = RecHitVec.begin();
00094 hit != RecHitVec.end();
00095 ++hit ) {
00096 if ((*hit)->localPosition().x() == rphi->localPosition().x()) {
00097 if ((*hit)->localPosition().y() == rphi->localPosition().y()) {
00098 add = false;
00099 break;
00100 }
00101 }
00102 }
00103 if ( add ) {
00104 RecHitVec.push_back(rphi);
00105 }
00106 }
00107 } else {
00108 edm::LogWarning("RoadSearch") << "matched RecHit collection not set properly";
00109 }
00110 }
00111 } else if (accessMode_ == rphi_stereo ) {
00112
00113
00114
00115 if( !StripDetId.glued() ) {
00116 if ( rphiHits_ != 0 ) {
00117 SiStripRecHit2DCollection::DetSet rphiDetHits = detSetOrEmpty(*rphiHits_, *detid);
00118 for ( SiStripRecHit2DCollection::DetSet::const_iterator rphiDetHit = rphiDetHits.begin();
00119 rphiDetHit != rphiDetHits.end();
00120 ++rphiDetHit ) {
00121 RecHitVec.push_back((TrackingRecHit*)(&(*rphiDetHit)));
00122 }
00123 } else {
00124 edm::LogWarning("RoadSearch") << "rphi RecHit collection not set properly";
00125 }
00126
00127 } else {
00128 DetId rphiDetId(StripDetId.glued()+2);
00129 if ( rphiHits_ != 0 ) {
00130 SiStripRecHit2DCollection::DetSet rphiDetHits = detSetOrEmpty(*rphiHits_, rphiDetId);
00131 for ( SiStripRecHit2DCollection::DetSet::const_iterator rphiDetHit = rphiDetHits.begin();
00132 rphiDetHit != rphiDetHits.end();
00133 ++rphiDetHit ) {
00134 RecHitVec.push_back((TrackingRecHit*)(&(*rphiDetHit)));
00135 }
00136 } else {
00137 edm::LogWarning("RoadSearch") << "rphi RecHit collection not set properly";
00138 }
00139
00140 DetId stereoDetId(StripDetId.glued()+1);
00141 if ( stereoHits_ != 0 ) {
00142 SiStripRecHit2DCollection::DetSet stereoDetHits = detSetOrEmpty(*stereoHits_, stereoDetId);
00143 for ( SiStripRecHit2DCollection::DetSet::const_iterator stereoDetHit = stereoDetHits.begin();
00144 stereoDetHit != stereoDetHits.end();
00145 ++stereoDetHit ) {
00146 RecHitVec.push_back((TrackingRecHit*)(&(*stereoDetHit)));
00147 }
00148 } else {
00149 edm::LogWarning("RoadSearch") << "stereo RecHit collection not set properly";
00150 }
00151 }
00152 } else if (accessMode_ == standard ) {
00153
00154
00155
00156
00157 if( !StripDetId.glued() ) {
00158 if ( rphiHits_ != 0 ) {
00159 SiStripRecHit2DCollection::DetSet rphiDetHits = detSetOrEmpty(*rphiHits_, *detid);
00160 for ( SiStripRecHit2DCollection::DetSet::const_iterator rphiDetHit = rphiDetHits.begin();
00161 rphiDetHit != rphiDetHits.end();
00162 ++rphiDetHit ) {
00163 RecHitVec.push_back((TrackingRecHit*)(&(*rphiDetHit)));
00164 }
00165 } else {
00166 edm::LogWarning("RoadSearch") << "rphi RecHit collection not set properly";
00167 }
00168 } else {
00169 if ( matchedHits_ != 0 ) {
00170 DetId useDetId(StripDetId.glued());
00171 SiStripMatchedRecHit2DCollection::DetSet matchedDetHits = detSetOrEmpty(*matchedHits_, useDetId);
00172 for ( SiStripMatchedRecHit2DCollection::DetSet::const_iterator matchedDetHit = matchedDetHits.begin();
00173 matchedDetHit != matchedDetHits.end(); ++matchedDetHit ) {
00174 RecHitVec.push_back((TrackingRecHit*)(&(*matchedDetHit)));
00175 }
00176 } else {
00177 edm::LogWarning("RoadSearch") << "matched RecHit collection not set properly";
00178 }
00179
00180
00181 if(use_rphiRecHits_) {
00182 DetId rphiDetId(StripDetId.glued()+2);
00183 if ( rphiHits_ != 0 ) {
00184 SiStripRecHit2DCollection::DetSet rphiDetHits = detSetOrEmpty(*rphiHits_, rphiDetId);
00185 for ( SiStripRecHit2DCollection::DetSet::const_iterator rphiDetHit = rphiDetHits.begin();
00186 rphiDetHit != rphiDetHits.end(); ++rphiDetHit ) {
00187 bool use_rphi=true;
00188 DetId useDetId(StripDetId.glued());
00189 SiStripMatchedRecHit2DCollection::DetSet matchedDetHits = detSetOrEmpty(*matchedHits_, useDetId);
00190
00191 for ( SiStripMatchedRecHit2DCollection::DetSet::const_iterator matchedDetHit = matchedDetHits.begin();
00192 matchedDetHit != matchedDetHits.end(); ++matchedDetHit ) {
00193 if (rphiDetHit->localPosition().x()==matchedDetHit->monoHit()->localPosition().x()
00194 && rphiDetHit->localPosition().y()==matchedDetHit->monoHit()->localPosition().y() ) {
00195 use_rphi=false;
00196 break;
00197 }
00198 }
00199 if(use_rphi) RecHitVec.push_back((TrackingRecHit*)(&(*rphiDetHit)));
00200 }
00201 } else {
00202 edm::LogWarning("RoadSearch") << "rphi RecHit collection not set properly";
00203 }
00204 }
00205
00206
00207 if(use_stereoRecHits_) {
00208 DetId stereoDetId(StripDetId.glued()+1);
00209 if ( stereoHits_ != 0 ) {
00210 SiStripRecHit2DCollection::DetSet stereoDetHits = detSetOrEmpty(*stereoHits_, stereoDetId);
00211 for ( SiStripRecHit2DCollection::DetSet::const_iterator stereoDetHit = stereoDetHits.begin();
00212 stereoDetHit != stereoDetHits.end(); ++stereoDetHit ) {
00213 bool use_stereo=true;
00214 DetId useDetId(StripDetId.glued());
00215 SiStripMatchedRecHit2DCollection::DetSet matchedDetHits = detSetOrEmpty(*matchedHits_, useDetId);
00216
00217 for ( SiStripMatchedRecHit2DCollection::DetSet::const_iterator matchedDetHit = matchedDetHits.begin();
00218 matchedDetHit != matchedDetHits.end(); ++matchedDetHit ) {
00219 if (stereoDetHit->localPosition().x()==matchedDetHit->stereoHit()->localPosition().x()
00220 && stereoDetHit->localPosition().y()==matchedDetHit->stereoHit()->localPosition().y() ) {
00221 use_stereo=false;
00222 break;
00223 }
00224 }
00225 if(use_stereo) RecHitVec.push_back((TrackingRecHit*)(&(*stereoDetHit)));
00226 }
00227 } else {
00228 edm::LogWarning("RoadSearch") << "stereo RecHit collection not set properly";
00229 }
00230 }
00231 }
00232 }
00233
00234 } else if ( (unsigned int)detid->subdetId() == PixelSubdetector::PixelBarrel
00235 || (unsigned int)detid->subdetId() == PixelSubdetector::PixelEndcap) {
00236
00237 if ( pixelHits_ != 0 ) {
00238 SiPixelRecHitCollection::DetSet pixelDetHits = detSetOrEmpty(*pixelHits_, *detid);
00239 for ( SiPixelRecHitCollection::DetSet::const_iterator pixelDetHit = pixelDetHits.begin();
00240 pixelDetHit!= pixelDetHits.end(); ++pixelDetHit) {
00241 RecHitVec.push_back((TrackingRecHit*)(&(*pixelDetHit)));
00242 }
00243 } else {
00244 edm::LogWarning("RoadSearch") << "pixel RecHit collection not set properly";
00245 }
00246 } else {
00247
00248 edm::LogError("RoadSearch") << "NEITHER PIXEL NOR STRIP DETECTOR ID";
00249
00250 }
00251
00252
00253 return RecHitVec;
00254 }
00255