Skip to content

Commit b9200c3

Browse files
authored
Merge pull request #48565 from bfonta/bugfix/ticl_barrel_dst_sequence
Bugfixes to TICL-barrel
2 parents b081df8 + ea8d625 commit b9200c3

24 files changed

+206
-231
lines changed

DataFormats/Common/interface/ValueMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace edm {
8989
void throwFillSize() const {
9090
Exception::throwThis(errors::InvalidReference,
9191
"ValueMap::Filler: handle and reference "
92-
"collections should the same size\n");
92+
"collections should have the same size\n");
9393
}
9494
void throwFillID(ProductID id) const {
9595
Exception e(errors::InvalidReference);

RecoLocalCalo/HGCalRecAlgos/src/RecHitTools.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,12 @@ bool RecHitTools::isScintillatorFine(const DetId& id) const {
519519
return false;
520520
}
521521
}
522-
bool RecHitTools::isBarrel(const DetId& id) const { return (id.det() == DetId::Ecal || id.det() == DetId::Hcal); }
522+
bool RecHitTools::isBarrel(const DetId& id) const {
523+
return (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) ||
524+
(id.det() == DetId::Hcal && id.subdetId() == HcalBarrel) ||
525+
(id.det() == DetId::Hcal && id.subdetId() == HcalOuter);
526+
}
527+
523528
bool RecHitTools::isOnlySilicon(const unsigned int layer) const {
524529
// HFnose TODO
525530
bool isonlysilicon = (layer % bhLastLayer_) < bhOffset_;

RecoLocalCalo/HGCalRecProducers/plugins/RecHitMapProducer.cc

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event
6262
auto hitMapHGCal = std::make_unique<DetIdRecHitMap>();
6363

6464
// Retrieve collections
65+
assert(hgcal_hits_token_.size() == 3);
6566
const auto& ee_hits = evt.getHandle(hgcal_hits_token_[0]);
6667
const auto& fh_hits = evt.getHandle(hgcal_hits_token_[1]);
6768
const auto& bh_hits = evt.getHandle(hgcal_hits_token_[2]);
6869

6970
// Check validity of all handles
70-
if ((ee_hits.isValid()) && (fh_hits.isValid()) && (bh_hits.isValid())) {
71+
if (!ee_hits.isValid() || !fh_hits.isValid() || !bh_hits.isValid()) {
72+
edm::LogWarning("HGCalRecHitMapProducer")
73+
<< "One or more HGCal hit collections are unavailable. Returning an empty map.";
74+
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
75+
} else {
7176
// TODO may be worth to avoid dependency on the order
7277
// of the collections, maybe using a map
7378
edm::MultiSpan<HGCRecHit> rechitSpan;
@@ -79,30 +84,33 @@ void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::Event
7984
const auto recHitDetId = rechitSpan[i].detid();
8085
hitMapHGCal->emplace(recHitDetId, i);
8186
}
82-
} else {
83-
edm::LogWarning("HGCalRecHitMapProducer") << "One or more hit collections are unavailable. Returning an empty map.";
87+
88+
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
8489
}
85-
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
86-
87-
if (!hgcalOnly_) {
88-
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
89-
90-
// Retrieve collections
91-
const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]);
92-
const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]);
93-
94-
if ((ecal_hits.isValid()) && (hbhe_hits.isValid())) {
95-
edm::MultiSpan<reco::PFRecHit> barrelRechitSpan;
96-
barrelRechitSpan.add(*ecal_hits);
97-
barrelRechitSpan.add(*hbhe_hits);
98-
for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) {
99-
const auto recHitDetId = barrelRechitSpan[i].detId();
100-
hitMapBarrel->emplace(recHitDetId, i);
101-
}
102-
} else {
103-
edm::LogWarning("RecHitMapProducer")
104-
<< "One or more barrel hit collections are unavailable. Returning an empty map.";
90+
91+
if (hgcalOnly_) {
92+
return;
93+
}
94+
95+
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
96+
97+
assert(barrel_hits_token_.size() == 2);
98+
const auto& ecal_hits = evt.getHandle(barrel_hits_token_[0]);
99+
const auto& hbhe_hits = evt.getHandle(barrel_hits_token_[1]);
100+
101+
if (!ecal_hits.isValid() || !hbhe_hits.isValid()) {
102+
edm::LogWarning("HGCalRecHitMapProducer")
103+
<< "One or more barrel hit collections are unavailable. Returning an empty map.";
104+
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
105+
} else {
106+
edm::MultiSpan<reco::PFRecHit> barrelRechitSpan;
107+
barrelRechitSpan.add(evt.get(barrel_hits_token_[0]));
108+
barrelRechitSpan.add(evt.get(barrel_hits_token_[1]));
109+
for (unsigned int i = 0; i < barrelRechitSpan.size(); ++i) {
110+
const auto recHitDetId = barrelRechitSpan[i].detId();
111+
hitMapBarrel->emplace(recHitDetId, i);
105112
}
113+
106114
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
107115
}
108116
}

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreImpl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ ticl::association LCToCPAssociatorByEnergyScoreImplT<HIT, CLUSTER>::makeConnecti
7474
const SimCluster& simCluster = (*(it_sc));
7575
std::vector<std::pair<uint32_t, float>> hits_and_fractions;
7676
if constexpr (std::is_same_v<HIT, HGCRecHit>)
77-
hits_and_fractions = simCluster.endcap_hits_and_fractions();
77+
hits_and_fractions = simCluster.filtered_hits_and_fractions(
78+
[this](const DetId& detid) { return !recHitTools_->isBarrel(detid); });
7879
else
79-
hits_and_fractions = simCluster.barrel_hits_and_fractions();
80+
hits_and_fractions = simCluster.filtered_hits_and_fractions(
81+
[this](const DetId& detid) { return recHitTools_->isBarrel(detid); });
8082
for (const auto& it_haf : hits_and_fractions) {
8183
const auto hitid = (it_haf.first);
8284
unsigned int cpLayerId = recHitTools_->getLayerWithOffset(hitid);

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::LCToCPAssociatorByEnergySc
99
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
1010
hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
1111
for (auto &label : hits_label_) {
12-
if constexpr (std::is_same_v<HIT, HGCRecHit>)
13-
hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(label));
14-
else
15-
hits_token_.push_back(consumes<std::vector<HIT>>(label));
12+
hits_token_.push_back(consumes<std::vector<HIT>>(label));
1613
}
1714

