FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pythia6Generator.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- M. Al-Turany June 2014 -----
10 // -------------------------------------------------------------------------
11 // -------------------------------------------------------------------------
12 // ----- Pythia6Generator source file -----
13 // ----- Created 08/08/08 by S. Spataro -----
14 // -------------------------------------------------------------------------
15 #include "Pythia6Generator.h"
16 
17 #include "FairLogger.h"
18 #include "FairPrimaryGenerator.h"
19 
20 #include <cstdio>
21 #include <iostream>
22 
23 using std::cout;
24 using std::endl;
25 using std::max;
26 
27 // ----- Default constructor ------------------------------------------
29 // ------------------------------------------------------------------------
30 
31 // ----- Standard constructor -----------------------------------------
33 {
34  fFileName = fileName;
35  fVerbose = 0;
36  cout << "-I Pythia6Generator: Opening input file " << fileName << endl;
37  if ((fInputFile = fopen(fFileName, "r")) == NULL)
38  // fInputFile = new ifstream(fFileName);
39  // if ( ! fInputFile->is_open() )
40  LOG(fatal) << "Pythia6Generator: Cannot open input file.";
41 
42  // fPDG=TDatabasePDG::Instance();
43 }
44 // ------------------------------------------------------------------------
45 
46 // ----- Destructor ---------------------------------------------------
48 // ------------------------------------------------------------------------
49 
50 // ----- Public method ReadEvent --------------------------------------
52 {
53 
54  // Check for input file
55  if (!fInputFile) {
56  // if ( ! fInputFile->is_open() ) {
57  cout << "-E Pythia6Generator: Input file not open!" << endl;
58  return kFALSE;
59  }
60 
61  // Define event variable to be read from file
62  Int_t ntracks = 0, eventID = 0, ncols = 0;
63 
64  // Define track variables to be read from file
65  Int_t nLev = 0, pdgID = 0, nM1 = -1, nM2 = -1, nDF = -1, nDL = -1;
66  Float_t fPx = 0., fPy = 0., fPz = 0., fM = 0., fE = 0.;
67  Float_t fVx = 0., fVy = 0., fVz = 0., fT = 0.;
68 
69  // Read event header line from input file
70 
71  Int_t max_nr = 0;
72 
73  Text_t buffer[200];
74  ncols = fscanf(fInputFile, "%d\t%d", &eventID, &ntracks);
75 
76  if (ncols && ntracks > 0) {
77 
78  if (fVerbose > 0)
79  cout << "Event number: " << eventID << "\tNtracks: " << ntracks << endl;
80 
81  for (Int_t ll = 0; ll < ntracks; ll++) {
82  ncols = fscanf(fInputFile,
83  "%d %d %d %d %d %d %f %f %f %f %f %f %f %f %f",
84  &nLev,
85  &pdgID,
86  &nM1,
87  &nM2,
88  &nDF,
89  &nDL,
90  &fPx,
91  &fPy,
92  &fPz,
93  &fE,
94  &fM,
95  &fVx,
96  &fVy,
97  &fVz,
98  &fT);
99  if (fVerbose > 0)
100  cout << nLev << "\t" << pdgID << "\t" << nM1 << "\t" << nM2 << "\t" << nDF << "\t" << nDL << "\t" << fPx
101  << "\t" << fPy << "\t" << fPz << "\t" << fE << "\t" << fM << "\t" << fVx << "\t" << fVy << "\t"
102  << fVz << "\t" << fT << endl;
103  if (nLev == 1)
104  primGen->AddTrack(pdgID, fPx, fPy, fPz, fVx, fVy, fVz);
105  }
106  } else {
107  cout << "-I Pythia6Generator: End of input file reached " << endl;
108  CloseInput();
109  return kFALSE;
110  }
111 
112  // If end of input file is reached : close it and abort run
113  if (feof(fInputFile)) {
114  cout << "-I Pythia6Generator: End of input file reached " << endl;
115  CloseInput();
116  return kFALSE;
117  }
118 
119  /*
120  cout << "-I Pythia6Generator: Event " << eventID << ", vertex = ("
121  << vx << "," << vy << "," << vz << ") cm, multiplicity "
122  << ntracks << endl;
123  */
124 
125  return kTRUE;
126 }
127 // ------------------------------------------------------------------------
128 
129 // ----- Private method CloseInput ------------------------------------
130 void Pythia6Generator::CloseInput()
131 {
132  if (fInputFile) {
133  // if ( fInputFile->is_open() ) {
134  {
135  cout << "-I Pythia6Generator: Closing input file " << fFileName << endl;
136  // fInputFile->close();
137 
138  fclose(fInputFile);
139  }
140  delete fInputFile;
141  fInputFile = NULL;
142  }
143 }
144 // ------------------------------------------------------------------------
145 
virtual ~Pythia6Generator()
ClassImp(FairEventBuilder)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
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)