Hepmc file to .root conversion

Greetings there,
I am a student of Msc Physics and trying to convert a .hepmc file to .root.
I found one code on github (link: GitHub - hbprosper/hepmc2root: Python program to convert a text file of events in HepMC2 format to a simple ROOT file.) which works perfectly fine but the hepmc2root.py file in it creates limited branches like: Px, Py, E ,mass etc. but i need the rapidity(eta), azimuthal angle(phi) for my project which are not included in the conversion file.
I’ve looked up everywhere but can’t find any updated conversion tool/file.

Can anyone suggest me some update hepmc2root file for that purpose or tell me how to update the file, it’d be really helpful for me.

Thank you in advance,
Dharmender

hepmc2root.py (12.9 KB)

Try with: HepMC3
There are some examples, e.g.:

Thank you for your quick reply, I tried installing HePMC3 with two methods:
Method 1:
I followed the steps mentioned in link : HepMC3 event record library: Building instructions

  1. Downloaded latest version of HepMC3(v3.2.5) and cd into the directory.
  2. Executed the command :
    "cmake -DCMAKE_INSTALL_PREFIX=/home/dharmender/hepmc3 -DHEPMC3_ENABLE_ROOTIO=ON -DHEPMC3_ENABLE_PYTHON=OFF CMakeLists.txt "
  3. cmake --build .
  4. cmake --install .
  5. ctests.
    The last command shows :
    "31% tests passed, 29 tests failed out of 42
    The following tests FAILED:
    1 - testBoost (Not Run)
    2 - testFourVector (Not Run)
    3 - testMass (Not Run)
    4 - testPrintBug (Not Run)
    5 - testPolarization (Not Run)
    6 - testUnits (Not Run)
    7 - testMultipleCopies (Not Run)
    8 - testWeights (Not Run)
    9 - testLoops (Not Run)
    10 - testDelete (Not Run)
    11 - testSkip1 (Not Run)
    12 - testIO1 (Not Run)
    13 - testIO3 (Not Run)
    14 - testIO6 (Not Run)
    15 - testIO7 (Not Run)
    16 - testIO8 (Not Run)
    17 - testReaderFactory1 (Not Run)
    18 - testSingleVertexHepMC2 (Not Run)
    19 - testAttributes (Not Run)
    20 - testHEPEVTWrapper1 (Not Run)
    21 - testThreads1 (Not Run)
    22 - testIO10 (Not Run)
    23 - testIO9 (Not Run)
    24 - testThreadssearch (Not Run)
    25 - testIO2 (Not Run)
    26 - testIO4 (Not Run)
    27 - testReaderFactory2 (Not Run)
    28 - testRoot300 (Not Run)
    29 - testRootTree300 (Not Run)
    "

Method 2 :
I followed the steps of link : HepMC / HepMC3 · GitLab

And did the following steps in my system

  1. git clone HepMC / HepMC3 · GitLab

  2. cmake -DHEPMC3_ENABLE_ROOTIO=ON -DROOT_DIR=path_to_ROOT6_installation
    -DHEPMC3_BUILD_EXAMPLES=ON
    -DHEPMC3_ENABLE_TEST=ON
    -DCMAKE_INSTALL_PREFIX=…/hepmc3-install …/HepMC3

  3. make

  4. sudo make install (make install wasn’t working)

  5. Then to test it I executed ‘ctest .’ which showed “100% tests passed, 0 tests failed out of 55”.

  6. After following the script, I tried to run the examples by executing these commands:
    ‘cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/hepmc2root/hepmc3-install/share/HepMC3/cmake CMakeLists.txt’ in the ‘examples’ directory which terminated with error:
    "-- Configuring done
    CMake Error at Pythia6Example/CMakeLists.txt:8 (add_executable):
    Cannot find source file:

    /pythia6/include/Pythia6/Pythia6ToHepMC3.cc

Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
.hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc

CMake Error at Pythia6Example/CMakeLists.txt:8 (add_executable):
No SOURCES given to target: pythia6_example.exe

CMake Generate step failed. Build files cannot be regenerated correctly."

  1. Then I tried to go into individual example directories and executed the same command:
    ‘cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/hepmc2root/hepmc3-install/share/HepMC3/cmake CMakeLists.txt’

(i) In the ‘BasicExamples’ directory; it worked fine and showed this in the end:
"Configuring done
– Generating done
CMake Warning:
Manually-specified variables were not used by the project:

