Skip to content

Commit 572bd82

Browse files
committed
Fix indices bug in otf decayer
1 parent a1c0848 commit 572bd82

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

ALICE3/Core/OTFParticle.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <bitset>
2525
#include <cmath>
2626
#include <cstdint>
27+
#include <iostream>
2728
#include <span>
2829

2930
namespace o2::upgrade
@@ -88,6 +89,14 @@ class OTFParticle
8889
mPz = pz;
8990
mE = e;
9091
}
92+
void setIndexOffset(const std::size_t offset)
93+
{
94+
static constexpr int NotFound = -1;
95+
mIndicesMother[0] = (mIndicesMother[0] >= 0) ? mIndicesMother[0] + static_cast<int>(offset) : NotFound;
96+
mIndicesMother[1] = (mIndicesMother[1] >= 0) ? mIndicesMother[1] + static_cast<int>(offset) : NotFound;
97+
mIndicesDaughter[0] = (mIndicesDaughter[0] >= 0) ? mIndicesDaughter[0] + static_cast<int>(offset) : NotFound;
98+
mIndicesDaughter[1] = (mIndicesDaughter[1] >= 0) ? mIndicesDaughter[1] + static_cast<int>(offset) : NotFound;
99+
}
91100

92101
// Getters
93102
int pdgCode() const { return mPdgCode; }
@@ -171,7 +180,7 @@ class OTFParticle
171180

172181
private:
173182
int mPdgCode{}, mGlobalIndex{-1};
174-
int mCollisionId{};
183+
int mCollisionId{-1};
175184
float mVx{}, mVy{}, mVz{}, mVt{};
176185
float mPx{}, mPy{}, mPz{}, mE{};
177186
bool mIsAlive{}, mIsFromMcParticles{false};

ALICE3/TableProducer/OTF/onTheFlyDecayer.cxx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ struct OnTheFlyDecayer {
7979
o2::upgrade::Decayer decayer;
8080
Service<o2::framework::O2DatabasePDG> pdgDB;
8181
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
82+
std::vector<std::vector<int>> mcParticlesGrouped;
8283

8384
Configurable<int> seed{"seed", 0, "Set seed for particle decayer"};
8485
Configurable<float> magneticField{"magneticField", 20., "Magnetic field (kG)"};
8586
Configurable<LabeledArray<int>> enabledDecays{"enabledDecays",
8687
{DefaultParameters[0], NumDecays, NumParameters, ParticleNames, ParameterNames},
8788
"Enable option for particle to be decayed: 0 - no, 1 - yes"};
8889

90+
std::size_t indexOffset = 0;
8991
static constexpr float PicoToNano = 1.e-3f;
90-
int mCollisionId{-1};
91-
9292
std::vector<int> mEnabledDecays;
9393
void init(o2::framework::InitContext&)
9494
{
@@ -154,7 +154,7 @@ struct OnTheFlyDecayer {
154154
particle.setIndicesDaughter(allParticles.size(), allParticles.size() + (decayStack.size() - 1));
155155
for (o2::upgrade::OTFParticle daughter : decayStack) {
156156
daughter.setIndicesMother(i, i);
157-
daughter.setCollisionId(mCollisionId);
157+
daughter.setCollisionId(particle.collisionId());
158158
daughter.setBitOn(o2::upgrade::DecayerBits::IsAlive);
159159
daughter.setBitOff(o2::upgrade::DecayerBits::IsPrimary);
160160
daughter.setProductionTime(trackTimeNS);
@@ -173,18 +173,14 @@ struct OnTheFlyDecayer {
173173
void process(aod::McCollisions_001From<aod::Hash<"TMP"_h>>::iterator const& collision, aod::McParticles_001From<aod::Hash<"TMP"_h>> const& mcParticles)
174174
{
175175
allParticles.clear();
176+
if (collision.globalIndex() == 0) {
177+
indexOffset = 0;
178+
}
176179

177180
// Reproduce collision table to have AOD origin
178-
mCollisionId = collision.globalIndex();
179-
tableMcCollisions(collision.bcId(),
180-
collision.generatorsID(),
181-
collision.posX(),
182-
collision.posY(),
183-
collision.posZ(),
184-
collision.t(),
185-
collision.weight(),
186-
collision.impactParameter(),
187-
collision.eventPlaneAngle());
181+
tableMcCollisions(collision.bcId(), collision.generatorsID(),
182+
collision.posX(), collision.posY(), collision.posZ(), collision.t(),
183+
collision.weight(), collision.impactParameter(), collision.eventPlaneAngle());
188184

189185
// First we copy the particles from the table into a vector that is extendable
190186
for (const auto& particle : mcParticles) {
@@ -195,7 +191,8 @@ struct OnTheFlyDecayer {
195191
decayParticles(0, allParticles.size());
196192

197193
// Fill output table
198-
for (const auto& otfParticle : allParticles) {
194+
for (auto& otfParticle : allParticles) {
195+
otfParticle.setIndexOffset(indexOffset);
199196
if (otfParticle.hasNaN()) {
200197
histos.fill(HIST("hNaNBookkeeping"), 1);
201198
} else {
@@ -208,6 +205,11 @@ struct OnTheFlyDecayer {
208205
otfParticle.px(), otfParticle.py(), otfParticle.pz(), otfParticle.e(),
209206
otfParticle.vx(), otfParticle.vy(), otfParticle.vz(), otfParticle.vt());
210207
}
208+
209+
// Particles for later collisions in df's needs to have thier mother
210+
// and daughter indices adjusted since their global index will be
211+
// shifted due to the appending of decay products
212+
indexOffset += allParticles.size();
211213
}
212214
};
213215

0 commit comments

Comments
 (0)