CMS 3D CMS Logo

Public Member Functions | Private Attributes

Pythia8Hadronizer Class Reference

Inheritance diagram for Pythia8Hadronizer:
gen::BaseHadronizer

List of all members.

Public Member Functions

const char * classname () const
bool decay ()
bool declareSpecialSettings (const std::vector< std::string >)
bool declareStableParticles (const std::vector< int > &pdgIds)
void finalizeEvent ()
bool generatePartonsAndHadronize ()
bool hadronize ()
bool initializeForExternalPartons ()
bool initializeForInternalPartons ()
 Pythia8Hadronizer (const edm::ParameterSet &params)
bool residualDecay ()
void statistics ()
 ~Pythia8Hadronizer ()

Private Attributes

double comEnergy
 Center-of-Mass energy.
std::auto_ptr< LHAupLesHoucheslhaUP
string LHEInputFileName
unsigned int maxEventsToPrint
 Events to print if verbosity.
ParameterCollector parameters
std::auto_ptr< Pythia > pythia
EventpythiaEvent
bool pythiaHepMCVerbosity
 HepMC verbosity flag.
unsigned int pythiaPylistVerbosity
 Pythia PYLIST Verbosity flag.
HepMC::I_Pythia8 toHepMC
bool useUserHook
 Switch User Hook flag.

Detailed Description

Definition at line 39 of file Pythia8Hadronizer.cc.


Constructor & Destructor Documentation

Pythia8Hadronizer::Pythia8Hadronizer ( const edm::ParameterSet params)

Definition at line 86 of file Pythia8Hadronizer.cc.

References edm::ParameterSet::exists(), gen::getEngineReference(), edm::ParameterSet::getParameter(), randomEngine, and useUserHook.

                                                                  :
        BaseHadronizer(params),
        parameters(params.getParameter<edm::ParameterSet>("PythiaParameters")),
        comEnergy(params.getParameter<double>("comEnergy")),
        pythiaPylistVerbosity(params.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
        pythiaHepMCVerbosity(params.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false)),
        maxEventsToPrint(params.getUntrackedParameter<int>("maxEventsToPrint", 0)),
    LHEInputFileName(params.getUntrackedParameter<string>("LHEInputFileName","")),
    useUserHook(false)
{
    if( params.exists( "useUserHook" ) )
      useUserHook = params.getParameter<bool>("useUserHook");
    randomEngine = &getEngineReference();
}
Pythia8Hadronizer::~Pythia8Hadronizer ( )

Definition at line 101 of file Pythia8Hadronizer.cc.

{
}

Member Function Documentation

const char* Pythia8Hadronizer::classname ( ) const [inline]

Definition at line 58 of file Pythia8Hadronizer.cc.

{ return "Pythia8Hadronizer"; }
bool Pythia8Hadronizer::decay ( )

Definition at line 287 of file Pythia8Hadronizer.cc.

{
        return true;
}
bool Pythia8Hadronizer::declareSpecialSettings ( const std::vector< std::string >  )

Definition at line 240 of file Pythia8Hadronizer.cc.

{
   return true;
}
bool Pythia8Hadronizer::declareStableParticles ( const std::vector< int > &  pdgIds)

Definition at line 219 of file Pythia8Hadronizer.cc.

References i, and pythia.

{

   for ( size_t i=0; i<pdgIds.size(); i++ )
   {
      // FIXME: need to double check if PID's are the same in Py6 & Py8,
      //        because the HepPDT translation tool is actually for **Py6** 
      // 
      int PyID = HepPID::translatePDTtoPythia( pdgIds[i] ); 
      std::ostringstream pyCard ;
      pyCard << PyID <<":mayDecay=false";
      pythia->readString( pyCard.str() );
      // alternative:
      // set the 2nd input argument warn=false 
      // - this way Py8 will NOT print warnings about unknown particle code(s)
      // pythia->readString( pyCard.str(), false )
   }
   
   return true;

}
void Pythia8Hadronizer::finalizeEvent ( )

Definition at line 297 of file Pythia8Hadronizer.cc.

