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 **************************************************************************/
20 #include "AliGenExtFile.h"
21 #include "AliGenMUONlib.h"
24 #include <TDirectory.h>
28 ClassImp(AliGenExtFile)
29 AliGenExtFile::AliGenExtFile()
34 fTitle="Primaries from ext. File";
35 fFileName="dtujet93.root";
43 AliGenExtFile::AliGenExtFile(Int_t npart)
48 fTitle="Primaries from ext. File";
49 fFileName="dtujet93.root";
54 //____________________________________________________________
55 AliGenExtFile::~AliGenExtFile()
60 //____________________________________________________________
61 void AliGenExtFile::NtupleInit()
64 // reset the existing file environment and open a new root file if
65 // the pointer to the Fluka tree is null
70 File = new TFile(fFileName);
72 cout<<"I have opened "<<fFileName<<" file "<<endl;
74 // get the tree address in the Fluka boundary source file
75 fTreeNtuple = (TTree*)gDirectory->Get("h888");
77 File = fTreeNtuple->GetCurrentFile();
81 TTree *h2=fTreeNtuple;
82 //Set branch addresses
83 //Set branch addresses
84 h2->SetBranchAddress("Nihead",&Nihead);
85 h2->SetBranchAddress("Ihead",Ihead);
86 h2->SetBranchAddress("Nrhead",&Nrhead);
87 h2->SetBranchAddress("Rhead",Rhead);
88 h2->SetBranchAddress("Idpart",&Idpart);
89 h2->SetBranchAddress("Theta",&Theta);
90 h2->SetBranchAddress("Phi",&Phi);
91 h2->SetBranchAddress("P",&P);
92 h2->SetBranchAddress("E",&E);
96 //____________________________________________________________
97 void AliGenExtFile::Generate()
100 Float_t polar[3]= {0,0,0};
102 Float_t origin[3]={0,0,0};
106 Int_t i, j, nt, Ntracks=0;
109 TTree *h2=fTreeNtuple;
110 Int_t nentries = (Int_t) h2->GetEntries();
111 // loop over number of particles
112 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
116 for (j=0;j<3;j++) origin[j]=fOrigin[j];
117 if(fVertexSmear==perEvent) {
120 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
121 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
125 if (fNcurrent >= nentries) {
126 printf("\n No more entries !!! !\n");
132 printf("\n This should never happen !\n");
134 printf("\n Next event contains %d tracks! \n", i6);
137 for (i=0; i<Ntracks; i++) {
139 Double_t amass = TDatabasePDG::Instance()->GetParticle(Idpart)->Mass();
141 Warning("Generate","Particle %d no %d E = %f mass = %f\n",Idpart,i,E,amass);
144 prwn=sqrt((E+amass)*(E-amass));
147 Theta *= TMath::Pi()/180.;
148 Phi = (Phi-180)*TMath::Pi()/180.;
149 if(Theta<fThetaMin || Theta>fThetaMax ||
150 Phi<fPhiMin || Phi>fPhiMax ||
151 prwn<fPMin || prwn>fPMax)
155 p[0]=prwn*TMath::Sin(Theta)*TMath::Cos(Phi);
156 p[1]=prwn*TMath::Sin(Theta)*TMath::Sin(Phi);
157 p[2]=prwn*TMath::Cos(Theta);
159 if(fVertexSmear==perTrack) {
163 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
164 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
167 gAlice->SetTrack(fTrackIt,-1,Idpart,p,origin,polar,0,"Primary",nt);
170 nb = (Int_t)h2->GetEvent(fNcurrent);
174 // Get AliRun object or create it
176 gAlice = (AliRun*)File->Get("gAlice");
177 if (gAlice) printf("AliRun object found on file\n");
178 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
180 TTree *fAli=gAlice->TreeK();
181 if (fAli) File =fAli->GetCurrentFile();