Skip to content

Commit e66b9a4

Browse files
ddobrigkalibuild
andauthored
[PWGLF] Optimize de-duplication and DCAtoPV calculation (#13031)
Co-authored-by: ALICE Builder <alibuild@users.noreply.github.com>
1 parent 8c87ead commit e66b9a4

File tree

2 files changed

+59
-28
lines changed

2 files changed

+59
-28
lines changed

PWGLF/Utils/strangenessBuilderHelper.h

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ class strangenessBuilderHelper
266266
//_______________________________________________________________________
267267
// standard build V0 function. Populates ::v0 object
268268
// ::v0 will be initialized to defaults if build fails
269-
template <bool useSelections = true, typename TTrack, typename TTrackParametrization>
269+
// --- useSelections: meant to maximize recovery, but beware high cost in CPU
270+
// --- calculateProngDCAtoPV: optionally don't propagate prongs to PV, saves
271+
// CPU, of interest when dealing with de-duplication (variable not checked)
272+
template <bool useSelections = true, bool calculateProngDCAtoPV = true, typename TTrack, typename TTrackParametrization>
270273
bool buildV0Candidate(int collisionIndex,
271274
float pvX, float pvY, float pvZ,
272275
TTrack const& positiveTrack,
@@ -277,6 +280,8 @@ class strangenessBuilderHelper
277280
bool calculateCovariance = false,
278281
bool acceptTPCOnly = false)
279282
{
283+
v0 = {}; // safe initialization: start new
284+
280285
if constexpr (useSelections) {
281286
// verify track quality
282287
if (positiveTrack.tpcNClsCrossedRows() < v0selections.minCrossedRows) {
@@ -296,41 +301,50 @@ class strangenessBuilderHelper
296301
v0 = {};
297302
return false;
298303
}
299-
if (!acceptTPCOnly && !positiveTrack.hasITS()) {
304+
if (!acceptTPCOnly && !positiveTrack.hasITS() && !negativeTrack.hasTRD() && !negativeTrack.hasTOF()) {
300305
v0 = {};
301306
return false;
302307
}
303-
if (!acceptTPCOnly && !negativeTrack.hasITS()) {
308+
if (!acceptTPCOnly && !negativeTrack.hasITS() && !negativeTrack.hasTRD() && !negativeTrack.hasTOF()) {
304309
v0 = {};
305310
return false;
306311
}
307312
}
308313

309-
// Calculate DCA with respect to the collision associated to the V0
310-
std::array<float, 2> dcaInfo;
314+
if constexpr (calculateProngDCAtoPV) {
315+
// Calculate DCA with respect to the collision associated to the V0
316+
std::array<float, 2> dcaInfo;
311317

312-
// do DCA to PV on copies instead of originals
313-
auto positiveTrackParamCopy = positiveTrackParam;
314-
auto negativeTrackParamCopy = negativeTrackParam;
318+
// do DCA to PV on TrackPar copies and not TrackParCov
319+
// TrackPar preferred: don't calculate multiple scattering / CovMat changes
320+
// Spares CPU since variables not checked
321+
o2::track::TrackPar positiveTrackParamCopy(positiveTrackParam);
322+
o2::track::TrackPar negativeTrackParamCopy(negativeTrackParam);
315323

316-
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, positiveTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
317-
v0.positiveDCAxy = dcaInfo[0];
324+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
325+
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, positiveTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
326+
v0.positiveDCAxy = dcaInfo[0];
318327

319-
if constexpr (useSelections) {
320-
if (std::fabs(v0.positiveDCAxy) < v0selections.dcanegtopv) {
321-
v0 = {};
322-
return false;
328+
if constexpr (useSelections) {
329+
if (std::fabs(v0.positiveDCAxy) < v0selections.dcapostopv) {
330+
v0 = {};
331+
return false;
332+
}
323333
}
324-
}
325334

326-
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, negativeTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
327-
v0.negativeDCAxy = dcaInfo[0];
335+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
336+
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, negativeTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
337+
v0.negativeDCAxy = dcaInfo[0];
328338

329-
if constexpr (useSelections) {
330-
if (std::fabs(v0.negativeDCAxy) < v0selections.dcanegtopv) {
331-
v0 = {};
332-
return false;
339+
if constexpr (useSelections) {
340+
if (std::fabs(v0.negativeDCAxy) < v0selections.dcanegtopv) {
341+
v0 = {};
342+
return false;
343+
}
333344
}
345+
} else {
346+
v0.positiveDCAxy = 0.0f; // default invalid
347+
v0.negativeDCAxy = 0.0f; // default invalid
334348
}
335349

336350
// Perform DCA fit
@@ -340,10 +354,12 @@ class strangenessBuilderHelper
340354
nCand = fitter.process(positiveTrackParam, negativeTrackParam);
341355
} catch (...) {
342356
v0 = {};
357+
fitter.setCollinear(false); // even if returned, reset
343358
return false;
344359
}
345360
if (nCand == 0) {
346361
v0 = {};
362+
fitter.setCollinear(false); // even if returned, reset
347363
return false;
348364
}
349365
fitter.setCollinear(false); // proper cleaning: when exiting this loop, always reset to not collinear
@@ -354,6 +370,7 @@ class strangenessBuilderHelper
354370
std::array<float, 2> dcaV0Info;
355371

356372
// propagate to collision vertex
373+
dcaV0Info[0] = dcaV0Info[1] = 999.0f; // default DCA: large, use with care if propagation fails
357374
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, V0Temp, 2.f, fitter.getMatCorrType(), &dcaV0Info);
358375
v0.v0DCAToPVxy = dcaV0Info[0];
359376
v0.v0DCAToPVz = dcaV0Info[1];
@@ -499,10 +516,13 @@ class strangenessBuilderHelper
499516
// Calculate DCA with respect to the collision associated to the V0
500517
std::array<float, 2> dcaInfo;
501518

502-
// do DCA to PV on copies instead of originals
503-
auto positiveTrackParamCopy = positiveTrackParam;
504-
auto negativeTrackParamCopy = negativeTrackParam;
519+
// do DCA to PV on TrackPar copies and not TrackParCov
520+
// TrackPar preferred: don't calculate multiple scattering / CovMat changes
521+
// Spares CPU since variables not checked
522+
o2::track::TrackPar positiveTrackParamCopy(positiveTrackParam);
523+
o2::track::TrackPar negativeTrackParamCopy(negativeTrackParam);
505524

525+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
506526
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, positiveTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
507527
v0.positiveDCAxy = dcaInfo[0];
508528

@@ -511,6 +531,7 @@ class strangenessBuilderHelper
511531
return false;
512532
}
513533

534+
dcaInfo[0] = dcaInfo[1] = 999.0f; // reset to default value
514535
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, negativeTrackParamCopy, 2.f, fitter.getMatCorrType(), &dcaInfo);
515536
v0.negativeDCAxy = dcaInfo[0];
516537

@@ -672,6 +693,8 @@ class strangenessBuilderHelper
672693
bool useCascadeMomentumAtPV = false,
673694
bool processCovariances = false)
674695
{
696+
cascade = {}; // initialize / empty (extra safety)
697+
675698
// verify track quality
676699
if (positiveTrack.tpcNClsCrossedRows() < cascadeselections.minCrossedRows) {
677700
cascade = {};
@@ -726,6 +749,7 @@ class strangenessBuilderHelper
726749
// bachelor DCA track to PV
727750
// Calculate DCA with respect to the collision associated to the V0, not individual tracks
728751
std::array<float, 2> dcaInfo;
752+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
729753

730754
auto bachTrackPar = getTrackPar(bachelorTrack);
731755
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, bachTrackPar, 2.f, fitter.getMatCorrType(), &dcaInfo);
@@ -902,6 +926,8 @@ class strangenessBuilderHelper
902926
bool kfDoDCAFitterPreMinimV0 = false,
903927
bool kfDoDCAFitterPreMinimCasc = false)
904928
{
929+
cascade = {}; // initialize / empty (extra safety)
930+
905931
//*>~<*>~<*>~<*>~<*>~<*>~<*>~<*>~<*>~<*
906932
// KF particle based rebuilding
907933
// dispenses prior V0 generation, uses constrained (re-)fit based on bachelor charge
@@ -950,13 +976,18 @@ class strangenessBuilderHelper
950976
// bachelor DCA track to PV
951977
// Calculate DCA with respect to the collision associated to the V0, not individual tracks
952978
std::array<float, 2> dcaInfo;
979+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
953980

954981
auto bachTrackPar = getTrackPar(bachelorTrack);
955982
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, bachTrackPar, 2.f, fitter.getMatCorrType(), &dcaInfo);
956983
cascade.bachelorDCAxy = dcaInfo[0];
984+
985+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
957986
o2::track::TrackParCov posTrackParCovForDCA = getTrackParCov(positiveTrack);
958987
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, posTrackParCovForDCA, 2.f, fitter.getMatCorrType(), &dcaInfo);
959988
cascade.positiveDCAxy = dcaInfo[0];
989+
990+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value to make sure candidate accepted
960991
o2::track::TrackParCov negTrackParCovForDCA = getTrackParCov(negativeTrack);
961992
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, negTrackParCovForDCA, 2.f, fitter.getMatCorrType(), &dcaInfo);
962993
cascade.negativeDCAxy = dcaInfo[0];
@@ -1272,8 +1303,7 @@ class strangenessBuilderHelper
12721303
o2::track::TrackPar wrongV0 = fitter.createParentTrackPar();
12731304
wrongV0.setAbsCharge(0); // charge zero
12741305
std::array<float, 2> dcaInfo;
1275-
dcaInfo[0] = 999;
1276-
dcaInfo[1] = 999;
1306+
dcaInfo[0] = dcaInfo[1] = 999.0f; // by default, take large value
12771307

