@@ -316,6 +316,43 @@ class CharmHadronBuilder {
316316
317317 }
318318
319+ template <typename T1 , typename T2 , typename T3 >
320+ void fillD0Tables (T1 & collisionProducts, T2 & d0Products, T3 const & candidate,
321+ float signedPt, float mass, int64_t posDauIndex, int64_t negDauIndex)
322+ {
323+ if (mProduceD0s ) {
324+ d0Products.producedD0s (collisionProducts.producedCollision .lastIndex (),
325+ signedPt,
326+ candidate.eta (),
327+ candidate.phi (),
328+ mass,
329+ posDauIndex,
330+ negDauIndex);
331+ }
332+ if (mProduceD0Masks ) {
333+ d0Products.producedD0Masks (mD0Selection .getBitmask ());
334+ }
335+ if (mProduceD0Extras ) {
336+ d0Products.producedD0Extras (
337+ mHfHelper .invMassD0ToPiK (candidate),
338+ mHfHelper .invMassD0barToKPi (candidate),
339+ candidate.cpa (),
340+ candidate.cpaXY (),
341+ candidate.decayLength (),
342+ candidate.decayLengthXY (),
343+ candidate.impactParameter0 () * candidate.impactParameter1 (),
344+ mHfHelper .cosThetaStarD0 (candidate),
345+ candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[0 ],
346+ candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[1 ],
347+ candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[2 ],
348+ candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[0 ],
349+ candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[1 ],
350+ candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[2 ],
351+ static_cast <int8_t >(candidate.isSelD0 ()),
352+ static_cast <int8_t >(candidate.isSelD0bar ()));
353+ }
354+ }
355+
319356 template <modes::System system, typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 >
320357 void fillD0s (T1 const & col, T2 & collisionBuilder, T3 & collisionProducts, T4 & trackProducts,
321358 T5 & d0Products, T6 const & candidates, T7 const & /* tracks*/ , T8 & trackBuilder)
@@ -343,78 +380,104 @@ class CharmHadronBuilder {
343380 continue ;
344381 }
345382
346- // resolve the D0 / D0bar hypothesis from PWGHF verdict
347- const bool selD0 = candidate.isSelD0 ();
348- const bool selD0bar = candidate.isSelD0bar ();
349-
350- float signedPt = 0 .f ;
351- float mass = 0 .f ;
352-
353- // ML scores are not cut on here (PWGHF already did via isSelD0); all 3 stored in QA
354- if (selD0 && !selD0bar) { // unambiguous D0
355- signedPt = candidate.pt (); // positive sign
356- mass = mHfHelper .invMassD0ToPiK (candidate);
357- } else if (!selD0 && selD0bar) { // unambiguous D0bar
358- signedPt = -candidate.pt (); // negative sign
359- mass = mHfHelper .invMassD0barToKPi (candidate);
360- } else if (selD0 && selD0bar) { // ambiguous: passes both
361- if (!mStoreDoubleHypo ) {
383+ const bool selD0 = candidate.isSelD0 ();
384+ const bool selD0bar = candidate.isSelD0bar ();
385+ if (selD0 && selD0bar && !mStoreDoubleHypo ) {
386+ continue ;
387+ }
388+ if constexpr (modes::isEqual (hadronType, modes::CharmHadron::kD0 )) {
389+ if (!selD0) {
390+ continue ;
391+ }
392+ } else {
393+ if (!selD0bar) {
362394 continue ;
363395 }
364- signedPt = candidate.pt (); // policy: treat as D0 (or emit both)
365- mass = mHfHelper .invMassD0ToPiK (candidate);
366- } else { // passes neither -> drop
367- continue ;
368396 }
369397
370- // run the bit selection and drop candidates failing required cuts
371398 mD0Selection .applySelections (candidate);
372399 if (!mD0Selection .passesAllRequiredSelections ()) {
373400 continue ;
374401 }
375402
376403 collisionBuilder.template fillCollision <system>(collisionProducts, col);
377404
378- // store the two prongs as femto tracks, keep their indices for D0 row
379405 auto prong0 = candidate.template prong0_as <T7 >();
380406 auto prong1 = candidate.template prong1_as <T7 >();
381407 int64_t posDauIndex = trackBuilder.template getDaughterIndex <modes::Track::kCharmDaughter >(prong0, trackProducts, collisionProducts);
382408 int64_t negDauIndex = trackBuilder.template getDaughterIndex <modes::Track::kCharmDaughter >(prong1, trackProducts, collisionProducts);
383409
384- if (mProduceD0s ) {
385- d0Products.producedD0s (collisionProducts.producedCollision .lastIndex (),
386- signedPt,
387- candidate.eta (),
388- candidate.phi (),
389- mass,
390- posDauIndex,
391- negDauIndex);
392- }
393- if (mProduceD0Masks ) {
394- d0Products.producedD0Masks (mD0Selection .getBitmask ());
410+ if constexpr (modes::isEqual (hadronType, modes::CharmHadron::kD0 )) {
411+ this ->fillD0Tables (collisionProducts, d0Products, candidate, candidate.pt (), mHfHelper .invMassD0ToPiK (candidate), posDauIndex, negDauIndex);
412+ } else {
413+ this ->fillD0Tables (collisionProducts, d0Products, candidate, -candidate.pt (), mHfHelper .invMassD0barToKPi (candidate), posDauIndex, negDauIndex);
395414 }
396- if (mProduceD0Extras ) {
397- d0Products.producedD0Extras (
398- mHfHelper .invMassD0ToPiK (candidate),
399- mHfHelper .invMassD0barToKPi (candidate),
400- candidate.cpa (),
401- candidate.cpaXY (),
402- candidate.decayLength (),
403- candidate.decayLengthXY (),
404- candidate.impactParameter0 () * candidate.impactParameter1 (),
405- mHfHelper .cosThetaStarD0 (candidate),
406- candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[0 ],
407- candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[1 ],
408- candidate.mlProbD0 ().size () < 3 ? -1 .f : candidate.mlProbD0 ()[2 ],
409- candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[0 ],
410- candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[1 ],
411- candidate.mlProbD0bar ().size () < 3 ? -1 .f : candidate.mlProbD0bar ()[2 ],
412- static_cast <int8_t >(candidate.isSelD0 ()),
413- static_cast <int8_t >(candidate.isSelD0bar ()));
415+
416+
417+ }
418+ }
419+
420+ template <modes::System system, typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 , typename T9 , typename T10 , typename T11 , typename T12 >
421+ void fillMcD0s (T1 const & col, T2 & collisionBuilder, T3 & collisionProducts, T4 const & mcCols, T5 & trackProducts,
422+ T6 & d0Products, T7 const & candidates, T8 const & tracks, T9 & trackBuilder, T10 const & mcParticles, T11 & mcBuilder, T12 & mcProducts)
423+ {
424+ if (!mFillAnyTable ) {
425+ return ;
426+ }
427+
428+ for (const auto & candidate : candidates) {
429+ if (!(candidate.hfflag () & (1 << o2::aod::hf_cand_2prong::DecayType::D0ToPiK))) {
430+ continue ;
414431 }
432+
433+ if (mD0Selection .getUseYCut ()) {
434+ const float y = mHfHelper .yD0 (candidate);
435+ if (y < mD0Selection .getYMin () || y > mD0Selection .getYMax ()) {
436+ continue ;
437+ }
438+ }
439+
440+ if (!mD0Selection .checkFilters (candidate)) {
441+ continue ;
442+ }
443+
444+ const bool selD0 = candidate.isSelD0 ();
445+ const bool selD0bar = candidate.isSelD0bar ();
446+ if (selD0 && selD0bar && !mStoreDoubleHypo ) {
447+ continue ;
448+ }
449+ if constexpr (modes::isEqual (hadronType, modes::CharmHadron::kD0 )) {
450+ if (!selD0) {
451+ continue ;
452+ }
453+ } else {
454+ if (!selD0bar) {
455+ continue ;
456+ }
457+ }
458+
459+ mD0Selection .applySelections (candidate);
460+ if (!mD0Selection .passesAllRequiredSelections ()) {
461+ continue ;
462+ }
463+
464+ collisionBuilder.template fillMcCollision <system>(collisionProducts, col, mcCols, mcProducts, mcBuilder);
465+
466+ auto prong0 = candidate.template prong0_as <T8 >();
467+ auto prong1 = candidate.template prong1_as <T8 >();
468+ int64_t posDauIndex = trackBuilder.template getDaughterIndex <system, modes::Track::kCharmDaughter >(col, collisionProducts, mcCols, prong0, trackProducts, mcParticles, mcBuilder, mcProducts);
469+ int64_t negDauIndex = trackBuilder.template getDaughterIndex <system, modes::Track::kCharmDaughter >(col, collisionProducts, mcCols, prong1, trackProducts, mcParticles, mcBuilder, mcProducts);
470+
471+ if constexpr (modes::isEqual (hadronType, modes::CharmHadron::kD0 )) {
472+ this ->fillD0Tables (collisionProducts, d0Products, candidate, candidate.pt (), mHfHelper .invMassD0ToPiK (candidate), posDauIndex, negDauIndex);
473+ } else {
474+ this ->fillD0Tables (collisionProducts, d0Products, candidate, -candidate.pt (), mHfHelper .invMassD0barToKPi (candidate), posDauIndex, negDauIndex);
475+ }
476+ mcBuilder.template fillMcD0WithLabel <system>(col, mcCols, candidate, tracks, mcParticles, mcProducts);
415477 }
416478 }
417479
480+
418481private:
419482 D0Selection<hadronType, SelectionHistName, FilterHistName> mD0Selection ;
420483 HfHelper mHfHelper ;
0 commit comments