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