Skip to content

Commit ddbcbba

Browse files
nzardoshvkucera
andauthored
[PWGHF] Add the possibility to run MC Gen only for HF derived data (#9357)
Co-authored-by: Vít Kučera <vit.kucera@cern.ch>
1 parent d7b61f7 commit ddbcbba

10 files changed

+349
-171
lines changed

PWGHF/TableProducer/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ o2physics_add_dpl_workflow(candidate-creator-xicc
100100
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter
101101
COMPONENT_NAME Analysis)
102102

103+
o2physics_add_dpl_workflow(candidate-creator-mc-gen
104+
SOURCES candidateCreatorMcGen.cxx
105+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
106+
COMPONENT_NAME Analysis)
107+
103108
# Candidate selectors
104109

105110
o2physics_add_dpl_workflow(candidate-selector-b0-to-d-pi

PWGHF/TableProducer/candidateCreator2Prong.cxx

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "PWGHF/Utils/utilsEvSelHf.h"
5050
#include "PWGHF/Utils/utilsPid.h"
5151
#include "PWGHF/Utils/utilsTrkCandHf.h"
52+
#include "PWGHF/Utils/utilsMcGen.h"
5253

5354
using namespace o2;
5455
using namespace o2::analysis;
@@ -839,47 +840,7 @@ struct HfCandidateCreator2ProngExpressions {
839840
}
840841
continue;
841842
}
842-
843-
// Match generated particles.
844-
for (const auto& particle : mcParticlesPerMcColl) {
845-
flag = 0;
846-
origin = 0;
847-
std::vector<int> idxBhadMothers{};
848-
// Reject particles from background events
849-
if (particle.fromBackgroundEvent() && rejectBackground) {
850-
rowMcMatchGen(flag, origin, -1);
851-
continue;
852-
}
853-
854-
// D0(bar) → π± K∓
855-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) {
856-
flag = sign * (1 << DecayType::D0ToPiK);
857-
}
858-
859-
// J/ψ → e+ e−
860-
if (flag == 0) {
861-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true)) {
862-
flag = 1 << DecayType::JpsiToEE;
863-
}
864-
}
865-
866-
// J/ψ → μ+ μ−
867-
if (flag == 0) {
868-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true)) {
869-
flag = 1 << DecayType::JpsiToMuMu;
870-
}
871-
}
872-
873-
// Check whether the particle is non-prompt (from a b quark).
874-
if (flag != 0) {
875-
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
876-
}
877-
if (origin == RecoDecay::OriginType::NonPrompt) {
878-
rowMcMatchGen(flag, origin, idxBhadMothers[0]);
879-
} else {
880-
rowMcMatchGen(flag, origin, -1);
881-
}
882-
}
843+
hf_mc_gen::fillMcMatchGen2Prong(mcParticlesPerMcColl, rowMcMatchGen, rejectBackground);
883844
}
884845
}
885846

PWGHF/TableProducer/candidateCreator3Prong.cxx

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "PWGHF/Utils/utilsBfieldCCDB.h"
4949
#include "PWGHF/Utils/utilsEvSelHf.h"
5050
#include "PWGHF/Utils/utilsTrkCandHf.h"
51+
#include "PWGHF/Utils/utilsMcGen.h"
5152

