Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:04

0001 #include "CommonTools/RecoAlgos/interface/MuonSelector.h"
0002 
0003 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0004 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0005 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0006 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0007 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0008 
0009 #include <DataFormats/SiStripDetId/interface/SiStripDetId.h>
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 using namespace reco;
0014 
0015 namespace helper {
0016   MuonCollectionStoreManager::MuonCollectionStoreManager(const edm::Handle<reco::MuonCollection> &)
0017       : selMuons_(new reco::MuonCollection),
0018         selTracks_(new reco::TrackCollection),
0019         selTracksExtras_(new reco::TrackExtraCollection),
0020         selTracksHits_(new TrackingRecHitCollection),
0021         selGlobalMuonTracks_(new reco::TrackCollection),
0022         selGlobalMuonTracksExtras_(new reco::TrackExtraCollection),
0023         selGlobalMuonTracksHits_(new TrackingRecHitCollection),
0024         selStandAloneTracks_(new reco::TrackCollection),
0025         selStandAloneTracksExtras_(new reco::TrackExtraCollection),
0026         selStandAloneTracksHits_(new TrackingRecHitCollection),
0027         selStripClusters_(new edmNew::DetSetVector<SiStripCluster>),
0028         selPixelClusters_(new edmNew::DetSetVector<SiPixelCluster>),
0029         rMuons_(),
0030         rTracks_(),
0031         rTrackExtras_(),
0032         rHits_(),
0033         rGBTracks_(),
0034         rGBTrackExtras_(),
0035         rGBHits_(),
0036         rSATracks_(),
0037         rSATrackExtras_(),
0038         rSAHits_(),
0039         clusterStorer_(),
0040         id_(0),
0041         igbd_(0),
0042         isad_(0),
0043         idx_(0),
0044         igbdx_(0),
0045         isadx_(0),
0046         hidx_(0),
0047         higbdx_(0),
0048         hisadx_(0),
0049         cloneClusters_(true) {}
0050 
0051   //------------------------------------------------------------------
0052   //!  Process a single muon.
0053   //------------------------------------------------------------------
0054   void MuonCollectionStoreManager::processMuon(const Muon &mu) {
0055     if (this->cloneClusters() && ((mu.globalTrack().isNonnull() && !this->clusterRefsOK(*mu.globalTrack())) ||
0056                                   (mu.innerTrack().isNonnull() && !this->clusterRefsOK(*mu.innerTrack()))
0057                                   // || (mu.outerTrack(). isNonnull() && !this->clusterRefsOK(*mu.outerTrack() ))
0058                                   )) {  // outer track is muon only and has no strip clusters...
0059       // At least until CMSSW_2_1_8, global muon track reconstruction assigns wrong hits in
0060       // case of a track from iterative tracking. These hits are fetched from Trajectories
0061       // instead of from Tracks and therefore reference temporary cluster collections.
0062       // As a hack we skip these muons here - they can anyway not be refitted.
0063       edm::LogError("BadRef") << "@SUB=MuonCollectionStoreManager::processMuon"
0064                               << "Skip muon: One of its tracks references "
0065                               << "non-available clusters!";
0066       return;
0067     }
0068 
0069     selMuons_->push_back(Muon(mu));
0070     // only tracker Muon Track
0071     selMuons_->back().setInnerTrack(TrackRef(rTracks_, id_++));
0072     TrackRef trkRef = mu.track();
0073     if (trkRef.isNonnull()) {
0074       selTracks_->push_back(Track(*trkRef));
0075 
0076       Track &trk = selTracks_->back();
0077 
0078       selTracksExtras_->push_back(TrackExtra(trk.outerPosition(),
0079                                              trk.outerMomentum(),
0080                                              trk.outerOk(),
0081                                              trk.innerPosition(),
0082                                              trk.innerMomentum(),
0083                                              trk.innerOk(),
0084                                              trk.outerStateCovariance(),
0085                                              trk.outerDetId(),
0086                                              trk.innerStateCovariance(),
0087                                              trk.innerDetId(),
0088                                              trk.seedDirection()));
0089 
0090       TrackExtra &tx = selTracksExtras_->back();
0091 
0092       auto const firstHitIndex = hidx_;
0093       unsigned int nHitsAdded = 0;
0094       for (trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++hit, ++hidx_) {
0095         selTracksHits_->push_back((*hit)->clone());
0096         TrackingRecHit *newHit = &(selTracksHits_->back());
0097         ++nHitsAdded;
0098         if (cloneClusters() && newHit->isValid() && ((*hit)->geographicalId().det() == DetId::Tracker)) {
0099           clusterStorer_.addCluster(*selTracksHits_, hidx_);
0100         }
0101       }  // end of for loop over tracking rec hits on this track
0102       tx.setHits(rHits_, firstHitIndex, nHitsAdded);
0103 
0104       trk.setExtra(TrackExtraRef(rTrackExtras_, idx_++));
0105 
0106     }  // TO trkRef.isNonnull
0107 
0108     // global Muon Track
0109     selMuons_->back().setGlobalTrack(TrackRef(rGBTracks_, igbd_++));
0110     trkRef = mu.combinedMuon();
0111     if (trkRef.isNonnull()) {
0112       selGlobalMuonTracks_->push_back(Track(*trkRef));
0113       Track &trk = selGlobalMuonTracks_->back();
0114 
0115       selGlobalMuonTracksExtras_->push_back(TrackExtra(trk.outerPosition(),
0116                                                        trk.outerMomentum(),
0117                                                        trk.outerOk(),
0118                                                        trk.innerPosition(),
0119                                                        trk.innerMomentum(),
0120                                                        trk.innerOk(),
0121                                                        trk.outerStateCovariance(),
0122                                                        trk.outerDetId(),
0123                                                        trk.innerStateCovariance(),
0124                                                        trk.innerDetId(),
0125                                                        trk.seedDirection()));
0126       TrackExtra &tx = selGlobalMuonTracksExtras_->back();
0127       auto const firstHitIndex = higbdx_;
0128       unsigned int nHitsAdded = 0;
0129       for (trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++hit, ++higbdx_) {
0130         selGlobalMuonTracksHits_->push_back((*hit)->clone());
0131         TrackingRecHit *newHit = &(selGlobalMuonTracksHits_->back());
0132         ++nHitsAdded;
0133         if (cloneClusters() && newHit->isValid() && ((*hit)->geographicalId().det() == DetId::Tracker)) {
0134           clusterStorer_.addCluster(*selGlobalMuonTracksHits_, higbdx_);
0135         }
0136       }
0137       tx.setHits(rGBHits_, firstHitIndex, nHitsAdded);
0138 
0139       trk.setExtra(TrackExtraRef(rGBTrackExtras_, igbdx_++));
0140 
0141     }  // GB trkRef.isNonnull()
0142 
0143     // stand alone Muon Track
0144     selMuons_->back().setOuterTrack(TrackRef(rSATracks_, isad_++));
0145     trkRef = mu.standAloneMuon();
0146     if (trkRef.isNonnull()) {
0147       selStandAloneTracks_->push_back(Track(*trkRef));
0148       Track &trk = selStandAloneTracks_->back();
0149 
0150       selStandAloneTracksExtras_->push_back(TrackExtra(trk.outerPosition(),
0151                                                        trk.outerMomentum(),
0152                                                        trk.outerOk(),
0153                                                        trk.innerPosition(),
0154                                                        trk.innerMomentum(),
0155                                                        trk.innerOk(),
0156                                                        trk.outerStateCovariance(),
0157                                                        trk.outerDetId(),
0158                                                        trk.innerStateCovariance(),
0159                                                        trk.innerDetId(),
0160                                                        trk.seedDirection()));
0161       TrackExtra &tx = selStandAloneTracksExtras_->back();
0162       auto const firstHitIndex = hisadx_;
0163       unsigned int nHitsAdded = 0;
0164       for (trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++hit) {
0165         selStandAloneTracksHits_->push_back((*hit)->clone());
0166         ++nHitsAdded;
0167         hisadx_++;
0168       }
0169       tx.setHits(rSAHits_, firstHitIndex, nHitsAdded);
0170       trk.setExtra(TrackExtraRef(rSATrackExtras_, isadx_++));
0171 
0172     }  // SA trkRef.isNonnull()
0173   }    // end of track, and function
0174 
0175   //-------------------------------------------------------------------------
0176   //!  Check if all references to silicon strip/pixel clusters are available.
0177   //-------------------------------------------------------------------------
0178   bool MuonCollectionStoreManager::clusterRefsOK(const reco::Track &track) const {
0179     for (trackingRecHit_iterator hitIt = track.recHitsBegin(); hitIt != track.recHitsEnd(); ++hitIt) {
0180       const TrackingRecHit &hit = **hitIt;
0181       if (!hit.isValid() || hit.geographicalId().det() != DetId::Tracker)
0182         continue;
0183 
0184       // So we are in the tracker - now check hit types and availability of cluster refs:
0185       const std::type_info &hit_type = typeid(hit);
0186       if (hit_type == typeid(SiPixelRecHit)) {
0187         if (!static_cast<const SiPixelRecHit &>(hit).cluster().isAvailable())
0188           return false;
0189       } else if (hit_type == typeid(SiStripRecHit2D)) {
0190         if (!static_cast<const SiStripRecHit2D &>(hit).cluster().isAvailable())
0191           return false;
0192       } else if (hit_type == typeid(SiStripRecHit1D)) {
0193         if (!static_cast<const SiStripRecHit1D &>(hit).cluster().isAvailable())
0194           return false;
0195       } else if (hit_type == typeid(SiStripMatchedRecHit2D)) {
0196         const SiStripMatchedRecHit2D &mHit = static_cast<const SiStripMatchedRecHit2D &>(hit);
0197         if (!mHit.monoHit().cluster().isAvailable())
0198           return false;
0199         if (!mHit.stereoHit().cluster().isAvailable())
0200           return false;
0201       } else if (hit_type == typeid(ProjectedSiStripRecHit2D)) {
0202         const ProjectedSiStripRecHit2D &pHit = static_cast<const ProjectedSiStripRecHit2D &>(hit);
0203         if (!pHit.originalHit().cluster().isAvailable())
0204           return false;
0205       } else {
0206         // std::cout << "|   It is a " << hit_type.name() << " hit !?" << std::endl;
0207         // Do nothing. We might end up here for FastSim hits.
0208       }  // end 'switch' on hit type
0209     }
0210 
0211     // No tracker hit with bad cluster found, so all fine:
0212     return true;
0213   }
0214 
0215   //------------------------------------------------------------------
0216   //!  Put Muons, tracks, track extras and hits+clusters into the event.
0217   //------------------------------------------------------------------
0218   edm::OrphanHandle<reco::MuonCollection> MuonCollectionStoreManager::put(edm::Event &evt) {
0219     edm::OrphanHandle<reco::MuonCollection> h;
0220     h = evt.put(std::move(selMuons_), "SelectedMuons");
0221     evt.put(std::move(selTracks_), "TrackerOnly");
0222     evt.put(std::move(selTracksExtras_), "TrackerOnly");
0223     evt.put(std::move(selTracksHits_), "TrackerOnly");
0224     evt.put(std::move(selGlobalMuonTracks_), "GlobalMuon");
0225     evt.put(std::move(selGlobalMuonTracksExtras_), "GlobalMuon");
0226     evt.put(std::move(selGlobalMuonTracksHits_), "GlobalMuon");
0227     evt.put(std::move(selStandAloneTracks_), "StandAlone");
0228     evt.put(std::move(selStandAloneTracksExtras_), "StandAlone");
0229     evt.put(std::move(selStandAloneTracksHits_), "StandAlone");
0230     if (cloneClusters()) {
0231       evt.put(std::move(selStripClusters_));
0232       evt.put(std::move(selPixelClusters_));
0233     }
0234     return h;
0235   }
0236 
0237 }  // end of namespace helper