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.10 2000/06/09 20:31:34 morsch
19 All coding rule violations except RS3 corrected
21 Revision 1.9 2000/03/07 13:52:54 morsch
24 Revision 1.8 2000/02/14 14:49:38 morsch
25 Correct particle type for gamma and neutrons
26 More consistent calculation of momentum from kin. energy and mass
28 Revision 1.7 1999/11/03 17:43:20 fca
29 New version from G.Martinez & A.Morsch
31 Revision 1.6 1999/09/29 09:24:12 fca
32 Introduction of the Copyright and cvs Log
36 #include "AliGenFLUKAsource.h"
46 ClassImp(AliGenFLUKAsource)
47 AliGenFLUKAsource::AliGenFLUKAsource()
52 fTitle="FLUKA Boundary Source";
53 // Read in all particle types by default
55 // Set maximum admitted age of particles to 1.e-05 by default
59 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
60 // from specific boundary source to the chamber (fZshift=4.5;),else there
61 // is no need to shift as it reads boundary source for the whole volume of
62 // the Muon Arm; the default value corresponds to boundary source for the
63 // whole volume of the MUON Arm
65 // Set the default file
66 fFileName="flukasource.root";
69 fTreeChain = new TChain("h1");
77 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
82 fTitle="FLUKA Boundary Source";
83 // Read in all particle types by default
85 // Set maximum admitted age of particles to 1.e-05 by default
89 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
90 // from specific boundary source to the chamber (fZshift=4.5;),else there
91 // is no need to shift as it reads boundary source for the whole volume of
92 // the Muon Arm; the default value corresponds to boundary source for the
93 // whole volume of the MUON Arm
95 // Set the default file
96 fFileName="flukasource.root";
99 fTreeChain = new TChain("h1");
103 AliGenFLUKAsource::AliGenFLUKAsource(const AliGenFLUKAsource & FLUKAsource)
109 //____________________________________________________________
110 AliGenFLUKAsource::~AliGenFLUKAsource()
113 if (fTreeFluka) delete fTreeFluka;
114 if (fTreeChain) delete fTreeChain;
117 void AliGenFLUKAsource::AddFile(const Text_t *filename)
119 // Add a file to the chain
120 fTreeChain->Add(filename);
125 //____________________________________________________________
126 void AliGenFLUKAsource::FlukaInit()
128 // Set branch addresses of data entries
129 TChain *h2=fTreeChain;
130 //Set branch addresses
131 h2->SetBranchAddress("Ip",&fIp);
132 h2->SetBranchAddress("Ipp",&fIpp);
133 h2->SetBranchAddress("Xi",&fXi);
134 h2->SetBranchAddress("Yi",&fYi);
135 h2->SetBranchAddress("Zi",&fZi);
136 h2->SetBranchAddress("Px",&fPx);
137 h2->SetBranchAddress("Py",&fPy);
138 h2->SetBranchAddress("Pz",&fPz);
139 h2->SetBranchAddress("Ekin",&fEkin);
140 h2->SetBranchAddress("Zv",&fZv);
141 h2->SetBranchAddress("Rv",&fRv);
142 h2->SetBranchAddress("Itra",&fItra);
143 h2->SetBranchAddress("Igas",&fIgas);
144 h2->SetBranchAddress("Wgt",&fWgt);
145 h2->SetBranchAddress("Etag",&fEtag);
146 h2->SetBranchAddress("Ptg",&fPtg);
147 h2->SetBranchAddress("Age",&fAge);
150 //____________________________________________________________
151 void AliGenFLUKAsource::Generate()
153 // Generate one event
154 AliMC* gMC = AliMC::GetMC();
156 const Int_t kIfluge[28]={kProton, kProtonBar, kElectron, kPositron,
157 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
158 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
159 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
160 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
162 Float_t polar[3]= {0,0,0};
170 Float_t amass, charge, tlife;
173 Int_t i, j, part, nt;
179 TChain *h2=fTreeChain;
180 Int_t nentries = (Int_t) h2->GetEntries();
181 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
183 // loop over number of particles
185 Int_t ev=gMC->CurrentEvent();
186 for (i=0; i<fNpart;i++) {
187 Int_t entry=fNpart*(ev-1)+i;
188 nb = (Int_t)h2->GetEvent(entry);
189 if (irwn > nentries) {
190 printf("No more entries in the FLUKA boundary source file\n");
192 // Get AliRun object or create it
194 gAlice = (AliRun*)pFile->Get("gAlice");
195 if (gAlice) printf("AliRun object found on file\n");
196 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
198 TTree *fAli=gAlice->TreeK();
199 if (fAli) pFile =fAli->GetCurrentFile();
201 printf("Generate - I'm out \n");
205 if (fSourceId != -1 && fIgas !=fSourceId) {
210 if (fIp > 28 || fIp < 0) {
215 if ((fIp != fIkine && fIkine != 6 && fIkine != 9 && fIkine != 10) || fAge > fAgeMax){
218 } else if (fIkine == 9) {
219 if (fIp == 7 || fIp == 8 || fAge > fAgeMax) {
223 } else if (fIkine == 10) {
224 if (fIp == 8 || fAge > fAgeMax) {
233 // PDG code from FLUKA particle type (fIp)
234 part=kIfluge[int(fIp)-1];
236 // Calculate momentum from kinetic energy and mass of the particle
237 gMC->Gfpart(part, name, itrtyp,
238 amass, charge, tlife);
239 prwn=fEkin*sqrt(1. + 2.*amass/fEkin);
250 //handle particle weight correctly
251 wgt = (part == 13) ? fWgt*fAddWeight : fWgt;
253 fwgt=wgt-Float_t(iwgt);
255 if (random[0] < fwgt) iwgt++;
256 if (part==1 && iwgt>100) iwgt=100;
258 for (j=0; j<iwgt; j++) {
259 gAlice->SetTrack(fTrackIt,-1,part,p,origin,polar,fAge,"Primary",nt);
261 phi=2*random[1]*TMath::Pi();
262 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
263 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
266 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
267 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
272 if (nstack == 0) continue;
276 // Get AliRun object or create it
278 gAlice = (AliRun*)pFile->Get("gAlice");
279 if (gAlice) printf("AliRun object found on file\n");
280 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
282 TTree *fAli=gAlice->TreeK();
283 if (fAli) pFile =fAli->GetCurrentFile();
288 AliGenFLUKAsource& AliGenFLUKAsource::operator=(const AliGenFLUKAsource& rhs)
290 // Assignment operator