Skip to content

Commit

Permalink
Merge pull request #12645 from richard-cms/HIN-MC-PhotonFilters_71X
Browse files Browse the repository at this point in the history
Add new GenFilter for use by HI photon team (71X)
  • Loading branch information
cmsbuild committed Dec 3, 2015
2 parents 6b2a6ec + 43ff961 commit 7fc42ea
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 0 deletions.
54 changes: 54 additions & 0 deletions GeneratorInterface/GenFilters/interface/PythiaFilterMultiMother.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef PYTHIAFILTERMULTIMOTHER_h
#define PYTHIAFILTERMULTIMOTHER_h


// system include files
#include <memory>

// 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"


//
// class decleration
//
namespace edm {
class HepMCProduct;
}

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


virtual bool filter(edm::Event&, const edm::EventSetup&);
private:
// ----------member data ---------------------------

edm::EDGetTokenT<edm::HepMCProduct> token_;
int particleID;
double minpcut;
double maxpcut;
double minptcut;
double maxptcut;
double minetacut;
double maxetacut;
double minrapcut;
double maxrapcut;
double minphicut;
double maxphicut;

double rapidity;

int status;
std::vector<int> motherIDs;
int processID;
};
#endif
124 changes: 124 additions & 0 deletions GeneratorInterface/GenFilters/src/PythiaFilterMultiMother.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

#include "GeneratorInterface/GenFilters/interface/PythiaFilterMultiMother.h"

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include <iostream>

using namespace edm;
using namespace std;


PythiaFilterMultiMother::PythiaFilterMultiMother(const edm::ParameterSet& iConfig) :
token_(consumes<edm::HepMCProduct>(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")))),
particleID(iConfig.getUntrackedParameter("ParticleID", 0)),
minpcut(iConfig.getUntrackedParameter("MinP", 0.)),
maxpcut(iConfig.getUntrackedParameter("MaxP", 10000.)),
minptcut(iConfig.getUntrackedParameter("MinPt", 0.)),
maxptcut(iConfig.getUntrackedParameter("MaxPt", 10000.)),
minetacut(iConfig.getUntrackedParameter("MinEta", -10.)),
maxetacut(iConfig.getUntrackedParameter("MaxEta", 10.)),
minrapcut(iConfig.getUntrackedParameter("MinRapidity", -20.)),
maxrapcut(iConfig.getUntrackedParameter("MaxRapidity", 20.)),
minphicut(iConfig.getUntrackedParameter("MinPhi", -3.5)),
maxphicut(iConfig.getUntrackedParameter("MaxPhi", 3.5)),
status(iConfig.getUntrackedParameter("Status", 0)),
motherIDs(iConfig.getUntrackedParameter("MotherIDs", std::vector<int>{0})),
processID(iConfig.getUntrackedParameter("ProcessID", 0))
{
//now do what ever initialization is needed

}


PythiaFilterMultiMother::~PythiaFilterMultiMother()
{

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

}


//
// member functions
//

// ------------ method called to produce the data ------------
bool PythiaFilterMultiMother::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;
bool accepted = false;
Handle<HepMCProduct> evt;
iEvent.getByToken(token_, evt);

const HepMC::GenEvent * myGenEvent = evt->GetEvent();

if(processID == 0 || processID == myGenEvent->signal_process_id()) {

for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
p != myGenEvent->particles_end(); ++p ) {

rapidity = 0.5*log( ((*p)->momentum().e()+(*p)->momentum().pz()) / ((*p)->momentum().e()-(*p)->momentum().pz()) );

if ( abs((*p)->pdg_id()) == particleID
&& (*p)->momentum().rho() > minpcut
&& (*p)->momentum().rho() < maxpcut
&& (*p)->momentum().perp() > minptcut
&& (*p)->momentum().perp() < maxptcut
&& (*p)->momentum().eta() > minetacut
&& (*p)->momentum().eta() < maxetacut
&& rapidity > minrapcut
&& rapidity < maxrapcut
&& (*p)->momentum().phi() > minphicut
&& (*p)->momentum().phi() < maxphicut ) {


for(std::vector<int>::const_iterator motherID = motherIDs.begin(); motherID != motherIDs.end(); ++motherID) {
if (status == 0 && *motherID == 0){
accepted = true;
}
if (status != 0 && *motherID == 0){
if ((*p)->status() == status)
accepted = true;
}

HepMC::GenParticle* mother = (*((*p)->production_vertex()->particles_in_const_begin()));

if (status == 0 && *motherID != 0){
if (abs(mother->pdg_id()) == abs(*motherID)) {
accepted = true;
}
}
if (status != 0 && *motherID != 0){

if ((*p)->status() == status && abs(mother->pdg_id()) == abs(*motherID)){
accepted = true;

}
}
}

/*
if (status == 0 && motherID != 0){
if (abs(((*p)->mother())->pdg_id()) == abs(motherID)) {
accepted = true;
}
}
if (status != 0 && motherID != 0){
if ((*p)->status() == status && abs(((*p)->mother())->pdg_id()) == abs(motherID)){
accepted = true;
}
}
*/

}
}

} else { accepted = true; }

if (accepted){
return true; } else {return false;}

}
2 changes: 2 additions & 0 deletions GeneratorInterface/GenFilters/src/SealModule.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "FWCore/Framework/interface/InputSourceMacros.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "GeneratorInterface/GenFilters/interface/PythiaFilter.h"
#include "GeneratorInterface/GenFilters/interface/PythiaFilterMultiMother.h"
#include "GeneratorInterface/GenFilters/interface/PythiaDauFilter.h"
#include "GeneratorInterface/GenFilters/interface/PythiaFilterGammaJet.h"
#include "GeneratorInterface/GenFilters/interface/PythiaFilterGammaGamma.h"
Expand Down Expand Up @@ -47,6 +48,7 @@
using cms::BHFilter;
DEFINE_FWK_MODULE(LQGenFilter);
DEFINE_FWK_MODULE(PythiaFilter);
DEFINE_FWK_MODULE(PythiaFilterMultiMother);
DEFINE_FWK_MODULE(PythiaDauFilter);
DEFINE_FWK_MODULE(PythiaFilterGammaJet);
DEFINE_FWK_MODULE(PythiaFilterGammaGamma);
Expand Down

0 comments on commit 7fc42ea

Please sign in to comment.