-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathPythia6Generator.cxx
More file actions
146 lines (121 loc) · 5.21 KB
/
Pythia6Generator.cxx
File metadata and controls
146 lines (121 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
// -------------------------------------------------------------------------
// ----- M. Al-Turany June 2014 -----
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// ----- Pythia6Generator source file -----
// ----- Created 08/08/08 by S. Spataro -----
// -------------------------------------------------------------------------
#include "Generators/Pythia6Generator.h"
#include "FairPrimaryGenerator.h"
#include <iostream>
#include <cstdio>
using std::cout;
using std::endl;
using std::max;
namespace o2
{
namespace eventgen
{
// ----- Default constructor ------------------------------------------
Pythia6Generator::Pythia6Generator() = default;
// ------------------------------------------------------------------------
// ----- Standard constructor -----------------------------------------
Pythia6Generator::Pythia6Generator(const char* fileName)
: mFileName(fileName), mInputFile(nullptr), mVerbose(0)
{
cout << "-I Pythia6Generator: Opening input file " << mFileName << endl;
if ((mInputFile = fopen(mFileName, "r")) == nullptr) {
Fatal("Pythia6Generator", "Cannot open input file.");
}
// mPDG=TDatabasePDG::Instance();
}
// ------------------------------------------------------------------------
// ----- Destructor ---------------------------------------------------
Pythia6Generator::~Pythia6Generator()
{
CloseInput();
}
// ------------------------------------------------------------------------
// ----- Public method ReadEvent --------------------------------------
Bool_t Pythia6Generator::ReadEvent(FairPrimaryGenerator* primGen)
{
// Check for input file
if (!mInputFile) {
// if ( ! mInputFile->is_open() ) {
cout << "-E Pythia6Generator: Input file not open!" << endl;
return kFALSE;
}
// Define event variable to be read from file
Int_t ntracks = 0, eventID = 0, ncols = 0;
// Define track variables to be read from file
Int_t nLev = 0, pdgID = 0, nM1 = -1, nM2 = -1, nDF = -1, nDL = -1;
Float_t fPx = 0., fPy = 0., fPz = 0., fM = 0., fE = 0.;
Float_t fVx = 0., fVy = 0., fVz = 0., fT = 0.;
// Read event header line from input file
Int_t max_nr = 0;
Text_t buffer[200];
ncols = fscanf(mInputFile, "%d\t%d", &eventID, &ntracks);
if (ncols && ntracks > 0) {
if (mVerbose > 0)
cout << "Event number: " << eventID << "\tNtracks: " << ntracks << endl;
for (Int_t ll = 0; ll < ntracks; ll++) {
ncols = fscanf(mInputFile, "%d %d %d %d %d %d %f %f %f %f %f %f %f %f %f", &nLev, &pdgID, &nM1, &nM2, &nDF, &nDL, &fPx, &fPy, &fPz, &fE, &fM, &fVx, &fVy, &fVz, &fT);
if (mVerbose > 0)
cout << nLev << "\t" << pdgID << "\t" << nM1 << "\t" << nM2 << "\t" << nDF << "\t" << nDL << "\t" << fPx << "\t" << fPy << "\t" << fPz << "\t" << fE << "\t" << fM << "\t" << fVx << "\t" << fVy << "\t" << fVz << "\t" << fT << endl;
if (nLev == 1)
primGen->AddTrack(pdgID, fPx, fPy, fPz, fVx, fVy, fVz);
}
} else {
cout << "-I Pythia6Generator: End of input file reached " << endl;
CloseInput();
return kFALSE;
}
// If end of input file is reached : close it and abort run
if (feof(mInputFile)) {
cout << "-I Pythia6Generator: End of input file reached " << endl;
CloseInput();
return kFALSE;
}
/*
cout << "-I Pythia6Generator: Event " << eventID << ", vertex = ("
<< vx << "," << vy << "," << vz << ") cm, multiplicity "
<< ntracks << endl;
*/
return kTRUE;
}
// ------------------------------------------------------------------------
// ----- Private method CloseInput ------------------------------------
void Pythia6Generator::CloseInput()
{
if (mInputFile) {
//if ( mInputFile->is_open() ) {
{
cout << "-I Pythia6Generator: Closing input file "
<< mFileName << endl;
// mInputFile->close();
fclose(mInputFile);
}
delete mInputFile;
mInputFile = nullptr;
}
}
// ------------------------------------------------------------------------
} // namespace eventgen
} // namespace o2
ClassImp(o2::eventgen::Pythia6Generator);