File indexing completed on 2023-10-25 10:01:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <string>
0019
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0022 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/EventSetup.h"
0027 #include "FWCore/Framework/interface/global/EDProducer.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031
0032 class L2MuonCandidateProducer : public edm::global::EDProducer<> {
0033 public:
0034
0035 L2MuonCandidateProducer(const edm::ParameterSet&);
0036
0037
0038 ~L2MuonCandidateProducer() override;
0039
0040
0041 void produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup&) const override;
0042
0043 private:
0044
0045 edm::InputTag theSACollectionLabel;
0046 edm::EDGetTokenT<reco::TrackCollection> tracksToken;
0047 };
0048
0049
0050 L2MuonCandidateProducer::L2MuonCandidateProducer(const edm::ParameterSet& parameterSet) {
0051 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " constructor called";
0052
0053
0054 theSACollectionLabel = parameterSet.getParameter<edm::InputTag>("InputObjects");
0055 tracksToken = consumes<reco::TrackCollection>(theSACollectionLabel);
0056 produces<reco::RecoChargedCandidateCollection>();
0057 }
0058
0059
0060 L2MuonCandidateProducer::~L2MuonCandidateProducer() {
0061 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " L2MuonCandidateProducer destructor called";
0062 }
0063
0064
0065 void L2MuonCandidateProducer::produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup& eventSetup) const {
0066 const std::string metname = "Muon|RecoMuon|L2MuonCandidateProducer";
0067
0068
0069 LogTrace(metname) << " Taking the StandAlone muons: " << theSACollectionLabel;
0070 edm::Handle<reco::TrackCollection> tracks;
0071 event.getByToken(tracksToken, tracks);
0072
0073
0074 LogTrace(metname) << " Creating the RecoChargedCandidate collection";
0075 auto candidates = std::make_unique<reco::RecoChargedCandidateCollection>();
0076
0077 for (unsigned int i = 0; i < tracks->size(); i++) {
0078 reco::TrackRef tkref(tracks, i);
0079 reco::Particle::Charge q = tkref->charge();
0080 reco::Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
0081 reco::Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
0082 int pid = 13;
0083 if (abs(q) == 1)
0084 pid = q < 0 ? 13 : -13;
0085 else
0086 edm::LogWarning(metname) << "L2MuonCandidate has charge = " << q;
0087 reco::RecoChargedCandidate cand(q, p4, vtx, pid);
0088 cand.setTrack(tkref);
0089 candidates->push_back(cand);
0090 }
0091
0092 event.put(std::move(candidates));
0093
0094 LogTrace(metname) << " Event loaded"
0095 << "================================";
0096 }
0097
0098
0099 #include "FWCore/Framework/interface/MakerMacros.h"
0100 DEFINE_FWK_MODULE(L2MuonCandidateProducer);