5253
using namespace o2;
5354
using namespace o2::analysis;
@@ -1048,96 +1049,7 @@ struct HfCandidateCreator3ProngExpressions {
10481049
}
10491050
continue;
10501051
}
1051-
1052-
// Match generated particles.
1053-
for (const auto& particle : mcParticlesPerMcColl) {
1054-
flag = 0;
1055-
origin = 0;
1056-
channel = 0;
1057-
arrDaughIndex.clear();
1058-
std::vector<int> idxBhadMothers{};
1059-
// Reject particles from background events
1060-
if (particle.fromBackgroundEvent() && rejectBackground) {
1061-
rowMcMatchGen(flag, origin, channel, -1);
1062-
continue;
1063-
}
1064-
1065-
// D± → π± K∓ π±
1066-
if (createDplus) {
1067-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kPiPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
1068-
flag = sign * (1 << DecayType::DplusToPiKPi);
1069-
}
1070-
}
1071-
1072-
// Ds± → K± K∓ π± and D± → K± K∓ π±
1073-
if (flag == 0 && createDs) {
1074-
bool isDplus = false;
1075-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDS, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
1076-
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
1077-
// TODO: move to different and explicit flags
1078-
flag = sign * (1 << DecayType::DsToKKPi);
1079-
} else if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kDPlus, std::array{+kKPlus, -kKPlus, +kPiPlus}, true, &sign, 2)) {
1080-
// DecayType::DsToKKPi is used to flag both Ds± → K± K∓ π± and D± → K± K∓ π±
1081-
// TODO: move to different and explicit flags
1082-
flag = sign * (1 << DecayType::DsToKKPi);
1083-
isDplus = true;
1084-
}
1085-
if (flag != 0) {
1086-
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
1087-
if (arrDaughIndex.size() == 2) {
1088-
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
1089-
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
1090-
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
1091-
}
1092-
if ((arrPDGDaugh[0] == arrPDGResonantDPhiPi[0] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[1]) || (arrPDGDaugh[0] == arrPDGResonantDPhiPi[1] && arrPDGDaugh[1] == arrPDGResonantDPhiPi[0])) {
1093-
channel = isDplus ? DecayChannelDToKKPi::DplusToPhiPi : DecayChannelDToKKPi::DsToPhiPi;
1094-
} else if ((arrPDGDaugh[0] == arrPDGResonantDKstarK[0] && arrPDGDaugh[1] == arrPDGResonantDKstarK[1]) || (arrPDGDaugh[0] == arrPDGResonantDKstarK[1] && arrPDGDaugh[1] == arrPDGResonantDKstarK[0])) {
1095-
channel = isDplus ? DecayChannelDToKKPi::DplusToK0starK : DecayChannelDToKKPi::DsToK0starK;
1096-
}
1097-
}
1098-
}
1099-
}
1100-
1101-
// Λc± → p± K∓ π±
1102-
if (flag == 0 && createLc) {
1103-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kLambdaCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
1104-
flag = sign * (1 << DecayType::LcToPKPi);
1105-
1106-
// Flagging the different Λc± → p± K∓ π± decay channels
1107-
RecoDecay::getDaughters(particle, &arrDaughIndex, std::array{0}, 1);
1108-
if (arrDaughIndex.size() == 2) {
1109-
for (auto jProng = 0u; jProng < arrDaughIndex.size(); ++jProng) {
1110-
auto daughJ = mcParticles.rawIteratorAt(arrDaughIndex[jProng]);
1111-
arrPDGDaugh[jProng] = std::abs(daughJ.pdgCode());
1112-
}
1113-
if ((arrPDGDaugh[0] == arrPDGResonant1[0] && arrPDGDaugh[1] == arrPDGResonant1[1]) || (arrPDGDaugh[0] == arrPDGResonant1[1] && arrPDGDaugh[1] == arrPDGResonant1[0])) {
1114-
channel = 1;
1115-
} else if ((arrPDGDaugh[0] == arrPDGResonant2[0] && arrPDGDaugh[1] == arrPDGResonant2[1]) || (arrPDGDaugh[0] == arrPDGResonant2[1] && arrPDGDaugh[1] == arrPDGResonant2[0])) {
1116-
channel = 2;
1117-
} else if ((arrPDGDaugh[0] == arrPDGResonant3[0] && arrPDGDaugh[1] == arrPDGResonant3[1]) || (arrPDGDaugh[0] == arrPDGResonant3[1] && arrPDGDaugh[1] == arrPDGResonant3[0])) {
1118-
channel = 3;
1119-
}
1120-
}
1121-
}
1122-
}
1123-
1124-
// Ξc± → p± K∓ π±
1125-
if (flag == 0 && createXic) {
1126-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kXiCPlus, std::array{+kProton, -kKPlus, +kPiPlus}, true, &sign, 2)) {
1127-
flag = sign * (1 << DecayType::XicToPKPi);
1128-
}
1129-
}
1130-
1131-
// Check whether the particle is non-prompt (from a b quark).
1132-
if (flag != 0) {
1133-
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
1134-
}
1135-
if (origin == RecoDecay::OriginType::NonPrompt) {
1136-
rowMcMatchGen(flag, origin, channel, idxBhadMothers[0]);
1137-
} else {
1138-
rowMcMatchGen(flag, origin, channel, -1);
1139-
}
1140-
}
1052+
hf_mc_gen::fillMcMatchGen3Prong(mcParticlesPerMcColl, rowMcMatchGen, rejectBackground, createDplus, createDs, createLc, createXic);
11411053
}
11421054
}
11431055

PWGHF/TableProducer/candidateCreatorB0.cxx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "PWGHF/DataModel/CandidateSelectionTables.h"
3535
#include "PWGHF/Utils/utilsBfieldCCDB.h"
3636
#include "PWGHF/Utils/utilsTrkCandHf.h"
37+
#include "PWGHF/Utils/utilsMcGen.h"
3738

3839
using namespace o2;
3940
using namespace o2::analysis;
@@ -452,20 +453,7 @@ struct HfCandidateCreatorB0Expressions {
452453
rowMcMatchRec(flag, origin, debug);
453454
} // rec
454455

