CMS 3D CMS Logo

SimHitTPAssociationProducer.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 #include <memory>
4 #include <utility>
5 #include <vector>
6 
8 
12 
14 
16 
18  : _simHitSrc(),
19  _trackingParticleSrc(
20  consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc"))) {
21  produces<SimHitTPAssociationList>();
22  std::vector<edm::InputTag> tags = cfg.getParameter<std::vector<edm::InputTag>>("simHitSrc");
23  _simHitSrc.reserve(tags.size());
24  for (auto const &tag : tags) {
25  _simHitSrc.emplace_back(consumes<edm::PSimHitContainer>(tag));
26  }
27 }
28 
30 
32  std::unique_ptr<SimHitTPAssociationList> simHitTPList(new SimHitTPAssociationList);
33 
34  // TrackingParticle
36  iEvent.getByToken(_trackingParticleSrc, TPCollectionH);
37 
38  // prepare temporary map between SimTrackId and TrackingParticle index
39  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
40  for (TrackingParticleCollection::size_type itp = 0; itp < TPCollectionH.product()->size(); ++itp) {
41  TrackingParticleRef trackingParticle(TPCollectionH, itp);
42  // SimTracks inside TrackingParticle
43  EncodedEventId eid(trackingParticle->eventId());
44  for (auto itrk = trackingParticle->g4Track_begin(); itrk != trackingParticle->g4Track_end(); ++itrk) {
45  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
46  mapping.insert(std::make_pair(trkid, trackingParticle));
47  }
48  }
49 
50  // PSimHits
51  for (auto const &psit : _simHitSrc) {
52  edm::Handle<edm::PSimHitContainer> PSimHitCollectionH;
53  iEvent.getByToken(psit, PSimHitCollectionH);
54  for (unsigned int psimHit = 0; psimHit != PSimHitCollectionH->size(); ++psimHit) {
55  TrackPSimHitRef pSimHitRef(PSimHitCollectionH, psimHit);
56  std::pair<uint32_t, EncodedEventId> simTkIds(pSimHitRef->trackId(), pSimHitRef->eventId());
57  auto ipos = mapping.find(simTkIds);
58  if (ipos != mapping.end()) {
59  simHitTPList->push_back(std::make_pair(ipos->second, pSimHitRef));
60  }
61  }
62  }
63 
64  std::sort(simHitTPList->begin(), simHitTPList->end(), simHitTPAssociationListGreater);
65  iEvent.put(std::move(simHitTPList));
66 }
67 
70 
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > _simHitSrc
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
SimHitTPAssociationProducer(const edm::ParameterSet &)
std::vector< TrackingParticle > TrackingParticleCollection
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
uint16_t size_type
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
T const * product() const
Definition: Handle.h:74
std::vector< SimHitTPPair > SimHitTPAssociationList
HLT enums.
def move(src, dest)
Definition: eostools.py:511