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 
edm::StreamID
Definition: StreamID.h:30
Handle.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SimHitTPAssociationProducer
Definition: SimHitTPAssociationProducer.h:15
ESHandle.h
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::Handle< TrackingParticleCollection >
edm::Ref< TrackingParticleCollection >
EncodedEventId
Definition: EncodedEventId.h:11
MakerMacros.h
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SimHitTPAssociationProducer::_simHitSrc
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > _simHitSrc
Definition: SimHitTPAssociationProducer.h:28
SimHitTPAssociationProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: SimHitTPAssociationProducer.cc:31
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::ParameterSet
Definition: ParameterSet.h:47
SimHitTPAssociationProducer::SimHitTPAssociationProducer
SimHitTPAssociationProducer(const edm::ParameterSet &)
Definition: SimHitTPAssociationProducer.cc:17
ModuleDef.h
iEvent
int iEvent
Definition: GenABIO.cc:224
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
edm::EventSetup
Definition: EventSetup.h:57
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
SimHitTPAssociationProducer.h
SimHitTPAssociationProducer::SimHitTPAssociationList
std::vector< SimHitTPPair > SimHitTPAssociationList
Definition: SimHitTPAssociationProducer.h:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
EventSetup.h
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
SimHitTPAssociationProducer::_trackingParticleSrc
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
Definition: SimHitTPAssociationProducer.h:29
edm::Event
Definition: Event.h:73
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
SimHitTPAssociationProducer::~SimHitTPAssociationProducer
~SimHitTPAssociationProducer() override
Definition: SimHitTPAssociationProducer.cc:29
SimHitTPAssociationProducer::simHitTPAssociationListGreater
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
Definition: SimHitTPAssociationProducer.h:23