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