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.13 2000/11/30 07:12:50 alibrary
19 Introducing new Rndm and QA classes
21 Revision 1.12 2000/10/27 13:54:45 morsch
22 Remove explicite reference to input file from constuctor.
24 Revision 1.11 2000/10/02 21:28:06 fca
25 Removal of useless dependecies via forward declarations
27 Revision 1.10 2000/07/11 18:24:55 fca
28 Coding convention corrections + few minor bug fixes
30 Revision 1.9 2000/06/14 15:20:09 morsch
33 Revision 1.8 2000/06/09 20:36:44 morsch
34 All coding rule violations except RS3 corrected
36 Revision 1.7 2000/02/16 14:56:27 morsch
37 Convert geant particle code into pdg code before putting particle on the stack.
39 Revision 1.6 1999/11/09 07:38:48 fca
40 Changes for compatibility with version 2.23 of ROOT
42 Revision 1.5 1999/09/29 09:24:12 fca
43 Introduction of the Copyright and cvs Log
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
56 #include "AliGenExtFile.h"
60 #include <TDirectory.h>
61 #include <TDatabasePDG.h>
66 ClassImp(AliGenExtFile)
67 AliGenExtFile::AliGenExtFile()
72 fTitle="Primaries from ext. File";
81 AliGenExtFile::AliGenExtFile(Int_t npart)
86 fTitle="Primaries from ext. File";
92 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
96 //____________________________________________________________
97 AliGenExtFile::~AliGenExtFile()
103 //____________________________________________________________
104 void AliGenExtFile::NtupleInit()
107 // reset the existing file environment and open a new root file if
108 // the pointer to the Fluka tree is null
111 if (fTreeNtuple==0) {
113 pFile = new TFile(fFileName);
115 cout<<"I have opened "<<fFileName<<" file "<<endl;
117 // get the tree address in the Fluka boundary source file
118 fTreeNtuple = (TTree*)gDirectory->Get("h888");
120 pFile = fTreeNtuple->GetCurrentFile();
124 TTree *h2=fTreeNtuple;
125 //Set branch addresses
126 //Set branch addresses
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);
139 //____________________________________________________________
140 void AliGenExtFile::Generate()
142 // Generate particles
144 Float_t polar[3]= {0,0,0};
146 Float_t origin[3]={0,0,0};
150 Int_t i, j, nt, nTracks=0;
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);
160 for (j=0;j<3;j++) origin[j]=fOrigin[j];
161 if(fVertexSmear==kPerTrack) {
164 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
165 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
169 if (fNcurrent >= nentries) {
170 printf("\n No more entries !!! !\n");
176 printf("\n This should never happen !\n");
178 printf("\n Next event contains %d tracks! \n", i6);
181 for (i=0; i<nTracks; i++) {
182 fIdpart=gMC->PDGFromId(fIdpart);
183 Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
185 Warning("Generate","Particle %d no %d E = %f mass = %f %f %f \n",
186 fIdpart,i,fE,amass, fPhi, fTheta);
189 prwn=sqrt((fE+amass)*(fE-amass));
192 fTheta *= TMath::Pi()/180.;
193 fPhi = (fPhi-180)*TMath::Pi()/180.;
194 if(fTheta<fThetaMin || fTheta>fThetaMax ||
195 fPhi<fPhiMin || fPhi>fPhiMax ||
196 prwn<fPMin || prwn>fPMax)
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);
204 if(fVertexSmear==kPerTrack) {
208 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
209 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
212 gAlice->SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,kPPrimary,nt);
215 nb = (Int_t)h2->GetEvent(fNcurrent);
219 // Get AliRun object or create it
221 gAlice = (AliRun*)pFile->Get("gAlice");
222 if (gAlice) printf("AliRun object found on file\n");
223 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
225 TTree *fAli=gAlice->TreeK();
226 if (fAli) pFile =fAli->GetCurrentFile();
231 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
233 // Assignment operator