HepMC output with Pythia8.C

Hi all,

I added HepMC codes to Pythia8.C example.

**but it gives this error: **
ToHepMC.fill_next_event( pythia, hepmcevt);

root doesnt like pythia
ToHepMC.fill_next_event( pythia, hepmcevt);

Here is my code:

/// \file
/// \ingroup tutorial_pythia
/// pythia8 basic example
/// to run, do:
/// ~~~{.cpp}
///  root > .x pythia8.C
/// ~~~
/// Note that before executing this script,
///  - the env variable PYTHIA8 must point to the pythia8100 (or newer) directory
///  - the env variable PYTHIA8DATA must be defined and it must point to $PYTHIA8/xmldoc
/// \macro_code
/// \author Andreas Morsch

#include "TSystem.h"
#include "TH1F.h"
#include "TClonesArray.h"
#include "TPythia8.h"
#include "TParticle.h"
#include "TDatabasePDG.h"
#include "TCanvas.h"

#include "Pythia8/Pythia.h"
#include "HepMCInterface.h"
#include "HepMC/GenEvent.h"
#include "HepMC/IO_GenEvent.h"
#include "Pythia8/Pythia8ToHepMC.h"

void pythia8(Int_t nev  = 100, Int_t ndeb = 1)
   const char *p8dataenv = gSystem->Getenv("PYTHIA8DATA");
   if (!p8dataenv) {
      const char *p8env = gSystem->Getenv("PYTHIA8");
      if (!p8env) {
               "Environment variable PYTHIA8 must contain path to pythia directory!");
      TString p8d = p8env;
      p8d += "/xmldoc";
      gSystem->Setenv("PYTHIA8DATA", p8d);

   const char* path = gSystem->ExpandPathName("$PYTHIA8DATA");
   if (gSystem->AccessPathName(path)) {
               "Environment variable PYTHIA8DATA must contain path to $PYTHIA8/xmldoc directory !");

// Load libraries
// Histograms
   TH1F* etaH = new TH1F("etaH", "Pseudorapidity", 120, -12., 12.);
   TH1F* ptH  = new TH1F("ptH",  "pt",              50,   0., 10.);

// Array of particles
   TClonesArray* particles = new TClonesArray("TParticle", 1000);
// Create pythia8 object
   TPythia8* pythia8 = new TPythia8();

// Configure
   pythia8->ReadString("HardQCD:all = on");

// Initialize

   pythia8->Initialize(2212 /* p */, 2212 /* p */, 14000. /* TeV */);
   HepMC::I_Pythia8 ToHepMC;
   HepMC::IO_GenEvent ascii_io("deneme.dat", std::ios::out);

// Event loop
   for (Int_t iev = 0; iev < nev; iev++) {
      if (iev < ndeb) pythia8->EventListing();
      Int_t np = particles->GetEntriesFast();
      HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
      ToHepMC.fill_next_event( pythia, hepmcevt);
      ascii_io << hepmcevt;
      delete hepmcevt;
// Particle loop
      for (Int_t ip = 0; ip < np; ip++) {
         TParticle* part = (TParticle*) particles->At(ip);
         Int_t ist = part->GetStatusCode();
         // Positive codes are final particles.
         if (ist <= 0) continue;
         Int_t pdg = part->GetPdgCode();
         Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
         if (charge == 0.) continue;
         Float_t eta = part->Eta();
         Float_t pt  = part->Pt();

         if (pt > 0.) ptH->Fill(pt, 1./(2. * pt));


   TCanvas* c1 = new TCanvas("c1","Pythia8 test example",800,800);
   c1->Divide(1, 2);

   ptH->SetXTitle("p_{t} [GeV/c]");
   ptH->SetYTitle("dN/dp_{t}^{2} [GeV/c]^{-2}");

Could you please help me?
What is wrong with it?

The pythia variable is not defined anywhere in your code… Maybe you should take a look at the documentation, for example: http://home.thep.lu.se/~torbjorn/pythia81html/HepMCInterface.html

Thank you @bellenot
i took a look at the documentation but i couldn’t find it out.
I made some changes.

I used this:

HepMC::Pythia8ToHepMC ToHepMC;

instead of this:

HepMC::I_Pythia8 ToHepMC;

Also this:

//ToHepMC.fill_next_event( pythia, hepmcevt);
      HepMC::Pythia8ToHepMC::fill_next_event( pythia, hepmcevt)
     //->Changed one

But still gives same error:
Should I use something different instead of “pythia” in the code?

ToHepMC.fill_next_event( pythia(***), hepmcevt);

As I said, in your code the pythia variable is not defined, you should maybe use pythia8. And note that this problem is more a Pythia/HepMC issue than a ROOT one…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.