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