Skip to content

Commit e0f417b

Browse files
authored
[DPG] Avoid rand() (#9424)
1 parent ee7cb93 commit e0f417b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

DPG/Tasks/AOTTrack/qaEventTrackLiteProducer.cxx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <vector>
2323

24+
#include "TRandom.h"
2425
#include "Framework/AnalysisTask.h"
2526
#include "Framework/HistogramRegistry.h"
2627
#include "Framework/runDataProcessing.h"
@@ -40,7 +41,7 @@ using namespace o2::framework;
4041
using namespace o2::framework::expressions;
4142
using namespace o2::dataformats;
4243

43-
struct qaEventTrackLiteProducer {
44+
struct QaEventTrackLiteProducer {
4445
// Tables to produce
4546
Produces<o2::aod::DPGCollisions> tableCollisions;
4647
Produces<o2::aod::DPGCollsBig> tableCollsBig;
@@ -180,7 +181,7 @@ struct qaEventTrackLiteProducer {
180181
{
181182
fillDerivedTable<false>(collision, tracks, 0, bcs);
182183
}
183-
PROCESS_SWITCH(qaEventTrackLiteProducer, processTableData, "Process data for table producing", true);
184+
PROCESS_SWITCH(QaEventTrackLiteProducer, processTableData, "Process data for table producing", true);
184185

185186
void processTableMC(CollisionTableMC::iterator const& collision,
186187
soa::Filtered<soa::Join<TrackTableMC, aod::TOFSignal, aod::TOFEvTime>> const& tracks,
@@ -190,7 +191,7 @@ struct qaEventTrackLiteProducer {
190191
{
191192
fillDerivedTable<true>(collision, tracks, mcParticles, bcs);
192193
}
193-
PROCESS_SWITCH(qaEventTrackLiteProducer, processTableMC, "Process MC for table producing", false);
194+
PROCESS_SWITCH(QaEventTrackLiteProducer, processTableMC, "Process MC for table producing", false);
194195

195196
//**************************************************************************************************
196197
/**
@@ -207,7 +208,7 @@ struct qaEventTrackLiteProducer {
207208
if (std::abs(collision.posZ()) > selectMaxVtxZ) {
208209
return;
209210
}
210-
if (fractionOfSampledEvents < 1.f && (static_cast<float>(rand()) / static_cast<float>(RAND_MAX)) > fractionOfSampledEvents) { // Skip events that are not sampled
211+
if (fractionOfSampledEvents < 1.f && (gRandom->Uniform()) > fractionOfSampledEvents) { // Skip events that are not sampled
211212
return;
212213
}
213214
if (nTableEventCounter > targetNumberOfEvents) { // Skip events if target is reached
@@ -312,9 +313,9 @@ struct qaEventTrackLiteProducer {
312313
if (nTableEventCounter > targetNumberOfEvents) { // Skip events if target is reached
313314
return;
314315
}
315-
for (auto& collision : collisions) {
316+
for (const auto& collision : collisions) {
316317

317-
if (fractionOfSampledEvents < 1.f && (static_cast<float>(rand()) / static_cast<float>(RAND_MAX)) > fractionOfSampledEvents) { // Skip events that are not sampled
318+
if (fractionOfSampledEvents < 1.f && (gRandom->Uniform()) > fractionOfSampledEvents) { // Skip events that are not sampled
318319
return;
319320
}
320321
nTableEventCounter++;
@@ -409,7 +410,7 @@ struct qaEventTrackLiteProducer {
409410
/// Let's update the DF counter
410411
counterDF++;
411412
}
412-
PROCESS_SWITCH(qaEventTrackLiteProducer, processTableDataCollsBig, "Process data for big collision table producing", false);
413+
PROCESS_SWITCH(QaEventTrackLiteProducer, processTableDataCollsBig, "Process data for big collision table producing", false);
413414

414415
/// Processing MC
415416
void processTableMCCollsBig(CollsBigTableMC const& collisions,
@@ -425,10 +426,10 @@ struct qaEventTrackLiteProducer {
425426
/// Let's update the DF counter
426427
counterDF++;
427428
}
428-
PROCESS_SWITCH(qaEventTrackLiteProducer, processTableMCCollsBig, "Process MC for big collision table producing", false);
429+
PROCESS_SWITCH(QaEventTrackLiteProducer, processTableMCCollsBig, "Process MC for big collision table producing", false);
429430
};
430431

431432
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
432433
{
433-
return WorkflowSpec{adaptAnalysisTask<qaEventTrackLiteProducer>(cfgc)};
434+
return WorkflowSpec{adaptAnalysisTask<QaEventTrackLiteProducer>(cfgc)};
434435
}

0 commit comments

Comments
 (0)