18 #include <TDatabasePDG.h>
19 #include <TLorentzVector.h>
21 #include <TParticlePDG.h>
43 LOG(info) <<
"FairUrqmdGenerator: Opening input file " << fileName;
44 fInputFile = fopen(fFileName,
"r");
46 LOG(fatal) <<
"Cannot open input file.";
48 ReadConversionTable();
58 LOG(info) <<
"FairUrqmdGenerator: Opening input file " << fileName;
59 fInputFile = fopen(fFileName,
"r");
61 LOG(fatal) <<
"Cannot open input file.";
63 ReadConversionTable(conversion_table);
73 fParticleTable.clear();
80 void skipBytes(
char* bytes,
size_t numBytes, FILE* file)
82 if (fgets(bytes, numBytes, file) ==
nullptr) {
83 LOG(error) <<
"Failed reading from file stream";
93 LOG(error) <<
"FairUrqmdGenerator: Input file not open! ";
99 LOG(error) <<
"FairUrqmdGenerator::ReadEvent: "
100 <<
"No PrimaryGenerator!";
105 int evnr = 0, ntracks = 0, aProj = 0, zProj = 0, aTarg = 0, zTarg = 0;
106 float b = 0., ekin = 0.;
108 int ityp = 0, i3 = 0, ichg = 0, pid = 0;
109 float ppx = 0., ppy = 0., ppz = 0., m = 0.;
113 skipBytes(read, 200, fInputFile);
114 if (feof(fInputFile)) {
115 LOG(info) <<
"FairUrqmdGenerator : End of input file reached.";
117 fInputFile =
nullptr;
120 if (read[0] !=
'U') {
121 LOG(error) <<
"FairUrqmdGenerator: Wrong event header";
128 skipBytes(read, 26, fInputFile);
129 retval = fscanf(fInputFile,
"%d", &aProj);
130 CheckReturnValue(retval);
131 retval = fscanf(fInputFile,
"%d", &zProj);
132 CheckReturnValue(retval);
133 skipBytes(read, 25, fInputFile);
134 retval = fscanf(fInputFile,
"%d", &aTarg);
135 CheckReturnValue(retval);
136 retval = fscanf(fInputFile,
"%d", &zTarg);
137 CheckReturnValue(retval);
138 skipBytes(read, 200, fInputFile);
139 skipBytes(read, 200, fInputFile);
140 skipBytes(read, 36, fInputFile);
141 retval = fscanf(fInputFile,
"%f", &b);
142 CheckReturnValue(retval);
143 skipBytes(read, 200, fInputFile);
144 skipBytes(read, 39, fInputFile);
145 retval = fscanf(fInputFile,
"%e", &ekin);
146 CheckReturnValue(retval);
147 skipBytes(read, 200, fInputFile);
148 skipBytes(read, 7, fInputFile);
149 retval = fscanf(fInputFile,
"%d", &evnr);
150 CheckReturnValue(retval);
151 skipBytes(read, 200, fInputFile);
152 for (
int iline = 0; iline < 8; iline++) {
153 skipBytes(read, 200, fInputFile);
155 retval = fscanf(fInputFile,
"%d", &ntracks);
156 if (ntracks < 0 || ntracks > (INT_MAX - 1))
157 LOG(fatal) <<
"Error reading the number of events from event header.";
158 CheckReturnValue(retval);
159 skipBytes(read, 200, fInputFile);
160 skipBytes(read, 200, fInputFile);
163 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
164 TParticlePDG* kProton = pdgDB->GetParticle(2212);
165 Double_t kProtonMass = kProton->Mass();
167 Double_t eBeam = ekin + kProtonMass;
168 Double_t pBeam = TMath::Sqrt(eBeam * eBeam - kProtonMass * kProtonMass);
169 Double_t betaCM = pBeam / (eBeam + kProtonMass);
170 Double_t gammaCM = TMath::Sqrt(1. / (1. - betaCM * betaCM));
172 LOG(info) <<
"FairUrqmdGenerator: Event " << evnr <<
", b = " << b <<
" fm, multiplicity " << ntracks
173 <<
", ekin: " << ekin;
177 if (event && (!event->IsSet())) {
180 event->MarkSet(kTRUE);
184 for (
int itrack = 0; itrack < ntracks; itrack++) {
187 skipBytes(read, 81, fInputFile);
188 retval = fscanf(fInputFile,
"%e", &ppx);
189 CheckReturnValue(retval);
190 retval = fscanf(fInputFile,
"%e", &ppy);
191 CheckReturnValue(retval);
192 retval = fscanf(fInputFile,
"%e", &ppz);
193 CheckReturnValue(retval);
194 retval = fscanf(fInputFile,
"%e", &m);
195 CheckReturnValue(retval);
196 retval = fscanf(fInputFile,
"%d", &ityp);
197 CheckReturnValue(retval);
198 retval = fscanf(fInputFile,
"%d", &i3);
199 CheckReturnValue(retval);
200 retval = fscanf(fInputFile,
"%d", &ichg);
201 CheckReturnValue(retval);
202 skipBytes(read, 200, fInputFile);
206 pid = 1000 * (ichg + 2) + ityp;
208 pid = -1000 * (ichg + 2) + ityp;
212 if (fParticleTable.find(pid) == fParticleTable.end()) {
213 LOG(warn) <<
"FairUrqmdGenerator: PID " << ityp <<
" charge " << ichg <<
" not found in table (" << pid
217 Int_t pdgID = fParticleTable[pid];
220 Double_t mass = Double_t(m);
221 Double_t px = Double_t(ppx);
222 Double_t py = Double_t(ppy);
223 Double_t pz = Double_t(ppz);
224 Double_t e = sqrt(mass * mass + px * px + py * py + pz * pz);
225 pz = gammaCM * (pz + betaCM * e);
226 Double_t ee = sqrt(mass * mass + px * px + py * py + pz * pz);
228 TVector3 aa(px, py, pz);
236 primGen->
AddTrack(pdgID, px, py, pz, 0., 0., 0.);
248 for (Int_t ii = 0; ii < count; ii++) {
251 LOG(error) <<
"FairUrqmdGenerator: Input file not open! ";
256 int evnr = 0, ntracks = 0, aProj = 0, zProj = 0, aTarg = 0, zTarg = 0;
257 float b = 0., ekin = 0.;
261 skipBytes(read, 200, fInputFile);
262 if (feof(fInputFile)) {
263 LOG(info) <<
"FairUrqmdGenerator : End of input file reached.";
265 fInputFile =
nullptr;
268 if (read[0] !=
'U') {
269 LOG(error) <<
"FairUrqmdGenerator: Wrong event header";
276 skipBytes(read, 26, fInputFile);
277 retval = fscanf(fInputFile,
"%d", &aProj);
278 CheckReturnValue(retval);
279 retval = fscanf(fInputFile,
"%d", &zProj);
280 CheckReturnValue(retval);
281 skipBytes(read, 25, fInputFile);
282 retval = fscanf(fInputFile,
"%d", &aTarg);
283 CheckReturnValue(retval);
284 retval = fscanf(fInputFile,
"%d", &zTarg);
285 CheckReturnValue(retval);
286 skipBytes(read, 200, fInputFile);
287 skipBytes(read, 200, fInputFile);
288 skipBytes(read, 36, fInputFile);
289 retval = fscanf(fInputFile,
"%f", &b);
290 CheckReturnValue(retval);
291 skipBytes(read, 200, fInputFile);
292 skipBytes(read, 39, fInputFile);
293 retval = fscanf(fInputFile,
"%e", &ekin);
294 CheckReturnValue(retval);
295 skipBytes(read, 200, fInputFile);
296 skipBytes(read, 7, fInputFile);
297 retval = fscanf(fInputFile,
"%d", &evnr);
298 CheckReturnValue(retval);
299 skipBytes(read, 200, fInputFile);
300 for (
int iline = 0; iline < 8; iline++) {
301 skipBytes(read, 200, fInputFile);
303 retval = fscanf(fInputFile,
"%d", &ntracks);
304 if (ntracks < 0 || ntracks > (INT_MAX - 1))
305 LOG(fatal) <<
"Error reading the number of events from event header.";
306 CheckReturnValue(retval);
307 skipBytes(read, 200, fInputFile);
308 skipBytes(read, 200, fInputFile);
310 LOG(info) <<
"FairUrqmdGenerator: Event " << evnr <<
" skipped!";
313 for (
int itrack = 0; itrack < ntracks; itrack++) {
316 skipBytes(read, 81, fInputFile);
317 skipBytes(read, 200, fInputFile);
323 void FairUrqmdGenerator::ReadConversionTable(TString conversion_table)
325 TString work = getenv(
"VMCWORKDIR");
328 if (conversion_table.IsNull()) {
329 fileName = work +
"/input/urqmd_pdg.dat";
331 fileName = conversion_table.Data();
334 std::ifstream* pdgconv =
new std::ifstream(fileName.Data());
336 if (!pdgconv->good()) {
337 LOG(fatal) <<
"Could not open Urqmd->PDG input file " << fileName;
344 while (!pdgconv->eof()) {
346 *pdgconv >> index >> pdgId;
347 fParticleTable[index] = pdgId;
353 LOG(info) <<
"FairUrqmdGenerator: Particle table for conversion from "
357 void FairUrqmdGenerator::CheckReturnValue(Int_t retval)
360 LOG(error) <<
"Error when reading variable from input file";
Bool_t SkipEvents(Int_t count)
ClassImp(FairEventBuilder)
virtual void AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t pz, Double_t vx, Double_t vy, Double_t vz, Int_t parent=-1, Bool_t wanttracking=true, Double_t e=-9e9, Double_t tof=0., Double_t weight=0., TMCProcess proc=kPPrimary)
FairMCEventHeader * GetEvent()
Bool_t ReadEvent(FairPrimaryGenerator *primGen)