Skip to content

Commit a358bf9

Browse files
authored
Fix: fix seeding in collision masker (AliceO2Group#4544)
1 parent 43bfa18 commit a358bf9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

PWGCF/FemtoDream/Tasks/femtoDreamCollisionMasker.cxx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
/// \brief Tasks creates bitmasks for femtodream collisions
1414
/// \author Anton Riedel, TU München, [email protected]
1515

16+
#include <cstdint>
1617
#include <vector>
1718
#include <bitset>
1819
#include <algorithm>
1920
#include <random>
21+
#include <chrono>
2022

2123
#include "fairlogger/Logger.h"
2224
#include "Framework/Configurable.h"
@@ -54,7 +56,7 @@ struct femoDreamCollisionMasker {
5456

5557
// configurable for downsampling
5658
Configurable<float> ConfDownsampling{"ConfDownsampling", -1., "Fraction of events to be used in mixed event sample. Factor should be between 0 and 1. Deactivate with negative value"};
57-
Configurable<uint> ConfSeed{"ConfSeed", 29012024, "Seed for downsampling"};
59+
Configurable<uint64_t> ConfSeed{"ConfSeed", 0, "Seed for downsampling. Set to 0 for using a seed unique in time."};
5860

5961
std::mt19937* rng = nullptr;
6062

@@ -94,8 +96,14 @@ struct femoDreamCollisionMasker {
9496
{
9597

9698
// seed rng for downsampling
97-
if (ConfSeed.value > 0) {
98-
rng = new std::mt19937(ConfSeed.value);
99+
if (ConfDownsampling.value > 0) {
100+
uint64_t randomSeed = 0;
101+
if (ConfSeed.value == 0) {
102+
randomSeed = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
103+
} else {
104+
randomSeed = ConfSeed.value;
105+
}
106+
rng = new std::mt19937(randomSeed);
99107
}
100108

101109
std::vector<std::string> MatchedWorkflows;
@@ -356,7 +364,7 @@ struct femoDreamCollisionMasker {
356364
bool UseInMixedEvent = true;
357365
std::uniform_real_distribution<> dist(0, 1);
358366

359-
if (ConfSeed.value > 0 && (1 - dist(*rng)) > ConfDownsampling.value) {
367+
if (ConfDownsampling.value > 0 && (1 - dist(*rng)) > ConfDownsampling.value) {
360368
UseInMixedEvent = false;
361369
}
362370

0 commit comments

Comments
 (0)