]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Memory leaks fixed. (M. Bondila)
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
CommitLineData
4c039060 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/*
17$Log$
ae872676 18Revision 1.17 2001/11/09 09:12:58 morsch
19Generalization by using AliGenReader object to read particles from file.
20
a48e3376 21Revision 1.16 2001/07/27 17:09:35 morsch
22Use local SetTrack, KeepTrack and SetHighWaterMark methods
23to delegate either to local stack or to stack owned by AliRun.
24(Piotr Skowronski, A.M.)
25
a99cf51f 26Revision 1.15 2001/01/23 13:29:37 morsch
27Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
28and GEANT3 codes (old ntuples) in input file.
29
f177bfed 30Revision 1.14 2000/12/21 16:24:06 morsch
31Coding convention clean-up
32
675e9664 33Revision 1.13 2000/11/30 07:12:50 alibrary
34Introducing new Rndm and QA classes
35
65fb704d 36Revision 1.12 2000/10/27 13:54:45 morsch
37Remove explicite reference to input file from constuctor.
38
38e6c6e6 39Revision 1.11 2000/10/02 21:28:06 fca
40Removal of useless dependecies via forward declarations
41
94de3818 42Revision 1.10 2000/07/11 18:24:55 fca
43Coding convention corrections + few minor bug fixes
44
aee8290b 45Revision 1.9 2000/06/14 15:20:09 morsch
46Include clean-up (IH)
47
5c3fd7ea 48Revision 1.8 2000/06/09 20:36:44 morsch
49All coding rule violations except RS3 corrected
50
f87cfe57 51Revision 1.7 2000/02/16 14:56:27 morsch
52Convert geant particle code into pdg code before putting particle on the stack.
53
3c8636e9 54Revision 1.6 1999/11/09 07:38:48 fca
55Changes for compatibility with version 2.23 of ROOT
56
084c1b4a 57Revision 1.5 1999/09/29 09:24:12 fca
58Introduction of the Copyright and cvs Log
59
4c039060 60*/
61
675e9664 62
a48e3376 63// Event generator that using an instance of type AliGenReader
64// reads particles from a file and applies cuts.
675e9664 65
084c1b4a 66#include <iostream.h>
67
693caace 68#include "AliGenExtFile.h"
693caace 69#include "AliRun.h"
5c3fd7ea 70
a48e3376 71#include <TParticle.h>
693caace 72#include <TFile.h>
a48e3376 73#include <TTree.h>
74
5c3fd7ea 75
693caace 76 ClassImp(AliGenExtFile)
77 AliGenExtFile::AliGenExtFile()
78 :AliGenerator(-1)
79{
f87cfe57 80// Constructor
693caace 81 fName="ExtFile";
82 fTitle="Primaries from ext. File";
693caace 83//
84// Read all particles
a48e3376 85 fNpart =- 1;
86 fReader = 0;
693caace 87}
88
89AliGenExtFile::AliGenExtFile(Int_t npart)
90 :AliGenerator(npart)
91{
f87cfe57 92// Constructor
a48e3376 93 fName = "ExtFile";
94 fTitle = "Primaries from ext. File";
95 fReader = 0;
693caace 96}
97
f87cfe57 98AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
99{
100// copy constructor
101}
693caace 102//____________________________________________________________
103AliGenExtFile::~AliGenExtFile()
104{
f87cfe57 105// Destructor
a48e3376 106 delete fReader;
693caace 107}
108
a48e3376 109//___________________________________________________________
110void AliGenExtFile::Init()
693caace 111{
a48e3376 112// Initialize
113 if (fReader) fReader->Init();
693caace 114}
115
a48e3376 116
693caace 117void AliGenExtFile::Generate()
118{
f87cfe57 119// Generate particles
693caace 120
a48e3376 121 Float_t polar[3] = {0,0,0};
693caace 122 //
a48e3376 123 Float_t origin[3] = {0,0,0};
693caace 124 Float_t p[3];
125 Float_t random[6];
a48e3376 126 Int_t i, j, nt;
693caace 127 //
693caace 128 for (j=0;j<3;j++) origin[j]=fOrigin[j];
a48e3376 129 if(fVertexSmear == kPerTrack) {
65fb704d 130 Rndm(random,6);
a48e3376 131 for (j = 0; j < 3; j++) {
132 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
693caace 133 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
134 }
135 }
136
a48e3376 137 Int_t nTracks = fReader->NextEvent();
138 if (nTracks == 0) {
139 printf("\n No more events !!! !\n");
693caace 140 return;
141 }
a48e3376 142
143 for (i = 0; i < nTracks; i++) {
144 TParticle* iparticle = fReader->NextParticle();
145 Double_t theta = iparticle->Theta();
146 Double_t phi = iparticle->Phi();
147 if (phi > TMath::Pi()) phi -= 2.*TMath::Pi();
148 Double_t pmom = iparticle->P();
149 Double_t pz = iparticle->Pz();
150 Double_t e = iparticle->Energy();
151 Double_t pt = iparticle->Pt();
152 Double_t y;
153
154 if ((e-pz) == 0) {
155 y = 20.;
156 } else if ((e+pz) == 0.) {
157 y = -20.;
c7a01d5a 158 } else {
a48e3376 159 y = 0.5*TMath::Log((e+pz)/(e-pz));
c7a01d5a 160 }
a48e3376 161
162 if(theta < fThetaMin || theta > fThetaMax ||
163 phi < fPhiMin || phi > fPhiMax ||
164 pmom < fPMin || pmom > fPMax ||
165 pt < fPtMin || pt > fPtMax ||
166 y < fYMin || y > fYMax )
693caace 167 {
a48e3376 168 printf("\n Not selected %d %f %f %f %f %f", i, theta, phi, pmom, pt, y);
ae872676 169 delete iparticle;
a48e3376 170 continue;
171 }
172 p[0] = iparticle->Px();
173 p[1] = iparticle->Py();
174 p[2] = iparticle->Pz();
175 Int_t idpart = iparticle->GetPdgCode();
176 if(fVertexSmear==kPerTrack) {
177 Rndm(random,6);
178 for (j = 0; j < 3; j++) {
179 origin[j]=fOrigin[j]
180 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
181 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
693caace 182 }
693caace 183 }
a48e3376 184 SetTrack(fTrackIt,-1,idpart,p,origin,polar,0,kPPrimary,nt);
ae872676 185 delete iparticle;
186 }
a48e3376 187 TFile *pFile=0;
693caace 188// Get AliRun object or create it
a48e3376 189 if (!gAlice) {
190 gAlice = (AliRun*)pFile->Get("gAlice");
191 if (gAlice) printf("AliRun object found on file\n");
192 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
193 }
194 TTree *fAli=gAlice->TreeK();
195 if (fAli) pFile =fAli->GetCurrentFile();
196 pFile->cd();
693caace 197}
198
199
f87cfe57 200AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
201{
202// Assignment operator
203 return *this;
204}
205
693caace 206
207
208
209
210
211
212