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.6 1999/09/29 09:24:12 fca
19 Introduction of the Copyright and cvs Log
23 #include "AliGenFLUKAsource.h"
24 #include "AliGenMUONlib.h"
28 #include <TDirectory.h>
32 ClassImp(AliGenFLUKAsource)
33 AliGenFLUKAsource::AliGenFLUKAsource()
38 fTitle="FLUKA Boundary Source";
39 // Read in all particle types by default
41 // Set maximum admitted age of particles to 1.e-05 by default
45 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
46 // from specific boundary source to the chamber (fZshift=4.5;),else there
47 // is no need to shift as it reads boundary source for the whole volume of
48 // the Muon Arm; the default value corresponds to boundary source for the
49 // whole volume of the MUON Arm
51 // Set the default file
52 fFileName="flukasource.root";
55 fTreeChain = new TChain("h1");
62 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
67 fTitle="FLUKA Boundary Source";
68 // Read in all particle types by default
70 // Set maximum admitted age of particles to 1.e-05 by default
74 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
75 // from specific boundary source to the chamber (fZshift=4.5;),else there
76 // is no need to shift as it reads boundary source for the whole volume of
77 // the Muon Arm; the default value corresponds to boundary source for the
78 // whole volume of the MUON Arm
80 // Set the default file
81 fFileName="flukasource.root";
84 fTreeChain = new TChain("h1");
87 //____________________________________________________________
88 AliGenFLUKAsource::~AliGenFLUKAsource()
90 if (fTreeFluka) delete fTreeFluka;
91 if (fTreeChain) delete fTreeChain;
92 // if (fFileName) delete fFileName;
95 void AliGenFLUKAsource::AddFile(const Text_t *filename)
97 fTreeChain->Add(filename);
102 //____________________________________________________________
103 void AliGenFLUKAsource::FlukaInit()
105 TChain *h2=fTreeChain;
106 //Set branch addresses
107 h2->SetBranchAddress("Ip",&Ip);
108 h2->SetBranchAddress("Ipp",&Ipp);
109 h2->SetBranchAddress("Xi",&Xi);
110 h2->SetBranchAddress("Yi",&Yi);
111 h2->SetBranchAddress("Zi",&Zi);
112 h2->SetBranchAddress("Px",&Px);
113 h2->SetBranchAddress("Py",&Py);
114 h2->SetBranchAddress("Pz",&Pz);
115 h2->SetBranchAddress("Ekin",&Ekin);
116 h2->SetBranchAddress("Zv",&Zv);
117 h2->SetBranchAddress("Rv",&Rv);
118 h2->SetBranchAddress("Itra",&Itra);
119 h2->SetBranchAddress("Igas",&Igas);
120 h2->SetBranchAddress("Wgt",&Wgt);
121 h2->SetBranchAddress("Etag",&Etag);
122 h2->SetBranchAddress("Ptg",&Ptg);
123 h2->SetBranchAddress("Age",&Age);
126 //____________________________________________________________
127 void AliGenFLUKAsource::Generate()
129 AliMC* gMC = AliMC::GetMC();
131 const Int_t ifluge[28]={kProton, kProtonBar, kElectron, kPositron,
132 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
133 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
134 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
135 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
137 Float_t polar[3]= {0,0,0};
145 Float_t amass, charge, tlife;
148 Int_t i, j, part, nt;
154 TChain *h2=fTreeChain;
155 Int_t nentries = (Int_t) h2->GetEntries();
156 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
158 // loop over number of particles
160 Int_t ev=gMC->CurrentEvent();
161 for (i=0; i<fNpart;i++) {
162 Int_t entry=fNpart*(ev-1)+i;
163 nb = (Int_t)h2->GetEvent(entry);
164 if (irwn > nentries) {
165 printf("No more entries in the FLUKA boundary source file\n");
167 // Get AliRun object or create it
169 gAlice = (AliRun*)File->Get("gAlice");
170 if (gAlice) printf("AliRun object found on file\n");
171 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
173 TTree *fAli=gAlice->TreeK();
174 if (fAli) File =fAli->GetCurrentFile();
176 printf("Generate - I'm out \n");
179 if (Ip > 28 || Ip < 0) {
184 if ((Ip != fIkine && fIkine != 6 && fIkine != 9 && fIkine != 10) || Age > fAgeMax){
187 } else if (fIkine == 9) {
188 if (Ip == 7 || Ip == 8 || Age > fAgeMax) {
192 } else if (fIkine == 10) {
193 if (Ip == 8 || Age > fAgeMax) {
201 printf("\n Particle type: %f \n \n ", Ip);
206 } else if (Ip == 8) {
207 prwn=Ekin*sqrt(1. + 2.*0.93956563/Ekin);
210 part=ifluge[int(Ip)-1];
211 gMC->Gfpart(part, name, itrtyp,
212 amass, charge, tlife);
213 prwn=Ekin*sqrt(1. + 2.*amass/Ekin);
223 //handle particle weight correctly
224 wgt = (part == 13) ? Wgt*fAddWeight : Wgt;
226 fwgt=wgt-Float_t(iwgt);
228 if (random[0] < fwgt) iwgt++;
229 if (part==1 && iwgt>100) iwgt=100;
231 for (j=0; j<iwgt; j++) {
232 gAlice->SetTrack(fTrackIt,-1,part,p,origin,polar,Age,"Primary",nt);
234 phi=2*random[1]*TMath::Pi();
235 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
236 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
239 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
240 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
245 if (nstack == 0) continue;
249 // Get AliRun object or create it
251 gAlice = (AliRun*)File->Get("gAlice");
252 if (gAlice) printf("AliRun object found on file\n");
253 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
255 TTree *fAli=gAlice->TreeK();
256 if (fAli) File =fAli->GetCurrentFile();