Go to the documentation of this file.00001 #include "CommonTools/RecoAlgos/interface/ClusterStorer.h"
00002
00003 #include "FWCore/Utilities/interface/Exception.h"
00004
00005 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00006 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00009 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00011
00012 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSRecHit2D.h"
00013 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2D.h"
00014
00015
00016 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00017
00018 namespace helper {
00019
00020
00021 void ClusterStorer::addCluster(TrackingRecHitCollection &hits, size_t index)
00022 {
00023 TrackingRecHit &newHit = hits[index];
00024 const std::type_info &hit_type = typeid(newHit);
00025 if (hit_type == typeid(SiPixelRecHit)) {
00026
00027 pixelClusterRecords_.push_back(PixelClusterHitRecord(static_cast<SiPixelRecHit&>(newHit),
00028 hits, index));
00029 } else if (hit_type == typeid(SiStripRecHit1D)) {
00030
00031 stripClusterRecords_.push_back(StripClusterHitRecord(static_cast<SiStripRecHit1D&>(newHit),
00032 hits, index));
00033 } else if (hit_type == typeid(SiStripRecHit2D)) {
00034
00035 stripClusterRecords_.push_back(StripClusterHitRecord(static_cast<SiStripRecHit2D&>(newHit),
00036 hits, index));
00037 } else if (hit_type == typeid(SiStripMatchedRecHit2D)) {
00038
00039 SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D&>(newHit);
00040 stripClusterRecords_.push_back(StripClusterHitRecord(*mhit.monoHit(), hits, index));
00041 stripClusterRecords_.push_back(StripClusterHitRecord(*mhit.stereoHit(), hits, index));
00042 } else if (hit_type == typeid(ProjectedSiStripRecHit2D)) {
00043
00044 ProjectedSiStripRecHit2D &phit = static_cast<ProjectedSiStripRecHit2D&>(newHit);
00045 stripClusterRecords_.push_back(StripClusterHitRecord(phit.originalHit(), hits, index));
00046 } else {
00047 if (hit_type == typeid(SiTrackerGSMatchedRecHit2D)
00048 || hit_type == typeid(SiTrackerGSRecHit2D)) {
00049
00050
00051
00052
00053
00054 } else {
00055
00056 throw cms::Exception("UnknownHitType") << "helper::ClusterStorer::addCluster: "
00057 << "Unknown hit type " << hit_type.name()
00058 << ".\n";
00059 }
00060 }
00061
00062 }
00063
00064
00065 void ClusterStorer::clear()
00066 {
00067 pixelClusterRecords_.clear();
00068 stripClusterRecords_.clear();
00069 }
00070
00071
00072 void ClusterStorer::
00073 processAllClusters(edmNew::DetSetVector<SiPixelCluster> &pixelDsvToFill,
00074 edm::RefProd<edmNew::DetSetVector<SiPixelCluster> > refPixelClusters,
00075 edmNew::DetSetVector<SiStripCluster> &stripDsvToFill,
00076 edm::RefProd<edmNew::DetSetVector<SiStripCluster> > refStripClusters)
00077 {
00078 if (!pixelClusterRecords_.empty()) {
00079 this->processClusters<SiPixelRecHit, SiPixelCluster>
00080 (pixelClusterRecords_, pixelDsvToFill, refPixelClusters);
00081 }
00082 if (!stripClusterRecords_.empty()) {
00083
00084
00085
00086
00087
00088 this->processClusters<SiStripRecHit2D, SiStripCluster>
00089 (stripClusterRecords_, stripDsvToFill, refStripClusters);
00090 }
00091 }
00092
00093
00094 template<typename HitType, typename ClusterType>
00095 void ClusterStorer::
00096 processClusters(std::vector<ClusterHitRecord<typename HitType::ClusterRef> > &clusterRecords,
00097 edmNew::DetSetVector<ClusterType> &dsvToFill,
00098 edm::RefProd< edmNew::DetSetVector<ClusterType> > &refprod)
00099 {
00100 std::sort(clusterRecords.begin(), clusterRecords.end());
00101 typedef
00102 typename std::vector<ClusterHitRecord<typename HitType::ClusterRef> >::const_iterator
00103 RIT;
00104 RIT it = clusterRecords.begin(), end = clusterRecords.end();
00105 size_t clusters = 0;
00106 while (it != end) {
00107 RIT it2 = it;
00108 uint32_t detid = it->detid();
00109
00110
00111 while ( (it2 != end) && (it2->detid() == detid)) { ++it2; }
00112
00113
00114
00115 typename edmNew::DetSetVector<ClusterType>::FastFiller filler(dsvToFill, detid);
00116 typename HitType::ClusterRef lastRef, newRef;
00117 for ( ; it != it2; ++it) {
00118
00119 if (it->clusterRef() != lastRef) {
00120 lastRef = it->clusterRef();
00121
00122 filler.push_back( *lastRef );
00123
00124 newRef = typename HitType::ClusterRef( refprod, clusters++ );
00125 }
00126 it->template rekey<HitType>(newRef);
00127 }
00128
00129 }
00130 }
00131
00132
00133
00134
00135
00136 template<typename ClusterRefType>
00137 template<typename RecHitType>
00138 void ClusterStorer::ClusterHitRecord<ClusterRefType>::
00139 rekey(const ClusterRefType &newRef) const
00140 {
00141 TrackingRecHit & genericHit = (*hits_)[index_];
00142 RecHitType *hit = 0;
00143 if (genericHit.geographicalId().rawId() == detid_) {
00144 hit = dynamic_cast<RecHitType *>(&genericHit);
00145 }
00146 assert (hit != 0);
00147 assert (hit->cluster() == ref_);
00148 hit->setClusterRef(newRef);
00149 }
00150
00151
00152
00153
00154 template<>
00155 template<typename RecHitType>
00156 void ClusterStorer::ClusterHitRecord<SiStripRecHit2D::ClusterRef>::
00157
00158 rekey(const SiStripRecHit2D::ClusterRef &newRef) const
00159 {
00160 TrackingRecHit &genericHit = (*hits_)[index_];
00161 const std::type_info &hit_type = typeid(genericHit);
00162
00163 if (typeid(SiStripRecHit1D) == hit_type) {
00164
00165 SiStripRecHit1D *hit = &static_cast<SiStripRecHit1D&>(genericHit);
00166 assert(hit->cluster() == ref_);
00167 hit->setClusterRef(newRef);
00168 } else {
00169
00170 SiStripRecHit2D *hit = 0;
00171 if (typeid(SiStripRecHit2D) == hit_type) {
00172 hit = &static_cast<SiStripRecHit2D&>(genericHit);
00173 } else if (typeid(SiStripMatchedRecHit2D) == hit_type) {
00174 SiStripMatchedRecHit2D &mhit = static_cast<SiStripMatchedRecHit2D&>(genericHit);
00175 hit = (SiStripDetId(detid_).stereo() ? mhit.stereoHit() : mhit.monoHit());
00176 } else if (typeid(ProjectedSiStripRecHit2D) == hit_type) {
00177 ProjectedSiStripRecHit2D &phit = static_cast<ProjectedSiStripRecHit2D&>(genericHit);
00178 hit = &phit.originalHit();
00179 }
00180 assert(hit != 0);
00181 assert(hit->cluster() == ref_);
00182 hit->setClusterRef(newRef);
00183 }
00184
00185 }
00186
00187 }