File indexing completed on 2024-04-06 12:25:56
0001
0002
0003
0004
0005
0006
0007
0008 #include "RecoLocalFastTime/FTLClusterizer/interface/MTDThresholdClusterizer.h"
0009 #include "RecoLocalFastTime/FTLClusterizer/interface/MTDClusterizerBase.h"
0010
0011
0012 #include "DataFormats/FTLRecHit/interface/FTLRecHit.h"
0013
0014
0015 #include <vector>
0016 #include <memory>
0017 #include <string>
0018 #include <iostream>
0019
0020
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
0023 #include "DataFormats/FTLRecHit/interface/FTLRecHitCollections.h"
0024 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0025 #include "Geometry/Records/interface/MTDTopologyRcd.h"
0026 #include "Geometry/CommonTopologies/interface/Topology.h"
0027 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0028 #include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
0029
0030 #include "DataFormats/Common/interface/Handle.h"
0031 #include "FWCore/Framework/interface/stream/EDProducer.h"
0032 #include "FWCore/Framework/interface/Event.h"
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/Framework/interface/ESHandle.h"
0035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0036 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0037 #include "FWCore/Utilities/interface/InputTag.h"
0038
0039 class MTDClusterProducer : public edm::stream::EDProducer<> {
0040 public:
0041
0042 explicit MTDClusterProducer(const edm::ParameterSet& conf);
0043 ~MTDClusterProducer() override = default;
0044 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045
0046
0047 void produce(edm::Event& e, const edm::EventSetup& c) override;
0048
0049
0050 template <typename T>
0051 void run(const T& input, FTLClusterCollection& output);
0052
0053 private:
0054 const edm::EDGetTokenT<FTLRecHitCollection> btlHits_;
0055 const edm::EDGetTokenT<FTLRecHitCollection> etlHits_;
0056
0057 const std::string ftlbInstance_;
0058 const std::string ftleInstance_;
0059
0060 const std::string clusterMode_;
0061 std::unique_ptr<MTDClusterizerBase> clusterizer_;
0062
0063 const MTDGeometry* geom_;
0064 const MTDTopology* topo_;
0065 edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
0066 edm::ESGetToken<MTDTopology, MTDTopologyRcd> mtdtopoToken_;
0067 };
0068
0069
0070
0071
0072 MTDClusterProducer::MTDClusterProducer(edm::ParameterSet const& conf)
0073 : btlHits_(consumes<FTLRecHitCollection>(conf.getParameter<edm::InputTag>("srcBarrel"))),
0074 etlHits_(consumes<FTLRecHitCollection>(conf.getParameter<edm::InputTag>("srcEndcap"))),
0075 ftlbInstance_(conf.getParameter<std::string>("BarrelClusterName")),
0076 ftleInstance_(conf.getParameter<std::string>("EndcapClusterName")),
0077 clusterMode_(conf.getParameter<std::string>("ClusterMode")) {
0078
0079 produces<FTLClusterCollection>(ftlbInstance_);
0080 produces<FTLClusterCollection>(ftleInstance_);
0081
0082 mtdgeoToken_ = esConsumes<MTDGeometry, MTDDigiGeometryRecord>();
0083 mtdtopoToken_ = esConsumes<MTDTopology, MTDTopologyRcd>();
0084
0085
0086
0087 if (clusterMode_ == "MTDThresholdClusterizer") {
0088 clusterizer_ = std::make_unique<MTDThresholdClusterizer>(conf);
0089 } else {
0090 throw cms::Exception("MTDClusterProducer") << "[MTDClusterProducer]:"
0091 << " choice " << clusterMode_ << " is invalid.\n"
0092 << "Possible choices:\n"
0093 << " MTDThresholdClusterizer";
0094 }
0095 }
0096
0097
0098 void MTDClusterProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0099 edm::ParameterSetDescription desc;
0100 desc.add<edm::InputTag>("srcBarrel", edm::InputTag("mtdRecHits:FTLBarrel"));
0101 desc.add<edm::InputTag>("srcEndcap", edm::InputTag("mtdRecHits:FTLEndcap"));
0102 desc.add<std::string>("BarrelClusterName", "FTLBarrel");
0103 desc.add<std::string>("EndcapClusterName", "FTLEndcap");
0104 desc.add<std::string>("ClusterMode", "MTDThresholdClusterizer");
0105 MTDThresholdClusterizer::fillPSetDescription(desc);
0106 descriptions.add("mtdClusterProducer", desc);
0107 }
0108
0109
0110
0111
0112 void MTDClusterProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0113
0114 edm::Handle<FTLRecHitCollection> inputBarrel;
0115 edm::Handle<FTLRecHitCollection> inputEndcap;
0116 e.getByToken(btlHits_, inputBarrel);
0117 e.getByToken(etlHits_, inputEndcap);
0118
0119
0120 auto geom = es.getTransientHandle(mtdgeoToken_);
0121 geom_ = geom.product();
0122
0123 auto mtdTopo = es.getTransientHandle(mtdtopoToken_);
0124 topo_ = mtdTopo.product();
0125
0126
0127 auto outputBarrel = std::make_unique<FTLClusterCollection>();
0128 auto outputEndcap = std::make_unique<FTLClusterCollection>();
0129
0130 if (inputBarrel.isValid())
0131 run(*inputBarrel, *outputBarrel);
0132 else
0133 edm::LogWarning("MTDReco") << "MTDClusterProducer:: Missing Barrel Digis";
0134 if (inputEndcap.isValid())
0135 run(*inputEndcap, *outputEndcap);
0136 else
0137 edm::LogWarning("MTDReco") << "MTDClusterProducer:: Missing Endcap Digis";
0138
0139 e.put(std::move(outputBarrel), ftlbInstance_);
0140 e.put(std::move(outputEndcap), ftleInstance_);
0141 }
0142
0143
0144
0145
0146 template <typename T>
0147 void MTDClusterProducer::run(const T& input, FTLClusterCollection& output) {
0148 if (!clusterizer_) {
0149 throw cms::Exception("MTDClusterProducer") << " at least one clusterizer is not ready -- can't run!";
0150 }
0151
0152 clusterizer_->clusterize(input, geom_, topo_, output);
0153
0154 LogDebug("MTDClusterProducer") << " Executing " << clusterMode_ << " resulted in " << output.size()
0155 << " MTDClusters for " << input.size() << " Hits.";
0156 }
0157
0158 #include "FWCore/PluginManager/interface/ModuleDef.h"
0159 #include "FWCore/Framework/interface/MakerMacros.h"
0160
0161 DEFINE_FWK_MODULE(MTDClusterProducer);