1616// /
1717// / \author Alexandre Bigot <alexandre.bigot@cern.ch>, IPHC Strasbourg
1818
19+ #include < vector>
20+
1921#include " CommonConstants/PhysicsConstants.h"
2022#include " Framework/AnalysisTask.h"
2123#include " Framework/runDataProcessing.h"
2224
2325#include " PWGHF/Core/HfHelper.h"
26+ #include " PWGHF/Core/CentralityEstimation.h"
2427#include " PWGHF/DataModel/CandidateReconstructionTables.h"
2528#include " PWGHF/DataModel/CandidateSelectionTables.h"
2629
2730using namespace o2 ;
2831using namespace o2 ::framework;
2932using namespace o2 ::framework::expressions;
33+ using namespace o2 ::hf_centrality;
3034
3135namespace o2 ::aod
3236{
@@ -50,6 +54,7 @@ DECLARE_SOA_COLUMN(Y, y, float);
5054DECLARE_SOA_COLUMN (Eta, eta, float ); // ! Pseudorapidity of candidate
5155DECLARE_SOA_COLUMN (Phi, phi, float ); // ! Azimuth angle of candidate
5256DECLARE_SOA_COLUMN (E, e, float ); // ! Energy of candidate (GeV)
57+ DECLARE_SOA_COLUMN (Centrality, centrality, float ); // ! Collision centrality
5358DECLARE_SOA_COLUMN (NSigTpcPi0, nSigTpcPi0, float ); // ! TPC Nsigma separation for prong0 with pion mass hypothesis
5459DECLARE_SOA_COLUMN (NSigTpcKa0, nSigTpcKa0, float ); // ! TPC Nsigma separation for prong0 with kaon mass hypothesis
5560DECLARE_SOA_COLUMN (NSigTofPi0, nSigTofPi0, float ); // ! TOF Nsigma separation for prong0 with pion mass hypothesis
@@ -129,6 +134,7 @@ DECLARE_SOA_TABLE(HfCandDpLites, "AOD", "HFCANDDPLITE",
129134 full::Eta,
130135 full::Phi,
131136 full::Y,
137+ full::Centrality,
132138 hf_cand_3prong::FlagMcMatchRec,
133139 hf_cand_3prong::OriginMcRec,
134140 hf_cand_3prong::FlagMcDecayChanRec)
@@ -210,6 +216,7 @@ DECLARE_SOA_TABLE(HfCandDpFulls, "AOD", "HFCANDDPFULL",
210216 full::Phi,
211217 full::Y,
212218 full::E,
219+ full::Centrality,
213220 hf_cand_3prong::FlagMcMatchRec,
214221 hf_cand_3prong::OriginMcRec,
215222 hf_cand_3prong::FlagMcDecayChanRec);
@@ -249,7 +256,8 @@ struct HfTreeCreatorDplusToPiKPi {
249256 Configurable<bool > fillOnlyBackground{" fillOnlyBackground" , false , " Flag to fill derived tables with background for ML trainings" };
250257 Configurable<float > downSampleBkgFactor{" downSampleBkgFactor" , 1 ., " Fraction of background candidates to keep for ML trainings" };
251258 Configurable<float > ptMaxForDownSample{" ptMaxForDownSample" , 10 ., " Maximum pt for the application of the downsampling factor" };
252- Configurable<std::vector<int >> classMl{" classMlindexes" , {0 , 2 }, " Indexes of ML bkg and non-prompt scores." };
259+ Configurable<std::vector<int >> classMlIndexes{" classMlIndexes" , {0 , 2 }, " Indexes of ML bkg and non-prompt scores." };
260+ Configurable<int > centEstimator{" centEstimator" , 0 , " Centrality estimation (None: 0, FT0C: 2, FT0M: 3)" };
253261
254262 HfHelper hfHelper;
255263
@@ -258,6 +266,8 @@ struct HfTreeCreatorDplusToPiKPi {
258266 using SelectedCandidatesMcWithMl = soa::Filtered<soa::Join<aod::HfCand3Prong, aod::HfCand3ProngMcRec, aod::HfSelDplusToPiKPi, aod::HfMlDplusToPiKPi>>;
259267 using TracksWPid = soa::Join<aod::Tracks, aod::TracksPidPi, aod::PidTpcTofFullPi, aod::TracksPidKa, aod::PidTpcTofFullKa>;
260268
269+ using CollisionsCent = soa::Join<aod::Collisions, aod::CentFT0Cs, aod::CentFT0Ms>;
270+
261271 Filter filterSelectCandidates = aod::hf_sel_candidate_dplus::isSelDplusToPiKPi >= selectionFlagDplus;
262272 Filter filterMcGenMatching = nabs(o2::aod::hf_cand_3prong::flagMcMatchGen) == static_cast <int8_t >(BIT(aod::hf_cand_3prong::DecayType::DplusToPiKPi));
263273
@@ -282,7 +292,7 @@ struct HfTreeCreatorDplusToPiKPi {
282292 runNumber);
283293 }
284294
285- template <bool doMc = false , bool doMl = false , typename T>
295+ template <typename Coll, bool doMc = false , bool doMl = false , typename T>
286296 void fillCandidateTable (const T& candidate)
287297 {
288298 int8_t flagMc = 0 ;
@@ -296,8 +306,8 @@ struct HfTreeCreatorDplusToPiKPi {
296306
297307 std::vector<float > outputMl = {-999 ., -999 .};
298308 if constexpr (doMl) {
299- for (unsigned int iclass = 0 ; iclass < classMl ->size (); iclass++) {
300- outputMl[iclass] = candidate.mlProbDplusToPiKPi ()[classMl ->at (iclass)];
309+ for (unsigned int iclass = 0 ; iclass < classMlIndexes ->size (); iclass++) {
310+ outputMl[iclass] = candidate.mlProbDplusToPiKPi ()[classMlIndexes ->at (iclass)];
301311 }
302312 rowCandidateMl (
303313 outputMl[0 ],
@@ -308,6 +318,12 @@ struct HfTreeCreatorDplusToPiKPi {
308318 auto prong1 = candidate.template prong1_as <TracksWPid>();
309319 auto prong2 = candidate.template prong2_as <TracksWPid>();
310320
321+ float cent{-1 .};
322+ auto coll = candidate.template collision_as <Coll>();
323+ if (std::is_same_v<Coll, CollisionsCent> && centEstimator != CentralityEstimator::None) {
324+ cent = getCentralityColl (coll, centEstimator);
325+ }
326+
311327 if (fillCandidateLiteTable) {
312328 rowCandidateLite (
313329 candidate.chi2PCA (),
@@ -351,13 +367,14 @@ struct HfTreeCreatorDplusToPiKPi {
351367 candidate.eta (),
352368 candidate.phi (),
353369 hfHelper.yDplus (candidate),
370+ cent,
354371 flagMc,
355372 originMc,
356373 channelMc);
357374 } else {
358375 rowCandidateFull (
359- candidate. collision () .bcId (),
360- candidate. collision () .numContrib (),
376+ coll .bcId (),
377+ coll .numContrib (),
361378 candidate.posX (),
362379 candidate.posY (),
363380 candidate.posZ (),
@@ -432,6 +449,7 @@ struct HfTreeCreatorDplusToPiKPi {
432449 candidate.phi (),
433450 hfHelper.yDplus (candidate),
434451 hfHelper.eDplus (candidate),
452+ cent,
435453 flagMc,
436454 originMc,
437455 channelMc);
@@ -461,7 +479,7 @@ struct HfTreeCreatorDplusToPiKPi {
461479 continue ;
462480 }
463481 }
464- fillCandidateTable (candidate);
482+ fillCandidateTable<aod::Collisions> (candidate);
465483 }
466484 }
467485
@@ -488,7 +506,7 @@ struct HfTreeCreatorDplusToPiKPi {
488506 rowCandidateFull.reserve (reconstructedCandSig.size ());
489507 }
490508 for (const auto & candidate : reconstructedCandSig) {
491- fillCandidateTable<true >(candidate);
509+ fillCandidateTable<aod::Collisions, true >(candidate);
492510 }
493511 } else if (fillOnlySignalMl) {
494512 rowCandidateMl.reserve (reconstructedCandSigMl.size ());
@@ -499,12 +517,12 @@ struct HfTreeCreatorDplusToPiKPi {
499517 }
500518 for (const auto & candidate : reconstructedCandSigMl) {
501519 if (downSampleBkgFactor < 1 .) {
502- float pseudoRndm = candidate.ptProng0 () * 1000 . - ( int64_t ) (candidate.ptProng0 () * 1000 );
520+ float pseudoRndm = candidate.ptProng0 () * 1000 . - static_cast < int64_t > (candidate.ptProng0 () * 1000 );
503521 if (candidate.pt () < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) {
504522 continue ;
505523 }
506524 }
507- fillCandidateTable<true , true >(candidate);
525+ fillCandidateTable<aod::Collisions, true , true >(candidate);
508526 }
509527 } else if (fillOnlyBackground) {
510528 if (fillCandidateLiteTable) {
@@ -519,7 +537,7 @@ struct HfTreeCreatorDplusToPiKPi {
519537 continue ;
520538 }
521539 }
522- fillCandidateTable<true >(candidate);
540+ fillCandidateTable<aod::Collisions, true >(candidate);
523541 }
524542 } else {
525543 if (fillCandidateLiteTable) {
@@ -528,7 +546,7 @@ struct HfTreeCreatorDplusToPiKPi {
528546 rowCandidateFull.reserve (candidates.size ());
529547 }
530548 for (const auto & candidate : candidates) {
531- fillCandidateTable<true >(candidate);
549+ fillCandidateTable<aod::Collisions, true >(candidate);
532550 }
533551 }
534552
@@ -547,6 +565,116 @@ struct HfTreeCreatorDplusToPiKPi {
547565 }
548566
549567 PROCESS_SWITCH (HfTreeCreatorDplusToPiKPi, processMc, " Process MC" , false );
568+
569+ void processDataWCent (CollisionsCent const & collisions,
570+ soa::Filtered<soa::Join<aod::HfCand3Prong, aod::HfSelDplusToPiKPi>> const & candidates,
571+ TracksWPid const &)
572+ {
573+ // Filling event properties
574+ rowCandidateFullEvents.reserve (collisions.size ());
575+ for (const auto & collision : collisions) {
576+ fillEvent (collision, 0 , 1 );
577+ }
578+
579+ // Filling candidate properties
580+ if (fillCandidateLiteTable) {
581+ rowCandidateLite.reserve (candidates.size ());
582+ } else {
583+ rowCandidateFull.reserve (candidates.size ());
584+ }
585+ for (const auto & candidate : candidates) {
586+ if (downSampleBkgFactor < 1 .) {
587+ float pseudoRndm = candidate.ptProng0 () * 1000 . - static_cast <int64_t >(candidate.ptProng0 () * 1000 );
588+ if (candidate.pt () < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) {
589+ continue ;
590+ }
591+ }
592+ fillCandidateTable<CollisionsCent>(candidate);
593+ }
594+ }
595+
596+ PROCESS_SWITCH (HfTreeCreatorDplusToPiKPi, processDataWCent, " Process data with cent" , false );
597+
598+ void processMcWCent (CollisionsCent const & collisions,
599+ aod::McCollisions const &,
600+ SelectedCandidatesMc const & candidates,
601+ MatchedGenCandidatesMc const & particles,
602+ SelectedCandidatesMcWithMl const &,
603+ TracksWPid const &)
604+ {
605+ // Filling event properties
606+ rowCandidateFullEvents.reserve (collisions.size ());
607+ for (const auto & collision : collisions) {
608+ fillEvent (collision, 0 , 1 );
609+ }
610+
611+ // Filling candidate properties
612+ if (fillOnlySignal) {
613+ if (fillCandidateLiteTable) {
614+ rowCandidateLite.reserve (reconstructedCandSig.size ());
615+ } else {
616+ rowCandidateFull.reserve (reconstructedCandSig.size ());
617+ }
618+ for (const auto & candidate : reconstructedCandSig) {
619+ fillCandidateTable<CollisionsCent, true >(candidate);
620+ }
621+ } else if (fillOnlySignalMl) {
622+ rowCandidateMl.reserve (reconstructedCandSigMl.size ());
623+ if (fillCandidateLiteTable) {
624+ rowCandidateLite.reserve (reconstructedCandSigMl.size ());
625+ } else {
626+ rowCandidateFull.reserve (reconstructedCandSigMl.size ());
627+ }
628+ for (const auto & candidate : reconstructedCandSigMl) {
629+ if (downSampleBkgFactor < 1 .) {
630+ float pseudoRndm = candidate.ptProng0 () * 1000 . - static_cast <int64_t >(candidate.ptProng0 () * 1000 );
631+ if (candidate.pt () < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) {
632+ continue ;
633+ }
634+ }
635+ fillCandidateTable<CollisionsCent, true , true >(candidate);
636+ }
637+ } else if (fillOnlyBackground) {
638+ if (fillCandidateLiteTable) {
639+ rowCandidateLite.reserve (reconstructedCandBkg.size ());
640+ } else {
641+ rowCandidateFull.reserve (reconstructedCandBkg.size ());
642+ }
643+ for (const auto & candidate : reconstructedCandBkg) {
644+ if (downSampleBkgFactor < 1 .) {
645+ float pseudoRndm = candidate.ptProng0 () * 1000 . - static_cast <int64_t >(candidate.ptProng0 () * 1000 );
646+ if (candidate.pt () < ptMaxForDownSample && pseudoRndm >= downSampleBkgFactor) {
647+ continue ;
648+ }
649+ }
650+ fillCandidateTable<CollisionsCent, true >(candidate);
651+ }
652+ } else {
653+ if (fillCandidateLiteTable) {
654+ rowCandidateLite.reserve (candidates.size ());
655+ } else {
656+ rowCandidateFull.reserve (candidates.size ());
657+ }
658+ for (const auto & candidate : candidates) {
659+ fillCandidateTable<CollisionsCent, true >(candidate);
660+ }
661+ }
662+
663+ // Filling particle properties
664+ rowCandidateFullParticles.reserve (particles.size ());
665+ for (const auto & particle : particles) {
666+ rowCandidateFullParticles (
667+ particle.mcCollision ().bcId (),
668+ particle.pt (),
669+ particle.eta (),
670+ particle.phi (),
671+ RecoDecay::y (particle.pVector (), o2::constants::physics::MassDPlus),
672+ particle.flagMcMatchGen (),
673+ particle.originMcGen ());
674+ }
675+ }
676+
677+ PROCESS_SWITCH (HfTreeCreatorDplusToPiKPi, processMcWCent, " Process MC with cent" , false );
550678};
551679
552680WorkflowSpec defineDataProcessing (ConfigContext const & cfgc)
0 commit comments