Skip to content

Commit f19a6ee

Browse files
author
Aswathy Menon
committed
Committing older uncom changes
1 parent 6178aee commit f19a6ee

4 files changed

Lines changed: 213 additions & 5 deletions

File tree

‎PWGDQ/Core/VarManager.cxx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ void VarManager::SetDefaultVarNames()
816816
fgVariableUnits[kMultDimuonsME] = "";
817817
fgVariableNames[kCentFT0C] = "Centrality FT0C";
818818
fgVariableUnits[kCentFT0C] = "%";
819+
fgVariableNames[kSpherocity] = "Spherocity"; // transverse spherocity
820+
fgVariableUnits[kSpherocity] = "";
821+
fgVariableNames[kSpherocityPtWeighted] = "SpherocityPtWeighted"; // pT-weighted transverse spherocity
822+
fgVariableUnits[kSpherocityPtWeighted] = "";
819823
fgVariableNames[kMCEventGeneratorId] = "MC Generator ID";
820824
fgVariableNames[kMCEventSubGeneratorId] = "MC SubGenerator ID";
821825
fgVariableNames[kMCVtxX] = "MC Vtx X";
@@ -2096,6 +2100,8 @@ void VarManager::SetDefaultVarNames()
20962100
fgVarNamesMap["kVtxChi2"] = kVtxChi2;
20972101
fgVarNamesMap["kCentVZERO"] = kCentVZERO;
20982102
fgVarNamesMap["kCentFT0C"] = kCentFT0C;
2103+
fgVarNamesMap["kSpherocity"] = kSpherocity; // transverse spherocity
2104+
fgVarNamesMap["kSpherocityPtWeighted"] = kSpherocityPtWeighted; // pT-weighted transverse spherocity
20992105
fgVarNamesMap["kCentFT0A"] = kCentFT0A;
21002106
fgVarNamesMap["kCentFT0M"] = kCentFT0M;
21012107
fgVarNamesMap["kMultTPC"] = kMultTPC;

‎PWGDQ/Core/VarManager.h‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class VarManager : public TObject
118118
RapidityGapFilter = BIT(21),
119119
Fit = BIT(22),
120120
ReducedFit = BIT(23),
121+
ReducedEventSpherocity = BIT(24), // Achu-Changes
121122
Track = BIT(0),
122123
TrackCov = BIT(1),
123124
TrackExtra = BIT(2),
@@ -283,6 +284,8 @@ class VarManager : public TObject
283284
kMultNTracksITSTPC,
284285
kMultNTracksPVeta1,
285286
kMultNTracksPVetaHalf,
287+
kSpherocity, // transverse spherocity
288+
kSpherocityPtWeighted, // pT-weighted transverse spherocity
286289
kTrackOccupancyInTimeRange,
287290
kFT0COccupancyInTimeRange,
288291
kNoCollInTimeRangeStandard,
@@ -1438,6 +1441,12 @@ class VarManager : public TObject
14381441
{
14391442
return RecoDecay::constrainAngle(psi1 - psi2, -o2::constants::math::PI / harmonic, harmonic);
14401443
}
1444+
1445+
// Spherocity function declaration--Start
1446+
template <typename T>
1447+
static float CalculateSpherocity(T const & tracks, float ptMin = 0.15, float ptMax = 10.0, float etaMin = -0.8, float etaMax = 0.8, int minMult = 10, bool usePtWeight = false);
1448+
//------------------------------------End
1449+
14411450
template <typename T, typename T1>
14421451
static o2::dataformats::VertexBase RecalculatePrimaryVertex(T const& track0, T const& track1, const T1& collision);
14431452

@@ -2316,6 +2325,11 @@ void VarManager::FillEvent(T const& event, float* values)
23162325
}
23172326
}
23182327

