Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-17 02:46:04

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 "RecoPixelVertexing/PixelLowPtUtilities/interface/ClusterShape.h"
0022 #include "RecoPixelVertexing/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   const auto& geom = &iSetup.getData(geomToken_);
0065 
0066   auto output = std::make_unique<SiPixelClusterShapeCache>(input);
0067   output->resize(input->data().size());
0068 
0069   ClusterData data;  // reused
0070   ClusterShape clusterShape;
0071 
0072   for (const auto& detSet : *input) {
0073     const GeomDetUnit* genericDet = geom->idToDetUnit(detSet.detId());
0074     const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
0075     assert(pixDet);
0076 
0077     edmNew::DetSet<SiPixelCluster>::const_iterator iCluster = detSet.begin(), endCluster = detSet.end();
0078     for (; iCluster != endCluster; ++iCluster) {
0079       SiPixelClusterShapeCache::ClusterRef clusterRef = edmNew::makeRefTo(input, iCluster);
0080       if (not output->isFilled(clusterRef)) {
0081         data.size.clear();
0082         clusterShape.determineShape(*pixDet, *iCluster, data);
0083         output->insert(clusterRef, data);
0084       }
0085     }
0086   }
0087   output->shrink_to_fit();
0088 
0089   iEvent.put(std::move(output));
0090 }
0091 
0092 DEFINE_FWK_MODULE(SiPixelClusterShapeCacheProducer);