Update GetSecondary arguments
[u/mrichter/AliRoot.git] / TGeant3 / gucode.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 */
19
20 #include "AliCallf77.h"
21 #include "TGeant3.h"
22 #include "AliRun.h"
23
24 #ifndef WIN32
25 #  define gudigi gudigi_
26 #  define guhadr guhadr_
27 #  define guout  guout_
28 #  define guphad guphad_
29 #  define gudcay gudcay_
30 #  define guiget guiget_
31 #  define guinme guinme_
32 #  define guinti guinti_
33 #  define gunear gunear_
34 #  define guskip guskip_
35 #  define guview guview_
36 #  define gupara gupara_
37 #  define gudtim gudtim_
38 #  define guplsh guplsh_
39 #  define gutrev gutrev_
40 #  define gutrak gutrak_
41 #  define guswim guswim_
42 #  define gufld  gufld_
43 #  define gustep gustep_
44 #  define gukine gukine_
45 #  define uglast uglast_
46
47 #  define gheish gheish_
48 #  define flufin flufin_
49 #  define gfmfin gfmfin_
50 #  define gpghei gpghei_
51 #  define fldist fldist_
52 #  define gfmdis gfmdis_
53 #  define ghelx3 ghelx3_
54 #  define ghelix ghelix_
55 #  define grkuta grkuta_
56 #  define gtrack gtrack_
57 #  define gtreve_root gtreve_root_
58 #  define glast  glast_
59
60 #else
61 #  define gudigi GUDIGI
62 #  define guhadr GUHADR
63 #  define guout  GUOUT
64 #  define guphad GUPHAD
65 #  define gudcay GUDCAY
66 #  define guiget GUIGET
67 #  define guinme GUINME
68 #  define guinti GUINTI
69 #  define gunear GUNEAR
70 #  define guskip GUSKIP
71 #  define guview GUVIEW
72 #  define gupara GUPARA
73 #  define gudtim GUDTIM
74 #  define guplsh GUPLSH
75 #  define gutrev GUTREV
76 #  define gutrak GUTRAK
77 #  define guswim GUSWIM
78 #  define gufld  GUFLD
79 #  define gustep GUSTEP
80 #  define gukine GUKINE
81 #  define uglast UGLAST
82
83 #  define gheish GHEISH
84 #  define flufin FLUFIN
85 #  define gfmfin GFMFIN
86 #  define gpghei GPGHEI
87 #  define fldist FLDIST
88 #  define gfmdis GFMDIS
89 #  define ghelx3 GHELX3
90 #  define ghelix GHELIX
91 #  define grkuta GRKUTA
92 #  define gtrack GTRACK
93 #  define gtreve_root GTREVE_ROOT
94 #  define glast  GLAST
95
96 #endif
97
98 extern "C" type_of_call void gheish();
99 extern "C" type_of_call void flufin();
100 extern "C" type_of_call void gfmfin();
101 extern "C" type_of_call void gpghei();
102 extern "C" type_of_call void fldist();
103 extern "C" type_of_call void gfmdis();
104 extern "C" type_of_call void ghelx3(Float_t&, Float_t&, Float_t*, Float_t*);
105 extern "C" type_of_call void ghelix(Float_t&, Float_t&, Float_t*, Float_t*);
106 extern "C" type_of_call void grkuta(Float_t&, Float_t&, Float_t*, Float_t*);
107 extern "C" type_of_call void gtrack();
108 extern "C" type_of_call void gtreve_root();
109 extern "C" type_of_call void glast();
110
111 extern "C" type_of_call {
112
113 //______________________________________________________________________
114 void gudigi() 
115 {
116 //
117 //    ******************************************************************
118 //    *                                                                *
119 //    *       User routine to digitize one event                       *
120 //    *                                                                *
121 //    *    ==>Called by : GTRIG                                        *
122 //    *                                                                *
123 //    ******************************************************************
124
125 }
126
127
128 //______________________________________________________________________
129 void guhadr()
130 {
131 //
132 //    ******************************************************************
133 //    *                                                                *
134 //    *       User routine to generate one hadronic interaction        *
135 //    *                                                                *
136 //    *    ==>Called by : GTHADR,GTNEUT                                *
137 //    *                                                                *
138 //    ******************************************************************
139 //
140 //
141 //    ------------------------------------------------------------------
142 //
143       TGeant3* geant3 = (TGeant3*) gMC;
144       Int_t ihadr=geant3->Gcphys()->ihadr;
145       if (ihadr<4)       gheish();
146       else if (ihadr==4) flufin();
147       else               gfmfin();
148 }
149
150 //______________________________________________________________________
151 void guout()
152 {
153 //
154 //    ******************************************************************
155 //    *                                                                *
156 //    *       User routine called at the end of each event             *
157 //    *                                                                *
158 //    *    ==>Called by : GTRIG                                        *
159 //    *                                                                *
160 //    ******************************************************************
161 //
162 //
163 //    ------------------------------------------------------------------
164 //
165 }
166
167 //______________________________________________________________________
168 void guphad()
169 {
170 //
171 //    ******************************************************************
172 //    *                                                                *
173 //    *       User routine to compute Hadron. inter. probabilities     *
174 //    *                                                                *
175 //    *    ==>Called by : GTHADR,GTNEUT                                *
176 //    *                                                                *
177 //    ******************************************************************
178 //
179 //
180 //    ------------------------------------------------------------------
181 //
182       TGeant3* geant3 = (TGeant3*) gMC;
183       Int_t ihadr=geant3->Gcphys()->ihadr;
184       if (ihadr<4)       gpghei();
185       else if (ihadr==4) fldist();
186       else               gfmdis();
187 }
188
189 //______________________________________________________________________
190 void gudcay()
191 {
192 //
193 //    ******************************************************************
194 //    *                                                                *
195 //    *       User routine to decay particles                          *
196 //    *                                                                *
197 //    *    ==>Called by : GDECAY                                       *
198 //    *                                                                *
199 //    ******************************************************************
200 //
201 //
202 //    ------------------------------------------------------------------
203 //
204 }
205
206 //______________________________________________________________________
207 void guiget(Int_t&, Int_t&, Int_t&)
208 {
209 //
210 //    ******************************************************************
211 //    *                                                                *
212 //    *       User routine for interactive control of GEANT            *
213 //    *                                                                *
214 //    *    ==>Called by : <GXINT>, GINCOM                              *
215 //    *                                                                *
216 //    ******************************************************************
217 //
218 //
219 //    ------------------------------------------------------------------
220 //
221 }
222
223 //______________________________________________________________________
224 void guinme(Float_t*, Int_t&, Float_t*, Int_t& IYES)
225 {
226 //
227 //    **********************************************
228 //    *                                            *
229 //    *    USER ROUTINE TO PROVIDE GINME FUNCTION  *
230 //    *    FOR ALL USER SHAPES IDENTIFIED BY THE   *
231 //    *    SHAPE NUMBER SH. POINT IS GIVEN IN X    *
232 //    *    THE PARAMETERS ARE GIVEN IN P. IYES IS  *
233 //    *    RETURNED 1 IF POINT IS IN, 0 IF POINT   *
234 //    *    IS OUT AND LESS THAN ZERO IF SHAPE      *
235 //    *    NUMBER IS NOT SUPPORTED.                *
236 //    *                                            *
237 //    *    ==>Called by : GINME                    *
238 //    *                                            *
239 //    **********************************************
240 //
241       IYES=-1;
242 }
243
244 //______________________________________________________________________
245 void guinti()
246 {
247 //
248 //    ******************************************************************
249 //    *                                                                *
250 //    *       User routine for interactive version                     *
251 //    *                                                                *
252 //    *    ==>Called by : <GXINT>,  GINTRI                             *
253 //    *                                                                *
254 //    ******************************************************************
255 //
256 //
257 //    ------------------------------------------------------------------
258 //
259 }
260
261 //______________________________________________________________________
262 void gunear(Int_t&, Int_t&, Float_t*, Int_t&)
263 {
264 //
265 //    ******************************************************************
266 //    *                                                                *
267 //    *    User search                                                 *
268 //    *       ISEARC to identify the given volume                      *
269 //    *       ICALL  to identify the calling routine                   *
270 //    *              1 GMEDIA like                                     *
271 //    *              2 GNEXT like                                      *
272 //    *       X      coordinates (+direction for ICALL=2)              *
273 //    *       JNEAR  address of default list of neighbours             *
274 //    *              (list to be overwriten by user)                   *
275 //    *                                                                *
276 //    *    Called by : GFTRAC, GINVOL, GTMEDI, GTNEXT, GNEXT, GMEDIA   *
277 //    *                                                                *
278 //    ******************************************************************
279 //
280 //
281 //    ------------------------------------------------------------------
282 //
283 }
284
285 //______________________________________________________________________
286 void guskip(Int_t& ISKIP)
287 {
288 //
289 //    ******************************************************************
290 //    *                                                                *
291 //    *   User routine to skip unwanted tracks                         *
292 //    *                                                                *
293 //    *   Called by : GSSTAK                                           *
294 //    *   Author    : F.Bruyant                                        *
295 //    *                                                                *
296 //    ******************************************************************
297 //
298 //
299 //    ------------------------------------------------------------------
300 //
301       ISKIP = 0;
302 }
303
304 //______________________________________________________________________
305 void guswim(Float_t& CHARGE, Float_t& STEP, Float_t* VECT, Float_t* VOUT)
306 {
307 //
308 //    ******************************************************************
309 //    *                                                                *
310 //    *       User routine to control tracking of one track            *
311 //    *       in a magnetic field                                      *
312 //    *                                                                *
313 //    *    ==>Called by : GTELEC,GTHADR,GTMUON                         *
314 //    *                                                                *
315 //    ******************************************************************
316 //
317 //
318 //    ------------------------------------------------------------------
319 //
320   TGeant3* geant3 = (TGeant3*) gMC;
321   Int_t ifield=geant3->Gctmed()->ifield;
322   Float_t fieldm=geant3->Gctmed()->fieldm;
323
324   if (ifield==3) {
325     Float_t fldcharge = fieldm*CHARGE;
326     ghelx3(fldcharge,STEP,VECT,VOUT);
327   }
328   else if (ifield==2) ghelix(CHARGE,STEP,VECT,VOUT);
329   else                grkuta(CHARGE,STEP,VECT,VOUT);
330 }
331
332 //______________________________________________________________________
333 void guview(Int_t&, Int_t&, DEFCHARD, Int_t& DEFCHARL)
334 {
335 //
336 //    ******************************************************************
337 //    *                                                                *
338 //    *       User routine for interactive version                     *
339 //    *                                                                *
340 //    *    ==>Called by : <GXINT>, GINC1                               *
341 //    *                                                                *
342 //    ******************************************************************
343 //
344 //
345 //    ------------------------------------------------------------------
346 //
347 }
348
349 //______________________________________________________________________
350 void gupara()
351 {
352 //
353 //    ******************************************************************
354 //    *                                                                *
355 //    *       User routine called every time a particle falls below    *
356 //    *       parametrization threshold. This routine should create    *
357 //    *       the parametrization stack, and, when this is full,       *
358 //    *       parametrize the shower and track the geantinos.          *
359 //    *                                                                *
360 //    *    ==>Called by : GTRACK                                       *
361 //    *                                                                *
362 //    ******************************************************************
363 //
364 //
365 //    ------------------------------------------------------------------
366 //
367 }
368
369 //______________________________________________________________________
370 Float_t gudtim(Float_t&, Float_t&, Int_t&, Int_t&)
371 {
372 //
373 //    ******************************************************************
374 //    *                                                                *
375 //    *       User function called by GCDRIF to return drift time      *
376 //    *                                                                *
377 //    *    ==>Called by : GCDRIF                                       *
378 //    *                                                                *
379 //    ******************************************************************
380 //
381 //
382 //    ------------------------------------------------------------------
383 //
384       return 0;
385 }
386
387
388 //______________________________________________________________________
389 Float_t guplsh(Int_t&, Int_t&)
390 {
391 //
392 //    ******************************************************************
393 //    *                                                                *
394 //    *                                                                *
395 //    *    ==>Called by : GLISUR                                       *
396 //    *                                                                *
397 //    ******************************************************************
398 //
399 //
400 //    ------------------------------------------------------------------
401 //
402 //
403 //*** By default this defines perfect smoothness
404       return 1;
405 }
406
407 //______________________________________________________________________
408 void gutrak()
409 {
410 //
411 //    ******************************************************************
412 //    *                                                                *
413 //    *       User routine to control tracking of one track            *
414 //    *                                                                *
415 //    *    ==>Called by : GTREVE                                       *
416 //    *                                                                *
417 //    ******************************************************************
418 //
419 //
420 //    ------------------------------------------------------------------
421 //
422      Int_t ndet = gAlice->Modules()->GetLast();
423      TObjArray &dets = *gAlice->Modules();
424      AliModule *module;
425      Int_t i;
426
427      for(i=0; i<=ndet; i++)
428        if((module = (AliModule*)dets[i]))
429          module->PreTrack();
430
431      gtrack();
432
433      for(i=0; i<=ndet; i++)
434        if((module = (AliModule*)dets[i]))
435          module->PostTrack();
436 }
437
438 //______________________________________________________________________
439 void gutrev()
440 {
441 //
442 //    ******************************************************************
443 //    *                                                                *
444 //    *       User routine to control tracking of one event            *
445 //    *                                                                *
446 //    *    ==>Called by : GTRIG                                        *
447 //    *                                                                *
448 //    ******************************************************************
449 //
450 //
451 //    ------------------------------------------------------------------
452 //
453   gtreve_root();
454 }
455
456
457 //______________________________________________________________________
458 void gufld(Float_t *x, Float_t *b)
459 {
460       if(gAlice->Field()) {
461          gAlice->Field()->Field(x,b);
462       } else {
463          printf("No mag field defined!\n");
464          b[0]=b[1]=b[2]=0;
465       }
466 }
467
468 //______________________________________________________________________
469 void gustep()
470 {
471 //
472 //    ******************************************************************
473 //    *                                                                *
474 //    *       User routine called at the end of each tracking step     *
475 //    *       INWVOL is different from 0 when the track has reached    *
476 //    *              a volume boundary                                 *
477 //    *       ISTOP is different from 0 if the track has stopped       *
478 //    *                                                                *
479 //    *    ==>Called by : GTRACK                                       *
480 //    *                                                                *
481 //    ******************************************************************
482 //
483
484
485   TLorentzVector x;
486   Float_t r;
487   Int_t ipp, jk, id, nt;
488   Float_t polar[3]={0,0,0};
489   Float_t mom[3];
490   char chproc[11];
491   
492   // --- Standard GEANT debug routine 
493   TGeant3* geant3 = (TGeant3*) gMC;
494   if(geant3->Gcflag()->idebug) geant3->Gdebug();
495
496   //     Stop particle if outside user defined tracking region 
497   gMC->TrackPosition(x);
498   r=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
499   if (r > gAlice->TrackingRmax() || TMath::Abs(x[2]) > gAlice->TrackingZmax()) {
500         gMC->StopTrack();
501   }
502   // --- Add new created particles 
503   if (gMC->NSecondaries() > 0) {
504     gMC->ProdProcess(chproc);
505     for (jk = 0; jk < geant3->Gcking()->ngkine; ++jk) {
506       ipp = Int_t (geant3->Gcking()->gkin[jk][4]+0.5);
507       // --- Skip neutrinos! 
508       if (ipp != 4) {
509         gAlice->SetTrack(1,gAlice->CurrentTrack(),gMC->PDGFromId(ipp), geant3->Gcking()->gkin[jk], 
510                          geant3->Gckin3()->gpos[jk], polar,geant3->Gctrak()->tofg, chproc, nt);
511       }
512     }
513   }
514   // Cherenkov photons here
515   if ( geant3->Gckin2()->ngphot ) {
516     for (jk = 0; jk < geant3->Gckin2()->ngphot; ++jk) {
517       mom[0]=geant3->Gckin2()->xphot[jk][3]*geant3->Gckin2()->xphot[jk][6];
518       mom[1]=geant3->Gckin2()->xphot[jk][4]*geant3->Gckin2()->xphot[jk][6];
519       mom[2]=geant3->Gckin2()->xphot[jk][5]*geant3->Gckin2()->xphot[jk][6];
520       gAlice->SetTrack(1, gAlice->CurrentTrack(), gMC->PDGFromId(50),
521                        mom,                             //momentum
522                        geant3->Gckin2()->xphot[jk],     //position
523                        &geant3->Gckin2()->xphot[jk][7], //polarisation
524                        geant3->Gckin2()->xphot[jk][10], //time of flight
525                        "Cherenkov", nt);
526       }
527   }
528   // --- Particle leaving the setup ?
529   if (!gMC->IsTrackOut()) 
530     if ((id=gAlice->DetFromMate(geant3->Gctmed()->numed)) >= 0) gAlice->StepManager(id);
531 }
532
533 //______________________________________________________________________
534 void gukine ()
535 {
536 //
537 //    ******************************************************************
538 //    *                                                                *
539 //    *       Read or Generates Kinematics for primary tracks          *
540 //    *                                                                *
541 //    *    ==>Called by : GTRIG                                        *
542 //    *                                                                *
543 //    ******************************************************************
544 //
545 //
546 //    ------------------------------------------------------------------
547 //
548   gAlice->Generator()->Generate();
549 }
550
551
552 //______________________________________________________________________
553 void uglast()
554 {
555 //
556 //    ******************************************************************
557 //    *                                                                *
558 //    *       User routine called at the end of the run                *
559 //    *                                                                *
560 //    *    ==>Called by : GRUN                                         *
561 //    *                                                                *
562 //    ******************************************************************
563 //
564 //
565 }
566 }