1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.7 1999/11/03 17:43:20 fca
19 New version from G.Martinez & A.Morsch
21 Revision 1.6 1999/09/29 09:24:12 fca
22 Introduction of the Copyright and cvs Log
26 #include "AliGenFLUKAsource.h"
27 #include "AliGenMUONlib.h"
31 #include <TDirectory.h>
35 ClassImp(AliGenFLUKAsource)
36 AliGenFLUKAsource::AliGenFLUKAsource()
41 fTitle="FLUKA Boundary Source";
42 // Read in all particle types by default
44 // Set maximum admitted age of particles to 1.e-05 by default
48 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
49 // from specific boundary source to the chamber (fZshift=4.5;),else there
50 // is no need to shift as it reads boundary source for the whole volume of
51 // the Muon Arm; the default value corresponds to boundary source for the
52 // whole volume of the MUON Arm
54 // Set the default file
55 fFileName="flukasource.root";
58 fTreeChain = new TChain("h1");
65 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
70 fTitle="FLUKA Boundary Source";
71 // Read in all particle types by default
73 // Set maximum admitted age of particles to 1.e-05 by default
77 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
78 // from specific boundary source to the chamber (fZshift=4.5;),else there
79 // is no need to shift as it reads boundary source for the whole volume of
80 // the Muon Arm; the default value corresponds to boundary source for the
81 // whole volume of the MUON Arm
83 // Set the default file
84 fFileName="flukasource.root";
87 fTreeChain = new TChain("h1");
90 //____________________________________________________________
91 AliGenFLUKAsource::~AliGenFLUKAsource()
93 if (fTreeFluka) delete fTreeFluka;
94 if (fTreeChain) delete fTreeChain;
95 // if (fFileName) delete fFileName;
98 void AliGenFLUKAsource::AddFile(const Text_t *filename)
100 fTreeChain->Add(filename);
105 //____________________________________________________________
106 void AliGenFLUKAsource::FlukaInit()
108 TChain *h2=fTreeChain;
109 //Set branch addresses
110 h2->SetBranchAddress("Ip",&Ip);
111 h2->SetBranchAddress("Ipp",&Ipp);
112 h2->SetBranchAddress("Xi",&Xi);
113 h2->SetBranchAddress("Yi",&Yi);
114 h2->SetBranchAddress("Zi",&Zi);
115 h2->SetBranchAddress("Px",&Px);
116 h2->SetBranchAddress("Py",&Py);
117 h2->SetBranchAddress("Pz",&Pz);
118 h2->SetBranchAddress("Ekin",&Ekin);
119 h2->SetBranchAddress("Zv",&Zv);
120 h2->SetBranchAddress("Rv",&Rv);
121 h2->SetBranchAddress("Itra",&Itra);
122 h2->SetBranchAddress("Igas",&Igas);
123 h2->SetBranchAddress("Wgt",&Wgt);
124 h2->SetBranchAddress("Etag",&Etag);
125 h2->SetBranchAddress("Ptg",&Ptg);
126 h2->SetBranchAddress("Age",&Age);
129 //____________________________________________________________
130 void AliGenFLUKAsource::Generate()
132 AliMC* gMC = AliMC::GetMC();
134 const Int_t ifluge[28]={kProton, kProtonBar, kElectron, kPositron,
135 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
136 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
137 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
138 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
140 Float_t polar[3]= {0,0,0};
148 Float_t amass, charge, tlife;
151 Int_t i, j, part, nt;
157 TChain *h2=fTreeChain;
158 Int_t nentries = (Int_t) h2->GetEntries();
159 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
161 // loop over number of particles
163 Int_t ev=gMC->CurrentEvent();
164 for (i=0; i<fNpart;i++) {
165 Int_t entry=fNpart*(ev-1)+i;
166 nb = (Int_t)h2->GetEvent(entry);
167 if (irwn > nentries) {
168 printf("No more entries in the FLUKA boundary source file\n");
170 // Get AliRun object or create it
172 gAlice = (AliRun*)File->Get("gAlice");
173 if (gAlice) printf("AliRun object found on file\n");
174 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
176 TTree *fAli=gAlice->TreeK();
177 if (fAli) File =fAli->GetCurrentFile();
179 printf("Generate - I'm out \n");
182 if (Ip > 28 || Ip < 0) {
187 if ((Ip != fIkine && fIkine != 6 && fIkine != 9 && fIkine != 10) || Age > fAgeMax){
190 } else if (fIkine == 9) {
191 if (Ip == 7 || Ip == 8 || Age > fAgeMax) {
195 } else if (fIkine == 10) {
196 if (Ip == 8 || Age > fAgeMax) {
205 // PDG code from FLUKA particle type (Ip)
206 part=ifluge[int(Ip)-1];
208 // Calculate momentum from kinetic energy and mass of the particle
209 gMC->Gfpart(part, name, itrtyp,
210 amass, charge, tlife);
211 prwn=Ekin*sqrt(1. + 2.*amass/Ekin);
222 //handle particle weight correctly
223 wgt = (part == 13) ? Wgt*fAddWeight : Wgt;
225 fwgt=wgt-Float_t(iwgt);
227 if (random[0] < fwgt) iwgt++;
228 if (part==1 && iwgt>100) iwgt=100;
230 for (j=0; j<iwgt; j++) {
231 gAlice->SetTrack(fTrackIt,-1,part,p,origin,polar,Age,"Primary",nt);
233 phi=2*random[1]*TMath::Pi();
234 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
235 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
238 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
239 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
244 if (nstack == 0) continue;
248 // Get AliRun object or create it
250 gAlice = (AliRun*)File->Get("gAlice");
251 if (gAlice) printf("AliRun object found on file\n");
252 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
254 TTree *fAli=gAlice->TreeK();
255 if (fAli) File =fAli->GetCurrentFile();