CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoMuon/L3MuonProducer/src/L3MuonCandidateProducerFromMuons.cc

Go to the documentation of this file.
00001 
00008 // Framework
00009 #include "FWCore/Framework/interface/EDProducer.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 #include "RecoMuon/L3MuonProducer/src/L3MuonCandidateProducerFromMuons.h"
00017 
00018 // Input and output collections
00019 #include "DataFormats/TrackReco/interface/Track.h"
00020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00021 
00022 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00023 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00024 
00025 #include "DataFormats/MuonReco/interface/Muon.h"
00026 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00027 
00028 #include <string>
00029 
00030 using namespace edm;
00031 using namespace std;
00032 using namespace reco;
00033 
00034 static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons");
00035 
00037 L3MuonCandidateProducerFromMuons::L3MuonCandidateProducerFromMuons(const ParameterSet& parameterSet) :
00038   m_L3CollectionLabel( parameterSet.getParameter<InputTag>("InputObjects") )       // standAlone Collection Label
00039 {
00040   LogTrace(category)<<" constructor called";
00041   produces<RecoChargedCandidateCollection>();
00042 }
00043 
00045 L3MuonCandidateProducerFromMuons::~L3MuonCandidateProducerFromMuons(){
00046   LogTrace(category)<<" L3MuonCandidateProducerFromMuons destructor called";
00047 }
00048 
00049 
00051 void L3MuonCandidateProducerFromMuons::produce(Event& event, const EventSetup& eventSetup){
00052   // Create a RecoChargedCandidate collection
00053   LogTrace(category)<<" Creating the RecoChargedCandidate collection";
00054   auto_ptr<RecoChargedCandidateCollection> candidates( new RecoChargedCandidateCollection());
00055 
00056   // Take the L3 container
00057   LogTrace(category)<<" Taking the L3/GLB muons: "<<m_L3CollectionLabel.label();
00058   Handle<reco::MuonCollection> muons;
00059   event.getByLabel(m_L3CollectionLabel,muons);
00060 
00061   if (not muons.isValid()) {
00062     LogError(category) << muons.whyFailed()->what();
00063   } else { 
00064     for (unsigned int i=0; i<muons->size(); i++) {
00065       TrackRef tkref = (*muons)[i].innerTrack();
00066 
00067       Particle::Charge q = tkref->charge();
00068       Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
00069       Particle::Point vtx(tkref->vx(),tkref->vy(), tkref->vz());
00070 
00071       int pid = 13;
00072       if (abs(q)==1) 
00073         pid = q < 0 ? 13 : -13;
00074       else 
00075         LogWarning(category) << "L3MuonCandidate has charge = " << q;
00076       RecoChargedCandidate cand(q, p4, vtx, pid);
00077 
00078       cand.setTrack(tkref);
00079       candidates->push_back(cand);
00080     }
00081   }
00082   event.put(candidates);
00083 }