1919#include "ALICE3/Core/TrackUtilities.h"
2020#include "ALICE3/DataModel/OTFMCParticle.h"
2121
22- #include <CCDB/BasicCCDBManager.h>
2322#include <CommonConstants/MathConstants.h>
2423#include <CommonConstants/PhysicsConstants.h>
25- #include <DCAFitter/DCAFitterN.h>
26- #include <DataFormatsParameters/GRPMagField.h>
27- #include <DetectorsBase/Propagator.h>
28- #include <DetectorsVertexing/PVertexer.h>
29- #include <DetectorsVertexing/PVertexerHelpers.h>
30- #include <Field/MagneticField.h>
3124#include <Framework/AnalysisDataModel.h>
3225#include <Framework/AnalysisTask.h>
3326#include <Framework/HistogramRegistry.h>
3427#include <Framework/O2DatabasePDGPlugin.h>
35- #include <Framework/StaticFor.h>
3628#include <Framework/runDataProcessing.h>
37- #include <ReconstructionDataFormats/DCA.h>
38- #include <SimulationDataFormat/InteractionSampler.h>
3929
4030#include <TPDGCode.h>
4131
@@ -69,14 +59,15 @@ static const std::vector<int> pdgCodes{kK0Short,
6959 kOmegaPlusBar};
7060
7161struct OnTheFlyDecayer {
72- Produces<aod::McParticlesWithDau > tableMcParticlesWithDau;
62+ Produces<aod::McPartsWithDau > tableMcParticlesWithDau;
7363
7464 o2::upgrade::Decayer decayer;
7565 Service<o2::framework::O2DatabasePDG> pdgDB;
7666 std::map<int, std::vector<o2::upgrade::OTFParticle>> mDecayDaughters;
7767
7868 Configurable<int> seed{"seed", 0, "Set seed for particle decayer"};
7969 Configurable<float> magneticField{"magneticField", 20., "Magnetic field (kG)"};
70+ Configurable<float> maxEta{"maxEta", 2.5, "Only decay particles that appear within selected eta range"};
8071 Configurable<LabeledArray<int>> enabledDecays{"enabledDecays",
8172 {DefaultParameters[0], NumDecays, NumParameters, particleNames, parameterNames},
8273 "Enable option for particle to be decayed: 0 - no, 1 - yes"};
@@ -122,6 +113,15 @@ struct OnTheFlyDecayer {
122113 y(y),
123114 isAlive(isAlive),
124115 isPrimary(isPrimary) {}
116+
117+ bool hasNaN() const
118+ {
119+ return std::isnan(px) || std::isnan(py) || std::isnan(pz) || std::isnan(e) ||
120+ std::isnan(vx) || std::isnan(vy) || std::isnan(vz) || std::isnan(vt) ||
121+ std::isnan(phi) || std::isnan(eta) || std::isnan(pt) || std::isnan(p) ||
122+ std::isnan(y) || std::isnan(weight);
123+ }
124+
125125 int collisionId;
126126 int pdgCode;
127127 int statusCode;
@@ -148,6 +148,10 @@ struct OnTheFlyDecayer {
148148 }
149149 }
150150
151+ auto hNaNBookkeeping = histos.add<TH1>("hNaNBookkeeping", "hNaNBookkeeping", kTH1D, {{2, -0.5, 1.5}});
152+ hNaNBookkeeping->GetXaxis()->SetBinLabel(1, "OK");
153+ hNaNBookkeeping->GetXaxis()->SetBinLabel(2, "NaN");
154+
151155 histos.add("K0S/hGenK0S", "hGenK0S", kTH1D, {axisPt});
152156 histos.add("Lambda/hGenLambda", "hGenLambda", kTH1D, {axisPt});
153157 histos.add("AntiLambda/hGenAntiLambda", "hGenAntiLambda", kTH1D, {axisPt});
@@ -175,30 +179,29 @@ struct OnTheFlyDecayer {
175179 mcParticlesAlice3.clear();
176180 u_int64_t nStoredDaughters = 0;
177181 for (int index{0}; index < static_cast<int>(mcParticles.size()); ++index) {
178- const auto& particle = mcParticles.iteratorAt(index);
179- std::vector<o2::upgrade::OTFParticle> decayDaughters;
180- static constexpr int MaxNestedDecays = 10;
181- int nDecays = 0;
182- if (canDecay(particle.pdgCode())) {
182+ const auto& particle = mcParticles.rawIteratorAt(index);
183+ std::vector<o2::upgrade::OTFParticle> decayDaughters, decayStack;
184+ if (canDecay(particle.pdgCode()) && std::abs(particle.eta()) < maxEta) {
183185 o2::track::TrackParCov o2track;
184186 o2::upgrade::convertMCParticleToO2Track(particle, o2track, pdgDB);
185- decayDaughters = decayer.decayParticle(pdgDB, o2track, particle.pdgCode());
186- for (size_t idau{0}; idau < decayDaughters.size(); ++idau) {
187- o2::upgrade::OTFParticle dau = decayDaughters[idau];
187+ decayStack = decayer.decayParticle(pdgDB, o2track, particle.pdgCode());
188+ while (!decayStack.empty()) {
189+ o2::upgrade::OTFParticle otfParticle = decayStack.back();
190+ decayStack.pop_back();
191+
192+ const bool stable = !canDecay(otfParticle.pdgCode());
193+ otfParticle.setIsAlive(stable);
194+ decayDaughters.push_back(otfParticle);
195+
196+ if (stable) {
197+ continue;
198+ }
199+
188200 o2::track::TrackParCov dauTrack;
189- o2::upgrade::convertOTFParticleToO2Track(dau, dauTrack, pdgDB);
190- if (canDecay(dau.pdgCode())) {
191- dau.setIsAlive(false);
192- std::vector<o2::upgrade::OTFParticle> cascadingDaughers = decayer.decayParticle(pdgDB, dauTrack, dau.pdgCode());
193- for (size_t idaudau{0}; idaudau < cascadingDaughers.size(); ++idaudau) {
194- o2::upgrade::OTFParticle daudau = cascadingDaughers[idaudau];
195- decayDaughters.push_back(daudau);
196- if (MaxNestedDecays < ++nDecays) {
197- LOG(error) << "Seemingly stuck trying to perpetually decay products from pdg: " << particle.pdgCode();
198- }
199- }
200- } else {
201- dau.setIsAlive(true);
201+ o2::upgrade::convertOTFParticleToO2Track(otfParticle, dauTrack, pdgDB);
202+ std::vector<o2::upgrade::OTFParticle> daughters = decayer.decayParticle(pdgDB, dauTrack, otfParticle.pdgCode());
203+ for (o2::upgrade::OTFParticle dau : daughters) {
204+ decayStack.push_back(dau);
202205 }
203206 }
204207
@@ -338,7 +341,7 @@ struct OnTheFlyDecayer {
338341 // TODO: Particle status code
339342 // TODO: Expression columns
340343 // TODO: vt
341- auto mother = mcParticles.iteratorAt (index);
344+ auto mother = mcParticles.rawIteratorAt (index);
342345 mcParticlesAlice3.push_back(McParticleAlice3{mother.mcCollisionId(), dau.pdgCode(), 1,
343346 -1, index, index, daughtersIdSlice[0], daughtersIdSlice[1], mother.weight(),
344347 dau.px(), dau.py(), dau.pz(), dau.e(),
@@ -348,8 +351,13 @@ struct OnTheFlyDecayer {
348351 }
349352
350353 for (const auto& particle : mcParticlesAlice3) {
351- std::span<const int> motherSpan(particle.mothersIds, 2);
354+ if (particle.hasNaN()) {
355+ histos.fill(HIST("hNaNBookkeeping"), 1);
356+ continue;
357+ }
352358
359+ histos.fill(HIST("hNaNBookkeeping"), 0);
360+ std::span<const int> motherSpan(particle.mothersIds, 2);
353361 tableMcParticlesWithDau(particle.collisionId, particle.pdgCode, particle.statusCode,
354362 particle.flags, motherSpan, particle.daughtersIdSlice, particle.weight,
355363 particle.px, particle.py, particle.pz, particle.e,
0 commit comments