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.23 2002/10/14 14:55:35 hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
21 Revision 1.20.4.1 2002/06/10 14:57:41 hristov
24 Revision 1.22 2002/05/15 11:59:49 morsch
25 CdEventFile() method added.
27 Revision 1.21 2002/04/26 10:39:31 morsch
28 AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
30 Revision 1.20 2002/03/22 09:43:28 morsch
31 Don't delete the TParticle.
33 Revision 1.19 2002/02/08 16:50:50 morsch
34 Add name and title in constructor.
36 Revision 1.18 2001/11/12 14:31:00 morsch
37 Memory leaks fixed. (M. Bondila)
39 Revision 1.17 2001/11/09 09:12:58 morsch
40 Generalization by using AliGenReader object to read particles from file.
42 Revision 1.16 2001/07/27 17:09:35 morsch
43 Use local SetTrack, KeepTrack and SetHighWaterMark methods
44 to delegate either to local stack or to stack owned by AliRun.
45 (Piotr Skowronski, A.M.)
47 Revision 1.15 2001/01/23 13:29:37 morsch
48 Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
49 and GEANT3 codes (old ntuples) in input file.
51 Revision 1.14 2000/12/21 16:24:06 morsch
52 Coding convention clean-up
54 Revision 1.13 2000/11/30 07:12:50 alibrary
55 Introducing new Rndm and QA classes
57 Revision 1.12 2000/10/27 13:54:45 morsch
58 Remove explicite reference to input file from constuctor.
60 Revision 1.11 2000/10/02 21:28:06 fca
61 Removal of useless dependecies via forward declarations
63 Revision 1.10 2000/07/11 18:24:55 fca
64 Coding convention corrections + few minor bug fixes
66 Revision 1.9 2000/06/14 15:20:09 morsch
69 Revision 1.8 2000/06/09 20:36:44 morsch
70 All coding rule violations except RS3 corrected
72 Revision 1.7 2000/02/16 14:56:27 morsch
73 Convert geant particle code into pdg code before putting particle on the stack.
75 Revision 1.6 1999/11/09 07:38:48 fca
76 Changes for compatibility with version 2.23 of ROOT
78 Revision 1.5 1999/09/29 09:24:12 fca
79 Introduction of the Copyright and cvs Log
84 // Event generator that using an instance of type AliGenReader
85 // reads particles from a file and applies cuts.
87 #include <Riostream.h>
89 #include "AliGenExtFile.h"
92 #include <TParticle.h>
97 ClassImp(AliGenExtFile)
99 AliGenExtFile::AliGenExtFile()
104 // Read all particles
109 AliGenExtFile::AliGenExtFile(Int_t npart)
114 fTitle = "Primaries from ext. File";
118 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
122 //____________________________________________________________
123 AliGenExtFile::~AliGenExtFile()
129 //___________________________________________________________
130 void AliGenExtFile::Init()
133 if (fReader) fReader->Init();
137 void AliGenExtFile::Generate()
139 // Generate particles
141 Float_t polar[3] = {0,0,0};
143 Float_t origin[3] = {0,0,0};
148 for (j=0;j<3;j++) origin[j]=fOrigin[j];
149 if(fVertexSmear == kPerTrack) {
151 for (j = 0; j < 3; j++) {
152 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
153 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
158 Int_t nTracks = fReader->NextEvent();
160 // printf("\n No more events !!! !\n");
161 Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
166 // Particle selection loop
168 // The selction criterium for the external file generator is as follows:
170 // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
171 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
173 // If the particle does not satisfy these cuts, it is not put on the
175 // 2) If fCutOnChild and some specific child is selected (e.g. if
176 // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
177 // child falls into the child-cuts.
179 // Count the selected children
182 for (i = 0; i < nTracks; i++) {
183 TParticle* iparticle = fReader->NextParticle();
184 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
186 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
190 if (!nSelected) continue; // No particle selected: Go to next event
191 fReader->RewindEvent();
195 // Stack filling loop
197 for (i = 0; i < nTracks; i++) {
199 TParticle* iparticle = fReader->NextParticle();
200 if (!KinematicSelection(iparticle,0)) {
201 Double_t pz = iparticle->Pz();
202 Double_t e = iparticle->Energy();
206 } else if ((e+pz) == 0.) {
209 y = 0.5*TMath::Log((e+pz)/(e-pz));
211 printf("\n Not selected %d %f %f %f %f %f", i,
220 p[0] = iparticle->Px();
221 p[1] = iparticle->Py();
222 p[2] = iparticle->Pz();
223 Int_t idpart = iparticle->GetPdgCode();
224 if(fVertexSmear==kPerTrack) {
226 for (j = 0; j < 3; j++) {
228 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
229 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
232 Int_t decayed = iparticle->GetFirstDaughter();
233 Int_t doTracking = fTrackIt && (decayed < 0) &&
234 (TMath::Abs(idpart) > 10);
235 // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
236 // idpart,decayed, doTracking);
237 SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
245 SetHighWaterMark(nt);
249 void AliGenExtFile::CdEventFile()
251 // CD back to the event file
254 gAlice = (AliRun*)pFile->Get("gAlice");
255 if (gAlice) printf("AliRun object found on file\n");
256 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
258 TTree *fAli=gAlice->TreeK();
259 if (fAli) pFile =fAli->GetCurrentFile();
264 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
266 // Assignment operator