Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWGHF] Extend information of sparses for efficiency evaluation. Refactor analysis utilities. #9153

Merged
merged 14 commits into from
Jan 11, 2025
Merged
76 changes: 76 additions & 0 deletions PWGHF/Core/CentralityEstimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,82 @@ float getCentralityColl(const Coll&)
return 105.0f;
}

/// Get the centrality
/// \param collision is the collision with the centrality information
/// \param centEstimator integer to select the centrality estimator
/// \return collision centrality
template <typename Coll>
float getCentralityColl(const Coll& collision, int centEstimator)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
float getCentralityColl(const Coll& collision, int centEstimator)
float getCentralityColl(const Coll& collision, CentralityEstimator centEstimator)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most common use-case of this function is when the centEstimator argument is a Configurable<int> type defined in the user tasks. As far as I am aware, casting is not defined from Configurable<int> types to enum types, so I don't know how to implement this conversion. Do you have any suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use centEstimator.value as argument of calling getCentralityColl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, centEstimator is a Configurable<int> type, centEstimator.value extracts an int value. But then I manage to get a working version only by passing to the function static_cast<o2::hf_centrality::CentralityEstimator>(centEstimator.value) since the casting from the int to an enum type is not automatic.

{
switch (centEstimator) {
case CentralityEstimator::FT0A:
if constexpr (hasFT0ACent<Coll>) {
return collision.centFT0A();
}
LOG(fatal) << "Collision does not have centFT0A().";
break;
case CentralityEstimator::FT0C:
if constexpr (hasFT0CCent<Coll>) {
return collision.centFT0C();
}
LOG(fatal) << "Collision does not have centFT0C().";
break;
case CentralityEstimator::FT0M:
if constexpr (hasFT0MCent<Coll>) {
return collision.centFT0M();
}
LOG(fatal) << "Collision does not have centFT0M().";
break;
case CentralityEstimator::FV0A:
if constexpr (hasFV0ACent<Coll>) {
return collision.centFV0A();
}
LOG(fatal) << "Collision does not have centFV0A().";
break;
default:
LOG(fatal) << "Centrality estimator not valid. Possible values are V0A, T0M, T0A, T0C.";
break;
}
return -999.f;
}

/// \brief Function to get MC collision centrality
/// \param collSlice collection of reconstructed collisions associated to a generated one
/// \return generated MC collision centrality
template <typename CCs>
float getCentralityGenColl(CCs const& collSlice)
{
float centrality{-1};
float multiplicity{0.f};
for (const auto& collision : collSlice) {
float collMult = collision.numContrib();
if (collMult > multiplicity) {
centrality = getCentralityColl(collision);
multiplicity = collMult;
}
}
return centrality;
}

/// \brief Function to get MC collision centrality
/// \param collSlice collection of reconstructed collisions associated to a generated one
/// \param centEstimator integer to select the centrality estimator
/// \return generated MC collision centrality
template <typename CCs>
float getCentralityGenColl(CCs const& collSlice, int centEstimator)
{
float centrality{-1};
float multiplicity{0.f};
for (const auto& collision : collSlice) {
float collMult = collision.numContrib();
if (collMult > multiplicity) {
centrality = getCentralityColl(collision, centEstimator);
multiplicity = collMult;
}
}
return centrality;
}

} // namespace o2::hf_centrality

#endif // PWGHF_CORE_CENTRALITYESTIMATION_H_
131 changes: 11 additions & 120 deletions PWGHF/D2H/Tasks/taskDplus.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,15 @@
#include "PWGHF/Core/HfHelper.h"
#include "PWGHF/DataModel/CandidateReconstructionTables.h"
#include "PWGHF/DataModel/CandidateSelectionTables.h"
#include "PWGHF/Utils/utilsEvSelHf.h"
#include "PWGHF/Utils/utilsAnalysis.h"

using namespace o2;
using namespace o2::analysis;
using namespace o2::framework;
using namespace o2::framework::expressions;
using namespace o2::hf_centrality;

enum OccupancyEstimator { None = 0,
ITS,
FT0C };

enum BHadMothers { NotMatched = 0,
BPlus,
BZero,
Bs,
LambdaBZero };
using namespace o2::hf_occupancy;

