Skip to content

Commit f7fd852

Browse files
committed
[PWGEM/Dilepton] reduce ML data in taggingHFE.cxx
1 parent 20f98c4 commit f7fd852

2 files changed

Lines changed: 154 additions & 16 deletions

File tree

PWGEM/Dilepton/DataModel/lmeeMLTables.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ DECLARE_SOA_COLUMN(SubGeneratorId, subGeneratorId, int); //! sub generator Id of
201201
} // namespace emmlevent
202202
namespace emmltrack
203203
{
204-
DECLARE_SOA_COLUMN(IsMotherFromHF, isMotherFromHF, bool); //! is HF included in decay history
205-
DECLARE_SOA_COLUMN(PdgCodeMother, pdgCodeMother, int); //! pdg code of mother of lepton
204+
DECLARE_SOA_COLUMN(IsMotherFromBeauty, isMotherFromBeauty, bool); //! is b quark included in decay history
205+
DECLARE_SOA_COLUMN(PdgCodeMother, pdgCodeMother, int); //! pdg code of mother of lepton
206206
} // namespace emmltrack
207207

208208
DECLARE_SOA_TABLE(EMMLLeptons, "AOD", "EMMLLEPTON", //!
209209
o2::soa::Index<>, collision::NumContrib, evsel::NumTracksInTimeRange, evsel::SumAmpFT0CInTimeRange, emmlevent::SubGeneratorId,
210210
track::Signed1Pt, track::Eta,
211211
track::DcaXY, track::DcaZ, o2::aod::track::CYY, o2::aod::track::CZY, o2::aod::track::CZZ,
212-
emmltrack::IsMotherFromHF, emmltrack::PdgCodeMother);
212+
emmltrack::IsMotherFromBeauty, emmltrack::PdgCodeMother);
213213
// iterators
214214
using EMMLLepton = EMMLLeptons::iterator;
215215

PWGEM/Dilepton/Tasks/taggingHFE.cxx

Lines changed: 151 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,36 @@ struct taggingHFE {
776776
}
777777
}
778778

779+
template <typename TMCParticle, typename TMCParticles>
780+
bool isSemiLeptonic(TMCParticle const& mcParticle, TMCParticles const& mcParticles, const int pdgLepton, const int pdgNeutrino)
781+
{
782+
if (!mcParticle.has_daughters()) {
783+
return false;
784+
}
785+
bool is_lepton_involved = false;
786+
bool is_neutrino_involved = false;
787+
for (int d = mcParticle.daughtersIds()[0]; d <= mcParticle.daughtersIds()[1]; ++d) {
788+
if (d < mcParticles.size()) { // protect against bad daughter indices
789+
auto daughter = mcParticles.rawIteratorAt(d);
790+
if (daughter.pdgCode() == pdgLepton) {
791+
is_lepton_involved = true;
792+
} else if (daughter.pdgCode() == pdgNeutrino) {
793+
is_neutrino_involved = true;
794+
}
795+
} else {
796+
std::cout << "Daughter label (" << d << ") exceeds the McParticles size (" << mcParticles.size() << ")" << std::endl;
797+
std::cout << " Check the MC generator" << std::endl;
798+
return false;
799+
}
800+
}
801+
802+
if (is_lepton_involved && is_neutrino_involved) {
803+
return true;
804+
} else {
805+
return false;
806+
}
807+
}
808+
779809
template <typename TMCParticle, typename TMCParticles>
780810
bool isSemiLeptonic(TMCParticle const& mcParticle, TMCParticles const& mcParticles, const int pdgLepton, const int pdgNeutrino, const int pdgStrHad)
781811
{
@@ -1098,12 +1128,6 @@ struct taggingHFE {
10981128
}
10991129
} // end of cascade loop
11001130

1101-
// // if (electronIds.size() > 0 || positronIds.size() > 0) {
1102-
// if ((electronIds.size() > 0 || positronIds.size() > 0) && (xiMinusIds.size() > 0 || xiPlusIds.size() > 0)) {
1103-
// LOGF(info, "collision.globalIndex() = %d, electronIds.size() = %d, positronIds.size() = %d, kaonMinusIds.size() = %d, kaonPlusIds.size() = %d, k0Ids.size() = %d, lambdaIds.size() = %d, antilambdaIds.size() = %d, xiMinusIds.size() = %d, xiPlusIds.size() = %d, omegaMinusIds.size() = %d, omegaPlusIds.size() = %d",
1104-
// collision.globalIndex(), electronIds.size(), positronIds.size(), kaonMinusIds.size(), kaonPlusIds.size(), k0Ids.size(), lambdaIds.size(), antilambdaIds.size(), xiMinusIds.size(), xiPlusIds.size(), omegaMinusIds.size(), omegaPlusIds.size());
1105-
// }
1106-
11071131
for (const auto& positronId : positronIds) {
11081132
auto pos = tracks.rawIteratorAt(positronId);
11091133
mDcaInfoCov.set(999, 999, 999, 999, 999);
@@ -1114,13 +1138,21 @@ struct taggingHFE {
11141138
float dcaZ_lepton = mDcaInfoCov.getZ();
11151139

11161140
auto mcpos = pos.template mcParticle_as<aod::McParticles>();
1117-
auto mcmother = mcpos.template mothers_as<aod::McParticles>()[0];
1118-
bool isMotherFromHF = (IsFromCharm(mcmother, mcParticles) > 0) || (IsFromBeauty(mcmother, mcParticles) > 0);
1141+
auto mcMother = mcpos.template mothers_as<aod::McParticles>()[0];
1142+
bool isMotherFromB = IsFromBeauty(mcMother, mcParticles) > -1;
11191143
auto mcCollision = mcpos.template mcCollision_as<aod::McCollisions>();
11201144

1145+
bool is_e_from_dy = std::abs(mcMother.pdgCode()) == 23; // virtual photon is Z in simulation.
1146+
bool is_e_from_jpsi = std::abs(mcMother.pdgCode()) == 443;
1147+
bool is_e_from_hc = (std::abs(mcMother.pdgCode()) == 411 || std::abs(mcMother.pdgCode()) == 421 || std::abs(mcMother.pdgCode()) == 431 || std::abs(mcMother.pdgCode()) == 4122 || std::abs(mcMother.pdgCode()) == 4132 || std::abs(mcMother.pdgCode()) == 4232 || std::abs(mcMother.pdgCode()) == 4332) && isSemiLeptonic(mcMother, mcParticles, -cfgPdgLepton, cfgPdgLepton + 1);
1148+
bool is_e_from_hb = (std::abs(mcMother.pdgCode()) == 511 || std::abs(mcMother.pdgCode()) == 521 || std::abs(mcMother.pdgCode()) == 531 || std::abs(mcMother.pdgCode()) == 541 || std::abs(mcMother.pdgCode()) == 5122 || std::abs(mcMother.pdgCode()) == 5132 || std::abs(mcMother.pdgCode()) == 5232 || std::abs(mcMother.pdgCode()) == 5332) && isSemiLeptonic(mcMother, mcParticles, -cfgPdgLepton, cfgPdgLepton + 1);
1149+
if (!(is_e_from_dy || is_e_from_jpsi || is_e_from_hc || is_e_from_hb)) {
1150+
continue;
1151+
}
1152+
11211153
leptonTable(collision.numContrib(), collision.trackOccupancyInTimeRange(), collision.ft0cOccupancyInTimeRange(), mcCollision.getSubGeneratorId(),
11221154
leptonParCov.getQ2Pt(), leptonParCov.getEta(), dcaXY_lepton, dcaZ_lepton, leptonParCov.getSigmaY2(), leptonParCov.getSigmaZY(), leptonParCov.getSigmaZ2(),
1123-
isMotherFromHF, mcmother.pdgCode());
1155+
isMotherFromB, mcMother.pdgCode());
11241156

11251157
// D0 -> e+ nu_e K-, br = 0.03538, ctau = 123.01 um, m = 1864 MeV/c2
11261158
for (const auto& kaonId : kaonMinusIds) {
@@ -1158,6 +1190,22 @@ struct taggingHFE {
11581190
}
11591191
}
11601192

1193+
if (!(((is_e_from_hc || is_e_from_hb) && foundCommonMother) || ((is_e_from_dy || is_e_from_jpsi) && !foundCommonMother) || ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother && std::abs(mckaon.pdgCode()) == cfgPdgLepton))) {
1194+
// I want 3 types.
1195+
// 1. truely found HF->eh (SV should found by eh, and truely found.) For signal sample in ML.
1196+
// 2. mistakenly found DY->eh (SV should not be found by eh, but found.) For bkg sample in ML.
1197+
// 3. truely found DY->ee with misidentified ee. (SV may be found at the same position of PV.) For bkg sample in ML.
1198+
continue;
1199+
}
1200+
1201+
// if (std::abs(mckaon.pdgCode()) == 11) {
1202+
// LOGF(info, "mcMother.pdgCode() = %d, mckaon.pdgCode() = %d, foundCommonMother = %d", mcMother.pdgCode(), mckaon.pdgCode(), foundCommonMother);
1203+
// for (int d = mcMother.daughtersIds()[0]; d <= mcMother.daughtersIds()[1]; ++d) {
1204+
// auto daughter = mcParticles.rawIteratorAt(d);
1205+
// LOGF(info, "daughter.pdgCode() = %d", daughter.pdgCode());
1206+
// }
1207+
// }
1208+
11611209
float tofNSigmaPi = mapTOFNsigmaPiReassociated[std::make_pair(collision.globalIndex(), kaon.globalIndex())];
11621210
float tofNSigmaKa = mapTOFNsigmaKaReassociated[std::make_pair(collision.globalIndex(), kaon.globalIndex())];
11631211

