Skip to content

Commit adf51db

Browse files
committed
PWGHF: optimize the code to add Kf to D0
1 parent f206832 commit adf51db

6 files changed

Lines changed: 171 additions & 186 deletions

File tree

PWGHF/D2H/Tasks/taskD0.cxx

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ using namespace o2::framework::expressions;
2828
using namespace o2::aod::hf_cand_2prong;
2929
using namespace o2::analysis::hf_cuts_d0_to_pi_k;
3030

31-
constexpr static int useDCAFitterN = 0;
32-
constexpr static int useKFParticle = 1;
33-
3431
/// D0 analysis task
3532
struct HfTaskD0 {
3633
Configurable<int> selectionFlagD0{"selectionFlagD0", 1, "Selection Flag for D0"};
@@ -166,8 +163,8 @@ struct HfTaskD0 {
166163
registry.add("hDecLengthxyVsPtSig", "2-prong candidates;decay length xy (cm) vs #it{p}_{T} for signal;entries", {HistType::kTH2F, {{800, 0., 4.}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}});
167164
}
168165

169-
template <int ReconstructionType, typename THfCand2Prong, typename THfCand2ProngSel>
170-
void processData(THfCand2Prong& candidates, THfCand2ProngSel& selectedD0CandidatesSets)
166+
template <int ReconstructionType, typename THfCand2ProngSel>
167+
void processData(THfCand2ProngSel& selectedD0CandidatesSets)
171168
{
172169
for (auto& candidate : selectedD0CandidatesSets) {
173170
if (!(candidate.hfflag() & 1 << DecayType::D0ToPiK)) {
@@ -178,14 +175,13 @@ struct HfTaskD0 {
178175
}
179176

180177
float massD0, massD0bar;
181-
if constexpr (ReconstructionType == useDCAFitterN) {
178+
if constexpr (ReconstructionType == o2::aod::hf_cand::useKFParticle) {
179+
massD0 = candidate.kfGeoMassD0();
180+
massD0bar = candidate.kfGeoMassD0bar();
181+
} else {
182182
massD0 = invMassD0ToPiK(candidate);
183183
massD0bar = invMassD0barToKPi(candidate);
184184
}
185-
if constexpr (ReconstructionType == useKFParticle) {
186-
massD0 = candidate.kfGeoMass_DZero();
187-
massD0bar = candidate.kfGeoMass_DZeroBar();
188-
}
189185
auto ptCandidate = candidate.pt();
190186

191187
if (candidate.isSelD0() >= selectionFlagD0) {
@@ -228,20 +224,20 @@ struct HfTaskD0 {
228224
registry.fill(HIST("hCPAXYFinerBinning"), candidate.cpaXY(), ptCandidate);
229225
}
230226
}
231-
void processWithDCAFitterN(soa::Join<aod::HfCand2Prong, aod::HfSelD0> const& candidates)
227+
void processWithDCAFitterN(soa::Join<aod::HfCand2Prong, aod::HfSelD0> const&)
232228
{
233-
processData<0>(candidates, selectedD0Candidates);
229+
processData<0>(selectedD0Candidates);
234230
}
235-
void processWithKFParticle(soa::Join<aod::HfCand2Prong, aod::HfCand2ProngKF, aod::HfSelD0> const& candidates)
231+
PROCESS_SWITCH(HfTaskD0, processWithDCAFitterN, "process taskD0 with DCAFitterN", true);
232+
233+
void processWithKFParticle(soa::Join<aod::HfCand2Prong, aod::HfCand2ProngKF, aod::HfSelD0> const&)
236234
{
237-
processData<1>(candidates, selectedD0CandidatesKF);
235+
processData<1>(selectedD0CandidatesKF);
238236
}
239-
240-
PROCESS_SWITCH(HfTaskD0, processWithDCAFitterN, "process taskD0 with DCAFitterN", true);
241237
PROCESS_SWITCH(HfTaskD0, processWithKFParticle, "process taskD0 with KFParticle", false);
242238

243-
template <int ReconstructionType, typename THfCand2Prong, typename THfCand2ProngFlag>
244-
void processMc(THfCand2Prong& candidates, THfCand2ProngFlag& recoFlag2ProngSets,
239+
template <int ReconstructionType, typename THfCand2ProngFlag>
240+
void processMc(THfCand2ProngFlag& recoFlag2ProngSets,
245241
soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& particlesMC, aod::TracksWMc const& tracks)
246242
{
247243
// MC rec.
@@ -254,14 +250,13 @@ struct HfTaskD0 {
254250
continue;
255251
}
256252
float massD0, massD0bar;
257-
if constexpr (ReconstructionType == useDCAFitterN) {
253+
if constexpr (ReconstructionType == o2::aod::hf_cand::useKFParticle) {
254+
massD0 = candidate.kfGeoMassD0();
255+
massD0bar = candidate.kfGeoMassD0bar();
256+
} else {
258257
massD0 = invMassD0ToPiK(candidate);
259258
massD0bar = invMassD0barToKPi(candidate);
260259
}
261-
if constexpr (ReconstructionType == useKFParticle) {
262-
massD0 = candidate.kfGeoMass_DZero();
263-
massD0bar = candidate.kfGeoMass_DZeroBar();
264-
}
265260
if (std::abs(candidate.flagMcMatchRec()) == 1 << DecayType::D0ToPiK) {
266261
// Get the corresponding MC particle.
267262
auto indexMother = RecoDecay::getMother(particlesMC, candidate.template prong0_as<aod::TracksWMc>().template mcParticle_as<soa::Join<aod::McParticles, aod::HfCand2ProngMcGen>>(), pdg::Code::kD0, true);
@@ -435,19 +430,16 @@ struct HfTaskD0 {
435430
}
436431
}
437432

438-
void processMcWithDCAFitterN(soa::Join<aod::HfCand2Prong, aod::HfSelD0, aod::HfCand2ProngMcRec>& candidates,
439-
soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& particlesMC, aod::TracksWMc const& tracks)
433+
void processMcWithDCAFitterN(soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& particlesMC, aod::TracksWMc const& tracks)
440434
{
441-
processMc<0>(candidates, recoFlag2Prong, particlesMC, tracks);
435+
processMc<0>(recoFlag2Prong, particlesMC, tracks);
442436
}
437+
PROCESS_SWITCH(HfTaskD0, processMcWithDCAFitterN, "Process MC with DCAFitterN", false);
443438

444-
void processMcWithKFParticle(soa::Join<aod::HfCand2Prong, aod::HfCand2ProngKF, aod::HfSelD0, aod::HfCand2ProngMcRec>& candidates,
445-
soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& particlesMC, aod::TracksWMc const& tracks)
439+
void processMcWithKFParticle(soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& particlesMC, aod::TracksWMc const& tracks)
446440
{
447-
processMc<1>(candidates, recoFlag2ProngKF, particlesMC, tracks);
441+
processMc<1>(recoFlag2ProngKF, particlesMC, tracks);
448442
}
449-
450-
PROCESS_SWITCH(HfTaskD0, processMcWithDCAFitterN, "Process MC with DCAFitterN", false);
451443
PROCESS_SWITCH(HfTaskD0, processMcWithKFParticle, "Process MC with KFParticle", false);
452444
};
453445

PWGHF/DataModel/CandidateReconstructionTables.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ DECLARE_SOA_COLUMN(ZSecondaryVertex, zSecondaryVertex, float); //!
261261
DECLARE_SOA_DYNAMIC_COLUMN(RSecondaryVertex, rSecondaryVertex, //!
262262
[](float xVtxS, float yVtxS) -> float { return RecoDecay::sqrtSumOfSquares(xVtxS, yVtxS); });
263263
DECLARE_SOA_COLUMN(Chi2PCA, chi2PCA, float); //! sum of (non-weighted) distances of the secondary vertex to its prongs
264-
DECLARE_SOA_COLUMN(KFTopChi2OverNDF, kfTopChi2OverNDF, float); //!
265-
DECLARE_SOA_COLUMN(KFGeoMass_DZero, kfGeoMass_DZero, float); //!
266-
DECLARE_SOA_COLUMN(KFGeoMass_DZeroBar, kfGeoMass_DZeroBar, float); //!
267264
// prong properties
268265
DECLARE_SOA_COLUMN(PxProng0, pxProng0, float); //!
269266
DECLARE_SOA_COLUMN(PyProng0, pyProng0, float); //!
@@ -343,6 +340,9 @@ DECLARE_SOA_DYNAMIC_COLUMN(Ct, ct, //!
343340
[](float xVtxP, float yVtxP, float zVtxP, float xVtxS, float yVtxS, float zVtxS, float px, float py, float pz, double m) -> float { return RecoDecay::ct(array{px, py, pz}, RecoDecay::distance(array{xVtxP, yVtxP, zVtxP}, array{xVtxS, yVtxS, zVtxS}), m); });
344341
DECLARE_SOA_DYNAMIC_COLUMN(ImpactParameterXY, impactParameterXY, //!
345342
[](float xVtxP, float yVtxP, float zVtxP, float xVtxS, float yVtxS, float zVtxS, float px, float py, float pz) -> float { return RecoDecay::impParXY(array{xVtxP, yVtxP, zVtxP}, array{xVtxS, yVtxS, zVtxS}, array{px, py, pz}); });
343+
344+
constexpr static int useDCAFitterN = 0;
345+
constexpr static int useKFParticle = 1;
346346
} // namespace hf_cand
347347

348348
// specific 2-prong decay properties
@@ -371,6 +371,10 @@ DECLARE_SOA_COLUMN(FlagMcMatchRec, flagMcMatchRec, int8_t); //! reconstruction l
371371
DECLARE_SOA_COLUMN(FlagMcMatchGen, flagMcMatchGen, int8_t); //! generator level
372372
DECLARE_SOA_COLUMN(OriginMcRec, originMcRec, int8_t); //! particle origin, reconstruction level
373373
DECLARE_SOA_COLUMN(OriginMcGen, originMcGen, int8_t); //! particle origin, generator level
374+
// KF related properties
375+
DECLARE_SOA_COLUMN(KfTopolChi2OverNdf, kfTopolChi2OverNdf, float); //! chi2overndf of the KFParticle topological constraint
376+
DECLARE_SOA_COLUMN(KfGeoMassD0, kfGeoMassD0, float); //! mass of the D0 candidate from the KFParticle geometric fit
377+
DECLARE_SOA_COLUMN(KfGeoMassD0bar, kfGeoMassD0bar, float); //! mass of the D0bar candidate from the KFParticle geometric fit
374378

375379
// mapping of decay types
376380
enum DecayType { D0ToPiK = 0,
@@ -523,8 +527,8 @@ DECLARE_SOA_EXTENDED_TABLE_USER(HfCand2ProngExt, HfCand2ProngBase, "HFCAND2PEXT"
523527
using HfCand2Prong = HfCand2ProngExt;
524528

525529
DECLARE_SOA_TABLE(HfCand2ProngKF, "AOD", "HFCAND2PKF",
526-
hf_cand::KFTopChi2OverNDF,
527-
hf_cand::KFGeoMass_DZero, hf_cand::KFGeoMass_DZeroBar);
530+
hf_cand_2prong::KfTopolChi2OverNdf,
531+
hf_cand_2prong::KfGeoMassD0, hf_cand_2prong::KfGeoMassD0bar);
528532

529533
// table with results of reconstruction level MC matching
530534
DECLARE_SOA_TABLE(HfCand2ProngMcRec, "AOD", "HFCAND2PMCREC", //!

PWGHF/TableProducer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ o2physics_add_dpl_workflow(refit-pv-dummy
2525

2626
o2physics_add_dpl_workflow(candidate-creator-2prong
2727
SOURCES candidateCreator2Prong.cxx
28-
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter KFParticle::KFParticle
28+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter KFParticle::KFParticle
2929
COMPONENT_NAME Analysis)
3030

3131
o2physics_add_dpl_workflow(candidate-creator-3prong

0 commit comments

Comments
 (0)