1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.19 2002/02/08 16:50:50 morsch
19 Add name and title in constructor.
21 Revision 1.18 2001/11/12 14:31:00 morsch
22 Memory leaks fixed. (M. Bondila)
24 Revision 1.17 2001/11/09 09:12:58 morsch
25 Generalization by using AliGenReader object to read particles from file.
27 Revision 1.16 2001/07/27 17:09:35 morsch
28 Use local SetTrack, KeepTrack and SetHighWaterMark methods
29 to delegate either to local stack or to stack owned by AliRun.
30 (Piotr Skowronski, A.M.)
32 Revision 1.15 2001/01/23 13:29:37 morsch
33 Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
34 and GEANT3 codes (old ntuples) in input file.
36 Revision 1.14 2000/12/21 16:24:06 morsch
37 Coding convention clean-up
39 Revision 1.13 2000/11/30 07:12:50 alibrary
40 Introducing new Rndm and QA classes
42 Revision 1.12 2000/10/27 13:54:45 morsch
43 Remove explicite reference to input file from constuctor.
45 Revision 1.11 2000/10/02 21:28:06 fca
46 Removal of useless dependecies via forward declarations
48 Revision 1.10 2000/07/11 18:24:55 fca
49 Coding convention corrections + few minor bug fixes
51 Revision 1.9 2000/06/14 15:20:09 morsch
54 Revision 1.8 2000/06/09 20:36:44 morsch
55 All coding rule violations except RS3 corrected
57 Revision 1.7 2000/02/16 14:56:27 morsch
58 Convert geant particle code into pdg code before putting particle on the stack.
60 Revision 1.6 1999/11/09 07:38:48 fca
61 Changes for compatibility with version 2.23 of ROOT
63 Revision 1.5 1999/09/29 09:24:12 fca
64 Introduction of the Copyright and cvs Log
69 // Event generator that using an instance of type AliGenReader
70 // reads particles from a file and applies cuts.
74 #include "AliGenExtFile.h"
77 #include <TParticle.h>
82 ClassImp(AliGenExtFile)
83 AliGenExtFile::AliGenExtFile()
93 AliGenExtFile::AliGenExtFile(Int_t npart)
98 fTitle = "Primaries from ext. File";
102 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
106 //____________________________________________________________
107 AliGenExtFile::~AliGenExtFile()
113 //___________________________________________________________
114 void AliGenExtFile::Init()
117 if (fReader) fReader->Init();
121 void AliGenExtFile::Generate()
123 // Generate particles
125 Float_t polar[3] = {0,0,0};
127 Float_t origin[3] = {0,0,0};
132 for (j=0;j<3;j++) origin[j]=fOrigin[j];
133 if(fVertexSmear == kPerTrack) {
135 for (j = 0; j < 3; j++) {
136 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
137 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
141 Int_t nTracks = fReader->NextEvent();
143 printf("\n No more events !!! !\n");
147 for (i = 0; i < nTracks; i++) {
150 TParticle* iparticle = fReader->NextParticle();
151 Double_t theta = iparticle->Theta();
152 Double_t phi = iparticle->Phi();
153 if (phi > TMath::Pi()) phi -= 2.*TMath::Pi();
154 Double_t pmom = iparticle->P();
155 Double_t pz = iparticle->Pz();
156 Double_t e = iparticle->Energy();
157 Double_t pt = iparticle->Pt();
161 } else if ((e+pz) == 0.) {
164 y = 0.5*TMath::Log((e+pz)/(e-pz));
167 if(theta < fThetaMin || theta > fThetaMax ||
168 phi < fPhiMin || phi > fPhiMax ||
169 pmom < fPMin || pmom > fPMax ||
170 pt < fPtMin || pt > fPtMax ||
171 y < fYMin || y > fYMax )
173 printf("\n Not selected %d %f %f %f %f %f", i, theta, phi, pmom, pt, y);
177 p[0] = iparticle->Px();
178 p[1] = iparticle->Py();
179 p[2] = iparticle->Pz();
180 Int_t idpart = iparticle->GetPdgCode();
181 if(fVertexSmear==kPerTrack) {
183 for (j = 0; j < 3; j++) {
185 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
186 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
189 SetTrack(fTrackIt,-1,idpart,p,origin,polar,0,kPPrimary,nt);
192 // Get AliRun object or create it
194 gAlice = (AliRun*)pFile->Get("gAlice");
195 if (gAlice) printf("AliRun object found on file\n");
196 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
198 TTree *fAli=gAlice->TreeK();
199 if (fAli) pFile =fAli->GetCurrentFile();
204 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
206 // Assignment operator