File indexing completed on 2024-04-06 12:01:08
0001 #ifndef RecoAlgos_MuonSelector_h
0002 #define RecoAlgos_MuonSelector_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "FWCore/Framework/interface/stream/EDFilter.h"
0017 #include "DataFormats/MuonReco/interface/Muon.h"
0018 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0019 #include "DataFormats/TrackReco/interface/Track.h"
0020 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0023 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0024 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0025 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0026 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0027 #include "CommonTools/RecoAlgos/interface/ClusterStorer.h"
0028 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
0029
0030 namespace helper {
0031 struct MuonCollectionStoreManager {
0032 public:
0033 typedef reco::MuonCollection collection;
0034
0035 MuonCollectionStoreManager(const edm::Handle<reco::MuonCollection> &);
0036
0037
0038
0039
0040
0041
0042
0043 inline bool cloneClusters() { return cloneClusters_; }
0044 inline void setCloneClusters(bool w) { cloneClusters_ = w; }
0045
0046
0047
0048
0049 edm::OrphanHandle<reco::MuonCollection> put(edm::Event &evt);
0050
0051
0052
0053
0054 inline size_t size() const { return selMuons_->size(); }
0055
0056
0057
0058
0059
0060
0061 template <typename I>
0062 void cloneAndStore(const I &begin, const I &end, edm::Event &evt);
0063
0064 private:
0065
0066 std::unique_ptr<reco::MuonCollection> selMuons_;
0067 std::unique_ptr<reco::TrackCollection> selTracks_;
0068 std::unique_ptr<reco::TrackExtraCollection> selTracksExtras_;
0069 std::unique_ptr<TrackingRecHitCollection> selTracksHits_;
0070 std::unique_ptr<reco::TrackCollection> selGlobalMuonTracks_;
0071 std::unique_ptr<reco::TrackExtraCollection> selGlobalMuonTracksExtras_;
0072 std::unique_ptr<TrackingRecHitCollection> selGlobalMuonTracksHits_;
0073 std::unique_ptr<reco::TrackCollection> selStandAloneTracks_;
0074 std::unique_ptr<reco::TrackExtraCollection> selStandAloneTracksExtras_;
0075 std::unique_ptr<TrackingRecHitCollection> selStandAloneTracksHits_;
0076 std::unique_ptr<edmNew::DetSetVector<SiStripCluster>> selStripClusters_;
0077 std::unique_ptr<edmNew::DetSetVector<SiPixelCluster>> selPixelClusters_;
0078 std::unique_ptr<edmNew::DetSetVector<Phase2TrackerCluster1D>> selPhase2OTClusters_;
0079
0080 reco::MuonRefProd rMuons_;
0081 reco::TrackRefProd rTracks_;
0082 reco::TrackExtraRefProd rTrackExtras_;
0083 TrackingRecHitRefProd rHits_;
0084
0085 reco::TrackRefProd rGBTracks_;
0086 reco::TrackExtraRefProd rGBTrackExtras_;
0087 TrackingRecHitRefProd rGBHits_;
0088
0089 reco::TrackRefProd rSATracks_;
0090 reco::TrackExtraRefProd rSATrackExtras_;
0091 TrackingRecHitRefProd rSAHits_;
0092
0093
0094
0095 ClusterStorer clusterStorer_;
0096
0097
0098 size_t id_, igbd_, isad_, idx_, igbdx_, isadx_, hidx_, higbdx_, hisadx_;
0099
0100
0101 bool cloneClusters_;
0102
0103
0104
0105
0106
0107 void processMuon(const reco::Muon &mu);
0108
0109 bool clusterRefsOK(const reco::Track &track) const;
0110 };
0111
0112
0113 template <typename I>
0114 void MuonCollectionStoreManager::cloneAndStore(const I &begin, const I &end, edm::Event &evt) {
0115 using namespace reco;
0116 rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("TrackerOnly");
0117 rGBHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("GlobalMuon");
0118 rSAHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("StandAlone");
0119 rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("TrackerOnly");
0120 rGBTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("GlobalMuon");
0121 rSATrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("StandAlone");
0122 rTracks_ = evt.template getRefBeforePut<TrackCollection>("TrackerOnly");
0123 rGBTracks_ = evt.template getRefBeforePut<TrackCollection>("GlobalMuon");
0124 rSATracks_ = evt.template getRefBeforePut<TrackCollection>("StandAlone");
0125 rMuons_ = evt.template getRefBeforePut<MuonCollection>("SelectedMuons");
0126
0127 edm::RefProd<edmNew::DetSetVector<SiStripCluster>> rStripClusters =
0128 evt.template getRefBeforePut<edmNew::DetSetVector<SiStripCluster>>();
0129
0130 edm::RefProd<edmNew::DetSetVector<SiPixelCluster>> rPixelClusters =
0131 evt.template getRefBeforePut<edmNew::DetSetVector<SiPixelCluster>>();
0132
0133 edm::RefProd<edmNew::DetSetVector<Phase2TrackerCluster1D>> rPhase2OTClusters =
0134 evt.template getRefBeforePut<edmNew::DetSetVector<Phase2TrackerCluster1D>>();
0135
0136 id_ = 0;
0137 igbd_ = 0;
0138 isad_ = 0;
0139 idx_ = 0;
0140 igbdx_ = 0;
0141 isadx_ = 0;
0142 hidx_ = 0;
0143 higbdx_ = 0;
0144 hisadx_ = 0;
0145 clusterStorer_.clear();
0146
0147 for (I i = begin; i != end; ++i) {
0148 const Muon &mu = **i;
0149
0150 processMuon(mu);
0151 }
0152
0153 clusterStorer_.processAllClusters(*selPixelClusters_,
0154 rPixelClusters,
0155 *selStripClusters_,
0156 rStripClusters,
0157 *selPhase2OTClusters_,
0158 rPhase2OTClusters);
0159 }
0160
0161
0162 class MuonSelectorBase : public edm::stream::EDFilter<> {
0163 public:
0164 MuonSelectorBase(const edm::ParameterSet &cfg) {
0165 std::string alias(cfg.getParameter<std::string>("@module_label"));
0166
0167 produces<reco::MuonCollection>("SelectedMuons").setBranchAlias(alias + "SelectedMuons");
0168 produces<reco::TrackCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyTracks");
0169 produces<reco::TrackExtraCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyExtras");
0170 produces<TrackingRecHitCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyHits");
0171
0172 produces<edmNew::DetSetVector<SiPixelCluster>>().setBranchAlias(alias + "PixelClusters");
0173 produces<edmNew::DetSetVector<SiStripCluster>>().setBranchAlias(alias + "StripClusters");
0174 produces<edmNew::DetSetVector<Phase2TrackerCluster1D>>().setBranchAlias(alias + "Phase2OTClusters");
0175 produces<reco::TrackCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonTracks");
0176 produces<reco::TrackExtraCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonExtras");
0177 produces<TrackingRecHitCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonHits");
0178 produces<reco::TrackCollection>("StandAlone").setBranchAlias(alias + "StandAloneTracks");
0179 produces<reco::TrackExtraCollection>("StandAlone").setBranchAlias(alias + "StandAloneExtras");
0180 produces<TrackingRecHitCollection>("StandAlone").setBranchAlias(alias + "StandAloneHits");
0181 }
0182 };
0183
0184 template <>
0185 struct StoreManagerTrait<reco::MuonCollection, edm::stream::EDFilter<>> {
0186 typedef MuonCollectionStoreManager type;
0187 typedef MuonSelectorBase base;
0188 };
0189
0190 }
0191
0192 #endif