test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackCollectionCloner.cc
Go to the documentation of this file.
2 
3 
5  copyExtras_(cloner.copyExtras_), copyTrajectories_(cloner.copyTrajectories_), evt(ievt) {
6  selTracks_ = std::make_unique<reco::TrackCollection>();
7  if (copyExtras_) {
8  selTrackExtras_ = std::make_unique<reco::TrackExtraCollection>();
9  selHits_ = std::make_unique<TrackingRecHitCollection>();
10  }
11  if ( copyTrajectories_ ) {
12  selTrajs_ = std::make_unique< std::vector<Trajectory> >();
13  selTTAss_ = std::make_unique< TrajTrackAssociationCollection >(evt.getRefBeforePut< std::vector<Trajectory> >(), evt.getRefBeforePut<reco::TrackCollection>());
14  }
15 
16 }
17 
18 
20 void TrackCollectionCloner::Producer::operator()(Tokens const & tokens, std::vector<unsigned int> const & selected) {
21 
22  auto rTracks = evt.getRefBeforePut<reco::TrackCollection>();
23 
25  reco::TrackExtraRefProd rTrackExtras;
26  if (copyExtras_) {
27  rHits = evt.getRefBeforePut<TrackingRecHitCollection>();
28  rTrackExtras = evt.getRefBeforePut<reco::TrackExtraCollection>();
29  }
30 
32  if ( copyTrajectories_ ) {
33  trajRefProd = evt.getRefBeforePut< std::vector<Trajectory> >();
34  }
35 
36  std::vector<Trajectory> dummy;
37 
38  auto const & trajIn = copyTrajectories_ ? tokens.trajectories(evt) : dummy;
39 
40  auto const & tracksIn = tokens.tracks(evt);
41  for (auto k : selected) {
42  auto const & trk = tracksIn[k];
43  selTracks_->emplace_back( trk ); // clone and store
44  if (copyTrajectories_) {
45  // we assume tracks and trajectories are one-to-one and the assocMap is useless
46  selTrajs_->emplace_back(trajIn[k]);
47  assert(selTrajs_->back().measurements().size()==trk.recHitsSize());
48  selTTAss_->insert ( edm::Ref< std::vector<Trajectory> >(trajRefProd, selTrajs_->size() - 1),
49  reco::TrackRef(rTracks, selTracks_->size() - 1)
50  );
51  }
52 
53  if (!copyExtras_) continue;
54 
55  // TrackExtras
56  selTrackExtras_->emplace_back( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
57  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
58  trk.outerStateCovariance(), trk.outerDetId(),
59  trk.innerStateCovariance(), trk.innerDetId(),
60  trk.seedDirection(), trk.seedRef()
61  );
62  selTracks_->back().setExtra( reco::TrackExtraRef( rTrackExtras, selTrackExtras_->size() - 1) );
63  auto & tx = selTrackExtras_->back();
64  tx.setResiduals(trk.residuals());
65  auto nh1=trk.recHitsSize();
66  tx.setHits(rHits,selHits_->size(),nh1);
67  // TrackingRecHits
68  for( auto hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
69  selHits_->push_back( (*hit)->clone() );
70  }
71  }
72 
73 }
74 
76  selTracks_->shrink_to_fit();
77  auto tsize = selTracks_->size();
78  evt.put(std::move(selTracks_));
79  if (copyExtras_) {
80  selTrackExtras_->shrink_to_fit();
81  assert(selTrackExtras_->size()==tsize);
82  selHits_->shrink_to_fit();
83  evt.put(std::move(selTrackExtras_));
84  evt.put(std::move(selHits_));
85  }
86  if ( copyTrajectories_ ) {
87  selTrajs_->shrink_to_fit();
88  assert(selTrajs_->size()==tsize);
89  assert(selTTAss_->size()==tsize);
90  evt.put(std::move(selTrajs_));
91  evt.put(std::move(selTTAss_));
92 
93  }
94 }
std::unique_ptr< std::vector< Trajectory > > selTrajs_
bool copyExtras_
copy only the tracks, not extras and rechits (for AOD)
assert(m_qm.get())
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::unique_ptr< reco::TrackExtraCollection > selTrackExtras_
std::unique_ptr< reco::TrackCollection > selTracks_
std::unique_ptr< TrackingRecHitCollection > selHits_
bool copyTrajectories_
copy also trajectories and trajectory-&gt;track associations
def move
Definition: eostools.py:510
std::vector< Trajectory > const & trajectories(edm::Event &evt) const
reco::TrackCollection const & tracks(edm::Event &evt) const
RefProd< PROD > getRefBeforePut()
Definition: Event.h:140
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
bool copyExtras_
copy only the tracks, not extras and rechits (for AOD)
Producer(edm::Event &ievt, TrackCollectionCloner const &cloner)
bool copyTrajectories_
copy also trajectories and trajectory-&gt;track associations
void operator()(Tokens const &tokens, std::vector< unsigned int > const &selected)
process one event
std::unique_ptr< TrajTrackAssociationCollection > selTTAss_