CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackFullCloneSelectorBase.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_TrackFullCloneSelectorBase_h
2 #define RecoAlgos_TrackFullCloneSelectorBase_h
3 
15 #include <utility>
16 #include <vector>
17 #include <memory>
18 #include <algorithm>
19 #include <map>
24 
30 
31 
32 namespace reco { namespace modules {
33 
34 template<typename Selector>
36 public:
39  src_( cfg.template getParameter<edm::InputTag>( "src" ) ),
40  copyExtras_(cfg.template getUntrackedParameter<bool>("copyExtras", false)),
41  copyTrajectories_(cfg.template getUntrackedParameter<bool>("copyTrajectories", false)),
42  selector_( cfg ) {
43  std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
44  produces<reco::TrackCollection>().setBranchAlias( alias + "Tracks" );
45  if (copyExtras_) {
46  produces<reco::TrackExtraCollection>().setBranchAlias( alias + "TrackExtras" );
47  produces<TrackingRecHitCollection>().setBranchAlias( alias + "RecHits" );
48  if (copyTrajectories_) {
49  produces< std::vector<Trajectory> >().setBranchAlias( alias + "Trajectories" );
50  produces< TrajTrackAssociationCollection >().setBranchAlias( alias + "TrajectoryTrackAssociations" );
51  }
52  }
53  }
56 
57 private:
59  void produce( edm::Event& evt, const edm::EventSetup& es) override {
63  evt.getByLabel( src_, hSrcTrack );
64 
65  selTracks_ = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection());
66  if (copyExtras_) {
67  selTrackExtras_ = std::auto_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
68  selHits_ = std::auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
69  }
70 
71  TrackRefProd rTracks = evt.template getRefBeforePut<TrackCollection>();
72 
74  TrackExtraRefProd rTrackExtras;
75  if (copyExtras_) {
76  rHits = evt.template getRefBeforePut<TrackingRecHitCollection>();
77  rTrackExtras = evt.template getRefBeforePut<TrackExtraCollection>();
78  }
79 
80  typedef reco::TrackRef::key_type TrackRefKey;
81  std::map<TrackRefKey, reco::TrackRef > goodTracks;
82  TrackRefKey current = 0;
83 
84  for (reco::TrackCollection::const_iterator it = hSrcTrack->begin(), ed = hSrcTrack->end(); it != ed; ++it, ++current) {
85  const reco::Track & trk = * it;
86  if (!selector_(trk, evt)) continue;
87 
88  selTracks_->push_back( Track( trk ) ); // clone and store
89  if (!copyExtras_) continue;
90 
91  // TrackExtras
92  selTrackExtras_->push_back( TrackExtra( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
93  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
94  trk.outerStateCovariance(), trk.outerDetId(),
95  trk.innerStateCovariance(), trk.innerDetId(),
96  trk.seedDirection() ) );
97  selTracks_->back().setExtra( TrackExtraRef( rTrackExtras, selTrackExtras_->size() - 1) );
98  TrackExtra & tx = selTrackExtras_->back();
99  // TrackingRecHits
100  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
101  selHits_->push_back( (*hit)->clone() );
102  tx.add( TrackingRecHitRef( rHits, selHits_->size() - 1) );
103  }
104  if (copyTrajectories_) {
105  goodTracks[current] = reco::TrackRef(rTracks, selTracks_->size() - 1);
106  }
107  }
108  if ( copyTrajectories_ ) {
111  evt.getByLabel(src_, hTTAss);
112  evt.getByLabel(src_, hTraj);
113  edm::RefProd< std::vector<Trajectory> > TrajRefProd = evt.template getRefBeforePut< std::vector<Trajectory> >();
114  selTrajs_ = std::auto_ptr< std::vector<Trajectory> >(new std::vector<Trajectory>());
115  selTTAss_ = std::auto_ptr< TrajTrackAssociationCollection >(new TrajTrackAssociationCollection());
116  for (size_t i = 0, n = hTraj->size(); i < n; ++i) {
117  edm::Ref< std::vector<Trajectory> > trajRef(hTraj, i);
119  if (match != hTTAss->end()) {
120  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
121  TrackRefKey oldKey = trkRef.key();
122  std::map<TrackRefKey, reco::TrackRef>::iterator getref = goodTracks.find(oldKey);
123  if (getref != goodTracks.end()) {
124  // do the clone
125  selTrajs_->push_back( Trajectory(*trajRef) );
126  selTTAss_->insert ( edm::Ref< std::vector<Trajectory> >(TrajRefProd, selTrajs_->size() - 1),
127  getref->second );
128  }
129  }
130  }
131  }
132 
133  evt.put(selTracks_);
134  if (copyExtras_) {
135  evt.put(selTrackExtras_);
136  evt.put(selHits_);
137  if ( copyTrajectories_ ) {
138  evt.put(selTrajs_);
139  evt.put(selTTAss_);
140  }
141  }
142  }
151  // some space
152  std::auto_ptr<reco::TrackCollection> selTracks_;
153  std::auto_ptr<reco::TrackExtraCollection> selTrackExtras_;
154  std::auto_ptr<TrackingRecHitCollection> selHits_;
155  std::auto_ptr< std::vector<Trajectory> > selTrajs_;
156  std::auto_ptr< TrajTrackAssociationCollection > selTTAss_;
157 };
158 
159 } }
160 #endif
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
TrackFullCloneSelectorBase(const edm::ParameterSet &cfg)
constructor
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:40
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:13
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:47
std::auto_ptr< reco::TrackExtraCollection > selTrackExtras_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
std::auto_ptr< TrajTrackAssociationCollection > selTTAss_
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
bool copyExtras_
copy only the tracks, not extras and rechits (for AOD)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:63
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:38
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:53
key_type key() const
Accessor for product key.
Definition: Ref.h:266
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
std::auto_ptr< std::vector< Trajectory > > selTrajs_
bool copyTrajectories_
copy also trajectories and trajectory-&gt;track associations
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:45
std::auto_ptr< reco::TrackCollection > selTracks_
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:105
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::auto_ptr< TrackingRecHitCollection > selHits_
edm::InputTag src_
source collection label
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
def template
Definition: svgfig.py:520
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:65