BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
MpdLAQGSMGeneratorExt.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- MpdLAQGSMGeneratorExt source file -----
3// -------------------------------------------------------------------------
4
5/** MpdLAQGSMGeneratorExt
6 *@author Elena Litvinenko <litvin@nf.jinr.ru>
7 *@version 15.02.2016
8 *
9 ** The MpdLAQGSMGeneratorExt uses the ASCII input
10 ** provided by K.Gudima LAQGSM event generator.
11 **/
12
14
15#include "FairIon.h"
16#include "FairMCEventHeader.h"
17#include "FairParticle.h"
18#include "FairPrimaryGenerator.h"
19#include "FairRootManager.h"
20#include "FairRunSim.h"
21#include "MpdHypYPtGenerator.h" //AZ
22#include "TDatabasePDG.h"
23#include "TFile.h"
24#include "TParticle.h"
25#include "TParticlePDG.h"
26#include "TSystem.h"
27
28#include <iostream>
29
30using std::cout;
31using std::endl;
32using std::map;
33
34// ----- Default constructor ------------------------------------------
35
37{
38 fMom = nullptr;
40 fMomBranchName = "StartP";
41 fMTree = nullptr;
42 fSourceFile = nullptr;
43 fNEvents = 0;
44 fIEvent = 0;
45}
46// ------------------------------------------------------------------------
47
48// ----- Standard constructor -----------------------------------------
49
50MpdLAQGSMGeneratorExt::MpdLAQGSMGeneratorExt(const vector<TString>& fileNames,
51 const Bool_t use_collider_system,
52 Int_t QGSM_format_ID,
53 Int_t Max_Event_Number,
54 Int_t pdg,
55 Bool_t extract_from_dir)
56// FairGenerator(),
57// fIonMap()
58{
59 fExtract_from_dir = extract_from_dir;
60 fMom = nullptr;
61 fMomBranchName = "StartP";
62 fMTree = nullptr;
63 fSourceFile = nullptr;
64 fNEvents = 0;
65 fIEvent = 0;
66
67 iFile = 0;
68 fSelPDG = pdg;
69 fFileVec = fileNames;
71
72 FairRootManager* ioman = FairRootManager::Instance();
73 if (NULL == ioman)
74 Fatal("Init", "FairRootManager is not instantiated");
75
76 printf("fExtract_from_dir %d\n", fExtract_from_dir);
77 if (fExtract_from_dir == kTRUE) {
80 ioman->Register(fMomBranchName, "bmndata", fMom, kTRUE); // last arg: save to file
81 TString sFileName = fFileVec[iFile];
82 if (sFileName.Contains(".gz"))
83 fGZ_input = 1;
84 else
85 fGZ_input = 0;
86
87 fFileName = sFileName.Data();
88 cout << "-I- MpdLAQGSMGeneratorExt: Opening input file " << fFileName << endl;
89
90 fInputFile = NULL;
91 fGZInputFile = NULL;
92
93 if (fGZ_input)
94 fGZInputFile = gzopen(fFileName, "rb");
95 else
96 fInputFile = fopen(fFileName, "r");
97
98 if ((!fInputFile) && (!fGZInputFile))
99 Fatal("MpdLAQGSMGeneratorExt", "Cannot open input file.");
100
101 fUseColliderSystem = use_collider_system;
102 fQGSM_format_ID = QGSM_format_ID;
103
104 Init(); // AZ
105 cout << "-I- MpdLAQGSMGeneratorExt: Looking for ions..." << endl;
106 // AZ Int_t nIons = RegisterIons();
107 // Int_t nIons = RegisterIons1();
108 // Int_t nIons = RegisterIons(); // MG
109 Int_t nIons = RegisterIons(Max_Event_Number); // EL
110 cout << "-I- MpdLAQGSMGeneratorExt: " << nIons << " ions registered." << endl;
111 iFile--;
112 CloseInput();
113 if (++iFile == (Int_t)fFileVec.size())
114 iFile = 0;
115 fFileName = fFileVec[iFile].Data();
116 cout << "-I- MpdLAQGSMGeneratorExt: Reopening input file " << fFileName << endl;
117 if (fGZ_input)
118 fGZInputFile = gzopen(fFileName, "rb");
119 else
120 fInputFile = fopen(fFileName, "r");
121 // OpenNext();
122 } else {
123 fSourceFile = new TFile(fFileVec[0].Data(), "READ");
124 if (fSourceFile->IsOpen() == false) {
125 Fatal("Init", "\n!!!!\ncannot open file !\n");
126 return;
127 }
129 printf("ReadEventFromFiltered selected!\n");
130 fMTree = (TTree*)fSourceFile->Get("bmndata");
131 fMTree->SetBranchAddress(fMomBranchName.Data(), &fMom);
132 // fMom = (TClonesArray*) ioman->GetObject(fMomBranchName.Data());
133 fNEvents = fMTree->GetEntries();
134 }
135 // AZ memset(la_tab,0,sizeof(la_tab));
136 fX = 0.0;
137 fY = 0.0;
138 fZ = 0.0;
139}
140// ------------------------------------------------------------------------
141
142// ----- Destructor ---------------------------------------------------
143
145{
146 if (fSourceFile) {
147 fSourceFile->Close();
148 delete fSourceFile;
149 }
150}
151// ------------------------------------------------------------------------
152
154{
155 if (++iFile == (Int_t)fFileVec.size()) {
156 if (fExtract_from_dir) {
157 printf("\nLast file finished!\n");
158 // fRunSimInst->GetMCApp()->StopRun();
159 // printf("run stopped \n");
160 // return;
161 iFile = 0;
162 // return kFALSE;
163 } else
164 iFile = 0;
165 }
166 fFileName = fFileVec[iFile].Data();
167 cout << "-I- MpdLAQGSMGeneratorExt: Reopening input file " << fFileName << endl;
168 if (fGZ_input)
169 fGZInputFile = gzopen(fFileName, "rb");
170 else
171 fInputFile = fopen(fFileName, "r");
172
173 return kTRUE;
174}
175
176// --------------Public method Init (fill list of known light particles)---
177
178// ------------------------------------------------------------------------
179
180// ------------------------------------------------------------------------
181
182// AZ ----- Public method SkipEvents --------------------------------------
183
185{
186
187 if (count <= 0)
188 return kTRUE;
189
190 // Check for input file
191 if (fGZ_input) {
192 if (!fGZInputFile) {
193 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
194 return kFALSE;
195 }
196 } else {
197 if (!fInputFile) {
198 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
199 return kFALSE;
200 }
201 }
202
203 Int_t eventId = 0, nTracks = 0;
204
205 for (Int_t ii = 0; ii < count; ii++) {
206 char ss[252];
207
208 if (!GetEventHeader(ss)) {
209 OpenNext();
210 if (!GetEventHeader(ss))
211 return kFALSE;
212 }
213
214 sscanf(ss, " %d %d", &eventId, &nTracks);
215 // cout << ii << " " << eventId << endl;
216
217 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
218 general_fgets(ss, 250, fInputFile);
219 }
220 }
221 return kTRUE;
222}
223// ------------------------------------------------------------------------
224
225// ----- Public method ReadEvent --------------------------------------
226
227Bool_t MpdLAQGSMGeneratorExt::ReadEvent(FairPrimaryGenerator* primGen)
228{
229 (this->*ReadEventImpl)(primGen);
230 return kTRUE;
231}
232
234{
235 printf("Read TextEvent\n");
236
237 // Check for input file
238 if (fGZ_input) {
239 if (!fGZInputFile) {
240 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
241 return kFALSE;
242 }
243 } else {
244 if (!fInputFile) {
245 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
246 return kFALSE;
247 }
248 }
249
250 // ---> Check for primary generator
251 if (!primGen) {
252 cout << "-E- MpdLAQGSMGeneratorExt::ReadEvent: "
253 << "No PrimaryGenerator!" << endl;
254 return kFALSE;
255 }
256
257 // AZ if (la_tab[0].pdg<=0)
258 if (fLa_tab[0]->pdg <= 0)
259 Init();
260
261 // Define event variable to be read from file
262 Int_t eventId = 0;
263 Int_t nTracks = 0;
264 Float_t b = 0., bx = 0, by = 0;
265
266 // Define track variables to be read from file
267 Int_t iCharge = 0, iLeptonic = 0, iStrange = 0, iBarionic = 0, iCode = 0, io1 = 0, io2 = 0, io3 = 0 //,
268 // A=0,
269 // Z=0
270 ;
271 Float_t px = 0., py = 0., pz = 0., pz1 = 0, pza1 = 0,
272 // Ekin = 0,
273 // Ekin1 = 0,
274 mass = 0;
275
276 Int_t PDG = 0;
277 char ss[252];
278
279 char ionName[30];
280
281 if (!GetEventHeader(ss)) {
282 OpenNext();
283 if (!GetEventHeader(ss))
284 return kFALSE;
285 }
286
287 // Double_t projA,projZ,projEex, targA, targZ, targEex;
288 Float_t projA, projZ, projEex, targA, targZ, targEex;
289
290 int bpos;
291 sscanf(ss, " %d %d %n", &eventId, &nTracks, &bpos);
292
293 if (!fQGSM_format_ID)
294 sscanf(&(ss[bpos]), "%g %g %g %g %g %g %g %g %g", &b, &bx, &by, &projA, &projZ, &projEex, &targA, &targZ,
295 &targEex);
296 else
297 sscanf(&(ss[bpos]), "%g %g %g", &b, &bx, &by);
298
299 cout << "-I- MpdLAQGSMGeneratorExt::ReadEvent: Event " << eventId << ", b = " << b << " fm, multiplicity "
300 << nTracks << endl;
301
302 TVector2 bb; // MG
303 bb.Set(bx, by); // MG
304
305 // Set event id and impact parameter in MCEvent if not yet done
306 FairMCEventHeader* event = primGen->GetEvent();
307 if (event && (!event->IsSet())) {
308 event->SetEventID(eventId - 1);
309 event->SetB(b);
310 // event->SetPhi(bb.Phi()); // MG
311 event->MarkSet(kTRUE);
312 }
313 // Loop over tracks in the current event
314 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
315
316 general_fgets(ss, 250, fInputFile);
317
318 if (fQGSM_format_ID < 3)
319 sscanf(ss, " %d %d %d %d %d", &iCharge, &iLeptonic, &iStrange, &iBarionic, &iCode);
320 else
321 sscanf(ss, " %d %d %d %d %d %d %d", &iCharge, &iLeptonic, &iStrange, &iBarionic, &io1, &io2, &io3);
322
323 Int_t p_num = 21;
324 if (fQGSM_format_ID == 3)
325 p_num = 36;
326
327 if (!fQGSM_format_ID)
328 sscanf(&(ss[p_num]), "%g%g%g%g%g", &px, &py, &pz, &pz1, &mass);
329 else
330 sscanf(&(ss[p_num]), "%g%g%g%g%g%g", &px, &py, &pz, &pz1, &pza1, &mass);
331
332 if (FindParticle(iCharge, iStrange, iLeptonic, iBarionic, mass, PDG, ionName)) {
333
334 if (PDG != fSelPDG)
335 continue;
336
337 if (!fPDG->GetParticle(PDG)) {
338 cout << "-W- MpdLAQGSMGeneratorExt::ReadEvent: Cannot find " << PDG << " " << ionName << " in database!"
339 << endl;
340 continue;
341 }
342
343 // Give track to PrimaryGenerator
345 primGen->AddTrack(PDG, px, py, pz, 0., 0., 0.);
346 else
347 primGen->AddTrack(PDG, px, py, pz1, fX, fY, fZ);
348 }
349 }
350
351 return kTRUE;
352}
353// ------------------------------------------------------------------------
354
356{
357 fMom->Clear("C");
358 Bool_t isFound = kFALSE;
359 while (!isFound) {
360 // Check for input file
361 if (fGZ_input) {
362 if (!fGZInputFile) {
363 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
364 return kFALSE;
365 }
366 } else {
367 if (!fInputFile) {
368 cout << "-E- MpdLAQGSMGeneratorExt: Input file not open!" << endl;
369 return kFALSE;
370 }
371 }
372 // AZ if (la_tab[0].pdg<=0)
373 if (fLa_tab[0]->pdg <= 0)
374 Init();
375
376 // Define event variable to be read from file
377 Int_t eventId = 0;
378 Int_t nTracks = 0;
379 Float_t b = 0., bx = 0, by = 0;
380
381 // Define track variables to be read from file
382 Int_t iCharge = 0, iLeptonic = 0, iStrange = 0, iBarionic = 0, iCode = 0, io1 = 0, io2 = 0, io3 = 0 //,
383 // A=0,
384 // Z=0
385 ;
386 Float_t px = 0., py = 0., pz = 0., pz1 = 0, pza1 = 0,
387 // Ekin = 0,
388 // Ekin1 = 0,
389 mass = 0;
390
391 Int_t PDG = 0;
392 char ss[252];
393
394 char ionName[30];
395
396 if (!GetEventHeader(ss)) {
397 if (OpenNext() == kFALSE)
398 return kFALSE;
399 if (!GetEventHeader(ss))
400 return kFALSE;
401 }
402
403 // Double_t projA,projZ,projEex, targA, targZ, targEex;
404 Float_t projA, projZ, projEex, targA, targZ, targEex;
405
406 int bpos;
407 sscanf(ss, " %d %d %n", &eventId, &nTracks, &bpos);
408
409 if (!fQGSM_format_ID)
410 sscanf(&(ss[bpos]), "%g %g %g %g %g %g %g %g %g", &b, &bx, &by, &projA, &projZ, &projEex, &targA, &targZ,
411 &targEex);
412 else
413 sscanf(&(ss[bpos]), "%g %g %g", &b, &bx, &by);
414
415 // cout << "-I- MpdLAQGSMGeneratorExt::ReadEvent: Event " << eventId
416 // << ", b = " << b << " fm, multiplicity " << nTracks << endl;
417
418 TVector2 bb; // MG
419 bb.Set(bx, by); // MG
420
421 // // Set event id and impact parameter in MCEvent if not yet done
422 // FairMCEventHeader* event = primGen->GetEvent();
423 // if (event && (!event->IsSet())) {
424 // event->SetEventID(eventId - 1);
425 // event->SetB(b);
426 // // event->SetPhi(bb.Phi()); // MG
427 // event->MarkSet(kTRUE);
428 // }
429 // Loop over tracks in the current event
430 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
431
432 general_fgets(ss, 250, fInputFile);
433
434 if (fQGSM_format_ID < 3)
435 sscanf(ss, " %d %d %d %d %d", &iCharge, &iLeptonic, &iStrange, &iBarionic, &iCode);
436 else
437 sscanf(ss, " %d %d %d %d %d %d %d", &iCharge, &iLeptonic, &iStrange, &iBarionic, &io1, &io2, &io3);
438
439 Int_t p_num = 21;
440 if (fQGSM_format_ID == 3)
441 p_num = 36;
442
443 if (!fQGSM_format_ID)
444 sscanf(&(ss[p_num]), "%g%g%g%g%g", &px, &py, &pz, &pz1, &mass);
445 else
446 sscanf(&(ss[p_num]), "%g%g%g%g%g%g", &px, &py, &pz, &pz1, &pza1, &mass);
447
448 if (FindParticle(iCharge, iStrange, iLeptonic, iBarionic, mass, PDG, ionName)) {
449 if (PDG != fSelPDG)
450 continue;
451 isFound = kTRUE;
453 new ((*fMom)[fMom->GetEntriesFast()]) TVector3(px, py, pz);
454 else
455 new ((*fMom)[fMom->GetEntriesFast()]) TVector3(px, py, pz1);
456 break; // if we need only 1 particle
457 }
458 }
459 }
460
461 return kTRUE;
462}
463
465{
466 // ---> Check for primary generator
467 if (!primGen) {
468 cout << "-E- MpdLAQGSMGeneratorExt::ReadEvent: "
469 << "No PrimaryGenerator!" << endl;
470 return kFALSE;
471 }
472 if (++fIEvent == fNEvents)
473 fIEvent = 0;
474 fMTree->GetEntry(fIEvent);
475
476 for (Int_t i = 0; i < fMom->GetEntriesFast(); i++) {
477 TVector3* v = (TVector3*)fMom->UncheckedAt(i);
478 // Give track to PrimaryGenerator
479 primGen->AddTrack(fSelPDG, v->X(), v->Y(), v->Z(), 0., 0., 0.);
480 }
481
482 return kTRUE;
483}
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
float Float_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
void Fatal(const char *location, const char *msgfmt,...)
MpdLAQGSMGeneratorExt()
Default constructor without arguments should not be used.
Bool_t ReadEventFromTxt(FairPrimaryGenerator *primGen)
Bool_t(MpdLAQGSMGeneratorExt::* ReadEventImpl)(FairPrimaryGenerator *primGen)
Bool_t ExtractEventFromTxt(FairPrimaryGenerator *primGen)
Bool_t ReadEventFromFiltered(FairPrimaryGenerator *primGen)
Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Reads on event from the input file and pushes the tracks onto the stack.
virtual ~MpdLAQGSMGeneratorExt()
Destructor.
void CloseInput()
Private method CloseInput.
Double_t fX
0: ascii input, 1: gzipped input
Int_t fQGSM_format_ID
PDG database.
Int_t RegisterIons(Int_t Max_Event_Number=0)
Private method RegisterIons.
virtual Bool_t Init()
Bool_t FindParticle(Int_t Z, Int_t strange, Int_t lepton, Int_t A, Float_t mass, Int_t &PDG, char name[11])
gzFile fGZInputFile
Input file.
const Char_t * fFileName
GZ Input file.
std::vector< la_tab_t * > fLa_tab
Bool_t fGZ_input
list of light particles known for MpdLAQGSMGenerator
virtual Bool_t GetEventHeader(char *ss)
TDatabasePDG * fPDG
Input file Name.
Bool_t general_fgets(char *ss, Int_t nn=250, FILE *p=0)
static TDatabasePDG * Instance()
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void Set(const TVector2 &v)
static TClass * Class()