Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 23:13:10

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/TracksterToSimTracksterAssociator.h"
0022 
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "DataFormats/HGCalReco/interface/Trackster.h"
0025 
0026 #include "FWCore/Utilities/interface/EDGetToken.h"
0027 
0028 //
0029 // class decleration
0030 //
0031 
0032 class TSToSimTSAssociatorEDProducer : public edm::global::EDProducer<> {
0033 public:
0034   explicit TSToSimTSAssociatorEDProducer(const edm::ParameterSet &);
0035   ~TSToSimTSAssociatorEDProducer() override;
0036 
0037 private:
0038   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0039 
0040   edm::EDGetTokenT<ticl::TracksterCollection> TSCollectionToken_;
0041   edm::EDGetTokenT<ticl::TracksterCollection> SimTSCollectionToken_;
0042   edm::EDGetTokenT<reco::CaloClusterCollection> LCCollectionToken_;
0043   edm::EDGetTokenT<ticl::TracksterToSimTracksterAssociator> associatorToken_;
0044 };
0045 
0046 TSToSimTSAssociatorEDProducer::TSToSimTSAssociatorEDProducer(const edm::ParameterSet &pset) {
0047   produces<ticl::SimToRecoCollectionSimTracksters>("simToReco");
0048   produces<ticl::RecoToSimCollectionSimTracksters>("recoToSim");
0049 
0050   TSCollectionToken_ = consumes<ticl::TracksterCollection>(pset.getParameter<edm::InputTag>("label_tst"));
0051   SimTSCollectionToken_ = consumes<ticl::TracksterCollection>(pset.getParameter<edm::InputTag>("label_simTst"));
0052   LCCollectionToken_ = consumes<reco::CaloClusterCollection>(pset.getParameter<edm::InputTag>("label_lcl"));
0053   associatorToken_ = consumes<ticl::TracksterToSimTracksterAssociator>(pset.getParameter<edm::InputTag>("associator"));
0054 }
0055 
0056 TSToSimTSAssociatorEDProducer::~TSToSimTSAssociatorEDProducer() {}
0057 
0058 //
0059 // member functions
0060 //
0061 
0062 // ------------ method called to produce the data  ------------
0063 void TSToSimTSAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0064   using namespace edm;
0065 
0066   edm::Handle<ticl::TracksterToSimTracksterAssociator> theAssociator;
0067   iEvent.getByToken(associatorToken_, theAssociator);
0068 
0069   Handle<ticl::TracksterCollection> TSCollection;
0070   iEvent.getByToken(TSCollectionToken_, TSCollection);
0071 
0072   Handle<ticl::TracksterCollection> SimTSCollection;
0073   iEvent.getByToken(SimTSCollectionToken_, SimTSCollection);
0074 
0075   Handle<reco::CaloClusterCollection> LCCollection;
0076   iEvent.getByToken(LCCollectionToken_, LCCollection);
0077 
0078   // associate TS and SimTS
0079   LogTrace("AssociatorValidator") << "Calling associateRecoToSim method\n";
0080   ticl::RecoToSimCollectionSimTracksters recSimColl =
0081       theAssociator->associateRecoToSim(TSCollection, LCCollection, SimTSCollection);
0082 
0083   LogTrace("AssociatorValidator") << "Calling associateSimToReco method\n";
0084   ticl::SimToRecoCollectionSimTracksters simRecColl =
0085       theAssociator->associateSimToReco(TSCollection, LCCollection, SimTSCollection);
0086 
0087   auto rts = std::make_unique<ticl::RecoToSimCollectionSimTracksters>(recSimColl);
0088   auto str = std::make_unique<ticl::SimToRecoCollectionSimTracksters>(simRecColl);
0089 
0090   iEvent.put(std::move(rts), "recoToSim");
0091   iEvent.put(std::move(str), "simToReco");
0092 }
0093 
0094 // define this as a plug-in
0095 DEFINE_FWK_MODULE(TSToSimTSAssociatorEDProducer);