CMS 3D CMS Logo

SimHitTPAssociationProducer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <map>
3 #include <vector>
4 
9 
16 
22 
24 
26  : _simHitSrc(),
27  _trackingParticleSrc(
28  consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))) {
29  produces<SimHitTPAssociationList>();
30  produces<SimTrackToTPMap>("simTrackToTP");
31  std::vector<edm::InputTag> tags = cfg.getParameter<std::vector<edm::InputTag>>("simHitSrc");
32  _simHitSrc.reserve(tags.size());
33  for (auto const &tag : tags) {
34  _simHitSrc.emplace_back(consumes<edm::PSimHitContainer>(tag));
35  }
36 }
37 
39 
41  std::unique_ptr<SimHitTPAssociationList> simHitTPList(new SimHitTPAssociationList);
42 
43  // TrackingParticle
45  iEvent.getByToken(_trackingParticleSrc, TPCollectionH);
46 
47  // prepare temporary map between SimTrackId and TrackingParticle index
48  auto simTrackToTPMap = std::make_unique<SimTrackToTPMap>();
49  auto const &tpColl = *TPCollectionH.product();
50  for (TrackingParticleCollection::size_type itp = 0, size = tpColl.size(); itp < size; ++itp) {
51  auto const &trackingParticle = tpColl[itp];
52  TrackingParticleRef trackingParticleRef(TPCollectionH, itp);
53  // SimTracks inside TrackingParticle
54  EncodedEventId eid(trackingParticle.eventId());
55  for (auto const &trk : trackingParticle.g4Tracks()) {
56  UniqueSimTrackId trkid(trk.trackId(), eid);
57  simTrackToTPMap->mapping.insert(std::make_pair(trkid, trackingParticleRef));
58  }
59  }
60 
61  // PSimHits
62  for (auto const &psit : _simHitSrc) {
63  edm::Handle<edm::PSimHitContainer> PSimHitCollectionH;
64  iEvent.getByToken(psit, PSimHitCollectionH);
65  auto const &pSimHitCollection = *PSimHitCollectionH;
66  for (unsigned int psimHitI = 0, size = pSimHitCollection.size(); psimHitI < size; ++psimHitI) {
67  TrackPSimHitRef pSimHitRef(PSimHitCollectionH, psimHitI);
68  auto const &pSimHit = pSimHitCollection[psimHitI];
69  UniqueSimTrackId simTkIds(pSimHit.trackId(), pSimHit.eventId());
70  auto ipos = simTrackToTPMap->mapping.find(simTkIds);
71  if (ipos != simTrackToTPMap->mapping.end()) {
72  simHitTPList->emplace_back(ipos->second, pSimHitRef);
73  }
74  }
75  }
76 
77  std::sort(simHitTPList->begin(), simHitTPList->end(), simHitTPAssociationListGreater);
78  iEvent.put(std::move(simHitTPList));
79  iEvent.put(std::move(simTrackToTPMap), "simTrackToTP");
80 }
81 
84 
size
Write out results.
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > _simHitSrc
SimHitTPAssociationProducer(const edm::ParameterSet &)
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
T const * product() const
Definition: Handle.h:70
Trktree trk
Definition: Trktree.cc:2
uint16_t size_type
std::vector< SimHitTPPair > SimHitTPAssociationList
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT enums.
std::vector< TrackingParticle > TrackingParticleCollection
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
def move(src, dest)
Definition: eostools.py:511