Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:09

0001 #ifndef RecoAlgos_TrackSelector_h
0002 #define RecoAlgos_TrackSelector_h
0003 /** \class TrackSelector
0004  *
0005  * Selects a subset of a track collection. Also clones
0006  * TrackExtra part, RecHits and used SiStrip-/SiPixelCluster
0007  * 
0008  * \author Luca Lista, INFN
0009  *         Reorganized by Petar Maksimovic, JHU
0010  *         Reorganized again by Giovanni Petrucciani
0011  *         Outsourcing of cluster cloning by Gero Flucke, DESY
0012  * \version $Revision: 1.1 $
0013  *
0014  * $Id: TrackSelector.h,v 1.1 2009/03/04 13:11:28 llista Exp $
0015  *
0016  */
0017 
0018 #include "FWCore/Framework/interface/stream/EDFilter.h"
0019 #include "DataFormats/TrackReco/interface/Track.h"
0020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0021 #include "DataFormats/TrackReco/interface/TrackExtra.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 
0032   //------------------------------------------------------------------
0033   //!  \brief Class to manage copying of RecHits and Clusters from Tracks.
0034   //------------------------------------------------------------------
0035   struct TrackCollectionStoreManager {
0036   public:
0037     typedef reco::TrackCollection collection;
0038 
0039     TrackCollectionStoreManager(const edm::Handle<reco::TrackCollection>&);
0040 
0041     //------------------------------------------------------------------
0042     //!  Use these to turn off/on the cloning of clusters.  The default
0043     //!  is to clone them.  To not clone (and save space in a quick local
0044     //!  job, do:
0045     //!              setCloneClusters(false);
0046     //------------------------------------------------------------------
0047     inline bool cloneClusters() { return cloneClusters_; }
0048     inline void setCloneClusters(bool w) { cloneClusters_ = w; }
0049 
0050     //------------------------------------------------------------------
0051     //!  Put tracks, track extras and hits+clusters into the event.
0052     //------------------------------------------------------------------
0053     edm::OrphanHandle<reco::TrackCollection> put(edm::Event& evt);
0054 
0055     //------------------------------------------------------------------
0056     //!  Get the size.
0057     //------------------------------------------------------------------
0058     inline size_t size() const { return selTracks_->size(); }
0059 
0060     //------------------------------------------------------------------
0061     //! \brief Method to clone tracks, track extras and their hits and clusters.
0062     //! typename I = this is an interator over a track collection, **I needs
0063     //! to dereference into a Track.
0064     //------------------------------------------------------------------
0065     template <typename I>
0066     void cloneAndStore(const I& begin, const I& end, edm::Event& evt);
0067 
0068   private:
0069     //--- Collections to store:
0070     std::unique_ptr<reco::TrackCollection> selTracks_;
0071     std::unique_ptr<reco::TrackExtraCollection> selTrackExtras_;
0072     std::unique_ptr<TrackingRecHitCollection> selHits_;
0073     std::unique_ptr<edmNew::DetSetVector<SiStripCluster> > selStripClusters_;
0074     std::unique_ptr<edmNew::DetSetVector<SiPixelCluster> > selPixelClusters_;
0075     std::unique_ptr<edmNew::DetSetVector<Phase2TrackerCluster1D> > selPhase2OTClusters_;
0076 
0077     //--- References to products (i.e. to collections):
0078     reco::TrackRefProd rTracks_;
0079     reco::TrackExtraRefProd rTrackExtras_;
0080     TrackingRecHitRefProd rHits_;
0081     /// Helper to treat copies of selected clusters
0082     ///  and make the hits refer to the output cluster collections:
0083     ClusterStorer clusterStorer_;
0084 
0085     //--- Indices into collections handled with RefProd
0086     size_t idx_;   //!<  index to track extra coll
0087     size_t hidx_;  //!<  index to tracking rec hits
0088 
0089     //--- Switches
0090     bool cloneClusters_;  //!< Clone clusters, or not?  Default: true.
0091 
0092     //--- Methods
0093     //------------------------------------------------------------------
0094     //!  Process a single track.
0095     //------------------------------------------------------------------
0096     void processTrack(const reco::Track& trk);
0097   };
0098   // (end of struct TrackCollectionStoreManager)
0099 
0100   template <typename I>
0101   void TrackCollectionStoreManager::cloneAndStore(const I& begin, const I& end, edm::Event& evt) {
0102     using namespace reco;
0103 
0104     rTracks_ = evt.template getRefBeforePut<TrackCollection>();
0105     rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>();
0106     rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>();
0107     //--- New: save clusters too
0108     edm::RefProd<edmNew::DetSetVector<SiPixelCluster> > rPixelClusters =
0109         evt.template getRefBeforePut<edmNew::DetSetVector<SiPixelCluster> >();
0110     edm::RefProd<edmNew::DetSetVector<SiStripCluster> > rStripClusters =
0111         evt.template getRefBeforePut<edmNew::DetSetVector<SiStripCluster> >();
0112     edm::RefProd<edmNew::DetSetVector<Phase2TrackerCluster1D> > rPhase2OTClusters =
0113         evt.template getRefBeforePut<edmNew::DetSetVector<Phase2TrackerCluster1D> >();
0114 
0115     //--- Indices into collections handled with RefProd
0116     idx_ = 0;   //!<  index to track extra coll
0117     hidx_ = 0;  //!<  index to tracking rec hits
0118     clusterStorer_.clear();
0119 
0120     //--- Loop over tracks
0121     for (I i = begin; i != end; ++i) {
0122       //--- Whatever type the iterator i is, deref to reco::Track &
0123       const reco::Track& trk = **i;
0124       //--- Clone this track, and store references aside
0125       processTrack(trk);
0126     }
0127     //--- Clone the clusters and fixup refs
0128     clusterStorer_.processAllClusters(*selPixelClusters_,
0129                                       rPixelClusters,
0130                                       *selStripClusters_,
0131                                       rStripClusters,
0132                                       *selPhase2OTClusters_,
0133                                       rPhase2OTClusters);
0134   }
0135 
0136   //----------------------------------------------------------------------
0137   class TrackSelectorBase : public edm::stream::EDFilter<> {
0138   public:
0139     TrackSelectorBase(const edm::ParameterSet& cfg) {
0140       std::string alias(cfg.getParameter<std::string>("@module_label"));
0141       produces<reco::TrackCollection>().setBranchAlias(alias + "Tracks");
0142       produces<reco::TrackExtraCollection>().setBranchAlias(alias + "TrackExtras");
0143       produces<TrackingRecHitCollection>().setBranchAlias(alias + "RecHits");
0144       //--- New: save clusters too
0145       produces<edmNew::DetSetVector<SiPixelCluster> >().setBranchAlias(alias + "PixelClusters");
0146       produces<edmNew::DetSetVector<SiStripCluster> >().setBranchAlias(alias + "StripClusters");
0147       produces<edmNew::DetSetVector<Phase2TrackerCluster1D> >().setBranchAlias(alias + "Phase2OTClusters");
0148     }
0149   };  // (end of class TrackSelectorBase)
0150 
0151   template <>
0152   struct StoreManagerTrait<reco::TrackCollection, edm::stream::EDFilter<> > {
0153     typedef TrackCollectionStoreManager type;
0154     typedef TrackSelectorBase base;
0155   };
0156 
0157 }  // namespace helper
0158 
0159 #endif