Skip to content

Commit 4e1eef2

Browse files
committed
Simulation example of embedding of adaptive Pythia8 signals
1 parent 7753bb7 commit 4e1eef2

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// \author R+Preghenella - April 2020
2+
3+
// Example of an implementation of an external event generator
4+
// that is used and adapts it behavior in an embedding scenario.
5+
//
6+
// usage: o2sim -g external --configKeyValues 'GeneratorExternal.fileName=adaptive_pythia8.C;GeneratorExternal.funcName="adaptive_pythia8(\"0.001 * x\")"'
7+
8+
using namespace o2::eventgen;
9+
10+
class Adaptive_Pythia8 : public GeneratorPythia8
11+
{
12+
public:
13+
Adaptive_Pythia8(const char *formula = "0.01 * x") :
14+
GeneratorPythia8(), mFormula("formula", formula) { };
15+
~Adaptive_Pythia8() = default;
16+
17+
// update the number of events to be generated
18+
// according to background primaries and formula
19+
void notifyEmbedding(const FairMCEventHeader *bkgHeader) override {
20+
auto nPrimaries = bkgHeader->GetNPrim();
21+
mEvents = mFormula.Eval(nPrimaries);
22+
};
23+
24+
// generate event and import particles
25+
// multiple times according to background and formula
26+
Bool_t generateEvent() override {
27+
for (int iev = 0; iev < mEvents; ++iev) {
28+
if (!GeneratorPythia8::generateEvent()) return false;
29+
if (!GeneratorPythia8::importParticles()) return false;
30+
}
31+
return true; };
32+
33+
// override this function to avoid importing particles
34+
// of the last event again as this is called by the base class
35+
Bool_t importParticles() override { return true; }
36+
37+
private:
38+
39+
int mEvents = 1;
40+
TFormula mFormula;
41+
42+
};
43+
44+
FairGenerator*
45+
adaptive_pythia8(const char *formula = "0.01 * x")
46+
{
47+
std::cout << " --- adaptive_pythia8 initialising with formula: " << formula << std::endl;
48+
auto py8 = new Adaptive_Pythia8(formula);
49+
return py8;
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### The setup uses an external even generator which is configured
2+
### to generate as many Pythia8 events according to a formula
3+
### The formula is passed via the function call, where x if the
4+
### number of primary particles in the background event
5+
6+
[GeneratorExternal]
7+
fileName=${O2DPG_ROOT}/MC/config/examples/external/generator/adaptive_pythia8.C
8+
funcName=adaptive_pythia8("0.002 * x")
9+
10+
### The external generator derives from GeneratorPythia8.
11+
### This part configures the underlying Pythia8 configuration.
12+
13+
[GeneratorPythia8]
14+
config = ${O2DPG_ROOT}/MC/config/common/pythia8/generator/pythia8_inel.cfg
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
### This script run the simulation of signal embedding into a heavy-ion background.
4+
### First the background is generated with Pythia8/Angantyr model and basic settings.
5+
### The signal generation is configured to be embedded into the background (--embedIntoFile).
6+
### The signal event generator is an external event generator which implements adaptive
7+
### features where the number of events to be injected depends on the characteristics
8+
### of the background.
9+
### The details are defined in the INI config files (--configFile).
10+
11+
set -x
12+
13+
MODULES="PIPE ITS TPC"
14+
BKGEVENTS=5
15+
SIGEVENTS=20
16+
NWORKERS=8
17+
18+
# generate background
19+
20+
o2-sim -j ${NWORKERS} -n ${BKGEVENTS} -g pythia8hi -m ${MODULES} -o bkg \
21+
--configFile ${O2DPG_ROOT}/MC/config/common/ini/basic.ini \
22+
> logbkg 2>&1
23+
24+
# embed signal into background
25+
26+
o2-sim -j ${NWORKERS} -n ${SIGEVENTS} -g external -m ${MODULES} -o sgn \
27+
--configFile ${O2DPG_ROOT}/MC/config/examples/ini/adaptive_pythia8.ini \
28+
--embedIntoFile bkg_Kine.root \
29+
> logsgn 2>&1

0 commit comments

Comments
 (0)