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