CMS 3D CMS Logo

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

#include <TSToSimTSHitLCAssociatorByEnergyScoreImpl.h>

Inheritance diagram for TSToSimTSHitLCAssociatorByEnergyScoreImpl:
ticl::TracksterToSimTracksterHitLCAssociatorBaseImpl

Public Member Functions

ticl::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...
 
ticl::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...
 
ticl::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 unsigned int > *, std::vector< const HGCRecHit *> &hits)
 
- Public Member Functions inherited from ticl::TracksterToSimTracksterHitLCAssociatorBaseImpl
ticl::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 unsigned int > * hitMap_
 
std::vector< const HGCRecHit * > hits_
 
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 unsigned int > *  hitMap,
std::vector< const HGCRecHit *> &  hits 
)
explicit

Definition at line 7 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References layers_, and recHitTools_.

13  : hardScatterOnly_(hardScatterOnly),
14  recHitTools_(recHitTools),
15  hitMap_(hitMap),
16  hits_(hits),
18  layers_ = recHitTools_->lastLayerBH();
19 }
const std::unordered_map< DetId, const unsigned int > * hitMap_
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)

Member Function Documentation

◆ associateRecoToSim()

ticl::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 ticl::TracksterToSimTracksterHitLCAssociatorBaseImpl.

Definition at line 216 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

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

221  {
223  const auto& links = makeConnections(tCH, lCCH, sCCH, cPCH, sTCH);
224  const auto& recoToSim_sharedEnergyAndScore = std::get<0>(links);
225  for (std::size_t tsId = 0; tsId < recoToSim_sharedEnergyAndScore.size(); ++tsId) {
226  std::size_t numSimTracksters = recoToSim_sharedEnergyAndScore[tsId].size();
227  for (std::size_t simTsId = 0; simTsId < numSimTracksters; ++simTsId) {
228  LogDebug("TSToSimTSHitLCAssociatorByEnergyScoreImpl")
229  << " Trackster Id:\t" << tsId << "\tSimTrackster id:\t" << recoToSim_sharedEnergyAndScore[tsId][simTsId].first
230  << "\tscore:\t" << recoToSim_sharedEnergyAndScore[tsId][simTsId].second << "\n";
231  // Fill AssociationMap
232  returnValue.insert(
233  edm::Ref<ticl::TracksterCollection>(tCH, tsId), // Ref to TS
234  std::make_pair(
236  std::make_pair(recoToSim_sharedEnergyAndScore[tsId][simTsId].first,
237  recoToSim_sharedEnergyAndScore[tsId][simTsId].second)) // Pair <Ref to ST, score>
238  );
239  }
240  }
241  return returnValue;
242 }
ticl::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
U second(std::pair< T, U > const &p)
#define LogDebug(id)

◆ associateSimToReco()

ticl::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 ticl::TracksterToSimTracksterHitLCAssociatorBaseImpl.

Definition at line 244 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

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

249  {
251  const auto& links = makeConnections(tCH, lCCH, sCCH, cPCH, sTCH);
252  const auto& simToReco_sharedEnergyAndScore = std::get<1>(links);
253  for (std::size_t simTsId = 0; simTsId < simToReco_sharedEnergyAndScore.size(); ++simTsId) {
254  std::size_t numTracksters = simToReco_sharedEnergyAndScore[simTsId].size();
255  for (std::size_t tsId = 0; tsId < numTracksters; ++tsId) {
256  LogDebug("TSToSimTSHitLCAssociatorByEnergyScoreImpl")
257  << "Trackster Id:\t" << tsId << "\tSimTrackster id:\t" << simTsId << " Shared energy "
258  << simToReco_sharedEnergyAndScore[simTsId][tsId].first << "\tscore:\t"
259  << simToReco_sharedEnergyAndScore[simTsId][tsId].second << "\n";
260  // Fill AssociationMap
261  returnValue.insert(edm::Ref<ticl::TracksterCollection>(sTCH, simTsId),
262  std::make_pair(edm::Ref<ticl::TracksterCollection>(tCH, tsId),
263  std::make_pair(simToReco_sharedEnergyAndScore[simTsId][tsId].first,
264  simToReco_sharedEnergyAndScore[simTsId][tsId].second)));
265  }
266  }
267  return returnValue;
268 }
ticl::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
U second(std::pair< T, U > const &p)
#define LogDebug(id)

◆ makeConnections()

ticl::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 21 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.cc.

References cms::cuda::assert(), HLT_2024v14_cff::distance, mps_fire::end, f, spr::find(), newFWLiteAna::found, HLT_2024v14_cff::fraction, hitMap_, hits_, 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().

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

◆ hitMap_

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

Definition at line 76 of file TSToSimTSHitLCAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ hits_

std::vector<const HGCRecHit *> TSToSimTSHitLCAssociatorByEnergyScoreImpl::hits_
private

Definition at line 77 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