CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/RecoMuon/GlobalMuonProducer/src/GlobalMuonProducer.cc

Go to the documentation of this file.
00001 
00014 // Framework
00015 #include "FWCore/Framework/interface/EDProducer.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "DataFormats/Common/interface/Handle.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 #include "RecoMuon/GlobalMuonProducer/src/GlobalMuonProducer.h"
00023 
00024 // TrackFinder and specific GLB Trajectory Builder
00025 #include "RecoMuon/GlobalTrackFinder/interface/GlobalMuonTrajectoryBuilder.h"
00026 #include "RecoMuon/TrackingTools/interface/MuonTrackFinder.h"
00027 #include "RecoMuon/TrackingTools/interface/MuonTrackLoader.h"
00028 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00029 
00030 // Input and output collection
00031 #include "DataFormats/TrackReco/interface/Track.h"
00032 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00033 
00034 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00035 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00036 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00037 #include "DataFormats/TrackReco/interface/TrackToTrackMap.h"
00038 
00039 using namespace edm;
00040 using namespace std;
00041 
00042 //
00043 // constructor with config
00044 //
00045 GlobalMuonProducer::GlobalMuonProducer(const ParameterSet& parameterSet) {
00046 
00047   LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "constructor called" << endl;
00048 
00049   // Parameter set for the Builder
00050   ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("GLBTrajBuilderParameters");
00051   InputTag trackCollectionTag = parameterSet.getParameter<InputTag>("TrackerCollectionLabel");
00052   trajectoryBuilderParameters.addParameter<InputTag>("TrackerCollectionLabel",trackCollectionTag);
00053   
00054   // STA Muon Collection Label
00055   theSTACollectionLabel = parameterSet.getParameter<InputTag>("MuonCollectionLabel");
00056 
00057   // service parameters
00058   ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
00059 
00060   // TrackLoader parameters
00061   ParameterSet trackLoaderParameters = parameterSet.getParameter<ParameterSet>("TrackLoaderParameters");
00062   
00063   // the services
00064   theService = new MuonServiceProxy(serviceParameters);
00065   
00066   // instantiate the concrete trajectory builder in the Track Finder
00067   MuonTrackLoader* mtl = new MuonTrackLoader(trackLoaderParameters,theService);
00068   GlobalMuonTrajectoryBuilder* gmtb = new GlobalMuonTrajectoryBuilder(trajectoryBuilderParameters, theService);
00069 
00070   theTrackFinder = new MuonTrackFinder(gmtb, mtl);
00071 
00072   setAlias(parameterSet.getParameter<std::string>("@module_label"));
00073   produces<reco::TrackCollection>().setBranchAlias(theAlias + "Tracks");
00074   produces<TrackingRecHitCollection>().setBranchAlias(theAlias + "RecHits");
00075   produces<reco::TrackExtraCollection>().setBranchAlias(theAlias + "TrackExtras");
00076   produces<vector<Trajectory> >().setBranchAlias(theAlias + "Trajectories") ;
00077   produces<TrajTrackAssociationCollection>().setBranchAlias(theAlias + "TrajTrackMap");
00078   produces<reco::MuonTrackLinksCollection>().setBranchAlias(theAlias + "s");
00079 }
00080 
00081 
00082 //
00083 // destructor
00084 //
00085 GlobalMuonProducer::~GlobalMuonProducer() {
00086 
00087   LogTrace("Muon|RecoMuon|GlobalMuonProducer") << "destructor called" << endl;
00088   if (theService) delete theService;
00089   if (theTrackFinder) delete theTrackFinder;
00090 
00091 }
00092 
00093 
00094 //
00095 // reconstruct muons
00096 //
00097 void GlobalMuonProducer::produce(Event& event, const EventSetup& eventSetup) {
00098   const string metname = "Muon|RecoMuon|GlobalMuonProducer";  
00099   LogTrace(metname)<<endl<<endl<<endl;
00100   LogTrace(metname)<<"Global Muon Reconstruction started"<<endl;  
00101 
00102   // Update the services
00103   theService->update(eventSetup);
00104 
00105   // Take the STA muon container(s)
00106   Handle<reco::TrackCollection> staMuons;
00107   event.getByLabel(theSTACollectionLabel,staMuons);
00108 
00109   Handle<vector<Trajectory> > staMuonsTraj;
00110 
00111   LogTrace(metname) << "Taking " << staMuons->size() << " Stand Alone Muons "<<theSTACollectionLabel<<endl;
00112 
00113   vector<MuonTrajectoryBuilder::TrackCand> staTrackCands;
00114 
00115   edm::Handle<TrajTrackAssociationCollection> staAssoMap;
00116 
00117   edm::Handle<reco::TrackToTrackMap> updatedStaAssoMap;
00118 
00119   if( event.getByLabel(theSTACollectionLabel.label(), staMuonsTraj) && event.getByLabel(theSTACollectionLabel.label(),staAssoMap) && event.getByLabel(theSTACollectionLabel.label(),updatedStaAssoMap) ) {    
00120     
00121     for(TrajTrackAssociationCollection::const_iterator it = staAssoMap->begin(); it != staAssoMap->end(); ++it){        
00122       const Ref<vector<Trajectory> > traj = it->key;
00123       const reco::TrackRef tkRegular  = it->val;
00124       reco::TrackRef tkUpdated;
00125       reco::TrackToTrackMap::const_iterator iEnd;
00126       reco::TrackToTrackMap::const_iterator iii;
00127       if ( theSTACollectionLabel.instance() == "UpdatedAtVtx") {
00128         iEnd = updatedStaAssoMap->end();
00129         iii = updatedStaAssoMap->find(it->val);
00130         if (iii != iEnd ) tkUpdated = (*updatedStaAssoMap)[it->val] ;
00131       }
00132       
00133       int etaFlip1 = ((tkUpdated.isNonnull() && tkRegular.isNonnull()) && ( (tkUpdated->eta() * tkRegular->eta() ) < 0)) ? -1 : 1; 
00134       
00135       const reco::TrackRef tk = ( tkUpdated.isNonnull() && etaFlip1==1 ) ? tkUpdated : tkRegular ;
00136 
00137       MuonTrajectoryBuilder::TrackCand tkCand = MuonTrajectoryBuilder::TrackCand((Trajectory*)(0),tk);
00138       if( traj->isValid() ) tkCand.first = &*traj ;
00139       staTrackCands.push_back(tkCand);
00140     }
00141   } else {
00142     for ( unsigned int position = 0; position != staMuons->size(); ++position ) {
00143       reco::TrackRef staTrackRef(staMuons,position);
00144       MuonTrajectoryBuilder::TrackCand staCand = MuonTrajectoryBuilder::TrackCand((Trajectory*)(0),staTrackRef);
00145       staTrackCands.push_back(staCand); 
00146     }
00147   }
00148     
00149   theTrackFinder->reconstruct(staTrackCands, event);      
00150   
00151   
00152   LogTrace(metname)<<"Event loaded"
00153                    <<"================================"
00154                    <<endl<<endl;
00155     
00156 }