Coverity fix.
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderSL.cxx
CommitLineData
ed551210 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17//
18// Realisations of the AliGenReader interface to be used with AliGenExFile.
19// NextEvent() loops over events
20// and NextParticle() loops over particles.
21// This implementation reads various StarLight output formats
22// Author: andreas.morsch@cern.ch
23
24#include <TVirtualMC.h>
25#include <TDatabasePDG.h>
26#include <TParticle.h>
27
28#include "AliGenReaderSL.h"
29#include "AliRun.h"
30
31
32ClassImp(AliGenReaderSL)
33
34
35AliGenReaderSL& AliGenReaderSL::operator=(const AliGenReaderSL& rhs)
36{
37// Assignment operator
38 rhs.Copy(*this);
39 return *this;
40}
41
42void AliGenReaderSL::Copy(TObject&) const
43{
44 //
45 // Copy
46 //
47 Fatal("Copy","Not implemented!\n");
48}
49
50void AliGenReaderSL::Init()
51{
52 // Initialisation
53 if( !(fFile = fopen(fFileName,"r")) ) {
54 printf("Couldn't open input file: %s \n", fFileName);
55 } else {
56 printf("File %s opened \n", fFileName);
57 }
58
59
60}
61
62Int_t AliGenReaderSL::NextEvent()
63{
64// Read the next event
65
66 if (fFormat == 0) {
67 fNParticles = 4;
68 return (fNParticles);
69 }
70
71// Example
72// EVENT: 7 23 1
73// GAMMAENERGIES: 27.6431
74// VERTEX: 0 0 0 0 1 0 0 23
75 char linelabel[20];
76 int i1 = 0;
77 int i2 = 0;
78 int i3 = 0;
79
80
81 double x1 = 0.0;
82 double x2 = 0.0;
83 double x3 = 0.0;
84 double x4 = 0.0;
85
86 int ntrk = 0;
87 int nvtx = 0;
88 //
89 Float_t eGamma1, eGamma2;
90 eGamma2 = 0.;
91
92 // Event line
93 fscanf(fFile,"%s %d %d %d ",linelabel, &i1, &ntrk, &i2);
94 fNParticles = ntrk;
95// printf("Event line: %s i1 = %5d ntrk = %5d i2 = %5d \n", linelabel, i1, ntrk, i2);
96
97 // Gamma line
98 if (fFormat == 1) {
99 fscanf(fFile, "%s %f ",linelabel, &eGamma1);
100 } else if (fFormat == 2) {
101 fscanf(fFile, "%s %f %f ",linelabel, &eGamma1, &eGamma2);
102 }
103
104// printf("Gamma line: %s Egamma1 = %13.3f Egamma2 = %13.3f \n", linelabel, eGamma1, eGamma2);
105
106 // Vertex line
107 fscanf(fFile, "%s %lf %lf %lf %lf %d %d %d %d",
108 linelabel, &x1, &x2, &x3, &x4, &i1, &i2, &i3, &nvtx);
109// printf("Vertex line: %s (x = %13.3f, y = %13.3f, z = %13.3f, t = %13.3f) i1 = %5d i2 = %5d i3 = %5d nvtx = %5d \n",
110// linelabel, x1, x2, x3, x4, i1, i2, i3, nvtx);
111 if(ntrk != nvtx) printf("ERROR: ntrk = %5d nvtx = %5d \n", ntrk, nvtx);
112
113 return (fNParticles);
114
115}
116
117TParticle* AliGenReaderSL::NextParticle()
118{
119 // Read next particle
120
121 Float_t px, py, pz;
122 Int_t pdg;
123 static TParticle particle;
124
125 if (fFormat == 0) {
126 Int_t ievent;
127 Int_t ipart;
128 fscanf(fFile, "%d %d %d %f %f %f ", &ievent, &ipart, &pdg, &px, &py, &pz);
129// printf("%5d %5d %5d %13.3f %13.3f %13.3f \n", ievent, ipart, pdg, px, py, pz);
130
131 if (pdg == 8) pdg = 211;
132 if (pdg == 9) pdg = -211;
133
134 } else {
135 char tracklabel[20];
136 int i1 = 0;
137 int i2 = 0;
138 int i3 = 0;
139 int i4 = 0;
140 fscanf(fFile,"%s %d %f %f %f %d %d %d %d",
141 tracklabel, &i1, &px, &py, &pz, &i2, &i3, &i4, &pdg);
142// printf("Particle %5d %13.3f %13.3f %13.3f \n", pdg, px, py, pz);
143 }
144
145 Double_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
146 Float_t e = TMath::Sqrt(px * px + py * py + pz * pz + mass * mass);
147 particle.SetMomentum(px, py, pz, e);
148 particle.SetPdgCode(pdg);
149
150 return &particle;
151}
152
153void AliGenReaderSL::RewindEvent()
154{
155// fFile->Rewind();
156}