Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cmake files in the examples related to HepMC and event generators #45

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from

Conversation

andriish
Copy link

This PR is the first step to add HepMC3-based examples to Geant4. It concentrates mostly on the improvements to the currently used cmake build system for the current examples (i.e. HepMC2-based examples).

Please squash the commits.

In this PR:

  • Updated FindPythia6.cmake
  • Updated FindPythia8.cmake
  • Added FindLHAPDF.cmake
  • Added dummy sources needed to compile an event generator from pythia6 library
  • Adjusted the CMakeLists.txt files in the examples to search properly for LHAPDF
  • Adjusted the CMakeLists.txt files in the examples allow for any Fortran compiller, not only gfortran

The PR also includes a simple CI, which tests the compilation of the examples.
The CI should be removed before the merge.

Tag @jrmadsen @drbenmorgan . It would be nice to tag Witold here, but I cannot find him in the list of members.
Will have to write a mail.

Best regards,

Andrii

@andriish
Copy link
Author

Hi @gcosmo , @WitekPokorski , if needed I can split this PR even into smaller pieces.

@ihrivnac
Copy link

Hi @andriish ,

The examples in the pythia directory do not use HepMC, so I'd not expect their modifications in your PR. The FindPythia* files provided in Geant4 define mainly the variables that are used in building Geant4 examples; we so not aim to fully substitute the absence of CMake configuration files for these packages.

As PRs from GitHub have to be transported to the internal Geant4 development GitLab repository, it would be easier to review a final PR (with the complete update that should be included in Geant4) and this should also include the update of the documentation (the README file in each example and each example category) for all modified examples/categories. From just this PR it is not possible to see (and so to review) where the added files are needed or how they should be used.

What do you(@WitekPokorski , @drbenmorgan) think?

Best regards,

@andriish
Copy link
Author

Hi @ihrivnac ,

there are two issues:

  1. Pythia
    There is a mixture of HepMC and Pythia code, e.g.
HepMCEx02 ${Geant4_LIBRARIES}
                      ${HEPMC_LIBRARIES} ${HEPMC_FIO_LIBRARIES}
                      ${PYTHIA6_LIBRARIES}

so some minimally working configuration for the Pythia6/Pythia8 is needed. The updated configurations are not super complex configurations, but these are just "OK".
The same is true for LHAPDF.

  1. So far this PR is just an improvement/bugfix of the existing examples.

From just this PR it is not possible to see (and so to review) where the added files are needed or how they should be used.

The added files are needed just to compile the examples. The current version of the examples does not work. One can understand it easily even w/o compiling anything, just looking at the CMakeLists.txt in the examples. E.g. the LHAPDF libraries will link only if found in the standard location, no way to specify where Pythia installation is + linkage problems etc.
Sorry that I haven't explained this from the very beginning.
As for me, it makes sense to merge this PR and only after that add an update with HepMC3. "Features should be added after bugfixes" approach. What do you think?

Best regards,

Andrii

@andriish
Copy link
Author

Some more descriptions of new files:

  • All *.F Fortran sources are simple/dummy Pythia6 routines.
  • The files in .github directory are related to Ci and should be ignored.
  • The Find*.cmake files are CMake find modules

Hopefully, that helps.

Tag @ihrivnac , @drbenmorgan , @jrmadsen , @WitekPokorski

@ihrivnac
Copy link

Hi @andriish ,

Thank you for more explanation; I used to test the HepMC examples with just the ascii files input and did not pay attention to the pythia6 option. On the other hand, I still do not see where LHAPDF or Pythia8 is used/linked.

The procedure how to compile with Pythia6 is described in the "decayer6" example documentation:
https://geant4-userdoc.web.cern.ch/Doxygen/examples_doc/html/Exampledecayer6.html

and using the PYTHIA6_DIR environment variable worked for me also for building HepMC example with Pythia6 enabled.

However when running the HepMCEx01 with hepmc_pygen.in I get a segmentation break, that I hoped to get fixed with your update; but it is not the case, I am still getting :

./HepMCEx01 hepmc_pygen.in  
...
1****************** PYINIT: initialization of PYTHIA routines *****************
HepMCEx01(24135,0x11ae63e00) malloc: can't allocate region
:*** mach_vm_map(size=140728898424832, flags: 100) failed (error code=3)
HepMCEx01(24135,0x11ae63e00) malloc: *** set a breakpoint in malloc_error_break to debug
Segmentation fault: 11

Any idea ?

