Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:20:16

0001 //
0002 // Original Author:  Leonardo Cristella
0003 //         Created:  Thu Dec  3 10:52:11 CET 2020
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/LayerClusterToSimTracksterAssociator.h"
0022 
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
0025 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0026 
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 
0029 //
0030 // class decleration
0031 //
0032 
0033 class LCToSimTSAssociatorEDProducer : public edm::global::EDProducer<> {
0034 public:
0035   explicit LCToSimTSAssociatorEDProducer(const edm::ParameterSet &);
0036   ~LCToSimTSAssociatorEDProducer() override;
0037 
0038 private:
0039   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0040 
0041   edm::EDGetTokenT<reco::CaloClusterCollection> LCCollectionToken_;
0042   edm::EDGetTokenT<ticl::TracksterCollection> SimTSCollectionToken_;
0043   edm::EDGetTokenT<hgcal::LayerClusterToSimTracksterAssociator> associatorToken_;
0044 
0045   edm::EDGetTokenT<CaloParticleCollection> CPCollectionToken_;
0046   edm::InputTag associatorCP_;
0047   edm::EDGetTokenT<hgcal::RecoToSimCollection> associationMapLCToCPToken_;
0048   edm::EDGetTokenT<hgcal::SimToRecoCollection> associationMapCPToLCToken_;
0049 
0050   edm::EDGetTokenT<SimClusterCollection> SCCollectionToken_;
0051   edm::InputTag associatorSC_;
0052   edm::EDGetTokenT<hgcal::RecoToSimCollectionWithSimClusters> associationMapLCToSCToken_;
0053   edm::EDGetTokenT<hgcal::SimToRecoCollectionWithSimClusters> associationMapSCToLCToken_;
0054 };
0055 
0056 LCToSimTSAssociatorEDProducer::LCToSimTSAssociatorEDProducer(const edm::ParameterSet &pset)
0057     : LCCollectionToken_(consumes<reco::CaloClusterCollection>(pset.getParameter<edm::InputTag>("label_lc"))),
0058       SimTSCollectionToken_(consumes<ticl::TracksterCollection>(pset.getParameter<edm::InputTag>("label_simTst"))),
0059       associatorToken_(
0060           consumes<hgcal::LayerClusterToSimTracksterAssociator>(pset.getParameter<edm::InputTag>("associator"))),
0061       CPCollectionToken_(consumes<CaloParticleCollection>(pset.getParameter<edm::InputTag>("label_cp"))),
0062       associatorCP_(pset.getParameter<edm::InputTag>("associator_cp")),
0063       associationMapLCToCPToken_(consumes<hgcal::RecoToSimCollection>(associatorCP_)),
0064       associationMapCPToLCToken_(consumes<hgcal::SimToRecoCollection>(associatorCP_)),
0065       SCCollectionToken_(consumes<SimClusterCollection>(pset.getParameter<edm::InputTag>("label_scl"))),
0066       associatorSC_(pset.getParameter<edm::InputTag>("associator_sc")),
0067       associationMapLCToSCToken_(consumes<hgcal::RecoToSimCollectionWithSimClusters>(associatorSC_)),
0068       associationMapSCToLCToken_(consumes<hgcal::SimToRecoCollectionWithSimClusters>(associatorSC_)) {
0069   produces<hgcal::SimTracksterToRecoCollection>();
0070   produces<hgcal::RecoToSimTracksterCollection>();
0071 }
0072 
0073 LCToSimTSAssociatorEDProducer::~LCToSimTSAssociatorEDProducer() {}
0074 
0075 //
0076 // member functions
0077 //
0078 
0079 // ------------ method called to produce the data  ------------
0080 void LCToSimTSAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0081   using namespace edm;
0082 
0083   edm::Handle<hgcal::LayerClusterToSimTracksterAssociator> theAssociator;
0084   iEvent.getByToken(associatorToken_, theAssociator);
0085 
0086   Handle<reco::CaloClusterCollection> LCCollection;
0087   iEvent.getByToken(LCCollectionToken_, LCCollection);
0088 
0089   Handle<ticl::TracksterCollection> SimTSCollection;
0090   iEvent.getByToken(SimTSCollectionToken_, SimTSCollection);
0091 
0092   Handle<CaloParticleCollection> CPCollection;
0093   iEvent.getByToken(CPCollectionToken_, CPCollection);
0094   const auto &LCToCPsColl = iEvent.get(associationMapLCToCPToken_);
0095   const auto &CPToLCsColl = iEvent.get(associationMapCPToLCToken_);
0096 
0097   Handle<SimClusterCollection> SCCollection;
0098   iEvent.getByToken(SCCollectionToken_, SCCollection);
0099   const auto &LCToSCsColl = iEvent.get(associationMapLCToSCToken_);
0100   const auto &SCToLCsColl = iEvent.get(associationMapSCToLCToken_);
0101 
0102   // associate LC and SimTS
0103   LogTrace("AssociatorValidator") << "Calling associateRecoToSim method\n";
0104   hgcal::RecoToSimTracksterCollection recSimColl = theAssociator->associateRecoToSim(
0105       LCCollection, SimTSCollection, CPCollection, LCToCPsColl, SCCollection, LCToSCsColl);
0106 
0107   LogTrace("AssociatorValidator") << "Calling associateSimToReco method\n";
0108   hgcal::SimTracksterToRecoCollection simRecColl = theAssociator->associateSimToReco(
0109       LCCollection, SimTSCollection, CPCollection, CPToLCsColl, SCCollection, SCToLCsColl);
0110 
0111   auto rts = std::make_unique<hgcal::RecoToSimTracksterCollection>(recSimColl);
0112   auto str = std::make_unique<hgcal::SimTracksterToRecoCollection>(simRecColl);
0113 
0114   iEvent.put(std::move(rts));
0115   iEvent.put(std::move(str));
0116 }
0117 
0118 // define this as a plug-in
0119 DEFINE_FWK_MODULE(LCToSimTSAssociatorEDProducer);