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.5 1999/09/29 09:24:12 fca
19 Introduction of the Copyright and cvs Log
25 #include "AliGenExtFile.h"
26 #include "AliGenMUONlib.h"
29 #include <TDirectory.h>
33 ClassImp(AliGenExtFile)
34 AliGenExtFile::AliGenExtFile()
39 fTitle="Primaries from ext. File";
40 fFileName="dtujet93.root";
48 AliGenExtFile::AliGenExtFile(Int_t npart)
53 fTitle="Primaries from ext. File";
54 fFileName="dtujet93.root";
59 //____________________________________________________________
60 AliGenExtFile::~AliGenExtFile()
65 //____________________________________________________________
66 void AliGenExtFile::NtupleInit()
69 // reset the existing file environment and open a new root file if
70 // the pointer to the Fluka tree is null
75 File = new TFile(fFileName);
77 cout<<"I have opened "<<fFileName<<" file "<<endl;
79 // get the tree address in the Fluka boundary source file
80 fTreeNtuple = (TTree*)gDirectory->Get("h888");
82 File = fTreeNtuple->GetCurrentFile();
86 TTree *h2=fTreeNtuple;
87 //Set branch addresses
88 //Set branch addresses
89 h2->SetBranchAddress("Nihead",&Nihead);
90 h2->SetBranchAddress("Ihead",Ihead);
91 h2->SetBranchAddress("Nrhead",&Nrhead);
92 h2->SetBranchAddress("Rhead",Rhead);
93 h2->SetBranchAddress("Idpart",&Idpart);
94 h2->SetBranchAddress("Theta",&Theta);
95 h2->SetBranchAddress("Phi",&Phi);
96 h2->SetBranchAddress("P",&P);
97 h2->SetBranchAddress("E",&E);
101 //____________________________________________________________
102 void AliGenExtFile::Generate()
105 Float_t polar[3]= {0,0,0};
107 Float_t origin[3]={0,0,0};
111 Int_t i, j, nt, Ntracks=0;
114 TTree *h2=fTreeNtuple;
115 Int_t nentries = (Int_t) h2->GetEntries();
116 // loop over number of particles
117 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
121 for (j=0;j<3;j++) origin[j]=fOrigin[j];
122 if(fVertexSmear==perEvent) {
125 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
126 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
130 if (fNcurrent >= nentries) {
131 printf("\n No more entries !!! !\n");
137 printf("\n This should never happen !\n");
139 printf("\n Next event contains %d tracks! \n", i6);
142 for (i=0; i<Ntracks; i++) {
144 Double_t amass = TDatabasePDG::Instance()->GetParticle(Idpart)->Mass();
146 Warning("Generate","Particle %d no %d E = %f mass = %f\n",Idpart,i,E,amass);
149 prwn=sqrt((E+amass)*(E-amass));
152 Theta *= TMath::Pi()/180.;
153 Phi = (Phi-180)*TMath::Pi()/180.;
154 if(Theta<fThetaMin || Theta>fThetaMax ||
155 Phi<fPhiMin || Phi>fPhiMax ||
156 prwn<fPMin || prwn>fPMax)
160 p[0]=prwn*TMath::Sin(Theta)*TMath::Cos(Phi);
161 p[1]=prwn*TMath::Sin(Theta)*TMath::Sin(Phi);
162 p[2]=prwn*TMath::Cos(Theta);
164 if(fVertexSmear==perTrack) {
168 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
169 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
172 gAlice->SetTrack(fTrackIt,-1,Idpart,p,origin,polar,0,"Primary",nt);
175 nb = (Int_t)h2->GetEvent(fNcurrent);
179 // Get AliRun object or create it
181 gAlice = (AliRun*)File->Get("gAlice");
182 if (gAlice) printf("AliRun object found on file\n");
183 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
185 TTree *fAli=gAlice->TreeK();
186 if (fAli) File =fAli->GetCurrentFile();