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