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