]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenExtFile.cxx
All coding rule violations except RS3 corrected
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.cxx
CommitLineData
4c039060 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$
f87cfe57 18Revision 1.7 2000/02/16 14:56:27 morsch
19Convert geant particle code into pdg code before putting particle on the stack.
20
3c8636e9 21Revision 1.6 1999/11/09 07:38:48 fca
22Changes for compatibility with version 2.23 of ROOT
23
084c1b4a 24Revision 1.5 1999/09/29 09:24:12 fca
25Introduction of the Copyright and cvs Log
26
4c039060 27*/
28
084c1b4a 29#include <iostream.h>
30
693caace 31#include "AliGenExtFile.h"
32#include "AliGenMUONlib.h"
33#include "AliMC.h"
34#include "AliRun.h"
35#include <TDirectory.h>
36#include <TFile.h>
37#include <TTree.h>
38#include <stdlib.h>
39 ClassImp(AliGenExtFile)
40 AliGenExtFile::AliGenExtFile()
41 :AliGenerator(-1)
42{
f87cfe57 43// Constructor
693caace 44 fName="ExtFile";
45 fTitle="Primaries from ext. File";
46 fFileName="dtujet93.root";
47 fTreeNtuple=0;
48 fNcurrent=0;
49//
50// Read all particles
51 fNpart=-1;
52}
53
54AliGenExtFile::AliGenExtFile(Int_t npart)
55 :AliGenerator(npart)
56{
f87cfe57 57// Constructor
693caace 58 fName="ExtFile";
59 fTitle="Primaries from ext. File";
60 fFileName="dtujet93.root";
61 fTreeNtuple=0;
62 fNcurrent=0;
63}
64
f87cfe57 65AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
66{
67// copy constructor
68}
693caace 69//____________________________________________________________
70AliGenExtFile::~AliGenExtFile()
71{
f87cfe57 72// Destructor
693caace 73 delete fTreeNtuple;
74}
75
76//____________________________________________________________
77void AliGenExtFile::NtupleInit()
78{
79//
80// reset the existing file environment and open a new root file if
81// the pointer to the Fluka tree is null
82
f87cfe57 83 TFile *pFile=0;
693caace 84 if (fTreeNtuple==0) {
f87cfe57 85 if (!pFile) {
86 pFile = new TFile(fFileName);
87 pFile->cd();
693caace 88 cout<<"I have opened "<<fFileName<<" file "<<endl;
89 }
90// get the tree address in the Fluka boundary source file
91 fTreeNtuple = (TTree*)gDirectory->Get("h888");
92 } else {
f87cfe57 93 pFile = fTreeNtuple->GetCurrentFile();
94 pFile->cd();
693caace 95 }
96
97 TTree *h2=fTreeNtuple;
98//Set branch addresses
99//Set branch addresses
f87cfe57 100 h2->SetBranchAddress("Nihead",&fNihead);
101 h2->SetBranchAddress("Ihead",fIhead);
102 h2->SetBranchAddress("Nrhead",&fNrhead);
103 h2->SetBranchAddress("Rhead",fRhead);
104 h2->SetBranchAddress("Idpart",&fIdpart);
105 h2->SetBranchAddress("Theta",&fTheta);
106 h2->SetBranchAddress("Phi",&fPhi);
107 h2->SetBranchAddress("P",&fP);
108 h2->SetBranchAddress("E",&fE);
693caace 109}
110
111
112//____________________________________________________________
113void AliGenExtFile::Generate()
114{
f87cfe57 115// Generate particles
693caace 116
693caace 117 Float_t polar[3]= {0,0,0};
118 //
119 Float_t origin[3]={0,0,0};
120 Float_t p[3];
121 Float_t random[6];
122 Float_t prwn;
f87cfe57 123 Int_t i, j, nt, nTracks=0;
693caace 124 //
125 NtupleInit();
126 TTree *h2=fTreeNtuple;
127 Int_t nentries = (Int_t) h2->GetEntries();
128 // loop over number of particles
129 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
f87cfe57 130 Int_t i5=fIhead[4];
131 Int_t i6=fIhead[5];
693caace 132
133 for (j=0;j<3;j++) origin[j]=fOrigin[j];
134 if(fVertexSmear==perEvent) {
cfce8870 135 gMC->Rndm(random,6);
693caace 136 for (j=0;j<3;j++) {
137 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
138 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
139 }
140 }
141
142 if (fNcurrent >= nentries) {
143 printf("\n No more entries !!! !\n");
144 return;
145 }
146
147
148 if (i5==0) {
149 printf("\n This should never happen !\n");
150 } else {
151 printf("\n Next event contains %d tracks! \n", i6);
f87cfe57 152 nTracks=i6;
693caace 153 }
f87cfe57 154 for (i=0; i<nTracks; i++) {
155 fIdpart=gMC->PDGFromId(fIdpart);
156 Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
157 if(fE<=amass) {
3c8636e9 158 Warning("Generate","Particle %d no %d E = %f mass = %f\n",
f87cfe57 159 fIdpart,i,fE,amass);
c7a01d5a 160 prwn=0;
161 } else {
f87cfe57 162 prwn=sqrt((fE+amass)*(fE-amass));
c7a01d5a 163 }
693caace 164
f87cfe57 165 fTheta *= TMath::Pi()/180.;
166 fPhi = (fPhi-180)*TMath::Pi()/180.;
167 if(fTheta<fThetaMin || fTheta>fThetaMax ||
168 fPhi<fPhiMin || fPhi>fPhiMax ||
693caace 169 prwn<fPMin || prwn>fPMax)
170 {
171 ;
172 } else {
f87cfe57 173 p[0]=prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
174 p[1]=prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);
175 p[2]=prwn*TMath::Cos(fTheta);
693caace 176
177 if(fVertexSmear==perTrack) {
cfce8870 178 gMC->Rndm(random,6);
693caace 179 for (j=0;j<3;j++) {
180 origin[j]=fOrigin[j]
181 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
182 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
183 }
184 }
f87cfe57 185 gAlice->SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,"Primary",nt);
693caace 186 }
187 fNcurrent++;
188 nb = (Int_t)h2->GetEvent(fNcurrent);
189 }
190
f87cfe57 191 TFile *pFile=0;
693caace 192// Get AliRun object or create it
193 if (!gAlice) {
f87cfe57 194 gAlice = (AliRun*)pFile->Get("gAlice");
693caace 195 if (gAlice) printf("AliRun object found on file\n");
196 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
197 }
198 TTree *fAli=gAlice->TreeK();
f87cfe57 199 if (fAli) pFile =fAli->GetCurrentFile();
200 pFile->cd();
693caace 201}
202
203
f87cfe57 204AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
205{
206// Assignment operator
207 return *this;
208}
209
693caace 210
211
212
213
214
215
216