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