Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-27 00:42:21

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