Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 69 additions & 8 deletions PWGCF/Femto/Core/cascadeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,23 @@ class CascadeSelection : public baseselection::BaseSelection<float, o2::analysis

struct CascadeBuilderProducts : o2::framework::ProducesGroup {
o2::framework::Produces<o2::aod::FXis> producedXis;
o2::framework::Produces<o2::aod::FLiteXis> producedLiteXis;
o2::framework::Produces<o2::aod::FXiMasks> producedXiMasks;
o2::framework::Produces<o2::aod::FXiExtras> producedXiExtras;
o2::framework::Produces<o2::aod::FOmegas> producedOmegas;
o2::framework::Produces<o2::aod::FLiteOmegas> producedLiteOmegas;
o2::framework::Produces<o2::aod::FOmegaMasks> producedOmegaMasks;
o2::framework::Produces<o2::aod::FOmegaExtras> producedOmegaExtras;
};

struct ConfCascadeTables : o2::framework::ConfigurableGroup {
std::string prefix = std::string("CascadeTables");
o2::framework::Configurable<int> produceXis{"produceXis", -1, "Produce Xis (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceLiteXis{"produceLiteXis", -1, "Produce LiteXis (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceXiMasks{"produceXiMasks", -1, "Produce XiMasks (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceXiExtras{"produceXiExtras", -1, "Produce XiExtras (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceOmegas{"produceOmegas", -1, "Produce Omegas (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceLiteOmegas{"produceLiteOmegas", -1, "Produce LiteOmegas (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceOmegaMasks{"produceOmegaMasks", -1, "Produce OmegaMasks (-1: auto; 0 off; 1 on)"};
o2::framework::Configurable<int> produceOmegaExtras{"produceOmegaExtras", -1, "Produce OmegaExtras (-1: auto; 0 off; 1 on)"};
};
Expand All @@ -467,23 +471,58 @@ class CascadeBuilder
CascadeBuilder() = default;
~CascadeBuilder() = default;

template <typename T1, typename T2, typename T3, typename T4>
void init(o2::framework::HistogramRegistry* registry, T1& config, T2& filter, T3& table, T4& initContext)
template <typename T1, typename T2, typename T3, typename T4, typename T5>
void init(o2::framework::HistogramRegistry* registry, T1& config, T2& filter, T3& table, T4& initContext, T5& trackBuilder)
{
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kXi)) {
LOG(info) << "Initialize femto Xi builder...";
mProduceLiteXis = utils::enableTable("FLiteXis_001", table.produceLiteXis.value, initContext);
mProduceXis = utils::enableTable("FXis_001", table.produceXis.value, initContext);
mProduceXiMasks = utils::enableTable("FXiMasks_001", table.produceXiMasks.value, initContext);
mProduceXiExtras = utils::enableTable("FXiExtras_001", table.produceXiExtras.value, initContext);

if (mProduceXis && mProduceLiteXis) {
LOG(fatal) << "FXis and FLiteXis are mutually exclusive -- enable only one. "
<< "FLiteXis is meant to replace FXis at the producer stage (for better compression in derived data); "
<< "use the dedicated converter task to reconstruct FXis from FLiteXis downstream.";
}
if (mProduceXis && !trackBuilder.producingTracks()) {
LOG(fatal) << "FXis is enabled, but the track builder is not producing FTracks (full precision). "
<< "FXis stores daughter indices into FTracks -- enable TrackTables.produceTracks, "
<< "or switch to FLiteXis if TrackTables.produceLiteTracks is enabled instead.";
}
if (mProduceLiteXis && !trackBuilder.producingLiteTracks()) {
LOG(fatal) << "FLiteXis is enabled, but the track builder is not producing FLiteTracks. "
<< "FLiteXis stores daughter indices into FLiteTracks -- enable TrackTables.produceLiteTracks, "
<< "or switch to FXis if TrackTables.produceTracks is enabled instead.";
}
}
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kOmega)) {
LOG(info) << "Initialize femto Omega builder...";
mProduceOmegas = utils::enableTable("FOmegas_001", table.produceOmegas.value, initContext);
mProduceLiteOmegas = utils::enableTable("FLiteOmegas_001", table.produceLiteOmegas.value, initContext);
mProduceOmegaMasks = utils::enableTable("FOmegaMasks_001", table.produceOmegaMasks.value, initContext);
mProduceOmegaExtras = utils::enableTable("FOmegaExtras_001", table.produceOmegaExtras.value, initContext);

if (mProduceOmegas && mProduceLiteOmegas) {
LOG(fatal) << "FOmegas and FLiteOmegas are mutually exclusive -- enable only one. "
<< "FLiteOmegas is meant to replace FOmegas at the producer stage (for better compression in derived data); "
<< "use the dedicated converter task to reconstruct FOmegas from FLiteOmegas downstream.";
}
if (mProduceOmegas && !trackBuilder.producingTracks()) {
LOG(fatal) << "FOmegas is enabled, but the track builder is not producing FTracks (full precision). "
<< "FOmegas stores daughter indices into FTracks -- enable TrackTables.produceTracks, "
<< "or switch to FLiteOmegas if TrackTables.produceLiteTracks is enabled instead.";
}
if (mProduceLiteOmegas && !trackBuilder.producingLiteTracks()) {
LOG(fatal) << "FLiteOmegas is enabled, but the track builder is not producing FLiteTracks. "
<< "FLiteOmegas stores daughter indices into FLiteTracks -- enable TrackTables.produceLiteTracks, "
<< "or switch to FOmegas if TrackTables.produceTracks is enabled instead.";
}
}

if (mProduceXis || mProduceXiExtras || mProduceXiMasks || mProduceOmegas || mProduceOmegaMasks || mProduceOmegaExtras) {
if (mProduceXis || mProduceLiteXis || mProduceXiExtras || mProduceXiMasks ||
mProduceOmegas || mProduceLiteOmegas || mProduceOmegaMasks || mProduceOmegaExtras) {
mFillAnyTable = true;
} else {
LOG(info) << "No tables configured, Selection object will not be configured...";
Expand Down Expand Up @@ -525,7 +564,7 @@ class CascadeBuilder
auto negDaughter = cascade.template negTrack_as<T7>();
negDaughterIndex = trackBuilder.template getDaughterIndex<modes::Track::kV0Daughter>(negDaughter, trackProducts, collisionBuilder);

fillCascade(collisionProducts, cascadeProducts, cascade, col, bachelorIndex, posDaughterIndex, negDaughterIndex);
fillCascade(collisionBuilder, cascadeProducts, cascade, col, bachelorIndex, posDaughterIndex, negDaughterIndex);
}
}

Expand Down Expand Up @@ -559,7 +598,7 @@ class CascadeBuilder
auto negDaughter = cascade.template negTrack_as<T8>();
negDaughterIndex = trackBuilder.template getDaughterIndex<system, modes::Track::kV0Daughter>(col, collisionBuilder, mcCols, negDaughter, trackProducts, mcParticles, mcBuilder, mcProducts);

fillCascade(collisionProducts, cascadeProducts, cascade, col, bachelorIndex, posDaughterIndex, negDaughterIndex);
fillCascade(collisionBuilder, cascadeProducts, cascade, col, bachelorIndex, posDaughterIndex, negDaughterIndex);
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kXi)) {
mcBuilder.template fillMcXiWithLabel<system>(col, mcCols, cascade, mcParticles, mcProducts);
}
Expand All @@ -570,11 +609,11 @@ class CascadeBuilder
}

