CMS 3D CMS Logo

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 
00048 #include "RecoMuon/TrackingTools/interface/MuonCandidate.h"
00049 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00050 #include "RecoMuon/GlobalTrackingTools/interface/GlobalMuonTrackMatcher.h"
00051 #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGenerator.h"
00052 #include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGeneratorFactory.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), theTkSeedGenerator(0) {
00073 
00074   theFirstEvent = true;
00075   
00076   //
00077   // start seed generator;
00078   //
00079    ParameterSet seedGenPSet = par.getParameter<ParameterSet>("SeedGeneratorParameters");
00080   std::string seedGenName = seedGenPSet.getParameter<std::string>("ComponentName");
00081   theTkSeedGenerator = TrackerSeedGeneratorFactory::get()->create(seedGenName, seedGenPSet);
00082   theTkSeedGenerator->init(GlobalTrajectoryBuilderBase::service());
00083   
00084   theTkBuilderName = par.getParameter<std::string>("TkTrackBuilder");
00085 
00086   theTrajectoryCleaner = new TrajectoryCleanerBySharedHits();    
00087 
00088   theSeedName = par.getParameter<edm::InputTag>("l3SeedLabel");
00089   theTkCollName = par.getParameter<edm::InputTag>("tkTrajLabel");
00090 
00091 }
00092 
00093 
00094 //--------------
00095 // Destructor --
00096 //--------------
00097 
00098 L3MuonTrajectoryBuilder::~L3MuonTrajectoryBuilder() {
00099   if (theTrajectoryCleaner) delete theTrajectoryCleaner;
00100 }
00101 
00102 //
00103 // get information from event
00104 //
00105 void L3MuonTrajectoryBuilder::setEvent(const edm::Event& event) {
00106   
00107   const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|setEvent";
00108     
00109   GlobalTrajectoryBuilderBase::setEvent(event);
00110     
00111     
00112   if (theFirstEvent) {
00113       
00114     theFirstEvent = false;
00115     LogInfo(category) << "Constructing a Tk Trajectory Builder";
00116     GlobalTrajectoryBuilderBase::service()->eventSetup().get<CkfComponentsRecord>().get(theTkBuilderName,theTkBuilder);  
00117   }
00118     
00119   theTkBuilder->setEvent(event);
00120     
00121   theTkSeedGenerator->setEvent(event);
00122 
00123   theSeedsAvailable = event.getByLabel(theSeedName,theSeedCollection);
00124   theTrajsAvailable = event.getByLabel(theTkCollName,theTkTrajCollection);
00125   theTkCandsAvailable = event.getByLabel(theTkCollName,theTkTrackCandCollection);
00126   
00127 }
00128 
00129 //
00130 // reconstruct trajectories
00131 //
00132 MuonCandidate::CandidateContainer L3MuonTrajectoryBuilder::trajectories(const TrackCand& staCandIn) {
00133 
00134   const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|trajectories";
00135 
00136   // cut on muons with low momenta
00137   if ( (staCandIn).second->pt() < thePtCut || (staCandIn).second->innerMomentum().Rho() < thePtCut || (staCandIn).second->innerMomentum().R() < 2.5 ) return CandidateContainer();
00138 
00139   // convert the STA track into a Trajectory if Trajectory not already present
00140   TrackCand staCand(staCandIn);
00141   addTraj(staCand);
00142 
00143   vector<TrackCand> trackerTracks;
00144 
00145   vector<TrackCand> regionalTkTracks = makeTkCandCollection(staCand);
00146   LogInfo(category) << "Found " << regionalTkTracks.size() << " tracks within region of interest";  
00147   
00148   // match tracker tracks to muon track
00149   trackerTracks = trackMatcher()->match(staCand, regionalTkTracks);
00150   
00151   LogInfo(category) << "Found " << trackerTracks.size() << " matching tracker tracks within region of interest";
00152   if ( trackerTracks.empty() ) return CandidateContainer();
00153   
00154   // build a combined tracker-muon MuonCandidate
00155   //
00156   // turn tkMatchedTracks into MuonCandidates
00157   //
00158   LogInfo(category) << "turn tkMatchedTracks into MuonCandidates";
00159   CandidateContainer tkTrajs;
00160   for (vector<TrackCand>::const_iterator tkt = trackerTracks.begin(); tkt != trackerTracks.end(); tkt++) {
00161     if ((*tkt).first != 0 && (*tkt).first->isValid()) {
00162       std::vector<Trajectory> refittedTk;
00163       Trajectory refittedTkTraj = *(*tkt).first;
00164       refittedTk = refitTrajectory(*(*tkt).first);
00165       if(refittedTk.size() == 1) refittedTkTraj = refittedTk.front();
00166       
00167       MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, new Trajectory(refittedTkTraj));
00168       tkTrajs.push_back(muonCand);
00169       LogTrace(category) << "tpush";
00170 
00171     }
00172   }
00173   
00174   if ( tkTrajs.empty() )  {
00175     LogInfo(category) << "tkTrajs empty";
00176     return CandidateContainer();
00177   }
00178   
00179   CandidateContainer result = build(staCand, tkTrajs);  
00180   LogInfo(category) << "Found "<< result.size() << " L3Muons from one L2Cand";
00181 
00182   // free memory
00183   if ( staCandIn.first == 0) delete staCand.first;
00184 
00185   for( CandidateContainer::const_iterator it = tkTrajs.begin(); it != tkTrajs.end(); ++it) {
00186     if ( (*it)->trajectory() ) delete (*it)->trajectory();
00187     if ( (*it)->trackerTrajectory() ) delete (*it)->trackerTrajectory();
00188     if ( *it ) delete (*it);
00189   }
00190   tkTrajs.clear();  
00191 
00192   for ( vector<TrackCand>::const_iterator is = regionalTkTracks.begin(); is != regionalTkTracks.end(); ++is) {
00193     delete (*is).first;   
00194   }
00195   
00196   return result;
00197   
00198 }
00199 
00200 //
00201 // make a TrackCand collection using tracker Track, Trajectory information
00202 //
00203 vector<L3MuonTrajectoryBuilder::TrackCand> L3MuonTrajectoryBuilder::makeTkCandCollection(const TrackCand& staCand) {
00204 
00205   const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|makeTkCandCollection";
00206 
00207   vector<TrackCand> tkCandColl;  
00208 
00209   if (theTrajsAvailable) {
00210     LogDebug(category) << "Found " << theTkTrajCollection->size() <<" tkCands";
00211     for (TC::const_iterator tt=theTkTrajCollection->begin();tt!=theTkTrajCollection->end();++tt){
00212       tkCandColl.push_back(TrackCand(new Trajectory(*tt),reco::TrackRef()));
00213     } 
00214     LogTrace(category) << "Found " << tkCandColl.size() << " tkCands from seeds";
00215     return tkCandColl;
00216   }
00217   
00218   // Tracks not available, make seeds and trajectories
00219   // std::vector<L3MuonTrajectorySeed> useSeeds;
00220   std::vector<TrajectorySeed> tkSeeds;
00221   if( theSeedsAvailable ) {
00222     L3MuonTrajectorySeedCollection::const_iterator l3Seed;
00223     for(l3Seed=theSeedCollection->begin(); l3Seed != theSeedCollection->end(); ++l3Seed) {
00224       const reco::TrackRef & l2FromSeed = l3Seed->l2Track();
00225       if(staCand.second == l2FromSeed) tkSeeds.push_back(*l3Seed);
00226     }    
00227   } else {
00228     
00229     LogTrace(category) << "Making Seeds";
00230     
00231     RectangularEtaPhiTrackingRegion region = defineRegionOfInterest((staCand.second));
00232     theTkSeedGenerator->trackerSeeds(staCand, region, tkSeeds);    
00233   }
00234 
00235   LogTrace(category) << "Found " << tkSeeds.size() << " tracker seeds";
00236 
00237   TC allTkTrajs = makeTrajsFromSeeds(tkSeeds);
00238   
00239   for (TC::const_iterator tt=allTkTrajs.begin();tt!=allTkTrajs.end();++tt){
00240     tkCandColl.push_back(TrackCand(new Trajectory(*tt),reco::TrackRef()));
00241   } 
00242   
00243   LogTrace(category) << "Found " << tkCandColl.size() << " tkCands from seeds";
00244 
00245   return tkCandColl;
00246 
00247 }
00248 
00249 
00250 //
00251 // build a tracker Trajectory from a seed
00252 //
00253 L3MuonTrajectoryBuilder::TC L3MuonTrajectoryBuilder::makeTrajsFromSeeds(const vector<TrajectorySeed>& tkSeeds) const {
00254 
00255   // retrieve navigation school
00256   edm::ESHandle<NavigationSchool> nav;
00257   GlobalTrajectoryBuilderBase::service()->eventSetup().get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
00258   // set the correct navigation
00259   NavigationSetter setter(*nav.product());
00260 
00261   const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|makeTrajsFromSeeds";
00262   TC result;
00263   
00264   LogInfo(category) << "Tracker Seeds from L2/STA Muon: " << tkSeeds.size();
00265   
00266   int nseed = 0;
00267   vector<Trajectory> rawResult;
00268   std::vector<TrajectorySeed>::const_iterator seed;
00269   for (seed = tkSeeds.begin(); seed != tkSeeds.end(); ++seed) {
00270     nseed++;
00271     LogTrace(category) << "Building a trajectory from seed " << nseed;
00272     
00273     TC tkTrajs;
00274 
00275     tkTrajs = theTkBuilder->trajectories(*seed);
00276 
00277     LogTrace(category) << "Trajectories from Seed " << tkTrajs.size();
00278     
00279     theTrajectoryCleaner->clean(tkTrajs);
00280     
00281     for(vector<Trajectory>::const_iterator it=tkTrajs.begin();
00282         it!=tkTrajs.end(); it++){
00283       if( it->isValid() ) {
00284         rawResult.push_back(*it);
00285       }
00286     }
00287     LogTrace(category) << "Trajectories from Seed after cleaning " << rawResult.size();
00288     
00289   }
00290 
00291   theTrajectoryCleaner->clean(rawResult);
00292   
00293   for (vector<Trajectory>::const_iterator itraw = rawResult.begin();
00294        itraw != rawResult.end(); itraw++) {
00295     if((*itraw).isValid()) result.push_back( *itraw);
00296   }
00297  
00298 
00299   LogInfo(category) << "Trajectories from all seeds " << result.size();
00300   return result;
00301 
00302 }
00303 
00304 

Generated on Tue Jun 9 17:44:17 2009 for CMSSW by  doxygen 1.5.4