Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 11_3_0] Stage 2 TC Distribution and Sorting #497

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ typedef HGCalAlgoWrapperBaseT<std::vector<edm::Ptr<l1t::HGCalTowerMap>>,
std::pair<const edm::EventSetup&, const edm::ParameterSet&>>
HGCalTowerMapsWrapperBase;

typedef HGCalAlgoWrapperBaseT<l1t::HGCalMulticlusterBxCollection,
l1t::HGCalMulticlusterBxCollection,
std::pair<const edm::EventSetup&, const edm::ParameterSet&>>
HGCalStage2FilteringWrapperBase;

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory<HGCalHistoClusteringWrapperBase*(const edm::ParameterSet&)>
HGCalHistoClusteringWrapperBaseFactory;
typedef edmplugin::PluginFactory<HGCalTowerMapsWrapperBase*(const edm::ParameterSet&)> HGCalTowerMapsWrapperBaseFactory;

typedef edmplugin::PluginFactory<HGCalStage2FilteringWrapperBase*(const edm::ParameterSet&)>
HGCalStage2FilteringWrapperBaseFactory;
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __L1Trigger_L1THGCal_HGCalSortingTruncationConfig_SA_h__
#define __L1Trigger_L1THGCal_HGCalSortingTruncationConfig_SA_h__

namespace l1thgcfirmware {

class SortingTruncationAlgoConfig {
public:
SortingTruncationAlgoConfig(const unsigned maxTCs) : maxTCs_(maxTCs){};

void setParameters(unsigned maxTCs) { maxTCs_ = maxTCs; };

void setParameters(const SortingTruncationAlgoConfig& newConfig) { setParameters(newConfig.maxTCs()); }

unsigned maxTCs() const { return maxTCs_; }

private:
unsigned maxTCs_;
};

} // namespace l1thgcfirmware

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __L1Trigger_L1THGCal_HGCalSortingTruncationImplSA_h__
#define __L1Trigger_L1THGCal_HGCalSortingTruncationImplSA_h__

#include "L1Trigger/L1THGCal/interface/backend/HGCalMulticluster_SA.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalSortingTruncationConfig_SA.h"

#include <vector>
#include <algorithm>