/// D± analysis task
struct HfTaskDplus {
Expand Down Expand Up @@ -455,10 +448,10 @@ struct HfTaskDplus {
if (storeCentrality || storeOccupancy) {
auto collision = candidate.template collision_as<CollisionsCent>();
if (storeCentrality && centEstimator != CentralityEstimator::None) {
cent = getCentrality(collision);
cent = getCentralityColl(collision, centEstimator);
}
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
occ = getOccupancy(collision);
occ = getOccupancyColl(collision, occEstimator);
}
}

Expand Down Expand Up @@ -506,10 +499,10 @@ struct HfTaskDplus {
if (storeCentrality || storeOccupancy) {
auto collision = candidate.template collision_as<McRecoCollisionsCent>();
if (storeCentrality && centEstimator != CentralityEstimator::None) {
cent = getCentrality(collision);
cent = getCentralityColl(collision, centEstimator);
}
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
occ = getOccupancy(collision);
occ = getOccupancyColl(collision, occEstimator);
}
}

Expand All @@ -526,10 +519,10 @@ struct HfTaskDplus {
}
auto collision = candidate.template collision_as<McRecoCollisionsCent>();
if (storeCentrality && centEstimator != CentralityEstimator::None) {
cent = getCentrality(collision);
cent = getCentralityColl(collision, centEstimator);
}
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
occ = getOccupancy(collision);
occ = getOccupancyColl(collision, occEstimator);
}
fillHistoMCRec<false>(candidate);
fillSparseML<true, false>(candidate, ptBhad, flagBHad, cent, occ);
Expand All @@ -556,10 +549,10 @@ struct HfTaskDplus {
const auto recoCollsPerGenMcColl = mcRecoCollisions.sliceBy(recoColPerMcCollision, mcGenCollision.globalIndex());
const auto mcParticlesPerGenMcColl = mcGenParticles.sliceBy(mcParticlesPerMcCollision, mcGenCollision.globalIndex());
if (storeCentrality && centEstimator != CentralityEstimator::None) {
cent = getMcGenCollCentrality(recoCollsPerGenMcColl);
cent = getCentralityGenColl(recoCollsPerGenMcColl, centEstimator);
}
if (storeOccupancy && occEstimator != OccupancyEstimator::None) {
occ = getMcGenCollOccupancy(recoCollsPerGenMcColl);
occ = getOccupancyGenColl(recoCollsPerGenMcColl, occEstimator);
}

for (const auto& particle : mcParticlesPerGenMcColl) {
Expand All @@ -582,108 +575,6 @@ struct HfTaskDplus {
}
}

/// Get the occupancy
/// \param collision is the collision with the occupancy information
/// \return collision occupancy
template <typename Coll>
float getOccupancy(Coll const& collision)
{
float occupancy = -999.;
switch (occEstimator) {
case OccupancyEstimator::ITS:
occupancy = collision.trackOccupancyInTimeRange();
break;
case OccupancyEstimator::FT0C:
occupancy = collision.ft0cOccupancyInTimeRange();
break;
default:
LOG(warning) << "Occupancy estimator not valid. Possible values are ITS or FT0C. Fallback to ITS";
occupancy = collision.trackOccupancyInTimeRange();
break;
}
return occupancy;
}

/// \brief Function to get MC collision occupancy
/// \param collSlice collection of reconstructed collisions associated to a generated one
/// \return generated MC collision occupancy
template <typename CCs>
int getMcGenCollOccupancy(CCs const& collSlice)
{
float multiplicity{0.f};
int occupancy = 0;
for (const auto& collision : collSlice) {
float collMult{0.f};
collMult = collision.numContrib();
if (collMult > multiplicity) {
occupancy = getOccupancy(collision);
multiplicity = collMult;
}
} // end loop over collisions

return occupancy;
}

/// Get the centrality
/// \param collision is the collision with the centrality information
/// \return collision centrality
template <typename Coll>
float getCentrality(Coll const& collision)
{
float cent = -999.;
switch (centEstimator) {
case CentralityEstimator::FT0C:
cent = collision.centFT0C();
break;
case CentralityEstimator::FT0M:
cent = collision.centFT0M();
break;
default:
LOG(warning) << "Centrality estimator not valid. Possible values are FT0C, FT0M. Fallback to FT0C";
cent = collision.centFT0C();
break;
}
return cent;
}

/// \brief Function to get MC collision centrality
/// \param collSlice collection of reconstructed collisions associated to a generated one
/// \return generated MC collision centrality
template <typename CCs>
float getMcGenCollCentrality(CCs const& collSlice)
{
float centrality{-1};
float multiplicity{0.f};
for (const auto& collision : collSlice) {
float collMult = collision.numContrib();
if (collMult > multiplicity) {
centrality = getCentrality(collision);
multiplicity = collMult;
}
}
return centrality;
}

/// Convert the B hadron mother PDG for non prompt candidates to a flag
/// \param pdg of the b hadron mother
/// \return integer map to specific mothers' PDG codes
int getBHadMotherFlag(const int& flagBHad)
{
if (std::abs(flagBHad) == o2::constants::physics::kBPlus) {
return BHadMothers::BPlus;
}
if (std::abs(flagBHad) == o2::constants::physics::kB0) {
return BHadMothers::BZero;
}
if (std::abs(flagBHad) == o2::constants::physics::kBS) {
return BHadMothers::Bs;
}
if (std::abs(flagBHad) == o2::constants::physics::kLambdaB0) {
return BHadMothers::LambdaBZero;
}
return BHadMothers::NotMatched;
}

// process functions
void processData(CandDplusData const& candidates, CollisionsCent const& collisions)
{
Expand Down
Loading
Loading