Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:33:27

0001 #include "FWCore/Framework/interface/ConsumesCollector.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/Frameworkfwd.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/Framework/interface/stream/EDProducer.h"
0006 #include "RecoParticleFlow/PFClusterProducer/interface/InitialClusteringStepBase.h"
0007 #include "RecoParticleFlow/PFClusterProducer/interface/PFCPositionCalculatorBase.h"
0008 #include "RecoParticleFlow/PFClusterProducer/interface/PFClusterBuilderBase.h"
0009 #include "RecoParticleFlow/PFClusterProducer/interface/PFClusterEnergyCorrectorBase.h"
0010 #include "RecoParticleFlow/PFClusterProducer/interface/RecHitTopologicalCleanerBase.h"
0011 #include "RecoParticleFlow/PFClusterProducer/interface/SeedFinderBase.h"
0012 
0013 #include <memory>
0014 
0015 class PFMultiDepthClusterProducer : public edm::stream::EDProducer<> {
0016   typedef InitialClusteringStepBase ICSB;
0017   typedef PFClusterBuilderBase PFCBB;
0018   typedef PFCPositionCalculatorBase PosCalc;
0019 
0020 public:
0021   PFMultiDepthClusterProducer(const edm::ParameterSet&);
0022   ~PFMultiDepthClusterProducer() override = default;
0023 
0024   void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
0025   void produce(edm::Event&, const edm::EventSetup&) override;
0026 
0027 private:
0028   // inputs
0029   edm::EDGetTokenT<reco::PFClusterCollection> _clustersLabel;
0030   // options
0031   // the actual algorithm
0032   std::unique_ptr<PFClusterBuilderBase> _pfClusterBuilder;
0033   std::unique_ptr<PFClusterEnergyCorrectorBase> _energyCorrector;
0034 };
0035 
0036 DEFINE_FWK_MODULE(PFMultiDepthClusterProducer);
0037 
0038 #ifdef PFLOW_DEBUG
0039 #define LOGVERB(x) edm::LogVerbatim(x)
0040 #define LOGWARN(x) edm::LogWarning(x)
0041 #define LOGERR(x) edm::LogError(x)
0042 #define LOGDRESSED(x) edm::LogInfo(x)
0043 #else
0044 #define LOGVERB(x) LogTrace(x)
0045 #define LOGWARN(x) edm::LogWarning(x)
0046 #define LOGERR(x) edm::LogError(x)
0047 #define LOGDRESSED(x) LogDebug(x)
0048 #endif
0049 
0050 PFMultiDepthClusterProducer::PFMultiDepthClusterProducer(const edm::ParameterSet& conf) {
0051   _clustersLabel = consumes<reco::PFClusterCollection>(conf.getParameter<edm::InputTag>("clustersSource"));
0052   const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
0053 
0054   edm::ConsumesCollector&& cc = consumesCollector();
0055   if (!pfcConf.empty()) {
0056     const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
0057     _pfClusterBuilder = PFClusterBuilderFactory::get()->create(pfcName, pfcConf, cc);
0058   }
0059   // see if new need to apply corrections, setup if there.
0060   const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
0061   if (!cConf.empty()) {
0062     const std::string& cName = cConf.getParameter<std::string>("algoName");
0063     _energyCorrector = PFClusterEnergyCorrectorFactory::get()->create(cName, cConf);
0064   }
0065 
0066   produces<reco::PFClusterCollection>();
0067 }
0068 
0069 void PFMultiDepthClusterProducer::beginLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup& es) {
0070   _pfClusterBuilder->update(es);
0071 }
0072 
0073 void PFMultiDepthClusterProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0074   _pfClusterBuilder->reset();
0075 
0076   edm::Handle<reco::PFClusterCollection> inputClusters;
0077   e.getByToken(_clustersLabel, inputClusters);
0078 
0079   std::vector<bool> seedable;
0080 
0081   auto pfClusters = std::make_unique<reco::PFClusterCollection>();
0082   _pfClusterBuilder->buildClusters(*inputClusters, seedable, *pfClusters);
0083   LOGVERB("PFMultiDepthClusterProducer::produce()") << *_pfClusterBuilder;
0084 
0085   if (_energyCorrector) {
0086     _energyCorrector->correctEnergies(*pfClusters);
0087   }
0088   e.put(std::move(pfClusters));
0089 }