0025 #include "RecoMuon/L2MuonProducer/src/L2MuonCandidateProducer.h"0026
0027
0028 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0029 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0030
0031 #include <string>
0032
0033 using namespace edm;
0034 using namespace std;
0035 using namespace reco;
0036
0037
0038 L2MuonCandidateProducer::L2MuonCandidateProducer(const ParameterSet& parameterSet){
0039 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer")<<" constructor called";
0040
0041
0042 theSACollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
0043 tracksToken = consumes<reco::TrackCollection>(theSACollectionLabel);
0044 produces<RecoChargedCandidateCollection>();
0045 }
0046
0047
0048 L2MuonCandidateProducer::~L2MuonCandidateProducer(){
0049 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer")<<" L2MuonCandidateProducer destructor called";
0050 }
0051
0052
0053
0054 void L2MuonCandidateProducer::produce(edm::StreamID sid, Event& event, const EventSetup& eventSetup) const {
0055 const string metname = "Muon|RecoMuon|L2MuonCandidateProducer";
0056
0057
0058 LogTrace(metname)<<" Taking the StandAlone muons: "<<theSACollectionLabel;
0059 Handle<TrackCollection> tracks;
0060 event.getByToken(tracksToken,tracks);
0061
0062
0063 LogTrace(metname)<<" Creating the RecoChargedCandidate collection";
0064 auto candidates = std::make_unique<RecoChargedCandidateCollection>();
0065
0066 for (unsigned int i=0; i<tracks->size(); i++) {
0067 TrackRef tkref(tracks,i);
0068 Particle::Charge q = tkref->charge();
0069 Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
0070 Particle::Point vtx(tkref->vx(),tkref->vy(), tkref->vz());
0071 int pid = 13;
0072 if(abs(q)==1) pid = q < 0 ? 13 : -13;
0073 else LogWarning(metname) << "L2MuonCandidate has charge = "<<q;
0074 RecoChargedCandidate cand(q, p4, vtx, pid);
0075 cand.setTrack(tkref);
0076 candidates->push_back(cand);
0077 }
0078
0079 event.put(std::move(candidates));
0080
0081 LogTrace(metname)<<" Event loaded"
0082 <<"================================";
0083 }