@@ -1232,6 +1280,13 @@ struct taggingHFE {
12321280
}
12331281
}
12341282

1283+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1284+
continue;
1285+
}
1286+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1287+
continue;
1288+
}
1289+
12351290
emmllv0pair(leptonTable.lastIndex(),
12361291
v0.pt(), v0.rapidity(0),
12371292
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{v0.x(), v0.y(), v0.z()}, std::array<float, 3>{v0.px(), v0.py(), v0.pz()}),
@@ -1288,6 +1343,13 @@ struct taggingHFE {
12881343
foundCommonMother = FindCommonMotherFrom2ProngsWithoutPDG(mcpos, mcLambda) > 0;
12891344
}
12901345

1346+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1347+
continue;
1348+
}
1349+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1350+
continue;
1351+
}
1352+
12911353
emmllv0pair(leptonTable.lastIndex(),
12921354
v0.pt(), v0.rapidity(1),
12931355
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{v0.x(), v0.y(), v0.z()}, std::array<float, 3>{v0.px(), v0.py(), v0.pz()}),
@@ -1349,6 +1411,13 @@ struct taggingHFE {
13491411
}
13501412
}
13511413

1414+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1415+
continue;
1416+
}
1417+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1418+
continue;
1419+
}
1420+
13521421
emmllcascpair(leptonTable.lastIndex(),
13531422
cascade.pt(), cascade.rapidity(0),
13541423
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{cascade.x(), cascade.y(), cascade.z()}, std::array<float, 3>{cascade.px(), cascade.py(), cascade.pz()}),
@@ -1410,6 +1479,13 @@ struct taggingHFE {
14101479
}
14111480
}
14121481