455-
// Match generated particles.
456-
for (const auto& particle : mcParticles) {
457-
flag = 0;
458-
origin = 0;
459-
// B0 → D- π+
460-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kB0, std::array{-static_cast<int>(Pdg::kDPlus), +kPiPlus}, true)) {
461-
// D- → π- K+ π-
462-
auto candDMC = mcParticles.rawIteratorAt(particle.daughtersIds().front());
463-
if (RecoDecay::isMatchedMCGen(mcParticles, candDMC, -static_cast<int>(Pdg::kDPlus), std::array{-kPiPlus, +kKPlus, -kPiPlus}, true, &sign)) {
464-
flag = sign * BIT(hf_cand_b0::DecayType::B0ToDPi);
465-
}
466-
}
467-
rowMcMatchGen(flag, origin);
468-
} // gen
456+
hf_mc_gen::fillMcMatchGenB0(mcParticles, rowMcMatchGen); // gen
469457
} // processMc
470458
PROCESS_SWITCH(HfCandidateCreatorB0Expressions, processMc, "Process MC", false);
471459
}; // struct

PWGHF/TableProducer/candidateCreatorBplus.cxx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "PWGHF/DataModel/CandidateSelectionTables.h"
3838
#include "PWGHF/Utils/utilsBfieldCCDB.h"
3939
#include "PWGHF/Utils/utilsTrkCandHf.h"
40+
#include "PWGHF/Utils/utilsMcGen.h"
4041

4142
using namespace o2;
4243
using namespace o2::analysis;
@@ -365,7 +366,6 @@ struct HfCandidateCreatorBplusExpressions {
365366
int8_t signB = 0, signD0 = 0;
366367
int8_t flag = 0;
367368
int8_t origin = 0;
368-
int kD0pdg = Pdg::kD0;
369369

370370
// Match reconstructed candidates.
371371
// Spawned table can be used directly
@@ -386,31 +386,7 @@ struct HfCandidateCreatorBplusExpressions {
386386
}
387387
rowMcMatchRec(flag, origin);
388388
}
389-
390-
// Match generated particles.
391-
for (const auto& particle : mcParticles) {
392-
flag = 0;
393-
origin = 0;
394-
signB = 0;
395-
signD0 = 0;
396-
int indexGenD0 = -1;
397-
398-
// B± → D0bar(D0) π± → (K± π∓) π±
399-
std::vector<int> arrayDaughterB;
400-
if (RecoDecay::isMatchedMCGen(mcParticles, particle, Pdg::kBPlus, std::array{-kD0pdg, +kPiPlus}, true, &signB, 1, &arrayDaughterB)) {
401-
// D0(bar) → π± K∓
402-
for (auto iD : arrayDaughterB) {
403-
auto candDaughterMC = mcParticles.rawIteratorAt(iD);
404-
if (std::abs(candDaughterMC.pdgCode()) == kD0pdg) {
405-
indexGenD0 = RecoDecay::isMatchedMCGen(mcParticles, candDaughterMC, Pdg::kD0, std::array{-kKPlus, +kPiPlus}, true, &signD0, 1);
406-
}
407-
}
408-
if (indexGenD0 > -1) {
409-
flag = signB * (1 << hf_cand_bplus::DecayType::BplusToD0Pi);
410-
}
411-
}
412-
rowMcMatchGen(flag, origin);
413-
} // B candidate
389+
hf_mc_gen::fillMcMatchGenBplus(mcParticles, rowMcMatchGen); // gen
414390
} // process
415391
PROCESS_SWITCH(HfCandidateCreatorBplusExpressions, processMc, "Process MC", false);
416392
}; // struct
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file candidateCreatorMcGen.cxx
13+
/// \brief McGen only selection of heavy-flavour particles
14+
///
15+
/// \author Nima Zardoshti, nima.zardoshti@cern.ch, CERN
16+
17+
#include <memory>
18+
#include <string>
19+
#include <vector>
20+
21+
#include <TPDGCode.h>
22+
23+
#include "CommonConstants/PhysicsConstants.h"
24+
#include "Framework/AnalysisTask.h"
25+
#include "Framework/HistogramRegistry.h"
26+
#include "Framework/runDataProcessing.h"
27+
#include "Framework/RunningWorkflowInfo.h"
28+
29+
#include "PWGHF/DataModel/CandidateReconstructionTables.h"
30+
#include "PWGHF/Utils/utilsMcGen.h"
31+
32+
using namespace o2;
33+
using namespace o2::analysis;
34+
using namespace o2::framework;
35+
36+
/// Reconstruction of heavy-flavour 2-prong decay candidates
37+
struct HfCandidateCreatorMcGen {
38+
39+
Produces<aod::HfCand2ProngMcGen> rowMcMatchGen2Prong;
40+
Produces<aod::HfCand3ProngMcGen> rowMcMatchGen3Prong;
41+
Produces<aod::HfCandBplusMcGen> rowMcMatchGenBplus;
42+
Produces<aod::HfCandB0McGen> rowMcMatchGenB0;
43+
Configurable<bool> fill2Prong{"fill2Prong", false, "fill table for 2 prong candidates"};
44+
Configurable<bool> fill3Prong{"fill3Prong", false, "fill table for 3 prong candidates"};
45+
Configurable<bool> fillBplus{"fillBplus", false, "fill table for for B+ candidates"};
46+
Configurable<bool> fillB0{"fillB0", false, "fill table for B0 candidates"};
47+
Configurable<bool> rejectBackground2Prong{"rejectBackground2Prong", false, "Reject particles from PbPb background for 2 prong candidates"};
48+
Configurable<bool> rejectBackground3Prong{"rejectBackground3Prong", false, "Reject particles from PbPb background for 3 prong candidates"};
49+
Configurable<bool> createDplus{"createDplus", false, "Create D+ in 3 prong"};
50+
Configurable<bool> createDs{"createDs", false, "Create Ds in 3 prong"};
51+
Configurable<bool> createLc{"createLc", false, "Create Lc in 3 prong"};
52+
Configurable<bool> createXic{"createXic", false, "Create Xic in 3 prong"};
53+
54+
void process(aod::McCollision const&,
55+
aod::McParticles const& mcParticles)
56+
{
57+
if (fill2Prong) {
58+
hf_mc_gen::fillMcMatchGen2Prong(mcParticles, rowMcMatchGen2Prong, rejectBackground2Prong);
59+
}
60+
if (fill3Prong) {
61+
hf_mc_gen::fillMcMatchGen3Prong(mcParticles, rowMcMatchGen3Prong, rejectBackground3Prong, createDplus, createDs, createLc, createXic);
62+
}
63+
if (fillBplus) {
64+
hf_mc_gen::fillMcMatchGenBplus(mcParticles, rowMcMatchGenBplus);
65+
}
66+
if (fillB0) {
67+
hf_mc_gen::fillMcMatchGenB0(mcParticles, rowMcMatchGenB0);
68+
}
69+
}
70+
};
71+
72+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
73+
{
74+
return WorkflowSpec{
75+
adaptAnalysisTask<HfCandidateCreatorMcGen>(cfgc)};
76+
}