References gather_cfg::cout, gen::BaseHadronizer::event(), gen::BaseHadronizer::eventInfo(), gen::BaseHadronizer::lheEvent(), maxEventsToPrint, pythia, pythiaHepMCVerbosity, and pythiaPylistVerbosity.

{
  bool lhe = lheEvent() != 0;

  event()->set_signal_process_id(pythia->info.code());
  event()->set_event_scale(pythia->info.pTHat());       //FIXME

  int id1 = pythia->info.id1();
  int id2 = pythia->info.id2();
  if (id1 == 21) id1 = 0;
  if (id2 == 21) id2 = 0;
  double x1 = pythia->info.x1();
  double x2 = pythia->info.x2();
  double Q = pythia->info.QRen();
  double pdf1 = pythia->info.pdf1() / pythia->info.x1();
  double pdf2 = pythia->info.pdf2() / pythia->info.x2();
  event()->set_pdf_info(HepMC::PdfInfo(id1,id2,x1,x2,Q,pdf1,pdf2));

  event()->weights().push_back(pythia->info.weight());

  // now create the GenEventInfo product from the GenEvent and fill
  // the missing pieces
  eventInfo().reset( new GenEventInfoProduct( event().get() ) );

  // in pythia pthat is used to subdivide samples into different bins
  // in LHE mode the binning is done by the external ME generator
  // which is likely not pthat, so only filling it for Py6 internal mode
  if (!lhe) {
    eventInfo()->setBinningValues(std::vector<double>(1, pythia->info.pTHat()));
  }

  //******** Verbosity ********

  if (maxEventsToPrint > 0 &&
      (pythiaPylistVerbosity || pythiaHepMCVerbosity)) {
    maxEventsToPrint--;
    if (pythiaPylistVerbosity) {
      pythia->info.list(std::cout); 
      pythia->event.list(std::cout);
    } 

        if (pythiaHepMCVerbosity) {
                        std::cout << "Event process = "
                                  << pythia->info.code() << "\n"
                                  << "----------------------" << std::endl;
                        event()->print();
                }
        }
}
bool Pythia8Hadronizer::generatePartonsAndHadronize ( )

Definition at line 255 of file Pythia8Hadronizer.cc.

References gen::BaseHadronizer::event(), pythia, pythiaEvent, and toHepMC.

{
        if (!pythia->next())
                return false;

        event().reset(new HepMC::GenEvent);
        toHepMC.fill_next_event(*pythiaEvent, event().get());

        return true;
}
bool Pythia8Hadronizer::hadronize ( )

Definition at line 266 of file Pythia8Hadronizer.cc.

References lhef::LHEEvent::count(), gen::BaseHadronizer::event(), lhef::LHERunInfo::kAccepted, lhaUP, gen::BaseHadronizer::lheEvent(), LHEInputFileName, pythia, pythiaEvent, and toHepMC.

{
    if(LHEInputFileName == string()) {
      //cout << "start loading event" << endl;
      lhaUP->loadEvent(lheEvent());
      //cout << "finish loading event" << endl;
    }

    if (!pythia->next())
        return false;

    // update LHE matching statistics
    //
    lheEvent()->count( lhef::LHERunInfo::kAccepted );

    event().reset(new HepMC::GenEvent);
    toHepMC.fill_next_event(*pythiaEvent, event().get());

    return true;
}
bool Pythia8Hadronizer::initializeForExternalPartons ( )

Definition at line 151 of file Pythia8Hadronizer.cc.

References gen::ParameterCollector::begin(), gather_cfg::cout, gen::ParameterCollector::end(), lhaUP, LHEInputFileName, gen::BaseHadronizer::lheRunInfo(), geometryCSVtoXML::line, parameters, pythia, pythiaEvent, and pythiaPylistVerbosity.

