1717// / \author Marcello Di Costanzo <marcello.di.costanzo@cern.ch>, Politecnico and INFN Torino
1818// / \author Luca Aglietta <luca.aglietta@unito.it>, Università and INFN Torino
1919
20+ #include < string>
21+
2022#include " TPDGCode.h"
2123
24+ #include " CCDB/BasicCCDBManager.h"
2225#include " Framework/AnalysisTask.h"
2326#include " Framework/runDataProcessing.h"
27+ #include " Framework/HistogramRegistry.h"
2428
2529#include " Common/DataModel/PIDResponse.h"
2630#include " Common/DataModel/Centrality.h"
2933#include " Common/DataModel/TrackSelectionTables.h"
3034#include " PWGLF/DataModel/LFStrangenessTables.h"
3135#include " PWGLF/DataModel/LFStrangenessPIDTables.h"
36+ #include " PWGHF/Utils/utilsEvSelHf.h"
37+ #include " PWGHF/Core/CentralityEstimation.h"
3238
3339using namespace o2 ;
3440using namespace o2 ::framework;
3541using namespace o2 ::framework::expressions;
42+ using namespace o2 ::hf_evsel;
43+ using namespace o2 ::hf_centrality;
3644
3745namespace o2 ::aod
3846{
@@ -83,6 +91,12 @@ DECLARE_SOA_COLUMN(OccupancyIts, occupancyIts, float); //! Occupancy from IT
8391DECLARE_SOA_COLUMN (CentralityFT0C, centralityFT0C, float ); // ! Centrality from FT0C
8492DECLARE_SOA_COLUMN (CentralityFT0M, centralityFT0M, float ); // ! Centrality from FT0M
8593DECLARE_SOA_COLUMN (CandFlag, candFlag, int ); // ! Flag for MC matching
94+
95+ const int minTpcNClsCrossedRows = 70 ; // Minimum number of crossed rows in TPC
96+ const float maxEta = 0.8 ; // Maximum pseudorapidity
97+ const float minPt = 0.1 ; // Minimum transverse momentum
98+ const float maxTpcChi2NCl = 4 ; // Maximum TPC chi2 per number of TPC clusters
99+ const float maxItsChi2NCl = 36 ; // Maximum ITS chi2 per number of ITS clusters
86100} // namespace pid_studies
87101
88102DECLARE_SOA_TABLE (PidV0s, " AOD" , " PIDV0S" , // ! Table with PID information
@@ -139,6 +153,8 @@ struct HfTaskPidStudies {
139153 Produces<o2::aod::PidV0s> pidV0;
140154 Produces<o2::aod::PidCascades> pidCascade;
141155
156+ Configurable<bool > applyEvSels{" applyEvSels" , true , " Apply event selections" };
157+ Configurable<bool > applyTrackSels{" applyTrackSels" , true , " Apply track selections" };
142158 Configurable<float > massK0Min{" massK0Min" , 0.4 , " Minimum mass for K0" };
143159 Configurable<float > massK0Max{" massK0Max" , 0.6 , " Maximum mass for K0" };
144160 Configurable<float > massLambdaMin{" massLambdaMin" , 1.0 , " Minimum mass for lambda" };
@@ -154,30 +170,42 @@ struct HfTaskPidStudies {
154170 Configurable<float > qtArmenterosMaxForLambda{" qtArmenterosMaxForLambda" , 0.12 , " Minimum Armenteros' qt for (anti)Lambda" };
155171 Configurable<float > downSampleBkgFactor{" downSampleBkgFactor" , 1 ., " Fraction of candidates to keep" };
156172 Configurable<float > ptMaxForDownSample{" ptMaxForDownSample" , 10 ., " Maximum pt for the application of the downsampling factor" };
173+ Configurable<std::string> ccdbUrl{" ccdbUrl" , " http://alice-ccdb.cern.ch" , " url of the ccdb repository" };
157174
158175 using PidTracks = soa::Join<aod::Tracks, aod::TracksExtra,
159176 aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr,
160177 aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr>;
161178 using CollSels = soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs, aod::CentFT0Ms>;
179+ using CollisionsMc = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::EvSels, aod::CentFT0Cs, aod::CentFT0Ms>;
162180 using V0sMcRec = soa::Join<aod::V0Datas, aod::V0CoreMCLabels>;
163181 using CascsMcRec = soa::Join<aod::CascDatas, aod::CascCoreMCLabels>;
164182
183+ HfEventSelection hfEvSel;
184+ HfEventSelectionMc hfEvSelMc;
185+
186+ o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb;
187+ HistogramRegistry registry{" registry" , {}};
188+
165189 void init (InitContext&)
166190 {
167191 if ((doprocessV0Mc && doprocessV0Data) || (doprocessCascMc && doprocessCascData)) {
168192 LOGP (fatal, " Both data and MC process functions were enabled! Please check your configuration!" );
169193 }
194+ ccdb->setURL (ccdbUrl);
195+ ccdb->setCaching (true );
196+ ccdb->setLocalObjectValidityChecking ();
197+ hfEvSel.addHistograms (registry);
170198 }
171199
172- template <bool isV0, typename Cand>
200+ template <bool isV0, typename Coll, typename Cand>
173201 void fillTree (Cand const & candidate, const int flag)
174202 {
175203 float pseudoRndm = candidate.pt () * 1000 . - static_cast <int64_t >(candidate.pt () * 1000 );
176204 if (candidate.pt () < ptMaxForDownSample && pseudoRndm > downSampleBkgFactor) {
177205 return ;
178206 }
179207
180- const auto & coll = candidate.template collision_as <CollSels >();
208+ const auto & coll = candidate.template collision_as <Coll >();
181209 if constexpr (isV0) {
182210 const auto & posTrack = candidate.template posTrack_as <PidTracks>();
183211 const auto & negTrack = candidate.template negTrack_as <PidTracks>();
@@ -274,6 +302,57 @@ struct HfTaskPidStudies {
274302 return aod::pid_studies::Particle::NotMatched;
275303 }
276304
305+ template <typename Coll>
306+ bool isCollSelected (const Coll& coll)
307+ {
308+ float cent{-1 .f };
309+ const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask <true , o2::hf_centrality::CentralityEstimator::None, aod::BCsWithTimestamps>(coll, cent, ccdb, registry);
310+ // / monitor the satisfied event selections
311+ hfEvSel.fillHistograms (coll, rejectionMask, cent);
312+ return rejectionMask == 0 ;
313+ }
314+
315+ template <bool isV0, typename T1>
316+ bool isTrackSelected (const T1& candidate)
317+ {
318+ const auto & posTrack = candidate.template posTrack_as <PidTracks>();
319+ const auto & negTrack = candidate.template negTrack_as <PidTracks>();
320+ if (posTrack.tpcNClsCrossedRows () < o2::aod::pid_studies::minTpcNClsCrossedRows || negTrack.tpcNClsCrossedRows () < o2::aod::pid_studies::minTpcNClsCrossedRows) {
321+ return false ;
322+ }
323+ if (std::abs (posTrack.eta ()) > o2::aod::pid_studies::maxEta || std::abs (negTrack.eta ()) > o2::aod::pid_studies::maxEta) {
324+ return false ;
325+ }
326+ if (posTrack.pt () < o2::aod::pid_studies::minPt || negTrack.pt () < o2::aod::pid_studies::minPt) {
327+ return false ;
328+ }
329+ if (posTrack.tpcChi2NCl () > o2::aod::pid_studies::maxTpcChi2NCl || negTrack.tpcChi2NCl () > o2::aod::pid_studies::maxTpcChi2NCl) {
330+ return false ;
331+ }
332+ if (posTrack.itsChi2NCl () > o2::aod::pid_studies::maxItsChi2NCl || negTrack.itsChi2NCl () > o2::aod::pid_studies::maxItsChi2NCl) {
333+ return false ;
334+ }
335+ if constexpr (!isV0) {
336+ const auto & bachTrack = candidate.template bachelor_as <PidTracks>();
337+ if (bachTrack.tpcNClsCrossedRows () < o2::aod::pid_studies::minTpcNClsCrossedRows) {
338+ return false ;
339+ }
340+ if (std::abs (bachTrack.eta ()) > o2::aod::pid_studies::maxEta) {
341+ return false ;
342+ }
343+ if (bachTrack.pt () < o2::aod::pid_studies::minPt) {
344+ return false ;
345+ }
346+ if (bachTrack.tpcChi2NCl () > o2::aod::pid_studies::maxTpcChi2NCl) {
347+ return false ;
348+ }
349+ if (bachTrack.itsChi2NCl () > o2::aod::pid_studies::maxItsChi2NCl) {
350+ return false ;
351+ }
352+ }
353+ return true ;
354+ }
355+
277356 template <typename V0Cand>
278357 bool isSelectedV0AsK0s (const V0Cand& v0)
279358 {
@@ -323,7 +402,7 @@ struct HfTaskPidStudies {
323402 return true ;
324403 }
325404
326- template <typename CascCand>
405+ template <typename Coll, typename CascCand>
327406 bool isSelectedCascAsOmega (const CascCand& casc)
328407 {
329408 if (casc.mOmega () < massOmegaMin || casc.mOmega () > massOmegaMax) {
@@ -335,7 +414,7 @@ struct HfTaskPidStudies {
335414 if (casc.cascradius () > radiusMax) {
336415 return false ;
337416 }
338- const auto & coll = casc.template collision_as <CollSels >();
417+ const auto & coll = casc.template collision_as <Coll >();
339418 if (casc.casccosPA (coll.posX (), coll.posY (), coll.posZ ()) < cosPaMin) {
340419 return false ;
341420 }
@@ -351,57 +430,87 @@ struct HfTaskPidStudies {
351430 return true ;
352431 }
353432
354- void processV0Mc (V0sMcRec const & V0s,
433+ void processV0Mc (CollisionsMc const & /* mcCollisions*/ ,
434+ V0sMcRec const & V0s,
355435 aod::V0MCCores const &,
356- CollSels const &,
357- PidTracks const &)
436+ aod::McParticles const & /* particlesMc*/ ,
437+ PidTracks const & /* tracks*/ ,
438+ aod::BCsWithTimestamps const &)
358439 {
359440 for (const auto & v0 : V0s) {
441+ if (applyEvSels && !isCollSelected (v0.collision_as <CollisionsMc>())) {
442+ return ;
443+ }
444+ if (applyTrackSels && !isTrackSelected<true >(v0)) {
445+ return ;
446+ }
360447 if (isSelectedV0AsK0s (v0) || isSelectedV0AsLambda (v0)) {
361448 int matched = isMatched (v0);
362449 if (matched != aod::pid_studies::Particle::NotMatched) {
363- fillTree<true >(v0, matched);
450+ fillTree<true , CollisionsMc >(v0, matched);
364451 }
365452 }
366453 }
367454 }
368455 PROCESS_SWITCH (HfTaskPidStudies, processV0Mc, " Process MC" , true );
369456
370457 void processV0Data (aod::V0Datas const & V0s,
371- CollSels const &,
372- PidTracks const &)
458+ PidTracks const &,
459+ aod::BCsWithTimestamps const &,
460+ CollSels const &)
373461 {
374462 for (const auto & v0 : V0s) {
463+ if (applyEvSels && !isCollSelected (v0.collision_as <CollSels>())) {
464+ return ;
465+ }
466+ if (applyTrackSels && !isTrackSelected<true >(v0)) {
467+ return ;
468+ }
375469 if (isSelectedV0AsK0s (v0) || isSelectedV0AsLambda (v0)) {
376- fillTree<true >(v0, aod::pid_studies::Particle::NotMatched);
470+ fillTree<true , CollSels >(v0, aod::pid_studies::Particle::NotMatched);
377471 }
378472 }
379473 }
380474 PROCESS_SWITCH (HfTaskPidStudies, processV0Data, " Process data" , false );
381475
382- void processCascMc (CascsMcRec const & cascades,
476+ void processCascMc (CollisionsMc const & /* mcCollisions*/ ,
477+ CascsMcRec const & cascades,
383478 aod::CascMCCores const &,
384- CollSels const &,
385- PidTracks const &)
479+ aod::McParticles const & /* particlesMc*/ ,
480+ PidTracks const &,
481+ aod::BCsWithTimestamps const &)
386482 {
387483 for (const auto & casc : cascades) {
388- if (isSelectedCascAsOmega (casc)) {
484+ if (applyEvSels && !isCollSelected (casc.collision_as <CollisionsMc>())) {
485+ return ;
486+ }
487+ if (applyTrackSels && !isTrackSelected<false >(casc)) {
488+ return ;
489+ }
490+ if (isSelectedCascAsOmega<CollisionsMc>(casc)) {
389491 int matched = isMatched (casc);
390492 if (matched != aod::pid_studies::Particle::NotMatched) {
391- fillTree<false >(casc, matched);
493+ fillTree<false , CollisionsMc >(casc, matched);
392494 }
393495 }
394496 }
395497 }
396498 PROCESS_SWITCH (HfTaskPidStudies, processCascMc, " Process MC" , true );
397499
398500 void processCascData (aod::CascDatas const & cascades,
399- CollSels const &,
400- PidTracks const &)
501+ PidTracks const &,
502+ aod::BCsWithTimestamps const &,
503+ CollSels const &)
401504 {
402505 for (const auto & casc : cascades) {
403- if (isSelectedCascAsOmega (casc)) {
404- fillTree<false >(casc, aod::pid_studies::Particle::NotMatched);
506+ if (applyEvSels && !isCollSelected (casc.collision_as <CollSels>())) {
507+ return ;
508+ }
509+ if (applyTrackSels && !isTrackSelected<false >(casc)) {
510+ return ;
511+ }
512+ if (isSelectedCascAsOmega<CollSels>(casc)) {
513+ fillTree<false , CollSels>(casc, aod::pid_studies::Particle::NotMatched);
405514 }
406515 }
407516 }
0 commit comments