template <typename T1, typename T2, typename T3, typename T4>
void fillCascade(T1& collisionProducts, T2& cascadeProducts, T3 const& cascade, T4 const& col, int bachelorIndex, int posDaughterIndex, int negDaughterIndex)
void fillCascade(T1& collisionBuilder, T2& cascadeProducts, T3 const& cascade, T4 const& col, int bachelorIndex, int posDaughterIndex, int negDaughterIndex)
{
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kXi)) {
if (mProduceXis) {
cascadeProducts.producedXis(collisionProducts.producedCollision.lastIndex(),
cascadeProducts.producedXis(collisionBuilder.collisionIndex(),
cascade.sign() * cascade.pt(),
cascade.eta(),
cascade.phi(),
Expand All @@ -583,6 +622,16 @@ class CascadeBuilder
posDaughterIndex,
negDaughterIndex);
}
if (mProduceLiteXis) {
cascadeProducts.producedLiteXis(collisionBuilder.collisionIndex(),
o2::aod::femtobase::lite::binSignedPt(cascade.sign() * cascade.pt()),
o2::aod::femtobase::lite::binEta(cascade.eta()),
o2::aod::femtobase::lite::binPhi(cascade.phi()),
o2::aod::femtocascades::lite::binXiMass(cascade.mXi()),
bachelorIndex,
posDaughterIndex,
negDaughterIndex);
}
if (mProduceXiMasks) {
cascadeProducts.producedXiMasks(mCascadeSelection.getBitmask());
}
Expand All @@ -601,7 +650,7 @@ class CascadeBuilder
}
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kOmega)) {
if (mProduceOmegas) {
cascadeProducts.producedOmegas(collisionProducts.producedCollision.lastIndex(),
cascadeProducts.producedOmegas(collisionBuilder.collisionIndex(),
cascade.sign() * cascade.pt(),
cascade.eta(),
cascade.phi(),
Expand All @@ -610,6 +659,16 @@ class CascadeBuilder
posDaughterIndex,
negDaughterIndex);
}
if (mProduceLiteOmegas) {
cascadeProducts.producedLiteOmegas(collisionBuilder.collisionIndex(),
o2::aod::femtobase::lite::binSignedPt(cascade.sign() * cascade.pt()),
o2::aod::femtobase::lite::binEta(cascade.eta()),
o2::aod::femtobase::lite::binPhi(cascade.phi()),
o2::aod::femtocascades::lite::binOmegaMass(cascade.mOmega()),
bachelorIndex,
posDaughterIndex,
negDaughterIndex);
}
if (mProduceOmegaMasks) {
cascadeProducts.producedOmegaMasks(mCascadeSelection.getBitmask());
}
Expand All @@ -634,9 +693,11 @@ class CascadeBuilder
CascadeSelection<cascadeType, SelectionHistName, FilterHistName> mCascadeSelection;
bool mFillAnyTable = false;
bool mProduceXis = false;
bool mProduceLiteXis = false;
bool mProduceXiMasks = false;
bool mProduceXiExtras = false;
bool mProduceOmegas = false;
bool mProduceLiteOmegas = false;
bool mProduceOmegaMasks = false;
bool mProduceOmegaExtras = false;
};
Expand Down
9 changes: 9 additions & 0 deletions PWGCF/Femto/Core/collisionBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,19 @@ class CollisionBuilder
template <typename T1>
bool checkCollision(T1 const& col)
{
if (!mFillAnyTable) {
return false; // selection object was never configured, nothing to check or fill
}
return mCollisionSelection.checkFilters(col) &&
mCollisionSelection.passesAllRequiredSelections();
}

template <typename T1, typename T2>
bool checkCollision(T1 const& col, T2 const& /*mcCols*/)
{
if (!mFillAnyTable) {
return false; // selection object was never configured, nothing to check or fill
}
// check sub generator id of associated generated collision
if (mSubGeneratorId >= 0) {
if (col.has_mcCollision()) {
Expand Down Expand Up @@ -698,6 +704,9 @@ class CollisionBuilder
mCurrentCollisionIndex = -1;
}

[[nodiscard]] bool producingCollisions() const { return mProducedCollisions; }
[[nodiscard]] bool producingLiteCollisions() const { return mProducedLiteCollisions; }

private:
CollisionSelection<SelectionHistName, FilterHistName> mCollisionSelection;
bool mCollisionAlreadyFilled = false;
Expand Down
39 changes: 39 additions & 0 deletions PWGCF/Femto/Core/femtoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <TPDGCode.h>

#include <sys/types.h>

#include <algorithm>
#include <cmath>
#include <concepts>
Expand Down Expand Up @@ -279,6 +281,43 @@ inline float unBinLogSigned(T binned, float magMin, float magMax)
return sign * mag;
}

template <typename T>
inline int unBinSign(T binned)
{
static_assert(std::is_unsigned_v<T>, "unBinSign requires an unsigned storage type");
constexpr uint64_t TotalBits = sizeof(T) * 8;
constexpr T SignMask = static_cast<T>(uint64_t{1} << (TotalBits - 1));
return (binned & SignMask) ? -1 : 1;
}

template <typename T>
inline T binLogUnsigned(float value, float magMin, float magMax)
{
static_assert(std::is_unsigned_v<T>, "binLogUnsigned requires an unsigned storage type");
constexpr uint64_t TotalBits = sizeof(T) * 8;
constexpr uint64_t Levels = uint64_t{1} << TotalBits; // number of representable values, e.g. 65536 for uint16_t
float mag = std::clamp(value, magMin, magMax);
float logLo = std::log(magMin);
float logHi = std::log(magMax);
float step = (logHi - logLo) / static_cast<float>(Levels - 1);
auto idx = static_cast<uint64_t>(std::round((std::log(mag) - logLo) / step));
idx = std::clamp(idx, uint64_t{0}, Levels - 1);
return static_cast<T>(idx);
}

template <typename T>
inline float unBinLogUnsigned(T binned, float magMin, float magMax)
{
constexpr uint64_t TotalBits = sizeof(T) * 8;
constexpr uint64_t Levels = uint64_t{1} << TotalBits;
uint64_t idx = binned;
float logLo = std::log(magMin);
float logHi = std::log(magMax);
float step = (logHi - logLo) / static_cast<float>(Levels - 1);
float mag = std::exp(logLo + static_cast<float>(idx) * step);
return mag;
}

}; // namespace utils
}; // namespace o2::analysis::femto
//
Expand Down
Loading
Loading