1815
rhtools_ = std::make_shared<hgcal::RecHitTools>();
@@ -32,37 +29,19 @@ void LCToCPAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::produce(edm::StreamID
3229
rhtools_->setGeometry(*geom);
3330

3431
std::vector<const HIT *> hits;
35-
if constexpr (std::is_same_v<HIT, HGCRecHit>) {
36-
for (auto &token : hgcal_hits_token_) {
37-
edm::Handle<HGCRecHitCollection> hits_handle;
38-
iEvent.getByToken(token, hits_handle);
3932

40-
// Check handle validity
41-
if (!hits_handle.isValid()) {
42-
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT")
43-
<< "HGCAL Hit collection not available for token. Skipping this collection.";
44-
continue; // Skip invalid handle
45-
}
33+
for (unsigned i = 0; i < hits_token_.size(); ++i) {
34+
auto hits_handle = iEvent.getHandle(hits_token_[i]);
4635

47-
for (const auto &hit : *hits_handle) {
48-
hits.push_back(&hit);
49-
}
36+
// Check handle validity
37+
if (!hits_handle.isValid()) {
38+
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducer")
39+
<< "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection.";
40+
continue; // Skip invalid handle
5041
}
51-
} else {
52-
for (auto &token : hits_token_) {
53-
edm::Handle<std::vector<HIT>> hits_handle;
54-
iEvent.getByToken(token, hits_handle);
55-
56-
// Check handle validity
57-
if (!hits_handle.isValid()) {
58-
edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT")
59-
<< "Barrel Hit collection not available for token. Skipping this collection.";
60-
continue; // Skip invalid handle
61-
}
6242

63-
for (const auto &hit : *hits_handle) {
64-
hits.push_back(&hit);
65-
}
43+
for (const auto &hit : *hits_handle) {
44+
hits.push_back(&hit);
6645
}
6746
}
6847

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class LCToCPAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<>
3535
const bool hardScatterOnly_;
3636
std::shared_ptr<hgcal::RecHitTools> rhtools_;
3737
std::vector<edm::InputTag> hits_label_;
38-
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
3938
std::vector<edm::EDGetTokenT<std::vector<HIT>>> hits_token_;
4039
};
4140

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorEDProducer.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010

1111
// user include files
1212
#include "FWCore/Framework/interface/global/EDProducer.h"
13-
1413
#include "FWCore/Framework/interface/Event.h"
1514
#include "FWCore/Framework/interface/MakerMacros.h"
16-
1715
#include "FWCore/Framework/interface/ESHandle.h"
18-
1916
#include "FWCore/ParameterSet/interface/ParameterSet.h"
20-
2117
#include "SimDataFormats/Associations/interface/LayerClusterToCaloParticleAssociator.h"
22-
2318
#include "FWCore/MessageLogger/interface/MessageLogger.h"
19+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
2420
#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h"
2521
#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h"
2622
#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
@@ -29,7 +25,6 @@
2925
#include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
3026
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
3127
#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
32-
3328
#include "FWCore/Utilities/interface/EDGetToken.h"
3429

3530
//
@@ -42,11 +37,15 @@ class LCToCPAssociatorEDProducerT : public edm::global::EDProducer<> {
4237
explicit LCToCPAssociatorEDProducerT(const edm::ParameterSet &);
4338
~LCToCPAssociatorEDProducerT() override = default;
4439

40+
// static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
41+
4542
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
4643

4744
private:
4845
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
4946

47+
edm::InputTag label_lc;
48+
5049
edm::EDGetTokenT<CaloParticleCollection> CPCollectionToken_;
5150
edm::EDGetTokenT<CLUSTER> LCCollectionToken_;
5251
edm::EDGetTokenT<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>> associatorToken_;
@@ -57,8 +56,10 @@ LCToCPAssociatorEDProducerT<CLUSTER>::LCToCPAssociatorEDProducerT(const edm::Par
5756
produces<ticl::SimToRecoCollectionT<CLUSTER>>();
5857
produces<ticl::RecoToSimCollectionT<CLUSTER>>();
5958

59+
label_lc = pset.getParameter<edm::InputTag>("label_lc");
60+
6061
CPCollectionToken_ = consumes<CaloParticleCollection>(pset.getParameter<edm::InputTag>("label_cp"));
61-
LCCollectionToken_ = consumes<CLUSTER>(pset.getParameter<edm::InputTag>("label_lc"));
62+
LCCollectionToken_ = consumes<CLUSTER>(label_lc);
6263
associatorToken_ =
6364
consumes<ticl::LayerClusterToCaloParticleAssociatorT<CLUSTER>>(pset.getParameter<edm::InputTag>("associator"));
6465
}
@@ -95,7 +96,7 @@ void LCToCPAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
9596
// Protection against missing cluster collection
9697
if (!LCCollection.isValid()) {
9798
edm::LogWarning("LCToCPAssociatorEDProducerT")
98-
<< "Cluster collection is unavailable. Producing empty associations.";
99+
<< "CaloCluster collection with label " << label_lc << " is unavailable. Producing empty associations.";
99100

100101
// Return empty collections
101102
auto emptyRecSimColl = std::make_unique<ticl::RecoToSimCollectionT<CLUSTER>>();
@@ -123,9 +124,9 @@ void LCToCPAssociatorEDProducerT<CLUSTER>::produce(edm::StreamID,
123124
template <typename CLUSTER>
124125
void LCToCPAssociatorEDProducerT<CLUSTER>::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
125126
edm::ParameterSetDescription desc;
126-
desc.add<edm::InputTag>("label_cp", edm::InputTag("cpAssocByEnergyScoreProducer"));
127-
desc.add<edm::InputTag>("label_lc", edm::InputTag("mix", "MergedCaloTruth"));
128-
desc.add<edm::InputTag>("associator", edm::InputTag("hgcalMergeLayerClusters"));
127+
desc.add<edm::InputTag>("label_cp", edm::InputTag("mix", "MergedCaloTruth"));
128+
desc.add<edm::InputTag>("label_lc", edm::InputTag("hgcalMergeLayerClusters"));
129+
desc.add<edm::InputTag>("associator", edm::InputTag("lcAssocByEnergyScoreProducer"));
129130
descriptions.addWithDefaultLabel(desc);
130131
}
131132

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreImpl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ ticl::association LCToSCAssociatorByEnergyScoreImplT<HIT, CLUSTER>::makeConnecti
7373
for (const auto& scId : sCIndices) {
7474
std::vector<std::pair<uint32_t, float>> hits_and_fractions = simClusters[scId].hits_and_fractions();
7575
if constexpr (std::is_same_v<HIT, HGCRecHit>)
76-
hits_and_fractions = simClusters[scId].endcap_hits_and_fractions();
76+
hits_and_fractions = simClusters[scId].filtered_hits_and_fractions(
77+
[this](const DetId& detid) { return !recHitTools_->isBarrel(detid); });
7778
else
78-
hits_and_fractions = simClusters[scId].barrel_hits_and_fractions();
79+
hits_and_fractions = simClusters[scId].filtered_hits_and_fractions(
80+
[this](const DetId& detid) { return recHitTools_->isBarrel(detid); });
7981
for (const auto& it_haf : hits_and_fractions) {
8082
const auto hitid = (it_haf.first);
8183
unsigned int scLayerId = recHitTools_->getLayer(hitid);

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ LCToSCAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::LCToSCAssociatorByEnergySc
99
hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
1010
hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
1111
for (auto &label : hits_label_) {
12-
if constexpr (std::is_same_v<HIT, HGCRecHit>)
13-
hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(label));
14-
else
15-
hits_token_.push_back(consumes<std::vector<HIT>>(label));
12+
hits_token_.push_back(consumes<std::vector<HIT>>(label));
1613
}
1714

1815
rhtools_ = std::make_shared<hgcal::RecHitTools>();
@@ -32,37 +29,19 @@ void LCToSCAssociatorByEnergyScoreProducerT<HIT, CLUSTER>::produce(edm::StreamID
3229
rhtools_->setGeometry(*geom);
3330

3431
std::vector<const HIT *> hits;
35-
if constexpr (std::is_same_v<HIT, HGCRecHit>) {
36-
for (auto &token : hgcal_hits_token_) {
37-
edm::Handle<HGCRecHitCollection> hits_handle;
38-
iEvent.getByToken(token, hits_handle);
3932

40-
// Check handle validity
41-
if (!hits_handle.isValid()) {
42-
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT")
43-
<< "HGCAL Hit collection not available for token. Skipping this collection.";
44-
continue; // Skip invalid handle
45-
}
33+
for (unsigned i = 0; i < hits_token_.size(); ++i) {
34+
auto hits_handle = iEvent.getHandle(hits_token_[i]);
4635

47-
for (const auto &hit : *hits_handle) {
48-
hits.push_back(&hit);
49-
}
36+
// Check handle validity
37+
if (!hits_handle.isValid()) {
38+
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducer")
39+
<< "Hit collection not available for token " << hits_label_[i] << ". Skipping this collection.";
40+
continue; // Skip invalid handle
5041
}
51-
} else {
52-
for (auto &token : hits_token_) {
53-
edm::Handle<std::vector<HIT>> hits_handle;
54-
iEvent.getByToken(token, hits_handle);
55-
56-
// Check handle validity
57-
if (!hits_handle.isValid()) {
58-
edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT")
59-
<< "Barrel Hit collection not available for token. Skipping this collection.";
60-
continue; // Skip invalid handle
61-
}
6242

63-
for (const auto &hit : *hits_handle) {
64-
hits.push_back(&hit);
65-
}
43+
for (const auto &hit : *hits_handle) {
44+
hits.push_back(&hit);
6645
}
6746
}
6847

SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class LCToSCAssociatorByEnergyScoreProducerT : public edm::global::EDProducer<>
3535
const bool hardScatterOnly_;
3636
std::shared_ptr<hgcal::RecHitTools> rhtools_;
3737
std::vector<edm::InputTag> hits_label_;
38-
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
3938
std::vector<edm::EDGetTokenT<std::vector<HIT>>> hits_token_;
4039
};
4140

0 commit comments

Comments
 (0)