]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Bugfix in AliPoints2Memory
[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$
2c354237 18Revision 1.21 2002/04/26 10:39:31 morsch
19AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
20
380956c5 21Revision 1.20 2002/03/22 09:43:28 morsch
22Don't delete the TParticle.
23
14412d0b 24Revision 1.19 2002/02/08 16:50:50 morsch
25Add name and title in constructor.
26
8b31bfac 27Revision 1.18 2001/11/12 14:31:00 morsch
28Memory leaks fixed. (M. Bondila)
29
ae872676 30Revision 1.17 2001/11/09 09:12:58 morsch
31Generalization by using AliGenReader object to read particles from file.
32
a48e3376 33Revision 1.16 2001/07/27 17:09:35 morsch
34Use local SetTrack, KeepTrack and SetHighWaterMark methods
35to delegate either to local stack or to stack owned by AliRun.
36(Piotr Skowronski, A.M.)
37
a99cf51f 38Revision 1.15 2001/01/23 13:29:37 morsch
39Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
40and GEANT3 codes (old ntuples) in input file.
41
f177bfed 42Revision 1.14 2000/12/21 16:24:06 morsch
43Coding convention clean-up
44
675e9664 45Revision 1.13 2000/11/30 07:12:50 alibrary
46Introducing new Rndm and QA classes
47
65fb704d 48Revision 1.12 2000/10/27 13:54:45 morsch
49Remove explicite reference to input file from constuctor.
50
38e6c6e6 51Revision 1.11 2000/10/02 21:28:06 fca
52Removal of useless dependecies via forward declarations
53
94de3818 54Revision 1.10 2000/07/11 18:24:55 fca
55Coding convention corrections + few minor bug fixes
56
aee8290b 57Revision 1.9 2000/06/14 15:20:09 morsch
58Include clean-up (IH)
59
5c3fd7ea 60Revision 1.8 2000/06/09 20:36:44 morsch
61All coding rule violations except RS3 corrected
62
f87cfe57 63Revision 1.7 2000/02/16 14:56:27 morsch
64Convert geant particle code into pdg code before putting particle on the stack.
65
3c8636e9 66Revision 1.6 1999/11/09 07:38:48 fca
67Changes for compatibility with version 2.23 of ROOT
68
084c1b4a 69Revision 1.5 1999/09/29 09:24:12 fca
70Introduction of the Copyright and cvs Log
71
4c039060 72*/
73
675e9664 74
a48e3376 75// Event generator that using an instance of type AliGenReader
76// reads particles from a file and applies cuts.
675e9664 77
084c1b4a 78#include <iostream.h>
79
693caace 80#include "AliGenExtFile.h"
693caace 81#include "AliRun.h"
5c3fd7ea 82
a48e3376 83#include <TParticle.h>
693caace 84#include <TFile.h>
a48e3376 85#include <TTree.h>
86
5c3fd7ea 87
693caace 88 ClassImp(AliGenExtFile)
380956c5 89
90AliGenExtFile::AliGenExtFile()
91 :AliGenMC()
693caace 92{
f87cfe57 93// Constructor
693caace 94//
95// Read all particles
a48e3376 96 fNpart =- 1;
97 fReader = 0;
693caace 98}
99
100AliGenExtFile::AliGenExtFile(Int_t npart)
380956c5 101 :AliGenMC(npart)
693caace 102{
f87cfe57 103// Constructor
a48e3376 104 fName = "ExtFile";
105 fTitle = "Primaries from ext. File";
106 fReader = 0;
693caace 107}
108
f87cfe57 109AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
110{
111// copy constructor
112}
693caace 113//____________________________________________________________
114AliGenExtFile::~AliGenExtFile()
115{
f87cfe57 116// Destructor
a48e3376 117 delete fReader;
693caace 118}
119
a48e3376 120//___________________________________________________________
121void AliGenExtFile::Init()
693caace 122{
a48e3376 123// Initialize
124 if (fReader) fReader->Init();
693caace 125}
126
a48e3376 127
693caace 128void AliGenExtFile::Generate()
129{
f87cfe57 130// Generate particles
693caace 131
a48e3376 132 Float_t polar[3] = {0,0,0};
693caace 133 //
a48e3376 134 Float_t origin[3] = {0,0,0};
693caace 135 Float_t p[3];
136 Float_t random[6];
a48e3376 137 Int_t i, j, nt;
693caace 138 //
693caace 139 for (j=0;j<3;j++) origin[j]=fOrigin[j];
a48e3376 140 if(fVertexSmear == kPerTrack) {
65fb704d 141 Rndm(random,6);
a48e3376 142 for (j = 0; j < 3; j++) {
143 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
693caace 144 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
145 }
146 }
147
380956c5 148 while(1) {
149 Int_t nTracks = fReader->NextEvent();
150 if (nTracks == 0) {
151 // printf("\n No more events !!! !\n");
152 Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
693caace 153 return;
380956c5 154 }
155
156 //
157 // Particle selection loop
158 //
159 // The selction criterium for the external file generator is as follows:
160 //
161 // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
162 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
163 // fYMin, fYMax.
164 // If the particle does not satisfy these cuts, it is not put on the
165 // stack.
166 // 2) If fCutOnChild and some specific child is selected (e.g. if
167 // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
168 // child falls into the child-cuts.
169 if(fCutOnChild) {
170 // Count the selected children
171 Int_t nSelected = 0;
172
173 for (i = 0; i < nTracks; i++) {
174 TParticle* iparticle = fReader->NextParticle();
175 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
176 kf = TMath::Abs(kf);
177 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
178 nSelected++;
179 }
180 }
181 if (!nSelected) continue; // No particle selected: Go to next event
182 fReader->RewindEvent();
183 }
a48e3376 184
380956c5 185 //
186 // Stack filling loop
187 //
188 for (i = 0; i < nTracks; i++) {
14412d0b 189
a48e3376 190 TParticle* iparticle = fReader->NextParticle();
380956c5 191 if (!KinematicSelection(iparticle,0)) {
192 Double_t pz = iparticle->Pz();
193 Double_t e = iparticle->Energy();
194 Double_t y;
195 if ((e-pz) == 0) {
a48e3376 196 y = 20.;
380956c5 197 } else if ((e+pz) == 0.) {
a48e3376 198 y = -20.;
380956c5 199 } else {
a48e3376 200 y = 0.5*TMath::Log((e+pz)/(e-pz));
380956c5 201 }
202 printf("\n Not selected %d %f %f %f %f %f", i,
203 iparticle->Theta(),
204 iparticle->Phi(),
205 iparticle->P(),
206 iparticle->Pt(),
207 y);
208 delete iparticle;
209 continue;
a48e3376 210 }
211 p[0] = iparticle->Px();
212 p[1] = iparticle->Py();
213 p[2] = iparticle->Pz();
214 Int_t idpart = iparticle->GetPdgCode();
215 if(fVertexSmear==kPerTrack) {
216 Rndm(random,6);
217 for (j = 0; j < 3; j++) {
218 origin[j]=fOrigin[j]
219 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
220 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
693caace 221 }
693caace 222 }
380956c5 223 Int_t decayed = iparticle->GetFirstDaughter();
224 Int_t doTracking = fTrackIt && (decayed < 0) &&
225 (TMath::Abs(idpart) > 10);
226 // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
227 // idpart,decayed, doTracking);
228 SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
229 KeepTrack(nt);
230 } // track loop
231
232 break;
233
234 } // event loop
235
236 SetHighWaterMark(nt);
2c354237 237 CdEventFile();
238}
380956c5 239
2c354237 240void AliGenExtFile::CdEventFile()
241{
242// CD back to the event file
a48e3376 243 TFile *pFile=0;
a48e3376 244 if (!gAlice) {
245 gAlice = (AliRun*)pFile->Get("gAlice");
246 if (gAlice) printf("AliRun object found on file\n");
247 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
248 }
249 TTree *fAli=gAlice->TreeK();
250 if (fAli) pFile =fAli->GetCurrentFile();
2c354237 251 pFile->cd();
693caace 252}
253
254
f87cfe57 255AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
256{
257// Assignment operator
258 return *this;
259}
260
693caace 261
262
263
264
265
266
267