File tree Expand file tree Collapse file tree 4 files changed +79
-0
lines changed
Expand file tree Collapse file tree 4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ /// \author Marco Giacalone - March 2025
2+
3+ // A simple wrapper and demonstrator around Pythia8 for extracting HepMC3 files.
4+
5+ #include "Pythia8/Pythia.h"
6+ #include "Pythia8Plugins/HepMC3.h"
7+
8+ using namespace o2 ::eventgen ;
9+
10+ class HepMC3_Pythia8Wrapper : public GeneratorPythia8
11+ {
12+ public :
13+ HepMC3_Pythia8Wrapper (std ::string filename = "pythia8.hepmc" ) : GeneratorPythia8 (), mFileName (filename ) {
14+ // HepMC conversion object.
15+ mToHepMC = std ::make_unique < Pythia8 ::Pythia8ToHepMC > ();
16+ mToHepMC -> setNewFile ((filename == "" ? "pythia.hepmc" : filename ));
17+ };
18+ ~HepMC3_Pythia8Wrapper () = default ;
19+
20+ bool importParticles () override
21+ {
22+ // events are written after the importParticles step
23+ // since some filtering is happening there
24+ auto ret = GeneratorPythia8 ::importParticles ();
25+ if (ret ) {
26+ LOG (info ) << "Writing event to HepMC3 format" ;
27+ mToHepMC -> writeNextEvent (mPythia );
28+ }
29+ return ret ;
30+ };
31+
32+ private :
33+ std ::string mFileName = "pythia8.hepmc" ;
34+ std ::unique_ptr < Pythia8 ::Pythia8ToHepMC > mToHepMC ;
35+ };
36+
37+ FairGenerator *
38+ hepmc_pythia8 (std ::string filename = "pythia8.hepmc" )
39+ {
40+ std ::cout << "HepMC3_Pythia8Wrapper initialising with filename: " << filename << std ::endl ;
41+ auto py8 = new HepMC3_Pythia8Wrapper (filename );
42+ return py8 ;
43+ }
Original file line number Diff line number Diff line change 1+ <!-- doxy
2+ \page refrunSimExamplesPythiaHepMCWrapper Example showing easy HepMC extraction using GeneratorPythia8
3+ /doxy -->
4+
5+ This example demonstrates how we can extend GeneratorPythia8 in a user-defined macro (or external generator),
6+ to achieve additional HepMC3 export of generated Pythia8 events.
7+
8+ The example provides a small utility for poeple in need to obtain HepMC files from Pythia8.
9+ Note that many other methods to achieve this are possible (See original Pythia8 example).
10+
11+ The example provides:
12+
13+ - The external generator implementation ` Pythia8HepMC3.C `
14+ - a ` run.sh ` script demonstrating it's usage and a check feeding back the generated hepmc into the simulation
15+
16+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ #
4+ # Script doing Pythia8 event generation and writing these events into HepMC3 files
5+ # (next to generating the usual MCTrack kinematics output).
6+ #
7+ # The script also performs a second event generation based on the generated HepMC3 files.
8+ # In principle it should yield identical kinematics files.
9+ #
10+
11+ NEVENTS=1000
12+ SEED=11
13+
14+ o2-sim -j 1 -g external --configKeyValues ' GeneratorExternal.fileName=Pythia8HepMC3.C;GeneratorExternal.funcName=hepmc_pythia8("skimmed.hepmc");GeneratorPythia8.config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg' --seed ${SEED} --noGeant -o pythia8_skimmed -n ${NEVENTS}
15+ o2-sim -j 1 -g external --configKeyValues ' GeneratorExternal.fileName=Pythia8HepMC3.C;GeneratorExternal.funcName=hepmc_pythia8("unskimmed.hepmc");GeneratorPythia8.config=${O2_ROOT}/share/Generators/egconfig/pythia8_inel.cfg;GeneratorPythia8.includePartonEvent=true' --seed ${SEED} --noGeant -o pythia8_unskimmed -n ${NEVENTS}
16+
17+ # propagate generated hepmc file; it should produce the same kinematics as the original Pythia8
18+ o2-sim -j 1 -g hepmc --configKeyValues=" GeneratorFileOrCmd.fileNames=skimmed.hepmc" --vertexMode kNoVertex --noGeant -o fromhepmc_skimmed -n ${NEVENTS} --seed ${SEED}
19+ o2-sim -j 1 -g hepmc --configKeyValues=" GeneratorFileOrCmd.fileNames=unskimmed.hepmc" --vertexMode kNoVertex --noGeant -o fromhepmc_unskimmed -n ${NEVENTS} --seed ${SEED}
Original file line number Diff line number Diff line change 66
77<!-- doxy
88* \subpage refrunSimExamplesPythia8
9+ * \subpage refrunSimExamplesPythiaHepMCWrapper
910* \subpage refrunSimExamplesHF_Embedding_Pythia8
1011* \subpage refrunSimExamplesSignal_ImpactB
1112* \subpage refrunSimExamplesTrigger_ImpactB_Pythia8
You can’t perform that action at this time.
0 commit comments