PWGHF/TableProducer/derivedDataCreatorBplusToD0Pi.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ struct HfDerivedDataCreatorBplusToD0Pi {
419419
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
420420
}
421421
PROCESS_SWITCH(HfDerivedDataCreatorBplusToD0Pi, processMcMlAll, "Process MC with ML", false);
422+
423+
void processMcGenOnly(TypeMcCollisions const& mcCollisions,
424+
MatchedGenCandidatesMc const& mcParticles)
425+
{
426+
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
427+
}
428+
PROCESS_SWITCH(HfDerivedDataCreatorBplusToD0Pi, processMcGenOnly, "Process MC gen. only", false);
422429
};
423430

424431
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)

PWGHF/TableProducer/derivedDataCreatorD0ToKPi.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ struct HfDerivedDataCreatorD0ToKPi {
516516
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
517517
}
518518
PROCESS_SWITCH(HfDerivedDataCreatorD0ToKPi, processMcWithKFParticleMlAll, "Process MC with KFParticle and ML", false);
519+
520+
void processMcGenOnly(TypeMcCollisions const& mcCollisions,
521+
MatchedGenCandidatesMc const& mcParticles)
522+
{
523+
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
524+
}
525+
PROCESS_SWITCH(HfDerivedDataCreatorD0ToKPi, processMcGenOnly, "Process MC gen. only", false);
519526
};
520527

521528
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)

PWGHF/TableProducer/derivedDataCreatorLcToPKPi.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ struct HfDerivedDataCreatorLcToPKPi {
387387
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
388388
}
389389
PROCESS_SWITCH(HfDerivedDataCreatorLcToPKPi, processMcMlAll, "Process MC with ML", false);
390+
391+
void processMcGenOnly(TypeMcCollisions const& mcCollisions,
392+
MatchedGenCandidatesMc const& mcParticles)
393+
{
394+
rowsCommon.processMcParticles(mcCollisions, mcParticlesPerMcCollision, mcParticles, mass);
395+
}
396+
PROCESS_SWITCH(HfDerivedDataCreatorLcToPKPi, processMcGenOnly, "Process MC gen. only", false);
390397
};
391398

392399
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)

0 commit comments

Comments
 (0)