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 **************************************************************************/
20 #include "AliGenFLUKAsource.h"
21 #include "AliGenMUONlib.h"
26 #include <TDirectory.h>
30 ClassImp(AliGenFLUKAsource)
31 AliGenFLUKAsource::AliGenFLUKAsource()
36 fTitle="FLUKA Boundary Source";
37 // Read in all particle types by default
39 // Set maximum admitted age of particles to 1.e-05 by default
43 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
44 // from specific boundary source to the chamber (fZshift=4.5;),else there
45 // is no need to shift as it reads boundary source for the whole volume of
46 // the Muon Arm; the default value corresponds to boundary source for the
47 // whole volume of the MUON Arm
49 // Set the default file
50 fFileName="flukasource.root";
59 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
64 fTitle="FLUKA Boundary Source";
65 // Read in all particle types by default
67 // Set maximum admitted age of particles to 1.e-05 by default
71 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
72 // from specific boundary source to the chamber (fZshift=4.5;),else there
73 // is no need to shift as it reads boundary source for the whole volume of
74 // the Muon Arm; the default value corresponds to boundary source for the
75 // whole volume of the MUON Arm
77 // Set the default file
78 fFileName="flukasource.root";
84 //____________________________________________________________
85 AliGenFLUKAsource::~AliGenFLUKAsource()
90 //____________________________________________________________
91 void AliGenFLUKAsource::FlukaInit()
94 // reset the existing file environment and open a new root file if
95 // the pointer to the Fluka tree is null
100 File = new TFile(fFileName);
102 cout<<"I have opened "<<fFileName<<" file "<<endl;
104 // get the tree address in the Fluka boundary source file
105 fTreeFluka = (TTree*)gDirectory->Get("h1");
107 File = fTreeFluka->GetCurrentFile();
111 TTree *h2=fTreeFluka;
112 //Set branch addresses
113 h2->SetBranchAddress("Ip",&Ip);
114 h2->SetBranchAddress("Ipp",&Ipp);
115 h2->SetBranchAddress("Xi",&Xi);
116 h2->SetBranchAddress("Yi",&Yi);
117 h2->SetBranchAddress("Zi",&Zi);
118 h2->SetBranchAddress("Px",&Px);
119 h2->SetBranchAddress("Py",&Py);
120 h2->SetBranchAddress("Pz",&Pz);
121 h2->SetBranchAddress("Ekin",&Ekin);
122 h2->SetBranchAddress("Zv",&Zv);
123 h2->SetBranchAddress("Rv",&Rv);
124 h2->SetBranchAddress("Itra",&Itra);
125 h2->SetBranchAddress("Igas",&Igas);
126 h2->SetBranchAddress("Wgt",&Wgt);
127 h2->SetBranchAddress("Etag",&Etag);
128 h2->SetBranchAddress("Ptg",&Ptg);
129 h2->SetBranchAddress("Age",&Age);
132 //____________________________________________________________
133 void AliGenFLUKAsource::Generate()
136 const Int_t ifluge[28]={kProton, kProtonBar, kElectron, kPositron,
137 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
138 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
139 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
140 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
142 Float_t polar[3]= {0,0,0};
150 Float_t amass, charge, tlife;
153 Int_t i, j, part, nt;
159 TTree *h2=fTreeFluka;
160 Int_t nentries = (Int_t) h2->GetEntries();
161 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
163 // loop over number of particles
165 for (i=0; i<fNpart;i++) {
166 Int_t ev=gMC->CurrentEvent();
167 Int_t entry=fNpart*(ev-1)+i;
168 nb = (Int_t)h2->GetEvent(entry);
169 if (irwn > nentries) {
170 printf("No more entries in the FLUKA boundary source file\n");
172 // Get AliRun object or create it
174 gAlice = (AliRun*)File->Get("gAlice");
175 if (gAlice) printf("AliRun object found on file\n");
176 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
178 TTree *fAli=gAlice->TreeK();
179 if (fAli) File =fAli->GetCurrentFile();
181 printf("Generate - I'm out \n");
184 if (Ip > 28 || Ip < 0) {
189 if ((Ip != fIkine && fIkine != 6 && fIkine != 9) || Age > fAgeMax){
192 } else if (fIkine == 9) {
193 if (Ip == 7 || Ip == 8 || Age > fAgeMax) {
201 printf("\n Particle type: %f \n \n ", Ip);
206 } else if (Ip == 8) {
207 prwn=sqrt(Ekin*Ekin + 2.*0.93956563);
210 part=ifluge[int(Ip)-1];
211 gMC->Gfpart(part, name, itrtyp,
212 amass, charge, tlife);
213 prwn=sqrt(Ekin*Ekin + 2.*amass);
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(1,-1,part,p,origin,polar,0,"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();