Skip to content

Commit ecc7d4c

Browse files
authored
[PWGLF] Avoid repetition in event mixing (#11255)
1 parent 83e6e5d commit ecc7d4c

File tree

1 file changed

+79
-186
lines changed

1 file changed

+79
-186
lines changed

PWGLF/Tasks/Strangeness/taskLambdaSpinCorr.cxx

Lines changed: 79 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ struct LfTaskLambdaSpinCorr {
240240
auto particle1Dummy = ROOT::Math::PxPyPzMVector(particle1.Px(), particle1.Py(), particle1.Pz(), 1.115683);
241241
auto particle2Dummy = ROOT::Math::PxPyPzMVector(particle2.Px(), particle2.Py(), particle2.Pz(), 1.115683);
242242
auto pairDummy = particle1Dummy + particle2Dummy;
243+
243244
// auto pairParticle = particle1 + particle2;
244245

245246
ROOT::Math::Boost boostPairToCM{pairDummy.BoostToCM()}; // boosting vector for pair CM
@@ -430,7 +431,7 @@ struct LfTaskLambdaSpinCorr {
430431

431432
// 2nd loop for combination of lambda lambda
432433
for (const auto& v02 : V0s) {
433-
if (v02.v0Id() <= v0.v0Id()) {
434+
if (v02.index() <= v0.index()) {
434435
continue;
435436
}
436437
auto [lambdaTag2, aLambdaTag2, isValid2] = getLambdaTags(v02, collision);
@@ -506,14 +507,20 @@ struct LfTaskLambdaSpinCorr {
506507
auto groupV03 = V0s.sliceBy(tracksPerCollisionV0, collision2.globalIndex());
507508
// for (auto& [t1, t2, t3] : soa::combinations(o2::soa::CombinationsFullIndexPolicy(groupV01, groupV02, groupV03))) {
508509
// LOGF(info, "Mixed event collisions: (%d, %d, %d)", t1.collisionId(),t2.collisionId(),t3.collisionId());
510+
auto maxV0Size = 1100;
511+
if (groupV01.size() > maxV0Size || groupV02.size() > maxV0Size || groupV03.size() > maxV0Size) {
512+
continue;
513+
}
514+
bool pairStatus[1150][1150] = {{false}};
509515
for (auto& [t1, t2] : soa::combinations(o2::soa::CombinationsFullIndexPolicy(groupV01, groupV02))) {
510516
bool pairfound = false;
511-
if (t2.v0Id() <= t1.v0Id()) {
517+
if (t2.index() <= t1.index()) {
512518
continue;
513519
}
514520
if (t1.collisionId() != t2.collisionId()) {
515521
continue;
516522
}
523+
517524
auto [lambdaTag1, aLambdaTag1, isValid1] = getLambdaTags(t1, collision1);
518525
auto [lambdaTag2, aLambdaTag2, isValid2] = getLambdaTags(t2, collision1);
519526
if (!isValid1) {
@@ -529,6 +536,10 @@ struct LfTaskLambdaSpinCorr {
529536
continue;
530537
}
531538
for (const auto& t3 : groupV03) {
539+
if (pairStatus[t3.index()][t2.index()]) {
540+
// LOGF(info, "repeat match found v0 id: (%d, %d)", t3.index(), t2.index());
541+
continue;
542+
}
532543
if (t1.collisionId() == t3.collisionId()) {
533544
continue;
534545
}
@@ -539,7 +550,6 @@ struct LfTaskLambdaSpinCorr {
539550
if (lambdaTag3 && aLambdaTag3) {
540551
continue;
541552
}
542-
543553
if (lambdaTag1 != lambdaTag3 || aLambdaTag1 != aLambdaTag3) {
544554
continue;
545555
}
@@ -552,7 +562,6 @@ struct LfTaskLambdaSpinCorr {
552562
if (std::abs(t1.phi() - t3.phi()) > phiMix) {
553563
continue;
554564
}
555-
556565
if (lambdaTag2) {
557566
proton = ROOT::Math::PxPyPzMVector(t2.pxpos(), t2.pypos(), t2.pzpos(), o2::constants::physics::MassProton);
558567
antiPion = ROOT::Math::PxPyPzMVector(t2.pxneg(), t2.pyneg(), t2.pzneg(), o2::constants::physics::MassPionCharged);
@@ -586,6 +595,8 @@ struct LfTaskLambdaSpinCorr {
586595
fillHistograms(0, 1, 1, 0, antiLambda, lambda2, antiProton, proton2, centrality, 2);
587596
}
588597
pairfound = true;
598+
pairStatus[t3.index()][t2.index()] = true;
599+
// LOGF(info, "v0 id: (%d, %d)", t3.index(), t2.index());
589600
if (pairfound) {
590601
// LOGF(info, "Pair found");
591602
break;
@@ -596,206 +607,79 @@ struct LfTaskLambdaSpinCorr {
596607
}
597608
PROCESS_SWITCH(LfTaskLambdaSpinCorr, processME, "Process data ME", true);
598609

599-
using CollisionMCTrueTable = aod::McCollisions;
600-
using TrackMCTrueTable = aod::McParticles;
601-
602-
using CollisionMCRecTableCentFT0C = soa::SmallGroups<soa::Join<aod::McCollisionLabels, aod::Collisions, aod::CentFT0Cs, aod::EvSels, aod::PVMults>>;
603-
using TrackMCRecTable = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::McTrackLabels, aod::TrackSelection, aod::pidTPCFullPi, aod::pidTPCFullPr>;
604-
// using FilTrackMCRecTable = soa::Filtered<TrackMCRecTable>;
605-
using FilTrackMCRecTable = TrackMCRecTable;
606-
Preslice<TrackMCRecTable> perCollision = aod::track::collisionId;
610+
using CollisionMCRecTableCentFT0C = soa::Join<aod::Collisions, aod::CentFT0Cs, aod::EvSels>;
611+
using TrackMCRecTable = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection, aod::pidTPCFullPi, aod::pidTPCFullPr>;
607612
using V0TrackCandidatesMC = soa::Join<aod::V0Datas, aod::McV0Labels>;
608-
609-
void processMC(CollisionMCTrueTable::iterator const& /*TrueCollision*/, CollisionMCRecTableCentFT0C const& RecCollisions, TrackMCTrueTable const& GenParticles, FilTrackMCRecTable const& /*RecTracks*/, V0TrackCandidatesMC const& V0s)
613+
void processMC(CollisionMCRecTableCentFT0C::iterator const& collision, TrackMCRecTable const& /*tracks*/, V0TrackCandidatesMC const& V0s)
610614
{
611615

612-
for (const auto& RecCollision : RecCollisions) {
613-
if (!RecCollision.sel8()) {
616+
// for (const auto& RecCollis : collision) {
617+
if (!collision.sel8()) {
618+
return;
619+
}
620+
if (std::abs(collision.posZ()) > cfgCutVertex) {
621+
return;
622+
}
623+
auto centrality = collision.centFT0C();
624+
histos.fill(HIST("hCentrality"), centrality);
625+
for (const auto& v0 : V0s) {
626+
auto [lambdaTag, aLambdaTag, isValid] = getLambdaTagsMC(v0, collision);
627+
if (!isValid) {
614628
continue;
615629
}
616-
if (!RecCollision.selection_bit(aod::evsel::kNoTimeFrameBorder) || !RecCollision.selection_bit(aod::evsel::kNoITSROFrameBorder)) {
617-
// continue;
630+
if (lambdaTag) {
631+
proton = ROOT::Math::PxPyPzMVector(v0.pxpos(), v0.pypos(), v0.pzpos(), o2::constants::physics::MassProton);
632+
antiPion = ROOT::Math::PxPyPzMVector(v0.pxneg(), v0.pyneg(), v0.pzneg(), o2::constants::physics::MassPionCharged);
633+
lambda = proton + antiPion;
618634
}
619-
if (std::abs(RecCollision.posZ()) > cfgCutVertex) {
635+
if (aLambdaTag) {
636+
antiProton = ROOT::Math::PxPyPzMVector(v0.pxneg(), v0.pyneg(), v0.pzneg(), o2::constants::physics::MassProton);
637+
pion = ROOT::Math::PxPyPzMVector(v0.pxpos(), v0.pypos(), v0.pzpos(), o2::constants::physics::MassPionCharged);
638+
antiLambda = antiProton + pion;
639+
}
640+
if (lambdaTag && aLambdaTag) {
620641
continue;
621642
}
622-
auto centrality = RecCollision.centFT0C();
623-
histos.fill(HIST("hCentrality"), centrality);
624-
for (const auto& v0 : V0s) {
625-
auto [lambdaTag, aLambdaTag, isValid] = getLambdaTagsMC(v0, RecCollision);
626-
if (!isValid) {
643+
auto postrack1 = v0.template posTrack_as<TrackMCRecTable>();
644+
auto negtrack1 = v0.template negTrack_as<TrackMCRecTable>();
645+
// 2nd loop for combination of lambda lambda
646+
for (const auto& v02 : V0s) {
647+
if (v02.index() <= v0.index()) {
627648
continue;
628649
}
629-
if (lambdaTag) {
630-
proton = ROOT::Math::PxPyPzMVector(v0.pxpos(), v0.pypos(), v0.pzpos(), o2::constants::physics::MassProton);
631-
antiPion = ROOT::Math::PxPyPzMVector(v0.pxneg(), v0.pyneg(), v0.pzneg(), o2::constants::physics::MassPionCharged);
632-
lambda = proton + antiPion;
633-
}
634-
if (aLambdaTag) {
635-
antiProton = ROOT::Math::PxPyPzMVector(v0.pxneg(), v0.pyneg(), v0.pzneg(), o2::constants::physics::MassProton);
636-
pion = ROOT::Math::PxPyPzMVector(v0.pxpos(), v0.pypos(), v0.pzpos(), o2::constants::physics::MassPionCharged);
637-
antiLambda = antiProton + pion;
638-
}
639-
if (lambdaTag && aLambdaTag) {
650+
auto [lambdaTag2, aLambdaTag2, isValid2] = getLambdaTagsMC(v02, collision);
651+
if (!isValid2) {
640652
continue;
641653
}
642-
auto postrack1 = v0.template posTrack_as<TrackMCRecTable>();
643-
auto negtrack1 = v0.template negTrack_as<TrackMCRecTable>();
644-
// 2nd loop for combination of lambda lambda
645-
for (const auto& v02 : V0s) {
646-
if (v02.v0Id() <= v0.v0Id()) {
647-
continue;
648-
}
649-
auto [lambdaTag2, aLambdaTag2, isValid2] = getLambdaTagsMC(v02, RecCollision);
650-
if (!isValid2) {
651-
continue;
652-
}
653-
if (lambdaTag2) {
654-
proton2 = ROOT::Math::PxPyPzMVector(v02.pxpos(), v02.pypos(), v02.pzpos(), o2::constants::physics::MassProton);
655-
antiPion2 = ROOT::Math::PxPyPzMVector(v02.pxneg(), v02.pyneg(), v02.pzneg(), o2::constants::physics::MassPionCharged);
656-
lambda2 = proton2 + antiPion2;
657-
}
658-
if (aLambdaTag2) {
659-
antiProton2 = ROOT::Math::PxPyPzMVector(v02.pxneg(), v02.pyneg(), v02.pzneg(), o2::constants::physics::MassProton);
660-
pion2 = ROOT::Math::PxPyPzMVector(v02.pxpos(), v02.pypos(), v02.pzpos(), o2::constants::physics::MassPionCharged);
661-
antiLambda2 = antiProton2 + pion2;
662-
}
663-
if (lambdaTag && aLambdaTag) {
664-
continue;
665-
}
666-
auto postrack2 = v02.template posTrack_as<TrackMCRecTable>();
667-
auto negtrack2 = v02.template negTrack_as<TrackMCRecTable>();
668-
if (postrack1.globalIndex() == postrack2.globalIndex() || negtrack1.globalIndex() == negtrack2.globalIndex()) {
669-
continue; // no shared decay products
670-
}
671-
if (lambdaTag && lambdaTag2) {
672-
fillHistograms(1, 0, 1, 0, lambda, lambda2, proton, proton2, centrality, 0);
673-
}
674-
if (aLambdaTag && aLambdaTag2) {
675-
fillHistograms(0, 1, 0, 1, antiLambda, antiLambda2, antiProton, antiProton2, centrality, 0);
676-
}
677-
if (lambdaTag && aLambdaTag2) {
678-
fillHistograms(1, 0, 0, 1, lambda, antiLambda2, proton, antiProton2, centrality, 0);
679-
}
680-
if (aLambdaTag && lambdaTag2) {
681-
fillHistograms(0, 1, 1, 0, antiLambda, lambda2, antiProton, proton2, centrality, 0);
682-
}
654+
if (lambdaTag2) {
655+
proton2 = ROOT::Math::PxPyPzMVector(v02.pxpos(), v02.pypos(), v02.pzpos(), o2::constants::physics::MassProton);
656+
antiPion2 = ROOT::Math::PxPyPzMVector(v02.pxneg(), v02.pyneg(), v02.pzneg(), o2::constants::physics::MassPionCharged);
657+
lambda2 = proton2 + antiPion2;
683658
}
684-
}
685-
686-
//*******generated****************
687-
for (const auto& mcParticle : GenParticles) {
688-
if (std::abs(mcParticle.y()) > confV0Rap) {
689-
continue;
659+
if (aLambdaTag2) {
660+
antiProton2 = ROOT::Math::PxPyPzMVector(v02.pxneg(), v02.pyneg(), v02.pzneg(), o2::constants::physics::MassProton);
661+
pion2 = ROOT::Math::PxPyPzMVector(v02.pxpos(), v02.pypos(), v02.pzpos(), o2::constants::physics::MassPionCharged);
662+
antiLambda2 = antiProton2 + pion2;
690663
}
691-
if (std::abs(mcParticle.pdgCode()) != PDG_t::kLambda0) {
664+
if (lambdaTag && aLambdaTag) {
692665
continue;
693666
}
694-
695-
int tagamc = 0;
696-
int tagbmc = 0;
697-
int taga2mc = 0;
698-
int tagb2mc = 0;
699-
700-
auto pdg1 = mcParticle.pdgCode();
701-
auto kDaughters = mcParticle.daughters_as<aod::McParticles>();
702-
int daughsize = 2;
703-
if (kDaughters.size() != daughsize) {
704-
continue;
667+
auto postrack2 = v02.template posTrack_as<TrackMCRecTable>();
668+
auto negtrack2 = v02.template negTrack_as<TrackMCRecTable>();
669+
if (postrack1.globalIndex() == postrack2.globalIndex() || negtrack1.globalIndex() == negtrack2.globalIndex()) {
670+
continue; // no shared decay products
705671
}
706-
707-
for (const auto& kCurrentDaughter : kDaughters) {
708-
709-
if (std::abs(kCurrentDaughter.pdgCode()) != PDG_t::kProton && std::abs(kCurrentDaughter.pdgCode()) != PDG_t::kPiPlus) {
710-
continue;
711-
}
712-
713-
if (kCurrentDaughter.pdgCode() == PDG_t::kProton) {
714-
protonmc = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), o2::constants::physics::MassProton);
715-
}
716-
if (kCurrentDaughter.pdgCode() == PDG_t::kPiMinus) {
717-
antiPionmc = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), o2::constants::physics::MassPionCharged);
718-
}
719-
720-
if (kCurrentDaughter.pdgCode() == PDG_t::kProtonBar) {
721-
antiProtonmc = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), o2::constants::physics::MassProton);
722-
}
723-
if (kCurrentDaughter.pdgCode() == PDG_t::kPiPlus) {
724-
pionmc = ROOT::Math::PxPyPzMVector(kCurrentDaughter.px(), kCurrentDaughter.py(), kCurrentDaughter.pz(), o2::constants::physics::MassPionCharged);
725-
}
672+
if (lambdaTag && lambdaTag2) {
673+
fillHistograms(1, 0, 1, 0, lambda, lambda2, proton, proton2, centrality, 0);
726674
}
727-
if (pdg1 == PDG_t::kLambda0) {
728-
tagamc = 1;
729-
lambdamc = protonmc + antiPionmc;
675+
if (aLambdaTag && aLambdaTag2) {
676+
fillHistograms(0, 1, 0, 1, antiLambda, antiLambda2, antiProton, antiProton2, centrality, 0);
730677
}
731-
732-
if (pdg1 == PDG_t::kLambda0Bar) {
733-
tagbmc = 1;
734-
antiLambdamc = antiProtonmc + pionmc;
678+
if (lambdaTag && aLambdaTag2) {
679+
fillHistograms(1, 0, 0, 1, lambda, antiLambda2, proton, antiProton2, centrality, 0);
735680
}
736-
737-
for (const auto& mcParticle2 : GenParticles) {
738-
if (std::abs(mcParticle2.y()) > confV0Rap) {
739-
continue;
740-
}
741-
if (std::abs(mcParticle2.pdgCode()) != PDG_t::kLambda0) {
742-
continue;
743-
}
744-
if (mcParticle.globalIndex() >= mcParticle2.globalIndex()) {
745-
continue;
746-
}
747-
748-
auto pdg2 = mcParticle2.pdgCode();
749-
auto kDaughters2 = mcParticle2.daughters_as<aod::McParticles>();
750-
751-
if (kDaughters2.size() != daughsize) {
752-
continue;
753-
}
754-
755-
for (const auto& kCurrentDaughter2 : kDaughters2) {
756-
if (std::abs(kCurrentDaughter2.pdgCode()) != PDG_t::kProton && std::abs(kCurrentDaughter2.pdgCode()) != PDG_t::kPiPlus) {
757-
continue;
758-
}
759-
760-
if (kCurrentDaughter2.pdgCode() == PDG_t::kProton) {
761-
proton2mc = ROOT::Math::PxPyPzMVector(kCurrentDaughter2.px(), kCurrentDaughter2.py(), kCurrentDaughter2.pz(), o2::constants::physics::MassProton);
762-
}
763-
if (kCurrentDaughter2.pdgCode() == PDG_t::kPiMinus) {
764-
antiPion2mc = ROOT::Math::PxPyPzMVector(kCurrentDaughter2.px(), kCurrentDaughter2.py(), kCurrentDaughter2.pz(), o2::constants::physics::MassPionCharged);
765-
}
766-
767-
if (kCurrentDaughter2.pdgCode() == PDG_t::kProtonBar) {
768-
antiProton2mc = ROOT::Math::PxPyPzMVector(kCurrentDaughter2.px(), kCurrentDaughter2.py(), kCurrentDaughter2.pz(), o2::constants::physics::MassProton);
769-
}
770-
if (kCurrentDaughter2.pdgCode() == PDG_t::kPiPlus) {
771-
pion2mc = ROOT::Math::PxPyPzMVector(kCurrentDaughter2.px(), kCurrentDaughter2.py(), kCurrentDaughter2.pz(), o2::constants::physics::MassPionCharged);
772-
}
773-
}
774-
775-
if (pdg2 == PDG_t::kLambda0) {
776-
taga2mc = 1;
777-
lambda2mc = proton2mc + antiPion2mc;
778-
}
779-
780-
if (pdg2 == PDG_t::kLambda0Bar) {
781-
tagb2mc = 1;
782-
antiLambda2mc = antiProton2mc + pion2mc;
783-
}
784-
785-
if (tagamc && taga2mc) {
786-
fillHistograms(tagamc, tagbmc, taga2mc, tagb2mc, lambdamc, lambda2mc, protonmc, proton2mc, centrality, 1);
787-
}
788-
if (tagamc && tagb2mc) {
789-
fillHistograms(tagamc, tagbmc, taga2mc, tagb2mc, lambdamc, antiLambda2mc, protonmc, antiProton2mc, centrality, 1);
790-
}
791-
792-
if (tagbmc && taga2mc) {
793-
fillHistograms(tagamc, tagbmc, taga2mc, tagb2mc, antiLambdamc, lambda2mc, antiProtonmc, proton2mc, centrality, 1);
794-
}
795-
796-
if (tagbmc && tagb2mc) {
797-
fillHistograms(tagamc, tagbmc, taga2mc, tagb2mc, antiLambdamc, antiLambda2mc, antiProtonmc, antiProton2mc, centrality, 1);
798-
}
681+
if (aLambdaTag && lambdaTag2) {
682+
fillHistograms(0, 1, 1, 0, antiLambda, lambda2, antiProton, proton2, centrality, 0);
799683
}
800684
}
801685
}
@@ -827,9 +711,14 @@ struct LfTaskLambdaSpinCorr {
827711
auto groupV03 = V0s.sliceBy(tracksPerCollisionV0, collision2.globalIndex());
828712
// for (auto& [t1, t2, t3] : soa::combinations(o2::soa::CombinationsFullIndexPolicy(groupV01, groupV02, groupV03))) {
829713
// LOGF(info, "Mixed event collisions: (%d, %d, %d)", t1.collisionId(),t2.collisionId(),t3.collisionId());
714+
auto maxV0Size = 1100;
715+
if (groupV01.size() > maxV0Size || groupV02.size() > maxV0Size || groupV03.size() > maxV0Size) {
716+
continue;
717+
}
718+
bool pairStatus[1150][1150] = {{false}};
830719
for (auto& [t1, t2] : soa::combinations(o2::soa::CombinationsFullIndexPolicy(groupV01, groupV02))) {
831720
bool pairfound = false;
832-
if (t2.v0Id() <= t1.v0Id()) {
721+
if (t2.index() <= t1.index()) {
833722
continue;
834723
}
835724
if (t1.collisionId() != t2.collisionId()) {
@@ -850,6 +739,10 @@ struct LfTaskLambdaSpinCorr {
850739
continue;
851740
}
852741
for (const auto& t3 : groupV03) {
742+
if (pairStatus[t3.index()][t2.index()]) {
743+
// LOGF(info, "repeat match found v0 id: (%d, %d)", t3.index(), t2.index());
744+
continue;
745+
}
853746
if (t1.collisionId() == t3.collisionId()) {
854747
continue;
855748
}
@@ -872,7 +765,6 @@ struct LfTaskLambdaSpinCorr {
872765
if (std::abs(t1.phi() - t3.phi()) > phiMix) {
873766
continue;
874767
}
875-
876768
if (lambdaTag2) {
877769
proton = ROOT::Math::PxPyPzMVector(t2.pxpos(), t2.pypos(), t2.pzpos(), o2::constants::physics::MassProton);
878770
antiPion = ROOT::Math::PxPyPzMVector(t2.pxneg(), t2.pyneg(), t2.pzneg(), o2::constants::physics::MassPionCharged);
@@ -906,6 +798,7 @@ struct LfTaskLambdaSpinCorr {
906798
fillHistograms(0, 1, 1, 0, antiLambda, lambda2, antiProton, proton2, centrality, 2);
907799
}
908800
pairfound = true;
801+
pairStatus[t3.index()][t2.index()] = true;
909802
if (pairfound) {
910803
// LOGF(info, "Pair found");
911804
break;

0 commit comments

Comments
 (0)