Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:54

0001 /**  \class GlobalMuonProducer
0002  * 
0003  *   Global muon reconstructor:
0004  *   reconstructs muons using DT, CSC, RPC and tracker
0005  *   information,<BR>
0006  *   starting from a standalone reonstructed muon.
0007  *
0008  *
0009  *   \author  R.Bellan - INFN TO
0010  */
0011 
0012 // Framework
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 #include "RecoMuon/GlobalMuonProducer/src/GlobalMuonProducer.h"
0021 
0022 // TrackFinder and specific GLB Trajectory Builder
0023 #include "RecoMuon/GlobalTrackFinder/interface/GlobalMuonTrajectoryBuilder.h"
0024 #include "RecoMuon/TrackingTools/interface/MuonTrackFinder.h"
0025 #include "RecoMuon/TrackingTools/interface/MuonTrackLoader.h"
0026 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0027 
0028 using namespace edm;
0029 using namespace std;
0030 
0031 //
0032 // constructor with config
0033 //
0034 GlobalMuonProducer::GlobalMuonProducer(const ParameterSet& parameterSet) {
0035   LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "constructor called" << endl;
0036 
0037   // Parameter set for the Builder
0038   ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("GLBTrajBuilderParameters");
0039   InputTag trackCollectionTag = parameterSet.getParameter<InputTag>("TrackerCollectionLabel");
0040   trajectoryBuilderParameters.addParameter<InputTag>("TrackerCollectionLabel", trackCollectionTag);
0041   InputTag vertexCollectionTag = parameterSet.getParameter<InputTag>("VertexCollectionLabel");
0042   trajectoryBuilderParameters.addParameter<InputTag>("VertexCollectionLabel", vertexCollectionTag);
0043   bool selectHighPurity_ = parameterSet.getParameter<bool>("selectHighPurity");
0044   trajectoryBuilderParameters.addParameter<bool>("selectHighPurity", selectHighPurity_);
0045 
0046   // STA Muon Collection Label
0047   theSTACollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
0048   staMuonsToken = consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel"));
0049   staMuonsTrajToken =
0050       consumes<std::vector<Trajectory> >(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
0051   staAssoMapToken =
0052       consumes<TrajTrackAssociationCollection>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
0053   updatedStaAssoMapToken =
0054       consumes<reco::TrackToTrackMap>(parameterSet.getParameter<InputTag>("MuonCollectionLabel").label());
0055 
0056   // service parameters
0057   ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
0058 
0059   // TrackLoader parameters
0060   ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
0061 
0062   // the services
0063   theService = new MuonServiceProxy(serviceParameters, consumesCollector());
0064 
0065   // instantiate the concrete trajectory builder in the Track Finder
0066   edm::ConsumesCollector iC = consumesCollector();
0067   auto mtl = std::make_unique<MuonTrackLoader>(trackLoaderParameters, iC, theService);
0068   auto gmtb = std::make_unique<GlobalMuonTrajectoryBuilder>(trajectoryBuilderParameters, theService, iC);
0069 
0070   theTrackFinder = std::make_unique<MuonTrackFinder>(std::move(gmtb), std::move(mtl), iC);
0071 
0072   setAlias(parameterSet.getParameter<std::string>("@module_label"));
0073   produces<reco::TrackCollection>().setBranchAlias(theAlias + "Tracks");
0074   produces<TrackingRecHitCollection>().setBranchAlias(theAlias + "RecHits");
0075   produces<reco::TrackExtraCollection>().setBranchAlias(theAlias + "TrackExtras");
0076   produces<vector<Trajectory> >().setBranchAlias(theAlias + "Trajectories");
0077   produces<TrajTrackAssociationCollection>().setBranchAlias(theAlias + "TrajTrackMap");
0078   produces<reco::MuonTrackLinksCollection>().setBranchAlias(theAlias + "s");
0079 }
0080 
0081 //
0082 // destructor
0083 //
0084 GlobalMuonProducer::~GlobalMuonProducer() {
0085   LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "destructor called" << endl;
0086   if (theService)
0087     delete theService;
0088 }
0089 
0090 //
0091 // reconstruct muons
0092 //
0093 void GlobalMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
0094   const string metname = "Muon|RecoMuon|GlobalMuonProducer";
0095   LogTrace(metname) << endl << endl << endl;
0096   LogTrace(metname) << "Global Muon Reconstruction started" << endl;
0097 
0098   // Update the services
0099   theService->update(eventSetup);
0100 
0101   // Take the STA muon container(s)
0102   Handle<reco::TrackCollection> staMuons;
0103   event.getByToken(staMuonsToken, staMuons);
0104 
0105   Handle<vector<Trajectory> > staMuonsTraj;
0106 
0107   LogTrace(metname) << "Taking " << staMuons->size() << " Stand Alone Muons " << endl;
0108 
0109   vector<MuonTrajectoryBuilder::TrackCand> staTrackCands;
0110 
0111   edm::Handle<TrajTrackAssociationCollection> staAssoMap;
0112 
0113   edm::Handle<reco::TrackToTrackMap> updatedStaAssoMap;
0114 
0115   if (event.getByToken(staMuonsTrajToken, staMuonsTraj) && event.getByToken(staAssoMapToken, staAssoMap) &&
0116       event.getByToken(updatedStaAssoMapToken, updatedStaAssoMap)) {
0117     for (TrajTrackAssociationCollection::const_iterator it = staAssoMap->begin(); it != staAssoMap->end(); ++it) {
0118       const Ref<vector<Trajectory> > traj = it->key;
0119       const reco::TrackRef tkRegular = it->val;
0120       reco::TrackRef tkUpdated;
0121       reco::TrackToTrackMap::const_iterator iEnd;
0122       reco::TrackToTrackMap::const_iterator iii;
0123       if (theSTACollectionLabel.instance() == "UpdatedAtVtx") {
0124         iEnd = updatedStaAssoMap->end();
0125         iii = updatedStaAssoMap->find(it->val);
0126         if (iii != iEnd)
0127           tkUpdated = (*updatedStaAssoMap)[it->val];
0128       }
0129 
0130       int etaFlip1 =
0131           ((tkUpdated.isNonnull() && tkRegular.isNonnull()) && ((tkUpdated->eta() * tkRegular->eta()) < 0)) ? -1 : 1;
0132 
0133       const reco::TrackRef tk = (tkUpdated.isNonnull() && etaFlip1 == 1) ? tkUpdated : tkRegular;
0134 
0135       MuonTrajectoryBuilder::TrackCand tkCand = MuonTrajectoryBuilder::TrackCand((Trajectory*)nullptr, tk);
0136       if (traj->isValid())
0137         tkCand.first = &*traj;
0138       staTrackCands.push_back(tkCand);
0139     }
0140   } else {
0141     for (unsigned int position = 0; position != staMuons->size(); ++position) {
0142       reco::TrackRef staTrackRef(staMuons, position);
0143       MuonTrajectoryBuilder::TrackCand staCand = MuonTrajectoryBuilder::TrackCand((Trajectory*)nullptr, staTrackRef);
0144       staTrackCands.push_back(staCand);
0145     }
0146   }
0147 
0148   theTrackFinder->reconstruct(staTrackCands, event, eventSetup);
0149 
0150   LogTrace(metname) << "Event loaded"
0151                     << "================================" << endl
0152                     << endl;
0153 }