1 #include "AliGenFLUKAsource.h"
2 #include "AliGenMUONlib.h"
5 #include <TDirectory.h>
9 ClassImp(AliGenFLUKAsource)
10 AliGenFLUKAsource::AliGenFLUKAsource()
15 fTitle="FLUKA Boundary Source";
16 // Read in all particle types by default
18 // Set maximum admitted age of particles to 1.e-05 by default
22 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
23 // from specific boundary source to the chamber (fZshift=4.5;),else there
24 // is no need to shift as it reads boundary source for the whole volume of
25 // the Muon Arm; the default value corresponds to boundary source for the
26 // whole volume of the MUON Arm
28 // Set the default file
29 fFileName="flukasource.root";
38 AliGenFLUKAsource::AliGenFLUKAsource(Int_t npart)
43 fTitle="FLUKA Boundary Source";
44 // Read in all particle types by default
46 // Set maximum admitted age of particles to 1.e-05 by default
50 // Shift the z-coordinate of the impact point by 4.5 cm only if it reads
51 // from specific boundary source to the chamber (fZshift=4.5;),else there
52 // is no need to shift as it reads boundary source for the whole volume of
53 // the Muon Arm; the default value corresponds to boundary source for the
54 // whole volume of the MUON Arm
56 // Set the default file
57 fFileName="flukasource.root";
63 //____________________________________________________________
64 AliGenFLUKAsource::~AliGenFLUKAsource()
69 //____________________________________________________________
70 void AliGenFLUKAsource::FlukaInit()
73 // reset the existing file environment and open a new root file if
74 // the pointer to the Fluka tree is null
79 File = new TFile(fFileName);
81 cout<<"I have opened "<<fFileName<<" file "<<endl;
83 // get the tree address in the Fluka boundary source file
84 fTreeFluka = (TTree*)gDirectory->Get("h1");
86 File = fTreeFluka->GetCurrentFile();
91 //Set branch addresses
92 h2->SetBranchAddress("Ip",&Ip);
93 h2->SetBranchAddress("Ipp",&Ipp);
94 h2->SetBranchAddress("Xi",&Xi);
95 h2->SetBranchAddress("Yi",&Yi);
96 h2->SetBranchAddress("Zi",&Zi);
97 h2->SetBranchAddress("Px",&Px);
98 h2->SetBranchAddress("Py",&Py);
99 h2->SetBranchAddress("Pz",&Pz);
100 h2->SetBranchAddress("Ekin",&Ekin);
101 h2->SetBranchAddress("Zv",&Zv);
102 h2->SetBranchAddress("Rv",&Rv);
103 h2->SetBranchAddress("Itra",&Itra);
104 h2->SetBranchAddress("Igas",&Igas);
105 h2->SetBranchAddress("Wgt",&Wgt);
106 h2->SetBranchAddress("Etag",&Etag);
107 h2->SetBranchAddress("Ptg",&Ptg);
108 h2->SetBranchAddress("Age",&Age);
111 //____________________________________________________________
112 void AliGenFLUKAsource::Generate()
115 AliMC* pMC = AliMC::GetMC();
117 const Int_t ifluge[28]={14, 15, 3, 2, 4, 4, 1, 13, 25, 5, 6, 10, 8, 9,
118 11, 12,18, 26, 16, 21, 19, 20, 7, 16,16,0,0,0};
119 Float_t polar[3]= {0,0,0};
127 Float_t amass, charge, tlife;
130 Int_t i, j, part, nt;
136 TTree *h2=fTreeFluka;
137 Int_t nentries = (Int_t) h2->GetEntries();
138 if (fNpart == -1) fNpart=Int_t(nentries*fFrac);
140 // loop over number of particles
142 for (i=0; i<fNpart;i++) {
143 Int_t ev=pMC->CurrentEvent();
144 Int_t entry=fNpart*(ev-1)+i;
145 nb = (Int_t)h2->GetEvent(entry);
146 if (irwn > nentries) {
147 printf("No more entries in the FLUKA boundary source file\n");
149 // Get AliRun object or create it
151 gAlice = (AliRun*)File->Get("gAlice");
152 if (gAlice) printf("AliRun object found on file\n");
153 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
155 TTree *fAli=gAlice->TreeK();
156 if (fAli) File =fAli->GetCurrentFile();
158 printf("Generate - I'm out \n");
161 if (Ip > 28 || Ip < 0) {
166 if ((Ip != fIkine && fIkine != 6 && fIkine != 9) || Age > fAgeMax){
169 } else if (fIkine == 9) {
170 if (Ip == 7 || Ip == 8 || Age > fAgeMax) {
178 printf("\n Particle type: %f \n \n ", Ip);
183 } else if (Ip == 8) {
184 prwn=sqrt(Ekin*Ekin + 2.*0.93956563);
187 part=ifluge[int(Ip)-1];
188 pMC->Gfpart(part, name, itrtyp,
189 amass, charge, tlife);
190 prwn=sqrt(Ekin*Ekin + 2.*amass);
200 //handle particle weight correctly
201 wgt = (part == 13) ? Wgt*fAddWeight : Wgt;
203 fwgt=wgt-Float_t(iwgt);
205 if (random[0] < fwgt) iwgt++;
206 if (part==1 && iwgt>100) iwgt=100;
208 for (j=0; j<iwgt; j++) {
209 gAlice->SetTrack(1,-1,part,p,origin,polar,0,"Primary",nt);
211 phi=2*random[1]*TMath::Pi();
212 Float_t pn1=p[0]*TMath::Sin(phi) - p[1]*TMath::Cos(phi);
213 Float_t pn2=p[0]*TMath::Cos(phi) + p[1]*TMath::Sin(phi);
216 Float_t on1=origin[0]*TMath::Sin(phi)-origin[1]*TMath::Cos(phi);
217 Float_t on2=origin[0]*TMath::Cos(phi)+origin[1]*TMath::Sin(phi);
222 if (nstack == 0) continue;
226 // Get AliRun object or create it
228 gAlice = (AliRun*)File->Get("gAlice");
229 if (gAlice) printf("AliRun object found on file\n");
230 if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
232 TTree *fAli=gAlice->TreeK();
233 if (fAli) File =fAli->GetCurrentFile();