CMS 3D CMS Logo

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

#include <SimClusterAssociatorByEnergyScoreImpl.h>

Inheritance diagram for SimClusterAssociatorByEnergyScoreImpl:
hgcal::LayerClusterToSimClusterAssociatorBaseImpl

Public Member Functions

hgcal::RecoToSimCollectionWithSimClusters associateRecoToSim (const edm::Handle< reco::CaloClusterCollection > &cCH, const edm::Handle< SimClusterCollection > &sCCH) const override
 Associate a LayerCluster to SimClusters. More...
 
hgcal::SimToRecoCollectionWithSimClusters associateSimToReco (const edm::Handle< reco::CaloClusterCollection > &cCH, const edm::Handle< SimClusterCollection > &sCCH) const override
 Associate a SimCluster to LayerClusters. More...
 
 SimClusterAssociatorByEnergyScoreImpl (edm::EDProductGetter const &, bool, std::shared_ptr< hgcal::RecHitTools >, const std::unordered_map< DetId, const HGCRecHit * > *)
 
- Public Member Functions inherited from hgcal::LayerClusterToSimClusterAssociatorBaseImpl
 LayerClusterToSimClusterAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~LayerClusterToSimClusterAssociatorBaseImpl ()
 Destructor. More...
 

Private Member Functions

