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.16 2002/11/21 16:22:35 alibrary
19 Removing AliMCProcess and AliMC
21 Revision 1.15 2001/07/27 17:09:36 morsch
22 Use local SetTrack, KeepTrack and SetHighWaterMark methods
23 to delegate either to local stack or to stack owned by AliRun.
24 (Piotr Skowronski, A.M.)
26 Revision 1.14 2001/03/21 11:28:20 morsch
27 Use enum constants for particle selection.
29 Revision 1.13 2000/12/21 16:24:06 morsch
30 Coding convention clean-up
32 Revision 1.12 2000/11/30 07:12:50 alibrary
33 Introducing new Rndm and QA classes
35 Revision 1.11 2000/06/14 15:20:40 morsch
38 Revision 1.10 2000/06/09 20:31:34 morsch
39 All coding rule violations except RS3 corrected
41 Revision 1.9 2000/03/07 13:52:54 morsch
44 Revision 1.8 2000/02/14 14:49:38 morsch
45 Correct particle type for gamma and neutrons
46 More consistent calculation of momentum from kin. energy and mass
48 Revision 1.7 1999/11/03 17:43:20 fca
49 New version from G.Martinez & A.Morsch
51 Revision 1.6 1999/09/29 09:24:12 fca
52 Introduction of the Copyright and cvs Log
58 // Read background particles from a FLUKA boundary source file
59 // This is a very special generator that works for background studies for the muon-spectrometer.
60 // The input files come from FLUKA simulations.
61 // Files can be chained.
62 // Author: andreas.morsch@cern.ch
66 #include "AliGenFLUKAsource.h"
74 ClassImp(AliGenFLUKAsource)
75 AliGenFLUKAsource::AliGenFLUKAsource()
80 fTitle="FLUKA Boundary Source";
81 // Read in all particle types by default
83 // Set maximum admitted age of particles to 1.e-05 by default
87 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
88 // from specific boundary source to the chamber (fZshift=4.5;),else there
89 // is no need to shift as it reads boundary source for the whole volume of
90 // the Muon Arm; the default value corresponds to boundary source for the
91 // whole volume of the MUON Arm
93 // Set the default file
97 fTreeChain = new TChain("h1");
103 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
108 fTitle = "FLUKA Boundary Source";
109 // Read in all particle types by default
111 // Set maximum admitted age of particles to 1.e-05 by default
115 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
116 // from specific boundary source to the chamber (fZshift=4.5;),else there
117 // is no need to shift as it reads boundary source for the whole volume of
118 // the Muon Arm; the default value corresponds to boundary source for the
119 // whole volume of the MUON Arm
121 // Set the default file
125 fTreeChain = new TChain("h1");
129 AliGenFLUKAsource::AliGenFLUKAsource(const AliGenFLUKAsource & FLUKAsource)
135 //____________________________________________________________
136 AliGenFLUKAsource::~AliGenFLUKAsource()
139 if (fTreeFluka) delete fTreeFluka;
140 if (fTreeChain) delete fTreeChain;
143 void AliGenFLUKAsource::AddFile(const Text_t *filename)
145 // Add a file to the chain
146 fTreeChain->Add(filename);
151 //____________________________________________________________
152 void AliGenFLUKAsource::FlukaInit()
154 // Set branch addresses of data entries
155 TChain *h2=fTreeChain;
156 //Set branch addresses
157 h2->SetBranchAddress("Ip",&fIp);
158 h2->SetBranchAddress("Ipp",&fIpp);
159 h2->SetBranchAddress("Xi",&fXi);
160 h2->SetBranchAddress("Yi",&fYi);
161 h2->SetBranchAddress("Zi",&fZi);
162 h2->SetBranchAddress("Px",&fPx);
163 h2->SetBranchAddress("Py",&fPy);
164 h2->SetBranchAddress("Pz",&fPz);
165 h2->SetBranchAddress("Ekin",&fEkin);
166 h2->SetBranchAddress("Zv",&fZv);
167 h2->SetBranchAddress("Rv",&fRv);
168 h2->SetBranchAddress("Itra",&fItra);
169 h2->SetBranchAddress("Igas",&fIgas);
170 h2->SetBranchAddress("Wgt",&fWgt);
171 h2->SetBranchAddress("Etag",&fEtag);
172 h2->SetBranchAddress("Ptg",&fPtg);
173 h2->SetBranchAddress("Age",&fAge);
176 //____________________________________________________________
177 void AliGenFLUKAsource::Generate()
179 // Generate one event
181 const Int_t kIfluge[28]={kProton, kProtonBar, kElectron, kPositron,
182 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
183 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
184 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
185 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
187 Float_t polar[3]= {0,0,0};
195 Float_t amass, charge, tlife;
198 Int_t i, j, part, nt;
204 TChain *h2=fTreeChain;
205 Int_t nentries = (Int_t) h2->GetEntries();
206 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
209 // loop over number of particles
211 Int_t ev=gMC->CurrentEvent();
212 for (i=0; i<fNpart;i++) {
213 Int_t entry=fNpart*(ev-1)+i;
214 nb = (Int_t)h2->GetEvent(entry);
215 if (irwn > nentries) {
216 printf("No more entries in the FLUKA boundary source file\n");
218 // Get AliRun object or create it
220 gAlice = (AliRun*)pFile->Get("gAlice");
221 if (gAlice) printf("AliRun object found on file\n");
222 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
224 TTree *fAli=gAlice->TreeK();
225 if (fAli) pFile =fAli->GetCurrentFile();
227 printf("Generate - I'm out \n");
231 Int_t ifip = Int_t(fIp);
234 if (fSourceId != -1 && fIgas !=fSourceId) {
239 if (ifip > 28 || ifip < 0) {
244 if ((ifip != fIkine && fIkine != kAll && fIkine != kCharged
245 && fIkine != 10) || fAge > fAgeMax){
248 } else if (fIkine == kCharged) {
249 if (ifip == 7 || ifip == 8 || fAge > fAgeMax) {
253 } else if (fIkine == kNoNeutron) {
254 if (ifip == 8 || fAge > fAgeMax) {
263 // PDG code from FLUKA particle type (ifip)
264 part=kIfluge[int(ifip)-1];
266 // Calculate momentum from kinetic energy and mass of the particle
267 gMC->Gfpart(part, name, itrtyp,
268 amass, charge, tlife);
269 prwn=fEkin*sqrt(1. + 2.*amass/fEkin);
280 //handle particle weight correctly
281 wgt = (part == 13) ? fWgt*fAddWeight : fWgt;
283 fwgt=wgt-Float_t(iwgt);
285 if (random[0] < fwgt) iwgt++;
286 if (part==1 && iwgt>100) iwgt=100;
288 for (j=0; j<iwgt; j++) {
289 SetTrack(fTrackIt,-1,part,p,origin,polar,fAge,kPPrimary,nt);
291 phi=2*random[1]*TMath::Pi();
292 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
293 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
296 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
297 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
302 if (nstack == 0) continue;
306 // Get AliRun object or create it
308 gAlice = (AliRun*)pFile->Get("gAlice");
309 if (gAlice) printf("AliRun object found on file\n");
310 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
312 TTree *fAli=gAlice->TreeK();
313 if (fAli) pFile =fAli->GetCurrentFile();
318 AliGenFLUKAsource& AliGenFLUKAsource::operator=(const AliGenFLUKAsource& rhs)
320 // Assignment operator