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 void
5  desc.addUntracked<bool>("copyExtras", true);
6  desc.addUntracked<bool>("copyTrajectories",true);
7 }
8 
10  copyExtras_(cloner.copyExtras_), copyTrajectories_(cloner.copyTrajectories_), evt(ievt) {
11  selTracks_ = std::make_unique<reco::TrackCollection>();
12  if (copyExtras_) {
13  selTrackExtras_ = std::make_unique<reco::TrackExtraCollection>();
14  selHits_ = std::make_unique<TrackingRecHitCollection>();
15  }
16  if ( copyTrajectories_ ) {
17  selTrajs_ = std::make_unique< std::vector<Trajectory> >();
18  selTTAss_ = std::make_unique< TrajTrackAssociationCollection >(evt.getRefBeforePut< std::vector<Trajectory> >(), evt.getRefBeforePut<reco::TrackCollection>());
19  }
20 
21 }
22 
23 
25 void TrackCollectionCloner::Producer::operator()(Tokens const & tokens, std::vector<unsigned int> const & selected) {
26 
27  auto rTracks = evt.getRefBeforePut<reco::TrackCollection>();
28 
30  reco::TrackExtraRefProd rTrackExtras;
31  if (copyExtras_) {
32  rHits = evt.getRefBeforePut<TrackingRecHitCollection>();
33  rTrackExtras = evt.getRefBeforePut<reco::TrackExtraCollection>();
34  }
35 
37  if ( copyTrajectories_ ) {
38  trajRefProd = evt.getRefBeforePut< std::vector<Trajectory> >();
39  }
40 
41  std::vector<Trajectory> dummy;
42 
43  auto const & trajIn = copyTrajectories_ ? tokens.trajectories(evt) : dummy;
44 
45  auto const & tracksIn = tokens.tracks(evt);
46  for (auto k : selected) {
47  auto const & trk = tracksIn[k];
48  selTracks_->emplace_back( trk ); // clone and store
49  if (copyTrajectories_) {
50  // we assume tracks and trajectories are one-to-one and the assocMap is useless
51  selTrajs_->emplace_back(trajIn[k]);
52  assert(selTrajs_->back().measurements().size()==trk.recHitsSize());
53  selTTAss_->insert ( edm::Ref< std::vector<Trajectory> >(trajRefProd, selTrajs_->size() - 1),
54  reco::TrackRef(rTracks, selTracks_->size() - 1)
55  );
56  }
57 
58  if (!copyExtras_) continue;
59 
60  // TrackExtras
61  selTrackExtras_->emplace_back( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
62  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
63  trk.outerStateCovariance(), trk.outerDetId(),
64  trk.innerStateCovariance(), trk.innerDetId(),
65  trk.seedDirection(), trk.seedRef()
66  );
67  selTracks_->back().setExtra( reco::TrackExtraRef( rTrackExtras, selTrackExtras_->size() - 1) );
68  auto & tx = selTrackExtras_->back();
69  tx.setResiduals(trk.residuals());
70  auto nh1=trk.recHitsSize();
71  tx.setHits(rHits,selHits_->size(),nh1);
72  // TrackingRecHits
73  for( auto hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
74  selHits_->push_back( (*hit)->clone() );
75  }
76  }
77 
78 }
79 
81  selTracks_->shrink_to_fit();
82  auto tsize = selTracks_->size();
83  evt.put(std::move(selTracks_));
84  if (copyExtras_) {
85  selTrackExtras_->shrink_to_fit();
86  assert(selTrackExtras_->size()==tsize);
87  selHits_->shrink_to_fit();
88  evt.put(std::move(selTrackExtras_));
89  evt.put(std::move(selHits_));
90  }
91  if ( copyTrajectories_ ) {
92  selTrajs_->shrink_to_fit();
93  assert(selTrajs_->size()==tsize);
94  assert(selTTAss_->size()==tsize);
95  evt.put(std::move(selTrajs_));
96  evt.put(std::move(selTTAss_));
97 
98  }
99 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
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
static void fill(edm::ParameterSetDescription &desc)
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:141
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_