Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

2.1 Getting Started with Event Generation

Original author: Gerardo Ganis

Enabling FCC Software

The FCC software is fully embedded in the Key4hep software stack or ecosystem, which means that the components providing the framework and those FCC specific are all available in Key4hep. To configure your environment for the FCC software is therefore sufficient to initialise Key4hep:

source /cvmfs/sw.hsf.org/key4hep/setup.sh

The main Gaudi steering application of Key4hep stack is called k4run which should be available at this point:

which k4run

with response:

/cvmfs/sw.hsf.org/key4hep/releases/2025-05-29/x86_64-almalinux9-gcc14.2.0-opt/k4fwcore/1.3-lix236/bin/k4run

(The output might differ, but shouldn’t be empty and the structure should be similar).

The application fccrun is still provided, fully equivalent to k4run.

Generators

Overview

The physics generators available for FCC usually come from Key4hep. However, any generator able to generate events in one of the understood formats, e.g. HepMC or EDM4hep or LHEf, can be used in standalone.

Following the discussion at the 1st ECFA workshop on Generators, the recommended formats are HepMC3 and EDM4hep; LHEf is still much in use though. This pages intend to illustrate the use of a few general purpose generators available: Pythia8, whizard, MadGraph5, Herwig, KKMCee, BHLUMI, BabaYaga.

Pythia8

Pythia8 is fully integrated in the Key4hep software stack and it provides diverse functionality in addition to event generation, including capability to read events in LHEf format.

To use Pythia8 we need a Gaudi steering file and a Pythia8 configuration file, usually having extension .cmd. Examples of these .cmd files are available from the FCC-config repository. The Gaudi steering file needs to activate the GaudiTool that interfaces Pythia8, available from the k4Gen repository under the name PythiaInterface.

An example of steering file can be found at pythia.py. The steering file runs the minimal set of algorithms to run Pythia8 and produce an output in EDM4hep format:

wget https://raw.githubusercontent.com/HEP-FCC/k4Gen/main/k4Gen/options/pythia.py
k4run --dry-run pythia.py

with expected output

[k4run - INFO] k4run.main: --> Pythia8 --> HepMCToEDMConverter --> StableParticles --> out
[...]

For example, to generate 500 e+e−→μ+μ−e^{+}e^{-} \rightarrow \mu^{+}\mu^{-} at 91.2 GeV, one can do the following, download the configuration file:

wget https://raw.githubusercontent.com/HEP-FCC/FCC-config/main/FCCee/Generator/Pythia8/p8_ee_Zmumu_ecm91.cmd

and run

k4run pythia.py -n 500 --out.filename p8_mumu_500.e4h.root --Pythia8.PythiaInterface.pythiacard p8_ee_Zmumu_ecm91.cmd

Whizard

Whizard is available as a standalone executable whizard, to check it’s presence in the current environment one can use:

which whizard

with expected result similar to

/cvmfs/sw.hsf.org/key4hep/releases/2025-05-29/x86_64-almalinux9-gcc14.2.0-opt/whizard/3.1.4-zjmc7r/bin/whizard

Whizard is run as this:

whizard <process_config>.sin

Example Sindarin configuration files can be found under

ls /cvmfs/sw.hsf.org/key4hep/releases/2025-05-29/x86_64-almalinux9-gcc14.2.0-opt/whizard/3.1.4-zjmc7r/share/whizard/examples/

or at https://gitlab.tp.nt.uni-siegen.de/whizard/public/-/tree/master/share/examples.

More examples specific to FCC can be found at https://fccsw.web.cern.ch/fccsw/share/gen/whizard/Zpole/.

KKMCee

KKMCee is an adaptation of the KKMC Monte Carlo generator (the latest version of the Koral generators) to the case of FCC-ee. KKMCee is available as standalone program when using the key4hep stack:

which KKMCee
/cvmfs/sw.hsf.org/spackages6/kkmcee/5.00.02/x86_64-centos7-gcc11.2.0-opt/eodg6/bin/KKMCee

A help function is available:

KKMCee -h

Note that the BES (Beam Energy Spread) options are only available in version 4.32.01 and higher.

A configuration example file for taus is available under at

ls `dirname $( which KKMCee )`/../share/KKMCee/kkmc-tauola.input

and a file kkmu_1000.hepmc created.

KKMCee creates several files during its run. These are saved into a folder called KKMCee-<date>-<time>, for example KKMCee-12Oct2022-191047. This folder contains the files:

ls KKMCee-12Oct2022-191047
DIZET-table1  TabMain77.output  TabMainC.output  mcgen.root  pro.input  pro.output  pro77.output

The file pro.input contains the configuration options and can be used to repeat the run

KKMCee -c KKMCee-12Oct2022-191047/pro.input

and, of course, as base configuration file example for further variations.

BHLUMI

BHLUMI is a Monte Carlo generator of Bhabha events used at LEP for luminosity studies. BHLUMI is available as standalone program when using the key4hep stack:

which BHLUMI
/cvmfs/sw.hsf.org/spackages4/bhlumi/4.04-linuxLHE/x86_64-centos7-gcc8.3.0-opt/o7rmcus/bin/BHLUMI

A help function is available:

BHLUMI -h

BabaYaga

BabaYaga is a Monte Carlo generator of two-photons events used at LEP. BabaYaga is available as standalone program when using the key4hep stack:

which babayaga
/cvmfs/sw.hsf.org/spackages4/babayaga/fcc-1.0.0/x86_64-centos7-gcc8.3.0-opt/jsgdir7/bin/babayaga

A help function is available:

babayaga -h

Herwig

Herwig is another historical LEP generator providing a diferent approach to hadronization wrt. Pythia8. It is available as standalone program:

which Herwig
/cvmfs/sw.hsf.org/spackages7/herwig3/7.2.3/x86_64-centos7-gcc11.2.0-opt/q3pxd/bin/Herwig

MadGraph5

MadGraph5 was developed for LHC but it is in reality general purpose and can be used also for FCC-ee. It is available as standalone program:

which mg5_aMC
/cvmfs/sw.hsf.org/spackages7/madgraph5amc/2.8.1/x86_64-centos7-gcc11.2.0-opt/nlauf/bin/mg5_aMC

Hands-on case study: ditau events with Pythia8, Whizard and KKMCee

In this section we describe, with exercises, the generation of an equivalent sample of Monte Carlo events with three diffent generators: Pythia8, Whizard and KKMCee. The process chosen is e−e+→τ−τ+e^{-}e^{+} \rightarrow \tau^{-}\tau^{+} (hereafter referred to as ditaus), with both taus decaying leptonically with a muon in the final state. The centre of mass energy of 91.2 GeV. In the three cases 10000 will be generated and saved in ROOT files in EDM4hep format: the steps to arrive at this results are however different.

Generating ditaus with Pythia8

As explained in the dedicated Pythia8 section, we need a Pythia8 configuration file and a Gaudi configuration file. For the former, to generate ditau events we will use the file p8_ee_Ztautau_mumu_ecm91.cmd. We create a sub-directory cards and we retrieve in it the file:

mkdir cards; cd cards
wget https://raw.githubusercontent.com/HEP-FCC/FCC-config/main/FCCee/Generator/Pythia8/p8_ee_Ztautau_mumu_ecm91.cmd

For the second, we create a sub-directory config and we retrieve in it the pythia.py file:

mkdir config; cd config
wget https://raw.githubusercontent.com/HEP-FCC/k4Gen/main/k4Gen/options/pythia.py

Before running it, we also create sub-directories gen/<generator_tag>_tautau_ecm91 for the generator files in format edm4hep.

Now: how will we run it? (hint: check specific section)

Running will take a few minutes. Among the last lines of the output there should be the total cross-section for the process:

 *-------  PYTHIA Event and Cross Section Statistics  -------------------------------------------------------------*
 |                                                                                                                 |
 | Subprocess                                    Code |            Number of events       |      sigma +- delta    |
 |                                                    |       Tried   Selected   Accepted |     (estimated) (mb)   |
 |                                                    |                                   |                        |
 |-----------------------------------------------------------------------------------------------------------------|
 |                                                    |                                   |                        |
 | f fbar -> gamma*/Z0                            221 |      140682      10000      10000 |   1.458e-06  7.715e-09 |
 |                                                    |                                   |                        |
 | sum                                                |      140682      10000      10000 |   1.458e-06  7.715e-09 |
 |                                                                                                                 |
 *-------  End PYTHIA Event and Cross Section Statistics ----------------------------------------------------------*

i.e. 1458.0 +- 7.7 pb.

Generating ditaus with Whizard

As explained in the dedicated Whizard section, to use whizard we need a Sindarin configuration file. To generate ditau events we will use the file Z_tautau.sin:

wget https://fccsw.web.cern.ch/tutorials/apr2023/tutorial1/Z_tautau.sin

