CMS 3D CMS Logo

L3MuonCandidateProducerFromMuons.cc
Go to the documentation of this file.
1 
8 // Framework
17 
18 // Input and output collections
21 
24 
25 #include <string>
26 
27 using namespace edm;
28 using namespace std;
29 using namespace reco;
30 
31 static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons");
32 
35  : m_L3CollectionLabel(parameterSet.getParameter<InputTag>("InputObjects")), // standAlone Collection Label
36  m_muonToken(consumes(m_L3CollectionLabel)),
37  m_displacedReco(parameterSet.getParameter<bool>("DisplacedReconstruction")) {
38  LogTrace(category) << " constructor called";
39  produces<RecoChargedCandidateCollection>();
40 }
41 
44  LogTrace(category) << " L3MuonCandidateProducerFromMuons destructor called";
45 }
46 
49  desc.add<edm::InputTag>("InputObjects", edm::InputTag("hltL3Muons"));
50  desc.add<bool>("DisplacedReconstruction", false);
51  descriptions.addWithDefaultLabel(desc);
52 }
53 
56  // Create a RecoChargedCandidate collection
57  LogTrace(category) << " Creating the RecoChargedCandidate collection";
58  auto candidates = std::make_unique<RecoChargedCandidateCollection>();
59 
60  // Take the L3 container
61  LogTrace(category) << " Taking the L3/GLB muons: " << m_L3CollectionLabel.label();
63  event.getByToken(m_muonToken, muons);
64 
65  if (not muons.isValid()) {
66  LogError(category) << muons.whyFailed()->what();
67  } else {
68  for (unsigned int i = 0; i < muons->size(); i++) {
69  // avoids crashing in case the muon is SA only.
70  TrackRef tkref;
71  if (m_displacedReco) {
72  tkref = (*muons)[i].isGlobalMuon() ? (*muons)[i].globalTrack() : (*muons)[i].muonBestTrack();
73  } else {
74  tkref = (*muons)[i].innerTrack().isNonnull() ? (*muons)[i].innerTrack() : (*muons)[i].muonBestTrack();
75  }
76  Particle::Charge q = tkref->charge();
77  Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
78  Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
79 
80  int pid = 13;
81  if (abs(q) == 1)
82  pid = q < 0 ? 13 : -13;
83  else
84  LogWarning(category) << "L3MuonCandidate has charge = " << q;
85  RecoChargedCandidate cand(q, p4, vtx, pid);
86 
87  cand.setTrack(tkref);
88  candidates->push_back(cand);
89  }
90  }
91  event.put(std::move(candidates));
92 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
descriptions
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::string const & label() const
Definition: InputTag.h:36
Log< level::Error, false > LogError
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
#define LogTrace(id)
edm::EDGetTokenT< reco::MuonCollection > const m_muonToken
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L3MuonCandidateProducerFromMuons(const edm::ParameterSet &)
constructor with config
fixed size matrix
HLT enums.
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
produce candidates
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector