Skip to content

Commit 00d8238

Browse files
committed
Autodetect and other changes
1 parent bcf2104 commit 00d8238

File tree

2 files changed

+111
-34
lines changed

2 files changed

+111
-34
lines changed

PWGLF/TableProducer/Strangeness/strangenessbuilder.cxx

Lines changed: 111 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,47 @@ struct StrangenessBuilder {
464464

465465
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
466466

467-
void init(InitContext&)
467+
void init(InitContext& context)
468468
{
469469
mRunNumber = 0;
470470

471471
mEnabledTables.resize(nTables, 0);
472472

473+
LOGF(info, "Configuring tables to generate");
474+
auto& workflows = context.services().get<RunningWorkflowInfo const>();
475+
473476
for (int i = 0; i < nTables; i++) {
474477
int f = enabledTables->get(tableNames[i].c_str(), "enable");
475478
if (f == 1) {
476479
mEnabledTables[i] = 1;
477-
LOGF(info, "Enabled table: %s", tableNames[i].c_str());
480+
}
481+
if( f == -1){
482+
// autodetect this table in other devices
483+
for (DeviceSpec const& device : workflows.devices) {
484+
// Step 1: check if this device subscribed to the V0data table
485+
for (auto const& input : device.inputs) {
486+
if (device.name.compare("strangenessbuilder-initializer") == 0)
487+
continue; // don't listen to the initializer
488+
if (input.matcher.binding == tableNames[i]) {
489+
LOGF(info, "Device %s has subscribed to %s", device.name, tableNames[i]);
490+
mEnabledTables[i] = 1;
491+
}
492+
}
493+
}
494+
}
495+
}
496+
497+
// list enabled tables
498+
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
499+
LOGF(info, " Strangeness builder: enabled table listing");
500+
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
501+
for (int i = 0; i < nTables; i++) {
502+
// printout to be improved in the future
503+
if(mEnabledTables[i]){
504+
LOGF(info, "Table enabled: %s", tableNames[i]);
478505
}
479506
}
507+
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
480508

481509
ccdb->setURL(ccdbConfigurations.ccdburl);
482510
ccdb->setCaching(true);
@@ -578,8 +606,8 @@ struct StrangenessBuilder {
578606
}
579607

580608
//__________________________________________________
581-
template <class TTracks, typename TCollisions, typename TV0s, typename TMCParticles>
582-
void buildV0s(TCollisions const& collisions, TV0s const& v0s, TMCParticles const& mcParticles)
609+
template <class TTracks, typename TV0s, typename TMCParticles>
610+
void buildV0s(TV0s const& v0s, TMCParticles const& mcParticles)
583611
{
584612
// prepare MC containers (not necessarily used)
585613
std::vector<mcV0info> mcV0infos; // V0MCCore information
@@ -603,7 +631,7 @@ struct StrangenessBuilder {
603631
auto const& collision = v0.collision();
604632
auto const& posTrack = v0.template posTrack_as<TTracks>();
605633
auto const& negTrack = v0.template negTrack_as<TTracks>();
606-
if(!straHelper.buildV0Candidate(collision, posTrack, negTrack, v0.isCollinearV0())){
634+
if(!straHelper.buildV0Candidate(collision, posTrack, negTrack, v0.isCollinearV0(), mEnabledTables[kV0Covs])){
607635
v0dataLink(-1, -1);
608636
continue;
609637
}
@@ -653,6 +681,9 @@ struct StrangenessBuilder {
653681
v0dauPositionsIU(positivePositionIU[0], positivePositionIU[1], positivePositionIU[2],
654682
negativePositionIU[0], negativePositionIU[1], negativePositionIU[2]);
655683
}
684+
if(mEnabledTables[kV0Covs]){
685+
v0covs(straHelper.v0.positionCovariance, straHelper.v0.momentumCovariance);
686+
}
656687

657688
//_________________________________________________________
658689
// MC handling part
@@ -981,8 +1012,8 @@ struct StrangenessBuilder {
9811012
}
9821013

9831014
//__________________________________________________
984-
template <class TTracks, typename TCollisions, typename TCascades, typename TMCParticles>
985-
void buildCascades(TCollisions const& collisions, TCascades const& cascades, TMCParticles const& mcParticles)
1015+
template <class TTracks, typename TCascades, typename TMCParticles>
1016+
void buildCascades(TCascades const& cascades, TMCParticles const& mcParticles)
9861017
{
9871018
// prepare MC containers (not necessarily used)
9881019
std::vector<mcCascinfo> mcCascinfos; // V0MCCore information
@@ -1108,6 +1139,45 @@ struct StrangenessBuilder {
11081139
}
11091140

11101141
} // enabled tables check
1142+
1143+
// if BB tags requested, generate them now
1144+
if(mEnabledTables[kMcCascBBTags]){
1145+
bool bbTag = false;
1146+
if (bachTrack.has_mcParticle()) {
1147+
auto bachelorParticle = bachTrack.template mcParticle_as<aod::McParticles>();
1148+
if (bachelorParticle.pdgCode() == 211) { // pi+, look for antiproton in negative prong
1149+
if (negTrack.has_mcParticle()) {
1150+
auto baryonParticle = negTrack.template mcParticle_as<aod::McParticles>();
1151+
if (baryonParticle.has_mothers() && bachelorParticle.has_mothers() && baryonParticle.pdgCode() == -2212) {
1152+
for (auto& baryonMother : baryonParticle.template mothers_as<aod::McParticles>()) {
1153+
for (auto& pionMother : bachelorParticle.template mothers_as<aod::McParticles>()) {
1154+
if (baryonMother.globalIndex() == pionMother.globalIndex() && baryonMother.pdgCode() == -3122) {
1155+
bbTag = true;
1156+
}
1157+
}
1158+
}
1159+
}
1160+
}
1161+
} // end if-pion
1162+
if (bachelorParticle.pdgCode() == -211) { // pi-, look for proton in positive prong
1163+
if (posTrack.has_mcParticle()) {
1164+
auto baryonParticle = posTrack.template mcParticle_as<aod::McParticles>();
1165+
if (baryonParticle.has_mothers() && bachelorParticle.has_mothers() && baryonParticle.pdgCode() == 2212) {
1166+
for (auto& baryonMother : baryonParticle.template mothers_as<aod::McParticles>()) {
1167+
for (auto& pionMother : bachelorParticle.template mothers_as<aod::McParticles>()) {
1168+
if (baryonMother.globalIndex() == pionMother.globalIndex() && baryonMother.pdgCode() == 3122) {
1169+
bbTag = true;
1170+
}
1171+
}
1172+
}
1173+
}
1174+
}
1175+
} // end if-pion
1176+
} // end bachelor has mcparticle
1177+
// Construct label table (note: this will be joinable with CascDatas)
1178+
bbtags(bbTag);
1179+
} // end BB tag table enabled check
1180+
11111181
} // constexpr requires mcParticles check
11121182
} // cascades loop
11131183

@@ -1208,20 +1278,20 @@ struct StrangenessBuilder {
12081278
}
12091279
}
12101280

1211-
for (auto thisInfo : mcCascinfos) {
1281+
for (auto thisInfoToFill : mcCascinfos) {
12121282
if(mEnabledTables[kCascMCCores]){
12131283
cascmccores( // a lot of the info below will be compressed in case of not-recoed MC (good!)
1214-
thisCascInfo.pdgCode, thisCascInfo.pdgCodeMother, thisCascInfo.pdgCodeV0, thisCascInfo.isPhysicalPrimary,
1215-
thisCascInfo.pdgCodePositive, thisCascInfo.pdgCodeNegative, thisCascInfo.pdgCodeBachelor,
1216-
thisCascInfo.xyz[0], thisCascInfo.xyz[1], thisCascInfo.xyz[2],
1217-
thisCascInfo.lxyz[0], thisCascInfo.lxyz[1], thisCascInfo.lxyz[2],
1218-
thisCascInfo.posP[0], thisCascInfo.posP[1], thisCascInfo.posP[2],
1219-
thisCascInfo.negP[0], thisCascInfo.negP[1], thisCascInfo.negP[2],
1220-
thisCascInfo.bachP[0], thisCascInfo.bachP[1], thisCascInfo.bachP[2],
1221-
thisCascInfo.momentum[0], thisCascInfo.momentum[1], thisCascInfo.momentum[2]);
1284+
thisInfoToFill.pdgCode, thisInfoToFill.pdgCodeMother, thisInfoToFill.pdgCodeV0, thisInfoToFill.isPhysicalPrimary,
1285+
thisInfoToFill.pdgCodePositive, thisInfoToFill.pdgCodeNegative, thisInfoToFill.pdgCodeBachelor,
1286+
thisInfoToFill.xyz[0], thisInfoToFill.xyz[1], thisInfoToFill.xyz[2],
1287+
thisInfoToFill.lxyz[0], thisInfoToFill.lxyz[1], thisInfoToFill.lxyz[2],
1288+
thisInfoToFill.posP[0], thisInfoToFill.posP[1], thisInfoToFill.posP[2],
1289+
thisInfoToFill.negP[0], thisInfoToFill.negP[1], thisInfoToFill.negP[2],
1290+
thisInfoToFill.bachP[0], thisInfoToFill.bachP[1], thisInfoToFill.bachP[2],
1291+
thisInfoToFill.momentum[0], thisInfoToFill.momentum[1], thisInfoToFill.momentum[2]);
12221292
}
12231293
if(mEnabledTables[kCascMCCollRefs]){
1224-
cascmccollrefs(thisCascInfo.mcCollision);
1294+
cascmccollrefs(thisInfoToFill.mcCollision);
12251295
}
12261296
}
12271297
}
@@ -1232,8 +1302,8 @@ struct StrangenessBuilder {
12321302
}
12331303

12341304
//__________________________________________________
1235-
template <class TTracks, typename TCollisions, typename TCascades, typename TMCParticles>
1236-
void buildKFCascades(TCollisions const& collisions, TCascades const& cascades, TMCParticles const& mcParticles)
1305+
template <class TTracks, typename TCascades, typename TMCParticles>
1306+
void buildKFCascades(TCascades const& cascades, TMCParticles const& mcParticles)
12371307
{
12381308
if(!mEnabledTables[kStoredKFCascCores]){
12391309
return; // don't do if no request for cascades in place
@@ -1311,8 +1381,8 @@ struct StrangenessBuilder {
13111381
}
13121382

13131383
//__________________________________________________
1314-
template <class TTracks, typename TCollisions, typename TStrangeTracks, typename TMCParticles>
1315-
void buildTrackedCascades(TCollisions const& collisions, TStrangeTracks const& cascadeTracks, TMCParticles const& mcParticles)
1384+
template <class TTracks, typename TStrangeTracks, typename TMCParticles>
1385+
void buildTrackedCascades(TStrangeTracks const& cascadeTracks, TMCParticles const& mcParticles)
13161386
{
13171387
if(!mEnabledTables[kStoredTraCascCores]){
13181388
return; // don't do if no request for cascades in place
@@ -1449,15 +1519,15 @@ struct StrangenessBuilder {
14491519
markV0sUsedInCascades(v0s, cascades);
14501520

14511521
// build V0s
1452-
buildV0s<TTracks>(collisions, v0s, mcParticles);
1522+
buildV0s<TTracks>(v0s, mcParticles);
14531523

14541524
// build cascades
1455-
buildCascades<TTracks>(collisions, cascades, mcParticles);
1456-
buildKFCascades<TTracks>(collisions, cascades, mcParticles);
1525+
buildCascades<TTracks>(cascades, mcParticles);
1526+
buildKFCascades<TTracks>(cascades, mcParticles);
14571527

14581528
// build tracked cascades only if subscription is Run 3 like (doesn't exist in Run 2)
14591529
if constexpr (requires { TTrackedCascades::iterator; }) {
1460-
buildTrackedCascades<TTracks>(collisions, trackedCascades, mcParticles);
1530+
buildTrackedCascades<TTracks>(trackedCascades, mcParticles);
14611531
}
14621532

14631533
populateCascadeInterlinks();
@@ -1468,7 +1538,7 @@ struct StrangenessBuilder {
14681538
dataProcess(collisions, v0s, cascades, trackedCascades, tracks, bcs, (TObject*) nullptr);
14691539
}
14701540

1471-
void processRealDataRun2(aod::Collisions const& collisions, aod::V0s const& v0s, aod::Cascades const& cascades, aod::TrackedCascades const& trackedCascades, FullTracksExt const& tracks, aod::BCsWithTimestamps const& bcs)
1541+
void processRealDataRun2(aod::Collisions const& collisions, aod::V0s const& v0s, aod::Cascades const& cascades, FullTracksExt const& tracks, aod::BCsWithTimestamps const& bcs)
14721542
{
14731543
dataProcess(collisions, v0s, cascades, (TObject*) nullptr, tracks, bcs, (TObject*) nullptr);
14741544
}
@@ -1478,9 +1548,9 @@ struct StrangenessBuilder {
14781548
dataProcess(collisions, v0s, cascades, trackedCascades, tracks, bcs, mcParticles);
14791549
}
14801550

1481-
void processMonteCarloRun2(aod::Collisions const& collisions, aod::V0s const& v0s, aod::Cascades const& cascades, aod::TrackedCascades const& trackedCascades, FullTracksExtLabeled const& tracks, aod::BCsWithTimestamps const& bcs, aod::McParticles const& mcParticles)
1551+
void processMonteCarloRun2(aod::Collisions const& collisions, aod::V0s const& v0s, aod::Cascades const& cascades, FullTracksExtLabeled const& tracks, aod::BCsWithTimestamps const& bcs, aod::McParticles const& mcParticles)
14821552
{
1483-
dataProcess(collisions, v0s, cascades, trackedCascades, tracks, bcs, mcParticles);
1553+
dataProcess(collisions, v0s, cascades, (TObject*) nullptr, tracks, bcs, mcParticles);
14841554
}
14851555

14861556
void processSimulationFindable(aod::Collisions const& collisions, aod::FindableV0s const& v0s, aod::Cascades const& cascades, FullTracksExtIU const& tracks, aod::BCsWithTimestamps const& bcs)
@@ -1490,13 +1560,23 @@ struct StrangenessBuilder {
14901560

14911561
PROCESS_SWITCH(StrangenessBuilder, processRealData, "process real data", true);
14921562
PROCESS_SWITCH(StrangenessBuilder, processRealDataRun2, "process real data (Run 2)", false);
1493-
PROCESS_SWITCH(StrangenessBuilder, processMonteCarlo, "process real data", true);
1494-
PROCESS_SWITCH(StrangenessBuilder, processMonteCarloRun2, "process real data (Run 2)", false);
1563+
PROCESS_SWITCH(StrangenessBuilder, processMonteCarlo, "process monte carlo", true);
1564+
PROCESS_SWITCH(StrangenessBuilder, processMonteCarloRun2, "process monte carlo (Run 2)", false);
14951565
PROCESS_SWITCH(StrangenessBuilder, processSimulationFindable, "process simulation findable (requires lambdakzeromcfinder)", false);
14961566
};
14971567

1568+
// Extends the v0data table with expression columns
1569+
struct strangenessbuilderInitializer {
1570+
Spawns<aod::V0Cores> v0cores;
1571+
Spawns<aod::CascCores> cascdataext;
1572+
Spawns<aod::KFCascCores> kfcascdataext;
1573+
Spawns<aod::TraCascCores> tracascdataext;
1574+
void init(InitContext const&) {}
1575+
};
1576+
14981577
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
14991578
{
15001579
return WorkflowSpec{
1501-
adaptAnalysisTask<StrangenessBuilder>(cfgc)};
1580+
adaptAnalysisTask<StrangenessBuilder>(cfgc),
1581+
adaptAnalysisTask<strangenessbuilderInitializer>(cfgc)};
15021582
}

PWGLF/Utils/strangenessBuilderHelper.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ class strangenessBuilderHelper
244244
v0.positionCovariance[5] = covVtxV(2, 2);
245245
std::array<float, 21> covTpositive = {0.};
246246
std::array<float, 21> covTnegative = {0.};
247-
// std::array<float, 6> momentumCovariance;
248-
float momentumCovariance[6];
249247
positiveTrackParam.getCovXYZPxPyPzGlo(covTpositive);
250248
negativeTrackParam.getCovXYZPxPyPzGlo(covTnegative);
251249
constexpr int MomInd[6] = {9, 13, 14, 18, 19, 20}; // cov matrix elements for momentum component
@@ -424,7 +422,6 @@ class strangenessBuilderHelper
424422
// store momentum covariance matrix
425423
std::array<float, 21> covTv0 = {0.};
426424
std::array<float, 21> covTbachelor = {0.};
427-
float covCascade[21];
428425
// std::array<float, 6> momentumCovariance;
429426
lV0Track.getCovXYZPxPyPzGlo(covTv0);
430427
lBachelorTrack.getCovXYZPxPyPzGlo(covTbachelor);

0 commit comments

Comments
 (0)