FairShip
Loading...
Searching...
No Matches
Pythia6Generator.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5// -------------------------------------------------------------------------
6// ----- Pythia6Generator source file -----
7// ----- Created 08/08/08 by S. Spataro -----
8// -------------------------------------------------------------------------
9#include "Pythia6Generator.h"
10
11#include <cstdio>
12#include <iostream>
13
14#include "FairPrimaryGenerator.h"
15
16using std::cout;
17using std::endl;
18using std::max;
19
20// ----- Default constructor ------------------------------------------
22// ------------------------------------------------------------------------
23
24// ----- Standard constructor -----------------------------------------
26 fFileName = fileName;
27 fVerbose = 0;
28 cout << "-I Pythia6Generator: Opening input file " << fileName << endl;
29 fInputFile = fopen(fFileName, "r");
30 if (fInputFile == nullptr)
31 // fInputFile = new ifstream(fFileName);
32 // if ( ! fInputFile->is_open() )
33 Fatal("Pythia6Generator", "Cannot open input file.");
34
35 // fPDG=TDatabasePDG::Instance();
36}
37// ------------------------------------------------------------------------
38
39// ----- Destructor ---------------------------------------------------
41// ------------------------------------------------------------------------
42
43// ----- Public method ReadEvent --------------------------------------
44Bool_t Pythia6Generator::ReadEvent(FairPrimaryGenerator* primGen) {
45 // Check for input file
46 if (!fInputFile) {
47 // if ( ! fInputFile->is_open() ) {
48 cout << "-E Pythia6Generator: Input file not open!" << endl;
49 return kFALSE;
50 }
51
52 // Define event variable to be read from file
53 Int_t ntracks = 0, eventID = 0, ncols = 0;
54
55 // Define track variables to be read from file
56 Int_t nLev = 0, pdgID = 0, nM1 = -1, nM2 = -1, nDF = -1, nDL = -1;
57 Float_t fPx = 0., fPy = 0., fPz = 0., fM = 0., fE = 0.;
58 Float_t fVx = 0., fVy = 0., fVz = 0., fT = 0.;
59
60 // Read event header line from input file
61
62 ncols = fscanf(fInputFile, "%d\t%d", &eventID, &ntracks);
63
64 if (ncols && ntracks > 0) {
65 if (fVerbose > 0)
66 cout << "Event number: " << eventID << "\tNtracks: " << ntracks << endl;
67
68 for (Int_t ll = 0; ll < ntracks; ll++) {
69 (void)fscanf(fInputFile, "%d %d %d %d %d %d %f %f %f %f %f %f %f %f %f",
70 &nLev, &pdgID, &nM1, &nM2, &nDF, &nDL, &fPx, &fPy, &fPz, &fE,
71 &fM, &fVx, &fVy, &fVz, &fT);
72 if (fVerbose > 0)
73 cout << nLev << "\t" << pdgID << "\t" << nM1 << "\t" << nM2 << "\t"
74 << nDF << "\t" << nDL << "\t" << fPx << "\t" << fPy << "\t" << fPz
75 << "\t" << fE << "\t" << fM << "\t" << fVx << "\t" << fVy << "\t"
76 << fVz << "\t" << fT << endl;
77 if (nLev == 1) primGen->AddTrack(pdgID, fPx, fPy, fPz, fVx, fVy, fVz);
78 }
79 } else {
80 cout << "-I Pythia6Generator: End of input file reached " << endl;
81 CloseInput();
82 return kFALSE;
83 }
84
85 // If end of input file is reached : close it and abort run
86 if (feof(fInputFile)) {
87 cout << "-I Pythia6Generator: End of input file reached " << endl;
88 CloseInput();
89 return kFALSE;
90 }
91
92 /*
93 cout << "-I Pythia6Generator: Event " << eventID << ", vertex = ("
94 << vx << "," << vy << "," << vz << ") cm, multiplicity "
95 << ntracks << endl;
96 */
97
98 return kTRUE;
99}
100// ------------------------------------------------------------------------
101
102// ----- Private method CloseInput ------------------------------------
104 if (fInputFile) {
105 // if ( fInputFile->is_open() ) {
106 {
107 cout << "-I Pythia6Generator: Closing input file " << fFileName << endl;
108 // fInputFile->close();
109
110 fclose(fInputFile);
111 }
112 delete fInputFile;
113 fInputFile = nullptr;
114 }
115}
116// ------------------------------------------------------------------------
FILE * fInputFile
Input file Name.
Bool_t ReadEvent(FairPrimaryGenerator *primGen) override
const Char_t * fFileName
void CloseInput()
Verbose Level.
~Pythia6Generator() override