Skip to content

Commit d09e67a

Browse files
authored
Merge pull request #46895 from felicepantaleo/cleanup_associationMap_14_2_X_rebase
[14_2_X] Improve TICL Association Map and update TICL event content
2 parents cc91330 + 595c929 commit d09e67a

22 files changed

+456
-966
lines changed

RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
['keep *_pfTICL_*_*'] +
2424
['keep CaloParticles_mix_*_*', 'keep SimClusters_mix_*_*', 'keep *_SimClusterToCaloParticleAssociation*_*_*'] +
2525
['keep *_SimClusterToCaloParticleAssociation*_*_*', 'keep *_layerClusterSimClusterAssociationProducer_*_*','keep *_layerClusterCaloParticleAssociationProducer_*_*', 'keep *_layerClusterSimTracksterAssociationProducer_*_*'] +
26-
['keep *_tracksterSimTracksterAssociation*_*_*' , 'keep *_tracksterSimTracksterFromCPsAssociation*_*_*' ]
26+
['keep *_allTrackstersToSimTrackstersAssociations*_*_*']
2727
)
2828
)
2929

@@ -50,7 +50,8 @@
5050
'keep *_ticlSimTracksters_*_*',
5151
'keep *_ticlSimTICLCandidates_*_*',
5252
'keep *_ticlSimTrackstersFromCP_*_*',
53-
'keep *_SimTau*_*_*'
53+
'keep *_SimTau*_*_*',
54+
'keep *_allTrackstersToSimTrackstersAssociations*_*_*'
5455
)
5556
)
5657
TICL_FEVT.outputCommands.extend(TICL_RECO.outputCommands)
@@ -61,6 +62,7 @@
6162
'keep *_ticlSimTrackstersFromCP_*_*',
6263
'keep CaloParticles_mix_*_*', 'keep SimClusters_mix_*_*', 'keep *_SimClusterToCaloParticleAssociation*_*_*',
6364
'keep *_SimClusterToCaloParticleAssociation*_*_*', 'keep *_layerClusterSimClusterAssociationProducer_*_*','keep *_layerClusterCaloParticleAssociationProducer_*_*', 'keep *_layerClusterSimTracksterAssociationProducer_*_*',
65+
'keep *_SimTau*_*_*',
6466
'keep *_allTrackstersToSimTrackstersAssociations*_*_*'
6567

6668
)
@@ -110,10 +112,10 @@ def cleanOutputAndSet(outputModule, ticl_outputCommads):
110112
'keep *_layerClusterCaloParticleAssociationProducer_*_*',
111113
'keep *_randomEngineStateProducer_*_*',
112114
'keep *_layerClusterSimTracksterAssociationProducer_*_*',
113-
'keep *_tracksterSimTracksterAssociation*_*_*',
114-
'keep *_tracksterSimTracksterFromCPsAssociation*_*_*',
115115
'keep *_SimClusterToCaloParticleAssociation*_*_*',
116-
'keep *_simClusterToCaloParticleAssociator*_*_*'
116+
'keep *_simClusterToCaloParticleAssociator*_*_*',
117+
'keep *_SimTau*_*_*',
118+
'keep *_allTrackstersToSimTrackstersAssociations*_*_*'
117119
])
118120

119121
if hasattr(process, 'FEVTDEBUGEventContent'):

RecoHGCal/TICL/plugins/TICLDumper.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#include "CommonTools/UtilAlgos/interface/TFileService.h"
6363

