geant4 icon indicating copy to clipboard operation
geant4 copied to clipboard

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

Open andriish opened this issue 3 years ago • 17 comments

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 avatar Apr 10 '22 13:04 andriish

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

andriish avatar Apr 12 '22 13:04 andriish

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,

ihrivnac avatar Apr 12 '22 13:04 ihrivnac

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 avatar Apr 29 '22 10:04 andriish

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

andriish avatar Apr 29 '22 10:04 andriish

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.

ihrivnac avatar Apr 29 '22 15:04 ihrivnac

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 avatar Apr 30 '22 11:04 andriish

@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 avatar Apr 30 '22 11:04 andriish

Hi @andriish ,

Thank for all the info. So LHAPDF is not needed technically (I mean to build and run the example with pythia6), right?

I am testing on MacOS, and I've rebuilt your versions of HepMC and pythia6 from source, and I am still getting the segmentation break above. @WitekPokorski , @drbenmorgan, any idea?

Best regards,

ihrivnac avatar May 03 '22 14:05 ihrivnac

Hi @ihrivnac ,

  1. So LHAPDF is not needed technically (I mean to build and run the example with pythia6), right?

It is needed. W/o LHAPDF pythia6 will not be able to generate events or the generation will be broken. If that "break" will be enough to produce a crash -- I don't know. Maybe yes. Maybe no.

  1. Ok, I did not know you was trying to compile on Mac.

  2. Nevertheless, I've added a CI job that runs on Mac using the pre-compiled Geant4 -11.0.1 There are some minor issues with the pre-compiled tarball and actually the pythia6 compilation docs should be updated.

  3. However, at least two test jobs are fine and for the others I get

 -------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : DIGIHIT1001
./.github/workflows/osx/entrypoint.sh: line 91:  8744 Segmentation fault: 11  $TOP/INSTALL/bin/HepMCEx01 hepmc_pygen.in
      issued by : G4VReadOutGeometry
+ /Users/runner/work/geant4/geant4/INSTALL/bin/HepMCEx01 hepmc_ascii.in
The concept and the functionality of Readout Geometry has been merged
into Parallel World. This G4VReadOutGeometry is kept for the sake of
not breaking the commonly-used interface in the sensitive detector class.
But this functionality of G4VReadOutGeometry class is no longer tested
and thus may not be working well. We strongly recommend our customers to
migrate to Parallel World scheme.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

But no crashes as you described and when I run the same setup on my laptop I see no problems at all. So maybe the problem is the way pythia6 is compiled and maybe the absence of lhapdf in your setup. Is there a way to reproduce your setup?

  1. Concerning the Pythia -- a modern approach to pythia6 compilation for examples would be to let cmake do everything -- download , unpack codes and compile. I can implement it as well...

Best regards,

Andrii

andriish avatar May 03 '22 18:05 andriish

Ok, I will try with LHAPDF, too. Could you point me where to get it and which version do you have?

ihrivnac avatar May 04 '22 09:05 ihrivnac

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

andriish avatar May 04 '22 14:05 andriish

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

ihrivnac avatar May 05 '22 14:05 ihrivnac

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 avatar May 06 '22 13:05 andriish

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

andriish avatar May 06 '22 14:05 andriish

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

ihrivnac avatar May 24 '22 15:05 ihrivnac

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 avatar Jun 10 '22 14:06 andriish

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

drbenmorgan avatar Mar 11 '24 15:03 drbenmorgan