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 }
edm::StreamID
Definition: StreamID.h:30
L3MuonCandidateProducer::L3MuonCandidateProducer
L3MuonCandidateProducer(const edm::ParameterSet &)
constructor with config
Definition: L3MuonCandidateProducer.cc:43
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
L3MuonCandidateProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
produce candidates
Definition: L3MuonCandidateProducer.cc:83
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
data-class-funcs.q
q
Definition: data-class-funcs.py:169
L3MuonCandidateProducer.h
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
L3MuonCandidateProducer::~L3MuonCandidateProducer
~L3MuonCandidateProducer() override
destructor
Definition: L3MuonCandidateProducer.cc:78
edm::Ref< TrackCollection >
deltaR.h
Point
math::XYZPoint Point
Definition: TrackerDpgAnalysis.cc:107
category
static const char category[]
Definition: L3MuonCandidateProducer.cc:40
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
cand
Definition: decayParser.h:34
p4
double p4[4]
Definition: TauolaWrapper.h:92
reco::RecoChargedCandidate
Definition: RecoChargedCandidate.h:15
edm::EventSetup
Definition: EventSetup.h:57
reco::JetExtendedAssociation::LorentzVector
math::PtEtaPhiELorentzVectorF LorentzVector
Definition: JetExtendedAssociation.h:25
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
RecoChargedCandidate.h
HLT_2018_cff.candidates
candidates
Definition: HLT_2018_cff.py:53513
electronStore.links
links
Definition: electronStore.py:149
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
PixelTestBeamValidation_cfi.Charge
Charge
Definition: PixelTestBeamValidation_cfi.py:78
EventSetup.h
or
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
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
RecoChargedCandidateFwd.h
edm::InputTag
Definition: InputTag.h:15