2328+
if constexpr ((fillMap & ObjTypes::ReducedEventSpherocity) > 0) {
2329+
values[kSpherocity] = event.spherocity();
2330+
values[kSpherocityPtWeighted] = event.spherocityPtWeighted();
2331+
}
2332+
23192333
if constexpr ((fillMap & ReducedEventVtxCov) > 0) {
23202334
values[kVtxCovXX] = event.covXX();
23212335
values[kVtxCovXY] = event.covXY();
@@ -7996,5 +8010,83 @@ void VarManager::FillTripletVertexingALICE3(C const& collision, T const& t1, T c
79968010
values[kVertexingTauxyzProjected] = values[kVertexingLxyzProjected] * v123.M() / (v123.P());
79978011
}
79988012
}
8013+
template <typename T>
8014+
float VarManager::CalculateSpherocity(T const& tracks, float ptMin, float ptMax, float etaMin, float etaMax, int minMult, bool usePtWeight)
8015+
{
8016+
LOGF(info, " >>> CalculateSpherocity CALLED: ptMin=%.2f, ptMax=%.2f, etaMin=%.2f, etaMax=%.2f, minMult=%d, usePtWeight=%s",
8017+
ptMin, ptMax, etaMin, etaMax, minMult, usePtWeight ? "true" : "false");
8018+
8019+
std::vector<float> pxNorm;
8020+
std::vector<float> pyNorm;
8021+
std::vector<float> ptValues;
8022+
float sumPt = 0.0;
8023+
int nTracks = 0;
8024+
8025+
// Collect valid tracks
8026+
for (const auto& track : tracks) {
8027+
float pt = track.pt();
8028+
float eta = track.eta();
8029+
8030+
if (pt < ptMin || pt > ptMax) continue;
8031+
if (eta < etaMin || eta > etaMax) continue;
8032+
8033+
float px = track.px();
8034+
float py = track.py();
8035+
8036+
if (pt <= 0.f) {
8037+
continue;
8038+
}
8039+
pxNorm.push_back(px / pt);
8040+
pyNorm.push_back(py / pt);
8041+
ptValues.push_back(pt);
8042+
sumPt += pt;
8043+
nTracks++;
8044+
}
8045+
8046+
// Check minimum multiplicity
8047+
if (nTracks < minMult) {
8048+
return -1.0f;
8049+
}
8050+
8051+
// Minimize over azimuthal angle
8052+
float spherocity = 5.0f; //float prevSpherocity = 5.0f; const float convergenceThreshold = 1e-4f;
8053+
const int nSteps = 360;
8054+
8055+
for (int iStep = 0; iStep < nSteps; iStep++) {
8056+
float phi = 2.0f * M_PI * static_cast<float>(iStep) / static_cast<float>(nSteps);
8057+
float nx = std::cos(phi);
8058+
float ny = std::sin(phi);
8059+
8060+
float numerator = 0.0f;
8061+
float denominator = 0.0f;
8062+
8063+
for (int iTrk = 0; iTrk < nTracks; iTrk++) {
8064+
// Cross product magnitude: |p_T x n| = |px*ny - py*nx|
8065+
float crossProduct = std::abs(pxNorm[iTrk] * ny - pyNorm[iTrk] * nx);
8066+
8067+
if (usePtWeight) {
8068+
numerator += ptValues[iTrk] * crossProduct;
8069+
denominator += ptValues[iTrk];
8070+
} else {
8071+
numerator += crossProduct;
8072+
denominator += 1.0f;
8073+
}
8074+
}
8075+
8076+
float sph = std::pow(numerator / denominator, 2);
8077+
if (sph < spherocity) {
8078+
spherocity = sph;
8079+
}
8080+
// // Early exit if converged
8081+
// if (iStep > 10 && std::abs(spherocity - prevSpherocity) < convergenceThreshold) {
8082+
// break;
8083+
// }
8084+
// prevSpherocity = spherocity;
8085+
}
8086+
8087+
spherocity *= (M_PI * M_PI / 4.0f);
8088+
return spherocity;
8089+
}
8090+
79998091

80008092
#endif // PWGDQ_CORE_VARMANAGER_H_

‎PWGDQ/DataModel/ReducedInfoTables.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ DECLARE_SOA_COLUMN(NTPCoccupMeanTimeShortA, nTPCoccupMeanTimeShortA, float);
6969
DECLARE_SOA_COLUMN(NTPCoccupMeanTimeShortC, nTPCoccupMeanTimeShortC, float); //! TPC pileup mean time on C side (short time range)
7070
DECLARE_SOA_COLUMN(NTPCoccupMedianTimeShortA, nTPCoccupMedianTimeShortA, float); //! TPC pileup median time on A side (short time range)
7171
DECLARE_SOA_COLUMN(NTPCoccupMedianTimeShortC, nTPCoccupMedianTimeShortC, float); //! TPC pileup median time on C side (short time range)
72+
DECLARE_SOA_COLUMN(Spherocity, spherocity, float); //! transverse spherocity
73+
DECLARE_SOA_COLUMN(SpherocityPtWeighted, spherocityPtWeighted, float); //! pT-weighted transverse spherocity// namespace reducedevent
7274
DECLARE_SOA_COLUMN(DCAzBimodalityCoefficient, dcazBimodalityCoefficient, float); //! Bimodality coefficient of the DCAz distribution of the tracks in the event
7375
DECLARE_SOA_COLUMN(DCAzBimodalityCoefficientBinned, dcazBimodalityCoefficientBinned, float); //! Bimodality coefficient of the DCAz distribution of the tracks in the event, binned
7476
DECLARE_SOA_COLUMN(DCAzBimodalityCoefficientBinnedTrimmed1, dcazBimodalityCoefficientBinnedTrimmed1, float); //! Bimodality coefficient of the DCAz distribution of the tracks in the event, binned and trimmed 1
@@ -177,7 +179,23 @@ DECLARE_SOA_TABLE_VERSIONED(ReducedEventsExtended_001, "AOD", "REEXTENDED", 1, /
177179
mult::MultFDDA, mult::MultFDDC, mult::MultZNA, mult::MultZNC, mult::MultTracklets, mult::MultNTracksPV,
178180
cent::CentFT0C, cent::CentFT0A, cent::CentFT0M);
179181

182+
DECLARE_SOA_TABLE_VERSIONED(ReducedEventsExtended_002, "AOD", "REEXTENDED", 2, //! Extended event information
183+
bc::GlobalBC, evsel::Alias, evsel::Selection, timestamp::Timestamp, cent::CentRun2V0M,
184+
mult::MultTPC, mult::MultFV0A, mult::MultFV0C, mult::MultFT0A, mult::MultFT0C,
185+
mult::MultFDDA, mult::MultFDDC, mult::MultZNA, mult::MultZNC, mult::MultTracklets, mult::MultNTracksPV,
186+
cent::CentFT0C, cent::CentFT0A, cent::CentFT0M,
187+
reducedevent::Spherocity,
188+
reducedevent::SpherocityPtWeighted);
189+
180190
using ReducedEventsExtended = ReducedEventsExtended_001;
191+
// using ReducedEventsExtended = ReducedEventsExtended_002;
192+
193+
// // In ReducedInfoTables.h, add this after the ReducedEventsExtended declaration
194+
// DECLARE_SOA_TABLE(ReducedEventsSpherocity, "AOD", "RESPHEROCITY",
195+
// reducedevent::Spherocity,
196+
// reducedevent::SpherocityPtWeighted);
197+
198+
// using ReducedEventSphero = ReducedEventsSpherocity::iterator;
181199

182200
DECLARE_SOA_TABLE(ReducedEventsMultPV_000, "AOD", "REMULTPV", //! Multiplicity information for primary vertex
183201
mult::MultNTracksHasITS, mult::MultNTracksHasTPC, mult::MultNTracksHasTOF, mult::MultNTracksHasTRD,

‎PWGDQ/TableProducer/tableMaker_withAssoc.cxx‎

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ struct TableMaker {
222222
// Q-vector related tables, to be filled only if the user selects the corresponding option
223223
Produces<ReducedEventsQvectorCentr> eventQvectorCentr;
224224
Produces<ReducedEventsQvectorCentrExtra> eventQvectorCentrExtra;
225+
Produces<ReducedEventsSpherocity> eventSpherocity; // Achu-Changes
225226
} outTables;
226227

227228
OutputObj<THashList> fOutputList{"output"}; //! the histogram manager output list
@@ -333,6 +334,16 @@ struct TableMaker {
333334
Configurable<bool> fExcludeShort{"cfgTPCExcludeShort", true, "Exclude short term from long term occupancy (micro-seconds)"};
334335
} fConfigVariousOptions;
335336

337+
// Spherocity configurables
338+
struct : ConfigurableGroup {
339+
Configurable<float> fConfigSpherocityPtMin{"cfgSpherocityPtMin", 0.15f, "Min pT for spherocity calculation"};
340+
Configurable<float> fConfigSpherocityPtMax{"cfgSpherocityPtMax", 10.0f, "Max pT for spherocity calculation"};
341+
Configurable<float> fConfigSpherocityEtaMin{"cfgSpherocityEtaMin", -0.8f, "Min eta for spherocity calculation"};
342+
Configurable<float> fConfigSpherocityEtaMax{"cfgSpherocityEtaMax", 0.8f, "Max eta for spherocity calculation"};
343+
Configurable<int> fConfigSpherocityMinMult{"cfgSpherocityMinMult", 5, "Min multiplicity for spherocity calculation"};
344+
Configurable<bool> fConfigSpherocityUsePtWeight{"cfgSpherocityUsePtWeight", false, "Use pT weighting for spherocity"};
345+
} fConfigSpherocity;
346+
336347
Service<o2::ccdb::BasicCCDBManager> fCCDB{};
337348
o2::ccdb::CcdbApi fCCDBApi;
338349

@@ -1033,15 +1044,22 @@ struct TableMaker {
10331044
}
10341045
}
10351046

1036-
template <uint32_t TEventFillMap, typename TEvents, typename TBCs,
1037-
typename TZdcs, typename TFt0s, typename TFv0as, typename TFdds>
1047+
template <uint32_t TEventFillMap, uint32_t TTrackFillMap, typename TEvents, typename TBCs,
1048+
typename TZdcs, typename TFt0s, typename TFv0as, typename TFdds, typename TTrackAssoc, typename TTracks>
10381049
void skimCollisions(TEvents const& collisions, TBCs const& bcs, TZdcs const& /*zdcs*/,
1039-
TFt0s const& ft0s, TFv0as const& fv0as, TFdds const& fdds)
1050+
TFt0s const& ft0s, TFv0as const& fv0as, TFdds const& fdds,
1051+
TTrackAssoc const& trackAssocs, TTracks const& tracksBarrel)
10401052
{
10411053
// Skim collisions
10421054
// NOTE: So far, collisions are filtered based on the user specified analysis cuts AND the filterPP or Zorro event filter.
10431055
// The collision-track associations which point to an event that is not selected for writing are discarded!
10441056

1057+
LOGF(info, "=== skimCollisions CALLED ===");
1058+
LOGF(info, "TEventFillMap = %u", TEventFillMap);
1059+
LOGF(info, "TTrackFillMap = %u", TTrackFillMap);
1060+
LOGF(info, "TTrackFillMap is zero: %s", TTrackFillMap == 0 ? "TRUE" : "FALSE");
1061+
LOGF(info, "Number of collisions = %d", static_cast<int>(collisions.size()));
1062+
10451063
VarManager::FillTimeFrame(collisions);
10461064
fCollIndexMap.clear();
10471065
int multTPC = -1.0;
@@ -1222,6 +1240,78 @@ struct TableMaker {
12221240
}
12231241
(dynamic_cast<TH2D*>(fStatsList->At(kStatsEvent)))->Fill(3.0, static_cast<float>(o2::aod::evsel::kNsel));
12241242

1243+
// Calculate spherocity for this collision
1244+
float spherocityValue = -1.0f;
1245+
float spherocityPtWeighted = -1.0f;
1246+
1247+
if constexpr (static_cast<bool>(TTrackFillMap)) {
1248+
// DIAGNOSTIC: Check table sizes
1249+
LOGF(info, "=== skimCollisions DIAGNOSTIC ===");
1250+
LOGF(info, "Total collisions: %d", static_cast<int>(collisions.size()));
1251+
LOGF(info, "Total tracksBarrel: %d", static_cast<int>(tracksBarrel.size()));
1252+
LOGF(info, "Total trackAssocs: %d", static_cast<int>(trackAssocs.size()));
1253+
LOGF(info, "================================");
1254+
1255+
LOGF(info, ">>> Collision %d: TTrackFillMap check PASSED", collision.globalIndex());
1256+
1257+
auto groupedTrackIndices = trackAssocs.sliceBy(trackIndicesPerCollision, collision.globalIndex());
1258+
LOGF(info, ">>> Collision %d: groupedTrackIndices.size() = %d",
1259+
collision.globalIndex(), static_cast<int>(groupedTrackIndices.size()));
1260+
1261+
if (static_cast<int>(groupedTrackIndices.size()) >= fConfigSpherocity.fConfigSpherocityMinMult) {
1262+
LOGF(info, ">>> Collision %d: PASSED multiplicity check, collecting tracks...",
1263+
collision.globalIndex());
1264+
1265+
std::vector<typename std::decay_t<decltype(tracksBarrel.begin())>> trackVec;
1266+
trackVec.reserve(groupedTrackIndices.size());
1267+
1268+
int validTracks = 0;
1269+
for (auto const& assoc : groupedTrackIndices) {
1270+
if (assoc.trackId() < tracksBarrel.size()) {
1271+
auto track = tracksBarrel.rawIteratorAt(assoc.trackId());
1272+
trackVec.push_back(track);
1273+
validTracks++;
1274+
}
1275+
}
1276+
1277+
LOGF(info, ">>> Collision %d: Collected %d valid tracks",
1278+
collision.globalIndex(), validTracks);
1279+
1280+
if (validTracks >= fConfigSpherocity.fConfigSpherocityMinMult) {
1281+
// Calculate unweighted spherocity
1282+
spherocityValue = VarManager::CalculateSpherocity(
1283+
trackVec,
1284+
fConfigSpherocity.fConfigSpherocityPtMin,
1285+
fConfigSpherocity.fConfigSpherocityPtMax,
1286+
fConfigSpherocity.fConfigSpherocityEtaMin,
1287+
fConfigSpherocity.fConfigSpherocityEtaMax,
1288+
fConfigSpherocity.fConfigSpherocityMinMult,
1289+
false);
1290+
1291+
// Calculate pT-weighted spherocity
1292+
spherocityPtWeighted = VarManager::CalculateSpherocity(
1293+
trackVec,
1294+
fConfigSpherocity.fConfigSpherocityPtMin,
1295+
fConfigSpherocity.fConfigSpherocityPtMax,
1296+
fConfigSpherocity.fConfigSpherocityEtaMin,
1297+
fConfigSpherocity.fConfigSpherocityEtaMax,
1298+
fConfigSpherocity.fConfigSpherocityMinMult,
1299+
true);
1300+
1301+
LOGF(info, "Event %d: Spherocity = %.3f, pT-weighted = %.3f, nTracks = %d",
1302+
collision.globalIndex(), spherocityValue, spherocityPtWeighted, validTracks);
1303+
}
1304+
}
1305+
}
1306+
1307+
// CRITICAL: Fill VarManager::fgValues so histograms can be filled!
1308+
VarManager::fgValues[VarManager::kSpherocity] = spherocityValue;
1309+
VarManager::fgValues[VarManager::kSpherocityPtWeighted] = spherocityPtWeighted;
1310+
LOGF(info, "Filled VarManager: Spherocity = %.3f, pT-weighted = %.3f",
1311+
VarManager::fgValues[VarManager::kSpherocity],
1312+
VarManager::fgValues[VarManager::kSpherocityPtWeighted]);
1313+
1314+
// fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
12251315
fHistMan->FillHistClass("Event_AfterCuts", dqtablemaker_helpers::varValues());
12261316

12271317
// create the event tables
@@ -1245,9 +1335,10 @@ struct TableMaker {
12451335
centFT0M = collision.centFT0M();
12461336
}
12471337
outTables.eventExtended(bc.globalBC(), collision.alias_raw(), collision.selection_raw(), bc.timestamp(), VarManager::fgValues[VarManager::kCentVZERO],
1248-
multTPC, multFV0A, multFV0C, multFT0A, multFT0C, multFDDA, multFDDC, multZNA, multZNC, multTracklets, multTracksPV, centFT0C, centFT0A, centFT0M);
1338+
multTPC, multFV0A, multFV0C, multFT0A, multFT0C, multFDDA, multFDDC, multZNA, multZNC, multTracklets, multTracksPV, centFT0C, centFT0A, centFT0M, spherocityValue, spherocityPtWeighted);
12491339
outTables.eventVtxCov(collision.covXX(), collision.covXY(), collision.covXZ(), collision.covYY(), collision.covYZ(), collision.covZZ(), collision.chi2());
12501340
outTables.eventInfo(collision.globalIndex());
1341+
outTables.eventSpherocity(spherocityValue, spherocityPtWeighted);
12511342

12521343
if constexpr ((TEventFillMap & VarManager::ObjTypes::CollisionQvectCentr) > 0) {
12531344
if (fConfigQvector.fConfigQvectCalibAvailable) {
@@ -1914,8 +2005,9 @@ struct TableMaker {
19142005
outTables.event.reserve(collisions.size());
19152006
outTables.eventExtended.reserve(collisions.size());
19162007
outTables.eventVtxCov.reserve(collisions.size());
2008+
outTables.eventSpherocity.reserve(collisions.size()); // ADD THIS LINE//Achu-Changes
19172009

1918-
skimCollisions<TEventFillMap>(collisions, bcs, zdcs, ft0s, fv0as, fdds);
2010+
skimCollisions<TEventFillMap, TTrackFillMap>(collisions, bcs, zdcs, ft0s, fv0as, fdds, trackAssocs, tracksBarrel);
19192011
if (fCollIndexMap.empty()) {
19202012
return;
19212013
}

0 commit comments

Comments
 (0)