CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoMuon/GlobalMuonProducer/src/TevMuonProducer.cc

Go to the documentation of this file.
00001 
00012 // Framework
00013 #include "FWCore/Framework/interface/EDProducer.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "DataFormats/Common/interface/Handle.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include "RecoMuon/GlobalMuonProducer/src/TevMuonProducer.h"
00021 
00022 // TrackFinder and specific GLB Trajectory Builder
00023 #include "RecoMuon/GlobalTrackFinder/interface/GlobalMuonTrajectoryBuilder.h"
00024 #include "RecoMuon/TrackingTools/interface/MuonTrackFinder.h"
00025 #include "RecoMuon/TrackingTools/interface/MuonTrackLoader.h"
00026 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00027 #include "RecoMuon/GlobalTrackingTools/interface/GlobalMuonRefitter.h"
00028 
00029 // Input and output collection
00030 #include "DataFormats/TrackReco/interface/Track.h"
00031 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00032 
00033 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00034 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00035 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00036 #include "DataFormats/TrackReco/interface/TrackToTrackMap.h"
00037 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00038 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00039 
00040 using namespace edm;
00041 using namespace std;
00042 
00043 //
00044 // constructor with config
00045 //
00046 TevMuonProducer::TevMuonProducer(const ParameterSet& parameterSet) {
00047 
00048   LogDebug("Muon|RecoMuon|TevMuonProducer") << "constructor called" << endl;
00049 
00050   // GLB Muon Collection Label
00051   theGLBCollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
00052 
00053   // service parameters
00054   ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
00055 
00056   // the services
00057   theService = new MuonServiceProxy(serviceParameters);
00058   
00059   // TrackRefitter parameters
00060   ParameterSet refitterParameters = parameterSet.getParameter<ParameterSet>("RefitterParameters");
00061   theRefitter = new GlobalMuonRefitter(refitterParameters, theService);
00062 
00063   // TrackLoader parameters
00064   ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
00065   theTrackLoader = new MuonTrackLoader(trackLoaderParameters,theService);
00066 
00067   theRefits = parameterSet.getParameter< std::vector<std::string> >("Refits");
00068   theRefitIndex = parameterSet.getParameter< std::vector<int> >("RefitIndex");
00069 
00070   for(unsigned int ww=0;ww<theRefits.size();ww++){
00071     LogDebug("Muon|RecoMuon|TevMuonProducer") << "Refit " << theRefits[ww];
00072     produces<reco::TrackCollection>(theRefits[ww]);
00073     produces<TrackingRecHitCollection>(theRefits[ww]);
00074     produces<reco::TrackExtraCollection>(theRefits[ww]);
00075     produces<vector<Trajectory> >(theRefits[ww]) ;
00076     produces<TrajTrackAssociationCollection>(theRefits[ww]);
00077     produces<reco::TrackToTrackMap>(theRefits[ww]);
00078   }
00079 }
00080 
00081 
00082 //
00083 // destructor
00084 //
00085 TevMuonProducer::~TevMuonProducer() {
00086 
00087   LogTrace("Muon|RecoMuon|TevMuonProducer") << "destructor called" << endl;
00088   if (theService) delete theService;
00089   if (theRefitter) delete theRefitter;
00090   if (theTrackLoader) delete theTrackLoader;
00091 }
00092 
00093 
00094 //
00095 // reconstruct muons
00096 //
00097 void TevMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
00098 
00099   const string metname = "Muon|RecoMuon|TevMuonProducer";  
00100   LogTrace(metname)<< endl << endl;
00101   LogTrace(metname)<< "TeV Muon Reconstruction started" << endl;  
00102 
00103   // Update the services
00104   theService->update(eventSetup);
00105 
00106   theRefitter->setEvent(event);
00107 
00108   theRefitter->setServices(theService->eventSetup());
00109 
00110   //Retrieve tracker topology from geometry
00111   edm::ESHandle<TrackerTopology> tTopoHand;
00112   eventSetup.get<IdealGeometryRecord>().get(tTopoHand);
00113   const TrackerTopology *tTopo=tTopoHand.product();
00114 
00115 
00116   // Take the GLB muon container(s)
00117   Handle<reco::TrackCollection> glbMuons;
00118   event.getByLabel(theGLBCollectionLabel,glbMuons);
00119 
00120   Handle<vector<Trajectory> > glbMuonsTraj;
00121 
00122   LogTrace(metname)<< "Taking " << glbMuons->size() << " Global Muons "<<theGLBCollectionLabel<<endl;
00123 
00124   vector<MuonTrajectoryBuilder::TrackCand> glbTrackCands;
00125 
00126   event.getByLabel(theGLBCollectionLabel.label(), glbMuonsTraj);
00127     
00128   const reco::TrackCollection *glbTracks = glbMuons.product();
00129   
00130   for(unsigned int ww=0;ww<theRefits.size();ww++) {
00131     LogDebug(metname)<<"TeVRefit for Refit: " <<theRefitIndex[ww];
00132     std::vector<std::pair<Trajectory*,reco::TrackRef> > miniMap;
00133     vector<Trajectory*> trajectories;
00134     reco::TrackRef::key_type trackIndex = 0;
00135     for (reco::TrackCollection::const_iterator track = glbTracks->begin(); track!=glbTracks->end(); track++ , ++trackIndex) {
00136       reco::TrackRef glbRef(glbMuons,trackIndex);
00137       
00138       vector<Trajectory> refitted=theRefitter->refit(*track,theRefitIndex[ww],tTopo);
00139 
00140       if (refitted.size()>0) {
00141         Trajectory *refit = new Trajectory(refitted.front());
00142         LogDebug(metname)<<"TeVTrackLoader for Refit: " <<theRefits[ww];
00143         trajectories.push_back(refit);
00144         std::pair<Trajectory*,reco::TrackRef> thisPair(refit,glbRef);
00145         miniMap.push_back(thisPair);
00146       }
00147     }
00148     theTrackLoader->loadTracks(trajectories,event,miniMap,theRefits[ww]);
00149   }
00150     
00151   LogTrace(metname) << "Done." << endl;    
00152 
00153 }