CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L3MuonCandidateProducerFromMuons.cc
Go to the documentation of this file.
1 
8 // Framework
14 
16 
17 // Input and output collections
20 
23 
24 #include <string>
25 
26 using namespace edm;
27 using namespace std;
28 using namespace reco;
29 
30 static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons");
31 
34  : m_L3CollectionLabel(parameterSet.getParameter<InputTag>("InputObjects")) // standAlone Collection Label
35 {
36  muonToken_ = consumes<reco::MuonCollection>(m_L3CollectionLabel);
37  LogTrace(category) << " constructor called";
38  produces<RecoChargedCandidateCollection>();
39 }
40 
43  LogTrace(category) << " L3MuonCandidateProducerFromMuons destructor called";
44 }
45 
48  // Create a RecoChargedCandidate collection
49  LogTrace(category) << " Creating the RecoChargedCandidate collection";
50  auto candidates = std::make_unique<RecoChargedCandidateCollection>();
51 
52  // Take the L3 container
53  LogTrace(category) << " Taking the L3/GLB muons: " << m_L3CollectionLabel.label();
55  event.getByToken(muonToken_, muons);
56 
57  if (not muons.isValid()) {
58  LogError(category) << muons.whyFailed()->what();
59  } else {
60  for (unsigned int i = 0; i < muons->size(); i++) {
61  // avoids crashing in case the muon is SA only.
62  TrackRef tkref = ((*muons)[i].innerTrack().isNonnull()) ? (*muons)[i].innerTrack() : (*muons)[i].muonBestTrack();
63 
64  Particle::Charge q = tkref->charge();
65  Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
66  Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
67 
68  int pid = 13;
69  if (abs(q) == 1)
70  pid = q < 0 ? 13 : -13;
71  else
72  LogWarning(category) << "L3MuonCandidate has charge = " << q;
73  RecoChargedCandidate cand(q, p4, vtx, pid);
74 
75  cand.setTrack(tkref);
76  candidates->push_back(cand);
77  }
78  }
79  event.put(std::move(candidates));
80 }
edm::EDGetTokenT< reco::MuonCollection > muonToken_
Log< level::Error, false > LogError
#define LogTrace(id)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
def move
Definition: eostools.py:511
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:70
L3MuonCandidateProducerFromMuons(const edm::ParameterSet &)
constructor with config
std::string const & label() const
Definition: InputTag.h:36
tuple muons
Definition: patZpeak.py:39
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
std::shared_ptr< cms::Exception > whyFailed() const
Definition: HandleBase.h:91
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
produce candidates
Log< level::Warning, false > LogWarning
void setTrack(const reco::TrackRef &r)
set reference to track
math::PtEtaPhiELorentzVectorF LorentzVector