CMS 3D CMS Logo

RecoTrackAccumulator.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
9 
11  edm::ProducesCollector producesCollector,
13  : signalTracksTag(conf.getParameter<edm::InputTag>("signalTracks")),
14  pileUpTracksTag(conf.getParameter<edm::InputTag>("pileUpTracks")),
15  outputLabel(conf.getParameter<std::string>("outputLabel")) {
16  producesCollector.produces<reco::TrackCollection>(outputLabel);
17  producesCollector.produces<TrackingRecHitCollection>(outputLabel);
19 
23 }
24 
26 
28  newTracks_ = std::make_unique<reco::TrackCollection>();
29  newHits_ = std::make_unique<TrackingRecHitCollection>();
30  newTrackExtras_ = std::make_unique<reco::TrackExtraCollection>();
31 
32  // this is needed to get the ProductId of the TrackExtra and TrackingRecHit and Track collections
33  rNewTracks = const_cast<edm::Event&>(e).getRefBeforePut<reco::TrackCollection>(outputLabel);
34  rNewTrackExtras = const_cast<edm::Event&>(e).getRefBeforePut<reco::TrackExtraCollection>(outputLabel);
35  rNewHits = const_cast<edm::Event&>(e).getRefBeforePut<TrackingRecHitCollection>(outputLabel);
36 }
37 
40 }
41 
43  edm::EventSetup const& iSetup,
44  edm::StreamID const&) {
45  if (e.bunchCrossing() == 0) {
47  }
48 }
49 
54 }
55 
56 template <class T>
61  e.getByLabel(label, tracks);
62  e.getByLabel(label, hits);
63  e.getByLabel(label, trackExtras);
64 
65  if (!tracks.isValid()) {
66  throw cms::Exception("RecoTrackAccumulator")
67  << "Failed to find track collections with inputTag " << label << std::endl;
68  }
69  if (!hits.isValid()) {
70  throw cms::Exception("RecoTrackAccumulator")
71  << "Failed to find hit collections with inputTag " << label << std::endl;
72  }
73  if (!trackExtras.isValid()) {
74  throw cms::Exception("RecoTrackAccumulator")
75  << "Failed to find trackExtra collections with inputTag " << label << std::endl;
76  }
77 
78  for (size_t t = 0; t < tracks->size(); ++t) {
79  const reco::Track& track = (*tracks)[t];
80  newTracks_->push_back(track);
81  // track extras:
82  auto const& extra = trackExtras->at(track.extra().key());
83  newTrackExtras_->emplace_back(extra.outerPosition(),
84  extra.outerMomentum(),
85  extra.outerOk(),
86  extra.innerPosition(),
87  extra.innerMomentum(),
88  extra.innerOk(),
89  extra.outerStateCovariance(),
90  extra.outerDetId(),
91  extra.innerStateCovariance(),
92  extra.innerDetId(),
93  extra.seedDirection(),
94  //If TrajectorySeeds are needed, then their list must be gotten from the
95  // secondary event directly and looked up similarly to TrackExtras.
96  //We can't use a default constructed RefToBase due to a bug in RefToBase
97  // which causes an seg fault when calling isAvailable on a default constructed one.
99  newTracks_->back().setExtra(reco::TrackExtraRef(rNewTrackExtras, newTracks_->size() - 1));
100  // rechits:
101  // note: extra.recHit(i) does not work for pileup events
102  // probably the Ref does not know its product id applies on a pileup event
103  auto& newExtra = newTrackExtras_->back();
104  auto const firstTrackIndex = newHits_->size();
105  for (unsigned int i = 0; i < extra.recHitsSize(); i++) {
106  newHits_->push_back((*hits)[extra.recHit(i).key()]);
107  }
108  newExtra.setHits(rNewHits, firstTrackIndex, newHits_->size() - firstTrackIndex);
109  newExtra.setTrajParams(extra.trajParams(), extra.chi2sX5());
110  assert(newExtra.recHitsSize() == newExtra.trajParams().size());
111  }
112 }
113 
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void accumulateEvent(const T &e, edm::EventSetup const &c, const edm::InputTag &label)
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
assert(be >=bs)
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
char const * label
std::unique_ptr< reco::TrackCollection > newTracks_
TrackingRecHitRefProd rNewHits
std::unique_ptr< reco::TrackExtraCollection > newTrackExtras_
reco::TrackRefProd rNewTracks
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
auto const & tracks
cannot be loose
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< TrackingRecHitCollection > newHits_
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
HLT enums.
#define DEFINE_DIGI_ACCUMULATOR(type)
long double T
def move(src, dest)
Definition: eostools.py:511
RecoTrackAccumulator(const edm::ParameterSet &conf, edm::ProducesCollector, edm::ConsumesCollector &iC)
reco::TrackExtraRefProd rNewTrackExtras