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  std::vector<edm::InputTag> tags = cfg.getParameter<std::vector<edm::InputTag>>("simHitSrc");
31  _simHitSrc.reserve(tags.size());
32  for (auto const &tag : tags) {
33  _simHitSrc.emplace_back(consumes<edm::PSimHitContainer>(tag));
34  }
35 }
36 
38 
40  std::unique_ptr<SimHitTPAssociationList> simHitTPList(new SimHitTPAssociationList);
41 
42  // TrackingParticle
44  iEvent.getByToken(_trackingParticleSrc, TPCollectionH);
45 
46  // prepare temporary map between SimTrackId and TrackingParticle index
47  std::unordered_map<UniqueSimTrackId, TrackingParticleRef, UniqueSimTrackIdHash> mapping;
48  auto const &tpColl = *TPCollectionH.product();
49  for (TrackingParticleCollection::size_type itp = 0, size = tpColl.size(); itp < size; ++itp) {
50  auto const &trackingParticle = tpColl[itp];
51  TrackingParticleRef trackingParticleRef(TPCollectionH, itp);
52  // SimTracks inside TrackingParticle
53  EncodedEventId eid(trackingParticle.eventId());
54  for (auto const &trk : trackingParticle.g4Tracks()) {
55  UniqueSimTrackId trkid(trk.trackId(), eid);
56  mapping.insert(std::make_pair(trkid, trackingParticleRef));
57  }
58  }
59 
60  // PSimHits
61  for (auto const &psit : _simHitSrc) {
62  edm::Handle<edm::PSimHitContainer> PSimHitCollectionH;
63  iEvent.getByToken(psit, PSimHitCollectionH);
64  auto const &pSimHitCollection = *PSimHitCollectionH;
65  for (unsigned int psimHitI = 0, size = pSimHitCollection.size(); psimHitI < size; ++psimHitI) {
66  TrackPSimHitRef pSimHitRef(PSimHitCollectionH, psimHitI);
67  auto const &pSimHit = pSimHitCollection[psimHitI];
68  UniqueSimTrackId simTkIds(pSimHit.trackId(), pSimHit.eventId());
69  auto ipos = mapping.find(simTkIds);
70  if (ipos != mapping.end()) {
71  simHitTPList->emplace_back(ipos->second, pSimHitRef);
72  }
73  }
74  }
75 
76  std::sort(simHitTPList->begin(), simHitTPList->end(), simHitTPAssociationListGreater);
77  iEvent.put(std::move(simHitTPList));
78 }
79 
82 
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
PSimHitContainer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
UniqueSimTrackId
std::pair< uint32_t, EncodedEventId > UniqueSimTrackId
Definition: UniqueSimTrackId.h:9
edm::Handle< TrackingParticleCollection >
SimHitTPAssociationProducer::SimHitTPAssociationList
std::vector< SimHitTPPair > SimHitTPAssociationList
Definition: SimHitTPAssociationProducer.h:18
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:39
EDGetToken.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
SimHitTPAssociationProducer::SimHitTPAssociationProducer
SimHitTPAssociationProducer(const edm::ParameterSet &)
Definition: SimHitTPAssociationProducer.cc:25
ModuleDef.h
iEvent
int iEvent
Definition: GenABIO.cc:224
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
edm::EventSetup
Definition: EventSetup.h:58
InputTag.h
looper.cfg
cfg
Definition: looper.py:296
SimHitTPAssociationProducer.h
TrackingParticle.h
UniqueSimTrackId.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
TrackingParticleFwd.h
Frameworkfwd.h
ParameterSetfwd.h
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
EventSetup.h
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
SimHitTPAssociationProducer::_trackingParticleSrc
edm::EDGetTokenT< TrackingParticleCollection > _trackingParticleSrc
Definition: SimHitTPAssociationProducer.h:29
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
taus_updatedMVAIds_cff.mapping
mapping
Definition: taus_updatedMVAIds_cff.py:29
SimHitTPAssociationProducer::~SimHitTPAssociationProducer
~SimHitTPAssociationProducer() override
Definition: SimHitTPAssociationProducer.cc:37
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
SimHitTPAssociationProducer::simHitTPAssociationListGreater
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
Definition: SimHitTPAssociationProducer.h:23