Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-12 22:32:59

0001 //---------------------------------------------------------------------------
0002 //! \class MTDClusterProducer
0003 //!
0004 //! \brief EDProducer to cluster FTLRecHits into FTLClusters.
0005 //!
0006 //---------------------------------------------------------------------------
0007 // Our own stuff
0008 #include "RecoLocalFastTime/FTLClusterizer/interface/MTDThresholdClusterizer.h"
0009 #include "RecoLocalFastTime/FTLClusterizer/interface/MTDClusterizerBase.h"
0010 
0011 // Data Formats
0012 #include "DataFormats/FTLRecHit/interface/FTLRecHit.h"
0013 
0014 // STL
0015 #include <vector>
0016 #include <memory>
0017 #include <string>
0018 #include <iostream>
0019 
0020 // MessageLogger
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   //--- Constructor, virtual destructor (just in case)
0042   explicit MTDClusterProducer(const edm::ParameterSet& conf);
0043   ~MTDClusterProducer() override = default;
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046   //--- The top-level event method.
0047   void produce(edm::Event& e, const edm::EventSetup& c) override;
0048 
0049   //--- Execute the algorithm(s).
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_;  // instance name of barrel clusters
0058   const std::string ftleInstance_;  // instance name of endcap clusters
0059 
0060   const std::string clusterMode_;                    // user's choice of the clusterizer
0061   std::unique_ptr<MTDClusterizerBase> clusterizer_;  // what we got (for now, one ptr to base class)
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 //!  Constructor: set the ParameterSet and defer all thinking to setupClusterizer().
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   //--- Declare to the EDM what kind of collections we will be making.
0079   produces<FTLClusterCollection>(ftlbInstance_);
0080   produces<FTLClusterCollection>(ftleInstance_);
0081 
0082   mtdgeoToken_ = esConsumes<MTDGeometry, MTDDigiGeometryRecord>();
0083   mtdtopoToken_ = esConsumes<MTDTopology, MTDTopologyRcd>();
0084 
0085   //--- Make the algorithm(s) according to what the user specified
0086   //--- in the ParameterSet.
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 // Configuration descriptions
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 //! The "Event" entrypoint: gets called by framework for every event
0111 //---------------------------------------------------------------------------
0112 void MTDClusterProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0113   // Step A.1: get input data
0114   edm::Handle<FTLRecHitCollection> inputBarrel;
0115   edm::Handle<FTLRecHitCollection> inputEndcap;
0116   e.getByToken(btlHits_, inputBarrel);
0117   e.getByToken(etlHits_, inputEndcap);
0118 
0119   // Step A.2: get event setup
0120   auto geom = es.getTransientHandle(mtdgeoToken_);
0121   geom_ = geom.product();
0122 
0123   auto mtdTopo = es.getTransientHandle(mtdtopoToken_);
0124   topo_ = mtdTopo.product();
0125 
0126   // Step B: create the final output collection
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 //!  Iterate over DetUnits, and invoke the PixelClusterizer on each.
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);