12781308
// bachelor-baryon DCAxy to PV
12791309
o2::base::Propagator::Instance()->propagateToDCABxByBz({pvX, pvY, pvZ}, wrongV0, 2.f, fitter.getMatCorrType(), &dcaInfo);

PWGLF/Utils/strangenessBuilderModule.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,10 @@ class BuilderModule
916916
} // end TPC drift treatment
917917

918918
// process candidate with helper, generate properties for consulting
919-
// <false>: do not apply selections: do as much as possible to preserve
919+
// first 'false' : do not apply selections: do as much as possible to preserve
920+
// second 'false': do not calculate prong DCA to PV, unnecessary, costly if XIU = 83.1f
920921
// candidate at this level and do not select with topo selections
921-
if (straHelper.buildV0Candidate<false>(v0tableGrouped[iV0].collisionIds[ic], collision.posX(), collision.posY(), collision.posZ(), pTrack, nTrack, posTrackPar, negTrackPar, true, false, true)) {
922+
if (straHelper.buildV0Candidate<false, false>(v0tableGrouped[iV0].collisionIds[ic], collision.posX(), collision.posY(), collision.posZ(), pTrack, nTrack, posTrackPar, negTrackPar, true, false, true)) {
922923
// candidate built, check pointing angle
923924
if (straHelper.v0.pointingAngle < bestPointingAngle) {
924925
bestPointingAngle = straHelper.v0.pointingAngle;

0 commit comments

Comments
 (0)