Skip to content

Commit 7915102

Browse files
authored
Merge pull request #46962 from felicepantaleo/HGCAL_Validation_reproducible_associators
Make HGCAL Validation reproducible
2 parents e804087 + d971df6 commit 7915102

File tree

6 files changed

+80
-57
lines changed

6 files changed

+80
-57
lines changed

SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ AllTracksterToSimTracksterAssociatorsByHitsProducer::AllTracksterToSimTracksterA
5454
const auto& tracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("tracksterCollections");
5555
for (const auto& tag : tracksterCollections) {
5656
std::string label = tag.label();
57-
if (tag.instance() != "") {
57+
if (!tag.instance().empty()) {
5858
label += tag.instance();
5959
}
6060
tracksterCollectionTokens_.emplace_back(label, consumes<std::vector<ticl::Trackster>>(tag));
@@ -69,7 +69,7 @@ AllTracksterToSimTracksterAssociatorsByHitsProducer::AllTracksterToSimTracksterA
6969
const auto& simTracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("simTracksterCollections");
7070
for (const auto& tag : simTracksterCollections) {
7171
std::string label = tag.label();
72-
if (tag.instance() != "") {
72+
if (!tag.instance().empty()) {
7373
label += tag.instance();
7474
}
7575
simTracksterCollectionTokens_.emplace_back(label, consumes<std::vector<ticl::Trackster>>(tag));
@@ -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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ AllTracksterToSimTracksterAssociatorsByLCsProducer::AllTracksterToSimTracksterAs
4343
const auto& tracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("tracksterCollections");
4444
for (const auto& tag : tracksterCollections) {
4545
std::string label = tag.label();
46-
if (tag.instance() != "") {
46+
if (!tag.instance().empty()) {
4747
label += tag.instance();
4848
}
4949
tracksterCollectionTokens_.emplace_back(label, consumes<std::vector<ticl::Trackster>>(tag));
@@ -57,7 +57,7 @@ AllTracksterToSimTracksterAssociatorsByLCsProducer::AllTracksterToSimTracksterAs
5757
const auto& simTracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("simTracksterCollections");
5858
for (const auto& tag : simTracksterCollections) {
5959
std::string label = tag.label();
60-
if (tag.instance() != "") {
60+
if (!tag.instance().empty()) {
6161
label += tag.instance();
6262
}
6363
simTracksterCollectionTokens_.emplace_back(label, consumes<std::vector<ticl::Trackster>>(tag));
@@ -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);

Validation/HGCalValidation/interface/HGCalValidator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "SimDataFormats/Associations/interface/LayerClusterToSimClusterAssociator.h"
3333
#include "SimDataFormats/Associations/interface/TICLAssociationMap.h"
3434

35+
#include "CommonTools/RecoAlgos/interface/MultiVectorManager.h"
36+
3537
class PileupSummaryInfo;
3638

3739
struct HGCalValidatorHistograms {
@@ -65,7 +67,7 @@ class HGCalValidator : public DQMGlobalEDAnalyzer<HGCalValidatorHistograms> {
6567
std::vector<size_t>& selected_cPeff,
6668
unsigned int layers,
6769
std::unordered_map<DetId, const unsigned int> const&,
68-
std::vector<HGCRecHit> const& hits) const;
70+
MultiVectorManager<HGCRecHit> const& hits) const;
6971

7072
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
7173

@@ -111,7 +113,7 @@ class HGCalValidator : public DQMGlobalEDAnalyzer<HGCalValidatorHistograms> {
111113
edm::EDGetTokenT<ticl::RecoToSimCollectionWithSimClusters> associatorMapRtSim;
112114
std::unique_ptr<HGVHistoProducerAlgo> histoProducerAlgo_;
113115
std::vector<edm::InputTag> hits_label_;
114-
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hits_token_;
116+
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hits_tokens_;
115117
std::unique_ptr<TICLCandidateValidator> candidateVal_;
116118
std::vector<edm::EDGetTokenT<TracksterToTracksterMap>> tracksterToTracksterAssociatorsTokens_;
117119
std::vector<edm::EDGetTokenT<TracksterToTracksterMap>> tracksterToTracksterByHitsAssociatorsTokens_;

Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "DataFormats/HGCalReco/interface/Trackster.h"
2323

2424
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
25+
#include "CommonTools/RecoAlgos/interface/MultiVectorManager.h"
26+
2527
#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
2628
#include "SimDataFormats/Vertex/interface/SimVertex.h"
2729
#include "RecoLocalCalo/HGCalRecProducers/interface/HGCalClusteringAlgoBase.h"
@@ -280,7 +282,7 @@ class HGVHistoProducerAlgo {
280282
unsigned int layers,
281283
const ticl::RecoToSimCollection& recSimColl,
282284
const ticl::SimToRecoCollection& simRecColl,
283-
std::vector<HGCRecHit> const& hits) const;
285+
MultiVectorManager<HGCRecHit> const& hits) const;
284286
void layerClusters_to_SimClusters(const Histograms& histograms,
285287
const int count,
286288
edm::Handle<reco::CaloClusterCollection> clusterHandle,
@@ -293,7 +295,7 @@ class HGVHistoProducerAlgo {
293295
unsigned int layers,
294296
const ticl::RecoToSimCollectionWithSimClusters& recSimColl,
295297
const ticl::SimToRecoCollectionWithSimClusters& simRecColl,
296-
std::vector<HGCRecHit> const& hits) const;
298+
MultiVectorManager<HGCRecHit> const& hits) const;
297299

298300
void tracksters_to_SimTracksters_fp(const Histograms& histograms,
299301
const int count,
@@ -312,7 +314,7 @@ class HGVHistoProducerAlgo {
312314
std::vector<SimVertex> const& simVertices,
313315
unsigned int layers,
314316
std::unordered_map<DetId, const unsigned int> const&,
315-
std::vector<HGCRecHit> const& hits) const;
317+
MultiVectorManager<HGCRecHit> const& hits) const;
316318
void fill_generic_cluster_histos(const Histograms& histograms,
317319
const int count,
318320
edm::Handle<reco::CaloClusterCollection> clusterHandle,
@@ -327,7 +329,7 @@ class HGVHistoProducerAlgo {
327329
std::vector<int> thicknesses,
328330
const ticl::RecoToSimCollection& recSimColl,
329331
const ticl::SimToRecoCollection& simRecColl,
330-
std::vector<HGCRecHit> const& hits) const;
332+
MultiVectorManager<HGCRecHit> const& hits) const;
331333
void fill_simCluster_histos(const Histograms& histograms,
332334
std::vector<SimCluster> const& simClusters,
333335
unsigned int layers,
@@ -344,7 +346,7 @@ class HGVHistoProducerAlgo {
344346
unsigned int layers,
345347
const ticl::RecoToSimCollectionWithSimClusters& recSimColl,
346348
const ticl::SimToRecoCollectionWithSimClusters& simRecColl,
347-
std::vector<HGCRecHit> const& hits) const;
349+
MultiVectorManager<HGCRecHit> const& hits) const;
348350
void fill_cluster_histos(const Histograms& histograms, const int count, const reco::CaloCluster& cluster) const;
349351
void fill_trackster_histos(const Histograms& histograms,
350352
const int count,
@@ -360,7 +362,7 @@ class HGVHistoProducerAlgo {
360362
std::vector<size_t> const& cPSelectedIndices,
361363
std::unordered_map<DetId, const unsigned int> const& hitMap,
362364
unsigned int layers,
363-
std::vector<HGCRecHit> const& hits,
365+
MultiVectorManager<HGCRecHit> const& hits,
364366
bool mapsFound,
365367
const edm::Handle<TracksterToTracksterMap>& trackstersToSimTrackstersByLCsMapH,
366368
const edm::Handle<TracksterToTracksterMap>& simTrackstersToTrackstersByLCsMapH,
@@ -378,7 +380,7 @@ class HGVHistoProducerAlgo {
378380

379381
DetId findmaxhit(const reco::CaloCluster& cluster,
380382
std::unordered_map<DetId, const unsigned int> const&,
381-
std::vector<HGCRecHit> const& hits) const;
383+
MultiVectorManager<HGCRecHit> const& hits) const;
382384

383385
struct detIdInfoInCluster {
384386
bool operator==(const detIdInfoInCluster& o) const { return clusterId == o.clusterId; };

0 commit comments

Comments
 (0)