Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-20 22:40:10

0001 // system include files
0002 #include <memory>
0003 #include <string>
0004 
0005 // user include files
0006 #include "FWCore/Framework/interface/global/EDProducer.h"
0007 
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 
0018 #include "SimDataFormats/Associations/interface/MtdSimLayerClusterToTPAssociator.h"
0019 
0020 #include "FWCore/Utilities/interface/EDGetToken.h"
0021 
0022 //
0023 // class decleration
0024 //
0025 
0026 class MtdSimLayerClusterToTPAssociatorEDProducer : public edm::global::EDProducer<> {
0027 public:
0028   explicit MtdSimLayerClusterToTPAssociatorEDProducer(const edm::ParameterSet &);
0029   ~MtdSimLayerClusterToTPAssociatorEDProducer() override;
0030 
0031   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0032 
0033 private:
0034   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0035 
0036   edm::EDGetTokenT<MtdSimLayerClusterCollection> simClustersToken_;
0037   edm::EDGetTokenT<TrackingParticleCollection> tpToken_;
0038   edm::EDGetTokenT<reco::MtdSimLayerClusterToTPAssociator> associatorToken_;
0039 };
0040 
0041 MtdSimLayerClusterToTPAssociatorEDProducer::MtdSimLayerClusterToTPAssociatorEDProducer(const edm::ParameterSet &pset) {
0042   produces<reco::SimToTPCollectionMtd>();
0043   produces<reco::TPToSimCollectionMtd>();
0044 
0045   simClustersToken_ = consumes<MtdSimLayerClusterCollection>(pset.getParameter<edm::InputTag>("mtdSimClustersTag"));
0046   tpToken_ = consumes<TrackingParticleCollection>(pset.getParameter<edm::InputTag>("trackingParticlesTag"));
0047   associatorToken_ = consumes<reco::MtdSimLayerClusterToTPAssociator>(pset.getParameter<edm::InputTag>("associator"));
0048 }
0049 
0050 MtdSimLayerClusterToTPAssociatorEDProducer::~MtdSimLayerClusterToTPAssociatorEDProducer() {}
0051 
0052 //
0053 // member functions
0054 //
0055 
0056 // ------------ method called to produce the data  ------------
0057 void MtdSimLayerClusterToTPAssociatorEDProducer::produce(edm::StreamID,
0058                                                          edm::Event &iEvent,
0059                                                          const edm::EventSetup &iSetup) const {
0060   using namespace edm;
0061 
0062   edm::Handle<reco::MtdSimLayerClusterToTPAssociator> theAssociator;
0063   iEvent.getByToken(associatorToken_, theAssociator);
0064 
0065   edm::Handle<MtdSimLayerClusterCollection> simClusters;
0066   iEvent.getByToken(simClustersToken_, simClusters);
0067 
0068   edm::Handle<TrackingParticleCollection> trackingParticles;
0069   iEvent.getByToken(tpToken_, trackingParticles);
0070 
0071   reco::SimToTPCollectionMtd simToTPColl = theAssociator->associateSimToTP(simClusters, trackingParticles);
0072   reco::TPToSimCollectionMtd tpToSimColl = theAssociator->associateTPToSim(simClusters, trackingParticles);
0073 
0074   auto s2tp = std::make_unique<reco::SimToTPCollectionMtd>(simToTPColl);
0075   auto tp2s = std::make_unique<reco::TPToSimCollectionMtd>(tpToSimColl);
0076 
0077   iEvent.put(std::move(s2tp));
0078   iEvent.put(std::move(tp2s));
0079 }
0080 
0081 void MtdSimLayerClusterToTPAssociatorEDProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
0082   edm::ParameterSetDescription desc;
0083   desc.add<edm::InputTag>("associator", edm::InputTag("mtdSimLayerClusterToTPAssociatorByTrackId"));
0084   desc.add<edm::InputTag>("mtdSimClustersTag", edm::InputTag("mix", "MergedMtdTruthLC"));
0085   desc.add<edm::InputTag>("trackingParticlesTag", edm::InputTag("mix", "MergedTrackTruth"));
0086 
0087   cfg.add("mtdSimLayerClusterToTPAssociationDefault", desc);
0088 }
0089 
0090 // define this as a plug-in
0091 DEFINE_FWK_MODULE(MtdSimLayerClusterToTPAssociatorEDProducer);