CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/GeneratorInterface/Pythia8Interface/plugins/Py8EGun.cc

Go to the documentation of this file.
00001 
00002 #include "GeneratorInterface/Core/interface/GeneratorFilter.h"
00003 #include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"
00004 
00005 #include "GeneratorInterface/Pythia8Interface/interface/Py8GunBase.h"
00006 #include "GeneratorInterface/Pythia8Interface/interface/RandomP8.h"
00007 
00008 namespace gen {
00009 
00010 class Py8EGun : public Py8GunBase {
00011    
00012    public:
00013       
00014       Py8EGun( edm::ParameterSet const& );
00015       ~Py8EGun() {}
00016          
00017       bool generatePartonsAndHadronize();
00018       const char* classname() const;
00019          
00020    private:
00021       
00022       // EGun particle(s) characteristics
00023       double  fMinEta;
00024       double  fMaxEta;
00025       double  fMinE ;
00026       double  fMaxE ;
00027       bool    fAddAntiParticle;
00028 
00029 };
00030 
00031 // implementation 
00032 //
00033 Py8EGun::Py8EGun( edm::ParameterSet const& ps )
00034    : Py8GunBase(ps) 
00035 {
00036 
00037    // ParameterSet defpset ;
00038    edm::ParameterSet pgun_params = 
00039       ps.getParameter<edm::ParameterSet>("PGunParameters"); // , defpset ) ;
00040    fMinEta     = pgun_params.getParameter<double>("MinEta"); // ,-2.2);
00041    fMaxEta     = pgun_params.getParameter<double>("MaxEta"); // , 2.2);
00042    fMinE       = pgun_params.getParameter<double>("MinE"); // ,  0.);
00043    fMaxE       = pgun_params.getParameter<double>("MaxE"); // ,  0.);
00044    fAddAntiParticle = pgun_params.getParameter<bool>("AddAntiParticle"); //, false) ;  
00045 
00046 }
00047 
00048 bool Py8EGun::generatePartonsAndHadronize()
00049 {
00050 
00051    fMasterGen->event.reset();
00052    
00053    for ( size_t i=0; i<fPartIDs.size(); i++ )
00054    {
00055 
00056       int particleID = fPartIDs[i]; // this is PDG - need to convert to Py8 ???
00057 
00058       // FIXME !!!
00059       // Ouch, it's using bare randomEngine pointer - that's NOT safe.
00060       // Need to hold a pointer somewhere properly !!!
00061       //
00062       double phi = (fMaxPhi-fMinPhi) * randomEngine->flat() + fMinPhi;
00063       double ee   = (fMaxE-fMinE) * randomEngine->flat() + fMinE;
00064       double eta  = (fMaxEta-fMinEta) * randomEngine->flat() + fMinEta;                                                      
00065       double the  = 2.*atan(exp(-eta));                                                                          
00066       
00067       double mass = (fMasterGen->particleData).mass( particleID );
00068 //      double mass = (pythia->particleData).m0( particleID );
00069 
00070       double pp = sqrt( ee*ee - mass*mass );
00071       double px = pp * sin(the) * cos(phi);
00072       double py = pp * sin(the) * sin(phi);
00073       double pz = pp * cos(the);
00074 
00075       if ( !((fMasterGen->particleData).isParticle( particleID )) )
00076       {
00077          particleID = std::fabs(particleID) ;
00078       }
00079       (fMasterGen->event).append( particleID, 1, 0, 0, px, py, pz, ee, mass ); 
00080 
00081 // Here also need to add anti-particle (if any)
00082 // otherwise just add a 2nd particle of the same type 
00083 // (for example, gamma)
00084 //
00085       if ( fAddAntiParticle )
00086       {
00087          if ( (fMasterGen->particleData).isParticle( -particleID ) )
00088          {
00089             (fMasterGen->event).append( -particleID, 1, 0, 0, px, py, pz, ee, mass );
00090          }
00091          else
00092          {
00093             (fMasterGen->event).append( particleID, 1, 0, 0, px, py, pz, ee, mass );
00094          }
00095       }
00096 
00097    }
00098    
00099    if ( !fMasterGen->next() ) return false;
00100    
00101    event().reset(new HepMC::GenEvent);
00102    toHepMC.fill_next_event( fMasterGen->event, event().get() );
00103       
00104    return true;   
00105   
00106 }
00107 
00108 const char* Py8EGun::classname() const
00109 {
00110    return "Py8EGun"; 
00111 }
00112 
00113 typedef edm::GeneratorFilter<gen::Py8EGun, gen::ExternalDecayDriver> Pythia8EGun;
00114 
00115 } // end namespace
00116 
00117 using gen::Pythia8EGun;
00118 DEFINE_FWK_MODULE(Pythia8EGun);