]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Field conversion factor added.
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
CommitLineData
4c039060 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$
159ec319 18Revision 1.23 2002/10/14 14:55:35 hristov
19Merging the VirtualMC branch to the main development branch (HEAD)
20
b9d0a01d 21Revision 1.20.4.1 2002/06/10 14:57:41 hristov
22Merged with v3-08-02
23
24Revision 1.22 2002/05/15 11:59:49 morsch
25CdEventFile() method added.
26
2c354237 27Revision 1.21 2002/04/26 10:39:31 morsch
28AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
29
380956c5 30Revision 1.20 2002/03/22 09:43:28 morsch
31Don't delete the TParticle.
32
14412d0b 33Revision 1.19 2002/02/08 16:50:50 morsch
34Add name and title in constructor.
35
8b31bfac 36Revision 1.18 2001/11/12 14:31:00 morsch
37Memory leaks fixed. (M. Bondila)
38
ae872676 39Revision 1.17 2001/11/09 09:12:58 morsch
40Generalization by using AliGenReader object to read particles from file.
41
a48e3376 42Revision 1.16 2001/07/27 17:09:35 morsch
43Use local SetTrack, KeepTrack and SetHighWaterMark methods
44to delegate either to local stack or to stack owned by AliRun.
45(Piotr Skowronski, A.M.)
46
a99cf51f 47Revision 1.15 2001/01/23 13:29:37 morsch
48Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
49and GEANT3 codes (old ntuples) in input file.
50
f177bfed 51Revision 1.14 2000/12/21 16:24:06 morsch
52Coding convention clean-up
53
675e9664 54Revision 1.13 2000/11/30 07:12:50 alibrary
55Introducing new Rndm and QA classes
56
65fb704d 57Revision 1.12 2000/10/27 13:54:45 morsch
58Remove explicite reference to input file from constuctor.
59
38e6c6e6 60Revision 1.11 2000/10/02 21:28:06 fca
61Removal of useless dependecies via forward declarations
62
94de3818 63Revision 1.10 2000/07/11 18:24:55 fca
64Coding convention corrections + few minor bug fixes
65
aee8290b 66Revision 1.9 2000/06/14 15:20:09 morsch
67Include clean-up (IH)
68
5c3fd7ea 69Revision 1.8 2000/06/09 20:36:44 morsch
70All coding rule violations except RS3 corrected
71
f87cfe57 72Revision 1.7 2000/02/16 14:56:27 morsch
73Convert geant particle code into pdg code before putting particle on the stack.
74
3c8636e9 75Revision 1.6 1999/11/09 07:38:48 fca
76Changes for compatibility with version 2.23 of ROOT
77
084c1b4a 78Revision 1.5 1999/09/29 09:24:12 fca
79Introduction of the Copyright and cvs Log
80
4c039060 81*/
82
675e9664 83
a48e3376 84// Event generator that using an instance of type AliGenReader
85// reads particles from a file and applies cuts.
675e9664 86
159ec319 87#include <Riostream.h>
084c1b4a 88
693caace 89#include "AliGenExtFile.h"
693caace 90#include "AliRun.h"
5c3fd7ea 91
a48e3376 92#include <TParticle.h>
693caace 93#include <TFile.h>
a48e3376 94#include <TTree.h>
95
5c3fd7ea 96
693caace 97 ClassImp(AliGenExtFile)
380956c5 98
99AliGenExtFile::AliGenExtFile()
100 :AliGenMC()
693caace 101{
f87cfe57 102// Constructor
693caace 103//
104// Read all particles
a48e3376 105 fNpart =- 1;
106 fReader = 0;
693caace 107}
108
109AliGenExtFile::AliGenExtFile(Int_t npart)
380956c5 110 :AliGenMC(npart)
693caace 111{
f87cfe57 112// Constructor
a48e3376 113 fName = "ExtFile";
114 fTitle = "Primaries from ext. File";
115 fReader = 0;
693caace 116}
117
f87cfe57 118AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
119{
120// copy constructor
121}
693caace 122//____________________________________________________________
123AliGenExtFile::~AliGenExtFile()
124{
f87cfe57 125// Destructor
a48e3376 126 delete fReader;
693caace 127}
128
a48e3376 129//___________________________________________________________
130void AliGenExtFile::Init()
693caace 131{
a48e3376 132// Initialize
133 if (fReader) fReader->Init();
693caace 134}
135
a48e3376 136
693caace 137void AliGenExtFile::Generate()
138{
f87cfe57 139// Generate particles
693caace 140
a48e3376 141 Float_t polar[3] = {0,0,0};
693caace 142 //
a48e3376 143 Float_t origin[3] = {0,0,0};
693caace 144 Float_t p[3];
145 Float_t random[6];
a48e3376 146 Int_t i, j, nt;
693caace 147 //
693caace 148 for (j=0;j<3;j++) origin[j]=fOrigin[j];
a48e3376 149 if(fVertexSmear == kPerTrack) {
65fb704d 150 Rndm(random,6);
a48e3376 151 for (j = 0; j < 3; j++) {
152 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
693caace 153 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
154 }
155 }
156
380956c5 157 while(1) {
158 Int_t nTracks = fReader->NextEvent();
159 if (nTracks == 0) {
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");
693caace 162 return;
380956c5 163 }
164
165 //
166 // Particle selection loop
167 //
168 // The selction criterium for the external file generator is as follows:
169 //
170 // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
171 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
172 // fYMin, fYMax.
173 // If the particle does not satisfy these cuts, it is not put on the
174 // stack.
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.
178 if(fCutOnChild) {
179 // Count the selected children
180 Int_t nSelected = 0;
181
182 for (i = 0; i < nTracks; i++) {
183 TParticle* iparticle = fReader->NextParticle();
184 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
185 kf = TMath::Abs(kf);
186 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
187 nSelected++;
188 }
189 }
190 if (!nSelected) continue; // No particle selected: Go to next event
191 fReader->RewindEvent();
192 }
a48e3376 193
380956c5 194 //
195 // Stack filling loop
196 //
197 for (i = 0; i < nTracks; i++) {
14412d0b 198
a48e3376 199 TParticle* iparticle = fReader->NextParticle();
380956c5 200 if (!KinematicSelection(iparticle,0)) {
201 Double_t pz = iparticle->Pz();
202 Double_t e = iparticle->Energy();
203 Double_t y;
204 if ((e-pz) == 0) {
a48e3376 205 y = 20.;
380956c5 206 } else if ((e+pz) == 0.) {
a48e3376 207 y = -20.;
380956c5 208 } else {
a48e3376 209 y = 0.5*TMath::Log((e+pz)/(e-pz));
380956c5 210 }
211 printf("\n Not selected %d %f %f %f %f %f", i,
212 iparticle->Theta(),
213 iparticle->Phi(),
214 iparticle->P(),
215 iparticle->Pt(),
216 y);
217 delete iparticle;
218 continue;
a48e3376 219 }
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) {
225 Rndm(random,6);
226 for (j = 0; j < 3; j++) {
227 origin[j]=fOrigin[j]
228 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
229 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
693caace 230 }
693caace 231 }
380956c5 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);
238 KeepTrack(nt);
239 } // track loop
240
241 break;
242
243 } // event loop
244
245 SetHighWaterMark(nt);
2c354237 246 CdEventFile();
247}
380956c5 248
2c354237 249void AliGenExtFile::CdEventFile()
250{
251// CD back to the event file
a48e3376 252 TFile *pFile=0;
a48e3376 253 if (!gAlice) {
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");
257 }
258 TTree *fAli=gAlice->TreeK();
259 if (fAli) pFile =fAli->GetCurrentFile();
2c354237 260 pFile->cd();
693caace 261}
262
263
f87cfe57 264AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
265{
266// Assignment operator
267 return *this;
268}
269
693caace 270
271
272
273
274
275
276