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>
@@ -67,40 +67,40 @@ struct HfProducerCharmHadronsCharmFemtoDream {
6767 Configurable<std::string> ccdbUrl{" ccdbUrl" , " http://alice-ccdb.cern.ch" ,
6868 " CCDB URL" };
6969 Configurable<std::string> ccdbPathGrpMag{
70- " ccdbPathGrpMag" , " GLO/Config/GRPMagField" , " Run 3 magnetic field" };
70+ " ccdbPathGrpMag" , " GLO/Config/GRPMagField" , " Run 3 magnetic field" };
7171
7272 // Each species needs its own model, feature order and pT-dependent cuts.
7373 struct MlConfig : ConfigurableGroup {
7474 std::string prefix;
7575 static inline const std::array<double , 3 > DefaultCuts{1 ., 0 ., 0 .};
7676 Configurable<int > applyMlMode{
77- " applyMlMode" , FillMlFromSelector,
78- " 0: no ML, 1: selector scores, 2: new BDT after selector" };
77+ " applyMlMode" , FillMlFromSelector,
78+ " 0: no ML, 1: selector scores, 2: new BDT after selector" };
7979 Configurable<std::vector<double >> binsPtMl{
80- " binsPtMl" , std::vector<double >{0 ., 36 .}, " pT bin limits for new BDT" };
80+ " binsPtMl" , std::vector<double >{0 ., 36 .}, " pT bin limits for new BDT" };
8181 Configurable<LabeledArray<double >> cutsMl{
82- " cutsMl" ,
83- {DefaultCuts.data (), 1 , 3 },
84- " New BDT cuts per pT bin: background, prompt, nonprompt" };
82+ " cutsMl" ,
83+ {DefaultCuts.data (), 1 , 3 },
84+ " New BDT cuts per pT bin: background, prompt, nonprompt" };
8585 Configurable<std::vector<int >> cutDirMl{
86- " cutDirMl" , std::vector<int >{0 , 1 , 1 },
87- " Reject scores above (0), below (1), or do not cut (2)" };
86+ " cutDirMl" , std::vector<int >{0 , 1 , 1 },
87+ " Reject scores above (0), below (1), or do not cut (2)" };
8888 Configurable<int > nClassesMl{
89- " nClassesMl" , 3 , " Three output classes: background, prompt, nonprompt" };
89+ " nClassesMl" , 3 , " Three output classes: background, prompt, nonprompt" };
9090 Configurable<std::vector<std::string>> namesInputFeatures{
91- " namesInputFeatures" , std::vector<std::string>{},
92- " Ordered input feature names for new BDT" };
91+ " namesInputFeatures" , std::vector<std::string>{},
92+ " Ordered input feature names for new BDT" };
9393 Configurable<std::vector<std::string>> onnxFileNames{
94- " onnxFileNames" , std::vector<std::string>{},
95- " Model files, one per pT bin" };
94+ " onnxFileNames" , std::vector<std::string>{},
95+ " Model files, one per pT bin" };
9696 Configurable<std::vector<std::string>> modelPathsCCDB{
97- " modelPathsCCDB" , std::vector<std::string>{},
98- " CCDB model paths, one per pT bin" };
97+ " modelPathsCCDB" , std::vector<std::string>{},
98+ " CCDB model paths, one per pT bin" };
9999 Configurable<int64_t > timestampCCDB{" timestampCCDB" , -1 ,
100100 " Timestamp used to retrieve models" };
101101 Configurable<bool > loadModelsFromCCDB{
102- " loadModelsFromCCDB" , false ,
103- " Load new BDT from CCDB instead of local files" };
102+ " loadModelsFromCCDB" , false ,
103+ " Load new BDT from CCDB instead of local files" };
104104 } mlD0{.prefix = " mlD0" }, mlDstar{.prefix = " mlDstar" };
105105 Produces<aod::FDCollisions> collisions;
106106 Produces<aod::FDColMasks> rowMasks;
@@ -122,20 +122,21 @@ struct HfProducerCharmHadronsCharmFemtoDream {
122122 using CollisionsWithFT0C = soa::Join<Collisions, aod::CentFT0Cs>;
123123 using D0s = soa::Join<aod::HfCand2Prong, aod::HfSelD0>;
124124 using Dstars =
125- soa::Join<aod::HfCandDstars, aod::HfD0FromDstar, aod::HfSelDstarToD0Pi>;
125+ soa::Join<aod::HfCandDstars, aod::HfD0FromDstar, aod::HfSelDstarToD0Pi>;
126126
127127 using D0sMl = soa::Join<aod::HfCand2ProngWPid, aod::HfSelD0, aod::HfMlD0>;
128128 using DstarsMl = soa::Join<aod::HfCandDstarsWPid, aod::HfD0FromDstar,
129129 aod::HfSelDstarToD0Pi, aod::HfMlDstarToD0Pi>;
130130
131131 Filter filterSelectCandidateD0 =
132- (aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 ||
133- aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0);
132+ (aod::hf_sel_candidate_d0::isSelD0 >= selectionFlagD0 ||
133+ aod::hf_sel_candidate_d0::isSelD0bar >= selectionFlagD0);
134134 Filter filterSelectCandidateDstar =
135- aod::hf_sel_candidate_dstar::isSelDstarToD0Pi == true ;
135+ aod::hf_sel_candidate_dstar::isSelDstarToD0Pi == true ;
136136
137137 template <typename Response>
138- void initMl (MlConfig const &cfg, Response &response, bool withMl) {
138+ void initMl (MlConfig const & cfg, Response& response, bool withMl)
139+ {
139140 if (cfg.applyMlMode .value < NoMl ||
140141 cfg.applyMlMode .value > FillMlFromNewBDT) {
141142 LOGP (fatal, " {}: invalid applyMlMode" , cfg.prefix );
@@ -146,7 +147,7 @@ struct HfProducerCharmHadronsCharmFemtoDream {
146147 if (!withMl) {
147148 LOGP (fatal, " {}: new BDT requires an Ml producer process" , cfg.prefix );
148149 }
149- auto const & edges = cfg.binsPtMl .value ;
150+ auto const & edges = cfg.binsPtMl .value ;
150151 if (edges.size () < 2 ||
151152 !std::all_of (edges.begin (), edges.end (),
152153 [](double x) { return std::isfinite (x); }) ||
@@ -195,16 +196,17 @@ struct HfProducerCharmHadronsCharmFemtoDream {
195196 response.init ();
196197 }
197198
198- void init (InitContext const &) {
199+ void init (InitContext const &)
200+ {
199201 const std::array<bool , 8 > processSwitches{
200- static_cast <bool >(doprocessD0D0),
201- static_cast <bool >(doprocessD0Dstar),
202- static_cast <bool >(doprocessD0D0Ml),
203- static_cast <bool >(doprocessD0DstarMl),
204- static_cast <bool >(doprocessD0D0WithFT0C),
205- static_cast <bool >(doprocessD0DstarWithFT0C),
206- static_cast <bool >(doprocessD0D0MlWithFT0C),
207- static_cast <bool >(doprocessD0DstarMlWithFT0C)};
202+ static_cast <bool >(doprocessD0D0),
203+ static_cast <bool >(doprocessD0Dstar),
204+ static_cast <bool >(doprocessD0D0Ml),
205+ static_cast <bool >(doprocessD0DstarMl),
206+ static_cast <bool >(doprocessD0D0WithFT0C),
207+ static_cast <bool >(doprocessD0DstarWithFT0C),
208+ static_cast <bool >(doprocessD0D0MlWithFT0C),
209+ static_cast <bool >(doprocessD0DstarMlWithFT0C)};
208210 if (std::count (processSwitches.begin (), processSwitches.end (), true ) != 1 ) {
209211 LOGP (fatal, " Enable exactly one charm-charm producer process" );
210212 }
@@ -230,11 +232,12 @@ struct HfProducerCharmHadronsCharmFemtoDream {
230232
231233 template <o2::hf_centrality::CentralityEstimator CentEstimator,
232234 typename Collision>
233- bool acceptCollision (Collision const &col) {
235+ bool acceptCollision (Collision const & col)
236+ {
234237 registry.fill (HIST (" events" ), 0 );
235238 float cent = -1 .f ; // No centrality for pp MB.
236239 const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask <
237- true , CentEstimator, aod::BCsWithTimestamps>(col, cent, ccdb, registry);
240+ true , CentEstimator, aod::BCsWithTimestamps>(col, cent, ccdb, registry);
238241 hfEvSel.fillHistograms (col, rejectionMask, cent);
239242 if (rejectionMask != 0 ) {
240243 return false ;
@@ -245,7 +248,7 @@ struct HfProducerCharmHadronsCharmFemtoDream {
245248 initCCDB (bc, runNumber, ccdb, ccdbPathGrpMag.value , nullptr , false );
246249 // Propagator field is in kG; FemtoDream uses Tesla.
247250 const float fieldTesla =
248- 0 .1f * o2::base::Propagator::Instance ()->getNominalBz ();
251+ 0 .1f * o2::base::Propagator::Instance ()->getNominalBz ();
249252 // MultV0M is the common reduced percentile column: FT0C or -1 (no
250253 // estimator).
251254 collisions (col.posZ (), cent, col.multNTracksPV (), 2 .f , fieldTesla);
@@ -255,7 +258,8 @@ struct HfProducerCharmHadronsCharmFemtoDream {
255258 }
256259
257260 template <typename Scores>
258- std::array<float , 3 > readScores (Scores const &scores) {
261+ std::array<float , 3 > readScores (Scores const & scores)
262+ {
259263 if (scores.size () != 3 ) {
260264 LOGP (fatal,
261265 " Expected three selector ML scores: background, prompt, nonprompt" );
@@ -270,10 +274,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
270274 }
271275
272276 template <bool WithMl, typename Collision, typename Candidates>
273- void fillD0 (Collision const &col, Candidates const &candidates) {
277+ void fillD0 (Collision const & col, Candidates const & candidates)
278+ {
274279 const auto timestamp =
275- col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
276- for (auto const & cand : candidates) {
280+ col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
281+ for (auto const & cand : candidates) {
277282 auto p0 = cand.template prong0_as <aod::Tracks>();
278283 auto p1 = cand.template prong1_as <aod::Tracks>();
279284 // The OR filter accepts the row if either hypothesis passes. Write only
@@ -299,7 +304,7 @@ struct HfProducerCharmHadronsCharmFemtoDream {
299304 const int pdgCode = hypothesis == 0 ? o2::constants::physics::kD0
300305 : -o2::constants::physics::kD0 ;
301306 auto features =
302- hfMlResponseD0.getInputFeatures <true >(cand, pdgCode);
307+ hfMlResponseD0.getInputFeatures <true >(cand, pdgCode);
303308 std::vector<float > output;
304309 if (!hfMlResponseD0.isSelectedMl (features, cand.pt (), output)) {
305310 continue ; // Reject this hypothesis only.
@@ -318,10 +323,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
318323 }
319324
320325 template <bool WithMl, typename Collision, typename Candidates>
321- void fillDstar (Collision const &col, Candidates const &candidates) {
326+ void fillDstar (Collision const & col, Candidates const & candidates)
327+ {
322328 const auto timestamp =
323- col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
324- for (auto const & cand : candidates) {
329+ col.template bc_as <aod::BCsWithTimestamps>().timestamp ();
330+ for (auto const & cand : candidates) {
325331 auto p0 = cand.template prong0_as <aod::Tracks>();
326332 auto p1 = cand.template prong1_as <aod::Tracks>();
327333 auto soft = cand.template prongPi_as <aod::Tracks>();
@@ -354,9 +360,10 @@ struct HfProducerCharmHadronsCharmFemtoDream {
354360 }
355361 }
356362
357- void processD0D0 (Collisions::iterator const &col,
358- aod::BCsWithTimestamps const &, aod::Tracks const &,
359- soa::Filtered<D0s> const &d0s) {
363+ void processD0D0 (Collisions::iterator const & col,
364+ aod::BCsWithTimestamps const &, aod::Tracks const &,
365+ soa::Filtered<D0s> const & d0s)
366+ {
360367 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
361368 fillD0<false >(col, d0s);
362369 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
@@ -365,10 +372,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
365372 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0,
366373 " D0 only, data" , true );
367374
368- void processD0Dstar (Collisions::iterator const &col,
369- aod::BCsWithTimestamps const &, aod::Tracks const &,
370- soa::Filtered<D0s> const &d0s,
371- soa::Filtered<Dstars> const &dstars) {
375+ void processD0Dstar (Collisions::iterator const & col,
376+ aod::BCsWithTimestamps const &, aod::Tracks const &,
377+ soa::Filtered<D0s> const & d0s,
378+ soa::Filtered<Dstars> const & dstars)
379+ {
372380 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
373381 fillD0<false >(col, d0s);
374382 fillDstar<false >(col, dstars);
@@ -378,9 +386,10 @@ struct HfProducerCharmHadronsCharmFemtoDream {
378386 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0Dstar,
379387 " D0 and Dstar, data" , false );
380388
381- void processD0D0Ml (Collisions::iterator const &col,
382- aod::BCsWithTimestamps const &, aod::Tracks const &,
383- soa::Filtered<D0sMl> const &d0s) {
389+ void processD0D0Ml (Collisions::iterator const & col,
390+ aod::BCsWithTimestamps const &, aod::Tracks const &,
391+ soa::Filtered<D0sMl> const & d0s)
392+ {
384393 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
385394 fillD0<true >(col, d0s);
386395 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
@@ -389,10 +398,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
389398 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0Ml,
390399 " D0 with selector ML scores" , false );
391400
392- void processD0DstarMl (Collisions::iterator const &col,
393- aod::BCsWithTimestamps const &, aod::Tracks const &,
394- soa::Filtered<D0sMl> const &d0s,
395- soa::Filtered<DstarsMl> const &dstars) {
401+ void processD0DstarMl (Collisions::iterator const & col,
402+ aod::BCsWithTimestamps const &, aod::Tracks const &,
403+ soa::Filtered<D0sMl> const & d0s,
404+ soa::Filtered<DstarsMl> const & dstars)
405+ {
396406 if (acceptCollision<o2::hf_centrality::CentralityEstimator::None>(col)) {
397407 fillD0<true >(col, d0s);
398408 fillDstar<true >(col, dstars);
@@ -402,9 +412,10 @@ struct HfProducerCharmHadronsCharmFemtoDream {
402412 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0DstarMl,
403413 " D0 and Dstar with selector ML scores" , false );
404414
405- void processD0D0WithFT0C (CollisionsWithFT0C::iterator const &col,
406- aod::BCsWithTimestamps const &, aod::Tracks const &,
407- soa::Filtered<D0s> const &d0s) {
415+ void processD0D0WithFT0C (CollisionsWithFT0C::iterator const & col,
416+ aod::BCsWithTimestamps const &, aod::Tracks const &,
417+ soa::Filtered<D0s> const & d0s)
418+ {
408419 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
409420 fillD0<false >(col, d0s);
410421 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
@@ -413,11 +424,12 @@ struct HfProducerCharmHadronsCharmFemtoDream {
413424 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0WithFT0C,
414425 " D0 only, data with FT0C centrality" , false );
415426
416- void processD0DstarWithFT0C (CollisionsWithFT0C::iterator const &col,
417- aod::BCsWithTimestamps const &,
418- aod::Tracks const &,
419- soa::Filtered<D0s> const &d0s,
420- soa::Filtered<Dstars> const &dstars) {
427+ void processD0DstarWithFT0C (CollisionsWithFT0C::iterator const & col,
428+ aod::BCsWithTimestamps const &,
429+ aod::Tracks const &,
430+ soa::Filtered<D0s> const & d0s,
431+ soa::Filtered<Dstars> const & dstars)
432+ {
421433 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
422434 fillD0<false >(col, d0s);
423435 fillDstar<false >(col, dstars);
@@ -427,10 +439,11 @@ struct HfProducerCharmHadronsCharmFemtoDream {
427439 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0DstarWithFT0C,
428440 " D0 and Dstar, data with FT0C centrality" , false );
429441
430- void processD0D0MlWithFT0C (CollisionsWithFT0C::iterator const &col,
431- aod::BCsWithTimestamps const &,
432- aod::Tracks const &,
433- soa::Filtered<D0sMl> const &d0s) {
442+ void processD0D0MlWithFT0C (CollisionsWithFT0C::iterator const & col,
443+ aod::BCsWithTimestamps const &,
444+ aod::Tracks const &,
445+ soa::Filtered<D0sMl> const & d0s)
446+ {
434447 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
435448 fillD0<true >(col, d0s);
436449 rowMasks (hasD0 ? 1 : 0 , hasDstar ? 1 : 0 , 0 );
@@ -439,11 +452,12 @@ struct HfProducerCharmHadronsCharmFemtoDream {
439452 PROCESS_SWITCH (HfProducerCharmHadronsCharmFemtoDream, processD0D0MlWithFT0C,
440453 " D0 with selector ML scores and FT0C centrality" , false );
441454
442- void processD0DstarMlWithFT0C (CollisionsWithFT0C::iterator const &col,
443- aod::BCsWithTimestamps const &,
444- aod::Tracks const &,
445- soa::Filtered<D0sMl> const &d0s,
446- soa::Filtered<DstarsMl> const &dstars) {
455+ void processD0DstarMlWithFT0C (CollisionsWithFT0C::iterator const & col,
456+ aod::BCsWithTimestamps const &,
457+ aod::Tracks const &,
458+ soa::Filtered<D0sMl> const & d0s,
459+ soa::Filtered<DstarsMl> const & dstars)
460+ {
447461 if (acceptCollision<o2::hf_centrality::CentralityEstimator::FT0C >(col)) {
448462 fillD0<true >(col, d0s);
449463 fillDstar<true >(col, dstars);
@@ -456,7 +470,8 @@ struct HfProducerCharmHadronsCharmFemtoDream {
456470 false );
457471};
458472
459- WorkflowSpec defineDataProcessing (ConfigContext const &cfgc) {
473+ WorkflowSpec defineDataProcessing (ConfigContext const & cfgc)
474+ {
460475 return WorkflowSpec{
461- adaptAnalysisTask<HfProducerCharmHadronsCharmFemtoDream>(cfgc)};
476+ adaptAnalysisTask<HfProducerCharmHadronsCharmFemtoDream>(cfgc)};
462477}
0 commit comments