Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:17

0001 /** \class MuonTrackFinder
0002  *  Concrete Track finder for the Muon Reco
0003  *
0004  *  \author R. Bellan - INFN Torino
0005  */
0006 
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0013 #include "DataFormats/TrackReco/interface/Track.h"
0014 #include "DataFormats/MuonReco/interface/Muon.h"
0015 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0016 
0017 #include "RecoMuon/TrackingTools/interface/MuonTrackFinder.h"
0018 #include "RecoMuon/TrackingTools/interface/MuonTrajectoryBuilder.h"
0019 #include "RecoMuon/TrackingTools/interface/MuonTrajectoryCleaner.h"
0020 #include "RecoMuon/TrackingTools/interface/MuonTrackLoader.h"
0021 
0022 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0023 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0024 
0025 using namespace std;
0026 using namespace edm;
0027 
0028 // Constructor, with default cleaner. For the STA reconstruction the trackLoader must have the propagator.
0029 MuonTrackFinder::MuonTrackFinder(std::unique_ptr<MuonTrajectoryBuilder> ConcreteMuonTrajectoryBuilder,
0030                                  std::unique_ptr<MuonTrackLoader> trackLoader,
0031                                  edm::ConsumesCollector iC)
0032     : MuonTrackFinder(std::move(ConcreteMuonTrajectoryBuilder),
0033                       std::move(trackLoader),
0034                       std::make_unique<MuonTrajectoryCleaner>(),
0035                       iC) {}
0036 
0037 // Constructor, with user-defined cleaner. For the STA reconstruction the trackLoader must have the propagator.
0038 MuonTrackFinder::MuonTrackFinder(std::unique_ptr<MuonTrajectoryBuilder> ConcreteMuonTrajectoryBuilder,
0039                                  std::unique_ptr<MuonTrackLoader> trackLoader,
0040                                  std::unique_ptr<MuonTrajectoryCleaner> cleaner,
0041                                  edm::ConsumesCollector iC)
0042     : theTtopoToken(iC.esConsumes()),
0043       theTrajBuilder(std::move(ConcreteMuonTrajectoryBuilder)),
0044       theTrajCleaner(std::move(cleaner)),
0045       theTrackLoader(std::move(trackLoader)) {}
0046 
0047 // destructor
0048 MuonTrackFinder::~MuonTrackFinder() {
0049   LogTrace("Muon|RecoMuon|MuonTrackFinder") << "MuonTrackFinder destructor called" << endl;
0050 }
0051 
0052 // percolate the event setup
0053 void MuonTrackFinder::setEvent(const Event& event) { theTrajBuilder->setEvent(event); }
0054 
0055 // convert the trajectories into tracks and load them in to the event
0056 edm::OrphanHandle<reco::TrackCollection> MuonTrackFinder::load(TrajectoryContainer& trajectories,
0057                                                                edm::Event& event,
0058                                                                const TrackerTopology& ttopo) {
0059   return theTrackLoader->loadTracks(trajectories, event, ttopo);
0060 }
0061 
0062 // convert the trajectories into tracks and load them in to the event
0063 void MuonTrackFinder::load(CandidateContainer& muonCands, Event& event, const TrackerTopology& ttopo) {
0064   theTrackLoader->loadTracks(muonCands, event, ttopo);
0065 }
0066 
0067 // reconstruct trajectories
0068 edm::OrphanHandle<reco::TrackCollection> MuonTrackFinder::reconstruct(
0069     const edm::Handle<edm::View<TrajectorySeed> >& seeds, edm::Event& event, const edm::EventSetup& es) {
0070   const string metname = "Muon|RecoMuon|MuonTrackFinder";
0071   LogTrace(metname) << "SA Recostruction starting from: " << seeds->size() << endl;
0072 
0073   // Percolate the event
0074   setEvent(event);
0075 
0076   const auto& ttopo = es.getData(theTtopoToken);
0077 
0078   // Trajectory container
0079   TrajectoryContainer muonTrajectories;
0080   TrajectorySeedCollection::size_type nSeed = 0;
0081   // reconstruct the trajectory
0082   edm::View<TrajectorySeed>::const_iterator seed;
0083   for (seed = seeds->begin(); seed != seeds->end(); ++seed, ++nSeed) {
0084     LogTrace(metname) << "+++ New Seed +++" << endl;
0085     TrajectoryContainer muonTrajs_temp = theTrajBuilder->trajectories(*seed);
0086     for (TrajectoryContainer::iterator it = muonTrajs_temp.begin(); it != muonTrajs_temp.end(); ++it) {
0087       (*it)->setSeedRef(seeds->refAt(nSeed));
0088       muonTrajectories.push_back(std::move(*it));
0089     }
0090   }
0091 
0092   // clean the clone traj
0093   LogTrace(metname) << "Clean the trajectories container" << endl;
0094   if (theTrajCleaner)
0095     theTrajCleaner->clean(muonTrajectories, event, seeds);  //used by reference...
0096 
0097   // convert the trajectories into tracks and load them in to the event
0098   LogTrace(metname) << "Convert the trajectories into tracks and load them in to the event" << endl;
0099   return load(muonTrajectories, event, ttopo);
0100 }
0101 
0102 // reconstruct trajectories
0103 void MuonTrackFinder::reconstruct(const std::vector<TrackCand>& staCandColl, Event& event, const edm::EventSetup& es) {
0104   const string metname = "Muon|RecoMuon|MuonTrackFinder";
0105 
0106   // percolate the event
0107   setEvent(event);
0108 
0109   const auto& ttopo = es.getData(theTtopoToken);
0110 
0111   // Muon Candidate container
0112   CandidateContainer muonCandidates;
0113 
0114   // reconstruct the muon candidates
0115   for (vector<TrackCand>::const_iterator staCand = staCandColl.begin(); staCand != staCandColl.end(); ++staCand) {
0116     CandidateContainer muonCands_temp = theTrajBuilder->trajectories(*staCand);
0117     muonCandidates.insert(muonCandidates.end(),
0118                           std::make_move_iterator(muonCands_temp.begin()),
0119                           std::make_move_iterator(muonCands_temp.end()));
0120   }
0121 
0122   // clean the cloned candidates
0123   if (theTrajCleaner)
0124     theTrajCleaner->clean(muonCandidates);
0125 
0126   // convert the trajectories into staTracks and load them into the event
0127   LogTrace(metname) << "Load Muon Candidates into the event" << endl;
0128   load(muonCandidates, event, ttopo);
0129 }