test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::auto_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(simHitTPList);
67 
68 }
69 
72 
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > _simHitSrc
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:293
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:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t size_type
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
tuple tags
Definition: o2o.py:248
T const * product() const
Definition: Handle.h:81
std::vector< SimHitTPPair > SimHitTPAssociationList
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override