27 using namespace particleFlowRecHitProducer;
29 template <
typename CAL>
33 :
ESProducer(iConfig), cutsFromDB_(iConfig.getParameter<
bool>(
"usePFThresholdsFromDB")) {
34 auto cc = setWhatProduced(
this);
35 geomToken_ =
cc.consumes();
36 if constexpr (std::is_same_v<CAL, HCAL>) {
37 hcalToken_ =
cc.consumes();
38 hcalCutsToken_ =
cc.consumes();
45 desc.add<
bool>(
"usePFThresholdsFromDB",
true);
47 desc.add<
bool>(
"usePFThresholdsFromDB",
false);
51 std::unique_ptr<typename CAL::TopologyTypeHost>
produce(
const typename CAL::TopologyRecordType& iRecord) {
52 const auto&
geom = iRecord.get(geomToken_);
54 auto view = product->view();
55 const int calEnums[2] = {CAL::kSubdetectorBarrelId, CAL::kSubdetectorEndcapId};
56 for (
const auto subdet : calEnums) {
62 std::variant<EcalBarrelTopology, EcalEndcapTopology> topoVar;
64 topo = &iRecord.get(hcalToken_);
71 for (
auto const detId :
geom.getValidDetIds(CAL::kDetectorId, subdet)) {
72 const uint32_t denseId = CAL::detId2denseId(
detId);
73 assert(denseId < CAL::kSize);
76 if constexpr (std::is_same_v<CAL, HCAL>) {
77 view.cutsFromDB() =
false;
79 view.cutsFromDB() =
true;
80 const HcalPFCuts& pfCuts = iRecord.get(hcalCutsToken_);
82 std::unique_ptr<HcalPFCuts>
prod = std::make_unique<HcalPFCuts>(pfCuts);
83 prod->setTopo(&htopo);
85 view.seedThreshold(denseId) =
prod->getValues(
detId.rawId())->seedThreshold();
90 view.positionX(denseId) =
pos.x();
91 view.positionY(denseId) =
pos.y();
92 view.positionZ(denseId) =
pos.z();
94 for (uint32_t
n = 0;
n < 8;
n++) {
95 uint32_t neighDetId = getNeighbourDetId(
detId,
n, *topo);
96 if (CAL::detIdInRange(neighDetId))
97 view.neighbours(denseId)(
n) = CAL::detId2denseId(neighDetId);
99 view.neighbours(denseId)(
n) = 0xffffffff;
105 if constexpr (std::is_same_v<CAL, HCAL>) {
106 for (
const auto subdet : calEnums)
107 for (
auto const detId :
geom.getValidDetIds(CAL::kDetectorId, subdet)) {
108 const uint32_t denseId = CAL::detId2denseId(
detId);
109 for (uint32_t
n = 0;
n < 8;
n++) {
110 if (
view.neighbours(denseId)[
n] == 0xffffffff)
113 view.neighbours(
view.neighbours(denseId)[
n]);
114 if (
std::find(neighboursOfNeighbour.begin(), neighboursOfNeighbour.end(), denseId) ==
115 neighboursOfNeighbour.end())
116 view.neighbours(denseId)[
n] = 0xffffffff;
122 LogDebug(
"PFRecHitTopologyESProducer").log([&](
auto&
log) {
123 for (
const auto subdet : calEnums)
124 for (
const auto detId :
geom.getValidDetIds(CAL::kDetectorId, subdet)) {
125 const uint32_t denseId = CAL::detId2denseId(
detId);
126 log.format(
"detId:{} denseId:{} pos:{},{},{} neighbours:{},{},{},{};{},{},{},{}\n",
129 view[denseId].positionX(),
130 view[denseId].positionY(),
131 view[denseId].positionZ(),
132 view[denseId].neighbours()(0),
133 view[denseId].neighbours()(1),
134 view[denseId].neighbours()(2),
135 view[denseId].neighbours()(3),
136 view[denseId].neighbours()(4),
137 view[denseId].neighbours()(5),
138 view[denseId].neighbours()(6),
139 view[denseId].neighbours()(7));
158 const uint32_t direction,
173 if (direction == 4) {
174 const uint32_t NE = getNeighbourDetId(getNeighbourDetId(
detId, 0, topo), 2, topo);
177 return getNeighbourDetId(getNeighbourDetId(
detId, 2, topo), 0, topo);
179 if (direction == 5) {
180 const uint32_t SW = getNeighbourDetId(getNeighbourDetId(
detId, 1, topo), 3, topo);
183 return getNeighbourDetId(getNeighbourDetId(
detId, 3, topo), 1, topo);
185 if (direction == 6) {
186 const uint32_t ES = getNeighbourDetId(getNeighbourDetId(
detId, 2, topo), 1, topo);
189 return getNeighbourDetId(getNeighbourDetId(
detId, 1, topo), 2, topo);
191 if (direction == 7) {
192 const uint32_t WN = getNeighbourDetId(getNeighbourDetId(
detId, 3, topo), 0, topo);
195 return getNeighbourDetId(getNeighbourDetId(
detId, 0, topo), 3, topo);
202 const uint32_t direction,
218 if (direction == 4) {
223 }
else if (direction == 5) {
228 }
else if (direction == 6) {
233 }
else if (direction == 7) {
241 const uint32_t nn2 = getNeighbourDetId(
detId,
directions.second, topo);
242 const uint32_t nnn = getNeighbourDetId(nn1,
directions.second, topo);
243 if (nnn == nn1 || nnn == nn2)
virtual DetId goNorth(const DetId &id) const
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
uint32_t cc[maxCellsPerHit]
PFRecHitTopologyESProducer< ECAL > PFRecHitECALTopologyESProducer
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual DetId goSouth(const DetId &id) const
std::unique_ptr< typename CAL::TopologyTypeHost > produce(const typename CAL::TopologyRecordType &iRecord)
Eigen::Matrix< uint32_t, 8, 1 > PFRecHitsTopologyNeighbours
static constexpr int getZside(uint32_t detId)
PFRecHitTopologyESProducer(edm::ParameterSet const &iConfig)
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > hcalToken_
virtual DetId goEast(const DetId &id) const
PFRecHitTopologyESProducer< HCAL > PFRecHitHCALTopologyESProducer
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
uint32_t getNeighbourDetId(const uint32_t detId, const uint32_t direction, const CaloSubdetectorTopology &topo)
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
#define DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(type)
virtual DetId goWest(const DetId &id) const
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_