@@ -277,6 +277,10 @@ struct StrangenessBuilder {
277277 // more algorithms to be added as necessary
278278 Configurable<int > deduplicationAlgorithm{" deduplicationAlgorithm" , 1 , " 0: disabled; 1: best pointing angle wins" };
279279
280+ // V0 buffer for V0s used in cascades: master switch
281+ // exchanges CPU (generate V0s again) with memory (save pre-generated V0s)
282+ Configurable<bool > useV0BufferForCascades{" useV0BufferForCascades" , false , " store array of V0s for cascades or not. False (default): save RAM, use more CPU; true: save CPU, use more RAM" };
283+
280284 Configurable<int > mc_findableMode{" mc_findableMode" , 0 , " 0: disabled; 1: add findable-but-not-found to existing V0s from AO2D; 2: reset V0s and generate only findable-but-not-found" };
281285
282286 // V0 building options
@@ -718,8 +722,8 @@ struct StrangenessBuilder {
718722 v0Entry currentV0Entry;
719723 cascadeEntry currentCascadeEntry;
720724
721- std::vector<int > ao2dV0toV0List; // index to relate AO2D V0s -> deduplicated V0s
722- std::vector<int > bestCollisionArray; // stores McCollision -> Collision map
725+ std::vector<int > ao2dV0toV0List; // index to relate AO2D V0s -> deduplicated V0s
726+ std::vector<int > bestCollisionArray; // stores McCollision -> Collision map
723727 std::vector<int > bestCollisionNContribsArray; // stores Ncontribs for biggest coll assoc to mccoll
724728
725729 int collisionLessV0s = 0 ;
@@ -747,9 +751,8 @@ struct StrangenessBuilder {
747751
748752 if (mc_findableMode.value < 2 ) {
749753 // keep all unless de-duplication active
750- std::vector<bool > keepV0 (v0s.size (), true );
751754 ao2dV0toV0List.clear ();
752- ao2dV0toV0List.resize (v0s.size (), -1 );
755+ ao2dV0toV0List.resize (v0s.size (), -1 ); // -1 means keep, -2 means do not keep
753756
754757 if (deduplicationAlgorithm>0 && v0BuilderOpts.generatePhotonCandidates ){
755758 // handle duplicates explicitly: group V0s according to (p,n) indices
@@ -761,12 +764,21 @@ struct StrangenessBuilder {
761764
762765 // process grouped duplicates, remove 'bad' ones
763766 for (size_t iV0 = 0 ; iV0<v0tableGrouped.size (); iV0++){
764- // skip single copy V0s
767+ auto pTrack = tracks.rawIteratorAt (v0tableGrouped[iV0].posTrackId );
768+ auto nTrack = tracks.rawIteratorAt (v0tableGrouped[iV0].negTrackId );
769+
770+ bool isPosTPCOnly = (pTrack.hasTPC () && !pTrack.hasITS () && !pTrack.hasTRD () && !pTrack.hasTOF ());
771+ bool isNegTPCOnly = (nTrack.hasTPC () && !nTrack.hasITS () && !nTrack.hasTRD () && !nTrack.hasTOF ());
772+
773+ // skip single copy V0s
765774 if (v0tableGrouped[iV0].collisionIds .size () == 1 ){
766775 continue ;
767776 }
768- auto pTrack = tracks.rawIteratorAt (v0tableGrouped[iV0].posTrackId );
769- auto nTrack = tracks.rawIteratorAt (v0tableGrouped[iV0].negTrackId );
777+
778+ // don't try to de-duplicate if no track is TPC only
779+ if (!isPosTPCOnly && !isNegTPCOnly){
780+ continue ;
781+ }
770782
771783 // fitness criteria defined here
772784 float bestPointingAngle = 10 ; // a nonsense angle, anything's better
@@ -780,7 +792,6 @@ struct StrangenessBuilder {
780792
781793 // handle TPC-only tracks properly (photon conversions)
782794 if (v0BuilderOpts.moveTPCOnlyTracks ) {
783- bool isPosTPCOnly = (pTrack.hasTPC () && !pTrack.hasITS () && !pTrack.hasTRD () && !pTrack.hasTOF ());
784795 if (isPosTPCOnly) {
785796 // Nota bene: positive is TPC-only -> this entire V0 merits treatment as photon candidate
786797 posTrackPar.setPID (o2::track::PID::Electron);
@@ -789,7 +800,6 @@ struct StrangenessBuilder {
789800 return ;
790801 }
791802 }
792- bool isNegTPCOnly = (nTrack.hasTPC () && !nTrack.hasITS () && !nTrack.hasTRD () && !nTrack.hasTOF ());
793803 if (isNegTPCOnly) {
794804 // Nota bene: negative is TPC-only -> this entire V0 merits treatment as photon candidate
795805 posTrackPar.setPID (o2::track::PID::Electron);
@@ -814,16 +824,16 @@ struct StrangenessBuilder {
814824
815825 // mark de-duplicated candidates
816826 for (size_t ic=0 ; ic<v0tableGrouped[iV0].collisionIds .size (); ic++){
817- keepV0 [v0tableGrouped[iV0].V0Ids [ic]] = false ;
827+ ao2dV0toV0List [v0tableGrouped[iV0].V0Ids [ic]] = - 2 ;
818828 if (bestPointingAngleIndex == ic){
819- keepV0 [v0tableGrouped[iV0].V0Ids [ic]] = true ; // keep best only
829+ ao2dV0toV0List [v0tableGrouped[iV0].V0Ids [ic]] = - 1 ; // keep best only
820830 }
821831 }
822832 } // end V0 loop
823833 } // end de-duplication process
824834
825835 for (const auto & v0 : v0s) {
826- if (keepV0 [v0.globalIndex ()]){ // keep only de-duplicated
836+ if (ao2dV0toV0List [v0.globalIndex ()]==- 1 ){ // keep only de-duplicated
827837 ao2dV0toV0List[v0.globalIndex ()] = v0List.size (); // maps V0s to the corresponding v0List entry
828838 currentV0Entry.globalId = v0.globalIndex ();
829839 currentV0Entry.collisionId = v0.collisionId ();
@@ -972,13 +982,16 @@ struct StrangenessBuilder {
972982 // N.B.: necessary also before cascade part
973983 sorted_v0.clear ();
974984 sorted_v0 = sort_indices (v0List, (mc_findableMode.value > 0 ));
975-
985+
976986 // Cascade part if cores are requested, skip otherwise
977987 if (mEnabledTables [kStoredCascCores ] || mEnabledTables [kStoredKFCascCores ]) {
978988 if (mc_findableMode.value < 2 ) {
979989 // simple passthrough: copy existing cascades to build list
980990 for (const auto & cascade : cascades) {
981991 auto const & v0 = cascade.v0 ();
992+ if (v0.v0Type ()>1 ){
993+ continue ; // skip any unexpected stuff (FIXME: follow-up)
994+ }
982995 currentCascadeEntry.globalId = cascade.globalIndex ();
983996 currentCascadeEntry.collisionId = cascade.collisionId ();
984997 currentCascadeEntry.v0Id = ao2dV0toV0List[v0.globalIndex ()];
@@ -1186,6 +1199,7 @@ struct StrangenessBuilder {
11861199 trackedCascadeCount = trackedCascades.size ();
11871200 for (const auto & trackedCascade : trackedCascades) {
11881201 auto const & cascade = trackedCascade.cascade ();
1202+ LOGF (info, " trouble: cascade.v0Id() = %i but v0Map size %i" , cascade.v0Id (), v0Map.size ());
11891203 if (v0Map[cascade.v0Id ()] == -2 ) {
11901204 v0sUsedInCascades++;
11911205 }
@@ -1268,7 +1282,7 @@ struct StrangenessBuilder {
12681282 products.v0dataLink (-1 , -1 );
12691283 continue ;
12701284 }
1271- if (v0Map[iv0] == -1 ) {
1285+ if (v0Map[iv0] == -1 && useV0BufferForCascades ) {
12721286 v0Map[iv0] = v0sFromCascades.size (); // provide actual valid index in buffer
12731287 v0sFromCascades.push_back (straHelper.v0 );
12741288 }
@@ -1702,17 +1716,37 @@ struct StrangenessBuilder {
17021716 interlinks.cascadeToCascCores .push_back (-1 );
17031717 continue ; // didn't work out, skip
17041718 }
1705- if (!straHelper.buildCascadeCandidate (cascade.collisionId , pvX, pvY, pvZ,
1706- v0sFromCascades[v0Map[cascade.v0Id ]],
1707- posTrack,
1708- negTrack,
1709- bachTrack,
1710- mEnabledTables [kCascBBs ],
1711- cascadeBuilderOpts.useCascadeMomentumAtPrimVtx ,
1712- mEnabledTables [kCascCovs ])) {
1713- products.cascdataLink (-1 );
1714- interlinks.cascadeToCascCores .push_back (-1 );
1715- continue ; // didn't work out, skip
1719+ if (useV0BufferForCascades){
1720+ // this processing path uses a buffer of V0s so that no
1721+ // additional minimization step is redone. It consumes less
1722+ // CPU at the cost of more memory. Since memory is a more
1723+ // limited commodity, this isn't the default option.
1724+ if (!straHelper.buildCascadeCandidate (cascade.collisionId , pvX, pvY, pvZ,
1725+ v0sFromCascades[v0Map[cascade.v0Id ]],
1726+ posTrack,
1727+ negTrack,
1728+ bachTrack,
1729+ mEnabledTables [kCascBBs ],
1730+ cascadeBuilderOpts.useCascadeMomentumAtPrimVtx ,
1731+ mEnabledTables [kCascCovs ])) {
1732+ products.cascdataLink (-1 );
1733+ interlinks.cascadeToCascCores .push_back (-1 );
1734+ continue ; // didn't work out, skip
1735+ }
1736+ }else {
1737+ // this processing path generates the entire cascade
1738+ // from tracks, without any need to have V0s generated.
1739+ if (!straHelper.buildCascadeCandidate (cascade.collisionId , pvX, pvY, pvZ,
1740+ posTrack,
1741+ negTrack,
1742+ bachTrack,
1743+ mEnabledTables [kCascBBs ],
1744+ cascadeBuilderOpts.useCascadeMomentumAtPrimVtx ,
1745+ mEnabledTables [kCascCovs ])) {
1746+ products.cascdataLink (-1 );
1747+ interlinks.cascadeToCascCores .push_back (-1 );
1748+ continue ; // didn't work out, skip
1749+ }
17161750 }
17171751 nCascades++;
17181752
0 commit comments