File indexing completed on 2023-03-17 11:19:44
0001 #include "DataFormats/Common/interface/DetSetVector.h"
0002 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0003 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0004 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0014 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0015 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0016
0017 #include <vector>
0018 #include <memory>
0019
0020 class SiStripApprox2Clusters : public edm::global::EDProducer<> {
0021 public:
0022 explicit SiStripApprox2Clusters(const edm::ParameterSet& conf);
0023
0024 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0025 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026
0027 private:
0028 edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster>> clusterToken_;
0029 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0030 };
0031
0032 SiStripApprox2Clusters::SiStripApprox2Clusters(const edm::ParameterSet& conf) {
0033 clusterToken_ = consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(
0034 conf.getParameter<edm::InputTag>("inputApproxClusters"));
0035 tkGeomToken_ = esConsumes();
0036 produces<edmNew::DetSetVector<SiStripCluster>>();
0037 }
0038
0039 void SiStripApprox2Clusters::produce(edm::StreamID id, edm::Event& event, const edm::EventSetup& iSetup) const {
0040 auto result = std::make_unique<edmNew::DetSetVector<SiStripCluster>>();
0041 const auto& clusterCollection = event.get(clusterToken_);
0042
0043 const auto& tkGeom = &iSetup.getData(tkGeomToken_);
0044 const auto& tkDets = tkGeom->dets();
0045
0046 for (const auto& detClusters : clusterCollection) {
0047 edmNew::DetSetVector<SiStripCluster>::FastFiller ff{*result, detClusters.id()};
0048 unsigned int detId = detClusters.id();
0049
0050 uint16_t nStrips{0};
0051 auto det = std::find_if(tkDets.begin(), tkDets.end(), [detId](auto& elem) -> bool {
0052 return (elem->geographicalId().rawId() == detId);
0053 });
0054 const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(*det)->specificTopology();
0055 nStrips = p.nstrips() - 1;
0056
0057 for (const auto& cluster : detClusters) {
0058 ff.push_back(SiStripCluster(cluster, nStrips));
0059 }
0060 }
0061
0062 event.put(std::move(result));
0063 }
0064
0065 void SiStripApprox2Clusters::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0066 edm::ParameterSetDescription desc;
0067 desc.add<edm::InputTag>("inputApproxClusters", edm::InputTag("siStripClusters"));
0068 descriptions.add("SiStripApprox2Clusters", desc);
0069 }
0070
0071 DEFINE_FWK_MODULE(SiStripApprox2Clusters);