Skip to content

Commit aee872d

Browse files
committed
External generator example for simple cocktails/gap gens
Providing a custom generator example that can serve as a template for generators using multiple internal o2::eventgen::Generator generators (cocktails, gap triggers, ...).
1 parent 23d985d commit aee872d

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Example of an implementation of an event generator
2+
// that alternates between 2 gun generators. Serves as example
3+
// to construct any meta-generator (such as cocktails) consisting
4+
// or using a pool of underlying o2::eventgen::Generators.
5+
6+
// Test is using #o2-sim-dpl-eventgen --nEvents 10 --generator external --configKeyValues "GeneratorExternal.fileName=${O2DPG_ROOT}/MC/config/examples/external/generator/SimpleCocktail.C;GeneratorExternal.funcName=getSimpleGap()"
7+
8+
namespace o2
9+
{
10+
namespace eventgen
11+
{
12+
13+
14+
/// A very simple gap generator alternating between 2 different particle guns
15+
class SimpleGap : public Generator
16+
{
17+
public:
18+
SimpleGap() {
19+
// put 2 different generators in the cocktail of generators
20+
gens.push_back(new o2::eventgen::BoxGenerator(22,10,-5,5,0,10,0,360));
21+
gens.push_back(new o2::eventgen::BoxGenerator(11,10,-5,5,0,10,0,360));
22+
}
23+
24+
~SimpleGap() = default;
25+
26+
Bool_t Init() override
27+
{
28+
// init all sub-gens
29+
for (auto gen : gens) {
30+
gen->Init();
31+
}
32+
addSubGenerator(0, "Gun 1"); // name the generators
33+
addSubGenerator(1, "Gun 2");
34+
return Generator::Init();
35+
}
36+
37+
Bool_t generateEvent() override
38+
{
39+
// here we call the individual gun generators in turn
40+
// (but we could easily call all of them to have cocktails)
41+
currentindex++;
42+
currentgen = gens[currentindex % 2];
43+
currentgen->generateEvent();
44+
// notify the sub event generator
45+
notifySubGenerator(currentindex % 2);
46+
return true;
47+
}
48+
49+
// We override this function to import the particles from the
50+
// underlying generators into **this** generator instance
51+
Bool_t importParticles() override
52+
{
53+
mParticles.clear(); // clear container of mother class
54+
currentgen->importParticles();
55+
std::copy(currentgen->getParticles().begin(), currentgen->getParticles().end(), std::back_insert_iterator(mParticles));
56+
57+
// we need to fix particles statuses --> need to enforce this on the importParticles level of individual generators
58+
for (auto& p : mParticles) {
59+
auto st = o2::mcgenstatus::MCGenStatusEncoding(p.GetStatusCode(), p.GetStatusCode()).fullEncoding;
60+
p.SetStatusCode(st);
61+
p.SetBit(ParticleStatus::kToBeDone, true);
62+
}
63+
64+
return true;
65+
}
66+
67+
private:
68+
int currentindex = -1;
69+
o2::eventgen::BoxGenerator* currentgen = nullptr;
70+
std::vector<o2::eventgen::BoxGenerator*> gens;
71+
};
72+
73+
} // namespace eventgen
74+
} // namespace o2
75+
76+
/** generator instance and settings **/
77+
78+
FairGenerator* getSimpleGap() {
79+
return new o2::eventgen::SimpleGap();
80+
}

0 commit comments

Comments
 (0)