Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:42:22

0001 /**  \class TevMuonProducer
0002  * 
0003  *   TeV muon reconstructor:
0004  *
0005  *
0006  *
0007  *   \author  Piotr Traczyk (SINS Warsaw)
0008  */
0009 
0010 // Framework
0011 #include "FWCore/Framework/interface/ConsumesCollector.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "DataFormats/Common/interface/Handle.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0018 
0019 #include "RecoMuon/GlobalMuonProducer/src/TevMuonProducer.h"
0020 
0021 // TrackFinder and specific GLB Trajectory Builder
0022 #include "RecoMuon/GlobalTrackFinder/interface/GlobalMuonTrajectoryBuilder.h"
0023 #include "RecoMuon/TrackingTools/interface/MuonTrackFinder.h"
0024 #include "RecoMuon/TrackingTools/interface/MuonTrackLoader.h"
0025 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0026 #include "RecoMuon/GlobalTrackingTools/interface/GlobalMuonRefitter.h"
0027 
0028 using namespace edm;
0029 using namespace std;
0030 using namespace reco;
0031 
0032 //
0033 // constructor with config
0034 //
0035 TevMuonProducer::TevMuonProducer(const ParameterSet& parameterSet) : tTopoToken(esConsumes()) {
0036   LogDebug("Muon|RecoMuon|TevMuonProducer") << "constructor called" << endl;
0037 
0038   // GLB Muon Collection Label
0039   theGLBCollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
0040   glbMuonsToken = consumes<reco::TrackCollection>(theGLBCollectionLabel);
0041   glbMuonsTrajToken = consumes<std::vector<Trajectory> >(theGLBCollectionLabel.label());
0042 
0043   // service parameters
0044   ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
0045 
0046   // the services
0047   theService = std::make_unique<MuonServiceProxy>(serviceParameters, consumesCollector());
0048   edm::ConsumesCollector iC = consumesCollector();
0049 
0050   // TrackRefitter parameters
0051   ParameterSet refitterParameters = parameterSet.getParameter<ParameterSet>("RefitterParameters");
0052   theRefitter = std::make_unique<GlobalMuonRefitter>(refitterParameters, theService.get(), iC);
0053 
0054   // TrackLoader parameters
0055   ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
0056   theTrackLoader = std::make_unique<MuonTrackLoader>(trackLoaderParameters, iC, theService.get());
0057 
0058   theRefits = parameterSet.getParameter<std::vector<std::string> >("Refits");
0059   theRefitIndex = parameterSet.getParameter<std::vector<int> >("RefitIndex");
0060 
0061   for (unsigned int ww = 0; ww < theRefits.size(); ww++) {
0062     LogDebug("Muon|RecoMuon|TevMuonProducer") << "Refit " << theRefits[ww];
0063     produces<reco::TrackCollection>(theRefits[ww]);
0064     produces<TrackingRecHitCollection>(theRefits[ww]);
0065     produces<reco::TrackExtraCollection>(theRefits[ww]);
0066     produces<vector<Trajectory> >(theRefits[ww]);
0067     produces<TrajTrackAssociationCollection>(theRefits[ww]);
0068     produces<reco::TrackToTrackMap>(theRefits[ww]);
0069   }
0070   produces<DYTestimators>("dytInfo");
0071 }
0072 
0073 //
0074 // destructor
0075 //
0076 TevMuonProducer::~TevMuonProducer() { LogTrace("Muon|RecoMuon|TevMuonProducer") << "destructor called" << endl; }
0077 
0078 //
0079 // reconstruct muons
0080 //
0081 void TevMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
0082   const string metname = "Muon|RecoMuon|TevMuonProducer";
0083   LogTrace(metname) << endl << endl;
0084   LogTrace(metname) << "TeV Muon Reconstruction started" << endl;
0085 
0086   // Update the services
0087   theService->update(eventSetup);
0088 
0089   theRefitter->setEvent(event);
0090 
0091   theRefitter->setServices(theService->eventSetup());
0092 
0093   //Retrieve tracker topology from geometry
0094   const TrackerTopology* tTopo = &eventSetup.getData(tTopoToken);
0095 
0096   // Take the GLB muon container(s)
0097   Handle<reco::TrackCollection> glbMuons;
0098   event.getByToken(glbMuonsToken, glbMuons);
0099 
0100   auto dytInfo = std::make_unique<DYTestimators>();
0101   DYTestimators::Filler filler(*dytInfo);
0102   size_t GLBmuonSize = glbMuons->size();
0103   vector<DYTInfo> dytTmp(GLBmuonSize);
0104 
0105   Handle<vector<Trajectory> > glbMuonsTraj;
0106 
0107   LogTrace(metname) << "Taking " << glbMuons->size() << " Global Muons " << theGLBCollectionLabel << endl;
0108 
0109   vector<MuonTrajectoryBuilder::TrackCand> glbTrackCands;
0110 
0111   event.getByToken(glbMuonsTrajToken, glbMuonsTraj);
0112 
0113   const reco::TrackCollection* glbTracks = glbMuons.product();
0114 
0115   for (unsigned int ww = 0; ww < theRefits.size(); ww++) {
0116     LogDebug(metname) << "TeVRefit for Refit: " << theRefitIndex[ww];
0117     std::vector<std::pair<Trajectory*, reco::TrackRef> > miniMap;
0118     MuonTrackLoader::TrajectoryContainer trajectories;
0119     reco::TrackRef::key_type trackIndex = 0;
0120     int glbCounter = 0;
0121     for (reco::TrackCollection::const_iterator track = glbTracks->begin(); track != glbTracks->end();
0122          track++, ++trackIndex) {
0123       reco::TrackRef glbRef(glbMuons, trackIndex);
0124 
0125       vector<Trajectory> refitted = theRefitter->refit(*track, theRefitIndex[ww], tTopo);
0126 
0127       if (theRefits[ww] == "dyt")
0128         dytTmp[glbCounter] = *theRefitter->getDYTInfo();
0129       glbCounter++;
0130 
0131       if (!refitted.empty()) {
0132         auto refit = std::make_unique<Trajectory>(refitted.front());
0133         LogDebug(metname) << "TeVTrackLoader for Refit: " << theRefits[ww];
0134         std::pair<Trajectory*, reco::TrackRef> thisPair(refit.get(), glbRef);
0135         miniMap.push_back(thisPair);
0136         trajectories.push_back(std::move(refit));
0137       }
0138     }
0139     theTrackLoader->loadTracks(trajectories, event, miniMap, glbMuons, *tTopo, theRefits[ww]);
0140   }
0141 
0142   filler.insert(glbMuons, dytTmp.begin(), dytTmp.end());
0143   filler.fill();
0144   event.put(std::move(dytInfo), "dytInfo");
0145 
0146   LogTrace(metname) << "Done." << endl;
0147 }