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