CMS 3D CMS Logo

SiStripOnTrackClusterTableProducerBase.cc
Go to the documentation of this file.
4 
6 
8 
9 namespace {
11  for (auto iTr = tracks.begin(); iTr != tracks.end(); ++iTr) {
12  if (&(*iTr) == track) {
13  return iTr - tracks.begin();
14  }
15  }
16  return -2;
17  }
18 } // namespace
19 
22  iEvent.getByToken(m_tracks_token, tracks);
23  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociations;
24  iEvent.getByToken(m_association_token, trajTrackAssociations);
25 
26  std::vector<OnTrackCluster> clusters{};
27 
28  for (const auto& assoc : *trajTrackAssociations) {
29  const auto traj = assoc.key.get();
30  const auto track = assoc.val.get();
31 
32  for (const auto& meas : traj->measurements()) {
33  const auto& trajState = meas.updatedState();
34  if (!trajState.isValid())
35  continue;
36 
37  // there can be 2 (stereo module), 1 (no stereo module), or 0 (no strip hit) clusters per measurement
38  const auto trechit = meas.recHit()->hit();
39  const auto simple1d = dynamic_cast<const SiStripRecHit1D*>(trechit);
40  const auto simple = dynamic_cast<const SiStripRecHit2D*>(trechit);
41  const auto matched = dynamic_cast<const SiStripMatchedRecHit2D*>(trechit);
42  if (matched) {
43  clusters.emplace_back(matched->monoId(), &matched->monoCluster(), traj, track, meas);
44  clusters.emplace_back(matched->stereoId(), &matched->stereoCluster(), traj, track, meas);
45  } else if (simple) {
46  clusters.emplace_back(simple->geographicalId().rawId(), simple->cluster().get(), traj, track, meas);
47  } else if (simple1d) {
48  clusters.emplace_back(simple1d->geographicalId().rawId(), simple1d->cluster().get(), traj, track, meas);
49  }
50  }
51  }
52 
53  auto out = std::make_unique<nanoaod::FlatTable>(clusters.size(), m_name, false, m_extension);
54  if (!m_extension) {
55  std::vector<int> c_trackindex;
56  c_trackindex.reserve(clusters.size());
57  std::vector<uint32_t> c_rawid;
58  c_rawid.reserve(clusters.size());
59  for (const auto clus : clusters) {
60  c_trackindex.push_back(findTrackIndex(*tracks, clus.track));
61  c_rawid.push_back(clus.det);
62  }
63  addColumn(out.get(), "trackindex", c_trackindex, "Track index");
64  addColumn(out.get(), "rawid", c_rawid, "DetId");
65  }
66  fillTable(clusters, *tracks, out.get(), iSetup);
67  iEvent.put(std::move(out));
68 }
int findTrackIndex(const edm::Handle< edm::View< reco::Track > > &h, const reco::Track *t)
Definition: ShallowTools.cc:25
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< TrajTrackAssociationCollection > m_association_token
auto const & tracks
cannot be loose
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
static void addColumn(nanoaod::FlatTable *table, const std::string &name, VALUES &&values, const std::string &doc)
const edm::EDGetTokenT< edm::View< reco::Track > > m_tracks_token
virtual void fillTable(const std::vector< OnTrackCluster > &clusters, const edm::View< reco::Track > &tracks, nanoaod::FlatTable *table, const edm::EventSetup &iSetup)=0
def move(src, dest)
Definition: eostools.py:511