File indexing completed on 2024-04-06 12:28:29
0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Utilities/interface/EDGetToken.h"
0006
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/SiPixelCluster/interface/SiPixelClusterShapeCache.h"
0013
0014 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0015 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0016 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0017
0018 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020
0021 #include "RecoTracker/PixelLowPtUtilities/interface/ClusterShape.h"
0022 #include "RecoTracker/PixelLowPtUtilities/interface/ClusterData.h"
0023
0024 #include <cassert>
0025
0026 class SiPixelClusterShapeCacheProducer : public edm::global::EDProducer<> {
0027 public:
0028 explicit SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig);
0029 ~SiPixelClusterShapeCacheProducer() override;
0030
0031 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032
0033 void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0034
0035 private:
0036 using InputCollection = edmNew::DetSetVector<SiPixelCluster>;
0037
0038 const edm::EDGetTokenT<InputCollection> token_;
0039 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0040 };
0041
0042 SiPixelClusterShapeCacheProducer::SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig)
0043 : token_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("src"))), geomToken_(esConsumes()) {
0044 if (iConfig.getParameter<bool>("onDemand")) {
0045 throw cms::Exception("OnDemandNotAllowed")
0046 << "Use of the `onDemand` feature of SiPixelClusterShapeCacheProducer is no longer supported";
0047 }
0048 produces<SiPixelClusterShapeCache>();
0049 }
0050
0051 SiPixelClusterShapeCacheProducer::~SiPixelClusterShapeCacheProducer() {}
0052
0053 void SiPixelClusterShapeCacheProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0054 edm::ParameterSetDescription desc;
0055 desc.add<edm::InputTag>("src", edm::InputTag("siPixelClusters"));
0056 desc.add<bool>("onDemand", false)->setComment("The on demand feature is no longer supported");
0057 descriptions.add("siPixelClusterShapeCache", desc);
0058 }
0059
0060 void SiPixelClusterShapeCacheProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0061 edm::Handle<InputCollection> input;
0062 iEvent.getByToken(token_, input);
0063
0064 if (!input.isValid()) {
0065 edm::LogError("siPixelClusterShapeCache") << "input pixel cluster collection is not valid!";
0066 auto output = std::make_unique<SiPixelClusterShapeCache>();
0067 iEvent.put(std::move(output));
0068 return;
0069 }
0070
0071 const auto& geom = &iSetup.getData(geomToken_);
0072
0073 auto output = std::make_unique<SiPixelClusterShapeCache>(input);
0074 output->resize(input->data().size());
0075
0076 ClusterData data;
0077 ClusterShape clusterShape;
0078
0079 for (const auto& detSet : *input) {
0080 const GeomDetUnit* genericDet = geom->idToDetUnit(detSet.detId());
0081 const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
0082 assert(pixDet);
0083
0084 edmNew::DetSet<SiPixelCluster>::const_iterator iCluster = detSet.begin(), endCluster = detSet.end();
0085 for (; iCluster != endCluster; ++iCluster) {
0086 SiPixelClusterShapeCache::ClusterRef clusterRef = edmNew::makeRefTo(input, iCluster);
0087 if (not output->isFilled(clusterRef)) {
0088 data.size.clear();
0089 clusterShape.determineShape(*pixDet, *iCluster, data);
0090 output->insert(clusterRef, data);
0091 }
0092 }
0093 }
0094 output->shrink_to_fit();
0095
0096 iEvent.put(std::move(output));
0097 }
0098
0099 DEFINE_FWK_MODULE(SiPixelClusterShapeCacheProducer);