Skip to content

Commit f37ddc4

Browse files
committed
GeneratorFactory: modular improvements
Some little restructuring to make it easy to reuse existing generator setups and to compose and mix generators. Reducing code duplication. Using this to setup a generator for test purposes leaving hits in all detectors.
1 parent 923ead3 commit f37ddc4

2 files changed

Lines changed: 53 additions & 68 deletions

File tree

Generators/src/GeneratorFactory.cxx

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -46,91 +46,82 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
4646
return;
4747
}
4848

49+
auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool debug = false) {
50+
auto gen = new FairBoxGenerator(pdgid, mult);
51+
gen->SetEtaRange(etamin, etamax);
52+
gen->SetPRange(pmin, pmax);
53+
gen->SetPhiRange(phimin, phimax);
54+
gen->SetDebug(debug);
55+
return gen;
56+
};
57+
58+
#ifdef GENERATORS_WITH_PYTHIA8
59+
auto makePythia8Gen = []() {
60+
// pythia8 pp
61+
// configures pythia for min.bias pp collisions at 14 TeV
62+
// TODO: make this configurable
63+
auto py8Gen = new o2::eventgen::Pythia8Generator();
64+
py8Gen->SetParameters("Beams:idA 2212"); // p
65+
py8Gen->SetParameters("Beams:idB 2212"); // p
66+
py8Gen->SetParameters("Beams:eCM 14000."); // [GeV]
67+
py8Gen->SetParameters("SoftQCD:inelastic on"); // all inelastic processes
68+
py8Gen->SetParameters("ParticleDecays:tau0Max 0.001");
69+
py8Gen->SetParameters("ParticleDecays:limitTau0 on");
70+
return py8Gen;
71+
};
72+
#endif
73+
4974
/** generators **/
5075