Can you let me know your versions of HepMC and Pythia6?
I dropped LHAPDF from the CMake files, as I don't have it installed and it does not seem to be used in the current examples.

@andriish
Copy link
Author

Hi @ihrivnac ,

On the other hand, I still do not see where LHAPDF

LHAPDF is needed to generate Pythia6 and Pythia8 events in pp collisions. W/o LHAPDF some internal dummy routines of Pythia6 and Pythia8 will be used, but no reasonable events will be generated and some crashes will be possible.

or Pythia8 is used/linked.

Pythia8 is used in examples/extended/eventgenerator/pythia/py8decayer . My motivation to change the FindPythia8.cmake was
to assure it has all the features needed in future PRs for HepMC3 support and that it is able to search for Pythia8 in more locations. These are just improvements.

and using the PYTHIA6_DIR environment variable worked for me also for building HepMC example with Pythia6 enabled.
Cmake recommends that it should be provided in the command line. In this PR both will work.

Can you let me know your versions of HepMC and Pythia6?

On CentOS8:
HepMC-2.06.11-1.el8.x86_64 from EPEL
pythia6-6.4.28-7.el8.x86_6 from https://copr.fedorainfracloud.org/coprs/averbyts/HEPrpms/ , i.e.
https://download.copr.fedorainfracloud.org/results/averbyts/HEPrpms/epel-8-x86_64/04097558-pythia6/

On Fedora35:
HepMC-2.06.11-1.fc35.x86_64 from Fedora
pythia6-6.4.28-7.fc35.x86_6 from https://copr.fedorainfracloud.org/coprs/averbyts/HEPrpms/ , i.e.
https://download.copr.fedorainfracloud.org/results/averbyts/HEPrpms/fedora-35-x86_64/04097558-pythia6/

Please note that I compile and link the examples with preinstalled Geant4-11.0.0 -- see the procedure in CI script
.github/workflows/fedora35/entrypoint.sh in current PR.

Also, I've added the tests explicitly to the current CI
I run

cd  $TOP/test/HepMC/HepMCEx01  
$TOP/INSTALL/bin/HepMCEx01 hepmc_pygen.in
$TOP/INSTALL/bin/HepMCEx01 hepmc_ascii.in

cd  $TOP/test/HepMC/HepMCEx02
$TOP/INSTALL/bin/HepMCEx02 hepmc_pygen.in
$TOP/INSTALL/bin/HepMCEx02 hepmc_ascii.in

and everything works. You can see the log files in "actions" of my fork -- I've added you to that project.

Best regards,
Andrii

@andriish
Copy link
Author

@ihrivnac
By the way, you can reproduce my setup exactly in docker or singularity just in 1-2 minutes.
The setup for singularity would be

singularity build  mygeant4buildenvilonment.sif  mygeant4buildenvilonment.def

with mygeant4buildenvilonment.def containing

Bootstrap: docker
From: fedora:35
%post
yum -y install dnf-plugins-core
yum -y install gcc gcc-c++ gcc-gfortran make which cmake cmake-data cmake-filesystem
yum -y install HepMC3 HepMC3-devel HepMC HepMC-devel redhat-rpm-config
yum -y install expat-devel  xerces-c-devel xerces-c expat expat-devel zlib zlib-devel lhapdf lhapdf-devel
yum -y install pythia8-devel pythia8 pythia8-data
yum -y install yum-plugin-copr
yum -y copr enable averbyts/HEPrpms
yum -y install geant4 geant4-devel  clhep clhep-devel PTL-devel  pythia6 
yum -y install clean all
#Needed for tests, large
yum -y install geant4-data
yum -y install clean all

Best regards,

Andrii

@andriish
Copy link
Author

andriish commented May 4, 2022

Hi @ihrivnac , that is 6.4.0 and I install it as

brew tap davidchall/hep
brew install lhapdf

but it should not matter.

Also, in other branch I've implemented downloading and compilation of pythia6 in cmake.

In any case, I would suggest to merge the changes as it is already an improvement over the existing setup (which does not work neither for me or for you, right?).

Best regards,
Andrii

@ihrivnac
Copy link

ihrivnac commented May 5, 2022

Hi @andriish ,

I compiled with LHAPDF, and this did not solve the problem. There is still the same break at the pythi6 initialization.

I searched the output from this test in the log in your MacOS CI and found the errors showing that pythia6 generator has not run al all (see below).

As I develop and test on MacOS, that is one of the supported and tested Geant4 platforms., we need to understand what's wrong here before proposing the merge request in the Geant4 development repository.

