Skip to content

Commit 233330f

Browse files
committed
Fix LF resonance gap injection and add phi channel
1 parent f3990a8 commit 233330f

3 files changed

Lines changed: 104 additions & 76 deletions

File tree

MC/config/PWGLF/pythia8/generator/resonancelistgun_width_inj.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
"rapidityMax": 1.2,
1111
"genDecayed": true
1212
},
13+
"phi(1020)" : {
14+
"pdg": 333,
15+
"n": 10,
16+
"ptMin": 0.0,
17+
"ptMax": 20,
18+
"etaMin": -1.2,
19+
"etaMax": 1.2,
20+
"rapidityMin": -1.2,
21+
"rapidityMax": 1.2,
22+
"genDecayed": true
23+
},
1324
"K1(1270)+": {
1425
"pdg": 10323,
1526
"n": 10,

MC/config/PWGLF/pythia8/generator/resonances_width.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
# 9010221:oneChannel = 1 1.000 0 211 -211
1111
9010221:onIfMatch = 211 -211
1212

13+
### phi(1020)
14+
# 333:all = phi phi 3 0 0 1.0195 0.0042 1.0091 1.0599 0
15+
333:onMode = off
16+
333:onIfMatch = 11 -11
17+
1318
# ### Delta(1232)++
1419
# 2224:all = DeltaPlusPlus DeltaPlusPlusbar 4 6 0 1.2320 0.1170 1.0778 2.4020 0
1520
2224:onMode = off

MC/config/PWGLF/pythia8/generator_pythia8_LF_rapidity_width.C

Lines changed: 88 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -191,31 +191,38 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
191191
/// Destructor
192192
~GeneratorPythia8LFRapidity() = default;
193193

194+
bool Init() override
195+
{
196+
// Follow the PWGHF gap-trigger convention and persist the event class in
197+
// MCEventHeader::subGeneratorId. The AOD producer exposes this through
198+
// mcCollision.getSubGeneratorId().
199+
addSubGenerator(kSubGeneratorMinimumBias, "Minimum bias");
200+
addSubGenerator(kSubGeneratorLFSignal, "LF signal");
201+
return o2::eventgen::GeneratorPythia8::Init();
202+
}
203+
194204
//__________________________________________________________________
195205
Bool_t generateEvent() override
196206
{
207+
// Follow the gap-trigger convention used by PWGHF/PWGDQ: a ratio N
208+
// produces signal events at 0, N, 2N, ... and minimum-bias events in
209+
// between. Ratios 0 and 1 both mean signal in every event.
210+
mDoSignalThisEvent = isSignalEvent();
211+
notifySubGenerator(mDoSignalThisEvent ? kSubGeneratorLFSignal : kSubGeneratorMinimumBias);
212+
197213
if (!mUseTriggering) { // Injected mode: Embedding into MB
198214
// 1. Generate Background (MB)
199-
// LOG(info) << "Generating background event " << mEventCounter;
200-
201215
bool lGenerationOK = false;
202216
while (!lGenerationOK) {
203217
lGenerationOK = pythiaObjectMinimumBias.next();
204218
}
205219
copyMinimumBiasEventForInjection();
206220

207-
// 2. Determine if we inject specific particles (Gap logic)
208-
bool doInjection = true;
209-
if (mGapBetweenInjection > 0) {
210-
if (mGapBetweenInjection == 1 && mEventCounter % 2 == 0) {
211-
doInjection = false;
212-
} else if (mEventCounter % mGapBetweenInjection != 0) {
213-
doInjection = false;
214-
}
215-
}
216-
217-
if (!doInjection) {
218-
LOG(info) << "Skipping injection for event " << mEventCounter;
221+
// Keep the generated minimum-bias event on gap events. It must still be
222+
// imported in importParticles(), otherwise o2-sim sees an empty event
223+
// and retries until it obtains another injected event.
224+
if (!mDoSignalThisEvent) {
225+
LOG(info) << "Generating minimum-bias gap event " << mEventCounter;
219226
return true;
220227
}
221228
}
@@ -230,7 +237,6 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
230237
mConfigToUse = mOneInjectionPerEvent ? static_cast<int>(gRandom->Uniform(0.f, getNGuns())) : -1;
231238
LOG(info) << "Using configuration " << mConfigToUse << " out of " << getNGuns() << ", of which " << mGunConfigs.size() << " are transport decayed and " << mGunConfigsGenDecayed.size() << " are generator decayed";
232239

233-
bool injectedForThisEvent = false;
234240
int nConfig = mGunConfigs.size(); // We start counting from the configurations of the transport decayed particles
235241
for (const ConfigContainer& cfg : mGunConfigsGenDecayed) {
236242
nConfig++;
@@ -239,10 +245,8 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
239245
}
240246
LOG(info) << "Using config container ";
241247
cfg.print();
242-
if (mUseTriggering) { // Do the triggering
243-
bool doSignal{mEventCounter % (mGapBetweenInjection + 1) == 0}; // Do signal or gap
244-
245-
if (doSignal) {
248+
if (mUseTriggering) { // Do the triggering
249+
if (mDoSignalThisEvent) {
246250
LOG(info) << "Generating triggered signal event for particle";
247251
cfg.print();
248252
bool satisfiesTrigger = false;
@@ -347,8 +351,6 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
347351

348352
mPythia.event.append(p);
349353
}
350-
351-
injectedForThisEvent = true;
352354
}
353355

354356
// For purely trivial injection (no generator decay needed in loop or just transport decay), we still might have injection flag
@@ -369,66 +371,67 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
369371
//__________________________________________________________________
370372
Bool_t importParticles() override
371373
{
372-
if (!mUseTriggering) { // If the triggering is used we handle the the gap when generating the signal
373-
if (mGapBetweenInjection > 0) {
374-
if (mGapBetweenInjection == 1 && mEventCounter % 2 == 0) {
375-
LOG(info) << "Skipping importParticles event " << mEventCounter++;
376-
return true;
377-
} else if (mEventCounter % mGapBetweenInjection != 0) {
378-
LOG(info) << "Skipping importParticles event " << mEventCounter++;
379-
return true;
380-
}
381-
}
382-
}
383-
LOG(info) << "importParticles " << mEventCounter++;
384-
GeneratorPythia8::importParticles();
385-
int nConfig = 0;
386-
for (const ConfigContainer& cfg : mGunConfigs) {
387-
nConfig++;
388-
if (mConfigToUse >= 0 && (nConfig - 1) != mConfigToUse) {
389-
continue;
390-
}
391-
LOGF(info, "Injecting %i particles with PDG %i, pT in [%f, %f], %s in [%f, %f]", cfg.mNInject, cfg.mPdg, cfg.mPtMin, cfg.mPtMax, (mUseRapidity ? "rapidity" : "eta"), cfg.mMin, cfg.mMax);
374+
LOG(info) << "importParticles " << mEventCounter << " (" << (mDoSignalThisEvent ? "signal" : "minimum bias") << ")";
392375

393-
for (int i{0}; i < cfg.mNInject; ++i) {
394-
const double pt = gRandom->Uniform(cfg.mPtMin, cfg.mPtMax);
395-
const double eta = gRandom->Uniform(cfg.mMin, cfg.mMax);
396-
const double phi = gRandom->Uniform(0, TMath::TwoPi());
397-
const double px{pt * std::cos(phi)};
398-
const double py{pt * std::sin(phi)};
399-
const double mass = sampleMass(cfg);
400-
double pz = 0;
401-
double et = 0;
376+
// Always import the Pythia event. On gap events this is the minimum-bias
377+
// event prepared in generateEvent().
378+
if (!GeneratorPythia8::importParticles()) {
379+
return false;
380+
}
402381

403-
if (mUseRapidity) {
404-
const double mT = std::sqrt(mass * mass + pt * pt);
405-
pz = mT * std::sinh(eta);
406-
et = mT * std::cosh(eta);
407-
} else {
408-
pz = pt * std::sinh(eta);
409-
const double p = pt * std::cosh(eta);
410-
et = std::sqrt(p * p + mass * mass);
382+
// Generator-decayed particles were already merged into mPythia.event in
383+
// generateEvent(). Append transport-decayed gun particles only on signal
384+
// events in injection mode.
385+
if (!mUseTriggering && mDoSignalThisEvent) {
386+
int nConfig = 0;
387+
for (const ConfigContainer& cfg : mGunConfigs) {
388+
nConfig++;
389+
if (mConfigToUse >= 0 && (nConfig - 1) != mConfigToUse) {
390+
continue;
411391
}
392+
LOGF(info, "Injecting %i particles with PDG %i, pT in [%f, %f], %s in [%f, %f]", cfg.mNInject, cfg.mPdg, cfg.mPtMin, cfg.mPtMax, (mUseRapidity ? "rapidity" : "eta"), cfg.mMin, cfg.mMax);
393+
394+
for (int i{0}; i < cfg.mNInject; ++i) {
395+
const double pt = gRandom->Uniform(cfg.mPtMin, cfg.mPtMax);
396+
const double eta = gRandom->Uniform(cfg.mMin, cfg.mMax);
397+
const double phi = gRandom->Uniform(0, TMath::TwoPi());
398+
const double px{pt * std::cos(phi)};
399+
const double py{pt * std::sin(phi)};
400+
const double mass = sampleMass(cfg);
401+
double pz = 0;
402+
double et = 0;
403+
404+
if (mUseRapidity) {
405+
const double mT = std::sqrt(mass * mass + pt * pt);
406+
pz = mT * std::sinh(eta);
407+
et = mT * std::cosh(eta);
408+
} else {
409+
pz = pt * std::sinh(eta);
410+
const double p = pt * std::cosh(eta);
411+
et = std::sqrt(p * p + mass * mass);
412+
}
412413

413-
// TParticle::TParticle(Int_t pdg,
414-
// Int_t status,
415-
// Int_t mother1, Int_t mother2,
416-
// Int_t daughter1, Int_t daughter2,
417-
// Double_t px, Double_t py, Double_t pz, Double_t etot,
418-
// Double_t vx, Double_t vy, Double_t vz, Double_t time)
419-
420-
mParticles.push_back(TParticle(cfg.mPdg,
421-
MCGenStatusEncoding(1, 1).fullEncoding,
422-
-1, -1,
423-
-1, -1,
424-
px, py, pz, et,
425-
0., 0., 0., 0.));
426-
// make sure status code is encoded properly. Transport flag will be set by default and we have nothing
427-
// to do since all pushed particles should be tracked.
428-
o2::mcutils::MCGenHelper::encodeParticleStatusAndTracking(mParticles.back());
414+
// TParticle::TParticle(Int_t pdg,
415+
// Int_t status,
416+
// Int_t mother1, Int_t mother2,
417+
// Int_t daughter1, Int_t daughter2,
418+
// Double_t px, Double_t py, Double_t pz, Double_t etot,
419+
// Double_t vx, Double_t vy, Double_t vz, Double_t time)
420+
421+
mParticles.push_back(TParticle(cfg.mPdg,
422+
MCGenStatusEncoding(1, 1).fullEncoding,
423+
-1, -1,
424+
-1, -1,
425+
px, py, pz, et,
426+
0., 0., 0., 0.));
427+
// make sure status code is encoded properly. Transport flag will be set by default and we have nothing
428+
// to do since all pushed particles should be tracked.
429+
o2::mcutils::MCGenHelper::encodeParticleStatusAndTracking(mParticles.back());
430+
}
429431
}
430-
nConfig++;
431432
}
433+
434+
mEventCounter++;
432435
if (mVerbose) {
433436
LOG(info) << "Printing particles that are appended";
434437
int n = 0;
@@ -576,6 +579,14 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
576579
void setVerbose(bool verbose = true) { mVerbose = verbose; }
577580

578581
private:
582+
static constexpr int kSubGeneratorMinimumBias = 0;
583+
static constexpr int kSubGeneratorLFSignal = 1;
584+
585+
bool isSignalEvent() const
586+
{
587+
return mGapBetweenInjection <= 1 || mEventCounter % mGapBetweenInjection == 0;
588+
}
589+
579590
void copyMinimumBiasEventForInjection()
580591
{
581592
mPythia.event = pythiaObjectMinimumBias.event;
@@ -631,12 +642,13 @@ class GeneratorPythia8LFRapidity : public o2::eventgen::GeneratorPythia8
631642
// Configuration
632643
const bool mOneInjectionPerEvent = true; // if true, only one injection per event is performed, i.e. if multiple PDG (including antiparticles) are requested to be injected only one will be done per event
633644
const bool mUseTriggering = false; // if true, use triggering instead of injection
634-
const int mGapBetweenInjection = 0; // Gap between two signal events. 0 means injection at every event
645+
const int mGapBetweenInjection = 0; // 0/1: signal every event; N>1: signal every Nth event
635646
const bool mUseRapidity = false; // if true, use rapidity instead of eta
636647

637648
// Running variables
638649
int mConfigToUse = -1; // Index of the configuration to use
639650
int mEventCounter = 0; // Event counter
651+
bool mDoSignalThisEvent = true;
640652
bool mVerbose = true; // Verbosity flag
641653

642654
std::vector<ConfigContainer> mGunConfigs; // List of gun configurations to use

0 commit comments

Comments
 (0)