1482+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1483+
continue;
1484+
}
1485+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1486+
continue;
1487+
}
1488+
14131489
emmllcascpair(leptonTable.lastIndex(),
14141490
cascade.pt(), cascade.rapidity(2),
14151491
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{cascade.x(), cascade.y(), cascade.z()}, std::array<float, 3>{cascade.px(), cascade.py(), cascade.pz()}),
@@ -1435,13 +1511,21 @@ struct taggingHFE {
14351511
float dcaZ_lepton = mDcaInfoCov.getZ();
14361512

14371513
auto mcele = ele.template mcParticle_as<aod::McParticles>();
1438-
auto mcmother = mcele.template mothers_as<aod::McParticles>()[0];
1439-
bool isMotherFromHF = (IsFromCharm(mcmother, mcParticles) > 0) || (IsFromBeauty(mcmother, mcParticles) > 0);
1514+
auto mcMother = mcele.template mothers_as<aod::McParticles>()[0];
1515+
bool isMotherFromB = IsFromBeauty(mcMother, mcParticles) > -1;
14401516
auto mcCollision = mcele.template mcCollision_as<aod::McCollisions>();
14411517

1518+
bool is_e_from_dy = std::abs(mcMother.pdgCode()) == 23; // virtual photon is Z in simulation.
1519+
bool is_e_from_jpsi = std::abs(mcMother.pdgCode()) == 443;
1520+
bool is_e_from_hc = (std::abs(mcMother.pdgCode()) == 411 || std::abs(mcMother.pdgCode()) == 421 || std::abs(mcMother.pdgCode()) == 431 || std::abs(mcMother.pdgCode()) == 4122 || std::abs(mcMother.pdgCode()) == 4132 || std::abs(mcMother.pdgCode()) == 4232 || std::abs(mcMother.pdgCode()) == 4332) && isSemiLeptonic(mcMother, mcParticles, cfgPdgLepton, -cfgPdgLepton - 1);
1521+
bool is_e_from_hb = (std::abs(mcMother.pdgCode()) == 511 || std::abs(mcMother.pdgCode()) == 521 || std::abs(mcMother.pdgCode()) == 531 || std::abs(mcMother.pdgCode()) == 541 || std::abs(mcMother.pdgCode()) == 5122 || std::abs(mcMother.pdgCode()) == 5132 || std::abs(mcMother.pdgCode()) == 5232 || std::abs(mcMother.pdgCode()) == 5332) && isSemiLeptonic(mcMother, mcParticles, cfgPdgLepton, -cfgPdgLepton - 1);
1522+
if (!(is_e_from_dy || is_e_from_jpsi || is_e_from_hc || is_e_from_hb)) {
1523+
continue;
1524+
}
1525+
14421526
leptonTable(collision.numContrib(), collision.trackOccupancyInTimeRange(), collision.ft0cOccupancyInTimeRange(), mcCollision.getSubGeneratorId(),
14431527
leptonParCov.getQ2Pt(), leptonParCov.getEta(), dcaXY_lepton, dcaZ_lepton, leptonParCov.getSigmaY2(), leptonParCov.getSigmaZY(), leptonParCov.getSigmaZ2(),
1444-
isMotherFromHF, mcmother.pdgCode());
1528+
isMotherFromB, mcMother.pdgCode());
14451529

14461530
// D0bar -> e- anti-nu_e K+, br = 0.03538, ctau = 123.01 um, m = 1864 MeV/c2
14471531
for (const auto& kaonId : kaonPlusIds) {
@@ -1478,6 +1562,22 @@ struct taggingHFE {
14781562
}
14791563
}
14801564

1565+
if (!(((is_e_from_hc || is_e_from_hb) && foundCommonMother) || ((is_e_from_dy || is_e_from_jpsi) && !foundCommonMother) || ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother && std::abs(mckaon.pdgCode()) == cfgPdgLepton))) {
1566+
// I want 3 types.
1567+
// 1. truely found HF->eh (SV should found by eh, and truely found.) For signal sample in ML.
1568+
// 2. mistakenly found DY->eh (SV should not be found by eh, but found.) For bkg sample in ML.
1569+
// 3. truely found DY->ee with misidentified ee. (SV may be found at the same position of PV.) For bkg sample in ML.
1570+
continue;
1571+
}
1572+
1573+
// if (std::abs(mckaon.pdgCode()) == 11) {
1574+
// LOGF(info, "mcMother.pdgCode() = %d, mckaon.pdgCode() = %d, foundCommonMother = %d", mcMother.pdgCode(), mckaon.pdgCode(), foundCommonMother);
1575+
// for (int d = mcMother.daughtersIds()[0]; d <= mcMother.daughtersIds()[1]; ++d) {
1576+
// auto daughter = mcParticles.rawIteratorAt(d);
1577+
// LOGF(info, "daughter.pdgCode() = %d", daughter.pdgCode());
1578+
// }
1579+
// }
1580+
14811581
float tofNSigmaPi = mapTOFNsigmaPiReassociated[std::make_pair(collision.globalIndex(), kaon.globalIndex())];
14821582
float tofNSigmaKa = mapTOFNsigmaKaReassociated[std::make_pair(collision.globalIndex(), kaon.globalIndex())];
14831583

