]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenExtFile.cxx
Changes for compatibility with version 2.23 of ROOT
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.5  1999/09/29 09:24:12  fca
19 Introduction of the Copyright and cvs Log
20
21 */
22
23 #include <iostream.h>
24
25 #include "AliGenExtFile.h"
26 #include "AliGenMUONlib.h"
27 #include "AliMC.h"
28 #include "AliRun.h"
29 #include <TDirectory.h>
30 #include <TFile.h>
31 #include <TTree.h>
32 #include <stdlib.h>
33  ClassImp(AliGenExtFile)
34      AliGenExtFile::AliGenExtFile()
35          :AliGenerator(-1)
36 {
37     //
38     fName="ExtFile";
39     fTitle="Primaries from ext. File";
40     fFileName="dtujet93.root";
41     fTreeNtuple=0;
42     fNcurrent=0;
43 //
44 //  Read all particles
45     fNpart=-1;
46 }
47
48 AliGenExtFile::AliGenExtFile(Int_t npart)
49     :AliGenerator(npart)
50 {
51     //
52     fName="ExtFile";
53     fTitle="Primaries from ext. File";
54     fFileName="dtujet93.root";
55     fTreeNtuple=0;
56     fNcurrent=0;
57 }
58
59 //____________________________________________________________
60 AliGenExtFile::~AliGenExtFile()
61 {
62     delete fTreeNtuple;
63 }
64
65 //____________________________________________________________
66 void AliGenExtFile::NtupleInit() 
67 {
68 //
69 // reset the existing file environment and open a new root file if
70 // the pointer to the Fluka tree is null
71     
72     TFile *File=0;
73     if (fTreeNtuple==0) {
74         if (!File) {
75             File = new TFile(fFileName);
76             File->cd();
77             cout<<"I have opened "<<fFileName<<" file "<<endl;
78         }
79 // get the tree address in the Fluka boundary source file
80         fTreeNtuple = (TTree*)gDirectory->Get("h888");
81     } else {
82         File = fTreeNtuple->GetCurrentFile();
83         File->cd();
84     }
85
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);
98 }
99
100
101 //____________________________________________________________
102 void AliGenExtFile::Generate()
103 {
104
105   Float_t polar[3]= {0,0,0};
106   //
107   Float_t origin[3]={0,0,0};
108   Float_t p[3];
109   Float_t random[6];
110   Float_t prwn;
111   Int_t i, j, nt, Ntracks=0;
112   //
113   NtupleInit();
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);
118   Int_t i5=Ihead[4];
119   Int_t i6=Ihead[5];
120
121   for (j=0;j<3;j++) origin[j]=fOrigin[j];
122   if(fVertexSmear==perEvent) {
123     gMC->Rndm(random,6);
124     for (j=0;j<3;j++) {
125         origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
126             TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
127     }
128   }
129
130   if (fNcurrent >= nentries) {
131       printf("\n No more entries !!! !\n");
132       return;
133   }
134   
135           
136   if (i5==0) {
137       printf("\n This should never happen !\n");
138   } else {
139       printf("\n Next event contains %d tracks! \n", i6);
140       Ntracks=i6;
141   }
142   for (i=0; i<Ntracks; i++) {
143
144       Double_t amass = TDatabasePDG::Instance()->GetParticle(Idpart)->Mass();
145       if(E<=amass) {
146         Warning("Generate","Particle %d no %d E = %f mass = %f\n",Idpart,i,E,amass);
147         prwn=0;
148       } else {
149         prwn=sqrt((E+amass)*(E-amass));
150       }
151
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)          
157       {
158           ;
159       } else {
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);
163           
164           if(fVertexSmear==perTrack) {
165               gMC->Rndm(random,6);
166               for (j=0;j<3;j++) {
167                   origin[j]=fOrigin[j]
168                       +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
169                       TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
170               }
171           }
172           gAlice->SetTrack(fTrackIt,-1,Idpart,p,origin,polar,0,"Primary",nt);
173       }
174       fNcurrent++;
175       nb = (Int_t)h2->GetEvent(fNcurrent); 
176   }
177  
178     TFile *File=0;
179 // Get AliRun object or create it 
180     if (!gAlice) {
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");
184     }
185     TTree *fAli=gAlice->TreeK();
186     if (fAli) File =fAli->GetCurrentFile();
187     File->cd();
188 }
189
190
191
192
193
194
195
196
197