HepMC3_DIR

– Build files have been written to: /home/dharmender/hepmc2root/HepMC3/examples/BasicExamples"

(ii) I didn’t go into the PythiaExample because i didn’t link with Pythia
(iii) For my purpose, I went into the ‘RootIOExample’ , ‘RootIOExample2’, ‘RootIOExample3’ directories and executed the same command: “cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/hepmc2root/hepmc3-install/share/HepMC3/cmake CMakeLists.txt”
But it ended with error:
"dharmender@dharmender-Inspiron-3521:~/hepmc2root/HepMC3/examples/RootIOExample$ cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/hepmc2root/hepmc3-install/share/HepMC3/cmake CMakeLists.txt
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as

project(ProjectName)

near the top of the file, but after cmake_minimum_required().

CMake is pretending there is a “project(Project)” command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.

– The C compiler identification is GNU 11.2.0
– The CXX compiler identification is GNU 11.2.0
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /usr/bin/gcc - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/g++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
CMake Error at CMakeLists.txt:25 (install):
install FILES given no DESTINATION!

CMake Error at CMakeLists.txt:26 (install):
install DIRECTORY given no DESTINATION!

CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 3.22)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run “cmake --help-policy CMP0000”.
This warning is for project developers. Use -Wno-dev to suppress it.

– Configuring incomplete, errors occurred!
See also “/home/dharmender/hepmc2root/HepMC3/examples/RootIOExample/CMakeFiles/CMakeOutput.log”."

cmake --version : 3.22.1

My main purpose is to convert into .root file that have atleast eta, phi , PID, px, py branches.
Can you suggest some way to convert into .root file ; it’d be really helpful for me.
Also I know it might sound basic but can you simply explain how to run the HePMC3 examples??
Do i need to convert my .hepmc file into HePMC3 file first and then convert in into .root file??
If so, how can I do it??

Thank you in advance,
Dharmender

# note: ROOTSYS must be set in advance, and below, use the same
#       Python version as returned by: root-config --python-version
#       (for me, it's Python 3.10.4, hence 3.10 and 310 below)

rm -rf HepMC3 HepMC3-build HepMC3-install # a total cleanup
git clone --depth=1 https://gitlab.cern.ch/hepmc/HepMC3
mkdir HepMC3-build
cd HepMC3-build
cmake -DCMAKE_INSTALL_PREFIX=../HepMC3-install \
      -DHEPMC3_PYTHON_VERSIONS=3.10 \
      -DHEPMC3_Python_SITEARCH310=../HepMC3-install/lib/python3.10/site-packages \
      -DHEPMC3_INSTALL_INTERFACES=ON \
      -DHEPMC3_BUILD_EXAMPLES=ON \
      -DHEPMC3_ENABLE_TEST=ON \
      ../HepMC3 2>&1 | tee -a cmake.out.txt
make 2>&1 | tee -a make.out.txt # note: built examples are in: ./outputs/bin
make test 2>&1 | tee -a make_test.out.txt
# ctest . 2>&1  | tee -a ctest.out.txt
make install 2>&1 | tee -a make_install.out.txt

See also: HepMC3 → Examples

Thanks for your detailed and quick answer…

I tried to reinstall by following the steps you mentioned.
Again the 'make test ’ command showed “100% tests passed” and all the commands you mentioned worked perfectly fine.

But when I try to do cmake in example directory it shows the previous error…

  1. In RootIOExample directory the command:
    ‘cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/h3/‘HepMC3-install’ CMakeLists.txt’

terminates with error:

"CMake Error at CMakeLists.txt:25 (install):
install FILES given no DESTINATION!

CMake Error at CMakeLists.txt:26 (install):
install DIRECTORY given no DESTINATION!"

  1. In RootIOExample2 directory the command:

‘cmake -DUSE_INSTALLED_HEPMC3=ON -DHepMC3_DIR=/home/dharmender/h3/‘HepMC3-install’ CMakeLists.txt’

terminates with error:

“CMake Error at CMakeLists.txt:9 (ROOT_GENERATE_DICTIONARY):
Unknown CMake command “ROOT_GENERATE_DICTIONARY”.”

Am I doing something wrong?
Isn’t there any way to directly obtain .root file from Herwig7 ??

Thanking you,
Dharmender

Report your problems: HepMC3 → Issues

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