Skip to content

Commit

Permalink
Fix code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
alintulu committed Dec 19, 2022
1 parent 8e347bc commit d187b69
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 403 deletions.
8 changes: 4 additions & 4 deletions CommonTools/RecoAlgos/plugins/JetDeltaRValueMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
multiValue_(false) {
if (!value_.empty()) {
if (value_ != "index") {
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
}
produces<JetValueMap>();
}
Expand Down Expand Up @@ -117,9 +117,9 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
jets1_locks.at(matched_index) = true;
if (!value_.empty()) {
if (value_ == "index") {
values.at(matched_index) = iindex;
values.at(matched_index) = iindex;
} else {
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
}
}
if (multiValue_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class Run3ScoutingParticleToRecoPFCandidateProducer : public edm::stream::EDProd

static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
void beginStream(edm::StreamID) override {}
void produce(edm::Event & iEvent, edm::EventSetup const & setup) override;
void produce(edm::Event &iEvent, edm::EventSetup const &setup) override;
void endStream() override {}

void createPFCandidates(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle, std::unique_ptr<reco::PFCandidateCollection> & pfcands);
void createPFCandidatesSK(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle, std::unique_ptr<reco::PFCandidateCollection> & pfcands);
void createPFCandidates(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle,
std::unique_ptr<reco::PFCandidateCollection> &pfcands);
void createPFCandidatesSK(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle,
std::unique_ptr<reco::PFCandidateCollection> &pfcands);
reco::PFCandidate createPFCand(Run3ScoutingParticle scoutingparticle);
void clearVars();

Expand All @@ -36,7 +38,7 @@ class Run3ScoutingParticleToRecoPFCandidateProducer : public edm::stream::EDProd
const edm::ESGetToken<HepPDT::ParticleDataTable, edm::DefaultRecord> particletable_token_;
bool use_softKiller_;
bool use_CHS_;
const HepPDT::ParticleDataTable* pdTable_;
const HepPDT::ParticleDataTable *pdTable_;

std::vector<int8_t> vertexIndex_;
std::vector<float> normchi2_;
Expand All @@ -54,12 +56,12 @@ class Run3ScoutingParticleToRecoPFCandidateProducer : public edm::stream::EDProd
//
// constructors and destructor
//
Run3ScoutingParticleToRecoPFCandidateProducer::Run3ScoutingParticleToRecoPFCandidateProducer(const edm::ParameterSet &iConfig)
Run3ScoutingParticleToRecoPFCandidateProducer::Run3ScoutingParticleToRecoPFCandidateProducer(
const edm::ParameterSet &iConfig)
: input_scoutingparticle_token_(consumes(iConfig.getParameter<edm::InputTag>("scoutingparticle"))),
particletable_token_(esConsumes<HepPDT::ParticleDataTable, edm::DefaultRecord>()),
use_softKiller_(iConfig.getParameter<bool>("softKiller")),
use_CHS_(iConfig.getParameter<bool>("CHS")) {

//register products
produces<reco::PFCandidateCollection>();
produces<edm::ValueMap<int>>("vertexIndex");
Expand All @@ -79,25 +81,25 @@ Run3ScoutingParticleToRecoPFCandidateProducer::~Run3ScoutingParticleToRecoPFCand

reco::PFCandidate Run3ScoutingParticleToRecoPFCandidateProducer::createPFCand(Run3ScoutingParticle scoutingparticle) {
auto m = pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId())) != nullptr
? pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId()))->mass()
: -99.f;
? pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId()))->mass()
: -99.f;
auto q = pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId())) != nullptr
? pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId()))->charge()
: -99.f;
? pdTable_->particle(HepPDT::ParticleID(scoutingparticle.pdgId()))->charge()
: -99.f;
if (m < -90 or q < -90) {
LogDebug("createPFCand") << "<Run3ScoutingParticleToRecoPFCandidateProducer::createPFCand>:" << std::endl
<< "Unrecognisable pdgId - skipping particle" << std::endl;
return reco::PFCandidate();
LogDebug("createPFCand") << "<Run3ScoutingParticleToRecoPFCandidateProducer::createPFCand>:" << std::endl
<< "Unrecognisable pdgId - skipping particle" << std::endl;
return reco::PFCandidate();
}