5176
auto genconfig = conf.getGenerator();
5277
if (genconfig.compare("boxgen") == 0) {
5378
// a simple "box" generator configurable via BoxGunparam
5479
auto& boxparam = BoxGunParam::Instance();
55-
LOG(INFO) << "Init box generator with following parameters";
80+
LOG(INFO) << "Init generic box generator with following parameters";
5681
LOG(INFO) << boxparam;
57-
auto boxGen = new FairBoxGenerator(boxparam.pdg, boxparam.number);
58-
boxGen->SetEtaRange(boxparam.eta[0], boxparam.eta[1]);
59-
boxGen->SetPRange(boxparam.prange[0], boxparam.prange[1]);
60-
boxGen->SetPhiRange(boxparam.phirange[0], boxparam.phirange[1]);
61-
boxGen->SetDebug(boxparam.debug);
62-
82+
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);
6383
primGen->AddGenerator(boxGen);
6484
} else if (genconfig.compare("fwmugen") == 0) {
6585
// a simple "box" generator for forward muons
6686
LOG(INFO) << "Init box forward muons generator";
67-
auto boxGen = new FairBoxGenerator(13, 1); /* mu- */
68-
boxGen->SetEtaRange(-2.5, -4.0);
69-
boxGen->SetPRange(100.0, 100.0);
70-
boxGen->SetPhiRange(0., 360.);
87+
auto boxGen = makeBoxGen(13, 100, -2.5, -4.0, 1000, 1000, 0., 360);
7188
primGen->AddGenerator(boxGen);
7289
} else if (genconfig.compare("hmpidgun") == 0) {
7390
// a simple "box" generator for forward muons
7491
LOG(INFO) << "Init hmpid gun generator";
75-
auto boxGen = new FairBoxGenerator(-211, 100); /* mu- */
76-
boxGen->SetEtaRange(-0.5, 0.5);
77-
boxGen->SetPRange(2, 5.0);
78-
boxGen->SetPhiRange(-5., 60.);
92+
auto boxGen = makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60);
7993
primGen->AddGenerator(boxGen);
8094
} else if (genconfig.compare("fwpigen") == 0) {
8195
// a simple "box" generator for forward pions
8296
LOG(INFO) << "Init box forward muons generator";
83-
auto boxGen = new FairBoxGenerator(-211, 1); /* pi- */
84-
boxGen->SetEtaRange(-2.5, -4.0);
85-
boxGen->SetPRange(7.0, 7.0);
86-
boxGen->SetPhiRange(0., 360.);
97+
auto boxGen = makeBoxGen(-211, 100, -2.5, -4.5, 7, 7, 0, 360);
8798
primGen->AddGenerator(boxGen);
8899
} else if (genconfig.compare("fwrootino") == 0) {
89100
// a simple "box" generator for forward rootinos
90101
LOG(INFO) << "Init box forward rootinos generator";
91-
auto boxGen = new FairBoxGenerator(0, 1); /* mu- */
92-
boxGen->SetEtaRange(-2.5, -4.0);
93-
boxGen->SetPRange(1, 5);
94-
boxGen->SetPhiRange(0., 360.);
102+
auto boxGen = makeBoxGen(0, 1, -2.5, -4.0, 1, 5, 0, 360);
95103
primGen->AddGenerator(boxGen);
96104
} else if (genconfig.compare("zdcgen") == 0) {
97105
// a simple "box" generator for forward neutrons
98-
LOG(INFO) << "Init box forward zdc generator";
99-
auto boxGenC = new FairBoxGenerator(2212, 500); /* neutrons */
100-
boxGenC->SetEtaRange(-8.0, -9999);
101-
boxGenC->SetPRange(10, 500);
102-
boxGenC->SetPhiRange(0., 360.);
103-
auto boxGenA = new FairBoxGenerator(2212, 500); /* neutrons */
104-
boxGenA->SetEtaRange(8.0, 9999);
105-
boxGenA->SetPRange(10, 500);
106-
boxGenA->SetPhiRange(0., 360.);
106+
LOG(INFO) << "Init box forward/backward zdc generator";
107+
auto boxGenC = makeBoxGen(2122 /*neutrons*/, 10, -8, -9999, 500, 1000, 0., 360.);
108+
auto boxGenA = makeBoxGen(2212 /*neutrons*/, 1, 8.0, 9999, 500, 1000, 0., 360.);
107109
primGen->AddGenerator(boxGenC);
108110
primGen->AddGenerator(boxGenA);
109111
} else if (genconfig.compare("emcgenele") == 0) {
110112
// box generator with one electron per event
111113
LOG(INFO) << "Init box generator for electrons in EMCAL";
112-
auto elecgen = new FairBoxGenerator(11, 1);
113-
elecgen->SetEtaRange(-0.67, 0.67);
114-
elecgen->SetPhiRange(80., 187.); // Phi range of the EMCAL
115-
elecgen->SetPtRange(15., 15.);
114+
// using phi range of emcal
115+
auto elecgen = makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187);
116116
primGen->AddGenerator(elecgen);
117117
} else if (genconfig.compare("emcgenphoton") == 0) {
118118
LOG(INFO) << "Init box generator for photons in EMCAL";
119-
auto photongen = new FairBoxGenerator(22, 1);
120-
photongen->SetEtaRange(-0.67, 0.67);
121-
photongen->SetPhiRange(80., 187.); // Phi range of the EMCAL
122-
photongen->SetPtRange(15., 15.);
119+
auto photongen = makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187);
123120
primGen->AddGenerator(photongen);
124121
} else if (genconfig.compare("fddgen") == 0) {
125122
LOG(INFO) << "Init box FDD generator";
126-
auto boxGenFDC = new FairBoxGenerator(13, 1000);
127-
boxGenFDC->SetEtaRange(-7.0, -4.8);
128-
boxGenFDC->SetPRange(10, 500);
129-
boxGenFDC->SetPhiRange(0., 360.);
130-
auto boxGenFDA = new FairBoxGenerator(13, 1000);
131-
boxGenFDA->SetEtaRange(4.9, 6.3);
132-
boxGenFDA->SetPRange(10, 500);
133-
boxGenFDA->SetPhiRange(0., 360.);
123+
auto boxGenFDC = makeBoxGen(13, 1000, -7, -4.8, 10, 500, 0, 360.);
124+
auto boxGenFDA = makeBoxGen(13, 1000, 4.9, 6.3, 10, 500, 0., 360);
134125
primGen->AddGenerator(boxGenFDA);
135126
primGen->AddGenerator(boxGenFDC);
136127
} else if (genconfig.compare("extkin") == 0) {
@@ -151,17 +142,17 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
151142
#endif
152143
#ifdef GENERATORS_WITH_PYTHIA8
153144
} else if (genconfig.compare("pythia8") == 0) {
154-
// pythia8 pp
155-
// configures pythia for min.bias pp collisions at 14 TeV
156-
// TODO: make this configurable
157-
auto py8Gen = new o2::eventgen::Pythia8Generator();
158-
py8Gen->SetParameters("Beams:idA 2212"); // p
159-
py8Gen->SetParameters("Beams:idB 2212"); // p
160-
py8Gen->SetParameters("Beams:eCM 14000."); // [GeV]
161-
py8Gen->SetParameters("SoftQCD:inelastic on"); // all inelastic processes
162-
py8Gen->SetParameters("ParticleDecays:tau0Max 0.001");
163-
py8Gen->SetParameters("ParticleDecays:limitTau0 on");
164-
primGen->AddGenerator(py8Gen);
145+
primGen->AddGenerator(makePythia8Gen());
146+
} else if (genconfig.compare("alldets") == 0) {
147+
// a simple generator for test purposes - making sure to generate hits
148+
// in all detectors
149+
// I compose it of:
150+
// 1) pythia8
151+
auto p8 = makePythia8Gen();
152+
primGen->AddGenerator(p8);
153+
// 2) forward muons
154+
auto muon = makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360);
155+
primGen->AddGenerator(muon);
165156
} else if (genconfig.compare("pythia8hf") == 0) {
166157
// pythia8 pp (HF production)
167158
// configures pythia for HF production in pp collisions at 14 TeV

prodtests/check_embedding_pileup.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@ set -x
66
# work
77

88
# The approach is the following:
9-
# 1) for each detector we simulate 2 events that both leave hits
9+
# 1) for each detector we simulate event sequences that leave (identical) hits
1010
# 2) we digitize the events with the same collision time assigned to both of them
1111
# and check whether the output digits have multiple labels --> checks pileup
1212
# 3) we digitize with trivial embedding: background and signal events are the same
1313
# and check whether the output digits have multiple labels --> checks embedding
1414

15-
# o2-sim -j 4 -g pythia8 -n 4 --seed 1 ok for
16-
# CVP, MCH, MID, HMP need special gun
17-
18-
dets=( ITS TPC TRD EMC PHS TOF CPV HMP MCH MID MFT FV0 FT0 FDD ZDC )
19-
generators=(boxgen boxgen boxgen boxgen hmpidgun boxgen boxgen hmpidgun fwpigen fwpigen fwpigen fddgen fddgen fddgen pythia8 )
20-
21-
dets=( ITS TPC TOF EMC HMP MCH MID MFT FV0 FT0 FDD)
22-
generators=( boxgen boxgen boxgen boxgen hmpidgun fwpigen fwpigen fwpigen fddgen fddgen fddgen)
15+
dets=( ITS TPC TOF EMC HMP MCH MID MFT FV0 FT0 FDD TRD PHS CPV ZDC )
16+
generators=( boxgen boxgen boxgen boxgen hmpidgun fwpigen fwpigen fwpigen fddgen fddgen fddgen boxgen boxgen boxgen boxgen )
2317

2418
for idx in "${!dets[@]}"; do
2519
d=${dets[$idx]}

0 commit comments

Comments
 (0)