]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
Code lost in transition to new I/O restored.
[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
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 //
693caace 95 for (j=0;j<3;j++) origin[j]=fOrigin[j];
a48e3376 96 if(fVertexSmear == kPerTrack) {
65fb704d 97 Rndm(random,6);
a48e3376 98 for (j = 0; j < 3; j++) {
99 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
693caace 100 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
101 }
102 }
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 //
115 // The selction criterium for the external file generator is as follows:
116 //
88cb7938 117 // 1) All tracks are subjects 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;
88cb7938 130 while ( (iparticle=fReader->NextParticle()) ) {
131 ;
380956c5 132 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
133 kf = TMath::Abs(kf);
134 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
135 nSelected++;
136 }
137 }
138 if (!nSelected) continue; // No particle selected: Go to next event
139 fReader->RewindEvent();
140 }
a48e3376 141
380956c5 142 //
143 // Stack filling loop
144 //
145 for (i = 0; i < nTracks; i++) {
14412d0b 146
a48e3376 147 TParticle* iparticle = fReader->NextParticle();
7b8b3898 148 Bool_t selected = KinematicSelection(iparticle,0);
149 if (!selected) {
380956c5 150 Double_t pz = iparticle->Pz();
151 Double_t e = iparticle->Energy();
152 Double_t y;
153 if ((e-pz) == 0) {
a48e3376 154 y = 20.;
380956c5 155 } else if ((e+pz) == 0.) {
a48e3376 156 y = -20.;
380956c5 157 } else {
a48e3376 158 y = 0.5*TMath::Log((e+pz)/(e-pz));
380956c5 159 }
160 printf("\n Not selected %d %f %f %f %f %f", i,
161 iparticle->Theta(),
162 iparticle->Phi(),
163 iparticle->P(),
164 iparticle->Pt(),
165 y);
602ca0fb 166 //PH delete iparticle;
7b8b3898 167 // continue;
a48e3376 168 }
169 p[0] = iparticle->Px();
170 p[1] = iparticle->Py();
171 p[2] = iparticle->Pz();
172 Int_t idpart = iparticle->GetPdgCode();
88cb7938 173 if(fVertexSmear==kPerTrack)
174 {
175 Rndm(random,6);
176 for (j = 0; j < 3; j++) {
177 origin[j]=fOrigin[j]+
178 fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
179 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
180 }
693caace 181 }
380956c5 182 Int_t decayed = iparticle->GetFirstDaughter();
183 Int_t doTracking = fTrackIt && (decayed < 0) &&
7b8b3898 184 (TMath::Abs(idpart) > 10) && selected;
380956c5 185 // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
186 // idpart,decayed, doTracking);
642f15cf 187 //PH PushTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
25454878 188 Int_t parent = iparticle->GetFirstMother();
642f15cf 189 PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
380956c5 190 KeepTrack(nt);
191 } // track loop
192
193 break;
194
195 } // event loop
196
197 SetHighWaterMark(nt);
2c354237 198 CdEventFile();
199}
380956c5 200
2c354237 201void AliGenExtFile::CdEventFile()
202{
203// CD back to the event file
a48e3376 204 TFile *pFile=0;
a48e3376 205 if (!gAlice) {
206 gAlice = (AliRun*)pFile->Get("gAlice");
207 if (gAlice) printf("AliRun object found on file\n");
208 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
209 }
210 TTree *fAli=gAlice->TreeK();
211 if (fAli) pFile =fAli->GetCurrentFile();
2c354237 212 pFile->cd();
693caace 213}
214
215
f87cfe57 216AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
217{
218// Assignment operator
198bb1c7 219 rhs.Copy(*this);
f87cfe57 220 return *this;
221}
198bb1c7 222
f87cfe57 223
dc1d768c 224void AliGenExtFile::Copy(TObject&) const
198bb1c7 225{
226 //
227 // Copy
228 //
229 Fatal("Copy","Not implemented!\n");
230}
693caace 231
232
233
234
235
236
237