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