Skip to content

Commit f6ee180

Browse files
f3schshahor02
authored andcommitted
AOD: Add thinner option to producer and seedable
This MR adds the following features: - make the random number optionally seedable, good for debugging - allow to thin tpc-only tracks and produce same output as the aod-thinner - adds some const for correctness Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent f6ff25c commit f6ee180

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

Detectors/AOD/include/AODProducerWorkflow/AODProducerWorkflowSpec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,19 @@ class AODProducerWorkflowDPL : public Task
227227
return std::uint64_t(mStartIR.toLong()) + relativeTime_to_LocalBC(relativeTimeStampInNS);
228228
}
229229

230+
bool mThinTracks{false};
230231
bool mPropTracks{false};
231232
bool mPropMuons{false};
232233
float mTrackQCFraction{0.00};
233234
int64_t mTrackQCNTrCut{4};
234235
float mSqrtS{13860.};
235-
std::mt19937 mGenerator; ///< random generator for trackQA sampling
236+
std::mt19937 mGenerator{}; ///< random generator for trackQA sampling
236237
o2::base::Propagator::MatCorrType mMatCorr{o2::base::Propagator::MatCorrType::USEMatCorrLUT};
237238
o2::dataformats::MeanVertexObject mVtx;
238239
float mMinPropR{o2::constants::geom::XTPCInnerRef + 0.1f};
239240

240241
std::unordered_set<GIndex> mGIDUsedBySVtx;
242+
std::unordered_set<GIndex> mGIDUsedByStr;
241243

