diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py index d89b5ea6233a4..8c31bd697fac1 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py @@ -5,12 +5,12 @@ detector = cms.string('HGCAL'), layer_clusters = cms.InputTag("hltHgcalMergeLayerClustersL1Seeded"), layer_clustersTime = cms.InputTag("hltHgcalMergeLayerClustersL1Seeded","timeLayerCluster"), - inferenceAlgo = cms.string('TracksterInferenceByDNN'), + inferenceAlgo = cms.string('TracksterInferenceByPFN'), linkingPSet = hltTiclTracksterLinksPSet, pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -21,6 +21,20 @@ doRegression = cms.int32(1), type = cms.string('TracksterInferenceByDNN') ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(1), + doRegression = cms.int32(1), + type = cms.string('TracksterInferenceByPFN') + ), mightGet = cms.optional.untracked.vstring, original_masks = cms.VInputTag("hltHgcalMergeLayerClustersL1Seeded:InitialLayerClustersMask"), propagator = cms.string('PropagatorWithMaterial'), diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py index ec40871157f21..0a42611690106 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py @@ -5,12 +5,12 @@ detector = cms.string('HGCAL'), layer_clusters = cms.InputTag("hltHgcalMergeLayerClusters"), layer_clustersTime = cms.InputTag("hltHgcalMergeLayerClusters","timeLayerCluster"), - inferenceAlgo = cms.string('TracksterInferenceByDNN'), + inferenceAlgo = cms.string('TracksterInferenceByPFN'), linkingPSet = hltTiclTracksterLinksPSet, pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -21,6 +21,20 @@ doRegression = cms.int32(1), type = cms.string('TracksterInferenceByDNN') ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(1), + doRegression = cms.int32(1), + type = cms.string('TracksterInferenceByPFN') + ), mightGet = cms.optional.untracked.vstring, original_masks = cms.VInputTag("hltHgcalMergeLayerClusters:InitialLayerClustersMask"), propagator = cms.string('PropagatorWithMaterial'), diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py index d80ca3f071ed7..d7bcb3f1426b2 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py @@ -120,8 +120,8 @@ ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -131,7 +131,20 @@ doRegression = cms.int32(0), type = cms.string('TracksterInferenceByDNN') ), - pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(1), + doRegression = cms.int32(0), + type = cms.string('TracksterInferenceByPFN') + ), + pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( algo_verbosity = cms.int32(0), type = cms.string('TracksterInferenceByANN') @@ -142,5 +155,5 @@ from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 ticl_v5.toModify(hltTiclTrackstersCLUE3DHighL1Seeded.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) -ticl_v5.toModify(hltTiclTrackstersCLUE3DHighL1Seeded.inferenceAlgo, type = cms.string('TracksterInferenceByDNN')) +ticl_v5.toModify(hltTiclTrackstersCLUE3DHighL1Seeded.inferenceAlgo, type = cms.string('TracksterInferenceByPFN')) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py index ee7df1e8e3edf..680ec07359db0 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py @@ -121,8 +121,8 @@ ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -132,6 +132,19 @@ doRegression = cms.int32(0), type = cms.string('TracksterInferenceByDNN') ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(1), + doRegression = cms.int32(0), + type = cms.string('TracksterInferenceByPFN') + ), pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( algo_verbosity = cms.int32(0), type = cms.string('TracksterInferenceByANN') @@ -143,4 +156,4 @@ from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 ticl_v5.toModify(hltTiclTrackstersCLUE3DHigh.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) -ticl_v5.toModify(hltTiclTrackstersCLUE3DHigh.inferenceAlgo, type = cms.string('TracksterInferenceByDNN')) +ticl_v5.toModify(hltTiclTrackstersCLUE3DHigh.inferenceAlgo, type = cms.string('TracksterInferenceByPFN')) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py index 43146ea1580bc..94a54c6f5ccb3 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py @@ -10,7 +10,7 @@ mightGet = cms.optional.untracked.vstring, original_mask = cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded"), patternRecognitionBy = cms.string('Recovery'), - inferenceAlgo = cms.string('TracksterInferenceByDNN'), + inferenceAlgo = cms.string('TracksterInferenceByPFN'), pluginPatternRecognitionByCA = cms.PSet( algo_verbosity = cms.int32(0), computeLocalTime = cms.bool(True), @@ -71,8 +71,8 @@ pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -83,6 +83,20 @@ doRegression = cms.int32(0), type = cms.string('TracksterInferenceByDNN') ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(0), + doRegression = cms.int32(0), + type = cms.string('TracksterInferenceByPFN') + ), pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( algo_verbosity = cms.int32(0), type = cms.string('TracksterInferenceByANN') diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py index 2c2facfdff316..c5e9c8ae32f24 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py @@ -10,7 +10,7 @@ mightGet = cms.optional.untracked.vstring, original_mask = cms.InputTag("hltTiclTrackstersCLUE3DHigh"), patternRecognitionBy = cms.string('Recovery'), - inferenceAlgo = cms.string('TracksterInferenceByDNN'), + inferenceAlgo = cms.string('TracksterInferenceByPFN'), pluginPatternRecognitionByCA = cms.PSet( algo_verbosity = cms.int32(0), computeLocalTime = cms.bool(True), @@ -71,8 +71,8 @@ pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -83,6 +83,20 @@ doRegression = cms.int32(0), type = cms.string('TracksterInferenceByDNN') ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(0), + doRegression = cms.int32(0), + type = cms.string('TracksterInferenceByPFN') + ), pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( algo_verbosity = cms.int32(0), type = cms.string('TracksterInferenceByANN') diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h b/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h new file mode 100644 index 0000000000000..93b8a8d2e7314 --- /dev/null +++ b/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h @@ -0,0 +1,41 @@ +#ifndef RecoHGCal_TICL_TracksterInferenceByPFN_H__ +#define RecoHGCal_TICL_TracksterInferenceByPFN_H__ + +#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" +#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" + +namespace ticl { + + class TracksterInferenceByPFN : public TracksterInferenceAlgoBase { + public: + explicit TracksterInferenceByPFN(const edm::ParameterSet& conf); + void inputData(const std::vector& layerClusters, std::vector& tracksters) override; + void runInference(std::vector& tracksters) override; + + static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + + private: + const cms::Ort::ONNXRuntime* onnxPIDSession_; + const cms::Ort::ONNXRuntime* onnxEnergySession_; + + const std::string id_modelPath_; + const std::string en_modelPath_; + const std::vector inputNames_; + const std::vector output_en_; + const std::vector output_id_; + const float eidMinClusterEnergy_; + const int eidNLayers_; + const int eidNClusters_; + static constexpr int eidNFeatures_ = 7; + int doPID_; + int doRegression_; + + hgcal::RecHitTools rhtools_; + std::vector> input_shapes_; + std::vector tracksterIndices_; + std::vector> input_Data_; + int batchSize_; + }; +} // namespace ticl + +#endif // RecoHGCal_TICL_TracksterInferenceByPFN_H__ diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc b/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc index b3580ab956cb4..72959412d3728 100644 --- a/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc +++ b/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc @@ -1,4 +1,5 @@ #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" +#include "RecoHGCal/TICL/interface/TracksterInferenceByPFN.h" #include "RecoHGCal/TICL/interface/TracksterInferenceByDNN.h" #include "RecoHGCal/TICL/interface/TracksterInferenceByANN.h" #include "RecoHGCal/TICL/interface/TracksterInferenceByCNNv4.h" @@ -6,6 +7,7 @@ #include "FWCore/ParameterSet/interface/ValidatedPluginMacros.h" EDM_REGISTER_VALIDATED_PLUGINFACTORY(TracksterInferenceAlgoFactory, "TracksterInferenceAlgoFactory"); +DEFINE_EDM_VALIDATED_PLUGIN(TracksterInferenceAlgoFactory, ticl::TracksterInferenceByPFN, "TracksterInferenceByPFN"); DEFINE_EDM_VALIDATED_PLUGIN(TracksterInferenceAlgoFactory, ticl::TracksterInferenceByDNN, "TracksterInferenceByDNN"); DEFINE_EDM_VALIDATED_PLUGIN(TracksterInferenceAlgoFactory, ticl::TracksterInferenceByANN, "TracksterInferenceByANN"); DEFINE_EDM_VALIDATED_PLUGIN(TracksterInferenceAlgoFactory, diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc index d9195f2811685..f72b9a8ab1a8c 100644 --- a/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc +++ b/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc @@ -128,13 +128,14 @@ namespace ticl { void TracksterInferenceByDNN::fillPSetDescription(edm::ParameterSetDescription& iDesc) { iDesc.add("algo_verbosity", 0); iDesc - .add("onnxPIDModelPath", - edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx")) + .add( + "onnxPIDModelPath", + edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx")) ->setComment("Path to ONNX PID model CLU3D"); iDesc .add( "onnxEnergyModelPath", - edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx")) + edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx")) ->setComment("Path to ONNX Energy model CLU3D"); iDesc.add>("inputNames", {"input"}); iDesc.add>("output_en", {"enreg_output"}); diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc new file mode 100644 index 0000000000000..bfe15fff37dcc --- /dev/null +++ b/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc @@ -0,0 +1,163 @@ +#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" +#include "RecoHGCal/TICL/interface/TracksterInferenceByPFN.h" +#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" +#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" +#include "TrackstersPCA.h" + +namespace ticl { + using namespace cms::Ort; // Use ONNXRuntime namespace + + // Constructor for TracksterInferenceByPFN + TracksterInferenceByPFN::TracksterInferenceByPFN(const edm::ParameterSet& conf) + : TracksterInferenceAlgoBase(conf), + id_modelPath_( + conf.getParameter("onnxPIDModelPath").fullPath()), // Path to the PID model CLU3D + en_modelPath_( + conf.getParameter("onnxEnergyModelPath").fullPath()), // Path to the Energy model CLU3D + inputNames_(conf.getParameter>("inputNames")), // Define input names for inference + output_en_(conf.getParameter>("output_en")), // Define output energy for inference + output_id_(conf.getParameter>("output_id")), // Define output PID for inference + eidMinClusterEnergy_(conf.getParameter("eid_min_cluster_energy")), // Minimum cluster energy + eidNLayers_(conf.getParameter("eid_n_layers")), // Number of layers + eidNClusters_(conf.getParameter("eid_n_clusters")), // Number of clusters + doPID_(conf.getParameter("doPID")), // Number of clusters + doRegression_(conf.getParameter("doRegression")) // Number of clusters + { + // Initialize ONNX Runtime sessions for PID and Energy models + static std::unique_ptr onnxPIDRuntimeInstance = + std::make_unique(id_modelPath_.c_str()); + onnxPIDSession_ = onnxPIDRuntimeInstance.get(); + static std::unique_ptr onnxEnergyRuntimeInstance = + std::make_unique(en_modelPath_.c_str()); + onnxEnergySession_ = onnxEnergyRuntimeInstance.get(); + } + + // Method to process input data and prepare it for inference + void TracksterInferenceByPFN::inputData(const std::vector& layerClusters, + std::vector& tracksters) { + tracksterIndices_.clear(); // Clear previous indices + for (int i = 0; i < static_cast(tracksters.size()); i++) { + float sumClusterEnergy = 0.; + for (const unsigned int& vertex : tracksters[i].vertices()) { + sumClusterEnergy += static_cast(layerClusters[vertex].energy()); + if (sumClusterEnergy >= eidMinClusterEnergy_) { + tracksters[i].setRegressedEnergy(0.f); // Set regressed energy to 0 + tracksters[i].zeroProbabilities(); // Zero out probabilities + tracksterIndices_.push_back(i); // Add index to the list + break; + } + } + } + + // Prepare input shapes and data for inference + batchSize_ = static_cast(tracksterIndices_.size()); + if (batchSize_ == 0) + return; // Exit if no tracksters + + std::vector inputShape_lc = {batchSize_, eidNLayers_, eidNClusters_, eidNFeatures_}; + std::vector inputShape_tr = {batchSize_, eidNFeatures_}; + input_shapes_ = {inputShape_lc, inputShape_tr}; + + input_Data_.clear(); + input_Data_.emplace_back(batchSize_ * eidNLayers_ * eidNClusters_ * eidNFeatures_, 0); + input_Data_.emplace_back(batchSize_ * eidNFeatures_, 0); + + for (int i = 0; i < batchSize_; i++) { + const Trackster& trackster = tracksters[tracksterIndices_[i]]; + auto index_tr = i * eidNFeatures_; + input_Data_[1][index_tr] = static_cast(trackster.raw_energy()); + input_Data_[1][index_tr + 1] = static_cast(trackster.raw_em_energy()); + input_Data_[1][index_tr + 2] = static_cast(trackster.barycenter().x()); + input_Data_[1][index_tr + 3] = static_cast(trackster.barycenter().y()); + input_Data_[1][index_tr + 4] = static_cast(std::abs(trackster.barycenter().z())); + input_Data_[1][index_tr + 5] = static_cast(std::abs(trackster.barycenter().eta())); + input_Data_[1][index_tr + 6] = static_cast(trackster.barycenter().phi()); + + // Prepare indices and sort clusters based on energy + std::vector clusterIndices(trackster.vertices().size()); + for (int k = 0; k < static_cast(trackster.vertices().size()); k++) { + clusterIndices[k] = k; + } + + std::sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &trackster](const int& a, const int& b) { + return layerClusters[trackster.vertices(a)].energy() > layerClusters[trackster.vertices(b)].energy(); + }); + + std::vector seenClusters(eidNLayers_, 0); + + // Fill input data with cluster information + for (const int& k : clusterIndices) { + const reco::CaloCluster& cluster = layerClusters[trackster.vertices(k)]; + int j = rhtools_.getLayerWithOffset(cluster.hitsAndFractions()[0].first) - 1; + if (j < eidNLayers_ && seenClusters[j] < eidNClusters_) { + auto index_lc = (i * eidNLayers_ + j) * eidNFeatures_ * eidNClusters_ + seenClusters[j] * eidNFeatures_; + // Adding more features regarding LC, such as E, eta, phi, x, y, z, and nhits. + input_Data_[0][index_lc] = + static_cast(cluster.energy() / static_cast(trackster.vertex_multiplicity(k))); + input_Data_[0][index_lc + 1] = static_cast(std::abs(cluster.eta())); + input_Data_[0][index_lc + 2] = static_cast(cluster.phi()); + input_Data_[0][index_lc + 3] = static_cast(cluster.x()); + input_Data_[0][index_lc + 4] = static_cast(cluster.y()); + input_Data_[0][index_lc + 5] = static_cast(std::abs(cluster.z())); + input_Data_[0][index_lc + 6] = static_cast(cluster.hitsAndFractions().size()); + seenClusters[j]++; + } + } + } + } + + // Method to run inference and update tracksters + void TracksterInferenceByPFN::runInference(std::vector& tracksters) { + if (batchSize_ == 0) + return; // Exit if no batch + + if (doPID_ and doRegression_) { + // Run energy model inference + auto result = onnxEnergySession_->run(inputNames_, input_Data_, input_shapes_, output_en_, batchSize_); + auto& energyOutputTensor = result[0]; + if (!output_en_.empty()) { + for (int i = 0; i < static_cast(batchSize_); i++) { + const float energy = energyOutputTensor[i]; + tracksters[tracksterIndices_[i]].setRegressedEnergy(energy); // Update energy + } + } + } + if (doPID_) { + // Run PID model inference + auto pidOutput = onnxPIDSession_->run(inputNames_, input_Data_, input_shapes_, output_id_, batchSize_); + auto pidOutputTensor = pidOutput[0]; + float* probs = pidOutputTensor.data(); + if (!output_id_.empty()) { + for (int i = 0; i < batchSize_; i++) { + tracksters[tracksterIndices_[i]].setProbabilities(probs); // Update probabilities + probs += tracksters[tracksterIndices_[i]].id_probabilities().size(); // Move to next set of probabilities + } + } + } + } + // Method to fill parameter set description for configuration + void TracksterInferenceByPFN::fillPSetDescription(edm::ParameterSetDescription& iDesc) { + iDesc.add("algo_verbosity", 0); + iDesc + .add( + "onnxPIDModelPath", + edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx")) + ->setComment("Path to ONNX PID model CLU3D"); + iDesc + .add( + "onnxEnergyModelPath", + edm::FileInPath("RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx")) + ->setComment("Path to ONNX Energy model CLU3D"); + iDesc.add>("inputNames", {"input", "input_tr_features"}); + iDesc.add>("output_en", {"enreg_output"}); + iDesc.add>("output_id", {"pid_output"}); + iDesc.add("eid_min_cluster_energy", 1.0); + iDesc.add("eid_n_layers", 50); + iDesc.add("eid_n_clusters", 10); + iDesc.add("doPID", 1); + iDesc.add("doRegression", 1); + } +} // namespace ticl diff --git a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc index 4901d0de3bc65..b15f5d74d89d6 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc @@ -230,13 +230,6 @@ void TracksterLinksProducer::produce(edm::Event &evt, const edm::EventSetup &es) } } - if (regressionAndPid_) { - // Run inference algorithm - inferenceAlgo_->inputData(layerClusters, *resultTracksters); - inferenceAlgo_->runInference( - *resultTracksters); //option to use "Linking" instead of "CLU3D"/"energyAndPid" instead of "PID" - } - assignPCAtoTracksters(*resultTracksters, layerClusters, layerClustersTimes, @@ -244,6 +237,13 @@ void TracksterLinksProducer::produce(edm::Event &evt, const edm::EventSetup &es) rhtools_, true); + if (regressionAndPid_) { + // Run inference algorithm + inferenceAlgo_->inputData(layerClusters, *resultTracksters); + inferenceAlgo_->runInference( + *resultTracksters); //option to use "Linking" instead of "CLU3D"/"energyAndPid" instead of "PID" + } + evt.put(std::move(linkedResultTracksters)); evt.put(std::move(resultMask)); evt.put(std::move(resultTracksters)); @@ -284,6 +284,11 @@ void TracksterLinksProducer::fillDescriptions(edm::ConfigurationDescriptions &de inferenceDesc.addNode(edm::PluginDescription("type", "TracksterInferenceByDNN", true)); desc.add("pluginInferenceAlgoTracksterInferenceByDNN", inferenceDesc); + edm::ParameterSetDescription inferenceDescPFN; + inferenceDescPFN.addNode( + edm::PluginDescription("type", "TracksterInferenceByPFN", true)); + desc.add("pluginInferenceAlgoTracksterInferenceByPFN", inferenceDescPFN); + edm::ParameterSetDescription inferenceDescCNNv4; inferenceDescCNNv4.addNode( edm::PluginDescription("type", "TracksterInferenceByCNNv4", true)); @@ -298,7 +303,7 @@ void TracksterLinksProducer::fillDescriptions(edm::ConfigurationDescriptions &de desc.add("regressionAndPid", false); desc.add("detector", "HGCAL"); desc.add("propagator", "PropagatorWithMaterial"); - desc.add("inferenceAlgo", "TracksterInferenceByDNN"); + desc.add("inferenceAlgo", "TracksterInferenceByPFN"); descriptions.add("tracksterLinksProducer", desc); } diff --git a/RecoHGCal/TICL/plugins/TrackstersProducer.cc b/RecoHGCal/TICL/plugins/TrackstersProducer.cc index d6dd656bc591a..558f36e33e83c 100644 --- a/RecoHGCal/TICL/plugins/TrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/TrackstersProducer.cc @@ -119,7 +119,7 @@ void TrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descri desc.add("seeding_regions", edm::InputTag("ticlSeedingRegionProducer")); desc.add("patternRecognitionBy", "CA"); desc.add("itername", "unknown"); - desc.add("inferenceAlgo", "TracksterInferenceByDNN"); + desc.add("inferenceAlgo", "TracksterInferenceByPFN"); // CA Plugin edm::ParameterSetDescription pluginDesc; @@ -146,6 +146,11 @@ void TrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descri inferenceDesc.addNode(edm::PluginDescription("type", "TracksterInferenceByDNN", true)); desc.add("pluginInferenceAlgoTracksterInferenceByDNN", inferenceDesc); + edm::ParameterSetDescription inferenceDescPFN; + inferenceDescPFN.addNode( + edm::PluginDescription("type", "TracksterInferenceByPFN", true)); + desc.add("pluginInferenceAlgoTracksterInferenceByPFN", inferenceDescPFN); + edm::ParameterSetDescription inferenceDescANN; inferenceDescANN.addNode( edm::PluginDescription("type", "TracksterInferenceByANN", true)); diff --git a/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py b/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py index 0bf9daaf436a1..a26760e106eb2 100644 --- a/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py +++ b/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py @@ -42,8 +42,8 @@ ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -54,6 +54,22 @@ doRegression = cms.int32(0), type = cms.string('TracksterInferenceByDNN') ), + + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_layers = cms.int32(50), + eid_n_clusters = cms.int32(10), + doPID = cms.int32(1), + doRegression = cms.int32(0), + type = cms.string('TracksterInferenceByPFN') + ), + pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( algo_verbosity = cms.int32(0), type = cms.string('TracksterInferenceByANN') @@ -66,7 +82,7 @@ from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 ticl_v5.toModify(ticlTrackstersCLUE3DHigh.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) ticl_v5.toModify(ticlTrackstersCLUE3DHigh.pluginPatternRecognitionByCLUE3D, usePCACleaning = cms.bool(True)) -ticl_v5.toModify(ticlTrackstersCLUE3DHigh.inferenceAlgo, type = cms.string('TracksterInferenceByDNN')) +ticl_v5.toModify(ticlTrackstersCLUE3DHigh.inferenceAlgo, type = cms.string('TracksterInferenceByPFN')) ticlCLUE3DHighStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersCLUE3DHigh diff --git a/RecoHGCal/TICL/python/iterativeTICL_cff.py b/RecoHGCal/TICL/python/iterativeTICL_cff.py index baec9c294c6c1..fceb6915f4b59 100644 --- a/RecoHGCal/TICL/python/iterativeTICL_cff.py +++ b/RecoHGCal/TICL/python/iterativeTICL_cff.py @@ -85,7 +85,7 @@ ), regressionAndPid = cms.bool(True), - inferenceAlgo = cms.string('TracksterInferenceByDNN'), + inferenceAlgo = cms.string('TracksterInferenceByPFN'), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), doPID = cms.int32(1), @@ -96,9 +96,23 @@ eid_min_cluster_energy = cms.double(1), eid_n_clusters = cms.int32(10), eid_n_layers = cms.int32(50), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/energy_v0.onnx'), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/id_v0.onnx'), type = cms.string('TracksterInferenceByDNN') + ), + pluginInferenceAlgoTracksterInferenceByPFN = cms.PSet( + algo_verbosity = cms.int32(0), + doPID = cms.int32(1), + doRegression = cms.int32(1), + inputNames = cms.vstring('input','input_tr_features'), + output_en = cms.vstring('enreg_output'), + output_id = cms.vstring('pid_output'), + eid_min_cluster_energy = cms.double(1), + eid_n_clusters = cms.int32(10), + eid_n_layers = cms.int32(50), + onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v0.onnx'), + onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/id_v0.onnx'), + type = cms.string('TracksterInferenceByPFN') ) ) ticlCandidate = _ticlCandidateProducer.clone()