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