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