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