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