CMS 3D CMS Logo

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

#include <TSToSimTSAssociatorByEnergyScoreImpl.h>

Inheritance diagram for TSToSimTSAssociatorByEnergyScoreImpl:
hgcal::TracksterToSimTracksterAssociatorBaseImpl

Public Member Functions

hgcal::RecoToSimCollectionSimTracksters associateRecoToSim (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, 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< ticl::TracksterCollection > &sTCH) const override
 Associate a SimCluster to Tracksters. More...
 
 TSToSimTSAssociatorByEnergyScoreImpl (edm::EDProductGetter const &, bool, std::shared_ptr< hgcal::RecHitTools >, const std::unordered_map< DetId, const HGCRecHit * > *)
 
- Public Member Functions inherited from hgcal::TracksterToSimTracksterAssociatorBaseImpl
 TracksterToSimTracksterAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TracksterToSimTracksterAssociatorBaseImpl ()
 Destructor. More...
 

Private Member Functions

hgcal::association makeConnections (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
 

Private Attributes

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

Detailed Description

Definition at line 40 of file TSToSimTSAssociatorByEnergyScoreImpl.h.

Constructor & Destructor Documentation

◆ TSToSimTSAssociatorByEnergyScoreImpl()

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

Definition at line 5 of file TSToSimTSAssociatorByEnergyScoreImpl.cc.

10  : hardScatterOnly_(hardScatterOnly), recHitTools_(recHitTools), hitMap_(hitMap), productGetter_(&productGetter) {
11  layers_ = recHitTools_->lastLayerBH();
12 }

References layers_, and recHitTools_.

Member Function Documentation

◆ associateRecoToSim()

hgcal::RecoToSimCollectionSimTracksters TSToSimTSAssociatorByEnergyScoreImpl::associateRecoToSim ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const
overridevirtual

Associate a Trackster to SimClusters.

Reimplemented from hgcal::TracksterToSimTracksterAssociatorBaseImpl.

Definition at line 432 of file TSToSimTSAssociatorByEnergyScoreImpl.cc.

435  {
437  const auto& links = makeConnections(tCH, lCCH, sTCH);
438 
439  const auto& stsInTrackster = std::get<0>(links);
440  for (size_t tsId = 0; tsId < stsInTrackster.size(); ++tsId) {
441  for (auto& stPair : stsInTrackster[tsId]) {
442  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "Trackster Id:\t" << tsId << "\tSimTrackster id:\t"
443  << stPair.first << "\tscore:\t" << stPair.second << "\n";
444  // Fill AssociationMap
445  returnValue.insert(edm::Ref<ticl::TracksterCollection>(tCH, tsId), // Ref to TS
446  std::make_pair(edm::Ref<ticl::TracksterCollection>(sTCH, stPair.first),
447  stPair.second) // Pair <Ref to ST, score>
448  );
449  }
450  }
451  return returnValue;
452 }

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

◆ associateSimToReco()

hgcal::SimToRecoCollectionSimTracksters TSToSimTSAssociatorByEnergyScoreImpl::associateSimToReco ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const
overridevirtual

Associate a SimCluster to Tracksters.

Reimplemented from hgcal::TracksterToSimTracksterAssociatorBaseImpl.

Definition at line 454 of file TSToSimTSAssociatorByEnergyScoreImpl.cc.

457  {
459  const auto& links = makeConnections(tCH, lCCH, sTCH);
460  const auto& tssInSimTrackster = std::get<1>(links);
461  for (size_t stId = 0; stId < tssInSimTrackster.size(); ++stId) {
462  for (auto& tsPair : tssInSimTrackster[stId].tracksterIdToEnergyAndScore) {
463  returnValue.insert(
464  edm::Ref<ticl::TracksterCollection>(sTCH, stId), // Ref to ST
465  std::make_pair(edm::Ref<ticl::TracksterCollection>(tCH, tsPair.first), // Pair <Ref to TS,
466  std::make_pair(tsPair.second.first, tsPair.second.second)) // pair <energy, score> >
467  );
468  }
469  }
470  return returnValue;
471 }

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

◆ makeConnections()

hgcal::association TSToSimTSAssociatorByEnergyScoreImpl::makeConnections ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< ticl::TracksterCollection > &  sTCH 
) const
private

Definition at line 14 of file TSToSimTSAssociatorByEnergyScoreImpl.cc.

