Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-31 03:10:53

0001 //
0002 // modified & integrated by Giovanni Abbiendi
0003 // from code by Arun Luthra:
0004 // UserCode/luthra/MuonTrackSelector/src/MuonTrackSelector.cc
0005 //
0006 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
0007 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
0008 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0009 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0010 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0011 #include "DataFormats/MuonReco/interface/Muon.h"
0012 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0013 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0014 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0015 #include "DataFormats/TrackReco/interface/Track.h"
0016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0017 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/global/EDProducer.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 #include <algorithm>
0024 #include <sstream>
0025 #include <memory>
0026 
0027 class MuonTrackProducer : public edm::global::EDProducer<> {
0028 public:
0029   explicit MuonTrackProducer(const edm::ParameterSet &);
0030 
0031 private:
0032   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0033 
0034   edm::EDGetTokenT<reco::MuonCollection> muonsToken;
0035   edm::EDGetTokenT<DTRecSegment4DCollection> inputDTRecSegment4DToken_;
0036   edm::EDGetTokenT<CSCSegmentCollection> inputCSCSegmentToken_;
0037   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
0038 
0039   std::vector<std::string> selectionTags;
0040   std::string trackType;
0041   bool ignoreMissingMuonCollection;
0042 };
0043 
0044 MuonTrackProducer::MuonTrackProducer(const edm::ParameterSet &parset)
0045     : muonsToken(consumes<reco::MuonCollection>(parset.getParameter<edm::InputTag>("muonsTag"))),
0046       inputDTRecSegment4DToken_(
0047           consumes<DTRecSegment4DCollection>(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection"))),
0048       inputCSCSegmentToken_(
0049           consumes<CSCSegmentCollection>(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection"))),
0050       ttopoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>()),
0051       selectionTags(parset.getParameter<std::vector<std::string>>("selectionTags")),
0052       trackType(parset.getParameter<std::string>("trackType")),
0053       ignoreMissingMuonCollection(parset.getUntrackedParameter<bool>("ignoreMissingMuonCollection", false)) {
0054   edm::LogVerbatim("MuonTrackProducer") << "constructing  MuonTrackProducer" << parset.dump();
0055   produces<reco::TrackCollection>();
0056   produces<reco::TrackExtraCollection>();
0057   produces<TrackingRecHitCollection>();
0058 }
0059 
0060 void MuonTrackProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0061   edm::Handle<reco::MuonCollection> muonCollectionH = iEvent.getHandle(muonsToken);
0062   if (ignoreMissingMuonCollection && !muonCollectionH.isValid())
0063     edm::LogVerbatim("MuonTrackProducer") << "\n ignoring missing muon collection.";
0064 
0065   else {
0066     const DTRecSegment4DCollection &dtSegmentCollection = iEvent.get(inputDTRecSegment4DToken_);
0067     const CSCSegmentCollection &cscSegmentCollection = iEvent.get(inputCSCSegmentToken_);
0068 
0069     const TrackerTopology &ttopo = iSetup.getData(ttopoToken_);
0070 
0071     std::unique_ptr<reco::TrackCollection> selectedTracks(new reco::TrackCollection);
0072     std::unique_ptr<reco::TrackExtraCollection> selectedTrackExtras(new reco::TrackExtraCollection());
0073     std::unique_ptr<TrackingRecHitCollection> selectedTrackHits(new TrackingRecHitCollection());
0074 
0075     reco::TrackRefProd rTracks = iEvent.getRefBeforePut<reco::TrackCollection>();
0076     reco::TrackExtraRefProd rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
0077     TrackingRecHitRefProd rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
0078 
0079     edm::Ref<reco::TrackExtraCollection>::key_type idx = 0;
0080     edm::Ref<reco::TrackExtraCollection>::key_type hidx = 0;
0081 
0082     edm::LogVerbatim("MuonTrackProducer") << "\nThere are " << dtSegmentCollection.size() << " DT segments.";
0083     unsigned int index_dt_segment = 0;
0084     for (DTRecSegment4DCollection::const_iterator segment = dtSegmentCollection.begin();
0085          segment != dtSegmentCollection.end();
0086          ++segment, index_dt_segment++) {
0087       LocalPoint segmentLocalPosition = segment->localPosition();
0088       LocalVector segmentLocalDirection = segment->localDirection();
0089       LocalError segmentLocalPositionError = segment->localPositionError();
0090       LocalError segmentLocalDirectionError = segment->localDirectionError();
0091       DetId geoid = segment->geographicalId();
0092       DTChamberId dtdetid = DTChamberId(geoid);
0093       int wheel = dtdetid.wheel();
0094       int station = dtdetid.station();
0095       int sector = dtdetid.sector();
0096 
0097       float segmentX = segmentLocalPosition.x();
0098       float segmentY = segmentLocalPosition.y();
0099       float segmentdXdZ = segmentLocalDirection.x() / segmentLocalDirection.z();
0100       float segmentdYdZ = segmentLocalDirection.y() / segmentLocalDirection.z();
0101       float segmentXerr = sqrt(segmentLocalPositionError.xx());
0102       float segmentYerr = sqrt(segmentLocalPositionError.yy());
0103       float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
0104       float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
0105 
0106       edm::LogVerbatim("MuonTrackProducer")
0107           << "\nDT segment index :" << index_dt_segment << "\nchamber Wh:" << wheel << ",St:" << station
0108           << ",Se:" << sector << "\nLocal Position (X,Y)=(" << segmentX << "," << segmentY << ") +/- (" << segmentXerr
0109           << "," << segmentYerr << "), "
0110           << "Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr << ","
0111           << segmentdYdZerr << ")";
0112     }
0113 
0114     edm::LogVerbatim("MuonTrackProducer") << "\nThere are " << cscSegmentCollection.size() << " CSC segments.";
0115     unsigned int index_csc_segment = 0;
0116     for (CSCSegmentCollection::const_iterator segment = cscSegmentCollection.begin();
0117          segment != cscSegmentCollection.end();
0118          ++segment, index_csc_segment++) {
0119       LocalPoint segmentLocalPosition = segment->localPosition();
0120       LocalVector segmentLocalDirection = segment->localDirection();
0121       LocalError segmentLocalPositionError = segment->localPositionError();
0122       LocalError segmentLocalDirectionError = segment->localDirectionError();
0123 
0124       DetId geoid = segment->geographicalId();
0125       CSCDetId cscdetid = CSCDetId(geoid);
0126       int endcap = cscdetid.endcap();
0127       int station = cscdetid.station();
0128       int ring = cscdetid.ring();
0129       int chamber = cscdetid.chamber();
0130 
0131       float segmentX = segmentLocalPosition.x();
0132       float segmentY = segmentLocalPosition.y();
0133       float segmentdXdZ = segmentLocalDirection.x() / segmentLocalDirection.z();
0134       float segmentdYdZ = segmentLocalDirection.y() / segmentLocalDirection.z();
0135       float segmentXerr = sqrt(segmentLocalPositionError.xx());
0136       float segmentYerr = sqrt(segmentLocalPositionError.yy());
0137       float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
0138       float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
0139 
0140       edm::LogVerbatim("MuonTrackProducer")
0141           << "\nCSC segment index :" << index_csc_segment << "\nchamber Endcap:" << endcap << ",St:" << station
0142           << ",Ri:" << ring << ",Ch:" << chamber << "\nLocal Position (X,Y)=(" << segmentX << "," << segmentY
0143           << ") +/- (" << segmentXerr << "," << segmentYerr << "), "
0144           << "Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- (" << segmentdXdZerr << ","
0145           << segmentdYdZerr << ")";
0146     }
0147 
0148     edm::LogVerbatim("MuonTrackProducer") << "\nThere are " << muonCollectionH->size() << " reco::Muons.";
0149     unsigned int muon_index = 0;
0150     for (reco::MuonCollection::const_iterator muon = muonCollectionH->begin(); muon != muonCollectionH->end();
0151          ++muon, muon_index++) {
0152       edm::LogVerbatim("MuonTrackProducer") << "\n******* muon index : " << muon_index;
0153 
0154       const bool isGoodResult =
0155           std::all_of(selectionTags.begin(), selectionTags.end(), [&muon](const std::string &name) {
0156             muon::SelectionType muonType = muon::selectionTypeFromString(name);
0157             return muon::isGoodMuon(*muon, muonType);
0158           });
0159 
0160       if (isGoodResult) {
0161         // new copy of Track
0162         reco::TrackRef trackref;
0163         bool addMatchedMuonSegments = false;
0164 
0165         if (trackType == "innerTrack") {
0166           if (muon->innerTrack().isNonnull())
0167             trackref = muon->innerTrack();
0168           else
0169             continue;
0170         } else if (trackType == "outerTrack") {
0171           if (muon->outerTrack().isNonnull())
0172             trackref = muon->outerTrack();
0173           else
0174             continue;
0175         } else if (trackType == "globalTrack") {
0176           if (muon->globalTrack().isNonnull())
0177             trackref = muon->globalTrack();
0178           else
0179             continue;
0180         } else if (trackType == "innerTrackPlusSegments") {
0181           if (muon->innerTrack().isNonnull()) {
0182             trackref = muon->innerTrack();
0183             addMatchedMuonSegments = true;
0184           } else
0185             continue;
0186         } else if (trackType == "rpcMuonTrack") {
0187           if (muon->innerTrack().isNonnull() && muon->isRPCMuon()) {
0188             trackref = muon->innerTrack();
0189           } else
0190             continue;
0191         } else if (trackType == "gemMuonTrack") {
0192           if (muon->innerTrack().isNonnull() && muon->isGEMMuon()) {
0193             trackref = muon->innerTrack();
0194           } else
0195             continue;
0196         } else if (trackType == "me0MuonTrack") {
0197           if (muon->innerTrack().isNonnull() && muon->isME0Muon()) {
0198             trackref = muon->innerTrack();
0199           } else
0200             continue;
0201         } else if (trackType == "tunepTrack") {
0202           if (muon->isGlobalMuon() && muon->tunePMuonBestTrack().isNonnull())
0203             trackref = muon->tunePMuonBestTrack();
0204           else
0205             continue;
0206         } else if (trackType == "pfTrack") {
0207           if (muon->isPFMuon() && muon->muonBestTrack().isNonnull())
0208             trackref = muon->muonBestTrack();
0209           else
0210             continue;
0211         } else if (trackType == "recomuonTrack") {
0212           if (muon->muonBestTrackType() != muon->tunePMuonBestTrackType())
0213             edm::LogVerbatim("MuonTrackProducer") << "\n *** PF != TuneP *** \n" << std::endl;
0214 
0215           edm::LogVerbatim("MuonTrackProducer") << "isGlobal     ? " << muon->isGlobalMuon() << std::endl;
0216           edm::LogVerbatim("MuonTrackProducer")
0217               << "isTracker    ? " << muon->isTrackerMuon() << ", isRPC ? " << muon->isRPCMuon() << ", isGEM ? "
0218               << muon->isGEMMuon() << ", isME0 ? " << muon->isME0Muon() << std::endl;
0219           edm::LogVerbatim("MuonTrackProducer") << "isStandAlone ? " << muon->isStandAloneMuon() << std::endl;
0220           edm::LogVerbatim("MuonTrackProducer") << "isCalo ? " << muon->isCaloMuon() << std::endl;
0221           edm::LogVerbatim("MuonTrackProducer") << "isPF         ? " << muon->isPFMuon() << std::endl << std::endl;
0222 
0223           edm::LogVerbatim("MuonTrackProducer")
0224               << " enum MuonTrackType {None, InnerTrack, OuterTrack, CombinedTrack, TPFMS, Picky, DYT }" << std::endl;
0225 
0226           edm::LogVerbatim("MuonTrackProducer")
0227               << "(muon) pt =   " << muon->pt() << ", eta = " << muon->eta() << ", phi = " << muon->phi() << std::endl;
0228 
0229           if (muon->muonBestTrack().isNonnull())
0230             edm::LogVerbatim("MuonTrackProducer")
0231                 << "(best) pt =   " << muon->muonBestTrack()->pt() << ", eta = " << muon->muonBestTrack()->eta()
0232                 << ", phi = " << muon->muonBestTrack()->phi()
0233                 << ", N mu hits = " << muon->muonBestTrack()->hitPattern().numberOfValidMuonHits()
0234                 << ", N trk hits = " << muon->muonBestTrack()->hitPattern().numberOfValidTrackerHits()
0235                 << ", MuonTrackType = " << muon->muonBestTrackType() << std::endl;
0236           if (muon->tunePMuonBestTrack().isNonnull())
0237             edm::LogVerbatim("MuonTrackProducer")
0238                 << "(tuneP) pt =  " << muon->tunePMuonBestTrack()->pt()
0239                 << ", eta = " << muon->tunePMuonBestTrack()->eta() << ", phi = " << muon->tunePMuonBestTrack()->phi()
0240                 << ", N mu hits = " << muon->tunePMuonBestTrack()->hitPattern().numberOfValidMuonHits()
0241                 << ", N trk hits = " << muon->tunePMuonBestTrack()->hitPattern().numberOfValidTrackerHits()
0242                 << ", MuonTrackType = " << muon->tunePMuonBestTrackType() << std::endl;
0243           if (muon->innerTrack().isNonnull())
0244             edm::LogVerbatim("MuonTrackProducer")
0245                 << "(inner) pt =  " << muon->innerTrack()->pt() << ", eta = " << muon->innerTrack()->eta()
0246                 << ", phi = " << muon->innerTrack()->phi()
0247                 << ", N trk hits = " << muon->innerTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
0248           if (muon->globalTrack().isNonnull())
0249             edm::LogVerbatim("MuonTrackProducer")
0250                 << "(global) pt = " << muon->globalTrack()->pt() << ", eta = " << muon->globalTrack()->eta()
0251                 << ", phi = " << muon->globalTrack()->phi()
0252                 << ", N mu hits = " << muon->globalTrack()->hitPattern().numberOfValidMuonHits()
0253                 << ", N trk hits = " << muon->globalTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
0254           if (muon->outerTrack().isNonnull())
0255             edm::LogVerbatim("MuonTrackProducer")
0256                 << "(outer) pt =  " << muon->outerTrack()->pt() << ", eta = " << muon->outerTrack()->eta()
0257                 << ", phi = " << muon->outerTrack()->phi()
0258                 << ", N mu hits = " << muon->outerTrack()->hitPattern().numberOfValidMuonHits() << std::endl;
0259           if (muon->tpfmsTrack().isNonnull())
0260             edm::LogVerbatim("MuonTrackProducer")
0261                 << "(tpfms) pt =  " << muon->tpfmsTrack()->pt() << ", eta = " << muon->tpfmsTrack()->eta()
0262                 << ", phi = " << muon->tpfmsTrack()->phi()
0263                 << ", N mu hits = " << muon->tpfmsTrack()->hitPattern().numberOfValidMuonHits()
0264                 << ", N trk hits = " << muon->tpfmsTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
0265           if (muon->pickyTrack().isNonnull())
0266             edm::LogVerbatim("MuonTrackProducer")
0267                 << "(picky) pt =  " << muon->pickyTrack()->pt() << ", eta = " << muon->pickyTrack()->eta()
0268                 << ", phi = " << muon->pickyTrack()->phi()
0269                 << ", N mu hits = " << muon->pickyTrack()->hitPattern().numberOfValidMuonHits()
0270                 << ", N trk hits = " << muon->pickyTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
0271           if (muon->dytTrack().isNonnull())
0272             edm::LogVerbatim("MuonTrackProducer")
0273                 << "(dyt) pt =    " << muon->dytTrack()->pt() << ", eta = " << muon->dytTrack()->eta()
0274                 << ", phi = " << muon->dytTrack()->phi()
0275                 << ", N mu hits = " << muon->dytTrack()->hitPattern().numberOfValidMuonHits()
0276                 << ", N trk hits = " << muon->dytTrack()->hitPattern().numberOfValidTrackerHits() << std::endl;
0277 
0278           if (muon->isGlobalMuon() && muon->globalTrack()->hitPattern().numberOfValidMuonHits() > 0)
0279             trackref = muon->globalTrack();
0280           else if (muon->isTrackerMuon()) {
0281             trackref = muon->innerTrack();
0282             addMatchedMuonSegments = true;
0283           } else if (muon->isPFMuon())
0284             trackref = muon->muonBestTrack();
0285           else if (muon->isStandAloneMuon())
0286             trackref = muon->outerTrack();
0287           else if (muon->isRPCMuon())
0288             trackref = muon->innerTrack();
0289           else if (muon->isGEMMuon())
0290             trackref = muon->innerTrack();
0291           else if (muon->isME0Muon())
0292             trackref = muon->innerTrack();
0293           else
0294             trackref = muon->muonBestTrack();
0295         }
0296 
0297         edm::LogVerbatim("MuonTrackProducer") << "\t *** Selected *** ";
0298         const reco::Track *trk = &(*trackref);
0299         // pointer to old track:
0300         std::unique_ptr<reco::Track> newTrk(new reco::Track(*trk));
0301 
0302         newTrk->setExtra(reco::TrackExtraRef(rTrackExtras, idx++));
0303         PropagationDirection seedDir = trk->seedDirection();
0304         // new copy of track Extras
0305         std::unique_ptr<reco::TrackExtra> newExtra(new reco::TrackExtra(trk->outerPosition(),
0306                                                                         trk->outerMomentum(),
0307                                                                         trk->outerOk(),
0308                                                                         trk->innerPosition(),
0309                                                                         trk->innerMomentum(),
0310                                                                         trk->innerOk(),
0311                                                                         trk->outerStateCovariance(),
0312                                                                         trk->outerDetId(),
0313                                                                         trk->innerStateCovariance(),
0314                                                                         trk->innerDetId(),
0315                                                                         seedDir));
0316 
0317         // new copy of the silicon hits; add hit refs to Extra and hits to hit
0318         // collection
0319 
0320         //      edm::LogVerbatim("MuonTrackProducer")<<"\n printing initial
0321         //      hit_pattern"; trk->hitPattern().print();
0322         unsigned int nHitsToAdd = 0;
0323         for (trackingRecHit_iterator iHit = trk->recHitsBegin(); iHit != trk->recHitsEnd(); iHit++) {
0324           TrackingRecHit *hit = (*iHit)->clone();
0325           selectedTrackHits->push_back(hit);
0326           ++nHitsToAdd;
0327         }
0328 
0329         if (addMatchedMuonSegments) {
0330           int wheel, station, sector;
0331           int endcap, /*station, */ ring, chamber;
0332 
0333           edm::LogVerbatim("MuonTrackProducer")
0334               << "Number of chambers: " << muon->matches().size()
0335               << ", arbitrated: " << muon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
0336           unsigned int index_chamber = 0;
0337 
0338           for (std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0339                chamberMatch != muon->matches().end();
0340                ++chamberMatch, index_chamber++) {
0341             std::stringstream chamberStr;
0342             chamberStr << "\nchamber index: " << index_chamber;
0343 
0344             int subdet = chamberMatch->detector();
0345             DetId did = chamberMatch->id;
0346 
0347             if (subdet == MuonSubdetId::DT) {
0348               DTChamberId dtdetid = DTChamberId(did);
0349               wheel = dtdetid.wheel();
0350               station = dtdetid.station();
0351               sector = dtdetid.sector();
0352               chamberStr << ", DT chamber Wh:" << wheel << ",St:" << station << ",Se:" << sector;
0353             } else if (subdet == MuonSubdetId::CSC) {
0354               CSCDetId cscdetid = CSCDetId(did);
0355               endcap = cscdetid.endcap();
0356               station = cscdetid.station();
0357               ring = cscdetid.ring();
0358               chamber = cscdetid.chamber();
0359               chamberStr << ", CSC chamber End:" << endcap << ",St:" << station << ",Ri:" << ring << ",Ch:" << chamber;
0360             }
0361 
0362             chamberStr << ", Number of segments: " << chamberMatch->segmentMatches.size();
0363             edm::LogVerbatim("MuonTrackProducer") << chamberStr.str();
0364 
0365             unsigned int index_segment = 0;
0366 
0367             for (std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch =
0368                      chamberMatch->segmentMatches.begin();
0369                  segmentMatch != chamberMatch->segmentMatches.end();
0370                  ++segmentMatch, index_segment++) {
0371               float segmentX = segmentMatch->x;
0372               float segmentY = segmentMatch->y;
0373               float segmentdXdZ = segmentMatch->dXdZ;
0374               float segmentdYdZ = segmentMatch->dYdZ;
0375               float segmentXerr = segmentMatch->xErr;
0376               float segmentYerr = segmentMatch->yErr;
0377               float segmentdXdZerr = segmentMatch->dXdZErr;
0378               float segmentdYdZerr = segmentMatch->dYdZErr;
0379 
0380               CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
0381               DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
0382 
0383               bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) &&
0384                                             segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
0385 
0386               std::string ARBITRATED(" ***Arbitrated Off*** ");
0387               if (segment_arbitrated_Ok)
0388                 ARBITRATED = " ***ARBITRATED OK*** ";
0389 
0390               if (subdet == MuonSubdetId::DT) {
0391                 edm::LogVerbatim("MuonTrackProducer")
0392                     << "\n\t segment index: " << index_segment << ARBITRATED << "\n\t  Local Position (X,Y)=("
0393                     << segmentX << "," << segmentY << ") +/- (" << segmentXerr << "," << segmentYerr << "), "
0394                     << "\n\t  Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- ("
0395                     << segmentdXdZerr << "," << segmentdYdZerr << ")";
0396 
0397                 if (!segment_arbitrated_Ok)
0398                   continue;
0399 
0400                 if (segmentDT.get() != nullptr) {
0401                   const DTRecSegment4D *segment = segmentDT.get();
0402 
0403                   edm::LogVerbatim("MuonTrackProducer")
0404                       << "\t ===> MATCHING with DT segment with index = " << segmentDT.key();
0405 
0406                   if (segment->hasPhi()) {
0407                     const DTChamberRecSegment2D *phiSeg = segment->phiSegment();
0408                     std::vector<const TrackingRecHit *> phiHits = phiSeg->recHits();
0409                     for (std::vector<const TrackingRecHit *>::const_iterator ihit = phiHits.begin();
0410                          ihit != phiHits.end();
0411                          ++ihit) {
0412                       TrackingRecHit *seghit = (*ihit)->clone();
0413                       newTrk->appendHitPattern(*seghit, ttopo);
0414                       //            edm::LogVerbatim("MuonTrackProducer")<<"hit
0415                       // pattern for position "<<index_hit<<" set to:";
0416                       //            newTrk->hitPattern().printHitPattern(index_hit,
0417                       // std::cout);
0418                       selectedTrackHits->push_back(seghit);
0419                       ++nHitsToAdd;
0420                     }
0421                   }
0422 
0423                   if (segment->hasZed()) {
0424                     const DTSLRecSegment2D *zSeg = (*segment).zSegment();
0425                     std::vector<const TrackingRecHit *> zedHits = zSeg->recHits();
0426                     for (std::vector<const TrackingRecHit *>::const_iterator ihit = zedHits.begin();
0427                          ihit != zedHits.end();
0428                          ++ihit) {
0429                       TrackingRecHit *seghit = (*ihit)->clone();
0430                       newTrk->appendHitPattern(*seghit, ttopo);
0431                       //            edm::LogVerbatim("MuonTrackProducer")<<"hit
0432                       // pattern for position "<<index_hit<<" set to:";
0433                       //            newTrk->hitPattern().printHitPattern(index_hit,
0434                       // std::cout);
0435                       selectedTrackHits->push_back(seghit);
0436                       ++nHitsToAdd;
0437                     }
0438                   }
0439                 } else
0440                   edm::LogWarning("MuonTrackProducer") << "\n***WARNING: UNMATCHED DT segment ! \n";
0441               }  // if (subdet == MuonSubdetId::DT)
0442 
0443               else if (subdet == MuonSubdetId::CSC) {
0444                 edm::LogVerbatim("MuonTrackProducer")
0445                     << "\n\t segment index: " << index_segment << ARBITRATED << "\n\t  Local Position (X,Y)=("
0446                     << segmentX << "," << segmentY << ") +/- (" << segmentXerr << "," << segmentYerr << "), "
0447                     << "\n\t  Local Direction (dXdZ,dYdZ)=(" << segmentdXdZ << "," << segmentdYdZ << ") +/- ("
0448                     << segmentdXdZerr << "," << segmentdYdZerr << ")";
0449 
0450                 if (!segment_arbitrated_Ok)
0451                   continue;
0452 
0453                 if (segmentCSC.get() != nullptr) {
0454                   const CSCSegment *segment = segmentCSC.get();
0455 
0456                   edm::LogVerbatim("MuonTrackProducer")
0457                       << "\t ===> MATCHING with CSC segment with index = " << segmentCSC.key();
0458 
0459                   std::vector<const TrackingRecHit *> hits = segment->recHits();
0460                   for (std::vector<const TrackingRecHit *>::const_iterator ihit = hits.begin(); ihit != hits.end();
0461                        ++ihit) {
0462                     TrackingRecHit *seghit = (*ihit)->clone();
0463                     newTrk->appendHitPattern(*seghit, ttopo);
0464                     //          edm::LogVerbatim("MuonTrackProducer")<<"hit
0465                     // pattern for position "<<index_hit<<" set to:";
0466                     //          newTrk->hitPattern().printHitPattern(index_hit,
0467                     // std::cout);
0468                     selectedTrackHits->push_back(seghit);
0469                     ++nHitsToAdd;
0470                   }
0471                 } else
0472                   edm::LogWarning("MuonTrackProducer") << "\n***WARNING: UNMATCHED CSC segment ! \n";
0473               }  //  else if (subdet == MuonSubdetId::CSC)
0474 
0475             }  // loop on vector<MuonSegmentMatch>
0476           }    // loop on vector<MuonChamberMatch>
0477         }      // if (trackType == "innerTrackPlusSegments")
0478 
0479         //      edm::LogVerbatim("MuonTrackProducer")<<"\n printing final
0480         //      hit_pattern"; newTrk->hitPattern().print();
0481 
0482         newExtra->setHits(rHits, hidx, nHitsToAdd);
0483         hidx += nHitsToAdd;
0484 
0485         selectedTracks->push_back(*newTrk);
0486         selectedTrackExtras->push_back(*newExtra);
0487 
0488       }  // if (isGoodResult)
0489     }    // loop on reco::MuonCollection
0490 
0491     iEvent.put(std::move(selectedTracks));
0492     iEvent.put(std::move(selectedTrackExtras));
0493     iEvent.put(std::move(selectedTrackHits));
0494   }
0495 }
0496 
0497 #include "FWCore/Framework/interface/MakerMacros.h"
0498 #include "FWCore/PluginManager/interface/ModuleDef.h"
0499 DEFINE_FWK_MODULE(MuonTrackProducer);