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.2 2000/02/29 19:11:17 fca
19 Move gucode into AliGeant3.cxx
21 Revision 1.1 2000/02/23 16:25:25 fca
22 AliVMC and AliGeant3 classes introduced
23 ReadEuclid moved from AliRun to AliModule
27 #include <TParticle.h>
29 #include "AliGeant3.h"
32 #include "AliCallf77.h"
36 # define rxgtrak rxgtrak_
37 # define rxstrak rxstrak_
38 # define rxkeep rxkeep_
39 # define rxouth rxouth_
42 # define rxgtrak RXGTRAK
43 # define rxstrak RXSTRAK
44 # define rxkeep RXKEEP
45 # define rxouth RXOUTH
50 AliGeant3::AliGeant3(const char *title) :
53 void AliGeant3::FinishGeometry()
55 TGeant3::FinishGeometry();
56 //Create the color table
60 void AliGeant3::Init()
63 //=================Create Materials and geometry
64 TObjArray *modules = gAlice->Modules();
67 while((detector = (AliModule*)next())) {
68 // Initialise detector materials and geometry
69 detector->CreateMaterials();
70 detector->CreateGeometry();
71 detector->BuildGeometry();
75 //Terminate building of geometry
79 //____________________________________________________________________________
80 void AliGeant3::ProcessRun(Int_t nevent)
82 Int_t todo = TMath::Abs(nevent);
83 for (Int_t i=0; i<todo; i++) {
84 // Process one run (one run = one event)
87 gAlice->FinishEvent();
91 void AliGeant3::ProcessEvent()
98 //_____________________________________________________________________________
99 void AliGeant3::SetColors()
102 // Set the colors for all the volumes
103 // this is done sequentially for all volumes
104 // based on the number of their medium
107 Int_t jvolum=fGclink->jvolum;
108 //Int_t jtmed=fGclink->jtmed;
109 //Int_t jmate=fGclink->jmate;
110 Int_t nvolum=fGcnum->nvolum;
113 // Now for all the volumes
114 for(kv=1;kv<=nvolum;kv++) {
115 // Get the tracking medium
116 Int_t itm=Int_t (fZq[fZlq[jvolum-kv]+4]);
118 //Int_t ima=Int_t (fZq[fZlq[jtmed-itm]+6]);
120 //Float_t z=fZq[fZlq[jmate-ima]+7];
122 //icol = Int_t(z)%6+2;
123 //icol = 17+Int_t(z*150./92.);
126 strncpy(name,(char*)&fZiq[jvolum+kv],4);
128 Gsatt(name,"COLO",icol);
132 //_____________________________________________________________________________
134 // Interfaces to Fortran
136 //_____________________________________________________________________________
138 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
139 Float_t &e, Float_t *vpos, Float_t *polar,
143 // Fetches next track from the ROOT stack for transport. Called by the
144 // modified version of GTREVE.
146 // Track number in the ROOT stack. If MTRACK=0 no
147 // mtrack more tracks are left in the stack to be
149 // ipart Particle code in the GEANT conventions.
150 // pmom[3] Particle momentum in GeV/c
151 // e Particle energy in GeV
152 // vpos[3] Particle position
153 // tof Particle time of flight in seconds
156 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
157 ipart = gMC->IdFromPDG(pdg);
161 //_____________________________________________________________________________
162 extern "C" void type_of_call
164 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
165 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
167 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
168 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
173 // Fetches next track from the ROOT stack for transport. Called by GUKINE
176 // Status of the track. If keep=0 the track is put
177 // keep on the ROOT stack but it is not fetched for
179 // parent Parent track. If parent=0 the track is a primary.
180 // In GUSTEP the routine is normally called to store
181 // secondaries generated by the current track whose
182 // ROOT stack number is MTRACK (common SCKINE.
183 // ipart Particle code in the GEANT conventions.
184 // pmom[3] Particle momentum in GeV/c
185 // vpos[3] Particle position
186 // tof Particle time of flight in seconds
188 // cmech (CHARACTER*10) Particle origin. This field is user
189 // defined and it is not used inside the GALICE code.
190 // ntr Number assigned to the particle in the ROOT stack.
193 Float_t polar[3]={0.,0.,0.};
194 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
196 Int_t pdg=gMC->PDGFromId(ipart);
197 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
201 //_____________________________________________________________________________
202 extern "C" void type_of_call rxkeep(const Int_t &n)
204 if( NULL==gAlice ) exit(1);
206 if( n<=0 || n>gAlice->Particles()->GetEntries() )
208 printf(" Bad index n=%d must be 0<n<=%d\n",
209 n,gAlice->Particles()->GetEntries());
213 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
216 //_____________________________________________________________________________
217 extern "C" void type_of_call rxouth ()
220 // Called by Gtreve at the end of each primary track
222 gAlice->FinishPrimary();
227 # define gudigi gudigi_
228 # define guhadr guhadr_
229 # define guout guout_
230 # define guphad guphad_
231 # define gudcay gudcay_
232 # define guiget guiget_
233 # define guinme guinme_
234 # define guinti guinti_
235 # define gunear gunear_
236 # define guskip guskip_
237 # define guview guview_
238 # define gupara gupara_
239 # define gudtim gudtim_
240 # define guplsh guplsh_
241 # define gutrev gutrev_
242 # define gutrak gutrak_
243 # define guswim guswim_
244 # define gufld gufld_
245 # define gustep gustep_
246 # define gukine gukine_
247 # define uglast uglast_
249 # define gheish gheish_
250 # define flufin flufin_
251 # define gfmfin gfmfin_
252 # define gpghei gpghei_
253 # define fldist fldist_
254 # define gfmdis gfmdis_
255 # define ghelx3 ghelx3_
256 # define ghelix ghelix_
257 # define grkuta grkuta_
258 # define gtrack gtrack_
259 # define gtreve_root gtreve_root_
260 # define glast glast_
263 # define gudigi GUDIGI
264 # define guhadr GUHADR
266 # define guphad GUPHAD
267 # define gudcay GUDCAY
268 # define guiget GUIGET
269 # define guinme GUINME
270 # define guinti GUINTI
271 # define gunear GUNEAR
272 # define guskip GUSKIP
273 # define guview GUVIEW
274 # define gupara GUPARA
275 # define gudtim GUDTIM
276 # define guplsh GUPLSH
277 # define gutrev GUTREV
278 # define gutrak GUTRAK
279 # define guswim GUSWIM
281 # define gustep GUSTEP
282 # define gukine GUKINE
283 # define uglast UGLAST
285 # define gheish GHEISH
286 # define flufin FLUFIN
287 # define gfmfin GFMFIN
288 # define gpghei GPGHEI
289 # define fldist FLDIST
290 # define gfmdis GFMDIS
291 # define ghelx3 GHELX3
292 # define ghelix GHELIX
293 # define grkuta GRKUTA
294 # define gtrack GTRACK
295 # define gtreve_root GTREVE_ROOT
300 extern "C" type_of_call void gheish();
301 extern "C" type_of_call void flufin();
302 extern "C" type_of_call void gfmfin();
303 extern "C" type_of_call void gpghei();
304 extern "C" type_of_call void fldist();
305 extern "C" type_of_call void gfmdis();
306 extern "C" type_of_call void ghelx3(Float_t&, Float_t&, Float_t*, Float_t*);
307 extern "C" type_of_call void ghelix(Float_t&, Float_t&, Float_t*, Float_t*);
308 extern "C" type_of_call void grkuta(Float_t&, Float_t&, Float_t*, Float_t*);
309 extern "C" type_of_call void gtrack();
310 extern "C" type_of_call void gtreve_root();
311 extern "C" type_of_call void glast();
313 extern "C" type_of_call {
315 //______________________________________________________________________
319 // ******************************************************************
321 // * User routine to digitize one event *
323 // * ==>Called by : GTRIG *
325 // ******************************************************************
330 //______________________________________________________________________
334 // ******************************************************************
336 // * User routine to generate one hadronic interaction *
338 // * ==>Called by : GTHADR,GTNEUT *
340 // ******************************************************************
343 // ------------------------------------------------------------------
345 TGeant3* geant3 = (TGeant3*) gMC;
346 Int_t ihadr=geant3->Gcphys()->ihadr;
347 if (ihadr<4) gheish();
348 else if (ihadr==4) flufin();
352 //______________________________________________________________________
356 // ******************************************************************
358 // * User routine called at the end of each event *
360 // * ==>Called by : GTRIG *
362 // ******************************************************************
365 // ------------------------------------------------------------------
369 //______________________________________________________________________
373 // ******************************************************************
375 // * User routine to compute Hadron. inter. probabilities *
377 // * ==>Called by : GTHADR,GTNEUT *
379 // ******************************************************************
382 // ------------------------------------------------------------------
384 TGeant3* geant3 = (TGeant3*) gMC;
385 Int_t ihadr=geant3->Gcphys()->ihadr;
386 if (ihadr<4) gpghei();
387 else if (ihadr==4) fldist();
391 //______________________________________________________________________
395 // ******************************************************************
397 // * User routine to decay particles *
399 // * ==>Called by : GDECAY *
401 // ******************************************************************
404 // ------------------------------------------------------------------
408 //______________________________________________________________________
409 void guiget(Int_t&, Int_t&, Int_t&)
412 // ******************************************************************
414 // * User routine for interactive control of GEANT *
416 // * ==>Called by : <GXINT>, GINCOM *
418 // ******************************************************************
421 // ------------------------------------------------------------------
425 //______________________________________________________________________
426 void guinme(Float_t*, Int_t&, Float_t*, Int_t& IYES)
429 // **********************************************
431 // * USER ROUTINE TO PROVIDE GINME FUNCTION *
432 // * FOR ALL USER SHAPES IDENTIFIED BY THE *
433 // * SHAPE NUMBER SH. POINT IS GIVEN IN X *
434 // * THE PARAMETERS ARE GIVEN IN P. IYES IS *
435 // * RETURNED 1 IF POINT IS IN, 0 IF POINT *
436 // * IS OUT AND LESS THAN ZERO IF SHAPE *
437 // * NUMBER IS NOT SUPPORTED. *
439 // * ==>Called by : GINME *
441 // **********************************************
446 //______________________________________________________________________
450 // ******************************************************************
452 // * User routine for interactive version *
454 // * ==>Called by : <GXINT>, GINTRI *
456 // ******************************************************************
459 // ------------------------------------------------------------------
463 //______________________________________________________________________
464 void gunear(Int_t&, Int_t&, Float_t*, Int_t&)
467 // ******************************************************************
470 // * ISEARC to identify the given volume *
471 // * ICALL to identify the calling routine *
474 // * X coordinates (+direction for ICALL=2) *
475 // * JNEAR address of default list of neighbours *
476 // * (list to be overwriten by user) *
478 // * Called by : GFTRAC, GINVOL, GTMEDI, GTNEXT, GNEXT, GMEDIA *
480 // ******************************************************************
483 // ------------------------------------------------------------------
487 //______________________________________________________________________
488 void guskip(Int_t& ISKIP)
491 // ******************************************************************
493 // * User routine to skip unwanted tracks *
495 // * Called by : GSSTAK *
496 // * Author : F.Bruyant *
498 // ******************************************************************
501 // ------------------------------------------------------------------
506 //______________________________________________________________________
507 void guswim(Float_t& CHARGE, Float_t& STEP, Float_t* VECT, Float_t* VOUT)
510 // ******************************************************************
512 // * User routine to control tracking of one track *
513 // * in a magnetic field *
515 // * ==>Called by : GTELEC,GTHADR,GTMUON *
517 // ******************************************************************
520 // ------------------------------------------------------------------
522 TGeant3* geant3 = (TGeant3*) gMC;
523 Int_t ifield=geant3->Gctmed()->ifield;
524 Float_t fieldm=geant3->Gctmed()->fieldm;
527 Float_t fldcharge = fieldm*CHARGE;
528 ghelx3(fldcharge,STEP,VECT,VOUT);
530 else if (ifield==2) ghelix(CHARGE,STEP,VECT,VOUT);
531 else grkuta(CHARGE,STEP,VECT,VOUT);
534 //______________________________________________________________________
535 void guview(Int_t&, Int_t&, DEFCHARD, Int_t& DEFCHARL)
538 // ******************************************************************
540 // * User routine for interactive version *
542 // * ==>Called by : <GXINT>, GINC1 *
544 // ******************************************************************
547 // ------------------------------------------------------------------
551 //______________________________________________________________________
555 // ******************************************************************
557 // * User routine called every time a particle falls below *
558 // * parametrization threshold. This routine should create *
559 // * the parametrization stack, and, when this is full, *
560 // * parametrize the shower and track the geantinos. *
562 // * ==>Called by : GTRACK *
564 // ******************************************************************
567 // ------------------------------------------------------------------
571 //______________________________________________________________________
572 Float_t gudtim(Float_t&, Float_t&, Int_t&, Int_t&)
575 // ******************************************************************
577 // * User function called by GCDRIF to return drift time *
579 // * ==>Called by : GCDRIF *
581 // ******************************************************************
584 // ------------------------------------------------------------------
590 //______________________________________________________________________
591 Float_t guplsh(Int_t&, Int_t&)
594 // ******************************************************************
597 // * ==>Called by : GLISUR *
599 // ******************************************************************
602 // ------------------------------------------------------------------
605 //*** By default this defines perfect smoothness
609 //______________________________________________________________________
613 // ******************************************************************
615 // * User routine to control tracking of one track *
617 // * ==>Called by : GTREVE *
619 // ******************************************************************
622 // ------------------------------------------------------------------
624 Int_t ndet = gAlice->Modules()->GetLast();
625 TObjArray &dets = *gAlice->Modules();
629 for(i=0; i<=ndet; i++)
630 if((module = (AliModule*)dets[i]))
635 for(i=0; i<=ndet; i++)
636 if((module = (AliModule*)dets[i]))
640 //______________________________________________________________________
644 // ******************************************************************
646 // * User routine to control tracking of one event *
648 // * ==>Called by : GTRIG *
650 // ******************************************************************
653 // ------------------------------------------------------------------
659 //______________________________________________________________________
660 void gufld(Float_t *x, Float_t *b)
662 if(gAlice->Field()) {
663 gAlice->Field()->Field(x,b);
665 printf("No mag field defined!\n");
670 //______________________________________________________________________
674 // ******************************************************************
676 // * User routine called at the end of each tracking step *
677 // * INWVOL is different from 0 when the track has reached *
678 // * a volume boundary *
679 // * ISTOP is different from 0 if the track has stopped *
681 // * ==>Called by : GTRACK *
683 // ******************************************************************
689 Int_t ipp, jk, id, nt;
690 Float_t polar[3]={0,0,0};
694 // --- Standard GEANT debug routine
695 TGeant3* geant3 = (TGeant3*) gMC;
696 if(geant3->Gcflag()->idebug) geant3->Gdebug();
698 // Stop particle if outside user defined tracking region
699 gMC->TrackPosition(x);
700 r=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
701 if (r > gAlice->TrackingRmax() || TMath::Abs(x[2]) > gAlice->TrackingZmax()) {
704 // --- Add new created particles
705 if (gMC->NSecondaries() > 0) {
706 chproc=gMC->ProdProcess();
707 for (jk = 0; jk < geant3->Gcking()->ngkine; ++jk) {
708 ipp = Int_t (geant3->Gcking()->gkin[jk][4]+0.5);
709 // --- Skip neutrinos!
711 gAlice->SetTrack(1,gAlice->CurrentTrack(),gMC->PDGFromId(ipp), geant3->Gcking()->gkin[jk],
712 geant3->Gckin3()->gpos[jk], polar,geant3->Gctrak()->tofg, chproc, nt);
716 // Cherenkov photons here
717 if ( geant3->Gckin2()->ngphot ) {
718 for (jk = 0; jk < geant3->Gckin2()->ngphot; ++jk) {
719 mom[0]=geant3->Gckin2()->xphot[jk][3]*geant3->Gckin2()->xphot[jk][6];
720 mom[1]=geant3->Gckin2()->xphot[jk][4]*geant3->Gckin2()->xphot[jk][6];
721 mom[2]=geant3->Gckin2()->xphot[jk][5]*geant3->Gckin2()->xphot[jk][6];
722 gAlice->SetTrack(1, gAlice->CurrentTrack(), gMC->PDGFromId(50),
724 geant3->Gckin2()->xphot[jk], //position
725 &geant3->Gckin2()->xphot[jk][7], //polarisation
726 geant3->Gckin2()->xphot[jk][10], //time of flight
730 // --- Particle leaving the setup ?
731 if (!gMC->IsTrackOut())
732 if ((id=gAlice->DetFromMate(geant3->Gctmed()->numed)) >= 0) gAlice->StepManager(id);
735 //______________________________________________________________________
739 // ******************************************************************
741 // * Read or Generates Kinematics for primary tracks *
743 // * ==>Called by : GTRIG *
745 // ******************************************************************
748 // ------------------------------------------------------------------
750 gAlice->Generator()->Generate();
754 //______________________________________________________________________
758 // ******************************************************************
760 // * User routine called at the end of the run *
762 // * ==>Called by : GRUN *
764 // ******************************************************************