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.15 2001/01/23 13:29:37 morsch
19 Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
20 and GEANT3 codes (old ntuples) in input file.
22 Revision 1.14 2000/12/21 16:24:06 morsch
23 Coding convention clean-up
25 Revision 1.13 2000/11/30 07:12:50 alibrary
26 Introducing new Rndm and QA classes
28 Revision 1.12 2000/10/27 13:54:45 morsch
29 Remove explicite reference to input file from constuctor.
31 Revision 1.11 2000/10/02 21:28:06 fca
32 Removal of useless dependecies via forward declarations
34 Revision 1.10 2000/07/11 18:24:55 fca
35 Coding convention corrections + few minor bug fixes
37 Revision 1.9 2000/06/14 15:20:09 morsch
40 Revision 1.8 2000/06/09 20:36:44 morsch
41 All coding rule violations except RS3 corrected
43 Revision 1.7 2000/02/16 14:56:27 morsch
44 Convert geant particle code into pdg code before putting particle on the stack.
46 Revision 1.6 1999/11/09 07:38:48 fca
47 Changes for compatibility with version 2.23 of ROOT
49 Revision 1.5 1999/09/29 09:24:12 fca
50 Introduction of the Copyright and cvs Log
55 // Event generator that can read the old ALICE event format based on CW-ntuples
56 // http://consult.cern.ch/alice/Internal_Notes/1995/32/abstract
57 // .cwn file have to be converted to .root using h2root
58 // Use SetFileName(file) to read from "file"
59 // Author: andreas.morsch@cern.ch
63 #include "AliGenExtFile.h"
67 #include <TDirectory.h>
68 #include <TDatabasePDG.h>
73 ClassImp(AliGenExtFile)
74 AliGenExtFile::AliGenExtFile()
79 fTitle="Primaries from ext. File";
89 AliGenExtFile::AliGenExtFile(Int_t npart)
94 fTitle="Primaries from ext. File";
101 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
105 //____________________________________________________________
106 AliGenExtFile::~AliGenExtFile()
112 //____________________________________________________________
113 void AliGenExtFile::NtupleInit()
116 // reset the existing file environment and open a new root file if
117 // the pointer to the Fluka tree is null
120 if (fTreeNtuple==0) {
122 pFile = new TFile(fFileName);
124 cout<<"I have opened "<<fFileName<<" file "<<endl;
126 // get the tree address in the Fluka boundary source file
127 fTreeNtuple = (TTree*)gDirectory->Get("h888");
129 pFile = fTreeNtuple->GetCurrentFile();
133 TTree *h2=fTreeNtuple;
134 //Set branch addresses
135 h2->SetBranchAddress("Nihead",&fNihead);
136 h2->SetBranchAddress("Ihead",fIhead);
137 h2->SetBranchAddress("Nrhead",&fNrhead);
138 h2->SetBranchAddress("Rhead",fRhead);
139 h2->SetBranchAddress("Idpart",&fIdpart);
140 h2->SetBranchAddress("Theta",&fTheta);
141 h2->SetBranchAddress("Phi",&fPhi);
142 h2->SetBranchAddress("P",&fP);
143 h2->SetBranchAddress("E",&fE);
147 //____________________________________________________________
148 void AliGenExtFile::Generate()
150 // Generate particles
152 Float_t polar[3]= {0,0,0};
154 Float_t origin[3]={0,0,0};
158 Int_t i, j, nt, nTracks=0;
161 TTree *h2=fTreeNtuple;
162 Int_t nentries = (Int_t) h2->GetEntries();
163 // loop over number of particles
164 Int_t nb = (Int_t)h2->GetEvent(fNcurrent);
168 for (j=0;j<3;j++) origin[j]=fOrigin[j];
169 if(fVertexSmear==kPerTrack) {
172 origin[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
173 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
177 if (fNcurrent >= nentries) {
178 printf("\n No more entries !!! !\n");
184 printf("\n This should never happen !\n");
186 printf("\n Next event contains %d tracks! \n", i6);
189 for (i=0; i<nTracks; i++) {
190 if (fCode == kGEANT3) fIdpart=gMC->PDGFromId(fIdpart);
191 Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
193 Warning("Generate","Particle %d no %d E = %f mass = %f %f %f \n",
194 fIdpart,i,fE,amass, fPhi, fTheta);
197 prwn=sqrt((fE+amass)*(fE-amass));
200 fTheta *= TMath::Pi()/180.;
201 fPhi = (fPhi-180)*TMath::Pi()/180.;
202 if(fTheta<fThetaMin || fTheta>fThetaMax ||
203 fPhi<fPhiMin || fPhi>fPhiMax ||
204 prwn<fPMin || prwn>fPMax)
208 p[0]=prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
209 p[1]=prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);
210 p[2]=prwn*TMath::Cos(fTheta);
212 if(fVertexSmear==kPerTrack) {
216 +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
217 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
220 SetTrack(fTrackIt,-1,fIdpart,p,origin,polar,0,kPPrimary,nt);
223 nb = (Int_t)h2->GetEvent(fNcurrent);
227 // Get AliRun object or create it
229 gAlice = (AliRun*)pFile->Get("gAlice");
230 if (gAlice) printf("AliRun object found on file\n");
231 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
233 TTree *fAli=gAlice->TreeK();
234 if (fAli) pFile =fAli->GetCurrentFile();
239 AliGenExtFile& AliGenExtFile::operator=(const AliGenExtFile& rhs)
241 // Assignment operator