Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-20 02:46:36

0001 //
0002 // Package:    RecoTracker/TrackInfoProducer
0003 // Class:      TrackInfoProducer
0004 //
0005 //
0006 // Description: Produce TrackInfo from Trajectory
0007 //
0008 //
0009 // Original Author:  Chiara Genta
0010 //         Created:
0011 //
0012 
0013 // system include files
0014 #include <memory>
0015 
0016 // user include files
0017 #include "AnalysisAlgos/TrackInfoProducer/interface/TrackInfoProducerAlgorithm.h"
0018 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfo.h"
0019 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfoTrackAssociation.h"
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0029 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0030 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0031 
0032 class TrackInfoProducer : public edm::stream::EDProducer<> {
0033 public:
0034   explicit TrackInfoProducer(const edm::ParameterSet& iConfig);
0035 
0036   ~TrackInfoProducer() override{};
0037 
0038   void produce(edm::Event&, const edm::EventSetup&) override;
0039 
0040 private:
0041   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0042   TrackInfoProducerAlgorithm theAlgo_;
0043   edm::EDGetTokenT<std::vector<Trajectory> > TrajectoryToken_;
0044   edm::EDGetTokenT<reco::TrackCollection> trackCollectionToken_;
0045   edm::EDGetTokenT<TrajTrackAssociationCollection> assoMapToken_;
0046   std::string forwardPredictedStateTag_, backwardPredictedStateTag_, updatedStateTag_, combinedStateTag_;
0047 };
0048 
0049 TrackInfoProducer::TrackInfoProducer(const edm::ParameterSet& iConfig)
0050     : tkGeomToken_(esConsumes()),
0051       theAlgo_(iConfig),
0052       TrajectoryToken_(consumes<std::vector<Trajectory> >(iConfig.getParameter<edm::InputTag>("cosmicTracks"))),
0053       trackCollectionToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("cosmicTracks"))),
0054       assoMapToken_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("cosmicTracks"))) {
0055   produces<reco::TrackInfoCollection>();
0056   produces<reco::TrackInfoTrackAssociationCollection>();
0057 }
0058 
0059 void TrackInfoProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0060   //
0061   // create empty output collections
0062   //
0063   std::unique_ptr<reco::TrackInfoCollection> outputColl(new reco::TrackInfoCollection);
0064 
0065   const TrackerGeometry* tracker = &setup.getData(tkGeomToken_);
0066 
0067   edm::Handle<std::vector<Trajectory> > TrajectoryCollection;
0068   edm::Handle<reco::TrackCollection> trackCollection;
0069   edm::Handle<TrajTrackAssociationCollection> assoMap;
0070 
0071   theEvent.getByToken(TrajectoryToken_, TrajectoryCollection);
0072   theEvent.getByToken(trackCollectionToken_, trackCollection);
0073   theEvent.getByToken(assoMapToken_, assoMap);
0074 
0075   //
0076   //run the algorithm
0077   //
0078   reco::TrackInfo output;
0079 
0080   edm::LogInfo("TrackInfoProducer") << "Loop on trajectories";
0081   std::map<reco::TrackRef, unsigned int> trackid;
0082   int i = 0;
0083 
0084   for (TrajTrackAssociationCollection::const_iterator it = assoMap->begin(); it != assoMap->end(); ++it) {
0085     const edm::Ref<std::vector<Trajectory> > traj = it->key;
0086     const reco::TrackRef track = it->val;
0087     trackid.insert(make_pair(track, i));
0088     i++;
0089     theAlgo_.run(traj, track, output, tracker);
0090     outputColl->push_back(output);
0091   }
0092 
0093   //put everything in the event
0094   edm::OrphanHandle<reco::TrackInfoCollection> rTrackInfo;
0095 
0096   //     if(forwardPredictedStateTag_!="") rTrackInfof = theEvent.put(std::move(outputFwdColl),forwardPredictedStateTag_ );
0097   //     if(backwardPredictedStateTag_!="") rTrackInfob =   theEvent.put(std::move(outputBwdColl),backwardPredictedStateTag_);
0098   //     if(updatedStateTag_!="") rTrackInfou =   theEvent.put(std::move(outputUpdatedColl),updatedStateTag_ );
0099   //     if(combinedStateTag_!="") rTrackInfoc =   theEvent.put(std::move(outputCombinedColl),combinedStateTag_ );
0100   rTrackInfo = theEvent.put(std::move(outputColl));
0101   std::unique_ptr<reco::TrackInfoTrackAssociationCollection> TIassociationColl(
0102       new reco::TrackInfoTrackAssociationCollection(assoMap->refProd().val, rTrackInfo));
0103 
0104   for (std::map<reco::TrackRef, unsigned int>::iterator ref_iter = trackid.begin(); ref_iter != trackid.end();
0105        ++ref_iter) {
0106     TIassociationColl->insert(ref_iter->first, edm::Ref<reco::TrackInfoCollection>(rTrackInfo, ref_iter->second));
0107   }
0108 
0109   theEvent.put(std::move(TIassociationColl));
0110 }
0111 
0112 DEFINE_FWK_MODULE(TrackInfoProducer);