Skip to content

Commit c37cf9d

Browse files
Refactor charm hadron task parameters and methods
1 parent c3a61da commit c37cf9d

1 file changed

Lines changed: 34 additions & 52 deletions

File tree

‎PWGHF/HFC/Tasks/taskCharmHadronsCharmFemtoDream.cxx‎

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ struct HfTaskCharmHadronsCharmFemtoDream {
7575
Configurable<float> daughterMassMin{"daughterMassMin", 1.80f, "Minimum Dstar daughter D0 mass"};
7676
Configurable<float> daughterMassMax{"daughterMassMax", 1.93f, "Maximum Dstar daughter D0 mass"};
7777
Configurable<bool> useMl{"useMl", false, "Require valid ML scores and apply score cuts"};
78-
Configurable<float> maxBkgD0{"maxBkgD0", 1.f, "Maximum D0 background score"};
79-
Configurable<float> minPromptD0{"minPromptD0", 0.f, "Minimum D0 prompt score"};
80-
Configurable<float> maxBkgDstar{"maxBkgDstar", 1.f, "Maximum Dstar background score"};
81-
Configurable<float> minPromptDstar{"minPromptDstar", 0.f, "Minimum Dstar prompt score"};
78+
Configurable<float> d0BkgBdtMax{"d0BkgBdtMax", 1.f, "Maximum D0 background score"};
79+
Configurable<float> d0PromptBdtMin{"d0PromptBdtMin", 0.f, "Minimum D0 prompt score"};
80+
Configurable<float> dstarBkgBdtMax{"dstarBkgBdtMax", 1.f, "Maximum Dstar background score"};
81+
Configurable<float> dstarPromptBdtMin{"dstarPromptBdtMin", 0.f, "Minimum Dstar prompt score"};
8282
Configurable<int> charmHadCandSel{"charmHadCandSel", 1, "Minimum reduced charm candidate selection flag"};
8383
struct : ConfigurableGroup {
8484
std::string prefix = "eventSel";
@@ -108,8 +108,8 @@ struct HfTaskCharmHadronsCharmFemtoDream {
108108
Preslice<FilteredCharmCand2Prongs> perCollisionD0 = aod::femtodreamparticle::fdCollisionId;
109109
Preslice<FilteredCharmCandDstars> perCollisionDstar = aod::femtodreamparticle::fdCollisionId;
110110

111-
Partition<FilteredCharmCand2Prongs> partitionCharmHadron2Prong = ifnode(useMl, aod::fdhf::bdtBkg <= maxBkgD0 && aod::fdhf::bdtPrompt >= minPromptD0, Node{LiteralNode{true}});
112-
Partition<FilteredCharmCandDstars> partitionCharmHadronDstar = ifnode(useMl, aod::fdhf::bdtBkg <= maxBkgDstar && aod::fdhf::bdtPrompt >= minPromptDstar, Node{LiteralNode{true}});
111+
Partition<FilteredCharmCand2Prongs> partitionCharmHadron2Prong = ifnode(useMl, aod::fdhf::bdtBkg <= d0BkgBdtMax && aod::fdhf::bdtPrompt >= d0PromptBdtMin, Node{LiteralNode{true}});
112+
Partition<FilteredCharmCandDstars> partitionCharmHadronDstar = ifnode(useMl, aod::fdhf::bdtBkg <= dstarBkgBdtMax && aod::fdhf::bdtPrompt >= dstarPromptBdtMin, Node{LiteralNode{true}});
113113

114114
ConfigurableAxis mixingBinMult{"mixingBinMult", {VARIABLE_WIDTH, 0.f, 20.f, 60.f, 200.f}, "Mixing bins - multiplicity"};
115115
ConfigurableAxis mixingBinMultPercentile{"mixingBinMultPercentile", {VARIABLE_WIDTH, 0.f, 100.f}, "Mixing bins - multiplicity percentile"};
@@ -125,19 +125,12 @@ struct HfTaskCharmHadronsCharmFemtoDream {
125125
if (doprocessD0D0 == doprocessD0Dstar) {
126126
LOGP(fatal, "Enable exactly one charm-charm analysis process");
127127
}
128-
if (mixSetting.mixingDepth < 0 || mixSetting.mixingBinPolicy < 0 ||
129-
mixSetting.mixingBinPolicy > MixingBinPolicyMax || ptMinD0 < 0 || ptMinD0 >= ptMaxD0 ||
130-
ptMinDstar < 0 || ptMinDstar >= ptMaxDstar || etaMax <= 0 ||
131-
massMinD0 >= massMaxD0 || deltaMassMin >= deltaMassMax ||
132-
daughterMassMin >= daughterMassMax || charmHadCandSel < 1 ||
133-
eventSel.multMin > eventSel.multMax ||
134-
eventSel.multPercentileMin > eventSel.multPercentileMax) {
128+
if (mixSetting.mixingDepth < 0 || mixSetting.mixingBinPolicy < 0 || mixSetting.mixingBinPolicy > MixingBinPolicyMax || ptMinD0 < 0 || ptMinD0 >= ptMaxD0 || ptMinDstar < 0 || ptMinDstar >= ptMaxDstar || etaMax <= 0 || massMinD0 >= massMaxD0 || deltaMassMin >= deltaMassMax || daughterMassMin >= daughterMassMax || charmHadCandSel < 1 || eventSel.multMin > eventSel.multMax || eventSel.multPercentileMin > eventSel.multPercentileMax) {
135129
LOGP(fatal, "Invalid charm-charm selection or mixing configuration");
136130
}
137131
colBinningMult = {{mixingBinVztx, mixingBinMult}, true};
138132
colBinningMultPercentile = {{mixingBinVztx, mixingBinMultPercentile}, true};
139-
colBinningMultMultPercentile = {
140-
{mixingBinVztx, mixingBinMult, mixingBinMultPercentile}, true};
133+
colBinningMultMultPercentile = {{mixingBinVztx, mixingBinMult, mixingBinMultPercentile}, true};
141134
const AxisSpec kstar{400, 0., 2., "k* (GeV/c)"};
142135
const AxisSpec massD0{300, massMinD0.value, massMaxD0.value, "M(Kpi) (GeV/c2)"};
143136
const AxisSpec deltaMass{310, deltaMassMin.value, deltaMassMax.value, "Delta M (GeV/c2)"};
@@ -198,15 +191,14 @@ struct HfTaskCharmHadronsCharmFemtoDream {
198191
return first.pt() < second.pt(); // leading pT first for equal flavours
199192
}
200193

201-
template <typename Candidates>
202-
void validateMlScores(Candidates const& candidates)
194+
template <typename CandsType>
195+
void validateMlScores(CandsType const& candidates)
203196
{
204197
if (!useMl) {
205198
return;
206199
}
207200
for (const auto& row : candidates) {
208-
if (!std::isfinite(row.bdtBkg()) || !std::isfinite(row.bdtPrompt()) ||
209-
row.bdtBkg() < 0.f || row.bdtPrompt() < 0.f) {
201+
if (!std::isfinite(row.bdtBkg()) || !std::isfinite(row.bdtPrompt()) || row.bdtBkg() < 0.f || row.bdtPrompt() < 0.f) {
210202
LOGP(fatal, "ML cuts requested on missing/invalid scores: use an ML producer process");
211203
}
212204
}
@@ -244,8 +236,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
244236
}
245237

246238
template <bool Mixed, bool IsDstar, typename FirstRow, typename SecondRow>
247-
void fillPair(FirstRow const& first, SecondRow const& second, float firstMass,
248-
float secondMass, float mult)
239+
void fillPair(FirstRow const& first, SecondRow const& second, float firstMass, float secondMass, float mult)
249240
{
250241
if constexpr (!Mixed) {
251242
if (sharesDaughter<IsDstar>(first, second)) {
@@ -276,17 +267,23 @@ struct HfTaskCharmHadronsCharmFemtoDream {
276267
}
277268
}
278269

279-
template <typename Policy, typename Collision>
280-
int mixingBin(Policy const& policy, Collision col)
270+
template <typename CollType>
271+
int mixingBin(CollType const& col)
281272
{
282-
return policy.getBin(policy.getBinningValues(col));
273+
switch (mixSetting.mixingBinPolicy) {
274+
case aod::femtodreamcollision::kMult:
275+
return colBinningMult.getBin({col.posZ(), col.multNtr()});
276+
case aod::femtodreamcollision::kMultPercentile:
277+
return colBinningMultPercentile.getBin({col.posZ(), col.multV0M()});
278+
case aod::femtodreamcollision::kMultMultPercentile:
279+
return colBinningMultMultPercentile.getBin({col.posZ(), col.multNtr(), col.multV0M()});
280+
default:
281+
return -1;
282+
}
283283
}
284284

285285
template <bool IsDstar, typename D0Table, typename OtherTable, typename Policy>
286-
void doMixedEvent(FilteredCollisions const& cols,
287-
D0Table const& d0Rows,
288-
OtherTable const& otherRows,
289-
Policy const& policy)
286+
void doMixedEvent(FilteredCollisions const& cols, D0Table const& d0Rows, OtherTable const& otherRows, Policy const& policy)
290287
{
291288
Partition<FilteredCollisions> partitionMaskedCol1 = (aod::femtodreamcollision::bitmaskTrackOne & bitMask) == bitMask;
292289
// TrackOne denotes D0 presence, TrackTwo denotes Dstar presence.
@@ -314,9 +311,9 @@ struct HfTaskCharmHadronsCharmFemtoDream {
314311
continue;
315312
}
316313
if constexpr (IsDstar) {
317-
registry.fill(HIST("MixingQA/hMECollisionBinsD0Dstar"), mixingBin(policy, collision1));
314+
registry.fill(HIST("MixingQA/hMECollisionBinsD0Dstar"), mixingBin(collision1));
318315
} else {
319-
registry.fill(HIST("MixingQA/hMECollisionBinsD0D0"), mixingBin(policy, collision1));
316+
registry.fill(HIST("MixingQA/hMECollisionBinsD0D0"), mixingBin(collision1));
320317
}
321318
auto first = d0Rows.sliceByCached(aod::femtodreamparticle::fdCollisionId, collision1.globalIndex(), cache);
322319
auto second = otherRows.sliceByCached(aod::femtodreamparticle::fdCollisionId, collision2.globalIndex(), cache);
@@ -334,9 +331,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
334331
// Write candidates once per collision, independently of SE/ME pair counts.
335332
// Reuse the same output tables and field conventions as the track/V0 tasks.
336333
template <bool WithDstar, typename CollType, typename D0Slice, typename DstarSlice>
337-
void fillTables(CollType const& col,
338-
D0Slice const& d0s,
339-
DstarSlice const& dstars)
334+
void fillTables(CollType const& col, D0Slice const& d0s, DstarSlice const& dstars)
340335
{
341336
int64_t timeStamp = -1;
342337
bool hasCandidate = false;
@@ -353,10 +348,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
353348
continue;
354349
}
355350
recordTimeStamp(part.timeStamp());
356-
rowFemtoResultCharm2Prong(col.globalIndex(), timeStamp, mass, part.pt(),
357-
part.eta(), part.phi(), part.prong0Id(),
358-
part.prong1Id(), part.charge(), part.bdtBkg(),
359-
part.bdtPrompt(), part.bdtFD(), 0, 0);
351+
rowFemtoResultCharm2Prong(col.globalIndex(), timeStamp, mass, part.pt(), part.eta(), part.phi(), part.prong0Id(), part.prong1Id(), part.charge(), part.bdtBkg(), part.bdtPrompt(), part.bdtFD(), 0, 0);
360352
}
361353
if constexpr (WithDstar) {
362354
for (const auto& part : dstars) {
@@ -367,11 +359,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
367359
recordTimeStamp(part.timeStamp());
368360
const std::array<double, 2> daughterMasses = part.charge() > 0 ? std::array{MassPiPlus, MassKPlus} : std::array{MassKPlus, MassPiPlus};
369361
// CharmM is delta mass, CharmDaughM is M(Kpi), as in D+Track.
370-
rowFemtoResultCharmDstar(
371-
col.globalIndex(), timeStamp, mass, part.mDaughD0(daughterMasses),
372-
part.pt(), part.eta(), part.phi(), part.prong0Id(), part.prong1Id(),
373-
part.prong2Id(), part.charge(), part.bdtBkg(), part.bdtPrompt(),
374-
part.bdtFD(), 0, 0);
362+
rowFemtoResultCharmDstar(col.globalIndex(), timeStamp, mass, part.mDaughD0(daughterMasses), part.pt(), part.eta(), part.phi(), part.prong0Id(), part.prong1Id(), part.prong2Id(), part.charge(), part.bdtBkg(), part.bdtPrompt(), part.bdtFD(), 0, 0);
375363
}
376364
}
377365
// Retain D0-only/Dstar-only events even when no clean SE pair exists.
@@ -382,10 +370,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
382370
}
383371

384372
template <bool WithDstar, typename D0Table, typename DstarTable, typename Policy>
385-
void runWithPolicy(FilteredCollisions const& cols,
386-
D0Table const& d0Rows,
387-
DstarTable const& dstarRows,
388-
Policy const& policy)
373+
void runWithPolicy(FilteredCollisions const& cols, D0Table const& d0Rows, DstarTable const& dstarRows, Policy const& policy)
389374
{
390375
for (const auto& col : cols) {
391376
auto d0s = d0Rows.sliceByCached(aod::femtodreamparticle::fdCollisionId, col.globalIndex(), cache);
@@ -396,7 +381,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
396381
} else {
397382
fillTables<false>(col, d0s, d0s);
398383
}
399-
const int bin = mixingBin(policy, col);
384+
const int bin = mixingBin(col);
400385
if (bin < 0 || !std::isfinite(col.magField())) {
401386
registry.fill(HIST("QA/events"), 1);
402387
continue;
@@ -428,9 +413,7 @@ struct HfTaskCharmHadronsCharmFemtoDream {
428413
}
429414

430415
template <bool WithDstar, typename DstarTable>
431-
void run(FilteredCollisions const& cols,
432-
FilteredCharmCand2Prongs const& d0Rows,
433-
DstarTable const& dstarRows)
416+
void run(FilteredCollisions const& cols, FilteredCharmCand2Prongs const& d0Rows, DstarTable const& dstarRows)
434417
{
435418
validateMlScores(d0Rows);
436419
partitionCharmHadron2Prong.bindTable(d0Rows);
@@ -471,6 +454,5 @@ struct HfTaskCharmHadronsCharmFemtoDream {
471454

472455
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
473456
{
474-
return WorkflowSpec{
475-
adaptAnalysisTask<HfTaskCharmHadronsCharmFemtoDream>(cfgc)};
457+
return WorkflowSpec{adaptAnalysisTask<HfTaskCharmHadronsCharmFemtoDream>(cfgc)};
476458
}

0 commit comments

Comments
 (0)