Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pythia8 seeding improvements #1695

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions MC/config/ALICE3/pythia8/generator_pythia8_ALICE3.C
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ using namespace Pythia8;
#endif

// Default pythia8 minimum bias generator

class GeneratorPythia8ALICE3 : public o2::eventgen::GeneratorPythia8
{
public:
Expand All @@ -18,20 +17,16 @@ public:
GeneratorPythia8ALICE3() {

char* alien_proc_id = getenv("ALIEN_PROC_ID");
uint64_t seedFull;
uint64_t seed = 0;
int64_t seed = 0;

if (alien_proc_id != NULL) {
seedFull = static_cast<uint64_t>(atol(alien_proc_id));
for(int ii=0; ii<29; ii++) // there might be a cleaner way but this will work
seed |= ((seedFull) & (static_cast<uint64_t>(1) << static_cast<uint64_t>(ii)));
LOG(info) << "Value of ALIEN_PROC_ID: " << seedFull <<" truncated to 0-28 bits: "<<seed<<endl;
seed = static_cast<int64_t>(atol(alien_proc_id));
} else {
LOG(info) << "Unable to retrieve ALIEN_PROC_ID";
LOG(info) << "Setting seed to 0 (random)";
seed = 0;
}
mPythia.readString("Random:seed = "+std::to_string(static_cast<int>(seed)));
setInitialSeed(seed);
}

/// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));


// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -70,13 +62,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBJpsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ GeneratorBeautyToMu_EvtGenFwdY(double rapidityMin = -4.3, double rapidityMax = -
}
if(forcedecay) gen->SetForceDecay(kEvtSemiMuonic);
else gen->SetForceDecay(kEvtAll);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -70,13 +61,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiDiElectron);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -68,13 +61,6 @@ FairGenerator*
printf("PDG %d \n", std::stoi(spdg));
}
gen->SetForceDecay(kEvtBPsiDiMuon);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ FairGenerator*
gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELE.DEC", pathO2.Data()));
// print debug
// gen->PrintDebug();
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));


return gen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ GeneratorCharmToMu_EvtGenFwdY(double rapidityMin = -4.3, double rapidityMax = -2
printf("PDG %d \n",std::stoi(spdg));
}
gen->SetForceDecay(kEvtSemiMuonic);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public:

protected:

Bool_t generateEvent() override
Bool_t generateEvent() override
{
// reset event
bool genOk = false;
Expand All @@ -90,13 +90,15 @@ Bool_t generateEvent() override
return true;
}

Bool_t Init() override
Bool_t Init() override
{
if(mConfigMBdecays.Contains("cfg")) pythiaMBgen.readFile(mConfigMBdecays.Data());
GeneratorPythia8::Init();
pythiaMBgen.init();
return true;
}
if(mConfigMBdecays.Contains("cfg")) {
pythiaMBgen.readFile(mConfigMBdecays.Data());
}
GeneratorPythia8::Init();
pythiaMBgen.init();
return true;
}

// search for q-qbar mother with at least one q in a selected rapidity window
bool findHeavyQuarkPair(Pythia8::Event& event)
Expand Down Expand Up @@ -181,14 +183,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -219,14 +213,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiElectron);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -261,15 +247,7 @@ FairGenerator*
//gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELE.DEC", pathO2.Data()));
gen->SetDecayTable(Form("%s/BPLUSTOKAONJPSITOELEALLMODES.DEC", pathO2.Data())); // decay table including decay modes for correlated background
// print debug
// gen->PrintDebug();
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// gen->PrintDebug();
return gen;
}

Expand Down Expand Up @@ -298,14 +276,6 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBJpsiDiMuon);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

Expand Down Expand Up @@ -337,17 +307,8 @@ FairGenerator*
}
gen->SetForceDecay(kEvtBPsiAndJpsiDiMuon);

// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));

// print debug
// gen->PrintDebug();

