59 static std::unique_ptr<ONNXRuntime> initializeGlobalCache(
const edm::ParameterSet &iConfig);
63 void printTrackstersDebug(
const std::vector<Trackster> &,
const char *
label)
const;
64 void dumpTrackster(
const Trackster &)
const;
65 void energyRegressionAndID(
const std::vector<reco::CaloCluster> &
layerClusters,
66 const tensorflow::Session *,
67 std::vector<Trackster> &
result)
const;
107 regressionAndPid_(ps.getParameter<
bool>(
"regressionAndPid")),
108 tfDnnLabel_(ps.getParameter<
std::
string>(
"tfDnnLabel")),
111 eidInputName_(ps.getParameter<
std::
string>(
"eid_input_name")),
112 eidOutputNameEnergy_(ps.getParameter<
std::
string>(
"eid_output_name_energy")),
113 eidOutputNameId_(ps.getParameter<
std::
string>(
"eid_output_name_id")),
114 eidMinClusterEnergy_(ps.getParameter<double>(
"eid_min_cluster_energy")),
115 eidNLayers_(ps.getParameter<
int>(
"eid_n_layers")),
116 eidNClusters_(ps.getParameter<
int>(
"eid_n_clusters")),
117 eidSession_(nullptr),
119 detector_(ps.getParameter<
std::
string>(
"detector")),
120 propName_(ps.getParameter<
std::
string>(
"propagator")),
125 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"tracksters_collections")) {
129 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"original_masks")) {
134 produces<std::vector<Trackster>>();
137 produces<std::vector<std::vector<unsigned int>>>();
138 produces<std::vector<std::vector<unsigned int>>>(
"linkedTracksterIdToInputTracksterId");
140 produces<std::vector<float>>();
145 std::string detectorName_ = (
detector_ ==
"HFNose") ?
"HGCalHFNoseSensitive" :
"HGCalEESensitive";
146 hdc_token_ = esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
155 if (pluginPset.exists(
"onnxModelPath"))
158 return std::unique_ptr<ONNXRuntime>(
nullptr);
179 auto e_over_h = (
t.raw_em_pt() / ((
t.raw_pt() -
t.raw_em_pt()) != 0. ? (
t.raw_pt() -
t.raw_em_pt()) : 1.));
181 <<
"\nTrackster raw_pt: " <<
t.raw_pt() <<
" raw_em_pt: " <<
t.raw_em_pt() <<
" eoh: " << e_over_h
182 <<
" barycenter: " <<
t.barycenter() <<
" eta,phi (baricenter): " <<
t.barycenter().eta() <<
", " 183 <<
t.barycenter().phi() <<
" eta,phi (eigen): " <<
t.eigenvectors(0).eta() <<
", " <<
t.eigenvectors(0).phi()
184 <<
" pt(eigen): " <<
std::sqrt(
t.eigenvectors(0).Unit().perp2()) *
t.raw_energy() <<
" seedID: " <<
t.seedID()
185 <<
" seedIndex: " <<
t.seedIndex() <<
" size: " <<
t.vertices().size() <<
" average usage: " 186 << (std::accumulate(std::begin(
t.vertex_multiplicity()), std::end(
t.vertex_multiplicity()), 0.) /
187 (
float)
t.vertex_multiplicity().size())
188 <<
" raw_energy: " <<
t.raw_energy() <<
" regressed energy: " <<
t.regressed_energy()
189 <<
" probs(ga/e/mu/np/cp/nh/am/unk): ";
190 for (
auto const &
p :
t.id_probabilities()) {
193 LogDebug(
"TracksterLinksProducer") <<
" sigmas: ";
194 for (
auto const &
s :
t.sigmas()) {
195 LogDebug(
"TracksterLinksProducer") <<
s <<
" ";
197 LogDebug(
"TracksterLinksProducer") << std::endl;
201 const tensorflow::Session *eidSession,
202 std::vector<Trackster> &tracksters)
const {
230 for (
auto &
t : tracksters) {
231 t.setRegressedEnergy(0.
f);
232 t.zeroProbabilities();
237 tensorflow::Tensor
input(tensorflow::DT_FLOAT,
shape);
241 std::vector<tensorflow::Tensor>
outputs;
258 std::vector<int> clusterIndices(trackster.
vertices().size());
260 clusterIndices[
k] =
k;
262 sort(clusterIndices.begin(), clusterIndices.end(), [&
layerClusters, &trackster](
const int &
a,
const int &
b) {
270 for (
const int &
k : clusterIndices) {
308 float regressedEnergy =
310 tracksters[
i].setRegressedEnergy(regressedEnergy);
318 float *probs =
outputs[probsIdx].flat<
float>().
data();
319 int probsNumber = tracksters[0].id_probabilities().size();
321 tracksters[
i].setProbabilities(&probs[
i * probsNumber]);
329 auto resultTracksters = std::make_unique<std::vector<Trackster>>();
331 auto linkedResultTracksters = std::make_unique<std::vector<std::vector<unsigned int>>>();
339 std::vector<float> original_global_mask(
layerClusters.size(), 1.f);
342 for (
unsigned int j = 0;
j < tmp_mask.size(); ++
j) {
343 original_global_mask[
j] *= tmp_mask[
j];
347 auto resultMask = std::make_unique<std::vector<float>>(original_global_mask);
349 std::vector<edm::Handle<std::vector<Trackster>>> tracksters_h(
tracksters_tokens_.size());
354 trackstersManager.addVector(*tracksters_h[
i]);
359 auto linkedTracksterIdToInputTracksterId = std::make_unique<std::vector<std::vector<unsigned int>>>();
366 linkingAlgo_->linkTracksters(
input, *resultTracksters, *linkedResultTracksters, *linkedTracksterIdToInputTracksterId);
371 for (
auto const &resultTrackster : *resultTracksters) {
372 for (
auto const &clusterIndex : resultTrackster.vertices()) {
373 (*resultMask)[clusterIndex] = 0.f;
390 evt.
put(
std::move(linkedTracksterIdToInputTracksterId),
"linkedTracksterIdToInputTracksterId");
395 LogDebug(
"TracksterLinksProducer").log([&](
auto &
log) {
396 for (
auto const &
t : tracksters) {
397 log <<
counter++ <<
" TracksterLinksProducer (" <<
label <<
") obj barycenter: " <<
t.barycenter()
398 <<
" eta,phi (baricenter): " <<
t.barycenter().eta() <<
", " <<
t.barycenter().phi()
399 <<
" eta,phi (eigen): " <<
t.eigenvectors(0).eta() <<
", " <<
t.eigenvectors(0).phi()
400 <<
" pt(eigen): " <<
std::sqrt(
t.eigenvectors(0).Unit().perp2()) *
t.raw_energy() <<
" seedID: " <<
t.seedID()
401 <<
" seedIndex: " <<
t.seedIndex() <<
" size: " <<
t.vertices().size() <<
" average usage: " 402 << (std::accumulate(std::begin(
t.vertex_multiplicity()), std::end(
t.vertex_multiplicity()), 0.) /
403 (
float)
t.vertex_multiplicity().size())
404 <<
" raw_energy: " <<
t.raw_energy() <<
" regressed energy: " <<
t.regressed_energy()
405 <<
" probs(ga/e/mu/np/cp/nh/am/unk): ";
406 for (
auto const &
p :
t.id_probabilities()) {
410 for (
auto const &
s :
t.sigmas()) {
424 desc.add<std::vector<edm::InputTag>>(
"tracksters_collections", {
edm::InputTag(
"ticlTrackstersCLUE3DHigh")});
425 desc.add<std::vector<edm::InputTag>>(
"original_masks",
426 {
edm::InputTag(
"hgcalMergeLayerClusters",
"InitialLayerClustersMask")});
429 desc.add<
bool>(
"regressionAndPid",
false);
432 desc.add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
433 desc.add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
434 desc.add<
double>(
"eid_min_cluster_energy", 2.5);
435 desc.add<
int>(
"eid_n_layers", 50);
436 desc.add<
int>(
"eid_n_clusters", 10);
439 descriptions.
add(
"tracksterLinksProducer",
desc);
const HGCalDDDConstants * hgcons_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string tfDnnLabel_
std::vector< NamedTensor > NamedTensorList
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
const bool regressionAndPid_
void produce(edm::Event &, const edm::EventSetup &) override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
bool get(ProductID const &oid, Handle< PROD > &result) const
tensorflow::Session * eidSession_
std::string fullPath() const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfield_token_
std::vector< edm::EDGetTokenT< std::vector< float > > > original_masks_tokens_
const std::string eidOutputNameEnergy_
static void globalEndJob(const ONNXRuntime *)
TracksterLinksProducer(const edm::ParameterSet &ps, const ONNXRuntime *)
hgcal::RecHitTools rhtools_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void assignPCAtoTracksters(std::vector< Trackster > &tracksters, const std::vector< reco::CaloCluster > &layerClusters, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, bool computeLocalTime=false, bool energyWeight=true, bool clean=false, int minLayer=10, int maxLayer=10)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::unique_ptr< TracksterLinkingAlgoBase > linkingAlgo_
double phi() const
azimuthal angle of cluster centroid
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
static constexpr int eidNFeatures_
static std::string const input
T const * product() const
const tensorflow::Session * tfSession_
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
static std::unique_ptr< ONNXRuntime > initializeGlobalCache(const edm::ParameterSet &iConfig)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const std::string eidInputName_
double energy() const
cluster energy
void printTrackstersDebug(const std::vector< Trackster > &, const char *label) const
std::vector< unsigned int > & vertices()
const std::string propName_
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< float > & vertex_multiplicity()
std::vector< edm::EDGetTokenT< std::vector< Trackster > > > tracksters_tokens_
~TracksterLinksProducer() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void dumpTrackster(const Trackster &) const
char data[epos_bytes_allocation]
const float eidMinClusterEnergy_
edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > hdc_token_
double eta() const
pseudorapidity of cluster centroid
const edm::ESGetToken< TfGraphDefWrapper, TfGraphRecord > tfDnnToken_
const std::string eidOutputNameId_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagator_token_
void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
const std::string detector_