]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Moving to the new VMC naming convention
[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
21// AliGenExtFile *gener = new AliGenExtFile(-1);
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"
693caace 35#include "AliRun.h"
5c3fd7ea 36
a48e3376 37#include <TParticle.h>
693caace 38#include <TFile.h>
a48e3376 39#include <TTree.h>
40
5c3fd7ea 41
693caace 42 ClassImp(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
f87cfe57 63AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
64{
65// copy constructor
66}
693caace 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 //
693caace 93 for (j=0;j<3;j++) origin[j]=fOrigin[j];
a48e3376 94 if(fVertexSmear == kPerTrack) {
65fb704d 95 Rndm(random,6);
a48e3376 96 for (j = 0; j < 3; j++) {
97 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
693caace 98 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
99 }
100 }
101
380956c5 102 while(1) {
103 Int_t nTracks = fReader->NextEvent();
104 if (nTracks == 0) {
105 // printf("\n No more events !!! !\n");
106 Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
693caace 107 return;
380956c5 108 }
109
110 //
111 // Particle selection loop
112 //
113 // The selction criterium for the external file generator is as follows:
114 //
88cb7938 115 // 1) All tracks are subjects to the cuts defined by AliGenerator, i.e.
380956c5 116 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
117 // fYMin, fYMax.
118 // If the particle does not satisfy these cuts, it is not put on the
119 // stack.
120 // 2) If fCutOnChild and some specific child is selected (e.g. if
121 // fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
122 // child falls into the child-cuts.
88cb7938 123 TParticle* iparticle = 0x0;
124
380956c5 125 if(fCutOnChild) {
126 // Count the selected children
127 Int_t nSelected = 0;
88cb7938 128 while ( (iparticle=fReader->NextParticle()) ) {
129 ;
380956c5 130 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
131 kf = TMath::Abs(kf);
132 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
133 nSelected++;
134 }
135 }
136 if (!nSelected) continue; // No particle selected: Go to next event
137 fReader->RewindEvent();
138 }
a48e3376 139
380956c5 140 //
141 // Stack filling loop
142 //
143 for (i = 0; i < nTracks; i++) {
14412d0b 144
a48e3376 145 TParticle* iparticle = fReader->NextParticle();
7b8b3898 146 Bool_t selected = KinematicSelection(iparticle,0);
147 if (!selected) {
380956c5 148 Double_t pz = iparticle->Pz();
149 Double_t e = iparticle->Energy();
150 Double_t y;
151 if ((e-pz) == 0) {
a48e3376 152 y = 20.;
380956c5 153 } else if ((e+pz) == 0.) {
a48e3376 154 y = -20.;
380956c5 155 } else {
a48e3376 156 y = 0.5*TMath::Log((e+pz)/(e-pz));
380956c5 157 }
158 printf("\n Not selected %d %f %f %f %f %f", i,
159 iparticle->Theta(),
160 iparticle->Phi(),
161 iparticle->P(),
162 iparticle->Pt(),
163 y);
602ca0fb 164 //PH delete iparticle;
7b8b3898 165 // continue;
a48e3376 166 }
167 p[0] = iparticle->Px();
168 p[1] = iparticle->Py();
169 p[2] = iparticle->Pz();
170 Int_t idpart = iparticle->GetPdgCode();
88cb7938 171 if(fVertexSmear==kPerTrack)
172 {
173 Rndm(random,6);
174 for (j = 0; j < 3; j++) {
175 origin[j]=fOrigin[j]+
176 fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
177 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
178 }
693caace 179 }
380956c5 180 Int_t decayed = iparticle->GetFirstDaughter();
181 Int_t doTracking = fTrackIt && (decayed < 0) &&
7b8b3898 182 (TMath::Abs(idpart) > 10) && selected;
380956c5 183 // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
184 // idpart,decayed, doTracking);
642f15cf 185 //PH PushTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
25454878 186 Int_t parent = iparticle->GetFirstMother();
642f15cf 187 PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
380956c5 188 KeepTrack(nt);
189 } // track loop
190
191 break;
192
193 } // event loop
194
195 SetHighWaterMark(nt);
2c354237 196 CdEventFile();
197}
380956c5 198
2c354237 199void AliGenExtFile::CdEventFile()
200{
201// CD back to the event file
a48e3376 202 TFile *pFile=0;
a48e3376 203 if (!gAlice) {
204 gAlice = (AliRun*)pFile->Get("gAlice");
205 if (gAlice) printf("AliRun object found on file\n");
206 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
207 }
208 TTree *fAli=gAlice->TreeK();
209 if (fAli) pFile =fAli->GetCurrentFile();
2c354237 210 pFile->cd();
693caace 211}
212
213
f87cfe57 214AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
215{
216// Assignment operator
217 return *this;
218}
219
693caace 220
221
222
223
224
225
226