5454#include < iterator>
5555#include < memory>
5656#include < string>
57+ #include < unordered_map>
5758#include < vector>
5859
5960using namespace o2 ;
@@ -71,6 +72,7 @@ enum LambdaPid { kLambda = 0,
7172struct Filter2Prong {
7273 SliceCache cache;
7374 Preslice<aod::CFTrackRefs> perCollisionCFTrackRefs = aod::track::collisionId;
75+ Preslice<aod::CFCollRefs> perCollisionCFCollRefs = aod::track::collisionId;
7476
7577 O2_DEFINE_CONFIGURABLE (cfgVerbosity, int , 0 , " Verbosity level (0 = major, 1 = per collision)" )
7678 O2_DEFINE_CONFIGURABLE (cfgYMax, float , -1 .0f , " Maximum candidate rapidity" )
@@ -806,8 +808,23 @@ struct Filter2Prong {
806808 PROCESS_SWITCH (Filter2Prong, processDataPhiV0, " Process data Phi and V0 candidates with invariant mass method" , false );
807809
808810 using DerivedCollisions = soa::Join<aod::Collisions, aod::EvSels, aod::CFMultiplicities>;
809- void processDataPhiMixed (DerivedCollisions const & collisions, Filter2Prong::PIDTrack const & /* tracksP*/ , aod::CFTrackRefs const & cftracks)
811+ void processDataPhiMixed (DerivedCollisions const & collisions, Filter2Prong::PIDTrack const & /* tracksP*/ , aod::CFCollRefs const & cfcollrefs, aod:: CFTrackRefs const & cftracks)
810812 {
813+ struct MixedPhiCandidate {
814+ int64_t cfCollisionId;
815+ int64_t cfTrackProng0Id;
816+ int64_t cfTrackProng1Id;
817+ float pt;
818+ float eta;
819+ float phi;
820+ float invMass;
821+ uint8_t decay;
822+ };
823+
824+ if (cfcollrefs.size () <= 0 || cftracks.size () <= 0 ) {
825+ return ;
826+ }
827+
811828 auto getMultiplicity = [](auto const & col) {
812829 return col.multiplicity ();
813830 };
@@ -819,11 +836,23 @@ struct Filter2Prong {
819836 using TB = std::tuple_element<std::tuple_size_v<decltype (tracksTuple)> - 1 , decltype (tracksTuple)>::type;
820837 Pair<DerivedCollisions, TA, TB, BinningTypeDerived> pairs{configurableBinningDerived, cfgNoMixedEvents, -1 , collisions, tracksTuple, &cache}; // -1 is the number of the bin to skip
821838
839+ std::unordered_map<int64_t , int64_t > collToCF;
840+ collToCF.reserve (cfcollrefs.size ());
841+ for (const auto & cfcollref : cfcollrefs) {
842+ collToCF.emplace (cfcollref.collisionId (), cfcollref.globalIndex ());
843+ }
844+
845+ std::vector<MixedPhiCandidate> mixedPhiCandidates;
822846 o2::aod::ITSResponse itsResponse;
823847
824848 for (auto it = pairs.begin (); it != pairs.end (); it++) {
825849 auto & [collision1, tracks1, collision2, tracks2] = *it;
826850
851+ auto cfColl1 = collToCF.find (collision1.globalIndex ());
852+ if (cfColl1 == collToCF.end () || collToCF.find (collision2.globalIndex ()) == collToCF.end ()) {
853+ continue ;
854+ }
855+
827856 if (!(collision1.sel8 () &&
828857 collision1.selection_bit (aod::evsel::kNoSameBunchPileup ) &&
829858 collision1.selection_bit (aod::evsel::kIsGoodZvtxFT0vsPV ) &&
@@ -890,16 +919,40 @@ struct Filter2Prong {
890919 }
891920
892921 float phi = RecoDecay::constrainAngle (s.Phi (), 0 .0f );
893-
894- output2ProngTracks (collision1.globalIndex (),
895- cftrack1.globalIndex (), cftrack2.globalIndex (),
896- s.pt (), s.eta (), phi, s.M (),
897- aod::cf2prongtrack::PhiToKKPID3Mixed);
922+ mixedPhiCandidates.push_back ({cfColl1->second ,
923+ cftrack1.globalIndex (),
924+ cftrack2.globalIndex (),
925+ static_cast <float >(s.pt ()),
926+ static_cast <float >(s.eta ()),
927+ phi,
928+ static_cast <float >(s.M ()),
929+ aod::cf2prongtrack::PhiToKKPID3Mixed});
898930 }
899931 }
900932 }
901933 }
902934 }
935+
936+ std::sort (mixedPhiCandidates.begin (), mixedPhiCandidates.end (), [](const auto & lhs, const auto & rhs) {
937+ if (lhs.cfCollisionId != rhs.cfCollisionId ) {
938+ return lhs.cfCollisionId < rhs.cfCollisionId ;
939+ }
940+ if (lhs.cfTrackProng0Id != rhs.cfTrackProng0Id ) {
941+ return lhs.cfTrackProng0Id < rhs.cfTrackProng0Id ;
942+ }
943+ return lhs.cfTrackProng1Id < rhs.cfTrackProng1Id ;
944+ });
945+
946+ for (const auto & candidate : mixedPhiCandidates) {
947+ output2ProngTracks (candidate.cfCollisionId ,
948+ candidate.cfTrackProng0Id ,
949+ candidate.cfTrackProng1Id ,
950+ candidate.pt ,
951+ candidate.eta ,
952+ candidate.phi ,
953+ candidate.invMass ,
954+ candidate.decay );
955+ }
903956 }
904957
905958 PROCESS_SWITCH (Filter2Prong, processDataPhiMixed, " Process mixed-event phi candidates using O2 framework" , false );
0 commit comments