Skip to content

Commit 07f8f59

Browse files
Optimize HGCalValidator, Avoid copying hits, move HGCAL Validation to rechit multivector manager
1 parent 5255be2 commit 07f8f59

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

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; };

Validation/HGCalValidation/plugins/HGCalValidator.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset)
100100
const edm::InputTag& label_cp_fake_tag = pset.getParameter<edm::InputTag>("label_cp_fake");
101101

102102
for (auto& label : hits_label_) {
103-
hits_token_.push_back(consumes<HGCRecHitCollection>(label));
103+
hits_tokens_.push_back(consumes<HGCRecHitCollection>(label));
104104
}
105105
label_cp_effic = consumes<std::vector<CaloParticle>>(label_cp_effic_tag);
106106
label_cp_fake = consumes<std::vector<CaloParticle>>(label_cp_fake_tag);
@@ -339,7 +339,7 @@ void HGCalValidator::cpParametersAndSelection(const Histograms& histograms,
339339
std::vector<size_t>& selected_cPeff,
340340
unsigned int layers,
341341
std::unordered_map<DetId, const unsigned int> const& hitMap,
342-
std::vector<HGCRecHit> const& hits) const {
342+
MultiVectorManager<HGCRecHit> const& hits) const {
343343
selected_cPeff.reserve(cPeff.size());
344344

345345
size_t j = 0;
@@ -387,28 +387,28 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
387387

388388
edm::Handle<std::map<uint, std::vector<uint>>> simTrackstersMapHandle;
389389
event.getByToken(simTrackstersMap_, simTrackstersMapHandle);
390-
const std::map<uint, std::vector<uint>> cpToSc_SimTrackstersMap = *simTrackstersMapHandle;
390+
const std::map<uint, std::vector<uint>>& cpToSc_SimTrackstersMap = *simTrackstersMapHandle;
391391

392392
edm::ESHandle<CaloGeometry> geom = setup.getHandle(caloGeomToken_);
393393
tools_->setGeometry(*geom);
394394
histoProducerAlgo_->setRecHitTools(tools_);
395395

396396
edm::Handle<ticl::SimToRecoCollection> simtorecoCollectionH;
397397
event.getByToken(associatorMapStR, simtorecoCollectionH);
398-
auto simRecColl = *simtorecoCollectionH;
398+
const auto& simRecColl = *simtorecoCollectionH;
399399
edm::Handle<ticl::RecoToSimCollection> recotosimCollectionH;
400400
event.getByToken(associatorMapRtS, recotosimCollectionH);
401-
auto recSimColl = *recotosimCollectionH;
401+
const auto& recSimColl = *recotosimCollectionH;
402402

403403
edm::Handle<std::unordered_map<DetId, const unsigned int>> hitMapHandle;
404404
event.getByToken(hitMap_, hitMapHandle);
405-
const std::unordered_map<DetId, const unsigned int>* hitMap = &*hitMapHandle;
405+
const std::unordered_map<DetId, const unsigned int>& hitMap = *hitMapHandle;
406406

407-
std::vector<HGCRecHit> hits;
408-
for (auto& token : hits_token_) {
409-
edm::Handle<HGCRecHitCollection> hitsHandle;
407+
MultiVectorManager<HGCRecHit> rechitManager;
408+
for (const auto &token : hits_tokens_) {
409+
Handle<HGCRecHitCollection> hitsHandle;
410410
event.getByToken(token, hitsHandle);
411-
hits.insert(hits.end(), (*hitsHandle).begin(), (*hitsHandle).end());
411+
rechitManager.addVector(*hitsHandle);
412412
}
413413

414414
//Some general info on layers etc.
@@ -428,7 +428,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
428428
LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl;
429429
std::vector<size_t> selected_cPeff;
430430
cpParametersAndSelection(
431-
histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, *hitMap, hits);
431+
histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, hitMap, rechitManager);
432432

433433
//get collections from the event
434434
//simClusters
@@ -500,11 +500,11 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
500500
simClusters,
501501
sCIndices,
502502
inputClusterMask,
503-
*hitMap,
503+
hitMap,
504504
totallayers_to_monitor_,
505505
recSimColl,
506506
simRecColl,
507-
hits);
507+
rechitManager);
508508

509509
//General Info on simClusters
510510
LogTrace("HGCalValidator") << "\n# of SimClusters: " << nSimClusters
@@ -525,13 +525,13 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
525525
caloParticles,
526526
cPIndices,
527527
selected_cPeff,
528-
*hitMap,
528+
hitMap,
529529
cumulative_material_budget,
530530
totallayers_to_monitor_,
531531
thicknesses_to_monitor_,
532532
recSimColl,
533533
simRecColl,
534-
hits);
534+
rechitManager);
535535

