CMS 3D CMS Logo

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

#include <TracksterAssociatorByEnergyScoreImpl.h>

Inheritance diagram for TracksterAssociatorByEnergyScoreImpl:
hgcal::TracksterToSimClusterAssociatorBaseImpl

Public Member Functions

hgcal::RecoToSimCollectionTracksters associateRecoToSim (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH) const override
 Associate a Trackster to SimClusters. More...
 
hgcal::SimToRecoCollectionTracksters associateSimToReco (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH) const override
 Associate a SimCluster to Tracksters. More...
 
 TracksterAssociatorByEnergyScoreImpl (edm::EDProductGetter const &, bool, std::shared_ptr< hgcal::RecHitTools >, const std::unordered_map< DetId, const HGCRecHit * > *)
 
- Public Member Functions inherited from hgcal::TracksterToSimClusterAssociatorBaseImpl
 TracksterToSimClusterAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TracksterToSimClusterAssociatorBaseImpl ()
 Destructor. More...
 

Private Member Functions

hgcal::association makeConnections (const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH) 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 TracksterAssociatorByEnergyScoreImpl.h.

Constructor & Destructor Documentation

◆ TracksterAssociatorByEnergyScoreImpl()

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

Definition at line 6 of file TracksterAssociatorByEnergyScoreImpl.cc.

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

References layers_, and recHitTools_.

Member Function Documentation

◆ associateRecoToSim()

hgcal::RecoToSimCollectionTracksters TracksterAssociatorByEnergyScoreImpl::associateRecoToSim ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< SimClusterCollection > &  sCCH 
) const
overridevirtual

Associate a Trackster to SimClusters.

Reimplemented from hgcal::TracksterToSimClusterAssociatorBaseImpl.

Definition at line 494 of file TracksterAssociatorByEnergyScoreImpl.cc.

497  {
499  const auto& links = makeConnections(tCH, lCCH, sCCH);
500 
501  const auto& scsInTrackster = std::get<0>(links);
502  for (size_t tsId = 0; tsId < scsInTrackster.size(); ++tsId) {
503  for (auto& scPair : scsInTrackster[tsId]) {
504  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "Trackster Id: \t" << tsId << "\t SimCluster id: \t"
505  << scPair.first << "\t score \t" << scPair.second << "\n";
506  // Fill AssociationMap
507  returnValue.insert(edm::Ref<ticl::TracksterCollection>(tCH, tsId), // Ref to TS
508  std::make_pair(edm::Ref<SimClusterCollection>(sCCH, scPair.first),
509  scPair.second) // Pair <Ref to SC, score>
510  );
511  }
512  }
513  return returnValue;
514 }

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

◆ associateSimToReco()

hgcal::SimToRecoCollectionTracksters TracksterAssociatorByEnergyScoreImpl::associateSimToReco ( const edm::Handle< ticl::TracksterCollection > &  tCH,
const edm::Handle< reco::CaloClusterCollection > &  lCCH,
const edm::Handle< SimClusterCollection > &  sCCH 
) const
overridevirtual

Associate a SimCluster to Tracksters.

Reimplemented from hgcal::TracksterToSimClusterAssociatorBaseImpl.

Definition at line 516 of file TracksterAssociatorByEnergyScoreImpl.cc.

519  {
521  const auto& links = makeConnections(tCH, lCCH, sCCH);
522  const auto& tssInSimCluster = std::get<1>(links);
523  for (size_t scId = 0; scId < tssInSimCluster.size(); ++scId) {
524  for (auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) {
525  returnValue.insert(
526  edm::Ref<SimClusterCollection>(sCCH, scId), // Ref to SC
527  std::make_pair(edm::Ref<ticl::TracksterCollection>(tCH, tsPair.first), // Pair <Ref to TS,
528  std::make_pair(tsPair.second.first, tsPair.second.second)) // pair <energy, score> >
529  );
530  }
531  }
532  return returnValue;
533 }

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

◆ makeConnections()

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

Definition at line 15 of file TracksterAssociatorByEnergyScoreImpl.cc.

