CMS 3D CMS Logo

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

#include <LCToSCAssociatorByEnergyScoreImpl.h>

Inheritance diagram for LCToSCAssociatorByEnergyScoreImpl:
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...
 
 LCToSCAssociatorByEnergyScoreImpl (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 LCToSCAssociatorByEnergyScoreImpl.h.

Constructor & Destructor Documentation

◆ LCToSCAssociatorByEnergyScoreImpl()

LCToSCAssociatorByEnergyScoreImpl::LCToSCAssociatorByEnergyScoreImpl ( 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 LCToSCAssociatorByEnergyScoreImpl.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 LCToSCAssociatorByEnergyScoreImpl::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 485 of file LCToSCAssociatorByEnergyScoreImpl.cc.

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

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

◆ associateSimToReco()

hgcal::SimToRecoCollectionWithSimClusters LCToSCAssociatorByEnergyScoreImpl::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 505 of file LCToSCAssociatorByEnergyScoreImpl.cc.

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

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

◆ makeConnections()

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

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

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 LCToSCAssociatorByEnergyScoreImpl::hardScatterOnly_
private

Definition at line 63 of file LCToSCAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ hitMap_

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

Definition at line 65 of file LCToSCAssociatorByEnergyScoreImpl.h.

Referenced by makeConnections().

◆ layers_

unsigned LCToSCAssociatorByEnergyScoreImpl::layers_
private

◆ productGetter_

const edm::EDProductGetter* LCToSCAssociatorByEnergyScoreImpl::productGetter_
private

Definition at line 67 of file LCToSCAssociatorByEnergyScoreImpl.h.

Referenced by associateRecoToSim(), and associateSimToReco().

◆ recHitTools_

std::shared_ptr<hgcal::RecHitTools> LCToSCAssociatorByEnergyScoreImpl::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
LCToSCAssociatorByEnergyScoreImpl::hardScatterOnly_
const bool hardScatterOnly_
Definition: LCToSCAssociatorByEnergyScoreImpl.h:63
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: LCToSCAssociatorByEnergyScoreImpl.h:42
DetId
Definition: DetId.h:17
LCToSCAssociatorByEnergyScoreImpl::recHitTools_
std::shared_ptr< hgcal::RecHitTools > recHitTools_
Definition: LCToSCAssociatorByEnergyScoreImpl.h:64
dqmdumpme.last
last
Definition: dqmdumpme.py:56
hgcal::simClusterToLayerCluster
std::vector< std::vector< hgcal::simClusterOnLayer > > simClusterToLayerCluster
Definition: LCToSCAssociatorByEnergyScoreImpl.h:43
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: LCToCPAssociatorByEnergyScoreImpl.h:18
edm::AssociationMap
Definition: AssociationMap.h:48
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edmPickEvents.event
event
Definition: edmPickEvents.py:273
LCToSCAssociatorByEnergyScoreImpl::productGetter_
const edm::EDProductGetter * productGetter_
Definition: LCToSCAssociatorByEnergyScoreImpl.h:67
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:15
LCToSCAssociatorByEnergyScoreImpl::layers_
unsigned layers_
Definition: LCToSCAssociatorByEnergyScoreImpl.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
LCToSCAssociatorByEnergyScoreImpl::makeConnections
hgcal::association makeConnections(const edm::Handle< reco::CaloClusterCollection > &cCH, const edm::Handle< SimClusterCollection > &sCCH) const
Definition: LCToSCAssociatorByEnergyScoreImpl.cc:15
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hit
Definition: SiStripHitEffFromCalibTree.cc:88
LCToSCAssociatorByEnergyScoreImpl::hitMap_
const std::unordered_map< DetId, const HGCRecHit * > * hitMap_
Definition: LCToSCAssociatorByEnergyScoreImpl.h:65