{

    std::cout << "Initializing for external partons" << std::endl;

    RandomP8* RP8 = new RandomP8();

    pythia.reset(new Pythia);

    pythia->setRndmEnginePtr(RP8);

    pythiaEvent = &pythia->event;

    for(ParameterCollector::const_iterator line = parameters.begin();
        line != parameters.end(); ++line) {
        if (line->find("Random:") != std::string::npos)
            throw cms::Exception("PythiaError")
                << "Attempted to set random number "
                   "using Pythia commands.  Please use "
                   "the RandomNumberGeneratorService."
                << std::endl;

        if (!pythia->readString(*line))
            throw cms::Exception("PythiaError")
                << "Pythia 8 did not accept \""
                << *line << "\"." << std::endl;
    }

    if(pythiaPylistVerbosity > 10) {
      if(pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13)
        pythia->settings.listAll();
      if(pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13)
        pythia->particleData.listAll();
    }

    if(LHEInputFileName != string()) {

      cout << endl;
      cout << "LHE Input File Name = " << LHEInputFileName << endl;
      cout << endl;
      pythia->init(LHEInputFileName);

    } else {

      lhaUP.reset(new LHAupLesHouches());
      lhaUP->loadRunInfo(lheRunInfo());
      pythia->init(lhaUP.get());

    }

    return true;
}
bool Pythia8Hadronizer::initializeForInternalPartons ( )

Definition at line 105 of file Pythia8Hadronizer.cc.

References gen::ParameterCollector::begin(), comEnergy, gen::ParameterCollector::end(), geometryCSVtoXML::line, parameters, pythia, pythiaEvent, pythiaPylistVerbosity, and useUserHook.

{
        //Old code that used Pythia8 own random engine
        //edm::Service<edm::RandomNumberGenerator> rng;
        //uint32_t seed = rng->mySeed();
        //Pythia8::Rndm::init(seed);

    RandomP8* RP8 = new RandomP8();

        pythia.reset(new Pythia);

    pythia->setRndmEnginePtr(RP8);
    if(useUserHook) pythia->setUserHooksPtr(new PtHatReweightUserHook());

        pythiaEvent = &pythia->event;

        for(ParameterCollector::const_iterator line = parameters.begin();
            line != parameters.end(); ++line) {
                if (line->find("Random:") != std::string::npos)
                        throw cms::Exception("PythiaError")
                                << "Attempted to set random number "
                                   "using Pythia commands.  Please use "
                                   "the RandomNumberGeneratorService."
                                << std::endl;

                if (!pythia->readString(*line))
                        throw cms::Exception("PythiaError")
                                << "Pythia 8 did not accept \""
                                << *line << "\"." << std::endl;
        }

    if(pythiaPylistVerbosity > 10) {
      if(pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13)
        pythia->settings.listAll();
      if(pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13)
        pythia->particleData.listAll();
    }

        pythia->init(2212, 2212, comEnergy);

        pythia->settings.listChanged();

        return true;
}
bool Pythia8Hadronizer::residualDecay ( )

Definition at line 292 of file Pythia8Hadronizer.cc.

{
        return true;
}
void Pythia8Hadronizer::statistics ( )

Definition at line 246 of file Pythia8Hadronizer.cc.

References pythia, gen::BaseHadronizer::runInfo(), and GenRunInfoProduct::setInternalXSec().

{
        pythia->statistics();

        double xsec = pythia->info.sigmaGen(); // cross section in mb
    xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
        runInfo().setInternalXSec(xsec);
}

Member Data Documentation

double Pythia8Hadronizer::comEnergy [private]

Center-of-Mass energy.

Definition at line 64 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons().

std::auto_ptr<LHAupLesHouches> Pythia8Hadronizer::lhaUP [private]

Definition at line 77 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

Definition at line 72 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

unsigned int Pythia8Hadronizer::maxEventsToPrint [private]

Events to print if verbosity.

Definition at line 70 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent().

std::auto_ptr<Pythia> Pythia8Hadronizer::pythia [private]

HepMC verbosity flag.

Definition at line 68 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent().

Pythia PYLIST Verbosity flag.

Definition at line 66 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent(), initializeForExternalPartons(), and initializeForInternalPartons().

HepMC::I_Pythia8 Pythia8Hadronizer::toHepMC [private]

Definition at line 81 of file Pythia8Hadronizer.cc.

Referenced by generatePartonsAndHadronize(), and hadronize().

Switch User Hook flag.

Definition at line 75 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons(), and Pythia8Hadronizer().