CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/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 
00038 using namespace edm;
00039 using namespace std;
00040 
00041 //
00042 // constructor with config
00043 //
00044 TevMuonProducer::TevMuonProducer(const ParameterSet& parameterSet) {
00045 
00046   LogDebug("Muon|RecoMuon|TevMuonProducer") << "constructor called" << endl;
00047 
00048   // GLB Muon Collection Label
00049   theGLBCollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
00050 
00051   // service parameters
00052   ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
00053 
00054   // the services
00055   theService = new MuonServiceProxy(serviceParameters);
00056   
00057   // TrackRefitter parameters
00058   ParameterSet refitterParameters = parameterSet.getParameter<ParameterSet>("RefitterParameters");
00059   theRefitter = new GlobalMuonRefitter(refitterParameters, theService);
00060 
00061   // TrackLoader parameters
00062   ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
00063   theTrackLoader = new MuonTrackLoader(trackLoaderParameters,theService);
00064 
00065   theRefits = parameterSet.getParameter< std::vector<std::string> >("Refits");
00066   theRefitIndex = parameterSet.getParameter< std::vector<int> >("RefitIndex");
00067 
00068   for(unsigned int ww=0;ww<theRefits.size();ww++){
00069     LogDebug("Muon|RecoMuon|TevMuonProducer") << "Refit " << theRefits[ww];
00070     produces<reco::TrackCollection>(theRefits[ww]);
00071     produces<TrackingRecHitCollection>(theRefits[ww]);
00072     produces<reco::TrackExtraCollection>(theRefits[ww]);
00073     produces<vector<Trajectory> >(theRefits[ww]) ;
00074     produces<TrajTrackAssociationCollection>(theRefits[ww]);
00075     produces<reco::TrackToTrackMap>(theRefits[ww]);
00076   }
00077 }
00078 
00079 
00080 //
00081 // destructor
00082 //
00083 TevMuonProducer::~TevMuonProducer() {
00084 
00085   LogTrace("Muon|RecoMuon|TevMuonProducer") << "destructor called" << endl;
00086   if (theService) delete theService;
00087   if (theRefitter) delete theRefitter;
00088   if (theTrackLoader) delete theTrackLoader;
00089 }
00090 
00091 
00092 //
00093 // reconstruct muons
00094 //
00095 void TevMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
00096 
00097   const string metname = "Muon|RecoMuon|TevMuonProducer";  
00098   LogTrace(metname)<< endl << endl;
00099   LogTrace(metname)<< "TeV Muon Reconstruction started" << endl;  
00100 
00101   // Update the services
00102   theService->update(eventSetup);
00103 
00104   theRefitter->setEvent(event);
00105 
00106   theRefitter->setServices(theService->eventSetup());
00107 
00108   // Take the GLB muon container(s)
00109   Handle<reco::TrackCollection> glbMuons;
00110   event.getByLabel(theGLBCollectionLabel,glbMuons);
00111 
00112   Handle<vector<Trajectory> > glbMuonsTraj;
00113 
00114   LogTrace(metname)<< "Taking " << glbMuons->size() << " Global Muons "<<theGLBCollectionLabel<<endl;
00115 
00116   vector<MuonTrajectoryBuilder::TrackCand> glbTrackCands;
00117 
00118   event.getByLabel(theGLBCollectionLabel.label(), glbMuonsTraj);
00119     
00120   const reco::TrackCollection *glbTracks = glbMuons.product();
00121   
00122   for(unsigned int ww=0;ww<theRefits.size();ww++) {
00123     LogDebug(metname)<<"TeVRefit for Refit: " <<theRefitIndex[ww];
00124     std::vector<std::pair<Trajectory*,reco::TrackRef> > miniMap;
00125     vector<Trajectory*> trajectories;
00126     reco::TrackRef::key_type trackIndex = 0;
00127     for (reco::TrackCollection::const_iterator track = glbTracks->begin(); track!=glbTracks->end(); track++ , ++trackIndex) {
00128       reco::TrackRef glbRef(glbMuons,trackIndex);
00129       
00130       vector<Trajectory> refitted=theRefitter->refit(*track,theRefitIndex[ww]);
00131 
00132       if (refitted.size()>0) {
00133         Trajectory *refit = new Trajectory(refitted.front());
00134         LogDebug(metname)<<"TeVTrackLoader for Refit: " <<theRefits[ww];
00135         trajectories.push_back(refit);
00136         std::pair<Trajectory*,reco::TrackRef> thisPair(refit,glbRef);
00137         miniMap.push_back(thisPair);
00138       }
00139     }
00140     theTrackLoader->loadTracks(trajectories,event,miniMap,theRefits[ww]);
00141   }
00142     
00143   LogTrace(metname) << "Done." << endl;    
00144 
00145 }