CMS 3D CMS Logo

MtdSimLayerClusterToTPAssociatorByTrackIdImpl.cc
Go to the documentation of this file.
1 //
4 
6 
7 using namespace reco;
8 using namespace std;
9 
10 /* Constructor */
13  : productGetter_(&productGetter) {}
14 
15 //
16 //---member functions
17 //
18 
21  const edm::Handle<TrackingParticleCollection>& trackingParticleH) const {
22  SimToTPCollectionMtd outputCollection(productGetter_);
23 
24  // -- get the collections
25  const auto& simClusters = *simClusH.product();
26  const auto& trackingParticles = *trackingParticleH.product();
27 
28  // -- Loop over tracking particles and build a temporary map of trackId, eventId --> tpRef
29  std::map<std::pair<unsigned int, uint32_t>, TrackingParticleRef> tpIdMap;
30  for (auto tpIt = trackingParticles.begin(); tpIt != trackingParticles.end(); tpIt++) {
31  const auto& tp = *tpIt;
32  unsigned int tpTrackId = tp.g4Tracks()[0].trackId();
33  EncodedEventId tpEventId = tp.eventId();
34  TrackingParticleRef tpRef =
35  edm::Ref<TrackingParticleCollection>(trackingParticleH, tpIt - trackingParticles.begin());
36  tpIdMap[std::make_pair(tpTrackId, tpEventId.rawId())] = tpRef;
37  }
38 
39  // -- loop over sim clusters and get the trackId, eventId
40 
41  LogDebug("MtdSimLayerClusterToTPAssociator")
42  << " Found " << simClusters.size() << " MtdSimLayerClusters in the event";
43 
44  for (auto simClusIt = simClusters.begin(); simClusIt != simClusters.end(); simClusIt++) {
45  const auto& simClus = *simClusIt;
46  size_t simClusIndex = simClusIt - simClusters.begin();
47  MtdSimLayerClusterRef simClusterRef = edm::Ref<MtdSimLayerClusterCollection>(simClusH, simClusIndex);
48  unsigned int simClusTrackId = simClus.g4Tracks()[0].trackId();
49  EncodedEventId simClusEventId = simClus.eventId();
50 
51  // -- Check the trackId offset of the sim hits and keep only clusters with "direct" hits (offset == 0)
52  /*
53  if (simClus.trackIdOffset() != 0 ) continue;
54  */
55 
56  std::pair uniqueId = std::make_pair(simClusTrackId, simClusEventId.rawId());
57  auto it = tpIdMap.find(uniqueId);
58 
59  if (it != tpIdMap.end()) {
60  TrackingParticleRef tpRef = tpIdMap[uniqueId];
61  outputCollection.insert(simClusterRef, tpRef);
62 
63  LogDebug("MtdSimLayerClusterToTPAssociator::associateSimToTP")
64  << "MtdSimLayerCluster: index = " << simClusIndex << " simClus TrackId = " << simClusTrackId
65  << " simClus EventId = " << simClusEventId.rawId() << " simClus Eta = " << simClus.eta()
66  << " simClus Phi = " << simClus.phi() << " simClus Time = " << simClus.simLCTime()
67  << " simClus Energy = " << simClus.simLCEnergy() << std::endl;
68  LogDebug("MtdSimLayerClusterToTPAssociator::associateSimToTP")
69  << " --> Found associated tracking particle: tp TrackId = " << (*tpRef).g4Tracks()[0].trackId()
70  << " tp EventId = " << (*tpRef).eventId().rawId() << std::endl;
71  }
72 
73  } // -- end loop over sim clus
74 
75  return outputCollection;
76 }
77 
80  const edm::Handle<TrackingParticleCollection>& trackingParticleH) const {
81  TPToSimCollectionMtd outputCollection(productGetter_);
82 
83  // -- get the collections
84  const auto& simClusters = *simClusH.product();
85  const auto& trackingParticles = *trackingParticleH.product();
86 
87  // -- Loop over MtdSimLayerClusters and build a temporary map of trackId, eventId --> simClusterRef
88  std::map<std::pair<unsigned int, uint32_t>, std::vector<MtdSimLayerClusterRef>> simClusIdMap;
89  for (auto simClusIt = simClusters.begin(); simClusIt != simClusters.end(); simClusIt++) {
90  const auto& simClus = *simClusIt;
91  unsigned int simClusTrackId = simClus.g4Tracks()[0].trackId();
92  EncodedEventId simClusEventId = simClus.eventId();
93  MtdSimLayerClusterRef simClusterRef =
94  edm::Ref<MtdSimLayerClusterCollection>(simClusH, simClusIt - simClusters.begin());
95  simClusIdMap[std::make_pair(simClusTrackId, simClusEventId.rawId())].push_back(simClusterRef);
96  }
97 
98  // -- Loop over the tracking particles
99  for (auto tpIt = trackingParticles.begin(); tpIt != trackingParticles.end(); tpIt++) {
100  const auto& tp = *tpIt;
101  size_t tpIndex = tpIt - trackingParticles.begin();
102  TrackingParticleRef tpRef = edm::Ref<TrackingParticleCollection>(trackingParticleH, tpIndex);
103  unsigned int tpTrackId = tp.g4Tracks()[0].trackId();
104  EncodedEventId tpEventId = tp.eventId();
105 
106  std::pair uniqueId = std::make_pair(tpTrackId, tpEventId.rawId());
107  auto it = simClusIdMap.find(uniqueId);
108 
109  if (it != simClusIdMap.end()) {
110  for (unsigned int i = 0; i < simClusIdMap[uniqueId].size(); i++) {
111  MtdSimLayerClusterRef simClusterRef = simClusIdMap[uniqueId][i];
112  // -- Check the trackId offset of the sim hits and keep only clusters with "direct" hits (offset == 0)
113  /*
114  if (simClus.trackIdOffset() != 0 ) continue;
115  */
116 
117  outputCollection.insert(tpRef, simClusterRef);
118 
119  LogDebug("MtdSimLayerClusterToTPAssociator")
120  << "Tracking particle: index = " << tpIndex << " tp TrackId = " << tpTrackId
121  << " tp EventId = " << tpEventId.rawId();
122  LogDebug("MtdSimLayerClusterToTPAssociator")
123  << " --> Found associated MtdSimLayerCluster: simClus TrackId = "
124  << (*simClusterRef).g4Tracks()[0].trackId() << " simClus EventId = " << (*simClusterRef).eventId().rawId()
125  << " simClus Eta = " << (*simClusterRef).eta() << " simClus Phi = " << (*simClusterRef).phi()
126  << " simClus Time = " << (*simClusterRef).simLCTime()
127  << " simClus Energy = " << (*simClusterRef).simLCEnergy() << std::endl;
128  }
129  }
130  }
131 
132  return outputCollection;
133 }
reco::TPToSimCollectionMtd associateTPToSim(const edm::Handle< MtdSimLayerClusterCollection > &simClusH, const edm::Handle< TrackingParticleCollection > &trackingParticleH) const override
Associate a TrackingParticle to MtdSimLayerCluster.
uint32_t rawId() const
get the raw id
T const * product() const
Definition: Handle.h:70
reco::SimToTPCollectionMtd associateSimToTP(const edm::Handle< MtdSimLayerClusterCollection > &simClusH, const edm::Handle< TrackingParticleCollection > &trackingParticleH) const override
Associate a MtdSimLayerCluster to TrackingParticle.
void insert(const key_type &k, const data_type &v)
insert an association
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
fixed size matrix
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)
#define LogDebug(id)