TUHKMgen
[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
3ff7721b 28#include "AliLog.h"
ed551210 29#include "AliGenReaderSL.h"
30#include "AliRun.h"
062089eb 31#include "AliStack.h"
ed551210 32
33
34ClassImp(AliGenReaderSL)
35
36
37AliGenReaderSL& AliGenReaderSL::operator=(const AliGenReaderSL& rhs)
38{
39// Assignment operator
40 rhs.Copy(*this);
41 return *this;
42}
43
44void AliGenReaderSL::Copy(TObject&) const
45{
46 //
47 // Copy
48 //
49 Fatal("Copy","Not implemented!\n");
50}
51
52void AliGenReaderSL::Init()
53{
54 // Initialisation
55 if( !(fFile = fopen(fFileName,"r")) ) {
56 printf("Couldn't open input file: %s \n", fFileName);
57 } else {
58 printf("File %s opened \n", fFileName);
59 }
60
61
62}
63
64Int_t AliGenReaderSL::NextEvent()
65{
66// Read the next event
67
68 if (fFormat == 0) {
69 fNParticles = 4;
70 return (fNParticles);
71 }
72
73// Example
74// EVENT: 7 23 1
75// GAMMAENERGIES: 27.6431
76// VERTEX: 0 0 0 0 1 0 0 23
77 char linelabel[20];
78 int i1 = 0;
79 int i2 = 0;
80 int i3 = 0;
81
82
83 double x1 = 0.0;
84 double x2 = 0.0;
85 double x3 = 0.0;
86 double x4 = 0.0;
87
88 int ntrk = 0;
89 int nvtx = 0;
90 //
91 Float_t eGamma1, eGamma2;
92 eGamma2 = 0.;
062089eb 93 Int_t nb;
ed551210 94 // Event line
062089eb 95 nb = fscanf(fFile,"%6s %d %d %d ",linelabel, &i1, &ntrk, &i2);
3ff7721b 96 if (nb <= 0) return (0);
97 if (nb != 4) AliFatal("malformed EVENT line");
ed551210 98 fNParticles = ntrk;
37475f5f 99 //printf("Event line: %s i1 = %5d ntrk = %5d i2 = %5d \n", linelabel, i1, ntrk, i2);
ed551210 100
101 // Gamma line
102 if (fFormat == 1) {
3ff7721b 103 nb = fscanf(fFile, "%14s %f ",linelabel, &eGamma1);
104 if (nb <= 0) return (0);
105 if (nb != 2) AliFatal("malformed GAMMA1 line");
ed551210 106 } else if (fFormat == 2) {
062089eb 107 nb = fscanf(fFile, "%14s %f %f ",linelabel, &eGamma1, &eGamma2);
3ff7721b 108 if (nb <= 0) return (0);
109 if (nb != 3) AliFatal("malformed GAMMA1,GAMMA2 line");
ed551210 110 }
37475f5f 111// printf("Gamma line: %s Egamma1 = %13.3f Egamma2 = %13.3f \n", linelabel, eGamma1, eGamma2);
ed551210 112
113 // Vertex line
062089eb 114 nb = fscanf(fFile, "%7s %lf %lf %lf %lf %d %d %d %d",
ed551210 115 linelabel, &x1, &x2, &x3, &x4, &i1, &i2, &i3, &nvtx);
116// 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",
117// linelabel, x1, x2, x3, x4, i1, i2, i3, nvtx);
3ff7721b 118 if (nb <= 0) return (0);
119 if (nb != 9) AliFatal("malformed VERTEX line");
ed551210 120 if(ntrk != nvtx) printf("ERROR: ntrk = %5d nvtx = %5d \n", ntrk, nvtx);
121
122 return (fNParticles);
123
124}
125
126TParticle* AliGenReaderSL::NextParticle()
127{
128 // Read next particle
129
130 Float_t px, py, pz;
131 Int_t pdg;
132 static TParticle particle;
062089eb 133 Int_t nb;
ed551210 134 if (fFormat == 0) {
135 Int_t ievent;
136 Int_t ipart;
062089eb 137 nb = fscanf(fFile, "%d %d %d %f %f %f ", &ievent, &ipart, &pdg, &px, &py, &pz);
3ff7721b 138 if (nb <= 0) return NULL;
139 if (nb != 6) AliFatal("malformed TRACK line");
ed551210 140// printf("%5d %5d %5d %13.3f %13.3f %13.3f \n", ievent, ipart, pdg, px, py, pz);
141
142 if (pdg == 8) pdg = 211;
143 if (pdg == 9) pdg = -211;
144
145 } else {
146 char tracklabel[20];
147 int i1 = 0;
148 int i2 = 0;
149 int i3 = 0;
150 int i4 = 0;
062089eb 151 nb = fscanf(fFile,"%6s %d %f %f %f %d %d %d %d",
ed551210 152 tracklabel, &i1, &px, &py, &pz, &i2, &i3, &i4, &pdg);
3ff7721b 153 if (nb <= 0) return NULL;
154 if (nb != 9) AliFatal("malformed TRACK line");
ed551210 155// printf("Particle %5d %13.3f %13.3f %13.3f \n", pdg, px, py, pz);
156 }
062089eb 157
3ff7721b 158 const Double_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
159 const Float_t e = TMath::Sqrt(px * px + py * py + pz * pz + mass * mass);
ed551210 160 particle.SetMomentum(px, py, pz, e);
161 particle.SetPdgCode(pdg);
062089eb 162 particle.SetFirstMother(-1);
163 particle.SetLastMother(-1);
164 particle.SetBit(kTransportBit);
ed551210 165 return &particle;
166}
167
168void AliGenReaderSL::RewindEvent()
169{
3ff7721b 170 AliFatal("AliGenReaderSL::RewindEvent() is not implemented");
ed551210 171// fFile->Rewind();
172}