]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TFluka/source.cxx
Dynamic storage of user configuration parameters.
[u/mrichter/AliRoot.git] / TFluka / source.cxx
CommitLineData
b9d0a01d 1// Fortran
2#include "TCallf77.h"
3
4// Fluka commons
5#include "Fdblprc.h" //(DBLPRC) fluka common
6#include "Fdimpar.h" //(DIMPAR) fluka parameters
7#include "Fepisor.h" //(EPISOR) fluka common
8#include "Fstack.h" //(STACK) fluka common
9#include "Fstars.h" //(STARS) fluka common
10#include "Fbeam.h" //(BEAM) fluka common
11#include "Fpaprop.h" //(PAPROP) fluka common
12#include "Fltclcm.h" //(LTCLCM) fluka common
cfd35035 13#include "Fopphst.h" //(OPPHST) fluka common
b9d0a01d 14//#include "Fcaslim.h" //(CASLIM) fluka common
15
16//Virutal MC
17#include "TFluka.h"
a7bb59a2 18
b9d0a01d 19#include "TVirtualMCStack.h"
fbf08100 20//#include "TVirtualMCApplication.h"
fbf08100 21
b9d0a01d 22#include "TParticle.h"
23#include "TVector3.h"
24
25//Other
eae0fe66 26#include <Riostream.h>
b9d0a01d 27
28#ifndef WIN32
29# define source source_
30# define geocrs geocrs_
31# define georeg georeg_
32# define geohsm geohsm_
33# define soevsv soevsv_
34#else
35# define source SOURCE
36# define geocrs GEOCRS
37# define georeg GEOREG
38# define geohsm GEOHSM
39# define soevsv SOEVSV
40#endif
41
b9d0a01d 42extern "C" {
43 //
44 // Prototypes for FLUKA functions
45 //
46 void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
47 void type_of_call georeg(Double_t &, Double_t &, Double_t &,
48 Int_t &, Int_t &);
49 void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
50 void type_of_call soevsv();
51 /*
52 *----------------------------------------------------------------------*
53 * *
54 * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala *
55 * Infn - Milan *
56 * *
57 * Last change on 21-jun-98 by Alfredo Ferrari *
58 * *
59 * C++ version on 27-sep-02 by Isidro Gonzalez *
60 * *
61 * This is just an example of a possible user written source routine. *
62 * note that the beam card still has some meaning - in the scoring the *
63 * maximum momentum used in deciding the binning is taken from the *
64 * beam momentum. Other beam card parameters are obsolete. *
65 * *
66 *----------------------------------------------------------------------*/
67
68 void source(Int_t& nomore) {
2bc4c610 69 // Get the pointer to TFluka
70 TFluka* fluka = (TFluka*)gMC;
71 Int_t verbosityLevel = fluka->GetVerbosityLevel();
72 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
73 if (debug) {
ce60a136 74 cout << "==> source(" << nomore << ")" << endl;
ce60a136 75 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
2bc4c610 76 }
b9d0a01d 77
2bc4c610 78 static Bool_t lfirst = true;
79 static Bool_t particleIsPrimary = true;
80 static Bool_t lastParticleWasPrimary = true;
ce60a136 81
82 /* +-------------------------------------------------------------------*
83 * First call initializations for FLUKA: */
b9d0a01d 84
b9d0a01d 85
ce60a136 86 nomore = 0;
ce60a136 87 // Get the stack
b9d0a01d 88 TVirtualMCStack* cppstack = fluka->GetStack();
ce60a136 89 TParticle* particle;
b9d0a01d 90 Int_t itrack = -1;
ce60a136 91 Int_t nprim = cppstack->GetNprimary();
92// Get the next particle from the stack
93 particle = cppstack->PopNextTrack(itrack);
2bc4c610 94 fluka->SetTrackIsNew(kTRUE);
ce60a136 95
96// Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
97 lastParticleWasPrimary = particleIsPrimary;
98
99 if (itrack >= nprim) {
100 particleIsPrimary = kFALSE;
101 } else {
102 particleIsPrimary = kTRUE;
103 }
104
105// printf("--->Got Particle %d %d %d\n", itrack, particleIsPrimary, lastParticleWasPrimary);
106
107 if (lfirst) {
108 EPISOR.tkesum = zerzer;
109 lfirst = false;
110 EPISOR.lussrc = true;
111 } else {
112//
113// Post-track actions for primary track
114//
115 if (particleIsPrimary) {
116 TVirtualMCApplication::Instance()->PostTrack();
117 TVirtualMCApplication::Instance()->FinishPrimary();
4d286778 118 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
ce60a136 119 }
120 }
b9d0a01d 121
122 //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
123 //this event
ce60a136 124
b9d0a01d 125 if (itrack<0) {
126 nomore = 1;
127 EPISOR.lsouit = false;
2bc4c610 128 if (debug) {
129 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
130 cout << "\t* No more particles. Exiting..." << endl;
131 cout << "<== source(" << nomore << ")" << endl;
132 }
b9d0a01d 133 return;
134 }
ce60a136 135
b9d0a01d 136 //Get some info about the particle and print it
ce60a136 137 //
138 //pdg code
139 Int_t pdg = particle->GetPdgCode();
140
b9d0a01d 141 TVector3 polarisation;
142 particle->GetPolarisation(polarisation);
2bc4c610 143 if (debug) {
144 cout << "\t* Particle " << itrack << " retrieved..." << endl;
145 cout << "\t\t+ Name = " << particle->GetName() << endl;
146 cout << "\t\t+ PDG/Fluka code = " << pdg
147 << " / " << fluka->IdFromPDG(pdg) << endl;
148 cout << "\t\t+ P = ("
149 << particle->Px() << " , "
150 << particle->Py() << " , "
151 << particle->Pz() << " ) --> "
152 << particle->P() << " GeV" << endl;
153 }
b9d0a01d 154 /* Lstack is the stack counter: of course any time source is called it
155 * must be =0
156 */
cfd35035 157 /* Cosines (tx,ty,tz)*/
158 Double_t cosx = particle->Px()/particle->P();
159 Double_t cosy = particle->Py()/particle->P();
160 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
161 if (particle->Pz() < 0.) cosz = -cosz;
ce60a136 162
b9d0a01d 163 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
cfd35035 164 if (pdg != 50000050 && pdg != 50000051) {
165 STACK.lstack++;
ce60a136 166
cfd35035 167 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
168
169 /* Wt is the weight of the particle*/
170 STACK.wt[STACK.lstack] = oneone;
171 STARS.weipri += STACK.wt[STACK.lstack];
172
173 STACK.lo[STACK.lstack] = 1;
174
175 /* User dependent flag:*/
176 STACK.louse[STACK.lstack] = 0;
ce60a136 177
cfd35035 178 /* User dependent spare variables:*/
179 Int_t ispr = 0;
180 for (ispr = 0; ispr < mkbmx1; ispr++)
181 STACK.sparek[STACK.lstack][ispr] = zerzer;
ce60a136 182
cfd35035 183 /* User dependent spare flags:*/
184 for (ispr = 0; ispr < mkbmx2; ispr++)
185 STACK.ispark[STACK.lstack][ispr] = 0;
ce60a136 186
cfd35035 187 /* Save the track number of the stack particle:*/
188 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
189 STACK.nparma++;
190 STACK.numpar[STACK.lstack] = STACK.nparma;
191 STACK.nevent[STACK.lstack] = 0;
192 STACK.dfnear[STACK.lstack] = +zerzer;
e5e3c7b1 193
cfd35035 194 /* Particle age (s)*/
195 STACK.agestk[STACK.lstack] = +zerzer;
e5e3c7b1 196 STACK.cmpath[STACK.lstack] = +zerzer;
cfd35035 197 STACK.aknshr[STACK.lstack] = -twotwo;
ce60a136 198
cfd35035 199 /* Group number for "low" energy neutrons, set to 0 anyway*/
200 STACK.igroup[STACK.lstack] = 0;
201
202 /* Kinetic energy */
ce60a136 203 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
cfd35035 204 /* Particle momentum*/
205 STACK.pmom [STACK.lstack] = particle->P();
b9d0a01d 206
cfd35035 207
208 STACK.tx [STACK.lstack] = cosx;
209 STACK.ty [STACK.lstack] = cosy;
210 STACK.tz [STACK.lstack] = cosz;
b9d0a01d 211
cfd35035 212 /* Polarization cosines:*/
213 if (polarisation.Mag()) {
214 Double_t cospolx = polarisation.Px() / polarisation.Mag();
215 Double_t cospoly = polarisation.Py() / polarisation.Mag();
216 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
217 STACK.txpol [STACK.lstack] = cospolx;
218 STACK.typol [STACK.lstack] = cospoly;
219 STACK.tzpol [STACK.lstack] = cospolz;
220 }
221 else {
222 STACK.txpol [STACK.lstack] = -twotwo;
223 STACK.typol [STACK.lstack] = +zerzer;
224 STACK.tzpol [STACK.lstack] = +zerzer;
225 }
226
227 /* Particle coordinates*/
228 // Vertext coordinates;
229 STACK.xa [STACK.lstack] = particle->Vx();
230 STACK.ya [STACK.lstack] = particle->Vy();
231 STACK.za [STACK.lstack] = particle->Vz();
b9d0a01d 232
cfd35035 233 /* Calculate the total kinetic energy of the primaries: don't change*/
234 Int_t st_ilo = STACK.ilo[STACK.lstack];
235 if ( st_ilo != 0 )
236 EPISOR.tkesum +=
237 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
238 * STACK.wt[STACK.lstack]);
239 else
240 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
241
242 /* Here we ask for the region number of the hitting point.
243 * NREG (LSTACK) = ...
244 * The following line makes the starting region search much more
245 * robust if particles are starting very close to a boundary:
246 */
247 geocrs( STACK.tx[STACK.lstack],
248 STACK.ty[STACK.lstack],
249 STACK.tz[STACK.lstack] );
b9d0a01d 250
cfd35035 251 Int_t idisc;
252
253 georeg ( STACK.xa[STACK.lstack],
254 STACK.ya[STACK.lstack],
255 STACK.za[STACK.lstack],
256 STACK.nreg[STACK.lstack],
257 idisc);//<-- dummy return variable not used
258 /* Do not change these cards:*/
259 Int_t igeohsm1 = 1;
260 Int_t igeohsm2 = -11;
261 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
262 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
263 soevsv();
264 } else {
265 // Next particle is optical photon
266 OPPHST.lstopp++;
267 OPPHST.donear [OPPHST.lstopp - 1] = 0.;
268
269 OPPHST.xoptph [OPPHST.lstopp - 1] = particle->Vx();
270 OPPHST.yoptph [OPPHST.lstopp - 1] = particle->Vy();
271 OPPHST.zoptph [OPPHST.lstopp - 1] = particle->Vz();
272
273 OPPHST.txopph [OPPHST.lstopp - 1] = cosx;
274 OPPHST.tyopph [OPPHST.lstopp - 1] = cosy;
275 OPPHST.tzopph [OPPHST.lstopp - 1] = cosz;
276
277
278 if (polarisation.Mag()) {
279 Double_t cospolx = polarisation.Px() / polarisation.Mag();
280 Double_t cospoly = polarisation.Py() / polarisation.Mag();
281 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
282 OPPHST.txpopp [OPPHST.lstopp - 1] = cospolx;
283 OPPHST.typopp [OPPHST.lstopp - 1] = cospoly;
284 OPPHST.tzpopp [OPPHST.lstopp - 1] = cospolz;
285 }
286 else {
287 OPPHST.txpopp [OPPHST.lstopp - 1] = -twotwo;
288 OPPHST.typopp [OPPHST.lstopp - 1] = +zerzer;
289 OPPHST.tzpopp [OPPHST.lstopp - 1] = +zerzer;
290 }
291
292 geocrs( OPPHST.txopph[OPPHST.lstopp - 1],
293 OPPHST.tyopph[OPPHST.lstopp - 1],
294 OPPHST.tzopph[OPPHST.lstopp - 1] );
ce60a136 295
cfd35035 296 Int_t idisc;
297
298 georeg ( OPPHST.xoptph[OPPHST.lstopp - 1],
299 OPPHST.yoptph[OPPHST.lstopp - 1],
300 OPPHST.zoptph[OPPHST.lstopp - 1],
301 OPPHST.nregop[OPPHST.lstopp - 1],
302 idisc);//<-- dummy return variable not used
303
304 OPPHST.wtopph [OPPHST.lstopp - 1] = particle->GetWeight();
305 OPPHST.poptph [OPPHST.lstopp - 1] = particle->P();
306 OPPHST.agopph [OPPHST.lstopp - 1] = particle->T();
e5e3c7b1 307 OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer;
cfd35035 308 OPPHST.loopph [OPPHST.lstopp - 1] = 0;
309// Int_t mother = particle->GetFirstMother();
310 OPPHST.louopp [OPPHST.lstopp - 1] = itrack;
311/*
312 if (mother > -1) {
313 TParticle* mparticle = cppstack->Particle(mother);
314 OPPHST.apropp [OPPHST.lstopp - 1] = mparticle->T();
315 Int_t mpdg = mparticle->GetPdgCode();
316 if (mpdg == 50000050 || mpdg 50000051) {
317 OPPHST.ipropp [OPPHST.lstopp - 1] = -1;
318 OPPHST.tpropp [OPPHST.lstopp - 1] = mparticle->Energy();
319 } else {
320 OPPHST.ipropp [OPPHST.lstopp - 1] = mpdg;
321 OPPHST.tpropp [OPPHST.lstopp - 1] = mparticle->Energy() - mparticle->GetMass();
322 }
ce60a136 323
cfd35035 324 }
325*/
326 }
327
ce60a136 328//
329// Pre-track actions at for primary tracks
330//
331 if (particleIsPrimary) {
332 TVirtualMCApplication::Instance()->BeginPrimary();
333 TVirtualMCApplication::Instance()->PreTrack();
334 }
335
336//
2bc4c610 337 if (debug) cout << "<== source(" << nomore << ")" << endl;
b9d0a01d 338 }
339}