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.21 2002/04/26 10:39:31 morsch
19 AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
21 Revision 1.20 2002/03/22 09:43:28 morsch
22 Don't delete the TParticle.
24 Revision 1.19 2002/02/08 16:50:50 morsch
25 Add name and title in constructor.
27 Revision 1.18 2001/11/12 14:31:00 morsch
28 Memory leaks fixed. (M. Bondila)
30 Revision 1.17 2001/11/09 09:12:58 morsch
31 Generalization by using AliGenReader object to read particles from file.
33 Revision 1.16 2001/07/27 17:09:35 morsch
34 Use local SetTrack, KeepTrack and SetHighWaterMark methods
35 to delegate either to local stack or to stack owned by AliRun.
36 (Piotr Skowronski, A.M.)
38 Revision 1.15 2001/01/23 13:29:37 morsch
39 Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
40 and GEANT3 codes (old ntuples) in input file.
42 Revision 1.14 2000/12/21 16:24:06 morsch
43 Coding convention clean-up
45 Revision 1.13 2000/11/30 07:12:50 alibrary
46 Introducing new Rndm and QA classes
48 Revision 1.12 2000/10/27 13:54:45 morsch
49 Remove explicite reference to input file from constuctor.
51 Revision 1.11 2000/10/02 21:28:06 fca
52 Removal of useless dependecies via forward declarations
54 Revision 1.10 2000/07/11 18:24:55 fca
55 Coding convention corrections + few minor bug fixes
57 Revision 1.9 2000/06/14 15:20:09 morsch
60 Revision 1.8 2000/06/09 20:36:44 morsch
61 All coding rule violations except RS3 corrected
63 Revision 1.7 2000/02/16 14:56:27 morsch
64 Convert geant particle code into pdg code before putting particle on the stack.
66 Revision 1.6 1999/11/09 07:38:48 fca
67 Changes for compatibility with version 2.23 of ROOT
69 Revision 1.5 1999/09/29 09:24:12 fca
70 Introduction of the Copyright and cvs Log
75 // Event generator that using an instance of type AliGenReader
76 // reads particles from a file and applies cuts.
80 #include "AliGenExtFile.h"
83 #include <TParticle.h>
88 ClassImp(AliGenExtFile)
90 AliGenExtFile::AliGenExtFile()
100 AliGenExtFile::AliGenExtFile(Int_t npart)
105 fTitle = "Primaries from ext. File";
109 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
113 //____________________________________________________________
114 AliGenExtFile::~AliGenExtFile()
120 //___________________________________________________________
121 void AliGenExtFile::Init()
124 if (fReader) fReader->Init();
128 void AliGenExtFile::Generate()
130 // Generate particles
132 Float_t polar[3] = {0,0,0};
134 Float_t origin[3] = {0,0,0};
139 for (j=0;j<3;j++) origin[j]=fOrigin[j];
140 if(fVertexSmear == kPerTrack) {
142 for (j = 0; j < 3; j++) {
143 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
144 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
149 Int_t nTracks = fReader->NextEvent();
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");
157 // Particle selection loop
159 // The selction criterium for the external file generator is as follows:
161 // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
162 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
164 // If the particle does not satisfy these cuts, it is not put on the
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.
170 // Count the selected children
173 for (i = 0; i < nTracks; i++) {
174 TParticle* iparticle = fReader->NextParticle();
175 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
177 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
181 if (!nSelected) continue; // No particle selected: Go to next event
182 fReader->RewindEvent();
186 // Stack filling loop
188 for (i = 0; i < nTracks; i++) {
190 TParticle* iparticle = fReader->NextParticle();
191 if (!KinematicSelection(iparticle,0)) {
192 Double_t pz = iparticle->Pz();
193 Double_t e = iparticle->Energy();
197 } else if ((e+pz) == 0.) {
200 y = 0.5*TMath::Log((e+pz)/(e-pz));
202 printf("\n Not selected %d %f %f %f %f %f", i,
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) {
217 for (j = 0; j < 3; j++) {
219 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
220 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
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);
236 SetHighWaterMark(nt);
240 void AliGenExtFile::CdEventFile()
242 // CD back to the event file
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");
249 TTree *fAli=gAlice->TreeK();
250 if (fAli) pFile =fAli->GetCurrentFile();
255 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
257 // Assignment operator