FairRoot/PandaRoot
PndPythia6Generator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndPythia6Generator source file -----
3 // ----- Created 08/08/08 by S. Spataro -----
4 // -------------------------------------------------------------------------
5 #include "PndPythia6Generator.h"
6 
7 #include "FairPrimaryGenerator.h"
8 
9 #include <iostream>
10 #include <cstdio>
11 
12 using std::cout;
13 using std::endl;
14 using std::max;
15 
16 // ----- Default constructor ------------------------------------------
18 // ------------------------------------------------------------------------
19 
20 
21 
22 // ----- Standard constructor -----------------------------------------
24  fFileName = fileName;
25  fVerbose = 0;
26  cout << "-I PndPythia6Generator: Opening input file " << fileName << endl;
27  if ((fInputFile = fopen(fFileName,"r"))==NULL)
28  // fInputFile = new ifstream(fFileName);
29  // if ( ! fInputFile->is_open() )
30  Fatal("PndPythia6Generator","Cannot open input file.");
31 
32  // fPDG=TDatabasePDG::Instance();
33 }
34 // ------------------------------------------------------------------------
35 
36 
37 
38 // ----- Destructor ---------------------------------------------------
40  CloseInput();
41 }
42 // ------------------------------------------------------------------------
43 
44 
45 
46 // ----- Public method ReadEvent --------------------------------------
48 
49  // Check for input file
50  if (!fInputFile) {
51  // if ( ! fInputFile->is_open() ) {
52  cout << "-E PndPythia6Generator: Input file not open!" << endl;
53  return kFALSE;
54  }
55 
56  // Define event variable to be read from file
57  Int_t ntracks = 0, eventID = 0, ncols = 0;
58 
59  // Define track variables to be read from file
60  Int_t nLev = 0, pdgID = 0, nM1 = -1, nM2 = -1, nDF = -1, nDL = -1;
61  Float_t fPx = 0., fPy = 0., fPz = 0., fM = 0., fE = 0.;
62  Float_t fVx = 0., fVy = 0., fVz = 0., fT = 0.;
63 
64  // Read event header line from input file
65 
66  //Int_t max_nr = 0; //[R.K. 01/2017] unused variable?
67 
68  //Text_t buffer[200]; //[R.K. 01/2017] unused variable?
69  ncols = fscanf(fInputFile,"%d\t%d", &eventID, &ntracks);
70 
71  if (ncols && ntracks>0) {
72 
73  if (fVerbose>0) cout << "Event number: " << eventID << "\tNtracks: " << ntracks << endl;
74 
75  for (Int_t ll=0; ll<ntracks; ll++)
76  {
77  ncols = fscanf(fInputFile,"%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);
78  if (fVerbose>0) cout << nLev << "\t" << pdgID << "\t" << nM1 << "\t" << nM2 << "\t" << nDF << "\t" << nDL <<
79  "\t" << fPx << "\t" << fPy << "\t" << fPz << "\t" << fE << "\t" << fM << "\t" << fVx << "\t" << fVy << "\t" << fVz << "\t" << fT << endl;
80  if (nLev==1)
81  primGen->AddTrack(pdgID, fPx, fPy, fPz, fVx, fVy, fVz);
82  }
83  }
84  else {
85  cout << "-I PndPythia6Generator: End of input file reached " << endl;
86  CloseInput();
87  return kFALSE;
88  }
89 
90 
91  // If end of input file is reached : close it and abort run
92  if ( feof(fInputFile) ) {
93  cout << "-I PndPythia6Generator: End of input file reached " << endl;
94  CloseInput();
95  return kFALSE;
96  }
97 
98  /*
99  cout << "-I PndPythia6Generator: Event " << eventID << ", vertex = ("
100  << vx << "," << vy << "," << vz << ") cm, multiplicity "
101  << ntracks << endl;
102  */
103 
104  return kTRUE;
105 }
106 // ------------------------------------------------------------------------
107 
108 
109 
110 // ----- Private method CloseInput ------------------------------------
112  if ( fInputFile ) {
113  //if ( fInputFile->is_open() ) {
114  {
115  cout << "-I PndPythia6Generator: Closing input file "
116  << fFileName << endl;
117  // fInputFile->close();
118 
119  fclose(fInputFile);
120  }
121  delete fInputFile;
122  fInputFile = NULL;
123  }
124 }
125 // ------------------------------------------------------------------------
126 
127 
129 
TClonesArray * fT
Definition: drawGLTracks.C:13
void CloseInput()
Verbose Level.
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
FILE * fInputFile
Input file Name.
const Char_t * fFileName
ClassImp(PndAnaContFact)
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)