59 "linkedTracksterIdToInputTracksterId",
63 superclusterEtThreshold_(ps.getParameter<double>(
"superclusterEtThreshold")),
64 enableRegression_(ps.getParameter<
bool>(
"enableRegression")) {
65 produces<reco::SuperClusterCollection>();
66 produces<reco::CaloClusterCollection>();
73 auto const& emTracksters = *emTracksters_h;
76 auto egammaSuperclusters = std::make_unique<reco::SuperClusterCollection>();
77 auto caloClustersEM = std::make_unique<reco::CaloClusterCollection>();
81 std::vector<std::pair<DetId, float>> hitsAndFractions;
83 std::for_each(std::begin(emTrackster.vertices()), std::end(emTrackster.vertices()), [&](
unsigned int lcId) {
84 const auto fraction = 1.f / emTrackster.vertex_multiplicity(iLC++);
85 for (
const auto& cell :
layerClusters[lcId].hitsAndFractions()) {
86 hitsAndFractions.emplace_back(cell.first, cell.second *
fraction);
91 emTrackster.raw_energy(),
96 hitsAndFractions.at(0)
105 assert(ticlSuperclusters.size() == ticlSuperclusterLinks.size());
106 const unsigned int regressionFeatureCount = 8;
107 std::vector<float> regressionInputs;
108 regressionInputs.reserve(ticlSuperclusters.size() * regressionFeatureCount);
109 unsigned int superclustersPassingSelectionsCount = 0;
110 for (std::size_t sc_i = 0; sc_i < ticlSuperclusters.size(); sc_i++) {
114 std::vector<unsigned int>
const& superclusterLink = ticlSuperclusterLinks[sc_i];
115 assert(!superclusterLink.empty());
122 for (
unsigned int tsInSc_id : superclusterLink) {
130 egammaSuperclusters->emplace_back(
134 superclusterLink[0]),
135 trackstersEMInSupercluster,
140 superclustersPassingSelectionsCount++;
143 regressionInputs.insert(
144 regressionInputs.end(),
149 max_phi - min_phi >
M_PI ? 2 *
static_cast<float>(
M_PI) - (max_phi - min_phi) : max_phi - min_phi,
150 emTracksters[superclusterLink[0]].raw_energy() -
151 (superclusterLink.size() >= 2 ? emTracksters[superclusterLink.back()].raw_energy() : 0.f),
152 emTracksters[superclusterLink[0]].raw_energy() / ticlSupercluster.
raw_energy(),
153 static_cast<float>(superclusterLink.size())});
160 std::vector<std::vector<float>> inputs_for_onnx{{
std::move(regressionInputs)}};
162 globalCache()->run({
"input"}, inputs_for_onnx, {}, {}, superclustersPassingSelectionsCount)[0];
165 for (std::size_t sc_i = 0; sc_i < egammaSuperclusters->size(); sc_i++) {
166 (*egammaSuperclusters)[sc_i].setCorrectedEnergy(
outputs[sc_i]);
178 return std::unique_ptr<ONNXRuntime>(
nullptr);
187 ->setComment(
"The trackster collection used before superclustering, ie CLUE3D EM tracksters");
189 ->setComment(
"The layer cluster collection that goes with ticlTrackstersEM");
190 desc.add<
double>(
"superclusterEtThreshold", 4.)->setComment(
"Minimum supercluster transverse energy.");
191 desc.add<
bool>(
"enableRegression",
true)->setComment(
"Enable supercluster energy regression");
193 edm::FileInPath(
"RecoHGCal/TICL/data/superclustering/regression_v1.onnx"))
194 ->setComment(
"Path to regression network (as ONNX model)");
196 descriptions.
add(
"ticlEGammaSuperClusterProducer",
desc);
T getParameter(std::string const &) const
const float raw_pt() const
const Vector & barycenter() const
edm::EDGetTokenT< ticl::TracksterCollection > ticlSuperClustersToken_
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::CaloClusterCollection > layerClustersToken_
void setCorrectedEnergy(double cenergy)
const float raw_energy() const
edm::EDGetTokenT< ticl::TracksterCollection > ticlTrackstersEMToken_
Abs< T >::type abs(const T &t)
static std::unique_ptr< ONNXRuntime > initializeGlobalCache(const edm::ParameterSet &iConfig)
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
#define DEFINE_FWK_MODULE(type)
XYZPointD XYZPoint
point in space with cartesian internal representation
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< Trackster > TracksterCollection
float superclusterEtThreshold_
edm::EDGetTokenT< std::vector< std::vector< unsigned int > > > superClusterLinksToken_
EGammaSuperclusterProducer(const edm::ParameterSet &, const ONNXRuntime *)
static void globalEndJob(const ONNXRuntime *)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)