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"
37 #include <TParticle.h>
42 ClassImp(AliGenExtFile)
44 AliGenExtFile::AliGenExtFile()
54 AliGenExtFile::AliGenExtFile(Int_t npart)
59 fTitle = "Primaries from ext. File";
63 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile):
69 //____________________________________________________________
70 AliGenExtFile::~AliGenExtFile()
76 //___________________________________________________________
77 void AliGenExtFile::Init()
80 if (fReader) fReader->Init();
84 void AliGenExtFile::Generate()
88 Float_t polar[3] = {0,0,0};
90 Float_t origin[3] = {0,0,0};
95 for (j=0;j<3;j++) origin[j]=fOrigin[j];
96 if(fVertexSmear == kPerTrack) {
98 for (j = 0; j < 3; j++) {
99 origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
100 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
105 Int_t nTracks = fReader->NextEvent();
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");
113 // Particle selection loop
115 // The selction criterium for the external file generator is as follows:
117 // 1) All tracks are subjects to the cuts defined by AliGenerator, i.e.
118 // fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
120 // If the particle does not satisfy these cuts, it is not put on the
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.
125 TParticle* iparticle = 0x0;
128 // Count the selected children
130 while ( (iparticle=fReader->NextParticle()) ) {
132 Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
134 if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
138 if (!nSelected) continue; // No particle selected: Go to next event
139 fReader->RewindEvent();
143 // Stack filling loop
145 for (i = 0; i < nTracks; i++) {
147 TParticle* iparticle = fReader->NextParticle();
148 Bool_t selected = KinematicSelection(iparticle,0);
150 Double_t pz = iparticle->Pz();
151 Double_t e = iparticle->Energy();
155 } else if ((e+pz) == 0.) {
158 y = 0.5*TMath::Log((e+pz)/(e-pz));
160 printf("\n Not selected %d %f %f %f %f %f", i,
166 //PH delete iparticle;
169 p[0] = iparticle->Px();
170 p[1] = iparticle->Py();
171 p[2] = iparticle->Pz();
172 Int_t idpart = iparticle->GetPdgCode();
173 if(fVertexSmear==kPerTrack)
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]));
182 Int_t decayed = iparticle->GetFirstDaughter();
183 Int_t doTracking = fTrackIt && (decayed < 0) &&
184 (TMath::Abs(idpart) > 10) && selected;
185 // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
186 // idpart,decayed, doTracking);
187 //PH PushTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
188 Int_t parent = iparticle->GetFirstMother();
189 PushTrack(doTracking,parent,idpart,p,origin,polar,0,kPPrimary,nt);
197 SetHighWaterMark(nt);
201 void AliGenExtFile::CdEventFile()
203 // CD back to the event file
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");
210 TTree *fAli=gAlice->TreeK();
211 if (fAli) pFile =fAli->GetCurrentFile();
216 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
218 // Assignment operator
224 void AliGenExtFile::Copy(TObject&) const
229 Fatal("Copy","Not implemented!\n");