From 29a759281b68d836ab8ca12a6749aac839f24eaf Mon Sep 17 00:00:00 2001 From: Sunanda Date: Thu, 14 Jul 2022 05:31:21 +0200 Subject: [PATCH 1/3] Test RecHitTool for partial wafers of HGCal and also add a few utility methods for wafer --- .../interface/HGCalWaferType.h | 10 +- .../HGCalCommonData/src/HGCalDDDConstants.cc | 4 + .../HGCalCommonData/src/HGCalWaferType.cc | 41 ++++-- .../python/hgcalToolTesterPartialWafer_cff.py | 8 ++ .../test/HGCalToolTesterPartialWafer.cc | 122 ++++++++++++++++++ .../test/testHGCalPartialWafer_cfg.py | 74 +++++++++++ SimG4CMS/Calo/plugins/HGCalHitPartial.cc | 16 +-- SimG4CMS/Calo/src/HGCalNumberingScheme.cc | 2 +- 8 files changed, 251 insertions(+), 26 deletions(-) create mode 100644 RecoLocalCalo/HGCalRecAlgos/python/hgcalToolTesterPartialWafer_cff.py create mode 100644 RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc create mode 100644 RecoLocalCalo/HGCalRecAlgos/test/testHGCalPartialWafer_cfg.py diff --git a/Geometry/HGCalCommonData/interface/HGCalWaferType.h b/Geometry/HGCalCommonData/interface/HGCalWaferType.h index 9c1d3ba24730f..a9ffd70b3a9e8 100644 --- a/Geometry/HGCalCommonData/interface/HGCalWaferType.h +++ b/Geometry/HGCalCommonData/interface/HGCalWaferType.h @@ -26,10 +26,14 @@ class HGCalWaferType { int choice, unsigned int cutValue, double cutFracArea); - ~HGCalWaferType(); - int getType(double xpos, double ypos, double zpos); - static int getType(int index, const std::vector& indices, const std::vector& types); + ~HGCalWaferType() = default; + + static int getCassette(int index, const HGCalParameters::waferInfo_map& wafers); + static int getOrient(int index, const HGCalParameters::waferInfo_map& wafers); + static int getPartial(int index, const HGCalParameters::waferInfo_map& wafers); static int getType(int index, const HGCalParameters::waferInfo_map& wafers); + static int getType(int index, const std::vector& indices, const std::vector& types); + int getType(double xpos, double ypos, double zpos); std::pair rLimits(double zpos); private: diff --git a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc index e95e9cbeae6e9..fdb79a34b938a 100644 --- a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc +++ b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc @@ -1336,6 +1336,10 @@ void HGCalDDDConstants::waferFromPosition(const double x, if (waferHexagon8File()) { int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV); celltype = HGCalWaferType::getType(index, hgpar_->waferInfoMap_); +#ifdef EDM_ML_DEBUG + if (debug) + edm::LogVerbatim("HGCalGeom") << "Position (" << x << ", " << y << ") Wafer type:partial:orient:cassette " << celltype << ":" << HGCalWaferType::getPartial(index, hgpar_->waferInfoMap_) << ":" << HGCalWaferType::getOrient(index, hgpar_->waferInfoMap_) << ":" << HGCalWaferType::getCassette(index, hgpar_->waferInfoMap_); +#endif } else { auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer, waferU, waferV)); celltype = ((itr == hgpar_->typesInLayers_.end()) ? HGCSiliconDetId::HGCalCoarseThick diff --git a/Geometry/HGCalCommonData/src/HGCalWaferType.cc b/Geometry/HGCalCommonData/src/HGCalWaferType.cc index e411a045f9fcb..028c85847a2b1 100644 --- a/Geometry/HGCalCommonData/src/HGCalWaferType.cc +++ b/Geometry/HGCalCommonData/src/HGCalWaferType.cc @@ -31,7 +31,33 @@ HGCalWaferType::HGCalWaferType(const std::vector& rad100, #endif } -HGCalWaferType::~HGCalWaferType() {} +int HGCalWaferType::getCassette(int index, const HGCalParameters::waferInfo_map& wafers) { + auto itr = wafers.find(index); + return ((itr == wafers.end()) ? -1 : ((itr->second).cassette)); +} + +int HGCalWaferType::getOrient(int index, const HGCalParameters::waferInfo_map& wafers) { + auto itr = wafers.find(index); + return ((itr == wafers.end()) ? -1 : ((itr->second).orient)); +} + +int HGCalWaferType::getPartial(int index, const HGCalParameters::waferInfo_map& wafers) { + auto itr = wafers.find(index); + return ((itr == wafers.end()) ? -1 : ((itr->second).part)); +} + +int HGCalWaferType::getType(int index, const HGCalParameters::waferInfo_map& wafers) { + auto itr = wafers.find(index); + return ((itr == wafers.end()) ? -1 : ((itr->second).type)); +} + +int HGCalWaferType::getType(int index, const std::vector& indices, const std::vector& properties) { + auto itr = std::find(std::begin(indices), std::end(indices), index); + int type = (itr == std::end(indices)) + ? -1 + : HGCalProperty::waferThick(properties[static_cast(itr - std::begin(indices))]); + return type; +} int HGCalWaferType::getType(double xpos, double ypos, double zpos) { std::vector xc(HGCalParameters::k_CornerSize, 0); @@ -104,19 +130,6 @@ int HGCalWaferType::getType(double xpos, double ypos, double zpos) { return type; } -int HGCalWaferType::getType(int index, const std::vector& indices, const std::vector& properties) { - auto itr = std::find(std::begin(indices), std::end(indices), index); - int type = (itr == std::end(indices)) - ? -1 - : HGCalProperty::waferThick(properties[static_cast(itr - std::begin(indices))]); - return type; -} - -int HGCalWaferType::getType(int index, const HGCalParameters::waferInfo_map& wafers) { - auto itr = wafers.find(index); - return ((itr == wafers.end()) ? -1 : ((itr->second).type)); -} - std::pair HGCalWaferType::rLimits(double zpos) { double zz = std::abs(zpos); if (zz < zMin_) diff --git a/RecoLocalCalo/HGCalRecAlgos/python/hgcalToolTesterPartialWafer_cff.py b/RecoLocalCalo/HGCalRecAlgos/python/hgcalToolTesterPartialWafer_cff.py new file mode 100644 index 0000000000000..a5caec5837db7 --- /dev/null +++ b/RecoLocalCalo/HGCalRecAlgos/python/hgcalToolTesterPartialWafer_cff.py @@ -0,0 +1,8 @@ +import FWCore.ParameterSet.Config as cms + +from RecoLocalCalo.HGCalRecAlgos.hgcalToolTesterPartialWaferEE_cfi import * + +hgcalToolTesterPartialWaferHE = hgcalToolTesterPartialWaferEE.clone( + nameSense = "HGCalHESiliconSensitive", + caloHitSource = "HGCHitsHEfront" +) diff --git a/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc b/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc new file mode 100644 index 0000000000000..eceb924ff4185 --- /dev/null +++ b/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc @@ -0,0 +1,122 @@ +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" + +#include "SimDataFormats/CaloHit/interface/PCaloHit.h" +#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloTopology/interface/HGCalTopology.h" +#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h" +#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" +#include "Geometry/HGCalCommonData/interface/HGCalParameters.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" + +#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" + +#include +#include + +class HGCalToolTesterPartialWafer : public edm::one::EDAnalyzer { +public: + HGCalToolTesterPartialWafer(const edm::ParameterSet& ps); + ~HGCalToolTesterPartialWafer() override = default; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +protected: + void beginRun(edm::Run const&, edm::EventSetup const&) override; + void analyze(edm::Event const&, edm::EventSetup const&) override; + void endRun(edm::Run const&, edm::EventSetup const&) override {} + void beginJob() override {} + void endJob() override {} + +private: + const std::string g4Label_, caloHitSource_, nameSense_; + const edm::EDGetTokenT tok_calo_; + const edm::ESGetToken geomToken_; + const HGCalGeometry* geom_; + CaloGeometry geo_; + hgcal::RecHitTools tool_; +}; + +HGCalToolTesterPartialWafer::HGCalToolTesterPartialWafer(const edm::ParameterSet& ps) + : g4Label_(ps.getParameter("moduleLabel")), + caloHitSource_(ps.getParameter("caloHitSource")), + nameSense_(ps.getParameter("nameSense")), + tok_calo_(consumes(edm::InputTag(g4Label_, caloHitSource_))), + geomToken_(esConsumes()), + geom_(nullptr) { + edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_ + << " Hits: " << caloHitSource_; +} + +void HGCalToolTesterPartialWafer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("moduleLabel", "g4SimHits"); + desc.add("caloHitSource", "HGCHitsEE"); + desc.add("nameSense", "HGCalEESensitive"); + descriptions.add("hgcalToolTesterPartialWaferEE", desc); +} + +void HGCalToolTesterPartialWafer::beginRun(const edm::Run&, const edm::EventSetup& iSetup) { + //Setup the tool + geo_ = iSetup.getData(geomToken_); + geom_ = (nameSense_ == "HGCalEESensitive") ? static_cast(geo_.getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty)) : static_cast(geo_.getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty)); + edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: beginRun Called for " << nameSense_; +} + +void HGCalToolTesterPartialWafer::analyze(const edm::Event& e, const edm::EventSetup& iS) { + // get HGCal geometry constant + tool_.setGeometry(geo_); + const HGCalDDDConstants& hgc = geom_->topology().dddConstants(); + + // get the hit collection + const edm::Handle& hitsCalo = e.getHandle(tok_calo_); + bool getHits = (hitsCalo.isValid()); + uint32_t nhits = (getHits) ? hitsCalo->size() : 0; + uint32_t good(0), allSi(0), all(0); + edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: Input flags Hits " << getHits << " with " << nhits << " hits"; + + if (getHits) { + std::vector hits; + hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end()); + if (!hits.empty()) { + // Loop over all hits + for (auto hit : hits) { + ++all; + DetId id(hit.id()); + if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) { + ++allSi; + HGCSiliconDetId hid(id); + const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV()); + // Only partial wafers + if (info.part != HGCalTypes::WaferFull) { + ++good; + GlobalPoint pos1 = geom_->getPosition(id); + GlobalPoint pos2 = tool_.getPosition(id); + edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id) + << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":" + << info.orient << ":" << info.cassette << " at (" << pos1.x() << ", " << pos1.y() + << ", " << pos1.z() << ") or (" < #include -class HGcalHitPartial : public edm::one::EDAnalyzer<> { +class HGCalHitPartial : public edm::one::EDAnalyzer<> { public: - HGcalHitPartial(const edm::ParameterSet& ps); - ~HGcalHitPartial() override = default; + HGCalHitPartial(const edm::ParameterSet& ps); + ~HGCalHitPartial() override = default; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); protected: @@ -42,7 +42,7 @@ class HGcalHitPartial : public edm::one::EDAnalyzer<> { const edm::ESGetToken geomToken_; }; -HGcalHitPartial::HGcalHitPartial(const edm::ParameterSet& ps) +HGCalHitPartial::HGCalHitPartial(const edm::ParameterSet& ps) : g4Label_(ps.getParameter("moduleLabel")), caloHitSource_(ps.getParameter("caloHitSource")), nameSense_(ps.getParameter("nameSense")), @@ -52,7 +52,7 @@ HGcalHitPartial::HGcalHitPartial(const edm::ParameterSet& ps) << " Hits: " << caloHitSource_; } -void HGcalHitPartial::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void HGCalHitPartial::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("moduleLabel", "g4SimHits"); desc.add("caloHitSource", "HGCHitsEE"); @@ -60,7 +60,7 @@ void HGcalHitPartial::fillDescriptions(edm::ConfigurationDescriptions& descripti descriptions.add("hgcalHitPartialEE", desc); } -void HGcalHitPartial::analyze(const edm::Event& e, const edm::EventSetup& iS) { +void HGCalHitPartial::analyze(const edm::Event& e, const edm::EventSetup& iS) { // get hcalGeometry const HGCalGeometry* geom = &iS.getData(geomToken_); const HGCalDDDConstants& hgc = geom->topology().dddConstants(); @@ -69,7 +69,7 @@ void HGcalHitPartial::analyze(const edm::Event& e, const edm::EventSetup& iS) { bool getHits = (hitsCalo.isValid()); uint32_t nhits = (getHits) ? hitsCalo->size() : 0; uint32_t good(0), allSi(0), all(0); - edm::LogVerbatim("HGCalSim") << "HGcalHitPartial: Input flags Hits " << getHits << " with " << nhits << " hits"; + edm::LogVerbatim("HGCalSim") << "HGCalHitPartial: Input flags Hits " << getHits << " with " << nhits << " hits"; if (getHits) { std::vector hits; @@ -100,4 +100,4 @@ void HGcalHitPartial::analyze(const edm::Event& e, const edm::EventSetup& iS) { } //define this as a plug-in -DEFINE_FWK_MODULE(HGcalHitPartial); +DEFINE_FWK_MODULE(HGCalHitPartial); diff --git a/SimG4CMS/Calo/src/HGCalNumberingScheme.cc b/SimG4CMS/Calo/src/HGCalNumberingScheme.cc index a0bcd2f4d22eb..72d9fdd7ab67b 100644 --- a/SimG4CMS/Calo/src/HGCalNumberingScheme.cc +++ b/SimG4CMS/Calo/src/HGCalNumberingScheme.cc @@ -51,7 +51,7 @@ uint32_t HGCalNumberingScheme::getUnitID(int layer, int module, int cell, int iz cellV = HGCalTypes::getUnpackedCellV(cell); } else if (mode_ != HGCalGeometryMode::Hexagon8) { double xx = (pos.z() > 0) ? pos.x() : -pos.x(); - hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt, false, false); + hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt, false, true); } if (waferType >= 0) { if (hgcons_.waferHexagon8File()) { From 729497c9794c3411c4f5e9a7f9f5cdbf18753123 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Thu, 14 Jul 2022 05:49:12 +0200 Subject: [PATCH 2/3] Code check --- Geometry/HGCalCommonData/src/HGCalDDDConstants.cc | 7 +++++-- .../test/HGCalToolTesterPartialWafer.cc | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc index fdb79a34b938a..24751c8394dcf 100644 --- a/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc +++ b/Geometry/HGCalCommonData/src/HGCalDDDConstants.cc @@ -1337,8 +1337,11 @@ void HGCalDDDConstants::waferFromPosition(const double x, int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV); celltype = HGCalWaferType::getType(index, hgpar_->waferInfoMap_); #ifdef EDM_ML_DEBUG - if (debug) - edm::LogVerbatim("HGCalGeom") << "Position (" << x << ", " << y << ") Wafer type:partial:orient:cassette " << celltype << ":" << HGCalWaferType::getPartial(index, hgpar_->waferInfoMap_) << ":" << HGCalWaferType::getOrient(index, hgpar_->waferInfoMap_) << ":" << HGCalWaferType::getCassette(index, hgpar_->waferInfoMap_); + if (debug) + edm::LogVerbatim("HGCalGeom") << "Position (" << x << ", " << y << ") Wafer type:partial:orient:cassette " + << celltype << ":" << HGCalWaferType::getPartial(index, hgpar_->waferInfoMap_) + << ":" << HGCalWaferType::getOrient(index, hgpar_->waferInfoMap_) << ":" + << HGCalWaferType::getCassette(index, hgpar_->waferInfoMap_); #endif } else { auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer, waferU, waferV)); diff --git a/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc b/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc index eceb924ff4185..86812d02b6a04 100644 --- a/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc +++ b/RecoLocalCalo/HGCalRecAlgos/test/HGCalToolTesterPartialWafer.cc @@ -38,7 +38,7 @@ class HGCalToolTesterPartialWafer : public edm::one::EDAnalyzer(geo_.getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty)) : static_cast(geo_.getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty)); + geom_ = (nameSense_ == "HGCalEESensitive") ? static_cast(geo_.getSubdetectorGeometry( + DetId::HGCalEE, ForwardSubdetector::ForwardEmpty)) + : static_cast(geo_.getSubdetectorGeometry( + DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty)); edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: beginRun Called for " << nameSense_; } @@ -87,7 +90,8 @@ void HGCalToolTesterPartialWafer::analyze(const edm::Event& e, const edm::EventS bool getHits = (hitsCalo.isValid()); uint32_t nhits = (getHits) ? hitsCalo->size() : 0; uint32_t good(0), allSi(0), all(0); - edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: Input flags Hits " << getHits << " with " << nhits << " hits"; + edm::LogVerbatim("HGCalSim") << "HGCalToolTesterPartialWafer: Input flags Hits " << getHits << " with " << nhits + << " hits"; if (getHits) { std::vector hits; @@ -108,8 +112,9 @@ void HGCalToolTesterPartialWafer::analyze(const edm::Event& e, const edm::EventS GlobalPoint pos2 = tool_.getPosition(id); edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id) << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":" - << info.orient << ":" << info.cassette << " at (" << pos1.x() << ", " << pos1.y() - << ", " << pos1.z() << ") or (" < Date: Mon, 18 Jul 2022 02:53:22 +0200 Subject: [PATCH 3/3] Revert the debug flag to false in HGCalNumberingScheme --- SimG4CMS/Calo/src/HGCalNumberingScheme.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4CMS/Calo/src/HGCalNumberingScheme.cc b/SimG4CMS/Calo/src/HGCalNumberingScheme.cc index 72d9fdd7ab67b..a0bcd2f4d22eb 100644 --- a/SimG4CMS/Calo/src/HGCalNumberingScheme.cc +++ b/SimG4CMS/Calo/src/HGCalNumberingScheme.cc @@ -51,7 +51,7 @@ uint32_t HGCalNumberingScheme::getUnitID(int layer, int module, int cell, int iz cellV = HGCalTypes::getUnpackedCellV(cell); } else if (mode_ != HGCalGeometryMode::Hexagon8) { double xx = (pos.z() > 0) ? pos.x() : -pos.x(); - hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt, false, true); + hgcons_.waferFromPosition(xx, pos.y(), layer, waferU, waferV, cellU, cellV, waferType, wt, false, false); } if (waferType >= 0) { if (hgcons_.waferHexagon8File()) {