Skip to content

Commit

Permalink
Modernize TtDecayChannelFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Jan 13, 2022
1 parent 801d592 commit 002c1f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
17 changes: 6 additions & 11 deletions TopQuarkAnalysis/TopSkimming/interface/TopDecayChannelFilter.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "AnalysisDataFormats/TopObjects/interface/TtGenEvent.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"

template <typename S>
class TopDecayChannelFilter : public edm::EDFilter {
class TopDecayChannelFilter : public edm::stream::EDFilter<> {
public:
TopDecayChannelFilter(const edm::ParameterSet&);
~TopDecayChannelFilter() override;

private:
bool filter(edm::Event&, const edm::EventSetup&) override;
Expand All @@ -30,26 +29,22 @@ TopDecayChannelFilter<S>::TopDecayChannelFilter(const edm::ParameterSet& cfg)
checkedSrcType_(false),
useTtGenEvent_(false) {}

template <typename S>
TopDecayChannelFilter<S>::~TopDecayChannelFilter() {}

template <typename S>
bool TopDecayChannelFilter<S>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<reco::GenParticleCollection> parts;
edm::Handle<TtGenEvent> genEvt;

if (!checkedSrcType_) {
checkedSrcType_ = true;
if (iEvent.getByToken(genEvt_, genEvt)) {
if (genEvt = iEvent.getHandle(genEvt_); genEvt.isValid()) {
useTtGenEvent_ = true;
return sel_(genEvt->particles(), src_.label());
}
} else {
if (useTtGenEvent_) {
iEvent.getByToken(genEvt_, genEvt);
genEvt = iEvent.getHandle(genEvt_);
return sel_(genEvt->particles(), src_.label());
}
}
iEvent.getByToken(parts_, parts);
return sel_(*parts, src_.label());
const auto& parts = iEvent.get(parts_);
return sel_(parts, src_.label());
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vector>
#include <cstring>
#include <iostream>
#include <string_view>

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
Expand All @@ -14,20 +15,18 @@ class TtDecayChannelSelector {

/// std contructor
TtDecayChannelSelector(const edm::ParameterSet&);
/// default destructor
~TtDecayChannelSelector();
/// operator for decay channel selection
bool operator()(const reco::GenParticleCollection& parts, std::string inputType) const;
bool operator()(const reco::GenParticleCollection& parts, std::string_view inputType) const;

private:
/// return decay channel to select for from configuration
unsigned int decayChannel() const;
// return the check sum of all entries
unsigned int checkSum(const Decay& vec) const;
/// search for particle with pdgId in given listing (for top)
bool search(reco::GenParticleCollection::const_iterator& part, int pdgId, std::string& inputType) const;
bool search(reco::GenParticleCollection::const_iterator& part, int pdgId, std::string_view inputType) const;
/// search for particle with pdgId in given listing (for top daughters)
bool search(reco::GenParticle::const_iterator& part, int pdgId, std::string& inputType) const;
bool search(reco::GenParticle::const_iterator& part, int pdgId, std::string_view inputType) const;
/// check tau decay to be leptonic, 1-prong or 3-prong
bool tauDecay(const reco::Candidate&) const;
/// count the number of charged particles for tau decays
Expand Down
10 changes: 5 additions & 5 deletions TopQuarkAnalysis/TopSkimming/src/TtDecayChannelSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ TtDecayChannelSelector::TtDecayChannelSelector(const edm::ParameterSet& cfg)
}
}

TtDecayChannelSelector::~TtDecayChannelSelector() {}

bool TtDecayChannelSelector::operator()(const reco::GenParticleCollection& parts, std::string inputType) const {
bool TtDecayChannelSelector::operator()(const reco::GenParticleCollection& parts, std::string_view inputType) const {
bool verbose =
false; // set this to true for debugging and add TtDecayChannelSelector category to the MessageLogger in your cfg file
unsigned int iLep = 0;
Expand Down Expand Up @@ -167,15 +165,17 @@ bool TtDecayChannelSelector::operator()(const reco::GenParticleCollection& parts

bool TtDecayChannelSelector::search(reco::GenParticleCollection::const_iterator& part,
int pdgId,
std::string& inputType) const {
std::string_view inputType) const {
if (inputType == kGenParticles) {
return (std::abs(part->pdgId()) == pdgId && part->status() == TopDecayID::unfrag) ? true : false;
} else {
return (std::abs(part->pdgId()) == pdgId) ? true : false;
}
}

bool TtDecayChannelSelector::search(reco::GenParticle::const_iterator& part, int pdgId, std::string& inputType) const {
bool TtDecayChannelSelector::search(reco::GenParticle::const_iterator& part,
int pdgId,
std::string_view inputType) const {
if (inputType == kGenParticles) {
return (std::abs(part->pdgId()) == pdgId && part->status() == TopDecayID::unfrag) ? true : false;
} else {
Expand Down

0 comments on commit 002c1f2

Please sign in to comment.