CMS 3D CMS Logo

SimHitTPAssociationProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
3 #include <iostream>
4 #include <fstream>
5 #include <utility>
6 
8 
12 
14 
16 
18  : _simHitSrc(),
19  _trackingParticleSrc(consumes<TrackingParticleCollection>(cfg.getParameter<edm::InputTag>("trackingParticleSrc")))
20 {
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 }
31 
33  std::unique_ptr<SimHitTPAssociationList> simHitTPList(new SimHitTPAssociationList);
34 
35  // TrackingParticle
37  iEvent.getByToken(_trackingParticleSrc, TPCollectionH);
38 
39  // prepare temporary map between SimTrackId and TrackingParticle index
40  std::map<std::pair<size_t, EncodedEventId>, TrackingParticleRef> mapping;
41  for (TrackingParticleCollection::size_type itp = 0; itp < TPCollectionH.product()->size(); ++itp) {
42  TrackingParticleRef trackingParticle(TPCollectionH, itp);
43  // SimTracks inside TrackingParticle
44  EncodedEventId eid(trackingParticle->eventId());
45  for (auto itrk = trackingParticle->g4Track_begin(); itrk != trackingParticle->g4Track_end(); ++itrk) {
46  std::pair<uint32_t, EncodedEventId> trkid(itrk->trackId(), eid);
47  mapping.insert(std::make_pair(trkid, trackingParticle));
48  }
49  }
50 
51  // PSimHits
52  for (auto const& psit : _simHitSrc ) {
53  edm::Handle<edm::PSimHitContainer> PSimHitCollectionH;
54  iEvent.getByToken(psit, PSimHitCollectionH);
55  for (unsigned int psimHit = 0;psimHit != PSimHitCollectionH->size();++psimHit) {
56  TrackPSimHitRef pSimHitRef(PSimHitCollectionH,psimHit);
57  std::pair<uint32_t, EncodedEventId> simTkIds(pSimHitRef->trackId(),pSimHitRef->eventId());
58  auto ipos = mapping.find(simTkIds);
59  if (ipos != mapping.end()) {
60  simHitTPList->push_back(std::make_pair(ipos->second,pSimHitRef));
61  }
62  }
63  }
64 
65  std::sort(simHitTPList->begin(),simHitTPList->end(),simHitTPAssociationListGreater);
66  iEvent.put(std::move(simHitTPList));
67 
68 }
69 
72 
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:122
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:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t size_type
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
T const * product() const
Definition: Handle.h:81
std::vector< SimHitTPPair > SimHitTPAssociationList
HLT enums.
def move(src, dest)
Definition: eostools.py:510