]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
One back.
[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"
aa4e331d 37#include "AliStack.h"
9ad9d6f5 38#include "AliGenEventHeader.h"
5c3fd7ea 39
a48e3376 40#include <TParticle.h>
693caace 41#include <TFile.h>
a48e3376 42#include <TTree.h>
43
5c3fd7ea 44
198bb1c7 45ClassImp(AliGenExtFile)
380956c5 46
47AliGenExtFile::AliGenExtFile()
1c56e311 48 :AliGenMC(),
49 fFileName(0),
50 fReader(0)
693caace 51{
f87cfe57 52// Constructor
693caace 53//
54// Read all particles
a48e3376 55 fNpart =- 1;
693caace 56}
57
58AliGenExtFile::AliGenExtFile(Int_t npart)
1c56e311 59 :AliGenMC(npart),
60 fFileName(0),
61 fReader(0)
693caace 62{
f87cfe57 63// Constructor
a48e3376 64 fName = "ExtFile";
65 fTitle = "Primaries from ext. File";
693caace 66}
67
68//____________________________________________________________
69AliGenExtFile::~AliGenExtFile()
70{
f87cfe57 71// Destructor
a48e3376 72 delete fReader;
693caace 73}
74
a48e3376 75//___________________________________________________________
76void AliGenExtFile::Init()
693caace 77{
a48e3376 78// Initialize
79 if (fReader) fReader->Init();
693caace 80}
81
a48e3376 82
693caace 83void AliGenExtFile::Generate()
84{
f87cfe57 85// Generate particles
693caace 86
eed0bb9a 87 Double_t polar[3] = {0,0,0};
693caace 88 //
eed0bb9a 89 Double_t origin[3] = {0,0,0};
1628e931 90 Double_t p[4];
693caace 91 Float_t random[6];
88cb7938 92 Int_t i = 0, j, nt;
693caace 93 //
4f23c932 94 //
95 if (fVertexSmear == kPerEvent) Vertex();
693caace 96
380956c5 97 while(1) {
98 Int_t nTracks = fReader->NextEvent();
99 if (nTracks == 0) {
100 // printf("\n No more events !!! !\n");
101 Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
693caace 102 return;
380956c5 103 }
104
105 //
106 // Particle selection loop
107 //
4f23c932 108 // The selection criterium for the external file generator is as follows:
380956c5 109 //
4f23c932 110 // 1) All tracks are subject to the cuts defined by AliGenerator, i.e.
380956c5 111 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
112 // fYMin, fYMax.
113 // If the particle does not satisfy these cuts, it is not put on the
114 // stack.
115 // 2) If fCutOnChild and some specific child is selected (e.g. if
116 // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
117 // child falls into the child-cuts.
88cb7938 118 TParticle* iparticle = 0x0;
119
380956c5 120 if(fCutOnChild) {
121 // Count the selected children
122 Int_t nSelected = 0;
4f23c932 123 while ((iparticle=fReader->NextParticle()) ) {
124 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
125 kf = TMath::Abs(kf);
126 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
127 nSelected++;
128 }
380956c5 129 }
130 if (!nSelected) continue; // No particle selected: Go to next event
131 fReader->RewindEvent();
132 }
a48e3376 133
380956c5 134 //
135 // Stack filling loop
136 //
7cf36cae 137 fNprimaries = 0;
380956c5 138 for (i = 0; i < nTracks; i++) {
ea79897e 139 TParticle* jparticle = fReader->NextParticle();
140 Bool_t selected = KinematicSelection(jparticle,0);
4f23c932 141 if (!selected) continue;
ea79897e 142 p[0] = jparticle->Px();
143 p[1] = jparticle->Py();
144 p[2] = jparticle->Pz();
1628e931 145 p[3] = jparticle->Energy();
146
b7a824ae 147 Int_t idpart = jparticle->GetPdgCode();
4f23c932 148 if(fVertexSmear==kPerTrack)
149 {
150 Rndm(random,6);
151 for (j = 0; j < 3; j++) {
152 origin[j]=fOrigin[j]+
153 fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
154 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
155 }
380956c5 156 } else {
ea79897e 157 origin[0] = fVertex[0] + jparticle->Vx();
158 origin[1] = fVertex[1] + jparticle->Vy();
159 origin[2] = fVertex[2] + jparticle->Vz();
380956c5 160 }
eed0bb9a 161 Double_t tof = jparticle->T();
8f126362 162 Int_t doTracking = fTrackIt && selected && (jparticle->TestBit(kTransportBit));
ea79897e 163 Int_t parent = jparticle->GetFirstMother();
4f23c932 164
eed0bb9a 165 PushTrack(doTracking, parent, idpart,
166 p[0], p[1], p[2], p[3], origin[0], origin[1], origin[2], tof,
167 polar[0], polar[1], polar[2],
168 kPPrimary, nt, 1., jparticle->GetStatusCode());
169
4f23c932 170 KeepTrack(nt);
7cf36cae 171 fNprimaries++;
380956c5 172 } // track loop
0b05fbf9 173
174 // Generated event header
4f23c932 175
0b05fbf9 176 AliGenEventHeader * header = new AliGenEventHeader();
7cf36cae 177 header->SetNProduced(fNprimaries);
0b05fbf9 178 header->SetPrimaryVertex(fVertex);
7cf36cae 179 AddHeader(header);
380956c5 180 break;
4f23c932 181
380956c5 182 } // event loop
4f23c932 183
380956c5 184 SetHighWaterMark(nt);
2c354237 185 CdEventFile();
186}
380956c5 187
2c354237 188void AliGenExtFile::CdEventFile()
189{
190// CD back to the event file
33c3c91a 191 AliRunLoader::Instance()->CdGAFile();
693caace 192}
193
194
693caace 195
196
197