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