Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters for initial state partons #573

Merged
merged 1 commit into from
Sep 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions GeneratorInterface/GenFilters/interface/MCPdgIndexFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef MCPdgIndexFilter_h
#define MCPdgIndexFilter_h
/*
Description: filter events based on the particle PDG ID at a given
index in the HepMC::GenEvent record.

Original Author: Burt Betchart, 2013/08/09
*/

#include <memory>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"


class MCPdgIndexFilter : public edm::EDFilter {
public:
explicit MCPdgIndexFilter(const edm::ParameterSet&);
~MCPdgIndexFilter() {};

virtual bool filter(edm::Event&, const edm::EventSetup&);
private:
bool pass(const edm::Event&);
const std::string label_;
const std::vector<int> pdgID;
const std::vector<unsigned> index;
const unsigned maxIndex;
const bool taggingMode;
const std::string tag;
};
#endif
52 changes: 52 additions & 0 deletions GeneratorInterface/GenFilters/src/MCPdgIndexFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "GeneratorInterface/GenFilters/interface/MCPdgIndexFilter.h"
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

MCPdgIndexFilter::MCPdgIndexFilter(const edm::ParameterSet& cfg) :
label_(cfg.getUntrackedParameter("moduleLabel",std::string("generator"))),
pdgID(cfg.getParameter<std::vector<int> >("PdgId")),
index(cfg.getParameter<std::vector<unsigned> >("Index")),
maxIndex(*std::max_element(index.begin(),index.end())),
taggingMode(cfg.getUntrackedParameter<bool>("TagMode",false)),
tag(cfg.getUntrackedParameter<std::string>("Tag",""))
{
if (pdgID.size() != index.size())
edm::LogWarning("MCPdgIndexFilter")
<< "Configuration Error :"
<< "Sizes of array parameters 'PdgId' and 'Index' differ.";

if (taggingMode) {
produces<bool>(tag);
edm::LogInfo("TagMode") << "Filter result in '" << tag << "', filtering disabled.";
}
}


bool MCPdgIndexFilter::filter(edm::Event& evt, const edm::EventSetup&) {
bool result = pass(evt);
LogDebug("FilterResult") << (result?"Pass":"Fail");
if (!taggingMode) return result;
evt.put( std::auto_ptr<bool>(new bool(result)), tag);
return true;
}


bool MCPdgIndexFilter::pass(const edm::Event& evt) {
edm::Handle<edm::HepMCProduct> hepmc;
evt.getByLabel(label_, hepmc);

const HepMC::GenEvent * genEvent = hepmc->GetEvent();

HepMC::GenEvent::particle_const_iterator
p(genEvent->particles_begin()),
p_end(genEvent->particles_end());

for ( unsigned i=0; p!=p_end && i<=maxIndex; ++p, i++ ) {
LogDebug("Particle") << "index: " << i << " pdgID: " << (*p)->pdg_id();
for (unsigned j = 0; j < pdgID.size(); j++) {
if (i==index[j] && pdgID[j] != (*p)->pdg_id())
return false;
}
}
return true;
}
2 changes: 2 additions & 0 deletions GeneratorInterface/GenFilters/src/SealModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "GeneratorInterface/GenFilters/interface/MCDijetResonance.h"
#include "GeneratorInterface/GenFilters/interface/MCProcessFilter.h"
#include "GeneratorInterface/GenFilters/interface/MCProcessRangeFilter.h"
#include "GeneratorInterface/GenFilters/interface/MCPdgIndexFilter.h"
#include "GeneratorInterface/GenFilters/interface/MCSingleParticleFilter.h"
#include "GeneratorInterface/GenFilters/interface/MCSmartSingleParticleFilter.h"
#include "GeneratorInterface/GenFilters/interface/MCZll.h"
Expand Down Expand Up @@ -59,6 +60,7 @@
DEFINE_FWK_MODULE(MCDijetResonance);
DEFINE_FWK_MODULE(MCProcessFilter);
DEFINE_FWK_MODULE(MCProcessRangeFilter);
DEFINE_FWK_MODULE(MCPdgIndexFilter);
DEFINE_FWK_MODULE(MCSingleParticleFilter);
DEFINE_FWK_MODULE(MCSmartSingleParticleFilter);
DEFINE_FWK_MODULE(MCZll);
Expand Down