18  {
19  // Get collections
20  const auto& tracksters = *tCH.product();
21  const auto& layerClusters = *lCCH.product();
22  const auto& simClusters = *sCCH.product();
23  auto nTracksters = tracksters.size();
24 
25  //There shouldn't be any SimTracks from different crossings, but maybe they will be added later.
26  //At the moment there should be one SimTrack in each SimCluster.
27  auto nSimClusters = simClusters.size();
28  std::vector<size_t> sCIndices;
29  for (unsigned int scId = 0; scId < nSimClusters; ++scId) {
30  if (hardScatterOnly_ && (simClusters[scId].g4Tracks()[0].eventId().event() != 0 or
31  simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() != 0)) {
32  LogDebug("TracksterAssociatorByEnergyScoreImpl")
33  << "Excluding SimCluster from event: " << simClusters[scId].g4Tracks()[0].eventId().event()
34  << " with BX: " << simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() << std::endl;
35  continue;
36  }
37  sCIndices.emplace_back(scId);
38  }
39  nSimClusters = sCIndices.size();
40 
41  // Initialize tssInSimCluster. To be returned outside, since it contains the
42  // information to compute the SimCluster-To-Trackster score.
43  // tssInSimCluster[scId]:
44  hgcal::simClusterToTrackster tssInSimCluster;
45  tssInSimCluster.resize(nSimClusters);
46  for (unsigned int i = 0; i < nSimClusters; ++i) {
47  tssInSimCluster[i].simClusterId = i;
48  tssInSimCluster[i].energy = 0.f;
49  tssInSimCluster[i].hits_and_fractions.clear();
50  }
51 
52  // Fill detIdToSimClusterId_Map and update tssInSimCluster
53  std::unordered_map<DetId, std::vector<hgcal::detIdInfoInCluster>> detIdToSimClusterId_Map;
54  for (const auto& scId : sCIndices) {
55  const auto& hits_and_fractions = simClusters[scId].hits_and_fractions();
56  for (const auto& it_haf : hits_and_fractions) {
57  const auto hitid = it_haf.first;
58  const auto itcheck = hitMap_->find(hitid);
59  if (itcheck != hitMap_->end()) {
60  const auto hit_find_it = detIdToSimClusterId_Map.find(hitid);
61  if (hit_find_it == detIdToSimClusterId_Map.end()) {
62  detIdToSimClusterId_Map[hitid] = std::vector<hgcal::detIdInfoInCluster>();
63  }
64  detIdToSimClusterId_Map[hitid].emplace_back(scId, it_haf.second);
65 
66  const HGCRecHit* hit = itcheck->second;
67  tssInSimCluster[scId].energy += it_haf.second * hit->energy();
68  tssInSimCluster[scId].hits_and_fractions.emplace_back(hitid, it_haf.second);
69  }
70  }
71  } // end of loop over SimClusters
72 
73 #ifdef EDM_ML_DEBUG
74  LogDebug("TracksterAssociatorByEnergyScoreImpl")
75  << "tssInSimCluster INFO (Only SimCluster filled at the moment)" << std::endl;
76  for (size_t sc = 0; sc < tssInSimCluster.size(); ++sc) {
77  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "For SimCluster Idx: " << sc << " we have: " << std::endl;
78  LogDebug("TracksterAssociatorByEnergyScoreImpl")
79  << " SimClusterIdx: " << tssInSimCluster[sc].simClusterId << std::endl;
80  LogDebug("TracksterAssociatorByEnergyScoreImpl")
81  << " Energy: " << tssInSimCluster[sc].energy << std::endl;
82  LogDebug("TracksterAssociatorByEnergyScoreImpl") << " # of clusters : " << nLayerClusters << std::endl;
83  double tot_energy = 0.;
84  for (auto const& haf : tssInSimCluster[sc].hits_and_fractions) {
85  LogDebug("TracksterAssociatorByEnergyScoreImpl")
86  << " Hits/fraction/energy: " << (uint32_t)haf.first << "/" << haf.second << "/"
87  << haf.second * hitMap_->at(haf.first)->energy() << std::endl;
88  tot_energy += haf.second * hitMap_->at(haf.first)->energy();
89  }
90  LogDebug("TracksterAssociatorByEnergyScoreImpl") << " Tot Sum haf: " << tot_energy << std::endl;
91  for (auto const& ts : tssInSimCluster[sc].tracksterIdToEnergyAndScore) {
92  LogDebug("TracksterAssociatorByEnergyScoreImpl")
93  << " tsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl;
94  }
95  }
96 
97  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "detIdToSimClusterId_Map INFO" << std::endl;
98  for (auto const& detId : detIdToSimClusterId_Map) {
99  LogDebug("TracksterAssociatorByEnergyScoreImpl")
100  << "For detId: " << (uint32_t)detId.first
101  << " we have found the following connections with SimClusters:" << std::endl;
102  for (auto const& sc : detId.second) {
103  LogDebug("TracksterAssociatorByEnergyScoreImpl")
104  << " SimCluster Id: " << sc.clusterId << " with fraction: " << sc.fraction
105  << " and energy: " << sc.fraction * hitMap_->at(detId.first)->energy() << std::endl;
106  }
107  }
108 #endif
109 
110  // Fill detIdToLayerClusterId_Map and scsInTrackster; update tssInSimCluster
111  std::unordered_map<DetId, std::vector<hgcal::detIdInfoInCluster>> detIdToLayerClusterId_Map;
112  // this contains the ids of the simclusters contributing with at least one
113  // hit to the Trackster. To be returned since this contains the information
114  // to compute the Trackster-To-SimCluster score.
115  hgcal::tracksterToSimCluster scsInTrackster; //[tsId][scId]->(energy,score)
116  scsInTrackster.resize(nTracksters);
117 
118  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
119  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
120  const auto lcId = tracksters[tsId].vertices(i);
121  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
122 
123  const std::vector<std::pair<DetId, float>>& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
124  unsigned int numberOfHitsInLC = hits_and_fractions.size();
125 
126  for (unsigned int hitId = 0; hitId < numberOfHitsInLC; hitId++) {
127  const auto rh_detid = hits_and_fractions[hitId].first;
128  const auto rhFraction = hits_and_fractions[hitId].second;
129 
130  const auto hit_find_in_LC = detIdToLayerClusterId_Map.find(rh_detid);
131  if (hit_find_in_LC == detIdToLayerClusterId_Map.end()) {
132  detIdToLayerClusterId_Map[rh_detid] = std::vector<hgcal::detIdInfoInCluster>();
133  }
134  detIdToLayerClusterId_Map[rh_detid].emplace_back(lcId, rhFraction);
135 
136  const auto hit_find_in_SC = detIdToSimClusterId_Map.find(rh_detid);
137 
138  if (hit_find_in_SC != detIdToSimClusterId_Map.end()) {
139  const auto itcheck = hitMap_->find(rh_detid);
140  const HGCRecHit* hit = itcheck->second;
141  //Loops through all the simclusters that have the layer cluster rechit under study
142  //Here is time to update the tssInSimCluster and connect the SimCluster with all
143  //the Tracksters that have the current rechit detid matched.
144  for (const auto& h : hit_find_in_SC->second) {
145  //tssInSimCluster[simclusterId][layerclusterId]-> (energy,score)
146  //SC_i - > TS_j, TS_k, ...
147  tssInSimCluster[h.clusterId].tracksterIdToEnergyAndScore[tsId].first +=
148  lcFractionInTs * h.fraction * hit->energy();
149  //TS_i -> SC_j, SC_k, ...
150  scsInTrackster[tsId].emplace_back(h.clusterId, 0.f);
151  }
152  }
153  } // End loop over hits on a LayerCluster
154  } // End loop over LayerClusters in Trackster
155  } // End of loop over Tracksters
156 
157 #ifdef EDM_ML_DEBUG
158  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
159  for (const auto& lcId : tracksters[tsId].vertices()) {
160  const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
161  unsigned int numberOfHitsInLC = hits_and_fractions.size();
162 
163  // This vector will store, for each hit in the Layercluster, the index of
164  // the SimCluster that contributed the most, in terms of energy, to it.
165  // Special values are:
166  //
167  // -2 --> the reconstruction fraction of the RecHit is 0 (used in the past to monitor Halo Hits)
168  // -3 --> same as before with the added condition that no SimCluster has been linked to this RecHit
169  // -1 --> the reco fraction is >0, but no SimCluster has been linked to it
170  // >=0 --> index of the linked SimCluster
171  std::vector<int> hitsToSimClusterId(numberOfHitsInLC);
172  // This will store the index of the SimCluster linked to the LayerCluster that has the largest number of hits in common.
173  int maxSCId_byNumberOfHits = -1;
174  // This will store the maximum number of shared hits between a LayerCluster and a SimCluster
175  unsigned int maxSCNumberOfHitsInLC = 0;
176  // This will store the index of the SimCluster linked to the LayerCluster that has the largest energy in common.
177  int maxSCId_byEnergy = -1;
178  // This will store the maximum number of shared energy between a LayerCluster and a SimCluster
179  float maxEnergySharedLCandSC = 0.f;
180  // This will store the fraction of the LayerCluster energy shared with the best(energy) SimCluster: e_shared/lc_energy
181  float energyFractionOfLCinSC = 0.f;
182  // This will store the fraction of the SimCluster energy shared with the Trackster: e_shared/sc_energy
183  float energyFractionOfSCinLC = 0.f;
184  std::unordered_map<unsigned, unsigned> occurrencesSCinLC;
185  unsigned int numberOfNoiseHitsInLC = 0;
186  std::unordered_map<unsigned, float> SCEnergyInLC;
187 
188  for (unsigned int hitId = 0; hitId < numberOfHitsInLC; hitId++) {
189  const auto rh_detid = hits_and_fractions[hitId].first;
190  const auto rhFraction = hits_and_fractions[hitId].second;
191 
192  const auto hit_find_in_SC = detIdToSimClusterId_Map.find(rh_detid);
193 
194  // if the fraction is zero or the hit does not belong to any SimCluster,
195  // set the SimCluster Id for the hit to -1; this will
196  // contribute to the number of noise hits
197 
198  // MR Remove the case in which the fraction is 0, since this could be a
199  // real hit that has been marked as halo.
200  if (rhFraction == 0.) {
201  hitsToSimClusterId[hitId] = -2;
202  }
203  //Now check if there are SimClusters linked to this rechit of the layercluster
204  if (hit_find_in_SC == detIdToSimClusterId_Map.end()) {
205  hitsToSimClusterId[hitId] -= 1;
206  } else {
207  const auto itcheck = hitMap_->find(rh_detid);
208  const HGCRecHit* hit = itcheck->second;
209  auto maxSCEnergyInLC = 0.f;
210  auto maxSCId = -1;
211  //Loop through all the linked SimClusters
212  for (const auto& h : hit_find_in_SC->second) {
213  SCEnergyInLC[h.clusterId] += h.fraction * hit->energy();
214  // Keep track of which SimCluster contributed the most, in terms
215  // of energy, to this specific Layer Cluster.
216  if (SCEnergyInLC[h.clusterId] > maxSCEnergyInLC) {
217  maxSCEnergyInLC = SCEnergyInLC[h.clusterId];
218  maxSCId = h.clusterId;
219  }
220  }
221  hitsToSimClusterId[hitId] = maxSCId;
222  }
223  } // End loop over hits on a LayerCluster
224 
225  for (const auto& c : hitsToSimClusterId) {
226  if (c < 0) {
227  numberOfNoiseHitsInLC++;
228  } else {
229  occurrencesSCinLC[c]++;
230  }
231  }
232 
233  for (const auto& c : occurrencesSCinLC) {
234  if (c.second > maxSCNumberOfHitsInLC) {
235  maxSCId_byNumberOfHits = c.first;
236  maxSCNumberOfHitsInLC = c.second;
237  }
238  }
239 
240  for (const auto& c : SCEnergyInLC) {
241  if (c.second > maxEnergySharedLCandSC) {
242  maxSCId_byEnergy = c.first;
243  maxEnergySharedLCandSC = c.second;
244  }
245  }
246 
247  float totalSCEnergyOnLayer = 0.f;
248  if (maxSCId_byEnergy >= 0) {
249  totalSCEnergyOnLayer = tssInSimCluster[maxSCId_byEnergy].energy;
250  energyFractionOfSCinLC = maxEnergySharedLCandSC / totalSCEnergyOnLayer;
251  if (tracksters[tsId].raw_energy() > 0.f) {
252  energyFractionOfLCinSC = maxEnergySharedLCandSC / tracksters[tsId].raw_energy();
253  }
254  }
255 
256  LogDebug("TracksterAssociatorByEnergyScoreImpl") << std::setw(12) << "TracksterID:"
257  << "\t" << std::setw(12) << "layerCluster"
258  << "\t" << std::setw(10) << "lc energy"
259  << "\t" << std::setw(5) << "nhits"
260  << "\t" << std::setw(12) << "noise hits"
261  << "\t" << std::setw(22) << "maxSCId_byNumberOfHits"
262  << "\t" << std::setw(8) << "nhitsSC"
263  << "\t" << std::setw(13) << "maxSCId_byEnergy"
264  << "\t" << std::setw(20) << "maxEnergySharedLCandSC"
265  << "\t" << std::setw(22) << "totalSCEnergyOnLayer"
266  << "\t" << std::setw(22) << "energyFractionOfLCinSC"
267  << "\t" << std::setw(25) << "energyFractionOfSCinLC"
268  << "\t"
269  << "\n";
270  LogDebug("TracksterAssociatorByEnergyScoreImpl")
271  << std::setw(12) << tsId << "\t" << std::setw(12) << lcId << "\t" << std::setw(10)
272  << tracksters[tsId].raw_energy() << "\t" << std::setw(5) << numberOfHitsInLC << "\t" << std::setw(12)
273  << numberOfNoiseHitsInLC << "\t" << std::setw(22) << maxSCId_byNumberOfHits << "\t" << std::setw(8)
274  << maxSCNumberOfHitsInLC << "\t" << std::setw(13) << maxSCId_byEnergy << "\t" << std::setw(20)
275  << maxEnergySharedLCandSC << "\t" << std::setw(22) << totalSCEnergyOnLayer << "\t" << std::setw(22)
276  << energyFractionOfLCinSC << "\t" << std::setw(25) << energyFractionOfSCinLC << "\n";
277  } // End of loop over LayerClusters in Trackster
278  } // End of loop over Tracksters
279 
280  LogDebug("TracksterAssociatorByEnergyScoreImpl")
281  << "Improved tssInSimCluster INFO (Now containing the linked tracksters id and energy - score still empty)"
282  << std::endl;
283  for (size_t sc = 0; sc < tssInSimCluster.size(); ++sc) {
284  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "For SimCluster Idx: " << sc << " we have: " << std::endl;
285  LogDebug("TracksterAssociatorByEnergyScoreImpl")
286  << " SimClusterIdx: " << tssInSimCluster[sc].simClusterId << std::endl;
287  LogDebug("TracksterAssociatorByEnergyScoreImpl")
288  << " Energy: " << tssInSimCluster[sc].energy << std::endl;
289  double tot_energy = 0.;
290  for (auto const& haf : tssInSimCluster[sc].hits_and_fractions) {
291  LogDebug("TracksterAssociatorByEnergyScoreImpl")
292  << " Hits/fraction/energy: " << (uint32_t)haf.first << "/" << haf.second << "/"
293  << haf.second * hitMap_->at(haf.first)->energy() << std::endl;
294  tot_energy += haf.second * hitMap_->at(haf.first)->energy();
295  }
296  LogDebug("TracksterAssociatorByEnergyScoreImpl") << " Tot Sum haf: " << tot_energy << std::endl;
297  for (auto const& ts : tssInSimCluster[sc].tracksterIdToEnergyAndScore) {
298  LogDebug("TracksterAssociatorByEnergyScoreImpl")
299  << " tsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl;
300  }
301  }
302 
303  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "Improved detIdToSimClusterId_Map INFO" << std::endl;
304  for (auto const& sc : detIdToSimClusterId_Map) {
305  LogDebug("TracksterAssociatorByEnergyScoreImpl")
306  << "For detId: " << (uint32_t)sc.first
307  << " we have found the following connections with SimClusters:" << std::endl;
308  for (auto const& sclu : sc.second) {
309  LogDebug("TracksterAssociatorByEnergyScoreImpl")
310  << " SimCluster Id: " << sclu.clusterId << " with fraction: " << sclu.fraction
311  << " and energy: " << sclu.fraction * hitMap_->at(sc.first)->energy() << std::endl;
312  }
313  }
314 #endif
315 
316  // Update scsInTrackster; compute the score Trackster-to-SimCluster,
317  // together with the returned AssociationMap
318  for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) {
319  // The SimClusters contributing to the Trackster's LayerClusters should already be unique.
320  // find the unique SimClusters id contributing to the Trackster's LayerClusters
321  std::sort(scsInTrackster[tsId].begin(), scsInTrackster[tsId].end());
322  auto last = std::unique(scsInTrackster[tsId].begin(), scsInTrackster[tsId].end());
323  scsInTrackster[tsId].erase(last, scsInTrackster[tsId].end());
324 
325  // If a reconstructed Trackster has energy 0 but is linked to a
326  // SimCluster, assigned score 1
327  if (tracksters[tsId].raw_energy() == 0. && !scsInTrackster[tsId].empty()) {
328  for (auto& scPair : scsInTrackster[tsId]) {
329  scPair.second = 1.;
330  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "TracksterId : \t " << tsId << "\t SC id : \t"
331  << scPair.first << "\t score \t " << scPair.second << "\n";
332  }
333  continue;
334  }
335 
336  float invTracksterEnergyWeight = 0.f;
337  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
338  const auto lcId = tracksters[tsId].vertices(i);
339  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
340 
341  const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
342  // Compute the correct normalization
343  for (auto const& haf : hits_and_fractions) {
344  invTracksterEnergyWeight += (lcFractionInTs * haf.second * hitMap_->at(haf.first)->energy()) *
345  (lcFractionInTs * haf.second * hitMap_->at(haf.first)->energy());
346  }
347  }
348  invTracksterEnergyWeight = 1.f / invTracksterEnergyWeight;
349 
350  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
351  const auto lcId = tracksters[tsId].vertices(i);
352  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
353 
354  const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions();
355  unsigned int numberOfHitsInLC = hits_and_fractions.size();
356  for (unsigned int i = 0; i < numberOfHitsInLC; ++i) {
357  DetId rh_detid = hits_and_fractions[i].first;
358  float rhFraction = hits_and_fractions[i].second * lcFractionInTs;
359 
360  const bool hitWithSC = (detIdToSimClusterId_Map.find(rh_detid) != detIdToSimClusterId_Map.end());
361 
362  const auto itcheck = hitMap_->find(rh_detid);
363  const HGCRecHit* hit = itcheck->second;
364  float hitEnergyWeight = hit->energy() * hit->energy();
365 
366  for (auto& scPair : scsInTrackster[tsId]) {
367  float scFraction = 0.f;
368  if (hitWithSC) {
369  const auto findHitIt = std::find(detIdToSimClusterId_Map[rh_detid].begin(),
370  detIdToSimClusterId_Map[rh_detid].end(),
371  hgcal::detIdInfoInCluster{scPair.first, 0.f});
372  if (findHitIt != detIdToSimClusterId_Map[rh_detid].end())
373  scFraction = findHitIt->fraction;
374  }
375  scPair.second +=
376  (rhFraction - scFraction) * (rhFraction - scFraction) * hitEnergyWeight * invTracksterEnergyWeight;
377 #ifdef EDM_ML_DEBUG
378  LogDebug("TracksterAssociatorByEnergyScoreImpl")
379  << "rh_detid:\t" << (uint32_t)rh_detid << "\ttracksterId:\t" << tsId << "\t"
380  << "rhfraction,scFraction:\t" << rhFraction << ", " << scFraction << "\t"
381  << "hitEnergyWeight:\t" << hitEnergyWeight << "\t"
382  << "current score:\t" << scPair.second << "\t"
383  << "invTracksterEnergyWeight:\t" << invTracksterEnergyWeight << "\n";
384 #endif
385  }
386  } // End of loop over Hits within a LayerCluster
387  } // End of loop over LayerClusters in Trackster
388 
389 #ifdef EDM_ML_DEBUG
390  if (scsInTrackster[tsId].empty())
391  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "trackster Id: \t" << tsId << "\tSC id:\t-1 "
392  << "\t score \t-1"
393  << "\n";
394 #endif
395  } // End of loop over Tracksters
396 
397  // Compute the SimCluster-To-Trackster score
398  for (const auto& scId : sCIndices) {
399  float invSCEnergyWeight = 0.f;
400 
401  const unsigned int SCNumberOfHits = tssInSimCluster[scId].hits_and_fractions.size();
402  if (SCNumberOfHits == 0)
403  continue;
404 #ifdef EDM_ML_DEBUG
405  int tsWithMaxEnergyInSC = -1;
406  //energy of the most energetic TS from all that were linked to SC
407  float maxEnergyTSinSC = 0.f;
408  float SCenergy = tssInSimCluster[scId].energy;
409  //most energetic TS from all TSs linked to SC over SC energy.
410  float SCEnergyFractionInTS = 0.f;
411  for (const auto& ts : tssInSimCluster[scId].tracksterIdToEnergyAndScore) {
412  if (ts.second.first > maxEnergyTSinSC) {
413  maxEnergyTSinSC = ts.second.first;
414  tsWithMaxEnergyInSC = ts.first;
415  }
416  }
417  if (SCenergy > 0.f)
418  SCEnergyFractionInTS = maxEnergyTSinSC / SCenergy;
419 
420  LogDebug("TracksterAssociatorByEnergyScoreImpl")
421  << std::setw(12) << "simcluster\t" << std::setw(15) << "sc total energy\t" << std::setw(15)
422  << "scEnergyOnLayer\t" << std::setw(14) << "SCNhitsOnLayer\t" << std::setw(18) << "tsWithMaxEnergyInSC\t"
423  << std::setw(15) << "maxEnergyTSinSC\t" << std::setw(20) << "SCEnergyFractionInTS"
424  << "\n";
425  LogDebug("TracksterAssociatorByEnergyScoreImpl")
426  << std::setw(12) << scId << "\t" << std::setw(15) << simClusters[scId].energy() << "\t" << std::setw(15)
427  << SCenergy << "\t" << std::setw(14) << SCNumberOfHits << "\t" << std::setw(18) << tsWithMaxEnergyInSC << "\t"
428  << std::setw(15) << maxEnergyTSinSC << "\t" << std::setw(20) << SCEnergyFractionInTS << "\n";
429 #endif
430  // Compute the correct normalization
431  for (auto const& haf : tssInSimCluster[scId].hits_and_fractions) {
432  invSCEnergyWeight += std::pow(haf.second * hitMap_->at(haf.first)->energy(), 2);
433  }
434  invSCEnergyWeight = 1.f / invSCEnergyWeight;
435 
436  for (unsigned int i = 0; i < SCNumberOfHits; ++i) {
437  auto& sc_hitDetId = tssInSimCluster[scId].hits_and_fractions[i].first;
438  auto& scFraction = tssInSimCluster[scId].hits_and_fractions[i].second;
439 
440  bool hitWithLC = false;
441  if (scFraction == 0.f)
442  continue; // hopefully this should never happen
443  const auto hit_find_in_LC = detIdToLayerClusterId_Map.find(sc_hitDetId);
444  if (hit_find_in_LC != detIdToLayerClusterId_Map.end())
445  hitWithLC = true;
446  const auto itcheck = hitMap_->find(sc_hitDetId);
447  const HGCRecHit* hit = itcheck->second;
448  float hitEnergyWeight = hit->energy() * hit->energy();
449  for (auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) {
450  unsigned int tsId = tsPair.first;
451  float tsFraction = 0.f;
452 
453  for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) {
454  const auto lcId = tracksters[tsId].vertices(i);
455  const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i);
456 
457  if (hitWithLC) {
458  const auto findHitIt = std::find(detIdToLayerClusterId_Map[sc_hitDetId].begin(),
459  detIdToLayerClusterId_Map[sc_hitDetId].end(),
460  hgcal::detIdInfoInCluster{lcId, 0.f});
461  if (findHitIt != detIdToLayerClusterId_Map[sc_hitDetId].end())
462  tsFraction = findHitIt->fraction * lcFractionInTs;
463  }
464  tsPair.second.second +=
465  (tsFraction - scFraction) * (tsFraction - scFraction) * hitEnergyWeight * invSCEnergyWeight;
466 #ifdef EDM_ML_DEBUG
467  LogDebug("TracksterAssociatorByEnergyScoreImpl")
468  << "SCDetId:\t" << (uint32_t)sc_hitDetId << "\tTracksterId:\t" << tracksterId << "\t"
469  << "tsFraction, scFraction:\t" << tsFraction << ", " << scFraction << "\t"
470  << "hitEnergyWeight:\t" << hitEnergyWeight << "\t"
471  << "current score:\t" << tsPair.second.second << "\t"
472  << "invSCEnergyWeight:\t" << invSCEnergyWeight << "\n";
473 #endif
474  } // End of loop over Trackster's LayerClusters
475  } // End of loop over Tracksters linked to hits of this SimCluster
476  } // End of loop over hits of SimCluster on a Layer
477 #ifdef EDM_ML_DEBUG
478  if (tssInSimCluster[scId].tracksterIdToEnergyAndScore.empty())
479  LogDebug("TracksterAssociatorByEnergyScoreImpl") << "SC Id: \t" << scId << "\tTS id:\t-1 "
480  << "\t score \t-1"
481  << "\n";
482 
483  for (const auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) {
484  LogDebug("TracksterAssociatorByEnergyScoreImpl")
485  << "SC Id: \t" << scId << "\t TS id: \t" << tsPair.first << "\t score \t" << tsPair.second.second
486  << "\t shared energy:\t" << tsPair.second.first << "\t shared energy fraction:\t"
487  << (tsPair.second.first / SCenergy) << "\n";
488  }
489 #endif
490  } // End loop over SimCluster indices
491  return {scsInTrackster, tssInSimCluster};
492 }

References c, relativeConstraints::empty, mps_fire::end, edmPickEvents::event, f, spr::find(), cms::cuda::for(), hardScatterOnly_, hitMap_, mps_fire::i, dqmdumpme::last, HLTEgPhaseIITestSequence_cff::layerClusters, LogDebug, or, funct::pow(), edm::Handle< T >::product(), jetUpdater_cfi::sort, tier0::unique(), and pwdgSkimBPark_cfi::vertices.

Referenced by associateRecoToSim(), and associateSimToReco().

Member Data Documentation

◆ hardScatterOnly_

const bool TracksterAssociatorByEnergyScoreImpl::hardScatterOnly_
private

Definition at line 56 of file TracksterAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ hitMap_

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

Definition at line 58 of file TracksterAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ layers_

unsigned TracksterAssociatorByEnergyScoreImpl::layers_
private

◆ productGetter_

const edm::EDProductGetter* TracksterAssociatorByEnergyScoreImpl::productGetter_
private

◆ recHitTools_

std::shared_ptr<hgcal::RecHitTools> TracksterAssociatorByEnergyScoreImpl::recHitTools_
private
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
hgcal::tracksterToSimCluster
std::vector< std::vector< std::pair< unsigned int, float > > > tracksterToSimCluster
Definition: TracksterAssociatorByEnergyScoreImpl.h:35
TracksterAssociatorByEnergyScoreImpl::hardScatterOnly_
const bool hardScatterOnly_
Definition: TracksterAssociatorByEnergyScoreImpl.h:56
hgcal::simClusterToTrackster
std::vector< hgcal::simClusterOnLayer > simClusterToTrackster
Definition: TracksterAssociatorByEnergyScoreImpl.h:36
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Ref
Definition: AssociativeIterator.h:58
DetId
Definition: DetId.h:17
dqmdumpme.last
last
Definition: dqmdumpme.py:56
mps_fire.end
end
Definition: mps_fire.py:242
TracksterAssociatorByEnergyScoreImpl::hitMap_
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
Definition: TracksterAssociatorByEnergyScoreImpl.h:58
h
HLTEgPhaseIITestSequence_cff.layerClusters
layerClusters
Definition: HLTEgPhaseIITestSequence_cff.py:2506
HGCRecHit
Definition: HGCRecHit.h:14
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
hgcal::detIdInfoInCluster
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:18
edm::AssociationMap
Definition: AssociationMap.h:48
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
TracksterAssociatorByEnergyScoreImpl::layers_
unsigned layers_
Definition: TracksterAssociatorByEnergyScoreImpl.h:59
edmPickEvents.event
event
Definition: edmPickEvents.py:273
TracksterAssociatorByEnergyScoreImpl::productGetter_
const edm::EDProductGetter * productGetter_
Definition: TracksterAssociatorByEnergyScoreImpl.h:60
edm::refcoreimpl::productGetter
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
Definition: refcore_implementation.h:72
cms::cuda::for
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Definition: HistoContainer.h:27
TracksterAssociatorByEnergyScoreImpl::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: TracksterAssociatorByEnergyScoreImpl.h:57
TracksterAssociatorByEnergyScoreImpl::makeConnections
hgcal::association makeConnections(const edm::Handle< ticl::TracksterCollection > &tCH, const edm::Handle< reco::CaloClusterCollection > &lCCH, const edm::Handle< SimClusterCollection > &sCCH) const
Definition: TracksterAssociatorByEnergyScoreImpl.cc:15
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
electronStore.links
links
Definition: electronStore.py:149
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
hit
Definition: SiStripHitEffFromCalibTree.cc:88
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7