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.15 2001/07/27 17:09:36 morsch
19 Use local SetTrack, KeepTrack and SetHighWaterMark methods
20 to delegate either to local stack or to stack owned by AliRun.
21 (Piotr Skowronski, A.M.)
23 Revision 1.14 2001/03/21 11:28:20 morsch
24 Use enum constants for particle selection.
26 Revision 1.13 2000/12/21 16:24:06 morsch
27 Coding convention clean-up
29 Revision 1.12 2000/11/30 07:12:50 alibrary
30 Introducing new Rndm and QA classes
32 Revision 1.11 2000/06/14 15:20:40 morsch
35 Revision 1.10 2000/06/09 20:31:34 morsch
36 All coding rule violations except RS3 corrected
38 Revision 1.9 2000/03/07 13:52:54 morsch
41 Revision 1.8 2000/02/14 14:49:38 morsch
42 Correct particle type for gamma and neutrons
43 More consistent calculation of momentum from kin. energy and mass
45 Revision 1.7 1999/11/03 17:43:20 fca
46 New version from G.Martinez & A.Morsch
48 Revision 1.6 1999/09/29 09:24:12 fca
49 Introduction of the Copyright and cvs Log
55 // Read background particles from a FLUKA boundary source file
56 // This is a very special generator that works for background studies for the muon-spectrometer.
57 // The input files come from FLUKA simulations.
58 // Files can be chained.
59 // Author: andreas.morsch@cern.ch
61 #include "AliGenFLUKAsource.h"
70 ClassImp(AliGenFLUKAsource)
71 AliGenFLUKAsource::AliGenFLUKAsource()
76 fTitle="FLUKA Boundary Source";
77 // Read in all particle types by default
79 // Set maximum admitted age of particles to 1.e-05 by default
83 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
84 // from specific boundary source to the chamber (fZshift=4.5;),else there
85 // is no need to shift as it reads boundary source for the whole volume of
86 // the Muon Arm; the default value corresponds to boundary source for the
87 // whole volume of the MUON Arm
89 // Set the default file
93 fTreeChain = new TChain("h1");
99 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
104 fTitle = "FLUKA Boundary Source";
105 // Read in all particle types by default
107 // Set maximum admitted age of particles to 1.e-05 by default
111 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
112 // from specific boundary source to the chamber (fZshift=4.5;),else there
113 // is no need to shift as it reads boundary source for the whole volume of
114 // the Muon Arm; the default value corresponds to boundary source for the
115 // whole volume of the MUON Arm
117 // Set the default file
121 fTreeChain = new TChain("h1");
125 AliGenFLUKAsource::AliGenFLUKAsource(const AliGenFLUKAsource & FLUKAsource)
131 //____________________________________________________________
132 AliGenFLUKAsource::~AliGenFLUKAsource()
135 if (fTreeFluka) delete fTreeFluka;
136 if (fTreeChain) delete fTreeChain;
139 void AliGenFLUKAsource::AddFile(const Text_t *filename)
141 // Add a file to the chain
142 fTreeChain->Add(filename);
147 //____________________________________________________________
148 void AliGenFLUKAsource::FlukaInit()
150 // Set branch addresses of data entries
151 TChain *h2=fTreeChain;
152 //Set branch addresses
153 h2->SetBranchAddress("Ip",&fIp);
154 h2->SetBranchAddress("Ipp",&fIpp);
155 h2->SetBranchAddress("Xi",&fXi);
156 h2->SetBranchAddress("Yi",&fYi);
157 h2->SetBranchAddress("Zi",&fZi);
158 h2->SetBranchAddress("Px",&fPx);
159 h2->SetBranchAddress("Py",&fPy);
160 h2->SetBranchAddress("Pz",&fPz);
161 h2->SetBranchAddress("Ekin",&fEkin);
162 h2->SetBranchAddress("Zv",&fZv);
163 h2->SetBranchAddress("Rv",&fRv);
164 h2->SetBranchAddress("Itra",&fItra);
165 h2->SetBranchAddress("Igas",&fIgas);
166 h2->SetBranchAddress("Wgt",&fWgt);
167 h2->SetBranchAddress("Etag",&fEtag);
168 h2->SetBranchAddress("Ptg",&fPtg);
169 h2->SetBranchAddress("Age",&fAge);
172 //____________________________________________________________
173 void AliGenFLUKAsource::Generate()
175 // Generate one event
177 const Int_t kIfluge[28]={kProton, kProtonBar, kElectron, kPositron,
178 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
179 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
180 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
181 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
183 Float_t polar[3]= {0,0,0};
191 Float_t amass, charge, tlife;
194 Int_t i, j, part, nt;
200 TChain *h2=fTreeChain;
201 Int_t nentries = (Int_t) h2->GetEntries();
202 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
205 // loop over number of particles
207 Int_t ev=gMC->CurrentEvent();
208 for (i=0; i<fNpart;i++) {
209 Int_t entry=fNpart*(ev-1)+i;
210 nb = (Int_t)h2->GetEvent(entry);
211 if (irwn > nentries) {
212 printf("No more entries in the FLUKA boundary source file\n");
214 // Get AliRun object or create it
216 gAlice = (AliRun*)pFile->Get("gAlice");
217 if (gAlice) printf("AliRun object found on file\n");
218 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
220 TTree *fAli=gAlice->TreeK();
221 if (fAli) pFile =fAli->GetCurrentFile();
223 printf("Generate - I'm out \n");
227 Int_t ifip = Int_t(fIp);
230 if (fSourceId != -1 && fIgas !=fSourceId) {
235 if (ifip > 28 || ifip < 0) {
240 if ((ifip != fIkine && fIkine != kAll && fIkine != kCharged
241 && fIkine != 10) || fAge > fAgeMax){
244 } else if (fIkine == kCharged) {
245 if (ifip == 7 || ifip == 8 || fAge > fAgeMax) {
249 } else if (fIkine == kNoNeutron) {
250 if (ifip == 8 || fAge > fAgeMax) {
259 // PDG code from FLUKA particle type (ifip)
260 part=kIfluge[int(ifip)-1];
262 // Calculate momentum from kinetic energy and mass of the particle
263 gMC->Gfpart(part, name, itrtyp,
264 amass, charge, tlife);
265 prwn=fEkin*sqrt(1. + 2.*amass/fEkin);
276 //handle particle weight correctly
277 wgt = (part == 13) ? fWgt*fAddWeight : fWgt;
279 fwgt=wgt-Float_t(iwgt);
281 if (random[0] < fwgt) iwgt++;
282 if (part==1 && iwgt>100) iwgt=100;
284 for (j=0; j<iwgt; j++) {
285 SetTrack(fTrackIt,-1,part,p,origin,polar,fAge,kPPrimary,nt);
287 phi=2*random[1]*TMath::Pi();
288 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
289 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
292 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
293 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
298 if (nstack == 0) continue;
302 // Get AliRun object or create it
304 gAlice = (AliRun*)pFile->Get("gAlice");
305 if (gAlice) printf("AliRun object found on file\n");
306 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
308 TTree *fAli=gAlice->TreeK();
309 if (fAli) pFile =fAli->GetCurrentFile();
314 AliGenFLUKAsource& AliGenFLUKAsource::operator=(const AliGenFLUKAsource& rhs)
316 // Assignment operator