return gen;
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ GeneratorBeautyToEle_EvtGen(double rapidityMin = -2., double rapidityMax = 2., b
if(forcedecay) gen->SetForceDecay(kEvtSemiElectronic);
else gen->SetForceDecay(kEvtAll);
//}
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ GeneratorCharmToEle_EvtGen(double rapidityMin = -2., double rapidityMax = 2., bo
printf("PDG %d \n",std::stoi(spdg));
}
gen->SetForceDecay(kEvtSemiElectronic);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ GeneratorHFToEleFull_EvtGen(bool forcedecay = true, bool allHF = true)
}
if(forcedecay) gen->SetForceDecay(kEvtSemiElectronic);
else gen->SetForceDecay(kEvtAll);
// set random seed
gen->readString("Random:setSeed on");
uint random_seed;
unsigned long long int random_value = 0;
ifstream urandom("/dev/urandom", ios::in|ios::binary);
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
gen->readString(Form("Random:seed = %d", random_value % 900000001));
// print debug
// gen->PrintDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,5 @@ class GeneratorPythia8GapTriggeredLFee : public GeneratorPythia8 {
// Predefined generators: // this function should be called in ini file.
FairGenerator *GeneratorPythia8GapTriggeredLFee_ForEM(int inputTriggerRatio = 5, float yMin=-1.2, float yMax=1.2, int nPart = 1, int mode = -1) {
auto myGen = new GeneratorPythia8GapTriggeredLFee(inputTriggerRatio, yMin, yMax, nPart, mode);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
return myGen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,5 @@ class GeneratorPythia8GapTriggeredLFgamma : public GeneratorPythia8 {
// Predefined generators: // this function should be called in ini file.
FairGenerator *GeneratorPythia8GapTriggeredLFgamma_ForEM(int inputTriggerRatio = 5, float yMin=-1.2, float yMax=1.2, int nPart = 1) {
auto myGen = new GeneratorPythia8GapTriggeredLFgamma(inputTriggerRatio, yMin, yMax, nPart);
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
myGen->readString("Random:setSeed on");
myGen->readString("Random:seed " + std::to_string(seed));
return myGen;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ namespace eventgen {
class DecayerPythia8ForceDecays : public DecayerPythia8 {
public:
DecayerPythia8ForceDecays(){
mPythia.readString("Random:setSeed = on");
char* alien_proc_id = getenv("ALIEN_PROC_ID");
int seed;
long seed;
if (alien_proc_id != NULL) {
seed = atoi(alien_proc_id);
LOG(info) << "Seed for DecayerPythia8 set to ALIEN_PROC_ID: " << seed;
Expand All @@ -21,7 +20,7 @@ public:
LOG(info) << "Setting seed for DecayerPyhtia8 to 0 (random)";
seed = 0;
}
mPythia.readString("Random:seed = "+std::to_string(seed));
setInitialSeed(seed);
}
~DecayerPythia8ForceDecays() = default;

Expand Down Expand Up @@ -109,18 +108,17 @@ class GeneratorPythia8ForcedDecays : public GeneratorPythia8 {

public:
GeneratorPythia8ForcedDecays(){
mPythia.readString("Random:setSeed = on");
char* alien_proc_id = getenv("ALIEN_PROC_ID");
int seed;
long seed;
if (alien_proc_id != NULL) {
seed = atoi(alien_proc_id);
LOG(info) << "Seed for GeneratorPythia8 set to ALIEN_PROC_ID: " << seed;
LOG(info) << "Seed for DecayerPythia8 set to ALIEN_PROC_ID: " << seed;
} else {
LOG(info) << "Unable to retrieve ALIEN_PROC_ID";
LOG(info) << "Setting seed for GeneratorPyhtia8 to 0 (random)";
LOG(info) << "Setting seed for DecayerPyhtia8 to 0 (random)";
seed = 0;
}
mPythia.readString("Random:seed = "+std::to_string(seed));
setInitialSeed(seed);
}
~GeneratorPythia8ForcedDecays() = default;

Expand Down
Loading