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