class HGCalSortingTruncationImplSA {
public:
HGCalSortingTruncationImplSA();
~HGCalSortingTruncationImplSA() {}

void sortAndTruncate_SA(const std::vector<l1thgcfirmware::HGCalMulticluster>& inputMulticlusters,
std::vector<l1thgcfirmware::HGCalMulticluster>& outputMulticlusters,
const l1thgcfirmware::SortingTruncationAlgoConfig& configuration) const;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef __L1Trigger_L1THGCal_HGCalStage2ClusterDistribution_h__
#define __L1Trigger_L1THGCal_HGCalStage2ClusterDistribution_h__

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"

#include "DataFormats/L1THGCal/interface/HGCalCluster.h"
#include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h"

class HGCalStage2ClusterDistribution {
public:
HGCalStage2ClusterDistribution(const edm::ParameterSet& conf);

HGCalTriggerGeometryBase::geom_set getStage2FPGAs(const unsigned stage1_fpga,
const HGCalTriggerGeometryBase::geom_set& stage2_fpgas,
const edm::Ptr<l1t::HGCalCluster>& tc_ptr) const;
unsigned phiBin(unsigned roverzbin, double phi) const;
double rotatedphi(double x, double y, double z, int sector) const;

private:
double roz_min_ = 0.;
double roz_max_ = 0.;
unsigned roz_bins_ = 42;
std::vector<double> phi_edges_;
double roz_bin_size_ = 0.;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "L1Trigger/L1THGCal/interface/backend/HGCalHistoSeedingImpl.h"
#include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalTriggerClusterInterpreterBase.h"
#include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalStage2ClusterDistribution.h"

#include <utility>

Expand All @@ -19,9 +21,17 @@ class HGCalBackendLayer2Processor3DClusteringSA : public HGCalBackendLayer2Proce

const edm::ParameterSet& clusteringParamConfig =
conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_clustering_parameters");
const edm::ParameterSet& sortingTruncationParamConfig =
conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_sorting_truncation_parameters");
const std::string& clusteringAlgoWrapperName = clusteringParamConfig.getParameter<std::string>("AlgoName");
const std::string& sortingTruncationAlgoWrapperName =
sortingTruncationParamConfig.getParameter<std::string>("AlgoName");

multiclusteringHistoClusteringWrapper_ = std::unique_ptr<HGCalHistoClusteringWrapperBase>{
HGCalHistoClusteringWrapperBaseFactory::get()->create(clusteringAlgoWrapperName, clusteringParamConfig)};
multiclusteringSortingTruncationWrapper_ =
std::unique_ptr<HGCalStage2FilteringWrapperBase>{HGCalStage2FilteringWrapperBaseFactory::get()->create(
sortingTruncationAlgoWrapperName, sortingTruncationParamConfig)};

for (const auto& interpretationPset : conf.getParameter<std::vector<edm::ParameterSet>>("energy_interpretations")) {
std::unique_ptr<HGCalTriggerClusterInterpreterBase> interpreter{
Expand All @@ -37,39 +47,69 @@ class HGCalBackendLayer2Processor3DClusteringSA : public HGCalBackendLayer2Proce
es.get<CaloGeometryRecord>().get("", triggerGeometry_);
if (multiclusteringHistoSeeding_)
multiclusteringHistoSeeding_->eventSetup(es);
l1t::HGCalMulticlusterBxCollection& collCluster3D = be_output.first;
l1t::HGCalMulticlusterBxCollection& collCluster3D_sorted = be_output.first;
l1t::HGCalClusterBxCollection& rejectedClusters = be_output.second;

/* create a persistent vector of pointers to the trigger-cells */
std::vector<edm::Ptr<l1t::HGCalCluster>> clustersPtrs;
std::unordered_map<uint32_t, std::vector<edm::Ptr<l1t::HGCalCluster>>> tcs_per_fpga;

for (unsigned i = 0; i < collHandle->size(); ++i) {
edm::Ptr<l1t::HGCalCluster> ptr(collHandle, i);
clustersPtrs.push_back(ptr);
}
edm::Ptr<l1t::HGCalCluster> tc_ptr(collHandle, i);
uint32_t module = geometry_->getModuleFromTriggerCell(tc_ptr->detId());
uint32_t stage1_fpga = geometry_->getStage1FpgaFromModule(module);
HGCalTriggerGeometryBase::geom_set possible_stage2_fpgas = geometry_->getStage2FpgasFromStage1Fpga(stage1_fpga);

HGCalStage2ClusterDistribution distributor(conf_.getParameterSet("DistributionParameters"));

/* create a vector of seed positions and their energy*/
std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
HGCalTriggerGeometryBase::geom_set stage2_fpgas =
distributor.getStage2FPGAs(stage1_fpga, possible_stage2_fpgas, tc_ptr);

/* call to multiclustering and compute shower shape*/
multiclusteringHistoSeeding_->findHistoSeeds(clustersPtrs, seedPositionsEnergy);
for (auto& fpga : stage2_fpgas) {
tcs_per_fpga[fpga].push_back(tc_ptr);
}
}

// Inputs
std::pair<const std::vector<edm::Ptr<l1t::HGCalCluster>>&, const std::vector<std::pair<GlobalPoint, double>>&>
inputClustersAndSeeds{clustersPtrs, seedPositionsEnergy};
// Outputs
std::pair<l1t::HGCalMulticlusterBxCollection&, l1t::HGCalClusterBxCollection&>
outputMulticlustersAndRejectedClusters{collCluster3D, rejectedClusters};
// Configuration
const std::pair<const edm::EventSetup&, const edm::ParameterSet&> configuration{es, conf_};

// Configure and process
multiclusteringHistoClusteringWrapper_->configure(configuration);
multiclusteringHistoClusteringWrapper_->process(inputClustersAndSeeds, outputMulticlustersAndRejectedClusters);

// Call all the energy interpretation modules on the cluster collection
for (const auto& interpreter : energy_interpreters_) {
interpreter->eventSetup(es);
interpreter->interpret(collCluster3D);
multiclusteringSortingTruncationWrapper_->configure(configuration);

for (auto& fpga_tcs : tcs_per_fpga) {
/* create a vector of seed positions and their energy*/
std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;

/* call to multiclustering and compute shower shape*/
multiclusteringHistoSeeding_->findHistoSeeds(fpga_tcs.second, seedPositionsEnergy);

// Inputs
std::pair<const std::vector<edm::Ptr<l1t::HGCalCluster>>&, const std::vector<std::pair<GlobalPoint, double>>&>
inputClustersAndSeeds{fpga_tcs.second, seedPositionsEnergy};
// Outputs
l1t::HGCalMulticlusterBxCollection collCluster3D_perFPGA;
l1t::HGCalMulticlusterBxCollection collCluster3D_perFPGA_sorted;
l1t::HGCalClusterBxCollection rejectedClusters_perFPGA;

std::pair<l1t::HGCalMulticlusterBxCollection&, l1t::HGCalClusterBxCollection&>
outputMulticlustersAndRejectedClusters_perFPGA{collCluster3D_perFPGA, rejectedClusters_perFPGA};

// Process
multiclusteringHistoClusteringWrapper_->process(inputClustersAndSeeds,
outputMulticlustersAndRejectedClusters_perFPGA);

multiclusteringSortingTruncationWrapper_->process(collCluster3D_perFPGA, collCluster3D_perFPGA_sorted);

// Call all the energy interpretation modules on the cluster collection
for (const auto& interpreter : energy_interpreters_) {
interpreter->eventSetup(es);
interpreter->interpret(collCluster3D_perFPGA_sorted);
}

for (const auto& collcluster : collCluster3D_perFPGA_sorted) {
collCluster3D_sorted.push_back(0, collcluster);
}
for (const auto& rejectedcluster : rejectedClusters_perFPGA) {
rejectedClusters.push_back(0, rejectedcluster);
}
}
}

Expand All @@ -81,6 +121,8 @@ class HGCalBackendLayer2Processor3DClusteringSA : public HGCalBackendLayer2Proce

std::unique_ptr<HGCalHistoClusteringWrapperBase> multiclusteringHistoClusteringWrapper_;

std::unique_ptr<HGCalStage2FilteringWrapperBase> multiclusteringSortingTruncationWrapper_;

std::vector<std::unique_ptr<HGCalTriggerClusterInterpreterBase>> energy_interpreters_;

const edm::ParameterSet conf_;
Expand Down
110 changes: 110 additions & 0 deletions L1Trigger/L1THGCal/plugins/backend/HGCalSortingTruncationWrapper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalSortingTruncationImpl_SA.h"

#include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
#include "L1Trigger/L1THGCal/interface/backend/HGCalMulticluster_SA.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
#include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"

class HGCalSortingTruncationWrapper : public HGCalStage2FilteringWrapperBase {
public:
HGCalSortingTruncationWrapper(const edm::ParameterSet& conf);
~HGCalSortingTruncationWrapper() override {}

void configure(const std::pair<const edm::EventSetup&, const edm::ParameterSet&>& configuration) override;

void process(const l1t::HGCalMulticlusterBxCollection&, l1t::HGCalMulticlusterBxCollection&) const override;

private:
void convertCMSSWInputs(const l1t::HGCalMulticlusterBxCollection& multiclusters,
l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_SA) const;
void convertAlgorithmOutputs(const l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_out,
const l1t::HGCalMulticlusterBxCollection& multiclusters_original,
l1t::HGCalMulticlusterBxCollection& multiclustersBXCollection) const;

void eventSetup(const edm::EventSetup& es) { triggerTools_.eventSetup(es); }

HGCalTriggerTools triggerTools_;
HGCalSortingTruncationImplSA theAlgo_;
l1thgcfirmware::SortingTruncationAlgoConfig theConfiguration_;
};

HGCalSortingTruncationWrapper::HGCalSortingTruncationWrapper(const edm::ParameterSet& conf)
: HGCalStage2FilteringWrapperBase(conf), theAlgo_(), theConfiguration_(conf.getParameter<unsigned>("maxTCs")) {}

void HGCalSortingTruncationWrapper::convertCMSSWInputs(
const l1t::HGCalMulticlusterBxCollection& multiclusters,
l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_SA) const {
multiclusters_SA.reserve(multiclusters.size());

for (unsigned int imulticluster = 0; imulticluster < multiclusters.size(); ++imulticluster) {
bool firstConstituent = true;
for (const auto& constituent : multiclusters[imulticluster].constituents()) {
if (firstConstituent) {
multiclusters_SA.emplace_back(l1thgcfirmware::HGCalMulticluster(
l1thgcfirmware::HGCalCluster(constituent.second->centreProj().x(),
constituent.second->centreProj().y(),
constituent.second->centreProj().z(),
triggerTools_.zside(constituent.second->detId()),
triggerTools_.layerWithOffset(constituent.second->detId()),
constituent.second->eta(),
constituent.second->phi(),
constituent.second->pt(),
constituent.second->mipPt(),
imulticluster),
1.));

} else {
multiclusters_SA.at(imulticluster)
.addConstituent(l1thgcfirmware::HGCalCluster(constituent.second->centreProj().x(),
constituent.second->centreProj().y(),
constituent.second->centreProj().z(),
triggerTools_.zside(constituent.second->detId()),
triggerTools_.layerWithOffset(constituent.second->detId()),
constituent.second->eta(),
constituent.second->phi(),
constituent.second->pt(),
constituent.second->mipPt(),
imulticluster),
1.);
}
firstConstituent = false;
}
}
}

void HGCalSortingTruncationWrapper::convertAlgorithmOutputs(
const std::vector<l1thgcfirmware::HGCalMulticluster>& multiclusters_out,
const l1t::HGCalMulticlusterBxCollection& multiclusters_original,
l1t::HGCalMulticlusterBxCollection& multiclustersBXCollection) const {
for (unsigned int imulticluster = 0; imulticluster < multiclusters_out.size(); ++imulticluster) {
unsigned multicluster_id = multiclusters_out[imulticluster].constituents().at(0).index_cmssw();
multiclustersBXCollection.push_back(0, multiclusters_original[multicluster_id]);
}
}

void HGCalSortingTruncationWrapper::process(const l1t::HGCalMulticlusterBxCollection& inputMulticlusters,
l1t::HGCalMulticlusterBxCollection& outputMulticlusters) const {
l1thgcfirmware::HGCalMulticlusterSACollection multiclusters_SA;
convertCMSSWInputs(inputMulticlusters, multiclusters_SA);

l1thgcfirmware::HGCalMulticlusterSACollection multiclusters_finalized_SA;

theAlgo_.sortAndTruncate_SA(multiclusters_SA, multiclusters_finalized_SA, theConfiguration_);

convertAlgorithmOutputs(multiclusters_finalized_SA, inputMulticlusters, outputMulticlusters);
}

void HGCalSortingTruncationWrapper::configure(
const std::pair<const edm::EventSetup&, const edm::ParameterSet&>& configuration) {
eventSetup(configuration.first);
};

DEFINE_EDM_PLUGIN(HGCalStage2FilteringWrapperBaseFactory,
HGCalSortingTruncationWrapper,
"HGCalSortingTruncationWrapper");
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ unsigned HGCalTriggerGeometryV9Imp3::getStage2FpgaFromStage1Link(const unsigned
HGCalTriggerGeometryBase::geom_set HGCalTriggerGeometryV9Imp3::getStage1LinksFromStage1Fpga(
const unsigned stage1_id) const {
geom_set stage1link_ids;

HGCalTriggerBackendDetId id(stage1_id);

auto stage1_itrs = stage1_to_stage1links_.equal_range(id.label());
Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/L1THGCal/python/customNewProcessors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FWCore.ParameterSet.Config as cms
from L1Trigger.L1THGCal.hgcalBackEndLayer1Producer_cfi import stage1truncation_proc

from L1Trigger.L1THGCal.hgcalBackEndLayer1Producer_cfi import truncation_params

def custom_stage1_truncation(process):
parameters = stage1truncation_proc.clone()
Expand All @@ -11,6 +11,7 @@ def custom_stage1_truncation(process):

def custom_clustering_standalone(process):
process.hgcalBackEndLayer2Producer.ProcessorParameters.ProcessorName = cms.string('HGCalBackendLayer2Processor3DClusteringSA')
process.hgcalBackEndLayer2Producer.ProcessorParameters.DistributionParameters = truncation_params
return process

def custom_tower_standalone(process):
Expand Down
7 changes: 5 additions & 2 deletions L1Trigger/L1THGCal/python/hgcalBackEndLayer2Producer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
BH_DR_GROUP = 12
MAX_LAYERS = 52


dr_layerbylayer = ([0] + # no layer 0
[0.015]*EE_DR_GROUP + [0.020]*EE_DR_GROUP + [0.030]*EE_DR_GROUP + [0.040]*EE_DR_GROUP + # EM
[0.040]*FH_DR_GROUP + [0.050]*FH_DR_GROUP + # FH
Expand Down Expand Up @@ -57,7 +56,6 @@
1., 1., 1., 1., 1.,
)


distance_C3d_params = cms.PSet(type_multicluster=cms.string('dRC3d'),
dR_multicluster=cms.double(0.01),
minPt_multicluster=cms.double(0.5), # minimum pt of the multicluster (GeV)
Expand Down Expand Up @@ -101,6 +99,10 @@
)


histoMax_C3d_sorting_truncation_params = cms.PSet(AlgoName = cms.string('HGCalSortingTruncationWrapper'),
maxTCs=cms.uint32(80),
)

# >= V9 samples have a different definition of the dEdx calibrations. To account for it
# we rescale the thresholds of the clustering seeds
# (see https://indico.cern.ch/event/806845/contributions/3359859/attachments/1815187/2966402/19-03-20_EGPerf_HGCBE.pdf
Expand Down Expand Up @@ -142,6 +144,7 @@
type_multicluster=cms.string('Histo'),
histoMax_C3d_clustering_parameters = histoMaxVariableDR_C3d_params.clone(),
histoMax_C3d_seeding_parameters = histoMax_C3d_seeding_params.clone(),
histoMax_C3d_sorting_truncation_parameters = histoMax_C3d_sorting_truncation_params.clone(),
)


Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/L1THGCal/src/HGCalAlgoWrapperBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

EDM_REGISTER_PLUGINFACTORY(HGCalHistoClusteringWrapperBaseFactory, "HGCalHistoClusteringWrapperBaseFactory");

EDM_REGISTER_PLUGINFACTORY(HGCalTowerMapsWrapperBaseFactory, "HGCalTowerMapsWrapperBaseFactory");
EDM_REGISTER_PLUGINFACTORY(HGCalTowerMapsWrapperBaseFactory, "HGCalTowerMapsWrapperBaseFactory");

EDM_REGISTER_PLUGINFACTORY(HGCalStage2FilteringWrapperBaseFactory, "HGCalStage2FilteringWrapperBaseFactory");