]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TFluka/source.cxx
number of DDLs set to 3 for FMD
[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) {
b496f27c 69// Get the pointer to TFluka
2bc4c610 70 TFluka* fluka = (TFluka*)gMC;
b496f27c 71
2bc4c610 72 Int_t verbosityLevel = fluka->GetVerbosityLevel();
73 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
74 if (debug) {
ce60a136 75 cout << "==> source(" << nomore << ")" << endl;
ce60a136 76 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
2bc4c610 77 }
b9d0a01d 78
2bc4c610 79 static Bool_t lfirst = true;
80 static Bool_t particleIsPrimary = true;
81 static Bool_t lastParticleWasPrimary = true;
b9d0a01d 82
ce60a136 83 nomore = 0;
b496f27c 84
85// Get the stack
b9d0a01d 86 TVirtualMCStack* cppstack = fluka->GetStack();
b496f27c 87
ce60a136 88 TParticle* particle;
b9d0a01d 89 Int_t itrack = -1;
ce60a136 90 Int_t nprim = cppstack->GetNprimary();
91// Get the next particle from the stack
92 particle = cppstack->PopNextTrack(itrack);
2bc4c610 93 fluka->SetTrackIsNew(kTRUE);
ce60a136 94
95// Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
96 lastParticleWasPrimary = particleIsPrimary;
97
98 if (itrack >= nprim) {
99 particleIsPrimary = kFALSE;
100 } else {
101 particleIsPrimary = kTRUE;
102 }
103
ce60a136 104 if (lfirst) {
105 EPISOR.tkesum = zerzer;
106 lfirst = false;
107 EPISOR.lussrc = true;
108 } else {
109//
110// Post-track actions for primary track
111//
112 if (particleIsPrimary) {
113 TVirtualMCApplication::Instance()->PostTrack();
114 TVirtualMCApplication::Instance()->FinishPrimary();
b496f27c 115 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
ce60a136 116 }
117 }
b9d0a01d 118
b496f27c 119 // Exit if itrack is negative (-1). Set lsouit to false to mark last track for this event
ce60a136 120
b9d0a01d 121 if (itrack<0) {
122 nomore = 1;
123 EPISOR.lsouit = false;
2bc4c610 124 if (debug) {
125 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
126 cout << "\t* No more particles. Exiting..." << endl;
127 cout << "<== source(" << nomore << ")" << endl;
128 }
b9d0a01d 129 return;
130 }
ce60a136 131
b496f27c 132 //
133 // Handle user event abortion
134 if (fluka->EventIsStopped()) {
135 printf("Event has been stopped by user !");
136 fluka->SetStopEvent(kFALSE);
137 nomore = 1;
138 EPISOR.lsouit = false;
139 return;
140 }
141
b9d0a01d 142 //Get some info about the particle and print it
ce60a136 143 //
144 //pdg code
145 Int_t pdg = particle->GetPdgCode();
b9d0a01d 146 TVector3 polarisation;
147 particle->GetPolarisation(polarisation);
2bc4c610 148 if (debug) {
149 cout << "\t* Particle " << itrack << " retrieved..." << endl;
150 cout << "\t\t+ Name = " << particle->GetName() << endl;
151 cout << "\t\t+ PDG/Fluka code = " << pdg
152 << " / " << fluka->IdFromPDG(pdg) << endl;
153 cout << "\t\t+ P = ("
154 << particle->Px() << " , "
155 << particle->Py() << " , "
156 << particle->Pz() << " ) --> "
157 << particle->P() << " GeV" << endl;
158 }
b9d0a01d 159 /* Lstack is the stack counter: of course any time source is called it
160 * must be =0
161 */
cfd35035 162 /* Cosines (tx,ty,tz)*/
163 Double_t cosx = particle->Px()/particle->P();
164 Double_t cosy = particle->Py()/particle->P();
165 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
166 if (particle->Pz() < 0.) cosz = -cosz;
ce60a136 167
b9d0a01d 168 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
cfd35035 169 if (pdg != 50000050 && pdg != 50000051) {
170 STACK.lstack++;
cfd35035 171 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
172
173 /* Wt is the weight of the particle*/
174 STACK.wt[STACK.lstack] = oneone;
175 STARS.weipri += STACK.wt[STACK.lstack];
176
177 STACK.lo[STACK.lstack] = 1;
178
179 /* User dependent flag:*/
180 STACK.louse[STACK.lstack] = 0;
ce60a136 181
cfd35035 182 /* User dependent spare variables:*/
183 Int_t ispr = 0;
184 for (ispr = 0; ispr < mkbmx1; ispr++)
185 STACK.sparek[STACK.lstack][ispr] = zerzer;
ce60a136 186
cfd35035 187 /* User dependent spare flags:*/
188 for (ispr = 0; ispr < mkbmx2; ispr++)
189 STACK.ispark[STACK.lstack][ispr] = 0;
ce60a136 190
cfd35035 191 /* Save the track number of the stack particle:*/
192 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
193 STACK.nparma++;
194 STACK.numpar[STACK.lstack] = STACK.nparma;
195 STACK.nevent[STACK.lstack] = 0;
196 STACK.dfnear[STACK.lstack] = +zerzer;
e5e3c7b1 197
cfd35035 198 /* Particle age (s)*/
199 STACK.agestk[STACK.lstack] = +zerzer;
e5e3c7b1 200 STACK.cmpath[STACK.lstack] = +zerzer;
cfd35035 201 STACK.aknshr[STACK.lstack] = -twotwo;
ce60a136 202
cfd35035 203 /* Group number for "low" energy neutrons, set to 0 anyway*/
204 STACK.igroup[STACK.lstack] = 0;
205
206 /* Kinetic energy */
ce60a136 207 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
cfd35035 208 /* Particle momentum*/
209 STACK.pmom [STACK.lstack] = particle->P();
b9d0a01d 210
cfd35035 211
212 STACK.tx [STACK.lstack] = cosx;
213 STACK.ty [STACK.lstack] = cosy;
214 STACK.tz [STACK.lstack] = cosz;
b9d0a01d 215
cfd35035 216 /* Polarization cosines:*/
217 if (polarisation.Mag()) {
218 Double_t cospolx = polarisation.Px() / polarisation.Mag();
219 Double_t cospoly = polarisation.Py() / polarisation.Mag();
220 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
221 STACK.txpol [STACK.lstack] = cospolx;
222 STACK.typol [STACK.lstack] = cospoly;
223 STACK.tzpol [STACK.lstack] = cospolz;
224 }
225 else {
226 STACK.txpol [STACK.lstack] = -twotwo;
227 STACK.typol [STACK.lstack] = +zerzer;
228 STACK.tzpol [STACK.lstack] = +zerzer;
229 }
230
231 /* Particle coordinates*/
232 // Vertext coordinates;
233 STACK.xa [STACK.lstack] = particle->Vx();
234 STACK.ya [STACK.lstack] = particle->Vy();
235 STACK.za [STACK.lstack] = particle->Vz();
b9d0a01d 236
cfd35035 237 /* Calculate the total kinetic energy of the primaries: don't change*/
238 Int_t st_ilo = STACK.ilo[STACK.lstack];
239 if ( st_ilo != 0 )
240 EPISOR.tkesum +=
241 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
242 * STACK.wt[STACK.lstack]);
243 else
244 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
245
246 /* Here we ask for the region number of the hitting point.
247 * NREG (LSTACK) = ...
248 * The following line makes the starting region search much more
249 * robust if particles are starting very close to a boundary:
250 */
251 geocrs( STACK.tx[STACK.lstack],
252 STACK.ty[STACK.lstack],
253 STACK.tz[STACK.lstack] );
b9d0a01d 254
cfd35035 255 Int_t idisc;
256
257 georeg ( STACK.xa[STACK.lstack],
258 STACK.ya[STACK.lstack],
259 STACK.za[STACK.lstack],
260 STACK.nreg[STACK.lstack],
261 idisc);//<-- dummy return variable not used
262 /* Do not change these cards:*/
263 Int_t igeohsm1 = 1;
264 Int_t igeohsm2 = -11;
265 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
266 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
267 soevsv();
268 } else {
b496f27c 269 //
cfd35035 270 // Next particle is optical photon
b496f27c 271 //
cfd35035 272 OPPHST.lstopp++;
273 OPPHST.donear [OPPHST.lstopp - 1] = 0.;
274
275 OPPHST.xoptph [OPPHST.lstopp - 1] = particle->Vx();
276 OPPHST.yoptph [OPPHST.lstopp - 1] = particle->Vy();
277 OPPHST.zoptph [OPPHST.lstopp - 1] = particle->Vz();
278
279 OPPHST.txopph [OPPHST.lstopp - 1] = cosx;
280 OPPHST.tyopph [OPPHST.lstopp - 1] = cosy;
281 OPPHST.tzopph [OPPHST.lstopp - 1] = cosz;
282
283
284 if (polarisation.Mag()) {
285 Double_t cospolx = polarisation.Px() / polarisation.Mag();
286 Double_t cospoly = polarisation.Py() / polarisation.Mag();
287 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
288 OPPHST.txpopp [OPPHST.lstopp - 1] = cospolx;
289 OPPHST.typopp [OPPHST.lstopp - 1] = cospoly;
290 OPPHST.tzpopp [OPPHST.lstopp - 1] = cospolz;
291 }
292 else {
293 OPPHST.txpopp [OPPHST.lstopp - 1] = -twotwo;
294 OPPHST.typopp [OPPHST.lstopp - 1] = +zerzer;
295 OPPHST.tzpopp [OPPHST.lstopp - 1] = +zerzer;
296 }
297
298 geocrs( OPPHST.txopph[OPPHST.lstopp - 1],
299 OPPHST.tyopph[OPPHST.lstopp - 1],
300 OPPHST.tzopph[OPPHST.lstopp - 1] );
ce60a136 301
cfd35035 302 Int_t idisc;
303
304 georeg ( OPPHST.xoptph[OPPHST.lstopp - 1],
305 OPPHST.yoptph[OPPHST.lstopp - 1],
306 OPPHST.zoptph[OPPHST.lstopp - 1],
307 OPPHST.nregop[OPPHST.lstopp - 1],
308 idisc);//<-- dummy return variable not used
309
310 OPPHST.wtopph [OPPHST.lstopp - 1] = particle->GetWeight();
311 OPPHST.poptph [OPPHST.lstopp - 1] = particle->P();
312 OPPHST.agopph [OPPHST.lstopp - 1] = particle->T();
e5e3c7b1 313 OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer;
cfd35035 314 OPPHST.loopph [OPPHST.lstopp - 1] = 0;
cfd35035 315 OPPHST.louopp [OPPHST.lstopp - 1] = itrack;
cfd35035 316 }
317
ce60a136 318//
319// Pre-track actions at for primary tracks
320//
321 if (particleIsPrimary) {
322 TVirtualMCApplication::Instance()->BeginPrimary();
323 TVirtualMCApplication::Instance()->PreTrack();
324 }
325
326//
2bc4c610 327 if (debug) cout << "<== source(" << nomore << ")" << endl;
b9d0a01d 328 }
329}