]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant3/AliGeant3.cxx
Coding convention corrections + few minor bug fixes
[u/mrichter/AliRoot.git] / TGeant3 / AliGeant3.cxx
CommitLineData
b13db077 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$
aee8290b 18Revision 1.5 2000/05/20 14:49:48 fca
19Call gdebug at the end of gustep
20
5bd6a80e 21Revision 1.4 2000/04/26 10:17:32 fca
22Changes in Lego for G4 compatibility
23
dffd31ef 24Revision 1.3 2000/04/07 11:12:35 fca
25G4 compatibility changes
26
875c717b 27Revision 1.2 2000/02/29 19:11:17 fca
28Move gucode into AliGeant3.cxx
29
d7067e4f 30Revision 1.1 2000/02/23 16:25:25 fca
31AliVMC and AliGeant3 classes introduced
32ReadEuclid moved from AliRun to AliModule
33
b13db077 34*/
35
36#include <TParticle.h>
37
38#include "AliGeant3.h"
39#include "AliRun.h"
40#include "TGeant3.h"
41#include "AliCallf77.h"
42
43#ifndef WIN32
44
45# define rxgtrak rxgtrak_
46# define rxstrak rxstrak_
47# define rxkeep rxkeep_
48# define rxouth rxouth_
49#else
50
51# define rxgtrak RXGTRAK
52# define rxstrak RXSTRAK
53# define rxkeep RXKEEP
54# define rxouth RXOUTH
55#endif
56
57ClassImp(AliGeant3)
58
875c717b 59AliGeant3::AliGeant3(const char *title) :
60 TGeant3(title) {}
61
62void AliGeant3::FinishGeometry()
b13db077 63{
875c717b 64 TGeant3::FinishGeometry();
65 //Create the color table
66 SetColors();
b13db077 67}
68
dffd31ef 69//____________________________________________________________________________
875c717b 70void AliGeant3::Init()
b13db077 71{
875c717b 72 //
73 //=================Create Materials and geometry
74 TObjArray *modules = gAlice->Modules();
75 TIter next(modules);
76 AliModule *detector;
77 while((detector = (AliModule*)next())) {
78 // Initialise detector materials and geometry
79 detector->CreateMaterials();
80 detector->CreateGeometry();
81 detector->BuildGeometry();
82 detector->Init();
83 }
84
85 //Terminate building of geometry
86 FinishGeometry();
b13db077 87}
88
875c717b 89//____________________________________________________________________________
90void AliGeant3::ProcessRun(Int_t nevent)
b13db077 91{
875c717b 92 Int_t todo = TMath::Abs(nevent);
93 for (Int_t i=0; i<todo; i++) {
94 // Process one run (one run = one event)
dffd31ef 95 gAlice->BeginEvent();
875c717b 96 ProcessEvent();
97 gAlice->FinishEvent();
98 }
b13db077 99}
100
875c717b 101void AliGeant3::ProcessEvent()
b13db077 102{
875c717b 103 Gtrigi();
104 Gtrigc();
105 Gtrig();
b13db077 106}
107
875c717b 108//_____________________________________________________________________________
109void AliGeant3::SetColors()
b13db077 110{
875c717b 111 //
112 // Set the colors for all the volumes
113 // this is done sequentially for all volumes
114 // based on the number of their medium
115 //
116 Int_t kv, icol;
117 Int_t jvolum=fGclink->jvolum;
118 //Int_t jtmed=fGclink->jtmed;
119 //Int_t jmate=fGclink->jmate;
120 Int_t nvolum=fGcnum->nvolum;
121 char name[5];
122 //
123 // Now for all the volumes
124 for(kv=1;kv<=nvolum;kv++) {
125 // Get the tracking medium
126 Int_t itm=Int_t (fZq[fZlq[jvolum-kv]+4]);
127 // Get the material
128 //Int_t ima=Int_t (fZq[fZlq[jtmed-itm]+6]);
129 // Get z
130 //Float_t z=fZq[fZlq[jmate-ima]+7];
131 // Find color number
132 //icol = Int_t(z)%6+2;
133 //icol = 17+Int_t(z*150./92.);
134 //icol = kv%6+2;
135 icol = itm%6+2;
136 strncpy(name,(char*)&fZiq[jvolum+kv],4);
137 name[4]='\0';
138 Gsatt(name,"COLO",icol);
139 }
b13db077 140}
141
142//_____________________________________________________________________________
143//
144// Interfaces to Fortran
145//
146//_____________________________________________________________________________
147
148extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
149 Float_t &e, Float_t *vpos, Float_t *polar,
150 Float_t &tof)
151{
152 //
153 // Fetches next track from the ROOT stack for transport. Called by the
154 // modified version of GTREVE.
155 //
156 // Track number in the ROOT stack. If MTRACK=0 no
157 // mtrack more tracks are left in the stack to be
158 // transported.
159 // ipart Particle code in the GEANT conventions.
160 // pmom[3] Particle momentum in GeV/c
161 // e Particle energy in GeV
162 // vpos[3] Particle position
163 // tof Particle time of flight in seconds
164 //
165 Int_t pdg;
166 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
167 ipart = gMC->IdFromPDG(pdg);
168 mtrack++;
169}
170
171//_____________________________________________________________________________
172extern "C" void type_of_call
173#ifndef WIN32
174rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
175 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
176#else
177rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
178 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
179 Int_t &ntr)
180#endif
181{
182 //
183 // Fetches next track from the ROOT stack for transport. Called by GUKINE
184 // and GUSTEP.
185 //
186 // Status of the track. If keep=0 the track is put
187 // keep on the ROOT stack but it is not fetched for
188 // transport.
189 // parent Parent track. If parent=0 the track is a primary.
190 // In GUSTEP the routine is normally called to store
191 // secondaries generated by the current track whose
192 // ROOT stack number is MTRACK (common SCKINE.
193 // ipart Particle code in the GEANT conventions.
194 // pmom[3] Particle momentum in GeV/c
195 // vpos[3] Particle position
196 // tof Particle time of flight in seconds
197 //
198 // cmech (CHARACTER*10) Particle origin. This field is user
199 // defined and it is not used inside the GALICE code.
200 // ntr Number assigned to the particle in the ROOT stack.
201 //
202 char mecha[11];
203 Float_t polar[3]={0.,0.,0.};
204 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
205 mecha[10]=0;
206 Int_t pdg=gMC->PDGFromId(ipart);
207 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
208 ntr++;
209}
210
211//_____________________________________________________________________________
212extern "C" void type_of_call rxkeep(const Int_t &n)
213{
214 if( NULL==gAlice ) exit(1);
215
216 if( n<=0 || n>gAlice->Particles()->GetEntries() )
217 {
218 printf(" Bad index n=%d must be 0<n<=%d\n",
219 n,gAlice->Particles()->GetEntries());
220 exit(1);
221 }
222
aee8290b 223 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(kKeepBit);
b13db077 224}
225
226//_____________________________________________________________________________
227extern "C" void type_of_call rxouth ()
228{
229 //
230 // Called by Gtreve at the end of each primary track
231 //
232 gAlice->FinishPrimary();
233}
234
d7067e4f 235
236#ifndef WIN32
237# define gudigi gudigi_
238# define guhadr guhadr_
239# define guout guout_
240# define guphad guphad_
241# define gudcay gudcay_
242# define guiget guiget_
243# define guinme guinme_
244# define guinti guinti_
245# define gunear gunear_
246# define guskip guskip_
247# define guview guview_
248# define gupara gupara_
249# define gudtim gudtim_
250# define guplsh guplsh_
251# define gutrev gutrev_
252# define gutrak gutrak_
253# define guswim guswim_
254# define gufld gufld_
255# define gustep gustep_
256# define gukine gukine_
257# define uglast uglast_
258
259# define gheish gheish_
260# define flufin flufin_
261# define gfmfin gfmfin_
262# define gpghei gpghei_
263# define fldist fldist_
264# define gfmdis gfmdis_
265# define ghelx3 ghelx3_
266# define ghelix ghelix_
267# define grkuta grkuta_
268# define gtrack gtrack_
aee8290b 269# define gtreveroot gtreveroot_
d7067e4f 270# define glast glast_
271
272#else
273# define gudigi GUDIGI
274# define guhadr GUHADR
275# define guout GUOUT
276# define guphad GUPHAD
277# define gudcay GUDCAY
278# define guiget GUIGET
279# define guinme GUINME
280# define guinti GUINTI
281# define gunear GUNEAR
282# define guskip GUSKIP
283# define guview GUVIEW
284# define gupara GUPARA
285# define gudtim GUDTIM
286# define guplsh GUPLSH
287# define gutrev GUTREV
288# define gutrak GUTRAK
289# define guswim GUSWIM
290# define gufld GUFLD
291# define gustep GUSTEP
292# define gukine GUKINE
293# define uglast UGLAST
294
295# define gheish GHEISH
296# define flufin FLUFIN
297# define gfmfin GFMFIN
298# define gpghei GPGHEI
299# define fldist FLDIST
300# define gfmdis GFMDIS
301# define ghelx3 GHELX3
302# define ghelix GHELIX
303# define grkuta GRKUTA
304# define gtrack GTRACK
aee8290b 305# define gtreveroot GTREVEROOT
d7067e4f 306# define glast GLAST
307
308#endif
309
310extern "C" type_of_call void gheish();
311extern "C" type_of_call void flufin();
312extern "C" type_of_call void gfmfin();
313extern "C" type_of_call void gpghei();
314extern "C" type_of_call void fldist();
315extern "C" type_of_call void gfmdis();
316extern "C" type_of_call void ghelx3(Float_t&, Float_t&, Float_t*, Float_t*);
317extern "C" type_of_call void ghelix(Float_t&, Float_t&, Float_t*, Float_t*);
318extern "C" type_of_call void grkuta(Float_t&, Float_t&, Float_t*, Float_t*);
319extern "C" type_of_call void gtrack();
aee8290b 320extern "C" type_of_call void gtreveroot();
d7067e4f 321extern "C" type_of_call void glast();
322
323extern "C" type_of_call {
324
325//______________________________________________________________________
326void gudigi()
327{
328//
329// ******************************************************************
330// * *
331// * User routine to digitize one event *
332// * *
333// * ==>Called by : GTRIG *
334// * *
335// ******************************************************************
336
337}
338
339
340//______________________________________________________________________
341void guhadr()
342{
343//
344// ******************************************************************
345// * *
346// * User routine to generate one hadronic interaction *
347// * *
348// * ==>Called by : GTHADR,GTNEUT *
349// * *
350// ******************************************************************
351//
352//
353// ------------------------------------------------------------------
354//
355 TGeant3* geant3 = (TGeant3*) gMC;
356 Int_t ihadr=geant3->Gcphys()->ihadr;
357 if (ihadr<4) gheish();
358 else if (ihadr==4) flufin();
359 else gfmfin();
360}
361
362//______________________________________________________________________
363void guout()
364{
365//
366// ******************************************************************
367// * *
368// * User routine called at the end of each event *
369// * *
370// * ==>Called by : GTRIG *
371// * *
372// ******************************************************************
373//
374//
375// ------------------------------------------------------------------
376//
377}
378
379//______________________________________________________________________
380void guphad()
381{
382//
383// ******************************************************************
384// * *
385// * User routine to compute Hadron. inter. probabilities *
386// * *
387// * ==>Called by : GTHADR,GTNEUT *
388// * *
389// ******************************************************************
390//
391//
392// ------------------------------------------------------------------
393//
394 TGeant3* geant3 = (TGeant3*) gMC;
395 Int_t ihadr=geant3->Gcphys()->ihadr;
396 if (ihadr<4) gpghei();
397 else if (ihadr==4) fldist();
398 else gfmdis();
399}
400
401//______________________________________________________________________
402void gudcay()
403{
404//
405// ******************************************************************
406// * *
407// * User routine to decay particles *
408// * *
409// * ==>Called by : GDECAY *
410// * *
411// ******************************************************************
412//
413//
414// ------------------------------------------------------------------
415//
416}
417
418//______________________________________________________________________
419void guiget(Int_t&, Int_t&, Int_t&)
420{
421//
422// ******************************************************************
423// * *
424// * User routine for interactive control of GEANT *
425// * *
426// * ==>Called by : <GXINT>, GINCOM *
427// * *
428// ******************************************************************
429//
430//
431// ------------------------------------------------------------------
432//
433}
434
435//______________________________________________________________________
436void guinme(Float_t*, Int_t&, Float_t*, Int_t& IYES)
437{
438//
439// **********************************************
440// * *
441// * USER ROUTINE TO PROVIDE GINME FUNCTION *
442// * FOR ALL USER SHAPES IDENTIFIED BY THE *
443// * SHAPE NUMBER SH. POINT IS GIVEN IN X *
444// * THE PARAMETERS ARE GIVEN IN P. IYES IS *
445// * RETURNED 1 IF POINT IS IN, 0 IF POINT *
446// * IS OUT AND LESS THAN ZERO IF SHAPE *
447// * NUMBER IS NOT SUPPORTED. *
448// * *
449// * ==>Called by : GINME *
450// * *
451// **********************************************
452//
453 IYES=-1;
454}
455
456//______________________________________________________________________
457void guinti()
458{
459//
460// ******************************************************************
461// * *
462// * User routine for interactive version *
463// * *
464// * ==>Called by : <GXINT>, GINTRI *
465// * *
466// ******************************************************************
467//
468//
469// ------------------------------------------------------------------
470//
471}
472
473//______________________________________________________________________
474void gunear(Int_t&, Int_t&, Float_t*, Int_t&)
475{
476//
477// ******************************************************************
478// * *
479// * User search *
480// * ISEARC to identify the given volume *
481// * ICALL to identify the calling routine *
482// * 1 GMEDIA like *
483// * 2 GNEXT like *
484// * X coordinates (+direction for ICALL=2) *
485// * JNEAR address of default list of neighbours *
486// * (list to be overwriten by user) *
487// * *
488// * Called by : GFTRAC, GINVOL, GTMEDI, GTNEXT, GNEXT, GMEDIA *
489// * *
490// ******************************************************************
491//
492//
493// ------------------------------------------------------------------
494//
495}
496
497//______________________________________________________________________
498void guskip(Int_t& ISKIP)
499{
500//
501// ******************************************************************
502// * *
503// * User routine to skip unwanted tracks *
504// * *
505// * Called by : GSSTAK *
506// * Author : F.Bruyant *
507// * *
508// ******************************************************************
509//
510//
511// ------------------------------------------------------------------
512//
513 ISKIP = 0;
514}
515
516//______________________________________________________________________
517void guswim(Float_t& CHARGE, Float_t& STEP, Float_t* VECT, Float_t* VOUT)
518{
519//
520// ******************************************************************
521// * *
522// * User routine to control tracking of one track *
523// * in a magnetic field *
524// * *
525// * ==>Called by : GTELEC,GTHADR,GTMUON *
526// * *
527// ******************************************************************
528//
529//
530// ------------------------------------------------------------------
531//
532 TGeant3* geant3 = (TGeant3*) gMC;
533 Int_t ifield=geant3->Gctmed()->ifield;
534 Float_t fieldm=geant3->Gctmed()->fieldm;
535
536 if (ifield==3) {
537 Float_t fldcharge = fieldm*CHARGE;
538 ghelx3(fldcharge,STEP,VECT,VOUT);
539 }
540 else if (ifield==2) ghelix(CHARGE,STEP,VECT,VOUT);
541 else grkuta(CHARGE,STEP,VECT,VOUT);
542}
543
544//______________________________________________________________________
545void guview(Int_t&, Int_t&, DEFCHARD, Int_t& DEFCHARL)
546{
547//
548// ******************************************************************
549// * *
550// * User routine for interactive version *
551// * *
552// * ==>Called by : <GXINT>, GINC1 *
553// * *
554// ******************************************************************
555//
556//
557// ------------------------------------------------------------------
558//
559}
560
561//______________________________________________________________________
562void gupara()
563{
564//
565// ******************************************************************
566// * *
567// * User routine called every time a particle falls below *
568// * parametrization threshold. This routine should create *
569// * the parametrization stack, and, when this is full, *
570// * parametrize the shower and track the geantinos. *
571// * *
572// * ==>Called by : GTRACK *
573// * *
574// ******************************************************************
575//
576//
577// ------------------------------------------------------------------
578//
579}
580
581//______________________________________________________________________
582Float_t gudtim(Float_t&, Float_t&, Int_t&, Int_t&)
583{
584//
585// ******************************************************************
586// * *
587// * User function called by GCDRIF to return drift time *
588// * *
589// * ==>Called by : GCDRIF *
590// * *
591// ******************************************************************
592//
593//
594// ------------------------------------------------------------------
595//
596 return 0;
597}
598
599
600//______________________________________________________________________
601Float_t guplsh(Int_t&, Int_t&)
602{
603//
604// ******************************************************************
605// * *
606// * *
607// * ==>Called by : GLISUR *
608// * *
609// ******************************************************************
610//
611//
612// ------------------------------------------------------------------
613//
614//
615//*** By default this defines perfect smoothness
616 return 1;
617}
618
619//______________________________________________________________________
620void gutrak()
621{
622//
623// ******************************************************************
624// * *
625// * User routine to control tracking of one track *
626// * *
627// * ==>Called by : GTREVE *
628// * *
629// ******************************************************************
630//
631//
632// ------------------------------------------------------------------
633//
634 Int_t ndet = gAlice->Modules()->GetLast();
635 TObjArray &dets = *gAlice->Modules();
636 AliModule *module;
637 Int_t i;
638
639 for(i=0; i<=ndet; i++)
640 if((module = (AliModule*)dets[i]))
641 module->PreTrack();
642
643 gtrack();
644
645 for(i=0; i<=ndet; i++)
646 if((module = (AliModule*)dets[i]))
647 module->PostTrack();
648}
649
650//______________________________________________________________________
651void gutrev()
652{
653//
654// ******************************************************************
655// * *
656// * User routine to control tracking of one event *
657// * *
658// * ==>Called by : GTRIG *
659// * *
660// ******************************************************************
661//
662//
663// ------------------------------------------------------------------
664//
aee8290b 665 gtreveroot();
d7067e4f 666}
667
668
669//______________________________________________________________________
670void gufld(Float_t *x, Float_t *b)
671{
672 if(gAlice->Field()) {
673 gAlice->Field()->Field(x,b);
674 } else {
675 printf("No mag field defined!\n");
676 b[0]=b[1]=b[2]=0;
677 }
678}
679
680//______________________________________________________________________
681void gustep()
682{
683//
684// ******************************************************************
685// * *
686// * User routine called at the end of each tracking step *
687// * INWVOL is different from 0 when the track has reached *
688// * a volume boundary *
689// * ISTOP is different from 0 if the track has stopped *
690// * *
691// * ==>Called by : GTRACK *
692// * *
693// ******************************************************************
694//
695
696
697 TLorentzVector x;
698 Float_t r;
699 Int_t ipp, jk, id, nt;
700 Float_t polar[3]={0,0,0};
701 Float_t mom[3];
702 const char *chproc;
703
d7067e4f 704 TGeant3* geant3 = (TGeant3*) gMC;
d7067e4f 705
706 // Stop particle if outside user defined tracking region
707 gMC->TrackPosition(x);
708 r=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
709 if (r > gAlice->TrackingRmax() || TMath::Abs(x[2]) > gAlice->TrackingZmax()) {
710 gMC->StopTrack();
711 }
5bd6a80e 712
d7067e4f 713 // --- Add new created particles
714 if (gMC->NSecondaries() > 0) {
715 chproc=gMC->ProdProcess();
716 for (jk = 0; jk < geant3->Gcking()->ngkine; ++jk) {
717 ipp = Int_t (geant3->Gcking()->gkin[jk][4]+0.5);
718 // --- Skip neutrinos!
719 if (ipp != 4) {
720 gAlice->SetTrack(1,gAlice->CurrentTrack(),gMC->PDGFromId(ipp), geant3->Gcking()->gkin[jk],
721 geant3->Gckin3()->gpos[jk], polar,geant3->Gctrak()->tofg, chproc, nt);
722 }
723 }
724 }
725 // Cherenkov photons here
726 if ( geant3->Gckin2()->ngphot ) {
727 for (jk = 0; jk < geant3->Gckin2()->ngphot; ++jk) {
728 mom[0]=geant3->Gckin2()->xphot[jk][3]*geant3->Gckin2()->xphot[jk][6];
729 mom[1]=geant3->Gckin2()->xphot[jk][4]*geant3->Gckin2()->xphot[jk][6];
730 mom[2]=geant3->Gckin2()->xphot[jk][5]*geant3->Gckin2()->xphot[jk][6];
731 gAlice->SetTrack(1, gAlice->CurrentTrack(), gMC->PDGFromId(50),
732 mom, //momentum
733 geant3->Gckin2()->xphot[jk], //position
734 &geant3->Gckin2()->xphot[jk][7], //polarisation
735 geant3->Gckin2()->xphot[jk][10], //time of flight
736 "Cherenkov", nt);
737 }
738 }
739 // --- Particle leaving the setup ?
740 if (!gMC->IsTrackOut())
741 if ((id=gAlice->DetFromMate(geant3->Gctmed()->numed)) >= 0) gAlice->StepManager(id);
5bd6a80e 742
743 // --- Standard GEANT debug routine
744 if(geant3->Gcflag()->idebug) geant3->Gdebug();
d7067e4f 745}
746
747//______________________________________________________________________
748void gukine ()
749{
750//
751// ******************************************************************
752// * *
753// * Read or Generates Kinematics for primary tracks *
754// * *
755// * ==>Called by : GTRIG *
756// * *
757// ******************************************************************
758//
759//
760// ------------------------------------------------------------------
761//
762 gAlice->Generator()->Generate();
763}
764
765
766//______________________________________________________________________
767void uglast()
768{
769//
770// ******************************************************************
771// * *
772// * User routine called at the end of the run *
773// * *
774// * ==>Called by : GRUN *
775// * *
776// ******************************************************************
777//
778//
779}
780}
781