From f624488c2a4b4c290666ac620c33974b75944174 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Wed, 16 Sep 2026 16:27:15 +0200 Subject: [PATCH] Give box-gun primaries weight 1 in o2-sim This fixes zero track weights for the box-gun generator presets in o2-sim. - FairBoxGenerator adds tracks without a weight, so FairRoot's default of 0 was used. - Geant4 scoring multiplies by the track weight, so all scores were zero. - The box-gun presets and toftest now use o2::eventgen::BoxGenerator, which gives weight 1. - BoxGenerator now looks up the mass for each call; the static cache gave every generator the mass of the first one used. - The kinematics distributions are unchanged; for a fixed seed the particle list is shifted by one particle. - BoxGunParam.debug no longer has an effect. --- Generators/src/BoxGenerator.cxx | 3 ++- Generators/src/GeneratorFactory.cxx | 19 +++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Generators/src/BoxGenerator.cxx b/Generators/src/BoxGenerator.cxx index 478934d98c621..b2df0389e08a7 100644 --- a/Generators/src/BoxGenerator.cxx +++ b/Generators/src/BoxGenerator.cxx @@ -36,7 +36,8 @@ TParticle o2::eventgen::BoxGenerator::sampleParticle() const // if SetCosTheta() function is used, the distribution will be uniform in // cos(theta) - static double mass = GetPDGMass(mPDG); + // per instance, since several box generators with different PDG codes can coexist + const double mass = GetPDGMass(mPDG); double pabs = 0, phi, pt = 0, theta = 0, eta, y, mt, px, py, pz = 0; phi = gRandom->Uniform(mPhiMin, mPhiMax) * TMath::DegToRad(); diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 1cc2659460a4b..f62e8dfddb849 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -14,7 +14,7 @@ #include #include #include "FairGenerator.h" -#include "FairBoxGenerator.h" +#include #include #include #include @@ -60,13 +60,8 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto primGenO2 = dynamic_cast(primGen); - auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool debug = false) { - auto gen = new FairBoxGenerator(pdgid, mult); - gen->SetEtaRange(etamin, etamax); - gen->SetPRange(pmin, pmax); - gen->SetPhiRange(phimin, phimax); - gen->SetDebug(debug); - return gen; + auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax) { + return new o2::eventgen::BoxGenerator(pdgid, mult, etamin, etamax, pmin, pmax, phimin, phimax); }; #ifdef GENERATORS_WITH_PYTHIA8 @@ -105,7 +100,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto& boxparam = BoxGunParam::Instance(); LOG(info) << "Init generic box generator with following parameters"; LOG(info) << boxparam; - auto boxGen = makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1], boxparam.debug); + auto boxGen = makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1]); primGen->AddGenerator(boxGen); } else if (genconfig.compare("fwmugen") == 0) { // a simple "box" generator for forward muons @@ -267,11 +262,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << "Init tof test generator -> 1 muon per sector and per module"; for (int i = 0; i < 18; i++) { for (int j = 0; j < 5; j++) { - auto boxGen = new FairBoxGenerator(13, 1); /*protons*/ - boxGen->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); - boxGen->SetPRange(9, 10); - boxGen->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); - boxGen->SetDebug(kTRUE); + auto boxGen = makeBoxGen(13 /*muons*/, 1, -0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17, 9, 10, 10 + 20. * i - 1, 10 + 20. * i + 1); primGen->AddGenerator(boxGen); } }