From a2c9edcafaf371b4633f288b457573250e7ad010 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Wed, 18 Oct 2023 10:31:25 +0200 Subject: [PATCH 1/7] Introducing SimTauCPLink --- .../python/RecoHGCal_EventContent_cff.py | 1 + .../plugins/SimTauCPLinkProducer.cc | 242 ++++++++++++++++++ .../python/SimTauCPLink_cfi.py | 7 + .../CaloAnalysis/interface/SimTauCPLink.h | 82 ++++++ SimDataFormats/CaloAnalysis/src/classes.h | 2 + .../CaloAnalysis/src/classes_def.xml | 6 + SimGeneral/Debugging/plugins/BuildFile.xml | 4 +- .../Debugging/plugins/SimTauAnalyzer.cc | 62 +++++ .../Debugging/test/simTauAnalyzer_cfg.py | 28 ++ .../Configuration/python/hgcalSimValid_cff.py | 4 +- 10 files changed, 436 insertions(+), 2 deletions(-) create mode 100644 SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc create mode 100644 SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py create mode 100644 SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h create mode 100644 SimGeneral/Debugging/plugins/SimTauAnalyzer.cc create mode 100644 SimGeneral/Debugging/test/simTauAnalyzer_cfg.py diff --git a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py index 867c8a52e9b09..cd378f8f543b4 100644 --- a/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py +++ b/RecoHGCal/Configuration/python/RecoHGCal_EventContent_cff.py @@ -35,6 +35,7 @@ 'keep *_ticlSimTracksters_*_*', 'keep *_ticlSimTICLCandidates_*_*', 'keep *_ticlSimTrackstersFromCP_*_*', + 'keep *_SimTau*_*_*' ) ) TICL_FEVT.outputCommands.extend(TICL_RECO.outputCommands) diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc new file mode 100644 index 0000000000000..6673392510594 --- /dev/null +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -0,0 +1,242 @@ +// -*- C++ -*- +// +// +// Authors: Marco Rovere, Andreas Gruber +// Created: Mon, 16 Oct 2023 14:24:35 GMT +// +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "DataFormats/HGCalReco/interface/TICLCandidate.h" +#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" +#include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" +#include "SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +class SimTauProducer : public edm::stream::EDProducer<> { +public: + explicit SimTauProducer(const edm::ParameterSet&); + ~SimTauProducer() override = default; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + + void buildSimTau(SimTauCPLink&, + uint8_t, + int, + const reco::GenParticle&, + int, + edm::Handle>, + const std::vector&); + int buildDecayModes(const SimTauCPLink&); + // ----------member data --------------------------- + const edm::EDGetTokenT> caloParticle_token_; + const edm::EDGetTokenT> genParticles_token_; + const edm::EDGetTokenT> genBarcodes_token_; +}; + +SimTauProducer::SimTauProducer(const edm::ParameterSet& iConfig) + : caloParticle_token_(consumes>(iConfig.getParameter("CaloParticle"))), + genParticles_token_(consumes(iConfig.getParameter("GenParticles"))), + genBarcodes_token_(consumes>(iConfig.getParameter("GenBarcodes"))) { + produces>(); +} + +void SimTauProducer::buildSimTau(SimTauCPLink& t, + uint8_t generation, + int resonance_idx, + const reco::GenParticle& gen_particle, + int gen_particle_key, + edm::Handle> calo_particle_h, + const std::vector& gen_particle_barcodes) { + const auto& caloPartVec = *calo_particle_h; + auto& daughters = gen_particle.daughterRefVector(); + bool is_leaf = (daughters.empty()); + if (is_leaf) { + LogDebug("SimTauProducer") << " TO BE SAVED " + std::to_string(resonance_idx) + " "; + auto const& gen_particle_barcode = gen_particle_barcodes[gen_particle_key]; + auto const& found_in_caloparticles = std::find_if(caloPartVec.begin(), caloPartVec.end(), [&](const auto& p) { + return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode; + }); + if (found_in_caloparticles != caloPartVec.end()) { + auto calo_particle_idx = (found_in_caloparticles - caloPartVec.begin()); + t.calo_particle_leaves.push_back(CaloParticleRef(calo_particle_h, calo_particle_idx)); + t.leaves.push_back( + {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key}); + LogDebug("SimTauProducer") << " CP " + std::to_string(calo_particle_idx) + " " << caloPartVec[calo_particle_idx]; + } else { + t.leaves.push_back({gen_particle.pdgId(), resonance_idx, -1, gen_particle_key}); + } + return; + } else if (generation != 0) { + t.resonances.push_back({gen_particle.pdgId(), resonance_idx}); + resonance_idx = t.resonances.size() - 1; + LogDebug("SimTauProducer") << " RESONANCE/INTERMEDIATE " + std::to_string(resonance_idx) + " "; + } + + ++generation; + for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) { + int gen_particle_key = (*daughter).key(); + LogDebug("SimTauProducer") << " gen " + std::to_string((int)generation) + " " + std::to_string(gen_particle_key) + + " " + std::to_string((*daughter)->pdgId()) + " "; + buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes); + } +} + +int SimTauProducer::buildDecayModes(const SimTauCPLink& t) { + enum decayModes { + kNull = -1, + kOneProng0PiZero, + kOneProng1PiZero, + kOneProng2PiZero, + kOneProng3PiZero, + kOneProngNPiZero, + kTwoProng0PiZero, + kTwoProng1PiZero, + kTwoProng2PiZero, + kTwoProng3PiZero, + kTwoProngNPiZero, + kThreeProng0PiZero, + kThreeProng1PiZero, + kThreeProng2PiZero, + kThreeProng3PiZero, + kThreeProngNPiZero, + kRareDecayMode, + kElectron, + kMuon + }; + + int numElectrons = 0; + int numMuons = 0; + int numHadrons = 0; + int numPhotons = 0; + auto& leaves = t.leaves; + for (auto leaf : leaves) { + int pdg_id = abs(leaf.pdgId()); + switch (pdg_id) { + case 22: + numPhotons++; + break; + case 11: + numElectrons++; + break; + case 13: + numMuons++; + break; + case 16: + break; + default: + numHadrons++; + } + } + + if (numElectrons == 1) + return kElectron; + else if (numMuons == 1) + return kMuon; + switch (numHadrons) { + case 1: + switch (numPhotons) { + case 0: + return kOneProng0PiZero; + case 2: + return kOneProng1PiZero; + case 4: + return kOneProng2PiZero; + case 6: + return kOneProng3PiZero; + default: + return kOneProngNPiZero; + } + case 2: + switch (numPhotons) { + case 0: + return kTwoProng0PiZero; + case 2: + return kTwoProng1PiZero; + case 4: + return kTwoProng2PiZero; + case 6: + return kTwoProng3PiZero; + default: + return kTwoProngNPiZero; + } + case 3: + switch (numPhotons) { + case 0: + return kThreeProng0PiZero; + case 2: + return kThreeProng1PiZero; + case 4: + return kThreeProng2PiZero; + case 6: + return kThreeProng3PiZero; + default: + return kThreeProngNPiZero; + } + default: + return kRareDecayMode; + } +} + +// ------------ method called for each event ------------ +void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + using namespace edm; + + Handle> CaloParticle_h; + iEvent.getByToken(caloParticle_token_, CaloParticle_h); + + edm::Handle> gen_particles_h; + iEvent.getByToken(genParticles_token_, gen_particles_h); + + Handle> gen_barcodes_h; + iEvent.getByToken(genBarcodes_token_, gen_barcodes_h); + + const auto& genParticles = *gen_particles_h; + const auto& genBarcodes = *gen_barcodes_h; + auto tauDecayVec = std::make_unique>(); + for (auto const& g : genParticles) { + auto const& flags = g.statusFlags(); + if (std::abs(g.pdgId()) == 15 and flags.isPrompt() and flags.isDecayedLeptonHadron()) { + SimTauCPLink t; + buildSimTau(t, 0, -1, g, -1, CaloParticle_h, genBarcodes); + t.decayMode = buildDecayModes(t); + t.dump(); + t.dumpFullDecay(); + (*tauDecayVec).push_back(t); + } + } + iEvent.put(std::move(tauDecayVec)); +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void SimTauProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SimTauProducer); diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py new file mode 100644 index 0000000000000..ae3ff0eeb6e9e --- /dev/null +++ b/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py @@ -0,0 +1,7 @@ +import FWCore.ParameterSet.Config as cms + +SimTauCPLink = cms.EDProducer("SimTauProducer", + CaloParticle = cms.InputTag('mix', 'MergedCaloTruth'), + GenParticles = cms.InputTag('genParticles'), + GenBarcodes = cms.InputTag('genParticles') + ) diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h new file mode 100644 index 0000000000000..45aeddab20305 --- /dev/null +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -0,0 +1,82 @@ +#ifndef SimDataFormats_SimTauCPLink_h +#define SimDataFormats_SimTauCPLink_h + +#include "DataFormats/HGCalReco/interface/TICLCandidate.h" +#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" +#include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +class SimTauCPLink { +public: + SimTauCPLink(){}; + ~SimTauCPLink(){}; + struct DecayNav { + int pdgId_; + int resonance_idx_; + int calo_particle_idx_; + int gen_particle_idx_; + int pdgId() const { return pdgId_; } + int resonance_idx() const { return resonance_idx_; } + int calo_particle_idx() const { return calo_particle_idx_; } + int gen_particle_idx() const { return gen_particle_idx_; } + }; + + std::vector> resonances; + std::vector leaves; + CaloParticleRefVector calo_particle_leaves; + int decayMode; + + enum decayModes { + kNull = -1, + kOneProng0PiZero, + kOneProng1PiZero, + kOneProng2PiZero, + kOneProng3PiZero, + kOneProngNPiZero, + kTwoProng0PiZero, + kTwoProng1PiZero, + kTwoProng2PiZero, + kTwoProng3PiZero, + kTwoProngNPiZero, + kThreeProng0PiZero, + kThreeProng1PiZero, + kThreeProng2PiZero, + kThreeProng3PiZero, + kThreeProngNPiZero, + kRareDecayMode, + kElectron, + kMuon + }; + + void dump(void) const { + for (auto const &l : leaves) { + LogDebug("SimTauProducer") << "L " + std::to_string(l.pdgId()) + " " + std::to_string(l.resonance_idx()) + + " CP: " + std::to_string(l.calo_particle_idx()) + + " GenP idx: " + std::to_string(l.gen_particle_idx()); + } + for (auto const &r : resonances) { + LogDebug("SimTauProducer") << "R " + std::to_string(r.first) + " " + std::to_string(r.second); + } + } + + void dumpDecay(const std::pair &entry) const { + if (entry.second == -1) { // No intermediate mother. + LogDebug("SimTauProducer") << std::to_string(entry.first) + " " + std::to_string(entry.second); + } else { + LogDebug("SimTauProducer") << std::to_string(entry.first) + " " + std::to_string(entry.second) + " coming from: "; + auto const &mother = resonances[entry.second]; + dumpDecay(mother); + } + } + + void dumpFullDecay(void) const { + for (auto const &leaf : leaves) { + dumpDecay({leaf.pdgId(), leaf.resonance_idx()}); + } + } + +private: +}; + +#endif //SimTauCPLink diff --git a/SimDataFormats/CaloAnalysis/src/classes.h b/SimDataFormats/CaloAnalysis/src/classes.h index 4ae821b748489..e176ec45d4b66 100644 --- a/SimDataFormats/CaloAnalysis/src/classes.h +++ b/SimDataFormats/CaloAnalysis/src/classes.h @@ -10,3 +10,5 @@ #include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h" #include "SimDataFormats/CaloAnalysis/interface/MtdSimTrackster.h" #include "SimDataFormats/CaloAnalysis/interface/MtdSimTracksterFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h" +#include "DataFormats/Common/interface/Wrapper.h" diff --git a/SimDataFormats/CaloAnalysis/src/classes_def.xml b/SimDataFormats/CaloAnalysis/src/classes_def.xml index 35ee606d29a93..bd0cc0f56c392 100644 --- a/SimDataFormats/CaloAnalysis/src/classes_def.xml +++ b/SimDataFormats/CaloAnalysis/src/classes_def.xml @@ -52,6 +52,12 @@ + + + + + + diff --git a/SimGeneral/Debugging/plugins/BuildFile.xml b/SimGeneral/Debugging/plugins/BuildFile.xml index 6660b275280f6..8d604197d92a7 100644 --- a/SimGeneral/Debugging/plugins/BuildFile.xml +++ b/SimGeneral/Debugging/plugins/BuildFile.xml @@ -9,4 +9,6 @@ - + + +\ diff --git a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc new file mode 100644 index 0000000000000..878470cc09a0a --- /dev/null +++ b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc @@ -0,0 +1,62 @@ +// -*- C++ -*- +// +// +// Original Author: Andreas Gruber +// Created: Mon, 16 Oct 2023 14:24:35 GMT +// +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "TH1.h" + +#include "SimDataFormats/CaloAnalysis/interface/CaloParticleFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/CaloParticle.h" +#include "SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +class SimTauAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit SimTauAnalyzer(const edm::ParameterSet&); + ~SimTauAnalyzer() override = default; + +private: + void analyze(const edm::Event&, const edm::EventSetup&) override; + + const edm::EDGetTokenT> simTau_token_; + TH1D* DM_histo; +}; + +SimTauAnalyzer::SimTauAnalyzer(const edm::ParameterSet& iConfig) + : simTau_token_(consumes>(iConfig.getParameter("simTau"))) { + edm::Service fs; + DM_histo = fs->make("DM_histo", "DM_histo", 20, -1, 19); +} + +// ------------ method called for each event ------------ +void SimTauAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle> simTau_h; + iEvent.getByToken(simTau_token_, simTau_h); + + const auto& simTaus = *simTau_h; + + for (auto const& simTau : simTaus) { + simTau.dumpFullDecay(); + simTau.dump(); + DM_histo->Fill(simTau.decayMode); + } +} + +//define this as a plug-in +DEFINE_FWK_MODULE(SimTauAnalyzer); diff --git a/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py new file mode 100644 index 0000000000000..4c747b9e81978 --- /dev/null +++ b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py @@ -0,0 +1,28 @@ +import FWCore.ParameterSet.Config as cms +import sys + +process = cms.Process("SimTauAnalyzer") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.threshold = "DEBUG" +process.MessageLogger.debugModules = ["SimTauCPLink", "SimTauProducer", "SimTauAnalyzer"] + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) + ) +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + #'file:/data/agruber/patatrack/CMSSW_13_3_0_pre3/src/24034.0_TTbar_14TeV+2026D96/step3.root' + 'file:SimTauProducer_test.root' + ) + ) + +process.TFileService = cms.Service("TFileService", + fileName = cms.string('test.root') + ) + +process.SimTauAnalyzer = cms.EDAnalyzer('SimTauAnalyzer', +GenParticles = cms.InputTag('genParticles'), +simTau = cms.InputTag('SimTauCPLink') + ) + +process.p = cms.Path(process.SimTauAnalyzer) diff --git a/Validation/Configuration/python/hgcalSimValid_cff.py b/Validation/Configuration/python/hgcalSimValid_cff.py index 142fda660ed81..3d39301ee6cf0 100644 --- a/Validation/Configuration/python/hgcalSimValid_cff.py +++ b/Validation/Configuration/python/hgcalSimValid_cff.py @@ -10,6 +10,7 @@ from SimCalorimetry.HGCalAssociatorProducers.LCToCPAssociation_cfi import layerClusterCaloParticleAssociationHFNose as layerClusterCaloParticleAssociationProducerHFNose from SimCalorimetry.HGCalAssociatorProducers.LCToSCAssociation_cfi import layerClusterSimClusterAssociationHFNose as layerClusterSimClusterAssociationProducerHFNose from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import tracksterSimTracksterAssociationLinking, tracksterSimTracksterAssociationPR,tracksterSimTracksterAssociationLinkingbyCLUE3D, tracksterSimTracksterAssociationPRbyCLUE3D, tracksterSimTracksterAssociationLinkingPU, tracksterSimTracksterAssociationPRPU +from SimCalorimetry.HGCalAssociatorProducers.SimTauCPLink_cfi import * from Validation.HGCalValidation.simhitValidation_cff import * from Validation.HGCalValidation.digiValidation_cff import * @@ -38,7 +39,8 @@ simTsAssocByEnergyScoreProducer, simTracksterHitLCAssociatorByEnergyScoreProducer, tracksterSimTracksterAssociationLinking, tracksterSimTracksterAssociationPR, tracksterSimTracksterAssociationLinkingbyCLUE3D, tracksterSimTracksterAssociationPRbyCLUE3D, - tracksterSimTracksterAssociationLinkingPU, tracksterSimTracksterAssociationPRPU + tracksterSimTracksterAssociationLinkingPU, tracksterSimTracksterAssociationPRPU, + SimTauCPLink ) hgcalValidation = cms.Sequence(hgcalSimHitValidationEE From 493aab30956abf1e25479ee2315b9455186b6d13 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Thu, 7 Dec 2023 11:34:37 +0100 Subject: [PATCH 2/7] move buildDecayModes to SimTauCPLink --- .../plugins/SimTauCPLinkProducer.cc | 143 +++--------------- .../python/SimTauCPLink_cfi.py | 6 +- .../CaloAnalysis/interface/SimTauCPLink.h | 74 +++++++++ .../Debugging/plugins/SimTauAnalyzer.cc | 6 +- .../Debugging/test/simTauAnalyzer_cfg.py | 3 +- 5 files changed, 104 insertions(+), 128 deletions(-) diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc index 6673392510594..e9626bd70e20b 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -48,17 +48,16 @@ class SimTauProducer : public edm::stream::EDProducer<> { int, edm::Handle>, const std::vector&); - int buildDecayModes(const SimTauCPLink&); // ----------member data --------------------------- - const edm::EDGetTokenT> caloParticle_token_; + const edm::EDGetTokenT> caloParticles_token_; const edm::EDGetTokenT> genParticles_token_; const edm::EDGetTokenT> genBarcodes_token_; }; SimTauProducer::SimTauProducer(const edm::ParameterSet& iConfig) - : caloParticle_token_(consumes>(iConfig.getParameter("CaloParticle"))), - genParticles_token_(consumes(iConfig.getParameter("GenParticles"))), - genBarcodes_token_(consumes>(iConfig.getParameter("GenBarcodes"))) { + : caloParticles_token_(consumes>(iConfig.getParameter("caloParticles"))), + genParticles_token_(consumes(iConfig.getParameter("genParticles"))), + genBarcodes_token_(consumes>(iConfig.getParameter("genBarcodes"))) { produces>(); } @@ -103,140 +102,42 @@ void SimTauProducer::buildSimTau(SimTauCPLink& t, } } -int SimTauProducer::buildDecayModes(const SimTauCPLink& t) { - enum decayModes { - kNull = -1, - kOneProng0PiZero, - kOneProng1PiZero, - kOneProng2PiZero, - kOneProng3PiZero, - kOneProngNPiZero, - kTwoProng0PiZero, - kTwoProng1PiZero, - kTwoProng2PiZero, - kTwoProng3PiZero, - kTwoProngNPiZero, - kThreeProng0PiZero, - kThreeProng1PiZero, - kThreeProng2PiZero, - kThreeProng3PiZero, - kThreeProngNPiZero, - kRareDecayMode, - kElectron, - kMuon - }; - - int numElectrons = 0; - int numMuons = 0; - int numHadrons = 0; - int numPhotons = 0; - auto& leaves = t.leaves; - for (auto leaf : leaves) { - int pdg_id = abs(leaf.pdgId()); - switch (pdg_id) { - case 22: - numPhotons++; - break; - case 11: - numElectrons++; - break; - case 13: - numMuons++; - break; - case 16: - break; - default: - numHadrons++; - } - } - - if (numElectrons == 1) - return kElectron; - else if (numMuons == 1) - return kMuon; - switch (numHadrons) { - case 1: - switch (numPhotons) { - case 0: - return kOneProng0PiZero; - case 2: - return kOneProng1PiZero; - case 4: - return kOneProng2PiZero; - case 6: - return kOneProng3PiZero; - default: - return kOneProngNPiZero; - } - case 2: - switch (numPhotons) { - case 0: - return kTwoProng0PiZero; - case 2: - return kTwoProng1PiZero; - case 4: - return kTwoProng2PiZero; - case 6: - return kTwoProng3PiZero; - default: - return kTwoProngNPiZero; - } - case 3: - switch (numPhotons) { - case 0: - return kThreeProng0PiZero; - case 2: - return kThreeProng1PiZero; - case 4: - return kThreeProng2PiZero; - case 6: - return kThreeProng3PiZero; - default: - return kThreeProngNPiZero; - } - default: - return kRareDecayMode; - } -} - -// ------------ method called for each event ------------ void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; - Handle> CaloParticle_h; - iEvent.getByToken(caloParticle_token_, CaloParticle_h); + Handle> caloParticles_h; + iEvent.getByToken(caloParticles_token_, caloParticles_h); - edm::Handle> gen_particles_h; - iEvent.getByToken(genParticles_token_, gen_particles_h); + edm::Handle> genParticles_h; + iEvent.getByToken(genParticles_token_, genParticles_h); - Handle> gen_barcodes_h; - iEvent.getByToken(genBarcodes_token_, gen_barcodes_h); + Handle> genBarcodes_h; + iEvent.getByToken(genBarcodes_token_, genBarcodes_h); - const auto& genParticles = *gen_particles_h; - const auto& genBarcodes = *gen_barcodes_h; + const auto& genParticles = *genParticles_h; + const auto& genBarcodes = *genBarcodes_h; auto tauDecayVec = std::make_unique>(); for (auto const& g : genParticles) { auto const& flags = g.statusFlags(); if (std::abs(g.pdgId()) == 15 and flags.isPrompt() and flags.isDecayedLeptonHadron()) { SimTauCPLink t; - buildSimTau(t, 0, -1, g, -1, CaloParticle_h, genBarcodes); - t.decayMode = buildDecayModes(t); - t.dump(); - t.dumpFullDecay(); + buildSimTau(t, 0, -1, g, -1, caloParticles_h, genBarcodes); + t.decayMode = t.buildDecayModes(); + #ifdef EDM_ML_DEBUG + t.dumpFullDecay(); + t.dump(); + #endif (*tauDecayVec).push_back(t); } } iEvent.put(std::move(tauDecayVec)); } -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void SimTauProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} + desc.add("caloParticles", edm::InputTag("mix", "MergedCaloTruth")); + desc.add("genParticles", edm::InputTag("genParticles")); + desc.add("genBarcodes", edm::InputTag("genParticles")); + descriptions.add("SimTauProducer", desc);} -//define this as a plug-in DEFINE_FWK_MODULE(SimTauProducer); diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py index ae3ff0eeb6e9e..3596cf098d194 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py +++ b/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py @@ -1,7 +1,7 @@ import FWCore.ParameterSet.Config as cms SimTauCPLink = cms.EDProducer("SimTauProducer", - CaloParticle = cms.InputTag('mix', 'MergedCaloTruth'), - GenParticles = cms.InputTag('genParticles'), - GenBarcodes = cms.InputTag('genParticles') + caloParticles = cms.InputTag('mix', 'MergedCaloTruth'), + genParticles = cms.InputTag('genParticles'), + genBarcodes = cms.InputTag('genParticles') ) diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h index 45aeddab20305..02a789fb34cc6 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -76,6 +76,80 @@ class SimTauCPLink { } } + int buildDecayModes() { + + int numElectrons = 0; + int numMuons = 0; + int numHadrons = 0; + int numPhotons = 0; + for (auto leaf : leaves) { + int pdg_id = abs(leaf.pdgId()); + switch (pdg_id) { + case 22: + numPhotons++; + break; + case 11: + numElectrons++; + break; + case 13: + numMuons++; + break; + case 16: + break; + default: + numHadrons++; + } + } + + if (numElectrons == 1) + return kElectron; + else if (numMuons == 1) + return kMuon; + switch (numHadrons) { + case 1: + switch (numPhotons) { + case 0: + return kOneProng0PiZero; + case 2: + return kOneProng1PiZero; + case 4: + return kOneProng2PiZero; + case 6: + return kOneProng3PiZero; + default: + return kOneProngNPiZero; + } + case 2: + switch (numPhotons) { + case 0: + return kTwoProng0PiZero; + case 2: + return kTwoProng1PiZero; + case 4: + return kTwoProng2PiZero; + case 6: + return kTwoProng3PiZero; + default: + return kTwoProngNPiZero; + } + case 3: + switch (numPhotons) { + case 0: + return kThreeProng0PiZero; + case 2: + return kThreeProng1PiZero; + case 4: + return kThreeProng2PiZero; + case 6: + return kThreeProng3PiZero; + default: + return kThreeProngNPiZero; + } + default: + return kRareDecayMode; + } +} + private: }; diff --git a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc index 878470cc09a0a..d6786c302b255 100644 --- a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc +++ b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc @@ -52,8 +52,10 @@ void SimTauAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iS const auto& simTaus = *simTau_h; for (auto const& simTau : simTaus) { - simTau.dumpFullDecay(); - simTau.dump(); + #ifdef EDM_ML_DEBUG + simTau.dumpFullDecay(); + simTau.dump(); + #endif DM_histo->Fill(simTau.decayMode); } } diff --git a/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py index 4c747b9e81978..bfc8c872f381a 100644 --- a/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py +++ b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py @@ -11,7 +11,7 @@ ) process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring( - #'file:/data/agruber/patatrack/CMSSW_13_3_0_pre3/src/24034.0_TTbar_14TeV+2026D96/step3.root' + #'file:/data/agruber/patatrack/CMSSW_14_0_0_pre0/src/24036.0_ZTT_14TeV+2026D96/step3.root' 'file:SimTauProducer_test.root' ) ) @@ -21,7 +21,6 @@ ) process.SimTauAnalyzer = cms.EDAnalyzer('SimTauAnalyzer', -GenParticles = cms.InputTag('genParticles'), simTau = cms.InputTag('SimTauCPLink') ) From 19e0a52f6e030e0df6ec968371f0b8984d49bbd5 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Thu, 7 Dec 2023 13:58:23 +0100 Subject: [PATCH 3/7] code-check updates --- .../plugins/SimTauCPLinkProducer.cc | 11 +- .../CaloAnalysis/interface/SimTauCPLink.h | 135 +++++++++--------- .../Debugging/plugins/SimTauAnalyzer.cc | 8 +- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc index e9626bd70e20b..68af82bb6aa23 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -123,10 +123,10 @@ void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) SimTauCPLink t; buildSimTau(t, 0, -1, g, -1, caloParticles_h, genBarcodes); t.decayMode = t.buildDecayModes(); - #ifdef EDM_ML_DEBUG - t.dumpFullDecay(); - t.dump(); - #endif +#ifdef EDM_ML_DEBUG + t.dumpFullDecay(); + t.dump(); +#endif (*tauDecayVec).push_back(t); } } @@ -138,6 +138,7 @@ void SimTauProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("caloParticles", edm::InputTag("mix", "MergedCaloTruth")); desc.add("genParticles", edm::InputTag("genParticles")); desc.add("genBarcodes", edm::InputTag("genParticles")); - descriptions.add("SimTauProducer", desc);} + descriptions.add("SimTauProducer", desc); +} DEFINE_FWK_MODULE(SimTauProducer); diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h index 02a789fb34cc6..26a6c70f7d2c4 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -77,79 +77,78 @@ class SimTauCPLink { } int buildDecayModes() { + int numElectrons = 0; + int numMuons = 0; + int numHadrons = 0; + int numPhotons = 0; + for (auto leaf : leaves) { + int pdg_id = abs(leaf.pdgId()); + switch (pdg_id) { + case 22: + numPhotons++; + break; + case 11: + numElectrons++; + break; + case 13: + numMuons++; + break; + case 16: + break; + default: + numHadrons++; + } + } - int numElectrons = 0; - int numMuons = 0; - int numHadrons = 0; - int numPhotons = 0; - for (auto leaf : leaves) { - int pdg_id = abs(leaf.pdgId()); - switch (pdg_id) { - case 22: - numPhotons++; - break; - case 11: - numElectrons++; - break; - case 13: - numMuons++; - break; - case 16: - break; + if (numElectrons == 1) + return kElectron; + else if (numMuons == 1) + return kMuon; + switch (numHadrons) { + case 1: + switch (numPhotons) { + case 0: + return kOneProng0PiZero; + case 2: + return kOneProng1PiZero; + case 4: + return kOneProng2PiZero; + case 6: + return kOneProng3PiZero; + default: + return kOneProngNPiZero; + } + case 2: + switch (numPhotons) { + case 0: + return kTwoProng0PiZero; + case 2: + return kTwoProng1PiZero; + case 4: + return kTwoProng2PiZero; + case 6: + return kTwoProng3PiZero; + default: + return kTwoProngNPiZero; + } + case 3: + switch (numPhotons) { + case 0: + return kThreeProng0PiZero; + case 2: + return kThreeProng1PiZero; + case 4: + return kThreeProng2PiZero; + case 6: + return kThreeProng3PiZero; + default: + return kThreeProngNPiZero; + } default: - numHadrons++; + return kRareDecayMode; } } - if (numElectrons == 1) - return kElectron; - else if (numMuons == 1) - return kMuon; - switch (numHadrons) { - case 1: - switch (numPhotons) { - case 0: - return kOneProng0PiZero; - case 2: - return kOneProng1PiZero; - case 4: - return kOneProng2PiZero; - case 6: - return kOneProng3PiZero; - default: - return kOneProngNPiZero; - } - case 2: - switch (numPhotons) { - case 0: - return kTwoProng0PiZero; - case 2: - return kTwoProng1PiZero; - case 4: - return kTwoProng2PiZero; - case 6: - return kTwoProng3PiZero; - default: - return kTwoProngNPiZero; - } - case 3: - switch (numPhotons) { - case 0: - return kThreeProng0PiZero; - case 2: - return kThreeProng1PiZero; - case 4: - return kThreeProng2PiZero; - case 6: - return kThreeProng3PiZero; - default: - return kThreeProngNPiZero; - } - default: - return kRareDecayMode; - } -} - private: }; diff --git a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc index d6786c302b255..cd0379d21fdb2 100644 --- a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc +++ b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc @@ -52,10 +52,10 @@ void SimTauAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iS const auto& simTaus = *simTau_h; for (auto const& simTau : simTaus) { - #ifdef EDM_ML_DEBUG - simTau.dumpFullDecay(); - simTau.dump(); - #endif +#ifdef EDM_ML_DEBUG + simTau.dumpFullDecay(); + simTau.dump(); +#endif DM_histo->Fill(simTau.decayMode); } } From 00aeaa7c009717585849b8f4b4040da7916ba079 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Mon, 18 Dec 2023 10:46:12 +0100 Subject: [PATCH 4/7] use generic Phase-2 geometry --- SimGeneral/Debugging/python/caloParticleDebugger_cfg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py b/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py index f60c86ca5bea0..f2680c1698dec 100644 --- a/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py +++ b/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py @@ -8,7 +8,7 @@ process = cms.Process("Demo") process.load("FWCore.MessageService.MessageLogger_cfi") -process.load('Configuration.Geometry.GeometryExtended2026D96Reco_cff') +process.load('Configuration.Geometry.GeometryExtended2026Default_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '') From d1ea35a480c8b2d14151d7b49fa9164cbd00e839 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Mon, 18 Dec 2023 11:14:02 +0100 Subject: [PATCH 5/7] update Phase-2 geometry --- SimGeneral/Debugging/python/caloParticleDebugger_cfg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py b/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py index f2680c1698dec..5b90c445f23a3 100644 --- a/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py +++ b/SimGeneral/Debugging/python/caloParticleDebugger_cfg.py @@ -8,7 +8,7 @@ process = cms.Process("Demo") process.load("FWCore.MessageService.MessageLogger_cfi") -process.load('Configuration.Geometry.GeometryExtended2026Default_cff') +process.load('Configuration.Geometry.GeometryExtended2026D96_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '') From 0a4c3477dd6ac67a6ffa70120f37f8fc6b52913f Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 12 Jan 2024 13:57:00 +0100 Subject: [PATCH 6/7] review changes core --- .../plugins/SimTauCPLinkProducer.cc | 64 ++++++++----------- .../python/SimTauCPLink_cfi.py | 7 -- .../CaloAnalysis/interface/SimTauCPLink.h | 11 ++-- .../CaloAnalysis/src/classes_def.xml | 4 +- SimGeneral/Debugging/plugins/BuildFile.xml | 2 +- .../Debugging/plugins/SimTauAnalyzer.cc | 3 +- .../Debugging/test/simTauAnalyzer_cfg.py | 4 +- .../Configuration/python/hgcalSimValid_cff.py | 4 +- 8 files changed, 41 insertions(+), 58 deletions(-) delete mode 100644 SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc index 68af82bb6aa23..f3f30256b75db 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -11,8 +11,7 @@ // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" @@ -28,10 +27,7 @@ #include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" #include "SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" - -class SimTauProducer : public edm::stream::EDProducer<> { +class SimTauProducer : public edm::global::EDProducer<> { public: explicit SimTauProducer(const edm::ParameterSet&); ~SimTauProducer() override = default; @@ -39,7 +35,7 @@ class SimTauProducer : public edm::stream::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override; void buildSimTau(SimTauCPLink&, uint8_t, @@ -47,7 +43,7 @@ class SimTauProducer : public edm::stream::EDProducer<> { const reco::GenParticle&, int, edm::Handle>, - const std::vector&); + const std::vector&) const; // ----------member data --------------------------- const edm::EDGetTokenT> caloParticles_token_; const edm::EDGetTokenT> genParticles_token_; @@ -67,55 +63,49 @@ void SimTauProducer::buildSimTau(SimTauCPLink& t, const reco::GenParticle& gen_particle, int gen_particle_key, edm::Handle> calo_particle_h, - const std::vector& gen_particle_barcodes) { + const std::vector& gen_particle_barcodes) const { const auto& caloPartVec = *calo_particle_h; auto& daughters = gen_particle.daughterRefVector(); bool is_leaf = (daughters.empty()); + if (is_leaf) { - LogDebug("SimTauProducer") << " TO BE SAVED " + std::to_string(resonance_idx) + " "; + LogDebug("SimTauProducer").format(" TO BE SAVED {} ", resonance_idx); auto const& gen_particle_barcode = gen_particle_barcodes[gen_particle_key]; auto const& found_in_caloparticles = std::find_if(caloPartVec.begin(), caloPartVec.end(), [&](const auto& p) { - return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode; + return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode; }); if (found_in_caloparticles != caloPartVec.end()) { auto calo_particle_idx = (found_in_caloparticles - caloPartVec.begin()); t.calo_particle_leaves.push_back(CaloParticleRef(calo_particle_h, calo_particle_idx)); t.leaves.push_back( - {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key}); - LogDebug("SimTauProducer") << " CP " + std::to_string(calo_particle_idx) + " " << caloPartVec[calo_particle_idx]; + {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key}); + LogDebug("SimTauProducer").format(" CP {} {}", calo_particle_idx, caloPartVec[calo_particle_idx]); } else { t.leaves.push_back({gen_particle.pdgId(), resonance_idx, -1, gen_particle_key}); } return; - } else if (generation != 0) { - t.resonances.push_back({gen_particle.pdgId(), resonance_idx}); - resonance_idx = t.resonances.size() - 1; - LogDebug("SimTauProducer") << " RESONANCE/INTERMEDIATE " + std::to_string(resonance_idx) + " "; - } + } else if (generation != 0) { + t.resonances.push_back({gen_particle.pdgId(), resonance_idx}); + resonance_idx = t.resonances.size() - 1; + LogDebug("SimTauProducer").format(" RESONANCE/INTERMEDIATE {} ", resonance_idx); + } - ++generation; - for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) { - int gen_particle_key = (*daughter).key(); - LogDebug("SimTauProducer") << " gen " + std::to_string((int)generation) + " " + std::to_string(gen_particle_key) + - " " + std::to_string((*daughter)->pdgId()) + " "; - buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes); - } + ++generation; + for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) { + int gen_particle_key = (*daughter).key(); + LogDebug("SimTauProducer").format(" gen {} {} {} ", generation, gen_particle_key, (*daughter)->pdgId()); + buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes); + } + } -void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void SimTauProducer::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const { using namespace edm; - Handle> caloParticles_h; - iEvent.getByToken(caloParticles_token_, caloParticles_h); - - edm::Handle> genParticles_h; - iEvent.getByToken(genParticles_token_, genParticles_h); - - Handle> genBarcodes_h; - iEvent.getByToken(genBarcodes_token_, genBarcodes_h); - - const auto& genParticles = *genParticles_h; - const auto& genBarcodes = *genBarcodes_h; + auto caloParticles_h = iEvent.getHandle(caloParticles_token_); + const auto& genParticles = iEvent.get(genParticles_token_); + const auto& genBarcodes = iEvent.get(genBarcodes_token_); + auto tauDecayVec = std::make_unique>(); for (auto const& g : genParticles) { auto const& flags = g.statusFlags(); diff --git a/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py b/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py deleted file mode 100644 index 3596cf098d194..0000000000000 --- a/SimCalorimetry/HGCalAssociatorProducers/python/SimTauCPLink_cfi.py +++ /dev/null @@ -1,7 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -SimTauCPLink = cms.EDProducer("SimTauProducer", - caloParticles = cms.InputTag('mix', 'MergedCaloTruth'), - genParticles = cms.InputTag('genParticles'), - genBarcodes = cms.InputTag('genParticles') - ) diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h index 26a6c70f7d2c4..d9465de08bb19 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -20,6 +20,7 @@ class SimTauCPLink { int resonance_idx() const { return resonance_idx_; } int calo_particle_idx() const { return calo_particle_idx_; } int gen_particle_idx() const { return gen_particle_idx_; } + private: }; std::vector> resonances; @@ -51,20 +52,18 @@ class SimTauCPLink { void dump(void) const { for (auto const &l : leaves) { - LogDebug("SimTauProducer") << "L " + std::to_string(l.pdgId()) + " " + std::to_string(l.resonance_idx()) + - " CP: " + std::to_string(l.calo_particle_idx()) + - " GenP idx: " + std::to_string(l.gen_particle_idx()); + LogDebug("SimTauProducer").format("L {} {} CP: {} GenP idx: {}", l.pdgId(), l.resonance_idx(), l.calo_particle_idx(), l.gen_particle_idx()); } for (auto const &r : resonances) { - LogDebug("SimTauProducer") << "R " + std::to_string(r.first) + " " + std::to_string(r.second); + LogDebug("SimTauProducer").format("R {} {}", r.first, r.second); } } void dumpDecay(const std::pair &entry) const { if (entry.second == -1) { // No intermediate mother. - LogDebug("SimTauProducer") << std::to_string(entry.first) + " " + std::to_string(entry.second); + LogDebug("SimTauProducer").format("{} {}", entry.first, entry.second); } else { - LogDebug("SimTauProducer") << std::to_string(entry.first) + " " + std::to_string(entry.second) + " coming from: "; + LogDebug("SimTauProducer").format("{} {} coming from: ", entry.first, entry.second); auto const &mother = resonances[entry.second]; dumpDecay(mother); } diff --git a/SimDataFormats/CaloAnalysis/src/classes_def.xml b/SimDataFormats/CaloAnalysis/src/classes_def.xml index bd0cc0f56c392..35eca588e8cb9 100644 --- a/SimDataFormats/CaloAnalysis/src/classes_def.xml +++ b/SimDataFormats/CaloAnalysis/src/classes_def.xml @@ -52,8 +52,8 @@ - - + + diff --git a/SimGeneral/Debugging/plugins/BuildFile.xml b/SimGeneral/Debugging/plugins/BuildFile.xml index 8d604197d92a7..bb457e1eaf2b6 100644 --- a/SimGeneral/Debugging/plugins/BuildFile.xml +++ b/SimGeneral/Debugging/plugins/BuildFile.xml @@ -11,4 +11,4 @@ -\ + diff --git a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc index cd0379d21fdb2..96fbfea2c3c2a 100644 --- a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc +++ b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc @@ -26,7 +26,7 @@ #include "FWCore/ServiceRegistry/interface/Service.h" #include "CommonTools/UtilAlgos/interface/TFileService.h" -class SimTauAnalyzer : public edm::one::EDAnalyzer<> { +class SimTauAnalyzer : public edm::one::EDAnalyzer { public: explicit SimTauAnalyzer(const edm::ParameterSet&); ~SimTauAnalyzer() override = default; @@ -40,6 +40,7 @@ class SimTauAnalyzer : public edm::one::EDAnalyzer<> { SimTauAnalyzer::SimTauAnalyzer(const edm::ParameterSet& iConfig) : simTau_token_(consumes>(iConfig.getParameter("simTau"))) { + usesResource(TFileService::kSharedResource); edm::Service fs; DM_histo = fs->make("DM_histo", "DM_histo", 20, -1, 19); } diff --git a/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py index bfc8c872f381a..5625bf1bccb57 100644 --- a/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py +++ b/SimGeneral/Debugging/test/simTauAnalyzer_cfg.py @@ -11,8 +11,8 @@ ) process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring( - #'file:/data/agruber/patatrack/CMSSW_14_0_0_pre0/src/24036.0_ZTT_14TeV+2026D96/step3.root' - 'file:SimTauProducer_test.root' + 'file:/data/agruber/patatrack/CMSSW_14_0_0_pre0/src/24036.0_ZTT_14TeV+2026D96/step3.root' + #'file:SimTauProducer_test.root' ) ) diff --git a/Validation/Configuration/python/hgcalSimValid_cff.py b/Validation/Configuration/python/hgcalSimValid_cff.py index 3d39301ee6cf0..89ff13ad37371 100644 --- a/Validation/Configuration/python/hgcalSimValid_cff.py +++ b/Validation/Configuration/python/hgcalSimValid_cff.py @@ -10,7 +10,7 @@ from SimCalorimetry.HGCalAssociatorProducers.LCToCPAssociation_cfi import layerClusterCaloParticleAssociationHFNose as layerClusterCaloParticleAssociationProducerHFNose from SimCalorimetry.HGCalAssociatorProducers.LCToSCAssociation_cfi import layerClusterSimClusterAssociationHFNose as layerClusterSimClusterAssociationProducerHFNose from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import tracksterSimTracksterAssociationLinking, tracksterSimTracksterAssociationPR,tracksterSimTracksterAssociationLinkingbyCLUE3D, tracksterSimTracksterAssociationPRbyCLUE3D, tracksterSimTracksterAssociationLinkingPU, tracksterSimTracksterAssociationPRPU -from SimCalorimetry.HGCalAssociatorProducers.SimTauCPLink_cfi import * +from SimCalorimetry.HGCalAssociatorProducers.SimTauProducer_cfi import * from Validation.HGCalValidation.simhitValidation_cff import * from Validation.HGCalValidation.digiValidation_cff import * @@ -40,7 +40,7 @@ tracksterSimTracksterAssociationLinking, tracksterSimTracksterAssociationPR, tracksterSimTracksterAssociationLinkingbyCLUE3D, tracksterSimTracksterAssociationPRbyCLUE3D, tracksterSimTracksterAssociationLinkingPU, tracksterSimTracksterAssociationPRPU, - SimTauCPLink + SimTauProducer ) hgcalValidation = cms.Sequence(hgcalSimHitValidationEE From d9eb42de1ab5e02e7245417c795b186369afd92b Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 12 Jan 2024 14:57:35 +0100 Subject: [PATCH 7/7] changes core code review --- .../plugins/SimTauCPLinkProducer.cc | 31 +++++++++---------- .../CaloAnalysis/interface/SimTauCPLink.h | 7 +++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc index f3f30256b75db..356a6b49d456a 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -67,36 +67,35 @@ void SimTauProducer::buildSimTau(SimTauCPLink& t, const auto& caloPartVec = *calo_particle_h; auto& daughters = gen_particle.daughterRefVector(); bool is_leaf = (daughters.empty()); - + if (is_leaf) { LogDebug("SimTauProducer").format(" TO BE SAVED {} ", resonance_idx); auto const& gen_particle_barcode = gen_particle_barcodes[gen_particle_key]; auto const& found_in_caloparticles = std::find_if(caloPartVec.begin(), caloPartVec.end(), [&](const auto& p) { - return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode; + return p.g4Tracks()[0].genpartIndex() == gen_particle_barcode; }); if (found_in_caloparticles != caloPartVec.end()) { auto calo_particle_idx = (found_in_caloparticles - caloPartVec.begin()); t.calo_particle_leaves.push_back(CaloParticleRef(calo_particle_h, calo_particle_idx)); t.leaves.push_back( - {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key}); + {gen_particle.pdgId(), resonance_idx, (int)t.calo_particle_leaves.size() - 1, gen_particle_key}); LogDebug("SimTauProducer").format(" CP {} {}", calo_particle_idx, caloPartVec[calo_particle_idx]); } else { t.leaves.push_back({gen_particle.pdgId(), resonance_idx, -1, gen_particle_key}); } return; - } else if (generation != 0) { - t.resonances.push_back({gen_particle.pdgId(), resonance_idx}); - resonance_idx = t.resonances.size() - 1; - LogDebug("SimTauProducer").format(" RESONANCE/INTERMEDIATE {} ", resonance_idx); - } + } else if (generation != 0) { + t.resonances.push_back({gen_particle.pdgId(), resonance_idx}); + resonance_idx = t.resonances.size() - 1; + LogDebug("SimTauProducer").format(" RESONANCE/INTERMEDIATE {} ", resonance_idx); + } - ++generation; - for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) { - int gen_particle_key = (*daughter).key(); - LogDebug("SimTauProducer").format(" gen {} {} {} ", generation, gen_particle_key, (*daughter)->pdgId()); - buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes); - } - + ++generation; + for (auto daughter = daughters.begin(); daughter != daughters.end(); ++daughter) { + int gen_particle_key = (*daughter).key(); + LogDebug("SimTauProducer").format(" gen {} {} {} ", generation, gen_particle_key, (*daughter)->pdgId()); + buildSimTau(t, generation, resonance_idx, *(*daughter), gen_particle_key, calo_particle_h, gen_particle_barcodes); + } } void SimTauProducer::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const { @@ -105,7 +104,7 @@ void SimTauProducer::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup auto caloParticles_h = iEvent.getHandle(caloParticles_token_); const auto& genParticles = iEvent.get(genParticles_token_); const auto& genBarcodes = iEvent.get(genBarcodes_token_); - + auto tauDecayVec = std::make_unique>(); for (auto const& g : genParticles) { auto const& flags = g.statusFlags(); diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h index d9465de08bb19..81237ad745a7d 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -20,7 +20,8 @@ class SimTauCPLink { int resonance_idx() const { return resonance_idx_; } int calo_particle_idx() const { return calo_particle_idx_; } int gen_particle_idx() const { return gen_particle_idx_; } - private: + + private: }; std::vector> resonances; @@ -52,7 +53,9 @@ class SimTauCPLink { void dump(void) const { for (auto const &l : leaves) { - LogDebug("SimTauProducer").format("L {} {} CP: {} GenP idx: {}", l.pdgId(), l.resonance_idx(), l.calo_particle_idx(), l.gen_particle_idx()); + LogDebug("SimTauProducer") + .format( + "L {} {} CP: {} GenP idx: {}", l.pdgId(), l.resonance_idx(), l.calo_particle_idx(), l.gen_particle_idx()); } for (auto const &r : resonances) { LogDebug("SimTauProducer").format("R {} {}", r.first, r.second);