CMS 3D CMS Logo

L3MuonCandidateProducer.cc
Go to the documentation of this file.
1 
18 // Framework
24 
26 
28 
29 // Input and output collections
32 
33 #include <string>
34 #include <algorithm>
35 
36 using namespace edm;
37 using namespace std;
38 using namespace reco;
39 
40 static const char category[] = "Muon|RecoMuon|L3MuonCandidateProducer";
41 
44  LogTrace(category) << " constructor called";
45 
46  // StandAlone Collection Label
47  theL3CollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
48  trackToken_ = consumes<reco::TrackCollection>(theL3CollectionLabel);
49 
50  // use links
51  theUseLinks = parameterSet.existsAs<InputTag>("InputLinksObjects");
52  if (theUseLinks) {
53  theL3LinksLabel = parameterSet.getParameter<InputTag>("InputLinksObjects");
54  linkToken_ = consumes<reco::MuonTrackLinksCollection>(theL3LinksLabel);
55  if (theL3LinksLabel.label().empty() or theL3LinksLabel.label() == "unused")
56  theUseLinks = false;
57  }
58 
59  // use global, standalone or tracker pT/4-vector assignment
60  const std::string& muon_track_for_momentum = parameterSet.existsAs<std::string>("MuonPtOption")
61  ? parameterSet.getParameter<std::string>("MuonPtOption")
62  : "Global";
63  if (muon_track_for_momentum == std::string("Tracker"))
64  theType = InnerTrack;
65  else if (muon_track_for_momentum == std::string("Standalone"))
66  theType = OuterTrack;
67  else if (muon_track_for_momentum == std::string("Global"))
68  theType = CombinedTrack;
69  else {
70  LogError(category) << "invalid value for MuonPtOption, please choose among 'Tracker', 'Standalone', 'Global'";
71  theType = CombinedTrack;
72  }
73 
74  produces<RecoChargedCandidateCollection>();
75 }
76 
79  LogTrace(category) << " L3MuonCandidateProducer destructor called";
80 }
81 
84  // Take the L3 container
85  LogTrace(category) << " Taking the L3/GLB muons: " << theL3CollectionLabel.label();
87  event.getByToken(trackToken_, tracks);
88 
90  if (theUseLinks)
91  event.getByToken(linkToken_, links);
92 
93  // Create a RecoChargedCandidate collection
94  LogTrace(category) << " Creating the RecoChargedCandidate collection";
95  auto candidates = std::make_unique<RecoChargedCandidateCollection>();
96  LogDebug(category) << " size = " << tracks->size();
97  for (unsigned int i = 0; i < tracks->size(); i++) {
98  TrackRef inRef(tracks, i);
99  TrackRef tkRef = TrackRef();
100 
101  if (theUseLinks) {
102  for (reco::MuonTrackLinksCollection::const_iterator link = links->begin(); link != links->end(); ++link) {
103  LogDebug(category) << " i = " << i;
104 
105  if (not link->trackerTrack().isNull())
106  LogTrace(category) << " link tk pt " << link->trackerTrack()->pt();
107  if (not link->standAloneTrack().isNull())
108  LogTrace(category) << " sta pt " << link->standAloneTrack()->pt();
109  if (not link->globalTrack().isNull())
110  LogTrace(category) << " global pt " << link->globalTrack()->pt();
111  if (not inRef.isNull())
112  LogTrace(category) << " inRef pt " << inRef->pt();
113 
114  if (link->globalTrack().isNull()) {
115  edm::LogError(category) << "null reference to the global track";
116  // skip this candidate
117  continue;
118  }
119 
120  float dR = deltaR(inRef->eta(), inRef->phi(), link->globalTrack()->eta(), link->globalTrack()->phi());
121  float dPt = abs(inRef->pt() - link->globalTrack()->pt()) / inRef->pt();
122  if (dR < 0.02 and dPt < 0.001) {
123  LogTrace(category) << " *** pt matches *** ";
124  switch (theType) {
125  case InnerTrack:
126  tkRef = link->trackerTrack();
127  break;
128  case OuterTrack:
129  tkRef = link->standAloneTrack();
130  break;
131  case CombinedTrack:
132  tkRef = link->globalTrack();
133  break;
134  default:
135  tkRef = link->globalTrack();
136  break;
137  }
138  }
139  }
140  if (tkRef.isNull()) {
141  edm::LogWarning(category) << "null reference to the linked track, reverting to old behaviour";
142  tkRef = inRef;
143  }
144  } else {
145  // theUseLinks is false
146  tkRef = inRef;
147  }
148  LogDebug(category) << "tkRef Used For Momentum pt " << tkRef->pt() << " inRef from the input collection pt "
149  << inRef->pt();
150 
151  Particle::Charge q = tkRef->charge();
152  Particle::LorentzVector p4(tkRef->px(), tkRef->py(), tkRef->pz(), tkRef->p());
153  Particle::Point vtx(tkRef->vx(), tkRef->vy(), tkRef->vz());
154 
155  int pid = 13;
156  if (abs(q) == 1)
157  pid = q < 0 ? 13 : -13;
158  else
159  LogWarning(category) << "L3MuonCandidate has charge = " << q;
160  RecoChargedCandidate cand(q, p4, vtx, pid);
161 
162  //set the inRef as the RecoChargedCandidate ref so that the isolation maps
163  //work in downstream filters
164  cand.setTrack(inRef);
165  candidates->push_back(cand);
166  }
167 
168  event.put(std::move(candidates));
169 
170  LogTrace(category) << " Event loaded"
171  << "================================";
172 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const char category[]
L3MuonCandidateProducer(const edm::ParameterSet &)
constructor with config
~L3MuonCandidateProducer() override
destructor
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
Log< level::Error, false > LogError
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
#define LogTrace(id)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isNull() const
Checks for null.
Definition: Ref.h:235
auto const & tracks
cannot be loose
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
fixed size matrix
HLT enums.
Log< level::Warning, false > LogWarning
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
produce candidates
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector
#define LogDebug(id)