17  {
18  // Get collections
19  const auto& tracksters = *tCH.product();
20  const auto& layerClusters = *lCCH.product();
21  const auto& simTracksters = *sTCH.product();
22  auto nTracksters = tracksters.size();
23 
24  //There shouldn't be any SimTrackster without vertices, but maybe they will be added later.
25  auto nSimTracksters = simTracksters.size();
26  std::vector<size_t> sTIndices;
27  for (unsigned int stId = 0; stId < nSimTracksters; ++stId) {
28  if (simTracksters[stId].vertices().empty()) {
29  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
30  << "Excluding SimTrackster " << stId << " witH no vertices!" << std::endl;
31  continue;
32  }
33  sTIndices.emplace_back(stId);
34  }
35  nSimTracksters = sTIndices.size();
36 
37  // Initialize tssInSimTrackster. To be returned outside, since it contains the
38  // information to compute the SimTrackster-To-Trackster score.
39  // tssInSimTrackster[stId]:
40  hgcal::simTracksterToTrackster tssInSimTrackster;
41  tssInSimTrackster.resize(nSimTracksters);
42  for (unsigned int i = 0; i < nSimTracksters; ++i) {
43  tssInSimTrackster[i].simTracksterId = i;
44  tssInSimTrackster[i].energy = 0.f;
45  tssInSimTrackster[i].lcs_and_fractions.clear();
46  }
47 
48  // Fill lcToSimTracksterId_Map and update tssInSimTrackster
49  std::unordered_map<int, std::vector<hgcal::lcInfoInTrackster>> lcToSimTracksterId_Map;
50  for (const auto& stId : sTIndices) {
51  const auto& lcs = simTracksters[stId].vertices();
52  int lcInSimTst = 0;
53  for (const auto& lcId : lcs) {
54  const auto fraction = 1.f / simTracksters[stId].vertex_multiplicity(lcInSimTst++);
55 
56  const auto lc_find_it = lcToSimTracksterId_Map.find(lcId);
57  if (lc_find_it == lcToSimTracksterId_Map.end()) {
58  lcToSimTracksterId_Map[lcId] = std::vector<hgcal::lcInfoInTrackster>();
59  }
60  lcToSimTracksterId_Map[lcId].emplace_back(stId, fraction);
61 
62  tssInSimTrackster[stId].energy += fraction * layerClusters[lcId].energy();
63  tssInSimTrackster[stId].lcs_and_fractions.emplace_back(lcId, fraction);
64  }
65  } // end of loop over SimTracksters
66 
67 #ifdef EDM_ML_DEBUG
68  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
69  << "tssInSimTrackster INFO (Only SimTrackster filled at the moment)" << std::endl;
70  for (size_t st = 0; st < tssInSimTrackster.size(); ++st) {
71  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "For SimTrackster Idx: " << st << " we have: " << std::endl;
72  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
73  << "\tSimTracksterIdx:\t" << tssInSimTrackster[st].simTracksterId << std::endl;
74  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "\tEnergy:\t" << tssInSimTrackster[st].energy << std::endl;
75  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "\t# of clusters:\t" << layerClusters.size() << std::endl;
76  double tot_energy = 0.;
77  for (auto const& lcaf : tssInSimTrackster[st].lcs_and_fractions) {
78  const auto lcEn = lcaf.second * layerClusters[lcaf.first].energy();
79  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
80  << "\tLC/fraction/energy: " << (uint32_t)lcaf.first << "/" << lcaf.second << "/" << lcEn << std::endl;
81  tot_energy += lcEn;
82  }
83  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "\tTot Sum lcaf: " << tot_energy << std::endl;
84  for (auto const& ts : tssInSimTrackster[st].tracksterIdToEnergyAndScore) {
85  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
86  << "\ttsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl;
87  }
88  }
89 
90  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "lcToSimTracksterId_Map INFO" << std::endl;
91  for (auto const& lc : lcToSimTracksterId_Map) {
92  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
93  << "For lcId: " << (uint32_t)lc.first
94  << " we have found the following connections with SimTracksters:" << std::endl;
95  for (auto const& st : lc.second) {
96  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
97  << "\tSimTrackster Id: " << st.clusterId << " with fraction: " << st.fraction
98  << " and energy: " << st.fraction * layerClusters[lc.first].energy() << std::endl;
99  }
100  }
101 #endif
102 
103  // Fill stsInTrackster and update tssInSimTrackster
104  // this contains the ids of the simTracksters contributing with at least one
105  // hit to the Trackster. To be returned since this contains the information
106  // to compute the Trackster-To-SimTrackster score.
107  hgcal::tracksterToSimTrackster stsInTrackster; //[tsId][stId]->(energy,score)
108  stsInTrackster.resize(nTracksters);
109 
110  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
111  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
112  const auto lcId = tracksters[tsId].vertices(i);
113  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
114 
115  const auto lc_find_in_ST = lcToSimTracksterId_Map.find(lcId);
116 
117  if (lc_find_in_ST != lcToSimTracksterId_Map.end()) {
118  //Loops through all the simTracksters that contain the layer cluster under study
119  //Here is time to update the tssInSimTrackster and connect the SimTrackster with all
120  //the Tracksters that have the current layer cluster matched.
121  for (const auto& st : lc_find_in_ST->second) {
122  //tssInSimTrackster[simTracksterId][layerclusterId]-> (energy,score)
123  //ST_i - > TS_j, TS_k, ...
124  tssInSimTrackster[st.clusterId].tracksterIdToEnergyAndScore[tsId].first +=
125  lcFractionInTs * st.fraction * layerClusters[lcId].energy();
126  //TS_i -> ST_j, ST_k, ...
127  stsInTrackster[tsId].emplace_back(st.clusterId, 0.f);
128  }
129  }
130  } // End loop over LayerClusters in Trackster
131  } // End of loop over Tracksters
132 
133 #ifdef EDM_ML_DEBUG
134  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
135  for (const auto& lcId : tracksters[tsId].vertices()) {
136  const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
137  unsigned int numberOfHitsInLC = hits_and_fractions.size();
138 
139  // This vector will store, for each hit in the Layercluster, the index of
140  // the SimTrackster that contributed the most, in terms of energy, to it.
141  // Special values are:
142  //
143  // -2 --> the reconstruction fraction of the RecHit is 0 (used in the past to monitor Halo Hits)
144  // -3 --> same as before with the added condition that no SimTrackster has been linked to this RecHit
145  // -1 --> the reco fraction is >0, but no SimTrackster has been linked to it
146  // >=0 --> index of the linked SimTrackster
147  std::vector<int> hitsToSimTracksterId(numberOfHitsInLC);
148  // This will store the index of the SimTrackster linked to the LayerCluster that has the largest number of hits in common.
149  int maxSTId_byNumberOfHits = -1;
150  // This will store the maximum number of shared hits between a LayerCluster and a SimTrackster
151  unsigned int maxSTNumberOfHitsInLC = 0;
152  // This will store the index of the SimTrackster linked to the LayerCluster that has the largest energy in common.
153  int maxSTId_byEnergy = -1;
154  // This will store the maximum number of shared energy between a LayerCluster and a SimTrackster
155  float maxEnergySharedLCandST = 0.f;
156  // This will store the fraction of the LayerCluster energy shared with the best(energy) SimTrackster: e_shared/lc_energy
157  float energyFractionOfLCinST = 0.f;
158  // This will store the fraction of the SimTrackster energy shared with the Trackster: e_shared/sc_energy
159  float energyFractionOfSTinLC = 0.f;
160  std::unordered_map<unsigned, unsigned> occurrencesSTinLC;
161  unsigned int numberOfNoiseHitsInLC = 0;
162  std::unordered_map<unsigned, float> STEnergyInLC;
163 
164  const auto lc_find_in_ST = lcToSimTracksterId_Map.find(lcId);
165  for (unsigned int hitId = 0; hitId < numberOfHitsInLC; hitId++) {
166  const auto rhFraction = hits_and_fractions[hitId].second;
167  // if the fraction is zero or the hit does not belong to any SimTrackster,
168  // set the SimTrackster Id for the hit to -1; this will
169  // contribute to the number of noise hits
170 
171  // MR Remove the case in which the fraction is 0, since this could be a
172  // real hit that has been marked as halo.
173  if (rhFraction == 0.) {
174  hitsToSimTracksterId[hitId] = -2;
175  }
176  //Now check if there are SimTracksters linked to this rechit of the layercluster
177  if (lc_find_in_ST == lcToSimTracksterId_Map.end()) {
178  hitsToSimTracksterId[hitId] -= 1;
179  } else {
180  auto maxSTEnergyInLC = 0.f;
181  auto maxSTId = -1;
182  //Loop through all the linked SimTracksters
183  for (const auto& st : lc_find_in_ST->second) {
184  const auto stId = st.clusterId;
185  STEnergyInLC[stId] += st.fraction * layerClusters[lcId].energy();
186  // Keep track of which SimTrackster contributed the most, in terms
187  // of energy, to this specific Layer Cluster.
188  if (STEnergyInLC[stId] > maxSTEnergyInLC) {
189  maxSTEnergyInLC = STEnergyInLC[stId];
190  maxSTId = stId;
191  }
192  }
193  hitsToSimTracksterId[hitId] = maxSTId;
194  }
195  } // End loop over hits on a LayerCluster
196 
197  for (const auto& c : hitsToSimTracksterId) {
198  if (c < 0) {
199  numberOfNoiseHitsInLC++;
200  } else {
201  occurrencesSTinLC[c]++;
202  }
203  }
204 
205  for (const auto& c : occurrencesSTinLC) {
206  if (c.second > maxSTNumberOfHitsInLC) {
207  maxSTId_byNumberOfHits = c.first;
208  maxSTNumberOfHitsInLC = c.second;
209  }
210  }
211 
212  for (const auto& c : STEnergyInLC) {
213  if (c.second > maxEnergySharedLCandST) {
214  maxSTId_byEnergy = c.first;
215  maxEnergySharedLCandST = c.second;
216  }
217  }
218 
219  float totalSTEnergyOnLayer = 0.f;
220  if (maxSTId_byEnergy >= 0) {
221  totalSTEnergyOnLayer = tssInSimTrackster[maxSTId_byEnergy].energy;
222  energyFractionOfSTinLC = maxEnergySharedLCandST / totalSTEnergyOnLayer;
223  if (tracksters[tsId].raw_energy() > 0.f) {
224  energyFractionOfLCinST = maxEnergySharedLCandST / tracksters[tsId].raw_energy();
225  }
226  }
227 
228  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
229  << std::setw(12) << "TracksterID:\t" << std::setw(12) << "layerCluster\t" << std::setw(10) << "lc energy\t"
230  << std::setw(5) << "nhits\t" << std::setw(12) << "noise hits\t" << std::setw(22) << "maxSTId_byNumberOfHits\t"
231  << std::setw(8) << "nhitsST\t" << std::setw(13) << "maxSTId_byEnergy\t" << std::setw(20)
232  << "maxEnergySharedLCandST\t" << std::setw(22) << "totalSTEnergyOnLayer\t" << std::setw(22)
233  << "energyFractionOfLCinST\t" << std::setw(25) << "energyFractionOfSTinLC\t"
234  << "\n";
235  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
236  << std::setw(12) << tsId << "\t" << std::setw(12) << lcId << "\t" << std::setw(10)
237  << tracksters[tsId].raw_energy() << "\t" << std::setw(5) << numberOfHitsInLC << "\t" << std::setw(12)
238  << numberOfNoiseHitsInLC << "\t" << std::setw(22) << maxSTId_byNumberOfHits << "\t" << std::setw(8)
239  << maxSTNumberOfHitsInLC << "\t" << std::setw(13) << maxSTId_byEnergy << "\t" << std::setw(20)
240  << maxEnergySharedLCandST << "\t" << std::setw(22) << totalSTEnergyOnLayer << "\t" << std::setw(22)
241  << energyFractionOfLCinST << "\t" << std::setw(25) << energyFractionOfSTinLC << "\n";
242  } // End of loop over LayerClusters in Trackster
243  } // End of loop over Tracksters
244 
245  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
246  << "Improved tssInSimTrackster INFO (Now containing the linked tracksters id and energy - score still empty)"
247  << std::endl;
248  for (size_t st = 0; st < tssInSimTrackster.size(); ++st) {
249  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "For SimTrackster Idx: " << st << " we have: " << std::endl;
250  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
251  << " SimTracksterIdx: " << tssInSimTrackster[st].simTracksterId << std::endl;
252  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "\tEnergy:\t" << tssInSimTrackster[st].energy << std::endl;
253  double tot_energy = 0.;
254  for (auto const& lcaf : tssInSimTrackster[st].lcs_and_fractions) {
255  const auto lcEn = lcaf.second * layerClusters[lcaf.first].energy();
256  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
257  << "\tLC/fraction/energy: " << (uint32_t)lcaf.first << "/" << lcaf.second << "/" << lcEn << std::endl;
258  tot_energy += lcEn;
259  }
260  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "\tTot Sum lcaf: " << tot_energy << std::endl;
261  for (auto const& ts : tssInSimTrackster[st].tracksterIdToEnergyAndScore) {
262  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
263  << "\ttsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl;
264  }
265  }
266 
267  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "Improved lcToSimTracksterId_Map INFO" << std::endl;
268  for (auto const& lc : lcToSimTracksterId_Map) {
269  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
270  << "For lcId: " << (uint32_t)lc.first
271  << " we have found the following connections with SimTracksters:" << std::endl;
272  for (auto const& st : lc.second) {
273  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
274  << " SimTrackster Id: " << st.clusterId << " with fraction: " << st.fraction
275  << " and energy: " << st.fraction * layerClusters[lc.first].energy() << std::endl;
276  }
277  }
278 #endif
279 
280  // Update stsInTrackster; compute the score Trackster-to-SimTrackster,
281  // together with the returned AssociationMap
282  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
283  // The SimTracksters contributing to the Trackster's LayerClusters should already be unique.
284  // find the unique SimTracksters id contributing to the Trackster's LayerClusters
285  std::sort(stsInTrackster[tsId].begin(), stsInTrackster[tsId].end());
286  auto last = std::unique(stsInTrackster[tsId].begin(), stsInTrackster[tsId].end());
287  stsInTrackster[tsId].erase(last, stsInTrackster[tsId].end());
288 
289  // If a reconstructed Trackster has energy 0 but is linked to a
290  // SimTrackster, assigned score 1
291  if (tracksters[tsId].raw_energy() == 0. && !stsInTrackster[tsId].empty()) {
292  for (auto& stPair : stsInTrackster[tsId]) {
293  stPair.second = 1.;
294  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
295  << "TracksterId:\t " << tsId << "\tST id:\t" << stPair.first << "\tscore\t " << stPair.second << "\n";
296  }
297  continue;
298  }
299 
300  float invTracksterEnergyWeight = 0.f;
301  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
302  const auto lcId = tracksters[tsId].vertices(i);
303  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
304 
305  const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
306  // Compute the correct normalization
307  for (auto const& haf : hits_and_fractions) {
308  invTracksterEnergyWeight += std::pow(lcFractionInTs * haf.second * hitMap_->at(haf.first)->energy(), 2);
309  }
310  }
311  invTracksterEnergyWeight = 1.f / invTracksterEnergyWeight;
312 
313  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
314  const auto lcId = tracksters[tsId].vertices(i);
315  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
316 
317  const bool lcWithST = (lcToSimTracksterId_Map.find(lcId) != lcToSimTracksterId_Map.end());
318 
319  float lcEnergyWeight = pow(layerClusters[lcId].energy(), 2);
320 
321  for (auto& stPair : stsInTrackster[tsId]) {
322  float stFraction = 0.f;
323  if (lcWithST) {
324  const auto findLCIt = std::find(lcToSimTracksterId_Map[lcId].begin(),
325  lcToSimTracksterId_Map[lcId].end(),
326  hgcal::lcInfoInTrackster{stPair.first, 0.f});
327  if (findLCIt != lcToSimTracksterId_Map[lcId].end()) {
328  stFraction = findLCIt->fraction;
329  }
330  }
331  stPair.second +=
332  (lcFractionInTs - stFraction) * (lcFractionInTs - stFraction) * lcEnergyWeight * invTracksterEnergyWeight;
333 #ifdef EDM_ML_DEBUG
334  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
335  << "lcId:\t" << (uint32_t)lcId << "\ttracksterId:\t" << tsId << "\ttsFraction,stFraction:\t"
336  << lcFractionInTs << ", " << stFraction << "\tlcEnergyWeight:\t" << lcEnergyWeight << "\tcurrent score:\t"
337  << stPair.second << "\tinvTracksterEnergyWeight:\t" << invTracksterEnergyWeight << "\n";
338 #endif
339  }
340  } // End of loop over LayerClusters in Trackster
341 
342 #ifdef EDM_ML_DEBUG
343  if (stsInTrackster[tsId].empty())
344  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "trackster Id:\t" << tsId << "\tST id:\t-1"
345  << "\tscore\t-1\n";
346 #endif
347  } // End of loop over Tracksters
348 
349  // Compute the SimTrackster-To-Trackster score
350  for (const auto& stId : sTIndices) {
351  float invSTEnergyWeight = 0.f;
352 
353  const unsigned int STNumberOfLCs = tssInSimTrackster[stId].lcs_and_fractions.size();
354  if (STNumberOfLCs == 0)
355  continue;
356 
357 #ifdef EDM_ML_DEBUG
358  int tsWithMaxEnergyInST = -1;
359  //energy of the most energetic TS from all that were linked to ST
360  float maxEnergyTSinST = 0.f;
361  float STenergy = tssInSimTrackster[stId].energy;
362  //most energetic TS from all TSs linked to ST over ST energy.
363  float STEnergyFractionInTS = 0.f;
364  for (const auto& ts : tssInSimTrackster[stId].tracksterIdToEnergyAndScore) {
365  if (ts.second.first > maxEnergyTSinST) {
366  maxEnergyTSinST = ts.second.first;
367  tsWithMaxEnergyInST = ts.first;
368  }
369  }
370  if (STenergy > 0.f)
371  STEnergyFractionInTS = maxEnergyTSinST / STenergy;
372 
373  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
374  << std::setw(12) << "simTrackster\t" << std::setw(15) << "st total energy\t" << std::setw(15)
375  << "stEnergyOnLayer\t" << std::setw(14) << "STNhitsOnLayer\t" << std::setw(18) << "tsWithMaxEnergyInST\t"
376  << std::setw(15) << "maxEnergyTSinST\t" << std::setw(20) << "STEnergyFractionInTS"
377  << "\n";
378  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
379  << std::setw(12) << stId << "\t" << std::setw(15) << simTracksters[stId].raw_energy() << "\t" << std::setw(15)
380  << STenergy << "\t" << std::setw(14) << STNumberOfLCs << "\t" << std::setw(18) << tsWithMaxEnergyInST << "\t"
381  << std::setw(15) << maxEnergyTSinST << "\t" << std::setw(20) << STEnergyFractionInTS << "\n";
382 #endif
383 
384  // Compute the correct normalization
385  for (auto const& lcaf : tssInSimTrackster[stId].lcs_and_fractions) {
386  invSTEnergyWeight += std::pow(lcaf.second * layerClusters[lcaf.first].energy(), 2);
387  }
388  invSTEnergyWeight = 1.f / invSTEnergyWeight;
389 
390  for (unsigned int i = 0; i < STNumberOfLCs; ++i) {
391  auto& st_lcId = tssInSimTrackster[stId].lcs_and_fractions[i].first;
392  auto& st_lcFraction = tssInSimTrackster[stId].lcs_and_fractions[i].second;
393 
394  if (st_lcFraction == 0.f)
395  continue; // hopefully this should never happen
396  float lcEnergyWeight = pow(layerClusters[st_lcId].energy(), 2);
397  for (auto& tsPair : tssInSimTrackster[stId].tracksterIdToEnergyAndScore) {
398  unsigned int tsId = tsPair.first;
399 
400  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
401  const auto tsFraction = 1.f / tracksters[tsId].vertex_multiplicity(i);
402 
403  tsPair.second.second +=
404  (tsFraction - st_lcFraction) * (tsFraction - st_lcFraction) * lcEnergyWeight * invSTEnergyWeight;
405 #ifdef EDM_ML_DEBUG
406  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
407  << "STLCId:\t" << (uint32_t)st_lcId << "\tTracksterId:\t" << tsId << "\t"
408  << "tsFraction, stFraction:\t" << tsFraction << ", " << st_lcFraction << "\t"
409  << "lcEnergyWeight:\t" << lcEnergyWeight << "\t"
410  << "current score:\t" << tsPair.second.second << "\t"
411  << "invSTEnergyWeight:\t" << invSTEnergyWeight << "\n";
412 #endif
413  } // End of loop over Trackster's LayerClusters
414  } // End of loop over Tracksters linked to hits of this SimTrackster
415  } // End of loop over hits of SimTrackster on a Layer
416 #ifdef EDM_ML_DEBUG
417  if (tssInSimTrackster[stId].tracksterIdToEnergyAndScore.empty())
418  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl") << "ST Id:\t" << stId << "\tTS id:\t-1 "
419  << "\tscore\t-1\n";
420 
421  for (const auto& tsPair : tssInSimTrackster[stId].tracksterIdToEnergyAndScore) {
422  LogDebug("TSToSimTSAssociatorByEnergyScoreImpl")
423  << "ST Id: \t" << stId << "\t TS id: \t" << tsPair.first << "\t score \t" << tsPair.second.second
424  << "\t shared energy:\t" << tsPair.second.first << "\t shared energy fraction:\t"
425  << (tsPair.second.first / STenergy) << "\n";
426  }
427 #endif
428  } // End loop over SimTrackster indices
429  return {stsInTrackster, tssInSimTrackster};
430 }

