CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/GeneratorInterface/GenFilters/src/PythiaFilter.cc

Go to the documentation of this file.
00001 
00002 #include "GeneratorInterface/GenFilters/interface/PythiaFilter.h"
00003 
00004 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00005 #include <iostream>
00006 
00007 using namespace edm;
00008 using namespace std;
00009 
00010 
00011 PythiaFilter::PythiaFilter(const edm::ParameterSet& iConfig) :
00012 label_(iConfig.getUntrackedParameter("moduleLabel",std::string("generator"))),
00013 particleID(iConfig.getUntrackedParameter("ParticleID", 0)),
00014 minpcut(iConfig.getUntrackedParameter("MinP", 0.)),
00015 maxpcut(iConfig.getUntrackedParameter("MaxP", 10000.)),
00016 minptcut(iConfig.getUntrackedParameter("MinPt", 0.)),
00017 maxptcut(iConfig.getUntrackedParameter("MaxPt", 10000.)),
00018 minetacut(iConfig.getUntrackedParameter("MinEta", -10.)),
00019 maxetacut(iConfig.getUntrackedParameter("MaxEta", 10.)),
00020 minrapcut(iConfig.getUntrackedParameter("MinRapidity", -20.)),
00021 maxrapcut(iConfig.getUntrackedParameter("MaxRapidity", 20.)),
00022 minphicut(iConfig.getUntrackedParameter("MinPhi", -3.5)),
00023 maxphicut(iConfig.getUntrackedParameter("MaxPhi", 3.5)),
00024 status(iConfig.getUntrackedParameter("Status", 0)),
00025 motherID(iConfig.getUntrackedParameter("MotherID", 0)),
00026 processID(iConfig.getUntrackedParameter("ProcessID", 0))
00027 {
00028    //now do what ever initialization is needed
00029 
00030 }
00031 
00032 
00033 PythiaFilter::~PythiaFilter()
00034 {
00035  
00036    // do anything here that needs to be done at desctruction time
00037    // (e.g. close files, deallocate resources etc.)
00038 
00039 }
00040 
00041 
00042 //
00043 // member functions
00044 //
00045 
00046 // ------------ method called to produce the data  ------------
00047 bool PythiaFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00048 {
00049    using namespace edm;
00050    bool accepted = false;
00051    Handle<HepMCProduct> evt;
00052    iEvent.getByLabel(label_, evt);
00053 
00054    const HepMC::GenEvent * myGenEvent = evt->GetEvent();
00055     
00056    if(processID == 0 || processID == myGenEvent->signal_process_id()) {
00057      
00058      for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
00059            p != myGenEvent->particles_end(); ++p ) {
00060        
00061        rapidity = 0.5*log( ((*p)->momentum().e()+(*p)->momentum().pz()) / ((*p)->momentum().e()-(*p)->momentum().pz()) );
00062        
00063        if ( abs((*p)->pdg_id()) == particleID 
00064             && (*p)->momentum().rho() > minpcut 
00065             && (*p)->momentum().rho() < maxpcut
00066             && (*p)->momentum().perp() > minptcut 
00067             && (*p)->momentum().perp() < maxptcut
00068             && (*p)->momentum().eta() > minetacut
00069             && (*p)->momentum().eta() < maxetacut 
00070             && rapidity > minrapcut
00071             && rapidity < maxrapcut 
00072             && (*p)->momentum().phi() > minphicut
00073             && (*p)->momentum().phi() < maxphicut ) {
00074          
00075          
00076          
00077          if (status == 0 && motherID == 0){
00078            accepted = true;
00079          }
00080          if (status != 0 && motherID == 0){
00081            if ((*p)->status() == status)   
00082              accepted = true;
00083          }
00084          
00085          HepMC::GenParticle* mother = (*((*p)->production_vertex()->particles_in_const_begin()));
00086          
00087          if (status == 0 && motherID != 0){    
00088            if (abs(mother->pdg_id()) == abs(motherID)) {
00089              accepted = true;
00090            }
00091          }
00092          if (status != 0 && motherID != 0){
00093            
00094            if ((*p)->status() == status && abs(mother->pdg_id()) == abs(motherID)){   
00095              accepted = true;
00096              
00097            }
00098          }
00099          
00100          /*
00101            if (status == 0 && motherID != 0){    
00102            if (abs(((*p)->mother())->pdg_id()) == abs(motherID)) {
00103            accepted = true;
00104            }
00105            }
00106            if (status != 0 && motherID != 0){
00107            
00108            if ((*p)->status() == status && abs(((*p)->mother())->pdg_id()) == abs(motherID)){   
00109            accepted = true;
00110            
00111            }
00112            }
00113          */
00114          
00115        }    
00116      }
00117      
00118    } else { accepted = true; }
00119 
00120    if (accepted){
00121    return true; } else {return false;}
00122 
00123 }
00124