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

add lhe generic filter #10817

Merged
merged 2 commits into from Aug 19, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions GeneratorInterface/GenFilters/interface/LHEGenericFilter.h
@@ -0,0 +1,58 @@
#ifndef LHEGenericFilter_h
#define LHEGenericFilter_h
// -*- C++ -*-
//
// Package: LHEGenericFilter
// Class: LHEGenericFilter
//
/*

Description: Filter to select events with an arbitrary number of given particle(s).

Implementation: derived from MCSingleParticleFilter

*/
//
// Original Author: Roberto Covarelli
// Created: Wed Feb 29 04:22:16 CST 2012
//
//

// system include files
#include <memory>
#include <iostream>

// user include files
#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"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"

//
// class declaration
//

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

private:
virtual bool filter(edm::Event&, const edm::EventSetup&);
virtual void endJob();

// ----------member data ---------------------------

edm::EDGetTokenT<LHEEventProduct> src_;
int numRequired_; // number of particles required to pass filter
bool acceptMore_; // if true (default), accept numRequired or more.
// if false, accept events with exactly equal to numRequired.
std::vector<int> particleID_; // vector of particle IDs to look for
int totalEvents_; // counters
int passedEvents_;
};
#endif
62 changes: 62 additions & 0 deletions GeneratorInterface/GenFilters/src/LHEGenericFilter.cc
@@ -0,0 +1,62 @@
#include "GeneratorInterface/GenFilters/interface/LHEGenericFilter.h"

LHEGenericFilter::LHEGenericFilter(const edm::ParameterSet& iConfig) :
numRequired_(iConfig.getParameter<int>("NumRequired")),
acceptMore_(iConfig.getParameter<bool>("AcceptMore")),
particleID_(iConfig.getParameter< std::vector<int> >("ParticleID")),
totalEvents_(0), passedEvents_(0)
{
//here do whatever other initialization is needed
src_ = consumes<LHEEventProduct>(iConfig.getParameter<edm::InputTag>("src"));
}

LHEGenericFilter::~LHEGenericFilter()
{

// do anything here that needs to be done at destruction time
// (e.g. close files, deallocate resources etc.)

}


// ------------ method called to skim the data ------------
bool LHEGenericFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
edm::Handle< LHEEventProduct > EvtHandle ;
iEvent.getByToken( src_ , EvtHandle ) ;

totalEvents_++;
int nFound = 0;

for (int i = 0; i < EvtHandle->hepeup().NUP; ++i) {
if (EvtHandle->hepeup().ISTUP[i] != 1) {
continue;
}
for (unsigned int j = 0; j < particleID_.size(); ++j) {
if (particleID_[j] == 0 || abs(particleID_[j]) == abs(EvtHandle->hepeup().IDUP[i]) ) {
nFound++;
break; // only match a given particle once!
}
} // loop over targets

if (acceptMore_ && nFound == numRequired_) break; // stop looking if we don't mind having more
} // loop over particles

if (nFound == numRequired_) {
passedEvents_++;
return true;
} else {
return false;
}

}

// ------------ method called once each job just after ending the event loop ------------
void LHEGenericFilter::endJob() {
edm::LogInfo("LHEGenericFilter") << "=== Results of LHEGenericFilter: passed "
<< passedEvents_ << "/" << totalEvents_ << " events" << std::endl;
}

//define this as a plug-in
DEFINE_FWK_MODULE(LHEGenericFilter);