Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:36

0001 //
0002 // Original Author:  Leonardo Cristella
0003 //         Created:  Tue Feb  2 10:52:11 CET 2021
0004 //
0005 //
0006 
0007 // system include files
0008 #include <memory>
0009 #include <string>
0010 
0011 // user include files
0012 #include "FWCore/Framework/interface/global/EDProducer.h"
0013 
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 
0021 #include "SimDataFormats/Associations/interface/MultiClusterToCaloParticleAssociator.h"
0022 
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
0025 #include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h"
0026 
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 
0029 //
0030 // class decleration
0031 //
0032 
0033 class MCToCPAssociatorEDProducer : public edm::global::EDProducer<> {
0034 public:
0035   explicit MCToCPAssociatorEDProducer(const edm::ParameterSet &);
0036   ~MCToCPAssociatorEDProducer() override;
0037 
0038 private:
0039   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0040 
0041   edm::EDGetTokenT<CaloParticleCollection> CPCollectionToken_;
0042   edm::EDGetTokenT<reco::HGCalMultiClusterCollection> MCCollectionToken_;
0043   edm::EDGetTokenT<hgcal::MultiClusterToCaloParticleAssociator> associatorToken_;
0044 };
0045 
0046 MCToCPAssociatorEDProducer::MCToCPAssociatorEDProducer(const edm::ParameterSet &pset) {
0047   produces<hgcal::SimToRecoCollectionWithMultiClusters>();
0048   produces<hgcal::RecoToSimCollectionWithMultiClusters>();
0049 
0050   CPCollectionToken_ = consumes<CaloParticleCollection>(pset.getParameter<edm::InputTag>("label_cp"));
0051   MCCollectionToken_ = consumes<reco::HGCalMultiClusterCollection>(pset.getParameter<edm::InputTag>("label_mcl"));
0052   associatorToken_ =
0053       consumes<hgcal::MultiClusterToCaloParticleAssociator>(pset.getParameter<edm::InputTag>("associator"));
0054 }
0055 
0056 MCToCPAssociatorEDProducer::~MCToCPAssociatorEDProducer() {}
0057 
0058 //
0059 // member functions
0060 //
0061 
0062 // ------------ method called to produce the data  ------------
0063 void MCToCPAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0064   using namespace edm;
0065 
0066   edm::Handle<hgcal::MultiClusterToCaloParticleAssociator> theAssociator;
0067   iEvent.getByToken(associatorToken_, theAssociator);
0068 
0069   Handle<CaloParticleCollection> CPCollection;
0070   iEvent.getByToken(CPCollectionToken_, CPCollection);
0071 
0072   Handle<reco::HGCalMultiClusterCollection> MCCollection;
0073   iEvent.getByToken(MCCollectionToken_, MCCollection);
0074 
0075   // associate MutiCluster and CP
0076   LogTrace("AssociatorValidator") << "Calling associateRecoToSim method"
0077                                   << "\n";
0078   hgcal::RecoToSimCollectionWithMultiClusters recSimColl =
0079       theAssociator->associateRecoToSim(MCCollection, CPCollection);
0080 
0081   LogTrace("AssociatorValidator") << "Calling associateSimToReco method"
0082                                   << "\n";
0083   hgcal::SimToRecoCollectionWithMultiClusters simRecColl =
0084       theAssociator->associateSimToReco(MCCollection, CPCollection);
0085 
0086   auto rts = std::make_unique<hgcal::RecoToSimCollectionWithMultiClusters>(recSimColl);
0087   auto str = std::make_unique<hgcal::SimToRecoCollectionWithMultiClusters>(simRecColl);
0088 
0089   iEvent.put(std::move(rts));
0090   iEvent.put(std::move(str));
0091 }
0092 
0093 // define this as a plug-in
0094 DEFINE_FWK_MODULE(MCToCPAssociatorEDProducer);