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