Skip to content

Commit 194ecdd

Browse files
sawenzelnoferini
authored andcommitted
Seeding improvements of digitizers
Allows for fully reproducible digitization, given same seed.
1 parent d08317f commit 194ecdd

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Common/SimConfig/include/SimConfig/DigiParams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct DigiParams : public o2::conf::ConfigurableParamHelper<DigiParams> {
3333
int maxOrbitsToDigitize = -1; // Digitizer can use this to truncate digits that fall beyond an orbit limit (relative to start of digization) given by this param; -1 means no limit imposed
3434
// This parameter should typically be set to coincide with a single timeframe length or multiples thereof.
3535
std::string passName = "unanchored"; // passName for anchored MC
36+
int seed = 0; // rndSeed to be applied in digitization; convention is that 0 is time based
3637
O2ParamDef(DigiParams, "DigiParams");
3738
};
3839

Detectors/Base/src/BaseDPLDigitizer.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <DetectorsBase/Propagator.h>
1717
#include <fairlogger/Logger.h>
1818
#include <TGeoGlobalMagField.h>
19+
#include <TRandom.h>
1920

2021
using namespace o2::base;
2122

@@ -54,6 +55,10 @@ void BaseDPLDigitizer::init(o2::framework::InitContext& ic)
5455
}
5556
}
5657

58+
// initialize the global ROOT random number generator (needed or not)
59+
LOG(info) << "Initializing ROOT digitizer random with seed " << o2::conf::DigiParams::Instance().seed;
60+
gRandom->SetSeed(o2::conf::DigiParams::Instance().seed);
61+
5762
// finally call specific init
5863
this->initDigitizerTask(ic);
5964
}

Detectors/EMCAL/simulation/src/Digitizer.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <fairlogger/Logger.h> // for LOG
2626
#include "CommonDataFormat/InteractionRecord.h"
2727
#include "CommonUtils/TreeStreamRedirector.h"
28+
#include "SimConfig/DigiParams.h"
2829

2930
ClassImp(o2::emcal::Digitizer);
3031

@@ -37,7 +38,11 @@ using namespace o2::emcal;
3738
void Digitizer::init()
3839
{
3940
mSimParam = &(o2::emcal::SimParam::Instance());
40-
mRandomGenerator = new TRandom3(std::chrono::high_resolution_clock::now().time_since_epoch().count());
41+
auto randomSeed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
42+
if (o2::conf::DigiParams::Instance().seed != 0) {
43+
randomSeed = o2::conf::DigiParams::Instance().seed;
44+
}
45+
mRandomGenerator = new TRandom3(randomSeed);
4146

4247
float tau = mSimParam->getTimeResponseTau();
4348
float N = mSimParam->getTimeResponsePower();

Detectors/EMCAL/simulation/src/DigitsVectorStream.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
#include "EMCALSimulation/LabeledDigit.h"
2020
#include "EMCALSimulation/DigitsVectorStream.h"
2121
#include "CommonConstants/Triggers.h"
22+
#include "SimConfig/DigiParams.h"
2223

2324
using namespace o2::emcal;
2425

2526
void DigitsVectorStream::init()
2627
{
2728
mSimParam = &(o2::emcal::SimParam::Instance());
28-
29-
mRandomGenerator = new TRandom3(std::chrono::high_resolution_clock::now().time_since_epoch().count());
29+
auto randomSeed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
30+
if (o2::conf::DigiParams::Instance().seed != 0) {
31+
randomSeed = o2::conf::DigiParams::Instance().seed;
32+
}
33+
mRandomGenerator = new TRandom3(randomSeed);
3034

3135
mRemoveDigitsBelowThreshold = mSimParam->doRemoveDigitsBelowThreshold();
3236
mSimulateNoiseDigits = mSimParam->doSimulateNoiseDigits();

0 commit comments

Comments
 (0)