Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjamimpl.cpp
More file actions
Latest commit
481 lines (417 loc) · 15.7 KB
/
Copy pathjamimpl.cpp
File metadata and controls
481 lines (417 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#include"config.hpp"
#include"jamimpl.hpp"
#include<cstdlib>
#include<vector>
#include<string>
#include<memory>
#ifdef USE_LIBJAM2
# include<sstream>
# include<fstream>
# include<Pythia8/Settings.h>
# include<libjam2.hpp>
#endif
#ifdef USE_LIBJAM1
# include"ParticleSample.hpp"
# include"libjam1.hpp"
#endif
namespaceidt {
namespacerunjam {
#ifdef USE_LIBJAM2
static libjam2::irunner* runner_instance = nullptr;
#endif
intgetParticleStableCode(int kf) {
#ifdef USE_LIBJAM2
if (runner_instance)
return runner_instance->get_particle_stable_code(kf);
#endif
#if defined(USE_LIBJAM1)
returnlibjam1::determineStableCode(kf);
#else
switch (std::abs(kf)) {
case111: case211: case221: // pions
case311: case321: // kaons
case2212: case2112: // nucleons
case3112: case3122: case3212: case3222: // Lambda and Sigma
case3312: case3322: case3334: // Xi and Omega
return1;
default:
return2;
}
#endif
}
#if defined(USE_LIBJAM2) || defined(USE_LIBJAM1)
doublegetParticleMass(int kf) {
# ifdef USE_LIBJAM2
if (runner_instance)
return runner_instance->get_particle_mass(kf);
# endif
# ifdef USE_LIBJAM1
returnlibjam1::jamMass(kf);
# else
std::cerr << "FATAL: libjam2::runner not yet initialized." << std::endl;
std::exit(3);
# endif
}
#endif
classNullRunner: publicIJamRunner {
std::string message;
voidabort() const {
std::cerr << message << std::endl;
std::exit(3);
}
public:
NullRunner(constchar* message): message(message) {}
voidinitialize(runjam_context const& ctx, std::string const& cascadeMode) override {
(void) ctx;
(void) cascadeMode;
this->abort();
}
voidfinalize() override {
this->abort();
}
voidadjust_mass(ParticleSampleBase& psample) constoverride {
(void) psample;
this->abort();
}
voiddo_decay(ParticleSampleBase& psamp, std::vector<Particle>& final_state) override {
(void) psamp;
(void) final_state;
this->abort();
}
voiddo_cascade(ParticleSampleBase& psamp, std::vector<Particle>& final_state, int iev = 0) override {
(void) psamp;
(void) final_state;
(void) iev;
this->abort();
}
doubleget_average_collision_number() constoverride {
this->abort();
return0.0;
}
};
#ifdef USE_LIBJAM2
classJam2Runner: publicIJamRunner {
std::unique_ptr<libjam2::irunner> m_runner;
double m_oversample = 1.0;
public:
voidinitialize(runjam_context const& ctx, std::string const& cascadeMode) override {
std::string const fconfig = ctx.get_config<std::string>("runjam_jam2_config", "/dev/null");
m_runner = libjam2::create_runner(ctx, fconfig);
m_oversample = ctx.get_config("runjam_oversampling_factor", 1.0);
if (m_oversample != std::floor(m_oversample)) {
std::cerr << "jam2: 'runjam_oversampling_factor=" << m_oversample << "' needs to be an integer." << std::endl;
std::exit(2);
}
autoconst settings = m_runner->settings();
settings->flag("Random:setSeed", true);
settings->mode("Random:seed", ctx.seed());
settings->mode("Cascade:model", cascadeMode == "decay" ? 0 : 3);
settings->mode("Cascade:overSample", (int) m_oversample);
std::string const cachedir = ctx.cachedir();
settings->word("Cascade:dataFile1", cachedir + "/BWintjam2a.dat");
settings->word("Cascade:dataFile2", cachedir + "/BWintjam2b.dat");
settings->word("Cascade:bwFileName1", cachedir + "/BWintjam2a.dat");
settings->word("Cascade:bwFileName2", cachedir + "/BWintjam2b.dat");
// weak decay
{
boolconst weakdecay = ctx.get_config("runjam_switch_weak_decay", false);
std::string const setting = weakdecay ? ":mayDecay = on" : ":mayDecay = off";
settings->readString("111" + setting); // pi0
settings->readString("311" + setting); // k0
settings->readString("-311" + setting); // ak0
settings->readString("310" + setting); // k0_S
settings->readString("130" + setting); // k0_L
settings->readString("411" + setting); // D+
settings->readString("421" + setting); // D0
settings->readString("221" + setting); // eta
settings->readString("331" + setting); // eta'
settings->readString("441" + setting); // xeta_c
settings->readString("310" + setting);
settings->readString("431" + setting);
settings->readString("511" + setting);
settings->readString("521" + setting);
settings->readString("531" + setting);
settings->readString("3122" + setting);
settings->readString("3112" + setting);
settings->readString("3212" + setting);
settings->readString("3222" + setting);
settings->readString("3312" + setting);
settings->readString("3322" + setting);
settings->readString("3334" + setting);
}
// phi decay
settings->flag("333:mayDecay", ctx.get_config("runjam_phi_decays", true));
m_runner->initialize();
if (runner_instance == nullptr)
runner_instance = m_runner.get();
}
voidfinalize() override {
m_runner.reset();
}
voidadjust_mass(ParticleSampleBase& psample) constoverride {
for (Particle& part: psample) {
if (part.pdg == 0) continue;
doubleconst px = part.px;
doubleconst py = part.py;
doubleconst pz = part.pz;
doubleconst e = part.e;
if (e < 0.0) {
doubleconst m = m_runner->get_particle_mass(part.pdg);
part.mass = m;
part.e = std::sqrt(px * px + py * py + pz * pz + m * m);
} else {
part.mass = std::sqrt(e * e - (px * px + py * py + pz * pz));
}
}
}
voiddo_cascade(ParticleSampleBase& psamp, std::vector<Particle>& final_state, int iev) override {
if (psamp.getOverSamplingFactor() != m_oversample) {
std::cerr << "ParticleSample: mismatching oversampling factor between the initial condition and JAM2 initialization." << std::endl;
std::exit(1);
}
(void) iev;
std::vector<Particle> initial_state(psamp.begin(), psamp.end());
m_runner->run(initial_state, final_state);
}
voiddo_decay(ParticleSampleBase& psamp, std::vector<Particle>& final_state) override {
// settings に指定している。
this->do_cascade(psamp, final_state, 0);
}
doubleget_average_collision_number() constoverride {
return m_runner->get_event_collision_number();
}
};
std::unique_ptr<IJamRunner> create_jam2_runner() {
return std::make_unique<Jam2Runner>();
}
#else
std::unique_ptr<IJamRunner> create_jam2_runner() {
return std::make_unique<NullRunner>("FATAL: runjam: compiled without the JAM2 support.");
}
#endif
#ifdef USE_LIBJAM1
staticvoidstoreParticlesInJam1(Particle const* begin, Particle const* end) {
int nv = 0;
int nbary = 0;
int nmeson = 0;
for (; begin != end; ++begin) {
Particle const& particle = *begin;
intconst kf = particle.pdg;
if (kf == 0) continue;
intconst kc = libjam1::jamComp(kf); // internal particle code.
intconst ks = libjam1::determineStableCode(kf);
intconst ibary = libjam1::getBaryonNumber(kc, kf); // baryon number
if (ibary == 0)
nmeson++;
else
nbary++;
nv++;
//...Zero the vector.
libjam1::jamZero(nv);
libjam1::setK(1, nv, ks);
libjam1::setK(2, nv, kf);
libjam1::setK(3, nv, 0);
libjam1::setK(4, nv, 0);
libjam1::setK(5, nv, -1);
libjam1::setK(6, nv, 0);
libjam1::setK(7, nv, 1);
libjam1::setK(8, nv, 1);
libjam1::setK(9, nv, ibary);
libjam1::setK(10, nv, 0);
libjam1::setK(11, nv, 0);
doubleconst x = particle.x;
doubleconst y = particle.y;
doubleconst z = particle.z;
doubleconst t = particle.t;
doubleconst px = particle.px ;
doubleconst py = particle.py ;
doubleconst pz = particle.pz ;
doubleconst pe = particle.e ;
doubleconst pm = particle.mass;
libjam1::setP(1, nv, px);
libjam1::setP(2, nv, py);
libjam1::setP(3, nv, pz);
libjam1::setP(4, nv, pe);
libjam1::setP(5, nv, pm);
libjam1::setR(1, nv, x);
libjam1::setR(2, nv, y);
libjam1::setR(3, nv, z);
libjam1::setR(4, nv, t);
libjam1::setR(5, nv, t); // formation time
libjam1::setV(1, nv, x); // vertex
libjam1::setV(2, nv, y); // vertex
libjam1::setV(3, nv, z); // vertex
libjam1::setV(4, nv, t); // vertex
// Set resonance decay time.
double decayTime = 1.0e+35;
if (ks == 2) decayTime = t + libjam1::jamDecayTime(1, kf, kc, ks, pm, pe);
libjam1::setV(5, nv, decayTime);
}
libjam1::setNV(nv); // set total number of particles
libjam1::setNBARY(nbary); // set total number of baryons
libjam1::setNMESON(nmeson); // set total number of mesons
}
staticintloadParticlesFromJam1(std::vector<Particle>& list) {
list.clear();
intconst nv = libjam1::getNV();
intconst ntest = libjam1::getMSTC(5);
for (int i = 1; i <= nv; i++) {
//if(libjam1::getK(1,i) > 10) continue;
list.emplace_back();
Particle& part = list.back();
part.pdg = libjam1::getK(2, i);
part.mass = libjam1::getP(5, i);
part.px = libjam1::getP(1, i);
part.py = libjam1::getP(2, i);
part.pz = libjam1::getP(3, i);
part.e = libjam1::getP(4, i);
part.x = libjam1::getR(1, i);
part.y = libjam1::getR(2, i);
part.z = libjam1::getR(3, i);
part.t = libjam1::getR(4, i);
}
return ntest;
}
classJam1Runner: publicIJamRunner {
public:
voidinitialize(runjam_context const& ctx, std::string const& cascadeMode) override {
(void) cascadeMode;
intconst cfg_nevent = ctx.nevent(1);
std::string const cfg_outdir = ctx.outdir();
intconst cfg_jamseed = ctx.get_config("runjam_jamseed", ctx.seed());
boolconst cfg_phi_decays = ctx.get_config("runjam_phi_decays", true);
boolconst cfg_weakdecay = ctx.get_config("runjam_switch_weak_decay", false);
// Initialize JAM
libjam1::setMSTC( 1, cfg_jamseed); // int seed = 1921;
libjam1::setMSTC( 2, cfg_nevent); // number of event
libjam1::setPARC( 6, 5.0); // scale of display
libjam1::setMSTC( 8, 0); // job mode
libjam1::setMSTC( 16, 0); // display on/off
//libjam1::setMSTC( 38, 6); // IO number for jamlist
//libjam1::setMSTC( 39, 0); //no output fname(4)
libjam1::setMSTC( 54, 0); // avoid first coll inside the same nucleus off
// Default settings
//libjam1::setMSTC(156, 0); // analysis of collision distribution
//libjam1::setMSTC(161, 0); // no analysis from jam internal subr
//libjam1::setMSTC(162, 0); // Output collision history
//libjam1::setMSTC(165, 0); //
// Additional settings
libjam1::setMSTC( 4, 100); // user defined frame
libjam1::setPARC( 7, 1.0); // Output time interval (fm/c)
//libjam1::setMSTC( 41, 0); // 0:no resonance decay after simulation
//libjam1::setMSTC( 61, 0); // isotropic resonance decay option
libjam1::setMSTC( 81, 0); // 1:hard scattering on/off
libjam1::setMSTC(156, 1); // analysis of collision distribution
libjam1::setMSTC(161, 0); // no analysis from jam internal subr
libjam1::setMSTC(162, 1); // Output collision history
libjam1::setMSTC(165, 1); //
// JAM*.DAT files
if (cfg_outdir.size() > 0) {
std::string const dir = cfg_outdir + "/";
libjam1::setFNAME(2, dir + libjam1::getFNAME(2));
libjam1::setFNAME(3, dir + libjam1::getFNAME(3));
libjam1::setFNAME(4, dir + libjam1::getFNAME(4));
libjam1::setFNAME(8, dir);
}
//libjam1::setMDCY(libjam1::jamComp(111) , 1, 0); // no pi0 decay
//libjam1::setMDCY(libjam1::jamComp(3122), 1, 1); // Lambda decay
//libjam1::setMDCY(libjam1::jamComp(3222), 1, 1); // Sigma- decay
//libjam1::setMDCY(libjam1::jamComp(3212), 1, 1); // Sigma0 decay
//libjam1::setMDCY(libjam1::jamComp(3112), 1, 1); // Sigma+ decay
if (!cfg_phi_decays)
libjam1::setMDCY(libjam1::jamComp(333), 1, 0); // no phi decay
if (cfg_weakdecay) libjam1::setMSTC(42, 0); // allow weak decay
// JAMINIT
std::string frame = "user"; // comp. frame in this case, user defined
double dt = 100.0; // collision time(fm/c)
int nstep = 1; // time step (i.e. no time step)
double bmin = 0.0; // minimum impact parameter (dummy)
double bmax = 0.0; // maximum impact parameter (dummy)
libjam1::setPARD(16, 10.0); // user defined frame.
libjam1::jamInit(cfg_nevent, bmin, bmax, dt, nstep, frame.c_str(), "p ", "p ", "2gev");
}
voidfinalize() override {
libjam1::jamFin();
}
voidadjust_mass(ParticleSampleBase& psample) constoverride {
for (Particle& part: psample) {
if (part.pdg == 0) continue;
doubleconst px = part.px;
doubleconst py = part.py;
doubleconst pz = part.pz;
doubleconst e = part.e;
if (e < 0.0) {
doubleconst m = runjam::getParticleMass(part.pdg);
part.mass = m;
part.e = std::sqrt(px * px + py * py + pz * pz + m * m);
} else {
part.mass = std::sqrt(e * e - (px * px + py * py + pz * pz));
}
}
}
voiddo_decay(ParticleSampleBase& psamp, std::vector<Particle>& final_state) override {
doubleconst ntest = psamp.getOverSamplingFactor();
libjam1::setMSTC(5, ntest);
storeParticlesInJam1(psamp.begin(), psamp.end());
libjam1::finalResonanceDecay();
loadParticlesFromJam1(final_state);
}
voiddo_cascade(ParticleSampleBase& psamp, std::vector<Particle>& final_state, int iev = 0) override {
doubleconst ntest = psamp.getOverSamplingFactor();
libjam1::setMSTC(5, ntest);
storeParticlesInJam1(psamp.begin(), psamp.end());
libjam1::jamEvt(iev);
loadParticlesFromJam1(final_state);
}
doubleget_average_collision_number() constoverride {
intconst ntest = libjam1::getMSTC(5);
return (libjam1::getMSTD(41) + libjam1::getMSTD(42)) / ntest;
}
};
std::unique_ptr<IJamRunner> create_jam1_runner() {
return std::make_unique<Jam1Runner>();
}
#else
std::unique_ptr<IJamRunner> create_jam1_runner() {
return std::make_unique<NullRunner>("FATAL: runjam: compiled without the JAM1 support.");
}
#endif
std::unique_ptr<IJamRunner> create_runner(runjam_context const& ctx) {
#if defined(USE_LIBJAM1) || defined(USE_LIBJAM2)
intconst libjam_version = ctx.get_config("runjam_jam_version", DEFAULT_JAM_VERSION);
switch (libjam_version) {
case1:
#ifdef USE_LIBJAM1
returnrunjam::create_jam1_runner();
#else
std::cerr << "runjam was compiled without the support for JAM1" << std::endl;
break;
#endif
case2:
#ifdef USE_LIBJAM2
returnrunjam::create_jam2_runner();
#else
std::cerr << "runjam was compiled without the support for JAM2" << std::endl;
break;
#endif
default:
std::cerr << "runjam: invalid value runjam_jam_version='" << libjam_version << "'" << std::endl;
break;
}
#else
std::cerr << " runjam was compiled without the support for JAM" << std::endl;
#endif
return std::unique_ptr<IJamRunner>();
}
std::vector<std::string> libjam_versions() {
std::vector<std::string> ret;
#ifdef USE_LIBJAM1
ret.push_back("libjam1");
#endif
#ifdef USE_LIBJAM2
ret.push_back(libjam2::version_string());
#endif
return ret;
}
}
}