diff --git a/Configuration/EventContent/python/EventContent_cff.py b/Configuration/EventContent/python/EventContent_cff.py index 3660d17f802d8..2eeaf23d92291 100644 --- a/Configuration/EventContent/python/EventContent_cff.py +++ b/Configuration/EventContent/python/EventContent_cff.py @@ -591,8 +591,6 @@ def SwapKeepAndDrop(l): outputCommands = FEVTEventContent.outputCommands + RecoLocalFastTimeFEVT.outputCommands) phase2_timing_layer.toModify(FEVTEventContent, outputCommands = FEVTEventContent.outputCommands + RecoMTDFEVT.outputCommands) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(FEVTEventContent, outputCommands=FEVTEventContent.outputCommands+TICLv5_FEVT.outputCommands) FEVTHLTALLEventContent = cms.PSet( outputCommands = cms.untracked.vstring('drop *'), @@ -680,7 +678,6 @@ def SwapKeepAndDrop(l): outputCommands = [x for x in FEVTDEBUGEventContent.outputCommands if '_hltSiStripClusters2ApproxClusters_' not in x] + [ 'keep *_hltSiStripClusters2ApproxClustersv1_*_*' ]) -ticl_v5.toModify(FEVTDEBUGEventContent, outputCommands=FEVTDEBUGEventContent.outputCommands+TICLv5_FEVT.outputCommands) # # # FEVTDEBUGHLT Data Tier definition @@ -754,7 +751,6 @@ def SwapKeepAndDrop(l): phase2_hgcal.toModify(FEVTDEBUGHLTEventContent, outputCommands = FEVTDEBUGHLTEventContent.outputCommands + TICL_FEVTHLT.outputCommands) -ticl_v5.toModify(FEVTDEBUGHLTEventContent, outputCommands=FEVTDEBUGHLTEventContent.outputCommands+TICLv5_FEVTHLT.outputCommands) from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 diff --git a/Configuration/ProcessModifiers/python/clue3D_cff.py b/Configuration/ProcessModifiers/python/clue3D_cff.py deleted file mode 100644 index 4530d01791d4f..0000000000000 --- a/Configuration/ProcessModifiers/python/clue3D_cff.py +++ /dev/null @@ -1,5 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -# This modifier is for injecting CLUE3D-based iterations in TICL. - -clue3D = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/enableCPfromPU_cff.py b/Configuration/ProcessModifiers/python/enableCPfromPU_cff.py deleted file mode 100644 index b9e00007d5a1c..0000000000000 --- a/Configuration/ProcessModifiers/python/enableCPfromPU_cff.py +++ /dev/null @@ -1,4 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -# This modifier enables the CaloParticles from pileup in the HGCAL associators and simulated objects. -enableCPfromPU = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/fastJetTICL_cff.py b/Configuration/ProcessModifiers/python/fastJetTICL_cff.py deleted file mode 100644 index 977b584061ae1..0000000000000 --- a/Configuration/ProcessModifiers/python/fastJetTICL_cff.py +++ /dev/null @@ -1,5 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -# This modifier is for injecting CLUE3D-based iterations in TICL. - -fastJetTICL = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/simTrackstersFromPU_cff.py b/Configuration/ProcessModifiers/python/simTrackstersFromPU_cff.py new file mode 100644 index 0000000000000..117c3b2c41fb1 --- /dev/null +++ b/Configuration/ProcessModifiers/python/simTrackstersFromPU_cff.py @@ -0,0 +1,4 @@ +import FWCore.ParameterSet.Config as cms + +# This modifier enables the SimTracksters from CaloParticles from pileup in the HGCAL associators and simulated objects. +simTrackstersFromPU = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/ticl_dev.py b/Configuration/ProcessModifiers/python/ticl_dev.py new file mode 100644 index 0000000000000..3a7bd4b7dfdae --- /dev/null +++ b/Configuration/ProcessModifiers/python/ticl_dev.py @@ -0,0 +1,5 @@ +import FWCore.ParameterSet.Config as cms + +# This modifier is for running the development version of TICL. + +ticl_dev = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/ticl_superclustering_dnn_cff.py b/Configuration/ProcessModifiers/python/ticl_superclustering_dnn_cff.py deleted file mode 100644 index 40cd46626a8b3..0000000000000 --- a/Configuration/ProcessModifiers/python/ticl_superclustering_dnn_cff.py +++ /dev/null @@ -1,10 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -from Configuration.ProcessModifiers.ticl_superclustering_mustache_pf_cff import ticl_superclustering_mustache_pf -from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl - -# Modifier to run superclustering with DNN -# It is not to be used directly in a Process since it is currently the default for ticl_v5 -# It only exists as convenience in configuration files -ticl_superclustering_dnn = ticl_v5 & (~ticl_superclustering_mustache_pf) & (~ticl_superclustering_mustache_ticl) diff --git a/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_pf_cff.py b/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_pf_cff.py index 3487edbac62a9..1e5028ac23f3a 100644 --- a/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_pf_cff.py +++ b/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_pf_cff.py @@ -1,4 +1,4 @@ import FWCore.ParameterSet.Config as cms -# Modifier (to be applied on top of ticl_v5 modifier) to use the pre-TICLv5 superclustering code (that translates tracksters to PFClusters before running Mustache) +# Modifier to use the pre-TICLv5 superclustering code (that translates tracksters to PFClusters before running Mustache) ticl_superclustering_mustache_pf = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_ticl_cff.py b/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_ticl_cff.py index 8b2755f583007..0115c8f31ebc2 100644 --- a/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_ticl_cff.py +++ b/Configuration/ProcessModifiers/python/ticl_superclustering_mustache_ticl_cff.py @@ -1,4 +1,4 @@ import FWCore.ParameterSet.Config as cms -# Modifier (to be applied on top of ticl_v5 modifier) to run superclustering using Mustache inside TICL (with tracksters as inputs) +# Modifier to run superclustering using Mustache inside TICL (with tracksters as inputs) ticl_superclustering_mustache_ticl = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/ticl_v5_cff.py b/Configuration/ProcessModifiers/python/ticl_v5_cff.py deleted file mode 100644 index 1bb678b4451ac..0000000000000 --- a/Configuration/ProcessModifiers/python/ticl_v5_cff.py +++ /dev/null @@ -1,5 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -# This modifier is for running TICL v5. - -ticl_v5 = cms.Modifier() diff --git a/Configuration/ProcessModifiers/python/ticlv5_TrackLinkingGNN_cff.py b/Configuration/ProcessModifiers/python/ticlv5_TrackLinkingGNN_cff.py index d387226097369..d4c48ca39c0d2 100644 --- a/Configuration/ProcessModifiers/python/ticlv5_TrackLinkingGNN_cff.py +++ b/Configuration/ProcessModifiers/python/ticlv5_TrackLinkingGNN_cff.py @@ -1,7 +1,4 @@ import FWCore.ParameterSet.Config as cms -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 - # This modifier is for running TICL v5 with GNN track-trackster linking. -ticl_v5_TrackLinkingGNN = cms.Modifier() -ticlv5_TrackLinkingGNN = cms.ModifierChain(ticl_v5, ticl_v5_TrackLinkingGNN) +ticlv5_TrackLinkingGNN = cms.Modifier() diff --git a/Configuration/PyReleaseValidation/README.md b/Configuration/PyReleaseValidation/README.md index 04f5abe43f6ba..6fb02684ec4ac 100644 --- a/Configuration/PyReleaseValidation/README.md +++ b/Configuration/PyReleaseValidation/README.md @@ -59,8 +59,7 @@ The offsets currently in use are: * 0.7502: HLT phase-2 menu, with tracking ntuple * 0.7503: HLT phase-2 menu, CPU vs. GPU validation * 0.751: HLT phase-2 timing menu Alpaka variant -* 0.752: HLT phase-2 timing menu ticl_v5 variant -* 0.7521: HLT phase-2 timing menu ticl_v5, ticlv5TrackLinkingGNN variant +* 0.7521: HLT phase-2 timing menu ticlv5TrackLinkingGNN variant * 0.753: HLT phase-2 timing menu legacy tracking * 0.754: HLT phase-2 timing menu legacy tracking with Patatrack quads * 0.755: HLT phase-2 timing menu LST building variant @@ -70,7 +69,7 @@ The offsets currently in use are: * 0.759: HLT phase-2 timing menu, with NANO:@Phase2HLT * 0.76: HLT phase-2 reduced menu, with DIGI step * 0.77: HLT phase-2 NGT Scouting menu -* 0.771: HLT phase-2 NGT Scouting menu, Alpaka, TICL-v5, TICL-Barrel +* 0.771: HLT phase-2 NGT Scouting menu, Alpaka, TICL-Barrel * 0.772: HLT phase-2 NGT Scouting menu, with NANO:@NGTScouting * 0.773: HLT phase-2 NGT Scouting menu, with NANO:@NGTScoutingVal * 0.775: HLT phase-2 NGT Scouting menu with Pixeltracks CA Extension + LST T5s as GeneralTracks @@ -111,11 +110,8 @@ The offsets currently in use are: * 0.914: DDD DB * 0.101: Phase-2 aging, 1000fb-1 * 0.103: Phase-2 aging, 3000fb-1 -* 0.201: HGCAL special TICL Pattern recognition Workflows: clue3D -* 0.202: HGCAL special TICL Pattern recognition Workflows: FastJet -* 0.203: HGCAL TICLv5 -* 0.204: HGCAL superclustering : using Mustache in TICLv5 -* 0.205: HGCAL superclustering : using old PFCluster-based Mustache algorithm with TICLv5 +* 0.204: HGCAL superclustering : using Mustache in TICL +* 0.205: HGCAL superclustering : using old PFCluster-based Mustache algorithm with TICL * 0.209: TICL barrel : run TICL in HGCAL and barrel calorimeters * 0.2091: TICL barrel with CaloParticles from PU enabled * 0.302: FastSim Run-3 trackingOnly validation diff --git a/Configuration/PyReleaseValidation/python/relval_Run4.py b/Configuration/PyReleaseValidation/python/relval_Run4.py index d650cf1d1533f..b54075b897127 100644 --- a/Configuration/PyReleaseValidation/python/relval_Run4.py +++ b/Configuration/PyReleaseValidation/python/relval_Run4.py @@ -62,8 +62,7 @@ numWFIB.extend([prefixDet+34.7502]) # HLTTrackingNtuple75e33 numWFIB.extend([prefixDet+34.7503]) # HLTHeterogeneousValid numWFIB.extend([prefixDet+34.751]) # HLTTiming75e33, alpaka -numWFIB.extend([prefixDet+34.752]) # HLTTiming75e33, ticl_v5 -numWFIB.extend([prefixDet+34.7521]) # HLTTiming75e33, ticl_v5, ticlv5TrackLinkingGNN +numWFIB.extend([prefixDet+34.7521]) # HLTTiming75e33, ticlv5TrackLinkingGNN numWFIB.extend([prefixDet+34.753]) # HLTTiming75e33, legacy tracking numWFIB.extend([prefixDet+34.754]) # HLTTiming75e33, legacy tracking with Patatrack quads numWFIB.extend([prefixDet+34.755]) # HLTTiming75e33, trackingLST @@ -72,7 +71,7 @@ numWFIB.extend([prefixDet+34.758]) # HLTTiming75e33, ticl_barrel numWFIB.extend([prefixDet+34.759]) # HLTTiming75e33 + NANO numWFIB.extend([prefixDet+34.77]) # NGTScouting -numWFIB.extend([prefixDet+34.771]) # NGTScouting + alpaka + TICL-v5 + TICL-Barrel +numWFIB.extend([prefixDet+34.771]) # NGTScouting + alpaka + TICL-Barrel numWFIB.extend([prefixDet+34.772]) # NGTScouting + NANO numWFIB.extend([prefixDet+34.773]) # NGTScouting + NANO (including validation) numWFIB.extend([prefixDet+34.775]) # NGTScouting + Phase2CAExtension&LSTT5 as GeneralTracks diff --git a/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py b/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py index ba76d044bb352..7eb04462c3ca5 100644 --- a/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py +++ b/Configuration/PyReleaseValidation/python/upgradeWorkflowComponents.py @@ -798,88 +798,8 @@ def condition(self, fragment, stepList, key, hasHarvest): '-s': 'HARVESTING:@trackingOnlyValidation+@pixelTrackingOnlyDQM' } -# Special TICL Pattern recognition Workflows -class UpgradeWorkflow_ticl_clue3D(UpgradeWorkflow): - def setup_(self, step, stepName, stepDict, k, properties): - if 'RecoGlobal' in step: - stepDict[stepName][k] = merge([self.step3, stepDict[step][k]]) - if 'HARVESTGlobal' in step: - stepDict[stepName][k] = merge([self.step4, stepDict[step][k]]) - def condition(self, fragment, stepList, key, hasHarvest): - return (fragment=="TTbar_14TeV" or 'CloseByPGun_CE' in fragment) and 'Run4' in key -upgradeWFs['ticl_clue3D'] = UpgradeWorkflow_ticl_clue3D( - steps = [ - 'RecoGlobal', - 'RecoGlobalFakeHLT', - 'HARVESTGlobal' - ], - PU = [ - 'RecoGlobal', - 'RecoGlobalFakeHLT', - 'HARVESTGlobal' - ], - suffix = '_ticl_clue3D', - offset = 0.201, -) -upgradeWFs['ticl_clue3D'].step3 = {'--procModifiers': 'clue3D'} -upgradeWFs['ticl_clue3D'].step4 = {'--procModifiers': 'clue3D'} -class UpgradeWorkflow_ticl_FastJet(UpgradeWorkflow): - def setup_(self, step, stepName, stepDict, k, properties): - if 'RecoGlobal' in step: - stepDict[stepName][k] = merge([self.step3, stepDict[step][k]]) - if 'HARVESTGlobal' in step: - stepDict[stepName][k] = merge([self.step4, stepDict[step][k]]) - def condition(self, fragment, stepList, key, hasHarvest): - return (fragment=="TTbar_14TeV" or 'CloseByPGun_CE' in fragment) and 'Run4' in key -upgradeWFs['ticl_FastJet'] = UpgradeWorkflow_ticl_FastJet( - steps = [ - 'RecoGlobal', - 'RecoGlobalFakeHLT', - 'HARVESTGlobal' - ], - PU = [ - 'RecoGlobal', - 'RecoGlobalFakeHLT', - 'HARVESTGlobal' - ], - suffix = '_ticl_FastJet', - offset = 0.202, -) -upgradeWFs['ticl_FastJet'].step3 = {'--procModifiers': 'fastJetTICL'} -upgradeWFs['ticl_FastJet'].step4 = {'--procModifiers': 'fastJetTICL'} - -class UpgradeWorkflow_ticl_v5(UpgradeWorkflow): - def setup_(self, step, stepName, stepDict, k, properties): - if ('Digi' in step and 'NoHLT' not in step) or ('HLTOnly' in step): - stepDict[stepName][k] = merge([self.step2, stepDict[step][k]]) - if 'RecoGlobal' in step: - stepDict[stepName][k] = merge([self.step3, stepDict[step][k]]) - if 'HARVESTGlobal' in step: - stepDict[stepName][k] = merge([self.step4, stepDict[step][k]]) - def condition(self, fragment, stepList, key, hasHarvest): - selected_fragments = ["TTbar_14TeV", "CloseByP", "Eta1p7_2p7", "ZEE_14"] - return any(sf in fragment for sf in selected_fragments) and 'Run4' in key -upgradeWFs['ticl_v5'] = UpgradeWorkflow_ticl_v5( - steps = [ - 'HLTOnly', - 'DigiTrigger', - 'RecoGlobal', - 'HARVESTGlobal' - ], - PU = [ - 'HLTOnly', - 'DigiTrigger', - 'RecoGlobal', - 'HARVESTGlobal' - ], - suffix = '_ticl_v5', - offset = 0.203, -) -upgradeWFs['ticl_v5'].step2 = {'--procModifiers': 'ticl_v5'} -upgradeWFs['ticl_v5'].step3 = {'--procModifiers': 'ticl_v5'} -upgradeWFs['ticl_v5'].step4 = {'--procModifiers': 'ticl_v5'} class UpgradeWorkflow_ticl_v5_superclustering(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): @@ -907,9 +827,9 @@ def condition(self, fragment, stepList, key, hasHarvest): suffix = '_ticl_v5_mustache', offset = 0.204, ) -upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step2 = {'--procModifiers': 'ticl_v5,ticl_superclustering_mustache_ticl'} -upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step3 = {'--procModifiers': 'ticl_v5,ticl_superclustering_mustache_ticl'} -upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step4 = {'--procModifiers': 'ticl_v5,ticl_superclustering_mustache_ticl'} +upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step2 = {'--procModifiers': 'ticl_superclustering_mustache_ticl'} +upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step3 = {'--procModifiers': 'ticl_superclustering_mustache_ticl'} +upgradeWFs['ticl_v5_superclustering_mustache_ticl'].step4 = {'--procModifiers': 'ticl_superclustering_mustache_ticl'} upgradeWFs['ticl_v5_superclustering_mustache_pf'] = UpgradeWorkflow_ticl_v5_superclustering( steps = [ @@ -925,8 +845,8 @@ def condition(self, fragment, stepList, key, hasHarvest): suffix = '_ticl_v5_mustache_pf', offset = 0.205, ) -upgradeWFs['ticl_v5_superclustering_mustache_pf'].step3 = {'--procModifiers': 'ticl_v5,ticl_superclustering_mustache_pf'} -upgradeWFs['ticl_v5_superclustering_mustache_pf'].step4 = {'--procModifiers': 'ticl_v5,ticl_superclustering_mustache_pf'} +upgradeWFs['ticl_v5_superclustering_mustache_pf'].step3 = {'--procModifiers': 'ticl_superclustering_mustache_pf'} +upgradeWFs['ticl_v5_superclustering_mustache_pf'].step4 = {'--procModifiers': 'ticl_superclustering_mustache_pf'} class UpgradeWorkflow_TICLdumper(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): @@ -947,26 +867,6 @@ def condition(self, fragment, stepList, key, hasHarvest): ) upgradeWFs['enableTICLdumper'].step3 = {'--customise': 'RecoHGCal/TICL/customiseTICLFromReco.customiseTICLForDumper'} -upgradeWFs['ticl_v5_withDumper'] = UpgradeWorkflow_ticl_v5( - steps = [ - 'HLTOnly', - 'DigiTrigger', - 'RecoGlobal', - 'HARVESTGlobal' - ], - PU = [ - 'HLTOnly', - 'DigiTrigger', - 'RecoGlobal', - 'HARVESTGlobal' - ], - suffix = '_ticl_v5_withDumper', - offset = 0.207, -) -upgradeWFs['ticl_v5_withDumper'].step2 = {'--procModifiers': 'ticl_v5'} -upgradeWFs['ticl_v5_withDumper'].step3 = {'--procModifiers': 'ticl_v5', - '--customise': 'RecoHGCal/TICL/customiseTICLFromReco.customiseTICLForDumper'} -upgradeWFs['ticl_v5_withDumper'].step4 = {'--procModifiers': 'ticl_v5'} class UpgradeWorkflow_CPfromPU(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): @@ -996,9 +896,9 @@ def condition(self, fragment, stepList, key, hasHarvest): offset = 0.208, ) -upgradeWFs['CPfromPU'].step2 = {'--procModifiers': 'enableCPfromPU'} -upgradeWFs['CPfromPU'].step3 = {'--procModifiers': 'enableCPfromPU'} -upgradeWFs['CPfromPU'].step4 = {'--procModifiers': 'enableCPfromPU'} +upgradeWFs['CPfromPU'].step2 = {'--procModifiers': 'simTrackstersFromPU'} +upgradeWFs['CPfromPU'].step3 = {'--procModifiers': 'simTrackstersFromPU'} +upgradeWFs['CPfromPU'].step4 = {'--procModifiers': 'simTrackstersFromPU'} class UpgradeWorkflow_ticl_barrel(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): @@ -1058,9 +958,9 @@ def condition(self, fragment, stepList, key, hasHarvest): suffix = '_ticl_barrel_CPfromPU', offset = 0.2091, ) -upgradeWFs['ticl_barrel_CPfromPU'].step2 = {'--procModifiers': 'ticl_barrel,enableCPfromPU'} -upgradeWFs['ticl_barrel_CPfromPU'].step3 = {'--procModifiers': 'ticl_barrel,enableCPfromPU'} -upgradeWFs['ticl_barrel_CPfromPU'].step4 = {'--procModifiers': 'ticl_barrel,enableCPfromPU'} +upgradeWFs['ticl_barrel_CPfromPU'].step2 = {'--procModifiers': 'ticl_barrel,simTrackstersFromPU'} +upgradeWFs['ticl_barrel_CPfromPU'].step3 = {'--procModifiers': 'ticl_barrel,simTrackstersFromPU'} +upgradeWFs['ticl_barrel_CPfromPU'].step4 = {'--procModifiers': 'ticl_barrel,simTrackstersFromPU'} class UpgradeWorkflow_ticlv5_TrackLinkingGNN(UpgradeWorkflow): def setup_(self, step, stepName, stepDict, k, properties): @@ -2031,19 +1931,6 @@ def condition(self, fragment, stepList, key, hasHarvest): '-s':'HARVESTING:@hltValidation' } -upgradeWFs['HLTTiming75e33TiclV5'] = deepcopy(upgradeWFs['HLTTiming75e33']) -upgradeWFs['HLTTiming75e33TiclV5'].suffix = '_HLT75e33TimingTiclV5' -upgradeWFs['HLTTiming75e33TiclV5'].offset = 0.752 -upgradeWFs['HLTTiming75e33TiclV5'].step2 = { - '-s':'DIGI:pdigi_valid,L1TrackTrigger,L1,L1P2GT,DIGI2RAW,HLT:75e33_timing,VALIDATION:@hltValidation', - '--procModifiers': 'ticl_v5', - '--datatier':'GEN-SIM-DIGI-RAW,DQMIO', - '--eventcontent':'FEVTDEBUGHLT,DQMIO' -} -upgradeWFs['HLTTiming75e33TiclV5'].step3 = { - '-s':'HARVESTING:@hltValidation' -} - upgradeWFs['HLTTiming75e33TiclV5TrackLinkingGNN'] = deepcopy(upgradeWFs['HLTTiming75e33']) upgradeWFs['HLTTiming75e33TiclV5TrackLinkingGNN'].suffix = '_HLT75e33TimingTiclV5TrackLinkGNN' upgradeWFs['HLTTiming75e33TiclV5TrackLinkingGNN'].offset = 0.7521 @@ -2279,12 +2166,12 @@ def condition(self, fragment, stepList, key, hasHarvest): upgradeWFs['NGTScoutingAll'].offset = 0.771 upgradeWFs['NGTScoutingAll'].step2 = { '-s':'DIGI:pdigi_valid,L1TrackTrigger,L1,L1P2GT,DIGI2RAW,HLT:NGTScouting,VALIDATION:@hltValidation', - '--procModifiers': 'ngtScouting,alpaka,ticl_v5,ticl_barrel', + '--procModifiers': 'ngtScouting,alpaka,ticl_barrel', '--datatier':'GEN-SIM-DIGI-RAW,DQMIO', '--eventcontent':'FEVTDEBUGHLT,DQMIO' } upgradeWFs['NGTScoutingAll'].step3 = { - '--procModifiers': 'ngtScouting,alpaka,ticl_v5,ticl_barrel', + '--procModifiers': 'ngtScouting,alpaka,ticl_barrel', '-s':'HARVESTING:@hltValidation' } diff --git a/Configuration/PyReleaseValidation/scripts/runTheMatrix.py b/Configuration/PyReleaseValidation/scripts/runTheMatrix.py index 19a2d550b74ee..f382c79b4abe6 100755 --- a/Configuration/PyReleaseValidation/scripts/runTheMatrix.py +++ b/Configuration/PyReleaseValidation/scripts/runTheMatrix.py @@ -162,7 +162,6 @@ def runSelected(opt): prefixDet+34.7501, # HLT phase-2 tracking-only menu prefixDet+34.7502, # HLT phase-2 tracking menu with tracking ntuple prefixDet+34.751, # HLT phase-2 timing menu Alpaka variant - prefixDet+34.752, # HLT phase-2 timing menu ticl_v5 variant prefixDet+34.7521, # HLT phase-2 timing menu ticlv5TrackLinkGNN variant prefixDet+34.753, # HLT phase-2 timing menu legacy tracking prefixDet+34.754, # HLT phase-2 timing menu legacy tracking with Patatrack quads @@ -172,7 +171,7 @@ def runSelected(opt): prefixDet+34.758, # HLT phase-2 timing menu ticl_barrel variant prefixDet+34.759, # HLT phase-2 timing menu, with NANO:@Phase2HLT prefixDet+34.77, # HLT phase-2 NGT Scouting menu - prefixDet+34.771, # HLT phase-2 NGT Scouting menu, Alpaka, TICL-v5, TICL-Barrel + prefixDet+34.771, # HLT phase-2 NGT Scouting menu, Alpaka, TICL-Barrel prefixDet+34.772, # HLT phase-2 NGT Scouting menu, with NANO:@NGTScouting prefixDet+34.773, # HLT phase-2 NGT Scouting menu, with NANO:@NGTScoutingVal prefixDet+34.775], # HLT phase-2 NGT Scouting menu, Phase2CAExtension&LSTT5 as GeneralTracks diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesL1Seeded_cfi.py index 4fe5fabfebf1d..60b2f5e0f4e3a 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesL1Seeded_cfi.py @@ -3,8 +3,6 @@ hltEgammaCandidatesL1Seeded = cms.EDProducer("EgammaHLTRecoEcalCandidateProducers", recoEcalCandidateCollection = cms.string(''), scHybridBarrelProducer = cms.InputTag("hltParticleFlowSuperClusterECALL1Seeded","particleFlowSuperClusterECALBarrel"), - scIslandEndcapProducer = cms.InputTag("hltParticleFlowSuperClusterHGCalFromTICLL1Seeded") + scIslandEndcapProducer = cms.InputTag("hltTiclEGammaSuperClusterProducerL1Seeded") ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltEgammaCandidatesL1Seeded, scIslandEndcapProducer = cms.InputTag("hltTiclEGammaSuperClusterProducerL1Seeded")) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesUnseeded_cfi.py index 8b2cb266a7816..1b753ee7e58cf 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesUnseeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltEgammaCandidatesUnseeded_cfi.py @@ -3,8 +3,6 @@ hltEgammaCandidatesUnseeded = cms.EDProducer("EgammaHLTRecoEcalCandidateProducers", recoEcalCandidateCollection = cms.string(''), scHybridBarrelProducer = cms.InputTag("hltParticleFlowSuperClusterECALUnseeded","particleFlowSuperClusterECALBarrel"), - scIslandEndcapProducer = cms.InputTag("hltParticleFlowSuperClusterHGCalFromTICLUnseeded") + scIslandEndcapProducer = cms.InputTag("hltTiclEGammaSuperClusterProducerUnseeded") ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltEgammaCandidatesUnseeded, scIslandEndcapProducer = cms.InputTag("hltTiclEGammaSuperClusterProducerUnseeded")) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHitL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHitL1Seeded_cfi.py index 9b99c1506fcb8..4d6de992164c4 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHitL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHitL1Seeded_cfi.py @@ -55,12 +55,10 @@ ), HGCHFNosedigiCollection = cms.InputTag("hfnoseDigis","HFNose"), HGCHFNosehitCollection = cms.string('HGCHFNoseUncalibRecHits'), - computeLocalTime = cms.bool(False), + computeLocalTime = cms.bool(True), algo = cms.string('HGCalUncalibRecHitWorkerWeights') ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltHGCalUncalibRecHitL1Seeded, computeLocalTime = cms.bool(True)) _modifiedHGCEEConfig_v19 = hltHGCalUncalibRecHitL1Seeded.HGCEEConfig.clone( fCPerMIP = HGCAL_reco_constants.fcPerMip[0:4] diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHit_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHit_cfi.py index 2f9abdd33dd0e..0c2d0051a7fea 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHit_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltHGCalUncalibRecHit_cfi.py @@ -56,12 +56,10 @@ ), HGCHFNosedigiCollection = cms.InputTag("hfnoseDigis","HFNose"), HGCHFNosehitCollection = cms.string('HGCHFNoseUncalibRecHits'), - computeLocalTime = cms.bool(False), + computeLocalTime = cms.bool(True), algo = cms.string('HGCalUncalibRecHitWorkerWeights') ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltHGCalUncalibRecHit, computeLocalTime = cms.bool(True)) _modifiedHGCEEConfig_v19 = hltHGCalUncalibRecHit.HGCEEConfig.clone( diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCalFromTICLUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCalFromTICLUnseeded_cfi.py index e59c391dad5c2..b4a662466c872 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCalFromTICLUnseeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCalFromTICLUnseeded_cfi.py @@ -34,5 +34,3 @@ usePFThresholdsFromDB = cms.bool(False) ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltParticleFlowClusterHGCalFromTICLUnseeded.initialClusteringStep, tracksterSrc = "hltTiclCandidate") diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCal_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCal_cfi.py index 2fabc663f3ddf..72b77a10be4a7 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCal_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowClusterHGCal_cfi.py @@ -13,7 +13,7 @@ filter_on_iterations = cms.vint32(0, 1), pid_threshold = cms.double(0.8), thresholdsByDetector = cms.VPSet(), - tracksterSrc = cms.InputTag("hltTiclTrackstersMerge") + tracksterSrc = cms.InputTag("hltTiclCandidate") ), pfClusterBuilder = cms.PSet( @@ -34,5 +34,3 @@ usePFThresholdsFromDB = cms.bool(False) ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltParticleFlowClusterHGCal.initialClusteringStep, tracksterSrc = "hltTiclCandidate") diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLL1Seeded_cfi.py deleted file mode 100644 index 5ff2eb180b358..0000000000000 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLL1Seeded_cfi.py +++ /dev/null @@ -1,52 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -hltParticleFlowSuperClusterHGCalFromTICLL1Seeded = cms.EDProducer("PFECALSuperClusterProducer", - BeamSpot = cms.InputTag("hltOnlineBeamSpot"), - ClusteringType = cms.string('Mustache'), - ESAssociation = cms.InputTag("hltParticleFlowClusterECALL1Seeded"), - EnergyWeight = cms.string('Raw'), - PFBasicClusterCollectionBarrel = cms.string('particleFlowBasicClusterECALBarrel'), - PFBasicClusterCollectionEndcap = cms.string(''), - PFBasicClusterCollectionPreshower = cms.string('particleFlowBasicClusterECALPreshower'), - PFClusters = cms.InputTag("hltParticleFlowClusterHGCalFromTICLL1Seeded"), - PFSuperClusterCollectionBarrel = cms.string('particleFlowSuperClusterECALBarrel'), - PFSuperClusterCollectionEndcap = cms.string(''), - PFSuperClusterCollectionEndcapWithPreshower = cms.string(''), - applyCrackCorrections = cms.bool(False), - barrelRecHits = cms.InputTag("hltRechitInRegionsECAL","EcalRecHitsEB"), - doSatelliteClusterMerge = cms.bool(False), - dropUnseedable = cms.bool(True), - endcapRecHits = cms.InputTag("hltRechitInRegionsECAL","EcalRecHitsEE"), - etawidth_SuperClusterBarrel = cms.double(0.04), - etawidth_SuperClusterEndcap = cms.double(0.04), - isOOTCollection = cms.bool(False), - mightGet = cms.optional.untracked.vstring, - phiwidth_SuperClusterBarrel = cms.double(0.6), - phiwidth_SuperClusterEndcap = cms.double(0.6), - regressionConfig = cms.PSet( - applySigmaIetaIphiBug = cms.bool(False), - eRecHitThreshold = cms.double(1), - ecalRecHitsEB = cms.InputTag("hltEcalRecHitL1Seeded","EcalRecHitsEB"), - ecalRecHitsEE = cms.InputTag("hltEcalRecHitL1Seeded","EcalRecHitsEE"), - hgcalRecHits = cms.InputTag("hltParticleFlowRecHitHGCL1Seeded"), - isHLT = cms.bool(True), - isPhaseII = cms.bool(True), - regressionKeyEB = cms.string('pfscecal_EBCorrection_offline_v2'), - regressionKeyEE = cms.string('superclus_hgcal_mean_online'), - uncertaintyKeyEB = cms.string('pfscecal_EBUncertainty_offline_v2'), - uncertaintyKeyEE = cms.string('superclus_hgcal_sigma_online'), - vertexCollection = cms.InputTag("") - ), - satelliteClusterSeedThreshold = cms.double(50), - satelliteMajorityFraction = cms.double(0.5), - seedThresholdIsET = cms.bool(True), - thresh_PFClusterBarrel = cms.double(0), - thresh_PFClusterES = cms.double(0), - thresh_PFClusterEndcap = cms.double(0.15), - thresh_PFClusterSeedBarrel = cms.double(1), - thresh_PFClusterSeedEndcap = cms.double(1), - thresh_SCEt = cms.double(10.0), - useDynamicDPhiWindow = cms.bool(True), - useRegression = cms.bool(True), - verbose = cms.untracked.bool(False) -) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLUnseeded_cfi.py deleted file mode 100644 index 9c40b31cd4e8c..0000000000000 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltParticleFlowSuperClusterHGCalFromTICLUnseeded_cfi.py +++ /dev/null @@ -1,52 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -hltParticleFlowSuperClusterHGCalFromTICLUnseeded = cms.EDProducer("PFECALSuperClusterProducer", - BeamSpot = cms.InputTag("hltOnlineBeamSpot"), - ClusteringType = cms.string('Mustache'), - ESAssociation = cms.InputTag("hltParticleFlowClusterECALUnseeded"), - EnergyWeight = cms.string('Raw'), - PFBasicClusterCollectionBarrel = cms.string('particleFlowBasicClusterECALBarrel'), - PFBasicClusterCollectionEndcap = cms.string(''), - PFBasicClusterCollectionPreshower = cms.string('particleFlowBasicClusterECALPreshower'), - PFClusters = cms.InputTag("hltParticleFlowClusterHGCalFromTICLUnseeded"), - PFSuperClusterCollectionBarrel = cms.string('particleFlowSuperClusterECALBarrel'), - PFSuperClusterCollectionEndcap = cms.string(''), - PFSuperClusterCollectionEndcapWithPreshower = cms.string(''), - applyCrackCorrections = cms.bool(False), - barrelRecHits = cms.InputTag("hltEcalRecHit","EcalRecHitsEB"), - doSatelliteClusterMerge = cms.bool(False), - dropUnseedable = cms.bool(True), - endcapRecHits = cms.InputTag("hltEcalRecHit","EcalRecHitsEE"), - etawidth_SuperClusterBarrel = cms.double(0.04), - etawidth_SuperClusterEndcap = cms.double(0.04), - isOOTCollection = cms.bool(False), - mightGet = cms.optional.untracked.vstring, - phiwidth_SuperClusterBarrel = cms.double(0.6), - phiwidth_SuperClusterEndcap = cms.double(0.6), - regressionConfig = cms.PSet( - applySigmaIetaIphiBug = cms.bool(False), - eRecHitThreshold = cms.double(1), - ecalRecHitsEB = cms.InputTag("hltEcalRecHit","EcalRecHitsEB"), - ecalRecHitsEE = cms.InputTag("hltEcalRecHit","EcalRecHitsEE"), - hgcalRecHits = cms.InputTag("hltParticleFlowRecHitHGC"), - isHLT = cms.bool(True), - isPhaseII = cms.bool(True), - regressionKeyEB = cms.string('pfscecal_EBCorrection_offline_v2'), - regressionKeyEE = cms.string('superclus_hgcal_mean_online'), - uncertaintyKeyEB = cms.string('pfscecal_EBUncertainty_offline_v2'), - uncertaintyKeyEE = cms.string('superclus_hgcal_sigma_online'), - vertexCollection = cms.InputTag("") - ), - satelliteClusterSeedThreshold = cms.double(50), - satelliteMajorityFraction = cms.double(0.5), - seedThresholdIsET = cms.bool(True), - thresh_PFClusterBarrel = cms.double(0), - thresh_PFClusterES = cms.double(0), - thresh_PFClusterEndcap = cms.double(0.15), - thresh_PFClusterSeedBarrel = cms.double(1), - thresh_PFClusterSeedEndcap = cms.double(1), - thresh_SCEt = cms.double(10.0), - useDynamicDPhiWindow = cms.bool(True), - useRegression = cms.bool(True), - verbose = cms.untracked.bool(False) -) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPfTICL_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPfTICL_cfi.py index c97900f0f8962..c3d7aaed120b0 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltPfTICL_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltPfTICL_cfi.py @@ -24,7 +24,7 @@ punchThroughMETFactor = cms.double(4), trackQuality = cms.string('highPurity') ), - ticlCandidateSrc = cms.InputTag("hltTiclTrackstersMerge"), + ticlCandidateSrc = cms.InputTag("hltTiclCandidate"), timingQualityThreshold = cms.double(0.5), trackTimeErrorMap = cms.InputTag("tofPID","sigmat0"), trackTimeQualityMap = cms.InputTag("mtdTrackQualityMVA","mtdQualMVA"), @@ -33,5 +33,3 @@ useTimingAverage = cms.bool(False) ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltPfTICL, ticlCandidateSrc = cms.InputTag('hltTiclCandidate'), isTICLv5 = cms.bool(True)) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclCandidate_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclCandidate_cfi.py index 4eec2db1080e6..2e93dccbba8f1 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclCandidate_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclCandidate_cfi.py @@ -5,8 +5,8 @@ regressionAndPid = cms.bool(True), 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_v1.onnx'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v1.onnx'), inputNames = cms.vstring( 'input', 'input_tr_features' @@ -46,8 +46,8 @@ useTimingAverage = cms.bool(False) ) -from Configuration.ProcessModifiers.ticlv5_TrackLinkingGNN_cff import ticl_v5_TrackLinkingGNN -ticl_v5_TrackLinkingGNN.toModify(hltTiclCandidate, +from Configuration.ProcessModifiers.ticlv5_TrackLinkingGNN_cff import ticlv5_TrackLinkingGNN +ticlv5_TrackLinkingGNN.toModify(hltTiclCandidate, interpretationDescPSet = cms.PSet( onnxTrkLinkingModelFirstDisk = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/TrackLinking_GNN/FirstDiskPropGNN_v0.onnx'), onnxTrkLinkingModelInterfaceDisk = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/TrackLinking_GNN/InterfaceDiskPropGNN_v0.onnx'), diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerL1Seeded_cfi.py new file mode 100644 index 0000000000000..31163b4f10e69 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerL1Seeded_cfi.py @@ -0,0 +1,19 @@ +import FWCore.ParameterSet.Config as cms + + +hltTiclEGammaSuperClusterProducerL1Seeded = cms.EDProducer('EGammaSuperclusterProducer', + ticlSuperClusters = cms.InputTag('hltTiclTracksterLinksSuperclusteringDNNL1Seeded'), + ticlTrackstersEM = cms.InputTag('hltTiclTrackstersCLUE3DHighL1Seeded'), + layerClusters = cms.InputTag('hltMergeLayerClustersL1Seeded'), + superclusterEtThreshold = cms.double(4), + enableRegression = cms.bool(True), + regressionModelPath = cms.FileInPath('RecoHGCal/TICL/data/superclustering/regression_v1.onnx'), + mightGet = cms.optional.untracked.vstring +) + +from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl + +ticl_superclustering_mustache_ticl.toModify(hltTiclEGammaSuperClusterProducerL1Seeded, + ticlSuperClusters=cms.InputTag("hltTiclTracksterLinksSuperclusteringMustacheL1Seeded"), + enableRegression=cms.bool(False) +) \ No newline at end of file diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerUnseeded_cfi.py new file mode 100644 index 0000000000000..b197aaf994274 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclEGammaSuperClusterProducerUnseeded_cfi.py @@ -0,0 +1,19 @@ +import FWCore.ParameterSet.Config as cms + + +hltTiclEGammaSuperClusterProducerUnseeded = cms.EDProducer('EGammaSuperclusterProducer', + ticlSuperClusters = cms.InputTag('hltTiclTracksterLinksSuperclusteringDNNUnseeded'), + ticlTrackstersEM = cms.InputTag('hltTiclTrackstersCLUE3DHigh'), + layerClusters = cms.InputTag('hltMergeLayerClusters'), + superclusterEtThreshold = cms.double(4), + enableRegression = cms.bool(True), + regressionModelPath = cms.FileInPath('RecoHGCal/TICL/data/superclustering/regression_v1.onnx'), + mightGet = cms.optional.untracked.vstring +) + +from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl + +ticl_superclustering_mustache_ticl.toModify(hltTiclEGammaSuperClusterProducerUnseeded, + ticlSuperClusters=cms.InputTag("hltTiclTracksterLinksSuperclusteringMustacheUnseeded"), + enableRegression=cms.bool(False) +) \ No newline at end of file diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksL1Seeded_cfi.py index f94091e6fea0f..410c64093c8a9 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("hltMergeLayerClustersL1Seeded"), layer_clustersTime = cms.InputTag("hltMergeLayerClustersL1Seeded","timeLayerCluster"), - inferenceAlgo = cms.string('TracksterInferenceByPFN'), + inferenceAlgo = cms.string(''), linkingPSet = hltTiclTracksterLinksPSet, pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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'), @@ -23,8 +23,8 @@ ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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'), diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNL1Seeded_cfi.py new file mode 100644 index 0000000000000..4ab0d48abb5a5 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNL1Seeded_cfi.py @@ -0,0 +1,12 @@ +from .hltTiclTracksterLinksL1Seeded_cfi import hltTiclTracksterLinksL1Seeded +import FWCore.ParameterSet.Config as cms + +hltTiclTracksterLinksSuperclusteringDNNL1Seeded = hltTiclTracksterLinksL1Seeded.clone( + linkingPSet = cms.PSet( + type=cms.string("SuperClusteringDNN"), + algo_verbosity=cms.int32(0), + onnxModelPath = cms.string("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), + nnWorkingPoint=cms.double(0.57247), + ), + tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced +) \ No newline at end of file diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNUnseeded_cfi.py new file mode 100644 index 0000000000000..7e878f3c0ca07 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringDNNUnseeded_cfi.py @@ -0,0 +1,12 @@ +from .hltTiclTracksterLinks_cfi import hltTiclTracksterLinks +import FWCore.ParameterSet.Config as cms + +hltTiclTracksterLinksSuperclusteringDNNUnseeded = hltTiclTracksterLinks.clone( + linkingPSet = cms.PSet( + type=cms.string("SuperClusteringDNN"), + algo_verbosity=cms.int32(0), + onnxModelPath = cms.string("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), + nnWorkingPoint=cms.double(0.57247), + ), + tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHigh")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced +) \ No newline at end of file diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheL1Seeded_cfi.py new file mode 100644 index 0000000000000..a8976b1e025e4 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheL1Seeded_cfi.py @@ -0,0 +1,11 @@ +from .hltTiclTracksterLinksL1Seeded_cfi import hltTiclTracksterLinksL1Seeded +import FWCore.ParameterSet.Config as cms + + +hltTiclTracksterLinksSuperclusteringMustacheL1Seeded = hltTiclTracksterLinksL1Seeded.clone( + linkingPSet = cms.PSet( + type = cms.string("SuperClusteringMustache"), + algo_verbosity = cms.int32(0) + ), + tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded")], +) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheUnseeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheUnseeded_cfi.py new file mode 100644 index 0000000000000..3e57403b646c3 --- /dev/null +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinksSuperclusteringMustacheUnseeded_cfi.py @@ -0,0 +1,11 @@ +from .hltTiclTracksterLinks_cfi import hltTiclTracksterLinks +import FWCore.ParameterSet.Config as cms + + +hltTiclTracksterLinksSuperclusteringMustacheUnseeded = hltTiclTracksterLinks.clone( + linkingPSet = cms.PSet( + type = cms.string("SuperClusteringMustache"), + algo_verbosity = cms.int32(0) + ), + tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHigh")], +) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTracksterLinks_cfi.py index 057c16b1c6ae3..043c397bf6517 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("hltMergeLayerClusters"), layer_clustersTime = cms.InputTag("hltMergeLayerClusters","timeLayerCluster"), - inferenceAlgo = cms.string('TracksterInferenceByPFN'), + inferenceAlgo = cms.string(''), linkingPSet = hltTiclTracksterLinksPSet, pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - 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'), + onnxPIDModelPath = cms.string(''), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -23,8 +23,8 @@ ), 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'), + onnxPIDModelPath = cms.string(''), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input','input_tr_features'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -33,7 +33,8 @@ eid_n_clusters = cms.int32(10), doPID = cms.int32(1), doRegression = cms.int32(1), - type = cms.string('TracksterInferenceByPFN') + type = cms.string('TracksterInferenceByPFN'), + miniBatchSize = cms.untracked.int32(64) ), mightGet = cms.optional.untracked.vstring, original_masks = cms.VInputTag("hltMergeLayerClusters:InitialLayerClustersMask"), diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py index d2203dc57b1f1..c4a085f2f8b2d 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHighL1Seeded_cfi.py @@ -10,7 +10,7 @@ mightGet = cms.optional.untracked.vstring, original_mask = cms.InputTag("hltMergeLayerClustersL1Seeded","InitialLayerClustersMask"), patternRecognitionBy = cms.string('CLUE3D'), - inferenceAlgo = cms.string('TracksterInferenceByCNNv4'), + inferenceAlgo = cms.string('TracksterInferenceByCNN'), pluginPatternRecognitionByCA = cms.PSet( algo_verbosity = cms.int32(0), energy_em_over_total_threshold = cms.double(-1), @@ -95,7 +95,7 @@ 2, 2 ), - computeLocalTime = cms.bool(False), + computeLocalTime = cms.bool(True), doPidCut = cms.bool(True), cutHadProb = cms.double(999.), type = cms.string('CLUE3D') @@ -106,22 +106,22 @@ minNumLayerCluster = cms.int32(5), type = cms.string('FastJet') ), - pluginInferenceAlgoTracksterInferenceByCNNv4 = cms.PSet( + pluginInferenceAlgoTracksterInferenceByCNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv4/onnx_models/energy_id_v0.onnx'), - inputNames = cms.vstring('input:0'), - outputNames = cms.vstring("output/regressed_energy:0", "output/id_probabilities:0"), - eid_min_cluster_energy = cms.double(1), + type = cms.string("TracksterInferenceByCNN"), + onnxModelPath = cms.string("RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/patternrecognition/id_v0.onnx"), + inputNames = cms.vstring("input"), + outputNames = cms.vstring("pid_output"), + eid_min_cluster_energy = cms.double(1.0), eid_n_layers = cms.int32(50), eid_n_clusters = cms.int32(10), doPID = cms.int32(1), - doRegression = cms.int32(0), - type = cms.string('TracksterInferenceByCNNv4') + miniBatchSize = cms.untracked.int32(64), ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -133,8 +133,8 @@ ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input','input_tr_features'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -142,18 +142,9 @@ 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') - + type = cms.string('TracksterInferenceByPFN'), + miniBatchSize = cms.untracked.int32(64) ), seeding_regions = cms.InputTag("hltTiclSeedingL1"), time_layerclusters = cms.InputTag("hltMergeLayerClustersL1Seeded","timeLayerCluster"), ) - -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltTiclTrackstersCLUE3DHighL1Seeded.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) -ticl_v5.toModify(hltTiclTrackstersCLUE3DHighL1Seeded, inferenceAlgo = 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 111ae49aa2fff..ffc428316bd6e 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersCLUE3DHigh_cfi.py @@ -10,7 +10,7 @@ mightGet = cms.optional.untracked.vstring, original_mask = cms.InputTag("hltMergeLayerClusters","InitialLayerClustersMask"), patternRecognitionBy = cms.string('CLUE3D'), - inferenceAlgo = cms.string('TracksterInferenceByCNNv4'), + inferenceAlgo = cms.string('TracksterInferenceByCNN'), pluginPatternRecognitionByCA = cms.PSet( algo_verbosity = cms.int32(0), energy_em_over_total_threshold = cms.double(-1), @@ -95,7 +95,7 @@ 2, 2 ), - computeLocalTime = cms.bool(False), + computeLocalTime = cms.bool(True), doPidCut = cms.bool(True), cutHadProb = cms.double(999.), type = cms.string('CLUE3D') @@ -107,22 +107,22 @@ minNumLayerCluster = cms.int32(5), type = cms.string('FastJet') ), - pluginInferenceAlgoTracksterInferenceByCNNv4 = cms.PSet( + pluginInferenceAlgoTracksterInferenceByCNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv4/onnx_models/energy_id_v0.onnx'), - inputNames = cms.vstring('input:0'), - outputNames = cms.vstring("output/regressed_energy:0", "output/id_probabilities:0"), - eid_min_cluster_energy = cms.double(1), + type = cms.string("TracksterInferenceByCNN"), + onnxModelPath = cms.string("RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/patternrecognition/id_v0.onnx"), + inputNames = cms.vstring("input"), + outputNames = cms.vstring("pid_output"), + eid_min_cluster_energy = cms.double(1.0), eid_n_layers = cms.int32(50), eid_n_clusters = cms.int32(10), doPID = cms.int32(1), - doRegression = cms.int32(0), - type = cms.string('TracksterInferenceByCNNv4') + miniBatchSize = cms.untracked.int32(64), ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -134,8 +134,8 @@ ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input','input_tr_features'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -143,17 +143,10 @@ 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') - + type = cms.string('TracksterInferenceByPFN'), + miniBatchSize = cms.untracked.int32(64) ), seeding_regions = cms.InputTag("hltTiclSeedingGlobal"), time_layerclusters = cms.InputTag("hltMergeLayerClusters","timeLayerCluster") ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(hltTiclTrackstersCLUE3DHigh.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) -ticl_v5.toModify(hltTiclTrackstersCLUE3DHigh, inferenceAlgo = cms.string('TracksterInferenceByPFN')) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersMerge_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersMerge_cfi.py deleted file mode 100644 index 59c5d7efca357..0000000000000 --- a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersMerge_cfi.py +++ /dev/null @@ -1,50 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -hltTiclTrackstersMerge = cms.EDProducer("TrackstersMergeProducer", - cosangle_align = cms.double(0.9945), - detector = cms.string('HGCAL'), - e_over_h_threshold = cms.double(1), - eid_input_name = cms.string('input'), - eid_min_cluster_energy = cms.double(2.5), - eid_n_clusters = cms.int32(10), - eid_n_layers = cms.int32(50), - eid_output_name_energy = cms.string('output/regressed_energy'), - eid_output_name_id = cms.string('output/id_probabilities'), - eta_bin_window = cms.int32(1), - halo_max_distance2 = cms.double(4), - layer_clusters = cms.InputTag("hltMergeLayerClusters"), - layer_clustersTime = cms.InputTag("hltMergeLayerClusters","timeLayerCluster"), - linkingPSet = cms.PSet( - algo_verbosity = cms.int32(0), - cutTk = cms.string('1.48 < abs(eta) < 3.0 && pt > 1. && quality("highPurity") && hitPattern().numberOfLostHits("MISSING_OUTER_HITS") < 5'), - delta_tk_ts_interface = cms.double(0.03), - delta_tk_ts_layer1 = cms.double(0.02), - delta_ts_em_had = cms.double(0.03), - delta_ts_had_had = cms.double(0.03), - track_time_quality_threshold = cms.double(0.5), - type = cms.string('LinkingAlgoByDirectionGeometric') - ), - mightGet = cms.optional.untracked.vstring, - muons = cms.InputTag("hltPhase2L3Muons"), - optimiseAcrossTracksters = cms.bool(True), - phi_bin_window = cms.int32(1), - propagator = cms.string('PropagatorWithMaterial'), - pt_neutral_threshold = cms.double(2), - pt_sigma_high = cms.double(2), - pt_sigma_low = cms.double(2), - resol_calo_offset_em = cms.double(1.5), - resol_calo_offset_had = cms.double(1.5), - resol_calo_scale_em = cms.double(0.15), - resol_calo_scale_had = cms.double(0.15), - tfDnnLabel = cms.string('tracksterSelectionTf'), - track_max_eta = cms.double(3), - track_max_missing_outerhits = cms.int32(5), - track_min_eta = cms.double(1.48), - track_min_pt = cms.double(1), - tracks = cms.InputTag("hltGeneralTracks"), - tracksTime = cms.InputTag("tofPID","t0"), - tracksTimeErr = cms.InputTag("tofPID","sigmat0"), - tracksTimeQual = cms.InputTag("mtdTrackQualityMVA","mtdQualMVA"), - trackstersclue3d = cms.InputTag("hltTiclTrackstersCLUE3DHigh"), - useMTDTiming = cms.bool(False) -) diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecoveryL1Seeded_cfi.py index 77e7e5eabdb1a..47e3844722465 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('TracksterInferenceByPFN'), + inferenceAlgo = cms.string(''), 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/DNN/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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'), @@ -85,22 +85,18 @@ ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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_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') - + type = cms.string('TracksterInferenceByPFN'), + miniBatchSize = cms.untracked.int32(64) ), seeding_regions = cms.InputTag("hltTiclSeedingL1"), time_layerclusters = cms.InputTag("hltMergeLayerClustersL1Seeded","timeLayerCluster") diff --git a/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/modules/hltTiclTrackstersRecovery_cfi.py index 8c4a5025fbead..b901fd45b2b30 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('TracksterInferenceByPFN'), + inferenceAlgo = cms.string(''), 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/DNN/patternrecognition/id_v0.onnx'), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/energy_v0.onnx'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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'), @@ -85,8 +85,8 @@ ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string('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'), @@ -95,12 +95,8 @@ 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') - + type = cms.string('TracksterInferenceByPFN'), + miniBatchSize = cms.untracked.int32(64) ), seeding_regions = cms.InputTag("hltTiclSeedingGlobal"), time_layerclusters = cms.InputTag("hltMergeLayerClusters","timeLayerCluster") diff --git a/HLTrigger/Configuration/python/HLT_75e33/psets/hltTiclTracksterLinksPSet_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/psets/hltTiclTracksterLinksPSet_cfi.py index d3f73a2fb1ff7..3ef79f00d96d8 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/psets/hltTiclTracksterLinksPSet_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/psets/hltTiclTracksterLinksPSet_cfi.py @@ -1,6 +1,7 @@ import FWCore.ParameterSet.Config as cms hltTiclTracksterLinksPSet = cms.PSet( + onnxModelPath = cms.string(""), cylinder_radius_sqr_split = cms.double(9), proj_distance_split = cms.double(5), track_time_quality_threshold = cms.double(0.5), diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaL1SeededSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaL1SeededSequence_cfi.py index 365463a73a7a2..a9b30c513116a 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaL1SeededSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaL1SeededSequence_cfi.py @@ -13,12 +13,15 @@ from ..modules.hltRechitInRegionsHGCAL_cfi import * from ..modules.hltParticleFlowClusterHGCalFromTICLL1Seeded_cfi import * from ..modules.hltParticleFlowRecHitHGCL1Seeded_cfi import * -from ..modules.hltParticleFlowSuperClusterHGCalFromTICLL1Seeded_cfi import * from ..modules.hltTiclLayerTileProducerL1Seeded_cfi import * from ..modules.hltTiclSeedingL1_cfi import * from ..modules.hltTiclTrackstersCLUE3DHighL1Seeded_cfi import * from ..modules.hltTiclTracksterLinksL1Seeded_cfi import * from ..modules.hltBarrelLayerClustersEBL1Seeded_cfi import * +from ..modules.hltTiclEGammaSuperClusterProducerL1Seeded_cfi import hltTiclEGammaSuperClusterProducerL1Seeded +from ..modules.hltTiclTracksterLinksSuperclusteringMustacheL1Seeded_cfi import hltTiclTracksterLinksSuperclusteringMustacheL1Seeded +from ..modules.hltTiclTracksterLinksSuperclusteringDNNL1Seeded_cfi import hltTiclTracksterLinksSuperclusteringDNNL1Seeded + _HgcalLocalRecoL1SeededSequence = cms.Sequence(hltHgcalDigis+ hltL1TEGammaHGCFilteredCollectionProducer+ @@ -37,46 +40,19 @@ hltTiclLayerTileProducerL1Seeded+ hltTiclTrackstersCLUE3DHighL1Seeded) -_SuperclusteringL1SeededSequence = cms.Sequence(hltParticleFlowClusterHGCalFromTICLL1Seeded+ - hltParticleFlowSuperClusterHGCalFromTICLL1Seeded) + + +_SuperclusteringL1SeededSequence = cms.Sequence(hltTiclTracksterLinksSuperclusteringDNNL1Seeded + + hltTiclEGammaSuperClusterProducerL1Seeded) + # The baseline sequence HLTHgcalTiclPFClusteringForEgammaL1SeededSequence = cms.Sequence(_HgcalLocalRecoL1SeededSequence + _HgcalTICLPatternRecognitionL1SeededSequence + _SuperclusteringL1SeededSequence) -# Enable EGammaSuperClusterProducer at HLT in ticl v5 -hltTiclTracksterLinksSuperclusteringDNNL1Seeded = hltTiclTracksterLinksL1Seeded.clone( - linkingPSet = cms.PSet( - type=cms.string("SuperClusteringDNN"), - algo_verbosity=cms.int32(0), - onnxModelPath = cms.FileInPath("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), - nnWorkingPoint=cms.double(0.57247), - ), - tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced -) -hltTiclTracksterLinksSuperclusteringMustacheL1Seeded = hltTiclTracksterLinksL1Seeded.clone( - linkingPSet = cms.PSet( - type=cms.string("SuperClusteringMustache"), - algo_verbosity=cms.int32(0) - ), - tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced -) -from RecoHGCal.TICL.ticlEGammaSuperClusterProducer_cfi import ticlEGammaSuperClusterProducer as _ticlEGammaSuperClusterProducer -hltTiclEGammaSuperClusterProducerL1Seeded = _ticlEGammaSuperClusterProducer.clone( - ticlSuperClusters = "hltTiclTracksterLinksSuperclusteringDNNL1Seeded", - ticlTrackstersEM = "hltTiclTrackstersCLUE3DHighL1Seeded", - layerClusters = "hltMergeLayerClustersL1Seeded" -) -# DNN -from Configuration.ProcessModifiers.ticl_superclustering_dnn_cff import ticl_superclustering_dnn -ticl_superclustering_dnn.toReplaceWith(_SuperclusteringL1SeededSequence, - cms.Sequence( - hltTiclTracksterLinksSuperclusteringDNNL1Seeded - + hltTiclEGammaSuperClusterProducerL1Seeded - ) -) + # Mustache from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl @@ -86,12 +62,6 @@ + hltTiclEGammaSuperClusterProducerL1Seeded ) ) -ticl_superclustering_mustache_ticl.toModify(hltTiclEGammaSuperClusterProducerL1Seeded, - ticlSuperClusters=cms.InputTag("hltTiclTracksterLinksSuperclusteringMustacheL1Seeded"), - ticlTrackstersEM=cms.InputTag("hltTiclTrackstersCLUE3DHighL1Seeded"), - layerClusters=cms.InputTag("hltMergeLayerClustersL1Seeded"), - enableRegression=cms.bool(False) -) from Configuration.ProcessModifiers.ticl_barrel_cff import ticl_barrel _HgcalLocalRecoL1SeededSequence_barrel = cms.Sequence( diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaUnseededSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaUnseededSequence_cfi.py index 78fe399cbc696..03228973bfeb7 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaUnseededSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTHgcalTiclPFClusteringForEgammaUnseededSequence_cfi.py @@ -10,7 +10,6 @@ from ..modules.hltHGCalUncalibRecHit_cfi import * from ..modules.hltParticleFlowClusterHGCalFromTICLUnseeded_cfi import * from ..modules.hltParticleFlowRecHitHGC_cfi import * -from ..modules.hltParticleFlowSuperClusterHGCalFromTICLUnseeded_cfi import * from ..modules.hltTiclLayerTileProducer_cfi import * from ..modules.hltTiclSeedingGlobal_cfi import * from ..modules.hltTiclTrackstersCLUE3DHigh_cfi import * @@ -22,6 +21,13 @@ # Barrel layer clusters from ..modules.hltBarrelLayerClustersEB_cfi import * from ..modules.hltBarrelLayerClustersHB_cfi import * + +from ..modules.hltTiclEGammaSuperClusterProducerUnseeded_cfi import hltTiclEGammaSuperClusterProducerUnseeded +from ..modules.hltTiclTracksterLinksSuperclusteringMustacheUnseeded_cfi import hltTiclTracksterLinksSuperclusteringMustacheUnseeded +from ..modules.hltTiclTracksterLinksSuperclusteringDNNUnseeded_cfi import hltTiclTracksterLinksSuperclusteringDNNUnseeded + + + _HgcalLocalRecoUnseededSequence = cms.Sequence(hltHgcalDigis+hltHGCalUncalibRecHit+ hltHGCalRecHit+hltParticleFlowRecHitHGC+ hltHgcalLayerClustersEE+ @@ -33,10 +39,9 @@ hltTiclSeedingGlobal+hltTiclLayerTileProducer+ hltTiclTrackstersCLUE3DHigh) -_SuperclusteringUnseededSequence = cms.Sequence(hltParticleFlowClusterHGCalFromTICLUnseeded+ - hltParticleFlowSuperClusterHGCalFromTICLUnseeded) -# The baseline sequence +_SuperclusteringUnseededSequence = cms.Sequence(hltTiclTracksterLinksSuperclusteringDNNUnseeded+ hltTiclEGammaSuperClusterProducerUnseeded) + HLTHgcalTiclPFClusteringForEgammaUnseededSequence = cms.Sequence(_HgcalLocalRecoUnseededSequence + _HgcalTICLPatternRecognitionUnseededSequence + _SuperclusteringUnseededSequence) # Alpaka @@ -56,40 +61,8 @@ ) ) -# Use EGammaSuperClusterProducer at HLT in ticl v5 -hltTiclTracksterLinksSuperclusteringDNNUnseeded = hltTiclTracksterLinks.clone( - linkingPSet = cms.PSet( - type=cms.string("SuperClusteringDNN"), - algo_verbosity=cms.int32(0), - onnxModelPath = cms.FileInPath("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), - nnWorkingPoint=cms.double(0.57247), - ), - tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHigh")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced -) - -hltTiclTracksterLinksSuperclusteringMustacheUnseeded = hltTiclTracksterLinks.clone( - linkingPSet = cms.PSet( - type=cms.string("SuperClusteringMustache"), - algo_verbosity=cms.int32(0) - ), - tracksters_collections = [cms.InputTag("hltTiclTrackstersCLUE3DHigh")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced -) -from RecoHGCal.TICL.ticlEGammaSuperClusterProducer_cfi import ticlEGammaSuperClusterProducer as _ticlEGammaSuperClusterProducer -hltTiclEGammaSuperClusterProducerUnseeded = _ticlEGammaSuperClusterProducer.clone( - ticlSuperClusters = "hltTiclTracksterLinksSuperclusteringDNNUnseeded", - ticlTrackstersEM = "hltTiclTrackstersCLUE3DHigh", - layerClusters = "hltMergeLayerClusters" -) -# DNN -from Configuration.ProcessModifiers.ticl_superclustering_dnn_cff import ticl_superclustering_dnn -ticl_superclustering_dnn.toReplaceWith(_SuperclusteringUnseededSequence, - cms.Sequence( - hltTiclTracksterLinksSuperclusteringDNNUnseeded - + hltTiclEGammaSuperClusterProducerUnseeded - ) -) # Ticl mustache from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl @@ -99,12 +72,7 @@ + hltTiclEGammaSuperClusterProducerUnseeded ) ) -ticl_superclustering_mustache_ticl.toModify(hltTiclEGammaSuperClusterProducerUnseeded, - ticlSuperClusters=cms.InputTag("hltTiclTracksterLinksSuperclusteringMustacheUnseeded"), - ticlTrackstersEM=cms.InputTag("hltTiclTrackstersCLUE3DHigh"), - layerClusters=cms.InputTag("hltMergeLayerClusters"), - enableRegression=cms.bool(False) -) + _HgcalLocalRecoUnseededSequence_barrel = _HgcalLocalRecoUnseededSequence.copy() _HgcalLocalRecoUnseededSequence_barrel += hltBarrelLayerClustersEB diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTIterTICLSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTIterTICLSequence_cfi.py index 31b48c0a24141..e56b974f25dc6 100644 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTIterTICLSequence_cfi.py +++ b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTIterTICLSequence_cfi.py @@ -2,13 +2,10 @@ from ..sequences.HLTTiclLayerTileSequence_cfi import * from ..sequences.HLTTiclPFSequence_cfi import * -from ..sequences.HLTTiclTracksterMergeSequence_cfi import * from ..sequences.HLTTiclTrackstersCLUE3DHighStepSequence_cfi import * from ..sequences.HLTTiclTrackstersRecoverySequence_cfi import * from ..sequences.HLTTiclTracksterLinksSequence_cfi import * from ..sequences.HLTTiclCandidateSequence_cfi import * -HLTIterTICLSequence = cms.Sequence(HLTTiclLayerTileSequence+HLTTiclTrackstersCLUE3DHighStepSequence+HLTTiclTracksterMergeSequence+HLTTiclPFSequence) +HLTIterTICLSequence = cms.Sequence(HLTTiclLayerTileSequence+HLTTiclTrackstersCLUE3DHighStepSequence+HLTTiclTrackstersRecoverySequence+HLTTiclTracksterLinksSequence+HLTTiclCandidateSequence+HLTTiclPFSequence) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toReplaceWith(HLTIterTICLSequence, cms.Sequence(HLTTiclLayerTileSequence+HLTTiclTrackstersCLUE3DHighStepSequence+HLTTiclTrackstersRecoverySequence+HLTTiclTracksterLinksSequence+HLTTiclCandidateSequence+HLTTiclPFSequence)) diff --git a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi.py b/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi.py deleted file mode 100644 index 41da827680889..0000000000000 --- a/HLTrigger/Configuration/python/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi.py +++ /dev/null @@ -1,5 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from ..modules.hltTiclTrackstersMerge_cfi import * - -HLTTiclTracksterMergeSequence = cms.Sequence(hltTiclTrackstersMerge) diff --git a/HLTrigger/Configuration/python/HLT_75e33_cff.py b/HLTrigger/Configuration/python/HLT_75e33_cff.py index 0abb71a072bc8..f6cf04dc37657 100644 --- a/HLTrigger/Configuration/python/HLT_75e33_cff.py +++ b/HLTrigger/Configuration/python/HLT_75e33_cff.py @@ -6,7 +6,6 @@ fragment.load("Configuration/StandardSequences/Accelerators_cff") fragment.load("CalibMuon/CSCCalibration/CSCChannelMapper_cfi") fragment.load("CalibMuon/CSCCalibration/CSCIndexer_cfi") -fragment.load("RecoHGCal/TICL/tracksterSelectionTf_cfi") fragment.load("RecoJets/Configuration/CaloTowersES_cfi") fragment.load("RecoLocalCalo/EcalRecAlgos/EcalSeverityLevelESProducer_cfi") fragment.load("RecoLocalCalo/HcalRecAlgos/hcalRecAlgoESProd_cfi") @@ -266,7 +265,6 @@ fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTRawToDigiSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclLayerTileSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclPFSequence_cfi") -fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTrackstersCLUE3DHighStepSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTVertexRecoSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/services/DQMStore_cfi") diff --git a/HLTrigger/Configuration/python/HLT_75e33_timing_cff.py b/HLTrigger/Configuration/python/HLT_75e33_timing_cff.py index 3bc1b1f1ffff5..fe7e1edad5f30 100644 --- a/HLTrigger/Configuration/python/HLT_75e33_timing_cff.py +++ b/HLTrigger/Configuration/python/HLT_75e33_timing_cff.py @@ -11,7 +11,6 @@ ### Non HLT-specific event-setups fragment.load("CalibMuon/CSCCalibration/CSCChannelMapper_cfi") fragment.load("CalibMuon/CSCCalibration/CSCIndexer_cfi") -fragment.load("RecoHGCal/TICL/tracksterSelectionTf_cfi") fragment.load("RecoJets/Configuration/CaloTowersES_cfi") fragment.load("RecoLocalCalo/EcalRecAlgos/EcalSeverityLevelESProducer_cfi") fragment.load("RecoLocalCalo/HcalRecAlgos/hcalRecAlgoESProd_cfi") @@ -256,7 +255,6 @@ fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTRawToDigiSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclLayerTileSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclPFSequence_cfi") -fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTrackstersCLUE3DHighStepSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTVertexRecoSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/services/FastTimerService_cfi") diff --git a/HLTrigger/Configuration/python/HLT_NGTScouting_cff.py b/HLTrigger/Configuration/python/HLT_NGTScouting_cff.py index 2702107d0cad7..11e8efb92b970 100644 --- a/HLTrigger/Configuration/python/HLT_NGTScouting_cff.py +++ b/HLTrigger/Configuration/python/HLT_NGTScouting_cff.py @@ -10,7 +10,6 @@ ### Non HLT-specific event-setups fragment.load("CalibMuon/CSCCalibration/CSCChannelMapper_cfi") fragment.load("CalibMuon/CSCCalibration/CSCIndexer_cfi") -fragment.load("RecoHGCal/TICL/tracksterSelectionTf_cfi") fragment.load("RecoJets/Configuration/CaloTowersES_cfi") fragment.load("RecoLocalCalo/EcalRecAlgos/EcalSeverityLevelESProducer_cfi") fragment.load("RecoLocalCalo/HcalRecAlgos/hcalRecAlgoESProd_cfi") @@ -232,7 +231,6 @@ fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTRawToDigiSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclLayerTileSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclPFSequence_cfi") -fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTracksterMergeSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTTiclTrackstersCLUE3DHighStepSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/sequences/HLTVertexRecoSequence_cfi") fragment.load("HLTrigger/Configuration/HLT_75e33/services/FastTimerService_cfi") diff --git a/HLTrigger/NGTScouting/plugins/TICLCandidateExtraTableProducer.cc b/HLTrigger/NGTScouting/plugins/TICLCandidateExtraTableProducer.cc index 83e1f60ce6e96..971cdcd29bb4a 100644 --- a/HLTrigger/NGTScouting/plugins/TICLCandidateExtraTableProducer.cc +++ b/HLTrigger/NGTScouting/plugins/TICLCandidateExtraTableProducer.cc @@ -93,7 +93,7 @@ class TICLCandidateExtraTableProducer : public SimpleFlatTableProducerBase>::baseDescriptions(); edm::ParameterSetDescription coltable; - coltable.add("name", "hltTiclTrackstersMerge"); + coltable.add("name", "hltTiclCandidate"); coltable.add("doc", "TICL Candidates"); coltable.add("useCount", true); coltable.add("useOffset", false); diff --git a/HLTrigger/NGTScouting/python/hltLayerClusters_cfi.py b/HLTrigger/NGTScouting/python/hltLayerClusters_cfi.py index f0652c059150a..a1eb8a8ca0704 100644 --- a/HLTrigger/NGTScouting/python/hltLayerClusters_cfi.py +++ b/HLTrigger/NGTScouting/python/hltLayerClusters_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.nano_cff import nanoMetadata -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet # Tracksters hltLayerClustersTable = cms.EDProducer( diff --git a/HLTrigger/NGTScouting/python/hltSimTracksters_cfi.py b/HLTrigger/NGTScouting/python/hltSimTracksters_cfi.py index 7e0889e34ddd6..1b0d1e33a515c 100644 --- a/HLTrigger/NGTScouting/python/hltSimTracksters_cfi.py +++ b/HLTrigger/NGTScouting/python/hltSimTracksters_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.nano_cff import nanoMetadata -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet hltUpgradeNanoTask = cms.Task(nanoMetadata) diff --git a/HLTrigger/NGTScouting/python/hltTICLCandidates_cfi.py b/HLTrigger/NGTScouting/python/hltTICLCandidates_cfi.py index 71e3cc48d1d43..3462abc0d9a37 100644 --- a/HLTrigger/NGTScouting/python/hltTICLCandidates_cfi.py +++ b/HLTrigger/NGTScouting/python/hltTICLCandidates_cfi.py @@ -1,14 +1,13 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.nano_cff import nanoMetadata -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 hltUpgradeNanoTask = cms.Task(nanoMetadata) hltTiclCandidateTable = cms.EDProducer( "TICLCandidateTableProducer", skipNonExistingSrc=cms.bool(True), - src=cms.InputTag("hltTiclTrackstersMerge"), + src=cms.InputTag("hltTiclCandidate"), cut=cms.string(""), name=cms.string("hltTICLCandidates"), doc=cms.string("TICLCandidates"), @@ -97,7 +96,7 @@ ) hltTiclCandidateExtraTable = cms.EDProducer( "TICLCandidateExtraTableProducer", - src = cms.InputTag("hltTiclTrackstersMerge"), + src = cms.InputTag("hltTiclCandidate"), name = cms.string("Candidate2Tracksters"), doc = cms.string("TICLCandidates extra table with linked Tracksters"), collectionVariables = cms.PSet( @@ -127,5 +126,4 @@ ), ) -ticl_v5.toModify(hltTiclCandidateTable, src = cms.InputTag('hltTiclCandidate')) -ticl_v5.toModify(hltTiclCandidateExtraTable, src = cms.InputTag('hltTiclCandidate')) + diff --git a/HLTrigger/NGTScouting/python/hltTICLSuperClusters_cfi.py b/HLTrigger/NGTScouting/python/hltTICLSuperClusters_cfi.py index c81a0fe5c25a4..21601ad9f0888 100644 --- a/HLTrigger/NGTScouting/python/hltTICLSuperClusters_cfi.py +++ b/HLTrigger/NGTScouting/python/hltTICLSuperClusters_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.nano_cff import nanoMetadata -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet hltUpgradeNanoTask = cms.Task(nanoMetadata) diff --git a/HLTrigger/NGTScouting/python/hltTracksters_cfi.py b/HLTrigger/NGTScouting/python/hltTracksters_cfi.py index 9196b67d9fadb..60de7621170c6 100644 --- a/HLTrigger/NGTScouting/python/hltTracksters_cfi.py +++ b/HLTrigger/NGTScouting/python/hltTracksters_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms from PhysicsTools.NanoAOD.common_cff import * from PhysicsTools.NanoAOD.nano_cff import nanoMetadata -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet hltUpgradeNanoTask = cms.Task(nanoMetadata) hltSimTrackstersLabels = [ @@ -11,7 +11,7 @@ hltSimTrackstersTable = [] hltTrackstersAssociationOneToManyTableProducers = [] tracksterTableProducers = [] -for iterLabel in hltTiclIterLabels: +for iterLabel in hltTiclIterLabelsPSet.labels: tracksterTable = cms.EDProducer( "TracksterCollectionTableProducer", skipNonExistingSrc=cms.bool(True), diff --git a/PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h b/PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h index 2fbc7c2098372..1e1215b6edfa8 100644 --- a/PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h +++ b/PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h @@ -6,6 +6,8 @@ * * Created on: Jun 28, 2019 * Author: hqu + * Improved on: Mar 30, 2026 + * Author: Felice Pantaleo */ #ifndef PHYSICSTOOLS_ONNXRUNTIME_INTERFACE_ONNXRUNTIME_H_ @@ -50,6 +52,22 @@ namespace cms::Ort { const std::vector& output_names = {}, int64_t batch_size = 1) const; + // Run inference writing outputs into user-provided buffers when possible. + // + // - output_values will be resized as needed; callers can reuse capacity across events to reduce allocations. + // - If output_shapes is provided (non-empty), outputs are written directly into output_values (preallocated path). + // - If output_shapes is empty: + // * for outputs with fully-known shapes (or only dynamic batch dim at index 0), we still use the preallocated path + // * for outputs with other dynamic dims (-1 at index > 0), the implementation falls back to ORT-allocated outputs + // and copies the results into output_values (capacity still reusable across events). + void runInto(const std::vector& input_names, + FloatArrays& input_values, + const std::vector>& input_shapes, + const std::vector& output_names, + FloatArrays& output_values, + const std::vector>& output_shapes = {}, + int64_t batch_size = 1) const; + // Get a list of names of all the output nodes const std::vector& getOutputNames() const; diff --git a/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc b/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc index bcea2f9c34b52..efa408cb66781 100644 --- a/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc +++ b/PhysicsTools/ONNXRuntime/src/ONNXRuntime.cc @@ -3,23 +3,46 @@ * * Created on: Jun 28, 2019 * Author: hqu + * Improved on: Mar 30, 2026 + * Author: Felice Pantaleo */ #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" #include "FWCore/Utilities/interface/Exception.h" #include "FWCore/Utilities/interface/thread_safety_macros.h" + #include #include #include #include #include #include +#include +#include +#include namespace cms::Ort { using namespace ::Ort; + namespace { + + inline int64_t numel(const std::vector& dims) { + return std::accumulate(dims.begin(), dims.end(), int64_t{1}, std::multiplies()); + } + + inline bool hasDynamicDimsExceptBatch(const std::vector& dims) { + for (size_t i = 0; i < dims.size(); ++i) { + if (dims[i] == -1 && i != 0) { + return true; + } + } + return false; + } + + } // namespace + const Env ONNXRuntime::env_(ORT_LOGGING_LEVEL_ERROR, ""); ONNXRuntime::ONNXRuntime(const std::string& model_path, const SessionOptions* session_options) { @@ -84,87 +107,176 @@ namespace cms::Ort { return sess_opts; } - FloatArrays ONNXRuntime::run(const std::vector& input_names, - FloatArrays& input_values, - const std::vector>& input_shapes, - const std::vector& output_names, - int64_t batch_size) const { + void ONNXRuntime::runInto(const std::vector& input_names, + FloatArrays& input_values, + const std::vector>& input_shapes, + const std::vector& output_names, + FloatArrays& output_values, + const std::vector>& output_shapes, + int64_t batch_size) const { assert(input_names.size() == input_values.size()); assert(input_shapes.empty() || input_names.size() == input_shapes.size()); + assert(output_shapes.empty() || (!output_names.empty() && output_shapes.size() == output_names.size())); assert(batch_size > 0); + // Fast lookup input name -> position + std::unordered_map inputPos; + inputPos.reserve(input_names.size()); + for (size_t i = 0; i < input_names.size(); ++i) { + inputPos.emplace(input_names[i], i); + } + // create input tensor objects from data values std::vector input_tensors; + input_tensors.reserve(input_node_strings_.size()); + auto memory_info = MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); + for (const auto& name : input_node_strings_) { - auto iter = std::find(input_names.begin(), input_names.end(), name); - if (iter == input_names.end()) { + auto it = inputPos.find(name); + if (it == inputPos.end()) { throw cms::Exception("RuntimeError") << "Input " << name << " is not provided!"; } - auto input_pos = iter - input_names.begin(); - auto value = input_values.begin() + input_pos; - std::vector input_dims; + const size_t input_pos = it->second; + auto& value = input_values[input_pos]; - //Get input dimensions: use provided shapes if available, otherwise fall back to ONNX model defaults + // Get input dimensions: use provided shapes if available, otherwise fall back to ONNX model defaults const auto& onnx_dims = input_node_dims_.at(name); - input_dims = input_shapes.empty() ? onnx_dims : input_shapes[input_pos]; + std::vector input_dims = input_shapes.empty() ? onnx_dims : input_shapes[input_pos]; - // Check if the model expects a dynamic batch dimension (indicated by -1) + // Dynamic batch handling (-1 in dim0) const bool has_dynamic_batch = !onnx_dims.empty() && (onnx_dims[0] == -1); - if (has_dynamic_batch) { if (input_shapes.empty()) { - // No shapes provided then enforce the current batch size input_dims[0] = batch_size; } else if (input_dims[0] != batch_size) { - // Shapes provided but batch size mismatch then update global batch size batch_size = input_dims[0]; } } - auto expected_len = std::accumulate(input_dims.begin(), input_dims.end(), 1, std::multiplies()); - if (expected_len != (int64_t)value->size()) { + const int64_t expected_len = numel(input_dims); + if (expected_len != static_cast(value.size())) { throw cms::Exception("RuntimeError") - << "Input array " << name << " has a wrong size of " << value->size() << ", expected " << expected_len; + << "Input array " << name << " has a wrong size of " << value.size() << ", expected " << expected_len; } + auto input_tensor = - Value::CreateTensor(memory_info, value->data(), value->size(), input_dims.data(), input_dims.size()); + Value::CreateTensor(memory_info, value.data(), value.size(), input_dims.data(), input_dims.size()); assert(input_tensor.IsTensor()); input_tensors.emplace_back(std::move(input_tensor)); } - // set output node names; will get all outputs if `output_names` is not provided - std::vector run_output_node_names; + // Resolve output node names; will get all outputs if `output_names` is not provided + std::vector resolved_output_names; if (output_names.empty()) { - run_output_node_names = output_node_names_; + resolved_output_names = output_node_strings_; } else { - for (const auto& name : output_names) { - run_output_node_names.push_back(name.c_str()); + resolved_output_names = output_names; + } + + std::vector run_output_node_names; + run_output_node_names.reserve(resolved_output_names.size()); + for (const auto& n : resolved_output_names) { + run_output_node_names.push_back(n.c_str()); + } + + // Decide whether we can use the preallocated output path. + // - If caller provided output_shapes => always preallocated. + // - Otherwise => preallocated only if ALL outputs have no dynamic dims except batch. + bool need_fallback_allocation = false; + if (output_shapes.empty()) { + for (const auto& out_name : resolved_output_names) { + std::vector out_dims = getOutputShape(out_name); + if (!out_dims.empty() && out_dims[0] == -1) { + out_dims[0] = batch_size; + } + if (hasDynamicDimsExceptBatch(out_dims)) { + need_fallback_allocation = true; + break; + } } } - // run - auto output_tensors = session_->Run(RunOptions{nullptr}, - input_node_names_.data(), - input_tensors.data(), - input_tensors.size(), - run_output_node_names.data(), - run_output_node_names.size()); + if (need_fallback_allocation) { + // Fallback: let ORT allocate outputs, then copy into output_values (capacity reused across events). + auto ort_outputs = session_->Run(RunOptions{nullptr}, + input_node_names_.data(), + input_tensors.data(), + input_tensors.size(), + run_output_node_names.data(), + run_output_node_names.size()); - // convert output to floats - FloatArrays outputs; - for (auto& output_tensor : output_tensors) { - assert(output_tensor.IsTensor()); + output_values.resize(ort_outputs.size()); + + for (size_t i = 0; i < ort_outputs.size(); ++i) { + auto& out_tensor = ort_outputs[i]; + assert(out_tensor.IsTensor()); + + auto tensor_info = out_tensor.GetTensorTypeAndShapeInfo(); + const size_t length = static_cast(tensor_info.GetElementCount()); + + const float* data = out_tensor.GetTensorData(); + + auto& out_buf = output_values[i]; + out_buf.resize(length); + std::copy(data, data + length, out_buf.begin()); + } + return; + } + + // Preallocated path (output_shapes provided, or outputs are statically known except batch) + output_values.resize(resolved_output_names.size()); + + std::vector output_tensors; + output_tensors.reserve(resolved_output_names.size()); + + for (size_t i = 0; i < resolved_output_names.size(); ++i) { + const auto& out_name = resolved_output_names[i]; + + std::vector out_dims; + if (!output_shapes.empty()) { + out_dims = output_shapes[i]; + } else { + out_dims = getOutputShape(out_name); + if (!out_dims.empty() && out_dims[0] == -1) { + out_dims[0] = batch_size; + } + // safe here because need_fallback_allocation == false + } - // get output shape - auto tensor_info = output_tensor.GetTensorTypeAndShapeInfo(); - auto length = tensor_info.GetElementCount(); + const int64_t out_len = numel(out_dims); + if (out_len <= 0) { + throw cms::Exception("RuntimeError") << "Output " << out_name << " has invalid inferred size " << out_len; + } - auto floatarr = output_tensor.GetTensorMutableData(); - outputs.emplace_back(floatarr, floatarr + length); + auto& out_buf = output_values[i]; + if (static_cast(out_buf.capacity()) < out_len) { + out_buf.reserve(static_cast(out_len)); + } + out_buf.resize(static_cast(out_len)); + + auto out_tensor = + Value::CreateTensor(memory_info, out_buf.data(), out_buf.size(), out_dims.data(), out_dims.size()); + assert(out_tensor.IsTensor()); + output_tensors.emplace_back(std::move(out_tensor)); } - assert(outputs.size() == run_output_node_names.size()); + session_->Run(RunOptions{nullptr}, + input_node_names_.data(), + input_tensors.data(), + input_tensors.size(), + run_output_node_names.data(), + output_tensors.data(), + output_tensors.size()); + } + + FloatArrays ONNXRuntime::run(const std::vector& input_names, + FloatArrays& input_values, + const std::vector>& input_shapes, + const std::vector& output_names, + int64_t batch_size) const { + FloatArrays outputs; + runInto(input_names, input_values, input_shapes, output_names, outputs, {}, batch_size); return outputs; } diff --git a/RecoEcal/EgammaClusterProducers/python/particleFlowSuperClusteringSequence_cff.py b/RecoEcal/EgammaClusterProducers/python/particleFlowSuperClusteringSequence_cff.py index 53ddabd9cdf1e..28ef09056eb8f 100644 --- a/RecoEcal/EgammaClusterProducers/python/particleFlowSuperClusteringSequence_cff.py +++ b/RecoEcal/EgammaClusterProducers/python/particleFlowSuperClusteringSequence_cff.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms #------------------ -#Hybrid clustering: +# Hybrid clustering: #------------------ # Producer for Box Particle Flow Super Clusters from RecoEcal.EgammaClusterProducers.particleFlowSuperClusterECAL_cff import * diff --git a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py index d4c3da0848029..eb43f21d538c3 100644 --- a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py +++ b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py @@ -1,15 +1,13 @@ import FWCore.ParameterSet.Config as cms +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels +trackstersIters = ['keep *_'+iteration+'_*_*' for iteration in ticlIterLabelsPSet.labels] -trackstersIters = ['keep *_'+iteration+'_*_*' for iteration in ticlIterLabels] - -#AOD content TICL_AOD = cms.PSet( outputCommands = cms.untracked.vstring() - ) +) -#RECO content +# RECO content - Includes associations and intermediate steps TICL_RECO = cms.PSet( outputCommands = cms.untracked.vstring( trackstersIters + @@ -19,32 +17,23 @@ 'keep *_ticlTrackstersHFNoseTrk_*_*', 'keep *_ticlTrackstersHFNoseMIP_*_*', 'keep *_ticlTrackstersHFNoseHAD_*_*', - 'keep *_ticlTrackstersHFNoseMerge_*_*',] + - ['keep *_pfTICL_*_*'] + - ['keep CaloParticles_mix_*_*', 'keep SimClusters_mix_*_*', 'keep *_SimClusterToCaloParticleAssociation*_*_*'] + - ['keep *_SimClusterToCaloParticleAssociation*_*_*', 'keep *_layerClusterSimClusterAssociationProducer_*_*','keep *_layerClusterCaloParticleAssociationProducer_*_*', 'keep *_layerClusterSimTracksterAssociationProducer_*_*'] + - ['keep *_allTrackstersToSimTrackstersAssociations*_*_*'] - ) - ) - -TICLv5_RECO = cms.PSet( - outputCommands = cms.untracked.vstring( - [ - 'drop *_ticlTracksters*_*_*', - 'keep *_ticlTrackstersCLUE3DHigh_*_*', - 'keep *_ticlTracksterLinks*_*_*', - 'keep *_ticlTracksterLinksSuperclustering*_*_*', - 'keep *_ticlCandidate_*_*', - - ] + 'keep *_ticlTrackstersHFNoseMerge_*_*', + 'keep *_ticlCandidate_*_*', + 'keep *_ticlTracksterLinks*_*_*', + 'keep *_pfTICL_*_*', + 'keep CaloParticles_mix_*_*', + 'keep SimClusters_mix_*_*', + 'keep *_SimClusterToCaloParticleAssociation*_*_*', + 'keep *_layerClusterSimClusterAssociationProducer_*_*', + 'keep *_layerClusterCaloParticleAssociationProducer_*_*', + 'keep *_layerClusterSimTracksterAssociationProducer_*_*', + 'keep *_allTrackstersToSimTrackstersAssociations*_*_*' + ] ) ) - - TICL_RECO.outputCommands.extend(TICL_AOD.outputCommands) - -# FEVT Content +# FEVT Content - Full debug info TICL_FEVT = cms.PSet( outputCommands = cms.untracked.vstring( 'keep *_ticlSimTracksters_*_*', @@ -53,52 +42,25 @@ 'keep *_SimTau*_*_*', 'keep *_allTrackstersToSimTrackstersAssociations*_*_*' ) - ) +) TICL_FEVT.outputCommands.extend(TICL_RECO.outputCommands) -TICLv5_FEVT = cms.PSet( - outputCommands = cms.untracked.vstring( - 'keep *_ticlSimTracksters_*_*', - 'keep *_ticlSimTICLCandidates_*_*', - 'keep *_ticlSimTrackstersFromCP_*_*', - 'keep CaloParticles_mix_*_*', 'keep SimClusters_mix_*_*', 'keep *_SimClusterToCaloParticleAssociation*_*_*', - 'keep *_SimClusterToCaloParticleAssociation*_*_*', 'keep *_layerClusterSimClusterAssociationProducer_*_*','keep *_layerClusterCaloParticleAssociationProducer_*_*', 'keep *_layerClusterSimTracksterAssociationProducer_*_*', - 'keep *_SimTau*_*_*', - 'keep *_allTrackstersToSimTrackstersAssociations*_*_*' - - ) - ) - -TICLv5_FEVT.outputCommands.extend(TICLv5_RECO.outputCommands) +# HLT Content TICL_FEVTHLT = cms.PSet( outputCommands = cms.untracked.vstring( ['keep *_hltPfTICL_*_*', - 'keep *_hltTiclTracksters*_*_*', - 'keep *_hltTiclCandidate_*_*', - 'keep *_hltPfTICL_*_*',] - ) -) - -TICL_FEVTHLT.outputCommands.extend(TICL_FEVT.outputCommands) - -TICLv5_FEVTHLT = cms.PSet( - outputCommands = cms.untracked.vstring( - [ - 'drop *_hltTiclTracksters*_*_*', 'keep *_hltTiclTrackstersCLUE3D*_*_*', - 'keep *_hltTiclTracksterLinks_*_*', - 'keep *_hltTiclCandidate_*_*', - 'keep *_hltPfTICL_*_*', - ] + 'keep *_hltTiclTracksterLinks*_*_*', + 'keep *_hltTiclCandidate_*_*'] ) ) +TICL_FEVTHLT.outputCommands.extend(TICL_FEVT.outputCommands) -TICLv5_FEVTHLT.outputCommands.extend(TICLv5_FEVT.outputCommands) def customiseHGCalOnlyEventContent(process): - def cleanOutputAndSet(outputModule, ticl_outputCommads): + def cleanOutputAndSet(outputModule, ticl_outputCommands): outputModule.outputCommands = ['drop *_*_*_*'] - outputModule.outputCommands.extend(ticl_outputCommads) + outputModule.outputCommands.extend(ticl_outputCommands) outputModule.outputCommands.extend(['keep *_HGCalRecHit_*_*', 'keep *_hgcalMergeLayerClusters_*_*', 'keep CaloParticles_mix_*_*', @@ -124,18 +86,3 @@ def cleanOutputAndSet(outputModule, ticl_outputCommads): return process - - -def customiseForTICLv5EventContent(process): - def cleanOutputAndSet(outputModule, ticl_outputCommands): - outputModule.outputCommands.extend(ticl_outputCommands) - - if hasattr(process, 'FEVTDEBUGEventContent'): - cleanOutputAndSet(process.FEVTDEBUGEventContent, TICLv5_FEVT.outputCommands) - if hasattr(process, 'FEVTDEBUGHLToutput'): - cleanOutputAndSet(process.FEVTDEBUGHLToutput, TICLv5_FEVTHLT.outputCommands) - if hasattr(process, 'FEVTEventContent'): - cleanOutputAndSet(process.FEVTEventContent, TICLv5_FEVT.outputCommands) - - return process - diff --git a/RecoHGCal/TICL/BuildFile.xml b/RecoHGCal/TICL/BuildFile.xml index 75a12c12c5e41..8447f1381bac4 100644 --- a/RecoHGCal/TICL/BuildFile.xml +++ b/RecoHGCal/TICL/BuildFile.xml @@ -3,7 +3,6 @@ - diff --git a/RecoHGCal/TICL/interface/GlobalCache.h b/RecoHGCal/TICL/interface/GlobalCache.h deleted file mode 100644 index 99f0fb3d9f037..0000000000000 --- a/RecoHGCal/TICL/interface/GlobalCache.h +++ /dev/null @@ -1,29 +0,0 @@ -// Definition of objects placed in the edm::GlobalCache. - -#ifndef RecoHGCal_TICL_GlobalCache_H__ -#define RecoHGCal_TICL_GlobalCache_H__ - -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" - -namespace ticl { - // base class across ticl for objects hold in the edm::GlobalCache by plugins - class CacheBase { - public: - CacheBase(const edm::ParameterSet& params) {} - - virtual ~CacheBase() {} - }; - - // data structure hold by TrackstersProducer to store the TF graph for energy regression and ID - class TrackstersCache : public CacheBase { - public: - TrackstersCache(const edm::ParameterSet& params) : CacheBase(params), eidGraphDef(nullptr) {} - - ~TrackstersCache() override {} - - std::atomic eidGraphDef; - }; -} // namespace ticl - -#endif // RecoHGCal_TICL_GlobalCache_H__ diff --git a/RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h b/RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h index fd337ed71df29..26c34191e74b8 100644 --- a/RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h +++ b/RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h @@ -14,10 +14,9 @@ #include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/ValueMap.h" -#include "RecoHGCal/TICL/interface/GlobalCache.h" #include "DataFormats/HGCalReco/interface/Common.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" +#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" namespace edm { class Event; @@ -59,8 +58,14 @@ namespace ticl { const Inputs& input, std::unordered_map>& seedToTracksterAssociation) = 0; + virtual void setGeometry(hgcal::RecHitTools const& rhtools) = 0; + protected: int algo_verbosity_; + + bool geometryReady_ = false; + + hgcal::RecHitTools const* rhtools_ = nullptr; // non-owning, set in beginRun() }; } // namespace ticl diff --git a/RecoHGCal/TICL/interface/SuperclusteringDNNInputs.h b/RecoHGCal/TICL/interface/SuperclusteringDNNInputs.h index d822c284af439..92cd19e8ebd8a 100644 --- a/RecoHGCal/TICL/interface/SuperclusteringDNNInputs.h +++ b/RecoHGCal/TICL/interface/SuperclusteringDNNInputs.h @@ -6,6 +6,11 @@ // Changes: Implementation of the delta time feature under a new DNN input version (v3) for the superclustering DNN and correcting the seed pT calculation. // Date: 07/2025 +// Modified by Felice Pantaleo +// Improved memory usage and inference performance. +// Date: 02/2026 +// + #ifndef __RecoHGCal_TICL_SuperclusteringDNNInputs_H__ #define __RecoHGCal_TICL_SuperclusteringDNNInputs_H__ @@ -13,44 +18,46 @@ #include #include #include +#include +#include +#include namespace ticl { // any raw_dt outside +/- kDeltaTimeDefault is considered bad - static constexpr float kDeltaTimeDefault = 50.f; - static constexpr float kBadDeltaTime = -5.f; + inline constexpr float kDeltaTimeDefault = 50.f; + inline constexpr float kBadDeltaTime = -5.f; // Abstract base class for DNN input preparation. class AbstractSuperclusteringDNNInput { public: virtual ~AbstractSuperclusteringDNNInput() = default; - virtual unsigned int featureCount() const { return featureNames().size(); }; + virtual unsigned int featureCount() const = 0; - /** Get name of features. Used for SuperclusteringSampleDumper branch names (inference does not use the names, only the indices) - * The default implementation is meant to be overriden by inheriting classes - */ + /** Get name of features. Used for SuperclusteringSampleDumper branch names (inference does not use the names, only the indices) */ virtual std::vector featureNames() const { std::vector defaultNames; defaultNames.reserve(featureCount()); - for (unsigned int i = 1; i <= featureCount(); i++) { - defaultNames.push_back(std::string("nb_") + std::to_string(i)); + for (unsigned int i = 1; i <= featureCount(); ++i) { + defaultNames.emplace_back(std::string("nb_") + std::to_string(i)); } return defaultNames; } - /** Compute feature for seed and candidate pair */ - virtual std::vector computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) = 0; + /** Compute features for seed and candidate pair into user-provided buffer (size = featureCount()). */ + virtual void computeInto(Trackster const& ts_base, Trackster const& ts_toCluster, std::span out) const = 0; + + protected: + AbstractSuperclusteringDNNInput() = default; }; - /* First version of DNN by Alessandro Tarabini. Meant as a DNN equivalent of Mustache algorithm (superclustering algo in ECAL) - Uses features : ['DeltaEta', 'DeltaPhi', 'multi_en', 'multi_eta', 'multi_pt', 'seedEta','seedPhi','seedEn', 'seedPt'] - */ - class SuperclusteringDNNInputV1 : public AbstractSuperclusteringDNNInput { + class SuperclusteringDNNInputV1 final : public AbstractSuperclusteringDNNInput { public: - unsigned int featureCount() const override { return 9; } + static constexpr unsigned int kNFeatures = 9; + unsigned int featureCount() const override { return kNFeatures; } - std::vector computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) override; + void computeInto(Trackster const& ts_base, Trackster const& ts_toCluster, std::span out) const override; std::vector featureNames() const override { return {"DeltaEtaBaryc", @@ -65,14 +72,12 @@ namespace ticl { } }; - /* Second version of DNN by Alessandro Tarabini, making use of HGCAL-specific features. - Uses features : ['DeltaEta', 'DeltaPhi', 'multi_en', 'multi_eta', 'multi_pt', 'seedEta','seedPhi','seedEn', 'seedPt', 'theta', 'theta_xz_seedFrame', 'theta_yz_seedFrame', 'theta_xy_cmsFrame', 'theta_yz_cmsFrame', 'theta_xz_cmsFrame', 'explVar', 'explVarRatio'] - */ - class SuperclusteringDNNInputV2 : public AbstractSuperclusteringDNNInput { + class SuperclusteringDNNInputV2 final : public AbstractSuperclusteringDNNInput { public: - unsigned int featureCount() const override { return 17; } + static constexpr unsigned int kNFeatures = 17; + unsigned int featureCount() const override { return kNFeatures; } - std::vector computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) override; + void computeInto(Trackster const& ts_base, Trackster const& ts_toCluster, std::span out) const override; std::vector featureNames() const override { return {"DeltaEtaBaryc", @@ -95,15 +100,12 @@ namespace ticl { } }; - /* Third version of DNN by Gamze Sokmen and Shamik Ghosh, making use of time information as new variables. - Uses features : ['DeltaEta', 'DeltaPhi', 'multi_en', 'multi_eta', 'multi_pt', 'seedEta','seedPhi','seedEn', 'seedPt', theta', 'theta_xz_seedFrame', 'theta_yz_seedFrame', 'theta_xy_cmsFrame', 'theta_yz_cmsFrame', 'theta_xz_cmsFrame', 'explVar', 'explVarRatio', 'mod_deltaTime'] - */ - - class SuperclusteringDNNInputV3 : public AbstractSuperclusteringDNNInput { + class SuperclusteringDNNInputV3 final : public AbstractSuperclusteringDNNInput { public: - unsigned int featureCount() const override { return 18; } + static constexpr unsigned int kNFeatures = 18; + unsigned int featureCount() const override { return kNFeatures; } - std::vector computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) override; + void computeInto(Trackster const& ts_base, Trackster const& ts_toCluster, std::span out) const override; std::vector featureNames() const override { return {"DeltaEtaBaryc", @@ -128,6 +130,7 @@ namespace ticl { }; std::unique_ptr makeSuperclusteringDNNInputFromString(std::string dnnVersion); + } // namespace ticl #endif diff --git a/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h b/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h index 389b680af4f13..cb7a16719f272 100644 --- a/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h +++ b/RecoHGCal/TICL/interface/TICLInterpretationAlgoBase.h @@ -18,10 +18,8 @@ #include "TrackingTools/GeomPropagators/interface/Propagator.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" -#include "RecoHGCal/TICL/interface/GlobalCache.h" #include "DataFormats/HGCalReco/interface/Common.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/Common/interface/MultiSpan.h" #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" diff --git a/RecoHGCal/TICL/interface/TICLONNXGlobalCache.h b/RecoHGCal/TICL/interface/TICLONNXGlobalCache.h new file mode 100644 index 0000000000000..c6b7b5f19e8db --- /dev/null +++ b/RecoHGCal/TICL/interface/TICLONNXGlobalCache.h @@ -0,0 +1,95 @@ +#ifndef RecoHGCal_TICL_TICLONNXGlobalCache_h +#define RecoHGCal_TICL_TICLONNXGlobalCache_h + +#include +#include +#include + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/FileInPath.h" +#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" + +namespace ticl { + + struct TICLONNXGlobalCache { + // Sessions indexed by fully resolved path (FileInPath::fullPath()). + std::unordered_map> sessionsByFullPath; + + cms::Ort::ONNXRuntime const* getByFullPath(std::string const& fullPath) const noexcept { + const auto it = sessionsByFullPath.find(fullPath); + return (it == sessionsByFullPath.end()) ? nullptr : it->second.get(); + } + + cms::Ort::ONNXRuntime const* getByModelPathString(std::string const& modelPath) const { + if (modelPath.empty()) { + return nullptr; + } + return getByFullPath(edm::FileInPath(modelPath).fullPath()); + } + + // - Consider inference plugin only if inferenceAlgo is non-empty. + static std::unique_ptr initialize(edm::ParameterSet const& modulePSet) { + Ort::SessionOptions sess_opts; + sess_opts.SetIntraOpNumThreads(1); + sess_opts.SetInterOpNumThreads(1); + sess_opts.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL); + // Enable profiling if "profileOutputFile" is set in the module PSet. This will create a file with detailed timing info for each ONNX Runtime session run, which can be visualized with tools like + if (modulePSet.existsAs("profileOutputFile", /*trackPar=*/true)) { + const auto profileFile = modulePSet.getParameter("profileOutputFile"); + if (!profileFile.empty()) { + sess_opts.EnableProfiling(profileFile.c_str()); + } + } + sess_opts.EnableCpuMemArena(); + sess_opts.EnableMemPattern(); + auto cache = std::make_unique(); + + // 1) Linking model (TracksterLinksProducer / TracksterLinksProducer-like modules) + // Load only if present and non-empty. + if (modulePSet.existsAs("linkingPSet", /*trackPar=*/true)) { + const auto linkingPSet = modulePSet.getParameter("linkingPSet"); + cache->tryLoadSessionFromKey(linkingPSet, "onnxModelPath", sess_opts); + } + + // 2) Inference models (TrackstersProducer / TracksterLinksProducer when regressionAndPid) + const std::string inferenceAlgo = modulePSet.getParameter("inferenceAlgo"); + if (inferenceAlgo.empty()) { + // Inference disabled => do not scan anything else. + return cache; + } + + const std::string infPSetName = std::string{"pluginInferenceAlgo"} + inferenceAlgo; + if (!modulePSet.existsAs(infPSetName, /*trackPar=*/true)) { + // Misconfigured: inferenceAlgo set but corresponding PSet missing. + // Keep cache as-is; inference plugin construction will effectively disable inference. + return cache; + } + + const auto infPSet = modulePSet.getParameter(infPSetName); + + cache->tryLoadSessionFromKey(infPSet, "onnxModelPath", sess_opts); + cache->tryLoadSessionFromKey(infPSet, "onnxPIDModelPath", sess_opts); + cache->tryLoadSessionFromKey(infPSet, "onnxEnergyModelPath", sess_opts); + + return cache; + } + + private: + void tryLoadSessionFromKey(edm::ParameterSet const& pset, char const* key, Ort::SessionOptions const& sess_opts) { + if (!pset.existsAs(key, /*trackPar=*/true)) { + return; + } + const std::string model = pset.getParameter(key); + if (model.empty()) { + return; + } + + const std::string fullPath = edm::FileInPath(model).fullPath(); + + sessionsByFullPath.try_emplace(fullPath, std::make_unique(fullPath, &sess_opts)); + } + }; + +} // namespace ticl + +#endif diff --git a/RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h b/RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h index 298a6997bf7a7..210f2f64f4c7e 100644 --- a/RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h +++ b/RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h @@ -1,41 +1,51 @@ -// Author: Felice Pantaleo - felice.pantaleo@cern.ch -// Date: 07/2024 - #ifndef RecoHGCal_TICL_TracksterInferenceAlgo_H__ #define RecoHGCal_TICL_TracksterInferenceAlgo_H__ #include + +#include "DataFormats/CaloRecHit/interface/CaloCluster.h" #include "DataFormats/HGCalReco/interface/Trackster.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/CaloRecHit/interface/CaloCluster.h" -#include "DataFormats/HGCalReco/interface/TICLCandidate.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" -#include "FWCore/PluginManager/interface/PluginFactory.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" namespace ticl { + class TracksterInferenceAlgoBase { public: - explicit TracksterInferenceAlgoBase(const edm::ParameterSet& conf) - : algo_verbosity_(conf.getParameter("algo_verbosity")) {} - virtual ~TracksterInferenceAlgoBase() {} + struct OrtScratch { + // Reused buffers for ONNXRuntime::runInto() within one event. + cms::Ort::FloatArrays inputs; + cms::Ort::FloatArrays outputs; - virtual void inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) = 0; - virtual void runInference(std::vector& tracksters) = 0; - static void fillPSetDescription(edm::ParameterSetDescription& desc) { desc.add("algo_verbosity", 0); }; + // One shape entry per input tensor. + std::vector> input_shapes; + + void clearPerEvent() { + // Keep capacity within the event, reset logical sizes. + outputs.clear(); + } + }; + + explicit TracksterInferenceAlgoBase(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache) + : algo_verbosity_(conf.getParameter("algo_verbosity")), cache_(cache) {} + + virtual ~TracksterInferenceAlgoBase() = default; + + // Build minibatches internally. + virtual void runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const = 0; + + static void fillPSetDescription(edm::ParameterSetDescription& desc) { desc.add("algo_verbosity", 0); } protected: int algo_verbosity_; + TICLONNXGlobalCache const* cache_; }; + } // namespace ticl #endif diff --git a/RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h b/RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h index 9ad204ce647b3..4f16c08ac46ff 100644 --- a/RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h +++ b/RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h @@ -9,7 +9,8 @@ #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" -typedef edmplugin::PluginFactory +typedef edmplugin::PluginFactory TracksterInferenceAlgoFactory; #endif diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByANN.h b/RecoHGCal/TICL/interface/TracksterInferenceByANN.h deleted file mode 100644 index 7844b9ecf542b..0000000000000 --- a/RecoHGCal/TICL/interface/TracksterInferenceByANN.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RecoHGCal_TICL_TracksterInferenceByANN_H__ -#define RecoHGCal_TICL_TracksterInferenceByANN_H__ - -#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" - -namespace ticl { - class TracksterInferenceByANN : public TracksterInferenceAlgoBase { - public: - explicit TracksterInferenceByANN(const edm::ParameterSet& conf); - void inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) override; - void runInference(std::vector& tracksters) override; - - private: - const cms::Ort::ONNXRuntime* onnxPIDSession_; - const cms::Ort::ONNXRuntime* onnxEnergySession_; - }; -} // namespace ticl - -#endif diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByCNN.h b/RecoHGCal/TICL/interface/TracksterInferenceByCNN.h new file mode 100644 index 0000000000000..c9d21219f698e --- /dev/null +++ b/RecoHGCal/TICL/interface/TracksterInferenceByCNN.h @@ -0,0 +1,48 @@ +#ifndef RecoHGCal_TICL_interface_TracksterInferenceByCNN_h +#define RecoHGCal_TICL_interface_TracksterInferenceByCNN_h + +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" +#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" + +#include +#include + +namespace reco { + class CaloCluster; +} + +namespace hgcal { + class RecHitTools; +} + +namespace ticl { + + class TracksterInferenceByCNN : public TracksterInferenceAlgoBase { + public: + TracksterInferenceByCNN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache); + + static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + + void runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const override; + + private: + std::vector inputNames_; + std::vector outputNames_; + + double eidMinClusterEnergy_; + int eidNLayers_; + int eidNClusters_; + int doPID_; + int miniBatchSize_; + + cms::Ort::ONNXRuntime const* onnxSession_ = nullptr; + bool enabled_ = false; + + static constexpr int eidNFeatures_ = 3; + }; + +} // namespace ticl + +#endif diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByCNNv4.h b/RecoHGCal/TICL/interface/TracksterInferenceByCNNv4.h deleted file mode 100644 index 41b453a8e19e5..0000000000000 --- a/RecoHGCal/TICL/interface/TracksterInferenceByCNNv4.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RecoHGCal_TICL_TracksterInferenceByCNNv4_H__ -#define RecoHGCal_TICL_TracksterInferenceByCNNv4_H__ - -#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" -#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" - -namespace ticl { - - class TracksterInferenceByCNNv4 : public TracksterInferenceAlgoBase { - public: - explicit TracksterInferenceByCNNv4(const edm::ParameterSet& conf); - void inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) override; - void runInference(std::vector& tracksters) override; - - static void fillPSetDescription(edm::ParameterSetDescription& iDesc); - - private: - const cms::Ort::ONNXRuntime* onnxSession_; - - const std::string modelPath_; - const std::vector inputNames_; - const std::vector outputNames_; - const float eidMinClusterEnergy_; - const int eidNLayers_; - const int eidNClusters_; - static constexpr int eidNFeatures_ = 3; - int doPID_; - int doRegression_; - - std::vector> input_shapes_; - std::vector tracksterIndices_; - std::vector> input_Data_; - int batchSize_; - }; -} // namespace ticl - -#endif // RecoHGCal_TICL_TracksterInferenceByDNN_H__ diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByDNN.h b/RecoHGCal/TICL/interface/TracksterInferenceByDNN.h index 323afb4a77033..16d8698f74089 100644 --- a/RecoHGCal/TICL/interface/TracksterInferenceByDNN.h +++ b/RecoHGCal/TICL/interface/TracksterInferenceByDNN.h @@ -1,42 +1,48 @@ #ifndef RecoHGCal_TICL_TracksterInferenceByDNN_H__ #define RecoHGCal_TICL_TracksterInferenceByDNN_H__ +#include +#include + #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" +#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" + +// TracksterInferenceByDNN.h namespace ticl { - class TracksterInferenceByDNN : public TracksterInferenceAlgoBase { + class TracksterInferenceByDNN final : public TracksterInferenceAlgoBase { public: - explicit TracksterInferenceByDNN(const edm::ParameterSet& conf); - void inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) override; - void runInference(std::vector& tracksters) override; + explicit TracksterInferenceByDNN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache); + + void runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const override; static void fillPSetDescription(edm::ParameterSetDescription& iDesc); private: - const std::unique_ptr onnxPIDRuntimeInstance_; - const std::unique_ptr onnxEnergyRuntimeInstance_; - const cms::Ort::ONNXRuntime* onnxPIDSession_; - const cms::Ort::ONNXRuntime* onnxEnergySession_; + // Sessions are owned by the GlobalCache. + cms::Ort::ONNXRuntime const* onnxPIDSession_ = nullptr; + cms::Ort::ONNXRuntime const* onnxEnergySession_ = nullptr; 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_ = 3; - int doPID_; - int doRegression_; - std::vector> input_shapes_; - std::vector tracksterIndices_; - std::vector> input_Data_; - int batchSize_; + const int doPID_; + const int doRegression_; + const int miniBatchSize_; + bool enabled_ = false; }; + } // namespace ticl #endif // RecoHGCal_TICL_TracksterInferenceByDNN_H__ diff --git a/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h b/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h index 60fc6d8825295..0dcd0a5c9ab26 100644 --- a/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h +++ b/RecoHGCal/TICL/interface/TracksterInferenceByPFN.h @@ -1,42 +1,47 @@ #ifndef RecoHGCal_TICL_TracksterInferenceByPFN_H__ #define RecoHGCal_TICL_TracksterInferenceByPFN_H__ +#include + #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" +#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" + +// TracksterInferenceByPFN.h namespace ticl { - class TracksterInferenceByPFN : public TracksterInferenceAlgoBase { + class TracksterInferenceByPFN final : public TracksterInferenceAlgoBase { public: - explicit TracksterInferenceByPFN(const edm::ParameterSet& conf); - void inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) override; - void runInference(std::vector& tracksters) override; + explicit TracksterInferenceByPFN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache); + + void runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const override; static void fillPSetDescription(edm::ParameterSetDescription& iDesc); private: - const std::unique_ptr onnxPIDRuntimeInstance_; - const std::unique_ptr onnxEnergyRuntimeInstance_; - const cms::Ort::ONNXRuntime* onnxPIDSession_; - const cms::Ort::ONNXRuntime* onnxEnergySession_; + // Sessions are owned by the GlobalCache. + cms::Ort::ONNXRuntime const* onnxPIDSession_ = nullptr; + cms::Ort::ONNXRuntime const* onnxEnergySession_ = nullptr; 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_; - std::vector> input_shapes_; - std::vector tracksterIndices_; - std::vector> input_Data_; - int batchSize_; + const int doPID_; + const int doRegression_; + const int miniBatchSize_; + bool enabled_ = false; }; + } // namespace ticl #endif // RecoHGCal_TICL_TracksterInferenceByPFN_H__ diff --git a/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h b/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h index fd5e399aa8aa3..15a32dda78e80 100644 --- a/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h +++ b/RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h @@ -15,10 +15,8 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "DataFormats/Common/interface/ValueMap.h" -#include "RecoHGCal/TICL/interface/GlobalCache.h" #include "DataFormats/HGCalReco/interface/Common.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/Common/interface/MultiSpan.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "TrackingTools/GeomPropagators/interface/Propagator.h" diff --git a/RecoHGCal/TICL/plugins/BuildFile.xml b/RecoHGCal/TICL/plugins/BuildFile.xml index 7bd12c3249e67..84de9b2bc2e7e 100644 --- a/RecoHGCal/TICL/plugins/BuildFile.xml +++ b/RecoHGCal/TICL/plugins/BuildFile.xml @@ -21,7 +21,6 @@ - diff --git a/RecoHGCal/TICL/plugins/EGammaSuperclusterProducer.cc b/RecoHGCal/TICL/plugins/EGammaSuperclusterProducer.cc index d42bbf9fee24b..6a6f783322850 100644 --- a/RecoHGCal/TICL/plugins/EGammaSuperclusterProducer.cc +++ b/RecoHGCal/TICL/plugins/EGammaSuperclusterProducer.cc @@ -48,6 +48,15 @@ class EGammaSuperclusterProducer : public edm::stream::EDProducer>> superClusterLinksToken_; edm::EDGetTokenT ticlTrackstersEMToken_; edm::EDGetTokenT layerClustersToken_; + + // Reusable buffers to avoid per-event allocations/copies. + static constexpr unsigned int kRegressionFeatureCount = 8; + + cms::Ort::FloatArrays onnxInputs_; + cms::Ort::FloatArrays onnxOutputs_; + std::vector> onnxInputShapes_; + std::vector regressionInputs_; + float superclusterEtThreshold_; bool enableRegression_; }; @@ -62,11 +71,22 @@ EGammaSuperclusterProducer::EGammaSuperclusterProducer(const edm::ParameterSet& layerClustersToken_(consumes(ps.getParameter("layerClusters"))), superclusterEtThreshold_(ps.getParameter("superclusterEtThreshold")), enableRegression_(ps.getParameter("enableRegression")) { + if (enableRegression_) { + onnxInputs_.resize(1); + // rank-2: [batch, features] + onnxInputShapes_.assign(1, std::vector(2, 0)); + // Reserve a reasonable default; will be grown if needed. + regressionInputs_.reserve(1024u * kRegressionFeatureCount); + } produces(); produces(); // The CaloCluster corresponding to each EM trackster } void EGammaSuperclusterProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + if (enableRegression_ && UNLIKELY(globalCache() == nullptr)) { + throw cms::Exception("Configuration") + << "EGammaSuperclusterProducer: enableRegression=true but GlobalCache is null."; + } auto const& ticlSuperclusters = iEvent.get(ticlSuperClustersToken_); auto const& ticlSuperclusterLinks = iEvent.get(superClusterLinksToken_); auto emTracksters_h = iEvent.getHandle(ticlTrackstersEMToken_); @@ -103,15 +123,18 @@ void EGammaSuperclusterProducer::produce(edm::Event& iEvent, const edm::EventSet // Fill reco::SuperCluster collection and prepare regression inputs assert(ticlSuperclusters.size() == ticlSuperclusterLinks.size()); - const unsigned int regressionFeatureCount = 8; - std::vector regressionInputs; - regressionInputs.reserve(ticlSuperclusters.size() * regressionFeatureCount); + regressionInputs_.clear(); + regressionInputs_.reserve(ticlSuperclusters.size() * kRegressionFeatureCount); + unsigned int superclustersPassingSelectionsCount = 0; - for (std::size_t sc_i = 0; sc_i < ticlSuperclusters.size(); sc_i++) { - ticl::Trackster const& ticlSupercluster = ticlSuperclusters[sc_i]; - if (ticlSupercluster.raw_pt() < superclusterEtThreshold_) + + for (std::size_t sc_i = 0; sc_i < ticlSuperclusters.size(); ++sc_i) { + auto const& ticlSupercluster = ticlSuperclusters[sc_i]; + if (ticlSupercluster.raw_pt() < superclusterEtThreshold_) { continue; - std::vector const& superclusterLink = ticlSuperclusterLinks[sc_i]; + } + + auto const& superclusterLink = ticlSuperclusterLinks[sc_i]; assert(!superclusterLink.empty()); reco::CaloClusterPtrVector trackstersEMInSupercluster; @@ -137,35 +160,69 @@ void EGammaSuperclusterProducer::produce(edm::Event& iEvent, const edm::EventSet -1, // phiwidth (not implemented yet) -1 // etawidth (not implemented yet) ); - superclustersPassingSelectionsCount++; + ++superclustersPassingSelectionsCount; if (enableRegression_) { - regressionInputs.insert( - regressionInputs.end(), - {ticlSupercluster.barycenter().eta(), - ticlSupercluster.barycenter().phi(), - ticlSupercluster.raw_energy(), - std::abs(max_eta - min_eta), - max_phi - min_phi > M_PI ? 2 * static_cast(M_PI) - (max_phi - min_phi) : max_phi - min_phi, - emTracksters[superclusterLink[0]].raw_energy() - - (superclusterLink.size() >= 2 ? emTracksters[superclusterLink.back()].raw_energy() : 0.f), - emTracksters[superclusterLink[0]].raw_energy() / ticlSupercluster.raw_energy(), - static_cast(superclusterLink.size())}); + const auto& seedTs = emTracksters[superclusterLink[0]]; + const float lastE = (superclusterLink.size() >= 2) ? emTracksters[superclusterLink.back()].raw_energy() : 0.f; + + const float etaWidth = std::abs(max_eta - min_eta); + const float phiWidth = std::abs(deltaPhi(max_phi, min_phi)); + + const float seedMinusLastE = seedTs.raw_energy() - lastE; + const float seedFrac = seedTs.raw_energy() / ticlSupercluster.raw_energy(); + const float nTs = static_cast(superclusterLink.size()); + + const size_t base = regressionInputs_.size(); + regressionInputs_.resize(base + kRegressionFeatureCount); + + regressionInputs_[base + 0] = ticlSupercluster.barycenter().eta(); + regressionInputs_[base + 1] = ticlSupercluster.barycenter().phi(); + regressionInputs_[base + 2] = ticlSupercluster.raw_energy(); + regressionInputs_[base + 3] = etaWidth; + regressionInputs_[base + 4] = phiWidth; + regressionInputs_[base + 5] = seedMinusLastE; + regressionInputs_[base + 6] = seedFrac; + regressionInputs_[base + 7] = nTs; } } - if (enableRegression_ && superclustersPassingSelectionsCount > 0) { - // Run the regression - // ONNXRuntime takes std::vector>& as input (non-const reference) so we have to make a new vector - std::vector> inputs_for_onnx{{std::move(regressionInputs)}}; - std::vector outputs = - globalCache()->run({"input"}, inputs_for_onnx, {}, {}, superclustersPassingSelectionsCount)[0]; - - assert(egammaSuperclusters->size() == outputs.size()); - for (std::size_t sc_i = 0; sc_i < egammaSuperclusters->size(); sc_i++) { - (*egammaSuperclusters)[sc_i].setCorrectedEnergy(outputs[sc_i]); - // correctedEnergyUncertainty is left at its default value + if (enableRegression_ && superclustersPassingSelectionsCount > 0u) { + // shape: [batch, features] + onnxInputShapes_[0][0] = static_cast(superclustersPassingSelectionsCount); + onnxInputShapes_[0][1] = static_cast(kRegressionFeatureCount); + + // Hand buffer ownership to ONNXRuntime without realloc/copy. + onnxInputs_[0].swap(regressionInputs_); + + onnxOutputs_.clear(); + static const std::vector kInputNames = {"input"}; + globalCache()->runInto(kInputNames, + onnxInputs_, + onnxInputShapes_, + {}, // all outputs + onnxOutputs_, // resized as needed + {}, // optional output shapes + static_cast(superclustersPassingSelectionsCount)); + + if (onnxOutputs_.empty()) { + throw cms::Exception("RuntimeError") << "Regression model returned no outputs."; } + + auto const& out = onnxOutputs_[0]; + if (out.size() < egammaSuperclusters->size()) { + throw cms::Exception("RuntimeError") + << "Regression output size " << out.size() << " smaller than number of produced superclusters " + << egammaSuperclusters->size(); + } + + for (std::size_t i = 0; i < egammaSuperclusters->size(); ++i) { + (*egammaSuperclusters)[i].setCorrectedEnergy(out[i]); + } + + // Restore buffer for reuse. + regressionInputs_.swap(onnxInputs_[0]); + regressionInputs_.clear(); } iEvent.put(std::move(egammaSuperclusters)); diff --git a/RecoHGCal/TICL/plugins/PFTICLProducer.cc b/RecoHGCal/TICL/plugins/PFTICLProducer.cc index 1fb3ae06c9ad9..fc196684755f3 100644 --- a/RecoHGCal/TICL/plugins/PFTICLProducer.cc +++ b/RecoHGCal/TICL/plugins/PFTICLProducer.cc @@ -30,7 +30,6 @@ class PFTICLProducer : public edm::stream::EDProducer<> { const bool useTimingAverage_; const float timingQualityThreshold_; const bool energy_from_regression_; - const bool isTICLv5_; // inputs const edm::EDGetTokenT> ticl_candidates_; edm::EDGetTokenT> srcTrackTime_, srcTrackTimeError_, srcTrackTimeQuality_; @@ -46,29 +45,22 @@ PFTICLProducer::PFTICLProducer(const edm::ParameterSet& conf) useTimingAverage_(conf.getParameter("useTimingAverage")), timingQualityThreshold_(conf.getParameter("timingQualityThreshold")), energy_from_regression_(conf.getParameter("energyFromRegression")), - isTICLv5_(conf.getParameter("isTICLv5")), ticl_candidates_(consumes>(conf.getParameter("ticlCandidateSrc"))), muons_(consumes(conf.getParameter("muonSrc"))), pfmu_(std::make_unique(conf.getParameterSet("pfMuonAlgoParameters"), false)) { // postMuonCleaning = false - if (not isTICLv5_) { - srcTrackTime_ = consumes>(conf.getParameter("trackTimeValueMap")); - srcTrackTimeError_ = consumes>(conf.getParameter("trackTimeErrorMap")); - srcTrackTimeQuality_ = consumes>(conf.getParameter("trackTimeQualityMap")); - } produces(); } void PFTICLProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("ticlCandidateSrc", edm::InputTag("ticlTrackstersMerge")); + desc.add("ticlCandidateSrc", edm::InputTag("ticlCandidate")); desc.add("trackTimeValueMap", edm::InputTag("tofPID:t0")); desc.add("trackTimeErrorMap", edm::InputTag("tofPID:sigmat0")); desc.add("trackTimeQualityMap", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA")); desc.add("energyFromRegression", true); desc.add("timingQualityThreshold", 0.5); desc.add("useMTDTiming", true); - desc.add("isTICLv5", false); desc.add("useTimingAverage", false); // For PFMuonAlgo desc.add("muonSrc", edm::InputTag("muons1stStep")); @@ -85,11 +77,6 @@ void PFTICLProducer::produce(edm::Event& evt, const edm::EventSetup& es) { evt.getByToken(ticl_candidates_, ticl_cand_h); const auto ticl_candidates = *ticl_cand_h; edm::Handle> trackTimeH, trackTimeErrH, trackTimeQualH; - if (not isTICLv5_) { - evt.getByToken(srcTrackTime_, trackTimeH); - evt.getByToken(srcTrackTimeError_, trackTimeErrH); - evt.getByToken(srcTrackTimeQuality_, trackTimeQualH); - } const auto muonH = evt.getHandle(muons_); const auto& muons = *muonH; @@ -146,19 +133,10 @@ void PFTICLProducer::produce(edm::Event& evt, const edm::EventSetup& es) { candidate.setTrackRef(trackref); // Utilize PFMuonAlgo const int muId = PFMuonAlgo::muAssocToTrack(trackref, muons); - if (isTICLv5_) { - if (muId != -1) { - const reco::MuonRef muonref = reco::MuonRef(muonH, muId); - if ((PFMuonAlgo::isMuon(muonref) and not(*muonH)[muId].isTrackerMuon()) or - (ticl_cand.tracksters().empty() and muonref.isNonnull() and muonref->isGlobalMuon())) { - const bool allowLoose = (part_type == reco::PFCandidate::mu); - // Redefine pfmuon candidate kinematics and add muonref - pfmu_->reconstructMuon(candidate, muonref, allowLoose); - } - } - } else { - if (muId != -1) { - const reco::MuonRef muonref = reco::MuonRef(muonH, muId); + if (muId != -1) { + const reco::MuonRef muonref = reco::MuonRef(muonH, muId); + if ((PFMuonAlgo::isMuon(muonref) and not(*muonH)[muId].isTrackerMuon()) or + (ticl_cand.tracksters().empty() and muonref.isNonnull() and muonref->isGlobalMuon())) { const bool allowLoose = (part_type == reco::PFCandidate::mu); // Redefine pfmuon candidate kinematics and add muonref pfmu_->reconstructMuon(candidate, muonref, allowLoose); @@ -166,40 +144,7 @@ void PFTICLProducer::produce(edm::Event& evt, const edm::EventSetup& es) { } } - if (isTICLv5_) { - candidate.setTime(ticl_cand.time(), ticl_cand.timeError()); - } else { - // HGCAL timing as default values - auto time = ticl_cand.time(); - auto timeE = ticl_cand.timeError(); - - if (useMTDTiming_ and candidate.charge()) { - // Ignore HGCAL timing until it will be TOF corrected - time = -99.; - timeE = -1.; - // Check MTD timing availability - const bool assocQuality = (*trackTimeQualH)[candidate.trackRef()] > timingQualityThreshold_; - if (assocQuality) { - const auto timeHGC = time; - const auto timeEHGC = timeE; - const auto timeMTD = (*trackTimeH)[candidate.trackRef()]; - const auto timeEMTD = (*trackTimeErrH)[candidate.trackRef()]; - - if (useTimingAverage_ && (timeEMTD > 0 && timeEHGC > 0)) { - // Compute weighted average between HGCAL and MTD timing - const auto invTimeESqHGC = pow(timeEHGC, -2); - const auto invTimeESqMTD = pow(timeEMTD, -2); - timeE = 1.f / (invTimeESqHGC + invTimeESqMTD); - time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeE; - timeE = sqrt(timeE); - } else if (timeEMTD > 0) { // Ignore HGCal timing until it will be TOF corrected - time = timeMTD; - timeE = timeEMTD; - } - } - } - candidate.setTime(time, timeE); - } + candidate.setTime(ticl_cand.time(), ticl_cand.timeError()); } evt.put(std::move(candidates)); diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h b/RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h index 2b6308a216085..4dd9fb98d21d4 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h +++ b/RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h @@ -5,7 +5,6 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" -#include "RecoHGCal/TICL/interface/GlobalCache.h" typedef edmplugin::PluginFactory*(const edm::ParameterSet&, edm::ConsumesCollector)> diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.cc b/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.cc index c303849b7a8ab..9eb05efbbbed0 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.cc +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.cc @@ -9,8 +9,6 @@ #include "PatternRecognitionbyCA.h" #include "TrackstersPCA.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "FWCore/Framework/interface/EventSetup.h" using namespace ticl; @@ -18,7 +16,6 @@ using namespace ticl; template PatternRecognitionbyCA::PatternRecognitionbyCA(const edm::ParameterSet &conf, edm::ConsumesCollector iC) : PatternRecognitionAlgoBaseT(conf, iC), - caloGeomToken_(iC.esConsumes()), theGraph_(std::make_unique>()), oneTracksterPerTrackSeed_(conf.getParameter("oneTracksterPerTrackSeed")), promoteEmptyRegionToTrackster_(conf.getParameter("promoteEmptyRegionToTrackster")), @@ -46,6 +43,11 @@ PatternRecognitionbyCA::PatternRecognitionbyCA(const edm::ParameterSet &c template PatternRecognitionbyCA::~PatternRecognitionbyCA(){}; +template +void PatternRecognitionbyCA::setGeometry(hgcal::RecHitTools const &rhtools) { + this->rhtools_ = &rhtools; + this->geometryReady_ = true; +} template void PatternRecognitionbyCA::makeTracksters( const typename PatternRecognitionAlgoBaseT::Inputs &input, @@ -55,9 +57,12 @@ void PatternRecognitionbyCA::makeTracksters( if (input.regions.empty()) return; - edm::EventSetup const &es = input.es; - const CaloGeometry &geom = es.getData(caloGeomToken_); - rhtools_.setGeometry(geom); + if (UNLIKELY(!this->geometryReady_ || this->rhtools_ == nullptr)) { + throw cms::Exception("LogicError") + << "PatternRecognitionbyCA::setGeometry() must be called in beginRun() before makeTracksters()."; + } + + auto const *rhtools = this->rhtools_; theGraph_->setVerbosity(PatternRecognitionAlgoBaseT::algo_verbosity_); theGraph_->clear(); @@ -86,10 +91,10 @@ void PatternRecognitionbyCA::makeTracksters( root_doublet_max_distance_from_seed_squared_, etaLimitIncreaseWindow_, skip_layers_, - rhtools_.lastLayer(isHFnose), + rhtools->lastLayer(isHFnose), max_delta_time_, - rhtools_.lastLayerEE(isHFnose), - rhtools_.lastLayerFH(), + rhtools->lastLayerEE(isHFnose), + rhtools->lastLayerFH(), siblings_maxRSquared_); theGraph_->findNtuplets(foundNtuplets, seedIndices, min_clusters_per_ntuplet_, out_in_dfs_, max_out_in_hops_); @@ -129,7 +134,7 @@ void PatternRecognitionbyCA::makeTracksters( lcIdAndLayer.reserve(effective_cluster_idx.size()); for (auto const i : effective_cluster_idx) { auto const &haf = input.layerClusters[i].hitsAndFractions(); - auto layerId = rhtools_.getLayerWithOffset(haf[0].first); + auto layerId = rhtools->getLayerWithOffset(haf[0].first); showerMinLayerId = std::min(layerId, showerMinLayerId); uniqueLayerIds.push_back(layerId); lcIdAndLayer.emplace_back(i, layerId); @@ -175,8 +180,8 @@ void PatternRecognitionbyCA::makeTracksters( ticl::assignPCAtoTracksters(result, input.layerClusters, input.layerClustersTime, - rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(), - rhtools_, + rhtools->getPositionLayer(rhtools->lastLayerEE(isHFnose), isHFnose).z(), + *rhtools, computeLocalTime_); theGraph_->clear(); @@ -294,7 +299,7 @@ void PatternRecognitionbyCA::fillPSetDescription(edm::ParameterSetDescrip ->setComment("make default such that no filtering is applied"); iDesc.add("max_longitudinal_sigmaPCA", 9999); iDesc.add("max_delta_time", 3.)->setComment("nsigma"); - iDesc.add("computeLocalTime", false); + iDesc.add("computeLocalTime", true); iDesc.add>("siblings_maxRSquared", {6e-4, 6e-4, 6e-4}); } diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.h b/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.h index 0a4eed44f0680..24bc6c818466b 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.h +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyCA.h @@ -4,9 +4,9 @@ #ifndef __RecoHGCal_TICL_PRbyCA_H__ #define __RecoHGCal_TICL_PRbyCA_H__ #include // unique_ptr +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "HGCGraph.h" namespace ticl { @@ -25,21 +25,18 @@ namespace ticl { const typename PatternRecognitionAlgoBaseT::Inputs& input, std::unordered_map>& seedToTracksterAssociation) override; - void energyRegressionAndID(const std::vector& layerClusters, - const tensorflow::Session*, - std::vector& result); void emptyTrackstersFromSeedsTRK(std::vector& tracksters, std::unordered_map>& seedToTracksterAssociation, const edm::ProductID& collectionID) const; static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + void setGeometry(hgcal::RecHitTools const& rhtools) override; private: void mergeTrackstersTRK(const std::vector&, const std::vector&, std::vector&, std::unordered_map>& seedToTracksterAssociation) const; - edm::ESGetToken caloGeomToken_; const std::unique_ptr> theGraph_; const bool oneTracksterPerTrackSeed_; const bool promoteEmptyRegionToTrackster_; @@ -64,8 +61,6 @@ namespace ticl { const std::string eidOutputNameEnergy_; const std::string eidOutputNameId_; const bool computeLocalTime_; - - hgcal::RecHitTools rhtools_; const std::vector siblings_maxRSquared_; }; diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.cc b/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.cc index e55e463129cd4..abd5e3a9427af 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.cc +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.cc @@ -11,8 +11,6 @@ #include "PatternRecognitionbyCLUE3D.h" #include "TrackstersPCA.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "FWCore/Framework/interface/EventSetup.h" using namespace ticl; @@ -20,7 +18,6 @@ using namespace ticl; template PatternRecognitionbyCLUE3D::PatternRecognitionbyCLUE3D(const edm::ParameterSet &conf, edm::ConsumesCollector iC) : PatternRecognitionAlgoBaseT(conf, iC), - caloGeomToken_(iC.esConsumes()), criticalDensity_(conf.getParameter>("criticalDensity")), criticalSelfDensity_(conf.getParameter>("criticalSelfDensity")), densitySiblingLayers_(conf.getParameter>("densitySiblingLayers")), @@ -45,7 +42,7 @@ template void PatternRecognitionbyCLUE3D::dumpTiles(const TILES &tiles) const { constexpr int nEtaBin = TILES::constants_type_t::nEtaBins; constexpr int nPhiBin = TILES::constants_type_t::nPhiBins; - auto lastLayerPerSide = static_cast(rhtools_.lastLayer(false)); + auto lastLayerPerSide = static_cast(this->rhtools_->lastLayer(false)); int maxLayer = 2 * lastLayerPerSide - 1; for (int layer = 0; layer <= maxLayer; layer++) { for (int ieta = 0; ieta < nEtaBin; ieta++) { @@ -144,6 +141,23 @@ void PatternRecognitionbyCLUE3D::dumpClusters(const TILES &tiles, } } +template +void PatternRecognitionbyCLUE3D::setGeometry(hgcal::RecHitTools const &rhtools) { + // Non-owning pointer: valid because TrackstersProducer owns rhtools_ for the module lifetime (per stream). + this->rhtools_ = &rhtools; + + layersPosZ_.clear(); + const unsigned int nLayers = this->rhtools_->lastLayer(); + layersPosZ_.reserve(nLayers); + + // Layers inside the HGCAL geometry start from 1. + for (unsigned int i = 0; i < nLayers; ++i) { + layersPosZ_.push_back(static_cast(this->rhtools_->getPositionLayer(i + 1).z())); + } + + this->geometryReady_ = true; +} + template void PatternRecognitionbyCLUE3D::makeTracksters( const typename PatternRecognitionAlgoBaseT::Inputs &input, @@ -153,28 +167,22 @@ void PatternRecognitionbyCLUE3D::makeTracksters( if (input.regions.empty()) return; - const int eventNumber = input.ev.eventAuxiliary().event(); + int eventNumber = -1; if (PatternRecognitionAlgoBaseT::algo_verbosity_ > VerbosityLevel::Advanced) { edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "New Event"; + eventNumber = input.ev.eventAuxiliary().event(); } + auto const *rhtools = this->rhtools_; - edm::EventSetup const &es = input.es; - const CaloGeometry &geom = es.getData(caloGeomToken_); - rhtools_.setGeometry(geom); - - // Assume identical Z-positioning between positive and negative sides. - // Also, layers inside the HGCAL geometry start from 1. - for (unsigned int i = 0; i < rhtools_.lastLayer(); ++i) { - layersPosZ_.push_back(rhtools_.getPositionLayer(i + 1).z()); - if (PatternRecognitionAlgoBaseT::algo_verbosity_ > VerbosityLevel::Advanced) { - edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Layer " << i << " located at Z: " << layersPosZ_.back(); - } + if (UNLIKELY(!this->geometryReady_ || rhtools == nullptr)) { + throw cms::Exception("LogicError") + << "PatternRecognitionbyCLUE3D::setGeometry() must be called in beginRun() before makeTracksters()."; } clusters_.clear(); tracksterSeedAlgoId_.clear(); - clusters_.resize(2 * rhtools_.lastLayer(false)); + clusters_.resize(2 * rhtools->lastLayer(false)); std::vector> layerIdx2layerandSoa; //used everywhere also to propagate cluster masking layerIdx2layerandSoa.reserve(input.layerClusters.size()); @@ -189,8 +197,8 @@ void PatternRecognitionbyCLUE3D::makeTracksters( continue; } const auto firstHitDetId = lc.hitsAndFractions()[0].first; - int layer = rhtools_.getLayerWithOffset(firstHitDetId) - 1 + - rhtools_.lastLayer(false) * ((rhtools_.zside(firstHitDetId) + 1) >> 1); + int layer = rhtools->getLayerWithOffset(firstHitDetId) - 1 + + rhtools->lastLayer(false) * ((rhtools->zside(firstHitDetId) + 1) >> 1); assert(layer >= 0); auto detId = lc.hitsAndFractions()[0].first; int layerClusterIndexInLayer = clusters_[layer].x.size(); @@ -203,7 +211,7 @@ void PatternRecognitionbyCLUE3D::makeTracksters( float ref_y = lc.y(); float invClsize = 1. / lc.hitsAndFractions().size(); for (auto const &hitsAndFractions : lc.hitsAndFractions()) { - auto const &point = rhtools_.getPosition(hitsAndFractions.first); + auto const &point = rhtools->getPosition(hitsAndFractions.first); sum_x += point.x() - ref_x; sum_sqr_x += (point.x() - ref_x) * (point.x() - ref_x); sum_y += point.y() - ref_y; @@ -227,15 +235,15 @@ void PatternRecognitionbyCLUE3D::makeTracksters( if (invClsize == 1.) { // Silicon case - if (rhtools_.isSilicon(detId)) { - radius_x = radius_y = rhtools_.getRadiusToSide(detId); + if (rhtools->isSilicon(detId)) { + radius_x = radius_y = rhtools->getRadiusToSide(detId); if (PatternRecognitionAlgoBaseT::algo_verbosity_ > VerbosityLevel::Advanced) { edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Single cell cluster in silicon, rx: " << std::setw(5) << radius_x << ", ry: " << std::setw(5) << radius_y; } } else { - auto const &point = rhtools_.getPosition(detId); - auto const &eta_phi_window = rhtools_.getScintDEtaDPhi(detId); + auto const &point = rhtools->getPosition(detId); + auto const &eta_phi_window = rhtools->getScintDEtaDPhi(detId); radius_x = radius_y = point.perp() * eta_phi_window.second; if (PatternRecognitionAlgoBaseT::algo_verbosity_ > VerbosityLevel::Advanced) { edm::LogVerbatim("PatternRecognitionbyCLUE3D") @@ -256,7 +264,7 @@ void PatternRecognitionbyCLUE3D::makeTracksters( clusters_[layer].phi.emplace_back(lc.phi()); clusters_[layer].cells.push_back(lc.hitsAndFractions().size()); clusters_[layer].algoId.push_back(lc.algo() - reco::CaloCluster::hgcal_em); - clusters_[layer].isSilicon.push_back(rhtools_.isSilicon(detId)); + clusters_[layer].isSilicon.push_back(rhtools->isSilicon(detId)); clusters_[layer].energy.emplace_back(lc.energy()); clusters_[layer].isSeed.push_back(false); clusters_[layer].clusterIndex.emplace_back(-1); @@ -271,7 +279,7 @@ void PatternRecognitionbyCLUE3D::makeTracksters( clusters_[layer].followers.resize(clusters_[layer].x.size()); } - auto lastLayerPerSide = static_cast(rhtools_.lastLayer(false)); + auto lastLayerPerSide = static_cast(rhtools->lastLayer(false)); int maxLayer = 2 * lastLayerPerSide - 1; std::vector numberOfClustersPerLayer(maxLayer, 0); for (int i = 0; i <= maxLayer; i++) { @@ -329,8 +337,8 @@ void PatternRecognitionbyCLUE3D::makeTracksters( ticl::assignPCAtoTracksters(result, input.layerClusters, input.layerClustersTime, - rhtools_.getPositionLayer(rhtools_.lastLayerEE(false), false).z(), - rhtools_, + rhtools->getPositionLayer(rhtools->lastLayerEE(false), false).z(), + *rhtools, computeLocalTime_, true, // energy weighting usePCACleaning_); @@ -396,7 +404,7 @@ void PatternRecognitionbyCLUE3D::calculateLocalDensity( for (unsigned int i = 0; i < numberOfClusters; i++) { auto algoId = clustersOnLayer.algoId[i]; // We need to partition the two sides of the HGCAL detector - auto lastLayerPerSide = static_cast(rhtools_.lastLayer(false)); + auto lastLayerPerSide = static_cast(this->rhtools_->lastLayer(false)); int minLayer = 0; int maxLayer = 2 * lastLayerPerSide - 1; if (layerId < lastLayerPerSide) { @@ -564,7 +572,7 @@ void PatternRecognitionbyCLUE3D::calculateDistanceToHigher( << tiles[layerId].phiBin(clustersOnLayer.phi[i]); } // We need to partition the two sides of the HGCAL detector - auto lastLayerPerSide = static_cast(rhtools_.lastLayer(false)); + auto lastLayerPerSide = static_cast(this->rhtools_->lastLayer(false)); int minLayer = 0; int maxLayer = 2 * lastLayerPerSide - 1; auto algoId = clustersOnLayer.algoId[i]; @@ -657,7 +665,7 @@ int PatternRecognitionbyCLUE3D::findAndAssignTracksters( const auto &critical_transverse_distance = useAbsoluteProjectiveScale_ ? criticalXYDistance_ : criticalEtaPhiDistance_; // find cluster seeds and outlier - for (unsigned int layer = 0; layer < 2 * rhtools_.lastLayer(); layer++) { + for (unsigned int layer = 0; layer < 2 * this->rhtools_->lastLayer(); layer++) { auto &clustersOnLayer = clusters_[layer]; unsigned int numberOfClusters = clustersOnLayer.x.size(); for (unsigned int i = 0; i < numberOfClusters; i++) { @@ -761,8 +769,8 @@ void PatternRecognitionbyCLUE3D::fillPSetDescription(edm::ParameterSetDes iDesc.add>("minNumLayerCluster", {2, 2, 2})->setComment("Not Inclusive"); iDesc.add("doPidCut", false); iDesc.add("cutHadProb", 0.5); - iDesc.add("computeLocalTime", false); - iDesc.add("usePCACleaning", false)->setComment("Enable PCA cleaning alorithm"); + iDesc.add("computeLocalTime", true); + iDesc.add("usePCACleaning", true)->setComment("Enable PCA cleaning algorithm"); } template class ticl::PatternRecognitionbyCLUE3D; diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.h b/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.h index fa907ad6a6eef..1d0a79f43eb1a 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.h +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyCLUE3D.h @@ -4,6 +4,7 @@ #ifndef __RecoHGCal_TICL_PRbyCLUE3D_H__ #define __RecoHGCal_TICL_PRbyCLUE3D_H__ #include // unique_ptr +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" @@ -23,11 +24,8 @@ namespace ticl { const typename PatternRecognitionAlgoBaseT::Inputs& input, std::unordered_map>& seedToTracksterAssociation) override; - void energyRegressionAndID(const std::vector& layerClusters, - const tensorflow::Session*, - std::vector& result); - static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + void setGeometry(hgcal::RecHitTools const& rhtools) override; private: struct ClustersOnLayer { @@ -116,10 +114,9 @@ namespace ticl { void dumpTiles(const TILES&) const; std::vector clusters_; - std::vector layersPosZ_; + std::vector layersPosZ_; // cached once per run/IOV std::vector tracksterSeedAlgoId_; - edm::ESGetToken caloGeomToken_; const std::vector criticalDensity_; const std::vector criticalSelfDensity_; const std::vector densitySiblingLayers_; @@ -141,8 +138,6 @@ namespace ticl { const std::vector filter_on_categories_; const bool computeLocalTime_; const bool usePCACleaning_; - - hgcal::RecHitTools rhtools_; }; } // namespace ticl diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.cc b/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.cc index 957abb847c0cb..50f65aea55140 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.cc +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.cc @@ -16,8 +16,6 @@ #include "PatternRecognitionbyFastJet.h" #include "TrackstersPCA.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "FWCore/Framework/interface/EventSetup.h" #include "fastjet/ClusterSequence.hh" @@ -29,11 +27,16 @@ template PatternRecognitionbyFastJet::PatternRecognitionbyFastJet(const edm::ParameterSet &conf, edm::ConsumesCollector iC) : PatternRecognitionAlgoBaseT(conf, iC), - caloGeomToken_(iC.esConsumes()), antikt_radius_(conf.getParameter("antikt_radius")), minNumLayerCluster_(conf.getParameter("minNumLayerCluster")), computeLocalTime_(conf.getParameter("computeLocalTime")){}; +template +void PatternRecognitionbyFastJet::setGeometry(hgcal::RecHitTools const &rhtools) { + this->rhtools_ = &rhtools; + this->geometryReady_ = true; +} + template void PatternRecognitionbyFastJet::buildJetAndTracksters(std::vector &fjInputs, std::vector &result) { @@ -84,16 +87,18 @@ void PatternRecognitionbyFastJet::makeTracksters( if (input.regions.empty()) return; - edm::EventSetup const &es = input.es; - const CaloGeometry &geom = es.getData(caloGeomToken_); - rhtools_.setGeometry(geom); + auto const *rhtools = this->rhtools_; + if (UNLIKELY(!this->geometryReady_ || rhtools == nullptr)) { + throw cms::Exception("LogicError") + << "PatternRecognitionbyFastJet::setGeometry() must be called in beginRun() before makeTracksters()."; + } constexpr auto isHFnose = std::is_same::value; constexpr int nEtaBin = TILES::constants_type_t::nEtaBins; constexpr int nPhiBin = TILES::constants_type_t::nPhiBins; // We need to partition the two sides of the HGCAL detector - auto lastLayerPerSide = static_cast(rhtools_.lastLayer(isHFnose)) - 1; + auto lastLayerPerSide = static_cast(rhtools->lastLayer(isHFnose)) - 1; unsigned int maxLayer = 2 * lastLayerPerSide - 1; std::vector fjInputs; fjInputs.clear(); @@ -139,8 +144,8 @@ void PatternRecognitionbyFastJet::makeTracksters( ticl::assignPCAtoTracksters(result, input.layerClusters, input.layerClustersTime, - rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(), - rhtools_, + rhtools->getPositionLayer(rhtools->lastLayerEE(isHFnose), isHFnose).z(), + *rhtools, computeLocalTime_); // run energy regression and ID @@ -167,7 +172,7 @@ void PatternRecognitionbyFastJet::fillPSetDescription(edm::ParameterSetDe iDesc.add("algo_verbosity", 0); iDesc.add("antikt_radius", 0.09)->setComment("Radius to be used while running the Anti-kt clustering"); iDesc.add("minNumLayerCluster", 5)->setComment("Not Inclusive"); - iDesc.add("computeLocalTime", false); + iDesc.add("computeLocalTime", true); } template class ticl::PatternRecognitionbyFastJet; diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.h b/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.h index bfc10ea26e9d3..5c2c54207b2f2 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.h +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyFastJet.h @@ -4,6 +4,7 @@ #ifndef __RecoHGCal_TICL_PRbyFASTJET_H__ #define __RecoHGCal_TICL_PRbyFASTJET_H__ #include // unique_ptr +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" @@ -29,20 +30,14 @@ namespace ticl { const typename PatternRecognitionAlgoBaseT::Inputs& input, std::unordered_map>& seedToTracksterAssociation) override; - void energyRegressionAndID(const std::vector& layerClusters, - const tensorflow::Session*, - std::vector& result); - static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + void setGeometry(hgcal::RecHitTools const& rhtools) override; private: - edm::ESGetToken caloGeomToken_; const double antikt_radius_; const int minNumLayerCluster_; const bool computeLocalTime_; - hgcal::RecHitTools rhtools_; - void buildJetAndTracksters(std::vector&, std::vector&); }; diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.cc b/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.cc index 2a033e8b617ee..007e2c7c63fab 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.cc +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.cc @@ -18,46 +18,60 @@ using namespace ticl; template PatternRecognitionbyRecovery::PatternRecognitionbyRecovery(const edm::ParameterSet &conf, edm::ConsumesCollector iC) - : PatternRecognitionAlgoBaseT(conf, iC), caloGeomToken_(iC.esConsumes()) {} + : PatternRecognitionAlgoBaseT(conf, iC) {} + +template +void PatternRecognitionbyRecovery::setGeometry(hgcal::RecHitTools const &rhtools) { + this->rhtools_ = &rhtools; + z_limit_em_ = std::abs(this->rhtools_->getPositionLayer(this->rhtools_->lastLayerEE(false), false).z()); + this->geometryReady_ = true; +} template void PatternRecognitionbyRecovery::makeTracksters( const typename PatternRecognitionAlgoBaseT::Inputs &input, std::vector &result, std::unordered_map> &seedToTracksterAssociation) { - // Get the geometry setup - edm::EventSetup const &es = input.es; - const CaloGeometry &geom = es.getData(caloGeomToken_); - rhtools_.setGeometry(geom); - const auto z_limit_em = rhtools_.getPositionLayer(rhtools_.lastLayerEE(false), false).z(); + if (UNLIKELY(!this->geometryReady_ || this->rhtools_ == nullptr)) { + throw cms::Exception("LogicError") + << "PatternRecognitionbyRecovery::setGeometry() must be called in beginRun() before makeTracksters()."; + } + // Clear the result vector result.clear(); + result.reserve(input.layerClusters.size() / 16); // Heuristic + // Iterate over all layer clusters - for (size_t i = 0; i < input.layerClusters.size(); ++i) { + for (unsigned int i = 0; i < input.layerClusters.size(); ++i) { if (input.mask[i] == 0.f) { continue; // Skip masked clusters } - // Create a new trackster for each layer cluster - Trackster trackster; - trackster.vertices().push_back(i); - trackster.vertex_multiplicity().push_back(1); + result.emplace_back(); + auto &trackster = result.back(); + auto &v = trackster.vertices(); + v.clear(); + v.reserve(1); + v.push_back(i); + + auto &mult = trackster.vertex_multiplicity(); + mult.clear(); + mult.reserve(1); + mult.push_back(1); const auto &lc = input.layerClusters[i]; - trackster.setTimeAndError(input.layerClustersTime.get(i).first, input.layerClustersTime.get(i).second); + const auto timePair = input.layerClustersTime.get(i); + trackster.setTimeAndError(timePair.first, timePair.second); trackster.setRawEnergy(lc.energy()); trackster.setBarycenter({float(lc.x()), float(lc.y()), float(lc.z())}); trackster.calculateRawPt(); - - if (std::abs(lc.z()) <= z_limit_em) { + const float z = lc.z(); + if (z <= z_limit_em_ && z >= -z_limit_em_) { trackster.setRawEmEnergy(lc.energy()); trackster.calculateRawEmPt(); } - - // Add the trackster to the result vector - result.push_back(trackster); } - + result.shrink_to_fit(); // Log the number of tracksters created if (PatternRecognitionAlgoBaseT::algo_verbosity_ > VerbosityLevel::Advanced) { edm::LogVerbatim("PatternRecognitionbyRecovery") << "Created " << result.size() << " tracksters"; diff --git a/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.h b/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.h index 7c2eb50e704b2..df20424fed485 100644 --- a/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.h +++ b/RecoHGCal/TICL/plugins/PatternRecognitionbyRecovery.h @@ -4,6 +4,7 @@ #ifndef __RecoHGCal_TICL_PatternRecognitionbyRecovery_H__ #define __RecoHGCal_TICL_PatternRecognitionbyRecovery_H__ #include // unique_ptr +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" @@ -24,10 +25,10 @@ namespace ticl { std::unordered_map>& seedToTracksterAssociation) override; static void fillPSetDescription(edm::ParameterSetDescription& iDesc); + void setGeometry(hgcal::RecHitTools const& rhtools) override; private: - edm::ESGetToken caloGeomToken_; - hgcal::RecHitTools rhtools_; + float z_limit_em_ = 0.f; }; } // namespace ticl diff --git a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc index 346d867a17c5d..7e0747d028d09 100644 --- a/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/SimTrackstersProducer.cc @@ -144,7 +144,7 @@ SimTrackstersProducer::SimTrackstersProducer(const edm::ParameterSet& ps) void SimTrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("detector", "HGCAL"); - desc.add("computeLocalTime", "false"); + desc.add("computeLocalTime", "true"); desc.add("layer_clusters", edm::InputTag("hgcalMergeLayerClusters")); desc.add("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster")); desc.add("filtered_mask", edm::InputTag("filteredLayerClustersSimTracksters", "ticlSimTracksters")); diff --git a/RecoHGCal/TICL/plugins/SuperclusteringSampleDumper.cc b/RecoHGCal/TICL/plugins/SuperclusteringSampleDumper.cc index 1600b9f9249f1..208896cd05e98 100644 --- a/RecoHGCal/TICL/plugins/SuperclusteringSampleDumper.cc +++ b/RecoHGCal/TICL/plugins/SuperclusteringSampleDumper.cc @@ -143,112 +143,136 @@ void SuperclusteringSampleDumper::analyze(const edm::Event& evt, const edm::Even edm::Handle assoc_CP_recoToSim; evt.getByToken(tsRecoToSimCP_token_, assoc_CP_recoToSim); - /* Sorting tracksters by decreasing order of pT (out-of-place sort). - inputTracksters[trackstersIndicesPt[0]], ..., inputTracksters[trackstersIndicesPt[N]] makes a list of tracksters sorted by decreasing pT - Indices into this pT sorted collection will have the suffix _pt. Thus inputTracksters[index] and inputTracksters[trackstersIndicesPt[index_pt]] are correct - */ - std::vector trackstersIndicesPt(inputTracksters->size()); - std::iota(trackstersIndicesPt.begin(), trackstersIndicesPt.end(), 0); + auto const& tracksters = *inputTracksters; + const auto nTs = static_cast(tracksters.size()); + if (nTs == 0u) { + output_tree_->Fill(); + return; + } + + // ---- pT-sorted indices (out-of-place) + std::vector trackstersIndicesPt(nTs); + std::iota(trackstersIndicesPt.begin(), trackstersIndicesPt.end(), 0u); std::stable_sort( - trackstersIndicesPt.begin(), trackstersIndicesPt.end(), [&inputTracksters](unsigned int i1, unsigned int i2) { - return (*inputTracksters)[i1].raw_pt() > (*inputTracksters)[i2].raw_pt(); + trackstersIndicesPt.begin(), trackstersIndicesPt.end(), [&tracksters](unsigned int a, unsigned int b) { + return tracksters[a].raw_pt() > tracksters[b].raw_pt(); }); - // Order of loops are reversed compared to SuperclusteringProducer (here outer is seed, inner is candidate), for performance reasons. - // The same pairs seed-candidate should be present, just in a different order - // First loop on seed tracksters - for (unsigned int ts_seed_idx_pt = 0; ts_seed_idx_pt < inputTracksters->size(); ts_seed_idx_pt++) { - const unsigned int ts_seed_idx_input = - trackstersIndicesPt[ts_seed_idx_pt]; // Index of seed trackster in input collection (not in pT sorted collection) - Trackster const& ts_seed = (*inputTracksters)[ts_seed_idx_input]; - - if (ts_seed.raw_pt() < seedPtThreshold_) - break; // All further seeds will have lower pT than threshold (due to pT sorting) - - if (!checkExplainedVarianceRatioCut(ts_seed)) + const auto nFeatures = static_cast(features_.size()); + // Sanity: this module expects the configured feature set to match the DNN input helper. + // (If you prefer, replace with a cms::Exception instead of assert.) + assert(nFeatures == dnnInput_->featureCount()); + + // ---- optional: reserve to reduce reallocs (cheap heuristic) + // Worst-case is O(N^2); don't do that. Use something modest. + // You can tune: e.g. nTs*8 tends to be safe-ish without huge memory. + const size_t reservePairs = static_cast(nTs) * 8u; + for (auto& col : features_) { + col.reserve(reservePairs); + } + seedTracksterIdx_.reserve(reservePairs); + candidateTracksterIdx_.reserve(reservePairs); + seedTracksterBestAssociationScore_.reserve(reservePairs); + seedTracksterBestAssociation_simTsIdx_.reserve(reservePairs); + seedTracksterBestAssociation_caloParticleEnergy_.reserve(reservePairs); + candidateTracksterBestAssociationScore_.reserve(reservePairs); + candidateTracksterBestAssociation_simTsIdx_.reserve(reservePairs); + candidateTracksterAssociationWithSeed_score_.reserve(reservePairs); + + // ---- scratch buffer for features (no per-pair allocation) + std::vector featScratch; + featScratch.resize(nFeatures); + + auto bestAssoc = [](auto const& val) -> ticl::RecoToSimCollectionSimTracksters::data_type const& { + return *std::min_element(val.begin(), val.end(), [](auto const& a, auto const& b) { + // pair>; best is smallest score + return a.second.second < b.second.second; + }); + }; + + // Outer: seed + for (unsigned int seed_pt = 0; seed_pt < nTs; ++seed_pt) { + const unsigned int seed_idx = trackstersIndicesPt[seed_pt]; + auto const& ts_seed = tracksters[seed_idx]; + + if (ts_seed.raw_pt() < seedPtThreshold_) { + break; // remaining seeds are lower-pT due to sorting + } + if (!checkExplainedVarianceRatioCut(ts_seed)) { continue; + } // Find best associated CaloParticle to the seed - auto seed_assocs = assoc_CP_recoToSim->find({inputTracksters, ts_seed_idx_input}); - if (seed_assocs == assoc_CP_recoToSim->end()) - continue; // No CaloParticle associations for the current trackster (extremly unlikely) - ticl::RecoToSimCollectionSimTracksters::data_type const& seed_assocWithBestScore = - *std::min_element(seed_assocs->val.begin(), - seed_assocs->val.end(), - [](ticl::RecoToSimCollectionSimTracksters::data_type const& assoc_1, - ticl::RecoToSimCollectionSimTracksters::data_type const& assoc_2) { - // assoc_* is of type : std::pair> - // Best score is smallest score - return assoc_1.second.second < assoc_2.second.second; - }); - - // Second loop on superclustering candidates tracksters - // Look only at candidate tracksters with lower pT than the seed (so all pairs are only looked at once) - for (unsigned int ts_cand_idx_pt = ts_seed_idx_pt + 1; ts_cand_idx_pt < inputTracksters->size(); ts_cand_idx_pt++) { - Trackster const& ts_cand = (*inputTracksters)[trackstersIndicesPt[ts_cand_idx_pt]]; - // Check that the two tracksters are geometrically compatible for superclustering (using deltaEta, deltaPhi window) - // There is no need to run training or inference for tracksters very far apart - if (!(std::abs(ts_seed.barycenter().Eta() - ts_cand.barycenter().Eta()) < deltaEtaWindow_ && - std::abs(deltaPhi(ts_seed.barycenter().Phi(), ts_cand.barycenter().Phi())) < deltaPhiWindow_ && - ts_cand.raw_energy() >= candidateEnergyThreshold_ && checkExplainedVarianceRatioCut(ts_cand))) + auto seed_assocs = assoc_CP_recoToSim->find(edm::Ref(inputTracksters, seed_idx)); + if (seed_assocs == assoc_CP_recoToSim->end() || seed_assocs->val.empty()) { + continue; + } + auto const& seed_best = bestAssoc(seed_assocs->val); + + // Inner: candidate (only lower-pT than seed) + for (unsigned int cand_pt = seed_pt + 1; cand_pt < nTs; ++cand_pt) { + const unsigned int cand_idx = trackstersIndicesPt[cand_pt]; + auto const& ts_cand = tracksters[cand_idx]; + + if (ts_cand.raw_energy() < candidateEnergyThreshold_) { + continue; + } + if (!checkExplainedVarianceRatioCut(ts_cand)) { continue; + } + if (std::abs(ts_seed.barycenter().Eta() - ts_cand.barycenter().Eta()) >= deltaEtaWindow_) { + continue; + } + if (std::abs(deltaPhi(ts_seed.barycenter().Phi(), ts_cand.barycenter().Phi())) >= deltaPhiWindow_) { + continue; + } + + // ---- compute features in-place + dnnInput_->computeInto(ts_seed, ts_cand, std::span(featScratch.data(), featScratch.size())); - std::vector features = dnnInput_->computeVector(ts_seed, ts_cand); - assert(features.size() == features_.size()); - for (unsigned int feature_idx = 0; feature_idx < features_.size(); feature_idx++) { - features_[feature_idx].push_back(features[feature_idx]); + // ---- store features (columnar vectors for the tree) + // Unrolled-ish simple loop, good locality on featScratch + for (unsigned int f = 0; f < nFeatures; ++f) { + features_[f].push_back(featScratch[f]); } - seedTracksterIdx_.push_back(trackstersIndicesPt[ts_seed_idx_pt]); - candidateTracksterIdx_.push_back(trackstersIndicesPt[ts_cand_idx_pt]); - - float candidateTracksterBestAssociationScore = 1.; // Best association score of candidate with any CaloParticle - long candidateTracksterBestAssociation_simTsIdx = -1; // Corresponding CaloParticle simTrackster index - float candidateTracksterAssociationWithSeed_score = - 1.; // Association score of candidate with CaloParticle best associated with seed - - // First find associated CaloParticles with candidate - auto cand_assocCP = assoc_CP_recoToSim->find( - edm::Ref(inputTracksters, trackstersIndicesPt[ts_cand_idx_pt])); - if (cand_assocCP != assoc_CP_recoToSim->end()) { - // find the association with best score - ticl::RecoToSimCollectionSimTracksters::data_type const& cand_assocWithBestScore = - *std::min_element(cand_assocCP->val.begin(), - cand_assocCP->val.end(), - [](ticl::RecoToSimCollectionSimTracksters::data_type const& assoc_1, - ticl::RecoToSimCollectionSimTracksters::data_type const& assoc_2) { - // assoc_* is of type : std::pair> - return assoc_1.second.second < assoc_2.second.second; - }); - candidateTracksterBestAssociationScore = cand_assocWithBestScore.second.second; - candidateTracksterBestAssociation_simTsIdx = cand_assocWithBestScore.first.key(); - - // find the association score with the same CaloParticle as the seed - auto cand_assocWithSeedCP = - std::find_if(cand_assocCP->val.begin(), - cand_assocCP->val.end(), - [&seed_assocWithBestScore](ticl::RecoToSimCollectionSimTracksters::data_type const& assoc) { - // assoc is of type : std::pair> - return assoc.first == seed_assocWithBestScore.first; - }); - if (cand_assocWithSeedCP != cand_assocCP->val.end()) { - candidateTracksterAssociationWithSeed_score = cand_assocWithSeedCP->second.second; + + seedTracksterIdx_.push_back(seed_idx); + candidateTracksterIdx_.push_back(cand_idx); + + float candBestScore = 1.f; + long candBestSimIdx = -1; + float candScoreWithSeed = 1.f; + + auto cand_assocs = assoc_CP_recoToSim->find(edm::Ref(inputTracksters, cand_idx)); + if (cand_assocs != assoc_CP_recoToSim->end() && !cand_assocs->val.empty()) { + auto const& cand_best = bestAssoc(cand_assocs->val); + candBestScore = cand_best.second.second; + candBestSimIdx = cand_best.first.key(); + + auto itSeed = std::find_if(cand_assocs->val.begin(), cand_assocs->val.end(), [&seed_best](auto const& assoc) { + return assoc.first == seed_best.first; + }); + if (itSeed != cand_assocs->val.end()) { + candScoreWithSeed = itSeed->second.second; } } - seedTracksterBestAssociationScore_.push_back(seed_assocWithBestScore.second.second); - seedTracksterBestAssociation_simTsIdx_.push_back(seed_assocWithBestScore.first.key()); - seedTracksterBestAssociation_caloParticleEnergy_.push_back(seed_assocWithBestScore.first->regressed_energy()); + seedTracksterBestAssociationScore_.push_back(seed_best.second.second); + seedTracksterBestAssociation_simTsIdx_.push_back(seed_best.first.key()); + seedTracksterBestAssociation_caloParticleEnergy_.push_back(seed_best.first->regressed_energy()); - candidateTracksterBestAssociationScore_.push_back(candidateTracksterBestAssociationScore); - candidateTracksterBestAssociation_simTsIdx_.push_back(candidateTracksterBestAssociation_simTsIdx); - - candidateTracksterAssociationWithSeed_score_.push_back(candidateTracksterAssociationWithSeed_score); + candidateTracksterBestAssociationScore_.push_back(candBestScore); + candidateTracksterBestAssociation_simTsIdx_.push_back(candBestSimIdx); + candidateTracksterAssociationWithSeed_score_.push_back(candScoreWithSeed); } } output_tree_->Fill(); - for (auto& feats : features_) - feats.clear(); + + // Clear but keep capacity (important for perf across events) + for (auto& col : features_) { + col.clear(); + } seedTracksterIdx_.clear(); candidateTracksterIdx_.clear(); seedTracksterBestAssociationScore_.clear(); @@ -295,4 +319,4 @@ void SuperclusteringSampleDumper::fillDescriptions(edm::ConfigurationDescription descriptions.add("superclusteringSampleDumper", desc); } -DEFINE_FWK_MODULE(SuperclusteringSampleDumper); \ No newline at end of file +DEFINE_FWK_MODULE(SuperclusteringSampleDumper); diff --git a/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc b/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc index a5bb94fdffbf0..d8b949bc62619 100644 --- a/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc +++ b/RecoHGCal/TICL/plugins/TICLCandidateProducer.cc @@ -35,7 +35,6 @@ #include "RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h" -#include "RecoHGCal/TICL/interface/GlobalCache.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h" @@ -47,7 +46,7 @@ #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" -#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" @@ -57,18 +56,18 @@ #include "TrackstersPCA.h" using namespace ticl; -using cms::Ort::ONNXRuntime; -class TICLCandidateProducer : public edm::stream::EDProducer, edm::stream::WatchRuns> { +class TICLCandidateProducer + : public edm::stream::EDProducer, edm::stream::WatchRuns> { public: - explicit TICLCandidateProducer(const edm::ParameterSet &ps, const ONNXRuntime *); + explicit TICLCandidateProducer(const edm::ParameterSet &ps, const ticl::TICLONNXGlobalCache *); ~TICLCandidateProducer() override {} void produce(edm::Event &, const edm::EventSetup &) override; static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override; - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet &iConfig); - static void globalEndJob(const ONNXRuntime *); + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet &iConfig); + static void globalEndJob(const ticl::TICLONNXGlobalCache *); private: void dumpCandidate(const TICLCandidate &) const; @@ -121,7 +120,7 @@ class TICLCandidateProducer : public edm::stream::EDProducer>(ps.getParameter("layer_clusters"))), clustersTime_token_( consumes>>(ps.getParameter("layer_clustersTime"))), @@ -177,11 +176,30 @@ TICLCandidateProducer::TICLCandidateProducer(const edm::ParameterSet &ps, const if (useMTDTiming_) { inputTimingToken_ = consumes(ps.getParameter("timingSoA")); } - // Initialize inference algorithm using the factory - std::string inferencePlugin = ps.getParameter("inferenceAlgo"); - edm::ParameterSet inferencePSet = ps.getParameter("pluginInferenceAlgo" + inferencePlugin); - inferenceAlgo_ = std::unique_ptr( - TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet)); + // Initialize inference algorithm using the factory. + // Do not build the inference plugin if it is disabled or if no model is configured (empty string => no session loaded). + if (regressionAndPid_) { + const std::string inferencePlugin = ps.getParameter("inferenceAlgo"); + if (!inferencePlugin.empty()) { + const edm::ParameterSet inferencePSet = + ps.getParameter("pluginInferenceAlgo" + inferencePlugin); + + // If the plugin config exposes model paths as std::string with default "", + // the cache will only contain sessions for non-empty paths. + const bool hasSingleModel = inferencePSet.existsAs("onnxModelPath", true) && + !inferencePSet.getParameter("onnxModelPath").empty(); + const bool hasPIDModel = inferencePSet.existsAs("onnxPIDModelPath", true) && + !inferencePSet.getParameter("onnxPIDModelPath").empty(); + const bool hasEnergyModel = inferencePSet.existsAs("onnxEnergyModelPath", true) && + !inferencePSet.getParameter("onnxEnergyModelPath").empty(); + + // Only instantiate the plugin if at least one model path is configured. + if (hasSingleModel || hasPIDModel || hasEnergyModel) { + inferenceAlgo_ = std::unique_ptr( + TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet, cache)); + } + } + } produces>(); @@ -194,11 +212,12 @@ TICLCandidateProducer::TICLCandidateProducer(const edm::ParameterSet &ps, const TICLGeneralInterpretationPluginFactory::get()->create(algoType, interpretationPSet, consumesCollector()); } -std::unique_ptr TICLCandidateProducer::initializeGlobalCache(const edm::ParameterSet &iConfig) { - return std::unique_ptr(nullptr); +std::unique_ptr TICLCandidateProducer::initializeGlobalCache( + const edm::ParameterSet &iConfig) { + return ticl::TICLONNXGlobalCache::initialize(iConfig); } -void TICLCandidateProducer::globalEndJob(const ONNXRuntime *) {} +void TICLCandidateProducer::globalEndJob(const ticl::TICLONNXGlobalCache *) {} void TICLCandidateProducer::beginRun(edm::Run const &iEvent, edm::EventSetup const &es) { edm::ESHandle hdc = es.getHandle(hdc_token_); @@ -212,7 +231,7 @@ void TICLCandidateProducer::beginRun(edm::Run const &iEvent, edm::EventSetup con generalInterpretationAlgo_->initialize(hgcons_, rhtools_, bfield_, propagator_); trackingGeometry_ = es.getHandle(trackingGeometry_token_); -}; +} void filterTracks(edm::Handle> tkH, const edm::Handle> &muons_h, @@ -234,7 +253,7 @@ void filterTracks(edm::Handle> tkH, } // don't consider tracks below 2 GeV for linking - if (std::sqrt(tk.p() * tk.p() + ticl::mpion2) < tkEnergyCut_) { + if (std::sqrt(tk.p() * tk.p() + mpion2) < tkEnergyCut_) { maskTracks[i] = false; continue; } @@ -333,9 +352,7 @@ void TICLCandidateProducer::produce(edm::Event &evt, const edm::EventSetup &es) true); if (regressionAndPid_) { // Run inference algorithm - inferenceAlgo_->inputData(layerClusters, *resultTracksters, rhtools_); - inferenceAlgo_->runInference( - *resultTracksters); //option to use "Linking" instead of "CLU3D"/"energyAndPid" instead of "PID" + inferenceAlgo_->runInference(layerClusters, *resultTracksters, rhtools_); } std::vector maskTracksters(resultTracksters->size(), true); diff --git a/RecoHGCal/TICL/plugins/TICLDumper.cc b/RecoHGCal/TICL/plugins/TICLDumper.cc index c714ab4f66bdd..b3fc35e9911a1 100644 --- a/RecoHGCal/TICL/plugins/TICLDumper.cc +++ b/RecoHGCal/TICL/plugins/TICLDumper.cc @@ -161,6 +161,7 @@ class TracksterDumperHelper { trackster_tree_->Branch("sigmaPCA3", &trackster_sigmaPCA3); if (tracksterType_ != TracksterType::Trackster) { trackster_tree_->Branch("regressed_pt", &simtrackster_regressed_pt); + trackster_tree_->Branch("CPidx", &simtrackster_CPidx); trackster_tree_->Branch("pdgID", &simtrackster_pdgID); trackster_tree_->Branch("trackIdx", &simtrackster_trackIdxs); trackster_tree_->Branch("timeBoundary", &simtrackster_timeBoundary); @@ -218,6 +219,7 @@ class TracksterDumperHelper { trackster_sigmaPCA3.clear(); simtrackster_regressed_pt.clear(); + simtrackster_CPidx.clear(); simtrackster_pdgID.clear(); simtrackster_trackIdxs.clear(); simtrackster_timeBoundary.clear(); @@ -289,6 +291,15 @@ class TracksterDumperHelper { if (tracksterType_ != TracksterType::Trackster) { // is simtrackster auto const& simclusters = *simClusters_h; auto const& caloparticles = *caloparticles_h; + std::map SimClusterToCaloParticleMap; + for (const auto& cp : caloparticles) { + auto cpIndex = &cp - &caloparticles[0]; + for (const auto& scRef : cp.simClusters()) { + auto const& sc = *(scRef); + auto const scIndex = &sc - &simclusters[0]; + SimClusterToCaloParticleMap[scIndex] = cpIndex; + } + } simtrackster_timeBoundary.push_back(trackster_iterator->boundaryTime()); @@ -299,14 +310,18 @@ class TracksterDumperHelper { - a SimCluster (other cases) Thus trackster.seedIndex() can point to either CaloParticle or SimCluster collection (check seedID to differentiate) */ + auto CPindex = 0; using CaloObjectVariant = std::variant; CaloObjectVariant caloObj; if (trackster_iterator->seedID() == caloparticles_h.id()) { caloObj = caloparticles[trackster_iterator->seedIndex()]; + CPindex = trackster_iterator->seedIndex(); } else { caloObj = simclusters[trackster_iterator->seedIndex()]; + CPindex = SimClusterToCaloParticleMap[trackster_iterator->seedIndex()]; } + simtrackster_CPidx.push_back(CPindex); simtrackster_pdgID.push_back(std::visit([](auto&& obj) { return obj.pdgId(); }, caloObj)); auto const& simTrack = std::visit([](auto&& obj) { return obj.g4Tracks()[0]; }, caloObj); auto const& caloPt = std::visit([](auto&& obj) { return obj.pt(); }, caloObj); @@ -466,6 +481,7 @@ class TracksterDumperHelper { // for simtrackster std::vector simtrackster_regressed_pt; + std::vector simtrackster_CPidx; std::vector simtrackster_pdgID; std::vector> simtrackster_trackIdxs; std::vector simtrackster_timeBoundary; @@ -1597,7 +1613,7 @@ void TICLDumper::fillDescriptions(edm::ConfigurationDescriptions& descriptions) desc.add("layerClusters", edm::InputTag("hgcalMergeLayerClusters")); desc.add("layer_clustersTime", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster")); - desc.add("ticlcandidates", edm::InputTag("ticlTrackstersMerge")); + desc.add("ticlcandidates", edm::InputTag("ticlCandidate")); desc.add("tracks", edm::InputTag("generalTracks")); desc.add("tracksTime", edm::InputTag("tofPID:t0")); desc.add("tracksTimeQual", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA")); @@ -1612,7 +1628,7 @@ void TICLDumper::fillDescriptions(edm::ConfigurationDescriptions& descriptions) ->setComment( "egamma supercluster collection (either from PFECALSuperClusterProducer for Mustache, or from " "TICL->Egamma converter in case of TICL DNN superclusters)"); - desc.add("recoSuperClusters_sourceTracksterCollection", edm::InputTag("ticlTrackstersMerge")) + desc.add("recoSuperClusters_sourceTracksterCollection", edm::InputTag("ticlCandidate")) ->setComment( "Trackster collection used to produce the reco::SuperCluster, used to provide a mapping back to the " "tracksters used in superclusters"); diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc b/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc index 72959412d3728..aa175f3727335 100644 --- a/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc +++ b/RecoHGCal/TICL/plugins/TracksterInferenceAlgoFactory.cc @@ -1,15 +1,12 @@ #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" +#include "RecoHGCal/TICL/interface/TracksterInferenceByCNN.h" + #include "FWCore/ParameterSet/interface/ValidatedPluginFactoryMacros.h" #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, - ticl::TracksterInferenceByCNNv4, - "TracksterInferenceByCNNv4"); +DEFINE_EDM_VALIDATED_PLUGIN(TracksterInferenceAlgoFactory, ticl::TracksterInferenceByCNN, "TracksterInferenceByCNN"); diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByANN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByANN.cc deleted file mode 100644 index 64b8017b4b459..0000000000000 --- a/RecoHGCal/TICL/plugins/TracksterInferenceByANN.cc +++ /dev/null @@ -1,25 +0,0 @@ -#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" -#include "RecoHGCal/TICL/interface/TracksterInferenceByANN.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" - -namespace ticl { - - TracksterInferenceByANN::TracksterInferenceByANN(const edm::ParameterSet& conf) : TracksterInferenceAlgoBase(conf) { - // Load ANN model - } - - void TracksterInferenceByANN::inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) { - // Prepare data for inference - } - - void TracksterInferenceByANN::runInference(std::vector& tracksters) { - // Run inference using ANN - } -} // namespace ticl - -// Define this as a plug-in -#include "FWCore/Framework/interface/MakerMacros.h" -DEFINE_EDM_PLUGIN(TracksterInferenceAlgoFactory, ticl::TracksterInferenceByANN, "TracksterInferenceByANN"); diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByCNN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByCNN.cc new file mode 100644 index 0000000000000..5cd4003bb5ad8 --- /dev/null +++ b/RecoHGCal/TICL/plugins/TracksterInferenceByCNN.cc @@ -0,0 +1,153 @@ +#include "RecoHGCal/TICL/interface/TracksterInferenceByCNN.h" +#include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" + +#include +#include +#include +#include + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" + +namespace ticl { + + TracksterInferenceByCNN::TracksterInferenceByCNN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache) + : TracksterInferenceAlgoBase(conf, cache), + inputNames_(conf.getParameter>("inputNames")), + outputNames_(conf.getParameter>("outputNames")), + eidMinClusterEnergy_(conf.getParameter("eid_min_cluster_energy")), + eidNLayers_(conf.getParameter("eid_n_layers")), + eidNClusters_(conf.getParameter("eid_n_clusters")), + doPID_(conf.getParameter("doPID")), + miniBatchSize_(conf.getUntrackedParameter("miniBatchSize", 64)) { + const std::string modelPath = conf.getParameter("onnxModelPath"); + + if (cache_ != nullptr && !modelPath.empty()) { + onnxSession_ = cache_->getByModelPathString(modelPath); + } + + enabled_ = (doPID_ != 0 && onnxSession_ != nullptr); + } + + void TracksterInferenceByCNN::runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const { + if (!enabled_ || tracksters.empty()) { + return; + } + + std::vector indices; + indices.reserve(tracksters.size()); + + for (int i = 0; i < static_cast(tracksters.size()); ++i) { + float sumClusterEnergy = 0.f; + for (const unsigned int& vertex : tracksters[i].vertices()) { + sumClusterEnergy += static_cast(layerClusters[vertex].energy()); + if (sumClusterEnergy >= eidMinClusterEnergy_) { + tracksters[i].zeroProbabilities(); + indices.push_back(i); + break; + } + } + } + + const int total = static_cast(indices.size()); + if (total == 0) { + return; + } + + const int mb = std::max(1, miniBatchSize_); + + // Scratch buffers are local to this event. + TracksterInferenceAlgoBase::OrtScratch ortScratch; + ortScratch.inputs.resize(1); + ortScratch.input_shapes.resize(1); + ortScratch.clearPerEvent(); + + std::vector seenClusters(eidNLayers_); + std::vector clusterIndices; + + for (int start = 0; start < total; start += mb) { + const int n = std::min(mb, total - start); + + ortScratch.input_shapes[0] = {n, eidNLayers_, eidNClusters_, eidNFeatures_}; + + const size_t nInput = static_cast(n) * eidNLayers_ * eidNClusters_ * eidNFeatures_; + + auto& inputTensor = ortScratch.inputs[0]; + inputTensor.assign(nInput, 0.f); + + for (int bi = 0; bi < n; ++bi) { + const int tsIdx = indices[start + bi]; + Trackster const& ts = tracksters[tsIdx]; + + const int vtxCount = static_cast(ts.vertices().size()); + clusterIndices.resize(vtxCount); + std::iota(clusterIndices.begin(), clusterIndices.end(), 0); + + std::sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &ts](int a, int b) { + return layerClusters[ts.vertices(a)].energy() > layerClusters[ts.vertices(b)].energy(); + }); + + std::fill(seenClusters.begin(), seenClusters.end(), 0); + + for (int k : clusterIndices) { + const unsigned int v = ts.vertices(k); + auto const& cl = layerClusters[v]; + + const int j = rhtools.getLayerWithOffset(cl.hitsAndFractions()[0].first) - 1; + if (j < 0 || j >= eidNLayers_) { + continue; + } + if (seenClusters[j] >= eidNClusters_) { + continue; + } + + const size_t base = + (static_cast(bi) * eidNLayers_ + static_cast(j)) * (eidNClusters_ * eidNFeatures_) + + static_cast(seenClusters[j]) * eidNFeatures_; + + inputTensor[base + 0] = static_cast(cl.energy() / static_cast(ts.vertex_multiplicity(k))); + inputTensor[base + 1] = static_cast(std::abs(cl.eta())); + inputTensor[base + 2] = static_cast(cl.phi()); + + ++seenClusters[j]; + } + } + + ortScratch.outputs.clear(); + + onnxSession_->runInto( + inputNames_, ortScratch.inputs, ortScratch.input_shapes, outputNames_, ortScratch.outputs, {}, n); + + if (!ortScratch.outputs.empty() && !outputNames_.empty()) { + float* probs = ortScratch.outputs[0].data(); + for (int bi = 0; bi < n; ++bi) { + auto& ts = tracksters[indices[start + bi]]; + ts.setProbabilities(probs); + probs += ts.id_probabilities().size(); + } + } + } + } + + void TracksterInferenceByCNN::fillPSetDescription(edm::ParameterSetDescription& iDesc) { + TracksterInferenceAlgoBase::fillPSetDescription(iDesc); + + iDesc.add("onnxModelPath", "RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/patternrecognition/id_v0.onnx") + ->setComment("Path to ONNX PID model. If empty, PID is skipped."); + + iDesc.add>("inputNames", {"input"}); + iDesc.add>("outputNames", {"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.addUntracked("miniBatchSize", 64) + ->setComment("Mini-batch size for inference to limit peak memory usage."); + } + +} // namespace ticl diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByCNNv4.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByCNNv4.cc deleted file mode 100644 index e4c98cd8597ef..0000000000000 --- a/RecoHGCal/TICL/plugins/TracksterInferenceByCNNv4.cc +++ /dev/null @@ -1,137 +0,0 @@ -#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" -#include "RecoHGCal/TICL/interface/TracksterInferenceByCNNv4.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 TracksterInferenceByCNNv4 - TracksterInferenceByCNNv4::TracksterInferenceByCNNv4(const edm::ParameterSet& conf) - : TracksterInferenceAlgoBase(conf), - modelPath_(conf.getParameter("onnxModelPath").fullPath()), // Path to the PID model CLU3D - inputNames_(conf.getParameter>("inputNames")), // Define input names for inference - outputNames_(conf.getParameter>("outputNames")), // Define output names 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 onnxRuntimeInstance = - std::make_unique(modelPath_.c_str()); - onnxSession_ = onnxRuntimeInstance.get(); - } - - // Method to process input data and prepare it for inference - void TracksterInferenceByCNNv4::inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) { - 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 = {batchSize_, eidNLayers_, eidNClusters_, eidNFeatures_}; - input_shapes_ = {inputShape}; - - input_Data_.clear(); - input_Data_.emplace_back(batchSize_ * eidNLayers_ * eidNClusters_ * eidNFeatures_, 0); - - for (int i = 0; i < batchSize_; i++) { - const Trackster& trackster = tracksters[tracksterIndices_[i]]; - - // 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 = (i * eidNLayers_ + j) * eidNFeatures_ * eidNClusters_ + seenClusters[j] * eidNFeatures_; - input_Data_[0][index] = - static_cast(cluster.energy() / static_cast(trackster.vertex_multiplicity(k))); - input_Data_[0][index + 1] = static_cast(std::abs(cluster.eta())); - input_Data_[0][index + 2] = static_cast(cluster.phi()); - seenClusters[j]++; - } - } - } - } - - // Method to run inference and update tracksters - void TracksterInferenceByCNNv4::runInference(std::vector& tracksters) { - if (batchSize_ == 0) - return; // Exit if no batch - - std::vector> outputTensors; - outputTensors = onnxSession_->run(inputNames_, input_Data_, input_shapes_, outputNames_, batchSize_); - if (doPID_ and doRegression_) { - // Run energy model inference - if (!outputNames_.empty()) { - for (int i = 0; i < static_cast(batchSize_); i++) { - const float energy = outputTensors[0][i]; - tracksters[tracksterIndices_[i]].setRegressedEnergy(energy); // Update energy - } - } - } - - if (doPID_) { - // Run PID model inference - if (!outputNames_.empty()) { - int probsIdx = outputNames_.empty() ? 0 : 1; - std::vector vec = outputTensors[probsIdx]; - float* probs = vec.data(); - 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 TracksterInferenceByCNNv4::fillPSetDescription(edm::ParameterSetDescription& iDesc) { - iDesc.add("algo_verbosity", 0); - iDesc - .add("onnxModelPath", - edm::FileInPath("RecoHGCal/TICL/data/ticlv4/onnx_models/energy_id_v0.onnx")) - ->setComment("Path to ONNX PID model CLU3D"); - iDesc.add>("inputNames", {"input:0"}); - iDesc.add>("outputNames", {"output/regressed_energy:0", "output/id_probabilities:0"}); - 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", 0); - } -} // namespace ticl diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc index 0bfe49bdbbdad..8eee82dc9900a 100644 --- a/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc +++ b/RecoHGCal/TICL/plugins/TracksterInferenceByDNN.cc @@ -1,148 +1,186 @@ -#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" #include "RecoHGCal/TICL/interface/TracksterInferenceByDNN.h" #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include +#include +#include + #include "FWCore/Framework/interface/MakerMacros.h" -#include "RecoHGCal/TICL/interface/PatternRecognitionAlgoBase.h" -#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "TrackstersPCA.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" namespace ticl { - using namespace cms::Ort; // Use ONNXRuntime namespace - - // Constructor for TracksterInferenceByDNN - TracksterInferenceByDNN::TracksterInferenceByDNN(const edm::ParameterSet& conf) - : TracksterInferenceAlgoBase(conf), - onnxPIDRuntimeInstance_(std::make_unique( - conf.getParameter("onnxPIDModelPath").fullPath().c_str())), - onnxEnergyRuntimeInstance_(std::make_unique( - conf.getParameter("onnxEnergyModelPath").fullPath().c_str())), - 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 - onnxPIDSession_ = onnxPIDRuntimeInstance_.get(); - onnxEnergySession_ = onnxEnergyRuntimeInstance_.get(); + + TracksterInferenceByDNN::TracksterInferenceByDNN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache) + : TracksterInferenceAlgoBase(conf, cache), + inputNames_(conf.getParameter>("inputNames")), + output_en_(conf.getParameter>("output_en")), + output_id_(conf.getParameter>("output_id")), + eidMinClusterEnergy_(conf.getParameter("eid_min_cluster_energy")), + eidNLayers_(conf.getParameter("eid_n_layers")), + eidNClusters_(conf.getParameter("eid_n_clusters")), + doPID_(conf.getParameter("doPID")), + doRegression_(conf.getParameter("doRegression")), + miniBatchSize_(conf.getUntrackedParameter("miniBatchSize", 256)) { + const std::string pidModel = conf.getParameter("onnxPIDModelPath"); + const std::string energyModel = conf.getParameter("onnxEnergyModelPath"); + + if (cache_ != nullptr) { + if (!pidModel.empty()) { + onnxPIDSession_ = cache_->getByModelPathString(pidModel); + } + if (!energyModel.empty()) { + onnxEnergySession_ = cache_->getByModelPathString(energyModel); + } + } + + enabled_ = ((doPID_ != 0 && onnxPIDSession_ != nullptr) || (doRegression_ != 0 && onnxEnergySession_ != nullptr)); } - // Method to process input data and prepare it for inference - void TracksterInferenceByDNN::inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) { - 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()) { - if (rhtools.isBarrel(layerClusters[vertex].seed())) + void TracksterInferenceByDNN::runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const { + if (!enabled_ || tracksters.empty()) { + return; + } + + std::vector indices; + indices.reserve(tracksters.size()); + + for (int i = 0; i < static_cast(tracksters.size()); ++i) { + float sumClusterEnergy = 0.f; + + for (const unsigned int& v : tracksters[i].vertices()) { + if (rhtools.isBarrel(layerClusters[v].seed())) { continue; - sumClusterEnergy += static_cast(layerClusters[vertex].energy()); + } + sumClusterEnergy += static_cast(layerClusters[v].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 + tracksters[i].setRegressedEnergy(0.f); + tracksters[i].zeroProbabilities(); + indices.push_back(i); break; } } } - // Prepare input shapes and data for inference - batchSize_ = static_cast(tracksterIndices_.size()); - if (batchSize_ == 0) - return; // Exit if no tracksters + const int total = static_cast(indices.size()); + if (total == 0) { + return; + } + + const int mb = std::max(1, miniBatchSize_); - std::vector inputShape = {batchSize_, eidNLayers_, eidNClusters_, eidNFeatures_}; - input_shapes_ = {inputShape}; + // Scratch buffers are local to this event. + OrtScratch ortScratch; + ortScratch.inputs.resize(1); + ortScratch.input_shapes.resize(1); + ortScratch.clearPerEvent(); - input_Data_.clear(); - input_Data_.emplace_back(batchSize_ * eidNLayers_ * eidNClusters_ * eidNFeatures_, 0); + // Reused within the event to avoid minibatch-level churn. + std::vector seenClusters(eidNLayers_); + std::vector clusterIndices; - for (int i = 0; i < batchSize_; i++) { - const Trackster& trackster = tracksters[tracksterIndices_[i]]; + auto& in = ortScratch.inputs[0]; - // 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; - } + for (int start = 0; start < total; start += mb) { + const int n = std::min(mb, total - start); + + ortScratch.input_shapes[0] = {n, eidNLayers_, eidNClusters_, eidNFeatures_}; + + const size_t nFloats = static_cast(n) * eidNLayers_ * eidNClusters_ * eidNFeatures_; + in.assign(nFloats, 0.f); + + for (int bi = 0; bi < n; ++bi) { + const int tsIdx = indices[start + bi]; + Trackster const& ts = tracksters[tsIdx]; - 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 = (i * eidNLayers_ + j) * eidNFeatures_ * eidNClusters_ + seenClusters[j] * eidNFeatures_; - input_Data_[0][index] = - static_cast(cluster.energy() / static_cast(trackster.vertex_multiplicity(k))); - input_Data_[0][index + 1] = static_cast(std::abs(cluster.eta())); - input_Data_[0][index + 2] = static_cast(cluster.phi()); - seenClusters[j]++; + const int vtxCount = static_cast(ts.vertices().size()); + clusterIndices.resize(vtxCount); + std::iota(clusterIndices.begin(), clusterIndices.end(), 0); + + std::sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &ts](int a, int b) { + return layerClusters[ts.vertices(a)].energy() > layerClusters[ts.vertices(b)].energy(); + }); + + std::fill(seenClusters.begin(), seenClusters.end(), 0); + + for (int k : clusterIndices) { + const unsigned int v = ts.vertices(k); + auto const& cl = layerClusters[v]; + + const int j = rhtools.getLayerWithOffset(cl.hitsAndFractions()[0].first) - 1; + if (j < 0 || j >= eidNLayers_) { + continue; + } + if (seenClusters[j] >= eidNClusters_) { + continue; + } + + const size_t base = + (static_cast(bi) * eidNLayers_ + static_cast(j)) * (eidNClusters_ * eidNFeatures_) + + static_cast(seenClusters[j]) * eidNFeatures_; + + in[base + 0] = static_cast(cl.energy() / static_cast(ts.vertex_multiplicity(k))); + in[base + 1] = static_cast(std::abs(cl.eta())); + in[base + 2] = static_cast(cl.phi()); + + ++seenClusters[j]; } } - } - } - // Method to run inference and update tracksters - void TracksterInferenceByDNN::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 (doRegression_ != 0 && onnxEnergySession_ != nullptr) { + ortScratch.outputs.clear(); + + onnxEnergySession_->runInto( + inputNames_, ortScratch.inputs, ortScratch.input_shapes, output_en_, ortScratch.outputs, {}, n); + + if (!ortScratch.outputs.empty() && !output_en_.empty()) { + auto const& energy = ortScratch.outputs[0]; + for (int bi = 0; bi < n; ++bi) { + tracksters[indices[start + bi]].setRegressedEnergy(energy[bi]); + } } } - } - 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 + if (doPID_ != 0 && onnxPIDSession_ != nullptr) { + ortScratch.outputs.clear(); + + onnxPIDSession_->runInto( + inputNames_, ortScratch.inputs, ortScratch.input_shapes, output_id_, ortScratch.outputs, {}, n); + + if (!ortScratch.outputs.empty() && !output_id_.empty()) { + float* probs = ortScratch.outputs[0].data(); + for (int bi = 0; bi < n; ++bi) { + auto& ts = tracksters[indices[start + bi]]; + ts.setProbabilities(probs); + probs += ts.id_probabilities().size(); + } } } } } - // Method to fill parameter set description for configuration + void TracksterInferenceByDNN::fillPSetDescription(edm::ParameterSetDescription& iDesc) { - iDesc.add("algo_verbosity", 0); - iDesc - .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/DNN/patternrecognition/energy_v0.onnx")) - ->setComment("Path to ONNX Energy model CLU3D"); + TracksterInferenceAlgoBase::fillPSetDescription(iDesc); + + iDesc.add("onnxPIDModelPath", "") + ->setComment("Path to ONNX PID model. If empty, PID inference is skipped."); + iDesc.add("onnxEnergyModelPath", "") + ->setComment("Path to ONNX energy model. If empty, energy regression is skipped."); + iDesc.add>("inputNames", {"input"}); 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); + + iDesc.addUntracked("miniBatchSize", 64) + ->setComment("Mini-batch size for inference to limit peak memory usage."); } + } // namespace ticl diff --git a/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc b/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc index ba65524fd09ff..f54021ad4b39b 100644 --- a/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc +++ b/RecoHGCal/TICL/plugins/TracksterInferenceByPFN.cc @@ -1,156 +1,209 @@ -#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" + +#include +#include +#include +#include +#include +#include +#include namespace ticl { - using namespace cms::Ort; // Use ONNXRuntime namespace - - // Constructor for TracksterInferenceByPFN - TracksterInferenceByPFN::TracksterInferenceByPFN(const edm::ParameterSet& conf) - : TracksterInferenceAlgoBase(conf), - onnxPIDRuntimeInstance_(std::make_unique( - conf.getParameter("onnxPIDModelPath").fullPath().c_str())), - onnxEnergyRuntimeInstance_(std::make_unique( - conf.getParameter("onnxEnergyModelPath").fullPath().c_str())), - 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 - { - onnxPIDSession_ = onnxPIDRuntimeInstance_.get(); - onnxEnergySession_ = onnxEnergyRuntimeInstance_.get(); - } - // Method to process input data and prepare it for inference - void TracksterInferenceByPFN::inputData(const std::vector& layerClusters, - std::vector& tracksters, - const hgcal::RecHitTools& rhtools) { - tracksterIndices_.clear(); // Clear previous indices - for (int i = 0; i < static_cast(tracksters.size()); i++) { - for (const unsigned int& vertex : tracksters[i].vertices()) { - if (rhtools.isBarrel(layerClusters[vertex].seed())) - continue; + + TracksterInferenceByPFN::TracksterInferenceByPFN(const edm::ParameterSet& conf, TICLONNXGlobalCache const* cache) + : TracksterInferenceAlgoBase(conf, cache), + inputNames_(conf.getParameter>("inputNames")), + output_en_(conf.getParameter>("output_en")), + output_id_(conf.getParameter>("output_id")), + eidMinClusterEnergy_(conf.getParameter("eid_min_cluster_energy")), + eidNLayers_(conf.getParameter("eid_n_layers")), + eidNClusters_(conf.getParameter("eid_n_clusters")), + doPID_(conf.getParameter("doPID")), + doRegression_(conf.getParameter("doRegression")), + miniBatchSize_(conf.getUntrackedParameter("miniBatchSize", 64)) { + const std::string pidModel = conf.getParameter("onnxPIDModelPath"); + const std::string energyModel = conf.getParameter("onnxEnergyModelPath"); + + if (cache_ != nullptr) { + if (!pidModel.empty()) { + onnxPIDSession_ = cache_->getByModelPathString(pidModel); + } + if (!energyModel.empty()) { + onnxEnergySession_ = cache_->getByModelPathString(energyModel); } - tracksters[i].setRegressedEnergy(0.f); // Initialize regressed energy to 0 - tracksters[i].zeroProbabilities(); // Zero out probabilities - tracksterIndices_.push_back(i); // Only tracksters above threshold go to inference } - // 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; - } + enabled_ = ((doPID_ != 0 && onnxPIDSession_ != nullptr) || (doRegression_ != 0 && onnxEnergySession_ != nullptr)); + } + + void TracksterInferenceByPFN::runInference(const std::vector& layerClusters, + std::vector& tracksters, + const hgcal::RecHitTools& rhtools) const { + if (!enabled_ || tracksters.empty()) { + return; + } - 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]++; + std::vector indices; + indices.reserve(tracksters.size()); + + for (int i = 0; i < static_cast(tracksters.size()); ++i) { + bool anyBarrel = false; + for (const unsigned int& v : tracksters[i].vertices()) { + if (rhtools.isBarrel(layerClusters[v].seed())) { + anyBarrel = true; + break; } } + if (anyBarrel) { + continue; + } + + tracksters[i].setRegressedEnergy(0.f); + tracksters[i].zeroProbabilities(); + indices.push_back(i); } - } - // 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& energyOutput = result[0]; - if (!output_en_.empty()) { - for (int i = 0; i < static_cast(batchSize_); i++) { - auto& ts = tracksters[tracksterIndices_[i]]; - float energy = ts.raw_energy() > eidMinClusterEnergy_ ? energyOutput[i] : ts.raw_energy(); - ts.setRegressedEnergy(energy); + const int total = static_cast(indices.size()); + if (total == 0) { + return; + } + + const int mb = std::max(1, miniBatchSize_); + + // Scratch buffers are local to this event. + TracksterInferenceAlgoBase::OrtScratch ortScratch; + ortScratch.inputs.resize(2); + ortScratch.input_shapes.resize(2); + ortScratch.clearPerEvent(); + + // Reused within the event to avoid minibatch-level churn. + std::vector seenClusters(eidNLayers_); + std::vector clusterIndices; + + for (int start = 0; start < total; start += mb) { + const int n = std::min(mb, total - start); + + // Input shapes: + // - [B, L, C, F_lc] for layer-cluster tensor + // - [B, F_tr] for trackster-level features + ortScratch.input_shapes[0] = {n, eidNLayers_, eidNClusters_, eidNFeatures_}; + ortScratch.input_shapes[1] = {n, eidNFeatures_}; + + const size_t nLC = static_cast(n) * eidNLayers_ * eidNClusters_ * eidNFeatures_; + const size_t nTR = static_cast(n) * eidNFeatures_; + + auto& lcTensor = ortScratch.inputs[0]; + auto& trTensor = ortScratch.inputs[1]; + + lcTensor.assign(nLC, 0.f); // sparse fill, must zero + trTensor.resize(nTR); // fully overwritten below + + for (int bi = 0; bi < n; ++bi) { + const int tsIdx = indices[start + bi]; + Trackster const& ts = tracksters[tsIdx]; + + const size_t base_tr = static_cast(bi) * eidNFeatures_; + trTensor[base_tr + 0] = static_cast(ts.raw_energy()); + trTensor[base_tr + 1] = static_cast(ts.raw_em_energy()); + trTensor[base_tr + 2] = static_cast(ts.barycenter().x()); + trTensor[base_tr + 3] = static_cast(ts.barycenter().y()); + trTensor[base_tr + 4] = static_cast(std::abs(ts.barycenter().z())); + trTensor[base_tr + 5] = static_cast(std::abs(ts.barycenter().eta())); + trTensor[base_tr + 6] = static_cast(ts.barycenter().phi()); + + const int vtxCount = static_cast(ts.vertices().size()); + clusterIndices.resize(vtxCount); + std::iota(clusterIndices.begin(), clusterIndices.end(), 0); + + std::sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &ts](int a, int b) { + return layerClusters[ts.vertices(a)].energy() > layerClusters[ts.vertices(b)].energy(); + }); + + std::fill(seenClusters.begin(), seenClusters.end(), 0); + + for (int k : clusterIndices) { + const unsigned int v = ts.vertices(k); + auto const& cl = layerClusters[v]; + + const int j = rhtools.getLayerWithOffset(cl.hitsAndFractions()[0].first) - 1; + if (j < 0 || j >= eidNLayers_) { + continue; + } + if (seenClusters[j] >= eidNClusters_) { + continue; + } + + const size_t base_lc = + (static_cast(bi) * eidNLayers_ + static_cast(j)) * (eidNClusters_ * eidNFeatures_) + + static_cast(seenClusters[j]) * eidNFeatures_; + + lcTensor[base_lc + 0] = static_cast(cl.energy() / static_cast(ts.vertex_multiplicity(k))); + lcTensor[base_lc + 1] = static_cast(std::abs(cl.eta())); + lcTensor[base_lc + 2] = static_cast(cl.phi()); + lcTensor[base_lc + 3] = static_cast(cl.x()); + lcTensor[base_lc + 4] = static_cast(cl.y()); + lcTensor[base_lc + 5] = static_cast(std::abs(cl.z())); + lcTensor[base_lc + 6] = static_cast(cl.hitsAndFractions().size()); + + ++seenClusters[j]; } } - } - 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 + + if (doRegression_ != 0 && onnxEnergySession_ != nullptr) { + ortScratch.outputs.clear(); + + onnxEnergySession_->runInto( + inputNames_, ortScratch.inputs, ortScratch.input_shapes, output_en_, ortScratch.outputs, {}, n); + + if (!ortScratch.outputs.empty() && !output_en_.empty()) { + auto const& energy = ortScratch.outputs[0]; + for (int bi = 0; bi < n; ++bi) { + auto& ts = tracksters[indices[start + bi]]; + const float regE = energy[bi]; + const float finalE = (ts.raw_energy() > eidMinClusterEnergy_) ? regE : static_cast(ts.raw_energy()); + ts.setRegressedEnergy(finalE); + } + } + } + + if (doPID_ != 0 && onnxPIDSession_ != nullptr) { + ortScratch.outputs.clear(); + + onnxPIDSession_->runInto( + inputNames_, ortScratch.inputs, ortScratch.input_shapes, output_id_, ortScratch.outputs, {}, n); + + if (!ortScratch.outputs.empty() && !output_id_.empty()) { + float* probs = ortScratch.outputs[0].data(); + for (int bi = 0; bi < n; ++bi) { + auto& ts = tracksters[indices[start + bi]]; + ts.setProbabilities(probs); + probs += ts.id_probabilities().size(); + } } } } } - // 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"); + TracksterInferenceAlgoBase::fillPSetDescription(iDesc); + + iDesc.add("onnxPIDModelPath", "")->setComment("Path to ONNX PID model. If empty, PID is skipped."); + iDesc.add("onnxEnergyModelPath", "") + ->setComment("Path to ONNX energy model. If empty, regression is skipped."); + 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); + + iDesc.addUntracked("miniBatchSize", 64) + ->setComment("Mini-batch size for inference to limit peak memory usage."); } + } // namespace ticl diff --git a/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.h b/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.h index 6a09f7297d611..4be77085b2f15 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.h +++ b/RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.h @@ -67,6 +67,7 @@ namespace ticl { const edm::ESHandle propH) override; static void fillPSetDescription(edm::ParameterSetDescription& iDesc) { + iDesc.add("onnxModelPath", "")->setComment("Optional ONNX model path, empty means unused"); iDesc.add("cylinder_radius_sqr_split", 9.); iDesc.add("proj_distance_split", 5.); iDesc.add("track_time_quality_threshold", 0.5); diff --git a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.cc b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.cc index 4bcf0c1200af6..e73cc540560fa 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.cc @@ -21,11 +21,16 @@ Date : 11/2023 Updates : Logic works as it should and switching to v3 (Shamik) Date: 07/2025 -*/ -#include -#include +Modified by Felice Pantaleo +Improved memory usage and inference performance. +Date: 02/2026 +*/ +#include #include +#include +#include +#include #include #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -52,15 +57,21 @@ TracksterLinkingbySuperClusteringDNN::TracksterLinkingbySuperClusteringDNN(const deltaPhiWindow_(ps.getParameter("deltaPhiWindow")), seedPtThreshold_(ps.getParameter("seedPtThreshold")), candidateEnergyThreshold_(ps.getParameter("candidateEnergyThreshold")), - explVarRatioCut_energyBoundary_(ps.getParameter("candidateEnergyThreshold")), + explVarRatioCut_energyBoundary_(ps.getParameter("explVarRatioCut_energyBoundary")), explVarRatioMinimum_lowEnergy_(ps.getParameter("explVarRatioMinimum_lowEnergy")), explVarRatioMinimum_highEnergy_(ps.getParameter("explVarRatioMinimum_highEnergy")), filterByTracksterPID_(ps.getParameter("filterByTracksterPID")), tracksterPIDCategoriesToFilter_(ps.getParameter>("tracksterPIDCategoriesToFilter")), PIDThreshold_(ps.getParameter("PIDThreshold")) { - assert(onnxRuntime_ && - "TracksterLinkingbySuperClusteringDNN : ONNXRuntime was not provided, the model should have been set in " - "onnxModelPath in the plugin config"); + const auto model = ps.getParameter("onnxModelPath"); + if (model.empty()) { + throw cms::Exception("Configuration") + << "TracksterLinkingbySuperClusteringDNN requires a non-empty 'onnxModelPath'."; + } + if (!onnxRuntime_) { + throw cms::Exception("Configuration") + << "TracksterLinkingbySuperClusteringDNN could not retrieve an ONNX session for 'onnxModelPath' = " << model; + } } void TracksterLinkingbySuperClusteringDNN::initialize(const HGCalDDDConstants* hgcons, @@ -107,222 +118,198 @@ void TracksterLinkingbySuperClusteringDNN::linkTracksters( std::vector& resultTracksters, std::vector>& outputSuperclusters, std::vector>& linkedTracksterIdToInputTracksterId) { - // For now we use all input tracksters for superclustering. At some point there might be a filter here for EM tracksters (electromagnetic identification with DNN ?) auto const& inputTracksters = input.tracksters; - const unsigned int tracksterCount = inputTracksters.size(); - - /* Sorting tracksters by decreasing order of pT (out-of-place sort). - inputTracksters[trackstersIndicesPt[0]], ..., inputTracksters[trackstersIndicesPt[N]] makes a list of tracksters sorted by decreasing pT - Indices into this pT sorted collection will have the suffix _pt. Thus inputTracksters[index] and inputTracksters[trackstersIndicesPt[index_pt]] are correct - */ - std::vector trackstersIndicesPt(inputTracksters.size()); - std::iota(trackstersIndicesPt.begin(), trackstersIndicesPt.end(), 0); + const auto tracksterCount = static_cast(inputTracksters.size()); + if (tracksterCount == 0) { + return; + } + + std::vector trackstersIndicesPt(tracksterCount); + std::iota(trackstersIndicesPt.begin(), trackstersIndicesPt.end(), 0u); std::stable_sort( - trackstersIndicesPt.begin(), trackstersIndicesPt.end(), [&inputTracksters](unsigned int i1, unsigned int i2) { - return inputTracksters[i1].raw_pt() > inputTracksters[i2].raw_pt(); + trackstersIndicesPt.begin(), trackstersIndicesPt.end(), [&inputTracksters](unsigned int a, unsigned int b) { + return inputTracksters[a].raw_pt() > inputTracksters[b].raw_pt(); }); - /* Evaluate in minibatches since running with trackster count = 3000 leads to a short-lived ~15GB memory allocation - Also we do not know in advance how many superclustering candidate pairs there are going to be - The batch size needs to be rounded to featureCount - */ - const unsigned int miniBatchSize = - static_cast(inferenceBatchSize_) / dnnInputs_->featureCount() * dnnInputs_->featureCount(); - - std::vector> - inputTensorBatches; // DNN input features tensors, in minibatches. Outer array : minibatches, inner array : 2D (flattened) array of features (indexed by batchIndex, featureId) - // How far along in the latest tensor of inputTensorBatches are we. Set to miniBatchSize to trigger the creation of the tensor batch on first run - unsigned int candidateIndexInCurrentBatch = miniBatchSize; - // List of all (ts_seed_id; ts_cand_id) selected for DNN inference (same layout as inputTensorBatches) - // Index is in global trackster collection (not pt ordered collection) - std::vector>> tracksterIndicesUsedInDNN; - - // Use TracksterTiles to speed up search of tracksters in eta-phi window. One per endcap - std::array tracksterTilesBothEndcaps_pt; // one per endcap - for (unsigned int i_pt = 0; i_pt < trackstersIndicesPt.size(); ++i_pt) { - Trackster const& ts = inputTracksters[trackstersIndicesPt[i_pt]]; - tracksterTilesBothEndcaps_pt[ts.barycenter().eta() > 0.].fill(ts.barycenter().eta(), ts.barycenter().phi(), i_pt); + // -1 = unknown, 0 = false, 1 = true + std::vector explVarRatioCache(tracksterCount, -1); + auto passesExplainedVarianceRatioCut = [&](unsigned int index) -> bool { + int8_t& cached = explVarRatioCache[index]; + if (cached == -1) { + cached = checkExplainedVarianceRatioCut(inputTracksters[index]) ? 1 : 0; + } + return cached == 1; + }; + + const auto featuresPerPair = static_cast(dnnInputs_->featureCount()); + const auto maxPairsPerBatch = static_cast(inferenceBatchSize_) / featuresPerPair; + + if (maxPairsPerBatch == 0u) { + throw cms::Exception("Configuration") << "inferenceBatchSize (" << inferenceBatchSize_ + << ") is smaller than featureCount (" << featuresPerPair << ")."; } - // First loop on candidate tracksters (start at 1 since the highest pt trackster can only be a seed, not a candidate) - for (unsigned int ts_cand_idx_pt = 1; ts_cand_idx_pt < tracksterCount; ts_cand_idx_pt++) { - Trackster const& ts_cand = inputTracksters[trackstersIndicesPt[ts_cand_idx_pt]]; + // ---- event-local reusable batch buffers + std::vector inputBatch; + std::vector> batchPairs; - if (ts_cand.raw_energy() < candidateEnergyThreshold_ || - // !checkExplainedVarianceRatioCut(ts_cand)) // || !trackstersPassesPIDCut(ts_cand) - !checkExplainedVarianceRatioCut(ts_cand)) // || !trackstersPassesPIDCut(ts_cand)) - continue; + const auto reservePairs = std::min(maxPairsPerBatch, std::max(64u, 4u * tracksterCount)); + inputBatch.reserve(static_cast(reservePairs) * featuresPerPair); + batchPairs.reserve(reservePairs); - auto& tracksterTiles = tracksterTilesBothEndcaps_pt[ts_cand.barycenter().eta() > 0]; - std::array search_box = tracksterTiles.searchBoxEtaPhi(ts_cand.barycenter().Eta() - deltaEtaWindow_, - ts_cand.barycenter().Eta() + deltaEtaWindow_, - ts_cand.barycenter().Phi() - deltaPhiWindow_, - ts_cand.barycenter().Phi() + deltaPhiWindow_); - // Look for seed trackster - for (int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) { - for (int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) { - for (unsigned int ts_seed_idx_pt : - tracksterTiles[tracksterTiles.globalBin(eta_i, (phi_i % TileConstants::nPhiBins))]) { - if (ts_seed_idx_pt >= ts_cand_idx_pt) - continue; // Look only at seed tracksters with higher pT than the candidate + cms::Ort::FloatArrays inputs_for_onnx(1); + cms::Ort::FloatArrays outputs_for_onnx; + std::vector> input_shapes(1, std::vector(2, 0)); + + static const std::vector kInputNames = {"input"}; - Trackster const& ts_seed = inputTracksters[trackstersIndicesPt[ts_seed_idx_pt]]; + std::array tracksterTilesBothEndcaps_pt; + for (unsigned int i_pt = 0; i_pt < tracksterCount; ++i_pt) { + auto const& ts = inputTracksters[trackstersIndicesPt[i_pt]]; + tracksterTilesBothEndcaps_pt[ts.barycenter().eta() > 0.f].fill(ts.barycenter().eta(), ts.barycenter().phi(), i_pt); + } - if (ts_seed.raw_pt() < seedPtThreshold_) - break; // All further seeds will have lower pT than threshold (due to pT sorting) + std::vector tracksterMask(tracksterCount, false); + std::vector usedAsCandidate(tracksterCount, false); + std::vector seedToOutputIndex(tracksterCount, -1); - if (!checkExplainedVarianceRatioCut(ts_seed) || !trackstersPassesPIDCut(ts_seed)) - continue; + constexpr auto kInvalid = std::numeric_limits::max(); + unsigned int previousCand = kInvalid; + unsigned int bestSeed = kInvalid; + float bestScore = nnWorkingPoint_; - // Check that the two tracksters are geometrically compatible for superclustering - if (std::abs(ts_seed.barycenter().Eta() - ts_cand.barycenter().Eta()) < deltaEtaWindow_ && - std::abs(deltaPhi(ts_seed.barycenter().Phi(), ts_cand.barycenter().Phi())) < deltaPhiWindow_) { - if (candidateIndexInCurrentBatch >= miniBatchSize) { - // Create new minibatch - assert(candidateIndexInCurrentBatch == miniBatchSize); - - /* Estimate how many seed-candidate pairs are remaining and don't allocate a full batch in this case. Use worst-case scenario of all pairs passing geometrical window - Also assume ts_seed_idx_pt=0 (worst case) - The last tensor of inputTensorBatches will be larger than necessary. The end of it will be uninitialized, then passed to the DNN. - We do not look at the output of the DNN on this section, so it will have no consequences. - */ - inputTensorBatches.emplace_back( - std::min(miniBatchSize, - (tracksterCount * (tracksterCount - 1) - ts_cand_idx_pt * (ts_cand_idx_pt - 1)) / 2) * - dnnInputs_->featureCount()); - - candidateIndexInCurrentBatch = 0; - tracksterIndicesUsedInDNN.emplace_back(); - } - - std::vector features = dnnInputs_->computeVector(ts_seed, ts_cand); // Compute DNN features - assert(features.size() == dnnInputs_->featureCount()); - assert((candidateIndexInCurrentBatch + 1) * dnnInputs_->featureCount() <= inputTensorBatches.back().size()); - // Copy the features into the batch (TODO : could probably avoid the copy and fill straight in the batch vector) - std::copy(features.begin(), - features.end(), - inputTensorBatches.back().begin() + candidateIndexInCurrentBatch * dnnInputs_->featureCount()); - candidateIndexInCurrentBatch++; - tracksterIndicesUsedInDNN.back().emplace_back(trackstersIndicesPt[ts_seed_idx_pt], - trackstersIndicesPt[ts_cand_idx_pt]); - } - } - } + auto onCandidateTransition = [&](unsigned int candIdx) { + if (bestSeed == kInvalid) { + return; } - } - if (inputTensorBatches.empty()) { - LogDebug("HGCalTICLSuperclustering") - << "No superclustering candidate pairs passed preselection before DNN. There are " << tracksterCount - << " tracksters in this event."; - } + tracksterMask[candIdx] = true; + usedAsCandidate[candIdx] = true; -#ifdef EDM_ML_DEBUG - if (!inputTensorBatches.empty()) { - std::ostringstream s; - // Print the first 20 seed-cndidate pairs sent for inference - for (unsigned int i = 0; - i < std::min(dnnInputs_->featureCount() * 20, static_cast(inputTensorBatches[0].size())); - i++) { - s << inputTensorBatches[0][i] << " "; - if (i != 0 && i % dnnInputs_->featureCount() == 0) - s << "],\t["; + int& outIdxRef = seedToOutputIndex[bestSeed]; + if (outIdxRef < 0) { + outputSuperclusters.emplace_back(std::initializer_list{bestSeed}); + resultTracksters.emplace_back(inputTracksters[bestSeed]); + linkedTracksterIdToInputTracksterId.emplace_back(std::initializer_list{bestSeed}); + outIdxRef = static_cast(outputSuperclusters.size()) - 1; + tracksterMask[bestSeed] = true; } - LogDebug("HGCalTICLSuperclustering") << inputTensorBatches.size() - << " batches were created. First batch starts as follows : [" << s.str() - << "]"; - } -#endif - // Run the DNN inference - std::vector> - batchOutputs; // Outer index : minibatch, inner index : inference index in minibatch, value : DNN score - for (std::vector& singleBatch : inputTensorBatches) { - // ONNXRuntime takes std::vector>& as input (non-const reference) so we have to make a new vector - std::vector> inputs_for_onnx{{std::move(singleBatch)}}; - std::vector outputs = onnxRuntime_->run( - {"input"}, inputs_for_onnx, {}, {}, inputs_for_onnx[0].size() / dnnInputs_->featureCount())[0]; - batchOutputs.push_back(std::move(outputs)); - } + const auto outIdx = static_cast(outIdxRef); + outputSuperclusters[outIdx].push_back(candIdx); + resultTracksters[outIdx].mergeTracksters(inputTracksters[candIdx]); + linkedTracksterIdToInputTracksterId[outIdx].push_back(candIdx); - /* Build mask of tracksters already superclustered as candidates (to avoid using a trackster superclustered as candidate as a seed in further iterations). - Also mask seeds (only needed to add tracksters not in a supercluster to the output). */ - std::vector tracksterMask(tracksterCount, false); + bestSeed = kInvalid; + bestScore = nnWorkingPoint_; + }; - /////////////////////////////////////////////////////////////////////////TRKBUILDINGMOD + auto flushBatch = [&]() { + const auto pairsInBatch = static_cast(batchPairs.size()); + if (pairsInBatch == 0u) { + return; + } - unsigned int previousCandTrackster_idx = std::numeric_limits::max(); - unsigned int bestSeedForCurrentCandidate_idx = std::numeric_limits::max(); - float bestSeedForCurrentCandidate_dnnScore = nnWorkingPoint_; + input_shapes[0][0] = static_cast(pairsInBatch); + input_shapes[0][1] = static_cast(featuresPerPair); - // Track which tracksters were ever used as candidates - std::vector usedAsCandidate(tracksterCount, false); + inputs_for_onnx[0].swap(inputBatch); - auto onCandidateTransition = [&](unsigned ts_cand_idx) { - if (bestSeedForCurrentCandidate_idx < std::numeric_limits::max()) { - tracksterMask[ts_cand_idx] = true; // Mask the candidate so it’s not reused as a seed - usedAsCandidate[ts_cand_idx] = true; - - // Find the supercluster the seed belongs to (even if it's already used in another supercluster) - // Find existing supercluster for the seed - auto seed_supercluster_it = std::find_if(outputSuperclusters.begin(), - outputSuperclusters.end(), - [bestSeedForCurrentCandidate_idx](const std::vector& sc) { - return sc[0] == bestSeedForCurrentCandidate_idx; - }); - if (seed_supercluster_it == outputSuperclusters.end()) { - // No supercluster exists for this seed, create one - outputSuperclusters.emplace_back(std::initializer_list{bestSeedForCurrentCandidate_idx}); - resultTracksters.emplace_back(inputTracksters[bestSeedForCurrentCandidate_idx]); - linkedTracksterIdToInputTracksterId.emplace_back( - std::initializer_list{bestSeedForCurrentCandidate_idx}); - seed_supercluster_it = outputSuperclusters.end() - 1; - tracksterMask[bestSeedForCurrentCandidate_idx] = true; + outputs_for_onnx.clear(); + onnxRuntime_->runInto( + kInputNames, inputs_for_onnx, input_shapes, {}, outputs_for_onnx, {}, static_cast(pairsInBatch)); + + if (outputs_for_onnx.empty()) { + throw cms::Exception("RuntimeError") << "ONNX model returned no outputs."; + } + + auto const& out = outputs_for_onnx[0]; + if (out.size() < pairsInBatch) { + throw cms::Exception("RuntimeError") + << "ONNX output has size " << out.size() << " but expected at least " << pairsInBatch; + } + + for (unsigned int i = 0; i < pairsInBatch; ++i) { + const auto [seedIdx, candIdx] = batchPairs[i]; + + if (previousCand != kInvalid && candIdx != previousCand) { + onCandidateTransition(previousCand); } - unsigned int indexIntoOutputTracksters = seed_supercluster_it - outputSuperclusters.begin(); - seed_supercluster_it->push_back(ts_cand_idx); - resultTracksters[indexIntoOutputTracksters].mergeTracksters(inputTracksters[ts_cand_idx]); - linkedTracksterIdToInputTracksterId[indexIntoOutputTracksters].push_back(ts_cand_idx); + const float score = out[i]; - assert(outputSuperclusters.size() == resultTracksters.size() && - outputSuperclusters.size() == linkedTracksterIdToInputTracksterId.size()); - assert(seed_supercluster_it->size() == linkedTracksterIdToInputTracksterId[indexIntoOutputTracksters].size()); + if (score > bestScore && !usedAsCandidate[seedIdx]) { + bestSeed = seedIdx; + bestScore = score; + } - bestSeedForCurrentCandidate_idx = std::numeric_limits::max(); - bestSeedForCurrentCandidate_dnnScore = nnWorkingPoint_; + previousCand = candIdx; } + + inputBatch.swap(inputs_for_onnx[0]); + inputBatch.clear(); + batchPairs.clear(); }; - // Iterate over minibatches - for (unsigned int batchIndex = 0; batchIndex < batchOutputs.size(); batchIndex++) { - std::vector const& currentBatchOutputs = batchOutputs[batchIndex]; + for (unsigned int cand_pt = 1; cand_pt < tracksterCount; ++cand_pt) { + auto const& ts_cand = inputTracksters[trackstersIndicesPt[cand_pt]]; - for (unsigned int indexInBatch = 0; indexInBatch < tracksterIndicesUsedInDNN[batchIndex].size(); indexInBatch++) { - assert(indexInBatch < static_cast(batchOutputs[batchIndex].size())); + if (ts_cand.raw_energy() < candidateEnergyThreshold_) { + continue; + } - const unsigned int ts_seed_idx = tracksterIndicesUsedInDNN[batchIndex][indexInBatch].first; - const unsigned int ts_cand_idx = tracksterIndicesUsedInDNN[batchIndex][indexInBatch].second; - const float currentDnnScore = currentBatchOutputs[indexInBatch]; + if (!passesExplainedVarianceRatioCut(trackstersIndicesPt[cand_pt])) { + continue; + } - if (previousCandTrackster_idx != std::numeric_limits::max() && - ts_cand_idx != previousCandTrackster_idx) { - onCandidateTransition(previousCandTrackster_idx); - } + auto& tiles = tracksterTilesBothEndcaps_pt[ts_cand.barycenter().eta() > 0.f]; + const auto search_box = tiles.searchBoxEtaPhi(ts_cand.barycenter().Eta() - deltaEtaWindow_, + ts_cand.barycenter().Eta() + deltaEtaWindow_, + ts_cand.barycenter().Phi() - deltaPhiWindow_, + ts_cand.barycenter().Phi() + deltaPhiWindow_); - // Ignore seed if it was previously used as a candidate - if (currentDnnScore > bestSeedForCurrentCandidate_dnnScore && !usedAsCandidate[ts_seed_idx]) { - bestSeedForCurrentCandidate_idx = ts_seed_idx; - bestSeedForCurrentCandidate_dnnScore = currentDnnScore; - } + for (int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) { + for (int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) { + const auto bin = tiles.globalBin(eta_i, (phi_i % TileConstants::nPhiBins)); + for (unsigned int seed_pt : tiles[bin]) { + if (seed_pt >= cand_pt) { + continue; + } - previousCandTrackster_idx = ts_cand_idx; + auto const& ts_seed = inputTracksters[trackstersIndicesPt[seed_pt]]; + + if (ts_seed.raw_pt() < seedPtThreshold_) { + break; + } + + if (!passesExplainedVarianceRatioCut(trackstersIndicesPt[seed_pt]) || !trackstersPassesPIDCut(ts_seed)) { + continue; + } + + if (std::abs(ts_seed.barycenter().Eta() - ts_cand.barycenter().Eta()) >= deltaEtaWindow_) { + continue; + } + if (std::abs(deltaPhi(ts_seed.barycenter().Phi(), ts_cand.barycenter().Phi())) >= deltaPhiWindow_) { + continue; + } + + if (batchPairs.size() == maxPairsPerBatch) { + flushBatch(); + } + + const size_t base = inputBatch.size(); + inputBatch.resize(base + featuresPerPair); + dnnInputs_->computeInto(ts_seed, ts_cand, std::span(inputBatch.data() + base, featuresPerPair)); + batchPairs.emplace_back(trackstersIndicesPt[seed_pt], trackstersIndicesPt[cand_pt]); + } + } } } - onCandidateTransition(previousCandTrackster_idx); - // Create singleton superclusters for unused tracksters with enough pt - for (unsigned int ts_id = 0; ts_id < tracksterCount; ts_id++) { + flushBatch(); + onCandidateTransition(previousCand); + + for (unsigned int ts_id = 0; ts_id < tracksterCount; ++ts_id) { if (!tracksterMask[ts_id] && inputTracksters[ts_id].raw_pt() >= seedPtThreshold_) { outputSuperclusters.emplace_back(std::initializer_list{ts_id}); resultTracksters.emplace_back(inputTracksters[ts_id]); @@ -330,8 +317,6 @@ void TracksterLinkingbySuperClusteringDNN::linkTracksters( } } - /////////////////////////////////////////////////////////////////////////TRKBUILDINGMOD - #ifdef EDM_ML_DEBUG for (std::vector const& sc : outputSuperclusters) { std::ostringstream s; @@ -345,12 +330,12 @@ void TracksterLinkingbySuperClusteringDNN::linkTracksters( void TracksterLinkingbySuperClusteringDNN::fillPSetDescription(edm::ParameterSetDescription& desc) { TracksterLinkingAlgoBase::fillPSetDescription(desc); // adds algo_verbosity - desc.add("onnxModelPath")->setComment("Path to DNN (as ONNX model)"); + desc.add("onnxModelPath")->setComment("Path to DNN (as ONNX model), empty disables loading"); desc.ifValue(edm::ParameterDescription("dnnInputsVersion", "v3", true), edm::allowedValues("v1", "v2", "v3")) ->setComment( "DNN inputs version tag. Defines which set of features is fed to the DNN. Must match with the actual DNN."); - desc.add("inferenceBatchSize", 1e5) + desc.add("inferenceBatchSize", 256) ->setComment( "Size of inference batches fed to DNN. Increasing it should produce faster inference but higher memory " "usage. " @@ -385,4 +370,4 @@ void TracksterLinkingbySuperClusteringDNN::fillPSetDescription(edm::ParameterSet {static_cast(Trackster::ParticleType::photon), static_cast(Trackster::ParticleType::electron)}) ->setComment("List of PID particle types (ticl::Trackster::ParticleType enum) to consider for PID filtering"); desc.add("PIDThreshold", 0.8)->setComment("PID score threshold"); -} \ No newline at end of file +} diff --git a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.h b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.h index a714cc6666101..745b451c2b0f8 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.h +++ b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringDNN.h @@ -1,3 +1,5 @@ +#ifndef RecoHGCal_TICL_TracksterLinkingSuperClustering_H +#define RecoHGCal_TICL_TracksterLinkingSuperClustering_H /* TICL plugin for electron superclustering in HGCAL using a DNN. DNN designed and trained by Alessandro Tarabini. @@ -8,11 +10,14 @@ Inputs are CLUE3D EM tracksters. Outputs are superclusters (as vectors of IDs of Authors : Theo Cuisset , Shamik Ghosh Date : 11/2023 -*/ -#ifndef RecoHGCal_TICL_TracksterLinkingSuperClustering_H -#define RecoHGCal_TICL_TracksterLinkingSuperClustering_H +Modified by Felice Pantaleo +Improved memory usage and inference performance. +Date: 02/2026 +*/ + +#include #include namespace cms { @@ -31,13 +36,15 @@ namespace ticl { TracksterLinkingbySuperClusteringDNN(const edm::ParameterSet& ps, edm::ConsumesCollector iC, cms::Ort::ONNXRuntime const* onnxRuntime = nullptr); - /* virtual */ ~TracksterLinkingbySuperClusteringDNN() override {} + ~TracksterLinkingbySuperClusteringDNN() override = default; + static void fillPSetDescription(edm::ParameterSetDescription& iDesc); void linkTracksters(const Inputs& input, std::vector& resultTracksters, std::vector>& linkedResultTracksters, std::vector>& linkedTracksterIdToInputTracksterId) override; + void initialize(const HGCalDDDConstants* hgcons, const hgcal::RecHitTools rhtools, const edm::ESHandle bfieldH, @@ -47,17 +54,17 @@ namespace ticl { bool checkExplainedVarianceRatioCut(ticl::Trackster const& ts) const; bool trackstersPassesPIDCut(const Trackster& ts) const; - std::unique_ptr dnnInputs_; // Helper class for DNN input features computation - unsigned int inferenceBatchSize_; // Size of inference batches fed to DNN - double - nnWorkingPoint_; // Working point for neural network (above this score, consider the trackster candidate for superclustering) - float deltaEtaWindow_; // Delta eta window to consider trackster seed-candidate pairs for inference - float deltaPhiWindow_; // Delta phi window - float seedPtThreshold_; // Min pT for a trackster to be considered as supercluster seed - float candidateEnergyThreshold_; // Min energy for a trackster to be superclustered as candidate - float explVarRatioCut_energyBoundary_; // Boundary energy between low and high energy explVarRatio cut threshold - float explVarRatioMinimum_lowEnergy_; // Cut on explained variance ratio of tracksters to be considered as candidate, for trackster raw_energy < explVarRatioCut_energyBoundary - float explVarRatioMinimum_highEnergy_; // Cut on explained variance ratio of tracksters to be considered as candidate, for trackster raw_energy > explVarRatioCut_energyBoundary + // --- Configuration + std::unique_ptr dnnInputs_; + unsigned int inferenceBatchSize_; + double nnWorkingPoint_; + float deltaEtaWindow_; + float deltaPhiWindow_; + float seedPtThreshold_; + float candidateEnergyThreshold_; + float explVarRatioCut_energyBoundary_; + float explVarRatioMinimum_lowEnergy_; + float explVarRatioMinimum_highEnergy_; bool filterByTracksterPID_; std::vector tracksterPIDCategoriesToFilter_; float PIDThreshold_; diff --git a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringMustache.cc b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringMustache.cc index 72a9b891823f8..4709241727edb 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringMustache.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinkingbySuperClusteringMustache.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" diff --git a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc index a2ae1abb3629b..eb77048e5e18f 100644 --- a/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc +++ b/RecoHGCal/TICL/plugins/TracksterLinksProducer.cc @@ -13,6 +13,8 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" #include "DataFormats/Common/interface/OrphanHandle.h" @@ -21,10 +23,6 @@ #include "DataFormats/HGCalReco/interface/TICLLayerTile.h" #include "DataFormats/HGCalReco/interface/Trackster.h" -#include "PhysicsTools/TensorFlow/interface/TfGraphRecord.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" -#include "PhysicsTools/TensorFlow/interface/TfGraphDefWrapper.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" #include "RecoHGCal/TICL/interface/TracksterLinkingAlgoBase.h" @@ -49,16 +47,17 @@ using namespace ticl; using cms::Ort::ONNXRuntime; -class TracksterLinksProducer : public edm::stream::EDProducer, edm::stream::WatchRuns> { +class TracksterLinksProducer + : public edm::stream::EDProducer, edm::stream::WatchRuns> { public: - explicit TracksterLinksProducer(const edm::ParameterSet &ps, const ONNXRuntime *); + explicit TracksterLinksProducer(const edm::ParameterSet &ps, const ticl::TICLONNXGlobalCache *cache); ~TracksterLinksProducer() override {}; void produce(edm::Event &, const edm::EventSetup &) override; static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override; - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet &iConfig); - static void globalEndJob(const ONNXRuntime *); + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet &iConfig); + static void globalEndJob(const ticl::TICLONNXGlobalCache *); private: void printTrackstersDebug(const std::vector &, const char *label) const; @@ -87,7 +86,7 @@ class TracksterLinksProducer : public edm::stream::EDProducer hdc_token_; }; -TracksterLinksProducer::TracksterLinksProducer(const edm::ParameterSet &ps, const ONNXRuntime *onnxRuntime) +TracksterLinksProducer::TracksterLinksProducer(const edm::ParameterSet &ps, const ticl::TICLONNXGlobalCache *cache) : algoType_(ps.getParameter("linkingPSet").getParameter("type")), clusters_token_(consumes>(ps.getParameter("layer_clusters"))), clustersTime_token_( @@ -99,49 +98,69 @@ TracksterLinksProducer::TracksterLinksProducer(const edm::ParameterSet &ps, cons bfield_token_(esConsumes()), propagator_token_( esConsumes(edm::ESInputTag("", propName_))) { - // Loop over the edm::VInputTag and append the token to tracksters_tokens_ for (auto const &tag : ps.getParameter>("tracksters_collections")) { tracksters_tokens_.emplace_back(consumes>(tag)); } - //Loop over the edm::VInputTag of masks and append the token to original_masks_tokens_ for (auto const &tag : ps.getParameter>("original_masks")) { original_masks_tokens_.emplace_back(consumes>(tag)); } - // Initialize inference algorithm using the factory - std::string inferencePlugin = ps.getParameter("inferenceAlgo"); - edm::ParameterSet inferencePSet = ps.getParameter("pluginInferenceAlgo" + inferencePlugin); - inferenceAlgo_ = std::unique_ptr( - TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet)); - // New trackster collection after linking produces>(); - - // Links produces>>(); produces>>("linkedTracksterIdToInputTracksterId"); - // LayerClusters Mask produces>(); - auto linkingPSet = ps.getParameter("linkingPSet"); - if (algoType_ == "Skeletons") { - std::string detectorName_ = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive"; + std::string detectorName = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive"; hdc_token_ = esConsumes( - edm::ESInputTag("", detectorName_)); + edm::ESInputTag("", detectorName)); } - linkingAlgo_ = TracksterLinkingPluginFactory::get()->create(algoType_, linkingPSet, consumesCollector(), onnxRuntime); + // Enforce presence of the superclustering DNN model when using a DNN-based linking plugin. + // This fails fast at construction time, before any event processing. + auto const linkingPSet = ps.getParameter("linkingPSet"); + cms::Ort::ONNXRuntime const *linkingSession = nullptr; + + if (linkingPSet.existsAs("onnxModelPath", true)) { + auto const model = linkingPSet.getParameter("onnxModelPath"); + linkingSession = cache ? cache->getByModelPathString(model) : nullptr; + } + + linkingAlgo_ = + TracksterLinkingPluginFactory::get()->create(algoType_, linkingPSet, consumesCollector(), linkingSession); + + // Initialize inference algorithm using the factory. + // Do not build the inference plugin if it is disabled or if no model is configured (empty string => no session loaded). + if (regressionAndPid_) { + const std::string inferencePlugin = ps.getParameter("inferenceAlgo"); + if (!inferencePlugin.empty()) { + const edm::ParameterSet inferencePSet = + ps.getParameter("pluginInferenceAlgo" + inferencePlugin); + + // If the plugin config exposes model paths as std::string with default "", + // the cache will only contain sessions for non-empty paths. + const bool hasSingleModel = inferencePSet.existsAs("onnxModelPath", true) && + !inferencePSet.getParameter("onnxModelPath").empty(); + const bool hasPIDModel = inferencePSet.existsAs("onnxPIDModelPath", true) && + !inferencePSet.getParameter("onnxPIDModelPath").empty(); + const bool hasEnergyModel = inferencePSet.existsAs("onnxEnergyModelPath", true) && + !inferencePSet.getParameter("onnxEnergyModelPath").empty(); + + // Only instantiate the plugin if at least one model path is configured. + if (hasSingleModel || hasPIDModel || hasEnergyModel) { + inferenceAlgo_ = std::unique_ptr( + TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet, cache)); + } + } + } } -std::unique_ptr TracksterLinksProducer::initializeGlobalCache(const edm::ParameterSet &iConfig) { - auto const &pluginPset = iConfig.getParameter("linkingPSet"); - if (pluginPset.exists("onnxModelPath")) - return std::make_unique(pluginPset.getParameter("onnxModelPath").fullPath()); - else - return std::unique_ptr(nullptr); +std::unique_ptr TracksterLinksProducer::initializeGlobalCache( + const edm::ParameterSet &iConfig) { + return ticl::TICLONNXGlobalCache::initialize(iConfig); } -void TracksterLinksProducer::globalEndJob(const ONNXRuntime *) {} +void TracksterLinksProducer::globalEndJob(const ticl::TICLONNXGlobalCache *) {} void TracksterLinksProducer::beginRun(edm::Run const &iEvent, edm::EventSetup const &es) { if (algoType_ == "Skeletons") { @@ -237,11 +256,8 @@ void TracksterLinksProducer::produce(edm::Event &evt, const edm::EventSetup &es) rhtools_, true); - if (regressionAndPid_) { - // Run inference algorithm - inferenceAlgo_->inputData(layerClusters, *resultTracksters, rhtools_); - inferenceAlgo_->runInference( - *resultTracksters); //option to use "Linking" instead of "CLU3D"/"energyAndPid" instead of "PID" + if (regressionAndPid_ && inferenceAlgo_) { + inferenceAlgo_->runInference(layerClusters, *resultTracksters, rhtools_); } evt.put(std::move(linkedResultTracksters)); @@ -288,12 +304,6 @@ void TracksterLinksProducer::fillDescriptions(edm::ConfigurationDescriptions &de inferenceDescPFN.addNode( edm::PluginDescription("type", "TracksterInferenceByPFN", true)); desc.add("pluginInferenceAlgoTracksterInferenceByPFN", inferenceDescPFN); - - edm::ParameterSetDescription inferenceDescCNNv4; - inferenceDescCNNv4.addNode( - edm::PluginDescription("type", "TracksterInferenceByCNNv4", true)); - desc.add("pluginInferenceAlgoTracksterInferenceByCNNv4", inferenceDescCNNv4); - desc.add("linkingPSet", linkingDesc); desc.add>("tracksters_collections", {edm::InputTag("ticlTrackstersCLUE3DHigh")}); desc.add>("original_masks", @@ -303,7 +313,7 @@ void TracksterLinksProducer::fillDescriptions(edm::ConfigurationDescriptions &de desc.add("regressionAndPid", false); desc.add("detector", "HGCAL"); desc.add("propagator", "PropagatorWithMaterial"); - desc.add("inferenceAlgo", "TracksterInferenceByPFN"); + desc.add("inferenceAlgo", ""); descriptions.add("tracksterLinksProducer", desc); } diff --git a/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc b/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc deleted file mode 100644 index 3ec398d23f1f7..0000000000000 --- a/RecoHGCal/TICL/plugins/TrackstersMergeProducer.cc +++ /dev/null @@ -1,633 +0,0 @@ -#include // unique_ptr -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "FWCore/ParameterSet/interface/PluginDescription.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/ESGetToken.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" - -#include "DataFormats/CaloRecHit/interface/CaloCluster.h" -#include "DataFormats/HGCalReco/interface/Common.h" -#include "DataFormats/HGCalReco/interface/TICLLayerTile.h" -#include "DataFormats/HGCalReco/interface/Trackster.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/GeometrySurface/interface/BoundDisk.h" -#include "DataFormats/HGCalReco/interface/TICLCandidate.h" -#include "DataFormats/TrackReco/interface/TrackFwd.h" -#include "DataFormats/Math/interface/Vector3D.h" - -#include "RecoHGCal/TICL/interface/GlobalCache.h" - -#include "PhysicsTools/TensorFlow/interface/TfGraphRecord.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" -#include "PhysicsTools/TensorFlow/interface/TfGraphDefWrapper.h" - -#include "RecoHGCal/TICL/plugins/LinkingAlgoBase.h" -#include "RecoHGCal/TICL/plugins/LinkingAlgoFactory.h" -#include "RecoHGCal/TICL/plugins/LinkingAlgoByDirectionGeometric.h" - -#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" - -#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h" -#include "TrackingTools/GeomPropagators/interface/Propagator.h" -#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" - -#include "MagneticField/Engine/interface/MagneticField.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" - -#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "Geometry/CommonDetUnit/interface/GeomDet.h" - -#include "TrackstersPCA.h" - -using namespace ticl; - -class TrackstersMergeProducer : public edm::stream::EDProducer { -public: - explicit TrackstersMergeProducer(const edm::ParameterSet &ps); - ~TrackstersMergeProducer() override {} - void produce(edm::Event &, const edm::EventSetup &) override; - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - - // static methods for handling the global cache - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet &); - static void globalEndJob(TrackstersCache *); - - void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override; - -private: - typedef ticl::Trackster::IterationIndex TracksterIterIndex; - typedef ticl::Vector Vector; - - void fillTile(TICLTracksterTiles &, const std::vector &, TracksterIterIndex); - - void energyRegressionAndID(const std::vector &layerClusters, - const tensorflow::Session *, - std::vector &result) const; - void printTrackstersDebug(const std::vector &, const char *label) const; - void assignTimeToCandidates(std::vector &resultCandidates) const; - void dumpTrackster(const Trackster &) const; - - std::unique_ptr linkingAlgo_; - - const edm::EDGetTokenT> tracksters_clue3d_token_; - const edm::EDGetTokenT> clusters_token_; - const edm::EDGetTokenT>> clustersTime_token_; - const edm::EDGetTokenT> tracks_token_; - edm::EDGetTokenT> tracks_time_token_; - edm::EDGetTokenT> tracks_time_quality_token_; - edm::EDGetTokenT> tracks_time_err_token_; - const edm::EDGetTokenT> muons_token_; - const std::string tfDnnLabel_; - const edm::ESGetToken tfDnnToken_; - const tensorflow::Session *tfSession_; - - const edm::ESGetToken geometry_token_; - const std::string detector_; - const std::string propName_; - - const edm::ESGetToken bfield_token_; - const edm::ESGetToken propagator_token_; - const bool optimiseAcrossTracksters_; - const bool useMTDTiming_; - const int eta_bin_window_; - const int phi_bin_window_; - const double pt_sigma_high_; - const double pt_sigma_low_; - const double halo_max_distance2_; - const double track_min_pt_; - const double track_min_eta_; - const double track_max_eta_; - const int track_max_missing_outerhits_; - const double cosangle_align_; - const double e_over_h_threshold_; - const double pt_neutral_threshold_; - const double resol_calo_offset_had_; - const double resol_calo_scale_had_; - const double resol_calo_offset_em_; - const double resol_calo_scale_em_; - const std::string eidInputName_; - const std::string eidOutputNameEnergy_; - const std::string eidOutputNameId_; - const float eidMinClusterEnergy_; - const int eidNLayers_; - const int eidNClusters_; - std::once_flag initializeGeometry_; - - const HGCalDDDConstants *hgcons_; - - std::unique_ptr firstDisk_[2]; - - tensorflow::Session *eidSession_; - hgcal::RecHitTools rhtools_; - - static constexpr int eidNFeatures_ = 3; - - edm::ESGetToken hdc_token_; -}; - -TrackstersMergeProducer::TrackstersMergeProducer(const edm::ParameterSet &ps) - : tracksters_clue3d_token_(consumes>(ps.getParameter("trackstersclue3d"))), - clusters_token_(consumes>(ps.getParameter("layer_clusters"))), - clustersTime_token_( - consumes>>(ps.getParameter("layer_clustersTime"))), - tracks_token_(consumes>(ps.getParameter("tracks"))), - muons_token_(consumes>(ps.getParameter("muons"))), - tfDnnLabel_(ps.getParameter("tfDnnLabel")), - tfDnnToken_(esConsumes(edm::ESInputTag("", tfDnnLabel_))), - tfSession_(nullptr), - geometry_token_(esConsumes()), - detector_(ps.getParameter("detector")), - propName_(ps.getParameter("propagator")), - bfield_token_(esConsumes()), - propagator_token_( - esConsumes(edm::ESInputTag("", propName_))), - optimiseAcrossTracksters_(ps.getParameter("optimiseAcrossTracksters")), - useMTDTiming_(ps.getParameter("useMTDTiming")), - eta_bin_window_(ps.getParameter("eta_bin_window")), - phi_bin_window_(ps.getParameter("phi_bin_window")), - pt_sigma_high_(ps.getParameter("pt_sigma_high")), - pt_sigma_low_(ps.getParameter("pt_sigma_low")), - halo_max_distance2_(ps.getParameter("halo_max_distance2")), - track_min_pt_(ps.getParameter("track_min_pt")), - track_min_eta_(ps.getParameter("track_min_eta")), - track_max_eta_(ps.getParameter("track_max_eta")), - track_max_missing_outerhits_(ps.getParameter("track_max_missing_outerhits")), - cosangle_align_(ps.getParameter("cosangle_align")), - e_over_h_threshold_(ps.getParameter("e_over_h_threshold")), - pt_neutral_threshold_(ps.getParameter("pt_neutral_threshold")), - resol_calo_offset_had_(ps.getParameter("resol_calo_offset_had")), - resol_calo_scale_had_(ps.getParameter("resol_calo_scale_had")), - resol_calo_offset_em_(ps.getParameter("resol_calo_offset_em")), - resol_calo_scale_em_(ps.getParameter("resol_calo_scale_em")), - eidInputName_(ps.getParameter("eid_input_name")), - eidOutputNameEnergy_(ps.getParameter("eid_output_name_energy")), - eidOutputNameId_(ps.getParameter("eid_output_name_id")), - eidMinClusterEnergy_(ps.getParameter("eid_min_cluster_energy")), - eidNLayers_(ps.getParameter("eid_n_layers")), - eidNClusters_(ps.getParameter("eid_n_clusters")), - eidSession_(nullptr) { - produces>(); - produces>(); - - if (useMTDTiming_) { - tracks_time_token_ = consumes>(ps.getParameter("tracksTime")); - tracks_time_quality_token_ = consumes>(ps.getParameter("tracksTimeQual")); - tracks_time_err_token_ = consumes>(ps.getParameter("tracksTimeErr")); - } - - std::string detectorName_ = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive"; - hdc_token_ = - esConsumes(edm::ESInputTag("", detectorName_)); - - auto linkingPSet = ps.getParameter("linkingPSet"); - auto algoType = linkingPSet.getParameter("type"); - linkingAlgo_ = LinkingAlgoFactory::get()->create(algoType, linkingPSet); -} - -void TrackstersMergeProducer::beginRun(edm::Run const &iEvent, edm::EventSetup const &es) { - edm::ESHandle hdc = es.getHandle(hdc_token_); - hgcons_ = hdc.product(); - - edm::ESHandle geom = es.getHandle(geometry_token_); - rhtools_.setGeometry(*geom); - - edm::ESHandle bfield = es.getHandle(bfield_token_); - edm::ESHandle propagator = es.getHandle(propagator_token_); - - linkingAlgo_->initialize(hgcons_, rhtools_, bfield, propagator); -}; - -void TrackstersMergeProducer::fillTile(TICLTracksterTiles &tracksterTile, - const std::vector &tracksters, - TracksterIterIndex tracksterIteration) { - int tracksterId = 0; - for (auto const &t : tracksters) { - tracksterTile.fill(tracksterIteration, t.barycenter().eta(), t.barycenter().phi(), tracksterId); - LogDebug("TrackstersMergeProducer") << "Adding tracksterId: " << tracksterId << " into bin [eta,phi]: [ " - << tracksterTile[tracksterIteration].etaBin(t.barycenter().eta()) << ", " - << tracksterTile[tracksterIteration].phiBin(t.barycenter().phi()) - << "] for iteration: " << tracksterIteration << std::endl; - - tracksterId++; - } -} - -void TrackstersMergeProducer::dumpTrackster(const Trackster &t) const { - auto e_over_h = (t.raw_em_pt() / ((t.raw_pt() - t.raw_em_pt()) != 0. ? (t.raw_pt() - t.raw_em_pt()) : 1.)); - LogDebug("TrackstersMergeProducer") - << "\nTrackster raw_pt: " << t.raw_pt() << " raw_em_pt: " << t.raw_em_pt() << " eoh: " << e_over_h - << " barycenter: " << t.barycenter() << " eta,phi (baricenter): " << t.barycenter().eta() << ", " - << t.barycenter().phi() << " eta,phi (eigen): " << t.eigenvectors(0).eta() << ", " << t.eigenvectors(0).phi() - << " pt(eigen): " << std::sqrt(t.eigenvectors(0).Unit().perp2()) * t.raw_energy() << " seedID: " << t.seedID() - << " seedIndex: " << t.seedIndex() << " size: " << t.vertices().size() << " average usage: " - << (std::accumulate(std::begin(t.vertex_multiplicity()), std::end(t.vertex_multiplicity()), 0.) / - (float)t.vertex_multiplicity().size()) - << " raw_energy: " << t.raw_energy() << " regressed energy: " << t.regressed_energy() - << " probs(ga/e/mu/np/cp/nh/am/unk): "; - for (auto const &p : t.id_probabilities()) { - LogDebug("TrackstersMergeProducer") << std::fixed << p << " "; - } - LogDebug("TrackstersMergeProducer") << " sigmas: "; - for (auto const &s : t.sigmas()) { - LogDebug("TrackstersMergeProducer") << s << " "; - } - LogDebug("TrackstersMergeProducer") << std::endl; -} - -void TrackstersMergeProducer::produce(edm::Event &evt, const edm::EventSetup &es) { - auto resultTrackstersMerged = std::make_unique>(); - auto resultCandidates = std::make_unique>(); - auto resultFromTracks = std::make_unique>(); - tfSession_ = es.getData(tfDnnToken_).getSession(); - - edm::Handle> trackstersclue3d_h; - evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h); - - edm::Handle> track_h; - evt.getByToken(tracks_token_, track_h); - const auto &tracks = *track_h; - - const auto &layerClusters = evt.get(clusters_token_); - const auto &layerClustersTimes = evt.get(clustersTime_token_); - const auto &muons = evt.get(muons_token_); - edm::Handle> trackTime_h; - edm::Handle> trackTimeErr_h; - edm::Handle> trackTimeQual_h; - if (useMTDTiming_) { - evt.getByToken(tracks_time_token_, trackTime_h); - evt.getByToken(tracks_time_err_token_, trackTimeErr_h); - evt.getByToken(tracks_time_quality_token_, trackTimeQual_h); - } - - // Linking - linkingAlgo_->linkTracksters(track_h, - trackTime_h, - trackTimeErr_h, - trackTimeQual_h, - muons, - trackstersclue3d_h, - useMTDTiming_, - *resultCandidates, - *resultFromTracks); - - // Print debug info - LogDebug("TrackstersMergeProducer") << "Results from the linking step : " << std::endl - << "No. of Tracks : " << tracks.size() - << " No. of Tracksters : " << (*trackstersclue3d_h).size() << std::endl - << "(neutral candidates have track id -1)" << std::endl; - - std::vector &candidates = *resultCandidates; - for (const auto &cand : candidates) { - auto track_ptr = cand.trackPtr(); - auto trackster_ptrs = cand.tracksters(); - - auto track_idx = track_ptr.get() - (edm::Ptr(track_h, 0)).get(); - track_idx = (track_ptr.isNull()) ? -1 : track_idx; -#ifdef EDM_ML_DEBUG - LogDebug("TrackstersMergeProducer") << "PDG ID " << cand.pdgId() << " charge " << cand.charge() << " p " << cand.p() - << std::endl; - LogDebug("TrackstersMergeProducer") << "track id (p) : " << track_idx << " (" - << (track_ptr.isNull() ? -1 : track_ptr->p()) << ") " - << " trackster ids (E) : "; -#endif - - // Merge included tracksters - ticl::Trackster outTrackster; - outTrackster.addTrackIdx(track_idx); - auto updated_size = 0; - for (const auto &ts_ptr : trackster_ptrs) { -#ifdef EDM_ML_DEBUG - auto ts_idx = ts_ptr.get() - (edm::Ptr(trackstersclue3d_h, 0)).get(); - LogDebug("TrackstersMergeProducer") << ts_idx << " (" << ts_ptr->raw_energy() << ") "; -#endif - - auto &thisTrackster = *ts_ptr; - updated_size += thisTrackster.vertices().size(); - outTrackster.vertices().reserve(updated_size); - outTrackster.vertex_multiplicity().reserve(updated_size); - std::copy(std::begin(thisTrackster.vertices()), - std::end(thisTrackster.vertices()), - std::back_inserter(outTrackster.vertices())); - std::copy(std::begin(thisTrackster.vertex_multiplicity()), - std::end(thisTrackster.vertex_multiplicity()), - std::back_inserter(outTrackster.vertex_multiplicity())); - } - - LogDebug("TrackstersMergeProducer") << std::endl; - - // Find duplicate LCs - auto &orig_vtx = outTrackster.vertices(); - auto vtx_sorted{orig_vtx}; - std::sort(std::begin(vtx_sorted), std::end(vtx_sorted)); - for (unsigned int iLC = 1; iLC < vtx_sorted.size(); ++iLC) { - if (vtx_sorted[iLC] == vtx_sorted[iLC - 1]) { - // Clean up duplicate LCs - const auto lcIdx = vtx_sorted[iLC]; - const auto firstEl = std::find(orig_vtx.begin(), orig_vtx.end(), lcIdx); - const auto firstPos = std::distance(std::begin(orig_vtx), firstEl); - auto iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx); - while (iDup != orig_vtx.end()) { - orig_vtx.erase(iDup); - outTrackster.vertex_multiplicity().erase(outTrackster.vertex_multiplicity().begin() + - std::distance(std::begin(orig_vtx), iDup)); - outTrackster.vertex_multiplicity()[firstPos] -= 1; - iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx); - }; - } - } - - outTrackster.zeroProbabilities(); - if (!outTrackster.vertices().empty()) { - resultTrackstersMerged->push_back(outTrackster); - } - } - - assignPCAtoTracksters(*resultTrackstersMerged, - layerClusters, - layerClustersTimes, - rhtools_.getPositionLayer(rhtools_.lastLayerEE()).z(), - rhtools_); - energyRegressionAndID(layerClusters, tfSession_, *resultTrackstersMerged); - - //filling the TICLCandidates information - assert(resultTrackstersMerged->size() == resultCandidates->size()); - - auto isHad = [](const Trackster &tracksterMerge) { - return tracksterMerge.id_probability(Trackster::ParticleType::photon) + - tracksterMerge.id_probability(Trackster::ParticleType::electron) < - 0.5; - }; - for (size_t i = 0; i < resultTrackstersMerged->size(); i++) { - auto const &tm = (*resultTrackstersMerged)[i]; - auto &cand = (*resultCandidates)[i]; - //common properties - cand.setIdProbabilities(tm.id_probabilities()); - //charged candidates - if (!cand.trackPtr().isNull()) { - auto pdgId = isHad(tm) ? 211 : 11; - auto const &tk = cand.trackPtr().get(); - cand.setPdgId(pdgId * tk->charge()); - cand.setCharge(tk->charge()); - cand.setRawEnergy(tm.raw_energy()); - auto const ®rE = tm.regressed_energy(); - math::XYZTLorentzVector p4(regrE * tk->momentum().unit().x(), - regrE * tk->momentum().unit().y(), - regrE * tk->momentum().unit().z(), - regrE); - cand.setP4(p4); - } else { // neutral candidates - auto pdgId = isHad(tm) ? 130 : 22; - cand.setPdgId(pdgId); - cand.setCharge(0); - cand.setRawEnergy(tm.raw_energy()); - const float ®rE = tm.regressed_energy(); - math::XYZTLorentzVector p4(regrE * tm.barycenter().unit().x(), - regrE * tm.barycenter().unit().y(), - regrE * tm.barycenter().unit().z(), - regrE); - cand.setP4(p4); - } - } - for (auto &cand : *resultFromTracks) { //Tracks with no linked tracksters are promoted to charged hadron candidates - auto const &tk = cand.trackPtr().get(); - cand.setPdgId(211 * tk->charge()); - cand.setCharge(tk->charge()); - const float energy = std::sqrt(tk->p() * tk->p() + ticl::mpion2); - cand.setRawEnergy(energy); - math::PtEtaPhiMLorentzVector p4Polar(tk->pt(), tk->eta(), tk->phi(), ticl::mpion); - cand.setP4(p4Polar); - } - // Compute timing - resultCandidates->insert(resultCandidates->end(), resultFromTracks->begin(), resultFromTracks->end()); - assignTimeToCandidates(*resultCandidates); - - evt.put(std::move(resultTrackstersMerged)); - evt.put(std::move(resultCandidates)); -} - -void TrackstersMergeProducer::energyRegressionAndID(const std::vector &layerClusters, - const tensorflow::Session *eidSession, - std::vector &tracksters) const { - // Energy regression and particle identification strategy: - // - // 1. Set default values for regressed energy and particle id for each trackster. - // 2. Store indices of tracksters whose total sum of cluster energies is above the - // eidMinClusterEnergy_ (GeV) threshold. Inference is not applied for soft tracksters. - // 3. When no trackster passes the selection, return. - // 4. Create input and output tensors. The batch dimension is determined by the number of - // selected tracksters. - // 5. Fill input tensors with layer cluster features. Per layer, clusters are ordered descending - // by energy. Given that tensor data is contiguous in memory, we can use pointer arithmetic to - // fill values, even with batching. - // 6. Zero-fill features for empty clusters in each layer. - // 7. Batched inference. - // 8. Assign the regressed energy and id probabilities to each trackster. - // - // Indices used throughout this method: - // i -> batch element / trackster - // j -> layer - // k -> cluster - // l -> feature - - // do nothing when no trackster passes the selection (3) - int batchSize = (int)tracksters.size(); - if (batchSize == 0) { - return; - } - - for (auto &t : tracksters) { - t.setRegressedEnergy(0.f); - t.zeroProbabilities(); - } - - // create input and output tensors (4) - tensorflow::TensorShape shape({batchSize, eidNLayers_, eidNClusters_, eidNFeatures_}); - tensorflow::Tensor input(tensorflow::DT_FLOAT, shape); - tensorflow::NamedTensorList inputList = {{eidInputName_, input}}; - static constexpr int inputDimension = 4; - - std::vector outputs; - std::vector outputNames; - if (!eidOutputNameEnergy_.empty()) { - outputNames.push_back(eidOutputNameEnergy_); - } - if (!eidOutputNameId_.empty()) { - outputNames.push_back(eidOutputNameId_); - } - - // fill input tensor (5) - for (int i = 0; i < batchSize; i++) { - const Trackster &trackster = tracksters[i]; - - // per layer, we only consider the first eidNClusters_ clusters in terms of - // energy, so in order to avoid creating large / nested structures to do - // the sorting for an unknown number of total clusters, create a sorted - // list of layer cluster indices to keep track of the filled clusters - std::vector clusterIndices(trackster.vertices().size()); - for (int k = 0; k < (int)trackster.vertices().size(); k++) { - clusterIndices[k] = k; - } - sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &trackster](const int &a, const int &b) { - return layerClusters[trackster.vertices(a)].energy() > layerClusters[trackster.vertices(b)].energy(); - }); - - // keep track of the number of seen clusters per layer - std::vector seenClusters(eidNLayers_); - - // loop through clusters by descending energy - for (const int &k : clusterIndices) { - // get features per layer and cluster and store the values directly in the input tensor - const reco::CaloCluster &cluster = layerClusters[trackster.vertices(k)]; - int j = rhtools_.getLayerWithOffset(cluster.hitsAndFractions()[0].first) - 1; - if (j < eidNLayers_ && seenClusters[j] < eidNClusters_) { - // get the pointer to the first feature value for the current batch, layer and cluster - float *features = &input.tensor()(i, j, seenClusters[j], 0); - - // fill features - *(features++) = float(cluster.energy() / float(trackster.vertex_multiplicity(k))); - *(features++) = float(std::abs(cluster.eta())); - *(features) = float(cluster.phi()); - - // increment seen clusters - seenClusters[j]++; - } - } - - // zero-fill features of empty clusters in each layer (6) - for (int j = 0; j < eidNLayers_; j++) { - for (int k = seenClusters[j]; k < eidNClusters_; k++) { - float *features = &input.tensor()(i, j, k, 0); - for (int l = 0; l < eidNFeatures_; l++) { - *(features++) = 0.f; - } - } - } - } - - // run the inference (7) - tensorflow::run(eidSession, inputList, outputNames, &outputs); - - // store regressed energy per trackster (8) - if (!eidOutputNameEnergy_.empty()) { - // get the pointer to the energy tensor, dimension is batch x 1 - float *energy = outputs[0].flat().data(); - - for (int i = 0; i < batchSize; ++i) { - float regressedEnergy = - tracksters[i].raw_energy() > eidMinClusterEnergy_ ? energy[i] : tracksters[i].raw_energy(); - tracksters[i].setRegressedEnergy(regressedEnergy); - } - } - - // store id probabilities per trackster (8) - if (!eidOutputNameId_.empty()) { - // get the pointer to the id probability tensor, dimension is batch x id_probabilities.size() - int probsIdx = !eidOutputNameEnergy_.empty(); - float *probs = outputs[probsIdx].flat().data(); - int probsNumber = tracksters[0].id_probabilities().size(); - for (int i = 0; i < batchSize; ++i) { - tracksters[i].setProbabilities(&probs[i * probsNumber]); - } - } -} - -void TrackstersMergeProducer::assignTimeToCandidates(std::vector &resultCandidates) const { - for (auto &cand : resultCandidates) { - if (cand.tracksters().size() > 1) { // For single-trackster candidates the timing is already set - float time = 0.f; - float invTimeErr = 0.f; - for (const auto &tr : cand.tracksters()) { - if (tr->timeError() > 0) { - auto invTimeESq = pow(tr->timeError(), -2); - time += tr->time() * invTimeESq; - invTimeErr += invTimeESq; - } - } - if (invTimeErr > 0) { - cand.setTime(time / invTimeErr, sqrt(1.f / invTimeErr)); - } - } - } -} - -void TrackstersMergeProducer::printTrackstersDebug(const std::vector &tracksters, const char *label) const { -#ifdef EDM_ML_DEBUG - int counter = 0; - for (auto const &t : tracksters) { - LogDebug("TrackstersMergeProducer") - << counter++ << " TrackstersMergeProducer (" << label << ") obj barycenter: " << t.barycenter() - << " eta,phi (baricenter): " << t.barycenter().eta() << ", " << t.barycenter().phi() - << " eta,phi (eigen): " << t.eigenvectors(0).eta() << ", " << t.eigenvectors(0).phi() - << " pt(eigen): " << std::sqrt(t.eigenvectors(0).Unit().perp2()) * t.raw_energy() << " seedID: " << t.seedID() - << " seedIndex: " << t.seedIndex() << " size: " << t.vertices().size() << " average usage: " - << (std::accumulate(std::begin(t.vertex_multiplicity()), std::end(t.vertex_multiplicity()), 0.) / - (float)t.vertex_multiplicity().size()) - << " raw_energy: " << t.raw_energy() << " regressed energy: " << t.regressed_energy() - << " probs(ga/e/mu/np/cp/nh/am/unk): "; - for (auto const &p : t.id_probabilities()) { - LogDebug("TrackstersMergeProducer") << std::fixed << p << " "; - } - LogDebug("TrackstersMergeProducer") << " sigmas: "; - for (auto const &s : t.sigmas()) { - LogDebug("TrackstersMergeProducer") << s << " "; - } - LogDebug("TrackstersMergeProducer") << std::endl; - } -#endif -} - -void TrackstersMergeProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - edm::ParameterSetDescription desc; - - edm::ParameterSetDescription linkingDesc; - linkingDesc.addNode(edm::PluginDescription("type", "LinkingAlgoByDirectionGeometric", true)); - desc.add("linkingPSet", linkingDesc); - - desc.add("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh")); - desc.add("layer_clusters", edm::InputTag("hgcalMergeLayerClusters")); - desc.add("layer_clustersTime", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster")); - desc.add("tracks", edm::InputTag("generalTracks")); - desc.add("tracksTime", edm::InputTag("tofPID:t0")); - desc.add("tracksTimeQual", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA")); - desc.add("tracksTimeErr", edm::InputTag("tofPID:sigmat0")); - desc.add("muons", edm::InputTag("muons1stStep")); - desc.add("detector", "HGCAL"); - desc.add("propagator", "PropagatorWithMaterial"); - desc.add("optimiseAcrossTracksters", true); - desc.add("useMTDTiming", true); - desc.add("eta_bin_window", 1); - desc.add("phi_bin_window", 1); - desc.add("pt_sigma_high", 2.); - desc.add("pt_sigma_low", 2.); - desc.add("halo_max_distance2", 4.); - desc.add("track_min_pt", 1.); - desc.add("track_min_eta", 1.48); - desc.add("track_max_eta", 3.); - desc.add("track_max_missing_outerhits", 5); - desc.add("cosangle_align", 0.9945); - desc.add("e_over_h_threshold", 1.); - desc.add("pt_neutral_threshold", 2.); - desc.add("resol_calo_offset_had", 1.5); - desc.add("resol_calo_scale_had", 0.15); - desc.add("resol_calo_offset_em", 1.5); - desc.add("resol_calo_scale_em", 0.15); - desc.add("tfDnnLabel", "tracksterSelectionTf"); - desc.add("eid_input_name", "input"); - desc.add("eid_output_name_energy", "output/regressed_energy"); - desc.add("eid_output_name_id", "output/id_probabilities"); - desc.add("eid_min_cluster_energy", 2.5); - desc.add("eid_n_layers", 50); - desc.add("eid_n_clusters", 10); - descriptions.add("trackstersMergeProducer", desc); -} - -DEFINE_FWK_MODULE(TrackstersMergeProducer); diff --git a/RecoHGCal/TICL/plugins/TrackstersPCA.h b/RecoHGCal/TICL/plugins/TrackstersPCA.h index 7c8212ed58628..47ff3259614de 100644 --- a/RecoHGCal/TICL/plugins/TrackstersPCA.h +++ b/RecoHGCal/TICL/plugins/TrackstersPCA.h @@ -23,7 +23,7 @@ namespace ticl { const edm::ValueMap> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, - bool computeLocalTime = false, + bool computeLocalTime = true, bool energyWeight = true, bool clean = false, int minLayer = 10, @@ -38,9 +38,7 @@ namespace ticl { size_t N); inline unsigned getLayerFromLC(const reco::CaloCluster &LC, const hgcal::RecHitTools &rhtools) { - std::vector> thisclusterHits = LC.hitsAndFractions(); - auto layer = rhtools.getLayerWithOffset(thisclusterHits[0].first); - return layer; + return rhtools.getLayerWithOffset(LC.hitsAndFractions()[0].first); } // Sort the layer clusters in the given trackster in bins of layer. Returns : vector[index=layer, value=vector[LC index]]] diff --git a/RecoHGCal/TICL/plugins/TrackstersProducer.cc b/RecoHGCal/TICL/plugins/TrackstersProducer.cc index 1d9cf0a4fc001..938dd8d362e56 100644 --- a/RecoHGCal/TICL/plugins/TrackstersProducer.cc +++ b/RecoHGCal/TICL/plugins/TrackstersProducer.cc @@ -1,7 +1,9 @@ // Author: Felice Pantaleo,Marco Rovere - felice.pantaleo@cern.ch,marco.rovere@cern.ch // Date: 09/2018 -// user include files +#include +#include +#include #include #include "FWCore/Framework/interface/ESHandle.h" @@ -15,41 +17,41 @@ #include "FWCore/ParameterSet/interface/PluginDescription.h" #include "DataFormats/CaloRecHit/interface/CaloCluster.h" -#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" - -#include "DataFormats/HGCalReco/interface/Trackster.h" #include "DataFormats/HGCalReco/interface/TICLLayerTile.h" #include "DataFormats/HGCalReco/interface/TICLSeedingRegion.h" -#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" - -#include "RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h" +#include "DataFormats/HGCalReco/interface/Trackster.h" +#include "RecoHGCal/TICL/interface/TICLONNXGlobalCache.h" #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoBase.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoHGCal/TICL/interface/TracksterInferenceAlgoFactory.h" +#include "RecoHGCal/TICL/plugins/PatternRecognitionPluginFactory.h" -#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "Geometry/CommonDetUnit/interface/GeomDet.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" using namespace ticl; -using namespace cms::Ort; -class TrackstersProducer : public edm::stream::EDProducer { +class TrackstersProducer + : public edm::stream::EDProducer, edm::stream::WatchRuns> { public: - explicit TrackstersProducer(const edm::ParameterSet&); + explicit TrackstersProducer(const edm::ParameterSet&, ticl::TICLONNXGlobalCache const* cache); ~TrackstersProducer() override {} + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet& iConfig); + static void globalEndJob(ticl::TICLONNXGlobalCache const*); void produce(edm::Event&, const edm::EventSetup&) override; - // static methods for handling the global cache - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); - static void globalEndJob(TrackstersCache*); void beginRun(const edm::Run&, const edm::EventSetup& es) override { const auto& geom = es.getData(geometry_token_); rhtools_.setGeometry(geom); + + // Configure the pattern recognition plugin once per run/IOV. + if (doNose_) { + myAlgoHFNose_->setGeometry(rhtools_); + } else { + myAlgo_->setGeometry(rhtools_); + } } private: @@ -57,22 +59,28 @@ class TrackstersProducer : public edm::stream::EDProducer> myAlgo_; std::unique_ptr> myAlgoHFNose_; + std::unique_ptr inferenceAlgo_; + const edm::EDGetTokenT> clusters_token_; const edm::EDGetTokenT> filtered_layerclusters_mask_token_; const edm::EDGetTokenT> original_layerclusters_mask_token_; const edm::EDGetTokenT>> clustersTime_token_; + edm::EDGetTokenT layer_clusters_tiles_token_; edm::EDGetTokenT layer_clusters_tiles_hfnose_token_; const edm::EDGetTokenT> seeding_regions_token_; + ticl::Trackster::IterationIndex iterIndex_ = ticl::Trackster::IterationIndex(0); + const edm::ESGetToken geometry_token_; hgcal::RecHitTools rhtools_; const std::string itername_; }; + DEFINE_FWK_MODULE(TrackstersProducer); -TrackstersProducer::TrackstersProducer(const edm::ParameterSet& ps) +TrackstersProducer::TrackstersProducer(const edm::ParameterSet& ps, ticl::TICLONNXGlobalCache const* cache) : detector_(ps.getParameter("detector")), doNose_(detector_ == "HFNose"), clusters_token_(consumes>(ps.getParameter("layer_clusters"))), @@ -84,24 +92,34 @@ TrackstersProducer::TrackstersProducer(const edm::ParameterSet& ps) consumes>(ps.getParameter("seeding_regions"))), geometry_token_(esConsumes()), itername_(ps.getParameter("itername")) { - auto plugin = ps.getParameter("patternRecognitionBy"); - auto pluginPSet = ps.getParameter("pluginPatternRecognitionBy" + plugin); + const auto plugin = ps.getParameter("patternRecognitionBy"); + const auto pluginPSet = ps.getParameter("pluginPatternRecognitionBy" + plugin); + if (doNose_) { - myAlgoHFNose_ = PatternRecognitionHFNoseFactory::get()->create( - ps.getParameter("patternRecognitionBy"), pluginPSet, consumesCollector()); + myAlgoHFNose_ = PatternRecognitionHFNoseFactory::get()->create(plugin, pluginPSet, consumesCollector()); layer_clusters_tiles_hfnose_token_ = consumes(ps.getParameter("layer_clusters_hfnose_tiles")); } else { - myAlgo_ = PatternRecognitionFactory::get()->create( - ps.getParameter("patternRecognitionBy"), pluginPSet, consumesCollector()); + myAlgo_ = PatternRecognitionFactory::get()->create(plugin, pluginPSet, consumesCollector()); layer_clusters_tiles_token_ = consumes(ps.getParameter("layer_clusters_tiles")); } - // Initialize inference algorithm using the factory - std::string inferencePlugin = ps.getParameter("inferenceAlgo"); - edm::ParameterSet inferencePSet = ps.getParameter("pluginInferenceAlgo" + inferencePlugin); - inferenceAlgo_ = std::unique_ptr( - TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet)); + // Instantiate the inference plugin only if it is configured with at least one non-empty model path. + const std::string inferencePlugin = ps.getParameter("inferenceAlgo"); + if (!inferencePlugin.empty()) { + const edm::ParameterSet inferencePSet = ps.getParameter("pluginInferenceAlgo" + inferencePlugin); + + const bool hasSingleModel = inferencePSet.existsAs("onnxModelPath", true) && + !inferencePSet.getParameter("onnxModelPath").empty(); + const bool hasPIDModel = inferencePSet.existsAs("onnxPIDModelPath", true) && + !inferencePSet.getParameter("onnxPIDModelPath").empty(); + const bool hasEnergyModel = inferencePSet.existsAs("onnxEnergyModelPath", true) && + !inferencePSet.getParameter("onnxEnergyModelPath").empty(); + + if (hasSingleModel || hasPIDModel || hasEnergyModel) { + inferenceAlgo_ = TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet, cache); + } + } if (itername_ == "TrkEM") iterIndex_ = ticl::Trackster::TRKEM; @@ -115,127 +133,125 @@ TrackstersProducer::TrackstersProducer(const edm::ParameterSet& ps) iterIndex_ = ticl::Trackster::MIP; produces>(); - produces>(); // Mask to be applied at the next iteration + produces>(); } -void TrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // hgcalMultiClusters - edm::ParameterSetDescription desc; - desc.add("detector", "HGCAL"); - desc.add("layer_clusters", edm::InputTag("hgcalMergeLayerClusters")); - desc.add("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere")); - desc.add("original_mask", edm::InputTag("hgcalMergeLayerClusters", "InitialLayerClustersMask")); - desc.add("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster")); - desc.add("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer")); - desc.add("layer_clusters_hfnose_tiles", edm::InputTag("ticlLayerTileHFNose")); - desc.add("seeding_regions", edm::InputTag("ticlSeedingRegionProducer")); - desc.add("patternRecognitionBy", "CA"); - desc.add("itername", "unknown"); - desc.add("inferenceAlgo", "TracksterInferenceByPFN"); - - // CA Plugin - edm::ParameterSetDescription pluginDesc; - pluginDesc.addNode(edm::PluginDescription("type", "CA", true)); - desc.add("pluginPatternRecognitionByCA", pluginDesc); - // - // CLUE3D Plugin - edm::ParameterSetDescription pluginDescClue3D; - pluginDescClue3D.addNode(edm::PluginDescription("type", "CLUE3D", true)); - desc.add("pluginPatternRecognitionByCLUE3D", pluginDescClue3D); - - // FastJet Plugin - edm::ParameterSetDescription pluginDescFastJet; - pluginDescFastJet.addNode(edm::PluginDescription("type", "FastJet", true)); - desc.add("pluginPatternRecognitionByFastJet", pluginDescFastJet); - - // Recovery Plugin - edm::ParameterSetDescription pluginDescRecovery; - pluginDescRecovery.addNode(edm::PluginDescription("type", "Recovery", true)); - desc.add("pluginPatternRecognitionByRecovery", pluginDescRecovery); - - // Inference Plugins - edm::ParameterSetDescription inferenceDesc; - 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)); - desc.add("pluginInferenceAlgoTracksterInferenceByANN", inferenceDescANN); - - edm::ParameterSetDescription inferenceDescCNNv4; - inferenceDescCNNv4.addNode( - edm::PluginDescription("type", "TracksterInferenceByCNNv4", true)); - desc.add("pluginInferenceAlgoTracksterInferenceByCNNv4", inferenceDescCNNv4); - - descriptions.add("trackstersProducer", desc); +std::unique_ptr TrackstersProducer::initializeGlobalCache(const edm::ParameterSet& iConfig) { + return ticl::TICLONNXGlobalCache::initialize(iConfig); } +void TrackstersProducer::globalEndJob(ticl::TICLONNXGlobalCache const*) {} + void TrackstersProducer::produce(edm::Event& evt, const edm::EventSetup& es) { auto result = std::make_unique>(); auto initialResult = std::make_unique>(); auto output_mask = std::make_unique>(); - const std::vector& original_layerclusters_mask = evt.get(original_layerclusters_mask_token_); + const auto& original_layerclusters_mask = evt.get(original_layerclusters_mask_token_); const auto& layerClusters = evt.get(clusters_token_); const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_); const auto& layerClustersTimes = evt.get(clustersTime_token_); const auto& seeding_regions = evt.get(seeding_regions_token_); std::unordered_map> seedToTrackstersAssociation; - // if it's regional iteration and there are seeding regions - if (!seeding_regions.empty()) { - if (seeding_regions[0].index != -1) { - auto numberOfSeedingRegions = seeding_regions.size(); - for (unsigned int i = 0; i < numberOfSeedingRegions; ++i) { - seedToTrackstersAssociation.emplace(seeding_regions[i].index, 0); - } + + if (!seeding_regions.empty() && seeding_regions[0].index != -1) { + for (unsigned int i = 0; i < seeding_regions.size(); ++i) { + seedToTrackstersAssociation.emplace(seeding_regions[i].index, 0); } + } + if (!seeding_regions.empty()) { if (doNose_) { - const auto& layer_clusters_hfnose_tiles = evt.get(layer_clusters_tiles_hfnose_token_); + const auto& tiles = evt.get(layer_clusters_tiles_hfnose_token_); const typename PatternRecognitionAlgoBaseT::Inputs inputHFNose( - evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_hfnose_tiles, seeding_regions); + evt, es, layerClusters, inputClusterMask, layerClustersTimes, tiles, seeding_regions); myAlgoHFNose_->makeTracksters(inputHFNose, *initialResult, seedToTrackstersAssociation); - // Run inference algorithm - inferenceAlgo_->inputData(layerClusters, *initialResult, rhtools_); - inferenceAlgo_->runInference(*initialResult); - myAlgoHFNose_->filter(*result, *initialResult, inputHFNose, seedToTrackstersAssociation); + if (inferenceAlgo_) { + inferenceAlgo_->runInference(layerClusters, *initialResult, rhtools_); + } + + myAlgoHFNose_->filter(*result, *initialResult, inputHFNose, seedToTrackstersAssociation); } else { - const auto& layer_clusters_tiles = evt.get(layer_clusters_tiles_token_); + const auto& tiles = evt.get(layer_clusters_tiles_token_); const typename PatternRecognitionAlgoBaseT::Inputs input( - evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_tiles, seeding_regions); + evt, es, layerClusters, inputClusterMask, layerClustersTimes, tiles, seeding_regions); myAlgo_->makeTracksters(input, *initialResult, seedToTrackstersAssociation); - // Run inference algorithm - inferenceAlgo_->inputData(layerClusters, *initialResult, rhtools_); - inferenceAlgo_->runInference(*initialResult); + + if (inferenceAlgo_) { + inferenceAlgo_->runInference(layerClusters, *initialResult, rhtools_); + } + myAlgo_->filter(*result, *initialResult, input, seedToTrackstersAssociation); } } - // Now update the global mask and put it into the event + output_mask->reserve(original_layerclusters_mask.size()); - // Copy over the previous state - std::copy( - std::begin(original_layerclusters_mask), std::end(original_layerclusters_mask), std::back_inserter(*output_mask)); + std::copy(original_layerclusters_mask.begin(), original_layerclusters_mask.end(), std::back_inserter(*output_mask)); for (auto& trackster : *result) { trackster.setIteration(iterIndex_); - // Mask the used elements, accordingly for (auto const v : trackster.vertices()) { - // TODO(rovere): for the moment we mask the layer cluster completely. In - // the future, properly compute the fraction of usage. - (*output_mask)[v] = 0.; + (*output_mask)[v] = 0.f; } } evt.put(std::move(result)); evt.put(std::move(output_mask)); } + +void TrackstersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("detector", "HGCAL"); + desc.add("layer_clusters", edm::InputTag("hgcalMergeLayerClusters")); + desc.add("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere")); + desc.add("original_mask", edm::InputTag("hgcalMergeLayerClusters", "InitialLayerClustersMask")); + desc.add("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster")); + desc.add("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer")); + desc.add("layer_clusters_hfnose_tiles", edm::InputTag("ticlLayerTileHFNose")); + desc.add("seeding_regions", edm::InputTag("ticlSeedingRegionProducer")); + desc.add("patternRecognitionBy", "CLUE3D"); + desc.add("itername", "unknown"); + + // Inference plugin name (can be left as default). If the corresponding plugin PSet + // contains only empty model path strings, inference will be disabled at runtime. + desc.add("inferenceAlgo", ""); + + // Pattern recognition plugins + edm::ParameterSetDescription pluginDescCA; + pluginDescCA.addNode(edm::PluginDescription("type", "CA", true)); + desc.add("pluginPatternRecognitionByCA", pluginDescCA); + + edm::ParameterSetDescription pluginDescClue3D; + pluginDescClue3D.addNode(edm::PluginDescription("type", "CLUE3D", true)); + desc.add("pluginPatternRecognitionByCLUE3D", pluginDescClue3D); + + edm::ParameterSetDescription pluginDescFastJet; + pluginDescFastJet.addNode(edm::PluginDescription("type", "FastJet", true)); + desc.add("pluginPatternRecognitionByFastJet", pluginDescFastJet); + + edm::ParameterSetDescription pluginDescRecovery; + pluginDescRecovery.addNode(edm::PluginDescription("type", "Recovery", true)); + desc.add("pluginPatternRecognitionByRecovery", pluginDescRecovery); + + // Inference plugins + edm::ParameterSetDescription inferenceDescDNN; + inferenceDescDNN.addNode( + edm::PluginDescription("type", "TracksterInferenceByDNN", true)); + desc.add("pluginInferenceAlgoTracksterInferenceByDNN", inferenceDescDNN); + + edm::ParameterSetDescription inferenceDescCNN; + inferenceDescCNN.addNode( + edm::PluginDescription("type", "TracksterInferenceByCNN", true)); + desc.add("pluginInferenceAlgoTracksterInferenceByCNN", inferenceDescCNN); + + edm::ParameterSetDescription inferenceDescPFN; + inferenceDescPFN.addNode( + edm::PluginDescription("type", "TracksterInferenceByPFN", true)); + desc.add("pluginInferenceAlgoTracksterInferenceByPFN", inferenceDescPFN); + + descriptions.add("trackstersProducer", desc); +} diff --git a/RecoHGCal/TICL/python/CLUE3DEM_cff.py b/RecoHGCal/TICL/python/CLUE3DEM_cff.py index eca99580f8290..ba10003d347d2 100644 --- a/RecoHGCal/TICL/python/CLUE3DEM_cff.py +++ b/RecoHGCal/TICL/python/CLUE3DEM_cff.py @@ -30,9 +30,6 @@ ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersCLUE3DEM.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) - ticlCLUE3DEMStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersCLUE3DEM ,ticlTrackstersCLUE3DEM) diff --git a/RecoHGCal/TICL/python/CLUE3DHAD_cff.py b/RecoHGCal/TICL/python/CLUE3DHAD_cff.py index d510887a1533e..7a9e961528ece 100644 --- a/RecoHGCal/TICL/python/CLUE3DHAD_cff.py +++ b/RecoHGCal/TICL/python/CLUE3DHAD_cff.py @@ -30,9 +30,6 @@ ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersCLUE3DHAD.pluginPatternRecognitionByCLUE3D, computeLocalTime = cms.bool(True)) - ticlCLUE3DHADStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersCLUE3DHAD ,ticlTrackstersCLUE3DHAD) diff --git a/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py b/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py index 71c08af590678..f2dee92620aec 100644 --- a/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py +++ b/RecoHGCal/TICL/python/CLUE3DHighStep_cff.py @@ -27,23 +27,23 @@ doPidCut = True, cutHadProb = 999 ), - inferenceAlgo = cms.string('TracksterInferenceByCNNv4'), - pluginInferenceAlgoTracksterInferenceByCNNv4 = cms.PSet( + inferenceAlgo = cms.string('TracksterInferenceByCNN'), + pluginInferenceAlgoTracksterInferenceByCNN = cms.PSet( algo_verbosity = cms.int32(0), - onnxModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv4/onnx_models/energy_id_v0.onnx'), - inputNames = cms.vstring('input:0'), - outputNames = cms.vstring("output/regressed_energy:0", "output/id_probabilities:0"), - eid_min_cluster_energy = cms.double(1), + type = cms.string("TracksterInferenceByCNN"), + onnxModelPath = cms.string("RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/patternrecognition/id_v0.onnx"), + inputNames = cms.vstring("input"), + outputNames = cms.vstring("pid_output"), + eid_min_cluster_energy = cms.double(1.0), eid_n_layers = cms.int32(50), eid_n_clusters = cms.int32(10), doPID = cms.int32(1), - doRegression = cms.int32(0), - type = cms.string('TracksterInferenceByCNNv4') + miniBatchSize = cms.untracked.int32(64), ), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), - 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -57,8 +57,8 @@ 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string(''), inputNames = cms.vstring('input','input_tr_features'), output_en = cms.vstring('enreg_output'), output_id = cms.vstring('pid_output'), @@ -68,22 +68,11 @@ doPID = cms.int32(1), doRegression = cms.int32(0), type = cms.string('TracksterInferenceByPFN') - ), - - pluginInferenceAlgoTracksterInferenceByANN = cms.PSet( - algo_verbosity = cms.int32(0), - type = cms.string('TracksterInferenceByANN') - - ), + ) ) -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 = cms.string('TracksterInferenceByPFN')) - ticlCLUE3DHighStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersCLUE3DHigh ,ticlTrackstersCLUE3DHigh) diff --git a/RecoHGCal/TICL/python/EMStep_cff.py b/RecoHGCal/TICL/python/EMStep_cff.py index c8cf97fcab3c9..c5653e96fb73f 100644 --- a/RecoHGCal/TICL/python/EMStep_cff.py +++ b/RecoHGCal/TICL/python/EMStep_cff.py @@ -37,8 +37,6 @@ ), itername = "EM" ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersEM.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlEMStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersEM @@ -73,7 +71,6 @@ shower_start_max_layer = 4 ### inclusive ) ) -ticl_v5.toModify(ticlTrackstersHFNoseEM.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlHFNoseEMStepTask = cms.Task(ticlSeedingGlobalHFNose ,filteredLayerClustersHFNoseEM diff --git a/RecoHGCal/TICL/python/FastJetStep_cff.py b/RecoHGCal/TICL/python/FastJetStep_cff.py index c13488b9e66d4..c97656af88c7a 100644 --- a/RecoHGCal/TICL/python/FastJetStep_cff.py +++ b/RecoHGCal/TICL/python/FastJetStep_cff.py @@ -20,12 +20,11 @@ itername = "FastJet", patternRecognitionBy = "FastJet", pluginPatternRecognitionByFastJet = dict ( - algo_verbosity = 2 + algo_verbosity = 2, + computeLocalTime = cms.bool(True), ) ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersFastJet.pluginPatternRecognitionByFastJet, computeLocalTime = cms.bool(True)) ticlFastJetStepTask = cms.Task(ticlSeedingGlobal diff --git a/RecoHGCal/TICL/python/HADStep_cff.py b/RecoHGCal/TICL/python/HADStep_cff.py index 8c4012e7127cd..67c6cafb19f26 100644 --- a/RecoHGCal/TICL/python/HADStep_cff.py +++ b/RecoHGCal/TICL/python/HADStep_cff.py @@ -33,8 +33,6 @@ itername = "HAD" ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersHAD.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlHADStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersHAD @@ -71,7 +69,6 @@ itername = "HADn" ) -ticl_v5.toModify(ticlTrackstersHFNoseHAD.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlHFNoseHADStepTask = cms.Task(ticlSeedingGlobalHFNose ,filteredLayerClustersHFNoseHAD diff --git a/RecoHGCal/TICL/python/HLTSimTracksters_cff.py b/RecoHGCal/TICL/python/HLTSimTracksters_cff.py index dc2614d9c1a25..b4e5b6e35f629 100644 --- a/RecoHGCal/TICL/python/HLTSimTracksters_cff.py +++ b/RecoHGCal/TICL/python/HLTSimTracksters_cff.py @@ -29,7 +29,7 @@ recoTracks = cms.InputTag("hltGeneralTracks"), simclusters = cms.InputTag("mix","MergedCaloTruth"), tpToTrack = cms.InputTag("tpToHltGeneralTrackAssociation"), - computeLocalTime = cms.bool(False) + computeLocalTime = cms.bool(True) ) from Validation.Configuration.hltHGCalSimValid_cff import * diff --git a/RecoHGCal/TICL/python/MIPStep_cff.py b/RecoHGCal/TICL/python/MIPStep_cff.py index b6057ed7bfbf4..04c93a33d5f32 100644 --- a/RecoHGCal/TICL/python/MIPStep_cff.py +++ b/RecoHGCal/TICL/python/MIPStep_cff.py @@ -29,9 +29,6 @@ itername = "MIP" ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersMIP.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) - ticlMIPStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersMIP ,ticlTrackstersMIP) @@ -54,7 +51,6 @@ pluginPatternRecognitionByCA = dict(min_layers_per_trackster = 6) ) -ticl_v5.toModify(ticlTrackstersHFNoseMIP.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlHFNoseMIPStepTask = cms.Task(ticlSeedingGlobalHFNose ,filteredLayerClustersHFNoseMIP diff --git a/RecoHGCal/TICL/python/PRbyRecovery_cff.py b/RecoHGCal/TICL/python/PRbyRecovery_cff.py index 07d5b67781c2a..01ea6bc84a5c7 100644 --- a/RecoHGCal/TICL/python/PRbyRecovery_cff.py +++ b/RecoHGCal/TICL/python/PRbyRecovery_cff.py @@ -22,13 +22,14 @@ seeding_regions = "ticlSeedingGlobal", itername = "Recovery", patternRecognitionBy = "Recovery", + inferenceAlgo=cms.string(''), pluginPatternRecognitionByRecovery = dict ( algo_verbosity = 0 ), 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'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/id_v0.onnx'), + onnxEnergyModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/patternrecognition/energy_v0.onnx'), inputNames = cms.vstring( 'input', 'input_tr_features' @@ -44,7 +45,6 @@ ), ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 ticlRecoveryStepTask = cms.Task(ticlSeedingGlobal ,filteredLayerClustersRecovery diff --git a/RecoHGCal/TICL/python/SimTracksters_cff.py b/RecoHGCal/TICL/python/SimTracksters_cff.py index 1a545bd243874..886acdc8be4e1 100644 --- a/RecoHGCal/TICL/python/SimTracksters_cff.py +++ b/RecoHGCal/TICL/python/SimTracksters_cff.py @@ -14,10 +14,8 @@ ) ticlSimTracksters = _simTrackstersProducer.clone( - computeLocalTime = cms.bool(False) + computeLocalTime = cms.bool(True) ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlSimTracksters, computeLocalTime = cms.bool(True)) from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 premix_stage2.toModify(ticlSimTracksters, diff --git a/RecoHGCal/TICL/python/TrkEMStep_cff.py b/RecoHGCal/TICL/python/TrkEMStep_cff.py index e642fcc143c26..5b62f103dd86f 100644 --- a/RecoHGCal/TICL/python/TrkEMStep_cff.py +++ b/RecoHGCal/TICL/python/TrkEMStep_cff.py @@ -37,9 +37,6 @@ itername = "TrkEM", ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersTrkEM.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) - ticlTrkEMStepTask = cms.Task(ticlSeedingTrk ,filteredLayerClustersTrkEM ,ticlTrackstersTrkEM) @@ -73,7 +70,6 @@ ) ) -ticl_v5.toModify(ticlTrackstersHFNoseTrkEM.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlHFNoseTrkEMStepTask = cms.Task(ticlSeedingTrkHFNose ,filteredLayerClustersHFNoseTrkEM diff --git a/RecoHGCal/TICL/python/TrkStep_cff.py b/RecoHGCal/TICL/python/TrkStep_cff.py index 82a26349ff835..0ce6ab66f333a 100644 --- a/RecoHGCal/TICL/python/TrkStep_cff.py +++ b/RecoHGCal/TICL/python/TrkStep_cff.py @@ -35,8 +35,6 @@ itername = "Trk" ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(ticlTrackstersTrk.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) ticlTrkStepTask = cms.Task(ticlSeedingTrk ,filteredLayerClustersTrk @@ -73,8 +71,6 @@ itername = "Trkn" ) -ticl_v5.toModify(ticlTrackstersHFNoseTrk.pluginPatternRecognitionByCA, computeLocalTime = cms.bool(True)) - ticlHFNoseTrkStepTask = cms.Task(ticlSeedingTrkHFNose ,filteredLayerClustersHFNoseTrk ,ticlTrackstersHFNoseTrk) diff --git a/RecoHGCal/TICL/python/customiseForTICLv5_cff.py b/RecoHGCal/TICL/python/customiseForTICLv5_cff.py deleted file mode 100644 index c63e36f8d8fc1..0000000000000 --- a/RecoHGCal/TICL/python/customiseForTICLv5_cff.py +++ /dev/null @@ -1,127 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoHGCal.TICL.ticlDumper_cff import ticlDumper -from RecoHGCal.Configuration.RecoHGCal_EventContent_cff import customiseForTICLv5EventContent -from RecoHGCal.TICL.mergedTrackstersProducer_cfi import mergedTrackstersProducer as _mergedTrackstersProducer -from RecoLocalCalo.HGCalRecProducers.hgcalLayerClusters_cff import hgcalLayerClustersEE, hgcalLayerClustersHSi, hgcalLayerClustersHSci -from RecoLocalCalo.HGCalRecProducers.hgcalMergeLayerClusters_cfi import hgcalMergeLayerClusters -from RecoTracker.IterativeTracking.iterativeTk_cff import trackdnn_source -from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cff import recHitMapProducer -from RecoHGCal.TICL.ticlLayerTileProducer_cfi import ticlLayerTileProducer - -from RecoHGCal.TICL.pfTICLProducer_cfi import pfTICLProducer as _pfTICLProducer - -from RecoHGCal.TICL.ticlLayerTileProducer_cfi import ticlLayerTileProducer -from RecoHGCal.TICL.tracksterSelectionTf_cfi import * - -from RecoHGCal.TICL.tracksterLinksProducer_cfi import tracksterLinksProducer as _tracksterLinksProducer -from RecoHGCal.TICL.ticlCandidateProducer_cfi import ticlCandidateProducer as _ticlCandidateProducer -from RecoHGCal.Configuration.RecoHGCal_EventContent_cff import customiseForTICLv5EventContent -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels -from RecoHGCal.TICL.mergedTrackstersProducer_cfi import mergedTrackstersProducer as _mergedTrackstersProducer -from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import allTrackstersToSimTrackstersAssociationsByLCs as _allTrackstersToSimTrackstersAssociationsByLCs -from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociationByHits_cfi import allTrackstersToSimTrackstersAssociationsByHits as _allTrackstersToSimTrackstersAssociationsByHits - -from SimCalorimetry.HGCalAssociatorProducers.SimClusterToCaloParticleAssociation_cfi import SimClusterToCaloParticleAssociation -from Validation.HGCalValidation.HGCalValidator_cff import hgcalValidator -from RecoLocalCalo.HGCalRecProducers.HGCalUncalibRecHit_cfi import HGCalUncalibRecHit -from RecoHGCal.TICL.SimTracksters_cff import ticlSimTracksters, ticlSimTrackstersTask - -from RecoHGCal.TICL.FastJetStep_cff import ticlTrackstersFastJet -from RecoHGCal.TICL.EMStep_cff import ticlTrackstersEM, ticlTrackstersHFNoseEM -from RecoHGCal.TICL.TrkStep_cff import ticlTrackstersTrk, ticlTrackstersHFNoseTrk -from RecoHGCal.TICL.MIPStep_cff import ticlTrackstersMIP, ticlTrackstersHFNoseMIP -from RecoHGCal.TICL.HADStep_cff import ticlTrackstersHAD, ticlTrackstersHFNoseHAD -from RecoHGCal.TICL.CLUE3DEM_cff import ticlTrackstersCLUE3DEM -from RecoHGCal.TICL.CLUE3DHAD_cff import ticlTrackstersCLUE3DHAD -from RecoHGCal.TICL.CLUE3DHighStep_cff import ticlTrackstersCLUE3DHigh -from RecoHGCal.TICL.TrkEMStep_cff import ticlTrackstersTrkEM, filteredLayerClustersHFNoseTrkEM - -from RecoHGCal.TICL.mtdSoAProducer_cfi import mtdSoAProducer as _mtdSoAProducer - -def customiseTICLv5FromReco(process, enableDumper = False): - # TensorFlow ESSource - - process.TFESSource = cms.Task(process.trackdnn_source) - - process.hgcalLayerClustersTask = cms.Task(process.hgcalLayerClustersEE, - process.hgcalLayerClustersHSi, - process.hgcalLayerClustersHSci, - process.hgcalMergeLayerClusters) - - # Reconstruction - - process.ticlSimTracksters.computeLocalTime = cms.bool(True) - - process.ticlTrackstersCLUE3DHigh.pluginPatternRecognitionByCLUE3D.computeLocalTime = cms.bool(True) - - '''for future CLUE3D separate iterations - process.ticlTrackstersCLUE3DHAD.pluginPatternRecognitionByCLUE3D.computeLocalTime = cms.bool(True) - process.ticlTrackstersCLUE3DEM.pluginPatternRecognitionByCLUE3D.computeLocalTime = cms.bool(True) - ''' - - process.ticlLayerTileTask = cms.Task(ticlLayerTileProducer) - - process.ticlIterationsTask = cms.Task( - process.ticlTrackstersCLUE3DHigh, - ) - - process.mtdSoA = _mtdSoAProducer.clone() - process.mtdSoATask = cms.Task(process.mtdSoA) - - process.ticlTracksterLinks = _tracksterLinksProducer.clone() - process.ticlTracksterLinks = _tracksterLinksProducer.clone( - tracksters_collections = cms.VInputTag( - 'ticlTrackstersCLUE3DHigh' - ), - ) - - process.ticlCandidate = _ticlCandidateProducer.clone() - process.ticlCandidateTask = cms.Task(process.ticlCandidate) - - process.allTrackstersToSimTrackstersAssociationsByLCs = _allTrackstersToSimTrackstersAssociationsByLCs.clone() - - process.allTrackstersToSimTrackstersAssociationsByHits = _allTrackstersToSimTrackstersAssociationsByHits.clone() - - process.iterTICLTask = cms.Path(process.hgcalLayerClustersTask, - process.TFESSource, - process.ticlLayerTileTask, - process.mtdSoATask, - process.ticlIterationsTask, - process.ticlTracksterLinksTask, - process.ticlCandidateTask) - - process.particleFlowClusterHGCal.initialClusteringStep.tracksterSrc = "ticlCandidate" - process.globalrecoTask.remove(process.ticlTrackstersMerge) - - - process.mergeTICLTask = cms.Task() - process.pfTICL = _pfTICLProducer.clone( - ticlCandidateSrc = cms.InputTag('ticlCandidate'), - isTICLv5 = cms.bool(True) - ) - process.hgcalAssociators = cms.Task(process.recHitMapProducer, process.lcAssocByEnergyScoreProducer, process.layerClusterCaloParticleAssociationProducer, - process.scAssocByEnergyScoreProducer, process.layerClusterSimClusterAssociationProducer, - # FP 07/2024 new associators: - process.allLayerClusterToTracksterAssociations, process.allHitToTracksterAssociations, - process.allTrackstersToSimTrackstersAssociationsByLCs, process.allTrackstersToSimTrackstersAssociationsByHits, - process.hitToSimClusterCaloParticleAssociator, process.SimClusterToCaloParticleAssociation, - ) - - if(enableDumper): - process.ticlDumper = ticlDumper - process.TFileService = cms.Service("TFileService", - fileName=cms.string("histo.root") - ) - - process.FEVTDEBUGHLToutput_step = cms.EndPath(process.ticlDumper) - - process.TICL_Validation = cms.Path(process.ticlSimTrackstersTask, process.hgcalAssociators) - -# Schedule definition - process.schedule = cms.Schedule(process.iterTICLTask, - process.TICL_Validation, - process.FEVTDEBUGHLToutput_step) - process = customiseForTICLv5EventContent(process) - - return process diff --git a/RecoHGCal/TICL/python/customiseTICLForDumper.py b/RecoHGCal/TICL/python/customiseTICLForDumper.py new file mode 100644 index 0000000000000..ae93509535956 --- /dev/null +++ b/RecoHGCal/TICL/python/customiseTICLForDumper.py @@ -0,0 +1,12 @@ +import FWCore.ParameterSet.Config as cms +from RecoHGCal.TICL.ticlDumper_cff import ticlDumper +def customiseTICLForDumper(process, histoName="histo.root"): + + process.ticlDumper = ticlDumper.clone() + + process.TFileService = cms.Service("TFileService", + fileName=cms.string(histoName) + ) + process.FEVTDEBUGHLToutput_step = cms.EndPath( + process.FEVTDEBUGHLToutput + process.ticlDumper) + return process diff --git a/RecoHGCal/TICL/python/customiseTICLFromReco.py b/RecoHGCal/TICL/python/customiseTICLFromReco.py deleted file mode 100644 index 28fffe2121e38..0000000000000 --- a/RecoHGCal/TICL/python/customiseTICLFromReco.py +++ /dev/null @@ -1,77 +0,0 @@ -# Reconstruction -from RecoHGCal.TICL.iterativeTICL_cff import * -from RecoLocalCalo.HGCalRecProducers.hgcalLayerClusters_cff import hgcalLayerClustersEE, hgcalLayerClustersHSi, hgcalLayerClustersHSci -from RecoLocalCalo.HGCalRecProducers.hgcalMergeLayerClusters_cfi import hgcalMergeLayerClusters -from RecoHGCal.TICL.ticlDumper_cff import ticlDumper -# Validation -from Validation.HGCalValidation.HGCalValidator_cff import * -from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cff import recHitMapProducer - -# Load DNN ESSource -from RecoTracker.IterativeTracking.iterativeTk_cff import trackdnn_source - -# Automatic addition of the customisation function from RecoHGCal.Configuration.RecoHGCal_EventContent_cff -from RecoHGCal.Configuration.RecoHGCal_EventContent_cff import customiseHGCalOnlyEventContent -from SimCalorimetry.HGCalAssociatorProducers.simTracksterAssociatorByEnergyScore_cfi import simTracksterAssociatorByEnergyScore as simTsAssocByEnergyScoreProducer -from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import allTrackstersToSimTrackstersAssociationsByLCs -from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociationByHits_cfi import allTrackstersToSimTrackstersAssociationsByHits -from SimCalorimetry.HGCalAssociatorProducers.SimClusterToCaloParticleAssociation_cfi import SimClusterToCaloParticleAssociation - - -def customiseTICLFromReco(process): - # TensorFlow ESSource - process.TFESSource = cms.Task(process.trackdnn_source) - - process.hgcalLayerClustersTask = cms.Task(process.hgcalLayerClustersEE, - process.hgcalLayerClustersHSi, - process.hgcalLayerClustersHSci, - process.hgcalMergeLayerClusters) - -# Reconstruction - process.TICL = cms.Path(process.hgcalLayerClustersTask, - process.TFESSource, - process.ticlLayerTileTask, - process.ticlIterationsTask, - process.ticlTracksterMergeTask) -# Validation - process.TICL_ValidationProducers = cms.Task(process.recHitMapProducer, - process.lcAssocByEnergyScoreProducer, - process.layerClusterCaloParticleAssociationProducer, - process.scAssocByEnergyScoreProducer, - process.layerClusterSimClusterAssociationProducer, - process.simTsAssocByEnergyScoreProducer, - process.simTracksterHitLCAssociatorByEnergyScoreProducer, - process.allTrackstersToSimTrackstersAssociationsByLCs, - process.allTrackstersToSimTrackstersAssociationsByHits, - process.SimClusterToCaloParticleAssociation, - ) - - process.TICL_Validator = cms.Task(process.hgcalValidator) - process.TICL_Validation = cms.Path(process.TICL_ValidationProducers, - process.TICL_Validator - ) -# Path and EndPath definitions - process.FEVTDEBUGHLToutput_step = cms.EndPath(process.FEVTDEBUGHLToutput) - process.DQMoutput_step = cms.EndPath(process.DQMoutput) - -# Schedule definition - process.schedule = cms.Schedule(process.TICL, - process.TICL_Validation, - process.FEVTDEBUGHLToutput_step, - process.DQMoutput_step) -# call to customisation function customiseHGCalOnlyEventContent imported from RecoHGCal.Configuration.RecoHGCal_EventContent_cff - process = customiseHGCalOnlyEventContent(process) - - return process - - -def customiseTICLForDumper(process, histoName="histo.root"): - - process.ticlDumper = ticlDumper.clone() - - process.TFileService = cms.Service("TFileService", - fileName=cms.string(histoName) - ) - process.FEVTDEBUGHLToutput_step = cms.EndPath( - process.FEVTDEBUGHLToutput + process.ticlDumper) - return process diff --git a/RecoHGCal/TICL/python/iterativeTICL_cff.py b/RecoHGCal/TICL/python/iterativeTICL_cff.py index 1dc53b7123876..fec45b4b9fe3e 100644 --- a/RecoHGCal/TICL/python/iterativeTICL_cff.py +++ b/RecoHGCal/TICL/python/iterativeTICL_cff.py @@ -13,25 +13,21 @@ from RecoHGCal.TICL.ticlLayerTileProducer_cfi import ticlLayerTileProducer from RecoHGCal.TICL.pfTICLProducer_cfi import pfTICLProducer as _pfTICLProducer -from RecoHGCal.TICL.trackstersMergeProducer_cfi import trackstersMergeProducer as _trackstersMergeProducer -from RecoHGCal.TICL.tracksterSelectionTf_cfi import * from RecoHGCal.TICL.tracksterLinksProducer_cfi import tracksterLinksProducer as _tracksterLinksProducer from RecoHGCal.TICL.superclustering_cff import * from RecoHGCal.TICL.ticlCandidateProducer_cfi import ticlCandidateProducer as _ticlCandidateProducer from RecoHGCal.TICL.mtdSoAProducer_cfi import mtdSoAProducer as _mtdSoAProducer +from Configuration.ProcessModifiers.ticlv5_TrackLinkingGNN_cff import ticlv5_TrackLinkingGNN -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -from Configuration.ProcessModifiers.ticlv5_TrackLinkingGNN_cff import ticl_v5_TrackLinkingGNN - -from Configuration.ProcessModifiers.ticl_superclustering_dnn_cff import ticl_superclustering_dnn from Configuration.ProcessModifiers.ticl_superclustering_mustache_pf_cff import ticl_superclustering_mustache_pf from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl ticlLayerTileTask = cms.Task(ticlLayerTileProducer) -ticlTrackstersMerge = _trackstersMergeProducer.clone() + +# TICLv5 is now the default configuration ticlTracksterLinks = _tracksterLinksProducer.clone( tracksters_collections = cms.VInputTag( 'ticlTrackstersCLUE3DHigh', @@ -45,75 +41,47 @@ min_trackster_energy = cms.double(20), pca_quality_th = cms.double(0.85), dot_prod_th = cms.double(0.97), - lower_boundary = cms.vdouble( - 20, - 10 - ), - upper_boundary = cms.vdouble( - 150, - 100 - ), - upper_distance_projective_sqr = cms.vdouble( - 4, - 60 - ), - lower_distance_projective_sqr = cms.vdouble( - 4, - 60 - ), - min_distance_z = cms.vdouble( - 35, - 35 - ), - upper_distance_projective_sqr_closest_points = cms.vdouble( - 5, - 30 - ), - lower_distance_projective_sqr_closest_points = cms.vdouble( - 10, - 50 - ), - max_z_distance_closest_points = cms.vdouble( - 35, - 35 - ), - cylinder_radius_sqr = cms.vdouble( - 9, - 15 - ), + lower_boundary = cms.vdouble(20, 10), + upper_boundary = cms.vdouble(150, 100), + upper_distance_projective_sqr = cms.vdouble(4, 60), + lower_distance_projective_sqr = cms.vdouble(4, 60), + min_distance_z = cms.vdouble(35, 35), + upper_distance_projective_sqr_closest_points = cms.vdouble(5, 30), + lower_distance_projective_sqr_closest_points = cms.vdouble(10, 50), + max_z_distance_closest_points = cms.vdouble(35, 35), + cylinder_radius_sqr = cms.vdouble(9, 15), deltaRxy = cms.double(4.), algo_verbosity = cms.int32(0), type = cms.string('Skeletons') - ), regressionAndPid = cms.bool(False), - inferenceAlgo = cms.string('TracksterInferenceByPFN'), + inferenceAlgo = cms.string(''), pluginInferenceAlgoTracksterInferenceByDNN = cms.PSet( algo_verbosity = cms.int32(0), doPID = cms.int32(1), doRegression = cms.int32(1), inputNames = cms.vstring('input'), output_en = cms.vstring('enreg_output'), - output_id = cms.vstring('pid_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/DNN/linking/energy_v0.onnx'), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/id_v0.onnx'), + onnxEnergyModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/DNN/linking/energy_v0.onnx'), + onnxPIDModelPath = cms.string('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), + 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(2.5), + eid_min_cluster_energy = cms.double(2.5), eid_n_clusters = cms.int32(10), - eid_n_layers = cms.int32(50), - onnxEnergyModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v1.onnx'), - onnxPIDModelPath = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/id_v0.onnx'), + eid_n_layers = cms.int32(50), + onnxEnergyModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v1.onnx'), + onnxPIDModelPath = cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/linking/id_v0.onnx'), type = cms.string('TracksterInferenceByPFN') ) ) @@ -123,14 +91,9 @@ regressionAndPid = cms.bool(True), 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_v1.onnx'), - inputNames=cms.vstring( - 'input', - 'input_tr_features' - ), + onnxPIDModelPath=cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/CNN/linking/id_v0.onnx'), + onnxEnergyModelPath=cms.string('RecoHGCal/TICL/data/ticlv5/onnx_models/PFN/linking/energy_v1.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(2.5), @@ -142,11 +105,7 @@ ) ) -mtdSoA = _mtdSoAProducer.clone() - -pfTICL = _pfTICLProducer.clone() -ticl_v5.toModify(pfTICL, ticlCandidateSrc = cms.InputTag('ticlCandidate'), isTICLv5 = cms.bool(True), useTimingAverage=True) -ticl_v5_TrackLinkingGNN.toModify(ticlCandidate, +ticlv5_TrackLinkingGNN.toModify(ticlCandidate, interpretationDescPSet = cms.PSet( onnxTrkLinkingModelFirstDisk = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/TrackLinking_GNN/FirstDiskPropGNN_v0.onnx'), onnxTrkLinkingModelInterfaceDisk = cms.FileInPath('RecoHGCal/TICL/data/ticlv5/onnx_models/TrackLinking_GNN/InterfaceDiskPropGNN_v0.onnx'), @@ -157,81 +116,83 @@ type = cms.string('GNNLink') ) ) +mtdSoA = _mtdSoAProducer.clone() + +# pfTICL uses ticlCandidate by default in v5 +pfTICL = _pfTICLProducer.clone( + ticlCandidateSrc = cms.InputTag('ticlCandidate'), + useTimingAverage=True +) + + ticlPFTask = cms.Task(pfTICL) +# v5 iterations: CLUE3DHigh + Recovery ticlIterationsTask = cms.Task( - ticlCLUE3DHighStepTask + ticlCLUE3DHighStepTask, + ticlRecoveryStepTask ) -ticl_v5.toModify(ticlIterationsTask , func=lambda x : x.add(ticlRecoveryStepTask)) -''' For future separate iterations -,ticlCLUE3DEMStepTask, -,ticlCLUE3DHADStepTask - ''' - -''' For future separate iterations -ticl_v5.toReplaceWith(ticlIterationsTask, ticlIterationsTask.copyAndExclude([ticlCLUE3DHighStepTask])) -''' - -from Configuration.ProcessModifiers.fastJetTICL_cff import fastJetTICL -fastJetTICL.toModify(ticlIterationsTask, func=lambda x : x.add(ticlFastJetStepTask)) +ticlIterLabelsPSet = cms.PSet( + labels=cms.vstring( + "ticlTrackstersCLUE3DHigh", + "ticlTracksterLinks", + "ticlCandidate", + "ticlTracksterLinksSuperclusteringDNN" + ) +) -ticlIterLabels = ["ticlTrackstersCLUE3DHigh", "ticlTrackstersMerge"] -ticlIterLabels_v5 = ["ticlTrackstersCLUE3DHigh", "ticlTracksterLinks", "ticlCandidate"] +ticl_superclustering_mustache_ticl.toModify( + ticlIterLabelsPSet, + labels=cms.vstring( + "ticlTrackstersCLUE3DHigh", + "ticlTracksterLinks", + "ticlCandidate", + "ticlTracksterLinksSuperclusteringMustache" + ) +) -''' For future separate iterations -"CLUE3DEM", "CLUE3DHAD", -''' +associatorsInstances = [] +for labelts in ticlIterLabelsPSet.labels: + for labelsts in ["ticlSimTracksters", "ticlSimTrackstersfromCPs"]: + associatorsInstances.append(labelts + "To" + labelsts) + associatorsInstances.append(labelsts + "To" + labelts) -ticlTracksterMergeTask = cms.Task(ticlTrackstersMerge) ticlTracksterLinksTask = cms.Task(ticlTracksterLinks, ticlSuperclusteringTask) - -mergeTICLTask = cms.Task(ticlLayerTileTask - ,ticlIterationsTask - ,ticlTracksterMergeTask +# mergeTICLTask default for v5 +mergeTICLTask = cms.Task( + ticlLayerTileTask, + ticlIterationsTask, + ticlTracksterLinksTask ) -ticl_v5.toReplaceWith(mergeTICLTask, mergeTICLTask.copyAndExclude([ticlTracksterMergeTask])) -ticl_v5.toModify(mergeTICLTask, func=lambda x : x.add(ticlTracksterLinksTask)) - mtdSoATask = cms.Task(mtdSoA) ticlCandidateTask = cms.Task(ticlCandidate) -if ticl_v5._isChosen(): - ticlIterLabels = ticlIterLabels_v5.copy() - if ticl_superclustering_mustache_ticl._isChosen(): - ticlIterLabels.append("ticlTracksterLinksSuperclusteringMustache") - if ticl_superclustering_dnn._isChosen(): - ticlIterLabels.append("ticlTracksterLinksSuperclusteringDNN") - -associatorsInstances = [] - -for labelts in ticlIterLabels: - for labelsts in ['ticlSimTracksters', 'ticlSimTrackstersfromCPs']: - associatorsInstances.append(labelts+'To'+labelsts) - associatorsInstances.append(labelsts+'To'+labelts) - -iterTICLTask = cms.Task(mergeTICLTask, - ticlPFTask) - -ticl_v5.toModify(iterTICLTask, func=lambda x : x.add(mtdSoATask, ticlCandidateTask)) +# iterTICLTask default for v5 +iterTICLTask = cms.Task( + mergeTICLTask, + mtdSoATask, + ticlCandidateTask, + ticlPFTask +) +# HFNose remains on legacy iterations ticlLayerTileHFNose = ticlLayerTileProducer.clone( detector = 'HFNose' ) - ticlLayerTileHFNoseTask = cms.Task(ticlLayerTileHFNose) - -iterHFNoseTICLTask = cms.Task(ticlLayerTileHFNoseTask - ,ticlHFNoseTrkEMStepTask - ,ticlHFNoseEMStepTask - ,ticlHFNoseTrkStepTask - ,ticlHFNoseHADStepTask - ,ticlHFNoseMIPStepTask +iterHFNoseTICLTask = cms.Task( + ticlLayerTileHFNoseTask, + ticlHFNoseTrkEMStepTask, + ticlHFNoseEMStepTask, + ticlHFNoseTrkStepTask, + ticlHFNoseHADStepTask, + ticlHFNoseMIPStepTask ) diff --git a/RecoHGCal/TICL/python/superclustering_cff.py b/RecoHGCal/TICL/python/superclustering_cff.py index 58d13a05a30f7..c731ae98e341f 100644 --- a/RecoHGCal/TICL/python/superclustering_cff.py +++ b/RecoHGCal/TICL/python/superclustering_cff.py @@ -2,10 +2,7 @@ from RecoHGCal.TICL.tracksterLinksProducer_cfi import tracksterLinksProducer as _tracksterLinksProducer from RecoHGCal.TICL.ticlEGammaSuperClusterProducer_cfi import ticlEGammaSuperClusterProducer -from RecoEcal.EgammaClusterProducers.particleFlowSuperClusteringSequence_cff import particleFlowSuperClusterHGCal -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -from Configuration.ProcessModifiers.ticl_superclustering_dnn_cff import ticl_superclustering_dnn from Configuration.ProcessModifiers.ticl_superclustering_mustache_pf_cff import ticl_superclustering_mustache_pf from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl @@ -13,7 +10,7 @@ linkingPSet = cms.PSet( type=cms.string("SuperClusteringDNN"), algo_verbosity=cms.int32(0), - onnxModelPath = cms.FileInPath("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), + onnxModelPath = cms.string("RecoHGCal/TICL/data/superclustering/supercls_v3.onnx"), nnWorkingPoint=cms.double(0.57247), ), tracksters_collections = [cms.InputTag("ticlTrackstersCLUE3DHigh")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced @@ -27,22 +24,12 @@ tracksters_collections = [cms.InputTag("ticlTrackstersCLUE3DHigh")], # to be changed to ticlTrackstersCLUE3DEM once separate CLUE3D iterations are introduced ) -### Superclustering : 3 options : DNN, Mustache-TICL (from tracksters), Mustache-PF (converting tracksters to PFClusters, default for ticl_v4, enable with modifier for v5) -ticlSuperclusteringTask = cms.Task() - -# DNN -_dnn_task = cms.Task(ticlTracksterLinksSuperclusteringDNN) -ticl_superclustering_dnn.toReplaceWith(ticlSuperclusteringTask, _dnn_task) -ticl_superclustering_dnn.toModify(ticlEGammaSuperClusterProducer, ticlSuperClusters=cms.InputTag("ticlTracksterLinksSuperclusteringDNN")) -ticl_superclustering_dnn.toReplaceWith(particleFlowSuperClusterHGCal, ticlEGammaSuperClusterProducer) +### Superclustering : 3 options : DNN, Mustache-TICL (from tracksters) +ticlSuperclusteringTask = cms.Task(ticlTracksterLinksSuperclusteringDNN, ticlEGammaSuperClusterProducer) # Mustache-TICL -_mustache_ticl_task = cms.Task(ticlTracksterLinksSuperclusteringMustache) -ticl_superclustering_mustache_ticl.toReplaceWith(ticlSuperclusteringTask, _mustache_ticl_task) ticl_superclustering_mustache_ticl.toModify(ticlEGammaSuperClusterProducer, ticlSuperClusters=cms.InputTag("ticlTracksterLinksSuperclusteringMustache"), enableRegression=cms.bool(False)) -ticl_superclustering_mustache_ticl.toReplaceWith(particleFlowSuperClusterHGCal, ticlEGammaSuperClusterProducer) - -# Mustache-PF -# (no changes to make) +_mustache_ticl_task = cms.Task(ticlTracksterLinksSuperclusteringMustache, ticlEGammaSuperClusterProducer) +ticl_superclustering_mustache_ticl.toReplaceWith(ticlSuperclusteringTask, _mustache_ticl_task) diff --git a/RecoHGCal/TICL/python/ticlDumper_cff.py b/RecoHGCal/TICL/python/ticlDumper_cff.py index bb29047f4a35c..98738bf52084b 100644 --- a/RecoHGCal/TICL/python/ticlDumper_cff.py +++ b/RecoHGCal/TICL/python/ticlDumper_cff.py @@ -1,20 +1,18 @@ import FWCore.ParameterSet.Config as cms from RecoHGCal.TICL.ticlDumper_cfi import ticlDumper as ticlDumper_ -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -from Configuration.ProcessModifiers.ticl_superclustering_dnn_cff import ticl_superclustering_dnn from Configuration.ProcessModifiers.ticl_superclustering_mustache_pf_cff import ticl_superclustering_mustache_pf from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, associatorsInstances +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet, associatorsInstances simTrackstersCollections = ["ticlSimTracksters", "ticlSimTrackstersfromCPs"] dumperAssociators = [] for simTrackstersCollection in simTrackstersCollections: - for tracksterIteration in ticlIterLabels: + for tracksterIteration in ticlIterLabelsPSet.labels: suffix = "CP" if "fromCPs" in simTrackstersCollection else "SC" dumperAssociators.append( cms.PSet( @@ -27,7 +25,7 @@ ticlDumper = ticlDumper_.clone( - tracksterCollections = [*[cms.PSet(treeName=cms.string(label), inputTag=cms.InputTag(label)) for label in ticlIterLabels], + tracksterCollections = [*[cms.PSet(treeName=cms.string(label), inputTag=cms.InputTag(label)) for label in ticlIterLabelsPSet.labels], cms.PSet( treeName=cms.string("simtrackstersSC"), inputTag=cms.InputTag("ticlSimTracksters"), @@ -41,13 +39,8 @@ ], associators=dumperAssociators.copy(), - saveSuperclustering = cms.bool(False) + saveSuperclustering = cms.bool(True) ) -ticl_v5.toModify(ticlDumper, - ticlcandidates = cms.InputTag("ticlCandidate"), - recoSuperClusters_sourceTracksterCollection=cms.InputTag("ticlTrackstersCLUE3DHigh"), - saveSuperclustering = cms.bool(True), - trackstersInCand=cms.InputTag("ticlCandidate")) -(ticl_v5 & ticl_superclustering_mustache_pf).toModify(ticlDumper, saveSuperclustering=False, recoSuperClusters_sourceTracksterCollection=cms.InputTag("ticlTrackstersCLUE3DHigh")) +ticl_superclustering_mustache_pf.toModify(ticlDumper, saveSuperclustering=False, recoSuperClusters_sourceTracksterCollection=cms.InputTag("ticlTrackstersCLUE3DHigh")) diff --git a/RecoHGCal/TICL/python/ticl_iterations.py b/RecoHGCal/TICL/python/ticl_iterations.py deleted file mode 100644 index 40b1cda9adbdf..0000000000000 --- a/RecoHGCal/TICL/python/ticl_iterations.py +++ /dev/null @@ -1,183 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoLocalCalo.HGCalRecProducers.HGCalUncalibRecHit_cfi import * -from RecoLocalCalo.HGCalRecProducers.HGCalRecHit_cfi import * - -# patch particle flow clusters for HGC into local reco sequence -# (for now until global reco is going with some sort of clustering) -from RecoParticleFlow.PFClusterProducer.particleFlowRecHitHGC_cff import * -from RecoParticleFlow.PFClusterProducer.particleFlowClusterHGC_cfi import * -from RecoLocalCalo.HGCalRecProducers.hgcalMergeLayerClusters_cff import hgcalMergeLayerClusters -from RecoLocalCalo.HGCalRecProducers.hgcalMultiClusters_cfi import hgcalMultiClusters - -from RecoHGCal.TICL.ticlSeedingRegionProducer_cfi import ticlSeedingRegionProducer -from RecoHGCal.TICL.ticlLayerTileProducer_cfi import ticlLayerTileProducer -from RecoHGCal.TICL.trackstersProducer_cfi import trackstersProducer -from RecoHGCal.TICL.filteredLayerClustersProducer_cfi import filteredLayerClustersProducer -from RecoHGCal.TICL.ticlCandidateFromTrackstersProducer_cfi import ticlCandidateFromTrackstersProducer -from RecoHGCal.TICL.pfTICLProducer_cfi import pfTICLProducer -from Validation.HGCalValidation.ticlPFValidationDefault_cfi import ticlPFValidationDefault as ticlPFValidation - -## withReco: requires full reco of the event to run this part -## i.e. collections of generalTracks can be accessed -def TICL_iterations_withReco(process): - process.FEVTDEBUGHLTEventContent.outputCommands.extend([ - 'keep *_ticlCandidateFromTrackstersProducer*_*_*', - 'keep *_pfTICLProducer*_*_*']) - - process.ticlLayerTileProducer = ticlLayerTileProducer.clone() - - process.ticlSeedingTrk = ticlSeedingRegionProducer.clone( - algoId = 1 - ) - - process.filteredLayerClustersTrk = filteredLayerClustersProducer.clone( - clusterFilter = "ClusterFilterByAlgo", - iteration_label = "Trk" - ) - - process.trackstersTrk = trackstersProducer.clone( - filtered_mask = "filteredLayerClustersTrk:Trk", - seeding_regions = "ticlSeedingTrk", - skip_layers = 3, - min_layers_per_trackster = 5, - min_cos_theta = 0.99, # ~10 degrees - min_cos_pointing = 0.9 - ) - - process.ticlSeedingGlobal = ticlSeedingRegionProducer.clone( - algoId = 2 - ) - - process.filteredLayerClustersMIP = filteredLayerClustersProducer.clone( - clusterFilter = "ClusterFilterBySize", - max_cluster_size = 2, # inclusive - iteration_label = "MIP" - ) - - process.trackstersMIP = trackstersProducer.clone( - filtered_mask = "filteredLayerClustersMIP:MIP", - seeding_regions = "ticlSeedingGlobal", - skip_layers = 3, - min_layers_per_trackster = 15, - min_cos_theta = 0.99, # ~10 degrees - min_cos_pointing = 0.9, - out_in_dfs = False, - ) - - process.filteredLayerClusters = filteredLayerClustersProducer.clone( - clusterFilter = "ClusterFilterByAlgoAndSize", - min_cluster_size = 2, - iteration_label = "algo8", - LayerClustersInputMask = "trackstersMIP" - ) - - process.trackstersEM = trackstersProducer.clone( - max_out_in_hops = 4, - original_mask = "trackstersMIP", - filtered_mask = "filteredLayerClusters:algo8", - seeding_regions = "ticlSeedingGlobal", - skip_layers = 1, - min_layers_per_trackster = 10, - min_cos_theta = 0.984, # ~10 degrees - min_cos_pointing = 0.9 # ~26 degrees - ) - - process.trackstersHAD = trackstersProducer.clone( - filtered_mask = "filteredLayerClusters:algo8", - seeding_regions = "ticlSeedingGlobal", - skip_layers = 2, - min_layers_per_trackster = 10, - min_cos_theta = 0.8, - min_cos_pointing = 0.7 - ) - - process.ticlCandidateFromTrackstersProducer = ticlCandidateFromTrackstersProducer.clone() - - process.pfTICLProducer = pfTICLProducer.clone() - - process.hgcalMultiClusters = hgcalMultiClusters - process.TICL_Task = cms.Task( - process.ticlLayerTileProducer, - process.ticlSeedingTrk, - process.filteredLayerClustersTrk, - process.trackstersTrk, - process.ticlSeedingGlobal, - process.filteredLayerClustersMIP, - process.trackstersMIP, - process.filteredLayerClusters, - process.trackstersEM, - process.trackstersHAD, - process.ticlCandidateFromTrackstersProducer, - process.pfTICLProducer) - - process.schedule.associate(process.TICL_Task) - - process.ticlPFValidation = ticlPFValidation - process.hgcalValidation.insert(-1, process.ticlPFValidation) - - if getattr(process,'hgcalValidator'): - process.hgcalValidator.label_lcl = "hgcalMergeLayerClusters" - process.hgcalValidator.label_mcl = ["multiClustersFromTrackstersEM:MultiClustersFromTracksterByCA", "multiClustersFromTrackstersHAD:MultiClustersFromTracksterByCA"] - process.hgcalValidator.domulticlustersPlots = True - - return process - - -## TICL_iterations: to be run with local HGCAL reco only -## i.e. collections of generalTracks (track-seeded iteration) NOT available -def TICL_iterations(process): - process.ticlLayerTileProducer = ticlLayerTileProducer.clone() - - process.ticlSeedingGlobal = ticlSeedingRegionProducer.clone( - algoId = 2 - ) - - process.filteredLayerClustersMIP = filteredLayerClustersProducer.clone( - clusterFilter = "ClusterFilterBySize", - max_cluster_size = 2, # inclusive - iteration_label = "MIP" - ) - - process.trackstersMIP = trackstersProducer.clone( - filtered_mask = "filteredLayerClustersMIP:MIP", - seeding_regions = "ticlSeedingGlobal", - skip_layers = 3, - min_layers_per_trackster = 15, - min_cos_theta = 0.99, # ~10 degrees - ) - - process.filteredLayerClusters = filteredLayerClustersProducer.clone( - clusterFilter = "ClusterFilterByAlgoAndSize", - min_cluster_size = 2, - iteration_label = "algo8" - ) - - process.tracksters = trackstersProducer.clone( - original_mask = "trackstersMIP", - filtered_mask = "filteredLayerClusters:algo8", - seeding_regions = "ticlSeedingGlobal", - skip_layers = 2, - min_layers_per_trackster = 15, - min_cos_theta = 0.94, # ~20 degrees - min_cos_pointing = 0.7 - ) - - process.HGCalUncalibRecHit = HGCalUncalibRecHit - process.HGCalRecHit = HGCalRecHit - process.hgcalMergeLayerClusters = hgcalMergeLayerClusters - process.hgcalMultiClusters = hgcalMultiClusters - process.TICL_Task = cms.Task(process.HGCalUncalibRecHit, - process.HGCalRecHit, - process.hgcalMergeLayerClusters, - process.filteredLayerClustersMIP, - process.ticlLayerTileProducer, - process.ticlSeedingGlobal, - process.trackstersMIP, - process.filteredLayerClusters, - process.tracksters, - process.hgcalMultiClusters) - process.schedule = cms.Schedule(process.raw2digi_step,process.FEVTDEBUGHLToutput_step) - process.schedule.associate(process.TICL_Task) - return process - diff --git a/RecoHGCal/TICL/python/tracksterSelectionTf_cfi.py b/RecoHGCal/TICL/python/tracksterSelectionTf_cfi.py deleted file mode 100644 index 52a83d14a3d29..0000000000000 --- a/RecoHGCal/TICL/python/tracksterSelectionTf_cfi.py +++ /dev/null @@ -1,5 +0,0 @@ -from PhysicsTools.TensorFlow.tfGraphDefProducer_cfi import tfGraphDefProducer as _tfGraphDefProducer -tracksterSelectionTf = _tfGraphDefProducer.clone( - ComponentName = "tracksterSelectionTf", - FileName = "RecoHGCal/TICL/data/ticlv4/tf_models/energy_id_v0.pb" -) diff --git a/RecoHGCal/TICL/src/SuperclusteringDNNInputs.cc b/RecoHGCal/TICL/src/SuperclusteringDNNInputs.cc index 560e0106ef554..3e08b08e6fa87 100644 --- a/RecoHGCal/TICL/src/SuperclusteringDNNInputs.cc +++ b/RecoHGCal/TICL/src/SuperclusteringDNNInputs.cc @@ -6,170 +6,186 @@ // Changes: Implementation of the delta time feature under a new DNN input version (v3) for the superclustering DNN and correcting the seed pT calculation. // Date: 07/2025 +// Modified by Felice Pantaleo +// Improved memory usage and inference performance. +// Date: 02/2026 + #include "RecoHGCal/TICL/interface/SuperclusteringDNNInputs.h" #include -#include +#include #include +#include +#include #include #include -#include #include -#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/HGCalReco/interface/Trackster.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" namespace ticl { - std::vector SuperclusteringDNNInputV1::computeVector(Trackster const& ts_base, Trackster const& ts_toCluster) { - /* We use the barycenter for most of the variables below as that is what seems to have been used by Alessandro Tarabini, - but using PCA might be better. - (It would need retraining of the DNN) - */ - return {{ - std::abs(ts_toCluster.barycenter().Eta()) - std::abs(ts_base.barycenter().Eta()), //DeltaEtaBaryc - ts_toCluster.barycenter().Phi() - ts_base.barycenter().phi(), //DeltaPhiBaryc - ts_toCluster.raw_energy(), //multi_en - ts_toCluster.barycenter().Eta(), //multi_eta - ts_toCluster.raw_pt(), //multi_pt - ts_base.barycenter().Eta(), //seedEta - ts_base.barycenter().Phi(), //seedPhi - ts_base.raw_energy(), //seedEn - ts_base.raw_pt(), //seedPt - }}; - } + namespace { + template + inline float cosTheta2D(const V1& v1, const V2& v2) { + const float v1_r2 = v1.X() * v1.X() + v1.Y() * v1.Y(); + const float v2_r2 = v2.X() * v2.X() + v2.Y() * v2.Y(); + const float denom = v1_r2 * v2_r2; + if (denom <= 0.f) { + return 0.f; + } + const float pdot = v1.X() * v2.X() + v1.Y() * v2.Y(); + const float c = pdot / std::sqrt(denom); + return std::clamp(c, -1.f, 1.f); + } - // Helper functions for angles. Adapted from ROOT (3D vectors -> 2D vectors) - template - float CosTheta2D(const Vector1& v1, const Vector2& v2) { - float arg; - float v1_r2 = v1.X() * v1.X() + v1.Y() * v1.Y(); - float v2_r2 = v2.X() * v2.X() + v2.Y() * v2.Y(); - float ptot2 = v1_r2 * v2_r2; - if (ptot2 <= 0) { - arg = 0.0; - } else { - float pdot = v1.X() * v2.X() + v1.Y() * v2.Y(); - using std::sqrt; - arg = pdot / sqrt(ptot2); - if (arg > 1.0) - arg = 1.0; - if (arg < -1.0) - arg = -1.0; + template + inline float angle2D(const V1& v1, const V2& v2) { + return std::acos(cosTheta2D(v1, v2)); } - return arg; - } - template - inline float Angle2D(const Vector1& v1, const Vector2& v2) { - return static_cast(std::acos(CosTheta2D(v1, v2))); + + inline float explainedVarianceRatio(const Trackster& ts) { + const float denom = + std::accumulate(std::begin(ts.eigenvalues()), std::end(ts.eigenvalues()), 0.f, std::plus()); + if (denom == 0.f) { + edm::LogWarning("HGCalTICLSuperclustering") + << "Sum of eigenvalues was zero for trackster. Could not compute explained variance ratio."; + return 0.f; + } + return ts.eigenvalues()[0] / denom; + } + + } // namespace + + void SuperclusteringDNNInputV1::computeInto(Trackster const& ts_base, + Trackster const& ts_toCluster, + std::span out) const { + assert(out.size() >= kNFeatures); + + const auto& bc_c = ts_toCluster.barycenter(); + const auto& bc_s = ts_base.barycenter(); + + out[0] = std::abs(bc_c.Eta()) - std::abs(bc_s.Eta()); + out[1] = bc_c.Phi() - bc_s.phi(); + out[2] = ts_toCluster.raw_energy(); + out[3] = bc_c.Eta(); + out[4] = ts_toCluster.raw_pt(); + out[5] = bc_s.Eta(); + out[6] = bc_s.Phi(); + out[7] = ts_base.raw_energy(); + out[8] = ts_base.raw_pt(); } - std::vector SuperclusteringDNNInputV2::computeVector(Trackster const& ts_base, Trackster const& ts_toCluster) { + void SuperclusteringDNNInputV2::computeInto(Trackster const& ts_base, + Trackster const& ts_toCluster, + std::span out) const { + assert(out.size() >= kNFeatures); + using ROOT::Math::XYVectorF; using ROOT::Math::XYZVectorF; using ROOT::Math::VectorUtil::Angle; - XYZVectorF const& pca_seed_cmsFrame(ts_base.eigenvectors(0)); - XYZVectorF const& pca_cand_cmsFrame(ts_toCluster.eigenvectors(0)); - XYZVectorF xs(pca_seed_cmsFrame.Cross(XYZVectorF(0, 0, 1)).Unit()); - ROOT::Math::Rotation3D rot(xs, xs.Cross(pca_seed_cmsFrame).Unit(), pca_seed_cmsFrame); - - XYZVectorF pca_cand_seedFrame = rot(pca_cand_cmsFrame); // seed coordinates - - float explVar_denominator = std::accumulate( - std::begin(ts_toCluster.eigenvalues()), std::end(ts_toCluster.eigenvalues()), 0.f, std::plus()); - float explVarRatio = 0.; - if (explVar_denominator != 0.) { - explVarRatio = ts_toCluster.eigenvalues()[0] / explVar_denominator; - } else { - edm::LogWarning("HGCalTICLSuperclustering") - << "Sum of eigenvalues was zero for trackster. Could not compute explained variance ratio."; - } - return {{ - std::abs(ts_toCluster.barycenter().Eta()) - std::abs(ts_base.barycenter().Eta()), //DeltaEtaBaryc - ts_toCluster.barycenter().Phi() - ts_base.barycenter().phi(), //DeltaPhiBaryc - ts_toCluster.raw_energy(), //multi_en - ts_toCluster.barycenter().Eta(), //multi_eta - ts_toCluster.raw_pt(), //multi_pt - ts_base.barycenter().Eta(), //seedEta - ts_base.barycenter().Phi(), //seedPhi - ts_base.raw_energy(), //seedEn - ts_base.raw_pt(), //seedPt - static_cast(Angle(pca_cand_cmsFrame, pca_seed_cmsFrame)), // theta : angle between seed and candidate - Angle2D(XYVectorF(pca_cand_seedFrame.x(), pca_cand_seedFrame.z()), XYVectorF(0, 1)), // theta_xz_seedFrame - Angle2D(XYVectorF(pca_cand_seedFrame.y(), pca_cand_seedFrame.z()), XYVectorF(0, 1)), // theta_yz_seedFrame - Angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.y()), - XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.y())), // theta_xy_cmsFrame - Angle2D(XYVectorF(pca_cand_cmsFrame.y(), pca_cand_cmsFrame.z()), - XYVectorF(pca_seed_cmsFrame.y(), pca_seed_cmsFrame.z())), // theta_yz_cmsFrame - Angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.z()), - XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.z())), // theta_xz_cmsFrame - ts_toCluster.eigenvalues()[0], // explVar - explVarRatio // explVarRatio - }}; + const auto& bc_c = ts_toCluster.barycenter(); + const auto& bc_s = ts_base.barycenter(); + + const XYZVectorF& pca_seed_cmsFrame(ts_base.eigenvectors(0)); + const XYZVectorF& pca_cand_cmsFrame(ts_toCluster.eigenvectors(0)); + const XYZVectorF xs(pca_seed_cmsFrame.Cross(XYZVectorF(0, 0, 1)).Unit()); + const ROOT::Math::Rotation3D rot(xs, xs.Cross(pca_seed_cmsFrame).Unit(), pca_seed_cmsFrame); + const XYZVectorF pca_cand_seedFrame = rot(pca_cand_cmsFrame); + + const float explVarRatio = explainedVarianceRatio(ts_toCluster); + + out[0] = std::abs(bc_c.Eta()) - std::abs(bc_s.Eta()); + out[1] = bc_c.Phi() - bc_s.phi(); + out[2] = ts_toCluster.raw_energy(); + out[3] = bc_c.Eta(); + out[4] = ts_toCluster.raw_pt(); + out[5] = bc_s.Eta(); + out[6] = bc_s.Phi(); + out[7] = ts_base.raw_energy(); + out[8] = ts_base.raw_pt(); + + out[9] = Angle(pca_cand_cmsFrame, pca_seed_cmsFrame); + + out[10] = angle2D(XYVectorF(pca_cand_seedFrame.x(), pca_cand_seedFrame.z()), XYVectorF(0, 1)); + out[11] = angle2D(XYVectorF(pca_cand_seedFrame.y(), pca_cand_seedFrame.z()), XYVectorF(0, 1)); + + out[12] = angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.y()), + XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.y())); + out[13] = angle2D(XYVectorF(pca_cand_cmsFrame.y(), pca_cand_cmsFrame.z()), + XYVectorF(pca_seed_cmsFrame.y(), pca_seed_cmsFrame.z())); + out[14] = angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.z()), + XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.z())); + + out[15] = ts_toCluster.eigenvalues()[0]; + out[16] = explVarRatio; } - std::vector SuperclusteringDNNInputV3::computeVector(Trackster const& ts_base, Trackster const& ts_toCluster) { + void SuperclusteringDNNInputV3::computeInto(Trackster const& ts_base, + Trackster const& ts_toCluster, + std::span out) const { + assert(out.size() >= kNFeatures); + using ROOT::Math::XYVectorF; using ROOT::Math::XYZVectorF; using ROOT::Math::VectorUtil::Angle; - XYZVectorF const& pca_seed_cmsFrame(ts_base.eigenvectors(0)); - XYZVectorF const& pca_cand_cmsFrame(ts_toCluster.eigenvectors(0)); - XYZVectorF xs(pca_seed_cmsFrame.Cross(XYZVectorF(0, 0, 1)).Unit()); - ROOT::Math::Rotation3D rot(xs, xs.Cross(pca_seed_cmsFrame).Unit(), pca_seed_cmsFrame); - - XYZVectorF pca_cand_seedFrame = rot(pca_cand_cmsFrame); // seed coordinates - - float explVar_denominator = std::accumulate( - std::begin(ts_toCluster.eigenvalues()), std::end(ts_toCluster.eigenvalues()), 0.f, std::plus()); - float explVarRatio = 0.f; - if (explVar_denominator != 0.f) { - explVarRatio = ts_toCluster.eigenvalues()[0] / explVar_denominator; - } else { - edm::LogWarning("HGCalTICLSuperclustering") - << "Sum of eigenvalues was zero for trackster. Could not compute explained variance ratio."; - } - // modified deltaTime: set the default values <-50 or >50 to -5 - float raw_dt = ts_toCluster.time() - ts_base.time(); - float mod_deltaTime = (raw_dt < -kDeltaTimeDefault || raw_dt > kDeltaTimeDefault) ? kBadDeltaTime : raw_dt; - - return {{ - std::abs(ts_toCluster.barycenter().Eta()) - std::abs(ts_base.barycenter().Eta()), // DeltaEtaBaryc - ts_toCluster.barycenter().Phi() - ts_base.barycenter().phi(), // DeltaPhiBaryc - ts_toCluster.raw_energy(), // multi_en - ts_toCluster.barycenter().Eta(), // multi_eta - ts_toCluster.raw_pt(), // multi_pt - ts_base.barycenter().Eta(), // seedEta - ts_base.barycenter().Phi(), // seedPhi - ts_base.raw_energy(), // seedEn - ts_base.raw_pt(), // seedPt - static_cast(Angle(pca_cand_cmsFrame, pca_seed_cmsFrame)), // theta - Angle2D(XYVectorF(pca_cand_seedFrame.x(), pca_cand_seedFrame.z()), // theta_xz_seedFrame - XYVectorF(0, 1)), - Angle2D(XYVectorF(pca_cand_seedFrame.y(), pca_cand_seedFrame.z()), // theta_yz_seedFrame - XYVectorF(0, 1)), - Angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.y()), // theta_xy_cmsFrame - XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.y())), - Angle2D(XYVectorF(pca_cand_cmsFrame.y(), pca_cand_cmsFrame.z()), // theta_yz_cmsFrame - XYVectorF(pca_seed_cmsFrame.y(), pca_seed_cmsFrame.z())), - Angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.z()), // theta_xz_cmsFrame - XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.z())), - ts_toCluster.eigenvalues()[0], // explVar - explVarRatio, // explVarRatio - mod_deltaTime // mod_deltaTime - }}; + const auto& bc_c = ts_toCluster.barycenter(); + const auto& bc_s = ts_base.barycenter(); + + const XYZVectorF& pca_seed_cmsFrame(ts_base.eigenvectors(0)); + const XYZVectorF& pca_cand_cmsFrame(ts_toCluster.eigenvectors(0)); + const XYZVectorF xs(pca_seed_cmsFrame.Cross(XYZVectorF(0, 0, 1)).Unit()); + const ROOT::Math::Rotation3D rot(xs, xs.Cross(pca_seed_cmsFrame).Unit(), pca_seed_cmsFrame); + const XYZVectorF pca_cand_seedFrame = rot(pca_cand_cmsFrame); + + const float explVarRatio = explainedVarianceRatio(ts_toCluster); + + const float raw_dt = ts_toCluster.time() - ts_base.time(); + const float mod_deltaTime = (raw_dt < -kDeltaTimeDefault || raw_dt > kDeltaTimeDefault) ? kBadDeltaTime : raw_dt; + + out[0] = std::abs(bc_c.Eta()) - std::abs(bc_s.Eta()); + out[1] = bc_c.Phi() - bc_s.phi(); + out[2] = ts_toCluster.raw_energy(); + out[3] = bc_c.Eta(); + out[4] = ts_toCluster.raw_pt(); + out[5] = bc_s.Eta(); + out[6] = bc_s.Phi(); + out[7] = ts_base.raw_energy(); + out[8] = ts_base.raw_pt(); + + out[9] = Angle(pca_cand_cmsFrame, pca_seed_cmsFrame); + + out[10] = angle2D(XYVectorF(pca_cand_seedFrame.x(), pca_cand_seedFrame.z()), XYVectorF(0, 1)); + out[11] = angle2D(XYVectorF(pca_cand_seedFrame.y(), pca_cand_seedFrame.z()), XYVectorF(0, 1)); + + out[12] = angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.y()), + XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.y())); + out[13] = angle2D(XYVectorF(pca_cand_cmsFrame.y(), pca_cand_cmsFrame.z()), + XYVectorF(pca_seed_cmsFrame.y(), pca_seed_cmsFrame.z())); + out[14] = angle2D(XYVectorF(pca_cand_cmsFrame.x(), pca_cand_cmsFrame.z()), + XYVectorF(pca_seed_cmsFrame.x(), pca_seed_cmsFrame.z())); + + out[15] = ts_toCluster.eigenvalues()[0]; + out[16] = explVarRatio; + out[17] = mod_deltaTime; } std::unique_ptr makeSuperclusteringDNNInputFromString(std::string dnnInputVersion) { - if (dnnInputVersion == "v1") + if (dnnInputVersion == "v1") { return std::make_unique(); - else if (dnnInputVersion == "v2") + } + if (dnnInputVersion == "v2") { return std::make_unique(); - else if (dnnInputVersion == "v3") + } + if (dnnInputVersion == "v3") { return std::make_unique(); + } assert(false); + return nullptr; } } // namespace ticl diff --git a/RecoLocalCalo/Configuration/python/RecoLocalCalo_EventContent_cff.py b/RecoLocalCalo/Configuration/python/RecoLocalCalo_EventContent_cff.py index 056eab19a2fda..d4d8c75ffca21 100644 --- a/RecoLocalCalo/Configuration/python/RecoLocalCalo_EventContent_cff.py +++ b/RecoLocalCalo/Configuration/python/RecoLocalCalo_EventContent_cff.py @@ -64,9 +64,6 @@ ) RecoLocalCaloRECO.outputCommands.extend(RecoLocalCaloAOD.outputCommands) RecoLocalCaloRECO.outputCommands.extend(ecalLocalRecoRECO.outputCommands) -phase2_hgcal.toModify( RecoLocalCaloRECO, - outputCommands = RecoLocalCaloRECO.outputCommands + ['keep *_hgcalMultiClusters_*_*', - 'keep *_iterHGCalMultiClusters_*_*']) #FEVT content RecoLocalCaloFEVT = cms.PSet( diff --git a/RecoLocalCalo/Configuration/python/hgcalLocalReco_cff.py b/RecoLocalCalo/Configuration/python/hgcalLocalReco_cff.py index 4b1acab3d1afc..bf44f0d140460 100644 --- a/RecoLocalCalo/Configuration/python/hgcalLocalReco_cff.py +++ b/RecoLocalCalo/Configuration/python/hgcalLocalReco_cff.py @@ -9,7 +9,6 @@ # (for now until global reco is going with some sort of clustering) from RecoParticleFlow.PFClusterProducer.particleFlowRecHitHGC_cfi import * from RecoParticleFlow.PFClusterProducer.particleFlowClusterHGC_cfi import * -from RecoLocalCalo.HGCalRecProducers.hgcalMultiClusters_cfi import * from RecoLocalCalo.HGCalRecProducers.hgcalLayerClusters_cff import hgcalLayerClustersHFNose, hgcalLayerClustersEE, hgcalLayerClustersHSi, hgcalLayerClustersHSci, hgcalMergeLayerClusters hgcalLocalRecoTask = cms.Task( HGCalUncalibRecHit, @@ -19,7 +18,6 @@ hgcalLayerClustersHSi, hgcalLayerClustersHSci, hgcalMergeLayerClusters, - hgcalMultiClusters, particleFlowRecHitHGC, particleFlowClusterHGCal ) diff --git a/RecoLocalCalo/HGCalRecProducers/interface/HGCalUncalibRecHitWorkerBaseClass.h b/RecoLocalCalo/HGCalRecProducers/interface/HGCalUncalibRecHitWorkerBaseClass.h index a1d19a74f6151..fd05bf3eb3662 100644 --- a/RecoLocalCalo/HGCalRecProducers/interface/HGCalUncalibRecHitWorkerBaseClass.h +++ b/RecoLocalCalo/HGCalRecProducers/interface/HGCalUncalibRecHitWorkerBaseClass.h @@ -39,7 +39,7 @@ class HGCalUncalibRecHitWorkerBaseClass { const HGCalDigiCollection& digis, HGChfnoseUncalibratedRecHitCollection& result) = 0; - bool computeLocalTime_ = false; + bool computeLocalTime_ = true; }; #endif diff --git a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalUncalibRecHitProducer.cc b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalUncalibRecHitProducer.cc index 51d3dd2b7611b..0e8cd2f81f2c6 100644 --- a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalUncalibRecHitProducer.cc +++ b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalUncalibRecHitProducer.cc @@ -143,7 +143,7 @@ void HGCalUncalibRecHitProducer::fillDescriptions(edm::ConfigurationDescriptions }); desc.add("HGCHFNoseConfig", HGCHFNoseConfigPSet); desc.add("algo", "HGCalUncalibRecHitWorkerWeights"); - desc.add("computeLocalTime", false); + desc.add("computeLocalTime", true); descriptions.add("HGCalUncalibRecHitProducer", desc); } diff --git a/RecoLocalCalo/HGCalRecProducers/python/HGCalUncalibRecHit_cfi.py b/RecoLocalCalo/HGCalRecProducers/python/HGCalUncalibRecHit_cfi.py index 61a035b839519..5f2b35bcc2628 100644 --- a/RecoLocalCalo/HGCalRecProducers/python/HGCalUncalibRecHit_cfi.py +++ b/RecoLocalCalo/HGCalRecProducers/python/HGCalUncalibRecHit_cfi.py @@ -88,6 +88,3 @@ phase2_hgcalV19.toModify( HGCalUncalibRecHit.HGCHFNoseConfig , fCPerMIP = fCPerMIP_mean_V19 ) - -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(HGCalUncalibRecHit, computeLocalTime = cms.bool(True)) diff --git a/RecoParticleFlow/Configuration/python/RecoParticleFlow_EventContent_cff.py b/RecoParticleFlow/Configuration/python/RecoParticleFlow_EventContent_cff.py index 0c43c82cc25a6..d0aef98083410 100644 --- a/RecoParticleFlow/Configuration/python/RecoParticleFlow_EventContent_cff.py +++ b/RecoParticleFlow/Configuration/python/RecoParticleFlow_EventContent_cff.py @@ -43,8 +43,7 @@ from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing phase2_hgcal.toModify( RecoParticleFlowAOD, - outputCommands = RecoParticleFlowAOD.outputCommands + ['keep recoPFRecHits_particleFlowRecHitHGC_Cleaned_*', - 'keep recoSuperClusters_simPFProducer_*_*']) + outputCommands = RecoParticleFlowAOD.outputCommands + ['keep recoPFRecHits_particleFlowRecHitHGC_Cleaned_*']) phase2_timing.toModify( RecoParticleFlowAOD, outputCommands = RecoParticleFlowAOD.outputCommands + ['keep *_ecalBarrelClusterFastTimer_*_*']) @@ -67,8 +66,7 @@ RecoParticleFlowRECO.outputCommands.extend(RecoParticleFlowAOD.outputCommands) phase2_hgcal.toModify( RecoParticleFlowRECO, - outputCommands = RecoParticleFlowRECO.outputCommands + ['keep *_particleFlowSuperClusterHGCal_*_*', - 'keep recoPFBlocks_simPFProducer_*_*']) + outputCommands = RecoParticleFlowRECO.outputCommands + ['keep *_particleFlowSuperClusterHGCal_*_*']) # Full Event content RecoParticleFlowFEVT = cms.PSet( @@ -78,6 +76,5 @@ phase2_hgcal.toModify( RecoParticleFlowFEVT, outputCommands = RecoParticleFlowFEVT.outputCommands + ['keep recoPFRecHits_particleFlowClusterECAL__*', - 'keep recoPFRecHits_particleFlowRecHitHGC__*', - 'keep *_simPFProducer_*_*']) + 'keep recoPFRecHits_particleFlowRecHitHGC__*']) diff --git a/RecoParticleFlow/Configuration/python/RecoParticleFlow_cff.py b/RecoParticleFlow/Configuration/python/RecoParticleFlow_cff.py index 9a771cbbde265..586a7fe1ef071 100644 --- a/RecoParticleFlow/Configuration/python/RecoParticleFlow_cff.py +++ b/RecoParticleFlow/Configuration/python/RecoParticleFlow_cff.py @@ -60,26 +60,19 @@ # If true, PF(Muon)Algo will ignore muon candidates incorporated via pfTICL # in addMissingMuons. This will prevent potential double-counting. ) +# We copy the standard task to create the Phase-2 specific task +_phase2_hgcal_particleFlowRecoTask = particleFlowRecoTask.copy() + +# We replace the standard 'particleFlowTmpTask' (which runs standard PF) +# with a task that runs: +# 1. particleFlowTmpBarrel (Standard PF restricted to Barrel) +# 2. particleFlowTmp (The Merger of Barrel + TICL) +_phase2_hgcal_particleFlowRecoTask.replace( + particleFlowTmpTask, + cms.Task(particleFlowTmpBarrel, particleFlowTmp) +) -# -# for simPF -from RecoParticleFlow.PFClusterProducer.particleFlowClusterHGC_cfi import * -from RecoParticleFlow.PFTracking.hgcalTrackCollection_cfi import * -from RecoParticleFlow.PFProducer.simPFProducer_cff import * -from SimTracker.TrackerHitAssociation.tpClusterProducer_cfi import * -from SimTracker.TrackAssociatorProducers.quickTrackAssociatorByHits_cfi import * - -_phase2_hgcal_simPFTask = cms.Task( pfTrack , - hgcalTrackCollection , - tpClusterProducer , - quickTrackAssociatorByHits , - particleFlowClusterHGCalFromSimCl , - simPFProducer ) -_phase2_hgcal_simPFSequence = cms.Sequence(_phase2_hgcal_simPFTask) - -_phase2_hgcal_particleFlowRecoTask = cms.Task( _phase2_hgcal_simPFTask , particleFlowRecoTask.copy() ) -_phase2_hgcal_particleFlowRecoTask.replace( particleFlowTmpTask, cms.Task( particleFlowTmpBarrel, particleFlowTmp ) ) - +# Switch to this new task in the phase2_hgcal era phase2_hgcal.toReplaceWith( particleFlowRecoTask, _phase2_hgcal_particleFlowRecoTask ) # diff --git a/RecoParticleFlow/PFClusterProducer/python/particleFlowClusterHGC_cfi.py b/RecoParticleFlow/PFClusterProducer/python/particleFlowClusterHGC_cfi.py index 4073547214f6f..b21f14d04b147 100644 --- a/RecoParticleFlow/PFClusterProducer/python/particleFlowClusterHGC_cfi.py +++ b/RecoParticleFlow/PFClusterProducer/python/particleFlowClusterHGC_cfi.py @@ -48,7 +48,7 @@ algoName = cms.string("PFClusterFromHGCalTrackster"), thresholdsByDetector = cms.VPSet( ), - tracksterSrc = cms.InputTag("ticlTrackstersMerge"), + tracksterSrc = cms.InputTag("ticlCandidate"), clusterSrc = cms.InputTag("hgcalMergeLayerClusters"), filterByTracksterPID = cms.bool(True), pid_threshold = cms.double(0.8), @@ -74,5 +74,3 @@ initialClusteringStep = _simClusterMapper_HGCal ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(particleFlowClusterHGCal.initialClusteringStep, tracksterSrc = "ticlCandidate") diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc index 776d7ad7d30de..f8ebeacf028a7 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllHitToTracksterAssociatorsProducer.cc @@ -64,7 +64,8 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE iEvent.getByToken(hitMapToken_, hitMap); if (!iEvent.getHandle(hitsToken_)) { - edm::LogWarning("AllHitToTracksterAssociatorsProducer") << "Missing edm::RefProdVector."; + edm::LogWarning("AllHitToTracksterAssociatorsProducer") + << "Missing edm::RefProdVector. Association maps will be empty."; for (const auto& tracksterToken : tracksterCollectionTokens_) { iEvent.put(std::make_unique>(), "hitTo" + tracksterToken.first); iEvent.put(std::make_unique>(), tracksterToken.first + "ToHit"); @@ -76,7 +77,7 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE const auto hits = iEvent.get(hitsToken_); for (std::size_t index = 0; const auto& hgcRecHitCollection : hits) { if (hgcRecHitCollection->empty()) { - edm::LogWarning("AllHitToTracksterAssociatorsProducer") << "HGCRecHitCollections #" << index << " is not valid."; + LogDebug("AllHitToTracksterAssociatorsProducer") << "HGCRecHitCollections #" << index << " is empty."; } index++; } @@ -84,8 +85,8 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE edm::MultiSpan rechitSpan(hits); // Check if rechitSpan is empty if (rechitSpan.size() == 0) { - edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") - << "No valid HGCRecHitCollections found. Association maps will be empty."; + LogDebug("HitToSimClusterCaloParticleAssociatorProducer") + << "Only empty HGCRecHitCollections found. Association maps will be empty."; for (const auto& tracksterToken : tracksterCollectionTokens_) { iEvent.put(std::make_unique>(), "hitTo" + tracksterToken.first); iEvent.put(std::make_unique>(), tracksterToken.first + "ToHit"); @@ -98,7 +99,8 @@ void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iE iEvent.getByToken(tracksterToken.second, tracksters); if (!tracksters.isValid()) { - edm::LogWarning("AllHitToTracksterAssociatorsProducer") << "Missing Tracksters for one of the hitsTokens."; + LogDebug("AllHitToTracksterAssociatorsProducer") + << "Missing Tracksters for collection " << tracksterToken.first << ". Association maps will be empty."; iEvent.put(std::make_unique>(), "hitTo" + tracksterToken.first); iEvent.put(std::make_unique>(), tracksterToken.first + "ToHit"); continue; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllLayerClusterToTracksterAssociatorsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllLayerClusterToTracksterAssociatorsProducer.cc index 1b858f6626ad8..26e844bc04ad7 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllLayerClusterToTracksterAssociatorsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllLayerClusterToTracksterAssociatorsProducer.cc @@ -70,7 +70,7 @@ void AllLayerClusterToTracksterAssociatorsProducer::produce(edm::StreamID, const auto& trackstersHandle = iEvent.getHandle(tracksterToken.second); // If tracksters collection is missing, produce empty map and continue if (!trackstersHandle.isValid()) { - edm::LogWarning("MissingInput") << "Tracksters collection '" << tracksterToken.first << "' not found."; + LogDebug("MissingInput") << "Tracksters collection '" << tracksterToken.first << "' not found."; iEvent.put(std::make_unique, std::vector>>(), diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc index 2d43cf73f6784..1aefdda0e2e07 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByHitsProducer.cc @@ -101,7 +101,8 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, using namespace edm; if (!iEvent.getHandle(hitsToken_).isValid()) { - edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") << "Missing MultiHGCRecHitCollection."; + edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") + << "MultiHGCRecHitCollection is invalid. Association maps will be empty."; for (const auto& tracksterToken : tracksterCollectionTokens_) { for (const auto& simTracksterToken : simTracksterCollectionTokens_) { iEvent.put(std::make_uniqueempty()) { - edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") - << "HGCRecHitCollections #" << index << " is not valid."; + LogDebug("AllTracksterToSimTracksterAssociatorsByHitsProducer") + << "HGCRecHitCollections #" << index << " is empty."; } index++; } @@ -130,8 +131,8 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, edm::MultiSpan rechitSpan(hits); // Check if rechitSpan is empty if (rechitSpan.size() == 0) { - edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") - << "No valid HGCRecHitCollections found. Association maps will be empty."; + LogDebug("AllTracksterToSimTracksterAssociatorsByHitsProducer") + << "Only empty HGCRecHitCollections found. Association maps will be empty."; for (const auto& tracksterToken : tracksterCollectionTokens_) { for (const auto& simTracksterToken : simTracksterCollectionTokens_) { @@ -164,8 +165,8 @@ void AllTracksterToSimTracksterAssociatorsByHitsProducer::produce(edm::StreamID, iEvent.getByToken(tracksterToken.second, recoTrackstersHandle); if (!recoTrackstersHandle.isValid()) { - edm::LogWarning("AllTracksterToSimTracksterAssociatorsByHitsProducer") - << "No valid Trackster collection found. Association maps will be empty."; + LogDebug("AllTracksterToSimTracksterAssociatorsByHitsProducer") + << "The collection " << tracksterToken.first << " is invalid. Association maps will be empty."; for (const auto& simTracksterToken : simTracksterCollectionTokens_) { Handle> simTrackstersHandle; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByLCsProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByLCsProducer.cc index c1c5dc1694571..d10388e3cab5f 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByLCsProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/AllTracksterToSimTracksterAssociatorsByLCsProducer.cc @@ -95,7 +95,7 @@ void AllTracksterToSimTracksterAssociatorsByLCsProducer::produce(edm::StreamID, // If layer clusters are missing, produce empty maps and return if (!layerClustersHandle.isValid()) { - edm::LogWarning("MissingInput") << "Layer clusters collection not found. Producing empty maps."; + edm::LogWarning("MissingInput") << "Layer clusters collection is invalid. Producing empty maps."; for (const auto& tracksterToken : tracksterCollectionTokens_) { for (const auto& simTracksterToken : simTracksterCollectionTokens_) { iEvent.put(std::make_unique, diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc index 1ea89645a1b2d..1367dfded03b2 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/HitToSimClusterCaloParticleAssociatorProducer.cc @@ -42,7 +42,7 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, if (!iEvent.getHandle(hitsToken_).isValid()) { edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") - << "No valid HGCRecHitCollections found. Association maps will be empty."; + << "HGCRecHitCollections is invalid. Association maps will be empty."; // Store empty maps in the event iEvent.put(std::make_unique>(), "hitToSimClusterMap"); iEvent.put(std::make_unique>(), "hitToCaloParticleMap"); @@ -53,8 +53,7 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, const auto hits = iEvent.get(hitsToken_); for (std::size_t index = 0; const auto &hgcRecHitCollection : hits) { if (hgcRecHitCollection->empty()) { - edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") - << "HGCRecHitCollection #" << index << " is empty or not valid."; + LogDebug("HitToSimClusterCaloParticleAssociatorProducer") << "HGCRecHitCollection #" << index << " is empty."; } index++; } @@ -62,8 +61,8 @@ void HitToSimClusterCaloParticleAssociatorProducer::produce(edm::StreamID, edm::MultiSpan rechitSpan(hits); // Check if rechitSpan is empty after processing hitsTokens_ if (rechitSpan.size() == 0) { - edm::LogWarning("HitToSimClusterCaloParticleAssociatorProducer") - << "No valid HGCRecHitCollections found. Association maps will be empty."; + LogDebug("HitToSimClusterCaloParticleAssociatorProducer") + << "HGCRecHitCollection is empty. Association maps will be empty."; // Store empty maps in the event iEvent.put(std::make_unique>(), "hitToSimClusterMap"); iEvent.put(std::make_unique>(), "hitToCaloParticleMap"); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc index 7b14b1470943f..29cfded8745ea 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToCPAssociatorByEnergyScoreProducer.cc @@ -47,8 +47,7 @@ void LCToCPAssociatorByEnergyScoreProducerT::produce(edm::StreamID const auto hits = iEvent.get(hits_token_); for (std::size_t index = 0; const auto &hgcRecHitCollection : hits) { if (hgcRecHitCollection->empty()) { - edm::LogWarning("LCToCPAssociatorByEnergyScoreProducerT") - << "HGCRecHitCollections #" << index << " is not valid."; + LogDebug("LCToCPAssociatorByEnergyScoreProducerT") << "HGCRecHitCollections #" << index << " is empty."; } index++; } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc index a5387e794630d..98303119f667f 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/LCToSCAssociatorByEnergyScoreProducer.cc @@ -46,8 +46,7 @@ void LCToSCAssociatorByEnergyScoreProducerT::produce(edm::StreamID const auto hits = iEvent.get(hits_token_); for (std::size_t index = 0; const auto &hgcRecHitCollection : hits) { if (hgcRecHitCollection->empty()) { - edm::LogWarning("LCToSCAssociatorByEnergyScoreProducerT") - << "HGCRecHitCollections #" << index << " is not valid."; + LogDebug("LCToSCAssociatorByEnergyScoreProducerT") << "HGCRecHitCollections #" << index << " is empty."; } index++; } diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/MCToCPAssociatorEDProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/MCToCPAssociatorEDProducer.cc deleted file mode 100644 index 4cf5d8d3f79d8..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/MCToCPAssociatorEDProducer.cc +++ /dev/null @@ -1,94 +0,0 @@ -// -// Original Author: Leonardo Cristella -// Created: Tue Feb 2 10:52:11 CET 2021 -// -// - -// system include files -#include -#include - -// user include files -#include "FWCore/Framework/interface/global/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/Framework/interface/ESHandle.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "SimDataFormats/Associations/interface/MultiClusterToCaloParticleAssociator.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" -#include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h" - -#include "FWCore/Utilities/interface/EDGetToken.h" - -// -// class decleration -// - -class MCToCPAssociatorEDProducer : public edm::global::EDProducer<> { -public: - explicit MCToCPAssociatorEDProducer(const edm::ParameterSet &); - ~MCToCPAssociatorEDProducer() override; - -private: - void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; - - edm::EDGetTokenT CPCollectionToken_; - edm::EDGetTokenT MCCollectionToken_; - edm::EDGetTokenT associatorToken_; -}; - -MCToCPAssociatorEDProducer::MCToCPAssociatorEDProducer(const edm::ParameterSet &pset) { - produces(); - produces(); - - CPCollectionToken_ = consumes(pset.getParameter("label_cp")); - MCCollectionToken_ = consumes(pset.getParameter("label_mcl")); - associatorToken_ = - consumes(pset.getParameter("associator")); -} - -MCToCPAssociatorEDProducer::~MCToCPAssociatorEDProducer() {} - -// -// member functions -// - -// ------------ method called to produce the data ------------ -void MCToCPAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const { - using namespace edm; - - edm::Handle theAssociator; - iEvent.getByToken(associatorToken_, theAssociator); - - Handle CPCollection; - iEvent.getByToken(CPCollectionToken_, CPCollection); - - Handle MCCollection; - iEvent.getByToken(MCCollectionToken_, MCCollection); - - // associate MutiCluster and CP - LogTrace("AssociatorValidator") << "Calling associateRecoToSim method" - << "\n"; - hgcal::RecoToSimCollectionWithMultiClusters recSimColl = - theAssociator->associateRecoToSim(MCCollection, CPCollection); - - LogTrace("AssociatorValidator") << "Calling associateSimToReco method" - << "\n"; - hgcal::SimToRecoCollectionWithMultiClusters simRecColl = - theAssociator->associateSimToReco(MCCollection, CPCollection); - - auto rts = std::make_unique(recSimColl); - auto str = std::make_unique(simRecColl); - - iEvent.put(std::move(rts)); - iEvent.put(std::move(str)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(MCToCPAssociatorEDProducer); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.cc deleted file mode 100644 index 89aa9dc5ad0ba..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.cc +++ /dev/null @@ -1,531 +0,0 @@ -#include "TSToSCAssociatorByEnergyScoreImpl.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" - -TSToSCAssociatorByEnergyScoreImpl::TSToSCAssociatorByEnergyScoreImpl( - edm::EDProductGetter const& productGetter, - bool hardScatterOnly, - std::shared_ptr recHitTools, - const std::unordered_map* hitMap, - std::vector& hits) - : hardScatterOnly_(hardScatterOnly), - recHitTools_(recHitTools), - hitMap_(hitMap), - hits_(hits), - productGetter_(&productGetter) { - layers_ = recHitTools_->lastLayerBH(); -} - -ticl::association TSToSCAssociatorByEnergyScoreImpl::makeConnections( - const edm::Handle& tCH, - const edm::Handle& lCCH, - const edm::Handle& sCCH) const { - // Get collections - const auto& tracksters = *tCH.product(); - const auto& layerClusters = *lCCH.product(); - const auto& simClusters = *sCCH.product(); - auto nTracksters = tracksters.size(); - - //There shouldn't be any SimTracks from different crossings, but maybe they will be added later. - //At the moment there should be one SimTrack in each SimCluster. - auto nSimClusters = simClusters.size(); - std::vector sCIndices; - for (unsigned int scId = 0; scId < nSimClusters; ++scId) { - if (hardScatterOnly_ && (simClusters[scId].g4Tracks()[0].eventId().event() != 0 or - simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() != 0)) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "Excluding SimCluster from event: " << simClusters[scId].g4Tracks()[0].eventId().event() - << " with BX: " << simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() << std::endl; - continue; - } - sCIndices.emplace_back(scId); - } - nSimClusters = sCIndices.size(); - - // Initialize tssInSimCluster. To be returned outside, since it contains the - // information to compute the SimCluster-To-Trackster score. - // tssInSimCluster[scId]: - ticl::simClusterToTrackster tssInSimCluster; - tssInSimCluster.resize(nSimClusters); - for (unsigned int i = 0; i < nSimClusters; ++i) { - tssInSimCluster[i].simClusterId = i; - tssInSimCluster[i].energy = 0.f; - tssInSimCluster[i].hits_and_fractions.clear(); - } - - // Fill detIdToSimClusterId_Map and update tssInSimCluster - std::unordered_map> detIdToSimClusterId_Map; - for (const auto& scId : sCIndices) { - const auto& hits_and_fractions = simClusters[scId].hits_and_fractions(); - for (const auto& it_haf : hits_and_fractions) { - const auto hitid = it_haf.first; - const auto itcheck = hitMap_->find(hitid); - if (itcheck != hitMap_->end()) { - const auto hit_find_it = detIdToSimClusterId_Map.find(hitid); - if (hit_find_it == detIdToSimClusterId_Map.end()) { - detIdToSimClusterId_Map[hitid] = std::vector(); - } - detIdToSimClusterId_Map[hitid].emplace_back(scId, it_haf.second); - - const HGCRecHit* hit = hits_[itcheck->second]; - tssInSimCluster[scId].energy += it_haf.second * hit->energy(); - tssInSimCluster[scId].hits_and_fractions.emplace_back(hitid, it_haf.second); - } - } - } // end of loop over SimClusters - -#ifdef EDM_ML_DEBUG - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "tssInSimCluster INFO (Only SimCluster filled at the moment)" << std::endl; - for (size_t sc = 0; sc < tssInSimCluster.size(); ++sc) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "For SimCluster Idx: " << sc << " we have: " << std::endl; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "\tSimClusterIdx:\t" << tssInSimCluster[sc].simClusterId << std::endl; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tEnergy:\t" << tssInSimCluster[sc].energy << std::endl; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\t# of clusters:\t" << layerClusters.size() << std::endl; - double tot_energy = 0.; - for (auto const& haf : tssInSimCluster[sc].hits_and_fractions) { - const HGCRecHit* hit = hits_[hitMap_->at(haf.first)]; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tHits/fraction/energy: " << (uint32_t)haf.first << "/" - << haf.second << "/" << haf.second * hit->energy() << std::endl; - tot_energy += haf.second * hit->energy(); - } - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tTot Sum haf: " << tot_energy << std::endl; - for (auto const& ts : tssInSimCluster[sc].tracksterIdToEnergyAndScore) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "\ttsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl; - } - } - - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "detIdToSimClusterId_Map INFO" << std::endl; - for (auto const& detId : detIdToSimClusterId_Map) { - const HGCRecHit* hit = hits_[hitMap_->at(detId.first)]; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "For detId: " << (uint32_t)detId.first - << " we have found the following connections with SimClusters:" << std::endl; - for (auto const& sc : detId.second) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "\tSimCluster Id: " << sc.clusterId << " with fraction: " << sc.fraction - << " and energy: " << sc.fraction * hit->energy() << std::endl; - } - } -#endif - - // Fill detIdToLayerClusterId_Map and scsInTrackster; update tssInSimCluster - std::unordered_map> detIdToLayerClusterId_Map; - // this contains the ids of the simclusters contributing with at least one - // hit to the Trackster. To be returned since this contains the information - // to compute the Trackster-To-SimCluster score. - ticl::tracksterToSimCluster scsInTrackster; //[tsId][scId]->(energy,score) - scsInTrackster.resize(nTracksters); - - for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) { - for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) { - const auto lcId = tracksters[tsId].vertices(i); - const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i); - - const std::vector>& hits_and_fractions = layerClusters[lcId].hitsAndFractions(); - unsigned int numberOfHitsInLC = hits_and_fractions.size(); - - for (unsigned int hitId = 0; hitId < numberOfHitsInLC; hitId++) { - const auto rh_detid = hits_and_fractions[hitId].first; - const auto rhFraction = hits_and_fractions[hitId].second; - - const auto hit_find_in_LC = detIdToLayerClusterId_Map.find(rh_detid); - if (hit_find_in_LC == detIdToLayerClusterId_Map.end()) { - detIdToLayerClusterId_Map[rh_detid] = std::vector(); - } - detIdToLayerClusterId_Map[rh_detid].emplace_back(lcId, rhFraction); - - const auto hit_find_in_SC = detIdToSimClusterId_Map.find(rh_detid); - - if (hit_find_in_SC != detIdToSimClusterId_Map.end()) { - const auto itcheck = hitMap_->find(rh_detid); - const HGCRecHit* hit = hits_[itcheck->second]; - //Loops through all the simclusters that have the layer cluster rechit under study - //Here is time to update the tssInSimCluster and connect the SimCluster with all - //the Tracksters that have the current rechit detid matched. - for (const auto& h : hit_find_in_SC->second) { - //tssInSimCluster[simclusterId][layerclusterId]-> (energy,score) - //SC_i - > TS_j, TS_k, ... - tssInSimCluster[h.clusterId].tracksterIdToEnergyAndScore[tsId].first += - lcFractionInTs * h.fraction * hit->energy(); - //TS_i -> SC_j, SC_k, ... - scsInTrackster[tsId].emplace_back(h.clusterId, 0.f); - } - } - } // End loop over hits on a LayerCluster - } // End loop over LayerClusters in Trackster - } // End of loop over Tracksters - -#ifdef EDM_ML_DEBUG - for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) { - for (const auto& lcId : tracksters[tsId].vertices()) { - const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions(); - unsigned int numberOfHitsInLC = hits_and_fractions.size(); - - // This vector will store, for each hit in the Layercluster, the index of - // the SimCluster that contributed the most, in terms of energy, to it. - // Special values are: - // - // -2 --> the reconstruction fraction of the RecHit is 0 (used in the past to monitor Halo Hits) - // -3 --> same as before with the added condition that no SimCluster has been linked to this RecHit - // -1 --> the reco fraction is >0, but no SimCluster has been linked to it - // >=0 --> index of the linked SimCluster - std::vector hitsToSimClusterId(numberOfHitsInLC); - // This will store the index of the SimCluster linked to the LayerCluster that has the largest number of hits in common. - int maxSCId_byNumberOfHits = -1; - // This will store the maximum number of shared hits between a LayerCluster and a SimCluster - unsigned int maxSCNumberOfHitsInLC = 0; - // This will store the index of the SimCluster linked to the LayerCluster that has the largest energy in common. - int maxSCId_byEnergy = -1; - // This will store the maximum number of shared energy between a LayerCluster and a SimCluster - float maxEnergySharedLCandSC = 0.f; - // This will store the fraction of the LayerCluster energy shared with the best(energy) SimCluster: e_shared/lc_energy - float energyFractionOfLCinSC = 0.f; - // This will store the fraction of the SimCluster energy shared with the Trackster: e_shared/sc_energy - float energyFractionOfSCinLC = 0.f; - std::unordered_map occurrencesSCinLC; - unsigned int numberOfNoiseHitsInLC = 0; - std::unordered_map SCEnergyInLC; - - for (unsigned int hitId = 0; hitId < numberOfHitsInLC; hitId++) { - const auto rh_detid = hits_and_fractions[hitId].first; - const auto rhFraction = hits_and_fractions[hitId].second; - - const auto hit_find_in_SC = detIdToSimClusterId_Map.find(rh_detid); - - // if the fraction is zero or the hit does not belong to any SimCluster, - // set the SimCluster Id for the hit to -1; this will - // contribute to the number of noise hits - - // MR Remove the case in which the fraction is 0, since this could be a - // real hit that has been marked as halo. - if (rhFraction == 0.) { - hitsToSimClusterId[hitId] = -2; - } - //Now check if there are SimClusters linked to this rechit of the layercluster - if (hit_find_in_SC == detIdToSimClusterId_Map.end()) { - hitsToSimClusterId[hitId] -= 1; - } else { - const auto itcheck = hitMap_->find(rh_detid); - const HGCRecHit* hit = hits_[itcheck->second]; - auto maxSCEnergyInLC = 0.f; - auto maxSCId = -1; - //Loop through all the linked SimClusters - for (const auto& h : hit_find_in_SC->second) { - SCEnergyInLC[h.clusterId] += h.fraction * hit->energy(); - // Keep track of which SimCluster contributed the most, in terms - // of energy, to this specific Layer Cluster. - if (SCEnergyInLC[h.clusterId] > maxSCEnergyInLC) { - maxSCEnergyInLC = SCEnergyInLC[h.clusterId]; - maxSCId = h.clusterId; - } - } - hitsToSimClusterId[hitId] = maxSCId; - } - } // End loop over hits on a LayerCluster - - for (const auto& c : hitsToSimClusterId) { - if (c < 0) { - numberOfNoiseHitsInLC++; - } else { - occurrencesSCinLC[c]++; - } - } - - for (const auto& c : occurrencesSCinLC) { - if (c.second > maxSCNumberOfHitsInLC) { - maxSCId_byNumberOfHits = c.first; - maxSCNumberOfHitsInLC = c.second; - } - } - - for (const auto& c : SCEnergyInLC) { - if (c.second > maxEnergySharedLCandSC) { - maxSCId_byEnergy = c.first; - maxEnergySharedLCandSC = c.second; - } - } - - float totalSCEnergyOnLayer = 0.f; - if (maxSCId_byEnergy >= 0) { - totalSCEnergyOnLayer = tssInSimCluster[maxSCId_byEnergy].energy; - energyFractionOfSCinLC = maxEnergySharedLCandSC / totalSCEnergyOnLayer; - if (tracksters[tsId].raw_energy() > 0.f) { - energyFractionOfLCinSC = maxEnergySharedLCandSC / tracksters[tsId].raw_energy(); - } - } - - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << std::setw(12) << "TracksterID:\t" << std::setw(12) << "layerCluster\t" << std::setw(10) << "lc energy\t" - << std::setw(5) << "nhits\t" << std::setw(12) << "noise hits\t" << std::setw(22) << "maxSCId_byNumberOfHits\t" - << std::setw(8) << "nhitsSC\t" << std::setw(13) << "maxSCId_byEnergy\t" << std::setw(20) - << "maxEnergySharedLCandSC\t" << std::setw(22) << "totalSCEnergyOnLayer\t" << std::setw(22) - << "energyFractionOfLCinSC\t" << std::setw(25) << "energyFractionOfSCinLC\t" - << "\n"; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << std::setw(12) << tsId << "\t" << std::setw(12) << lcId << "\t" << std::setw(10) - << tracksters[tsId].raw_energy() << "\t" << std::setw(5) << numberOfHitsInLC << "\t" << std::setw(12) - << numberOfNoiseHitsInLC << "\t" << std::setw(22) << maxSCId_byNumberOfHits << "\t" << std::setw(8) - << maxSCNumberOfHitsInLC << "\t" << std::setw(13) << maxSCId_byEnergy << "\t" << std::setw(20) - << maxEnergySharedLCandSC << "\t" << std::setw(22) << totalSCEnergyOnLayer << "\t" << std::setw(22) - << energyFractionOfLCinSC << "\t" << std::setw(25) << energyFractionOfSCinLC << "\n"; - } // End of loop over LayerClusters in Trackster - } // End of loop over Tracksters - - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "Improved tssInSimCluster INFO (Now containing the linked tracksters id and energy - score still empty)" - << std::endl; - for (size_t sc = 0; sc < tssInSimCluster.size(); ++sc) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "For SimCluster Idx: " << sc << " we have: " << std::endl; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << " SimClusterIdx: " << tssInSimCluster[sc].simClusterId << std::endl; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tEnergy:\t" << tssInSimCluster[sc].energy << std::endl; - double tot_energy = 0.; - for (auto const& haf : tssInSimCluster[sc].hits_and_fractions) { - const HGCRecHit* hit = hits_[hitMap_->at(haf.first)]; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tHits/fraction/energy: " << (uint32_t)haf.first << "/" - << haf.second << "/" << haf.second * hit->energy() << std::endl; - tot_energy += haf.second * hit->energy(); - } - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "\tTot Sum haf: " << tot_energy << std::endl; - for (auto const& ts : tssInSimCluster[sc].tracksterIdToEnergyAndScore) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "\ttsIdx/energy/score: " << ts.first << "/" << ts.second.first << "/" << ts.second.second << std::endl; - } - } - - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "Improved detIdToSimClusterId_Map INFO" << std::endl; - for (auto const& sc : detIdToSimClusterId_Map) { - const HGCRecHit* hit = hits_[hitMap_->at(sc.first)]; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "For detId: " << (uint32_t)sc.first - << " we have found the following connections with SimClusters:" << std::endl; - for (auto const& sclu : sc.second) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << " SimCluster Id: " << sclu.clusterId << " with fraction: " << sclu.fraction - << " and energy: " << sclu.fraction * hit->energy() << std::endl; - } - } -#endif - - // Update scsInTrackster; compute the score Trackster-to-SimCluster, - // together with the returned AssociationMap - for (unsigned int tsId = 0; tsId < nTracksters; ++tsId) { - // The SimClusters contributing to the Trackster's LayerClusters should already be unique. - // find the unique SimClusters id contributing to the Trackster's LayerClusters - std::sort(scsInTrackster[tsId].begin(), scsInTrackster[tsId].end()); - auto last = std::unique(scsInTrackster[tsId].begin(), scsInTrackster[tsId].end()); - scsInTrackster[tsId].erase(last, scsInTrackster[tsId].end()); - - // If a reconstructed Trackster has energy 0 but is linked to a - // SimCluster, assigned score 1 - if (tracksters[tsId].raw_energy() == 0. && !scsInTrackster[tsId].empty()) { - for (auto& scPair : scsInTrackster[tsId]) { - scPair.second = 1.; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "TracksterId:\t " << tsId << "\tSC id:\t" << scPair.first << "\tscore\t " << scPair.second << "\n"; - } - continue; - } - - float invTracksterEnergyWeight = 0.f; - for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) { - const auto lcId = tracksters[tsId].vertices(i); - const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i); - - const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions(); - // Compute the correct normalization - for (auto const& haf : hits_and_fractions) { - const HGCRecHit* hit = hits_[hitMap_->at(haf.first)]; - invTracksterEnergyWeight += - (lcFractionInTs * haf.second * hit->energy()) * (lcFractionInTs * haf.second * hit->energy()); - } - } - invTracksterEnergyWeight = 1.f / invTracksterEnergyWeight; - - for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) { - const auto lcId = tracksters[tsId].vertices(i); - const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i); - - const auto& hits_and_fractions = layerClusters[lcId].hitsAndFractions(); - unsigned int numberOfHitsInLC = hits_and_fractions.size(); - for (unsigned int i = 0; i < numberOfHitsInLC; ++i) { - DetId rh_detid = hits_and_fractions[i].first; - float rhFraction = hits_and_fractions[i].second * lcFractionInTs; - - const bool hitWithSC = (detIdToSimClusterId_Map.find(rh_detid) != detIdToSimClusterId_Map.end()); - - const auto itcheck = hitMap_->find(rh_detid); - const HGCRecHit* hit = hits_[itcheck->second]; - float hitEnergyWeight = hit->energy() * hit->energy(); - - for (auto& scPair : scsInTrackster[tsId]) { - float scFraction = 0.f; - if (hitWithSC) { - const auto findHitIt = std::find(detIdToSimClusterId_Map[rh_detid].begin(), - detIdToSimClusterId_Map[rh_detid].end(), - ticl::detIdInfoInCluster{scPair.first, 0.f}); - if (findHitIt != detIdToSimClusterId_Map[rh_detid].end()) - scFraction = findHitIt->fraction; - } - scPair.second += - (rhFraction - scFraction) * (rhFraction - scFraction) * hitEnergyWeight * invTracksterEnergyWeight; -#ifdef EDM_ML_DEBUG - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "rh_detid:\t" << (uint32_t)rh_detid << "\ttracksterId:\t" << tsId << "\t" - << "rhfraction,scFraction:\t" << rhFraction << ", " << scFraction << "\t" - << "hitEnergyWeight:\t" << hitEnergyWeight << "\t" - << "current score:\t" << scPair.second << "\t" - << "invTracksterEnergyWeight:\t" << invTracksterEnergyWeight << "\n"; -#endif - } - } // End of loop over Hits within a LayerCluster - } // End of loop over LayerClusters in Trackster - -#ifdef EDM_ML_DEBUG - if (scsInTrackster[tsId].empty()) - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "trackster Id:\t" << tsId << "\tSC id:\t-1" - << "\tscore\t-1\n"; -#endif - } // End of loop over Tracksters - - // Compute the SimCluster-To-Trackster score - for (const auto& scId : sCIndices) { - float invSCEnergyWeight = 0.f; - - const unsigned int SCNumberOfHits = tssInSimCluster[scId].hits_and_fractions.size(); - if (SCNumberOfHits == 0) - continue; -#ifdef EDM_ML_DEBUG - int tsWithMaxEnergyInSC = -1; - //energy of the most energetic TS from all that were linked to SC - float maxEnergyTSinSC = 0.f; - float SCenergy = tssInSimCluster[scId].energy; - //most energetic TS from all TSs linked to SC over SC energy. - float SCEnergyFractionInTS = 0.f; - for (const auto& ts : tssInSimCluster[scId].tracksterIdToEnergyAndScore) { - if (ts.second.first > maxEnergyTSinSC) { - maxEnergyTSinSC = ts.second.first; - tsWithMaxEnergyInSC = ts.first; - } - } - if (SCenergy > 0.f) - SCEnergyFractionInTS = maxEnergyTSinSC / SCenergy; - - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << std::setw(12) << "simcluster\t" << std::setw(15) << "sc total energy\t" << std::setw(15) - << "scEnergyOnLayer\t" << std::setw(14) << "SCNhitsOnLayer\t" << std::setw(18) << "tsWithMaxEnergyInSC\t" - << std::setw(15) << "maxEnergyTSinSC\t" << std::setw(20) << "SCEnergyFractionInTS" - << "\n"; - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << std::setw(12) << scId << "\t" << std::setw(15) << simClusters[scId].energy() << "\t" << std::setw(15) - << SCenergy << "\t" << std::setw(14) << SCNumberOfHits << "\t" << std::setw(18) << tsWithMaxEnergyInSC << "\t" - << std::setw(15) << maxEnergyTSinSC << "\t" << std::setw(20) << SCEnergyFractionInTS << "\n"; -#endif - // Compute the correct normalization - for (auto const& haf : tssInSimCluster[scId].hits_and_fractions) { - const HGCRecHit* hit = hits_[hitMap_->at(haf.first)]; - invSCEnergyWeight += std::pow(haf.second * hit->energy(), 2); - } - invSCEnergyWeight = 1.f / invSCEnergyWeight; - - for (unsigned int i = 0; i < SCNumberOfHits; ++i) { - auto& sc_hitDetId = tssInSimCluster[scId].hits_and_fractions[i].first; - auto& scFraction = tssInSimCluster[scId].hits_and_fractions[i].second; - - bool hitWithLC = false; - if (scFraction == 0.f) - continue; // hopefully this should never happen - const auto hit_find_in_LC = detIdToLayerClusterId_Map.find(sc_hitDetId); - if (hit_find_in_LC != detIdToLayerClusterId_Map.end()) - hitWithLC = true; - const auto itcheck = hitMap_->find(sc_hitDetId); - const HGCRecHit* hit = hits_[itcheck->second]; - float hitEnergyWeight = hit->energy() * hit->energy(); - for (auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) { - unsigned int tsId = tsPair.first; - float tsFraction = 0.f; - - for (unsigned int i = 0; i < tracksters[tsId].vertices().size(); ++i) { - const auto lcId = tracksters[tsId].vertices(i); - const auto lcFractionInTs = 1.f / tracksters[tsId].vertex_multiplicity(i); - - if (hitWithLC) { - const auto findHitIt = std::find(detIdToLayerClusterId_Map[sc_hitDetId].begin(), - detIdToLayerClusterId_Map[sc_hitDetId].end(), - ticl::detIdInfoInCluster{lcId, 0.f}); - if (findHitIt != detIdToLayerClusterId_Map[sc_hitDetId].end()) - tsFraction = findHitIt->fraction * lcFractionInTs; - } - tsPair.second.second += - (tsFraction - scFraction) * (tsFraction - scFraction) * hitEnergyWeight * invSCEnergyWeight; -#ifdef EDM_ML_DEBUG - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "SCDetId:\t" << (uint32_t)sc_hitDetId << "\tTracksterId:\t" << tsId << "\t" - << "tsFraction, scFraction:\t" << tsFraction << ", " << scFraction << "\t" - << "hitEnergyWeight:\t" << hitEnergyWeight << "\t" - << "current score:\t" << tsPair.second.second << "\t" - << "invSCEnergyWeight:\t" << invSCEnergyWeight << "\n"; -#endif - } // End of loop over Trackster's LayerClusters - } // End of loop over Tracksters linked to hits of this SimCluster - } // End of loop over hits of SimCluster on a Layer -#ifdef EDM_ML_DEBUG - if (tssInSimCluster[scId].tracksterIdToEnergyAndScore.empty()) - LogDebug("TSToSCAssociatorByEnergyScoreImpl") << "SC Id:\t" << scId << "\tTS id:\t-1 " - << "\tscore\t-1\n"; - - for (const auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "SC Id: \t" << scId << "\t TS id: \t" << tsPair.first << "\t score \t" << tsPair.second.second - << "\t shared energy:\t" << tsPair.second.first << "\t shared energy fraction:\t" - << (tsPair.second.first / SCenergy) << "\n"; - } -#endif - } // End loop over SimCluster indices - return {scsInTrackster, tssInSimCluster}; -} - -ticl::RecoToSimCollectionTracksters TSToSCAssociatorByEnergyScoreImpl::associateRecoToSim( - const edm::Handle& tCH, - const edm::Handle& lCCH, - const edm::Handle& sCCH) const { - ticl::RecoToSimCollectionTracksters returnValue(productGetter_); - const auto& links = makeConnections(tCH, lCCH, sCCH); - - const auto& scsInTrackster = std::get<0>(links); - for (size_t tsId = 0; tsId < scsInTrackster.size(); ++tsId) { - for (auto& scPair : scsInTrackster[tsId]) { - LogDebug("TSToSCAssociatorByEnergyScoreImpl") - << "Trackster Id:\t" << tsId << "\tSimCluster id:\t" << scPair.first << "\tscore:\t" << scPair.second << "\n"; - // Fill AssociationMap - returnValue.insert(edm::Ref(tCH, tsId), // Ref to TS - std::make_pair(edm::Ref(sCCH, scPair.first), - scPair.second) // Pair - ); - } - } - return returnValue; -} - -ticl::SimToRecoCollectionTracksters TSToSCAssociatorByEnergyScoreImpl::associateSimToReco( - const edm::Handle& tCH, - const edm::Handle& lCCH, - const edm::Handle& sCCH) const { - ticl::SimToRecoCollectionTracksters returnValue(productGetter_); - const auto& links = makeConnections(tCH, lCCH, sCCH); - const auto& tssInSimCluster = std::get<1>(links); - for (size_t scId = 0; scId < tssInSimCluster.size(); ++scId) { - for (auto& tsPair : tssInSimCluster[scId].tracksterIdToEnergyAndScore) { - returnValue.insert( - edm::Ref(sCCH, scId), // Ref to SC - std::make_pair(edm::Ref(tCH, tsPair.first), // Pair > - ); - } - } - return returnValue; -} diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.h b/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.h deleted file mode 100644 index da026254e6a37..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreImpl.h +++ /dev/null @@ -1,67 +0,0 @@ -// Original Author: Leonardo Cristella - -#include -#include -#include -#include // shared_ptr - -#include "DataFormats/ForwardDetId/interface/HGCalDetId.h" -#include "DataFormats/HGCRecHit/interface/HGCRecHit.h" -#include "SimDataFormats/Associations/interface/TracksterToSimClusterAssociator.h" -#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h" -#include "DataFormats/CaloRecHit/interface/CaloCluster.h" - -namespace edm { - class EDProductGetter; -} - -namespace ticl { - struct detIdInfoInCluster { - bool operator==(const detIdInfoInCluster &o) const { return clusterId == o.clusterId; }; - long unsigned int clusterId; - float fraction; - detIdInfoInCluster(long unsigned int cId, float fr) { - clusterId = cId; - fraction = fr; - } - }; - - struct simClusterOnBLayer { - unsigned int simClusterId; - float energy = 0; - std::vector> hits_and_fractions; - std::unordered_map> tracksterIdToEnergyAndScore; - }; - - typedef std::vector>> tracksterToSimCluster; - typedef std::vector simClusterToTrackster; - typedef std::tuple association; -} // namespace ticl - -class TSToSCAssociatorByEnergyScoreImpl : public ticl::TracksterToSimClusterAssociatorBaseImpl { -public: - explicit TSToSCAssociatorByEnergyScoreImpl(edm::EDProductGetter const &, - bool, - std::shared_ptr, - const std::unordered_map *, - std::vector &hits); - - ticl::RecoToSimCollectionTracksters associateRecoToSim(const edm::Handle &tCH, - const edm::Handle &lCCH, - const edm::Handle &sCCH) const override; - - ticl::SimToRecoCollectionTracksters associateSimToReco(const edm::Handle &tCH, - const edm::Handle &lCCH, - const edm::Handle &sCCH) const override; - -private: - const bool hardScatterOnly_; - std::shared_ptr recHitTools_; - const std::unordered_map *hitMap_; - std::vector hits_; - unsigned layers_; - edm::EDProductGetter const *productGetter_; - ticl::association makeConnections(const edm::Handle &tCH, - const edm::Handle &lCCH, - const edm::Handle &sCCH) const; -}; diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreProducer.cc deleted file mode 100644 index fc4bfe3dad2a1..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorByEnergyScoreProducer.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Original author: Leonardo Cristella - -// user include files -#include - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/global/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/EDGetToken.h" -#include "FWCore/Utilities/interface/ESGetToken.h" - -#include "SimDataFormats/Associations/interface/TracksterToSimClusterAssociator.h" -#include "TSToSCAssociatorByEnergyScoreImpl.h" - -#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" - -class TSToSCAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> { -public: - explicit TSToSCAssociatorByEnergyScoreProducer(const edm::ParameterSet &); - ~TSToSCAssociatorByEnergyScoreProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; - edm::EDGetTokenT> hitMap_; - edm::ESGetToken caloGeometry_; - const bool hardScatterOnly_; - std::shared_ptr rhtools_; - std::vector hits_label_; - std::vector> hits_token_; -}; - -TSToSCAssociatorByEnergyScoreProducer::TSToSCAssociatorByEnergyScoreProducer(const edm::ParameterSet &ps) - : hitMap_(consumes>(ps.getParameter("hitMapTag"))), - caloGeometry_(esConsumes()), - hardScatterOnly_(ps.getParameter("hardScatterOnly")), - hits_label_(ps.getParameter>("hits")) { - rhtools_ = std::make_shared(); - - for (auto &label : hits_label_) { - hits_token_.push_back(consumes(label)); - } - // Register the product - produces(); -} - -TSToSCAssociatorByEnergyScoreProducer::~TSToSCAssociatorByEnergyScoreProducer() {} - -void TSToSCAssociatorByEnergyScoreProducer::produce(edm::StreamID, - edm::Event &iEvent, - const edm::EventSetup &es) const { - edm::ESHandle geom = es.getHandle(caloGeometry_); - rhtools_->setGeometry(*geom); - - std::vector hits; - for (auto &token : hits_token_) { - edm::Handle hits_handle; - iEvent.getByToken(token, hits_handle); - for (const auto &hit : *hits_handle) { - hits.push_back(&hit); - } - } - - if (hits.empty()) { - edm::LogWarning("TSToSCAssociatorByEnergyScoreProducer") << "No hits collected. Producing empty associator."; - } - - if (!iEvent.getHandle(hitMap_)) { - edm::LogWarning("TSToSCAssociatorByEnergyScoreProducer") << "Hit map not valid. Producing empty associator."; - - const std::unordered_map hitMap; // empty map - auto impl = std::make_unique( - iEvent.productGetter(), hardScatterOnly_, rhtools_, &hitMap, hits); - auto emptyAssociator = std::make_unique(std::move(impl)); - iEvent.put(std::move(emptyAssociator)); - return; - } - - const auto hitMap = &iEvent.get(hitMap_); - auto impl = std::make_unique( - iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits); - auto toPut = std::make_unique(std::move(impl)); - iEvent.put(std::move(toPut)); -} - -void TSToSCAssociatorByEnergyScoreProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) { - edm::ParameterSetDescription desc; - desc.add("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap")); - desc.add>("hits", - {edm::InputTag("HGCalRecHit", "HGCEERecHits"), - edm::InputTag("HGCalRecHit", "HGCHEFRecHits"), - edm::InputTag("HGCalRecHit", "HGCHEBRecHits")}); - desc.add("hardScatterOnly", true); - - cfg.add("tracksterAssociatorByEnergyScore", desc); -} - -//define this as a plug-in -DEFINE_FWK_MODULE(TSToSCAssociatorByEnergyScoreProducer); diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorEDProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorEDProducer.cc deleted file mode 100644 index ebc002be96ae1..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/TSToSCAssociatorEDProducer.cc +++ /dev/null @@ -1,95 +0,0 @@ -// -// Original Author: Leonardo Cristella -// Created: Thu Dec 3 10:52:11 CET 2020 -// -// - -// system include files -#include -#include - -// user include files -#include "FWCore/Framework/interface/global/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/Framework/interface/ESHandle.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "SimDataFormats/Associations/interface/TracksterToSimClusterAssociator.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "DataFormats/HGCalReco/interface/Trackster.h" - -#include "FWCore/Utilities/interface/EDGetToken.h" - -// -// class decleration -// - -class TSToSCAssociatorEDProducer : public edm::global::EDProducer<> { -public: - explicit TSToSCAssociatorEDProducer(const edm::ParameterSet &); - ~TSToSCAssociatorEDProducer() override; - -private: - void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; - - edm::EDGetTokenT SCCollectionToken_; - edm::EDGetTokenT TSCollectionToken_; - edm::EDGetTokenT LCCollectionToken_; - edm::EDGetTokenT associatorToken_; -}; - -TSToSCAssociatorEDProducer::TSToSCAssociatorEDProducer(const edm::ParameterSet &pset) { - produces(); - produces(); - - SCCollectionToken_ = consumes(pset.getParameter("label_scl")); - TSCollectionToken_ = consumes(pset.getParameter("label_tst")); - LCCollectionToken_ = consumes(pset.getParameter("label_lcl")); - associatorToken_ = consumes(pset.getParameter("associator")); -} - -TSToSCAssociatorEDProducer::~TSToSCAssociatorEDProducer() {} - -// -// member functions -// - -// ------------ method called to produce the data ------------ -void TSToSCAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const { - using namespace edm; - - edm::Handle theAssociator; - iEvent.getByToken(associatorToken_, theAssociator); - - Handle SCCollection; - iEvent.getByToken(SCCollectionToken_, SCCollection); - - Handle TSCollection; - iEvent.getByToken(TSCollectionToken_, TSCollection); - - Handle LCCollection; - iEvent.getByToken(LCCollectionToken_, LCCollection); - - // associate TS and SC - LogTrace("AssociatorValidator") << "Calling associateRecoToSim method\n"; - ticl::RecoToSimCollectionTracksters recSimColl = - theAssociator->associateRecoToSim(TSCollection, LCCollection, SCCollection); - - LogTrace("AssociatorValidator") << "Calling associateSimToReco method\n"; - ticl::SimToRecoCollectionTracksters simRecColl = - theAssociator->associateSimToReco(TSCollection, LCCollection, SCCollection); - - auto rts = std::make_unique(recSimColl); - auto str = std::make_unique(simRecColl); - - iEvent.put(std::move(rts)); - iEvent.put(std::move(str)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(TSToSCAssociatorEDProducer); diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/HitToTracksterAssociation_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/HitToTracksterAssociation_cfi.py index 86444adc7fe7f..dafa511039c24 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/python/HitToTracksterAssociation_cfi.py +++ b/SimCalorimetry/HGCalAssociatorProducers/python/HitToTracksterAssociation_cfi.py @@ -2,7 +2,7 @@ from SimCalorimetry.HGCalAssociatorProducers.hitToTracksterAssociator_cfi import hitToTracksterAssociator hitToTrackstersAssociationLinking = hitToTracksterAssociator.clone( - tracksters = cms.InputTag("ticlTrackstersMerge"), + tracksters = cms.InputTag("ticlCandidate"), ) @@ -19,16 +19,12 @@ ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 - -ticl_v5.toModify(hitToTrackstersAssociationLinking, tracksters = cms.InputTag("ticlCandidate")) - from SimCalorimetry.HGCalAssociatorProducers.AllHitToTracksterAssociatorsProducer_cfi import AllHitToTracksterAssociatorsProducer -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet allHitToTracksterAssociations = AllHitToTracksterAssociatorsProducer.clone( tracksterCollections = cms.VInputTag( - *[cms.InputTag(label) for label in ticlIterLabels], + *[cms.InputTag(label) for label in ticlIterLabelsPSet.labels], cms.InputTag("ticlSimTracksters"), cms.InputTag("ticlSimTracksters", "fromCPs"), ) diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/LCToTSAssociator_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/LCToTSAssociator_cfi.py index b3c2e24d7dab1..14125ee44587e 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/python/LCToTSAssociator_cfi.py +++ b/SimCalorimetry/HGCalAssociatorProducers/python/LCToTSAssociator_cfi.py @@ -12,7 +12,7 @@ ) layerClusterToTracksterMergeAssociation = LCToTSAssociatorProducer.clone( - tracksters = cms.InputTag("ticlTrackstersMerge") + tracksters = cms.InputTag("ticlCandidate") ) layerClusterToSimTracksterAssociation = LCToTSAssociatorProducer.clone( @@ -23,15 +23,12 @@ tracksters = cms.InputTag("ticlSimTracksters", "fromCPs") ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify(layerClusterToTracksterMergeAssociation, tracksters = cms.InputTag("ticlCandidate")) - from SimCalorimetry.HGCalAssociatorProducers.AllLayerClusterToTracksterAssociatorsProducer_cfi import AllLayerClusterToTracksterAssociatorsProducer -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet allLayerClusterToTracksterAssociations = AllLayerClusterToTracksterAssociatorsProducer.clone( tracksterCollections = cms.VInputTag( - *[cms.InputTag(label) for label in ticlIterLabels], + *[cms.InputTag(label) for label in ticlIterLabelsPSet.labels], cms.InputTag("ticlSimTracksters"), cms.InputTag("ticlSimTracksters", "fromCPs"), ) diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/MCToCPAssociation_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/MCToCPAssociation_cfi.py deleted file mode 100644 index 7e82345bfa585..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/python/MCToCPAssociation_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -multiClusterCaloParticleAssociation = cms.EDProducer("MCToCPAssociatorEDProducer", - associator = cms.InputTag('mcAssocByEnergyScoreProducer'), - label_cp = cms.InputTag("mix","MergedCaloTruth"), - label_mcl = cms.InputTag("ticlMultiClustersFromTrackstersMerge") -) - -from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 -premix_stage2.toModify(multiClusterCaloParticleAssociation, - label_cp = "mixData:MergedCaloTruth" -) diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSCAssociation_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/TSToSCAssociation_cfi.py deleted file mode 100644 index b0f24d1a23262..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSCAssociation_cfi.py +++ /dev/null @@ -1,13 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -tracksterSimClusterAssociation = cms.EDProducer("TSToSCAssociatorEDProducer", - associator = cms.InputTag('tsAssocByEnergyScoreProducer'), - label_scl = cms.InputTag("mix","MergedCaloTruth"), - label_tst = cms.InputTag("ticlTrackstersMerge"), - label_lcl = cms.InputTag("hgcalMergeLayerClusters") -) - -from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 -premix_stage2.toModify(tracksterSimClusterAssociation, - label_scl = "mixData:MergedCaloTruth" -) diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociationByHits_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociationByHits_cfi.py index 43a05ba1b9743..ec2ce31776421 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociationByHits_cfi.py +++ b/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociationByHits_cfi.py @@ -1,11 +1,11 @@ import FWCore.ParameterSet.Config as cms from SimCalorimetry.HGCalAssociatorProducers.HitToTracksterAssociation_cfi import * from SimCalorimetry.HGCalAssociatorProducers.AllTracksterToSimTracksterAssociatorsByHitsProducer_cfi import AllTracksterToSimTracksterAssociatorsByHitsProducer -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet allTrackstersToSimTrackstersAssociationsByHits = AllTracksterToSimTracksterAssociatorsByHitsProducer.clone( tracksterCollections = cms.VInputTag( - *[cms.InputTag(label) for label in ticlIterLabels] + *[cms.InputTag(label) for label in ticlIterLabelsPSet.labels] ), simTracksterCollections = cms.VInputTag( 'ticlSimTracksters', diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociation_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociation_cfi.py index 374a01fb24efe..45354939c5659 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociation_cfi.py +++ b/SimCalorimetry/HGCalAssociatorProducers/python/TSToSimTSAssociation_cfi.py @@ -1,16 +1,15 @@ import FWCore.ParameterSet.Config as cms from SimCalorimetry.HGCalAssociatorProducers.LCToTSAssociator_cfi import layerClusterToCLUE3DTracksterAssociation, layerClusterToTracksterMergeAssociation, layerClusterToSimTracksterAssociation, layerClusterToSimTracksterFromCPsAssociation -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 from Configuration.ProcessModifiers.ticl_superclustering_mustache_ticl_cff import ticl_superclustering_mustache_ticl from SimCalorimetry.HGCalAssociatorProducers.AllTracksterToSimTracksterAssociatorsByLCsProducer_cfi import AllTracksterToSimTracksterAssociatorsByLCsProducer -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, associatorsInstances +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet, associatorsInstances allTrackstersToSimTrackstersAssociationsByLCs = AllTracksterToSimTracksterAssociatorsByLCsProducer.clone( tracksterCollections = cms.VInputTag( - *[cms.InputTag(label) for label in ticlIterLabels] + *[cms.InputTag(label) for label in ticlIterLabelsPSet.labels] ), simTracksterCollections = cms.VInputTag( cms.InputTag('ticlSimTracksters'), diff --git a/SimCalorimetry/HGCalSimProducers/python/hgcHitAssociation_cfi.py b/SimCalorimetry/HGCalSimProducers/python/hgcHitAssociation_cfi.py index 21037728b61b4..62e176b5bb6cd 100644 --- a/SimCalorimetry/HGCalSimProducers/python/hgcHitAssociation_cfi.py +++ b/SimCalorimetry/HGCalSimProducers/python/hgcHitAssociation_cfi.py @@ -5,7 +5,7 @@ lcAssocByEnergyScoreProducer = _lcAssocByEnergyScoreProducer.clone(hardScatterOnly = cms.bool(True)) scAssocByEnergyScoreProducer = _scAssocByEnergyScoreProducer.clone(hardScatterOnly = cms.bool(True)) -from Configuration.ProcessModifiers.enableCPfromPU_cff import enableCPfromPU +from Configuration.ProcessModifiers.simTrackstersFromPU_cff import simTrackstersFromPU -enableCPfromPU.toModify(lcAssocByEnergyScoreProducer, hardScatterOnly = cms.bool(False)) -enableCPfromPU.toModify(scAssocByEnergyScoreProducer, hardScatterOnly = cms.bool(False)) +simTrackstersFromPU.toModify(lcAssocByEnergyScoreProducer, hardScatterOnly = cms.bool(False)) +simTrackstersFromPU.toModify(scAssocByEnergyScoreProducer, hardScatterOnly = cms.bool(False)) diff --git a/Validation/Configuration/python/hgcalSimValid_cff.py b/Validation/Configuration/python/hgcalSimValid_cff.py index cb26e292f3857..c837cd97726a0 100644 --- a/Validation/Configuration/python/hgcalSimValid_cff.py +++ b/Validation/Configuration/python/hgcalSimValid_cff.py @@ -53,7 +53,6 @@ SimClusterToCaloParticleAssociation, ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 from Configuration.ProcessModifiers.ticl_superclustering_mustache_pf_cff import ticl_superclustering_mustache_pf diff --git a/Validation/Configuration/python/hltHGCalSimValid_cff.py b/Validation/Configuration/python/hltHGCalSimValid_cff.py index 634c929d1337e..3ea8a210cc54d 100644 --- a/Validation/Configuration/python/hltHGCalSimValid_cff.py +++ b/Validation/Configuration/python/hltHGCalSimValid_cff.py @@ -9,7 +9,7 @@ from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import allTrackstersToSimTrackstersAssociationsByLCs as _allTrackstersToSimTrackstersAssociationsByLCs from SimCalorimetry.HGCalAssociatorProducers.hitToSimClusterCaloParticleAssociator_cfi import hitToSimClusterCaloParticleAssociator as _hitToSimClusterCaloParticleAssociator -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels as _hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet as _hltTiclIterLabelsPSet from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cff import recHitMapProducer as _recHitMapProducer @@ -33,15 +33,24 @@ from SimCalorimetry.HGCalAssociatorProducers.AllLayerClusterToTracksterAssociatorsProducer_cfi import AllLayerClusterToTracksterAssociatorsProducer as _AllLayerClusterToTracksterAssociatorsProducer hltAllLayerClusterToTracksterAssociations = _AllLayerClusterToTracksterAssociatorsProducer.clone( - layer_clusters = 'hltMergeLayerClusters', - tracksterCollections = [*[cms.InputTag(label) for label in _hltTiclIterLabels], 'hltTiclSimTracksters', 'hltTiclSimTracksters:fromCPs'] + layer_clusters = cms.InputTag("hltMergeLayerClusters"), + tracksterCollections = cms.VInputTag( + *[cms.InputTag(label) for label in _hltTiclIterLabelsPSet.labels], + cms.InputTag("hltTiclSimTracksters"), + cms.InputTag("hltTiclSimTracksters", "fromCPs"), + ) ) hltAllTrackstersToSimTrackstersAssociationsByLCs = _allTrackstersToSimTrackstersAssociationsByLCs.clone( - allLCtoTSAccoc = 'hltAllLayerClusterToTracksterAssociations', - layerClusters = 'hltMergeLayerClusters', - tracksterCollections = [*[cms.InputTag(label) for label in _hltTiclIterLabels]], - simTracksterCollections = ['hltTiclSimTracksters', 'hltTiclSimTracksters:fromCPs'] + allLCtoTSAccoc = cms.string("hltAllLayerClusterToTracksterAssociations"), + layerClusters = cms.InputTag("hltMergeLayerClusters"), + tracksterCollections = cms.VInputTag( + *[cms.InputTag(label) for label in _hltTiclIterLabelsPSet.labels] + ), + simTracksterCollections = cms.VInputTag( + cms.InputTag('hltTiclSimTracksters'), + cms.InputTag('hltTiclSimTracksters','fromCPs') + ), ) from SimCalorimetry.HGCalAssociatorProducers.AllTracksterToSimTracksterAssociatorsByHitsProducer_cfi import AllTracksterToSimTracksterAssociatorsByHitsProducer as _AllTracksterToSimTracksterAssociatorsByHitsProducer @@ -54,25 +63,31 @@ from SimCalorimetry.HGCalAssociatorProducers.AllHitToTracksterAssociatorsProducer_cfi import AllHitToTracksterAssociatorsProducer as _AllHitToTracksterAssociatorsProducer hltAllHitToTracksterAssociations = _AllHitToTracksterAssociatorsProducer.clone( - hitMapTag = 'hltHGCalRecHitMapProducer:hgcalRecHitMap', - hits = 'hltHGCalRecHitMapProducer:RefProdVectorHGCRecHitCollection', - layerClusters = 'hltMergeLayerClusters', - tracksterCollections = [*[cms.InputTag(label) for label in _hltTiclIterLabels], 'hltTiclSimTracksters', 'hltTiclSimTracksters:fromCPs'] + hitMapTag = cms.InputTag("hltHGCalRecHitMapProducer","hgcalRecHitMap"), + hits = cms.InputTag("hltHGCalRecHitMapProducer", "RefProdVectorHGCRecHitCollection"), + layerClusters = cms.InputTag("hltMergeLayerClusters"), + tracksterCollections = cms.VInputTag( + *[cms.InputTag(label) for label in _hltTiclIterLabelsPSet.labels], + cms.InputTag("hltTiclSimTracksters"), + cms.InputTag("hltTiclSimTracksters", "fromCPs"), + ) ) hltAllTrackstersToSimTrackstersAssociationsByHits = _AllTracksterToSimTracksterAssociatorsByHitsProducer.clone( - allHitToTSAccoc = 'hltAllHitToTracksterAssociations', - hitToCaloParticleMap = 'hltHitToSimClusterCaloParticleAssociator:hitToCaloParticleMap', - hitToSimClusterMap = 'hltHitToSimClusterCaloParticleAssociator:hitToSimClusterMap', - hits = 'hltHGCalRecHitMapProducer:RefProdVectorHGCRecHitCollection', - tracksterCollections = [*[cms.InputTag(label) for label in _hltTiclIterLabels]], - simTracksterCollections = ['hltTiclSimTracksters', 'hltTiclSimTracksters:fromCPs'] + allHitToTSAccoc = cms.string("hltAllHitToTracksterAssociations"), + hitToCaloParticleMap = cms.InputTag("hltHitToSimClusterCaloParticleAssociator","hitToCaloParticleMap"), + hitToSimClusterMap = cms.InputTag("hltHitToSimClusterCaloParticleAssociator","hitToSimClusterMap"), + hits = cms.InputTag("hltHGCalRecHitMapProducer", "RefProdVectorHGCRecHitCollection"), + tracksterCollections = cms.VInputTag( + *[cms.InputTag(label) for label in _hltTiclIterLabelsPSet.labels] + ), + simTracksterCollections = cms.VInputTag( + 'hltTiclSimTracksters', + 'hltTiclSimTracksters:fromCPs' + ), ) - -from SimCalorimetry.HGCalAssociatorProducers.hltLCToCPAssociation_cfi import (hltHGCalLCToCPAssociatorByEnergyScoreProducer, - hltHGCalLayerClusterCaloParticleAssociation) -from SimCalorimetry.HGCalAssociatorProducers.hltLCToSCAssociation_cfi import (hltHGCalLCToSCAssociatorByEnergyScoreProducer, - hltHGCalLayerClusterSimClusterAssociation) +from SimCalorimetry.HGCalAssociatorProducers.hltLCToCPAssociation_cfi import hltHGCalLCToCPAssociatorByEnergyScoreProducer, hltHGCalLayerClusterCaloParticleAssociation +from SimCalorimetry.HGCalAssociatorProducers.hltLCToSCAssociation_cfi import hltHGCalLCToSCAssociatorByEnergyScoreProducer, hltHGCalLayerClusterSimClusterAssociation hltHgcalAssociatorsTask = cms.Task(hltHGCalRecHitMapProducer, hltHGCalLCToCPAssociatorByEnergyScoreProducer, diff --git a/Validation/HGCalValidation/interface/HGCalValidator.h b/Validation/HGCalValidation/interface/HGCalValidator.h index 320f55ee5f28d..2f072477bc744 100644 --- a/Validation/HGCalValidation/interface/HGCalValidator.h +++ b/Validation/HGCalValidation/interface/HGCalValidator.h @@ -96,7 +96,6 @@ class HGCalValidator : public DQMGlobalEDAnalyzer { const bool doCandidatesPlots_; std::string label_candidates_; const edm::FileInPath cummatbudinxo_; - const bool isTICLv5_; std::vector> labelToken; edm::EDGetTokenT> simClusters_; diff --git a/Validation/HGCalValidation/interface/TICLCandidateValidator.h b/Validation/HGCalValidation/interface/TICLCandidateValidator.h index ee3a4c7f0cb15..339b2c3b4febf 100644 --- a/Validation/HGCalValidation/interface/TICLCandidateValidator.h +++ b/Validation/HGCalValidation/interface/TICLCandidateValidator.h @@ -145,8 +145,7 @@ class TICLCandidateValidator { edm::EDGetTokenT> recoTracksToken, edm::EDGetTokenT> trackstersToken, edm::EDGetTokenT associatorMapRtSToken, - edm::EDGetTokenT associatorMapStRToken, - bool isTICLv5); + edm::EDGetTokenT associatorMapStRToken); ~TICLCandidateValidator(); using Histograms = TICLCandidateValidatorHistograms; @@ -165,7 +164,6 @@ class TICLCandidateValidator { edm::EDGetTokenT> trackstersToken_; edm::EDGetTokenT associatorMapRtSToken_; edm::EDGetTokenT associatorMapStRToken_; - bool isTICLv5_ = false; }; #endif diff --git a/Validation/HGCalValidation/plugins/BarrelValidator.cc b/Validation/HGCalValidation/plugins/BarrelValidator.cc index f330cf50abab8..b001efd9c65ff 100644 --- a/Validation/HGCalValidation/plugins/BarrelValidator.cc +++ b/Validation/HGCalValidation/plugins/BarrelValidator.cc @@ -305,7 +305,7 @@ void BarrelValidator::dqmAnalyze(const edm::Event& event, const auto& hits = event.get(hitsToken_); for (std::size_t index = 0; const auto& pfRecHitCollection : hits) { if (pfRecHitCollection->empty()) { - edm::LogWarning("BarrelValidator") << "PFRecHitCollections #" << index << " is not valid."; + LogDebug("BarrelValidator") << "PFRecHitCollections #" << index << " is empty."; } index++; } @@ -567,7 +567,7 @@ void BarrelValidator::fillDescriptions(edm::ConfigurationDescriptions& descripti desc.add>("label_tst", { edm::InputTag("ticlTrackstersCLUE3DHigh"), - edm::InputTag("ticlTrackstersMerge"), + edm::InputTag("ticlCandidate"), edm::InputTag("ticlSimTracksters", "fromCPs"), edm::InputTag("ticlSimTracksters"), }); diff --git a/Validation/HGCalValidation/plugins/HGCalValidator.cc b/Validation/HGCalValidation/plugins/HGCalValidator.cc index 89c8dc3a7a7a5..bef9ab9ead147 100644 --- a/Validation/HGCalValidation/plugins/HGCalValidator.cc +++ b/Validation/HGCalValidation/plugins/HGCalValidator.cc @@ -96,7 +96,6 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset) doCandidatesPlots_(pset.getUntrackedParameter("doCandidatesPlots")), label_candidates_(pset.getParameter("ticlCandidates")), cummatbudinxo_(pset.getParameter("cummatbudinxo")), - isTICLv5_(pset.getUntrackedParameter("isticlv5")), hitsToken_(consumes>(pset.getParameter("hits"))), scToCpMapToken_( consumes(pset.getParameter("simClustersToCaloParticlesMap"))), @@ -151,8 +150,7 @@ HGCalValidator::HGCalValidator(const edm::ParameterSet& pset) recoTracksToken, trackstersToken, associatorMapRtSToken, - associatorMapStRToken, - isTICLv5_); + associatorMapStRToken); } for (auto& itag : label_tst) { @@ -382,7 +380,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, edm::Handle simTracksterHandle; event.getByToken(simTracksters_, simTracksterHandle); if (!simTracksterHandle.isValid()) { - edm::LogWarning("HGCalValidator") << "Missing SimTrackster collection"; + LogDebug("HGCalValidator") << "SimTrackster collection is invalid."; return; } ticl::TracksterCollection const& simTracksters = *simTracksterHandle; @@ -390,7 +388,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, edm::Handle simTracksterFromCPHandle; event.getByToken(simTracksters_fromCPs_, simTracksterFromCPHandle); if (!simTracksterFromCPHandle.isValid()) { - edm::LogWarning("HGCalValidator") << "Missing SimTrackster collection from CP"; + LogDebug("HGCalValidator") << "SimTrackster collection from CP is invalid."; return; } ticl::TracksterCollection const& simTrackstersFromCPs = *simTracksterFromCPHandle; @@ -415,7 +413,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, const std::unordered_map& hitMap = *hitMapHandle; if (!event.getHandle(hitsToken_).isValid()) { - edm::LogWarning("HGCalValidator") << "edm::RefProdVector token is not valid."; + LogDebug("HGCalValidator") << "edm::RefProdVector token is not valid."; return; } @@ -423,14 +421,14 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, const auto& hits = event.get(hitsToken_); for (std::size_t index = 0; const auto& hgcRecHitCollection : hits) { if (hgcRecHitCollection->empty()) { - edm::LogWarning("HGCalValidator") << "HGCRecHitCollection #" << index << "is not valid."; + LogDebug("HGCalValidator") << "HGCRecHitCollection #" << index << " is empty."; } index++; } edm::MultiSpan rechitSpan(hits); if (rechitSpan.size() == 0) { - edm::LogWarning("HGCalValidator") << "The HGCRecHitCollection MultiSpan is empty."; + LogDebug("HGCalValidator") << "The HGCRecHitCollection MultiSpan is empty."; } //Some general info on layers etc. @@ -584,7 +582,7 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event, event.getByToken(label_tstTokens[wml], tracksterHandle); if (!tracksterHandle.isValid()) { - edm::LogWarning("HGCalValidator") << "Failed to retrieve tracksters for wml index: " << wml; + LogDebug("HGCalValidator") << "Failed to retrieve tracksters: " << label_tst[wml].label(); continue; // Or handle the error as needed } @@ -861,15 +859,15 @@ void HGCalValidator::fillDescriptions(edm::ConfigurationDescriptions& descriptio }); desc.addUntracked("doCandidatesPlots", true); desc.add("ticlCandidates", "ticlCandidates"); - desc.add("ticlTrackstersMerge", edm::InputTag("ticlTrackstersMerge")); + desc.add("ticlTrackstersMerge", edm::InputTag("ticlCandidate")); desc.add("simTiclCandidates", edm::InputTag("ticlSimTracksters")); desc.add("recoTracks", edm::InputTag("generalTracks")); desc.add( "mergeRecoToSimAssociator", - edm::InputTag("allTrackstersToSimTrackstersAssociationsByLCs", "ticlTrackstersMergeToticlSimTrackstersfromCPs")); + edm::InputTag("allTrackstersToSimTrackstersAssociationsByLCs", "ticlCandidateToticlSimTrackstersfromCPs")); desc.add( "mergeSimToRecoAssociator", - edm::InputTag("allTrackstersToSimTrackstersAssociationsByLCs", "ticlSimTrackstersfromCPsToticlTrackstersMerge")); + edm::InputTag("allTrackstersToSimTrackstersAssociationsByLCs", "ticlSimTrackstersfromCPsToticlCandidate")); desc.add("cummatbudinxo", edm::FileInPath("Validation/HGCalValidation/data/D41.cumulative.xo")); desc.add("label_cp_effic", edm::InputTag("mix", "MergedCaloTruth")); desc.add("label_cp_fake", edm::InputTag("mix", "MergedCaloTruth")); @@ -895,6 +893,5 @@ void HGCalValidator::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("cutTk", "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5"); - desc.addUntracked("isticlv5", false); descriptions.add("hgcalValidator", desc); } diff --git a/Validation/HGCalValidation/python/HGCalValidator_cff.py b/Validation/HGCalValidation/python/HGCalValidator_cff.py index 2c3494421b0a4..e8f891f748a5d 100644 --- a/Validation/HGCalValidation/python/HGCalValidator_cff.py +++ b/Validation/HGCalValidation/python/HGCalValidator_cff.py @@ -2,13 +2,22 @@ from DQMServices.Core.DQM_cfg import * from Validation.HGCalValidation.hgcalValidator_cfi import hgcalValidator as _hgcalValidator -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, associatorsInstances - +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet, associatorsInstances +# Default configuration is now TICLv5 hgcalValidator = _hgcalValidator.clone( - label_tst = cms.VInputTag(*[cms.InputTag(label) for label in ticlIterLabels] + [cms.InputTag("ticlSimTracksters", "fromCPs"), cms.InputTag("ticlSimTracksters")]), + label_tst = cms.VInputTag(*[cms.InputTag(label) for label in ticlIterLabelsPSet.labels] + [cms.InputTag("ticlSimTracksters", "fromCPs"), cms.InputTag("ticlSimTracksters")]), allTracksterTracksterAssociatorsLabels = cms.VInputTag( *[cms.InputTag('allTrackstersToSimTrackstersAssociationsByLCs:'+associator) for associator in associatorsInstances] ), - allTracksterTracksterByHitsAssociatorsLabels = cms.VInputTag( *[cms.InputTag('allTrackstersToSimTrackstersAssociationsByHits:'+associator) for associator in associatorsInstances] ) + allTracksterTracksterByHitsAssociatorsLabels = cms.VInputTag( *[cms.InputTag('allTrackstersToSimTrackstersAssociationsByHits:'+associator) for associator in associatorsInstances] ), + # v5 defaults + LayerClustersInputMask = cms.VInputTag( + cms.InputTag("ticlTrackstersCLUE3DHigh"), + cms.InputTag("ticlSimTracksters", "fromCPs"), + cms.InputTag("ticlSimTracksters") + ), + ticlTrackstersMerge = cms.InputTag("ticlCandidate"), + mergeSimToRecoAssociator = cms.InputTag("allTrackstersToSimTrackstersAssociationsByLCs:ticlSimTrackstersfromCPsToticlCandidate"), + mergeRecoToSimAssociator = cms.InputTag("allTrackstersToSimTrackstersAssociationsByLCs:ticlCandidateToticlSimTrackstersfromCPs"), ) from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2 @@ -22,17 +31,4 @@ phase2_hgcalV10.toModify(hgcalValidator, totallayers_to_monitor = cms.int32(50)) from Configuration.Eras.Modifier_phase2_hgcalV16_cff import phase2_hgcalV16 -phase2_hgcalV16.toModify(hgcalValidator, totallayers_to_monitor = cms.int32(47)) - -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 - -lcInputMask_v5 = ["ticlTrackstersCLUE3DHigh"] -lcInputMask_v5.extend([cms.InputTag("ticlSimTracksters", "fromCPs"), cms.InputTag("ticlSimTracksters")]) - -ticl_v5.toModify(hgcalValidator, - LayerClustersInputMask = cms.VInputTag(lcInputMask_v5), - ticlTrackstersMerge = cms.InputTag("ticlCandidate"), - isticlv5 = cms.untracked.bool(True), - mergeSimToRecoAssociator = cms.InputTag("allTrackstersToSimTrackstersAssociationsByLCs:ticlSimTrackstersfromCPsToticlCandidate"), - mergeRecoToSimAssociator = cms.InputTag("allTrackstersToSimTrackstersAssociationsByLCs:ticlCandidateToticlSimTrackstersfromCPs"), -) +phase2_hgcalV16.toModify(hgcalValidator, totallayers_to_monitor = cms.int32(47)) \ No newline at end of file diff --git a/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py b/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py index b5dc7722cc8ff..4af7befdedd78 100644 --- a/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py +++ b/Validation/HGCalValidation/python/HLTHGCalPostProcessor_cff.py @@ -5,11 +5,11 @@ from Validation.HGCalValidation.PostProcessorHGCAL_cfi import postProcessorHGCALTracksters as _postProcessorHGCALTracksters from Validation.HGCalValidation.PostProcessorHGCAL_cfi import postProcessorHGCALCandidates as _postProcessorHGCALCandidates -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels as _hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet as _hltTiclIterLabelsPSet from Validation.HGCalValidation.HLTHGCalValidator_cff import hltHgcalValidator as _hltHgcalValidator hltPrefix = 'HLT/HGCAL/HGCalValidator/' -hltTracksterLabels = _hltTiclIterLabels.copy() +hltTracksterLabels = _hltTiclIterLabelsPSet.labels.copy() hltTracksterLabels.extend(['hltTiclSimTracksters', 'hltTiclSimTracksters_fromCPs']) hltLcToCP_linking = _hltHgcalValidator.label_LCToCPLinking.value() diff --git a/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py b/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py index 438a217b6ff9a..a6d96e460e0fe 100644 --- a/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py +++ b/Validation/HGCalValidation/python/HLTHGCalValidator_cff.py @@ -1,49 +1,36 @@ import FWCore.ParameterSet.Config as cms from Validation.HGCalValidation.hgcalValidator_cfi import hgcalValidator as _hgcalValidator -from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels as _hltTiclIterLabels +from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabelsPSet as _hltTiclIterLabelsPSet hltAssociatorInstances = [] - -for labelts in _hltTiclIterLabels: +for labelts in _hltTiclIterLabelsPSet.labels: for labelsts in ['hltTiclSimTracksters', 'hltTiclSimTrackstersfromCPs']: hltAssociatorInstances.append(labelts+'To'+labelsts) hltAssociatorInstances.append(labelsts+'To'+labelts) +# Default is TICLv5 hltHgcalValidator = _hgcalValidator.clone( LayerClustersInputMask = cms.VInputTag("hltTiclTrackstersCLUE3DHigh", "hltTiclSimTracksters:fromCPs", "hltTiclSimTracksters"), - label_tst = [label for label in _hltTiclIterLabels] + ['hltTiclSimTracksters:fromCPs', 'hltTiclSimTracksters'], - allTracksterTracksterAssociatorsLabels = ['hltAllTrackstersToSimTrackstersAssociationsByLCs:'+associator for associator in hltAssociatorInstances], - allTracksterTracksterByHitsAssociatorsLabels = ['hltAllTrackstersToSimTrackstersAssociationsByHits:'+associator for associator in hltAssociatorInstances], + label_tst = cms.VInputTag(*[cms.InputTag(label) for label in _hltTiclIterLabelsPSet.labels] + [cms.InputTag("hltTiclSimTracksters", "fromCPs"), cms.InputTag("hltTiclSimTracksters")]), + allTracksterTracksterAssociatorsLabels = cms.VInputTag( *[cms.InputTag('hltAllTrackstersToSimTrackstersAssociationsByLCs:'+associator) for associator in hltAssociatorInstances] ), + allTracksterTracksterByHitsAssociatorsLabels = cms.VInputTag( *[cms.InputTag('hltAllTrackstersToSimTrackstersAssociationsByHits:'+associator) for associator in hltAssociatorInstances] ), associator = cms.untracked.InputTag("hltHGCalLayerClusterCaloParticleAssociation"), associatorSim = cms.untracked.InputTag("hltHGCalLayerClusterSimClusterAssociation"), - dirName = 'HLT/HGCAL/HGCalValidator/', - hits = 'hltHGCalRecHitMapProducer:RefProdVectorHGCRecHitCollection', - hitMap = 'hltHGCalRecHitMapProducer:hgcalRecHitMap', - simTrackstersMap = 'hltTiclSimTracksters', - label_layerClustersPlots = 'hltHgcalMergeLayerClusters', - label_lcl = 'hltMergeLayerClusters', - label_simTS = 'hltTiclSimTracksters', - label_simTSFromCP = 'hltTiclSimTracksters:fromCPs', - recoTracks = 'hltGeneralTracks', - simClustersToCaloParticlesMap = 'SimClusterToCaloParticleAssociation:simClusterToCaloParticleMap', - simTiclCandidates = 'hltTiclSimTracksters', - ticlCandidates = 'hltTiclCandidate', - ticlTrackstersMerge = 'hltTiclTrackstersMerge', - mergeRecoToSimAssociator = 'hltAllTrackstersToSimTrackstersAssociationsByLCs:hltTiclTrackstersMergeTohltTiclSimTrackstersfromCPs', - mergeSimToRecoAssociator = 'hltAllTrackstersToSimTrackstersAssociationsByLCs:hltTiclSimTrackstersfromCPsTohltTiclTrackstersMerge', + dirName = cms.string('HLT/HGCAL/HGCalValidator/'), + hits = cms.InputTag("hltHGCalRecHitMapProducer", "RefProdVectorHGCRecHitCollection"), + hitMap = cms.InputTag("hltHGCalRecHitMapProducer","hgcalRecHitMap"), + simTrackstersMap = cms.InputTag("hltTiclSimTracksters"), + label_layerClustersPlots = cms.string("hltHgcalMergeLayerClusters"), + label_lcl = cms.InputTag("hltMergeLayerClusters"), + label_simTS = cms.InputTag("hltTiclSimTracksters"), + label_simTSFromCP = cms.InputTag("hltTiclSimTracksters","fromCPs"), + recoTracks = cms.InputTag("hltGeneralTracks"), + simClustersToCaloParticlesMap = cms.InputTag("SimClusterToCaloParticleAssociation","simClusterToCaloParticleMap"), + simTiclCandidates = cms.InputTag("hltTiclSimTracksters"), + ticlCandidates = cms.string('hltTiclCandidate'), + ticlTrackstersMerge = cms.InputTag("hltTiclCandidate"), + mergeRecoToSimAssociator = cms.InputTag("hltAllTrackstersToSimTrackstersAssociationsByLCs","hltTiclCandidateTohltTiclSimTrackstersfromCPs"), + mergeSimToRecoAssociator = cms.InputTag("hltAllTrackstersToSimTrackstersAssociationsByLCs","hltTiclSimTrackstersfromCPsTohltTiclCandidate"), ) -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 - -lcInputMask_v5 = ["hltTiclTrackstersCLUE3DHigh"] -lcInputMask_v5.extend([cms.InputTag("hltTiclSimTracksters", "fromCPs"), cms.InputTag("hltTiclSimTracksters")]) - -ticl_v5.toModify(hltHgcalValidator, - LayerClustersInputMask = cms.VInputTag(lcInputMask_v5), - ticlTrackstersMerge = cms.InputTag("hltTiclCandidate"), - isticlv5 = cms.untracked.bool(True), - mergeSimToRecoAssociator = cms.InputTag("hltAllTrackstersToSimTrackstersAssociationsByLCs:hltTiclSimTrackstersfromCPsTohltTiclCandidate"), - mergeRecoToSimAssociator = cms.InputTag("hltAllTrackstersToSimTrackstersAssociationsByLCs:hltTiclCandidateTohltTiclSimTrackstersfromCPs"), - ) - diff --git a/Validation/HGCalValidation/python/HLT_TICLIterLabels_cff.py b/Validation/HGCalValidation/python/HLT_TICLIterLabels_cff.py index d74417b4ff2e7..9fa579f05a45c 100644 --- a/Validation/HGCalValidation/python/HLT_TICLIterLabels_cff.py +++ b/Validation/HGCalValidation/python/HLT_TICLIterLabels_cff.py @@ -1,25 +1,21 @@ import FWCore.ParameterSet.Config as cms -hltTiclIterLabels = ["hltTiclTrackstersCLUE3DHigh", "hltTiclTrackstersCLUE3DHighL1Seeded", "hltTiclTrackstersMerge"] -from Configuration.ProcessModifiers.ticl_v5_cff import ticl_v5 -ticl_v5.toModify( - globals(), - lambda g: g.update({ - "hltTiclIterLabels": [ - "hltTiclTrackstersCLUE3DHigh", - "hltTiclTrackstersCLUE3DHighL1Seeded", - "hltTiclTracksterLinks", - #"hltTiclTracksterLinksSuperclusteringDNNUnseeded", - #"hltTiclTracksterLinksSuperclusteringDNNL1Seeded", - "hltTiclCandidate" - ] - }) +hltTiclIterLabelsPSet = cms.PSet( + labels=cms.vstring( + "hltTiclTrackstersCLUE3DHigh", + "hltTiclTrackstersCLUE3DHighL1Seeded", + "hltTiclTracksterLinks", + "hltTiclTracksterLinksSuperclusteringDNN", + "hltTiclTracksterLinksSuperclusteringDNNL1Seeded", + "hltTiclCandidate" + ) ) -## remove the L1Seeded iteration form the HLT Ticl labels + +## remove the L1Seeded iteration form the HLT Ticl labels for Scouting from Configuration.ProcessModifiers.ngtScouting_cff import ngtScouting -_ngtLabels = [label for label in hltTiclIterLabels if label != "hltTiclTrackstersCLUE3DHighL1Seeded"] +_ngtLabels = [label for label in hltTiclIterLabelsPSet.labels if label != "hltTiclTrackstersCLUE3DHighL1Seeded"] ngtScouting.toModify( globals(), lambda g: g.update({"hltTiclIterLabels": _ngtLabels}) -) +) \ No newline at end of file diff --git a/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py b/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py index dc4b7f7514905..0f9d308005cdd 100644 --- a/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py +++ b/Validation/HGCalValidation/python/PostProcessorHGCAL_cfi.py @@ -1,9 +1,9 @@ import FWCore.ParameterSet.Config as cms from DQMServices.Core.DQMEDHarvester import DQMEDHarvester -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels +from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabelsPSet from Validation.HGCalValidation.HGCalValidator_cff import hgcalValidator -tracksterLabels = ticlIterLabels.copy() +tracksterLabels = ticlIterLabelsPSet.labels.copy() tracksterLabels.extend(['ticlSimTracksters', 'ticlSimTracksters_fromCPs']) prefix = 'HGCAL/HGCalValidator/' diff --git a/Validation/HGCalValidation/python/hgcalHitValidation_cff.py b/Validation/HGCalValidation/python/hgcalHitValidation_cff.py index a7184b58da9fe..1f4c07a0c4a96 100644 --- a/Validation/HGCalValidation/python/hgcalHitValidation_cff.py +++ b/Validation/HGCalValidation/python/hgcalHitValidation_cff.py @@ -16,6 +16,5 @@ ) from Validation.HGCalValidation.hgcalHitCalibration_cfi import hgcalHitCalibration -from Validation.HGCalValidation.caloparticlevalidation_cfi import caloparticlevalidation -hgcalHitValidationSequence = cms.Sequence(hgcalHitValidation+hgcalHitCalibration+caloparticlevalidation) +hgcalHitValidationSequence = cms.Sequence(hgcalHitValidation+hgcalHitCalibration) diff --git a/Validation/HGCalValidation/python/hgcalHtml.py b/Validation/HGCalValidation/python/hgcalHtml.py index 6f7339656550e..b4c79923b934d 100644 --- a/Validation/HGCalValidation/python/hgcalHtml.py +++ b/Validation/HGCalValidation/python/hgcalHtml.py @@ -107,8 +107,37 @@ "standalone" : "Standalone study on simulated hits, digis, reconstructed hits" } + +# Extra page display names (used by the HTML report) for TICL candidates and trackster association pages. +_candidateTypePageNameMap = { + "charged_hadrons": "Charged hadrons", + "electrons": "Electrons", + "muons": "Muons", + "neutral_hadrons": "Neutral hadrons", + "neutral_pions": "Neutral pions", + "photons": "Photons", +} + +_pageNameMap.update({ + # Candidates + "General": "Candidates (all)", + **_candidateTypePageNameMap, + + # Trackster association pages (strings as used in hgcalPlots.py) + "Trackster to SimTracksters from CP Associated by Hits": "Trackster to SimTracksters from CP (by hits)", + "Trackster to SimTracksters Associated by LCs": "Trackster to SimTracksters (by LCs)", + "Trackster to SimTracksters from CP Associated by LCs": "Trackster to SimTracksters from CP (by LCs)", + "Trackster to SimTracksters Associated by Hits": "Trackster to SimTracksters (by hits)", + + # Common top-level pages in hgcalPlots.py + "Hits": "Hits", + "CaloParticles": "CaloParticles", + "SimClusters": "SimClusters", + "Calibrated RecHits": "Calibrated RecHits", +}) _sectionNameMapOrder = collections.OrderedDict([ ("layerClusters", "Layer clusters"), + ("Candidates", "Candidates"), ("tracksters","Tracksters"), ("Tracksters","Tracksters"), ("TICL-Trackster_vs_SimTracksterFromCP_byHits","Tracksters vs SimTracksters from CPs Associated by Hits"), diff --git a/Validation/HGCalValidation/python/hgcalPlots.py b/Validation/HGCalValidation/python/hgcalPlots.py index d5c6c700aa7e0..066d945b1b835 100644 --- a/Validation/HGCalValidation/python/hgcalPlots.py +++ b/Validation/HGCalValidation/python/hgcalPlots.py @@ -1729,9 +1729,9 @@ _common["scale"] = 100. #, ztitle = "% of clusters" normalizeToUnitArea=True -_multiplicity_numberOfEventsHistogram = hgcVal_dqm + "ticlTrackstersMerge/multiplicity_numberOfEventsHistogram" -_multiplicity_zminus_numberOfEventsHistogram = hgcVal_dqm + "ticlTrackstersMerge/multiplicity_zminus_numberOfEventsHistogram" -_multiplicity_zplus_numberOfEventsHistogram = hgcVal_dqm + "ticlTrackstersMerge/multiplicity_zplus_numberOfEventsHistogram" +_multiplicity_numberOfEventsHistogram = hgcVal_dqm + "ticlCandidate/multiplicity_numberOfEventsHistogram" +_multiplicity_zminus_numberOfEventsHistogram = hgcVal_dqm + "ticlCandidate/multiplicity_zminus_numberOfEventsHistogram" +_multiplicity_zplus_numberOfEventsHistogram = hgcVal_dqm + "ticlCandidate/multiplicity_zplus_numberOfEventsHistogram" _multiplicityOfLCinTST_plots = [Plot("multiplicityOfLCinTST", drawCommand = "colz text45", normalizeToNumberOfEvents = True, **_common)] @@ -2399,6 +2399,9 @@ def append_hgcalLayerClustersPlots(collection = hgcalValidator.label_layerClustersPlots.value(), name_collection = layerClustersLabel, extended = False): print('extended : ',extended) + if hasattr(collection, 'value'): + collection = collection.value() + collection = str(collection) regions_ClusterLevel = ["General: Cluster Level", "Z-minus: Cluster Level", "Z-plus: Cluster Level"] regions_CellLevel = ["Z-minus: Cell Level", "Z-plus: Cell Level"] regions_LCtoCP_association = ["Z-minus: LC_CP association", "Z-plus: LC_CP association"] @@ -2951,19 +2954,29 @@ def append_hgcalDigisPlots(collection = "HGCalDigisV", name_collection = "Digis" purpose=PlotPurpose.Timing, page=hitCalibrationLabel, section=hitCalibrationLabel )) -hgcalTICLCandPlotter = Plotter() - -hgcalTICLCandPlotter.append('ticlCandidates', [ - "DQMData/Run 1/HGCAL/Run summary/HGCalValidator/"+hgcalValidator.ticlCandidates.value(), - ], PlotFolder( - *_candidatesPlots, - loopSubFolders=False, - purpose=PlotPurpose.Timing, page="General", section="Candidates")) - -for i in range(6): - hgcalTICLCandPlotter.append('ticlCandidates', [ - "DQMData/Run 1/HGCAL/Run summary/HGCalValidator/"+hgcalValidator.ticlCandidates.value()+"/"+cand_type[i], - ], PlotFolder( +def hgcalTICLCandPlotter(labels): + """Build the TICL candidates plotter for a given HGCalValidator base folder.""" + plotter = Plotter() + + for label in labels: + plotter.append('ticlCandidates', [ + hgcVal_dqm + label, + ], PlotFolder( + *_candidatesPlots, + loopSubFolders=False, + purpose=PlotPurpose.Timing, page="General", section="Candidates")) + + for i in range(6): + plotter.append('ticlCandidates', [ + hgcVal_dqm + label + "/" + cand_type[i], + ], PlotFolder( *_allCandidatesPlots[i], loopSubFolders=False, purpose=PlotPurpose.Timing, page=cand_type[i], section="Candidates")) + + return plotter + +def set_hgcVal_dqm(dqm_base): + """Override the HGCalValidator base folder and rebuild dependent plotters.""" + global hgcVal_dqm + hgcVal_dqm = dqm_base diff --git a/Validation/HGCalValidation/scripts/harvestHGCalValidationPlots.py b/Validation/HGCalValidation/scripts/harvestHGCalValidationPlots.py deleted file mode 100755 index 9ebefb6e0a6d8..0000000000000 --- a/Validation/HGCalValidation/scripts/harvestHGCalValidationPlots.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 - -import sys,os,tempfile,shutil,subprocess,glob -import argparse - -if __name__ == "__main__": - - print("Warning: this script is deprecated and will be removed in the future. Please use the step4_HARVESTING.py step provided by cmsDriver in your workflow instead.") - # define options - parser = argparse.ArgumentParser(description="Harvest track validation plots") - parser.add_argument("files", metavar="file", type=str, nargs="+", - help="files to be harvested (convert edm DQM format to plain ROOT format") - parser.add_argument("-o", "--outputFile", type=str, default="harvest.root", - help="output file (default: 'harvest.root')") - - opts = parser.parse_args() - - # absolute path outputFile - outputFile = os.path.abspath(opts.outputFile) - - # check the input files - for f in opts.files: - if not os.path.exists(f): - parser.error("DQM file %s does not exist" % f) - - # compile a file list for cmsDriver - filelist = ",".join(["file:{0}".format(os.path.abspath(_file)) for _file in opts.files]) - - # go to a temporary directory - _cwd = os.getcwd() - _tempdir = tempfile.mkdtemp() - os.chdir(_tempdir) - - # compile cmsDriver command - cmsDriverCommand = "cmsDriver.py harvest --scenario pp --filetype DQM --conditions auto:phase2_realistic --mc -s HARVESTING:@JetMETOnlyValidation+@HGCalValidation -n -1 --filein {0}".format(filelist) - print("# running cmsDriver" + "\n" + cmsDriverCommand) - - # run it - subprocess.call(cmsDriverCommand.split(" ")) - - # find the output and move it to the specified output file path - ofiles = glob.glob("DQM*.root") - if len(ofiles) != 1: - print("ERROR: expecting exactly one output file matching DQM*.root") - print(" ls of current directory({0}):".format(_tempdir)) - os.system("ls -lt") - sys.exit() - shutil.move(ofiles[0],outputFile) - - # move back to the original directory - os.chdir(_cwd) - - # and get rid of the temporary directory - shutil.rmtree(_tempdir) diff --git a/Validation/HGCalValidation/scripts/makeHGCalValidationPlots.py b/Validation/HGCalValidation/scripts/makeHGCalValidationPlots.py index b9c23243763aa..02f29ec0d8bc6 100755 --- a/Validation/HGCalValidation/scripts/makeHGCalValidationPlots.py +++ b/Validation/HGCalValidation/scripts/makeHGCalValidationPlots.py @@ -4,11 +4,8 @@ import argparse import datetime -from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, ticlIterLabels_v5 - from Validation.RecoTrack.plotting.validation import SeparateValidation, SimpleValidation, SimpleSample from Validation.HGCalValidation.HGCalValidator_cff import hgcalValidator -import Validation.HGCalValidation.hgcalPlots as hgcalPlots import Validation.RecoTrack.plotting.plotting as plotting simClustersIters = [hgcalValidator.label_SimClustersLevel.value(), "ticlSimTracksters"] @@ -21,17 +18,42 @@ candidatesLabel = 'candidates' simLabel = 'simulation' allLabel = 'all' -ticlVersions = [4, 5] -ticlVersion = 4 +ticlVersions = [5] +ticlVersion = 5 collection_choices = [allLabel] -collection_choices.extend([hitCalLabel]+[hitValLabel]+[layerClustersLabel]+[trackstersLabel]+[trackstersWithEdgesLabel]+[candidatesLabel]+[simLabel]) +collection_choices.extend([hitCalLabel] + [hitValLabel] + [layerClustersLabel] + [trackstersLabel] + + [trackstersWithEdgesLabel] + [candidatesLabel] + [simLabel]) tracksters = [] + +def _write_top_index(output_dir, entries): + """Create a single top-level index.html linking to per-flavour reports.""" + index_path = os.path.join(output_dir, "index.html") + lines = [] + lines.append("") + lines.append("") + lines.append("") + lines.append(" ") + lines.append(" ") + lines.append(" HGCal validation plots") + lines.append(" ") + lines.append("") + lines.append("") + lines.append("

HGCal validation plots

") + lines.append("
    ") + for label, rel_index in entries: + lines.append(f"
  • {label}
  • ") + lines.append("
") + lines.append("") + lines.append("") + with open(index_path, "w", encoding="utf-8") as f: + f.write("\n".join(lines)) + + def main(opts): - - drawArgs={} + + drawArgs = {} extendedFlag = False - ticlVersion = 4 if opts.no_ratio: drawArgs["ratio"] = False if opts.separate: @@ -42,130 +64,244 @@ def main(opts): extendedFlag = True if opts.verbose: plotting.verbose = True - if opts.ticlv == 5: - ticlVersion = 5 + + collections = [c.strip() for c in opts.collection.split(",")] + for coll in collections: + if coll not in collection_choices: + raise ValueError(f"Unknown collection '{coll}'. Valid options: {collection_choices}.") + + import ROOT + + def _discover_subdirs(dqm_file, dqm_base): + """Return direct subdirectory names under dqm_base in the DQM ROOT file.""" + f = ROOT.TFile.Open(dqm_file) + if not f or f.IsZombie(): + print(f"Warning: could not open DQM file {dqm_file} to discover collections") + return set() + d = f.GetDirectory(dqm_base) + if not d: + print(f"Warning: base directory '{dqm_base}' not found in {dqm_file}") + f.Close() + return set() + names = set() + keys = d.GetListOfKeys() + if keys: + key = keys.First() + while key: + obj = key.ReadObj() + if obj and obj.InheritsFrom("TDirectory"): + names.add(key.GetName()) + key = keys.After(key) + f.Close() + return names + + output_root = opts.outputDir[0] + os.makedirs(output_root, exist_ok=True) filenames = [(f, f.replace(".root", "")) for f in opts.files] - sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames) - val = SimpleValidation([sample], opts.outputDir[0], nProc=opts.jobs) - if opts.separate: - val = SeparateValidation([sample], opts.outputDir[0]) - htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0]) - trackstersIters = [] - if (ticlVersion == 5): - trackstersIters = ticlIterLabels_v5.copy() - trackstersIters.extend(['ticlTracksterLinksSuperclusteringDNN','ticlTracksterLinksSuperclusteringMustache']) - else: - trackstersIters = ticlIterLabels.copy() - trackstersIters.extend(['ticlSimTracksters', 'ticlSimTracksters_fromCPs']) - #layerClusters - def plot_LC(): - hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter] - hgcalPlots.append_hgcalLayerClustersPlots(hgcalValidator.label_layerClustersPlots.value(), "Layer Clusters", extendedFlag) - val.doPlots(hgclayclus, plotterDrawArgs=drawArgs) - - #simClusters - def plot_SC(): - hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter] - for i_iter in simClustersIters: - hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter) - val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs) - - #tracksters - def plot_Tst(): - - hgctrackster = [hgcalPlots.hgcalTrackstersPlotter] - for tracksterCollection in trackstersIters : - print("Searching for tracksters collection in DQM files: ", tracksterCollection) - - hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection) - val.doPlots(hgctrackster, plotterDrawArgs=drawArgs) - - #trackstersWithEdges - def plot_TstEdges(): - plot_Tst() - for tracksterCollection in trackstersIters : - hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)] - val.doPlots(hgctracksters, plotterDrawArgs=drawArgs) - - #caloParticles - def plot_CP(): - particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111", - "muon-": "-13", "muon+":"13", - "electron-": "-11", "electron+": "11", "photon": "22", - "kaon0L": "310", "kaon0S": "130", - "kaon-": "-321", "kaon+": "321"} - hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter] - for i_part, i_partID in particletypes.items() : - hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part) - val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs) - - #hitValidation - def plot_hitVal(): - hgchit = [hgcalPlots.hgcalHitPlotter] - hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits") - hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits") - hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis") - val.doPlots(hgchit, plotterDrawArgs=drawArgs) - - #hitCalibration - def plot_hitCal(): - hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter] - val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs) - - def plotCand(): - ticlcand = [hgcalPlots.hgcalTICLCandPlotter] - val.doPlots(ticlcand, plotterDrawArgs=drawArgs) - - plotDict = {hitCalLabel:[plot_hitCal], hitValLabel:[plot_hitVal], layerClustersLabel:[plot_LC], trackstersLabel:[plot_Tst], trackstersWithEdgesLabel:[plot_TstEdges], simLabel:[plot_SC, plot_CP], candidatesLabel:[plotCand]} - - if (opts.collection != allLabel): - for task in plotDict[opts.collection]: - task() - else: - for label in plotDict: - if (label == trackstersLabel): continue # already run in trackstersWithEdges - for task in plotDict[label]: - task() + # Hardcoded Offline and HLT HGCalValidator base folders + flavours = ( + ("offline", "DQMData/Run 1/HGCAL/Run summary/HGCalValidator/"), + ("hlt", "DQMData/Run 1/HLT/Run summary/HGCAL/HGCalValidator/"), + ) - if opts.no_html: - print("Plots created into directory '%s'." % opts.outputDir) - else: - htmlReport.write() + # Import once, then reload each pass to avoid accumulating plot definitions + import importlib + import Validation.HGCalValidation.hgcalPlots as hgcalPlots + + top_index_entries = [] + + for prefix, dqm_base in flavours: + out_dir = os.path.join(output_root, prefix) + os.makedirs(out_dir, exist_ok=True) + + # Reset plotters for each pass + hgcalPlots = importlib.reload(hgcalPlots) + + # Override the HGCalValidator base (used at least by TICL candidates) + if hasattr(hgcalPlots, "set_hgcVal_dqm"): + hgcalPlots.set_hgcVal_dqm(dqm_base) + else: + hgcalPlots.hgcVal_dqm = dqm_base + + sample = SimpleSample(prefix, opts.html_sample, filenames) + + val = SimpleValidation([sample], out_dir, nProc=opts.jobs) + if opts.separate: + val = SeparateValidation([sample], out_dir) + + htmlReport = val.createHtmlReport( + validationName=f"{opts.html_validation_name[0]} ({prefix})" + ) + + # Discover which collections exist under this base in the DQM file + discovered_subdirs = _discover_subdirs(opts.files[0], dqm_base) + + # Add any folder that looks like a trackster collection (case-insensitive match) + trackstersIters = [] + for name in sorted(discovered_subdirs, key=str.lower): + if (("trackster" in name.lower()) or ("candidate" in name.lower())) and name not in trackstersIters: + trackstersIters.append(name) + + # Add any direct subfolder that contains "layerClusters" in the name, case-insensitive + layerClustersIters = [ + name for name in sorted(discovered_subdirs, key=str.lower) + if "layerclusters" in name.lower() + ] + + # Fallback to the default validator label if no matching folder is found + if not layerClustersIters: + default_lc = hgcalValidator.label_layerClustersPlots.value() + if default_lc in discovered_subdirs: + layerClustersIters = [default_lc] + + # Detect candidates presence similarly + has_candidates = any("candidat" in n.lower() for n in discovered_subdirs) + + if opts.verbose: + print(f"Discovered under {dqm_base}: {sorted(discovered_subdirs, key=str.lower)}") + print(f"Using layerClusters collections for {prefix}: {layerClustersIters}") + print(f"Using tracksters collections for {prefix}: {trackstersIters}") + print(f"Candidates present for {prefix}: {has_candidates}") + + # layerClusters + def plot_LC(): + if not layerClustersIters: + print(f"Skipping layerClusters for {prefix}: no folder matching 'layerClusters' found under {dqm_base}") + return + + hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter] + for layerClusterCollection in layerClustersIters: + print("Searching for layerClusters collection in DQM files: ", layerClusterCollection) + hgcalPlots.append_hgcalLayerClustersPlots( + layerClusterCollection, + layerClusterCollection, + extendedFlag + ) + val.doPlots(hgclayclus, plotterDrawArgs=drawArgs) + + # simClusters + def plot_SC(): + hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter] + for i_iter in simClustersIters: + hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter) + val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs) + + # tracksters + def plot_Tst(): + hgctrackster = [hgcalPlots.hgcalTrackstersPlotter] + for tracksterCollection in trackstersIters: + print("Searching for tracksters collection in DQM files: ", tracksterCollection) + hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection) + val.doPlots(hgctrackster, plotterDrawArgs=drawArgs) + + # trackstersWithEdges + def plot_TstEdges(): + plot_Tst() + for tracksterCollection in trackstersIters: + hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)] + val.doPlots(hgctracksters, plotterDrawArgs=drawArgs) + + # caloParticles + def plot_CP(): + particletypes = { + "pion-": "-211", "pion+": "211", "pion0": "111", + "muon-": "-13", "muon+": "13", + "electron-": "-11", "electron+": "11", "photon": "22", + "kaon0L": "310", "kaon0S": "130", + "kaon-": "-321", "kaon+": "321" + } + hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter] + for i_part, i_partID in particletypes.items(): + hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part) + val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs) + + # hitValidation + def plot_hitVal(): + hgchit = [hgcalPlots.hgcalHitPlotter] + hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits") + hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits") + hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis") + val.doPlots(hgchit, plotterDrawArgs=drawArgs) + + # hitCalibration + def plot_hitCal(): + hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter] + val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs) + + # candidates + def plotCand(): + if not has_candidates: + print(f"Skipping candidates for {prefix}: no folder matching 'candidate' found under {dqm_base}") + return + candidate_labels = [n for n in discovered_subdirs if "candidate" in n.lower()] + ticlcand = [hgcalPlots.hgcalTICLCandPlotter(candidate_labels)] + val.doPlots(ticlcand, plotterDrawArgs=drawArgs) + + plotDict = { + hitCalLabel: [plot_hitCal], + hitValLabel: [plot_hitVal], + layerClustersLabel: [plot_LC], + trackstersLabel: [plot_Tst], + trackstersWithEdgesLabel: [plot_TstEdges], + simLabel: [plot_SC, plot_CP], + candidatesLabel: [plotCand], + } + + if allLabel not in collections: + for coll in collections: + for task in plotDict[coll]: + task() + else: + for label in plotDict: + if label == trackstersLabel: + continue # already run in trackstersWithEdges + for task in plotDict[label]: + task() + + if opts.no_html: + print("Plots created into directory '%s'." % out_dir) + else: + htmlReport.write() + print("Plots and HTML report created into directory '%s'." % out_dir) + top_index_entries.append((prefix, f"{prefix}/index.html")) + + if (not opts.no_html) and top_index_entries: + _write_top_index(output_root, top_index_entries) + print("Top-level index written to '%s'." % os.path.join(output_root, "index.html")) - print("Plots and HTML report created into directory '%s'. You can just move it to some www area and access the pages via web browser" % (','.join(opts.outputDir))) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.") parser.add_argument("files", metavar="file", type=str, nargs="+", - default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root", + default="DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root", help="DQM file to plot the validation plots from") - parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+", - help="Plot output directories (default: 'plots1'") - parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+", - help="Prefix for subdirectories inside outputDir (default: 'plots1')") - parser.add_argument("--no-ratio", action="store_true", default = False, + parser.add_argument("-o", "--outputDir", type=str, default=["plots"], nargs="+", + help="Plot output directories (default: 'plots'") + parser.add_argument("--subdirprefix", type=str, default=["HLT", "offline"], nargs="+", + help="Prefix for subdirectories inside outputDir (default: 'HLT, offline')") + parser.add_argument("--no-ratio", action="store_true", default=False, help="Disable ratio pads") - parser.add_argument("--separate", action="store_true", default = False, + parser.add_argument("--separate", action="store_true", default=False, help="Save all plots separately instead of grouping them") - parser.add_argument("--png", action="store_true", default = True, + parser.add_argument("--png", action="store_true", default=True, help="Save plots in PNG instead of PDF") - parser.add_argument("--no-html", action="store_true", default = False, + parser.add_argument("--no-html", action="store_true", default=False, help="Disable HTML page generation") - parser.add_argument("--html-sample", default=os.environ['CMSSW_VERSION'], + parser.add_argument("--html-sample", default=os.environ.get('CMSSW_VERSION', 'CMSSW'), help="Sample name for HTML page generation (default: CMSSW version)") - parser.add_argument("--html-validation-name", type=str, default=["TICL Validation",""], nargs="+", + parser.add_argument("--html-validation-name", type=str, default=["TICL Validation", ""], nargs="+", help="Validation name for HTML page generation (enters to element) (default 'TICL Validation')") - parser.add_argument("--collection", choices=collection_choices, default=layerClustersLabel, - help="Choose output plots collections among possible choices") - parser.add_argument("--extended", action="store_true", default = False, + parser.add_argument("--collection", default=trackstersLabel, type=str, + help="Choose output plots collections among possible choices: {collection_choices}") + parser.add_argument("--extended", action="store_true", default=False, help="Include extended set of plots (e.g. bunch of distributions; default off)") parser.add_argument("--jobs", default=0, type=int, help="Number of jobs to run in parallel for generating plots. Default is 0 i.e. run number of cpu cores jobs.") - parser.add_argument("--ticlv", choices=ticlVersions, default=4, type=int, - help="TICL Version. Specify 4 or 5. Default 4.") - parser.add_argument("--verbose", action="store_true", default = False, + parser.add_argument("--ticlv", choices=ticlVersions, default=5, type=int, + help="TICL Version. Default 5.") + parser.add_argument("--verbose", action="store_true", default=False, help="Be verbose") opts = parser.parse_args() @@ -173,5 +309,7 @@ def plotCand(): for f in opts.files: if not os.path.exists(f): parser.error("DQM file %s does not exist" % f) - - main(opts) + if len(opts.files) == 0: + parser.error("No DQM files specified") + else: + main(opts) \ No newline at end of file diff --git a/Validation/HGCalValidation/src/TICLCandidateValidator.cc b/Validation/HGCalValidation/src/TICLCandidateValidator.cc index 09d4d735820a6..890e776ef209a 100644 --- a/Validation/HGCalValidation/src/TICLCandidateValidator.cc +++ b/Validation/HGCalValidation/src/TICLCandidateValidator.cc @@ -10,15 +10,13 @@ TICLCandidateValidator::TICLCandidateValidator(edm::EDGetTokenT<std::vector<TICL edm::EDGetTokenT<std::vector<reco::Track>> recoTracksToken, edm::EDGetTokenT<std::vector<ticl::Trackster>> trackstersToken, edm::EDGetTokenT<ticl::TracksterToTracksterMap> associatorMapRtSToken, - edm::EDGetTokenT<ticl::TracksterToTracksterMap> associatorMapStRToken, - bool isTICLv5) + edm::EDGetTokenT<ticl::TracksterToTracksterMap> associatorMapStRToken) : TICLCandidatesToken_(ticlCandidates), simTICLCandidatesToken_(simTICLCandidatesToken), recoTracksToken_(recoTracksToken), trackstersToken_(trackstersToken), associatorMapRtSToken_(associatorMapRtSToken), - associatorMapStRToken_(associatorMapStRToken), - isTICLv5_(isTICLv5) {} + associatorMapStRToken_(associatorMapStRToken) {} TICLCandidateValidator::~TICLCandidateValidator() {} @@ -529,21 +527,20 @@ void TICLCandidateValidator::fillCandidateHistos(const edm::Event& event, } auto& recoCand = TICLCandidates[cand_idx]; - if (isTICLv5_) { - // cand_idx is the tsMerge index, find the ts in the candidates collection - auto cand_it = - std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [firstTs, cand_idx](TICLCandidate const& cand) { - if (!cand.tracksters().empty()) - return (cand.tracksters()[0]).get() - firstTs == - cand_idx; // in TICLv5 there is one trackster per candidate - else - return false; - }); - if (cand_it != TICLCandidates.end()) - recoCand = *cand_it; - else - continue; - } + + // cand_idx is the tsMerge index, find the ts in the candidates collection + auto cand_it = + std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [firstTs, cand_idx](TICLCandidate const& cand) { + if (!cand.tracksters().empty()) + return (cand.tracksters()[0]).get() - firstTs == + cand_idx; // in TICLv5 there is one trackster per candidate + else + return false; + }); + if (cand_it != TICLCandidates.end()) + recoCand = *cand_it; + else + continue; if (recoCand.trackPtr().get() != nullptr) { const auto candTrackIdx = recoCand.trackPtr().get() - firstTrack; @@ -614,21 +611,20 @@ void TICLCandidateValidator::fillCandidateHistos(const edm::Event& event, } auto& recoCand = TICLCandidates[cand_idx]; - if (isTICLv5_) { - // cand_idx is the tsMerge index, find the ts in the candidates collection - auto cand_it = - std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [firstTs, cand_idx](TICLCandidate const& cand) { - if (!cand.tracksters().empty()) - return (cand.tracksters()[0]).get() - firstTs == - cand_idx; // in TICLv5 there is one trackster per candidate - else - return false; - }); - if (cand_it != TICLCandidates.end()) - recoCand = *cand_it; - else - continue; - } + + // cand_idx is the tsMerge index, find the ts in the candidates collection + auto cand_it = + std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [firstTs, cand_idx](TICLCandidate const& cand) { + if (!cand.tracksters().empty()) + return (cand.tracksters()[0]).get() - firstTs == + cand_idx; // in TICLv5 there is one trackster per candidate + else + return false; + }); + if (cand_it != TICLCandidates.end()) + recoCand = *cand_it; + else + continue; if (recoCand.trackPtr().get() != nullptr) continue; @@ -691,11 +687,7 @@ void TICLCandidateValidator::fillCandidateHistos(const edm::Event& event, if (cand.tracksters().empty()) continue; - // i is the candidate idx == ts idx only in v4, find ts_idx in v5 - auto mergeTs_id = i; - if (isTICLv5_) { - mergeTs_id = cand.tracksters()[0].get() - firstTs; - } + auto mergeTs_id = cand.tracksters()[0].get() - firstTs; // +1 to all denominators histograms.h_den_fake_chg_energy_candidate[index]->Fill(cand.rawEnergy()); @@ -806,11 +798,7 @@ void TICLCandidateValidator::fillCandidateHistos(const edm::Event& event, if (cand.tracksters().empty()) continue; - // i is the candidate idx == ts idx only in v4, find ts_idx in v5 - auto mergeTs_id = i; - if (isTICLv5_) { - mergeTs_id = cand.tracksters()[0].get() - firstTs; - } + auto mergeTs_id = cand.tracksters()[0].get() - firstTs; // +1 to all denominators histograms.h_den_fake_neut_energy_candidate[index]->Fill(cand.rawEnergy()); diff --git a/Validation/HGCalValidation/test/python/standalone_fromRECO.py b/Validation/HGCalValidation/test/python/standalone_fromRECO.py index a9f3ca36f64d9..793d143fb7c1a 100644 --- a/Validation/HGCalValidation/test/python/standalone_fromRECO.py +++ b/Validation/HGCalValidation/test/python/standalone_fromRECO.py @@ -56,9 +56,8 @@ process.load("Validation.HGCalValidation.hgcalHitValidation_cfi") process.load("Validation.HGCalValidation.hgcalHitCalibration_cfi") -process.load("Validation.HGCalValidation.caloparticlevalidation_cfi") -process.dqmoffline_step = cms.EndPath(process.hgcalHitValidation+process.hgcalHitCalibration+process.caloparticlevalidation) +process.dqmoffline_step = cms.EndPath(process.hgcalHitValidation+process.hgcalHitCalibration) process.DQMoutput_step = cms.EndPath(process.DQMoutput) # Schedule definition diff --git a/Validation/HGCalValidation/test/test_makeHGCalValidationPlots.sh b/Validation/HGCalValidation/test/test_makeHGCalValidationPlots.sh index f48bd5938dbf0..d7fecd9cdb164 100755 --- a/Validation/HGCalValidation/test/test_makeHGCalValidationPlots.sh +++ b/Validation/HGCalValidation/test/test_makeHGCalValidationPlots.sh @@ -6,4 +6,4 @@ function die { cat 29690*/*.log; echo $1: status $2; exit $2; } # 29690.0 is SingleGamma eta1p7to2p7 D110 runTheMatrix.py -w upgrade -l 29690.0 --startFrom HARVESTING --maxSteps 4 --recycle das:/RelValTTbar_14TeV/CMSSW_15_1_0-150X_mcRun4_realistic_v1_STD_RecycledGS_Run4D110_noPU-v2/DQMIO --command="-s HARVESTING:@HGCalValidation" || die "Could not run HARVESTING" $? -(makeHGCalValidationPlots.py --collection all --jobs 4 --ticlv 4 29690.0*/DQM*.root) || die "makeHGCalValidationPlots.py failed" $? +(makeHGCalValidationPlots.py --collection all --jobs 4 29690.0*/DQM*.root) || die "makeHGCalValidationPlots.py failed" $?