File indexing completed on 2024-04-06 12:26:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEBase.h"
0045
0046
0047 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0048 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0049 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0050 #include "DataFormats/Common/interface/DetSetVector.h"
0051
0052
0053 #include "FWCore/Framework/interface/stream/EDProducer.h"
0054 #include "FWCore/Framework/interface/Event.h"
0055 #include "FWCore/Framework/interface/EventSetup.h"
0056 #include "FWCore/Framework/interface/MakerMacros.h"
0057 #include "DataFormats/Common/interface/Handle.h"
0058 #include "FWCore/Framework/interface/ESHandle.h"
0059 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0060 #include "FWCore/Utilities/interface/InputTag.h"
0061 #include "FWCore/Utilities/interface/EDPutToken.h"
0062 #include "FWCore/Utilities/interface/ESGetToken.h"
0063
0064
0065 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0066 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0067
0068
0069 #include "DataFormats/DetId/interface/DetId.h"
0070 #include "DataFormats/Common/interface/Ref.h"
0071 #include "DataFormats/Common/interface/DetSet2RangeMap.h"
0072
0073
0074 #include <vector>
0075 #include <memory>
0076 #include <string>
0077 #include <iostream>
0078
0079
0080 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0081
0082 #include "RecoLocalTracker/Records/interface/TkPixelCPERecord.h"
0083
0084
0085 #include "CUDADataFormats/SiPixelCluster/interface/gpuClusteringConstants.h"
0086 #include "CUDADataFormats/Common/interface/HostProduct.h"
0087
0088 using namespace std;
0089
0090 namespace cms {
0091
0092 class SiPixelRecHitConverter : public edm::stream::EDProducer<> {
0093 public:
0094
0095 explicit SiPixelRecHitConverter(const edm::ParameterSet& conf);
0096 ~SiPixelRecHitConverter() override;
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 void produce(edm::Event& e, const edm::EventSetup& c) override;
0108
0109
0110 void run(edm::Event& e,
0111 edm::Handle<SiPixelClusterCollectionNew> inputhandle,
0112 SiPixelRecHitCollectionNew& output,
0113 TrackerGeometry const& geom);
0114
0115 private:
0116 using HMSstorage = HostProduct<uint32_t[]>;
0117
0118
0119 PixelCPEBase const* cpe_ = nullptr;
0120 edm::InputTag const src_;
0121 std::string const cpeName_;
0122 edm::EDGetTokenT<SiPixelClusterCollectionNew> const tPixelCluster_;
0123 edm::EDPutTokenT<SiPixelRecHitCollection> const tPut_;
0124 edm::EDPutTokenT<HMSstorage> const tHost_;
0125 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> const tTrackerGeom_;
0126 edm::ESGetToken<PixelClusterParameterEstimator, TkPixelCPERecord> const tCPE_;
0127 bool m_newCont;
0128 };
0129
0130
0131
0132
0133 SiPixelRecHitConverter::SiPixelRecHitConverter(edm::ParameterSet const& conf)
0134 : src_(conf.getParameter<edm::InputTag>("src")),
0135 cpeName_(conf.getParameter<std::string>("CPE")),
0136 tPixelCluster_(consumes<SiPixelClusterCollectionNew>(src_)),
0137 tPut_(produces<SiPixelRecHitCollection>()),
0138 tHost_(produces<HMSstorage>()),
0139 tTrackerGeom_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
0140 tCPE_(esConsumes<PixelClusterParameterEstimator, TkPixelCPERecord>(edm::ESInputTag("", cpeName_))) {}
0141
0142
0143 SiPixelRecHitConverter::~SiPixelRecHitConverter() {}
0144
0145
0146
0147
0148 void SiPixelRecHitConverter::produce(edm::Event& e, const edm::EventSetup& es) {
0149
0150 edm::Handle<SiPixelClusterCollectionNew> input;
0151 e.getByToken(tPixelCluster_, input);
0152
0153
0154 auto const& geom = es.getData(tTrackerGeom_);
0155
0156
0157 SiPixelRecHitCollectionNew output;
0158
0159
0160 cpe_ = dynamic_cast<const PixelCPEBase*>(&es.getData(tCPE_));
0161
0162
0163
0164
0165 run(e, input, output, geom);
0166
0167 output.shrink_to_fit();
0168 e.emplace(tPut_, std::move(output));
0169 }
0170
0171
0172
0173
0174
0175
0176 void SiPixelRecHitConverter::run(edm::Event& iEvent,
0177 edm::Handle<SiPixelClusterCollectionNew> inputhandle,
0178 SiPixelRecHitCollectionNew& output,
0179 TrackerGeometry const& geom) {
0180 if (!cpe_) {
0181 edm::LogError("SiPixelRecHitConverter") << " at least one CPE is not ready -- can't run!";
0182
0183 assert(0);
0184 return;
0185 }
0186
0187 int numberOfDetUnits = 0;
0188 int numberOfClusters = 0;
0189
0190 const SiPixelClusterCollectionNew& input = *inputhandle;
0191
0192
0193 auto hmsp = std::make_unique<uint32_t[]>(gpuClustering::maxNumModules + 1);
0194
0195 auto hitsModuleStart = hmsp.get();
0196
0197 std::array<uint32_t, gpuClustering::maxNumModules + 1> clusInModule{};
0198 for (auto const& dsv : input) {
0199 unsigned int detid = dsv.detId();
0200 DetId detIdObject(detid);
0201 const GeomDetUnit* genericDet = geom.idToDetUnit(detIdObject);
0202 auto gind = genericDet->index();
0203
0204 if (gind >= int(gpuClustering::maxNumModules))
0205 continue;
0206 auto const nclus = dsv.size();
0207 assert(nclus > 0);
0208 clusInModule[gind] = nclus;
0209 numberOfClusters += nclus;
0210 }
0211 hitsModuleStart[0] = 0;
0212 assert(clusInModule.size() > gpuClustering::maxNumModules);
0213 for (int i = 1, n = clusInModule.size(); i < n; ++i)
0214 hitsModuleStart[i] = hitsModuleStart[i - 1] + clusInModule[i - 1];
0215 assert(numberOfClusters == int(hitsModuleStart[gpuClustering::maxNumModules]));
0216
0217
0218 iEvent.emplace(tHost_, std::move(hmsp));
0219
0220 numberOfClusters = 0;
0221 for (auto const& dsv : input) {
0222 numberOfDetUnits++;
0223 unsigned int detid = dsv.detId();
0224 DetId detIdObject(detid);
0225 const GeomDetUnit* genericDet = geom.idToDetUnit(detIdObject);
0226 const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
0227 assert(pixDet);
0228 SiPixelRecHitCollectionNew::FastFiller recHitsOnDetUnit(output, detid);
0229
0230 edmNew::DetSet<SiPixelCluster>::const_iterator clustIt = dsv.begin(), clustEnd = dsv.end();
0231
0232 for (; clustIt != clustEnd; clustIt++) {
0233 numberOfClusters++;
0234 std::tuple<LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType> tuple =
0235 cpe_->getParameters(*clustIt, *genericDet);
0236 LocalPoint lp(std::get<0>(tuple));
0237 LocalError le(std::get<1>(tuple));
0238 SiPixelRecHitQuality::QualWordType rqw(std::get<2>(tuple));
0239
0240 SiPixelClusterRefNew cluster = edmNew::makeRefTo(inputhandle, clustIt);
0241
0242 SiPixelRecHit hit(lp, le, rqw, *genericDet, cluster);
0243 recHitsOnDetUnit.push_back(hit);
0244
0245 LogDebug("SiPixelRecHitConverter") << "RecHit " << (numberOfClusters - 1)
0246 << " with local position " << lp << " and local error " << le;
0247 }
0248
0249 LogDebug("SiPixelRecHitConverter") << "Found " << recHitsOnDetUnit.size() << " RecHits on " << detid;
0250
0251 }
0252
0253 LogDebug("SiPixelRecHitConverter") << cpeName_ << " converted " << numberOfClusters
0254 << " SiPixelClusters into SiPixelRecHits, in " << numberOfDetUnits
0255 << " DetUnits.";
0256 }
0257 }
0258
0259 using cms::SiPixelRecHitConverter;
0260
0261 DEFINE_FWK_MODULE(SiPixelRecHitConverter);