and run it in a dedicate directory to not pollute the working one with the many files produced:

mkdir -p whizard; cd whizard;
whizard ../Z_tautau.sin

The output created by whizard is LHEf (Les Houches Event format); this is because the current build does not support writing HepMC; this may change in the future.

Exercise: look at produced LHEf file z_tautau.lhe: what did we notice?

The first lines of the LHEf file give the total cross-section: 1.508 +- 2 pb, which seems definitely higher than the others.

LHEf to EDM4hep conversion

In order to get the events in EDM4hep format, we exploit the fact that Pythia provides LHEf reader functionality. To activate that we will use Gaudi and a special .cmd file which considers the input LHEf input file as a Beam. This special .cmd is called p8_lhereader.cmd and it is available on the web:

cd ../cards
wget https://fccsw.web.cern.ch/tutorials/apr2023/tutorial1/p8_lhereader.cmd

Please note the lines

! 4) Read-in Les Houches Event file - alternative beam and process selection.
Beams:frameType = 4                      ! read info from a LHEF
Beams:LHEF = z_tautau.lhe                ! the LHEF to read from

This file needs to be edited to enter the exact locaton of the input file (it could also be a symlink to avoid always editng the file.

Also note the lines:

! Tau decays to mu nu_tau nu_mu (from pythia8)
15:onMode = off
15:onIfAny = 14

which will make decay the taus in pythia8

As steering we will use the file pythia.py.

Q: how will we run it from the whizard sub-directory? (hint: think of the conversion file)

Generating ditaus with KKMCee

As shown in the KKMCee section, event generation with the KKMCee is controlled through a configuration file. The interface available in key4hep allowed a generation of the configuration file through command line switches. Starting from the command line switches is therefore always a good option when no confguration file is available.

Currently, KKMCee does not have the option to save directly the events in EDM4hep format. In order to get there we need first to generate the events in HepMC format.

Generating HepMC events

Q: What are the commands (options) to generate 10000 ditau events and save them into the file gen/kk_ee_Ztautau_mumu_ecm91_10000.hepmc?

The remaining output files from the run are found in the KKMCee-<date>-<time> directory. In particular the file pro.output contains at the end information about the process cross-section.

In this example

tail -37 KKMCee-<date>-<time>/pro.output
tail -37 kk/KKMCee-24Apr2023-060444/pro.output
   *****************************
   ****   KKMCee   Finalize ****
   *****************************
********************************************************************************
*                                                                              *
*                   ****************************************                   *
*                   ******      KKMCee::Finalize      ******                   *
*                   ****************************************                   *
*   f_NevGen =      10000 =                          No. of generated events   *
*   XsPrimPb =       2700.8551   =                   Primary from Foam [pb]    *
*  FoamInteg =       1714.1189   =                   Crude from FOAM   [pb]    *
*         +- =    0.0015340174   =                   error                     *
*                   ****************************************                   *
*   <WtMain> =      0.54999872   =                   average WtMain            *
*         +- =    0.0014270066   =                   error abs.                *
*     XsMain =       1485.4669   =                   Xsection main [pb]        *
*         +- =    0.0070075399   =                   error absolute            *
*         +- =    0.0025945634   =                   error relative            *
*                   ********** More from WtMainMonit *******                   *
*      AveWt =      0.54999872   =                   average <WtMain>          *
*      ERela =    0.0025945634   =                   relative error            *
*      sigma =      0.38656078   =                   dispersion of WtMain      *
*   DB_WTmax =               4   =                   input WTmax               *
*      WtMax =       5.6197178   =                   maximum  WTmain           *
*      WtMin =               0   =                   mainimum WTmain           *
*      AvUnd =               0   =                   underflow                 *
*      AvOve =   3.8040121e-05   =                   overflow                  *
* AvOve/<Wt> =   6.9164016e-05   =                   relative: AvOve/AveWt     *
*       Ntot =           73381   =                   Ntot primary events       *
*       Nacc =           10000   =                   accepted events           *
*  Nacc/Ntot =      0.13627506   =                   acceptance rate           *
*       Nneg =               0   =                   WT<0 events               *
*       Nove =               2   =                   WT>WTmax events           *
*  Nove/Ntot =   2.7255012e-05   =                   Nove/Ntot                 *
*       Nzer =            1209   =                   WT=0 events               *
*                                                                              *
********************************************************************************

i.e the total ditau cross-section at 91.2 GeV from KKMCee is 1485.5±0.007 pb1485.5 \pm 0.007~\mathrm{pb}.

HepMC to EDM4hep conversion

In order to get the events in EDM4hep format, we will use Gaudi and the tools available in k4FWCore and k4Gen. We need a Gaudi steering file that reads the HepMC file and writes out the EDM4hep file. A minimal version of such a steering code is available on the tutorial reference page:

wget https://fccsw.web.cern.ch/tutorials/apr2023/tutorial1/hepmc2edm.py

Let’s see what it does: that is shown by the first line of the help function

k4run hepmc2edm.py -h
 -->  GenAlg  -->  HepMCToEDMConverter  -->  out
...
Dissection of hepmc2edm.py
Running hepmc2edm.py

Among the hepmc2edm switches relevant for the purpose are those controlling input an output files:

k4run hepmc2edm.py -h
...
  --GenAlg.HepMCFileReader.Filename [GENALG.HEPMCFILEREADER.FILENAME], --Filename.GenAlg.HepMCFileReader [GENALG.HEPMCFILEREADER.FILENAME]
                        Name of the HepMC file to read [HepMCFileReader]
...
  --out.filename [OUT.FILENAME], --filename.out [OUT.FILENAME]
                        Name of the file to create [PodioOutput]
...

Q: We would like the output file to be called kk_Ztautau_mumu_10000.e4h.root . Which command should we use for that?

Q: Can you explain why we need to pass the -n 10000 switch and how you could modify hepmc2edm.py to avoid that?

Note en passant that the EDM4hep file is much smaller than the HepMC one:

ls -lt
total 43032
-rw-r--r-- 1 ganis vboxsf  3661630 Oct 18  2022 kk_tautau_10000.e4h.root
-rw-r--r-- 1 ganis vboxsf     1232 Oct 18  2022 hepmc2edm.py
drwxr-xr-x 1 ganis vboxsf      288 Oct 18 16:12 KKMCee-18Oct2022-161012
-rw-r--r-- 1 ganis vboxsf 19584017 Oct 18 16:12 kk_tautau_10000.hepmc

Q: Can you explain why?

Q: How the cross-sections compare?

Looking at the produced files. Comparing distributions

The idea here is to look at some distributions, typically key for generators (angles, momenta). We take as example: acollinearity (of the initial taus, of the decaying products), momenta and cosinus of polar angles of the final 1-prompt products.

Looking the MCParticle class

Despite being ROOT files and the information stored in POD (Plain Old Data), the EDM4hep files are not easily usable, because interpreting the PODs requires the higher level PODIO / EDM4hep classes. This is what the helper functions available in FCCAnalyses, which depend of EDM4hep, do. They can be used to create flat ntuples, to be used for the analysis later on.

Building FCCAnalyses

FCCAnalyses is available at https://github.com/HEP-FCC/FCCAnalyses. FCCAnalysis, which is based on ROOT RDataFrame, changes regularly, almost daily. Therefore it is always good to rebuild the latest version. It is advised to do it in a separate directory, for example ../FCCAnalyses.

cd ..
git clone --branch pre-edm4hep1 https://github.com/HEP-FCC/FCCAnalyses.git
cd FCCAnalyses
source setup.sh
fccanalysis build -j 8
cd ../../tutorials1

It is mandatory to run setup after the build in the source directory.

Now we are ready to go.

Creating histograms with FCCAnalyses

At this purpose we will use the recently introduced build_graph attribute. The example is availble at histmaker_ttmm.py.

Dissection of histmaker_ttmm.py
Running histmaker_ttmm.py

The build_graph is part of the fccanalyses run:

fccanalysis run histmaker_ttmm.py

This should produce ROOT files with the histograms in ./outputs:

ls -lt outputs/
total 24
-rw-r--r--. 1 ganis sf 7386 Apr 24 18:01 kk_tautau_ecm91.root
-rw-r--r--. 1 ganis sf 7384 Apr 24 18:01 wz_tautau_ecm91.root
-rw-r--r--. 1 ganis sf 7399 Apr 24 18:01 p8_tautau_ecm91.root

Comparing distributions

FCCAnalyses provides the plots option to prepare some plots. A possible way to plot the histos is available at plots_ttmm.py, which can run as

fccanalysis plots plots_ttmm.py

with results available under plots.

Example of a result are: positive muon momentum, positive muon cosine theta, acollinearity of muons.

Possible conclusion of the exercise

Think of your own. Expand for a possible one.