hgcal::association makeConnections (const edm::Handle< reco::CaloClusterCollection > &cCH, 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 47 of file SimClusterAssociatorByEnergyScoreImpl.h.

Constructor & Destructor Documentation

◆ SimClusterAssociatorByEnergyScoreImpl()

SimClusterAssociatorByEnergyScoreImpl::SimClusterAssociatorByEnergyScoreImpl ( 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 SimClusterAssociatorByEnergyScoreImpl.cc.

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

References layers_, and recHitTools_.

Member Function Documentation

◆ associateRecoToSim()

hgcal::RecoToSimCollectionWithSimClusters SimClusterAssociatorByEnergyScoreImpl::associateRecoToSim ( const edm::Handle< reco::CaloClusterCollection > &  cCH,
const edm::Handle< SimClusterCollection > &  sCCH 
) const
overridevirtual

Associate a LayerCluster to SimClusters.

Reimplemented from hgcal::LayerClusterToSimClusterAssociatorBaseImpl.

Definition at line 486 of file SimClusterAssociatorByEnergyScoreImpl.cc.

487  {
489  const auto& links = makeConnections(cCCH, sCCH);
490 
491  const auto& scsInLayerCluster = std::get<0>(links);
492  for (size_t lcId = 0; lcId < scsInLayerCluster.size(); ++lcId) {
493  for (auto& scPair : scsInLayerCluster[lcId]) {
494  LogDebug("SimClusterAssociatorByEnergyScoreImpl")
495  << "layerCluster Id: \t" << lcId << "\t SC id: \t" << scPair.first << "\t score \t" << scPair.second << "\n";
496  // Fill AssociationMap
497  returnValue.insert(edm::Ref<reco::CaloClusterCollection>(cCCH, lcId), // Ref to LC
498  std::make_pair(edm::Ref<SimClusterCollection>(sCCH, scPair.first),
499  scPair.second) // Pair <Ref to SC, score>
500  );
501  }
502  }
503  return returnValue;
504 }

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

◆ associateSimToReco()

hgcal::SimToRecoCollectionWithSimClusters SimClusterAssociatorByEnergyScoreImpl::associateSimToReco ( const edm::Handle< reco::CaloClusterCollection > &  cCH,
const edm::Handle< SimClusterCollection > &  sCCH 
) const
overridevirtual

Associate a SimCluster to LayerClusters.

Reimplemented from hgcal::LayerClusterToSimClusterAssociatorBaseImpl.

Definition at line 506 of file SimClusterAssociatorByEnergyScoreImpl.cc.

507  {
509  const auto& links = makeConnections(cCCH, sCCH);
510  const auto& lcsInSimCluster = std::get<1>(links);
511  for (size_t scId = 0; scId < lcsInSimCluster.size(); ++scId) {
512  for (size_t layerId = 0; layerId < lcsInSimCluster[scId].size(); ++layerId) {
513  for (auto& lcPair : lcsInSimCluster[scId][layerId].layerClusterIdToEnergyAndScore) {
514  returnValue.insert(
515  edm::Ref<SimClusterCollection>(sCCH, scId), // Ref to SC
516  std::make_pair(edm::Ref<reco::CaloClusterCollection>(cCCH, lcPair.first), // Pair <Ref to LC,
517  std::make_pair(lcPair.second.first, lcPair.second.second)) // pair <energy, score> >
518  );
519  }
520  }
521  }
522  return returnValue;
523 }

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

◆ makeConnections()

hgcal::association SimClusterAssociatorByEnergyScoreImpl::makeConnections ( const edm::Handle< reco::CaloClusterCollection > &  cCH,
const edm::Handle< SimClusterCollection > &  sCCH 
) const
private

Definition at line 15 of file SimClusterAssociatorByEnergyScoreImpl.cc.

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

References c, bsc_activity_cfg::clusters, relativeConstraints::empty, mps_fire::end, HCALHighEnergyHPDFilter_cfi::energy, edmPickEvents::event, f, spr::find(), cms::cuda::for(), hardScatterOnly_, hitMap_, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::last, layers_, LogDebug, or, funct::pow(), edm::Handle< T >::product(), recHitTools_, jetUpdater_cfi::sort, and tier0::unique().

Referenced by associateRecoToSim(), and associateSimToReco().

Member Data Documentation

◆ hardScatterOnly_

const bool SimClusterAssociatorByEnergyScoreImpl::hardScatterOnly_
private

Definition at line 63 of file SimClusterAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ hitMap_

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

Definition at line 65 of file SimClusterAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ layers_

unsigned SimClusterAssociatorByEnergyScoreImpl::layers_
private

◆ productGetter_

const edm::EDProductGetter* SimClusterAssociatorByEnergyScoreImpl::productGetter_
private

◆ recHitTools_

std::shared_ptr<hgcal::RecHitTools> SimClusterAssociatorByEnergyScoreImpl::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
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
hgcal::layerClusterToSimCluster
std::vector< std::vector< std::pair< unsigned int, float > > > layerClusterToSimCluster
Definition: SimClusterAssociatorByEnergyScoreImpl.h:42
DetId
Definition: DetId.h:17
SimClusterAssociatorByEnergyScoreImpl::hitMap_
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
Definition: SimClusterAssociatorByEnergyScoreImpl.h:65
dqmdumpme.last
last
Definition: dqmdumpme.py:56
hgcal::simClusterToLayerCluster
std::vector< std::vector< hgcal::simClusterOnLayer > > simClusterToLayerCluster
Definition: SimClusterAssociatorByEnergyScoreImpl.h:43
SimClusterAssociatorByEnergyScoreImpl::hardScatterOnly_
const bool hardScatterOnly_
Definition: SimClusterAssociatorByEnergyScoreImpl.h:63
mps_fire.end
end
Definition: mps_fire.py:242
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
h
HGCRecHit
Definition: HGCRecHit.h:14
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
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
edmPickEvents.event
event
Definition: edmPickEvents.py:273
SimClusterAssociatorByEnergyScoreImpl::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: SimClusterAssociatorByEnergyScoreImpl.h:64
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
SimClusterAssociatorByEnergyScoreImpl::productGetter_
const edm::EDProductGetter * productGetter_
Definition: SimClusterAssociatorByEnergyScoreImpl.h:67
SimClusterAssociatorByEnergyScoreImpl::layers_
unsigned layers_
Definition: SimClusterAssociatorByEnergyScoreImpl.h:66
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
SimClusterAssociatorByEnergyScoreImpl::makeConnections
hgcal::association makeConnections(const edm::Handle< reco::CaloClusterCollection > &cCH, const edm::Handle< SimClusterCollection > &sCCH) const
Definition: SimClusterAssociatorByEnergyScoreImpl.cc:15
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hit
Definition: SiStripHitEffFromCalibTree.cc:88