@@ -113,6 +113,11 @@ enum class D0CandFlag : uint8_t {
113113
114114struct HfProducerCharmHadronsTrackFemtoDream {
115115
116+ enum TrackCharge {
117+ PositiveCharge = 1 ,
118+ NegativeCharge = -1
119+ };
120+
116121 struct : ProducesGroup {
117122 Produces<aod::FDCollisions> outputCollision;
118123 Produces<aod::FDColMasks> rowMasks;
@@ -237,8 +242,8 @@ struct HfProducerCharmHadronsTrackFemtoDream {
237242
238243 using FemtoFullCollision = soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFT0Ms>::iterator;
239244 using FemtoFullCollisionMc = soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFT0Ms, aod::McCollisionLabels>::iterator;
240- using FemtoFullMcgenCollisions = soa::Join<aod::McCollisions, o2::aod::MultsExtraMC>;
241- using FemtoFullMcgenCollision = FemtoFullMcgenCollisions ::iterator;
245+ using FemtoMcgenCollisions = soa::Join<aod::McCollisions, o2::aod::MultsExtraMC>;
246+ using FemtoMcgenCollision = FemtoMcgenCollisions ::iterator;
242247 using FemtoHFTracks = soa::Join<aod::FullTracks, aod::TracksDCA, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, aod::pidTPCFullDe, aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFFullDe, aod::TracksPidPi, aod::PidTpcTofFullPi, aod::TracksPidKa, aod::PidTpcTofFullKa, aod::TracksPidPr, aod::PidTpcTofFullPr>;
243248 using FemtoHFTrack = FemtoHFTracks::iterator;
244249 using FemtoHFMcTracks = soa::Join<aod::McTrackLabels, FemtoHFTracks>;
@@ -255,6 +260,8 @@ struct HfProducerCharmHadronsTrackFemtoDream {
255260 Filter filterSelectCandidateLc = (aod::hf_sel_candidate_lc::isSelLcToPKPi >= generalCfg.selectionFlagHadron || aod::hf_sel_candidate_lc::isSelLcToPiKP >= generalCfg.selectionFlagHadron);
256261 Filter filterSelectCandidateXic = aod::hf_sel_candidate_xic::isSelXicToXiPiPi >= generalCfg.selectionFlagHadron;
257262
263+ Preslice<GeneratedDstarMc> perMcCollision = aod::mcparticle::mcCollisionId;
264+
258265 HistogramRegistry qaRegistry{" QAHistos" , {}, OutputObjHandlingPolicy::AnalysisObject};
259266 HistogramRegistry trackRegistry{" Tracks" , {}, OutputObjHandlingPolicy::AnalysisObject};
260267 OutputObj<ZorroSummary> zorroSummary{" zorroSummary" };
@@ -555,7 +562,7 @@ struct HfProducerCharmHadronsTrackFemtoDream {
555562 void fillMcCollision (CollisionType const & col)
556563 {
557564 if (col.has_mcCollision ()) {
558- // auto genMCcol = col.template mcCollision_as<FemtoFullMcgenCollisions >();
565+ // auto genMCcol = col.template mcCollision_as<FemtoMcgenCollisions >();
559566 // tables.outputMcCollision(genMCcol.multMCNParticlesEta08());
560567 tables.outputCollsMcLabels (tables.outputMcCollision .lastIndex ());
561568 } else {
@@ -1084,29 +1091,112 @@ struct HfProducerCharmHadronsTrackFemtoDream {
10841091 // / \param TC type of the femto track cuts
10851092 // / \return whether or not the tracks fulfills the all selections
10861093 template <typename C, typename T, typename TC >
1087- bool isNoSelectedTracks (C const & /* col*/ , T const & tracks, TC & trackCuts )
1094+ bool isNoSelectedTracks (C const & /* col*/ , T const & tracks, TC & trackSelections )
10881095 {
10891096 for (auto const & track : tracks) {
1090- if (trackCuts .isSelectedMinimal (track)) {
1097+ if (trackSelections .isSelectedMinimal (track)) {
10911098 return false ;
10921099 }
10931100 }
10941101 return true ;
10951102 }
10961103
10971104 template <DecayChannel Channel, typename ParticleType>
1098- void fillCharmHadMcGen (const ParticleType& particles)
1105+ void fillCharmHadMcGen (const ParticleType& particles, FemtoMcgenCollisions const * collisions = nullptr )
10991106 {
11001107 // Filling particle properties
11011108 tables.rowCandCharmHadGen .reserve (particles.size () + 1 );
11021109 if constexpr (Channel == DecayChannel::DplusToPiKPi) {
1103- for (const auto & particle : particles) {
1104- if (std::abs (particle.flagMcMatchGen ()) == hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi) {
1105- tables.rowCandCharmHadGen (
1106- particle.mcCollisionId (),
1107- particle.flagMcMatchGen (),
1108- particle.originMcGen ());
1110+ constexpr int InvalidMcIndex = -1 ;
1111+ const int64_t timeStamp = -1 ; // No need for Gen process.
1112+ const float bdtScore = -1 .f ; // No need for Gen particles.
1113+ const float dcaXY = 999 .f ; // No need for Gen particles.
1114+ const float sphericity = 2 .f ; // Not computed.
1115+ const aod::femtodreamparticle::cutContainerType bitPos = 1u << 1 ;
1116+ const aod::femtodreamparticle::cutContainerType bitNeg = 1u << 0 ;
1117+ std::vector<int > daughterIds;
1118+ std::vector<int > const childIds = {InvalidMcIndex, InvalidMcIndex};
1119+ for (const auto & col : *collisions) {
1120+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::All);
1121+ if (col.posZ () < hfEvSel.zPvPosMin || col.posZ () > hfEvSel.zPvPosMax ) {
1122+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::RejEveSel);
1123+ continue ;
1124+ }
1125+ auto groupedMCParticles = particles.sliceBy (perMcCollision, col.globalIndex ());
1126+ // MC provides particle multiplicity, but no reconstructed centrality or magnetic field.
1127+ const float multiplicityPercentile = 0 .f ;
1128+ const float magneticField = 0 .f ;
1129+ tables.outputCollision (col.posZ (), multiplicityPercentile, col.multMCNParticlesEta08 (), sphericity, magneticField);
1130+ tables.outputMcCollision (col.multMCNParticlesEta08 ());
1131+ tables.outputCollsMcLabels (tables.outputMcCollision .lastIndex ());
1132+
1133+ bool isTrackFilled = false ;
1134+ bool isCharmFilled = false ;
1135+ for (const auto & particle : groupedMCParticles) {
1136+ if (std::abs (particle.pdgCode ()) != o2::constants::physics::Pdg::kDPlus ||
1137+ std::abs (particle.flagMcMatchGen ()) != hf_decay::hf_cand_3prong::DecayChannelMain::DplusToPiKPi ||
1138+ !particle.producedByGenerator ()) {
1139+ continue ;
1140+ }
1141+ daughterIds.clear ();
1142+ RecoDecay::getDaughters (particle, &daughterIds, std::array<int , 2 >{kPiPlus , kKPlus });
1143+ int prong0Id = InvalidMcIndex;
1144+ int prong1Id = InvalidMcIndex;
1145+ int prong2Id = InvalidMcIndex;
1146+ for (const auto & daughterId : daughterIds) {
1147+ const auto daughter = particles.rawIteratorAt (daughterId);
1148+ if (std::abs (daughter.pdgCode ()) == kKPlus ) {
1149+ prong1Id = daughter.globalIndex ();
1150+ } else if (std::abs (daughter.pdgCode ()) == kPiPlus ) {
1151+ if (prong0Id == InvalidMcIndex) {
1152+ prong0Id = daughter.globalIndex ();
1153+ } else {
1154+ prong2Id = daughter.globalIndex ();
1155+ }
1156+ }
1157+ }
1158+ const auto prong0 = particles.rawIteratorAt (prong0Id);
1159+ const auto prong1 = particles.rawIteratorAt (prong1Id);
1160+ const auto prong2 = particles.rawIteratorAt (prong2Id);
1161+ tables.rowCandCharm3Prong (tables.outputCollision .lastIndex (), timeStamp,
1162+ particle.pdgCode () > 0 ? PositiveCharge : NegativeCharge,
1163+ prong0Id, prong1Id, prong2Id,
1164+ prong0.pt (), prong1.pt (), prong2.pt (),
1165+ prong0.eta (), prong1.eta (), prong2.eta (),
1166+ prong0.phi (), prong1.phi (), prong2.phi (),
1167+ true , bdtScore, bdtScore, bdtScore);
1168+ const auto particleOrigin = particle.originMcGen () == RecoDecay::OriginType::Prompt
1169+ ? aod::femtodreamMCparticle::ParticleOriginMCTruth::kPrimary
1170+ : aod::femtodreamMCparticle::ParticleOriginMCTruth::kSecondaryFromHF ;
1171+ tables.outputPartsMc (particleOrigin, particle.pdgCode (), particle.pt (), particle.eta (), particle.phi ());
1172+ tables.rowCandCharmHadGen (tables.outputPartsMc .lastIndex (), particle.flagMcMatchGen (), particle.originMcGen ());
1173+ tables.rowCandMcCharmHad (particle.flagMcMatchGen (), particle.originMcGen ());
1174+ tables.outputPartsMcLabels (tables.outputPartsMc .lastIndex ());
1175+ isCharmFilled = true ;
1176+ }
1177+ for (const auto & particle : groupedMCParticles) {
1178+ if (std::abs (particle.pdgCode ()) == std::abs (trackCfg.trkPDGCode .value ) && particle.isPhysicalPrimary () && particle.producedByGenerator ()) {
1179+ tables.outputPartsIndex (particle.globalIndex ());
1180+ tables.outputPartsTime (timeStamp);
1181+ // Store the PDG code instead of detector PID bits, as in the femto truth producer.
1182+ tables.outputParts (tables.outputCollision .lastIndex (),
1183+ particle.pt (), particle.eta (), particle.phi (),
1184+ aod::femtodreamparticle::ParticleType::kTrack ,
1185+ particle.pdgCode () > 0 ? bitPos : bitNeg,
1186+ std::abs (particle.pdgCode ()), dcaXY, childIds, 0 .f , 0 .f );
1187+ isTrackFilled = true ;
1188+ }
11091189 }
1190+ if (isTrackFilled) {
1191+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::TrackSelected);
1192+ }
1193+ if (isCharmFilled) {
1194+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::CharmSelected);
1195+ }
1196+ if (isTrackFilled && isCharmFilled) {
1197+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::PairSelected);
1198+ }
1199+ tables.rowMasks (isTrackFilled, isCharmFilled, false );
11101200 }
11111201 } else if constexpr (Channel == DecayChannel::LcToPKPi) {
11121202 for (const auto & particle : particles) {
@@ -1127,13 +1217,99 @@ struct HfProducerCharmHadronsTrackFemtoDream {
11271217 }
11281218 }
11291219 } else if constexpr (Channel == DecayChannel::DstarToD0Pi) {
1130- for (const auto & particle : particles) {
1131- if (std::abs (particle.flagMcMatchGen ()) == hf_decay::hf_cand_dstar::DecayChannelMain::DstarToPiKPi) {
1132- tables.rowCandCharmHadGen (
1133- particle.mcCollisionId (),
1134- particle.flagMcMatchGen (),
1135- particle.originMcGen ());
1220+ constexpr int InvalidMcIndex = -1 ;
1221+ const int64_t timeStamp = -1 ; // No need for Gen process.
1222+ const float bdtScore = -1 .f ; // No need for Gen particles.
1223+ const float dcaXY = 999 .f ; // No need for Gen particles.
1224+ const float sphericity = 2 .f ; // Not computed.
1225+ const aod::femtodreamparticle::cutContainerType bitPos = 1u << 1 ;
1226+ const aod::femtodreamparticle::cutContainerType bitNeg = 1u << 0 ;
1227+ std::vector<int > daughterIds;
1228+ std::vector<int > const childIds = {InvalidMcIndex, InvalidMcIndex};
1229+ for (const auto & col : *collisions) {
1230+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::All);
1231+ if (col.posZ () < hfEvSel.zPvPosMin || col.posZ () > hfEvSel.zPvPosMax ) {
1232+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::RejEveSel);
1233+ continue ;
1234+ }
1235+ auto groupedMCParticles = particles.sliceBy (perMcCollision, col.globalIndex ());
1236+ // MC provides particle multiplicity, but no reconstructed centrality or magnetic field.
1237+ const float multiplicityPercentile = 0 .f ;
1238+ const float magneticField = 0 .f ;
1239+ tables.outputCollision (col.posZ (), multiplicityPercentile, col.multMCNParticlesEta08 (), sphericity, magneticField);
1240+ tables.outputMcCollision (col.multMCNParticlesEta08 ());
1241+ tables.outputCollsMcLabels (tables.outputMcCollision .lastIndex ());
1242+
1243+ bool isTrackFilled = false ;
1244+ bool isCharmFilled = false ;
1245+ for (const auto & particle : groupedMCParticles) {
1246+ if (std::abs (particle.pdgCode ()) != o2::constants::physics::Pdg::kDStar ||
1247+ std::abs (particle.flagMcMatchGen ()) != hf_decay::hf_cand_dstar::DecayChannelMain::DstarToPiKPi ||
1248+ !particle.producedByGenerator ()) {
1249+ continue ;
1250+ }
1251+ daughterIds.clear ();
1252+ RecoDecay::getDaughters (particle, &daughterIds, std::array<int , 2 >{kPiPlus , kKPlus });
1253+ int prongPosId = InvalidMcIndex;
1254+ int prongNegId = InvalidMcIndex;
1255+ int softPionId = InvalidMcIndex;
1256+ for (const auto & daughterId : daughterIds) {
1257+ const auto daughter = particles.rawIteratorAt (daughterId);
1258+ if (std::abs (daughter.pdgCode ()) != kPiPlus && std::abs (daughter.pdgCode ()) != kKPlus ) {
1259+ continue ;
1260+ }
1261+ const auto mother = daughter.template mothers_first_as <ParticleType>();
1262+ if (std::abs (mother.pdgCode ()) == o2::constants::physics::Pdg::kDStar ) {
1263+ softPionId = daughter.globalIndex ();
1264+ } else if (daughter.pdgCode () > 0 ) {
1265+ prongPosId = daughter.globalIndex ();
1266+ } else {
1267+ prongNegId = daughter.globalIndex ();
1268+ }
1269+ }
1270+ const auto prongPos = particles.rawIteratorAt (prongPosId);
1271+ const auto prongNeg = particles.rawIteratorAt (prongNegId);
1272+ const auto softPion = particles.rawIteratorAt (softPionId);
1273+ // The existing pair-mass helper selects the pion/kaon hypothesis with candidateSelFlag == 1.
1274+ tables.rowCandCharmDstar (tables.outputCollision .lastIndex (), timeStamp,
1275+ particle.pdgCode () > 0 ? PositiveCharge : NegativeCharge,
1276+ prongPosId, prongNegId, softPionId,
1277+ prongPos.pt (), prongNeg.pt (), softPion.pt (),
1278+ prongPos.eta (), prongNeg.eta (), softPion.eta (),
1279+ prongPos.phi (), prongNeg.phi (), softPion.phi (),
1280+ particle.pdgCode () > 0 , bdtScore, bdtScore, bdtScore);
1281+ const auto particleOrigin = particle.originMcGen () == RecoDecay::OriginType::Prompt
1282+ ? aod::femtodreamMCparticle::ParticleOriginMCTruth::kPrimary
1283+ : aod::femtodreamMCparticle::ParticleOriginMCTruth::kSecondaryFromHF ;
1284+ tables.outputPartsMc (particleOrigin, particle.pdgCode (), particle.pt (), particle.eta (), particle.phi ());
1285+ tables.rowCandCharmHadGen (tables.outputPartsMc .lastIndex (), particle.flagMcMatchGen (), particle.originMcGen ());
1286+ tables.rowCandMcCharmHad (particle.flagMcMatchGen (), particle.originMcGen ());
1287+ tables.outputPartsMcLabels (tables.outputPartsMc .lastIndex ());
1288+ isCharmFilled = true ;
1289+ }
1290+ for (const auto & particle : groupedMCParticles) {
1291+ if (std::abs (particle.pdgCode ()) == std::abs (trackCfg.trkPDGCode .value ) && particle.isPhysicalPrimary () && particle.producedByGenerator ()) {
1292+ tables.outputPartsIndex (particle.globalIndex ());
1293+ tables.outputPartsTime (timeStamp);
1294+ // Store the PDG code instead of detector PID bits, as in the femto truth producer.
1295+ tables.outputParts (tables.outputCollision .lastIndex (),
1296+ particle.pt (), particle.eta (), particle.phi (),
1297+ aod::femtodreamparticle::ParticleType::kTrack ,
1298+ particle.pdgCode () > 0 ? bitPos : bitNeg,
1299+ std::abs (particle.pdgCode ()), dcaXY, childIds, 0 .f , 0 .f );
1300+ isTrackFilled = true ;
1301+ }
11361302 }
1303+ if (isTrackFilled) {
1304+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::TrackSelected);
1305+ }
1306+ if (isCharmFilled) {
1307+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::CharmSelected);
1308+ }
1309+ if (isTrackFilled && isCharmFilled) {
1310+ qaRegistry.fill (HIST (" hEventQA" ), 1 + Event::PairSelected);
1311+ }
1312+ tables.rowMasks (isTrackFilled, isCharmFilled, false );
11371313 }
11381314 }
11391315 }
@@ -1257,10 +1433,9 @@ struct HfProducerCharmHadronsTrackFemtoDream {
12571433 }
12581434 PROCESS_SWITCH (HfProducerCharmHadronsTrackFemtoDream, processMcDstarToD0PiWithML, " Provide Mc for DstarToD0Pi with ml" , false );
12591435
1260- void processMcDstarToD0PiGen (GeneratedDstarMc const & particles)
1436+ void processMcDstarToD0PiGen (FemtoMcgenCollisions const & collisions, GeneratedDstarMc const & particles)
12611437 {
1262-
1263- fillCharmHadMcGen<DecayChannel::DstarToD0Pi>(particles);
1438+ fillCharmHadMcGen<DecayChannel::DstarToD0Pi>(particles, &collisions);
12641439 }
12651440 PROCESS_SWITCH (HfProducerCharmHadronsTrackFemtoDream, processMcDstarToD0PiGen, " Provide Mc Generated DstarToD0Pi" , false );
12661441
@@ -1314,10 +1489,10 @@ struct HfProducerCharmHadronsTrackFemtoDream {
13141489 }
13151490 PROCESS_SWITCH (HfProducerCharmHadronsTrackFemtoDream, processMcDplusToPiKPiWithML, " Provide Mc for DplusToPiKPi with ml" , false );
13161491
1317- void processMcDplusToPiKPiGen (Generated3ProngMc const & particles)
1492+ void processMcDplusToPiKPiGen (FemtoMcgenCollisions const & collisions, Generated3ProngMc const & particles)
13181493 {
13191494
1320- fillCharmHadMcGen<DecayChannel::DplusToPiKPi>(particles);
1495+ fillCharmHadMcGen<DecayChannel::DplusToPiKPi>(particles, &collisions );
13211496 }
13221497 PROCESS_SWITCH (HfProducerCharmHadronsTrackFemtoDream, processMcDplusToPiKPiGen, " Provide Mc Generated DplusToPiKPi" , false );
13231498
0 commit comments