File indexing completed on 2025-01-08 03:36:30
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/ConfigurationDescriptions.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0032 #include "FWCore/Utilities/interface/InputTag.h"
0033
0034 class L2MuonCandidateProducer : public edm::global::EDProducer<> {
0035 public:
0036
0037 L2MuonCandidateProducer(const edm::ParameterSet&);
0038
0039
0040 ~L2MuonCandidateProducer() override;
0041
0042
0043 void produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup&) const override;
0044
0045
0046 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0047
0048 private:
0049
0050 const edm::InputTag theSACollectionLabel;
0051 const edm::EDGetTokenT<reco::TrackCollection> tracksToken;
0052 };
0053
0054
0055 L2MuonCandidateProducer::L2MuonCandidateProducer(const edm::ParameterSet& parameterSet)
0056 :
0057 theSACollectionLabel{parameterSet.getParameter<edm::InputTag>("InputObjects")},
0058 tracksToken{consumes<reco::TrackCollection>(theSACollectionLabel)} {
0059 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " constructor called";
0060 produces<reco::RecoChargedCandidateCollection>();
0061 }
0062
0063 void L2MuonCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0064 edm::ParameterSetDescription desc;
0065 desc.add<edm::InputTag>("InputObjects", edm::InputTag("L2Muons", "UpdatedAtVtx"))
0066 ->setComment("Standalone Collection Label");
0067 descriptions.addWithDefaultLabel(desc);
0068 }
0069
0070
0071 L2MuonCandidateProducer::~L2MuonCandidateProducer() {
0072 LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " L2MuonCandidateProducer destructor called";
0073 }
0074
0075
0076 void L2MuonCandidateProducer::produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup& eventSetup) const {
0077 const std::string metname = "Muon|RecoMuon|L2MuonCandidateProducer";
0078
0079
0080 LogTrace(metname) << " Taking the StandAlone muons: " << theSACollectionLabel;
0081 edm::Handle<reco::TrackCollection> tracks;
0082 event.getByToken(tracksToken, tracks);
0083
0084
0085 LogTrace(metname) << " Creating the RecoChargedCandidate collection";
0086 auto candidates = std::make_unique<reco::RecoChargedCandidateCollection>();
0087
0088 for (unsigned int i = 0; i < tracks->size(); i++) {
0089 reco::TrackRef tkref(tracks, i);
0090 reco::Particle::Charge q = tkref->charge();
0091 reco::Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
0092 reco::Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
0093 int pid = 13;
0094 if (abs(q) == 1)
0095 pid = q < 0 ? 13 : -13;
0096 else
0097 edm::LogWarning(metname) << "L2MuonCandidate has charge = " << q;
0098 reco::RecoChargedCandidate cand(q, p4, vtx, pid);
0099 cand.setTrack(tkref);
0100 candidates->push_back(cand);
0101 }
0102
0103 event.put(std::move(candidates));
0104
0105 LogTrace(metname) << " Event loaded"
0106 << "================================";
0107 }
0108
0109
0110 #include "FWCore/Framework/interface/MakerMacros.h"
0111 DEFINE_FWK_MODULE(L2MuonCandidateProducer);