@@ -1551,6 +1651,13 @@ struct taggingHFE {
15511651
}
15521652
}
15531653

1654+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1655+
continue;
1656+
}
1657+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1658+
continue;
1659+
}
1660+
15541661
emmllv0pair(leptonTable.lastIndex(),
15551662
v0.pt(), v0.rapidity(0),
15561663
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{v0.x(), v0.y(), v0.z()}, std::array<float, 3>{v0.px(), v0.py(), v0.pz()}),
@@ -1607,6 +1714,13 @@ struct taggingHFE {
16071714
foundCommonMother = FindCommonMotherFrom2ProngsWithoutPDG(mcele, mcLambda) > 0;
16081715
}
16091716

1717+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1718+
continue;
1719+
}
1720+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1721+
continue;
1722+
}
1723+
16101724
emmllv0pair(leptonTable.lastIndex(),
16111725
v0.pt(), v0.rapidity(1),
16121726
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{v0.x(), v0.y(), v0.z()}, std::array<float, 3>{v0.px(), v0.py(), v0.pz()}),
@@ -1668,6 +1782,13 @@ struct taggingHFE {
16681782
}
16691783
}
16701784

1785+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1786+
continue;
1787+
}
1788+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1789+
continue;
1790+
}
1791+
16711792
emmllcascpair(leptonTable.lastIndex(),
16721793
cascade.pt(), cascade.rapidity(0),
16731794
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{cascade.x(), cascade.y(), cascade.z()}, std::array<float, 3>{cascade.px(), cascade.py(), cascade.pz()}),
@@ -1729,6 +1850,13 @@ struct taggingHFE {
17291850
}
17301851
}
17311852

1853+
if ((is_e_from_hc || is_e_from_hb) && !foundCommonMother) {
1854+
continue;
1855+
}
1856+
if ((is_e_from_dy || is_e_from_jpsi) && foundCommonMother) {
1857+
continue;
1858+
}
1859+
17321860
emmllcascpair(leptonTable.lastIndex(),
17331861
cascade.pt(), cascade.rapidity(2),
17341862
RecoDecay::cpa(std::array<float, 3>{collision.posX(), collision.posY(), collision.posZ()}, std::array<float, 3>{cascade.x(), cascade.y(), cascade.z()}, std::array<float, 3>{cascade.px(), cascade.py(), cascade.pz()}),
@@ -1857,7 +1985,16 @@ struct taggingHFE {
18571985
fRegistry.fill(HIST("Generated/Lc/hsAcc"), ptLepton, ptHadron, etaLepton, etaHadron);
18581986
}
18591987

1860-
} // end of D0 loop per mcCollision
1988+
} // end of Lc loop per mcCollision
1989+
1990+
// auto mcB0s_per_mccollision = mcB0s.sliceBy(perMcCollision, mcCollision.globalIndex());
1991+
// for (const auto& mcParticle : mcB0s_per_mccollision) {
1992+
// LOGF(info, "B0: mcParticle.pdgCode() = %d", mcParticle.pdgCode());
1993+
// for (int d = mcParticle.daughtersIds()[0]; d <= mcParticle.daughtersIds()[1]; ++d) {
1994+
// auto daughter = mcParticles.rawIteratorAt(d);
1995+
// LOGF(info, "B0: daughter.pdgCode() = %d", daughter.pdgCode());
1996+
// }
1997+
// } // end of B0 loop per mcCollision
18611998
}
18621999
}
18632000

@@ -1867,6 +2004,7 @@ struct taggingHFE {
18672004
Partition<aod::McParticles> mcLcs = nabs(o2::aod::mcparticle::pdgCode) == 4122;
18682005
// Partition<aod::McParticles> mcXic0s = nabs(o2::aod::mcparticle::pdgCode) == 4232;
18692006
// Partition<aod::McParticles> mcOmegac0s = nabs(o2::aod::mcparticle::pdgCode) == 4332;
2007+
// Partition<aod::McParticles> mcB0s = nabs(o2::aod::mcparticle::pdgCode) == 511;
18702008

18712009
SliceCache cache;
18722010
Preslice<aod::TracksIU> perCol = o2::aod::track::collisionId;

0 commit comments

Comments
 (0)