1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.3 2000/04/07 11:12:35 fca
19 G4 compatibility changes
21 Revision 1.2 2000/02/29 19:11:17 fca
22 Move gucode into AliGeant3.cxx
24 Revision 1.1 2000/02/23 16:25:25 fca
25 AliVMC and AliGeant3 classes introduced
26 ReadEuclid moved from AliRun to AliModule
30 #include <TParticle.h>
32 #include "AliGeant3.h"
35 #include "AliCallf77.h"
39 # define rxgtrak rxgtrak_
40 # define rxstrak rxstrak_
41 # define rxkeep rxkeep_
42 # define rxouth rxouth_
45 # define rxgtrak RXGTRAK
46 # define rxstrak RXSTRAK
47 # define rxkeep RXKEEP
48 # define rxouth RXOUTH
53 AliGeant3::AliGeant3(const char *title) :
56 void AliGeant3::FinishGeometry()
58 TGeant3::FinishGeometry();
59 //Create the color table
63 //____________________________________________________________________________
64 void AliGeant3::Init()
67 //=================Create Materials and geometry
68 TObjArray *modules = gAlice->Modules();
71 while((detector = (AliModule*)next())) {
72 // Initialise detector materials and geometry
73 detector->CreateMaterials();
74 detector->CreateGeometry();
75 detector->BuildGeometry();
79 //Terminate building of geometry
83 //____________________________________________________________________________
84 void AliGeant3::ProcessRun(Int_t nevent)
86 Int_t todo = TMath::Abs(nevent);
87 for (Int_t i=0; i<todo; i++) {
88 // Process one run (one run = one event)
91 gAlice->FinishEvent();
95 void AliGeant3::ProcessEvent()
102 //_____________________________________________________________________________
103 void AliGeant3::SetColors()
106 // Set the colors for all the volumes
107 // this is done sequentially for all volumes
108 // based on the number of their medium
111 Int_t jvolum=fGclink->jvolum;
112 //Int_t jtmed=fGclink->jtmed;
113 //Int_t jmate=fGclink->jmate;
114 Int_t nvolum=fGcnum->nvolum;
117 // Now for all the volumes
118 for(kv=1;kv<=nvolum;kv++) {
119 // Get the tracking medium
120 Int_t itm=Int_t (fZq[fZlq[jvolum-kv]+4]);
122 //Int_t ima=Int_t (fZq[fZlq[jtmed-itm]+6]);
124 //Float_t z=fZq[fZlq[jmate-ima]+7];
126 //icol = Int_t(z)%6+2;
127 //icol = 17+Int_t(z*150./92.);
130 strncpy(name,(char*)&fZiq[jvolum+kv],4);
132 Gsatt(name,"COLO",icol);
136 //_____________________________________________________________________________
138 // Interfaces to Fortran
140 //_____________________________________________________________________________
142 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
143 Float_t &e, Float_t *vpos, Float_t *polar,
147 // Fetches next track from the ROOT stack for transport. Called by the
148 // modified version of GTREVE.
150 // Track number in the ROOT stack. If MTRACK=0 no
151 // mtrack more tracks are left in the stack to be
153 // ipart Particle code in the GEANT conventions.
154 // pmom[3] Particle momentum in GeV/c
155 // e Particle energy in GeV
156 // vpos[3] Particle position
157 // tof Particle time of flight in seconds
160 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
161 ipart = gMC->IdFromPDG(pdg);
165 //_____________________________________________________________________________
166 extern "C" void type_of_call
168 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
169 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
171 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
172 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
177 // Fetches next track from the ROOT stack for transport. Called by GUKINE
180 // Status of the track. If keep=0 the track is put
181 // keep on the ROOT stack but it is not fetched for
183 // parent Parent track. If parent=0 the track is a primary.
184 // In GUSTEP the routine is normally called to store
185 // secondaries generated by the current track whose
186 // ROOT stack number is MTRACK (common SCKINE.
187 // ipart Particle code in the GEANT conventions.
188 // pmom[3] Particle momentum in GeV/c
189 // vpos[3] Particle position
190 // tof Particle time of flight in seconds
192 // cmech (CHARACTER*10) Particle origin. This field is user
193 // defined and it is not used inside the GALICE code.
194 // ntr Number assigned to the particle in the ROOT stack.
197 Float_t polar[3]={0.,0.,0.};
198 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
200 Int_t pdg=gMC->PDGFromId(ipart);
201 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
205 //_____________________________________________________________________________
206 extern "C" void type_of_call rxkeep(const Int_t &n)
208 if( NULL==gAlice ) exit(1);
210 if( n<=0 || n>gAlice->Particles()->GetEntries() )
212 printf(" Bad index n=%d must be 0<n<=%d\n",
213 n,gAlice->Particles()->GetEntries());
217 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
220 //_____________________________________________________________________________
221 extern "C" void type_of_call rxouth ()
224 // Called by Gtreve at the end of each primary track
226 gAlice->FinishPrimary();
231 # define gudigi gudigi_
232 # define guhadr guhadr_
233 # define guout guout_
234 # define guphad guphad_
235 # define gudcay gudcay_
236 # define guiget guiget_
237 # define guinme guinme_
238 # define guinti guinti_
239 # define gunear gunear_
240 # define guskip guskip_
241 # define guview guview_
242 # define gupara gupara_
243 # define gudtim gudtim_
244 # define guplsh guplsh_
245 # define gutrev gutrev_
246 # define gutrak gutrak_
247 # define guswim guswim_
248 # define gufld gufld_
249 # define gustep gustep_
250 # define gukine gukine_
251 # define uglast uglast_
253 # define gheish gheish_
254 # define flufin flufin_
255 # define gfmfin gfmfin_
256 # define gpghei gpghei_
257 # define fldist fldist_
258 # define gfmdis gfmdis_
259 # define ghelx3 ghelx3_
260 # define ghelix ghelix_
261 # define grkuta grkuta_
262 # define gtrack gtrack_
263 # define gtreve_root gtreve_root_
264 # define glast glast_
267 # define gudigi GUDIGI
268 # define guhadr GUHADR
270 # define guphad GUPHAD
271 # define gudcay GUDCAY
272 # define guiget GUIGET
273 # define guinme GUINME
274 # define guinti GUINTI
275 # define gunear GUNEAR
276 # define guskip GUSKIP
277 # define guview GUVIEW
278 # define gupara GUPARA
279 # define gudtim GUDTIM
280 # define guplsh GUPLSH
281 # define gutrev GUTREV
282 # define gutrak GUTRAK
283 # define guswim GUSWIM
285 # define gustep GUSTEP
286 # define gukine GUKINE
287 # define uglast UGLAST
289 # define gheish GHEISH
290 # define flufin FLUFIN
291 # define gfmfin GFMFIN
292 # define gpghei GPGHEI
293 # define fldist FLDIST
294 # define gfmdis GFMDIS
295 # define ghelx3 GHELX3
296 # define ghelix GHELIX
297 # define grkuta GRKUTA
298 # define gtrack GTRACK
299 # define gtreve_root GTREVE_ROOT
304 extern "C" type_of_call void gheish();
305 extern "C" type_of_call void flufin();
306 extern "C" type_of_call void gfmfin();
307 extern "C" type_of_call void gpghei();
308 extern "C" type_of_call void fldist();
309 extern "C" type_of_call void gfmdis();
310 extern "C" type_of_call void ghelx3(Float_t&, Float_t&, Float_t*, Float_t*);
311 extern "C" type_of_call void ghelix(Float_t&, Float_t&, Float_t*, Float_t*);
312 extern "C" type_of_call void grkuta(Float_t&, Float_t&, Float_t*, Float_t*);
313 extern "C" type_of_call void gtrack();
314 extern "C" type_of_call void gtreve_root();
315 extern "C" type_of_call void glast();
317 extern "C" type_of_call {
319 //______________________________________________________________________
323 // ******************************************************************
325 // * User routine to digitize one event *
327 // * ==>Called by : GTRIG *
329 // ******************************************************************
334 //______________________________________________________________________
338 // ******************************************************************
340 // * User routine to generate one hadronic interaction *
342 // * ==>Called by : GTHADR,GTNEUT *
344 // ******************************************************************
347 // ------------------------------------------------------------------
349 TGeant3* geant3 = (TGeant3*) gMC;
350 Int_t ihadr=geant3->Gcphys()->ihadr;
351 if (ihadr<4) gheish();
352 else if (ihadr==4) flufin();
356 //______________________________________________________________________
360 // ******************************************************************
362 // * User routine called at the end of each event *
364 // * ==>Called by : GTRIG *
366 // ******************************************************************
369 // ------------------------------------------------------------------
373 //______________________________________________________________________
377 // ******************************************************************
379 // * User routine to compute Hadron. inter. probabilities *
381 // * ==>Called by : GTHADR,GTNEUT *
383 // ******************************************************************
386 // ------------------------------------------------------------------
388 TGeant3* geant3 = (TGeant3*) gMC;
389 Int_t ihadr=geant3->Gcphys()->ihadr;
390 if (ihadr<4) gpghei();
391 else if (ihadr==4) fldist();
395 //______________________________________________________________________
399 // ******************************************************************
401 // * User routine to decay particles *
403 // * ==>Called by : GDECAY *
405 // ******************************************************************
408 // ------------------------------------------------------------------
412 //______________________________________________________________________
413 void guiget(Int_t&, Int_t&, Int_t&)
416 // ******************************************************************
418 // * User routine for interactive control of GEANT *
420 // * ==>Called by : <GXINT>, GINCOM *
422 // ******************************************************************
425 // ------------------------------------------------------------------
429 //______________________________________________________________________
430 void guinme(Float_t*, Int_t&, Float_t*, Int_t& IYES)
433 // **********************************************
435 // * USER ROUTINE TO PROVIDE GINME FUNCTION *
436 // * FOR ALL USER SHAPES IDENTIFIED BY THE *
437 // * SHAPE NUMBER SH. POINT IS GIVEN IN X *
438 // * THE PARAMETERS ARE GIVEN IN P. IYES IS *
439 // * RETURNED 1 IF POINT IS IN, 0 IF POINT *
440 // * IS OUT AND LESS THAN ZERO IF SHAPE *
441 // * NUMBER IS NOT SUPPORTED. *
443 // * ==>Called by : GINME *
445 // **********************************************
450 //______________________________________________________________________
454 // ******************************************************************
456 // * User routine for interactive version *
458 // * ==>Called by : <GXINT>, GINTRI *
460 // ******************************************************************
463 // ------------------------------------------------------------------
467 //______________________________________________________________________
468 void gunear(Int_t&, Int_t&, Float_t*, Int_t&)
471 // ******************************************************************
474 // * ISEARC to identify the given volume *
475 // * ICALL to identify the calling routine *
478 // * X coordinates (+direction for ICALL=2) *
479 // * JNEAR address of default list of neighbours *
480 // * (list to be overwriten by user) *
482 // * Called by : GFTRAC, GINVOL, GTMEDI, GTNEXT, GNEXT, GMEDIA *
484 // ******************************************************************
487 // ------------------------------------------------------------------
491 //______________________________________________________________________
492 void guskip(Int_t& ISKIP)
495 // ******************************************************************
497 // * User routine to skip unwanted tracks *
499 // * Called by : GSSTAK *
500 // * Author : F.Bruyant *
502 // ******************************************************************
505 // ------------------------------------------------------------------
510 //______________________________________________________________________
511 void guswim(Float_t& CHARGE, Float_t& STEP, Float_t* VECT, Float_t* VOUT)
514 // ******************************************************************
516 // * User routine to control tracking of one track *
517 // * in a magnetic field *
519 // * ==>Called by : GTELEC,GTHADR,GTMUON *
521 // ******************************************************************
524 // ------------------------------------------------------------------
526 TGeant3* geant3 = (TGeant3*) gMC;
527 Int_t ifield=geant3->Gctmed()->ifield;
528 Float_t fieldm=geant3->Gctmed()->fieldm;
531 Float_t fldcharge = fieldm*CHARGE;
532 ghelx3(fldcharge,STEP,VECT,VOUT);
534 else if (ifield==2) ghelix(CHARGE,STEP,VECT,VOUT);
535 else grkuta(CHARGE,STEP,VECT,VOUT);
538 //______________________________________________________________________
539 void guview(Int_t&, Int_t&, DEFCHARD, Int_t& DEFCHARL)
542 // ******************************************************************
544 // * User routine for interactive version *
546 // * ==>Called by : <GXINT>, GINC1 *
548 // ******************************************************************
551 // ------------------------------------------------------------------
555 //______________________________________________________________________
559 // ******************************************************************
561 // * User routine called every time a particle falls below *
562 // * parametrization threshold. This routine should create *
563 // * the parametrization stack, and, when this is full, *
564 // * parametrize the shower and track the geantinos. *
566 // * ==>Called by : GTRACK *
568 // ******************************************************************
571 // ------------------------------------------------------------------
575 //______________________________________________________________________
576 Float_t gudtim(Float_t&, Float_t&, Int_t&, Int_t&)
579 // ******************************************************************
581 // * User function called by GCDRIF to return drift time *
583 // * ==>Called by : GCDRIF *
585 // ******************************************************************
588 // ------------------------------------------------------------------
594 //______________________________________________________________________
595 Float_t guplsh(Int_t&, Int_t&)
598 // ******************************************************************
601 // * ==>Called by : GLISUR *
603 // ******************************************************************
606 // ------------------------------------------------------------------
609 //*** By default this defines perfect smoothness
613 //______________________________________________________________________
617 // ******************************************************************
619 // * User routine to control tracking of one track *
621 // * ==>Called by : GTREVE *
623 // ******************************************************************
626 // ------------------------------------------------------------------
628 Int_t ndet = gAlice->Modules()->GetLast();
629 TObjArray &dets = *gAlice->Modules();
633 for(i=0; i<=ndet; i++)
634 if((module = (AliModule*)dets[i]))
639 for(i=0; i<=ndet; i++)
640 if((module = (AliModule*)dets[i]))
644 //______________________________________________________________________
648 // ******************************************************************
650 // * User routine to control tracking of one event *
652 // * ==>Called by : GTRIG *
654 // ******************************************************************
657 // ------------------------------------------------------------------
663 //______________________________________________________________________
664 void gufld(Float_t *x, Float_t *b)
666 if(gAlice->Field()) {
667 gAlice->Field()->Field(x,b);
669 printf("No mag field defined!\n");
674 //______________________________________________________________________
678 // ******************************************************************
680 // * User routine called at the end of each tracking step *
681 // * INWVOL is different from 0 when the track has reached *
682 // * a volume boundary *
683 // * ISTOP is different from 0 if the track has stopped *
685 // * ==>Called by : GTRACK *
687 // ******************************************************************
693 Int_t ipp, jk, id, nt;
694 Float_t polar[3]={0,0,0};
698 // --- Standard GEANT debug routine
699 TGeant3* geant3 = (TGeant3*) gMC;
700 if(geant3->Gcflag()->idebug) geant3->Gdebug();
702 // Stop particle if outside user defined tracking region
703 gMC->TrackPosition(x);
704 r=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
705 if (r > gAlice->TrackingRmax() || TMath::Abs(x[2]) > gAlice->TrackingZmax()) {
708 // --- Add new created particles
709 if (gMC->NSecondaries() > 0) {
710 chproc=gMC->ProdProcess();
711 for (jk = 0; jk < geant3->Gcking()->ngkine; ++jk) {
712 ipp = Int_t (geant3->Gcking()->gkin[jk][4]+0.5);
713 // --- Skip neutrinos!
715 gAlice->SetTrack(1,gAlice->CurrentTrack(),gMC->PDGFromId(ipp), geant3->Gcking()->gkin[jk],
716 geant3->Gckin3()->gpos[jk], polar,geant3->Gctrak()->tofg, chproc, nt);
720 // Cherenkov photons here
721 if ( geant3->Gckin2()->ngphot ) {
722 for (jk = 0; jk < geant3->Gckin2()->ngphot; ++jk) {
723 mom[0]=geant3->Gckin2()->xphot[jk][3]*geant3->Gckin2()->xphot[jk][6];
724 mom[1]=geant3->Gckin2()->xphot[jk][4]*geant3->Gckin2()->xphot[jk][6];
725 mom[2]=geant3->Gckin2()->xphot[jk][5]*geant3->Gckin2()->xphot[jk][6];
726 gAlice->SetTrack(1, gAlice->CurrentTrack(), gMC->PDGFromId(50),
728 geant3->Gckin2()->xphot[jk], //position
729 &geant3->Gckin2()->xphot[jk][7], //polarisation
730 geant3->Gckin2()->xphot[jk][10], //time of flight
734 // --- Particle leaving the setup ?
735 if (!gMC->IsTrackOut())
736 if ((id=gAlice->DetFromMate(geant3->Gctmed()->numed)) >= 0) gAlice->StepManager(id);
739 //______________________________________________________________________
743 // ******************************************************************
745 // * Read or Generates Kinematics for primary tracks *
747 // * ==>Called by : GTRIG *
749 // ******************************************************************
752 // ------------------------------------------------------------------
754 gAlice->Generator()->Generate();
758 //______________________________________________________________________
762 // ******************************************************************
764 // * User routine called at the end of the run *
766 // * ==>Called by : GRUN *
768 // ******************************************************************