CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoMuon/L2MuonProducer/src/L2MuonCandidateProducer.cc

Go to the documentation of this file.
00001 
00018 // Framework
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 
00026 #include "RecoMuon/L2MuonProducer/src/L2MuonCandidateProducer.h"
00027 
00028 // Input and output collections
00029 #include "DataFormats/TrackReco/interface/Track.h"
00030 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00031 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00032 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00033 
00034 #include <string>
00035 
00036 using namespace edm;
00037 using namespace std;
00038 using namespace reco;
00039 
00041 L2MuonCandidateProducer::L2MuonCandidateProducer(const ParameterSet& parameterSet){
00042   LogTrace("Muon|RecoMuon|L2MuonCandidateProducer")<<" constructor called";
00043 
00044   // StandAlone Collection Label
00045   theSACollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
00046 
00047   produces<RecoChargedCandidateCollection>();
00048 }
00049   
00051 L2MuonCandidateProducer::~L2MuonCandidateProducer(){
00052   LogTrace("Muon|RecoMuon|L2MuonCandidateProducer")<<" L2MuonCandidateProducer destructor called";
00053 }
00054 
00055 
00057 void L2MuonCandidateProducer::produce(Event& event, const EventSetup& eventSetup){
00058   const string metname = "Muon|RecoMuon|L2MuonCandidateProducer";
00059   
00060   // Take the SA container
00061   LogTrace(metname)<<" Taking the StandAlone muons: "<<theSACollectionLabel;
00062   Handle<TrackCollection> tracks; 
00063   event.getByLabel(theSACollectionLabel,tracks);
00064 
00065   // Create a RecoChargedCandidate collection
00066   LogTrace(metname)<<" Creating the RecoChargedCandidate collection";
00067   auto_ptr<RecoChargedCandidateCollection> candidates( new RecoChargedCandidateCollection());
00068 
00069   for (unsigned int i=0; i<tracks->size(); i++) {
00070       TrackRef tkref(tracks,i);
00071       Particle::Charge q = tkref->charge();
00072       Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
00073       Particle::Point vtx(tkref->vx(),tkref->vy(), tkref->vz());
00074       int pid = 13;
00075       if(abs(q)==1) pid = q < 0 ? 13 : -13;
00076       else LogWarning(metname) << "L2MuonCandidate has charge = "<<q;
00077       RecoChargedCandidate cand(q, p4, vtx, pid);
00078       cand.setTrack(tkref);
00079       candidates->push_back(cand);
00080   }
00081   
00082   event.put(candidates);
00083  
00084   LogTrace(metname)<<" Event loaded"
00085                    <<"================================";
00086 }