float px = scoutingparticle.pt() * cos(scoutingparticle.phi());
float py = scoutingparticle.pt() * sin(scoutingparticle.phi());
float pz = scoutingparticle.pt() * sinh(scoutingparticle.eta());
float p = scoutingparticle.pt() * cosh(scoutingparticle.eta());
float energy = std::sqrt(p*p + m*m);
reco::Particle::LorentzVector p4(px, py, pz, energy);
float energy = std::sqrt(p * p + m * m);
reco::Particle::LorentzVector p4(px, py, pz, energy);

static const reco::PFCandidate dummy;
static const reco::PFCandidate dummy;
auto pfcand = reco::PFCandidate(q, p4, dummy.translatePdgIdToType(scoutingparticle.pdgId()));

bool relativeTrackVars = scoutingparticle.relative_trk_vars();
Expand All @@ -110,53 +112,66 @@ reco::PFCandidate Run3ScoutingParticleToRecoPFCandidateProducer::createPFCand(Ru
lostInnerHits_.push_back(scoutingparticle.lostInnerHits());
quality_.push_back(scoutingparticle.quality());
trkPt_.push_back(relativeTrackVars ? scoutingparticle.trk_pt() + scoutingparticle.pt() : scoutingparticle.trk_pt());
trkEta_.push_back(relativeTrackVars ? scoutingparticle.trk_eta() + scoutingparticle.eta() : scoutingparticle.trk_eta());
trkPhi_.push_back(relativeTrackVars ? scoutingparticle.trk_phi() + scoutingparticle.phi() : scoutingparticle.trk_phi());
trkEta_.push_back(relativeTrackVars ? scoutingparticle.trk_eta() + scoutingparticle.eta()
: scoutingparticle.trk_eta());
trkPhi_.push_back(relativeTrackVars ? scoutingparticle.trk_phi() + scoutingparticle.phi()
: scoutingparticle.trk_phi());

return pfcand;
return pfcand;
}

void Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidates(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle, std::unique_ptr<reco::PFCandidateCollection> & pfcands) {
void Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidates(
edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle,
std::unique_ptr<reco::PFCandidateCollection> &pfcands) {
for (unsigned int icand = 0; icand < scoutingparticleHandle->size(); ++icand) {
auto &scoutingparticle = (*scoutingparticleHandle)[icand];

auto& scoutingparticle = (*scoutingparticleHandle)[icand];
if (use_CHS_ and scoutingparticle.vertex() != 0)
continue;

if (use_CHS_ and scoutingparticle.vertex() != 0) continue;

auto pfcand = createPFCand(scoutingparticle);
if (pfcand.energy() != 0) pfcands->push_back(pfcand);
auto pfcand = createPFCand(scoutingparticle);
if (pfcand.energy() != 0)
pfcands->push_back(pfcand);
}
}

void Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidatesSK(edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle, std::unique_ptr<reco::PFCandidateCollection> & pfcands) {
void Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidatesSK(
edm::Handle<std::vector<Run3ScoutingParticle>> scoutingparticleHandle,
std::unique_ptr<reco::PFCandidateCollection> &pfcands) {
std::vector<fastjet::PseudoJet> fj;

for (auto iter = scoutingparticleHandle->begin(), ibegin = scoutingparticleHandle->begin(), iend = scoutingparticleHandle->end(); iter != iend; ++iter) {
for (auto iter = scoutingparticleHandle->begin(),
ibegin = scoutingparticleHandle->begin(),
iend = scoutingparticleHandle->end();
iter != iend;
++iter) {
auto m = pdTable_->particle(HepPDT::ParticleID(iter->pdgId())) != nullptr
? pdTable_->particle(HepPDT::ParticleID(iter->pdgId()))->mass()
: -99.f;
? pdTable_->particle(HepPDT::ParticleID(iter->pdgId()))->mass()
: -99.f;
if (m < -90) {
LogDebug("createPFCandidatesSK") << "<Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidatesSK>:" << std::endl
<< "Unrecognisable pdgId - skipping particle" << std::endl;
continue;
LogDebug("createPFCandidatesSK") << "<Run3ScoutingParticleToRecoPFCandidateProducer::createPFCandidatesSK>:"
<< std::endl
<< "Unrecognisable pdgId - skipping particle" << std::endl;
continue;
}
math::PtEtaPhiMLorentzVector p4(iter->pt(), iter->eta(), iter->phi(), m);
fj.push_back(fastjet::PseudoJet(p4.px(), p4.py(), p4.pz(), p4.energy()));
fj.back().set_user_index(iter - ibegin);
}
}

fastjet::contrib::SoftKiller soft_killer(5, 0.4);
std::vector<fastjet::PseudoJet> soft_killed_particles = soft_killer(fj);

for (auto &particle : soft_killed_particles) {
const Run3ScoutingParticle scoutingparticle = scoutingparticleHandle->at(particle.user_index());
auto pfcand = createPFCand(scoutingparticle);
if (pfcand.energy() != 0) pfcands->push_back(pfcand);
if (pfcand.energy() != 0)
pfcands->push_back(pfcand);
}
}

// ------------ method called to produce the data ------------
void Run3ScoutingParticleToRecoPFCandidateProducer::produce(edm::Event & iEvent, edm::EventSetup const & setup) {
void Run3ScoutingParticleToRecoPFCandidateProducer::produce(edm::Event &iEvent, edm::EventSetup const &setup) {
using namespace edm;

auto pdt = setup.getHandle(particletable_token_);
Expand All @@ -168,19 +183,19 @@ void Run3ScoutingParticleToRecoPFCandidateProducer::produce(edm::Event & iEvent,
auto pfcands = std::make_unique<reco::PFCandidateCollection>();

if (use_softKiller_) {
createPFCandidatesSK(scoutingparticleHandle, pfcands);
createPFCandidatesSK(scoutingparticleHandle, pfcands);
} else {
createPFCandidates(scoutingparticleHandle, pfcands);
createPFCandidates(scoutingparticleHandle, pfcands);
}

edm::OrphanHandle<reco::PFCandidateCollection> oh = iEvent.put(std::move(pfcands));

std::unique_ptr<edm::ValueMap<int>> vertexIndex_VM(new edm::ValueMap<int>());
edm::ValueMap<int>::Filler filler_vertexIndex(*vertexIndex_VM);
filler_vertexIndex.insert(oh, vertexIndex_.begin(), vertexIndex_.end());
filler_vertexIndex.fill();
iEvent.put(std::move(vertexIndex_VM), "vertexIndex");

std::unique_ptr<edm::ValueMap<float>> normchi2_VM(new edm::ValueMap<float>());
edm::ValueMap<float>::Filler filler_normchi2(*normchi2_VM);
filler_normchi2.insert(oh, normchi2_.begin(), normchi2_.end());
Expand Down Expand Up @@ -244,7 +259,7 @@ void Run3ScoutingParticleToRecoPFCandidateProducer::produce(edm::Event & iEvent,
clearVars();
}

void Run3ScoutingParticleToRecoPFCandidateProducer::clearVars() {
void Run3ScoutingParticleToRecoPFCandidateProducer::clearVars() {
vertexIndex_.clear();
normchi2_.clear();
dz_.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);

11 changes: 8 additions & 3 deletions PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void TriggerOutputBranches::updateTriggerNames(TTree& tree,
for (unsigned int j = 0; j < newNames.size(); j++) {
std::string name = newNames[j]; // no const & as it will be modified below!
std::size_t vfound = name.rfind("_v");
if (vfound != std::string::npos && ((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 2, "L1") == 0 || (m_isPFScouting && name.find("PFScouting") != std::string::npos))) {
if (vfound != std::string::npos &&
((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 2, "L1") == 0 ||
(m_isPFScouting && name.find("PFScouting") != std::string::npos))) {
name.replace(vfound, name.size() - vfound, "");
}
if (name == existing.name)
Expand All @@ -32,11 +34,14 @@ void TriggerOutputBranches::updateTriggerNames(TTree& tree,
for (unsigned int j = 0; j < newNames.size(); j++) {
std::string name = newNames[j]; // no const & as it will be modified below!
std::size_t vfound = name.rfind("_v");
if (vfound != std::string::npos && ((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 2, "L1") == 0 || (m_isPFScouting && name.find("PFScouting") != std::string::npos))) {
if (vfound != std::string::npos &&
((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 2, "L1") == 0 ||
(m_isPFScouting && name.find("PFScouting") != std::string::npos))) {
name.replace(vfound, name.size() - vfound, "");
}
bool found = false;
if ((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 4, "Flag") == 0 || name.compare(0, 2, "L1") == 0 || (m_isPFScouting && name.find("PFScouting") != std::string::npos)) {
if ((name.compare(0, 3, "HLT") == 0 && !(m_isPFScouting)) || name.compare(0, 4, "Flag") == 0 ||
name.compare(0, 2, "L1") == 0 || (m_isPFScouting && name.find("PFScouting") != std::string::npos)) {
for (auto& existing : m_triggerBranches) {
if (name == existing.name)
found = true;
Expand Down
Loading

0 comments on commit d187b69

Please sign in to comment.