536536
for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) {
537537
histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]);
@@ -587,9 +587,9 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
587587
caloParticles,
588588
cPIndices,
589589
selected_cPeff,
590-
*hitMap,
590+
hitMap,
591591
totallayers_to_monitor_,
592-
hits,
592+
rechitManager,
593593
mapsFound,
594594
trackstersToSimTrackstersMapH,
595595
simTrackstersToTrackstersMapH,

Validation/HGCalValidation/src/HGVHistoProducerAlgo.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ void HGVHistoProducerAlgo::fill_caloparticle_histos(const Histograms& histograms
14531453
std::vector<SimVertex> const& simVertices,
14541454
unsigned int layers,
14551455
std::unordered_map<DetId, const unsigned int> const& hitMap,
1456-
std::vector<HGCRecHit> const& hits) const {
1456+
MultiVectorManager<HGCRecHit> const& hits) const {
14571457
const auto eta = getEta(caloParticle.eta());
14581458
if (histograms.h_caloparticle_eta.count(pdgid)) {
14591459
histograms.h_caloparticle_eta.at(pdgid)->Fill(eta);
@@ -1715,7 +1715,7 @@ void HGVHistoProducerAlgo::HGVHistoProducerAlgo::fill_simClusterAssociation_hist
17151715
unsigned int layers,
17161716
const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap,
17171717
const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap,
1718-
std::vector<HGCRecHit> const& hits) const {
1718+
MultiVectorManager<HGCRecHit> const& hits) const {
17191719
//Each event to be treated as two events: an event in +ve endcap,
17201720
//plus another event in -ve endcap. In this spirit there will be
17211721
//a layer variable (layerid) that maps the layers in :
@@ -1757,7 +1757,7 @@ void HGVHistoProducerAlgo::layerClusters_to_CaloParticles(const Histograms& hist
17571757
unsigned int layers,
17581758
const ticl::RecoToSimCollection& cpsInLayerClusterMap,
17591759
const ticl::SimToRecoCollection& cPOnLayerMap,
1760-
std::vector<HGCRecHit> const& hits) const {
1760+
MultiVectorManager<HGCRecHit> const& hits) const {
17611761
const auto nLayerClusters = clusters.size();
17621762

17631763
std::unordered_map<DetId, std::vector<HGVHistoProducerAlgo::detIdInfoInCluster>> detIdToCaloParticleId_Map;
@@ -2018,7 +2018,7 @@ void HGVHistoProducerAlgo::layerClusters_to_SimClusters(
20182018
unsigned int layers,
20192019
const ticl::RecoToSimCollectionWithSimClusters& scsInLayerClusterMap,
20202020
const ticl::SimToRecoCollectionWithSimClusters& lcsInSimClusterMap,
2021-
std::vector<HGCRecHit> const& hits) const {
2021+
MultiVectorManager<HGCRecHit> const& hits) const {
20222022
// Here fill the plots to compute the different metrics linked to
20232023
// reco-level, namely fake-rate and merge-rate. In this loop should *not*
20242024
// restrict only to the selected SimClusters.
@@ -2199,7 +2199,7 @@ void HGVHistoProducerAlgo::fill_generic_cluster_histos(const Histograms& histogr
21992199
std::vector<int> thicknesses,
22002200
const ticl::RecoToSimCollection& cpsInLayerClusterMap,
22012201
const ticl::SimToRecoCollection& cPOnLayerMap,
2202-
std::vector<HGCRecHit> const& hits) const {
2202+
MultiVectorManager<HGCRecHit> const& hits) const {
22032203
//Each event to be treated as two events: an event in +ve endcap,
22042204
//plus another event in -ve endcap. In this spirit there will be
22052205
//a layer variable (layerid) that maps the layers in :
@@ -2684,7 +2684,7 @@ void HGVHistoProducerAlgo::fill_trackster_histos(
26842684
std::vector<size_t> const& cPSelectedIndices,
26852685
std::unordered_map<DetId, const unsigned int> const& hitMap,
26862686
unsigned int layers,
2687-
std::vector<HGCRecHit> const& hits,
2687+
MultiVectorManager<HGCRecHit> const& hits,
26882688
bool mapsFound,
26892689
const edm::Handle<TracksterToTracksterMap>& trackstersToSimTrackstersByLCsMapH,
26902690
const edm::Handle<TracksterToTracksterMap>& simTrackstersToTrackstersByLCsMapH,
@@ -2932,7 +2932,7 @@ void HGVHistoProducerAlgo::setRecHitTools(std::shared_ptr<hgcal::RecHitTools> re
29322932

29332933
DetId HGVHistoProducerAlgo::findmaxhit(const reco::CaloCluster& cluster,
29342934
std::unordered_map<DetId, const unsigned int> const& hitMap,
2935-
std::vector<HGCRecHit> const& hits) const {
2935+
MultiVectorManager<HGCRecHit> const& hits) const {
29362936
const auto& hits_and_fractions = cluster.hitsAndFractions();
29372937

29382938
DetId themaxid;

0 commit comments

Comments
 (0)