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
127 changes: 50 additions & 77 deletions PWGLF/DataModel/LFSpinAlignVecMesonTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// or submit itself to any jurisdiction.

/// \file LFSpinAlignVecMesonTables.h
/// \brief Derived-data tables for K*0 and phi spin-alignment studies
/// \brief Derived-data tables for K*0 and phi spin-alignment studies (tracks only: the K*0 and phi pairs are built in the analysis)

#ifndef PWGLF_DATAMODEL_LFSPINALIGNVECMESONTABLES_H_
#define PWGLF_DATAMODEL_LFSPINALIGNVECMESONTABLES_H_
Expand All @@ -22,11 +22,13 @@
#include <Framework/ASoA.h>
#include <Framework/AnalysisDataModel.h>

#include <bit>
#include <cmath>
#include <cstdint>

namespace o2::aod
{
DECLARE_SOA_TABLE(SpinAlignEvents, "AOD", "SAVMEVENT",
DECLARE_SOA_TABLE(SpinAlignEvents, "AOD", "SPINALIGNEVENT",
o2::soa::Index<>,
bc::RunNumber,
collision::PosZ,
Expand All @@ -40,85 +42,52 @@ DECLARE_SOA_TABLE(SpinAlignEvents, "AOD", "SAVMEVENT",
epcalibrationtable::QTPC);
using SpinAlignEvent = SpinAlignEvents::iterator;

namespace savmcand
namespace savmtrack
{
DECLARE_SOA_INDEX_COLUMN(SpinAlignEvent, spinAlignEvent);
DECLARE_SOA_COLUMN(Mass, mass, float);
DECLARE_SOA_COLUMN(Px, px, float);
DECLARE_SOA_COLUMN(Py, py, float);
DECLARE_SOA_COLUMN(Pz, pz, float);
DECLARE_SOA_COLUMN(PosPx, posPx, float);
DECLARE_SOA_COLUMN(PosPy, posPy, float);
DECLARE_SOA_COLUMN(PosPz, posPz, float);
DECLARE_SOA_COLUMN(PosTPCNSigma, posTPCNSigma, float);
DECLARE_SOA_COLUMN(PosTOFNSigma, posTOFNSigma, float);
DECLARE_SOA_COLUMN(PosHasTOF, posHasTOF, bool);
DECLARE_SOA_COLUMN(NegPx, negPx, float);
DECLARE_SOA_COLUMN(NegPy, negPy, float);
DECLARE_SOA_COLUMN(NegPz, negPz, float);
DECLARE_SOA_COLUMN(NegTPCNSigma, negTPCNSigma, float);
DECLARE_SOA_COLUMN(NegTOFNSigma, negTOFNSigma, float);
DECLARE_SOA_COLUMN(NegHasTOF, negHasTOF, bool);
DECLARE_SOA_COLUMN(Flavour, flavour, int8_t);
} // namespace savmcand

DECLARE_SOA_TABLE(SAKstarCands, "AOD", "SAKSTARCAND",
o2::soa::Index<>,
savmcand::SpinAlignEventId,
savmcand::Flavour,
savmcand::Mass,
savmcand::Px,
savmcand::Py,
savmcand::Pz,
savmcand::PosPx,
savmcand::PosPy,
savmcand::PosPz,
savmcand::NegPx,
savmcand::NegPy,
savmcand::NegPz,
savmcand::PosTPCNSigma,
savmcand::PosTOFNSigma,
savmcand::PosHasTOF,
savmcand::NegTPCNSigma,
savmcand::NegTOFNSigma,
savmcand::NegHasTOF);
using SAKstarCand = SAKstarCands::iterator;
// Compact storage (the table is the bulk of the derived data):
// - momentum components keep MomentumMantissaBits of the 23 float mantissa bits (relative precision 6e-5, far below
// the tracking resolution), which makes them compress much better;
// - n-sigma values are stored as int8 in steps of 0.1, rounded away from zero, so that |stored| <= cut is the same
// as |n-sigma| <= cut for every cut on the 0.1 grid (2.0, 2.5, 3.0, ...). Range +-12.7.
constexpr int MomentumMantissaBits = 14;

DECLARE_SOA_TABLE(SAPhiCands, "AOD", "SAPHICAND",
o2::soa::Index<>,
savmcand::SpinAlignEventId,
savmcand::Mass,
savmcand::Px,
savmcand::Py,
savmcand::Pz,
savmcand::PosPx,
savmcand::PosPy,
savmcand::PosPz,
savmcand::NegPx,
savmcand::NegPy,
savmcand::NegPz,
savmcand::PosTPCNSigma,
savmcand::PosTOFNSigma,
savmcand::PosHasTOF,
savmcand::NegTPCNSigma,
savmcand::NegTOFNSigma,
savmcand::NegHasTOF);
using SAPhiCand = SAPhiCands::iterator;
inline float truncateMomentum(float value)
{
constexpr uint32_t Mask = ~((1u << (23 - MomentumMantissaBits)) - 1u);
return std::bit_cast<float>(std::bit_cast<uint32_t>(value) & Mask);
}

namespace savmtrack
inline int8_t packNSigma(float nSigma)
{
DECLARE_SOA_INDEX_COLUMN(SpinAlignEvent, spinAlignEvent);
DECLARE_SOA_COLUMN(Px, px, float);
DECLARE_SOA_COLUMN(Py, py, float);
DECLARE_SOA_COLUMN(Pz, pz, float);
constexpr float Steps = 10.f;
constexpr float MaxSteps = 127.f;
const float steps = std::ceil(std::abs(nSigma) * Steps);
if (!(steps < MaxSteps)) { // also catches NaN and infinity
return static_cast<int8_t>(nSigma < 0.f ? -MaxSteps : MaxSteps);
}
return static_cast<int8_t>(nSigma < 0.f ? -steps : steps);
}

DECLARE_SOA_COLUMN(Px, px, float); //! truncated to MomentumMantissaBits
DECLARE_SOA_COLUMN(Py, py, float); //! truncated to MomentumMantissaBits
DECLARE_SOA_COLUMN(Pz, pz, float); //! truncated to MomentumMantissaBits
DECLARE_SOA_COLUMN(Sign, sign, int8_t);
DECLARE_SOA_COLUMN(TPCNSigmaKa, tpcNSigmaKa, float);
DECLARE_SOA_COLUMN(TPCNSigmaPi, tpcNSigmaPi, float);
DECLARE_SOA_COLUMN(TOFNSigmaKa, tofNSigmaKa, float);
DECLARE_SOA_COLUMN(TOFNSigmaPi, tofNSigmaPi, float);
DECLARE_SOA_COLUMN(TPCNSigmaKa10, tpcNSigmaKa10, int8_t); //! TPC n-sigma (kaon) x 10, see packNSigma
DECLARE_SOA_COLUMN(TPCNSigmaPi10, tpcNSigmaPi10, int8_t); //! TPC n-sigma (pion) x 10
DECLARE_SOA_COLUMN(TOFNSigmaKa10, tofNSigmaKa10, int8_t); //! TOF n-sigma (kaon) x 10
DECLARE_SOA_COLUMN(TOFNSigmaPi10, tofNSigmaPi10, int8_t); //! TOF n-sigma (pion) x 10
DECLARE_SOA_COLUMN(HasTOF, hasTOF, bool);
DECLARE_SOA_COLUMN(IsKaon, isKaon, bool);
DECLARE_SOA_COLUMN(IsPion, isPion, bool);
DECLARE_SOA_DYNAMIC_COLUMN(TPCNSigmaKa, tpcNSigmaKa, //! TPC n-sigma (kaon)
[](int8_t tpcNSigmaKa10) { return static_cast<float>(tpcNSigmaKa10) / 10.f; });
DECLARE_SOA_DYNAMIC_COLUMN(TPCNSigmaPi, tpcNSigmaPi, //! TPC n-sigma (pion)
[](int8_t tpcNSigmaPi10) { return static_cast<float>(tpcNSigmaPi10) / 10.f; });
DECLARE_SOA_DYNAMIC_COLUMN(TOFNSigmaKa, tofNSigmaKa, //! TOF n-sigma (kaon)
[](int8_t tofNSigmaKa10) { return static_cast<float>(tofNSigmaKa10) / 10.f; });
DECLARE_SOA_DYNAMIC_COLUMN(TOFNSigmaPi, tofNSigmaPi, //! TOF n-sigma (pion)
[](int8_t tofNSigmaPi10) { return static_cast<float>(tofNSigmaPi10) / 10.f; });
} // namespace savmtrack

DECLARE_SOA_TABLE(SAVMTracks, "AOD", "SAVMTRACK",
Expand All @@ -128,13 +97,17 @@ DECLARE_SOA_TABLE(SAVMTracks, "AOD", "SAVMTRACK",
savmtrack::Py,
savmtrack::Pz,
savmtrack::Sign,
savmtrack::TPCNSigmaKa,
savmtrack::TPCNSigmaPi,
savmtrack::TOFNSigmaKa,
savmtrack::TOFNSigmaPi,
savmtrack::TPCNSigmaKa10,
savmtrack::TPCNSigmaPi10,
savmtrack::TOFNSigmaKa10,
savmtrack::TOFNSigmaPi10,
savmtrack::HasTOF,
savmtrack::IsKaon,
savmtrack::IsPion);
savmtrack::IsPion,
savmtrack::TPCNSigmaKa<savmtrack::TPCNSigmaKa10>,
savmtrack::TPCNSigmaPi<savmtrack::TPCNSigmaPi10>,
savmtrack::TOFNSigmaKa<savmtrack::TOFNSigmaKa10>,
savmtrack::TOFNSigmaPi<savmtrack::TOFNSigmaPi10>);
using SAVMTrack = SAVMTracks::iterator;
} // namespace o2::aod

Expand Down
127 changes: 27 additions & 100 deletions PWGLF/TableProducer/Resonances/spinAlignVecMesonTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// or submit itself to any jurisdiction.

/// \file spinAlignVecMesonTable.cxx
/// \brief Derived-data producer for K*0 and phi spin alignment
/// \brief Derived-data producer for K*0 and phi spin alignment: selected events and their kaon and pion tracks.
/// The K*0 and phi candidates are built from these tracks in the analysis (kstarpbpb).

#include "PWGLF/DataModel/EPCalibrationTables.h"
#include "PWGLF/DataModel/LFSpinAlignVecMesonTables.h"
Expand All @@ -24,7 +25,6 @@
#include "Common/DataModel/TrackSelectionTables.h"

#include <CommonConstants/MathConstants.h>
#include <CommonConstants/PhysicsConstants.h>
#include <Framework/AnalysisDataModel.h>
#include <Framework/AnalysisHelpers.h>
#include <Framework/AnalysisTask.h>
Expand All @@ -35,9 +35,6 @@
#include <Framework/OutputObjHeader.h>
#include <Framework/runDataProcessing.h>

#include <Math/Vector4D.h> // IWYU pragma: keep
#include <Math/Vector4Dfwd.h>

#include <cmath>
#include <cstdint>
#include <string>
Expand All @@ -50,8 +47,6 @@ using namespace o2::aod::rctsel;
struct SpinAlignVecMesonTable {

Produces<aod::SpinAlignEvents> eventTable;
Produces<aod::SAKstarCands> kstarTable;
Produces<aod::SAPhiCands> phiTable;
Produces<aod::SAVMTracks> trackTable;

Configurable<float> cfgCutVertex{"cfgCutVertex", 10.0f, "Maximum |Vz| (cm)"};
Expand All @@ -74,32 +69,20 @@ struct SpinAlignVecMesonTable {
Configurable<float> cfgNSigmaTOFPi{"cfgNSigmaTOFPi", 3.0f, "Pion: maximum |n-sigma TOF|"};
Configurable<bool> cfgRequireTOF{"cfgRequireTOF", false, "Require a TOF hit above cfgPtTOFRequired"};
Configurable<float> cfgPtTOFRequired{"cfgPtTOFRequired", 0.5f, "pT (GeV/c) above which TOF is required"};

Configurable<float> cfgKstarMassMin{"cfgKstarMassMin", 0.70f, "Minimum K pi mass (GeV/c^2)"};
Configurable<float> cfgKstarMassMax{"cfgKstarMassMax", 1.10f, "Maximum K pi mass (GeV/c^2)"};
Configurable<float> cfgPhiMassMin{"cfgPhiMassMin", 0.99f, "Minimum K K mass (GeV/c^2)"};
Configurable<float> cfgPhiMassMax{"cfgPhiMassMax", 1.07f, "Maximum K K mass (GeV/c^2)"};
Configurable<float> cfgPairRapidity{"cfgPairRapidity", 0.5f, "Maximum pair |y|"};
Configurable<bool> cfgStoreTracks{"cfgStoreTracks", true, "Store the selected single kaon and pion tracks (SAVMTracks), needed for the v2 like-sign and mixed-event pairs (not for rho00)"};
Configurable<bool> cfgStorePions{"cfgStorePions", true, "Store pion tracks (needed for K*0); false gives a phi-only production with kaon tracks only"};

HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
RCTFlagsChecker rctChecker;

static constexpr double MassKa = o2::constants::physics::MassKaonCharged;
static constexpr double MassPi = o2::constants::physics::MassPionCharged;

void init(InitContext&)
{
rctChecker.init(cfgRCTLabel.value, false, true);

histos.add("hEvents", "Number of events;;Events", kTH1F, {{2, 0.0f, 2.0f}});
histos.add("hCent", "Selected events;FT0C centrality (%);Events", kTH1F, {{100, 0.0f, 100.0f}});
histos.add("hKstarMass", "K* candidates;M_{K#pi} (GeV/c^{2});Counts", kTH1F, {{200, 0.6f, 1.2f}});
histos.add("hPhiMass", "#phi candidates;M_{KK} (GeV/c^{2});Counts", kTH1F, {{200, 0.98f, 1.08f}});
histos.add("hPsiFT0C", "Selected events;FT0C centrality (%);#Psi_{2}^{FT0C}", kTH2F, {{8, 0.0f, 80.0f}, {100, -o2::constants::math::PIHalf, o2::constants::math::PIHalf}});
if (cfgStoreTracks) {
histos.add("hNTracks", "Stored kaon/pion tracks per event;N_{tracks};Events", kTH1F, {{500, 0.0f, 2000.0f}});
}
histos.add("hNKaons", "Stored kaon tracks per event;N_{K};Events", kTH1F, {{500, 0.0f, 1000.0f}});
histos.add("hNPions", "Stored pion tracks per event;N_{#pi};Events", kTH1F, {{500, 0.0f, 2000.0f}});
}

Filter vertexFilter = nabs(aod::collision::posZ) < cfgCutVertex;
Expand Down Expand Up @@ -190,14 +173,6 @@ struct SpinAlignVecMesonTable {
return true;
}

template <typename T>
ROOT::Math::PxPyPzMVector makePair(T const& pos, double massPos, T const& neg, double massNeg)
{
ROOT::Math::PxPyPzMVector p4Pos(pos.px(), pos.py(), pos.pz(), massPos);
ROOT::Math::PxPyPzMVector p4Neg(neg.px(), neg.py(), neg.pz(), massNeg);
return p4Pos + p4Neg;
}

void processData(EventCandidates::iterator const& collision,
TrackCandidates const& tracks,
aod::BCsWithTimestamps const&)
Expand All @@ -216,80 +191,32 @@ struct SpinAlignVecMesonTable {
collision.qFT0C(), collision.qFT0A(), collision.qTPC());
auto eventIndex = eventTable.lastIndex();

if (cfgStoreTracks) {
int nStored = 0;
for (const auto& track : tracks) {
if (track.sign() == 0 || !isGoodTrack(track)) {
continue;
}
const bool kaon = isKaon(track);
const bool pion = isPion(track);
if (!kaon && !pion) {
continue;
}
trackTable(eventIndex, track.px(), track.py(), track.pz(), static_cast<int8_t>(track.sign()),
track.tpcNSigmaKa(), track.tpcNSigmaPi(), track.tofNSigmaKa(), track.tofNSigmaPi(),
track.hasTOF(), kaon, pion);
++nStored;
}
histos.fill(HIST("hNTracks"), nStored);
}

for (const auto& pos : tracks) {
if (pos.sign() <= 0 || !isGoodTrack(pos)) {
int nKaons = 0;
int nPions = 0;
for (const auto& track : tracks) {
if (track.sign() == 0 || !isGoodTrack(track)) {
continue;
}

for (const auto& neg : tracks) {
if (neg.sign() >= 0 || !isGoodTrack(neg)) {
continue;
}

if (isKaon(pos) && isKaon(neg)) {
auto phi = makePair(pos, MassKa, neg, MassKa);
float mass = phi.M();
if (mass > cfgPhiMassMin && mass < cfgPhiMassMax && std::abs(phi.Rapidity()) < cfgPairRapidity) {
phiTable(eventIndex, mass,
static_cast<float>(phi.Px()), static_cast<float>(phi.Py()), static_cast<float>(phi.Pz()),
pos.px(), pos.py(), pos.pz(),
neg.px(), neg.py(), neg.pz(),
pos.tpcNSigmaKa(), pos.tofNSigmaKa(), pos.hasTOF(),
neg.tpcNSigmaKa(), neg.tofNSigmaKa(), neg.hasTOF());
histos.fill(HIST("hPhiMass"), mass);
}
}

if (isKaon(pos) && isPion(neg)) {
auto kstar = makePair(pos, MassKa, neg, MassPi);
float mass = kstar.M();
if (mass > cfgKstarMassMin && mass < cfgKstarMassMax && std::abs(kstar.Rapidity()) < cfgPairRapidity) {
kstarTable(eventIndex, static_cast<int8_t>(1), mass,
static_cast<float>(kstar.Px()), static_cast<float>(kstar.Py()), static_cast<float>(kstar.Pz()),
pos.px(), pos.py(), pos.pz(),
neg.px(), neg.py(), neg.pz(),
pos.tpcNSigmaKa(), pos.tofNSigmaKa(), pos.hasTOF(),
neg.tpcNSigmaPi(), neg.tofNSigmaPi(), neg.hasTOF());
histos.fill(HIST("hKstarMass"), mass);
}
}

if (isPion(pos) && isKaon(neg)) {
auto kstar = makePair(pos, MassPi, neg, MassKa);
float mass = kstar.M();
if (mass > cfgKstarMassMin && mass < cfgKstarMassMax && std::abs(kstar.Rapidity()) < cfgPairRapidity) {
kstarTable(eventIndex, static_cast<int8_t>(-1), mass,
static_cast<float>(kstar.Px()), static_cast<float>(kstar.Py()), static_cast<float>(kstar.Pz()),
pos.px(), pos.py(), pos.pz(),
neg.px(), neg.py(), neg.pz(),
pos.tpcNSigmaPi(), pos.tofNSigmaPi(), pos.hasTOF(),
neg.tpcNSigmaKa(), neg.tofNSigmaKa(), neg.hasTOF());
histos.fill(HIST("hKstarMass"), mass);
}
}
const bool kaon = isKaon(track);
const bool pion = cfgStorePions && isPion(track);
if (!kaon && !pion) {
continue;
}
}
// compact storage (see LFSpinAlignVecMesonTables.h): truncated momentum, n-sigma x 10 as int8;
// the kaon/pion flags above use the full-precision n-sigma
trackTable(eventIndex,
aod::savmtrack::truncateMomentum(track.px()), aod::savmtrack::truncateMomentum(track.py()), aod::savmtrack::truncateMomentum(track.pz()),
static_cast<int8_t>(track.sign()),
aod::savmtrack::packNSigma(track.tpcNSigmaKa()), aod::savmtrack::packNSigma(track.tpcNSigmaPi()),
aod::savmtrack::packNSigma(track.tofNSigmaKa()), aod::savmtrack::packNSigma(track.tofNSigmaPi()),
track.hasTOF(), kaon, pion);
nKaons += kaon;
nPions += pion;
}
histos.fill(HIST("hNKaons"), nKaons);
histos.fill(HIST("hNPions"), nPions);
}
PROCESS_SWITCH(SpinAlignVecMesonTable, processData, "Fill K* and phi derived tables", true);
PROCESS_SWITCH(SpinAlignVecMesonTable, processData, "Fill the event and kaon/pion track tables", true);
};

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
Expand Down
Loading
Loading