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 Revision 1.10 2000/07/11 18:24:55 fca
19 Coding convention corrections + few minor bug fixes
21 Revision 1.9 2000/06/14 15:20:09 morsch
24 Revision 1.8 2000/06/09 20:36:44 morsch
25 All coding rule violations except RS3 corrected
27 Revision 1.7 2000/02/16 14:56:27 morsch
28 Convert geant particle code into pdg code before putting particle on the stack.
30 Revision 1.6 1999/11/09 07:38:48 fca
31 Changes for compatibility with version 2.23 of ROOT
33 Revision 1.5 1999/09/29 09:24:12 fca
34 Introduction of the Copyright and cvs Log
40 #include "AliGenExtFile.h"
44 #include <TDirectory.h>
45 #include <TDatabasePDG.h>
49 ClassImp(AliGenExtFile)
50 AliGenExtFile::AliGenExtFile()
55 fTitle="Primaries from ext. File";
56 fFileName="dtujet93.root";
64 AliGenExtFile::AliGenExtFile(Int_t npart)
69 fTitle="Primaries from ext. File";
70 fFileName="dtujet93.root";
75 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
79 //____________________________________________________________
80 AliGenExtFile::~AliGenExtFile()
86 //____________________________________________________________
87 void AliGenExtFile::NtupleInit()
90 // reset the existing file environment and open a new root file if
91 // the pointer to the Fluka tree is null
96 pFile = new TFile(fFileName);
98 cout<<"I have opened "<<fFileName<<" file "<<endl;
100 // get the tree address in the Fluka boundary source file
101 fTreeNtuple = (TTree*)gDirectory->Get("h888");
103 pFile = fTreeNtuple->GetCurrentFile();
107 TTree *h2=fTreeNtuple;
108 //Set branch addresses
109 //Set branch addresses
110 h2->SetBranchAddress("Nihead",&fNihead);
111 h2->SetBranchAddress("Ihead",fIhead);
112 h2->SetBranchAddress("Nrhead",&fNrhead);
113 h2->SetBranchAddress("Rhead",fRhead);
114 h2->SetBranchAddress("Idpart",&fIdpart);
115 h2->SetBranchAddress("Theta",&fTheta);
116 h2->SetBranchAddress("Phi",&fPhi);
117 h2->SetBranchAddress("P",&fP);
118 h2->SetBranchAddress("E",&fE);
122 //____________________________________________________________
123 void AliGenExtFile::Generate()
125 // Generate particles
127 Float_t polar[3]= {0,0,0};
129 Float_t origin[3]={0,0,0};
133 Int_t i, j, nt, nTracks=0;
136 TTree *h2=fTreeNtuple;
137 Int_t nentries = (Int_t) h2->GetEntries();
138 // loop over number of particles
139 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
143 for (j=0;j<3;j++) origin[j]=fOrigin[j];
144 if(fVertexSmear==kPerTrack) {
147 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
148 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
152 if (fNcurrent >= nentries) {
153 printf("\n No more entries !!! !\n");
159 printf("\n This should never happen !\n");
161 printf("\n Next event contains %d tracks! \n", i6);
164 for (i=0; i<nTracks; i++) {
165 fIdpart=gMC->PDGFromId(fIdpart);
166 Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
168 Warning("Generate","Particle %d no %d E = %f mass = %f\n",
172 prwn=sqrt((fE+amass)*(fE-amass));
175 fTheta *= TMath::Pi()/180.;
176 fPhi = (fPhi-180)*TMath::Pi()/180.;
177 if(fTheta<fThetaMin || fTheta>fThetaMax ||
178 fPhi<fPhiMin || fPhi>fPhiMax ||
179 prwn<fPMin || prwn>fPMax)
183 p[0]=prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
184 p[1]=prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);
185 p[2]=prwn*TMath::Cos(fTheta);
187 if(fVertexSmear==kPerTrack) {
191 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
192 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
195 gAlice->SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,"Primary",nt);
198 nb = (Int_t)h2->GetEvent(fNcurrent);
202 // Get AliRun object or create it
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");
208 TTree *fAli=gAlice->TreeK();
209 if (fAli) pFile =fAli->GetCurrentFile();
214 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
216 // Assignment operator