242244
int mNThreads = 1;
243245
bool mUseMC = true;

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void AODProducerWorkflowDPL::fillTrackTablesPerCollision(int collisionID,
455455
tracksExtraCursor.reserve(nToReserve + tracksExtraCursor.lastIndex());
456456
}
457457
for (int ti = start; ti < end; ti++) {
458-
auto& trackIndex = GIndices[ti];
458+
const auto& trackIndex = GIndices[ti];
459459
if (GIndex::includesSource(src, mInputSources)) {
460460
if (src == GIndex::Source::MFT) { // MFT tracks are treated separately since they are stored in a different table
461461
if (trackIndex.isAmbiguous() && mGIDToTableMFTID.find(trackIndex) != mGIDToTableMFTID.end()) { // was it already stored ?
@@ -477,11 +477,12 @@ void AODProducerWorkflowDPL::fillTrackTablesPerCollision(int collisionID,
477477
if (trackIndex.isAmbiguous() && mGIDToTableID.find(trackIndex) != mGIDToTableID.end()) { // was it already stored ?
478478
continue;
479479
}
480-
auto extraInfoHolder = processBarrelTrack(collisionID, collisionBC, trackIndex, data, bcsMap);
481480

482481
float weight = 0;
483-
std::uniform_real_distribution<> distr(0., 1.);
482+
static std::uniform_real_distribution<> distr(0., 1.);
484483
bool writeQAData = o2::math_utils::Tsallis::downsampleTsallisCharged(data.getTrackParam(trackIndex).getPt(), mTrackQCFraction, mSqrtS, weight, distr(mGenerator));
484+
auto extraInfoHolder = processBarrelTrack(collisionID, collisionBC, trackIndex, data, bcsMap);
485+
485486
if (writeQAData) {
486487
auto trackQAInfoHolder = processBarrelTrackQA(collisionID, collisionBC, trackIndex, data, bcsMap);
487488
if (std::bitset<8>(trackQAInfoHolder.tpcClusterByteMask).count() >= mTrackQCNTrCut) {
@@ -490,17 +491,26 @@ void AODProducerWorkflowDPL::fillTrackTablesPerCollision(int collisionID,
490491
trackQAInfoHolder.tpcTime0 = (trackQAInfoHolder.tpcTime0 * 8 - extraInfoHolder.diffBCRef) * o2::constants::lhc::LHCBunchSpacingNS - extraInfoHolder.trackTime;
491492
// difference between TPC track time0 and stored track nominal time in ns instead of TF start
492493
addToTracksQATable(tracksQACursor, trackQAInfoHolder);
494+
} else {
495+
writeQAData = false;
493496
}
494497
}
495498

499+
if (mThinTracks && src == GIndex::Source::TPC && mGIDUsedBySVtx.find(trackIndex) == mGIDUsedBySVtx.end() && mGIDUsedByStr.find(trackIndex) == mGIDUsedByStr.end() && !writeQAData) {
500+
mGIDToTableID.emplace(trackIndex, -1); // pretend skipped tracks are stored; this is safe since they are are not written to disk and -1 indicates to all users to not use this track
501+
continue;
502+
}
503+
496504
if (!extraInfoHolder.isTPConly && extraInfoHolder.trackTimeRes < 0.f) { // failed or rejected?
497505
LOG(warning) << "Barrel track " << trackIndex << " has no time set, rejection is not expected : time=" << extraInfoHolder.trackTime
498506
<< " timeErr=" << extraInfoHolder.trackTimeRes << " BCSlice: " << extraInfoHolder.bcSlice[0] << ":" << extraInfoHolder.bcSlice[1];
499507
continue;
500508
}
501509
const auto& trOrig = data.getTrackParam(trackIndex);
502510
bool isProp = false;
503-
if (mPropTracks && trOrig.getX() < mMinPropR && mGIDUsedBySVtx.find(trackIndex) == mGIDUsedBySVtx.end()) { // Do not propagate track assoc. to V0s
511+
if (mPropTracks && trOrig.getX() < mMinPropR &&
512+
mGIDUsedBySVtx.find(trackIndex) == mGIDUsedBySVtx.end() &&
513+
mGIDUsedByStr.find(trackIndex) == mGIDUsedByStr.end()) { // Do not propagate track assoc. to V0s and str. tracking
504514
auto trackPar(trOrig);
505515
isProp = propagateTrackToPV(trackPar, data, collisionID);
506516
if (isProp) {
@@ -511,7 +521,7 @@ void AODProducerWorkflowDPL::fillTrackTablesPerCollision(int collisionID,
511521
addToTracksTable(tracksCursor, tracksCovCursor, trOrig, collisionID, aod::track::TrackIU);
512522
}
513523
addToTracksExtraTable(tracksExtraCursor, extraInfoHolder);
514-
// addToTracksQATable(tracksQACursor, trackQAInfoHolder);
524+
515525
// collecting table indices of barrel tracks for V0s table
516526
if (extraInfoHolder.bcSlice[0] >= 0 && collisionID < 0) {
517527
ambigTracksCursor(mTableTrID, extraInfoHolder.bcSlice);
@@ -1334,7 +1344,7 @@ void AODProducerWorkflowDPL::fillStrangenessTrackingTables(const o2::globaltrack
13341344
int nCasc = 0;
13351345
int nD3Body = 0;
13361346

1337-
for (auto& sTrk : recoData.getStrangeTracks()) {
1347+
for (const auto& sTrk : recoData.getStrangeTracks()) {
13381348
if (sTrk.mPartType == dataformats::kStrkV0) {
13391349
nV0++;
13401350
} else if (sTrk.mPartType == dataformats::kStrkCascade) {
@@ -1348,13 +1358,13 @@ void AODProducerWorkflowDPL::fillStrangenessTrackingTables(const o2::globaltrack
13481358
cascCurs.reserve(nCasc);
13491359
d3BodyCurs.reserve(nD3Body);
13501360

1351-
for (auto& sTrk : recoData.getStrangeTracks()) {
1361+
for (const auto& sTrk : recoData.getStrangeTracks()) {
13521362
auto ITSIndex = GIndex{sTrk.mITSRef, GIndex::ITS};
13531363
auto item = mGIDToTableID.find(ITSIndex);
13541364
if (item != mGIDToTableID.end()) {
13551365
itsTableIdx = item->second;
13561366
} else {
1357-
LOG(warn) << "Could not find a ITS strange track index";
1367+
LOG(warn) << "Could not find a ITS strange track index " << ITSIndex;
13581368
continue;
13591369
}
13601370
if (sTrk.mPartType == dataformats::kStrkV0) {
@@ -1649,11 +1659,22 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
16491659
mCTPReadout = ic.options().get<int>("ctpreadout-create");
16501660
mNThreads = std::max(1, ic.options().get<int>("nthreads"));
16511661
mEMCselectLeading = ic.options().get<bool>("emc-select-leading");
1662+
mThinTracks = ic.options().get<bool>("thin-tracks");
16521663
mPropTracks = ic.options().get<bool>("propagate-tracks");
16531664
mPropMuons = ic.options().get<bool>("propagate-muons");
16541665
mTrackQCFraction = ic.options().get<float>("trackqc-fraction");
16551666
mTrackQCNTrCut = ic.options().get<int64_t>("trackqc-NTrCut");
1656-
mGenerator = std::mt19937(std::random_device{}());
1667+
if (auto seed = ic.options().get<int>("seed"); seed == 0) {
1668+
LOGP(info, "Using random device for seeding");
1669+
std::random_device rd;
1670+
std::array<int, std::mt19937::state_size> seed_data{};
1671+
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
1672+
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
1673+
mGenerator = std::mt19937(seq);
1674+
} else {
1675+
LOGP(info, "Using seed {} for sampling", seed);
1676+
mGenerator.seed(seed);
1677+
}
16571678
#ifdef WITH_OPENMP
16581679
LOGP(info, "Multi-threaded parts will run with {} OpenMP threads", mNThreads);
16591680
#else
@@ -2094,7 +2115,7 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
20942115
mGIDToTableFwdID.clear(); // reset the tables to be used by 'fillTrackTablesPerCollision'
20952116
mGIDToTableMFTID.clear();
20962117

2097-
if (mPropTracks) {
2118+
if (mPropTracks || mThinTracks) {
20982119
auto v0s = recoData.getV0sIdx();
20992120
auto cascades = recoData.getCascadesIdx();
21002121
auto decays3Body = recoData.getDecays3BodyIdx();
@@ -2111,6 +2132,11 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
21112132
mGIDUsedBySVtx.insert(id3Body.getProngID(1));
21122133
mGIDUsedBySVtx.insert(id3Body.getProngID(2));
21132134
}
2135+
2136+
mGIDUsedByStr.reserve(recoData.getStrangeTracks().size());
2137+
for (const auto& sTrk : recoData.getStrangeTracks()) {
2138+
mGIDUsedByStr.emplace(sTrk.mITSRef, GIndex::ITS);
2139+
}
21142140
}
21152141

21162142
// filling unassigned tracks first
@@ -2284,6 +2310,7 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
22842310
mBCLookup.clear();
22852311

22862312
mGIDUsedBySVtx.clear();
2313+
mGIDUsedByStr.clear();
22872314

22882315
originCursor(tfNumber);
22892316

@@ -3003,8 +3030,10 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
30033030
ConfigParamSpec{"propagate-tracks", VariantType::Bool, false, {"Propagate tracks (not used for secondary vertices) to IP"}},
30043031
ConfigParamSpec{"hepmc-update", VariantType::String, "always", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present (not valid yet)"}},
30053032
ConfigParamSpec{"propagate-muons", VariantType::Bool, false, {"Propagate muons to IP"}},
3033+
ConfigParamSpec{"thin-tracks", VariantType::Bool, false, {"Produce thinned track tables"}},
30063034
ConfigParamSpec{"trackqc-fraction", VariantType::Float, float(0.1), {"Fraction of tracks to QC"}},
30073035
ConfigParamSpec{"trackqc-NTrCut", VariantType::Int64, 4L, {"Minimal length of the track - in amount of tracklets"}},
3036+
ConfigParamSpec{"seed", VariantType::Int, 0, {"Set seed for random generator used for sampling (0 (default) means using a random_device)"}},
30083037
}};
30093038
}
30103039

0 commit comments

Comments
 (0)