46 inputDTRecSegment4DToken_(
48 inputCSCSegmentToken_(
55 produces<reco::TrackCollection>();
56 produces<reco::TrackExtraCollection>();
57 produces<TrackingRecHitCollection>();
63 edm::LogVerbatim(
"MuonTrackProducer") <<
"\n ignoring missing muon collection.";
82 edm::LogVerbatim(
"MuonTrackProducer") <<
"\nThere are " << dtSegmentCollection.size() <<
" DT segments.";
83 unsigned int index_dt_segment = 0;
85 segment != dtSegmentCollection.end();
86 ++segment, index_dt_segment++) {
87 LocalPoint segmentLocalPosition = segment->localPosition();
88 LocalVector segmentLocalDirection = segment->localDirection();
89 LocalError segmentLocalPositionError = segment->localPositionError();
90 LocalError segmentLocalDirectionError = segment->localDirectionError();
91 DetId geoid = segment->geographicalId();
95 int sector = dtdetid.
sector();
97 float segmentX = segmentLocalPosition.
x();
98 float segmentY = segmentLocalPosition.
y();
99 float segmentdXdZ = segmentLocalDirection.
x() / segmentLocalDirection.
z();
100 float segmentdYdZ = segmentLocalDirection.
y() / segmentLocalDirection.
z();
101 float segmentXerr =
sqrt(segmentLocalPositionError.
xx());
102 float segmentYerr =
sqrt(segmentLocalPositionError.
yy());
103 float segmentdXdZerr =
sqrt(segmentLocalDirectionError.
xx());
104 float segmentdYdZerr =
sqrt(segmentLocalDirectionError.
yy());
107 <<
"\nDT segment index :" << index_dt_segment <<
"\nchamber Wh:" <<
wheel <<
",St:" <<
station
108 <<
",Se:" << sector <<
"\nLocal Position (X,Y)=(" << segmentX <<
"," << segmentY <<
") +/- (" << segmentXerr
109 <<
"," << segmentYerr <<
"), "
110 <<
"Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ <<
"," << segmentdYdZ <<
") +/- (" << segmentdXdZerr <<
","
111 << segmentdYdZerr <<
")";
114 edm::LogVerbatim(
"MuonTrackProducer") <<
"\nThere are " << cscSegmentCollection.size() <<
" CSC segments.";
115 unsigned int index_csc_segment = 0;
117 segment != cscSegmentCollection.end();
118 ++segment, index_csc_segment++) {
119 LocalPoint segmentLocalPosition = segment->localPosition();
120 LocalVector segmentLocalDirection = segment->localDirection();
121 LocalError segmentLocalPositionError = segment->localPositionError();
122 LocalError segmentLocalDirectionError = segment->localDirectionError();
124 DetId geoid = segment->geographicalId();
131 float segmentX = segmentLocalPosition.
x();
132 float segmentY = segmentLocalPosition.
y();
133 float segmentdXdZ = segmentLocalDirection.
x() / segmentLocalDirection.
z();
134 float segmentdYdZ = segmentLocalDirection.
y() / segmentLocalDirection.
z();
135 float segmentXerr =
sqrt(segmentLocalPositionError.
xx());
136 float segmentYerr =
sqrt(segmentLocalPositionError.
yy());
137 float segmentdXdZerr =
sqrt(segmentLocalDirectionError.
xx());
138 float segmentdYdZerr =
sqrt(segmentLocalDirectionError.
yy());
141 <<
"\nCSC segment index :" << index_csc_segment <<
"\nchamber Endcap:" <<
endcap <<
",St:" <<
station
142 <<
",Ri:" <<
ring <<
",Ch:" <<
chamber <<
"\nLocal Position (X,Y)=(" << segmentX <<
"," << segmentY
143 <<
") +/- (" << segmentXerr <<
"," << segmentYerr <<
"), "
144 <<
"Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ <<
"," << segmentdYdZ <<
") +/- (" << segmentdXdZerr <<
","
145 << segmentdYdZerr <<
")";
148 edm::LogVerbatim(
"MuonTrackProducer") <<
"\nThere are " << muonCollectionH->size() <<
" reco::Muons.";
149 unsigned int muon_index = 0;
150 for (reco::MuonCollection::const_iterator
muon = muonCollectionH->begin();
muon != muonCollectionH->end();
151 ++
muon, muon_index++) {
152 edm::LogVerbatim(
"MuonTrackProducer") <<
"\n******* muon index : " << muon_index;
154 const bool isGoodResult =
163 bool addMatchedMuonSegments =
false;
166 if (
muon->innerTrack().isNonnull())
167 trackref =
muon->innerTrack();
171 if (
muon->outerTrack().isNonnull())
172 trackref =
muon->outerTrack();
176 if (
muon->globalTrack().isNonnull())
177 trackref =
muon->globalTrack();
180 }
else if (
trackType ==
"innerTrackPlusSegments") {
181 if (
muon->innerTrack().isNonnull()) {
182 trackref =
muon->innerTrack();
183 addMatchedMuonSegments =
true;
186 }
else if (
trackType ==
"rpcMuonTrack") {
187 if (
muon->innerTrack().isNonnull() &&
muon->isRPCMuon()) {
188 trackref =
muon->innerTrack();
191 }
else if (
trackType ==
"gemMuonTrack") {
192 if (
muon->innerTrack().isNonnull() &&
muon->isGEMMuon()) {
193 trackref =
muon->innerTrack();
196 }
else if (
trackType ==
"me0MuonTrack") {
197 if (
muon->innerTrack().isNonnull() &&
muon->isME0Muon()) {
198 trackref =
muon->innerTrack();
202 if (
muon->isGlobalMuon() &&
muon->tunePMuonBestTrack().isNonnull())
203 trackref =
muon->tunePMuonBestTrack();
207 if (
muon->isPFMuon() &&
muon->muonBestTrack().isNonnull())
208 trackref =
muon->muonBestTrack();
211 }
else if (
trackType ==
"recomuonTrack") {
212 if (
muon->isGlobalMuon())
213 trackref =
muon->globalTrack();
214 else if (
muon->isTrackerMuon()) {
215 trackref =
muon->innerTrack();
216 addMatchedMuonSegments =
true;
217 }
else if (
muon->isStandAloneMuon())
218 trackref =
muon->outerTrack();
219 else if (
muon->isRPCMuon())
220 trackref =
muon->innerTrack();
221 else if (
muon->isGEMMuon())
222 trackref =
muon->innerTrack();
223 else if (
muon->isME0Muon())
224 trackref =
muon->innerTrack();
226 trackref =
muon->muonBestTrack();
228 if (
muon->muonBestTrackType() !=
muon->tunePMuonBestTrackType())
229 edm::LogVerbatim(
"MuonTrackProducer") <<
"\n *** PF != TuneP *** \n" << std::endl;
233 <<
"isTracker ? " <<
muon->isTrackerMuon() <<
", isRPC ? " <<
muon->isRPCMuon() <<
", isGEM ? "
234 <<
muon->isGEMMuon() <<
", isME0 ? " <<
muon->isME0Muon() << std::endl;
235 edm::LogVerbatim(
"MuonTrackProducer") <<
"isStandAlone ? " <<
muon->isStandAloneMuon() << std::endl;
237 edm::LogVerbatim(
"MuonTrackProducer") <<
"isPF ? " <<
muon->isPFMuon() << std::endl << std::endl;
240 <<
" enum MuonTrackType {None, InnerTrack, OuterTrack, CombinedTrack, TPFMS, Picky, DYT }" << std::endl;
243 <<
"(muon) pt = " <<
muon->pt() <<
", eta = " <<
muon->eta() <<
", phi = " <<
muon->phi() << std::endl;
245 if (
muon->muonBestTrack().isNonnull())
247 <<
"(best) pt = " <<
muon->muonBestTrack()->pt() <<
", eta = " <<
muon->muonBestTrack()->eta()
248 <<
", phi = " <<
muon->muonBestTrack()->phi()
249 <<
", N mu hits = " <<
muon->muonBestTrack()->hitPattern().numberOfValidMuonHits()
250 <<
", N trk hits = " <<
muon->muonBestTrack()->hitPattern().numberOfValidTrackerHits()
251 <<
", MuonTrackType = " <<
muon->muonBestTrackType() << std::endl;
252 if (
muon->tunePMuonBestTrack().isNonnull())
254 <<
"(tuneP) pt = " <<
muon->tunePMuonBestTrack()->pt()
255 <<
", eta = " <<
muon->tunePMuonBestTrack()->eta() <<
", phi = " <<
muon->tunePMuonBestTrack()->phi()
256 <<
", N mu hits = " <<
muon->tunePMuonBestTrack()->hitPattern().numberOfValidMuonHits()
257 <<
", N trk hits = " <<
muon->tunePMuonBestTrack()->hitPattern().numberOfValidTrackerHits()
258 <<
", MuonTrackType = " <<
muon->tunePMuonBestTrackType() << std::endl;
259 if (
muon->innerTrack().isNonnull())
261 <<
"(inner) pt = " <<
muon->innerTrack()->pt() <<
", eta = " <<
muon->innerTrack()->eta()
262 <<
", phi = " <<
muon->innerTrack()->phi()
263 <<
", N trk hits = " <<
muon->innerTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
264 if (
muon->globalTrack().isNonnull())
266 <<
"(global) pt = " <<
muon->globalTrack()->pt() <<
", eta = " <<
muon->globalTrack()->eta()
267 <<
", phi = " <<
muon->globalTrack()->phi()
268 <<
", N mu hits = " <<
muon->globalTrack()->hitPattern().numberOfValidMuonHits()
269 <<
", N trk hits = " <<
muon->globalTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
270 if (
muon->outerTrack().isNonnull())
272 <<
"(outer) pt = " <<
muon->outerTrack()->pt() <<
", eta = " <<
muon->outerTrack()->eta()
273 <<
", phi = " <<
muon->outerTrack()->phi()
274 <<
", N mu hits = " <<
muon->outerTrack()->hitPattern().numberOfValidMuonHits() << std::endl;
275 if (
muon->tpfmsTrack().isNonnull())
277 <<
"(tpfms) pt = " <<
muon->tpfmsTrack()->pt() <<
", eta = " <<
muon->tpfmsTrack()->eta()
278 <<
", phi = " <<
muon->tpfmsTrack()->phi()
279 <<
", N mu hits = " <<
muon->tpfmsTrack()->hitPattern().numberOfValidMuonHits()
280 <<
", N trk hits = " <<
muon->tpfmsTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
281 if (
muon->pickyTrack().isNonnull())
283 <<
"(picky) pt = " <<
muon->pickyTrack()->pt() <<
", eta = " <<
muon->pickyTrack()->eta()
284 <<
", phi = " <<
muon->pickyTrack()->phi()
285 <<
", N mu hits = " <<
muon->pickyTrack()->hitPattern().numberOfValidMuonHits()
286 <<
", N trk hits = " <<
muon->pickyTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
287 if (
muon->dytTrack().isNonnull())
289 <<
"(dyt) pt = " <<
muon->dytTrack()->pt() <<
", eta = " <<
muon->dytTrack()->eta()
290 <<
", phi = " <<
muon->dytTrack()->phi()
291 <<
", N mu hits = " <<
muon->dytTrack()->hitPattern().numberOfValidMuonHits()
292 <<
", N trk hits = " <<
muon->dytTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
298 std::unique_ptr<reco::Track> newTrk(
new reco::Track(*trk));
320 unsigned int nHitsToAdd = 0;
323 selectedTrackHits->push_back(
hit);
327 if (addMatchedMuonSegments) {
332 <<
"Number of chambers: " <<
muon->matches().size()
334 unsigned int index_chamber = 0;
336 for (std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch =
muon->matches().begin();
337 chamberMatch !=
muon->matches().end();
338 ++chamberMatch, index_chamber++) {
339 std::stringstream chamberStr;
340 chamberStr <<
"\nchamber index: " << index_chamber;
342 int subdet = chamberMatch->detector();
343 DetId did = chamberMatch->id;
349 sector = dtdetid.
sector();
350 chamberStr <<
", DT chamber Wh:" <<
wheel <<
",St:" <<
station <<
",Se:" << sector;
360 chamberStr <<
", Number of segments: " << chamberMatch->segmentMatches.size();
363 unsigned int index_segment = 0;
365 for (std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch =
366 chamberMatch->segmentMatches.begin();
367 segmentMatch != chamberMatch->segmentMatches.end();
368 ++segmentMatch, index_segment++) {
369 float segmentX = segmentMatch->x;
370 float segmentY = segmentMatch->y;
371 float segmentdXdZ = segmentMatch->dXdZ;
372 float segmentdYdZ = segmentMatch->dYdZ;
373 float segmentXerr = segmentMatch->xErr;
374 float segmentYerr = segmentMatch->yErr;
375 float segmentdXdZerr = segmentMatch->dXdZErr;
376 float segmentdYdZerr = segmentMatch->dYdZErr;
385 if (segment_arbitrated_Ok)
386 ARBITRATED =
" ***ARBITRATED OK*** ";
390 <<
"\n\t segment index: " << index_segment << ARBITRATED <<
"\n\t Local Position (X,Y)=("
391 << segmentX <<
"," << segmentY <<
") +/- (" << segmentXerr <<
"," << segmentYerr <<
"), "
392 <<
"\n\t Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ <<
"," << segmentdYdZ <<
") +/- ("
393 << segmentdXdZerr <<
"," << segmentdYdZerr <<
")";
395 if (!segment_arbitrated_Ok)
398 if (segmentDT.
get() !=
nullptr) {
402 <<
"\t ===> MATCHING with DT segment with index = " << segmentDT.
key();
406 std::vector<const TrackingRecHit *> phiHits = phiSeg->
recHits();
407 for (std::vector<const TrackingRecHit *>::const_iterator ihit = phiHits.begin();
408 ihit != phiHits.end();
411 newTrk->appendHitPattern(*seghit, ttopo);
416 selectedTrackHits->push_back(seghit);
423 std::vector<const TrackingRecHit *> zedHits = zSeg->
recHits();
424 for (std::vector<const TrackingRecHit *>::const_iterator ihit = zedHits.begin();
425 ihit != zedHits.end();
428 newTrk->appendHitPattern(*seghit, ttopo);
433 selectedTrackHits->push_back(seghit);
438 edm::LogWarning(
"MuonTrackProducer") <<
"\n***WARNING: UNMATCHED DT segment ! \n";
443 <<
"\n\t segment index: " << index_segment << ARBITRATED <<
"\n\t Local Position (X,Y)=("
444 << segmentX <<
"," << segmentY <<
") +/- (" << segmentXerr <<
"," << segmentYerr <<
"), "
445 <<
"\n\t Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ <<
"," << segmentdYdZ <<
") +/- ("
446 << segmentdXdZerr <<
"," << segmentdYdZerr <<
")";
448 if (!segment_arbitrated_Ok)
451 if (segmentCSC.
get() !=
nullptr) {
455 <<
"\t ===> MATCHING with CSC segment with index = " << segmentCSC.
key();
457 std::vector<const TrackingRecHit *>
hits = segment->
recHits();
458 for (std::vector<const TrackingRecHit *>::const_iterator ihit =
hits.begin(); ihit !=
hits.end();
461 newTrk->appendHitPattern(*seghit, ttopo);
466 selectedTrackHits->push_back(seghit);
470 edm::LogWarning(
"MuonTrackProducer") <<
"\n***WARNING: UNMATCHED CSC segment ! \n";
480 newExtra->setHits(rHits, hidx, nHitsToAdd);
484 selectedTrackExtras->push_back(*newExtra);