Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:28

0001 #ifndef RecoTracker_FinalTrackSelectors_TrackCollectionCloner_H
0002 #define RecoTracker_FinalTrackSelectors_TrackCollectionCloner_H
0003 /*
0004  *
0005  * selects a subset of a track collection, copying extra information on demand
0006  * to be used moslty as an helper in the produce method of selectors
0007  *
0008  * \author Giovanni Petrucciani
0009  *
0010  *
0011  *
0012  */
0013 
0014 #include <utility>
0015 #include <memory>
0016 #include <algorithm>
0017 #include "FWCore/Framework/interface/ProducesCollector.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 
0021 #include "DataFormats/TrackReco/interface/Track.h"
0022 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0023 #include "TrackingTools/PatternTools/interface/TrackCollectionTokens.h"
0024 
0025 class TrackCollectionCloner {
0026 public:
0027   /// copy only the tracks, not extras and rechits (for AOD)
0028   bool copyExtras_;
0029   /// copy also trajectories and trajectory->track associations
0030   bool copyTrajectories_;
0031 
0032   using Tokens = TrackCollectionTokens;
0033 
0034   TrackCollectionCloner(edm::ProducesCollector producesCollector, const edm::ParameterSet& cfg, bool copyDefault)
0035       : copyExtras_(cfg.template getUntrackedParameter<bool>("copyExtras", copyDefault)),
0036         copyTrajectories_(cfg.template getUntrackedParameter<bool>("copyTrajectories", copyDefault)) {
0037     std::string alias(cfg.getParameter<std::string>("@module_label"));
0038     producesCollector.produces<reco::TrackCollection>().setBranchAlias(alias + "Tracks");
0039     if (copyExtras_) {
0040       producesCollector.produces<reco::TrackExtraCollection>().setBranchAlias(alias + "TrackExtras");
0041       producesCollector.produces<TrackingRecHitCollection>().setBranchAlias(alias + "RecHits");
0042     }
0043     if (copyTrajectories_) {
0044       producesCollector.produces<std::vector<Trajectory> >().setBranchAlias(alias + "Trajectories");
0045       producesCollector.produces<TrajTrackAssociationCollection>().setBranchAlias(alias +
0046                                                                                   "TrajectoryTrackAssociations");
0047     }
0048   }
0049 
0050   static void fill(edm::ParameterSetDescription& desc);
0051 
0052   struct Producer {
0053     Producer(edm::Event& ievt, TrackCollectionCloner const& cloner);
0054 
0055     ~Producer();
0056 
0057     void operator()(Tokens const& tokens, std::vector<unsigned int> const& selected);
0058 
0059     /// copy only the tracks, not extras and rechits (for AOD)
0060     bool copyExtras_;
0061     /// copy also trajectories and trajectory->track associations
0062     bool copyTrajectories_;
0063 
0064     /// the event
0065     edm::Event& evt;
0066     // some space
0067     std::unique_ptr<reco::TrackCollection> selTracks_;
0068     std::unique_ptr<reco::TrackExtraCollection> selTrackExtras_;
0069     std::unique_ptr<TrackingRecHitCollection> selHits_;
0070     std::unique_ptr<std::vector<Trajectory> > selTrajs_;
0071     std::unique_ptr<TrajTrackAssociationCollection> selTTAss_;
0072   };
0073 };
0074 
0075 #endif