References c, relativeConstraints::empty, mps_fire::end, HCALHighEnergyHPDFilter_cfi::energy, f, spr::find(), cms::cuda::for(), HLT_FULL_cff::fraction, hitMap_, mps_fire::i, dqmdumpme::last, HLTEgPhaseIITestSequence_cff::layerClusters, LogDebug, funct::pow(), edm::Handle< T >::product(), jetUpdater_cfi::sort, tier0::unique(), and AlignmentTracksFromVertexSelector_cfi::vertices.

Referenced by associateRecoToSim(), and associateSimToReco().

Member Data Documentation

◆ hardScatterOnly_

const bool TSToSimTSAssociatorByEnergyScoreImpl::hardScatterOnly_
private

Definition at line 58 of file TSToSimTSAssociatorByEnergyScoreImpl.h.

◆ hitMap_

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

Definition at line 60 of file TSToSimTSAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ layers_

unsigned TSToSimTSAssociatorByEnergyScoreImpl::layers_
private

◆ productGetter_

const edm::EDProductGetter* TSToSimTSAssociatorByEnergyScoreImpl::productGetter_
private

◆ recHitTools_

std::shared_ptr<hgcal::RecHitTools> TSToSimTSAssociatorByEnergyScoreImpl::recHitTools_
private
TSToSimTSAssociatorByEnergyScoreImpl::hitMap_
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:60
mps_fire.i
i
Definition: mps_fire.py:428
edm::Handle::product
T const * product() const
Definition: Handle.h:70
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
TSToSimTSAssociatorByEnergyScoreImpl::layers_
unsigned layers_
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:61
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
AlignmentTracksFromVertexSelector_cfi.vertices
vertices
Definition: AlignmentTracksFromVertexSelector_cfi.py:5
edm::Ref
Definition: AssociativeIterator.h:58
TSToSimTSAssociatorByEnergyScoreImpl::productGetter_
const edm::EDProductGetter * productGetter_
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:62
dqmdumpme.last
last
Definition: dqmdumpme.py:56
HLT_FULL_cff.fraction
fraction
Definition: HLT_FULL_cff.py:52823
mps_fire.end
end
Definition: mps_fire.py:242
TSToSimTSAssociatorByEnergyScoreImpl::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:59
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HLTEgPhaseIITestSequence_cff.layerClusters
layerClusters
Definition: HLTEgPhaseIITestSequence_cff.py:2506
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::AssociationMap
Definition: AssociationMap.h:48
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edm::refcoreimpl::productGetter
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
Definition: refcore_implementation.h:72
TSToSimTSAssociatorByEnergyScoreImpl::hardScatterOnly_
const bool hardScatterOnly_
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:58
cms::cuda::for
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Definition: HistoContainer.h:15
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
hgcal::tracksterToSimTrackster
std::vector< std::vector< std::pair< unsigned int, float > > > tracksterToSimTrackster
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:35
electronStore.links
links
Definition: electronStore.py:149
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
TSToSimTSAssociatorByEnergyScoreImpl::makeConnections
hgcal::association makeConnections(const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< ticl::TracksterCollection > &sTCH) const
Definition: TSToSimTSAssociatorByEnergyScoreImpl.cc:14
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
hgcal::lcInfoInTrackster
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:18
hgcal::simTracksterToTrackster
std::vector< hgcal::simTracksterOnLayer > simTracksterToTrackster
Definition: TSToSimTSAssociatorByEnergyScoreImpl.h:36