BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
MpdUrqmdGenerator.cxx
Go to the documentation of this file.
1
// -------------------------------------------------------------------------
2
// ----- MpdUrqmdGenerator source file -----
3
// ----- Created 24/06/04 by V. Friese -----
4
// -------------------------------------------------------------------------
5
#include "
MpdUrqmdGenerator.h
"
6
7
#include "FairMCEventHeader.h"
8
#include "FairPrimaryGenerator.h"
9
#include "
TDatabasePDG.h
"
10
#include "
TLorentzVector.h
"
11
#include "TMCProcess.h"
12
#include "
TObjArray.h
"
13
#include "
TPDGCode.h
"
14
#include "
TParticle.h
"
15
#include "
TParticlePDG.h
"
16
#include "
TRandom.h
"
17
#include "
TString.h
"
18
#include "TVirtualMCStack.h"
19
#include "constants.h"
20
21
#include <cstring>
22
#include <iostream>
23
#include <stdio.h>
24
25
using namespace
std
;
26
using namespace
TMath
;
27
28
// const Double_t kProtonMass = 0.938271998;
29
30
// ----- Default constructor ------------------------------------------
31
MpdUrqmdGenerator::MpdUrqmdGenerator
()
32
:
FairGenerator
()
33
,
fInputFile
(NULL)
34
,
fParticleTable
()
35
,
fPhiMin
(0.)
36
,
fPhiMax
(0.)
37
,
fEventPlaneSet
(
kFALSE
)
38
,
fFileName
(NULL)
39
,
fX
(0.)
40
,
fY
(0.)
41
,
fZ
(0.)
42
{}
43
44
// ----- Standard constructor -----------------------------------------
45
MpdUrqmdGenerator::MpdUrqmdGenerator
(
const
char
* fileName)
46
:
FairGenerator
()
47
,
fInputFile
(NULL)
48
,
fParticleTable
()
49
,
fPhiMin
(0.)
50
,
fPhiMax
(0.)
51
,
fEventPlaneSet
(
kFALSE
)
52
,
fFileName
(fileName)
53
,
fX
(0.)
54
,
fY
(0.)
55
,
fZ
(0.)
56
{
57
// fFileName = fileName;
58
cout <<
"-I MpdUrqmdGenerator: Opening input file "
<<
fFileName
<< endl;
59
fInputFile
= gzopen(
fFileName
,
"rb"
);
60
if
(!
fInputFile
) {
61
Fatal
(
"MpdUrqmdGenerator"
,
"Cannot open input file."
);
62
exit(1);
63
}
64
ReadConversionTable
();
65
}
66
// ------------------------------------------------------------------------
67
68
// ----- Destructor ---------------------------------------------------
69
MpdUrqmdGenerator::~MpdUrqmdGenerator
()
70
{
71
// cout<<"Enter Destructor of MpdUrqmdGenerator"<<endl;
72
if
(
fInputFile
) {
73
#ifdef GZIP_SUPPORT
74
gzclose(
fInputFile
);
75
#else
76
fclose(
fInputFile
);
77
#endif
78
fInputFile
= NULL;
79
}
80
fParticleTable
.clear();
81
// cout<<"Leave Destructor of MpdUrqmdGenerator"<<endl;
82
}
83
// ------------------------------------------------------------------------
84
85
// ----- Public method ReadEvent --------------------------------------
86
87
Bool_t
MpdUrqmdGenerator::ReadEvent
(FairPrimaryGenerator* primGen)
88
{
89
90
// ---> Check for input file
91
if
(!
fInputFile
) {
92
cout <<
"-E MpdUrqmdGenerator: Input file not open! "
<< endl;
93
return
kFALSE
;
94
}
95
96
// ---> Check for primary generator
97
if
(!primGen) {
98
cout <<
"-E- MpdUrqmdGenerator::ReadEvent: "
99
<<
"No PrimaryGenerator!"
<< endl;
100
return
kFALSE
;
101
}
102
103
// ---> Define event variables to be read from file
104
int
evnr = 0, ntracks = 0, aProj = 0, zProj = 0, aTarg = 0, zTarg = 0;
105
float
b = 0., ekin = 0.;
106
107
int
ityp = 0, i3 = 0, ichg = 0, pid = 0;
108
float
ppx = 0., ppy = 0., ppz = 0.,
m
= 0.;
109
110
// ---> Read and check first event header line from input file
111
char
read[200];
112
#ifdef GZIP_SUPPORT
113
gzgets(
fInputFile
, read, 200);
// line 1
114
#else
115
fgets(read, 200,
fInputFile
);
116
#endif
117
Int_t
urqmdVersion = 0;
118
sscanf(read,
"UQMD version: %d 1000 %d output_file 14"
, &urqmdVersion, &urqmdVersion);
119
cout <<
"URQMD VERSION USED = "
<< urqmdVersion << endl;
120
#ifdef GZIP_SUPPORT
121
if
(gzeof(
fInputFile
)) {
122
cout <<
"-I MpdUrqmdGenerator : End of input file reached."
<< endl;
123
gzclose(
fInputFile
);
124
#else
125
if
(feof(
fInputFile
)) {
126
cout <<
"-I MpdUrqmdGenerator : End of input file reached."
<< endl;
127
fclose(
fInputFile
);
128
#endif
129
fInputFile
= NULL;
130
return
kFALSE
;
131
}
132
if
(read[0] !=
'U'
) {
133
cout <<
"-E MpdUrqmdGenerator: Wrong event header"
<< endl;
134
return
kFALSE
;
135
}
136
137
// ---> Read rest of event header
138
#ifdef GZIP_SUPPORT
139
gzgets(
fInputFile
, read, 200);
// line 2
140
sscanf(read,
"projectile: (mass, char) %d %d target: (mass, char) %d %d"
, &aProj, &zProj, &aTarg,
141
&zTarg);
// line 2
142
gzgets(
fInputFile
, read, 200);
// line 3
143
gzgets(
fInputFile
, read, 36);
// line 4
144
gzgets(
fInputFile
, read, 200);
// line 4
145
sscanf(read,
"%f"
, &b);
// line 4
146
gzgets(
fInputFile
, read, 39);
// line 5
147
gzgets(
fInputFile
, read, 200);
// line 5
148
sscanf(read,
"%e"
, &ekin);
// line 5
149
gzgets(
fInputFile
, read, 7);
// line 6
150
gzgets(
fInputFile
, read, 200);
// line 6
151
sscanf(read,
"%d"
, &evnr);
// line 6
152
153
for
(
Int_t
iline = 0; iline < ((urqmdVersion == 30400) ? 11 : 8); iline++)
154
gzgets(
fInputFile
, read, 200);
155
156
gzgets(
fInputFile
, read, 200);
// line 18
157
sscanf(read,
"%d"
, &ntracks);
// line 18
158
gzgets(
fInputFile
, read, 200);
// line 19
159
#else
160
fgets(read, 26,
fInputFile
);
161
fscanf(
fInputFile
,
"%d"
, &aProj);
162
fscanf(
fInputFile
,
"%d"
, &zProj);
163
fgets(read, 25,
fInputFile
);
164
fscanf(
fInputFile
,
"%d"
, &aTarg);
165
fscanf(
fInputFile
,
"%d"
, &zTarg);
166
fgets(read, 200,
fInputFile
);
167
fgets(read, 200,
fInputFile
);
168
fgets(read, 36,
fInputFile
);
169
fscanf(
fInputFile
,
"%f"
, &b);
170
fgets(read, 200,
fInputFile
);
171
fgets(read, 39,
fInputFile
);
172
fscanf(
fInputFile
,
"%e"
, &ekin);
173
fgets(read, 200,
fInputFile
);
174
fgets(read, 7,
fInputFile
);
175
fscanf(
fInputFile
,
"%d"
, &evnr);
176
fgets(read, 200,
fInputFile
);
177
for
(
int
iline = 0; iline < 8; iline++) {
178
fgets(read, 200,
fInputFile
);
179
}
180
fscanf(
fInputFile
,
"%d"
, &ntracks);
181
fgets(read, 200,
fInputFile
);
182
fgets(read, 200,
fInputFile
);
183
#endif
184
185
// ---> Calculate beta and gamma for Lorentztransformation
186
TDatabasePDG
* pdgDB =
TDatabasePDG::Instance
();
187
TParticlePDG
*
kProton
= pdgDB->
GetParticle
(2212);
188
Double_t
kProtonMass =
kProton
->Mass();
189
190
Double_t
eBeam = ekin + kProtonMass;
191
Double_t
pBeam =
TMath::Sqrt
(eBeam * eBeam - kProtonMass * kProtonMass);
192
Double_t
betaCM = pBeam / (eBeam + kProtonMass);
193
Double_t
gammaCM =
TMath::Sqrt
(1. / (1. - betaCM * betaCM));
194
195
cout <<
"-I MpdUrqmdGenerator: Event "
<< evnr <<
", b = "
<< b <<
" fm, multiplicity "
<< ntracks
196
<<
", ekin: "
<< ekin << endl;
197
198
Double_t
phi = 0.;
199
// ---> Generate rotation angle
200
if
(
fEventPlaneSet
) {
201
phi =
gRandom
->Uniform(
fPhiMin
,
fPhiMax
);
202
}
203
204
// Set event id and impact parameter in MCEvent if not yet done
205
FairMCEventHeader
*
event
= primGen->GetEvent();
206
if
(event && (!event->IsSet())) {
207
event
->SetEventID(evnr);
208
event
->SetB(b);
209
event
->MarkSet(
kTRUE
);
210
event
->SetRotZ(phi);
211
}
212
213
// ---> Loop over tracks in the current event
214
for
(
int
itrack = 0; itrack < ntracks; itrack++) {
215
216
// Read momentum and PID from file
217
#ifdef GZIP_SUPPORT
218
gzgets(
fInputFile
, read, 81);
219
gzgets(
fInputFile
, read, 200);
220
sscanf(read,
"%e %e %e %e %d %d %d"
, &ppx, &ppy, &ppz, &
m
, &ityp, &i3, &ichg);
221
#else
222
fgets(read, 81,
fInputFile
);
223
fscanf(
fInputFile
,
"%e"
, &ppx);
224
fscanf(
fInputFile
,
"%e"
, &ppy);
225
fscanf(
fInputFile
,
"%e"
, &ppz);
226
fscanf(
fInputFile
,
"%e"
, &
m
);
227
fscanf(
fInputFile
,
"%d"
, &ityp);
228
fscanf(
fInputFile
,
"%d"
, &i3);
229
fscanf(
fInputFile
,
"%d"
, &ichg);
230
fgets(read, 200,
fInputFile
);
231
#endif
232
233
// Convert UrQMD type and charge to unique pid identifier
234
if
(ityp >= 0) {
235
pid = 1000 * (ichg + 2) + ityp;
236
}
else
{
237
pid = -1000 * (ichg + 2) + ityp;
238
}
239
240
// Convert Unique PID into PDG particle code
241
if
(
fParticleTable
.find(pid) ==
fParticleTable
.end()) {
242
cout <<
"-W MpdUrqmdGenerator: PID "
<< ityp <<
" charge "
<< ichg <<
" not found in table ("
<< pid <<
")"
243
<< endl;
244
continue
;
245
}
246
Int_t
pdgID =
fParticleTable
[pid];
247
248
// Lorentztransformation to lab
249
Double_t
mass =
Double_t
(
m
);
250
Double_t
px =
Double_t
(ppx);
251
Double_t
py =
Double_t
(ppy);
252
Double_t
pz =
Double_t
(ppz);
253
Double_t
e =
sqrt
(mass * mass + px * px + py * py + pz * pz);
254
if
(
gCoordinateSystem
==
sysLaboratory
)
255
pz = gammaCM * (pz + betaCM * e);
256
Double_t
ee =
sqrt
(mass * mass + px * px + py * py + pz * pz);
257
258
if
(
fEventPlaneSet
) {
259
Double_t
pt =
Sqrt
(px * px + py * py);
260
Double_t
azim =
ATan2
(py, px);
261
azim += phi;
262
px = pt *
Cos
(azim);
263
py = pt *
Sin
(azim);
264
}
265
266
TLorentzVector
pp;
267
pp.
SetPx
(px);
268
pp.
SetPy
(py);
269
pp.
SetPz
(pz);
270
pp.
SetE
(ee);
271
272
// Give track to PrimaryGenerator
273
// primGen->AddTrack(pdgID, px, py, pz, 0., 0., 0.);
274
primGen->AddTrack(pdgID, px, py, pz,
fX
,
fY
,
fZ
);
275
}
276
277
return
kTRUE
;
278
}
279
// ------------------------------------------------------------------------
280
281
// ----- Public method ReadEvent --------------------------------------
282
283
Bool_t
MpdUrqmdGenerator::SkipEvents
(
Int_t
count)
284
{
285
if
(count <= 0) {
286
return
kTRUE
;
287
}
288
289
for
(
Int_t
ii = 0; ii < count; ii++) {
290
// ---> Check for input file
291
if
(!
fInputFile
) {
292
cout <<
"-E MpdUrqmdGenerator: Input file not open! "
<< endl;
293
return
kFALSE
;
294
}
295
296
// ---> Define event variables to be read from file
297
int
evnr = 0, ntracks = 0, aProj = 0, zProj = 0, aTarg = 0, zTarg = 0;
298
float
b = 0., ekin = 0.;
299
300
// ---> Read and check first event header line from input file
301
char
read[200];
302
#ifdef GZIP_SUPPORT
303
gzgets(
fInputFile
, read, 200);
// line 1
304
#else
305
fgets(read, 200,
fInputFile
);
306
#endif
307
Int_t
urqmdVersion = 0;
308
sscanf(read,
"UQMD version: %d 1000 %d output_file 14"
, &urqmdVersion, &urqmdVersion);
309
cout <<
"URQMD VERSION USED = "
<< urqmdVersion << endl;
310
311
#ifdef GZIP_SUPPORT
312
if
(gzeof(
fInputFile
)) {
313
cout <<
"-I MpdUrqmdGenerator : End of input file reached."
<< endl;
314
gzclose(
fInputFile
);
315
#else
316
if
(feof(
fInputFile
)) {
317
cout <<
"-I MpdUrqmdGenerator : End of input file reached."
<< endl;
318
fclose(
fInputFile
);
319
#endif
320
fInputFile
= NULL;
321
return
kFALSE
;
322
}
323
if
(read[0] !=
'U'
) {
324
cout <<
"-E MpdUrqmdGenerator: Wrong event header"
<< endl;
325
return
kFALSE
;
326
}
327
328
// ---> Read rest of event header
329
#ifdef GZIP_SUPPORT
330
gzgets(
fInputFile
, read, 200);
// line 2
331
sscanf(read,
"projectile: (mass, char) %d %d target: (mass, char) %d %d"
, &aProj, &zProj, &aTarg,
332
&zTarg);
// line 2
333
gzgets(
fInputFile
, read, 200);
// line 3
334
gzgets(
fInputFile
, read, 36);
// line 4
335
gzgets(
fInputFile
, read, 200);
// line 4
336
sscanf(read,
"%f"
, &b);
// line 4
337
gzgets(
fInputFile
, read, 39);
// line 5
338
gzgets(
fInputFile
, read, 200);
// line 5
339
sscanf(read,
"%e"
, &ekin);
// line 5
340
gzgets(
fInputFile
, read, 7);
// line 6
341
gzgets(
fInputFile
, read, 200);
// line 6
342
sscanf(read,
"%d"
, &evnr);
// line 6
343
344
for
(
Int_t
iline = 0; iline < ((urqmdVersion == 30400) ? 11 : 8); iline++)
345
gzgets(
fInputFile
, read, 200);
346
347
gzgets(
fInputFile
, read, 200);
// line 15
348
sscanf(read,
"%d"
, &ntracks);
// line 15
349
gzgets(
fInputFile
, read, 200);
// line 16
350
#else
351
fgets(read, 26,
fInputFile
);
352
fscanf(
fInputFile
,
"%d"
, &aProj);
353
fscanf(
fInputFile
,
"%d"
, &zProj);
354
fgets(read, 25,
fInputFile
);
355
fscanf(
fInputFile
,
"%d"
, &aTarg);
356
fscanf(
fInputFile
,
"%d"
, &zTarg);
357
fgets(read, 200,
fInputFile
);
358
fgets(read, 200,
fInputFile
);
359
fgets(read, 36,
fInputFile
);
360
fscanf(
fInputFile
,
"%f"
, &b);
361
fgets(read, 200,
fInputFile
);
362
fgets(read, 39,
fInputFile
);
363
fscanf(
fInputFile
,
"%e"
, &ekin);
364
fgets(read, 200,
fInputFile
);
365
fgets(read, 7,
fInputFile
);
366
fscanf(
fInputFile
,
"%d"
, &evnr);
367
fgets(read, 200,
fInputFile
);
368
for
(
int
iline = 0; iline < 8; iline++) {
369
fgets(read, 200,
fInputFile
);
370
}
371
fscanf(
fInputFile
,
"%d"
, &ntracks);
372
fgets(read, 200,
fInputFile
);
373
fgets(read, 200,
fInputFile
);
374
#endif
375
376
cout <<
"-I MpdUrqmdGenerator: Event "
<< evnr <<
" skipped!"
<< endl;
377
378
// ---> Loop over tracks in the current event
379
for
(
int
itrack = 0; itrack < ntracks; itrack++) {
380
381
// Read momentum and PID from file
382
#ifdef GZIP_SUPPORT
383
gzgets(
fInputFile
, read, 200);
384
#else
385
fgets(read, 81,
fInputFile
);
386
fgets(read, 200,
fInputFile
);
387
#endif
388
}
389
}
390
return
kTRUE
;
391
}
392
// ------------------------------------------------------------------------
393
394
// ----- Private method ReadConverisonTable ---------------------------
395
396
void
MpdUrqmdGenerator::ReadConversionTable
()
397
{
398
399
TString
work = getenv(
"VMCWORKDIR"
);
400
TString
fileName = work +
"/input/urqmd_pdg.dat"
;
401
ifstream* pdgconv =
new
ifstream(fileName.
Data
());
402
403
Int_t
index = 0;
404
Int_t
pdgId = 0;
405
406
while
(!pdgconv->eof()) {
407
index = pdgId = 0;
408
*pdgconv >> index >> pdgId;
409
fParticleTable
[index] = pdgId;
410
}
411
412
pdgconv->close();
413
delete
pdgconv;
414
415
cout <<
"-I MpdUrqmdGenerator: Particle table for conversion from "
416
<<
"UrQMD loaded"
<< endl;
417
}
418
// ------------------------------------------------------------------------
419
420
void
MpdUrqmdGenerator::SetEventPlane
(
Double_t
phiMin,
Double_t
phiMax)
421
{
422
fPhiMin
= phiMin;
423
fPhiMax
= phiMax;
424
fEventPlaneSet
=
kTRUE
;
425
}
m
__m128 m
Definition
P4_F32vec4.h:27
Bool_t
bool Bool_t
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
TDatabasePDG.h
Fatal
void Fatal(const char *location, const char *msgfmt,...)
TLorentzVector.h
TObjArray.h
TPDGCode.h
kProton
kProton
TParticlePDG.h
TParticle.h
TRandom.h
gRandom
R__EXTERN TRandom * gRandom
TString.h
FairGenerator
FairMCEventHeader
MpdUrqmdGenerator::MpdUrqmdGenerator
MpdUrqmdGenerator()
Default constructor without arguments should not be used.
Definition
MpdUrqmdGenerator.cxx:31
MpdUrqmdGenerator::fParticleTable
std::map< Int_t, Int_t > fParticleTable
Input file.
Definition
MpdUrqmdGenerator.h:75
MpdUrqmdGenerator::fPhiMax
Double32_t fPhiMax
Definition
MpdUrqmdGenerator.h:77
MpdUrqmdGenerator::fFileName
const Char_t * fFileName
Definition
MpdUrqmdGenerator.h:80
MpdUrqmdGenerator::fPhiMin
Double32_t fPhiMin
Map from UrQMD PID to PDGPID.
Definition
MpdUrqmdGenerator.h:77
MpdUrqmdGenerator::fInputFile
gzFile fInputFile
Definition
MpdUrqmdGenerator.h:69
MpdUrqmdGenerator::ReadEvent
Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Reads on event from the input file and pushes the tracks onto the stack.
Definition
MpdUrqmdGenerator.cxx:87
MpdUrqmdGenerator::fY
Double32_t fY
Definition
MpdUrqmdGenerator.h:82
MpdUrqmdGenerator::ReadConversionTable
void ReadConversionTable()
Private method ReadConversionTable.
Definition
MpdUrqmdGenerator.cxx:396
MpdUrqmdGenerator::SkipEvents
Bool_t SkipEvents(Int_t count)
Definition
MpdUrqmdGenerator.cxx:283
MpdUrqmdGenerator::~MpdUrqmdGenerator
~MpdUrqmdGenerator()
Destructor.
Definition
MpdUrqmdGenerator.cxx:69
MpdUrqmdGenerator::fEventPlaneSet
Bool_t fEventPlaneSet
Definition
MpdUrqmdGenerator.h:78
MpdUrqmdGenerator::fX
Double32_t fX
Input file name.
Definition
MpdUrqmdGenerator.h:82
MpdUrqmdGenerator::SetEventPlane
void SetEventPlane(Double_t phiMin, Double_t phiMax)
Definition
MpdUrqmdGenerator.cxx:420
MpdUrqmdGenerator::fZ
Double32_t fZ
Definition
MpdUrqmdGenerator.h:82
TDatabasePDG
TDatabasePDG::Instance
static TDatabasePDG * Instance()
TDatabasePDG::GetParticle
TParticlePDG * GetParticle(const char *name) const
TLorentzVector
TLorentzVector::SetPy
void SetPy(Double_t a)
TLorentzVector::SetE
void SetE(Double_t a)
TLorentzVector::SetPz
void SetPz(Double_t a)
TLorentzVector::SetPx
void SetPx(Double_t a)
TParticlePDG
TString
TString::Data
const char * Data() const
gCoordinateSystem
const CoordinateSystem gCoordinateSystem
Definition
constants.h:6
sysLaboratory
@ sysLaboratory
Definition
constants.h:4
MpdUrqmdGenerator.h
sqrt
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
TMath
TMath::ATan2
Double_t ATan2(Double_t y, Double_t x)
TMath::Sqrt
Double_t Sqrt(Double_t x)
TMath::Cos
Double_t Cos(Double_t)
TMath::Sin
Double_t Sin(Double_t)
std
Definition
json.hpp:4446
generators
MpdUrqmdGenerator.cxx
Generated on
for BmnRoot by
1.17.0