Skip to content

Commit 6d50485

Browse files
authored
MC/config/PWGEM: add Generator.C and ini for LF->ee/gamma in PWGEM (#1583)
1 parent 66b2973 commit 6d50485

File tree

7 files changed

+729
-0
lines changed

7 files changed

+729
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include <vector>
2+
3+
using namespace o2::eventgen;
4+
5+
// This is to evaluate MC efficiency. Not for comparison between data and LMEE cocktail.
6+
class GeneratorCocktailWithGap : public Generator
7+
{
8+
public:
9+
GeneratorCocktailWithGap() : Generator() {
10+
lGeneratedEvents = 0;
11+
lInverseTriggerRatio = 1;
12+
mGeneratorsSig->clear();
13+
mGeneratorsGap->clear();
14+
mGeneratorsSig->shrink_to_fit();
15+
mGeneratorsGap->shrink_to_fit();
16+
};
17+
18+
GeneratorCocktailWithGap(int lInputTriggerRatio) : Generator() {
19+
lGeneratedEvents = 0;
20+
lInverseTriggerRatio = lInputTriggerRatio;
21+
mGeneratorsSig->clear();
22+
mGeneratorsGap->clear();
23+
mGeneratorsSig->shrink_to_fit();
24+
mGeneratorsGap->shrink_to_fit();
25+
};
26+
27+
~GeneratorCocktailWithGap() = default;
28+
29+
// at init we init all generators
30+
bool Init() override
31+
{
32+
for (auto& g : *mGeneratorsSig) {
33+
g->Init();
34+
}
35+
for (auto& g : *mGeneratorsGap) {
36+
g->Init();
37+
}
38+
39+
Generator::Init();
40+
return true;
41+
};
42+
43+
void setInputTriggerRatio(int lInputTriggerRatio) { lInverseTriggerRatio = lInputTriggerRatio; };
44+
45+
// call generate method for all generators
46+
bool generateEvent() override
47+
{
48+
// Simple straightforward check to alternate generators
49+
if (lGeneratedEvents % lInverseTriggerRatio == 0) {
50+
// Generate event of interest
51+
printf("generate signal event %lld\n", lGeneratedEvents);
52+
for (auto& g : *mGeneratorsSig){
53+
printf("generate signal event %s\n", g->GetName());
54+
bool isOK = g->generateEvent();
55+
}
56+
} else {
57+
// Generate gap event
58+
printf("generate gap event %lld\n", lGeneratedEvents);
59+
for (auto& g : *mGeneratorsGap){
60+
printf("generate gap event %s\n", g->GetName());
61+
bool isOK = g->generateEvent();
62+
}
63+
}
64+
lGeneratedEvents++;
65+
return true;
66+
};
67+
68+
// at importParticles we add particles to the output particle vector
69+
bool importParticles() override
70+
{
71+
//note that lGeneratedEvents++ is called in generateEvent();
72+
if ((lGeneratedEvents-1) % lInverseTriggerRatio == 0) {
73+
for (auto& g : *mGeneratorsSig) {
74+
int nPart = mParticles.size();
75+
g->importParticles();
76+
printf("generator %s : ngen = %zu\n", g->GetName(), g->getParticles().size());
77+
for (auto p : g->getParticles()) {
78+
mParticles.push_back(p);
79+
auto& pEdit = mParticles.back();
80+
o2::mcutils::MCGenHelper::encodeParticleStatusAndTracking(pEdit);
81+
82+
if (pEdit.GetFirstMother() > -1){
83+
pEdit.SetFirstMother(pEdit.GetFirstMother() + nPart);
84+
}
85+
if (pEdit.GetSecondMother() > -1){
86+
pEdit.SetLastMother(pEdit.GetSecondMother() + nPart);
87+
}
88+
if (pEdit.GetFirstDaughter() > -1){
89+
pEdit.SetFirstDaughter(pEdit.GetFirstDaughter() + nPart);
90+
}
91+
if (pEdit.GetLastDaughter() > -1){
92+
pEdit.SetLastDaughter(pEdit.GetLastDaughter() + nPart);
93+
}
94+
}
95+
g->clearParticles();
96+
}
97+
} else {
98+
for (auto& g : *mGeneratorsGap) {
99+
int nPart = mParticles.size();
100+
g->importParticles();
101+
printf("generator %s : ngen = %zu\n", g->GetName(), g->getParticles().size());
102+
for (auto p : g->getParticles()) {
103+
mParticles.push_back(p);
104+
auto& pEdit = mParticles.back();
105+
o2::mcutils::MCGenHelper::encodeParticleStatusAndTracking(pEdit);
106+
107+
if (pEdit.GetFirstMother() > -1){
108+
pEdit.SetFirstMother(pEdit.GetFirstMother() + nPart);
109+
}
110+
if (pEdit.GetSecondMother() > -1){
111+
pEdit.SetLastMother(pEdit.GetSecondMother() + nPart);
112+
}
113+
if (pEdit.GetFirstDaughter() > -1){
114+
pEdit.SetFirstDaughter(pEdit.GetFirstDaughter() + nPart);
115+
}
116+
if (pEdit.GetLastDaughter() > -1){
117+
pEdit.SetLastDaughter(pEdit.GetLastDaughter() + nPart);
118+
}
119+
}
120+
g->clearParticles();
121+
}
122+
}
123+
124+
//maybe, it is better to implement mParticle.shrink_to_fit() in Generator::clearParticles();
125+
126+
return true;
127+
};
128+
129+
void addGeneratorSig(Generator* gen, int ntimes = 1) {
130+
for (int in = 0; in < ntimes; in++){
131+
mGeneratorsSig->push_back(gen);
132+
}
133+
};
134+
void addGeneratorGap(Generator* gen, int ntimes = 1) {
135+
for (int in = 0; in < ntimes; in++){
136+
mGeneratorsGap->push_back(gen);
137+
}
138+
};
139+
140+
std::vector<Generator*>* getGeneratorsSig() { return mGeneratorsSig; };
141+
std::vector<Generator*>* getGeneratorsGap() { return mGeneratorsGap; };
142+
143+
private:
144+
// Control gap-triggering
145+
Long64_t lGeneratedEvents;
146+
int lInverseTriggerRatio;
147+
std::vector<Generator*>* mGeneratorsSig = new std::vector<Generator*>(); // vector of Generator for signal
148+
std::vector<Generator*>* mGeneratorsGap = new std::vector<Generator*>(); // vector of Generator for gap
149+
};

0 commit comments

Comments
 (0)