From 3760111fd66a8e66b37b27e9b6af765b9bf28293 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 1 Dec 2023 11:46:49 +0100 Subject: [PATCH] applying code-checks and code-format changes --- .../plugins/SimTauCPLinkProducer.cc | 162 +++++++++--------- .../CaloAnalysis/interface/SimTauCPLink.h | 53 +++--- .../Debugging/plugins/SimTauAnalyzer.cc | 16 +- 3 files changed, 114 insertions(+), 117 deletions(-) diff --git a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc index 3823d4c04c25e..6673392510594 100644 --- a/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc +++ b/SimCalorimetry/HGCalAssociatorProducers/plugins/SimTauCPLinkProducer.cc @@ -33,17 +33,21 @@ class SimTauProducer : public edm::stream::EDProducer<> { public: - explicit SimTauProducer(const edm::ParameterSet&); - ~SimTauProducer() = default; + ~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 &); + + 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_; @@ -53,55 +57,53 @@ class SimTauProducer : public edm::stream::EDProducer<> { SimTauProducer::SimTauProducer(const edm::ParameterSet& iConfig) : caloParticle_token_(consumes>(iConfig.getParameter("CaloParticle"))), - genParticles_token_(consumes(iConfig.getParameter("GenParticles"))), - genBarcodes_token_(consumes>(iConfig.getParameter("GenBarcodes"))) { + 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) { +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.size() == 0); + 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;} - ); + 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}); + 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}); + t.leaves.push_back({gen_particle.pdgId(), resonance_idx, -1, gen_particle_key}); } return; - } else if (generation !=0) { + } 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) + " "; + 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()) + " "; + 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) { +int SimTauProducer::buildDecayModes(const SimTauCPLink& t) { enum decayModes { kNull = -1, kOneProng0PiZero, @@ -128,8 +130,8 @@ int SimTauProducer::buildDecayModes(const SimTauCPLink &t) { int numMuons = 0; int numHadrons = 0; int numPhotons = 0; - auto &leaves = t.leaves; - for (auto leaf: leaves) { + auto& leaves = t.leaves; + for (auto leaf : leaves) { int pdg_id = abs(leaf.pdgId()); switch (pdg_id) { case 22: @@ -143,61 +145,60 @@ int SimTauProducer::buildDecayModes(const SimTauCPLink &t) { break; case 16: break; - default: + 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; -} + 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; @@ -214,8 +215,8 @@ void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) 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(); + 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); @@ -228,7 +229,6 @@ void SimTauProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) 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 diff --git a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h index 7de6f871a897a..45aeddab20305 100644 --- a/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h +++ b/SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h @@ -7,22 +7,19 @@ #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_; } +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; @@ -53,31 +50,33 @@ 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()); + 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); + 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); + 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: "; + 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) { + for (auto const &leaf : leaves) { dumpDecay({leaf.pdgId(), leaf.resonance_idx()}); } } - private: -}; -#endif //SimTauCPLink +private: +}; +#endif //SimTauCPLink diff --git a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc index 8beef708d4e7c..878470cc09a0a 100644 --- a/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc +++ b/SimGeneral/Debugging/plugins/SimTauAnalyzer.cc @@ -28,32 +28,30 @@ class SimTauAnalyzer : public edm::one::EDAnalyzer<> { public: - explicit SimTauAnalyzer(const edm::ParameterSet&); - ~SimTauAnalyzer() = default; + ~SimTauAnalyzer() override = default; private: void analyze(const edm::Event&, const edm::EventSetup&) override; const edm::EDGetTokenT> simTau_token_; - TH1D *DM_histo; + 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); - } + : 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) { + for (auto const& simTau : simTaus) { simTau.dumpFullDecay(); simTau.dump(); DM_histo->Fill(simTau.decayMode);