1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Event generator that using an instance of type AliGenReader
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);
32 #include <Riostream.h>
34 #include "AliGenExtFile.h"
35 #include "AliRunLoader.h"
36 #include "AliHeader.h"
38 #include "AliGenEventHeader.h"
39 #include "AliGenReader.h"
41 #include <TParticle.h>
46 ClassImp(AliGenExtFile)
48 AliGenExtFile::AliGenExtFile()
59 AliGenExtFile::AliGenExtFile(Int_t npart)
66 fTitle = "Primaries from ext. File";
69 //____________________________________________________________
70 AliGenExtFile::~AliGenExtFile()
76 //___________________________________________________________
77 void AliGenExtFile::Init()
80 if (fReader) fReader->Init();
84 void AliGenExtFile::Generate()
88 Double_t polar[3] = {0,0,0};
90 Double_t origin[3] = {0,0,0};
96 if (fVertexSmear == kPerEvent) Vertex();
99 Int_t nTracks = fReader->NextEvent();
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");
107 // Particle selection loop
109 // The selection criterium for the external file generator is as follows:
111 // 1) All tracks are subject to the cuts defined by AliGenerator, i.e.
112 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
114 // If the particle does not satisfy these cuts, it is not put on the
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.
119 TParticle* iparticle = 0x0;
122 // Count the selected children
124 while ((iparticle=fReader->NextParticle()) ) {
125 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
127 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
131 if (!nSelected) continue; // No particle selected: Go to next event
132 fReader->RewindEvent();
136 // Stack filling loop
139 for (i = 0; i < nTracks; i++) {
140 TParticle* jparticle = fReader->NextParticle();
141 Bool_t selected = KinematicSelection(jparticle,0);
142 if (!selected) continue;
143 p[0] = jparticle->Px();
144 p[1] = jparticle->Py();
145 p[2] = jparticle->Pz();
146 p[3] = jparticle->Energy();
148 Int_t idpart = jparticle->GetPdgCode();
149 if(fVertexSmear==kPerTrack)
152 for (j = 0; j < 3; j++) {
153 origin[j]=fOrigin[j]+
154 fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
155 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
158 origin[0] = fVertex[0] + jparticle->Vx();
159 origin[1] = fVertex[1] + jparticle->Vy();
160 origin[2] = fVertex[2] + jparticle->Vz();
162 Double_t tof = jparticle->T();
163 Int_t doTracking = fTrackIt && selected && (jparticle->TestBit(kTransportBit));
164 Int_t parent = jparticle->GetFirstMother();
166 PushTrack(doTracking, parent, idpart,
167 p[0], p[1], p[2], p[3], origin[0], origin[1], origin[2], tof,
168 polar[0], polar[1], polar[2],
169 kPPrimary, nt, 1., jparticle->GetStatusCode());
175 // Generated event header
177 AliGenEventHeader * header = new AliGenEventHeader();
178 header->SetNProduced(fNprimaries);
179 header->SetPrimaryVertex(fVertex);
185 SetHighWaterMark(nt);
189 void AliGenExtFile::CdEventFile()
191 // CD back to the event file
192 AliRunLoader::Instance()->CdGAFile();