CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
TSToSimTSHitLCAssociatorByEnergyScoreImpl Class Reference

#include <TSToSimTSHitLCAssociatorByEnergyScoreImpl.h>

Inheritance diagram for TSToSimTSHitLCAssociatorByEnergyScoreImpl:
hgcal::TracksterToSimTracksterHitLCAssociatorBaseImpl

Public Member Functions

hgcal::RecoToSimCollectionSimTracksters associateRecoToSim (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const override
 Associate a Trackster to SimClusters. More...
 
hgcal::SimToRecoCollectionSimTracksters associateSimToReco (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const override
 Associate a SimCluster to Tracksters. More...
 
hgcal::association_t makeConnections (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
 
 TSToSimTSHitLCAssociatorByEnergyScoreImpl (edm::EDProductGetter const &, bool, std::shared_ptr< hgcal::RecHitTools >, const std::unordered_map< DetId, const HGCRecHit *> *)
 
- Public Member Functions inherited from hgcal::TracksterToSimTracksterHitLCAssociatorBaseImpl
hgcal::association_t makeConnections (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
 
 TracksterToSimTracksterHitLCAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TracksterToSimTracksterHitLCAssociatorBaseImpl ()
 Destructor. More...
 

Private Attributes

const bool hardScatterOnly_
 
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
 
unsigned layers_
 
edm::EDProductGetter const * productGetter_
 
std::shared_ptr< hgcal::RecHitToolsrecHitTools_
 

Detailed Description

Definition at line 45 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.h.

Constructor & Destructor Documentation

◆ TSToSimTSHitLCAssociatorByEnergyScoreImpl()

TSToSimTSHitLCAssociatorByEnergyScoreImpl::TSToSimTSHitLCAssociatorByEnergyScoreImpl ( edm::EDProductGetter const &  productGetter,
bool  hardScatterOnly,
std::shared_ptr< hgcal::RecHitTools recHitTools,
const std::unordered_map< DetId, const HGCRecHit *> *  hitMap 
)
explicit

Definition at line 7 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References layers_, and recHitTools_.

12  : hardScatterOnly_(hardScatterOnly), recHitTools_(recHitTools), hitMap_(hitMap), productGetter_(&productGetter) {
13  layers_ = recHitTools_->lastLayerBH();
14 }
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)

Member Function Documentation

◆ associateRecoToSim()

hgcal::RecoToSimCollectionSimTracksters TSToSimTSHitLCAssociatorByEnergyScoreImpl::associateRecoToSim ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< SimClusterCollection > &  sCCH,
const edm::Handle< CaloParticleCollection > &  cPCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const
overridevirtual

Associate a Trackster to SimClusters.

Reimplemented from hgcal::TracksterToSimTracksterHitLCAssociatorBaseImpl.

Definition at line 209 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References dqmdumpme::first, edm::AssociationMap< Tag >::insert(), electronStore::links, LogDebug, makeConnections(), productGetter_, and edm::second().

214  {
216  const auto& links = makeConnections(tCH, lCCH, sCCH, cPCH, sTCH);
217  const auto& recoToSim_sharedEnergyAndScore = std::get<0>(links);
218  for (std::size_t tsId = 0; tsId < recoToSim_sharedEnergyAndScore.size(); ++tsId) {
219  std::size_t numSimTracksters = recoToSim_sharedEnergyAndScore[tsId].size();
220  for (std::size_t simTsId = 0; simTsId < numSimTracksters; ++simTsId) {
221  LogDebug("TSToSimTSHitLCAssociatorByEnergyScoreImpl")
222  << " Trackster Id:\t" << tsId << "\tSimTrackster id:\t" << recoToSim_sharedEnergyAndScore[tsId][simTsId].first
223  << "\tscore:\t" << recoToSim_sharedEnergyAndScore[tsId][simTsId].second << "\n";
224  // Fill AssociationMap
225  returnValue.insert(
226  edm::Ref<ticl::TracksterCollection>(tCH, tsId), // Ref to TS
227  std::make_pair(
229  std::make_pair(recoToSim_sharedEnergyAndScore[tsId][simTsId].first,
230  recoToSim_sharedEnergyAndScore[tsId][simTsId].second)) // Pair <Ref to ST, score>
231  );
232  }
233  }
234  return returnValue;
235 }
U second(std::pair< T, U > const &p)
hgcal::association_t makeConnections(const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
#define LogDebug(id)

◆ associateSimToReco()

hgcal::SimToRecoCollectionSimTracksters TSToSimTSHitLCAssociatorByEnergyScoreImpl::associateSimToReco ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< SimClusterCollection > &  sCCH,
const edm::Handle< CaloParticleCollection > &  cPCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const
overridevirtual

Associate a SimCluster to Tracksters.

Reimplemented from hgcal::TracksterToSimTracksterHitLCAssociatorBaseImpl.

Definition at line 237 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References dqmdumpme::first, edm::AssociationMap< Tag >::insert(), electronStore::links, LogDebug, makeConnections(), productGetter_, and edm::second().

242  {
244  const auto& links = makeConnections(tCH, lCCH, sCCH, cPCH, sTCH);
245  const auto& simToReco_sharedEnergyAndScore = std::get<1>(links);
246  for (std::size_t simTsId = 0; simTsId < simToReco_sharedEnergyAndScore.size(); ++simTsId) {
247  std::size_t numTracksters = simToReco_sharedEnergyAndScore[simTsId].size();
248  for (std::size_t tsId = 0; tsId < numTracksters; ++tsId) {
249  LogDebug("TSToSimTSHitLCAssociatorByEnergyScoreImpl")
250  << "Trackster Id:\t" << tsId << "\tSimTrackster id:\t" << simTsId << " Shared energy "
251  << simToReco_sharedEnergyAndScore[simTsId][tsId].first << "\tscore:\t"
252  << simToReco_sharedEnergyAndScore[simTsId][tsId].second << "\n";
253  // Fill AssociationMap
254  returnValue.insert(edm::Ref<ticl::TracksterCollection>(sTCH, simTsId),
255  std::make_pair(edm::Ref<ticl::TracksterCollection>(tCH, tsId),
256  std::make_pair(simToReco_sharedEnergyAndScore[simTsId][tsId].first,
257  simToReco_sharedEnergyAndScore[simTsId][tsId].second)));
258  }
259  }
260  return returnValue;
261 }
U second(std::pair< T, U > const &p)
hgcal::association_t makeConnections(const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH, const edm::Handle< CaloParticleCollection > &cPCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
#define LogDebug(id)

◆ makeConnections()

hgcal::association_t TSToSimTSHitLCAssociatorByEnergyScoreImpl::makeConnections ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< SimClusterCollection > &  sCCH,
const edm::Handle< CaloParticleCollection > &  cPCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const

Definition at line 16 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References cms::cuda::assert(), HLT_2024v13_cff::distance, mps_fire::end, f, spr::find(), newFWLiteAna::found, HLT_2024v13_cff::fraction, hitMap_, mps_fire::i, edm::HandleBase::id(), dqmiolumiharvest::j, hltEgammaHGCALIDVarsL1Seeded_cfi::layerClusters, SiStripPI::min, edm::Handle< T >::product(), egamma::sharedEnergy(), findQualityFiles::v, and AlignmentTracksFromVertexSelector_cfi::vertices.

Referenced by associateRecoToSim(), and associateSimToReco().

21  {
22  // Get collections
23  const auto& tracksters = *tCH.product();
24  const auto& layerClusters = *lCCH.product();
25  const auto& sC = *sCCH.product();
26  const auto& cP = *cPCH.product();
27  const auto cPHandle_id = cPCH.id();
28  const auto& simTSs = *sTCH.product();
29  const auto nTracksters = tracksters.size();
30  const auto nSimTracksters = simTSs.size();
31 
32  std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimTSId_Map;
33  std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdSimClusterId_Map;
34  std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdCaloParticleId_Map;
35  std::unordered_map<DetId, std::vector<std::pair<int, float>>> detIdToRecoTSId_Map;
36 
37  hgcal::sharedEnergyAndScore_t recoToSim_sharedEnergyAndScore;
38  hgcal::sharedEnergyAndScore_t simToReco_sharedEnergyAndScore;
39 
40  recoToSim_sharedEnergyAndScore.resize(nTracksters);
41  simToReco_sharedEnergyAndScore.resize(nSimTracksters);
42 
43  for (size_t i = 0; i < nTracksters; ++i)
44  recoToSim_sharedEnergyAndScore[i].resize(nSimTracksters);
45  for (size_t i = 0; i < nSimTracksters; ++i)
46  simToReco_sharedEnergyAndScore[i].resize(nTracksters);
47 
48  // fill sim maps
49 
50  for (size_t i = 0; i < sC.size(); ++i) {
51  for (const auto& haf : sC[i].hits_and_fractions()) {
52  detIdSimClusterId_Map[haf.first].emplace_back(i, haf.second);
53  }
54  }
55 
56  for (size_t i = 0; i < cP.size(); ++i) {
57  for (const auto& sc : cP[i].simClusters()) {
58  for (const auto& haf : sc->hits_and_fractions()) {
59  auto hitId = haf.first;
60  auto found = std::find_if(detIdCaloParticleId_Map[hitId].begin(),
61  detIdCaloParticleId_Map[hitId].end(),
62  [=](const std::pair<int, float>& v) { return v.first == static_cast<int>(i); });
63  if (found == detIdCaloParticleId_Map[hitId].end())
64  detIdCaloParticleId_Map[haf.first].emplace_back(i, haf.second);
65  else
66  found->second += haf.second;
67  }
68  }
69  }
70 
71  for (size_t i = 0; i < nSimTracksters; ++i) {
72  const auto& lcsInSimTrackster = simTSs[i].vertices();
73  const auto& multiplicities = simTSs[i].vertex_multiplicity();
74  for (size_t j = 0; j < lcsInSimTrackster.size(); ++j) {
75  assert(multiplicities[j] > 0.f);
76  const auto& v = lcsInSimTrackster[j];
77  float fraction = 1.f / multiplicities[j];
78  for (const auto& haf : layerClusters[v].hitsAndFractions()) {
79  detIdSimTSId_Map[haf.first].emplace_back(i, haf.second * fraction);
80  }
81  }
82  }
83 
84  // fill reco map
85 
86  for (size_t i = 0; i < nTracksters; ++i) {
87  const auto& lcsInSimTrackster = tracksters[i].vertices();
88  const auto& multiplicities = tracksters[i].vertex_multiplicity();
89  for (size_t j = 0; j < lcsInSimTrackster.size(); ++j) {
90  assert(multiplicities[j] > 0.f);
91  const auto& v = lcsInSimTrackster[j];
92  float fraction = 1.f / multiplicities[j];
93  for (const auto& haf : layerClusters[v].hitsAndFractions()) {
94  detIdToRecoTSId_Map[haf.first].emplace_back(i, haf.second * fraction);
95  }
96  }
97  }
98 
99  std::vector<float> denominator_simToReco(nSimTracksters, 0.f);
100  std::vector<std::vector<float>> numerator_simToReco(nSimTracksters);
101  std::vector<std::vector<float>> sharedEnergy(nSimTracksters);
102 
103  for (size_t i = 0; i < nSimTracksters; ++i) {
104  numerator_simToReco[i].resize(nTracksters, 0.f);
105  sharedEnergy[i].resize(nTracksters, 0.f);
106 
107  const auto seedIndex = simTSs[i].seedIndex();
108  const auto& lcsInSimTrackster = simTSs[i].vertices();
109 
110  for (const auto& v : lcsInSimTrackster) {
111  for (const auto& haf : layerClusters[v].hitsAndFractions()) {
112  const auto hitId = haf.first;
113  float simFraction = 0.f;
114 
115  std::vector<std::pair<int, float>>::iterator found;
116  if (simTSs[i].seedID() == cPHandle_id) {
117  found = std::find_if(detIdSimTSId_Map[hitId].begin(),
118  detIdSimTSId_Map[hitId].end(),
119  [=](const std::pair<int, float>& v) { return v.first == seedIndex; });
120  if (found != detIdSimTSId_Map[hitId].end()) {
121  const auto iLC = std::find(simTSs[i].vertices().begin(), simTSs[i].vertices().end(), v);
122  const auto lcFraction =
123  1.f / simTSs[i].vertex_multiplicity(std::distance(std::begin(simTSs[i].vertices()), iLC));
124  simFraction = found->second * lcFraction;
125  }
126  } else {
127  found = std::find_if(detIdSimClusterId_Map[hitId].begin(),
128  detIdSimClusterId_Map[hitId].end(),
129  [=](const std::pair<int, float>& v) { return v.first == seedIndex; });
130  if (found != detIdSimClusterId_Map[hitId].end()) {
131  simFraction = found->second;
132  }
133  }
134 
135  float hitEnergy = hitMap_->find(hitId)->second->energy();
136  float hitEnergySquared = hitEnergy * hitEnergy;
137  float simFractionSquared = simFraction * simFraction;
138  denominator_simToReco[i] += simFractionSquared * hitEnergySquared;
139  for (size_t j = 0; j < nTracksters; ++j) {
140  float recoFraction = 0.f;
141 
142  auto found_reco =
143  std::find_if(detIdToRecoTSId_Map[hitId].begin(),
144  detIdToRecoTSId_Map[hitId].end(),
145  [=](const std::pair<int, float>& v) { return v.first == static_cast<int>(j); });
146  if (found_reco != detIdToRecoTSId_Map[hitId].end())
147  recoFraction = found_reco->second;
148  numerator_simToReco[i][j] +=
149  std::min(simFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
150  hitEnergySquared;
151  sharedEnergy[i][j] += std::min(simFraction, recoFraction) * hitEnergy;
152  }
153  }
154  }
155  }
156 
157  std::vector<float> denominator_recoToSim(nTracksters, 0.f);
158  std::vector<std::vector<float>> numerator_recoToSim(nTracksters);
159 
160  for (unsigned int i = 0; i < nTracksters; ++i) {
161  numerator_recoToSim[i].resize(nSimTracksters, 0.f);
162  const auto& lcsInTrackster = tracksters[i].vertices();
163  for (const auto& v : lcsInTrackster) {
164  for (const auto& haf : layerClusters[v].hitsAndFractions()) {
165  const auto hitId = haf.first;
166  float recoFraction = 0.f;
167 
168  auto found = std::find_if(detIdToRecoTSId_Map[hitId].begin(),
169  detIdToRecoTSId_Map[hitId].end(),
170  [=](const std::pair<int, float>& v) { return v.first == static_cast<int>(i); });
171  if (found != detIdToRecoTSId_Map[hitId].end())
172  recoFraction = found->second;
173 
174  float hitEnergy = hitMap_->find(hitId)->second->energy();
175  float hitEnergySquared = hitEnergy * hitEnergy;
176  float recoFractionSquared = recoFraction * recoFraction;
177  denominator_recoToSim[i] += recoFractionSquared * hitEnergySquared;
178 
179  for (size_t j = 0; j < nSimTracksters; ++j) {
180  float simFraction = 0.f;
181 
182  auto found_sim = std::find_if(detIdSimTSId_Map[hitId].begin(),
183  detIdSimTSId_Map[hitId].end(),
184  [=](const std::pair<int, float>& v) { return v.first == static_cast<int>(j); });
185  if (found_sim != detIdSimTSId_Map[hitId].end())
186  simFraction = found_sim->second;
187  numerator_recoToSim[i][j] +=
188  std::min(recoFractionSquared, (simFraction - recoFraction) * (simFraction - recoFraction)) *
189  hitEnergySquared;
190  }
191  }
192  }
193  }
194 
195  // compute score
196 
197  for (size_t i = 0; i < nSimTracksters; ++i) {
198  for (size_t j = 0; j < nTracksters; ++j) {
199  simToReco_sharedEnergyAndScore[i][j].first = sharedEnergy[i][j];
200  simToReco_sharedEnergyAndScore[i][j].second = numerator_simToReco[i][j] / denominator_simToReco[i];
201  recoToSim_sharedEnergyAndScore[j][i].first = sharedEnergy[i][j];
202  recoToSim_sharedEnergyAndScore[j][i].second = numerator_recoToSim[j][i] / denominator_recoToSim[j];
203  }
204  }
205 
206  return {recoToSim_sharedEnergyAndScore, simToReco_sharedEnergyAndScore};
207 }
ProductID id() const
Definition: HandleBase.cc:29
T const * product() const
Definition: Handle.h:70
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
double f[11][100]
std::vector< std::vector< std::pair< float, float > > > sharedEnergyAndScore_t
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)

Member Data Documentation

◆ hardScatterOnly_

const bool TSToSimTSHitLCAssociatorByEnergyScoreImpl::hardScatterOnly_
private

Definition at line 73 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.h.

◆ hitMap_

const std::unordered_map<DetId, const HGCRecHit *>* TSToSimTSHitLCAssociatorByEnergyScoreImpl::hitMap_
private

Definition at line 75 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ layers_

unsigned TSToSimTSHitLCAssociatorByEnergyScoreImpl::layers_
private

◆ productGetter_

edm::EDProductGetter const* TSToSimTSHitLCAssociatorByEnergyScoreImpl::productGetter_
private

◆ recHitTools_

std::shared_ptr<hgcal::RecHitTools> TSToSimTSHitLCAssociatorByEnergyScoreImpl::recHitTools_
private