Skip to content

Commit 0860f6f

Browse files
committed
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.
1 parent 0ca3db4 commit 0860f6f

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

Generators/src/BoxGenerator.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ TParticle o2::eventgen::BoxGenerator::sampleParticle() const
3636
// if SetCosTheta() function is used, the distribution will be uniform in
3737
// cos(theta)
3838

39-
static double mass = GetPDGMass(mPDG);
39+
// per instance, since several box generators with different PDG codes can coexist
40+
const double mass = GetPDGMass(mPDG);
4041

4142
double pabs = 0, phi, pt = 0, theta = 0, eta, y, mt, px, py, pz = 0;
4243
phi = gRandom->Uniform(mPhiMin, mPhiMax) * TMath::DegToRad();

Generators/src/GeneratorFactory.cxx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <SimulationDataFormat/O2DatabasePDG.h>
1515
#include <Generators/GeneratorFactory.h>
1616
#include "FairGenerator.h"
17-
#include "FairBoxGenerator.h"
17+
#include <Generators/BoxGenerator.h>
1818
#include <fairlogger/Logger.h>
1919
#include <SimConfig/SimConfig.h>
2020
#include <Generators/GeneratorFromFile.h>
@@ -60,13 +60,8 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
6060

6161
auto primGenO2 = dynamic_cast<PrimaryGenerator*>(primGen);
6262

63-
auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool debug = false) {
64-
auto gen = new FairBoxGenerator(pdgid, mult);
65-
gen->SetEtaRange(etamin, etamax);
66-
gen->SetPRange(pmin, pmax);
67-
gen->SetPhiRange(phimin, phimax);
68-
gen->SetDebug(debug);
69-
return gen;
63+
auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax) {
64+
return new o2::eventgen::BoxGenerator(pdgid, mult, etamin, etamax, pmin, pmax, phimin, phimax);
7065
};
7166

7267
#ifdef GENERATORS_WITH_PYTHIA8
@@ -105,7 +100,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
105100
auto& boxparam = BoxGunParam::Instance();
106101
LOG(info) << "Init generic box generator with following parameters";
107102
LOG(info) << boxparam;
108-
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);
103+
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]);
109104
primGen->AddGenerator(boxGen);
110105
} else if (genconfig.compare("fwmugen") == 0) {
111106
// a simple "box" generator for forward muons
@@ -267,11 +262,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
267262
LOG(info) << "Init tof test generator -> 1 muon per sector and per module";
268263
for (int i = 0; i < 18; i++) {
269264
for (int j = 0; j < 5; j++) {
270-
auto boxGen = new FairBoxGenerator(13, 1); /*protons*/
271-
boxGen->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17);
272-
boxGen->SetPRange(9, 10);
273-
boxGen->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1);
274-
boxGen->SetDebug(kTRUE);
265+
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);
275266
primGen->AddGenerator(boxGen);
276267
}
277268
}

0 commit comments

Comments
 (0)