.lhef output from pythiaexample.c?


pythiaexample.c gives a root file. But I need to use this file with Delphes.
When I checked Delphes input file format there are 3 options:

1-) .lhef
2-) .hepmc
3-) .hep

How can I take Delphes file formats from pythiaexample.c?
Script? Converter?

Thank you.


could you post the (small?) ROOT file somewhere?
I might have a few tools that can convert it into a .hepmc file.

Thank you so much for your answer @sbinet
I have the root file (small) on my work computer but I cannot reach now.
In an hour, I will post the root file here and will inform you.

Hello again @sbinet

Here is my .root file from pythia.
I need this .root file in one of the Delphes input format’s (.lhef, .hep, .hepmc)

p.s: File size 3.4 mb and root form accepts only 3 mb so i uploaded wetransfer.


ah… sorry, my tool isn’t (yet) able to read that kind of ROOT file.

but here is the code to convert a Pythia Event into a HepMC2 file:

// main41.cc is a part of the PYTHIA event generator.
// Copyright (C) 2017 Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.

// Author: Mikhail Kirsanov, Mikhail.Kirsanov@cern.ch, based on main01.cc.
// This program illustrates how HepMC can be interfaced to Pythia8.
// It studies the charged multiplicity distribution at the LHC.
// HepMC events are output to the hepmcout41.dat file.

// WARNING: typically one needs 25 MB/100 events at the LHC.
// Therefore large event samples may be impractical.

#include "Pythia8/Pythia.h"
#include "Pythia8Plugins/HepMC2.h"

using namespace Pythia8;

int main() {

  // Interface for conversion from Pythia8::Event to HepMC event.
  HepMC::Pythia8ToHepMC ToHepMC;

  // Specify file where HepMC events will be stored.
  HepMC::IO_GenEvent ascii_io("hepmcout41.dat", std::ios::out);

  // Generator. Process selection. LHC initialization. Histogram.
  Pythia pythia;
  pythia.readString("Beams:eCM = 8000.");
  pythia.readString("HardQCD:all = on");
  pythia.readString("PhaseSpace:pTHatMin = 20.");
  Hist mult("charged multiplicity", 100, -0.5, 799.5);

  // Begin event loop. Generate event. Skip if error.
  for (int iEvent = 0; iEvent < 100; ++iEvent) {
    if (!pythia.next()) continue;

    // Find number of all final charged particles and fill histogram.
    int nCharged = 0;
    for (int i = 0; i < pythia.event.size(); ++i)
      if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
    mult.fill( nCharged );

    // Construct new empty HepMC event and fill it.
    // Units will be as chosen for HepMC build; but can be changed
    // by arguments, e.g. GenEvt( HepMC::Units::GEV, HepMC::Units::MM)
    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
    ToHepMC.fill_next_event( pythia, hepmcevt );

    // Write the HepMC event to file. Done with it.
    ascii_io << hepmcevt;
    delete hepmcevt;

  // End of event loop. Statistics. Histogram.
  cout << mult;

  // Done.
  return 0;


Thank you for your help @sbinet
despite the compiling the Pythia with hepmc still main41 does not work.
I checked all the header files needed.
But unfortunately it’s not working.

Could you be provide more details?
What is not working? Is it a compilation error? A runtime error?

Could you post the source file that you used to generate that ROOT file?


Source file is pythiaexample.c
here is the macro: https://root.cern.ch/doc/master/pythiaExample_8C_source.html
At the beginning, I tried to generate events with this macro. it’s easy to use.
But it’s pythia6.

Than, I decided to use pythia8 examples (main41 & main42). Because, these examples are about hepmc file format.
I compiled pythia8 with hepmc. Everything seems well when I try to work with main41 examples gives header file errors.
this: fatal error: ‘Pythia8/Pythia.h’ file not found
But I am pretty sure it’s not about the header file because header files reachable from macro.
include paths is true !

as a result,
It’s not important to use “pythiaExample.c” or main41.cc I just need to generate Pythia events than use delphes.

pythiaexample.c gives root file but I need something like lhef, hep or hepmc output.
It would be great to learn how can I do this.

Thank you.

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