CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMuon/GlobalTrackFinder/src/GlobalMuonTrajectoryBuilder.cc

Go to the documentation of this file.
00001 
00026 #include "RecoMuon/GlobalTrackFinder/interface/GlobalMuonTrajectoryBuilder.h"
00027 
00028 //---------------
00029 // C++ Headers --
00030 //---------------
00031 
00032 #include <iostream>
00033 #include <iomanip>
00034 #include <algorithm>
00035 
00036 //-------------------------------
00037 // Collaborating Class Headers --
00038 //-------------------------------
00039 
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041 #include "FWCore/Framework/interface/Event.h"
00042 
00043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00044 
00045 #include "DataFormats/TrackReco/interface/Track.h"
00046 
00047 #include "RecoMuon/TrackingTools/interface/MuonCandidate.h"
00048 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00049 #include "RecoMuon/GlobalTrackingTools/interface/GlobalMuonTrackMatcher.h"
00050 
00051 using namespace std;
00052 using namespace edm;
00053 
00054 //----------------
00055 // Constructors --
00056 //----------------
00057 
00058 GlobalMuonTrajectoryBuilder::GlobalMuonTrajectoryBuilder(const edm::ParameterSet& par,
00059                                                          const MuonServiceProxy* service) : GlobalTrajectoryBuilderBase(par, service)
00060            
00061 {
00062 
00063   theTkTrackLabel = par.getParameter<edm::InputTag>("TrackerCollectionLabel");
00064 
00065 }
00066 
00067 
00068 //--------------
00069 // Destructor --
00070 //--------------
00071 
00072 GlobalMuonTrajectoryBuilder::~GlobalMuonTrajectoryBuilder() {
00073 }
00074 
00075 //
00076 // get information from event
00077 //
00078 void GlobalMuonTrajectoryBuilder::setEvent(const edm::Event& event) {
00079   
00080   const std::string category = "Muon|RecoMuon|GlobalMuonTrajectoryBuilder|setEvent";
00081   
00082   GlobalTrajectoryBuilderBase::setEvent(event);
00083 
00084   // get tracker TrackCollection from Event
00085   event.getByLabel(theTkTrackLabel,allTrackerTracks);
00086   LogDebug(category) 
00087       << " Found " << allTrackerTracks->size() 
00088       << " tracker Tracks with label "<< theTkTrackLabel;  
00089 
00090 }
00091 
00092 //
00093 // reconstruct trajectories
00094 //
00095 MuonCandidate::CandidateContainer GlobalMuonTrajectoryBuilder::trajectories(const TrackCand& staCandIn) {
00096 
00097   const std::string category = "Muon|RecoMuon|GlobalMuonTrajectoryBuilder|trajectories";
00098 
00099   // cut on muons with low momenta
00100   LogTrace(category) << " STA pt " << staCandIn.second->pt() << " rho " << staCandIn.second->innerMomentum().Rho() << " R " << staCandIn.second->innerMomentum().R() << " theCut " << thePtCut;
00101 
00102   // convert the STA track into a Trajectory if Trajectory not already present
00103   TrackCand staCand(staCandIn);
00104 
00105   vector<TrackCand> regionalTkTracks = makeTkCandCollection(staCand);
00106   LogTrace(category) << " Found " << regionalTkTracks.size() << " tracks within region of interest";
00107 
00108   // match tracker tracks to muon track
00109   vector<TrackCand> trackerTracks = trackMatcher()->match(staCand, regionalTkTracks);
00110   LogTrace(category) << " Found " << trackerTracks.size() << " matching tracker tracks within region of interest";
00111 
00112   if ( trackerTracks.empty() ) {
00113     if ( staCandIn.first == 0) delete staCand.first;
00114 
00115     return CandidateContainer();
00116   }
00117 
00118   // build a combined tracker-muon MuonCandidate
00119   //
00120   // turn tkMatchedTracks into MuonCandidates
00121   //
00122   LogTrace(category) << " Turn tkMatchedTracks into MuonCandidates";
00123   CandidateContainer tkTrajs;
00124   for (vector<TrackCand>::const_iterator tkt = trackerTracks.begin(); tkt != trackerTracks.end(); tkt++) {
00125 
00126       MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, 0);
00127       tkTrajs.push_back(muonCand);
00128   }
00129 
00130   if ( tkTrajs.empty() )  {
00131     LogTrace(category) << " tkTrajs empty";
00132     if ( staCandIn.first == 0) delete staCand.first;
00133 
00134     return CandidateContainer();
00135   }
00136 
00137   CandidateContainer result = build(staCand, tkTrajs);
00138   LogTrace(category) << " Found "<< result.size() << " GLBMuons from one STACand";
00139 
00140   // free memory
00141   if ( staCandIn.first == 0) delete staCand.first;
00142 
00143   for( CandidateContainer::const_iterator it = tkTrajs.begin(); it != tkTrajs.end(); ++it) {
00144     if ( (*it)->trajectory() ) delete (*it)->trajectory();
00145     if ( (*it)->trackerTrajectory() ) delete (*it)->trackerTrajectory();
00146     if ( *it ) delete (*it);
00147   }
00148   tkTrajs.clear();  
00149 
00150 
00151   return result;
00152   
00153 }
00154 
00155 //
00156 // make a TrackCand collection using tracker Track, Trajectory information
00157 //
00158 vector<GlobalMuonTrajectoryBuilder::TrackCand> GlobalMuonTrajectoryBuilder::makeTkCandCollection(const TrackCand& staCand) {
00159 
00160   const std::string category = "Muon|RecoMuon|GlobalMuonTrajectoryBuilder|makeTkCandCollection";
00161 
00162   vector<TrackCand> tkCandColl;
00163   
00164   vector<TrackCand> tkTrackCands;
00165     
00166   for ( unsigned int position = 0; position != allTrackerTracks->size(); ++position ) {
00167     reco::TrackRef tkTrackRef(allTrackerTracks,position);
00168     TrackCand tkCand = TrackCand((Trajectory*)(0),tkTrackRef);
00169     tkTrackCands.push_back(tkCand); 
00170   }
00171   
00172   
00173   tkCandColl = chooseRegionalTrackerTracks(staCand,tkTrackCands);
00174   
00175   return tkCandColl;
00176   
00177 }