1- // Copyright 2019-2025 CERN and copyright holders of ALICE O2.
2- // See https://alice-o2.web.cern.ch/copyright for details of the copyright
3- // holders. All rights not expressly granted are reserved.
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.
44//
55// This software is distributed under the terms of the GNU General Public
66// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
2626#include " Common/DataModel/Centrality.h"
2727#include " Common/DataModel/EventSelection.h"
2828#include " Common/DataModel/Multiplicity.h"
29+ #include < Tools/ML/MlResponse.h>
2930
3031#include < CCDB/BasicCCDBManager.h>
3132#include < CCDB/CcdbApi.h>
4344#include < Framework/InitContext.h>
4445#include < Framework/OutputObjHeader.h>
4546#include < Framework/runDataProcessing.h>
46- #include < Tools/ML/MlResponse.h>
4747
4848#include < algorithm>
4949#include < array>
@@ -100,18 +100,13 @@ struct HfProducerCharmHadronsCharmFemtoDream {
100100 using Collisions = soa::Join<aod::Collisions, aod::EvSels, aod::Mults>;
101101 using CollisionsWithFT0C = soa::Join<Collisions, aod::CentFT0Cs>;
102102 using D0s = soa::Join<aod::HfCand2Prong, aod::HfSelD0>;
103- using Dstars =
104- soa::Join<aod::HfCandDstars, aod::HfD0FromDstar, aod::HfSelDstarToD0Pi>;
103+ using Dstars = soa::Join<aod::HfCandDstars, aod::HfD0FromDstar, aod::HfSelDstarToD0Pi>;
105104
106105 using D0sMl = soa::Join<aod::HfCand2ProngWPid, aod::HfSelD0, aod::HfMlD0>;
107- using DstarsMl = soa::Join<aod::HfCandDstarsWPid, aod::HfD0FromDstar,
108- aod::HfSelDstarToD0Pi, aod::HfMlDstarToD0Pi>;
106+ using DstarsMl = soa::Join<aod::HfCandDstarsWPid, aod::HfD0FromDstar, aod::HfSelDstarToD0Pi, aod::HfMlDstarToD0Pi>;
109107
110- Filter filterSelectCandidateD0 =
111- (aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 ||
112- aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0);
113- Filter filterSelectCandidateDstar =
114- aod::hf_sel_candidate_dstar::isSelDstarToD0Pi == true ;
108+ Filter filterSelectCandidateD0 = (aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 || aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0);
109+ Filter filterSelectCandidateDstar = aod::hf_sel_candidate_dstar::isSelDstarToD0Pi == true ;
115110
116111 HistogramRegistry registry{" registry" };
117112 OutputObj<ZorroSummary> zorroSummary{" zorroSummary" };
@@ -121,9 +116,9 @@ struct HfProducerCharmHadronsCharmFemtoDream {
121116 int runNumber = -1 ;
122117
123118 template <typename Response>
124- void initMl (HfMlConfig const &cfg, Response & response, bool withMl) {
125- if (cfg. applyMlMode . value < NoMl ||
126- cfg.applyMlMode .value > FillMlFromNewBDT) {
119+ void initMl (HfMlConfig const & cfg, Response& response, bool withMl)
120+ {
121+ if (cfg. applyMlMode . value < NoMl || cfg.applyMlMode .value > FillMlFromNewBDT) {
127122 LOGP (fatal, " {}: invalid applyMlMode" , cfg.prefix );
128123 }
129124 if (cfg.applyMlMode .value != FillMlFromNewBDT) {
@@ -132,31 +127,18 @@ struct HfProducerCharmHadronsCharmFemtoDream {
132127 if (!withMl) {
133128 LOGP (fatal, " {}: new BDT requires an Ml producer process" , cfg.prefix );
134129 }
135- auto const &edges = cfg.binsPtMl .value ;
136- if (edges.size () < NMlPtEdgesMin ||
137- !std::all_of (edges.begin (), edges.end (),
138- [](double x) { return std::isfinite (x); }) ||
139- std::adjacent_find (edges.begin (), edges.end (), [](double a, double b) {
140- return a >= b;
141- }) != edges.end ()) {
142- LOGP (fatal, " {}: binsPtMl must be finite and strictly increasing" ,
143- cfg.prefix );
130+ auto const & edges = cfg.binsPtMl .value ;
131+ if (edges.size () < NMlPtEdgesMin || !std::all_of (edges.begin (), edges.end (), [](double x) { return std::isfinite (x); }) || std::adjacent_find (edges.begin (), edges.end (), [](double a, double b) {
132+ return a >= b;
133+ }) != edges.end ()) {
134+ LOGP (fatal, " {}: binsPtMl must be finite and strictly increasing" , cfg.prefix );
144135 }
145136 const auto nBins = edges.size () - 1 ;
146- if (cfg.nClassesMl .value != NMlClasses || cfg.cutDirMl .value .size () != NMlClasses ||
147- cfg.cutsMl .value .rows () != nBins || cfg.cutsMl .value .cols () != NMlClasses ||
148- cfg.onnxFileNames .value .size () != nBins ||
149- cfg.namesInputFeatures .value .empty () ||
150- (cfg.loadModelsFromCCDB .value &&
151- cfg.modelPathsCCDB .value .size () != nBins)) {
152- LOGP (fatal,
153- " {}: provide three classes, cuts/models for every pT bin, and input "
154- " features" ,
155- cfg.prefix );
137+ if (cfg.nClassesMl .value != NMlClasses || cfg.cutDirMl .value .size () != NMlClasses || cfg.cutsMl .value .rows () != nBins || cfg.cutsMl .value .cols () != NMlClasses || cfg.onnxFileNames .value .size () != nBins || cfg.namesInputFeatures .value .empty () || (cfg.loadModelsFromCCDB .value && cfg.modelPathsCCDB .value .size () != nBins)) {
138+ LOGP (fatal, " {}: provide three classes, cuts/models for every pT bin, and input features" , cfg.prefix );
156139 }
157140 for (const auto & direction : cfg.cutDirMl .value ) {
158- if (direction < o2::cuts_ml::CutGreater ||
159- direction > o2::cuts_ml::CutNot) {
141+ if (direction < o2::cuts_ml::CutGreater || direction > o2::cuts_ml::CutNot) {
160142 LOGP (fatal, " {}: invalid cutDirMl" , cfg.prefix );
161143 }
162144 }
@@ -167,30 +149,28 @@ struct HfProducerCharmHadronsCharmFemtoDream {
167149 }
168150 }
169151 }
170- response.configure (edges, cfg.cutsMl .value , cfg.cutDirMl .value ,
171- cfg.nClassesMl .value );
152+ response.configure (edges, cfg.cutsMl .value , cfg.cutDirMl .value , cfg.nClassesMl .value );
172153 response.cacheInputFeaturesIndices (cfg.namesInputFeatures .value );
173154 if (cfg.loadModelsFromCCDB .value ) {
174155 ccdbApi.init (ccdbUrl.value );
175- response.setModelPathsCCDB (cfg.onnxFileNames .value , ccdbApi,
176- cfg.modelPathsCCDB .value ,
177- cfg.timestampCCDB .value );
156+ response.setModelPathsCCDB (cfg.onnxFileNames .value , ccdbApi, cfg.modelPathsCCDB .value , cfg.timestampCCDB .value );
178157 } else {
179158 response.setModelPathsLocal (cfg.onnxFileNames .value );
180159 }
181160 response.init ();
182161 }
183162
184- void init (InitContext const &) {
163+ void init (InitContext const &)
164+ {
185165 const std::array<bool , 8 > processSwitches{
186- static_cast <bool >(doprocessD0D0),
187- static_cast <bool >(doprocessD0Dstar),
188- static_cast <bool >(doprocessD0D0Ml),
189- static_cast <bool >(doprocessD0DstarMl),
190- static_cast <bool >(doprocessD0D0WithFT0C),
191- static_cast <bool >(doprocessD0DstarWithFT0C),
192- static_cast <bool >(doprocessD0D0MlWithFT0C),
193- static_cast <bool >(doprocessD0DstarMlWithFT0C)};
166+ static_cast <bool >(doprocessD0D0),
167+ static_cast <bool >(doprocessD0Dstar),
168+ static_cast <bool >(doprocessD0D0Ml),
169+ static_cast <bool >(doprocessD0DstarMl),
170+ static_cast <bool >(doprocessD0D0WithFT0C),
171+ static_cast <bool >(doprocessD0DstarWithFT0C),
172+ static_cast <bool >(doprocessD0D0MlWithFT0C),
173+ static_cast <bool >(doprocessD0DstarMlWithFT0C)};
194174 if (std::count (processSwitches.begin (), processSwitches.end (), true ) != 1 ) {
195175 LOGP (fatal, " Enable exactly one charm-charm producer process" );
196176 }
@@ -200,28 +180,25 @@ struct HfProducerCharmHadronsCharmFemtoDream {
200180 ccdb->setURL (ccdbUrl);
201181 ccdb->setCaching (true );
202182 ccdb->setLocalObjectValidityChecking ();
203- const bool withMl = doprocessD0D0Ml || doprocessD0DstarMl ||
204- doprocessD0D0MlWithFT0C || doprocessD0DstarMlWithFT0C;
183+ const bool withMl = doprocessD0D0Ml || doprocessD0DstarMl || doprocessD0D0MlWithFT0C || doprocessD0DstarMlWithFT0C;
205184 initMl (mlD0, hfMlResponseD0, withMl);
206- if (doprocessD0Dstar || doprocessD0DstarMl || doprocessD0DstarWithFT0C ||
207- doprocessD0DstarMlWithFT0C) {
185+ if (doprocessD0Dstar || doprocessD0DstarMl || doprocessD0DstarWithFT0C || doprocessD0DstarMlWithFT0C) {
208186 initMl (mlDstar, hfMlResponseDstar, withMl);
209187 }
210188 hfEvSel.init (registry, &zorroSummary);
211189 const AxisSpec eventStage{2 , -0.5 , 1.5 , " stage (0=all,1=accepted)" };
212- const AxisSpec candidateSpecies{
213- 4 , -0.5 , 3.5 , " species (0=D0,1=D0bar,2=Dstar+,3=Dstar-)" };
190+ const AxisSpec candidateSpecies{4 , -0.5 , 3.5 , " species (0=D0,1=D0bar,2=Dstar+,3=Dstar-)" };
214191 registry.add (" events" , " Events" , kTH1F , {eventStage});
215192 registry.add (" candidates" , " Candidates" , kTH1F , {candidateSpecies});
216193 }
217194
218195 template <o2::hf_centrality::CentralityEstimator CentEstimator,
219196 typename Collision>
220- bool acceptCollision (Collision const &col) {
197+ bool acceptCollision (Collision const & col)
198+ {
221199 registry.fill (HIST (" events" ), 0 );
222200 float cent = -1 .f ; // No centrality for pp MB.
223- const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask <
224- true , CentEstimator, aod::BCsWithTimestamps>(col, cent, ccdb, registry);
201+ const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask <true , CentEstimator, aod::BCsWithTimestamps>(col, cent, ccdb, registry);
225202 hfEvSel.fillHistograms (col, rejectionMask, cent);
226203 if (rejectionMask != 0 ) {
227204 return false ;
@@ -231,8 +208,7 @@ struct HfProducerCharmHadronsCharmFemtoDream {
231208 auto bc = col.template bc_as <aod::BCsWithTimestamps>();
232209 initCCDB (bc, runNumber, ccdb, ccdbPathGrpMag.value , nullptr , false );
233210 // Propagator field is in kG; FemtoDream uses Tesla.
234- const float fieldTesla =
235- 0 .1f * o2::base::Propagator::Instance ()->getNominalBz ();
211+ const float fieldTesla = 0 .1f * o2::base::Propagator::Instance ()->getNominalBz ();
236212 // MultV0M is the common reduced percentile column: FT0C or -1 (no
237213 // estimator).
238214 collisions (col.posZ (), cent, col.multNTracksPV (), 2 .f , fieldTesla);
@@ -242,10 +218,10 @@ struct HfProducerCharmHadronsCharmFemtoDream {
242218 }
243219
244220 template <typename Scores>
245- std::array<float , 3 > readScores (Scores const &scores) {
221+ std::array<float , 3 > readScores (Scores const & scores)
222+ {
246223 if (scores.size () != NMlClasses) {
247- LOGP (fatal,
248- " Expected three selector ML scores: background, prompt, nonprompt" );
224+ LOGP (fatal, " Expected three selector ML scores: background, prompt, nonprompt" );
249225 return {-1 .f , -1 .f , -1 .f };
250226 }
251227 for (const auto & score : scores) {
@@ -257,9 +233,9 @@ struct HfProducerCharmHadronsCharmFemtoDream {
257233 }
258234
259235 template <bool WithMl, typename Collision, typename Candidates>
260- void fillD0 (Collision const &col, Candidates const &candidates) {
261- const auto timestamp =
262- col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
236+ void fillD0 (Collision const & col, Candidates const & candidates)
237+ {
238+ const auto timestamp = col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
263239 for (const auto & cand : candidates) {
264240 auto p0 = cand.template prong0_as <aod::Tracks>();
265241 auto p1 = cand.template prong1_as <aod::Tracks>();
@@ -278,15 +254,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
278254 }
279255 if (mlD0.applyMlMode == FillMlFromNewBDT) {
280256 // Do not call the ML response with an out-of-range model index.
281- if (!std::isfinite (cand.pt ()) ||
282- cand.pt () < mlD0.binsPtMl .value .front () ||
283- cand.pt () >= mlD0.binsPtMl .value .back ()) {
257+ if (!std::isfinite (cand.pt ()) || cand.pt () < mlD0.binsPtMl .value .front () || cand.pt () >= mlD0.binsPtMl .value .back ()) {
284258 continue ;
285259 }
286- const int pdgCode = hypothesis == 0 ? o2::constants::physics::kD0
287- : -o2::constants::physics::kD0 ;
288- auto features =
289- hfMlResponseD0.getInputFeatures <true >(cand, pdgCode);
260+ const int pdgCode = hypothesis == 0 ? o2::constants::physics::kD0 : -o2::constants::physics::kD0 ;
261+ auto features = hfMlResponseD0.getInputFeatures <true >(cand, pdgCode);
290262 std::vector<float > output;
291263 if (!hfMlResponseD0.isSelectedMl (features, cand.pt (), output)) {
292264 continue ; // Reject this hypothesis only.
@@ -305,9 +277,9 @@ struct HfProducerCharmHadronsCharmFemtoDream {
305277 }
306278
307279 template <bool WithMl, typename Collision, typename Candidates>
308- void fillDstar (Collision const &col, Candidates const &candidates) {
309- const auto timestamp =
310- col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
280+ void fillDstar (Collision const & col, Candidates const & candidates)
281+ {
282+ const auto timestamp = col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
311283 for (const auto & cand : candidates) {
312284 auto p0 = cand.template prong0_as <aod::Tracks>();
313285 auto p1 = cand.template prong1_as <aod::Tracks>();
@@ -318,9 +290,7 @@ struct HfProducerCharmHadronsCharmFemtoDream {
318290 scores = readScores (cand.mlProbDstarToD0Pi ());
319291 }
320292 if (mlDstar.applyMlMode == FillMlFromNewBDT) {
321- if (!std::isfinite (cand.pt ()) ||
322- cand.pt () < mlDstar.binsPtMl .value .front () ||
323- cand.pt () >= mlDstar.binsPtMl .value .back ()) {
293+ if (!std::isfinite (cand.pt ()) || cand.pt () < mlDstar.binsPtMl .value .front () || cand.pt () >= mlDstar.binsPtMl .value .back ()) {
324294 continue ;
325295 }
326296 // Match the unswapped daughter convention used by D+track.
@@ -341,20 +311,22 @@ struct HfProducerCharmHadronsCharmFemtoDream {
341311 }
342312 }
343313
344- void processD0D0 (Collisions::iterator const &col,
314+ void processD0D0 (Collisions::iterator const & col,
345315 aod::BCsWithTimestamps const &, aod::Tracks const &,
346- soa::Filtered<D0s> const &d0s) {
316+ soa::Filtered<D0s> const & d0s)
317+ {
347318 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
348319 fillD0<false >(col, d0s);
349320 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
350321 }
351322 }
352323 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0, " D0 only, data" , true );
353324
354- void processD0Dstar (Collisions::iterator const &col,
325+ void processD0Dstar (Collisions::iterator const & col,
355326 aod::BCsWithTimestamps const &, aod::Tracks const &,
356- soa::Filtered<D0s> const &d0s,
357- soa::Filtered<Dstars> const &dstars) {
327+ soa::Filtered<D0s> const & d0s,
328+ soa::Filtered<Dstars> const & dstars)
329+ {
358330 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
359331 fillD0<false >(col, d0s);
360332 fillDstar<false >(col, dstars);
@@ -363,20 +335,22 @@ struct HfProducerCharmHadronsCharmFemtoDream {
363335 }
364336 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0Dstar, " D0 and Dstar, data" , false );
365337
366- void processD0D0Ml (Collisions::iterator const &col,
338+ void processD0D0Ml (Collisions::iterator const & col,
367339 aod::BCsWithTimestamps const &, aod::Tracks const &,
368- soa::Filtered<D0sMl> const &d0s) {
340+ soa::Filtered<D0sMl> const & d0s)
341+ {
369342 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
370343 fillD0<true >(col, d0s);
371344 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
372345 }
373346 }
374347 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0Ml, " D0 with selector ML scores" , false );
375348
376- void processD0DstarMl (Collisions::iterator const &col,
349+ void processD0DstarMl (Collisions::iterator const & col,
377350 aod::BCsWithTimestamps const &, aod::Tracks const &,
378- soa::Filtered<D0sMl> const &d0s,
379- soa::Filtered<DstarsMl> const &dstars) {
351+ soa::Filtered<D0sMl> const & d0s,
352+ soa::Filtered<DstarsMl> const & dstars)
353+ {
380354 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
381355 fillD0<true >(col, d0s);
382356 fillDstar<true >(col, dstars);
@@ -385,21 +359,23 @@ struct HfProducerCharmHadronsCharmFemtoDream {
385359 }
386360 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0DstarMl, " D0 and Dstar with selector ML scores" , false );
387361
388- void processD0D0WithFT0C (CollisionsWithFT0C::iterator const &col,
362+ void processD0D0WithFT0C (CollisionsWithFT0C::iterator const & col,
389363 aod::BCsWithTimestamps const &, aod::Tracks const &,
390- soa::Filtered<D0s> const &d0s) {
364+ soa::Filtered<D0s> const & d0s)
365+ {
391366 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
392367 fillD0<false >(col, d0s);
393368 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
394369 }
395370 }
396371 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0WithFT0C, " D0 only, data with FT0C centrality" , false );
397372
398- void processD0DstarWithFT0C (CollisionsWithFT0C::iterator const &col,
373+ void processD0DstarWithFT0C (CollisionsWithFT0C::iterator const & col,
399374 aod::BCsWithTimestamps const &,
400375 aod::Tracks const &,
401- soa::Filtered<D0s> const &d0s,
402- soa::Filtered<Dstars> const &dstars) {
376+ soa::Filtered<D0s> const & d0s,
377+ soa::Filtered<Dstars> const & dstars)
378+ {
403379 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
404380 fillD0<false >(col, d0s);
405381 fillDstar<false >(col, dstars);
@@ -408,22 +384,24 @@ struct HfProducerCharmHadronsCharmFemtoDream {
408384 }
409385 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0DstarWithFT0C, " D0 and Dstar, data with FT0C centrality" , false );
410386
411- void processD0D0MlWithFT0C (CollisionsWithFT0C::iterator const &col,
387+ void processD0D0MlWithFT0C (CollisionsWithFT0C::iterator const & col,
412388 aod::BCsWithTimestamps const &,
413389 aod::Tracks const &,
414- soa::Filtered<D0sMl> const &d0s) {
390+ soa::Filtered<D0sMl> const & d0s)
391+ {
415392 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
416393 fillD0<true >(col, d0s);
417394 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
418395 }
419396 }
420397 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0MlWithFT0C, " D0 with selector ML scores and FT0C centrality" , false );
421398
422- void processD0DstarMlWithFT0C (CollisionsWithFT0C::iterator const &col,
399+ void processD0DstarMlWithFT0C (CollisionsWithFT0C::iterator const & col,
423400 aod::BCsWithTimestamps const &,
424401 aod::Tracks const &,
425- soa::Filtered<D0sMl> const &d0s,
426- soa::Filtered<DstarsMl> const &dstars) {
402+ soa::Filtered<D0sMl> const & d0s,
403+ soa::Filtered<DstarsMl> const & dstars)
404+ {
427405 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
428406 fillD0<true >(col, d0s);
429407 fillDstar<true >(col, dstars);
@@ -433,7 +411,8 @@ struct HfProducerCharmHadronsCharmFemtoDream {
433411 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0DstarMlWithFT0C, " D0 and Dstar with selector ML scores and FT0C centrality" , false );
434412};
435413
436- WorkflowSpec defineDataProcessing (ConfigContext const &cfgc) {
414+ WorkflowSpec defineDataProcessing (ConfigContext const & cfgc)
415+ {
437416 return WorkflowSpec{
438- adaptAnalysisTask<HfProducerCharmHadronsCharmFemtoDream>(cfgc)};
417+ adaptAnalysisTask<HfProducerCharmHadronsCharmFemtoDream>(cfgc)};
439418}
0 commit comments