6464
using TracksterToTracksterMap =
65-
ticl::AssociationMap<ticl::mapWithFractionAndScore, std::vector<ticl::Trackster>, std::vector<ticl::Trackster>>;
65+
ticl::AssociationMap<ticl::mapWithSharedEnergyAndScore, std::vector<ticl::Trackster>, std::vector<ticl::Trackster>>;
6666
// Helper class for geometry, magnetic field, etc
6767
class DetectorTools {
6868
public:
@@ -514,10 +514,10 @@ class TracksterToSimTracksterAssociationHelper {
514514
recoToSim_sharedE.resize(numberOfTracksters);
515515

516516
for (size_t i = 0; i < numberOfTracksters; ++i) {
517-
for (const auto& [simTracksterIndex, sharedEnergyAndScorePair] : recoToSimMap[i]) {
518-
recoToSim[i].push_back(simTracksterIndex);
519-
recoToSim_sharedE[i].push_back(sharedEnergyAndScorePair.first);
520-
recoToSim_score[i].push_back(sharedEnergyAndScorePair.second);
517+
for (const auto& simTracksterElement : recoToSimMap[i]) {
518+
recoToSim[i].push_back(simTracksterElement.index());
519+
recoToSim_sharedE[i].push_back(simTracksterElement.sharedEnergy());
520+
recoToSim_score[i].push_back(simTracksterElement.score());
521521
}
522522
}
523523

@@ -528,10 +528,10 @@ class TracksterToSimTracksterAssociationHelper {
528528
simToReco_sharedE.resize(numberOfSimTracksters);
529529

530530
for (size_t i = 0; i < numberOfSimTracksters; ++i) {
531-
for (const auto& [recoTracksterIndex, sharedEnergyAndScorePair] : simToRecoMap[i]) {
532-
simToReco[i].push_back(recoTracksterIndex);
533-
simToReco_sharedE[i].push_back(sharedEnergyAndScorePair.first);
534-
simToReco_score[i].push_back(sharedEnergyAndScorePair.second);
531+
for (const auto& recoTracksterElement : simToRecoMap[i]) {
532+
simToReco[i].push_back(recoTracksterElement.index());
533+
simToReco_sharedE[i].push_back(recoTracksterElement.sharedEnergy());
534+
simToReco_score[i].push_back(recoTracksterElement.score());
535535
}
536536
}
537537
}

SimCalorimetry/HGCalAssociatorProducers/plugins/AllLayerClusterToTracksterAssociatorsProducer.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ AllLayerClusterToTracksterAssociatorsProducer::AllLayerClusterToTracksterAssocia
4040

4141
// Produce separate association maps for each trackster collection using the trackster label
4242
for (const auto& tracksterToken : tracksterCollectionTokens_) {
43-
produces<ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
43+
produces<
44+
ticl::AssociationMap<ticl::mapWithSharedEnergy, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
4445
tracksterToken.first);
4546
}
4647
}
@@ -59,7 +60,7 @@ void AllLayerClusterToTracksterAssociatorsProducer::produce(edm::StreamID,
5960

6061
// Create association map
6162
auto lcToTracksterMap = std::make_unique<
62-
ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
63+
ticl::AssociationMap<ticl::mapWithSharedEnergy, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
6364
layer_clusters, tracksters, iEvent);
6465

6566
// Loop over tracksters

SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ AllTracksterToSimTracksterAssociatorsByHitsProducer::AllTracksterToSimTracksterA
9191
for (const auto& tracksterToken : tracksterCollectionTokens_) {
9292
for (const auto& simTracksterToken : simTracksterCollectionTokens_) {
9393
std::string instanceLabel = tracksterToken.first + "To" + simTracksterToken.first;
94-
produces<ticl::AssociationMap<ticl::mapWithFractionAndScore,
94+
produces<ticl::AssociationMap<ticl::mapWithSharedEnergyAndScore,
9595
std::vector<ticl::Trackster>,
9696
std::vector<ticl::Trackster>>>(instanceLabel);
9797
std::string reverseInstanceLabel = simTracksterToken.first + "To" + tracksterToken.first;
98-
produces<ticl::AssociationMap<ticl::mapWithFractionAndScore,
98+
produces<ticl::AssociationMap<ticl::mapWithSharedEnergyAndScore,
9999
std::vector<ticl::Trackster>,
100100
std::vector<ticl::Trackster>>>(reverseInstanceLabel);
101101
}
@@ -180,11 +180,13 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
180180
const auto& simTracksterToHitMap = *simTracksterToHitMapHandle;
181181

182182
// Create the association maps
183-
auto tracksterToSimTracksterMap = std::make_unique<
184-
ticl::AssociationMap<ticl::mapWithFractionAndScore, std::vector<ticl::Trackster>, std::vector<ticl::Trackster>>>(
183+
auto tracksterToSimTracksterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithSharedEnergyAndScore,
184+
std::vector<ticl::Trackster>,
185+
std::vector<ticl::Trackster>>>(
185186
recoTrackstersHandle, simTrackstersHandle, iEvent);
186-
auto simTracksterToTracksterMap = std::make_unique<
187-
ticl::AssociationMap<ticl::mapWithFractionAndScore, std::vector<ticl::Trackster>, std::vector<ticl::Trackster>>>(
187+
auto simTracksterToTracksterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithSharedEnergyAndScore,
188+
std::vector<ticl::Trackster>,
189+
std::vector<ticl::Trackster>>>(
188190
simTrackstersHandle, recoTrackstersHandle, iEvent);
189191

190192
for (unsigned int tracksterIndex = 0; tracksterIndex < recoTracksters.size(); ++tracksterIndex) {
@@ -195,33 +197,37 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
195197
recoTracksterHitsAndFractions.size());
196198
std::vector<unsigned int> associatedSimTracksterIndices;
197199
for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
198-
const auto& [hitIndex, recoFraction] = recoTracksterHitsAndFractions[i];
200+
const auto& hitElement = recoTracksterHitsAndFractions[i];
201+
unsigned int hitIndex = hitElement.index();
202+
float recoFraction = hitElement.fraction();
199203
const auto& recHit = rechitManager[hitIndex];
200204
float squaredRecoFraction = recoFraction * recoFraction;
201205
float rechitEnergy = recHit.energy();
202206
float squaredRecHitEnergy = rechitEnergy * rechitEnergy;
203207
recoToSimScoresDenominator += squaredRecoFraction * squaredRecHitEnergy;
204208

205209
const auto& hitToSimTracksterVec = hitToSimTracksterMap[hitIndex];
206-
for (const auto& [simTracksterIndex, fraction] : hitToSimTracksterVec) {
210+
for (const auto& simTracksterElement : hitToSimTracksterVec) {
211+
auto simTracksterIndex = simTracksterElement.index();
207212
const auto& simTrackster = simTracksters[simTracksterIndex];
208213
auto& seed = simTrackster.seedID();
209214
float simFraction = 0;
210215
if (seed == caloParticlesHandle.id()) {
211216
unsigned int caloParticleIndex = simTrackster.seedIndex();
212-
auto it = std::find_if(hitToCaloParticleMap[hitIndex].begin(),
213-
hitToCaloParticleMap[hitIndex].end(),
214-
[caloParticleIndex](const auto& pair) { return pair.first == caloParticleIndex; });
217+
auto it =
218+
std::find_if(hitToCaloParticleMap[hitIndex].begin(),
219+
hitToCaloParticleMap[hitIndex].end(),
220+
[caloParticleIndex](const auto& pair) { return pair.index() == caloParticleIndex; });
215221
if (it != hitToCaloParticleMap[hitIndex].end()) {
216-
simFraction = it->second;
222+
simFraction = it->fraction();
217223
}
218224
} else {
219225
unsigned int simClusterIndex = simTracksters[simTracksterIndex].seedIndex();
220226
auto it = std::find_if(hitToSimClusterMap[hitIndex].begin(),
221227
hitToSimClusterMap[hitIndex].end(),
222-
[simClusterIndex](const auto& pair) { return pair.first == simClusterIndex; });
228+
[simClusterIndex](const auto& pair) { return pair.index() == simClusterIndex; });
223229
if (it != hitToSimClusterMap[hitIndex].end()) {
224-
simFraction = it->second;
230+
simFraction = it->fraction();
225231
}
226232
}
227233
hitToAssociatedSimTracksterMap.insert(i, simTracksterIndex, simFraction);
@@ -235,11 +241,11 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
235241

236242
// Add missing sim tracksters with 0 shared energy to hitToAssociatedSimTracksterMap
237243
for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
238-
unsigned int hitId = recoTracksterHitsAndFractions[i].first;
244+
unsigned int hitId = recoTracksterHitsAndFractions[i].index();
239245
const auto& simTracksterVec = hitToSimTracksterMap[hitId];
240246
for (unsigned int simTracksterIndex : associatedSimTracksterIndices) {
241247
if (std::find_if(simTracksterVec.begin(), simTracksterVec.end(), [simTracksterIndex](const auto& pair) {
242-
return pair.first == simTracksterIndex;
248+
return pair.index() == simTracksterIndex;
243249
}) == simTracksterVec.end()) {
244250
hitToAssociatedSimTracksterMap.insert(i, simTracksterIndex, 0);
245251
}
@@ -249,14 +255,16 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
249255
const float invDenominator = 1.f / recoToSimScoresDenominator;
250256

251257
for (unsigned int i = 0; i < recoTracksterHitsAndFractions.size(); ++i) {
252-
unsigned int hitIndex = recoTracksterHitsAndFractions[i].first;
258+
unsigned int hitIndex = recoTracksterHitsAndFractions[i].index();
253259
const auto& recHit = rechitManager[hitIndex];
254-
float recoFraction = recoTracksterHitsAndFractions[i].second;
260+
float recoFraction = recoTracksterHitsAndFractions[i].fraction();
255261
float squaredRecoFraction = recoFraction * recoFraction;
256262
float squaredRecHitEnergy = recHit.energy() * recHit.energy();
257263
float recoSharedEnergy = recHit.energy() * recoFraction;
258264
const auto& simTracksterVec = hitToAssociatedSimTracksterMap[i];
259-
for (const auto& [simTracksterIndex, simFraction] : simTracksterVec) {
265+
for (const auto& simTracksterElement : simTracksterVec) {
266+
auto simTracksterIndex = simTracksterElement.index();
267+
auto simFraction = simTracksterElement.fraction();
260268
edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersHandle, simTracksterIndex);
261269
float sharedEnergy = std::min(simFraction * recHit.energy(), recoSharedEnergy);
262270
float squaredFraction =
@@ -281,17 +289,16 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
281289
bool isSimTracksterFromCP = (seed == caloParticlesHandle.id());
282290
std::vector<float> simFractions(simTracksterHitsAndFractions.size(), 0.f);
283291
for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
284-
const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
285-
292+
auto hitIndex = simTracksterHitsAndFractions[i].index();
286293
auto it = isSimTracksterFromCP
287294
? (std::find_if(hitToCaloParticleMap[hitIndex].begin(),
288295
hitToCaloParticleMap[hitIndex].end(),
289-
[simObjectIndex](const auto& pair) { return pair.first == simObjectIndex; }))
296+
[simObjectIndex](const auto& pair) { return pair.index() == simObjectIndex; }))
290297
: std::find_if(hitToSimClusterMap[hitIndex].begin(),
291298
hitToSimClusterMap[hitIndex].end(),
292-
[simObjectIndex](const auto& pair) { return pair.first == simObjectIndex; });
299+
[simObjectIndex](const auto& pair) { return pair.index() == simObjectIndex; });
293300
if (it != hitToCaloParticleMap[hitIndex].end() and it != hitToSimClusterMap[hitIndex].end()) {
294-
simFractions[i] = it->second;
301+
simFractions[i] = it->fraction();
295302
}
296303
float simFraction = simFractions[i];
297304
const auto& recHit = rechitManager[hitIndex];
@@ -300,7 +307,9 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
300307
simToRecoScoresDenominator += squaredSimFraction * squaredRecHitEnergy;
301308

302309
const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
303-
for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
310+
for (const auto& recoTracksterElement : hitToRecoTracksterVec) {
311+
unsigned int recoTracksterIndex = recoTracksterElement.index();
312+
float recoFraction = recoTracksterElement.fraction();
304313
hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, recoFraction);
305314
associatedRecoTracksterIndices.push_back(recoTracksterIndex);
306315
}
@@ -312,12 +321,12 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
312321
associatedRecoTracksterIndices.end());
313322

314323
for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
315-
unsigned int hitIndex = simTracksterHitsAndFractions[i].first;
324+
unsigned int hitIndex = simTracksterHitsAndFractions[i].index();
316325
const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
317326
for (unsigned int recoTracksterIndex : associatedRecoTracksterIndices) {
318327
if (std::find_if(
319328
hitToRecoTracksterVec.begin(), hitToRecoTracksterVec.end(), [recoTracksterIndex](const auto& pair) {
320-
return pair.first == recoTracksterIndex;
329+
return pair.index() == recoTracksterIndex;
321330
}) == hitToRecoTracksterVec.end()) {
322331
hitToAssociatedRecoTracksterMap.insert(i, recoTracksterIndex, 0);
323332
}
@@ -327,15 +336,17 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
327336
const float invDenominator = 1.f / simToRecoScoresDenominator;
328337

329338
for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
330-
const auto& [hitIndex, simTracksterFraction] = simTracksterHitsAndFractions[i];
339+
const auto& hitIndex = simTracksterHitsAndFractions[i].index();
331340
float simFraction = simFractions[i];
332341
const auto& recHit = rechitManager[hitIndex];
333342
float squaredSimFraction = simFraction * simFraction;
334343
float squaredRecHitEnergy = recHit.energy() * recHit.energy();
335344
float simSharedEnergy = recHit.energy() * simFraction;
336345

337346
const auto& hitToRecoTracksterVec = hitToAssociatedRecoTracksterMap[i];
338-
for (const auto& [recoTracksterIndex, recoFraction] : hitToRecoTracksterVec) {
347+
for (const auto& recoTracksterElement : hitToRecoTracksterVec) {
348+
auto recoTracksterIndex = recoTracksterElement.index();
349+
float recoFraction = recoTracksterElement.fraction();
339350
edm::Ref<std::vector<ticl::Trackster>> recoTracksterRef(recoTrackstersHandle, recoTracksterIndex);
340351
float sharedEnergy = std::min(recoFraction * recHit.energy(), simSharedEnergy);
341352
float squaredFraction =
@@ -346,8 +357,9 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
346357
}
347358
}
348359

349-
tracksterToSimTracksterMap->sort(true);
350-
simTracksterToTracksterMap->sort(true);
360+
// Sort the maps by score in ascending order
361+
tracksterToSimTracksterMap->sort([](const auto& a, const auto& b) { return a.score() < b.score(); });
362+
simTracksterToTracksterMap->sort([](const auto& a, const auto& b) { return a.score() < b.score(); });
351363

352364
// After populating the maps, store them in the event
353365
iEvent.put(std::move(tracksterToSimTracksterMap), tracksterToken.first + "To" + simTracksterToken.first);

0 commit comments

Comments
 (0)