CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoMuon/L3TrackFinder/src/L3MuonTrajectoryBuilder.cc

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