Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/Common/interface/DetSetVectorNew.h"
0026 #include "CommonTools/RecoAlgos/interface/ClusterStorer.h"
0027 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
0028 
0029 namespace helper {
0030 
0031   //------------------------------------------------------------------
0032   //!  \brief Class to manage copying of RecHits and Clusters from Tracks.
0033   //------------------------------------------------------------------
0034   struct TrackCollectionStoreManager {
0035   public:
0036     typedef reco::TrackCollection collection;
0037 
0038     TrackCollectionStoreManager(const edm::Handle<reco::TrackCollection>&);
0039 
0040     //------------------------------------------------------------------
0041     //!  Use these to turn off/on the cloning of clusters.  The default
0042     //!  is to clone them.  To not clone (and save space in a quick local
0043     //!  job, do:
0044     //!              setCloneClusters(false);
0045     //------------------------------------------------------------------
0046     inline bool cloneClusters() { return cloneClusters_; }
0047     inline void setCloneClusters(bool w) { cloneClusters_ = w; }
0048 
0049     //------------------------------------------------------------------
0050     //!  Put tracks, track extras and hits+clusters into the event.
0051     //------------------------------------------------------------------
0052     edm::OrphanHandle<reco::TrackCollection> put(edm::Event& evt);
0053 
0054     //------------------------------------------------------------------
0055     //!  Get the size.
0056     //------------------------------------------------------------------
0057     inline size_t size() const { return selTracks_->size(); }
0058 
0059     //------------------------------------------------------------------
0060     //! \brief Method to clone tracks, track extras and their hits and clusters.
0061     //! typename I = this is an interator over a track collection, **I needs
0062     //! to dereference into a Track.
0063     //------------------------------------------------------------------
0064     template <typename I>
0065     void cloneAndStore(const I& begin, const I& end, edm::Event& evt);
0066 
0067   private:
0068     //--- Collections to store:
0069     std::unique_ptr<reco::TrackCollection> selTracks_;
0070     std::unique_ptr<reco::TrackExtraCollection> selTrackExtras_;
0071     std::unique_ptr<TrackingRecHitCollection> selHits_;
0072     std::unique_ptr<edmNew::DetSetVector<SiStripCluster> > selStripClusters_;
0073     std::unique_ptr<edmNew::DetSetVector<SiPixelCluster> > selPixelClusters_;
0074 
0075     //--- References to products (i.e. to collections):
0076     reco::TrackRefProd rTracks_;
0077     reco::TrackExtraRefProd rTrackExtras_;
0078     TrackingRecHitRefProd rHits_;
0079     /// Helper to treat copies of selected clusters
0080     ///  and make the hits refer to the output cluster collections:
0081     ClusterStorer clusterStorer_;
0082 
0083     //--- Indices into collections handled with RefProd
0084     size_t idx_;   //!<  index to track extra coll
0085     size_t hidx_;  //!<  index to tracking rec hits
0086 
0087     //--- Switches
0088     bool cloneClusters_;  //!< Clone clusters, or not?  Default: true.
0089 
0090     //--- Methods
0091     //------------------------------------------------------------------
0092     //!  Process a single track.
0093     //------------------------------------------------------------------
0094     void processTrack(const reco::Track& trk);
0095   };
0096   // (end of struct TrackCollectionStoreManager)
0097 
0098   template <typename I>
0099   void TrackCollectionStoreManager::cloneAndStore(const I& begin, const I& end, edm::Event& evt) {
0100     using namespace reco;
0101 
0102     rTracks_ = evt.template getRefBeforePut<TrackCollection>();
0103     rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>();
0104     rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>();
0105     //--- New: save clusters too
0106     edm::RefProd<edmNew::DetSetVector<SiPixelCluster> > rPixelClusters =
0107         evt.template getRefBeforePut<edmNew::DetSetVector<SiPixelCluster> >();
0108     edm::RefProd<edmNew::DetSetVector<SiStripCluster> > rStripClusters =
0109         evt.template getRefBeforePut<edmNew::DetSetVector<SiStripCluster> >();
0110 
0111     //--- Indices into collections handled with RefProd
0112     idx_ = 0;   //!<  index to track extra coll
0113     hidx_ = 0;  //!<  index to tracking rec hits
0114     clusterStorer_.clear();
0115 
0116     //--- Loop over tracks
0117     for (I i = begin; i != end; ++i) {
0118       //--- Whatever type the iterator i is, deref to reco::Track &
0119       const reco::Track& trk = **i;
0120       //--- Clone this track, and store references aside
0121       processTrack(trk);
0122     }
0123     //--- Clone the clusters and fixup refs
0124     clusterStorer_.processAllClusters(*selPixelClusters_, rPixelClusters, *selStripClusters_, rStripClusters);
0125   }
0126 
0127   //----------------------------------------------------------------------
0128   class TrackSelectorBase : public edm::stream::EDFilter<> {
0129   public:
0130     TrackSelectorBase(const edm::ParameterSet& cfg) {
0131       std::string alias(cfg.getParameter<std::string>("@module_label"));
0132       produces<reco::TrackCollection>().setBranchAlias(alias + "Tracks");
0133       produces<reco::TrackExtraCollection>().setBranchAlias(alias + "TrackExtras");
0134       produces<TrackingRecHitCollection>().setBranchAlias(alias + "RecHits");
0135       //--- New: save clusters too
0136       produces<edmNew::DetSetVector<SiPixelCluster> >().setBranchAlias(alias + "PixelClusters");
0137       produces<edmNew::DetSetVector<SiStripCluster> >().setBranchAlias(alias + "StripClusters");
0138     }
0139   };  // (end of class TrackSelectorBase)
0140 
0141   template <>
0142   struct StoreManagerTrait<reco::TrackCollection, edm::stream::EDFilter<> > {
0143     typedef TrackCollectionStoreManager type;
0144     typedef TrackSelectorBase base;
0145   };
0146 
0147 }  // namespace helper
0148 
0149 #endif