1515// / \author Gian Michele Innocenti <[email protected] >, CERN1616// / \author Vít Kučera <[email protected] >, CERN1717
18+ #include < vector>
19+
1820#include " CommonConstants/PhysicsConstants.h"
1921#include " Framework/AnalysisTask.h"
2022#include " Framework/HistogramRegistry.h"
@@ -64,6 +66,7 @@ struct HfTaskD0 {
6466 ConfigurableAxis thnConfigAxisCandType{" thnConfigAxisCandType" , {4 , -0.5 , 3.5 }, " D0 type" };
6567 ConfigurableAxis thnConfigAxisGenPtD{" thnConfigAxisGenPtD" , {500 , 0 , 50 }, " Gen Pt D" };
6668 ConfigurableAxis thnConfigAxisGenPtB{" thnConfigAxisGenPtB" , {1000 , 0 , 100 }, " Gen Pt B" };
69+ ConfigurableAxis thnConfigAxisNumPvContr{" thnConfigAxisNumPvContr" , {200 , -0.5 , 199.5 }, " Number of PV contributors" };
6770
6871 HfHelper hfHelper;
6972
@@ -77,6 +80,10 @@ struct HfTaskD0 {
7780 using D0CandidatesMlKF = soa::Join<D0CandidatesMl, aod::HfCand2ProngKF>;
7881 using D0CandidatesMlMcKF = soa::Join<D0CandidatesMlKF, aod::HfCand2ProngMcRec>;
7982
83+ using CollisionsWithMcLabels = soa::Join<aod::Collisions, aod::McCollisionLabels>;
84+ PresliceUnsorted<CollisionsWithMcLabels> colPerMcCollision = aod::mccollisionlabel::mcCollisionId;
85+ SliceCache cache;
86+
8087 Partition<D0Candidates> selectedD0Candidates = aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 || aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0bar;
8188 Partition<D0CandidatesKF> selectedD0CandidatesKF = aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 || aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0bar;
8289 Partition<D0CandidatesMc> selectedD0CandidatesMc = aod::hf_sel_candidate_d0::isRecoHfFlag >= selectionFlagHf;
@@ -220,19 +227,30 @@ struct HfTaskD0 {
220227 const AxisSpec thnAxisCandType{thnConfigAxisCandType, " D0 type" };
221228 const AxisSpec thnAxisGenPtD{thnConfigAxisGenPtD, " #it{p}_{T} (GeV/#it{c})" };
222229 const AxisSpec thnAxisGenPtB{thnConfigAxisGenPtB, " #it{p}_{T}^{B} (GeV/#it{c})" };
230+ const AxisSpec thnAxisNumPvContr{thnConfigAxisNumPvContr, " Number of PV contributors" };
223231
224- registry.add (" hSparseAcc" , " Thn for generated D0 from charm and beauty" , HistType::kTHnSparseD , {thnAxisGenPtD, thnAxisGenPtB, thnAxisY, thnAxisOrigin});
225- registry.get <THnSparse>(HIST (" hSparseAcc" ))->Sumw2 ();
232+ if (doprocessMcWithDCAFitterN || doprocessMcWithKFParticle || doprocessMcWithDCAFitterNMl || doprocessMcWithKFParticleMl) {
233+ registry.add (" hSparseAcc" , " Thn for generated D0 from charm and beauty" , HistType::kTHnSparseD , {thnAxisGenPtD, thnAxisGenPtB, thnAxisY, thnAxisOrigin, thnAxisNumPvContr});
234+ registry.get <THnSparse>(HIST (" hSparseAcc" ))->Sumw2 ();
235+ }
226236
227237 if (applyMl) {
228238 const AxisSpec thnAxisBkgScore{thnConfigAxisBkgScore, " BDT score bkg." };
229239 const AxisSpec thnAxisNonPromptScore{thnConfigAxisNonPromptScore, " BDT score non-prompt." };
230240 const AxisSpec thnAxisPromptScore{thnConfigAxisPromptScore, " BDT score prompt." };
231241
232- registry.add (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates with BDT scores" , HistType::kTHnSparseD , {thnAxisBkgScore, thnAxisNonPromptScore, thnAxisPromptScore, thnAxisMass, thnAxisPt, thnAxisPtB, thnAxisY, thnAxisOrigin, thnAxisCandType});
242+ if (doprocessMcWithDCAFitterN || doprocessMcWithKFParticle || doprocessMcWithDCAFitterNMl || doprocessMcWithKFParticleMl) {
243+ registry.add (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates with BDT scores" , HistType::kTHnSparseD , {thnAxisBkgScore, thnAxisNonPromptScore, thnAxisPromptScore, thnAxisMass, thnAxisPt, thnAxisY, thnAxisCandType, thnAxisPtB, thnAxisOrigin, thnAxisNumPvContr});
244+ } else {
245+ registry.add (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates with BDT scores" , HistType::kTHnSparseD , {thnAxisBkgScore, thnAxisNonPromptScore, thnAxisPromptScore, thnAxisMass, thnAxisPt, thnAxisY, thnAxisCandType});
246+ }
233247 registry.get <THnSparse>(HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ))->Sumw2 ();
234248 } else {
235- registry.add (" hMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates without BDT scores" , HistType::kTHnSparseD , {thnAxisMass, thnAxisPt, thnAxisPtB, thnAxisY, thnAxisOrigin, thnAxisCandType});
249+ if (doprocessMcWithDCAFitterN || doprocessMcWithKFParticle || doprocessMcWithDCAFitterNMl || doprocessMcWithKFParticleMl) {
250+ registry.add (" hMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates without BDT scores" , HistType::kTHnSparseD , {thnAxisMass, thnAxisPt, thnAxisY, thnAxisCandType, thnAxisPtB, thnAxisOrigin});
251+ } else {
252+ registry.add (" hMassVsPtVsPtBVsYVsOriginVsD0Type" , " Thn for D0 candidates without BDT scores" , HistType::kTHnSparseD , {thnAxisMass, thnAxisPt, thnAxisY, thnAxisCandType});
253+ }
236254 registry.get <THnSparse>(HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ))->Sumw2 ();
237255 }
238256 }
@@ -299,17 +317,17 @@ struct HfTaskD0 {
299317
300318 if constexpr (applyMl) {
301319 if (candidate.isSelD0 () >= selectionFlagD0) {
302- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, - 1 , hfHelper.yD0 (candidate), 0 , SigD0);
320+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, hfHelper.yD0 (candidate), SigD0);
303321 }
304322 if (candidate.isSelD0bar () >= selectionFlagD0bar) {
305- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, - 1 , hfHelper.yD0 (candidate), 0 , SigD0bar);
323+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, hfHelper.yD0 (candidate), SigD0bar);
306324 }
307325 } else {
308326 if (candidate.isSelD0 () >= selectionFlagD0) {
309- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, - 1 , hfHelper.yD0 (candidate), 0 , SigD0);
327+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, hfHelper.yD0 (candidate), SigD0);
310328 }
311329 if (candidate.isSelD0bar () >= selectionFlagD0bar) {
312- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, - 1 , hfHelper.yD0 (candidate), 0 , SigD0bar);
330+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, hfHelper.yD0 (candidate), SigD0bar);
313331 }
314332 }
315333 }
@@ -341,7 +359,8 @@ struct HfTaskD0 {
341359 template <int reconstructionType, bool applyMl, typename CandType>
342360 void processMc (CandType const & candidates,
343361 soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const & mcParticles,
344- aod::TracksWMc const &)
362+ aod::TracksWMc const &,
363+ CollisionsWithMcLabels const & collisions)
345364 {
346365 // MC rec.
347366 for (const auto & candidate : candidates) {
@@ -351,6 +370,9 @@ struct HfTaskD0 {
351370 if (yCandRecoMax >= 0 . && std::abs (hfHelper.yD0 (candidate)) > yCandRecoMax) {
352371 continue ;
353372 }
373+
374+ auto collision = candidate.template collision_as <CollisionsWithMcLabels>();
375+ auto numPvContributors = collision.numContrib ();
354376 float massD0, massD0bar;
355377 if constexpr (reconstructionType == aod::hf_cand::VertexerType::KfParticle) {
356378 massD0 = candidate.kfGeoMassD0 ();
@@ -476,9 +498,9 @@ struct HfTaskD0 {
476498 registry.fill (HIST (" hDecLengthxyVsPtSig" ), declengthxyCandidate, ptCandidate);
477499 registry.fill (HIST (" hMassSigD0" ), massD0, ptCandidate, rapidityCandidate);
478500 if constexpr (applyMl) {
479- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), SigD0 );
501+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, rapidityCandidate, SigD0, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
480502 } else {
481- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), SigD0 );
503+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, rapidityCandidate, SigD0, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
482504 }
483505 } else {
484506 registry.fill (HIST (" hPtProng0Bkg" ), ptProng0, rapidityCandidate);
@@ -498,9 +520,9 @@ struct HfTaskD0 {
498520 if (candidate.flagMcMatchRec () == -(1 << aod::hf_cand_2prong::DecayType::D0ToPiK)) {
499521 registry.fill (HIST (" hMassReflBkgD0" ), massD0, ptCandidate, rapidityCandidate);
500522 if constexpr (applyMl) {
501- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), ReflectedD0 );
523+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0 ()[0 ], candidate.mlProbD0 ()[1 ], candidate.mlProbD0 ()[2 ], massD0, ptCandidate, rapidityCandidate, ReflectedD0, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
502524 } else {
503- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), ReflectedD0 );
525+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0, ptCandidate, rapidityCandidate, ReflectedD0, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
504526 }
505527 }
506528 }
@@ -510,18 +532,18 @@ struct HfTaskD0 {
510532 if (candidate.flagMcMatchRec () == -(1 << aod::hf_cand_2prong::DecayType::D0ToPiK)) {
511533 registry.fill (HIST (" hMassSigD0bar" ), massD0bar, ptCandidate, rapidityCandidate);
512534 if constexpr (applyMl) {
513- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), SigD0bar );
535+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, rapidityCandidate, SigD0bar, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
514536 } else {
515- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), SigD0bar );
537+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, rapidityCandidate, SigD0bar, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
516538 }
517539 } else {
518540 registry.fill (HIST (" hMassBkgD0bar" ), massD0bar, ptCandidate, rapidityCandidate);
519541 if (candidate.flagMcMatchRec () == (1 << aod::hf_cand_2prong::DecayType::D0ToPiK)) {
520542 registry.fill (HIST (" hMassReflBkgD0bar" ), massD0bar, ptCandidate, rapidityCandidate);
521543 if constexpr (applyMl) {
522- registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), ReflectedD0bar );
544+ registry.fill (HIST (" hBdtScoreVsMassVsPtVsPtBVsYVsOriginVsD0Type" ), candidate.mlProbD0bar ()[0 ], candidate.mlProbD0bar ()[1 ], candidate.mlProbD0bar ()[2 ], massD0bar, ptCandidate, rapidityCandidate, ReflectedD0bar, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
523545 } else {
524- registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, candidate.ptBhadMotherPart (), rapidityCandidate, candidate.originMcRec (), ReflectedD0bar );
546+ registry.fill (HIST (" hMassVsPtVsPtBVsYVsOriginVsD0Type" ), massD0bar, ptCandidate, rapidityCandidate, ReflectedD0bar, candidate.ptBhadMotherPart (), candidate.originMcRec (), numPvContributors );
525547 }
526548 }
527549 }
@@ -539,17 +561,23 @@ struct HfTaskD0 {
539561 registry.fill (HIST (" hPtGen" ), ptGen);
540562 registry.fill (HIST (" hPtVsYGen" ), ptGen, yGen);
541563
564+ unsigned maxNumContrib = 0 ;
565+ const auto & recoCollsPerMcColl = collisions.sliceBy (colPerMcCollision, particle.mcCollision ().globalIndex ());
566+ for (const auto & recCol : recoCollsPerMcColl) {
567+ maxNumContrib = recCol.numContrib () > maxNumContrib ? recCol.numContrib () : maxNumContrib;
568+ }
569+
542570 if (particle.originMcGen () == RecoDecay::OriginType::Prompt) {
543571 registry.fill (HIST (" hPtGenPrompt" ), ptGen);
544572 registry.fill (HIST (" hYGenPrompt" ), yGen);
545573 registry.fill (HIST (" hPtVsYGenPrompt" ), ptGen, yGen);
546- registry.fill (HIST (" hSparseAcc" ), ptGen, ptGenB, yGen, 1 );
574+ registry.fill (HIST (" hSparseAcc" ), ptGen, ptGenB, yGen, 1 , maxNumContrib );
547575 } else {
548576 ptGenB = mcParticles.rawIteratorAt (particle.idxBhadMotherPart ()).pt ();
549577 registry.fill (HIST (" hPtGenNonPrompt" ), ptGen);
550578 registry.fill (HIST (" hYGenNonPrompt" ), yGen);
551579 registry.fill (HIST (" hPtVsYGenNonPrompt" ), ptGen, yGen);
552- registry.fill (HIST (" hSparseAcc" ), ptGen, ptGenB, yGen, 2 );
580+ registry.fill (HIST (" hSparseAcc" ), ptGen, ptGenB, yGen, 2 , maxNumContrib );
553581 }
554582 registry.fill (HIST (" hEtaGen" ), particle.eta ());
555583 }
@@ -558,33 +586,37 @@ struct HfTaskD0 {
558586
559587 void processMcWithDCAFitterN (D0CandidatesMc const &,
560588 soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const & mcParticles,
561- aod::TracksWMc const & tracks)
589+ aod::TracksWMc const & tracks,
590+ CollisionsWithMcLabels const & collisions)
562591 {
563- processMc<aod::hf_cand::VertexerType::DCAFitter, false >(selectedD0CandidatesMc, mcParticles, tracks);
592+ processMc<aod::hf_cand::VertexerType::DCAFitter, false >(selectedD0CandidatesMc, mcParticles, tracks, collisions );
564593 }
565594 PROCESS_SWITCH (HfTaskD0, processMcWithDCAFitterN, " Process MC with DCAFitterN" , false );
566595
567596 void processMcWithKFParticle (D0CandidatesMcKF const &,
568597 soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const & mcParticles,
569- aod::TracksWMc const & tracks)
598+ aod::TracksWMc const & tracks,
599+ CollisionsWithMcLabels const & collisions)
570600 {
571- processMc<aod::hf_cand::VertexerType::KfParticle, false >(selectedD0CandidatesMcKF, mcParticles, tracks);
601+ processMc<aod::hf_cand::VertexerType::KfParticle, false >(selectedD0CandidatesMcKF, mcParticles, tracks, collisions );
572602 }
573603 PROCESS_SWITCH (HfTaskD0, processMcWithKFParticle, " Process MC with KFParticle" , false );
574604
575605 void processMcWithDCAFitterNMl (D0CandidatesMlMc const &,
576606 soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const & mcParticles,
577- aod::TracksWMc const & tracks)
607+ aod::TracksWMc const & tracks,
608+ CollisionsWithMcLabels const & collisions)
578609 {
579- processMc<aod::hf_cand::VertexerType::DCAFitter, true >(selectedD0CandidatesMlMc, mcParticles, tracks);
610+ processMc<aod::hf_cand::VertexerType::DCAFitter, true >(selectedD0CandidatesMlMc, mcParticles, tracks, collisions );
580611 }
581612 PROCESS_SWITCH (HfTaskD0, processMcWithDCAFitterNMl, " Process MC with DCAFitterN and ML selection" , false );
582613
583614 void processMcWithKFParticleMl (D0CandidatesMlMcKF const &,
584615 soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const & mcParticles,
585- aod::TracksWMc const & tracks)
616+ aod::TracksWMc const & tracks,
617+ CollisionsWithMcLabels const & collisions)
586618 {
587- processMc<aod::hf_cand::VertexerType::KfParticle, true >(selectedD0CandidatesMlMcKF, mcParticles, tracks);
619+ processMc<aod::hf_cand::VertexerType::KfParticle, true >(selectedD0CandidatesMlMcKF, mcParticles, tracks, collisions );
588620 }
589621 PROCESS_SWITCH (HfTaskD0, processMcWithKFParticleMl, " Process MC with KFParticle and ML selections" , false );
590622};
0 commit comments