Best regards,

+ /Users/runner/work/geant4/geant4/INSTALL/bin/HepMCEx02 hepmc_pygen.in

see from line #6470
***** COMMAND NOT FOUND </generator/pythia/pygive PMAS(6,1)=174.3D0> *****

***** Batch is interrupted!! *****
***** COMMAND NOT FOUND </control/execute pyh4mu.mac> *****

***** Batch is interrupted!! *****
***** COMMAND NOT FOUND </control/execute pyset.mac> *****

***** Batch is interrupted!! *****
current generator type: pythia

Alois Kabelschacht and others added 4 commits May 6, 2022 10:48
@andriish
Copy link
Author

andriish commented May 6, 2022

Hi @ihrivnac ,

You are right, it was not running.
After some digging it seems this is a pythia6 bug. So the option to compile with external Pythia6 makes no sense.

Will try to make updates that make this branch work.

BEst regards,

Andrii

@andriish
Copy link
Author

andriish commented May 6, 2022

Hi @ihrivnac ,

hopefuly this will work for you as well. Please run cmake with -DPYTHIA6_INTERNAL=ON. Pythia6 will be downloaded and compiled automatically.

Best regards,
Andrii

@ihrivnac
Copy link

Hi @andriish ,
Sorry for the silence, but we were giving the Geant4 Orsay tutorial last week, and I had to devote all my time to it.

I tried out your update, but this leads to the linking errors below. Also, I do not find the CMake instructions for downloading Pythia6, but just see copying the pynit.f file from the upper directory into the examples.

Could you, also explain, what is wrong in the original pythia6 code that needed your fix? We use pythia6 in the ALICE framework and do not need to patch this subroutine here.

I have proposed a merge request in the Geant4 development gitlab with the compilation fix in HepMCEx01 stepping action class due to changes in G4String in Geant4 11, that will go also on the next patch. For the rest, we need to understand what's wrong with this pythia6 part.

Best regards,

[ 53%] Linking CXX executable HepMCEx01
Undefined symbols for architecture x86_64:
  "_pydatr_", referenced from:
      HepMCG4PythiaInterface::SetRandomSeed(int) in HepMCG4PythiaInterface.cc.o
      HepMCG4PythiaInterface::PrintRandomStatus(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in HepMCG4PythiaInterface.cc.o
  "_pyevnt_", referenced from:
      call_pyevnt() in HepMCG4PythiaInterface.cc.o
  "_pygive_", referenced from:
      call_pygive(G4String) in HepMCG4PythiaInterface.cc.o
  "_pyhepc_", referenced from:
      call_pyhepc(int) in HepMCG4PythiaInterface.cc.o
  "_pyinit_", referenced from:
      call_pyinit(char const*, char const*, char const*, double) in HepMCG4PythiaInterface.cc.o
  "_pylist_", referenced from:
      call_pylist(int) in HepMCG4PythiaInterface.cc.o
  "_pyrget_", referenced from:
      call_pyrget(int, int) in HepMCG4PythiaInterface.cc.o
  "_pyrset_", referenced from:
      call_pyrset(int, int) in HepMCG4PythiaInterface.cc.o
  "_pystat_", referenced from:
      call_pystat(int) in HepMCG4PythiaInterface.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [HepMCEx01/HepMCEx01] Error 1
make[1]: *** [HepMCEx01/CMakeFiles/HepMCEx01.dir/all] Error 2
make: *** [all] Error 2

@andriish
Copy link
Author

Hi @ihrivnac ,

sorry for the silence as well. It seems I did not get any mails about your answer.

  1. Pythia
    In the pyinit.f I've replaced
C...Identify beam and target particles and frame of process.
      CHFRAM=FRAME//' '
      CHBEAM=BEAM//' '
      CHTARG=TARGET//' '

with

C...Identify beam and target particles and frame of process.
      CHFRAM=FRAME(1:len(FRAME))//' '
      CHBEAM=BEAM(1:len(BEAM))//' '
      CHTARG=TARGET(1:len(TARGET))//' '
  1. The Pythia6 is downloaded in examples/extended/eventgenerator/CMakeLists.txt starting at line 19.
    One should use -DPYTHIA6_INTERNAL=ON.

Best regards,

Andrii

@andriish andriish marked this pull request as draft November 29, 2023 15:56
@drbenmorgan
Copy link
Member

@andriish, I'm just going through our current PRs, is there any update on this?

@andriish andriish mentioned this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants