]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Adding comment lines to class description needed for Root documentation,
[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
25454878 16/* $Id$ */
675e9664 17
a48e3376 18// Event generator that using an instance of type AliGenReader
25454878 19// reads particles from a file and applies cuts.
20// Example: In your Config.C you can include the following lines
4f23c932 21// AliGenExtFile *gener = new AliGenExtFile(-1);
25454878 22// gener->SetMomentumRange(0,999);
23// gener->SetPhiRange(-180.,180.);
24// gener->SetThetaRange(0,180);
25// gener->SetYRange(-999,999);
26// AliGenReaderTreeK * reader = new AliGenReaderTreeK();
27// reader->SetFileName("myFileWithTreeK.root");
28// gener->SetReader(reader);
29// gener->Init();
30
675e9664 31
159ec319 32#include <Riostream.h>
084c1b4a 33
693caace 34#include "AliGenExtFile.h"
4f23c932 35#include "AliRunLoader.h"
9ad9d6f5 36#include "AliHeader.h"
37#include "AliGenEventHeader.h"
5c3fd7ea 38
a48e3376 39#include <TParticle.h>
693caace 40#include <TFile.h>
a48e3376 41#include <TTree.h>
42
5c3fd7ea 43
198bb1c7 44ClassImp(AliGenExtFile)
380956c5 45
46AliGenExtFile::AliGenExtFile()
1c56e311 47 :AliGenMC(),
48 fFileName(0),
49 fReader(0)
693caace 50{
f87cfe57 51// Constructor
693caace 52//
53// Read all particles
a48e3376 54 fNpart =- 1;
693caace 55}
56
57AliGenExtFile::AliGenExtFile(Int_t npart)
1c56e311 58 :AliGenMC(npart),
59 fFileName(0),
60 fReader(0)
693caace 61{
f87cfe57 62// Constructor
a48e3376 63 fName = "ExtFile";
64 fTitle = "Primaries from ext. File";
693caace 65}
66
67//____________________________________________________________
68AliGenExtFile::~AliGenExtFile()
69{
f87cfe57 70// Destructor
a48e3376 71 delete fReader;
693caace 72}
73
a48e3376 74//___________________________________________________________
75void AliGenExtFile::Init()
693caace 76{
a48e3376 77// Initialize
78 if (fReader) fReader->Init();
693caace 79}
80
a48e3376 81
693caace 82void AliGenExtFile::Generate()
83{
f87cfe57 84// Generate particles
693caace 85
a48e3376 86 Float_t polar[3] = {0,0,0};
693caace 87 //
a48e3376 88 Float_t origin[3] = {0,0,0};
693caace 89 Float_t p[3];
90 Float_t random[6];
88cb7938 91 Int_t i = 0, j, nt;
693caace 92 //
4f23c932 93 //
94 if (fVertexSmear == kPerEvent) Vertex();
693caace 95
380956c5 96 while(1) {
97 Int_t nTracks = fReader->NextEvent();
98 if (nTracks == 0) {
99 // printf("\n No more events !!! !\n");
100 Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
693caace 101 return;
380956c5 102 }
103
104 //
105 // Particle selection loop
106 //
4f23c932 107 // The selection criterium for the external file generator is as follows:
380956c5 108 //
4f23c932 109 // 1) All tracks are subject to the cuts defined by AliGenerator, i.e.
380956c5 110 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
111 // fYMin, fYMax.
112 // If the particle does not satisfy these cuts, it is not put on the
113 // stack.
114 // 2) If fCutOnChild and some specific child is selected (e.g. if
115 // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
116 // child falls into the child-cuts.
88cb7938 117 TParticle* iparticle = 0x0;
118
380956c5 119 if(fCutOnChild) {
120 // Count the selected children
121 Int_t nSelected = 0;
4f23c932 122 while ((iparticle=fReader->NextParticle()) ) {
123 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
124 kf = TMath::Abs(kf);
125 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
126 nSelected++;
127 }
380956c5 128 }
129 if (!nSelected) continue; // No particle selected: Go to next event
130 fReader->RewindEvent();
131 }
a48e3376 132
380956c5 133 //
134 // Stack filling loop
135 //
136 for (i = 0; i < nTracks; i++) {
4f23c932 137 TParticle* iparticle = fReader->NextParticle();
138 Bool_t selected = KinematicSelection(iparticle,0);
139 if (!selected) continue;
140 p[0] = iparticle->Px();
141 p[1] = iparticle->Py();
142 p[2] = iparticle->Pz();
143 Int_t idpart = iparticle->GetPdgCode();
144 if(fVertexSmear==kPerTrack)
145 {
146 Rndm(random,6);
147 for (j = 0; j < 3; j++) {
148 origin[j]=fOrigin[j]+
149 fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
150 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
151 }
380956c5 152 } else {
4f23c932 153 origin[0] = fVertex[0] + iparticle->Vx();
154 origin[1] = fVertex[1] + iparticle->Vy();
155 origin[2] = fVertex[2] + iparticle->Vz();
380956c5 156 }
4f23c932 157
158 Int_t decayed = iparticle->GetFirstDaughter();
159 Int_t doTracking = fTrackIt && (decayed < 0) && (TMath::Abs(idpart) > 10) && selected;
160 Int_t parent = iparticle->GetFirstMother();
161
162 PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
163 KeepTrack(nt);
380956c5 164 } // track loop
0b05fbf9 165
166 // Generated event header
4f23c932 167
0b05fbf9 168 AliGenEventHeader * header = new AliGenEventHeader();
169 header->SetNProduced(nt+1);
170 header->SetPrimaryVertex(fVertex);
171 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
172
380956c5 173 break;
4f23c932 174
380956c5 175 } // event loop
4f23c932 176
380956c5 177 SetHighWaterMark(nt);
2c354237 178 CdEventFile();
179}
380956c5 180
2c354237 181void AliGenExtFile::CdEventFile()
182{
183// CD back to the event file
4f23c932 184 (AliRunLoader::GetRunLoader())->CdGAFile();
693caace 185}
186
187
693caace 188
189
190