Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RecoAlgos_MuonSelector_h
0002 #define RecoAlgos_MuonSelector_h
0003 /** \class MuonSelector
0004  *
0005  * selects a subset of a muon collection and clones
0006  * Track, TrackExtra, RecHits and 'used tracker cluster' collections
0007  * for SA, GB and Tracker Only options
0008  * 
0009  * \author Javier Fernandez, Uniovi
0010  *
0011  * \version $Revision: 1.1 $
0012  *
0013  * $Id: MuonSelector.h,v 1.1 2009/03/04 13:11:28 llista Exp $
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/Common/interface/DetSetVectorNew.h"
0026 #include "CommonTools/RecoAlgos/interface/ClusterStorer.h"
0027 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
0028 
0029 namespace helper {
0030   struct MuonCollectionStoreManager {
0031   public:
0032     typedef reco::MuonCollection collection;
0033 
0034     MuonCollectionStoreManager(const edm::Handle<reco::MuonCollection> &);
0035 
0036     //------------------------------------------------------------------
0037     //!  Use these to turn off/on the cloning of clusters.  The default
0038     //!  is to clone them.  To not clone (and save space in a quick local
0039     //!  job, do:
0040     //!              setCloneClusters(false);
0041     //------------------------------------------------------------------
0042     inline bool cloneClusters() { return cloneClusters_; }
0043     inline void setCloneClusters(bool w) { cloneClusters_ = w; }
0044 
0045     //------------------------------------------------------------------
0046     //!  Put tracks, track extras and hits+clusters into the event.
0047     //------------------------------------------------------------------
0048     edm::OrphanHandle<reco::MuonCollection> put(edm::Event &evt);
0049 
0050     //------------------------------------------------------------------
0051     //!  Get the size.
0052     //------------------------------------------------------------------
0053     inline size_t size() const { return selMuons_->size(); }
0054 
0055     //------------------------------------------------------------------
0056     //! \brief Method to clone tracks, track extras and their hits and clusters.
0057     //! typename I = this is an interator over a Muon collection, **I needs
0058     //! to dereference into a Muon.
0059     //------------------------------------------------------------------
0060     template <typename I>
0061     void cloneAndStore(const I &begin, const I &end, edm::Event &evt);
0062 
0063   private:
0064     //--- Collections to store:
0065     std::unique_ptr<reco::MuonCollection> selMuons_;
0066     std::unique_ptr<reco::TrackCollection> selTracks_;
0067     std::unique_ptr<reco::TrackExtraCollection> selTracksExtras_;
0068     std::unique_ptr<TrackingRecHitCollection> selTracksHits_;
0069     std::unique_ptr<reco::TrackCollection> selGlobalMuonTracks_;
0070     std::unique_ptr<reco::TrackExtraCollection> selGlobalMuonTracksExtras_;
0071     std::unique_ptr<TrackingRecHitCollection> selGlobalMuonTracksHits_;
0072     std::unique_ptr<reco::TrackCollection> selStandAloneTracks_;
0073     std::unique_ptr<reco::TrackExtraCollection> selStandAloneTracksExtras_;
0074     std::unique_ptr<TrackingRecHitCollection> selStandAloneTracksHits_;
0075     std::unique_ptr<edmNew::DetSetVector<SiStripCluster>> selStripClusters_;
0076     std::unique_ptr<edmNew::DetSetVector<SiPixelCluster>> selPixelClusters_;
0077 
0078     reco::MuonRefProd rMuons_;
0079     reco::TrackRefProd rTracks_;
0080     reco::TrackExtraRefProd rTrackExtras_;
0081     TrackingRecHitRefProd rHits_;
0082 
0083     reco::TrackRefProd rGBTracks_;
0084     reco::TrackExtraRefProd rGBTrackExtras_;
0085     TrackingRecHitRefProd rGBHits_;
0086 
0087     reco::TrackRefProd rSATracks_;
0088     reco::TrackExtraRefProd rSATrackExtras_;
0089     TrackingRecHitRefProd rSAHits_;
0090 
0091     /// Helper to treat copies of selected clusters
0092     ///  and make the hits refer to the output cluster collections:
0093     ClusterStorer clusterStorer_;
0094 
0095     //--- Indices into collections handled with RefProd
0096     size_t id_, igbd_, isad_, idx_, igbdx_, isadx_, hidx_, higbdx_, hisadx_;
0097 
0098     //--- Switches
0099     bool cloneClusters_;  //!< Clone clusters, or not?  Default: true.
0100 
0101     //--- Methods
0102     //------------------------------------------------------------------
0103     //!  Process a single muon.
0104     //------------------------------------------------------------------
0105     void processMuon(const reco::Muon &mu);
0106 
0107     bool clusterRefsOK(const reco::Track &track) const;
0108   };
0109   // (end of struct MuonCollectionStoreManager)
0110 
0111   template <typename I>
0112   void MuonCollectionStoreManager::cloneAndStore(const I &begin, const I &end, edm::Event &evt) {
0113     using namespace reco;
0114     rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("TrackerOnly");
0115     rGBHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("GlobalMuon");
0116     rSAHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("StandAlone");
0117     rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("TrackerOnly");
0118     rGBTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("GlobalMuon");
0119     rSATrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("StandAlone");
0120     rTracks_ = evt.template getRefBeforePut<TrackCollection>("TrackerOnly");
0121     rGBTracks_ = evt.template getRefBeforePut<TrackCollection>("GlobalMuon");
0122     rSATracks_ = evt.template getRefBeforePut<TrackCollection>("StandAlone");
0123     rMuons_ = evt.template getRefBeforePut<MuonCollection>("SelectedMuons");
0124     //--- New: save clusters too
0125     edm::RefProd<edmNew::DetSetVector<SiStripCluster>> rStripClusters =
0126         evt.template getRefBeforePut<edmNew::DetSetVector<SiStripCluster>>();
0127 
0128     edm::RefProd<edmNew::DetSetVector<SiPixelCluster>> rPixelClusters =
0129         evt.template getRefBeforePut<edmNew::DetSetVector<SiPixelCluster>>();
0130 
0131     id_ = 0;
0132     igbd_ = 0;
0133     isad_ = 0;
0134     idx_ = 0;
0135     igbdx_ = 0;
0136     isadx_ = 0;
0137     hidx_ = 0;
0138     higbdx_ = 0;
0139     hisadx_ = 0;
0140     clusterStorer_.clear();
0141 
0142     for (I i = begin; i != end; ++i) {
0143       const Muon &mu = **i;
0144       //--- Clone this track, and store references aside
0145       processMuon(mu);
0146     }
0147     //--- Clone the clusters and fixup refs
0148     clusterStorer_.processAllClusters(*selPixelClusters_, rPixelClusters, *selStripClusters_, rStripClusters);
0149   }
0150 
0151   //----------------------------------------------------------------------
0152   class MuonSelectorBase : public edm::stream::EDFilter<> {
0153   public:
0154     MuonSelectorBase(const edm::ParameterSet &cfg) {
0155       std::string alias(cfg.getParameter<std::string>("@module_label"));
0156 
0157       produces<reco::MuonCollection>("SelectedMuons").setBranchAlias(alias + "SelectedMuons");
0158       produces<reco::TrackCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyTracks");
0159       produces<reco::TrackExtraCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyExtras");
0160       produces<TrackingRecHitCollection>("TrackerOnly").setBranchAlias(alias + "TrackerOnlyHits");
0161       //--- New: save clusters too
0162       produces<edmNew::DetSetVector<SiPixelCluster>>().setBranchAlias(alias + "PixelClusters");
0163       produces<edmNew::DetSetVector<SiStripCluster>>().setBranchAlias(alias + "StripClusters");
0164       produces<reco::TrackCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonTracks");
0165       produces<reco::TrackExtraCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonExtras");
0166       produces<TrackingRecHitCollection>("GlobalMuon").setBranchAlias(alias + "GlobalMuonHits");
0167       produces<reco::TrackCollection>("StandAlone").setBranchAlias(alias + "StandAloneTracks");
0168       produces<reco::TrackExtraCollection>("StandAlone").setBranchAlias(alias + "StandAloneExtras");
0169       produces<TrackingRecHitCollection>("StandAlone").setBranchAlias(alias + "StandAloneHits");
0170     }
0171   };  // (end of class MuonSelectorBase)
0172 
0173   template <>
0174   struct StoreManagerTrait<reco::MuonCollection, edm::stream::EDFilter<>> {
0175     typedef MuonCollectionStoreManager type;
0176     typedef MuonSelectorBase base;
0177   };
0178 
0179 }  // namespace helper
0180 
0181 #endif