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