Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:00

0001 //
0002 // Original Author:  Stefano Magni
0003 //         Created:  Fri Mar  9 10:52:11 CET 2007
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/ParameterSet/interface/ParameterSet.h"
0018 
0019 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0020 
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0023 
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 
0026 //
0027 // class decleration
0028 //
0029 
0030 class TrackAssociatorEDProducer : public edm::global::EDProducer<> {
0031 public:
0032   explicit TrackAssociatorEDProducer(const edm::ParameterSet &);
0033   ~TrackAssociatorEDProducer() override;
0034 
0035 private:
0036   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0037 
0038   bool theIgnoremissingtrackcollection;
0039 
0040   edm::EDGetTokenT<TrackingParticleCollection> TPCollectionToken_;
0041   edm::EDGetTokenT<edm::View<reco::Track>> trackCollectionToken_;
0042   edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> associatorToken_;
0043 };
0044 
0045 TrackAssociatorEDProducer::TrackAssociatorEDProducer(const edm::ParameterSet &pset)
0046     : theIgnoremissingtrackcollection(pset.getUntrackedParameter<bool>("ignoremissingtrackcollection", false)) {
0047   produces<reco::SimToRecoCollection>();
0048   produces<reco::RecoToSimCollection>();
0049 
0050   TPCollectionToken_ = consumes<TrackingParticleCollection>(pset.getParameter<edm::InputTag>("label_tp"));
0051   trackCollectionToken_ = consumes<edm::View<reco::Track>>(pset.getParameter<edm::InputTag>("label_tr"));
0052   associatorToken_ = consumes<reco::TrackToTrackingParticleAssociator>(pset.getParameter<edm::InputTag>("associator"));
0053 }
0054 
0055 TrackAssociatorEDProducer::~TrackAssociatorEDProducer() {}
0056 
0057 //
0058 // member functions
0059 //
0060 
0061 // ------------ method called to produce the data  ------------
0062 void TrackAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0063   using namespace edm;
0064 
0065   edm::Handle<reco::TrackToTrackingParticleAssociator> theAssociator;
0066   iEvent.getByToken(associatorToken_, theAssociator);
0067 
0068   Handle<TrackingParticleCollection> TPCollection;
0069   iEvent.getByToken(TPCollectionToken_, TPCollection);
0070 
0071   Handle<edm::View<reco::Track>> trackCollection;
0072   bool trackAvailable = iEvent.getByToken(trackCollectionToken_, trackCollection);
0073 
0074   std::unique_ptr<reco::RecoToSimCollection> rts;
0075   std::unique_ptr<reco::SimToRecoCollection> str;
0076 
0077   if (theIgnoremissingtrackcollection && !trackAvailable) {
0078     // the track collection is not in the event and we're being told to ignore
0079     // this. do not output anything to the event, other wise this would be
0080     // considered as inefficiency.
0081   } else {
0082     // associate tracks
0083     LogTrace("TrackValidator") << "Calling associateRecoToSim method"
0084                                << "\n";
0085     reco::RecoToSimCollection recSimColl = theAssociator->associateRecoToSim(trackCollection, TPCollection);
0086 
0087     LogTrace("TrackValidator") << "Calling associateSimToReco method"
0088                                << "\n";
0089     reco::SimToRecoCollection simRecColl = theAssociator->associateSimToReco(trackCollection, TPCollection);
0090 
0091     rts = std::make_unique<reco::RecoToSimCollection>(recSimColl);
0092     str = std::make_unique<reco::SimToRecoCollection>(simRecColl);
0093 
0094     iEvent.put(std::move(rts));
0095     iEvent.put(std::move(str));
0096   }
0097 }
0098 
0099 // define this as a plug-in
0100 DEFINE_FWK_MODULE(TrackAssociatorEDProducer);