CMS 3D CMS Logo

TrackListCombiner.cc
Go to the documentation of this file.
1 #include "TrackListCombiner.h"
2 
6 
8 
12 
13 using namespace std;
14 
15 /*****************************************************************************/
17  for (const std::string& prod : ps.getParameter<vector<string>>("trackProducers")) {
18  trackProducers.emplace_back(consumes<vector<Trajectory>>(prod), consumes<TrajTrackAssociationCollection>(prod));
19  }
20 
21  produces<reco::TrackCollection>();
22  produces<reco::TrackExtraCollection>();
23  produces<TrackingRecHitCollection>();
24  produces<vector<Trajectory>>();
25  produces<TrajTrackAssociationCollection>();
26 }
27 
28 /*****************************************************************************/
30 
31 /*****************************************************************************/
33  auto recoTracks = std::make_unique<reco::TrackCollection>();
34  auto recoTrackExtras = std::make_unique<reco::TrackExtraCollection>();
35  auto recoHits = std::make_unique<TrackingRecHitCollection>();
36  auto recoTrajectories = std::make_unique<vector<Trajectory>>();
37  auto recoTrajTrackMap = std::make_unique<TrajTrackAssociationCollection>();
38 
39  LogTrace("MinBiasTracking") << "[TrackListCombiner]";
40 
41  // Go through all track producers
42  int i = 1;
43  for (auto trackProducer = trackProducers.begin(); trackProducer != trackProducers.end(); trackProducer++, i++) {
45  switch (i) {
46  case 1:
48  break;
49  case 2:
51  break;
52  case 3:
54  break;
55  default:
57  }
58 
59  edm::Handle<vector<Trajectory>> theTrajectoryCollection;
61 
62  ev.getByToken(trackProducer->trajectory, theTrajectoryCollection);
63  ev.getByToken(trackProducer->assoMap, theAssoMap);
64 
65 #ifdef EDM_ML_DEBUG
67  labelsForToken(trackProducer->trajectory, labels);
68 
69  LogTrace("MinBiasTracking") << " [TrackListCombiner] " << labels.module << " : " << theAssoMap->size();
70 #endif
71 
72  // The track collection iterators
75  anAssociation = theAssoMap->begin();
76  lastAssociation = theAssoMap->end();
77 
78  // Build the map of correspondance between reco tracks and sim tracks
79  for (; anAssociation != lastAssociation; ++anAssociation) {
80  edm::Ref<vector<Trajectory>> aTrajectoryRef = anAssociation->key;
81  reco::TrackRef aTrackRef = anAssociation->val;
82 
83  // A copy of the track
84  reco::Track aRecoTrack(*aTrackRef);
85 
86  // Set algorithm
87  aRecoTrack.setAlgorithm(algo);
88 
89  recoTracks->push_back(aRecoTrack);
90 
91  // A copy of the hits
92  unsigned nh = aRecoTrack.recHitsSize();
93  for (unsigned ih = 0; ih < nh; ++ih) {
94  TrackingRecHit* hit = aRecoTrack.recHit(ih)->clone();
95  recoHits->push_back(hit);
96  }
97 
98  // A copy of the trajectories
99  recoTrajectories->push_back(*aTrajectoryRef);
100  }
101  }
102 
103  LogTrace("MinBiasTracking") << " [TrackListCombiner] allTracks : " << recoTracks->size() << "|"
104  << recoTrajectories->size();
105 
106  // Save the tracking recHits
107  edm::OrphanHandle<TrackingRecHitCollection> theRecoHits = ev.put(std::move(recoHits));
108 
109  edm::RefProd<TrackingRecHitCollection> theRecoHitsProd(theRecoHits);
110  // Create the track extras and add the references to the rechits
111  unsigned hits = 0;
112  unsigned nTracks = recoTracks->size();
113  recoTrackExtras->reserve(nTracks); // To save some time at push_back
114  for (unsigned index = 0; index < nTracks; ++index) {
115  reco::Track& aTrack = recoTracks->at(index);
116  reco::TrackExtra aTrackExtra(aTrack.outerPosition(),
117  aTrack.outerMomentum(),
118  aTrack.outerOk(),
119  aTrack.innerPosition(),
120  aTrack.innerMomentum(),
121  aTrack.innerOk(),
122  aTrack.outerStateCovariance(),
123  aTrack.outerDetId(),
124  aTrack.innerStateCovariance(),
125  aTrack.innerDetId(),
126  aTrack.seedDirection(),
127  aTrack.seedRef());
128 
129  unsigned nHits = aTrack.recHitsSize();
130  aTrackExtra.setHits(theRecoHitsProd, hits, nHits);
131  hits += nHits;
132 
133  recoTrackExtras->push_back(aTrackExtra);
134  }
135 
136  // Save the track extras
137  edm::OrphanHandle<reco::TrackExtraCollection> theRecoTrackExtras = ev.put(std::move(recoTrackExtras));
138 
139  // Add the reference to the track extra in the tracks
140  for (unsigned index = 0; index < nTracks; ++index) {
141  const reco::TrackExtraRef theTrackExtraRef(theRecoTrackExtras, index);
142  (recoTracks->at(index)).setExtra(theTrackExtraRef);
143  }
144 
145  // Save the tracks
146  edm::OrphanHandle<reco::TrackCollection> theRecoTracks = ev.put(std::move(recoTracks));
147 
148  // Save the trajectories
149  edm::OrphanHandle<vector<Trajectory>> theRecoTrajectories = ev.put(std::move(recoTrajectories));
150 
151  // Create and set the trajectory/track association map
152  for (unsigned index = 0; index < nTracks; ++index) {
153  edm::Ref<vector<Trajectory>> trajRef(theRecoTrajectories, index);
154  edm::Ref<reco::TrackCollection> tkRef(theRecoTracks, index);
155  recoTrajTrackMap->insert(trajRef, tkRef);
156  }
157 
158  // Save the association map
159  ev.put(std::move(recoTrajTrackMap));
160 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:97
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:68
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:65
const edm::RefToBase< TrajectorySeed > & seedRef() const
Definition: Track.h:155
key_type key() const
Accessor for product key.
Definition: Ref.h:250
TrackAlgorithm
track algorithm
Definition: TrackBase.h:89
#define LogTrace(id)
const_iterator end() const
last iterator over the map (read only)
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:71
size_type size() const
map size
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:82
uint32_t nh
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:53
const PropagationDirection & seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:148
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:79
TrackListCombiner(const edm::ParameterSet &ps)
~TrackListCombiner() override
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:94
void setAlgorithm(const TrackAlgorithm a)
Track algorithm.
Definition: TrackBase.h:832
const_iterator begin() const
first iterator over the map (read only)
void produce(edm::StreamID, edm::Event &ev, const edm::EventSetup &es) const override
trackProducer
Run2: False; Run1: True.
Definition: L1TCSCTF_cfi.py:12
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
def move(src, dest)
Definition: eostools.py:511
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:50