Skip to content

Commit

Permalink
Common: add bc2mult / mult2bc maps (AliceO2Group#7563)
Browse files Browse the repository at this point in the history
* Common: add bc2mult / mult2bc maps

* Please consider the following formatting changes (#339)

* Add MC vtxZ

* Please consider the following formatting changes (#340)

---------

Co-authored-by: ALICE Builder <[email protected]>
  • Loading branch information
ddobrigk and alibuild authored Sep 5, 2024
1 parent 4ed329e commit 3f92df7
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 102 deletions.
12 changes: 10 additions & 2 deletions Common/DataModel/Multiplicity.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ DECLARE_SOA_COLUMN(MultMCFT0C, multMCFT0C, int); //!
DECLARE_SOA_COLUMN(MultMCNParticlesEta10, multMCNParticlesEta10, int); //!
DECLARE_SOA_COLUMN(MultMCNParticlesEta08, multMCNParticlesEta08, int); //!
DECLARE_SOA_COLUMN(MultMCNParticlesEta05, multMCNParticlesEta05, int); //!
DECLARE_SOA_COLUMN(MultMCPVz, multMCPVz, float); //!

// complementary / MultsExtra table
DECLARE_SOA_COLUMN(MultPVTotalContributors, multPVTotalContributors, int); //!
Expand All @@ -76,7 +77,8 @@ DECLARE_SOA_COLUMN(MultNGlobalTracksPV, multNGlobalTracksPV, int);
DECLARE_SOA_COLUMN(MultNGlobalTracksPVeta1, multNGlobalTracksPVeta1, int);
DECLARE_SOA_COLUMN(MultNGlobalTracksPVetaHalf, multNGlobalTracksPVetaHalf, int);

DECLARE_SOA_COLUMN(BCNumber, bcNumber, int); //!
DECLARE_SOA_INDEX_COLUMN(BC, bc);
DECLARE_SOA_INDEX_COLUMN(Collision, collision);

// even further QA: timing information for neighboring events
DECLARE_SOA_COLUMN(TimeToPrePrevious, timeToPrePrevious, float); //!
Expand Down Expand Up @@ -111,12 +113,17 @@ using Mults = soa::Join<BarrelMults, FV0Mults, FT0Mults, FDDMults, ZDCMults>;
using Mult = Mults::iterator;

// for QA purposes
DECLARE_SOA_TABLE(Mults2BC, "AOD", "MULTS2BC", //! Relate mult -> BC
o2::soa::Index<>, mult::BCId);
DECLARE_SOA_TABLE(BC2Mults, "AOD", "BC2MULTS", //! Relate BC -> mult
o2::soa::Index<>, mult::CollisionId);

DECLARE_SOA_TABLE(MultsExtra, "AOD", "MULTEXTRA", //!
mult::MultPVTotalContributors, mult::MultPVChi2, mult::MultCollisionTimeRes, mult::MultRunNumber, mult::MultPVz, mult::MultSel8,
mult::MultNTracksHasITS, mult::MultNTracksHasTPC, mult::MultNTracksHasTOF, mult::MultNTracksHasTRD,
mult::MultNTracksITSOnly, mult::MultNTracksTPCOnly, mult::MultNTracksITSTPC,
mult::MultAllTracksTPCOnly, mult::MultAllTracksITSTPC,
mult::BCNumber, evsel::NumTracksInTimeRange);
evsel::NumTracksInTimeRange);

DECLARE_SOA_TABLE(MultNeighs, "AOD", "MULTNEIGH", //!
mult::TimeToPrePrevious, mult::TimeToPrevious,
Expand All @@ -137,6 +144,7 @@ DECLARE_SOA_TABLE(MultsExtraMC, "AOD", "MULTEXTRAMC", //! Table for the MC infor
mult::MultMCNParticlesEta05,
mult::MultMCNParticlesEta08,
mult::MultMCNParticlesEta10,
mult::MultMCPVz,
mult::IsInelGt0<mult::MultMCNParticlesEta10>,
mult::IsInelGt1<mult::MultMCNParticlesEta10>,
o2::soa::Marker<1>);
Expand Down
234 changes: 137 additions & 97 deletions Common/TableProducer/multiplicityExtraTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct MultiplicityExtraTable {
Produces<aod::MultsBC> multBC;
Produces<aod::MultNeighs> multNeigh;

Produces<aod::Mults2BC> mult2bc;
Produces<aod::BC2Mults> bc2mult;

// Allow for downscaling of BC table for less space use in derived data
Configurable<float> bcDownscaleFactor{"bcDownscaleFactor", 2, "Downscale factor for BC table (0: save nothing, 1: save all)"};
Configurable<float> minFT0CforBCTable{"minFT0CforBCTable", 25.0f, "Minimum FT0C amplitude to fill BC table to reduce data"};
Expand All @@ -59,117 +62,154 @@ struct MultiplicityExtraTable {

using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Timestamps, aod::Run3MatchedToBCSparse>;

void processBCs(BCsWithRun3Matchings::iterator const& bc, aod::FV0As const&, aod::FT0s const&, aod::FDDs const&, aod::Zdcs const&)
void processBCs(BCsWithRun3Matchings const& bcs, aod::FV0As const&, aod::FT0s const&, aod::FDDs const&, aod::Zdcs const&, aod::Collisions const& collisions)
{
// downscale if requested to do so
if (bcDownscaleFactor < 1.f && (static_cast<float>(rand_r(&randomSeed)) / static_cast<float>(RAND_MAX)) > bcDownscaleFactor) {
return;
}
//+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+
// determine saved BCs and corresponding new BC table index
std::vector<int> newBCindex(bcs.size());
std::vector<int> bc2multArray(bcs.size());
int atIndex = 0;
for (const auto& bc : bcs) {
newBCindex[bc.globalIndex()] = -1;
bc2multArray[bc.globalIndex()] = -1;

// downscale if requested to do so
if (bcDownscaleFactor < 1.f && (static_cast<float>(rand_r(&randomSeed)) / static_cast<float>(RAND_MAX)) > bcDownscaleFactor) {
continue;
}

bool Tvx = false;
bool isFV0OrA = false;
float multFT0C = 0.f;
float multFT0A = 0.f;
float multFV0A = 0.f;
float multFDDA = 0.f;
float multFDDC = 0.f;

// ZDC amplitudes
float multZEM1 = -1.f;
float multZEM2 = -1.f;
float multZNA = -1.f;
float multZNC = -1.f;
float multZPA = -1.f;
float multZPC = -1.f;

uint8_t multFT0TriggerBits = 0;
uint8_t multFV0TriggerBits = 0;
uint8_t multFDDTriggerBits = 0;
uint64_t multBCTriggerMask = bc.triggerMask();

// initialize - from Arvind
newRunNumber = bc.runNumber();
int localBC = bc.globalBC() % nBCsPerOrbit;

if (newRunNumber != oldRunNumber) {
auto soreor = o2::ccdb::BasicCCDBManager::getRunDuration(ccdbApi, newRunNumber);
auto ts = soreor.first;

LOG(info) << " newRunNumber " << newRunNumber << " time stamp " << ts;
oldRunNumber = newRunNumber;
auto grplhcif = ccdb->getForTimeStamp<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", ts);
CollidingBunch = grplhcif->getBunchFilling().getBCPattern();
} // new run number

bool collidingBC = CollidingBunch.test(localBC);

if (bc.has_ft0()) {
auto ft0 = bc.ft0();
std::bitset<8> triggers = ft0.triggerMask();
Tvx = triggers[o2::fit::Triggers::bitVertex];
multFT0TriggerBits = static_cast<uint8_t>(triggers.to_ulong());

// calculate T0 charge
for (auto amplitude : ft0.amplitudeA()) {
multFT0A += amplitude;
float multFT0C = 0.f;
if (bc.has_ft0()) {
auto ft0 = bc.ft0();
for (auto amplitude : ft0.amplitudeC()) {
multFT0C += amplitude;
}
} else {
multFT0C = -999.0f;
}
for (auto amplitude : ft0.amplitudeC()) {
multFT0C += amplitude;

if (multFT0C < minFT0CforBCTable) {
continue; // skip this event
}
} else {
multFT0A = -999.0f;
multFT0C = -999.0f;
newBCindex[bc.globalIndex()] = atIndex++;
}
if (bc.has_fv0a()) {
auto fv0 = bc.fv0a();
std::bitset<8> fV0Triggers = fv0.triggerMask();
multFV0TriggerBits = static_cast<uint8_t>(fV0Triggers.to_ulong());
//+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+

for (auto amplitude : fv0.amplitude()) {
multFV0A += amplitude;
}
isFV0OrA = fV0Triggers[o2::fit::Triggers::bitA];
} else {
multFV0A = -999.0f;
//+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+
// interlink: collision -> valid BC, BC -> collision
for (const auto& collision : collisions) {
mult2bc(newBCindex[collision.bcId()]);
bc2multArray[collision.bcId()] = collision.globalIndex();
}
//+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+-<*>-+

if (bc.has_fdd()) {
auto fdd = bc.fdd();
std::bitset<8> fFDDTriggers = fdd.triggerMask();
multFDDTriggerBits = static_cast<uint8_t>(fFDDTriggers.to_ulong());
for (const auto& bc : bcs) {
if (newBCindex[bc.globalIndex()] < 0) {
continue; // don't keep if low mult or downsampled out
}

for (auto amplitude : fdd.chargeA()) {
multFDDA += amplitude;
bool Tvx = false;
bool isFV0OrA = false;
float multFT0C = 0.f;
float multFT0A = 0.f;
float multFV0A = 0.f;
float multFDDA = 0.f;
float multFDDC = 0.f;

// ZDC amplitudes
float multZEM1 = -1.f;
float multZEM2 = -1.f;
float multZNA = -1.f;
float multZNC = -1.f;
float multZPA = -1.f;
float multZPC = -1.f;

uint8_t multFT0TriggerBits = 0;
uint8_t multFV0TriggerBits = 0;
uint8_t multFDDTriggerBits = 0;
uint64_t multBCTriggerMask = bc.triggerMask();

// initialize - from Arvind
newRunNumber = bc.runNumber();
int localBC = bc.globalBC() % nBCsPerOrbit;

if (newRunNumber != oldRunNumber) {
auto soreor = o2::ccdb::BasicCCDBManager::getRunDuration(ccdbApi, newRunNumber);
auto ts = soreor.first;

LOG(info) << " newRunNumber " << newRunNumber << " time stamp " << ts;
oldRunNumber = newRunNumber;
auto grplhcif = ccdb->getForTimeStamp<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", ts);
CollidingBunch = grplhcif->getBunchFilling().getBCPattern();
} // new run number

bool collidingBC = CollidingBunch.test(localBC);

if (bc.has_ft0()) {
auto ft0 = bc.ft0();
std::bitset<8> triggers = ft0.triggerMask();
Tvx = triggers[o2::fit::Triggers::bitVertex];
multFT0TriggerBits = static_cast<uint8_t>(triggers.to_ulong());

// calculate T0 charge
for (auto amplitude : ft0.amplitudeA()) {
multFT0A += amplitude;
}
for (auto amplitude : ft0.amplitudeC()) {
multFT0C += amplitude;
}
} else {
multFT0A = -999.0f;
multFT0C = -999.0f;
}
for (auto amplitude : fdd.chargeC()) {
multFDDC += amplitude;
if (bc.has_fv0a()) {
auto fv0 = bc.fv0a();
std::bitset<8> fV0Triggers = fv0.triggerMask();
multFV0TriggerBits = static_cast<uint8_t>(fV0Triggers.to_ulong());

for (auto amplitude : fv0.amplitude()) {
multFV0A += amplitude;
}
isFV0OrA = fV0Triggers[o2::fit::Triggers::bitA];
} else {
multFV0A = -999.0f;
}
} else {
multFDDA = -999.0f;
multFDDC = -999.0f;
}

if (bc.has_zdc()) {
multZNA = bc.zdc().amplitudeZNA();
multZNC = bc.zdc().amplitudeZNC();
multZEM1 = bc.zdc().amplitudeZEM1();
multZEM2 = bc.zdc().amplitudeZEM2();
multZPA = bc.zdc().amplitudeZPA();
multZPC = bc.zdc().amplitudeZPC();
} else {
multZNA = -999.f;
multZNC = -999.f;
multZEM1 = -999.f;
multZEM2 = -999.f;
multZPA = -999.f;
multZPC = -999.f;
}
if (bc.has_fdd()) {
auto fdd = bc.fdd();
std::bitset<8> fFDDTriggers = fdd.triggerMask();
multFDDTriggerBits = static_cast<uint8_t>(fFDDTriggers.to_ulong());

for (auto amplitude : fdd.chargeA()) {
multFDDA += amplitude;
}
for (auto amplitude : fdd.chargeC()) {
multFDDC += amplitude;
}
} else {
multFDDA = -999.0f;
multFDDC = -999.0f;
}

if (multFT0C < minFT0CforBCTable) {
return; // skip this event
}
if (bc.has_zdc()) {
multZNA = bc.zdc().amplitudeZNA();
multZNC = bc.zdc().amplitudeZNC();
multZEM1 = bc.zdc().amplitudeZEM1();
multZEM2 = bc.zdc().amplitudeZEM2();
multZPA = bc.zdc().amplitudeZPA();
multZPC = bc.zdc().amplitudeZPC();
} else {
multZNA = -999.f;
multZNC = -999.f;
multZEM1 = -999.f;
multZEM2 = -999.f;
multZPA = -999.f;
multZPC = -999.f;
}

multBC(multFT0A, multFT0C, multFV0A, multFDDA, multFDDC, multZNA, multZNC, multZEM1, multZEM2, multZPA, multZPC, Tvx, isFV0OrA, multFV0TriggerBits, multFT0TriggerBits, multFDDTriggerBits, multBCTriggerMask, collidingBC);
bc2mult(bc2multArray[bc.globalIndex()]);
multBC(multFT0A, multFT0C, multFV0A, multFDDA, multFDDC, multZNA, multZNC, multZEM1, multZEM2, multZPA, multZPC, Tvx, isFV0OrA, multFV0TriggerBits, multFT0TriggerBits, multFDDTriggerBits, multBCTriggerMask, collidingBC);
}
}

void processCollisionNeighbors(aod::Collisions const& collisions)
Expand Down
6 changes: 3 additions & 3 deletions Common/TableProducer/multiplicityTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ struct MultiplicityTable {
tableExtra(collision.numContrib(), collision.chi2(), collision.collisionTimeRes(),
mRunNumber, collision.posZ(), collision.sel8(),
nHasITS, nHasTPC, nHasTOF, nHasTRD, nITSonly, nTPConly, nITSTPC,
nAllTracksTPCOnly, nAllTracksITSTPC, bcNumber, collision.trackOccupancyInTimeRange());
nAllTracksTPCOnly, nAllTracksITSTPC, collision.trackOccupancyInTimeRange());
} break;
case kMultSelections: // Multiplicity selections
{
Expand Down Expand Up @@ -627,7 +627,7 @@ struct MultiplicityTable {
Filter mcParticleFilter = (aod::mcparticle::eta < 4.9f) && (aod::mcparticle::eta > -3.3f);
using mcParticlesFiltered = soa::Filtered<aod::McParticles>;

void processMC(aod::McCollision const&, mcParticlesFiltered const& mcParticles)
void processMC(aod::McCollision const& mcCollision, mcParticlesFiltered const& mcParticles)
{
int multFT0A = 0;
int multFT0C = 0;
Expand Down Expand Up @@ -662,7 +662,7 @@ struct MultiplicityTable {
if (3.5 < mcPart.eta() && mcPart.eta() < 4.9)
multFT0A++;
}
tableExtraMc(multFT0A, multFT0C, multBarrelEta05, multBarrelEta08, multBarrelEta10);
tableExtraMc(multFT0A, multFT0C, multBarrelEta05, multBarrelEta08, multBarrelEta10, mcCollision.posZ());
}

Configurable<float> min_pt_globaltrack{"min_pt_globaltrack", 0.15, "min. pT for global tracks"};
Expand Down

0 comments on commit 3f92df7

Please sign in to comment.