Skip to content

Commit

Permalink
applying code-checks and code-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
agrubercms committed Dec 1, 2023
1 parent 57d8405 commit 3760111
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<CaloParticle>>, const std::vector<int> &);

void buildSimTau(SimTauCPLink&,
uint8_t,
int,
const reco::GenParticle&,
int,
edm::Handle<std::vector<CaloParticle>>,
const std::vector<int>&);
int buildDecayModes(const SimTauCPLink&);
// ----------member data ---------------------------
const edm::EDGetTokenT<std::vector<CaloParticle>> caloParticle_token_;
Expand All @@ -53,55 +57,53 @@ class SimTauProducer : public edm::stream::EDProducer<> {

SimTauProducer::SimTauProducer(const edm::ParameterSet& iConfig)
: caloParticle_token_(consumes<std::vector<CaloParticle>>(iConfig.getParameter<edm::InputTag>("CaloParticle"))),
genParticles_token_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("GenParticles"))),
genBarcodes_token_(consumes<std::vector<int>>(iConfig.getParameter<edm::InputTag>("GenBarcodes"))) {
genParticles_token_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("GenParticles"))),
genBarcodes_token_(consumes<std::vector<int>>(iConfig.getParameter<edm::InputTag>("GenBarcodes"))) {
produces<std::vector<SimTauCPLink>>();
}


void SimTauProducer::buildSimTau(SimTauCPLink &t,
uint8_t generation,
int resonance_idx,
const reco::GenParticle & gen_particle,
int gen_particle_key,
edm::Handle<std::vector<CaloParticle>> calo_particle_h,
const std::vector<int> & 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<std::vector<CaloParticle>> calo_particle_h,
const std::vector<int>& 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,
Expand All @@ -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:
Expand All @@ -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;
Expand All @@ -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<std::vector<SimTauCPLink>>();
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);
Expand All @@ -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
Expand Down
53 changes: 26 additions & 27 deletions SimDataFormats/CaloAnalysis/interface/SimTauCPLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<int, int>> resonances;
Expand Down Expand Up @@ -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<int, int> & 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<int, int> &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
16 changes: 7 additions & 9 deletions SimGeneral/Debugging/plugins/SimTauAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<SimTauCPLink>> simTau_token_;
TH1D *DM_histo;
TH1D* DM_histo;
};

SimTauAnalyzer::SimTauAnalyzer(const edm::ParameterSet& iConfig)
: simTau_token_(consumes<std::vector<SimTauCPLink>>(iConfig.getParameter<edm::InputTag>("simTau"))) {
edm::Service<TFileService> fs;
DM_histo = fs->make<TH1D>("DM_histo", "DM_histo", 20, -1, 19);
}
: simTau_token_(consumes<std::vector<SimTauCPLink>>(iConfig.getParameter<edm::InputTag>("simTau"))) {
edm::Service<TFileService> fs;
DM_histo = fs->make<TH1D>("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<std::vector<SimTauCPLink>> 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);
Expand Down

0 comments on commit 3760111

Please sign in to comment.