Skip to content

Commit 5255be2

Browse files
Make tracksters Associators reproducible
1 parent ab76956 commit 5255be2

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
259259
const auto& recHit = rechitManager[hitIndex];
260260
float recoFraction = recoTracksterHitsAndFractions[i].fraction();
261261
float squaredRecoFraction = recoFraction * recoFraction;
262-
float squaredRecHitEnergy = recHit.energy() * recHit.energy();
263-
float recoSharedEnergy = recHit.energy() * recoFraction;
262+
float rechitEnergy = recHit.energy();
263+
float squaredRecHitEnergy = rechitEnergy * rechitEnergy;
264+
float recoSharedEnergy = rechitEnergy * recoFraction;
264265
const auto& simTracksterVec = hitToAssociatedSimTracksterMap[i];
265266
for (const auto& simTracksterElement : simTracksterVec) {
266267
auto simTracksterIndex = simTracksterElement.index();
267268
auto simFraction = simTracksterElement.fraction();
268269
edm::Ref<std::vector<ticl::Trackster>> simTracksterRef(simTrackstersHandle, simTracksterIndex);
269-
float sharedEnergy = std::min(simFraction * recHit.energy(), recoSharedEnergy);
270+
float sharedEnergy = std::min(simFraction * rechitEnergy, recoSharedEnergy);
270271
float squaredFraction =
271272
std::min(squaredRecoFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
272273
float score = invDenominator * squaredFraction * squaredRecHitEnergy;
@@ -297,15 +298,16 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
297298
: std::find_if(hitToSimClusterMap[hitIndex].begin(),
298299
hitToSimClusterMap[hitIndex].end(),
299300
[simObjectIndex](const auto& pair) { return pair.index() == simObjectIndex; });
300-
if (it != hitToCaloParticleMap[hitIndex].end() and it != hitToSimClusterMap[hitIndex].end()) {
301+
if ((isSimTracksterFromCP and it != hitToCaloParticleMap[hitIndex].end()) or
302+
(!isSimTracksterFromCP and it != hitToSimClusterMap[hitIndex].end())) {
301303
simFractions[i] = it->fraction();
302304
}
303305
float simFraction = simFractions[i];
304306
const auto& recHit = rechitManager[hitIndex];
307+
float rechitEnergy = recHit.energy();
305308
float squaredSimFraction = simFraction * simFraction;
306-
float squaredRecHitEnergy = recHit.energy() * recHit.energy();
309+
float squaredRecHitEnergy = rechitEnergy * rechitEnergy;
307310
simToRecoScoresDenominator += squaredSimFraction * squaredRecHitEnergy;
308-
309311
const auto& hitToRecoTracksterVec = hitToTracksterMap[hitIndex];
310312
for (const auto& recoTracksterElement : hitToRecoTracksterVec) {
311313
unsigned int recoTracksterIndex = recoTracksterElement.index();
@@ -333,22 +335,22 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
333335
}
334336
}
335337

338+
assert(simToRecoScoresDenominator > 0.f);
336339
const float invDenominator = 1.f / simToRecoScoresDenominator;
337-
338340
for (unsigned int i = 0; i < simTracksterHitsAndFractions.size(); ++i) {
339341
const auto& hitIndex = simTracksterHitsAndFractions[i].index();
340342
float simFraction = simFractions[i];
341343
const auto& recHit = rechitManager[hitIndex];
344+
float rechitEnergy = recHit.energy();
342345
float squaredSimFraction = simFraction * simFraction;
343-
float squaredRecHitEnergy = recHit.energy() * recHit.energy();
344-
float simSharedEnergy = recHit.energy() * simFraction;
345-
346+
float squaredRecHitEnergy = rechitEnergy * rechitEnergy;
347+
float simSharedEnergy = rechitEnergy * simFraction;
346348
const auto& hitToRecoTracksterVec = hitToAssociatedRecoTracksterMap[i];
347349
for (const auto& recoTracksterElement : hitToRecoTracksterVec) {
348350
auto recoTracksterIndex = recoTracksterElement.index();
349351
float recoFraction = recoTracksterElement.fraction();
350352
edm::Ref<std::vector<ticl::Trackster>> recoTracksterRef(recoTrackstersHandle, recoTracksterIndex);
351-
float sharedEnergy = std::min(recoFraction * recHit.energy(), simSharedEnergy);
353+
float sharedEnergy = std::min(recoFraction * rechitEnergy, simSharedEnergy);
352354
float squaredFraction =
353355
std::min(squaredSimFraction, (recoFraction - simFraction) * (recoFraction - simFraction));
354356
float score = invDenominator * squaredFraction * squaredRecHitEnergy;
@@ -357,9 +359,16 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID,
357359
}
358360
}
359361

362+
auto sortingFunc = [](const auto& a, const auto& b) {
363+
if (a.score() != b.score())
364+
return a.score() < b.score();
365+
else
366+
return a.index() < b.index();
367+
};
368+
360369
// 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(); });
370+
tracksterToSimTracksterMap->sort(sortingFunc);
371+
simTracksterToTracksterMap->sort(sortingFunc);
363372

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

SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByLCsProducer.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void AllTracksterToSimTracksterAssociatorsByLCsProducer::produce(edm::StreamID,
244244
}
245245
}
246246
}
247-
247+
assert(simToRecoScoresDenominator > 0.f);
248248
const float invDenominator = 1.f / simToRecoScoresDenominator;
249249

250250
for (unsigned int i = 0; i < layerClustersIds.size(); ++i) {
@@ -269,9 +269,16 @@ void AllTracksterToSimTracksterAssociatorsByLCsProducer::produce(edm::StreamID,
269269
}
270270
}
271271
}
272+
auto sortingFunc = [](const auto& a, const auto& b) {
273+
if (a.score() != b.score())
274+
return a.score() < b.score();
275+
else
276+
return a.index() < b.index();
277+
};
278+
272279
// Sort the maps by score in ascending order
273-
tracksterToSimTracksterMap->sort([](const auto& a, const auto& b) { return a.score() < b.score(); });
274-
simTracksterToTracksterMap->sort([](const auto& a, const auto& b) { return a.score() < b.score(); });
280+
tracksterToSimTracksterMap->sort(sortingFunc);
281+
simTracksterToTracksterMap->sort(sortingFunc);
275282

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

0 commit comments

Comments
 (0)