]>
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$ | |
65fb704d | 18 | Revision 1.11 2000/06/14 15:20:40 morsch |
19 | Include clean-up (IH) | |
20 | ||
5c3fd7ea | 21 | Revision 1.10 2000/06/09 20:31:34 morsch |
22 | All coding rule violations except RS3 corrected | |
23 | ||
f87cfe57 | 24 | Revision 1.9 2000/03/07 13:52:54 morsch |
25 | static Int_t irwn=0; | |
26 | ||
e7bafa6d | 27 | Revision 1.8 2000/02/14 14:49:38 morsch |
28 | Correct particle type for gamma and neutrons | |
29 | More consistent calculation of momentum from kin. energy and mass | |
30 | ||
02769dba | 31 | Revision 1.7 1999/11/03 17:43:20 fca |
32 | New version from G.Martinez & A.Morsch | |
33 | ||
886b6f73 | 34 | Revision 1.6 1999/09/29 09:24:12 fca |
35 | Introduction of the Copyright and cvs Log | |
36 | ||
4c039060 | 37 | */ |
38 | ||
fe4da5cc | 39 | #include "AliGenFLUKAsource.h" |
fe4da5cc | 40 | #include "AliMC.h" |
41 | #include "AliRun.h" | |
c5970876 | 42 | #include "AliPDG.h" |
5c3fd7ea | 43 | |
44 | ||
fe4da5cc | 45 | #include <TFile.h> |
46 | #include <TTree.h> | |
f87cfe57 | 47 | #include <TChain.h> |
fe4da5cc | 48 | #include <stdlib.h> |
49 | ClassImp(AliGenFLUKAsource) | |
50 | AliGenFLUKAsource::AliGenFLUKAsource() | |
51 | :AliGenerator(-1) | |
52 | { | |
f87cfe57 | 53 | // Constructor |
fe4da5cc | 54 | fName="FLUKA"; |
55 | fTitle="FLUKA Boundary Source"; | |
56 | // Read in all particle types by default | |
57 | fIkine=6; | |
58 | // Set maximum admitted age of particles to 1.e-05 by default | |
59 | fAgeMax=1.e-05; | |
60 | // Do not add weight | |
61 | fAddWeight=1.; | |
62 | // Shift the z-coordinate of the impact point by 4.5 cm only if it reads | |
63 | // from specific boundary source to the chamber (fZshift=4.5;),else there | |
64 | // is no need to shift as it reads boundary source for the whole volume of | |
65 | // the Muon Arm; the default value corresponds to boundary source for the | |
66 | // whole volume of the MUON Arm | |
67 | fZshift=0; | |
68 | // Set the default file | |
69 | fFileName="flukasource.root"; | |
70 | ||
71 | fTreeFluka=0; | |
886b6f73 | 72 | fTreeChain = new TChain("h1"); |
fe4da5cc | 73 | // |
74 | // Read all particles | |
75 | fNpart=-1; | |
f87cfe57 | 76 | |
fe4da5cc | 77 | |
78 | } | |
79 | ||
80 | AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart) | |
81 | :AliGenerator(npart) | |
82 | { | |
f87cfe57 | 83 | // Constructor |
fe4da5cc | 84 | fName="FLUKA"; |
85 | fTitle="FLUKA Boundary Source"; | |
86 | // Read in all particle types by default | |
87 | fIkine=6; | |
88 | // Set maximum admitted age of particles to 1.e-05 by default | |
89 | fAgeMax=1.e-05; | |
90 | // Do not add weight | |
91 | fAddWeight=1.; | |
92 | // Shift the z-coordinate of the impact point by 4.5 cm only if it reads | |
93 | // from specific boundary source to the chamber (fZshift=4.5;),else there | |
94 | // is no need to shift as it reads boundary source for the whole volume of | |
95 | // the Muon Arm; the default value corresponds to boundary source for the | |
96 | // whole volume of the MUON Arm | |
97 | fZshift=0; | |
98 | // Set the default file | |
99 | fFileName="flukasource.root"; | |
100 | ||
101 | fTreeFluka=0; | |
886b6f73 | 102 | fTreeChain = new TChain("h1"); |
f87cfe57 | 103 | fSourceId=-1; |
fe4da5cc | 104 | } |
105 | ||
f87cfe57 | 106 | AliGenFLUKAsource::AliGenFLUKAsource(const AliGenFLUKAsource & FLUKAsource) |
107 | { | |
108 | // copy constructor | |
109 | } | |
110 | ||
111 | ||
fe4da5cc | 112 | //____________________________________________________________ |
113 | AliGenFLUKAsource::~AliGenFLUKAsource() | |
114 | { | |
f87cfe57 | 115 | // Destructor |
886b6f73 | 116 | if (fTreeFluka) delete fTreeFluka; |
117 | if (fTreeChain) delete fTreeChain; | |
fe4da5cc | 118 | } |
119 | ||
886b6f73 | 120 | void AliGenFLUKAsource::AddFile(const Text_t *filename) |
fe4da5cc | 121 | { |
f87cfe57 | 122 | // Add a file to the chain |
886b6f73 | 123 | fTreeChain->Add(filename); |
fe4da5cc | 124 | |
886b6f73 | 125 | } |
126 | ||
fe4da5cc | 127 | |
886b6f73 | 128 | //____________________________________________________________ |
129 | void AliGenFLUKAsource::FlukaInit() | |
130 | { | |
f87cfe57 | 131 | // Set branch addresses of data entries |
886b6f73 | 132 | TChain *h2=fTreeChain; |
fe4da5cc | 133 | //Set branch addresses |
f87cfe57 | 134 | h2->SetBranchAddress("Ip",&fIp); |
135 | h2->SetBranchAddress("Ipp",&fIpp); | |
136 | h2->SetBranchAddress("Xi",&fXi); | |
137 | h2->SetBranchAddress("Yi",&fYi); | |
138 | h2->SetBranchAddress("Zi",&fZi); | |
139 | h2->SetBranchAddress("Px",&fPx); | |
140 | h2->SetBranchAddress("Py",&fPy); | |
141 | h2->SetBranchAddress("Pz",&fPz); | |
142 | h2->SetBranchAddress("Ekin",&fEkin); | |
143 | h2->SetBranchAddress("Zv",&fZv); | |
144 | h2->SetBranchAddress("Rv",&fRv); | |
145 | h2->SetBranchAddress("Itra",&fItra); | |
146 | h2->SetBranchAddress("Igas",&fIgas); | |
147 | h2->SetBranchAddress("Wgt",&fWgt); | |
148 | h2->SetBranchAddress("Etag",&fEtag); | |
149 | h2->SetBranchAddress("Ptg",&fPtg); | |
150 | h2->SetBranchAddress("Age",&fAge); | |
fe4da5cc | 151 | } |
152 | ||
153 | //____________________________________________________________ | |
154 | void AliGenFLUKAsource::Generate() | |
f87cfe57 | 155 | { |
156 | // Generate one event | |
886b6f73 | 157 | AliMC* gMC = AliMC::GetMC(); |
fe4da5cc | 158 | |
f87cfe57 | 159 | const Int_t kIfluge[28]={kProton, kProtonBar, kElectron, kPositron, |
1578254f | 160 | kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar, |
161 | kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus, | |
162 | kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short, | |
163 | kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar, | |
164 | 0,kNuMu,kNuMuBar}; | |
886b6f73 | 165 | Float_t polar[3]= {0,0,0}; |
fe4da5cc | 166 | // |
886b6f73 | 167 | Float_t origin[3]; |
168 | Float_t p[3]; | |
169 | Float_t prwn; | |
170 | Float_t wgt, fwgt; | |
171 | Float_t phi; | |
172 | char name[100]; | |
173 | Float_t amass, charge, tlife; | |
174 | Int_t itrtyp; | |
175 | Int_t iwgt; | |
176 | Int_t i, j, part, nt; | |
e7bafa6d | 177 | static Int_t irwn=0; |
886b6f73 | 178 | // |
179 | Float_t random[2]; | |
fe4da5cc | 180 | // |
886b6f73 | 181 | FlukaInit(); |
182 | TChain *h2=fTreeChain; | |
183 | Int_t nentries = (Int_t) h2->GetEntries(); | |
184 | if (fNpart == -1) fNpart=Int_t(nentries*fFrac); | |
fe4da5cc | 185 | |
186 | // loop over number of particles | |
886b6f73 | 187 | Int_t nb=0; |
cfce8870 | 188 | Int_t ev=gMC->CurrentEvent(); |
886b6f73 | 189 | for (i=0; i<fNpart;i++) { |
190 | Int_t entry=fNpart*(ev-1)+i; | |
191 | nb = (Int_t)h2->GetEvent(entry); | |
192 | if (irwn > nentries) { | |
193 | printf("No more entries in the FLUKA boundary source file\n"); | |
f87cfe57 | 194 | TFile *pFile=0; |
886b6f73 | 195 | // Get AliRun object or create it |
196 | if (!gAlice) { | |
f87cfe57 | 197 | gAlice = (AliRun*)pFile->Get("gAlice"); |
886b6f73 | 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(); | |
886b6f73 | 204 | printf("Generate - I'm out \n"); |
205 | return; | |
206 | } | |
f87cfe57 | 207 | |
208 | if (fSourceId != -1 && fIgas !=fSourceId) { | |
209 | irwn++; | |
210 | continue; | |
211 | } | |
212 | ||
213 | if (fIp > 28 || fIp < 0) { | |
886b6f73 | 214 | irwn++; |
215 | continue; | |
216 | } | |
217 | ||
f87cfe57 | 218 | if ((fIp != fIkine && fIkine != 6 && fIkine != 9 && fIkine != 10) || fAge > fAgeMax){ |
886b6f73 | 219 | irwn++; |
220 | continue; | |
221 | } else if (fIkine == 9) { | |
f87cfe57 | 222 | if (fIp == 7 || fIp == 8 || fAge > fAgeMax) { |
886b6f73 | 223 | irwn++; |
224 | continue; | |
225 | } | |
226 | } else if (fIkine == 10) { | |
f87cfe57 | 227 | if (fIp == 8 || fAge > fAgeMax) { |
886b6f73 | 228 | irwn++; |
229 | continue; | |
230 | } | |
231 | } | |
fe4da5cc | 232 | |
fe4da5cc | 233 | |
886b6f73 | 234 | irwn++; |
02769dba | 235 | // |
f87cfe57 | 236 | // PDG code from FLUKA particle type (fIp) |
237 | part=kIfluge[int(fIp)-1]; | |
02769dba | 238 | // |
239 | // Calculate momentum from kinetic energy and mass of the particle | |
240 | gMC->Gfpart(part, name, itrtyp, | |
241 | amass, charge, tlife); | |
f87cfe57 | 242 | prwn=fEkin*sqrt(1. + 2.*amass/fEkin); |
02769dba | 243 | |
244 | ||
f87cfe57 | 245 | origin[0]=fYi; |
246 | origin[1]=fXi; | |
247 | origin[2]=fZi; | |
886b6f73 | 248 | |
f87cfe57 | 249 | p[0]=fPy*prwn; |
250 | p[1]=fPx*prwn; | |
251 | p[2]=fPz*prwn; | |
fe4da5cc | 252 | |
886b6f73 | 253 | //handle particle weight correctly |
f87cfe57 | 254 | wgt = (part == 13) ? fWgt*fAddWeight : fWgt; |
886b6f73 | 255 | iwgt=Int_t(wgt); |
256 | fwgt=wgt-Float_t(iwgt); | |
65fb704d | 257 | Rndm(random,2); |
886b6f73 | 258 | if (random[0] < fwgt) iwgt++; |
259 | if (part==1 && iwgt>100) iwgt=100; | |
260 | Int_t nstack=0; | |
261 | for (j=0; j<iwgt; j++) { | |
65fb704d | 262 | gAlice->SetTrack(fTrackIt,-1,part,p,origin,polar,fAge,kPPrimary,nt); |
263 | Rndm(random,2); | |
886b6f73 | 264 | phi=2*random[1]*TMath::Pi(); |
265 | Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi); | |
266 | Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi); | |
267 | p[0]=pn1; | |
268 | p[1]=pn2; | |
269 | Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi); | |
270 | Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi); | |
271 | origin[0]=on1; | |
272 | origin[1]=on2; | |
273 | nstack++; | |
274 | } | |
275 | if (nstack == 0) continue; | |
fe4da5cc | 276 | } |
886b6f73 | 277 | |
f87cfe57 | 278 | TFile *pFile=0; |
fe4da5cc | 279 | // Get AliRun object or create it |
280 | if (!gAlice) { | |
f87cfe57 | 281 | gAlice = (AliRun*)pFile->Get("gAlice"); |
fe4da5cc | 282 | if (gAlice) printf("AliRun object found on file\n"); |
283 | if (!gAlice) gAlice = new AliRun("gAlice","Alice test program"); | |
284 | } | |
285 | TTree *fAli=gAlice->TreeK(); | |
f87cfe57 | 286 | if (fAli) pFile =fAli->GetCurrentFile(); |
287 | pFile->cd(); | |
fe4da5cc | 288 | } |
289 | ||
290 | ||
f87cfe57 | 291 | AliGenFLUKAsource& AliGenFLUKAsource::operator=(const AliGenFLUKAsource& rhs) |
292 | { | |
293 | // Assignment operator | |
294 | return *this; | |
295 | } | |
fe4da5cc | 296 | |
297 | ||
298 | ||
299 | ||
300 | ||
301 |