]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant3/TGeant3.cxx
New method IsNewTrack and fix for a problem in Father-Daughter relations
[u/mrichter/AliRoot.git] / TGeant3 / TGeant3.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 Revision 1.25  2000/04/07 11:12:35  fca
19 G4 compatibility changes
20
21 Revision 1.24  2000/02/28 21:03:57  fca
22 Some additions to improve the compatibility with G4
23
24 Revision 1.23  2000/02/23 16:25:25  fca
25 AliVMC and AliGeant3 classes introduced
26 ReadEuclid moved from AliRun to AliModule
27
28 Revision 1.22  2000/01/18 15:40:13  morsch
29 Interface to GEANT3 routines GFTMAT, GBRELM and GPRELM added
30 Define geant particle type 51: Feedback Photon with Cherenkov photon properties.
31
32 Revision 1.21  2000/01/17 19:41:17  fca
33 Add SetERAN function
34
35 Revision 1.20  2000/01/12 11:29:27  fca
36 Close material file
37
38 Revision 1.19  1999/12/17 09:03:12  fca
39 Introduce a names array
40
41 Revision 1.18  1999/11/26 16:55:39  fca
42 Reimplement CurrentVolName() to avoid memory leaks
43
44 Revision 1.17  1999/11/03 16:58:28  fca
45 Correct source of address violation in creating character string
46
47 Revision 1.16  1999/11/03 13:17:08  fca
48 Have ProdProcess return const char*
49
50 Revision 1.15  1999/10/26 06:04:50  fca
51 Introduce TLorentzVector in AliMC::GetSecondary. Thanks to I.Hrivnacova
52
53 Revision 1.14  1999/09/29 09:24:30  fca
54 Introduction of the Copyright and cvs Log
55
56 */
57
58 ///////////////////////////////////////////////////////////////////////////////
59 //                                                                           //
60 //  Interface Class to the Geant3.21 MonteCarlo                              //
61 //                                                                           //
62 //Begin_Html
63 /*
64 <img src="picts/TGeant3Class.gif">
65 */
66 //End_Html
67 //                                                                           //
68 //                                                                           //
69 ///////////////////////////////////////////////////////////////////////////////
70
71 #include "TGeant3.h" 
72 #include "TROOT.h" 
73 #include "THIGZ.h" 
74 #include "ctype.h" 
75 #include <TDatabasePDG.h>
76 #include "AliCallf77.h" 
77  
78 #ifndef WIN32 
79 # define gzebra  gzebra_ 
80 # define grfile  grfile_ 
81 # define gpcxyz  gpcxyz_ 
82 # define ggclos  ggclos_ 
83 # define glast   glast_ 
84 # define ginit   ginit_ 
85 # define gcinit  gcinit_ 
86 # define grun    grun_ 
87 # define gtrig   gtrig_ 
88 # define gtrigc  gtrigc_ 
89 # define gtrigi  gtrigi_ 
90 # define gwork   gwork_ 
91 # define gzinit  gzinit_ 
92 # define gfmate  gfmate_ 
93 # define gfpart  gfpart_ 
94 # define gftmed  gftmed_ 
95 # define gftmat  gftmat_ 
96 # define gmate   gmate_ 
97 # define gpart   gpart_ 
98 # define gsdk    gsdk_ 
99 # define gsmate  gsmate_ 
100 # define gsmixt  gsmixt_ 
101 # define gspart  gspart_ 
102 # define gstmed  gstmed_ 
103 # define gsckov  gsckov_
104 # define gstpar  gstpar_ 
105 # define gfkine  gfkine_ 
106 # define gfvert  gfvert_ 
107 # define gskine  gskine_ 
108 # define gsvert  gsvert_ 
109 # define gphysi  gphysi_ 
110 # define gdebug  gdebug_ 
111 # define gekbin  gekbin_ 
112 # define gfinds  gfinds_ 
113 # define gsking  gsking_ 
114 # define gskpho  gskpho_ 
115 # define gsstak  gsstak_ 
116 # define gsxyz   gsxyz_ 
117 # define gtrack  gtrack_ 
118 # define gtreve  gtreve_ 
119 # define gtreve_root  gtreve_root_ 
120 # define grndm   grndm_ 
121 # define grndmq  grndmq_ 
122 # define gdtom   gdtom_ 
123 # define glmoth  glmoth_ 
124 # define gmedia  gmedia_ 
125 # define gmtod   gmtod_ 
126 # define gsdvn   gsdvn_ 
127 # define gsdvn2  gsdvn2_ 
128 # define gsdvs   gsdvs_ 
129 # define gsdvs2  gsdvs2_ 
130 # define gsdvt   gsdvt_ 
131 # define gsdvt2  gsdvt2_
132 # define gsord   gsord_ 
133 # define gspos   gspos_ 
134 # define gsposp  gsposp_ 
135 # define gsrotm  gsrotm_ 
136 # define gprotm  gprotm_ 
137 # define gsvolu  gsvolu_ 
138 # define gprint  gprint_ 
139 # define gdinit  gdinit_ 
140 # define gdopt   gdopt_ 
141 # define gdraw   gdraw_ 
142 # define gdrayt  gdrayt_
143 # define gdrawc  gdrawc_ 
144 # define gdrawx  gdrawx_ 
145 # define gdhead  gdhead_ 
146 # define gdwmn1  gdwmn1_ 
147 # define gdwmn2  gdwmn2_ 
148 # define gdwmn3  gdwmn3_ 
149 # define gdxyz   gdxyz_ 
150 # define gdcxyz  gdcxyz_ 
151 # define gdman   gdman_ 
152 # define gdspec  gdspec_ 
153 # define gdtree  gdtree_ 
154 # define gdelet  gdelet_ 
155 # define gdclos  gdclos_ 
156 # define gdshow  gdshow_ 
157 # define gdopen  gdopen_ 
158 # define dzshow  dzshow_ 
159 # define gsatt   gsatt_ 
160 # define gfpara  gfpara_
161 # define gckpar  gckpar_
162 # define gckmat  gckmat_
163 # define geditv  geditv_
164 # define mzdrop  mzdrop_
165
166 # define ertrak  ertrak_
167 # define ertrgo  ertrgo_
168  
169 # define setbomb setbomb_
170 # define setclip setclip_
171 # define gcomad gcomad_
172
173 # define gbrelm gbrelm_
174 # define gprelm gprelm_
175 #else 
176 # define gzebra  GZEBRA 
177 # define grfile  GRFILE 
178 # define gpcxyz  GPCXYZ 
179 # define ggclos  GGCLOS 
180 # define glast   GLAST 
181 # define ginit   GINIT 
182 # define gcinit  GCINIT 
183 # define grun    GRUN 
184 # define gtrig   GTRIG 
185 # define gtrigc  GTRIGC 
186 # define gtrigi  GTRIGI 
187 # define gwork   GWORK 
188 # define gzinit  GZINIT 
189 # define gfmate  GFMATE 
190 # define gfpart  GFPART 
191 # define gftmed  GFTMED 
192 # define gftmat  GFTMAT
193 # define gmate   GMATE 
194 # define gpart   GPART 
195 # define gsdk    GSDK 
196 # define gsmate  GSMATE 
197 # define gsmixt  GSMIXT 
198 # define gspart  GSPART 
199 # define gstmed  GSTMED 
200 # define gsckov  GSCKOV
201 # define gstpar  GSTPAR 
202 # define gfkine  GFKINE 
203 # define gfvert  GFVERT 
204 # define gskine  GSKINE 
205 # define gsvert  GSVERT 
206 # define gphysi  GPHYSI 
207 # define gdebug  GDEBUG 
208 # define gekbin  GEKBIN 
209 # define gfinds  GFINDS 
210 # define gsking  GSKING 
211 # define gskpho  GSKPHO 
212 # define gsstak  GSSTAK 
213 # define gsxyz   GSXYZ 
214 # define gtrack  GTRACK 
215 # define gtreve  GTREVE 
216 # define gtreve_root  GTREVE_ROOT
217 # define grndm   GRNDM
218 # define grndmq  GRNDMQ
219 # define gdtom   GDTOM 
220 # define glmoth  GLMOTH 
221 # define gmedia  GMEDIA 
222 # define gmtod   GMTOD 
223 # define gsdvn   GSDVN 
224 # define gsdvn2  GSDVN2 
225 # define gsdvs   GSDVS 
226 # define gsdvs2  GSDVS2 
227 # define gsdvt   GSDVT 
228 # define gsdvt2  GSDVT2
229 # define gsord   GSORD 
230 # define gspos   GSPOS 
231 # define gsposp  GSPOSP 
232 # define gsrotm  GSROTM 
233 # define gprotm  GPROTM 
234 # define gsvolu  GSVOLU 
235 # define gprint  GPRINT 
236 # define gdinit  GDINIT
237 # define gdopt   GDOPT 
238 # define gdraw   GDRAW
239 # define gdrayt  GDRAYT
240 # define gdrawc  GDRAWC
241 # define gdrawx  GDRAWX 
242 # define gdhead  GDHEAD
243 # define gdwmn1  GDWMN1
244 # define gdwmn2  GDWMN2
245 # define gdwmn3  GDWMN3
246 # define gdxyz   GDXYZ
247 # define gdcxyz  GDCXYZ
248 # define gdman   GDMAN
249 # define gdfspc  GDFSPC
250 # define gdspec  GDSPEC
251 # define gdtree  GDTREE
252 # define gdelet  GDELET
253 # define gdclos  GDCLOS
254 # define gdshow  GDSHOW
255 # define gdopen  GDOPEN
256 # define dzshow  DZSHOW 
257 # define gsatt   GSATT 
258 # define gfpara  GFPARA
259 # define gckpar  GCKPAR
260 # define gckmat  GCKMAT
261 # define geditv  GEDITV
262 # define mzdrop  MZDROP 
263
264 # define ertrak  ERTRAK
265 # define ertrgo  ERTRGO
266  
267 # define setbomb SETBOMB
268 # define setclip SETCLIP
269 # define gcomad  GCOMAD
270  
271 # define gbrelm GBRELM
272 # define gprelm GPRELM
273
274 #endif 
275
276 //____________________________________________________________________________ 
277 extern "C" 
278 {
279   //
280   // Prototypes for GEANT functions
281   //
282   void type_of_call gzebra(const int&); 
283
284   void type_of_call gpcxyz(); 
285
286   void type_of_call ggclos(); 
287
288   void type_of_call glast(); 
289
290   void type_of_call ginit(); 
291
292   void type_of_call gcinit(); 
293
294   void type_of_call grun(); 
295
296   void type_of_call gtrig(); 
297
298   void type_of_call gtrigc(); 
299
300   void type_of_call gtrigi(); 
301
302   void type_of_call gwork(const int&); 
303
304   void type_of_call gzinit(); 
305
306   void type_of_call gmate(); 
307
308   void type_of_call gpart(); 
309
310   void type_of_call gsdk(Int_t &, Float_t *, Int_t *); 
311
312   void type_of_call gfkine(Int_t &, Float_t *, Float_t *, Int_t &,
313                            Int_t &, Float_t *, Int_t &); 
314
315   void type_of_call gfvert(Int_t &, Float_t *, Int_t &, Int_t &, 
316                            Float_t &, Float_t *, Int_t &); 
317
318   void type_of_call gskine(Float_t *,Int_t &, Int_t &, Float_t *,
319                            Int_t &, Int_t &); 
320
321   void type_of_call gsvert(Float_t *,Int_t &, Int_t &, Float_t *,
322                            Int_t &, Int_t &); 
323
324   void type_of_call gphysi(); 
325
326   void type_of_call gdebug(); 
327
328   void type_of_call gekbin(); 
329
330   void type_of_call gfinds(); 
331
332   void type_of_call gsking(Int_t &); 
333
334   void type_of_call gskpho(Int_t &); 
335
336   void type_of_call gsstak(Int_t &); 
337
338   void type_of_call gsxyz(); 
339
340   void type_of_call gtrack(); 
341
342   void type_of_call gtreve(); 
343
344   void type_of_call gtreve_root(); 
345
346   void type_of_call grndm(Float_t *, const Int_t &); 
347
348   void type_of_call grndmq(Int_t &, Int_t &, const Int_t &,
349                            DEFCHARD DEFCHARL); 
350
351   void type_of_call gdtom(Float_t *, Float_t *, Int_t &); 
352
353   void type_of_call glmoth(DEFCHARD, Int_t &, Int_t &, Int_t *,
354                            Int_t *, Int_t * DEFCHARL); 
355
356   void type_of_call gmedia(Float_t *, Int_t &); 
357
358   void type_of_call gmtod(Float_t *, Float_t *, Int_t &); 
359
360   void type_of_call gsrotm(const Int_t &, const Float_t &, const Float_t &,
361                            const Float_t &, const Float_t &, const Float_t &,
362                            const Float_t &); 
363
364   void type_of_call gprotm(const Int_t &); 
365
366   void type_of_call grfile(const Int_t&, DEFCHARD, 
367                            DEFCHARD DEFCHARL DEFCHARL); 
368
369   void type_of_call gfmate(const Int_t&, DEFCHARD, Float_t &, Float_t &,
370                            Float_t &, Float_t &, Float_t &, Float_t *,
371                            Int_t& DEFCHARL); 
372
373   void type_of_call gfpart(const Int_t&, DEFCHARD, Int_t &, Float_t &,
374                            Float_t &, Float_t &, Float_t *, Int_t & DEFCHARL); 
375
376   void type_of_call gftmed(const Int_t&, DEFCHARD, Int_t &, Int_t &, Int_t &,
377                            Float_t &, Float_t &, Float_t &, Float_t &,
378                            Float_t &, Float_t &, Float_t *, Int_t * DEFCHARL); 
379
380   void type_of_call gftmat(const Int_t&, const Int_t&, DEFCHARD, const Int_t&,
381                            Float_t*, Float_t*
382                            ,Float_t *, Int_t & DEFCHARL);
383
384   void type_of_call gsmate(const Int_t&, DEFCHARD, Float_t &, Float_t &,
385                            Float_t &, Float_t &, Float_t &, Float_t *,
386                            Int_t & DEFCHARL); 
387
388   void type_of_call gsmixt(const Int_t&, DEFCHARD, Float_t *, Float_t *,
389                            Float_t &, Int_t &, Float_t * DEFCHARL); 
390
391   void type_of_call gspart(const Int_t&, DEFCHARD, Int_t &, Float_t &,
392                            Float_t &, Float_t &, Float_t *, Int_t & DEFCHARL); 
393
394
395   void type_of_call gstmed(const Int_t&, DEFCHARD, Int_t &, Int_t &, Int_t &,
396                            Float_t &, Float_t &, Float_t &, Float_t &,
397                            Float_t &, Float_t &, Float_t *, Int_t & DEFCHARL); 
398
399   void type_of_call gsckov(Int_t &itmed, Int_t &npckov, Float_t *ppckov,
400                            Float_t *absco, Float_t *effic, Float_t *rindex);
401   void type_of_call gstpar(const Int_t&, DEFCHARD, Float_t & DEFCHARL); 
402
403   void type_of_call gsdvn(DEFCHARD,DEFCHARD, Int_t &, Int_t &
404                           DEFCHARL DEFCHARL); 
405
406   void type_of_call gsdvn2(DEFCHARD,DEFCHARD, Int_t &, Int_t &, Float_t &,
407                            Int_t & DEFCHARL DEFCHARL); 
408
409   void type_of_call gsdvs(DEFCHARD,DEFCHARD, Float_t &, Int_t &, Int_t &
410                           DEFCHARL DEFCHARL); 
411
412   void type_of_call gsdvs2(DEFCHARD,DEFCHARD, Float_t &, Int_t &, Float_t &,
413                            Int_t & DEFCHARL DEFCHARL); 
414
415   void type_of_call gsdvt(DEFCHARD,DEFCHARD, Float_t &, Int_t &, Int_t &,
416                           Int_t & DEFCHARL DEFCHARL); 
417
418   void type_of_call gsdvt2(DEFCHARD,DEFCHARD, Float_t &, Int_t &, Float_t&,
419                            Int_t &, Int_t & DEFCHARL DEFCHARL); 
420
421   void type_of_call gsord(DEFCHARD, Int_t & DEFCHARL); 
422
423   void type_of_call gspos(DEFCHARD, Int_t &, DEFCHARD, Float_t &, Float_t &,
424                           Float_t &, Int_t &, DEFCHARD DEFCHARL DEFCHARL
425                           DEFCHARL); 
426
427   void type_of_call gsposp(DEFCHARD, Int_t &, DEFCHARD, Float_t &, Float_t &,
428                            Float_t &, Int_t &, DEFCHARD,  
429                            Float_t *, Int_t & DEFCHARL DEFCHARL DEFCHARL); 
430
431   void type_of_call gsvolu(DEFCHARD, DEFCHARD, Int_t &, Float_t *, Int_t &,
432                            Int_t & DEFCHARL DEFCHARL); 
433
434   void type_of_call gsatt(DEFCHARD, DEFCHARD, Int_t & DEFCHARL DEFCHARL); 
435
436   void type_of_call gfpara(DEFCHARD , Int_t&, Int_t&, Int_t&, Int_t&, Float_t*,
437                            Float_t* DEFCHARL);
438
439   void type_of_call gckpar(Int_t&, Int_t&, Float_t*);
440
441   void type_of_call gckmat(Int_t&, DEFCHARD DEFCHARL);
442
443   void type_of_call gprint(DEFCHARD,const int& DEFCHARL); 
444
445   void type_of_call gdinit(); 
446
447   void type_of_call gdopt(DEFCHARD,DEFCHARD DEFCHARL DEFCHARL); 
448   
449   void type_of_call gdraw(DEFCHARD,Float_t &,Float_t &, Float_t &,Float_t &,
450                           Float_t &, Float_t &, Float_t & DEFCHARL); 
451   void type_of_call gdrayt(DEFCHARD,Float_t &,Float_t &, Float_t &,Float_t &,
452                            Float_t &, Float_t &, Float_t & DEFCHARL); 
453   void type_of_call gdrawc(DEFCHARD,Int_t &, Float_t &, Float_t &, Float_t &,
454                           Float_t &, Float_t & DEFCHARL); 
455   void type_of_call gdrawx(DEFCHARD,Float_t &, Float_t &, Float_t &, Float_t &,
456                            Float_t &, Float_t &, Float_t &, Float_t &,
457                            Float_t & DEFCHARL); 
458   void type_of_call gdhead(Int_t &,DEFCHARD, Float_t & DEFCHARL);
459   void type_of_call gdxyz(Int_t &);
460   void type_of_call gdcxyz();
461   void type_of_call gdman(Float_t &, Float_t &);
462   void type_of_call gdwmn1(Float_t &, Float_t &);
463   void type_of_call gdwmn2(Float_t &, Float_t &);
464   void type_of_call gdwmn3(Float_t &, Float_t &);
465   void type_of_call gdspec(DEFCHARD DEFCHARL);
466   void type_of_call gdfspc(DEFCHARD, Int_t &, Int_t & DEFCHARL) {;}
467   void type_of_call gdtree(DEFCHARD, Int_t &, Int_t & DEFCHARL);
468
469   void type_of_call gdopen(Int_t &);
470   void type_of_call gdclos();
471   void type_of_call gdelet(Int_t &);
472   void type_of_call gdshow(Int_t &);
473   void type_of_call geditv(Int_t &) {;}
474
475
476   void type_of_call dzshow(DEFCHARD,const int&,const int&,DEFCHARD,const int&,
477                            const int&, const int&, const int& DEFCHARL
478                            DEFCHARL); 
479
480   void type_of_call mzdrop(Int_t&, Int_t&, DEFCHARD DEFCHARL);
481
482   void type_of_call setbomb(Float_t &);
483   void type_of_call setclip(DEFCHARD, Float_t &,Float_t &,Float_t &,Float_t &,
484                             Float_t &, Float_t & DEFCHARL); 
485   void type_of_call gcomad(DEFCHARD, Int_t*& DEFCHARL); 
486
487   void type_of_call ertrak(const Float_t *const x1, const Float_t *const p1,
488                            const Float_t *x2, const Float_t *p2,
489                            const Int_t &ipa, DEFCHARD DEFCHARL);
490
491   void type_of_call ertrgo();
492   
493     float type_of_call gbrelm(const Float_t &z, const Float_t& t, const Float_t& cut);
494     float type_of_call gprelm(const Float_t &z, const Float_t& t, const Float_t& cut);
495 }
496
497 //
498 // Geant3 global pointer
499 //
500 static Int_t defSize = 600;
501
502 ClassImp(TGeant3) 
503  
504 //____________________________________________________________________________ 
505 TGeant3::TGeant3()
506
507   //
508   // Default constructor
509   //
510
511  
512 //____________________________________________________________________________ 
513 TGeant3::TGeant3(const char *title, Int_t nwgeant) 
514        :AliMC("TGeant3",title) 
515 {
516   //
517   // Standard constructor for TGeant3 with ZEBRA initialisation
518   // 
519    
520   if(nwgeant) {
521     gzebra(nwgeant); 
522     ginit(); 
523     gzinit();
524   } else {
525     gcinit();
526   }
527   //
528   // Load Address of Geant3 commons    
529   LoadAddress(); 
530   //
531   // Zero number of particles
532   fNPDGCodes=0;
533
534
535 //____________________________________________________________________________ 
536 Int_t TGeant3::CurrentMaterial(Float_t &a, Float_t &z, Float_t &dens,
537                                Float_t &radl, Float_t &absl) const
538 {
539   //
540   // Return the parameters of the current material during transport
541   //
542   z     = fGcmate->z;
543   a     = fGcmate->a;
544   dens  = fGcmate->dens;
545   radl  = fGcmate->radl;
546   absl  = fGcmate->absl;
547   return 1;  //this could be the number of elements in mixture
548 }
549    
550 //____________________________________________________________________________ 
551 void TGeant3::DefaultRange()
552
553   //
554   // Set range of current drawing pad to 20x20 cm
555   //
556   if (!higz) {
557     new THIGZ(defSize); 
558     gdinit();
559   }
560   higz->Range(0,0,20,20);
561 }
562
563 //____________________________________________________________________________ 
564 void TGeant3::InitHIGZ() 
565
566   //
567   // Initialise HIGZ
568   //
569   if (!higz) {
570     new THIGZ(defSize); 
571     gdinit();
572   }
573 }
574  
575 //____________________________________________________________________________ 
576 void TGeant3::LoadAddress() 
577
578   //
579   // Assigns the address of the GEANT common blocks to the structures
580   // that allow their access from C++
581   //
582   Int_t *addr;
583   gcomad(PASSCHARD("QUEST"), (int*&) fQuest PASSCHARL("QUEST"));
584   gcomad(PASSCHARD("GCBANK"),(int*&) fGcbank  PASSCHARL("GCBANK"));
585   gcomad(PASSCHARD("GCLINK"),(int*&) fGclink  PASSCHARL("GCLINK"));
586   gcomad(PASSCHARD("GCCUTS"),(int*&) fGccuts  PASSCHARL("GCCUTS"));
587   gcomad(PASSCHARD("GCMULO"),(int*&) fGcmulo  PASSCHARL("GCMULO"));
588   gcomad(PASSCHARD("GCFLAG"),(int*&) fGcflag  PASSCHARL("GCFLAG"));
589   gcomad(PASSCHARD("GCKINE"),(int*&) fGckine  PASSCHARL("GCKINE"));
590   gcomad(PASSCHARD("GCKING"),(int*&) fGcking  PASSCHARL("GCKING"));
591   gcomad(PASSCHARD("GCKIN2"),(int*&) fGckin2  PASSCHARL("GCKIN2"));
592   gcomad(PASSCHARD("GCKIN3"),(int*&) fGckin3  PASSCHARL("GCKIN3"));
593   gcomad(PASSCHARD("GCMATE"),(int*&) fGcmate  PASSCHARL("GCMATE"));
594   gcomad(PASSCHARD("GCTMED"),(int*&) fGctmed  PASSCHARL("GCTMED"));
595   gcomad(PASSCHARD("GCTRAK"),(int*&) fGctrak  PASSCHARL("GCTRAK"));
596   gcomad(PASSCHARD("GCTPOL"),(int*&) fGctpol  PASSCHARL("GCTPOL"));
597   gcomad(PASSCHARD("GCVOLU"),(int*&) fGcvolu  PASSCHARL("GCVOLU"));
598   gcomad(PASSCHARD("GCNUM"), (int*&) fGcnum   PASSCHARL("GCNUM"));
599   gcomad(PASSCHARD("GCSETS"),(int*&) fGcsets  PASSCHARL("GCSETS"));
600   gcomad(PASSCHARD("GCPHYS"),(int*&) fGcphys  PASSCHARL("GCPHYS"));
601   gcomad(PASSCHARD("GCOPTI"),(int*&) fGcopti  PASSCHARL("GCOPTI"));
602   gcomad(PASSCHARD("GCTLIT"),(int*&) fGctlit  PASSCHARL("GCTLIT"));
603   gcomad(PASSCHARD("GCVDMA"),(int*&) fGcvdma  PASSCHARL("GCVDMA"));
604
605   // Commons for GEANE
606   gcomad(PASSCHARD("ERTRIO"),(int*&) fErtrio  PASSCHARL("ERTRIO"));
607   gcomad(PASSCHARD("EROPTS"),(int*&) fEropts  PASSCHARL("EROPTS"));
608   gcomad(PASSCHARD("EROPTC"),(int*&) fEroptc  PASSCHARL("EROPTC"));
609   gcomad(PASSCHARD("ERWORK"),(int*&) fErwork  PASSCHARL("ERWORK"));
610
611   // Variables for ZEBRA store
612   gcomad(PASSCHARD("IQ"), addr  PASSCHARL("IQ"));
613   fZiq = addr;
614   gcomad(PASSCHARD("LQ"), addr  PASSCHARL("LQ"));
615   fZlq = addr;
616   fZq       = (float*)fZiq; 
617
618
619 //_____________________________________________________________________________
620 void TGeant3::GeomIter()
621 {
622   //
623   // Geometry iterator for moving upward in the geometry tree
624   // Initialise the iterator
625   //
626   fNextVol=fGcvolu->nlevel;
627 }
628
629 //____________________________________________________________________________ 
630 void TGeant3::FinishGeometry()
631 {
632   //Close the geometry structure
633   Ggclos();
634 }
635   
636 //____________________________________________________________________________ 
637 Int_t TGeant3::NextVolUp(Text_t *name, Int_t &copy)
638 {
639   //
640   // Geometry iterator for moving upward in the geometry tree
641   // Return next volume up
642   //
643   Int_t i, gname;
644   fNextVol--;
645   if(fNextVol>=0) {
646     gname=fGcvolu->names[fNextVol];
647     copy=fGcvolu->number[fNextVol];
648     i=fGcvolu->lvolum[fNextVol];
649     name = fVolNames[i-1];
650     if(gname == fZiq[fGclink->jvolum+i]) return i;
651     else printf("GeomTree: Volume %s not found in bank\n",name);
652   }
653   return 0;
654 }
655
656 //_____________________________________________________________________________
657 void TGeant3::BuildPhysics()
658 {
659   Gphysi();
660 }
661
662 //_____________________________________________________________________________
663 Int_t TGeant3::CurrentVolID(Int_t &copy) const
664 {
665   //
666   // Returns the current volume ID and copy number
667   //
668   Int_t i, gname;
669   if( (i=fGcvolu->nlevel-1) < 0 ) {
670     Warning("CurrentVolID","Stack depth only %d\n",fGcvolu->nlevel);
671   } else {
672     gname=fGcvolu->names[i];
673     copy=fGcvolu->number[i];
674     i=fGcvolu->lvolum[i];   
675     if(gname == fZiq[fGclink->jvolum+i]) return i;
676     else Warning("CurrentVolID","Volume %4s not found\n",(char*)&gname);
677   }
678   return 0;
679 }
680
681 //_____________________________________________________________________________
682 Int_t TGeant3::CurrentVolOffID(Int_t off, Int_t &copy) const
683 {
684   //
685   // Return the current volume "off" upward in the geometrical tree 
686   // ID and copy number
687   //
688   Int_t i, gname;
689   if( (i=fGcvolu->nlevel-off-1) < 0 ) {
690     Warning("CurrentVolOffID","Offset requested %d but stack depth %d\n",
691             off,fGcvolu->nlevel);
692   } else {
693     gname=fGcvolu->names[i];
694     copy=fGcvolu->number[i];          
695     i=fGcvolu->lvolum[i];    
696     if(gname == fZiq[fGclink->jvolum+i]) return i;
697     else Warning("CurrentVolOffID","Volume %4s not found\n",(char*)&gname);
698   }
699   return 0;
700 }
701
702 //_____________________________________________________________________________
703 const char* TGeant3::CurrentVolName() const
704 {
705   //
706   // Returns the current volume name
707   //
708   Int_t i, gname;
709   if( (i=fGcvolu->nlevel-1) < 0 ) {
710     Warning("CurrentVolName","Stack depth %d\n",fGcvolu->nlevel);
711   } else {
712     gname=fGcvolu->names[i];
713     i=fGcvolu->lvolum[i];   
714     if(gname == fZiq[fGclink->jvolum+i]) return fVolNames[i-1];
715     else Warning("CurrentVolName","Volume %4s not found\n",(char*) &gname);
716   }
717   return 0;
718 }
719
720 //_____________________________________________________________________________
721 const char* TGeant3::CurrentVolOffName(Int_t off) const
722 {
723   //
724   // Return the current volume "off" upward in the geometrical tree 
725   // ID, name and copy number
726   // if name=0 no name is returned
727   //
728   Int_t i, gname;
729   if( (i=fGcvolu->nlevel-off-1) < 0 ) {
730     Warning("CurrentVolOffName",
731             "Offset requested %d but stack depth %d\n",off,fGcvolu->nlevel);
732   } else {
733     gname=fGcvolu->names[i];
734     i=fGcvolu->lvolum[i];    
735     if(gname == fZiq[fGclink->jvolum+i]) return fVolNames[i-1];
736     else Warning("CurrentVolOffName","Volume %4s not found\n",(char*)&gname);
737   }
738   return 0;
739 }
740
741 //_____________________________________________________________________________
742 Int_t TGeant3::IdFromPDG(Int_t pdg) const 
743 {
744   //
745   // Return Geant3 code from PDG and pseudo ENDF code
746
747   for(Int_t i=0;i<fNPDGCodes;++i)
748     if(pdg==fPDGCode[i]) return i;
749   return -1;
750 }
751
752 //_____________________________________________________________________________
753 Int_t TGeant3::PDGFromId(Int_t id) const 
754 {
755   if(id>0 && id<fNPDGCodes) return fPDGCode[id];
756   else return -1;
757 }
758
759 //_____________________________________________________________________________
760 void TGeant3::DefineParticles() 
761 {
762   //
763   // Define standard Geant 3 particles
764   Gpart();
765   //
766   // Load standard numbers for GEANT particles and PDG conversion
767   fPDGCode[fNPDGCodes++]=-99;   //  0 = unused location
768   fPDGCode[fNPDGCodes++]=22;    //  1 = photon
769   fPDGCode[fNPDGCodes++]=-11;   //  2 = positron
770   fPDGCode[fNPDGCodes++]=11;    //  3 = electron
771   fPDGCode[fNPDGCodes++]=12;    //  4 = neutrino e
772   fPDGCode[fNPDGCodes++]=-13;   //  5 = muon +
773   fPDGCode[fNPDGCodes++]=13;    //  6 = muon -
774   fPDGCode[fNPDGCodes++]=111;   //  7 = pi0
775   fPDGCode[fNPDGCodes++]=211;   //  8 = pi+
776   fPDGCode[fNPDGCodes++]=-211;  //  9 = pi-
777   fPDGCode[fNPDGCodes++]=130;   // 10 = Kaon Long
778   fPDGCode[fNPDGCodes++]=321;   // 11 = Kaon +
779   fPDGCode[fNPDGCodes++]=-321;  // 12 = Kaon -
780   fPDGCode[fNPDGCodes++]=2112;  // 13 = Neutron
781   fPDGCode[fNPDGCodes++]=2212;  // 14 = Proton
782   fPDGCode[fNPDGCodes++]=-2212; // 15 = Anti Proton
783   fPDGCode[fNPDGCodes++]=310;   // 16 = Kaon Short
784   fPDGCode[fNPDGCodes++]=221;   // 17 = Eta
785   fPDGCode[fNPDGCodes++]=3122;  // 18 = Lambda
786   fPDGCode[fNPDGCodes++]=3222;  // 19 = Sigma +
787   fPDGCode[fNPDGCodes++]=3212;  // 20 = Sigma 0
788   fPDGCode[fNPDGCodes++]=3112;  // 21 = Sigma -
789   fPDGCode[fNPDGCodes++]=3322;  // 22 = Xi0
790   fPDGCode[fNPDGCodes++]=3312;  // 23 = Xi-
791   fPDGCode[fNPDGCodes++]=3334;  // 24 = Omega-
792   fPDGCode[fNPDGCodes++]=-2112; // 25 = Anti Proton
793   fPDGCode[fNPDGCodes++]=-3122; // 26 = Anti Proton
794   fPDGCode[fNPDGCodes++]=-3222; // 27 = Anti Sigma -
795   fPDGCode[fNPDGCodes++]=-3212; // 28 = Anti Sigma 0
796   fPDGCode[fNPDGCodes++]=-3112; // 29 = Anti Sigma 0
797   fPDGCode[fNPDGCodes++]=-3322; // 30 = Anti Xi 0
798   fPDGCode[fNPDGCodes++]=-3312; // 31 = Anti Xi +
799   fPDGCode[fNPDGCodes++]=-3334; // 32 = Anti Omega +
800
801
802   Int_t mode[6];
803   Int_t kz, ipa;
804   Float_t bratio[6];
805
806   /* --- Define additional particles */
807   Gspart(33, "OMEGA(782)", 3, 0.782, 0., 7.836e-23);
808   fPDGCode[fNPDGCodes++]=223;   // 33 = Omega(782)
809   
810   Gspart(34, "PHI(1020)", 3, 1.019, 0., 1.486e-22);
811   fPDGCode[fNPDGCodes++]=333;   // 34 = PHI (1020)
812
813   Gspart(35, "D +", 4, 1.87, 1., 1.066e-12);
814   fPDGCode[fNPDGCodes++]=411;   // 35 = D+
815
816   Gspart(36, "D -", 4, 1.87, -1., 1.066e-12);
817   fPDGCode[fNPDGCodes++]=-411;  // 36 = D-
818
819   Gspart(37, "D 0", 3, 1.865, 0., 4.2e-13);
820   fPDGCode[fNPDGCodes++]=421;   // 37 = D0
821
822   Gspart(38, "ANTI D 0", 3, 1.865, 0., 4.2e-13);
823   fPDGCode[fNPDGCodes++]=-421;  // 38 = D0 bar
824
825   fPDGCode[fNPDGCodes++]=-99;  // 39 = unassigned
826
827   fPDGCode[fNPDGCodes++]=-99;  // 40 = unassigned
828
829   fPDGCode[fNPDGCodes++]=-99;  // 41 = unassigned
830
831   Gspart(42, "RHO +", 4, 0.768, 1., 4.353e-24);
832   fPDGCode[fNPDGCodes++]=213;   // 42 = RHO+
833
834   Gspart(43, "RHO -", 4, 0.768, -1., 4.353e-24);
835   fPDGCode[fNPDGCodes++]=-213;   // 40 = RHO-
836
837   Gspart(44, "RHO 0", 3, 0.768, 0., 4.353e-24);
838   fPDGCode[fNPDGCodes++]=113;   // 37 = D0
839
840   //
841   // Use ENDF-6 mapping for ions = 10000*z+10*a+iso
842   // and add 1 000 000
843   // and numbers above 5 000 000 for special applications
844   //
845
846   const Int_t kion=10000000;
847
848   const Int_t kspe=50000000;
849
850   TDatabasePDG *pdgDB = TDatabasePDG::Instance();
851
852   const Double_t autogev=0.9314943228;
853   const Double_t hslash = 1.0545726663e-27;
854   const Double_t erggev = 1/1.6021773349e-3;
855   const Double_t hshgev = hslash*erggev;
856   const Double_t yearstosec = 3600*24*365.25;
857
858
859   pdgDB->AddParticle("Deuteron","Deuteron",2*autogev+8.071e-3,kTRUE,
860                      0,1,"Ion",kion+10020);
861   fPDGCode[fNPDGCodes++]=kion+10020;   // 45 = Deuteron
862
863   pdgDB->AddParticle("Triton","Triton",3*autogev+14.931e-3,kFALSE,
864                      hshgev/(12.33*yearstosec),1,"Ion",kion+10030);
865   fPDGCode[fNPDGCodes++]=kion+10030;   // 46 = Triton
866
867   pdgDB->AddParticle("Alpha","Alpha",4*autogev+2.424e-3,kTRUE,
868                      hshgev/(12.33*yearstosec),2,"Ion",kion+20040);
869   fPDGCode[fNPDGCodes++]=kion+20040;   // 47 = Alpha
870
871   fPDGCode[fNPDGCodes++]=0;   // 48 = geantino mapped to rootino
872
873   pdgDB->AddParticle("HE3","HE3",3*autogev+14.931e-3,kFALSE,
874                      0,2,"Ion",kion+20030);
875   fPDGCode[fNPDGCodes++]=kion+20030;   // 49 = HE3
876
877   pdgDB->AddParticle("Cherenkov","Cherenkov",0,kFALSE,
878                      0,0,"Special",kspe+50);
879   fPDGCode[fNPDGCodes++]=kspe+50;   // 50 = Cherenkov
880
881   Gspart(51, "FeedbackPhoton", 7, 0., 0.,1.e20 );
882   pdgDB->AddParticle("FeedbackPhoton","FeedbackPhoton",0,kFALSE,
883                      0,0,"Special",kspe+51);
884   fPDGCode[fNPDGCodes++]=kspe+51;   // 51 = FeedbackPhoton
885
886 /* --- Define additional decay modes --- */
887 /* --- omega(783) --- */
888     for (kz = 0; kz < 6; ++kz) {
889         bratio[kz] = 0.;
890         mode[kz] = 0;
891     }
892     ipa = 33;
893     bratio[0] = 89.;
894     bratio[1] = 8.5;
895     bratio[2] = 2.5;
896     mode[0] = 70809;
897     mode[1] = 107;
898     mode[2] = 908;
899     Gsdk(ipa, bratio, mode);
900 /* --- phi(1020) --- */
901     for (kz = 0; kz < 6; ++kz) {
902         bratio[kz] = 0.;
903         mode[kz] = 0;
904     }
905     ipa = 34;
906     bratio[0] = 49.;
907     bratio[1] = 34.4;
908     bratio[2] = 12.9;
909     bratio[3] = 2.4;
910     bratio[4] = 1.3;
911     mode[0] = 1112;
912     mode[1] = 1610;
913     mode[2] = 4407;
914     mode[3] = 90807;
915     mode[4] = 1701;
916     Gsdk(ipa, bratio, mode);
917 /* --- D+ --- */
918     for (kz = 0; kz < 6; ++kz) {
919         bratio[kz] = 0.;
920         mode[kz] = 0;
921     }
922     ipa = 35;
923     bratio[0] = 25.;
924     bratio[1] = 25.;
925     bratio[2] = 25.;
926     bratio[3] = 25.;
927     mode[0] = 80809;
928     mode[1] = 120808;
929     mode[2] = 111208;
930     mode[3] = 110809;
931     Gsdk(ipa, bratio, mode);
932 /* --- D- --- */
933     for (kz = 0; kz < 6; ++kz) {
934         bratio[kz] = 0.;
935         mode[kz] = 0;
936     }
937     ipa = 36;
938     bratio[0] = 25.;
939     bratio[1] = 25.;
940     bratio[2] = 25.;
941     bratio[3] = 25.;
942     mode[0] = 90908;
943     mode[1] = 110909;
944     mode[2] = 121109;
945     mode[3] = 120908;
946     Gsdk(ipa, bratio, mode);
947 /* --- D0 --- */
948     for (kz = 0; kz < 6; ++kz) {
949         bratio[kz] = 0.;
950         mode[kz] = 0;
951     }
952     ipa = 37;
953     bratio[0] = 33.;
954     bratio[1] = 33.;
955     bratio[2] = 33.;
956     mode[0] = 809;
957     mode[1] = 1208;
958     mode[2] = 1112;
959     Gsdk(ipa, bratio, mode);
960 /* --- Anti D0 --- */
961     for (kz = 0; kz < 6; ++kz) {
962         bratio[kz] = 0.;
963         mode[kz] = 0;
964     }
965     ipa = 38;
966     bratio[0] = 33.;
967     bratio[1] = 33.;
968     bratio[2] = 33.;
969     mode[0] = 809;
970     mode[1] = 1109;
971     mode[2] = 1112;
972     Gsdk(ipa, bratio, mode);
973 /* --- rho+ --- */
974     for (kz = 0; kz < 6; ++kz) {
975         bratio[kz] = 0.;
976         mode[kz] = 0;
977     }
978     ipa = 42;
979     bratio[0] = 100.;
980     mode[0] = 807;
981     Gsdk(ipa, bratio, mode);
982 /* --- rho- --- */
983     for (kz = 0; kz < 6; ++kz) {
984         bratio[kz] = 0.;
985         mode[kz] = 0;
986     }
987     ipa = 43;
988     bratio[0] = 100.;
989     mode[0] = 907;
990     Gsdk(ipa, bratio, mode);
991 /* --- rho0 --- */
992     for (kz = 0; kz < 6; ++kz) {
993         bratio[kz] = 0.;
994         mode[kz] = 0;
995     }
996     ipa = 44;
997     bratio[0] = 100.;
998     mode[0] = 707;
999     Gsdk(ipa, bratio, mode);
1000     /*
1001 // --- jpsi ---
1002     for (kz = 0; kz < 6; ++kz) {
1003         bratio[kz] = 0.;
1004         mode[kz] = 0;
1005     }
1006     ipa = 113;
1007     bratio[0] = 50.;
1008     bratio[1] = 50.;
1009     mode[0] = 506;
1010     mode[1] = 605;
1011     Gsdk(ipa, bratio, mode);
1012 // --- upsilon --- 
1013     ipa = 114;
1014     Gsdk(ipa, bratio, mode);
1015 // --- phi --- 
1016     ipa = 115;
1017     Gsdk(ipa, bratio, mode);
1018     */
1019
1020 }
1021
1022 //_____________________________________________________________________________
1023 Int_t TGeant3::VolId(const Text_t *name) const
1024 {
1025   //
1026   // Return the unique numeric identifier for volume name
1027   //
1028   Int_t gname, i;
1029   strncpy((char *) &gname, name, 4);
1030   for(i=1; i<=fGcnum->nvolum; i++)
1031     if(gname == fZiq[fGclink->jvolum+i]) return i;
1032   printf("VolId: Volume %s not found\n",name);
1033   return 0;
1034 }
1035
1036 //_____________________________________________________________________________
1037 Int_t TGeant3::NofVolumes() const 
1038 {
1039   //
1040   // Return total number of volumes in the geometry
1041   //
1042   return fGcnum->nvolum;
1043 }
1044
1045 //_____________________________________________________________________________
1046 const char* TGeant3::VolName(Int_t id) const
1047 {
1048   //
1049   // Return the volume name given the volume identifier
1050   //
1051   const char name[5]="NULL";
1052   if(id<1 || id > fGcnum->nvolum || fGclink->jvolum<=0) 
1053     return name;
1054   else
1055     return fVolNames[id-1];
1056 }
1057
1058 //_____________________________________________________________________________
1059 void    TGeant3::SetCut(const char* cutName, Float_t cutValue)
1060 {
1061   if(!strcmp(cutName,"CUTGAM")) 
1062     fGccuts->cutgam=cutValue; 
1063   else if(!strcmp(cutName,"CUTGAM")) 
1064     fGccuts->cutele=cutValue; 
1065   else if(!strcmp(cutName,"CUTELE")) 
1066     fGccuts->cutneu=cutValue; 
1067   else if(!strcmp(cutName,"CUTHAD")) 
1068     fGccuts->cuthad=cutValue; 
1069   else if(!strcmp(cutName,"CUTMUO")) 
1070     fGccuts->cutmuo=cutValue; 
1071   else if(!strcmp(cutName,"BCUTE")) 
1072     fGccuts->bcute=cutValue; 
1073   else if(!strcmp(cutName,"BCUTM")) 
1074     fGccuts->bcutm=cutValue; 
1075   else if(!strcmp(cutName,"DCUTE")) 
1076     fGccuts->dcute=cutValue; 
1077   else if(!strcmp(cutName,"DCUTM")) 
1078     fGccuts->dcutm=cutValue; 
1079   else if(!strcmp(cutName,"PPCUTM")) 
1080     fGccuts->ppcutm=cutValue; 
1081   else if(!strcmp(cutName,"TOFMAX")) 
1082     fGccuts->tofmax=cutValue; 
1083   else Warning("SetCut","Cut %s not implemented\n",cutName);
1084 }
1085
1086 //_____________________________________________________________________________
1087 void    TGeant3::SetProcess(const char* flagName, Int_t flagValue)
1088 {
1089   if(!strcmp(flagName,"PAIR")) 
1090     fGcphys->ipair=flagValue;
1091   else if(!strcmp(flagName,"COMP")) 
1092     fGcphys->icomp=flagValue;
1093   else if(!strcmp(flagName,"PHOT")) 
1094     fGcphys->iphot=flagValue;
1095   else if(!strcmp(flagName,"PFIS")) 
1096     fGcphys->ipfis=flagValue;
1097   else if(!strcmp(flagName,"DRAY")) 
1098     fGcphys->idray=flagValue;
1099   else if(!strcmp(flagName,"ANNI")) 
1100     fGcphys->ianni=flagValue;
1101   else if(!strcmp(flagName,"BREM")) 
1102     fGcphys->ibrem=flagValue;
1103   else if(!strcmp(flagName,"HADR")) 
1104     fGcphys->ihadr=flagValue;
1105   else if(!strcmp(flagName,"MUNU")) 
1106     fGcphys->imunu=flagValue;
1107   else if(!strcmp(flagName,"DCAY")) 
1108     fGcphys->idcay=flagValue;
1109   else if(!strcmp(flagName,"LOSS")) 
1110     fGcphys->iloss=flagValue;
1111   else if(!strcmp(flagName,"MULS")) 
1112     fGcphys->imuls=flagValue;
1113   else if(!strcmp(flagName,"RAYL")) 
1114     fGcphys->irayl=flagValue;
1115   else  Warning("SetFlag","Flag %s not implemented\n",flagName);
1116 }
1117
1118 //_____________________________________________________________________________
1119 Float_t TGeant3::Xsec(char* reac, Float_t energy, Int_t part, Int_t mate)
1120 {
1121   Int_t gpart = IdFromPDG(part);
1122   if(!strcmp(reac,"PHOT"))
1123   {
1124     if(part!=22) {
1125       Error("Xsec","Can calculate photoelectric only for photons\n");
1126     }
1127   }
1128   return 0;
1129 }
1130
1131 //_____________________________________________________________________________
1132 void TGeant3::TrackPosition(TLorentzVector &xyz) const
1133 {
1134   //
1135   // Return the current position in the master reference frame of the
1136   // track being transported
1137   //
1138   xyz[0]=fGctrak->vect[0];
1139   xyz[1]=fGctrak->vect[1];
1140   xyz[2]=fGctrak->vect[2];
1141   xyz[3]=fGctrak->tofg;
1142 }
1143
1144 //_____________________________________________________________________________
1145 Float_t TGeant3::TrackTime() const
1146 {
1147   //
1148   // Return the current time of flight of the track being transported
1149   //
1150   return fGctrak->tofg;
1151 }
1152
1153 //_____________________________________________________________________________
1154 void TGeant3::TrackMomentum(TLorentzVector &xyz) const
1155 {
1156   //
1157   // Return the direction and the momentum (GeV/c) of the track
1158   // currently being transported
1159   //
1160   Double_t ptot=fGctrak->vect[6];
1161   xyz[0]=fGctrak->vect[3]*ptot;
1162   xyz[1]=fGctrak->vect[4]*ptot;
1163   xyz[2]=fGctrak->vect[5]*ptot;
1164   xyz[3]=fGctrak->getot;
1165 }
1166
1167 //_____________________________________________________________________________
1168 Float_t TGeant3::TrackCharge() const
1169 {
1170   //
1171   // Return charge of the track currently transported
1172   //
1173   return fGckine->charge;
1174 }
1175
1176 //_____________________________________________________________________________
1177 Float_t TGeant3::TrackMass() const
1178 {
1179   //
1180   // Return the mass of the track currently transported
1181   //
1182   return fGckine->amass;
1183 }
1184
1185 //_____________________________________________________________________________
1186 Int_t TGeant3::TrackPid() const
1187 {
1188   //
1189   // Return the id of the particle transported
1190   //
1191   return PDGFromId(fGckine->ipart);
1192 }
1193
1194 //_____________________________________________________________________________
1195 Float_t TGeant3::TrackStep() const
1196 {
1197   //
1198   // Return the length in centimeters of the current step
1199   //
1200   return fGctrak->step;
1201 }
1202
1203 //_____________________________________________________________________________
1204 Float_t TGeant3::TrackLength() const
1205 {
1206   //
1207   // Return the length of the current track from its origin
1208   //
1209   return fGctrak->sleng;
1210 }
1211
1212 //_____________________________________________________________________________
1213 Bool_t TGeant3::IsNewTrack() const
1214 {
1215   //
1216   // True if the track is not at the boundary of the current volume
1217   //
1218   return (fGctrak->sleng>0);
1219 }
1220
1221 //_____________________________________________________________________________
1222 Bool_t TGeant3::IsTrackInside() const
1223 {
1224   //
1225   // True if the track is not at the boundary of the current volume
1226   //
1227   return (fGctrak->inwvol==0);
1228 }
1229
1230 //_____________________________________________________________________________
1231 Bool_t TGeant3::IsTrackEntering() const
1232 {
1233   //
1234   // True if this is the first step of the track in the current volume
1235   //
1236   return (fGctrak->inwvol==1);
1237 }
1238
1239 //_____________________________________________________________________________
1240 Bool_t TGeant3::IsTrackExiting() const
1241 {
1242   //
1243   // True if this is the last step of the track in the current volume
1244   //
1245   return (fGctrak->inwvol==2);
1246 }
1247
1248 //_____________________________________________________________________________
1249 Bool_t TGeant3::IsTrackOut() const
1250 {
1251   //
1252   // True if the track is out of the setup
1253   //
1254   return (fGctrak->inwvol==3);
1255 }
1256
1257 //_____________________________________________________________________________
1258 Bool_t TGeant3::IsTrackStop() const
1259 {
1260   //
1261   // True if the track energy has fallen below the threshold 
1262   //
1263   return (fGctrak->istop==2);
1264 }
1265
1266 //_____________________________________________________________________________
1267 Int_t   TGeant3::NSecondaries() const
1268 {
1269   //
1270   // Number of secondary particles generated in the current step
1271   //
1272   return fGcking->ngkine;
1273 }
1274
1275 //_____________________________________________________________________________
1276 Int_t   TGeant3::CurrentEvent() const
1277 {
1278   //
1279   // Number of the current event
1280   //
1281   return fGcflag->idevt;
1282 }
1283
1284 //_____________________________________________________________________________
1285 const char* TGeant3::ProdProcess() const
1286 {
1287   //
1288   // Name of the process that has produced the secondary particles
1289   // in the current step
1290   //
1291   static char proc[5];
1292   const Int_t ipmec[13] = { 5,6,7,8,9,10,11,12,21,23,25,105,108 };
1293   Int_t mec, km, im;
1294   //
1295   if(fGcking->ngkine>0) {
1296     for (km = 0; km < fGctrak->nmec; ++km) {
1297       for (im = 0; im < 13; ++im) {
1298         if (fGctrak->lmec[km] == ipmec[im]) {
1299           mec = fGctrak->lmec[km];
1300           if (0 < mec && mec < 31) {
1301             strncpy(proc,(char *)&fGctrak->namec[mec - 1],4);
1302           } else if (mec - 100 <= 30 && mec - 100 > 0) {
1303             strncpy(proc,(char *)&fGctpol->namec1[mec - 101],4);
1304           }
1305           proc[4]='\0';
1306           return proc;
1307         }
1308       }
1309     }
1310     strcpy(proc,"UNKN");
1311   } else strcpy(proc,"NONE");
1312   return proc;
1313 }
1314
1315 //_____________________________________________________________________________
1316 void    TGeant3::GetSecondary(Int_t isec, Int_t& ipart, 
1317                               TLorentzVector &x, TLorentzVector &p)
1318 {
1319   //
1320   // Get the parameters of the secondary track number isec produced
1321   // in the current step
1322   //
1323   Int_t i;
1324   if(-1<isec && isec<fGcking->ngkine) {
1325     ipart=Int_t (fGcking->gkin[isec][4] +0.5);
1326     for(i=0;i<3;i++) {
1327       x[i]=fGckin3->gpos[isec][i];
1328       p[i]=fGcking->gkin[isec][i];
1329     }
1330     x[3]=fGcking->tofd[isec];
1331     p[3]=fGcking->gkin[isec][3];
1332   } else {
1333     printf(" * TGeant3::GetSecondary * Secondary %d does not exist\n",isec);
1334     x[0]=x[1]=x[2]=x[3]=p[0]=p[1]=p[2]=p[3]=0;
1335     ipart=0;
1336   }
1337 }
1338
1339 //_____________________________________________________________________________
1340 void TGeant3::InitLego()
1341 {
1342   SetSWIT(4,0);
1343   SetDEBU(0,0,0);  //do not print a message 
1344 }
1345
1346 //_____________________________________________________________________________
1347 Bool_t TGeant3::IsTrackDisappeared() const
1348 {
1349   //
1350   // True if the current particle has disappered
1351   // either because it decayed or because it underwent
1352   // an inelastic collision
1353   //
1354   return (fGctrak->istop==1);
1355 }
1356
1357 //_____________________________________________________________________________
1358 Bool_t TGeant3::IsTrackAlive() const
1359 {
1360   //
1361   // True if the current particle is alive and will continue to be
1362   // transported
1363   //
1364   return (fGctrak->istop==0);
1365 }
1366
1367 //_____________________________________________________________________________
1368 void TGeant3::StopTrack()
1369 {
1370   //
1371   // Stop the transport of the current particle and skip to the next
1372   //
1373   fGctrak->istop=1;
1374 }
1375
1376 //_____________________________________________________________________________
1377 void TGeant3::StopEvent()
1378 {
1379   //
1380   // Stop simulation of the current event and skip to the next
1381   //
1382   fGcflag->ieotri=1;
1383 }
1384
1385 //_____________________________________________________________________________
1386 Float_t TGeant3::MaxStep() const
1387 {
1388   //
1389   // Return the maximum step length in the current medium
1390   //
1391   return fGctmed->stemax;
1392 }
1393
1394 //_____________________________________________________________________________
1395 void TGeant3::SetMaxStep(Float_t maxstep)
1396 {
1397   //
1398   // Set the maximum step allowed till the particle is in the current medium
1399   //
1400   fGctmed->stemax=maxstep;
1401 }
1402
1403 //_____________________________________________________________________________
1404 void TGeant3::SetMaxNStep(Int_t maxnstp)
1405 {
1406   //
1407   // Set the maximum number of steps till the particle is in the current medium
1408   //
1409   fGctrak->maxnst=maxnstp;
1410 }
1411
1412 //_____________________________________________________________________________
1413 Int_t TGeant3::GetMaxNStep() const
1414 {
1415   //
1416   // Maximum number of steps allowed in current medium
1417   //
1418   return fGctrak->maxnst;
1419 }
1420
1421 //_____________________________________________________________________________
1422 void TGeant3::Material(Int_t& kmat, const char* name, Float_t a, Float_t z,
1423                        Float_t dens, Float_t radl, Float_t absl, Float_t* buf,
1424                        Int_t nwbuf)
1425 {
1426   //
1427   // Defines a Material
1428   // 
1429   //  kmat               number assigned to the material
1430   //  name               material name
1431   //  a                  atomic mass in au
1432   //  z                  atomic number
1433   //  dens               density in g/cm3
1434   //  absl               absorbtion length in cm
1435   //                     if >=0 it is ignored and the program 
1436   //                     calculates it, if <0. -absl is taken
1437   //  radl               radiation length in cm
1438   //                     if >=0 it is ignored and the program 
1439   //                     calculates it, if <0. -radl is taken
1440   //  buf                pointer to an array of user words
1441   //  nbuf               number of user words
1442   //
1443   Int_t jmate=fGclink->jmate;
1444   kmat=1;
1445   Int_t ns, i;
1446   if(jmate>0) {
1447     ns=fZiq[jmate-2];
1448     kmat=ns+1;
1449     for(i=1; i<=ns; i++) {
1450       if(fZlq[jmate-i]==0) {
1451         kmat=i;
1452         break;
1453       }
1454     }
1455   }
1456   gsmate(kmat,PASSCHARD(name), a, z, dens, radl, absl, buf,
1457          nwbuf PASSCHARL(name)); 
1458 }
1459
1460 //_____________________________________________________________________________
1461 void TGeant3::Mixture(Int_t& kmat, const char* name, Float_t* a, Float_t* z, 
1462                       Float_t dens, Int_t nlmat, Float_t* wmat)
1463 {
1464   //
1465   // Defines mixture OR COMPOUND IMAT as composed by 
1466   // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
1467   // 
1468   // If NLMAT > 0 then wmat contains the proportion by
1469   // weights of each basic material in the mixture. 
1470   // 
1471   // If nlmat < 0 then WMAT contains the number of atoms 
1472   // of a given kind into the molecule of the COMPOUND
1473   // In this case, WMAT in output is changed to relative
1474   // weigths.
1475   //
1476   Int_t jmate=fGclink->jmate;
1477   kmat=1;
1478   Int_t ns, i;
1479   if(jmate>0) {
1480     ns=fZiq[jmate-2];
1481     kmat=ns+1;
1482     for(i=1; i<=ns; i++) {
1483       if(fZlq[jmate-i]==0) {
1484         kmat=i;
1485         break;
1486       }
1487     }
1488   }
1489   gsmixt(kmat,PASSCHARD(name), a, z,dens, nlmat,wmat PASSCHARL(name)); 
1490 }
1491
1492 //_____________________________________________________________________________
1493 void TGeant3::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
1494                      Int_t ifield, Float_t fieldm, Float_t tmaxfd,
1495                      Float_t stemax, Float_t deemax, Float_t epsil,
1496                      Float_t stmin, Float_t* ubuf, Int_t nbuf)
1497 {
1498   //
1499   //  kmed      tracking medium number assigned
1500   //  name      tracking medium name
1501   //  nmat      material number
1502   //  isvol     sensitive volume flag
1503   //  ifield    magnetic field
1504   //  fieldm    max. field value (kilogauss)
1505   //  tmaxfd    max. angle due to field (deg/step)
1506   //  stemax    max. step allowed
1507   //  deemax    max. fraction of energy lost in a step
1508   //  epsil     tracking precision (cm)
1509   //  stmin     min. step due to continuos processes (cm)
1510   //
1511   //  ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
1512   //  ifield = 1 if tracking performed with grkuta; ifield = 2 if tracking
1513   //  performed with ghelix; ifield = 3 if tracking performed with ghelx3.
1514   //  
1515   Int_t jtmed=fGclink->jtmed;
1516   kmed=1;
1517   Int_t ns, i;
1518   if(jtmed>0) {
1519     ns=fZiq[jtmed-2];
1520     kmed=ns+1;
1521     for(i=1; i<=ns; i++) {
1522       if(fZlq[jtmed-i]==0) {
1523         kmed=i;
1524         break;
1525       }
1526     }
1527   }
1528   gstmed(kmed, PASSCHARD(name), nmat, isvol, ifield, fieldm, tmaxfd, stemax,
1529          deemax, epsil, stmin, ubuf, nbuf PASSCHARL(name)); 
1530 }
1531
1532 //_____________________________________________________________________________
1533 void TGeant3::Matrix(Int_t& krot, Float_t thex, Float_t phix, Float_t they,
1534                      Float_t phiy, Float_t thez, Float_t phiz)
1535 {
1536   //
1537   //  krot     rotation matrix number assigned
1538   //  theta1   polar angle for axis i
1539   //  phi1     azimuthal angle for axis i
1540   //  theta2   polar angle for axis ii
1541   //  phi2     azimuthal angle for axis ii
1542   //  theta3   polar angle for axis iii
1543   //  phi3     azimuthal angle for axis iii
1544   //
1545   //  it defines the rotation matrix number irot.
1546   //  
1547   Int_t jrotm=fGclink->jrotm;
1548   krot=1;
1549   Int_t ns, i;
1550   if(jrotm>0) {
1551     ns=fZiq[jrotm-2];
1552     krot=ns+1;
1553     for(i=1; i<=ns; i++) {
1554       if(fZlq[jrotm-i]==0) {
1555         krot=i;
1556         break;
1557       }
1558     }
1559   }
1560   gsrotm(krot, thex, phix, they, phiy, thez, phiz);
1561 }
1562
1563 //_____________________________________________________________________________
1564 Int_t TGeant3::GetMedium() const
1565 {
1566   //
1567   // Return the number of the current medium
1568   //
1569   return fGctmed->numed;
1570 }
1571
1572 //_____________________________________________________________________________
1573 Float_t TGeant3::Edep() const
1574 {
1575   //
1576   // Return the energy lost in the current step
1577   //
1578   return fGctrak->destep;
1579 }
1580
1581 //_____________________________________________________________________________
1582 Float_t TGeant3::Etot() const
1583 {
1584   //
1585   // Return the total energy of the current track
1586   //
1587   return fGctrak->getot;
1588 }
1589
1590 //_____________________________________________________________________________
1591 void TGeant3::Rndm(Float_t* r, const Int_t n) const
1592 {
1593   //
1594   // Return an array of n random numbers uniformly distributed 
1595   // between 0 and 1 not included
1596   //
1597   Grndm(r,n);
1598 }
1599
1600 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1601 //
1602 //                        Functions from GBASE
1603 //
1604 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1605
1606 //____________________________________________________________________________ 
1607 void  TGeant3::Gfile(const char *filename, const char *option) 
1608
1609   //
1610   //    Routine to open a GEANT/RZ data base. 
1611   //
1612   //    LUN logical unit number associated to the file 
1613   //
1614   //    CHFILE RZ file name   
1615   //  
1616   //    CHOPT is a character string which may be  
1617   //        N  To create a new file 
1618   //        U  to open an existing file for update 
1619   //       " " to open an existing file for read only
1620   //        Q  The initial allocation (default 1000 records) 
1621   //           is given in IQUEST(10)
1622   //        X  Open the file in exchange format
1623   //        I  Read all data structures from file to memory 
1624   //        O  Write all data structures from memory to file 
1625   // 
1626   // Note:
1627   //      If options "I"  or "O" all data structures are read or
1628   //         written from/to file and the file is closed. 
1629   //      See routine GRMDIR to create subdirectories  
1630   //      See routines GROUT,GRIN to write,read objects 
1631   //  
1632   grfile(21, PASSCHARD(filename), PASSCHARD(option) PASSCHARL(filename)
1633          PASSCHARL(option)); 
1634
1635  
1636 //____________________________________________________________________________ 
1637 void  TGeant3::Gpcxyz() 
1638
1639   //
1640   //    Print track and volume parameters at current point
1641   //
1642   gpcxyz(); 
1643
1644  
1645 //_____________________________________________________________________________
1646 void  TGeant3::Ggclos() 
1647
1648   //
1649   //   Closes off the geometry setting.
1650   //   Initializes the search list for the contents of each
1651   //   volume following the order they have been positioned, and
1652   //   inserting the content '0' when a call to GSNEXT (-1) has
1653   //   been required by the user.
1654   //   Performs the development of the JVOLUM structure for all 
1655   //   volumes with variable parameters, by calling GGDVLP. 
1656   //   Interprets the user calls to GSORD, through GGORD.
1657   //   Computes and stores in a bank (next to JVOLUM mother bank)
1658   //   the number of levels in the geometrical tree and the
1659   //   maximum number of contents per level, by calling GGNLEV.
1660   //   Sets status bit for CONCAVE volumes, through GGCAVE.
1661   //   Completes the JSET structure with the list of volume names 
1662   //   which identify uniquely a given physical detector, the
1663   //   list of bit numbers to pack the corresponding volume copy 
1664   //   numbers, and the generic path(s) in the JVOLUM tree, 
1665   //   through the routine GHCLOS. 
1666   //
1667   ggclos(); 
1668   // Create internal list of volumes
1669   fVolNames = new char[fGcnum->nvolum][5];
1670   Int_t i;
1671   for(i=0; i<fGcnum->nvolum; ++i) {
1672     strncpy(fVolNames[i], (char *) &fZiq[fGclink->jvolum+i+1], 4);
1673     fVolNames[i][4]='\0';
1674   }
1675
1676  
1677 //_____________________________________________________________________________
1678 void  TGeant3::Glast() 
1679
1680   //
1681   // Finish a Geant run
1682   //
1683   glast(); 
1684
1685  
1686 //_____________________________________________________________________________
1687 void  TGeant3::Gprint(const char *name) 
1688
1689   //
1690   // Routine to print data structures
1691   // CHNAME   name of a data structure
1692   // 
1693   char vname[5];
1694   Vname(name,vname);
1695   gprint(PASSCHARD(vname),0 PASSCHARL(vname)); 
1696
1697
1698 //_____________________________________________________________________________
1699 void  TGeant3::Grun() 
1700
1701   //
1702   // Steering function to process one run
1703   //
1704   grun(); 
1705
1706  
1707 //_____________________________________________________________________________
1708 void  TGeant3::Gtrig() 
1709
1710   //
1711   // Steering function to process one event
1712   //
1713   gtrig(); 
1714
1715  
1716 //_____________________________________________________________________________
1717 void  TGeant3::Gtrigc() 
1718
1719   //
1720   // Clear event partition
1721   //
1722   gtrigc(); 
1723
1724  
1725 //_____________________________________________________________________________
1726 void  TGeant3::Gtrigi() 
1727
1728   //
1729   // Initialises event partition
1730   //
1731   gtrigi(); 
1732
1733  
1734 //_____________________________________________________________________________
1735 void  TGeant3::Gwork(Int_t nwork) 
1736
1737   //
1738   // Allocates workspace in ZEBRA memory
1739   //
1740   gwork(nwork); 
1741
1742  
1743 //_____________________________________________________________________________
1744 void  TGeant3::Gzinit() 
1745
1746   //
1747   // To initialise GEANT/ZEBRA data structures
1748   //
1749   gzinit(); 
1750
1751  
1752 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1753 //
1754 //                        Functions from GCONS
1755 //
1756 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1757  
1758 //_____________________________________________________________________________
1759 void  TGeant3::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,  
1760                       Float_t &dens, Float_t &radl, Float_t &absl,
1761                       Float_t* ubuf, Int_t& nbuf) 
1762
1763   //
1764   // Return parameters for material IMAT 
1765   //
1766   gfmate(imat, PASSCHARD(name), a, z, dens, radl, absl, ubuf, nbuf
1767          PASSCHARL(name)); 
1768
1769  
1770 //_____________________________________________________________________________
1771 void  TGeant3::Gfpart(Int_t ipart, char *name, Int_t &itrtyp,  
1772                    Float_t &amass, Float_t &charge, Float_t &tlife) 
1773
1774   //
1775   // Return parameters for particle of type IPART
1776   //
1777   Float_t *ubuf=0; 
1778   Int_t   nbuf; 
1779   Int_t igpart = IdFromPDG(ipart);
1780   gfpart(igpart, PASSCHARD(name), itrtyp, amass, charge, tlife, ubuf, nbuf
1781          PASSCHARL(name)); 
1782
1783  
1784 //_____________________________________________________________________________
1785 void  TGeant3::Gftmed(Int_t numed, char *name, Int_t &nmat, Int_t &isvol,  
1786                    Int_t &ifield, Float_t &fieldm, Float_t &tmaxfd, 
1787                     Float_t &stemax, Float_t &deemax, Float_t &epsil, 
1788                     Float_t &stmin, Float_t *ubuf, Int_t *nbuf) 
1789
1790   //
1791   // Return parameters for tracking medium NUMED
1792   //
1793   gftmed(numed, PASSCHARD(name), nmat, isvol, ifield, fieldm, tmaxfd, stemax,  
1794          deemax, epsil, stmin, ubuf, nbuf PASSCHARL(name)); 
1795 }
1796
1797  
1798  void  TGeant3::Gftmat(Int_t imate, Int_t ipart, char *chmeca, Int_t kdim,
1799                       Float_t* tkin, Float_t* value, Float_t* pcut,
1800                       Int_t &ixst)
1801
1802   //
1803   // Return parameters for tracking medium NUMED
1804   //
1805   gftmat(imate, ipart, PASSCHARD(chmeca), kdim,
1806          tkin, value, pcut, ixst PASSCHARL(chmeca));
1807
1808
1809
1810 Float_t TGeant3::Gbrelm(Float_t z, Float_t t, Float_t bcut)
1811 {
1812     return gbrelm(z,t,bcut);
1813 }
1814
1815 Float_t TGeant3::Gprelm(Float_t z, Float_t t, Float_t bcut)
1816 {
1817     return gprelm(z,t,bcut);
1818 }
1819  
1820 //_____________________________________________________________________________
1821 void  TGeant3::Gmate() 
1822
1823   //
1824   // Define standard GEANT materials
1825   //
1826   gmate(); 
1827
1828  
1829 //_____________________________________________________________________________
1830 void  TGeant3::Gpart() 
1831
1832   //
1833   //  Define standard GEANT particles plus selected decay modes
1834   //  and branching ratios.
1835   //
1836   gpart(); 
1837
1838  
1839 //_____________________________________________________________________________
1840 void  TGeant3::Gsdk(Int_t ipart, Float_t *bratio, Int_t *mode) 
1841
1842 //  Defines branching ratios and decay modes for standard
1843 //  GEANT particles.
1844    gsdk(ipart,bratio,mode); 
1845
1846  
1847 //_____________________________________________________________________________
1848 void  TGeant3::Gsmate(Int_t imat, const char *name, Float_t a, Float_t z,  
1849                    Float_t dens, Float_t radl, Float_t absl) 
1850
1851   //
1852   // Defines a Material
1853   // 
1854   //  kmat               number assigned to the material
1855   //  name               material name
1856   //  a                  atomic mass in au
1857   //  z                  atomic number
1858   //  dens               density in g/cm3
1859   //  absl               absorbtion length in cm
1860   //                     if >=0 it is ignored and the program 
1861   //                     calculates it, if <0. -absl is taken
1862   //  radl               radiation length in cm
1863   //                     if >=0 it is ignored and the program 
1864   //                     calculates it, if <0. -radl is taken
1865   //  buf                pointer to an array of user words
1866   //  nbuf               number of user words
1867   //
1868   Float_t *ubuf=0; 
1869   Int_t   nbuf=0; 
1870   gsmate(imat,PASSCHARD(name), a, z, dens, radl, absl, ubuf, nbuf
1871          PASSCHARL(name)); 
1872
1873  
1874 //_____________________________________________________________________________
1875 void  TGeant3::Gsmixt(Int_t imat, const char *name, Float_t *a, Float_t *z,  
1876                    Float_t dens, Int_t nlmat, Float_t *wmat) 
1877
1878   //
1879   //       Defines mixture OR COMPOUND IMAT as composed by 
1880   //       THE BASIC NLMAT materials defined by arrays A,Z and WMAT
1881   // 
1882   //       If NLMAT.GT.0 then WMAT contains the PROPORTION BY
1883   //       WEIGTHS OF EACH BASIC MATERIAL IN THE MIXTURE. 
1884   // 
1885   //       If NLMAT.LT.0 then WMAT contains the number of atoms 
1886   //       of a given kind into the molecule of the COMPOUND
1887   //       In this case, WMAT in output is changed to relative
1888   //       weigths.
1889   //
1890   gsmixt(imat,PASSCHARD(name), a, z,dens, nlmat,wmat PASSCHARL(name)); 
1891
1892  
1893 //_____________________________________________________________________________
1894 void  TGeant3::Gspart(Int_t ipart, const char *name, Int_t itrtyp,  
1895                    Float_t amass, Float_t charge, Float_t tlife) 
1896
1897   //
1898   // Store particle parameters
1899   //
1900   // ipart           particle code
1901   // name            particle name
1902   // itrtyp          transport method (see GEANT manual)
1903   // amass           mass in GeV/c2
1904   // charge          charge in electron units
1905   // tlife           lifetime in seconds
1906   //
1907   Float_t *ubuf=0; 
1908   Int_t   nbuf=0; 
1909   gspart(ipart,PASSCHARD(name), itrtyp, amass, charge, tlife, ubuf, nbuf
1910          PASSCHARL(name)); 
1911
1912  
1913 //_____________________________________________________________________________
1914 void  TGeant3::Gstmed(Int_t numed, const char *name, Int_t nmat, Int_t isvol,  
1915                       Int_t ifield, Float_t fieldm, Float_t tmaxfd,
1916                       Float_t stemax, Float_t deemax, Float_t epsil,
1917                       Float_t stmin) 
1918
1919   //
1920   //  NTMED  Tracking medium number
1921   //  NAME   Tracking medium name
1922   //  NMAT   Material number
1923   //  ISVOL  Sensitive volume flag
1924   //  IFIELD Magnetic field
1925   //  FIELDM Max. field value (Kilogauss)
1926   //  TMAXFD Max. angle due to field (deg/step)
1927   //  STEMAX Max. step allowed
1928   //  DEEMAX Max. fraction of energy lost in a step
1929   //  EPSIL  Tracking precision (cm)
1930   //  STMIN  Min. step due to continuos processes (cm)
1931   //
1932   //  IFIELD = 0 if no magnetic field; IFIELD = -1 if user decision in GUSWIM;
1933   //  IFIELD = 1 if tracking performed with GRKUTA; IFIELD = 2 if tracking
1934   //  performed with GHELIX; IFIELD = 3 if tracking performed with GHELX3.
1935   //  
1936   Float_t *ubuf=0; 
1937   Int_t   nbuf=0; 
1938   gstmed(numed,PASSCHARD(name), nmat, isvol, ifield, fieldm, tmaxfd, stemax,
1939          deemax, epsil, stmin, ubuf, nbuf PASSCHARL(name)); 
1940
1941  
1942 //_____________________________________________________________________________
1943 void  TGeant3::Gsckov(Int_t itmed, Int_t npckov, Float_t *ppckov,
1944                       Float_t *absco, Float_t *effic, Float_t *rindex)
1945
1946   //
1947   //    Stores the tables for UV photon tracking in medium ITMED 
1948   //    Please note that it is the user's responsability to 
1949   //    provide all the coefficients:
1950   //
1951   //
1952   //       ITMED       Tracking medium number
1953   //       NPCKOV      Number of bins of each table
1954   //       PPCKOV      Value of photon momentum (in GeV)
1955   //       ABSCO       Absorbtion coefficients 
1956   //                   dielectric: absorbtion length in cm
1957   //                   metals    : absorbtion fraction (0<=x<=1)
1958   //       EFFIC       Detection efficiency for UV photons 
1959   //       RINDEX      Refraction index (if=0 metal)
1960   //
1961   gsckov(itmed,npckov,ppckov,absco,effic,rindex);
1962 }
1963
1964 //_____________________________________________________________________________
1965 void  TGeant3::Gstpar(Int_t itmed, const char *param, Float_t parval) 
1966
1967   //
1968   //  To change the value of cut  or mechanism "CHPAR"
1969   //      to a new value PARVAL  for tracking medium ITMED
1970   //    The  data   structure  JTMED   contains  the   standard  tracking
1971   //  parameters (CUTS and flags to control the physics processes)  which
1972   //  are used  by default  for all  tracking media.   It is  possible to
1973   //  redefine individually  with GSTPAR  any of  these parameters  for a
1974   //  given tracking medium. 
1975   //  ITMED     tracking medium number 
1976   //  CHPAR     is a character string (variable name) 
1977   //  PARVAL    must be given as a floating point.
1978   //
1979   gstpar(itmed,PASSCHARD(param), parval PASSCHARL(param)); 
1980
1981  
1982 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1983 //
1984 //                        Functions from GCONS
1985 //
1986 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1987  
1988 //_____________________________________________________________________________
1989 void  TGeant3::Gfkine(Int_t itra, Float_t *vert, Float_t *pvert, Int_t &ipart,
1990                       Int_t &nvert) 
1991
1992   //           Storing/Retrieving Vertex and Track parameters
1993   //           ---------------------------------------------- 
1994   //
1995   //  Stores vertex parameters. 
1996   //  VERT      array of (x,y,z) position of the vertex 
1997   //  NTBEAM    beam track number origin of the vertex 
1998   //            =0 if none exists  
1999   //  NTTARG    target track number origin of the vertex
2000   //  UBUF      user array of NUBUF floating point numbers
2001   //  NUBUF       
2002   //  NVTX      new vertex number (=0 in case of error). 
2003   //  Prints vertex parameters.
2004   //  IVTX      for vertex IVTX.
2005   //            (For all vertices if IVTX=0) 
2006   //  Stores long life track parameters.
2007   //  PLAB      components of momentum 
2008   //  IPART     type of particle (see GSPART)
2009   //  NV        vertex number origin of track
2010   //  UBUF      array of NUBUF floating point user parameters 
2011   //  NUBUF
2012   //  NT        track number (if=0 error).
2013   //  Retrieves long life track parameters.
2014   //  ITRA      track number for which parameters are requested
2015   //  VERT      vector origin of the track  
2016   //  PVERT     4 momentum components at the track origin 
2017   //  IPART     particle type (=0 if track ITRA does not exist)
2018   //  NVERT     vertex number origin of the track 
2019   //  UBUF      user words stored in GSKINE. 
2020   //  Prints initial track parameters. 
2021   //  ITRA      for track ITRA 
2022   //            (For all tracks if ITRA=0) 
2023   //
2024   Float_t *ubuf=0; 
2025   Int_t   nbuf; 
2026   gfkine(itra,vert,pvert,ipart,nvert,ubuf,nbuf); 
2027
2028
2029 //_____________________________________________________________________________
2030 void  TGeant3::Gfvert(Int_t nvtx, Float_t *v, Int_t &ntbeam, Int_t &nttarg,
2031                       Float_t &tofg) 
2032
2033   //
2034   //       Retrieves the parameter of a vertex bank
2035   //       Vertex is generated from tracks NTBEAM NTTARG
2036   //       NVTX is the new vertex number 
2037   //
2038   Float_t *ubuf=0; 
2039   Int_t   nbuf; 
2040   gfvert(nvtx,v,ntbeam,nttarg,tofg,ubuf,nbuf); 
2041
2042  
2043 //_____________________________________________________________________________
2044 Int_t TGeant3::Gskine(Float_t *plab, Int_t ipart, Int_t nv, Float_t *buf,
2045                       Int_t nwbuf) 
2046
2047   //
2048   //       Store kinematics of track NT into data structure
2049   //       Track is coming from vertex NV
2050   //
2051   Int_t nt = 0; 
2052   gskine(plab, ipart, nv, buf, nwbuf, nt); 
2053   return nt; 
2054
2055  
2056 //_____________________________________________________________________________
2057 Int_t TGeant3::Gsvert(Float_t *v, Int_t ntbeam, Int_t nttarg, Float_t *ubuf,
2058                       Int_t nwbuf) 
2059
2060   //
2061   //       Creates a new vertex bank 
2062   //       Vertex is generated from tracks NTBEAM NTTARG 
2063   //       NVTX is the new vertex number
2064   //
2065   Int_t nwtx = 0; 
2066   gsvert(v, ntbeam, nttarg, ubuf, nwbuf, nwtx); 
2067   return nwtx; 
2068
2069  
2070 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2071 //
2072 //                        Functions from GPHYS
2073 //
2074 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2075
2076 //_____________________________________________________________________________
2077 void  TGeant3::Gphysi() 
2078
2079   //
2080   //       Initialise material constants for all the physics
2081   //       mechanisms used by GEANT
2082   //
2083   gphysi(); 
2084
2085  
2086 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2087 //
2088 //                        Functions from GTRAK
2089 //
2090 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2091  
2092 //_____________________________________________________________________________
2093 void  TGeant3::Gdebug() 
2094
2095   //
2096   // Debug the current step
2097   //
2098   gdebug(); 
2099
2100  
2101 //_____________________________________________________________________________
2102 void  TGeant3::Gekbin() 
2103
2104   //
2105   //       To find bin number in kinetic energy table
2106   //       stored in ELOW(NEKBIN)
2107   //
2108   gekbin(); 
2109
2110  
2111 //_____________________________________________________________________________
2112 void  TGeant3::Gfinds() 
2113
2114   //
2115   //       Returns the set/volume parameters corresponding to 
2116   //       the current space point in /GCTRAK/
2117   //       and fill common /GCSETS/
2118   // 
2119   //       IHSET  user set identifier 
2120   //       IHDET  user detector identifier 
2121   //       ISET set number in JSET  
2122   //       IDET   detector number in JS=LQ(JSET-ISET) 
2123   //       IDTYPE detector type (1,2)  
2124   //       NUMBV  detector volume numbers (array of length NVNAME)
2125   //       NVNAME number of volume levels
2126   //
2127   gfinds(); 
2128
2129  
2130 //_____________________________________________________________________________
2131 void  TGeant3::Gsking(Int_t igk) 
2132
2133   //
2134   //   Stores in stack JSTAK either the IGKth track of /GCKING/,
2135   //    or the NGKINE tracks when IGK is 0.
2136   //
2137   gsking(igk); 
2138
2139  
2140 //_____________________________________________________________________________
2141 void  TGeant3::Gskpho(Int_t igk) 
2142
2143   //
2144   //  Stores in stack JSTAK either the IGKth Cherenkov photon of  
2145   //  /GCKIN2/, or the NPHOT tracks when IGK is 0.                
2146   //
2147   gskpho(igk); 
2148
2149  
2150 //_____________________________________________________________________________
2151 void  TGeant3::Gsstak(Int_t iflag) 
2152
2153   //
2154   //   Stores in auxiliary stack JSTAK the particle currently 
2155   //    described in common /GCKINE/. 
2156   // 
2157   //   On request, creates also an entry in structure JKINE :
2158   //    IFLAG =
2159   //     0 : No entry in JKINE structure required (user) 
2160   //     1 : New entry in JVERTX / JKINE structures required (user)
2161   //    <0 : New entry in JKINE structure at vertex -IFLAG (user)
2162   //     2 : Entry in JKINE structure exists already (from GTREVE)
2163   //
2164   gsstak(iflag); 
2165
2166  
2167 //_____________________________________________________________________________
2168 void  TGeant3::Gsxyz() 
2169
2170   //
2171   //   Store space point VECT in banks JXYZ 
2172   //
2173   gsxyz(); 
2174
2175  
2176 //_____________________________________________________________________________
2177 void  TGeant3::Gtrack() 
2178
2179   //
2180   //   Controls tracking of current particle 
2181   //
2182   gtrack(); 
2183
2184  
2185 //_____________________________________________________________________________
2186 void  TGeant3::Gtreve() 
2187
2188   //
2189   //   Controls tracking of all particles belonging to the current event
2190   //
2191   gtreve(); 
2192
2193
2194 //_____________________________________________________________________________
2195 void  TGeant3::Gtreve_root() 
2196
2197   //
2198   //   Controls tracking of all particles belonging to the current event
2199   //
2200   gtreve_root(); 
2201
2202
2203 //_____________________________________________________________________________
2204 void  TGeant3::Grndm(Float_t *rvec, const Int_t len) const
2205 {
2206   //
2207   //   To generate a vector RVECV of LEN random numbers 
2208   //   Copy of the CERN Library routine RANECU 
2209   grndm(rvec,len);
2210 }
2211
2212 //_____________________________________________________________________________
2213 void  TGeant3::Grndmq(Int_t &is1, Int_t &is2, const Int_t iseq,
2214                       const Text_t *chopt)
2215 {
2216   //
2217   //  To set/retrieve the seed of the random number generator
2218   //
2219   grndmq(is1,is2,iseq,PASSCHARD(chopt) PASSCHARL(chopt));
2220 }
2221
2222 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2223 //
2224 //                        Functions from GDRAW
2225 //
2226 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2227
2228 //_____________________________________________________________________________
2229 void  TGeant3::Gdxyz(Int_t it)
2230 {
2231   //
2232   // Draw the points stored with Gsxyz relative to track it
2233   //
2234   gdxyz(it);
2235 }
2236
2237 //_____________________________________________________________________________
2238 void  TGeant3::Gdcxyz()
2239 {
2240   //
2241   // Draw the position of the current track
2242   //
2243   gdcxyz();
2244 }
2245
2246 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2247 //
2248 //                        Functions from GGEOM
2249 //
2250 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2251
2252 //_____________________________________________________________________________
2253 void  TGeant3::Gdtom(Float_t *xd, Float_t *xm, Int_t iflag) 
2254
2255   //
2256   //  Computes coordinates XM (Master Reference System
2257   //  knowing the coordinates XD (Detector Ref System)
2258   //  The local reference system can be initialized by
2259   //    - the tracking routines and GDTOM used in GUSTEP
2260   //    - a call to GSCMED(NLEVEL,NAMES,NUMBER)
2261   //        (inverse routine is GMTOD)
2262   // 
2263   //   If IFLAG=1  convert coordinates
2264   //      IFLAG=2  convert direction cosinus
2265   //
2266   gdtom(xd, xm, iflag); 
2267
2268  
2269 //_____________________________________________________________________________
2270 void  TGeant3::Glmoth(const char* iudet, Int_t iunum, Int_t &nlev, Int_t *lvols,
2271                       Int_t *lindx) 
2272
2273   //
2274   //   Loads the top part of the Volume tree in LVOLS (IVO's),
2275   //   LINDX (IN indices) for a given volume defined through
2276   //   its name IUDET and number IUNUM.
2277   // 
2278   //   The routine stores only upto the last level where JVOLUM
2279   //   data structure is developed. If there is no development
2280   //   above the current level, it returns NLEV zero.
2281   Int_t *idum=0; 
2282   glmoth(PASSCHARD(iudet), iunum, nlev, lvols, lindx, idum PASSCHARL(iudet)); 
2283
2284
2285 //_____________________________________________________________________________
2286 void  TGeant3::Gmedia(Float_t *x, Int_t &numed) 
2287
2288   //
2289   //   Finds in which volume/medium the point X is, and updates the
2290   //    common /GCVOLU/ and the structure JGPAR accordingly. 
2291   // 
2292   //   NUMED returns the tracking medium number, or 0 if point is
2293   //         outside the experimental setup.
2294   //
2295   gmedia(x,numed); 
2296
2297  
2298 //_____________________________________________________________________________
2299 void  TGeant3::Gmtod(Float_t *xm, Float_t *xd, Int_t iflag) 
2300
2301   //
2302   //       Computes coordinates XD (in DRS) 
2303   //       from known coordinates XM in MRS 
2304   //       The local reference system can be initialized by
2305   //         - the tracking routines and GMTOD used in GUSTEP
2306   //         - a call to GMEDIA(XM,NUMED)
2307   //         - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER) 
2308   //             (inverse routine is GDTOM) 
2309   //
2310   //        If IFLAG=1  convert coordinates 
2311   //           IFLAG=2  convert direction cosinus
2312   //
2313   gmtod(xm, xd, iflag); 
2314
2315  
2316 //_____________________________________________________________________________
2317 void  TGeant3::Gsdvn(const char *name, const char *mother, Int_t ndiv,
2318                      Int_t iaxis) 
2319
2320   //
2321   // Create a new volume by dividing an existing one
2322   // 
2323   //  NAME   Volume name
2324   //  MOTHER Mother volume name
2325   //  NDIV   Number of divisions
2326   //  IAXIS  Axis value
2327   //
2328   //  X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
2329   //  It divides a previously defined volume.
2330   //  
2331   char vname[5];
2332   Vname(name,vname);
2333   char vmother[5];
2334   Vname(mother,vmother);
2335   gsdvn(PASSCHARD(vname), PASSCHARD(vmother), ndiv, iaxis PASSCHARL(vname)
2336         PASSCHARL(vmother)); 
2337
2338  
2339 //_____________________________________________________________________________
2340 void  TGeant3::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
2341                       Int_t iaxis, Float_t c0i, Int_t numed) 
2342
2343   //
2344   // Create a new volume by dividing an existing one
2345   // 
2346   // Divides mother into ndiv divisions called name
2347   // along axis iaxis starting at coordinate value c0.
2348   // the new volume created will be medium number numed.
2349   //
2350   char vname[5];
2351   Vname(name,vname);
2352   char vmother[5];
2353   Vname(mother,vmother);
2354   gsdvn2(PASSCHARD(vname), PASSCHARD(vmother), ndiv, iaxis, c0i, numed
2355          PASSCHARL(vname) PASSCHARL(vmother)); 
2356
2357  
2358 //_____________________________________________________________________________
2359 void  TGeant3::Gsdvs(const char *name, const char *mother, Float_t step,
2360                      Int_t iaxis, Int_t numed) 
2361
2362   //
2363   // Create a new volume by dividing an existing one
2364   // 
2365   char vname[5];
2366   Vname(name,vname);
2367   char vmother[5];
2368   Vname(mother,vmother);
2369   gsdvs(PASSCHARD(vname), PASSCHARD(vmother), step, iaxis, numed
2370         PASSCHARL(vname) PASSCHARL(vmother)); 
2371
2372  
2373 //_____________________________________________________________________________
2374 void  TGeant3::Gsdvs2(const char *name, const char *mother, Float_t step,
2375                       Int_t iaxis, Float_t c0, Int_t numed) 
2376
2377   //
2378   // Create a new volume by dividing an existing one
2379   // 
2380   char vname[5];
2381   Vname(name,vname);
2382   char vmother[5];
2383   Vname(mother,vmother);
2384   gsdvs2(PASSCHARD(vname), PASSCHARD(vmother), step, iaxis, c0, numed
2385          PASSCHARL(vname) PASSCHARL(vmother)); 
2386
2387  
2388 //_____________________________________________________________________________
2389 void  TGeant3::Gsdvt(const char *name, const char *mother, Float_t step,
2390                      Int_t iaxis, Int_t numed, Int_t ndvmx) 
2391
2392   //
2393   // Create a new volume by dividing an existing one
2394   // 
2395   //       Divides MOTHER into divisions called NAME along
2396   //       axis IAXIS in steps of STEP. If not exactly divisible 
2397   //       will make as many as possible and will centre them 
2398   //       with respect to the mother. Divisions will have medium 
2399   //       number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
2400   //       NDVMX is the expected maximum number of divisions
2401   //          (If 0, no protection tests are performed) 
2402   //
2403   char vname[5];
2404   Vname(name,vname);
2405   char vmother[5];
2406   Vname(mother,vmother);
2407   gsdvt(PASSCHARD(vname), PASSCHARD(vmother), step, iaxis, numed, ndvmx
2408         PASSCHARL(vname) PASSCHARL(vmother)); 
2409
2410
2411 //_____________________________________________________________________________
2412 void  TGeant3::Gsdvt2(const char *name, const char *mother, Float_t step,
2413                       Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx) 
2414
2415   //
2416   // Create a new volume by dividing an existing one
2417   //                                                                    
2418   //           Divides MOTHER into divisions called NAME along          
2419   //            axis IAXIS starting at coordinate value C0 with step    
2420   //            size STEP.                                              
2421   //           The new volume created will have medium number NUMED.    
2422   //           If NUMED is 0, NUMED of mother is taken.                 
2423   //           NDVMX is the expected maximum number of divisions        
2424   //             (If 0, no protection tests are performed)              
2425   //
2426   char vname[5];
2427   Vname(name,vname);
2428   char vmother[5];
2429   Vname(mother,vmother);
2430   gsdvt2(PASSCHARD(vname), PASSCHARD(vmother), step, iaxis, c0,
2431          numed, ndvmx PASSCHARL(vname) PASSCHARL(vmother)); 
2432
2433
2434 //_____________________________________________________________________________
2435 void  TGeant3::Gsord(const char *name, Int_t iax) 
2436
2437   //
2438   //    Flags volume CHNAME whose contents will have to be ordered 
2439   //    along axis IAX, by setting the search flag to -IAX
2440   //           IAX = 1    X axis 
2441   //           IAX = 2    Y axis 
2442   //           IAX = 3    Z axis 
2443   //           IAX = 4    Rxy (static ordering only  -> GTMEDI)
2444   //           IAX = 14   Rxy (also dynamic ordering -> GTNEXT)
2445   //           IAX = 5    Rxyz (static ordering only -> GTMEDI)
2446   //           IAX = 15   Rxyz (also dynamic ordering -> GTNEXT)
2447   //           IAX = 6    PHI   (PHI=0 => X axis)
2448   //           IAX = 7    THETA (THETA=0 => Z axis)
2449   //
2450   char vname[5];
2451   Vname(name,vname);
2452   gsord(PASSCHARD(vname), iax PASSCHARL(vname)); 
2453
2454  
2455 //_____________________________________________________________________________
2456 void  TGeant3::Gspos(const char *name, Int_t nr, const char *mother, Float_t x,
2457                      Float_t y, Float_t z, Int_t irot, const char *konly) 
2458
2459   //
2460   // Position a volume into an existing one
2461   //
2462   //  NAME   Volume name
2463   //  NUMBER Copy number of the volume
2464   //  MOTHER Mother volume name
2465   //  X      X coord. of the volume in mother ref. sys.
2466   //  Y      Y coord. of the volume in mother ref. sys.
2467   //  Z      Z coord. of the volume in mother ref. sys.
2468   //  IROT   Rotation matrix number w.r.t. mother ref. sys.
2469   //  ONLY   ONLY/MANY flag
2470   //
2471   //  It positions a previously defined volume in the mother.
2472   //  
2473   char vname[5];
2474   Vname(name,vname);
2475   char vmother[5];
2476   Vname(mother,vmother);
2477   gspos(PASSCHARD(vname), nr, PASSCHARD(vmother), x, y, z, irot,
2478         PASSCHARD(konly) PASSCHARL(vname) PASSCHARL(vmother)
2479         PASSCHARL(konly)); 
2480
2481  
2482 //_____________________________________________________________________________
2483 void  TGeant3::Gsposp(const char *name, Int_t nr, const char *mother,  
2484                    Float_t x, Float_t y, Float_t z, Int_t irot,
2485                       const char *konly, Float_t *upar, Int_t np ) 
2486
2487   //
2488   //      Place a copy of generic volume NAME with user number
2489   //      NR inside MOTHER, with its parameters UPAR(1..NP)
2490   //
2491   char vname[5];
2492   Vname(name,vname);
2493   char vmother[5];
2494   Vname(mother,vmother);
2495   gsposp(PASSCHARD(vname), nr, PASSCHARD(vmother), x, y, z, irot,
2496          PASSCHARD(konly), upar, np PASSCHARL(vname) PASSCHARL(vmother)
2497          PASSCHARL(konly)); 
2498
2499  
2500 //_____________________________________________________________________________
2501 void  TGeant3::Gsrotm(Int_t nmat, Float_t theta1, Float_t phi1, Float_t theta2,
2502                       Float_t phi2, Float_t theta3, Float_t phi3) 
2503
2504   //
2505   //  nmat   Rotation matrix number
2506   //  THETA1 Polar angle for axis I
2507   //  PHI1   Azimuthal angle for axis I
2508   //  THETA2 Polar angle for axis II
2509   //  PHI2   Azimuthal angle for axis II
2510   //  THETA3 Polar angle for axis III
2511   //  PHI3   Azimuthal angle for axis III
2512   //
2513   //  It defines the rotation matrix number IROT.
2514   //  
2515   gsrotm(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
2516
2517  
2518 //_____________________________________________________________________________
2519 void  TGeant3::Gprotm(Int_t nmat) 
2520
2521   //
2522   //    To print rotation matrices structure JROTM
2523   //     nmat     Rotation matrix number
2524   //
2525   gprotm(nmat); 
2526
2527  
2528 //_____________________________________________________________________________
2529 Int_t TGeant3::Gsvolu(const char *name, const char *shape, Int_t nmed,  
2530                       Float_t *upar, Int_t npar) 
2531
2532   //
2533   //  NAME   Volume name
2534   //  SHAPE  Volume type
2535   //  NUMED  Tracking medium number
2536   //  NPAR   Number of shape parameters
2537   //  UPAR   Vector containing shape parameters
2538   //
2539   //  It creates a new volume in the JVOLUM data structure.
2540   //  
2541   Int_t ivolu = 0; 
2542   char vname[5];
2543   Vname(name,vname);
2544   char vshape[5];
2545   Vname(shape,vshape);
2546   gsvolu(PASSCHARD(vname), PASSCHARD(vshape), nmed, upar, npar, ivolu
2547          PASSCHARL(vname) PASSCHARL(vshape)); 
2548   return ivolu; 
2549
2550  
2551 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2552 //
2553 //           T H E    D R A W I N G   P A C K A G E
2554 //           ======================================
2555 //  Drawing functions. These functions allow the visualization in several ways
2556 //  of the volumes defined in the geometrical data structure. It is possible
2557 //  to draw the logical tree of volumes belonging to the detector (DTREE),
2558 //  to show their geometrical specification (DSPEC,DFSPC), to draw them
2559 //  and their cut views (DRAW, DCUT). Moreover, it is possible to execute
2560 //  these commands when the hidden line removal option is activated; in
2561 //  this case, the volumes can be also either translated in the space
2562 //  (SHIFT), or clipped by boolean operation (CVOL). In addition, it is
2563 //  possible to fill the surfaces of the volumes
2564 //  with solid colours when the shading option (SHAD) is activated.
2565 //  Several tools (ZOOM, LENS) have been developed to zoom detailed parts
2566 //  of the detectors or to scan physical events as well.
2567 //  Finally, the command MOVE will allow the rotation, translation and zooming
2568 //  on real time parts of the detectors or tracks and hits of a simulated event.
2569 //  Ray-tracing commands. In case the command (DOPT RAYT ON) is executed,
2570 //  the drawing is performed by the Geant ray-tracing;
2571 //  automatically, the color is assigned according to the tracking medium of each
2572 //  volume and the volumes with a density lower/equal than the air are considered
2573 //  transparent; if the option (USER) is set (ON) (again via the command (DOPT)),
2574 //  the user can set color and visibility for the desired volumes via the command
2575 //  (SATT), as usual, relatively to the attributes (COLO) and (SEEN).
2576 //  The resolution can be set via the command (SATT * FILL VALUE), where (VALUE)
2577 //  is the ratio between the number of pixels drawn and 20 (user coordinates).
2578 //  Parallel view and perspective view are possible (DOPT PROJ PARA/PERS); in the
2579 //  first case, we assume that the first mother volume of the tree is a box with
2580 //  dimensions 10000 X 10000 X 10000 cm and the view point (infinetely far) is
2581 //  5000 cm far from the origin along the Z axis of the user coordinates; in the
2582 //  second case, the distance between the observer and the origin of the world
2583 //  reference system is set in cm by the command (PERSP NAME VALUE); grand-angle
2584 //  or telescopic effects can be achieved changing the scale factors in the command
2585 //  (DRAW). When the final picture does not occupy the full window,
2586 //  mapping the space before tracing can speed up the drawing, but can also
2587 //  produce less precise results; values from 1 to 4 are allowed in the command
2588 //  (DOPT MAPP VALUE), the mapping being more precise for increasing (VALUE); for
2589 //  (VALUE = 0) no mapping is performed (therefore max precision and lowest speed).
2590 //  The command (VALCUT) allows the cutting of the detector by three planes
2591 //  ortogonal to the x,y,z axis. The attribute (LSTY) can be set by the command
2592 //  SATT for any desired volume and can assume values from 0 to 7; it determines
2593 //  the different light processing to be performed for different materials:
2594 //  0 = dark-matt, 1 = bright-matt, 2 = plastic, 3 = ceramic, 4 = rough-metals,
2595 //  5 = shiny-metals, 6 = glass, 7 = mirror. The detector is assumed to be in the
2596 //  dark, the ambient light luminosity is 0.2 for each basic hue (the saturation
2597 //  is 0.9) and the observer is assumed to have a light source (therefore he will
2598 //  produce parallel light in the case of parallel view and point-like-source
2599 //  light in the case of perspective view).
2600 //
2601 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
2602
2603 //_____________________________________________________________________________
2604 void TGeant3::Gsatt(const char *name, const char *att, Int_t val)
2605
2606   //
2607   //  NAME   Volume name
2608   //  IOPT   Name of the attribute to be set
2609   //  IVAL   Value to which the attribute is to be set
2610   //
2611   //  name= "*" stands for all the volumes.
2612   //  iopt can be chosen among the following :
2613   //  
2614   //     WORK   0=volume name is inactive for the tracking
2615   //            1=volume name is active for the tracking (default)
2616   //  
2617   //     SEEN   0=volume name is invisible
2618   //            1=volume name is visible (default)
2619   //           -1=volume invisible with all its descendants in the tree
2620   //           -2=volume visible but not its descendants in the tree
2621   //  
2622   //     LSTY   line style 1,2,3,... (default=1)
2623   //            LSTY=7 will produce a very precise approximation for
2624   //            revolution bodies.
2625   //  
2626   //     LWID   line width -7,...,1,2,3,..7 (default=1)
2627   //            LWID<0 will act as abs(LWID) was set for the volume
2628   //            and for all the levels below it. When SHAD is 'ON', LWID
2629   //            represent the linewidth of the scan lines filling the surfaces
2630   //            (whereas the FILL value represent their number). Therefore
2631   //            tuning this parameter will help to obtain the desired
2632   //            quality/performance ratio.
2633   //  
2634   //     COLO   colour code -166,...,1,2,..166 (default=1)
2635   //            n=1=black
2636   //            n=2=red;    n=17+m, m=0,25, increasing luminosity according to 'm';
2637   //            n=3=green;  n=67+m, m=0,25, increasing luminosity according to 'm';
2638   //            n=4=blue;   n=117+m, m=0,25, increasing luminosity according to 'm';
2639   //            n=5=yellow; n=42+m, m=0,25, increasing luminosity according to 'm';
2640   //            n=6=violet; n=142+m, m=0,25, increasing luminosity according to 'm';
2641   //            n=7=lightblue; n=92+m, m=0,25, increasing luminosity according to 'm';
2642   //            colour=n*10+m, m=1,2,...9, will produce the same colour
2643   //            as 'n', but with increasing luminosity according to 'm';
2644   //            COLO<0 will act as if abs(COLO) was set for the volume
2645   //            and for all the levels below it.
2646   //            When for a volume the attribute FILL is > 1 (and the
2647   //            option SHAD is on), the ABS of its colour code must be < 8
2648   //            because an automatic shading of its faces will be
2649   //            performed.
2650   //  
2651   //     FILL  (1992) fill area  -7,...,0,1,...7 (default=0)
2652   //            when option SHAD is "on" the FILL attribute of any
2653   //            volume can be set different from 0 (normal drawing);
2654   //            if it is set to 1, the faces of such volume will be filled
2655   //            with solid colours; if ABS(FILL) is > 1, then a light
2656   //            source is placed along the observer line, and the faces of
2657   //            such volumes will be painted by colours whose luminosity
2658   //            will depend on the amount of light reflected;
2659   //            if ABS(FILL) = 1, then it is possible to use all the 166
2660   //            colours of the colour table, becouse the automatic shading
2661   //            is not performed;
2662   //            for increasing values of FILL the drawing will be performed
2663   //            with higher and higher resolution improving the quality (the
2664   //            number of scan lines used to fill the faces increases with FILL);
2665   //            it is possible to set different values of FILL
2666   //            for different volumes, in order to optimize at the same time
2667   //            the performance and the quality of the picture;
2668   //            FILL<0 will act as if abs(FILL) was set for the volume
2669   //            and for all the levels below it.
2670   //            This kind of drawing can be saved in 'picture files'
2671   //            or in view banks.
2672   //            0=drawing without fill area
2673   //            1=faces filled with solid colours and resolution = 6
2674   //            2=lowest resolution (very fast)
2675   //            3=default resolution
2676   //            4=.................
2677   //            5=.................
2678   //            6=.................
2679   //            7=max resolution
2680   //            Finally, if a coloured background is desired, the FILL
2681   //            attribute for the first volume of the tree must be set
2682   //            equal to -abs(colo), colo being >0 and <166.
2683   //  
2684   //     SET   set number associated to volume name
2685   //     DET   detector number associated to volume name
2686   //     DTYP  detector type (1,2)
2687   //  
2688   InitHIGZ();
2689   char vname[5];
2690   Vname(name,vname);
2691   char vatt[5];
2692   Vname(att,vatt);
2693   gsatt(PASSCHARD(vname), PASSCHARD(vatt), val PASSCHARL(vname)
2694         PASSCHARL(vatt)); 
2695
2696
2697 //_____________________________________________________________________________
2698 void TGeant3::Gfpara(const char *name, Int_t number, Int_t intext, Int_t& npar,
2699                          Int_t& natt, Float_t* par, Float_t* att)
2700 {
2701   //
2702   // Find the parameters of a volume
2703   //
2704   gfpara(PASSCHARD(name), number, intext, npar, natt, par, att
2705          PASSCHARL(name));
2706 }
2707
2708 //_____________________________________________________________________________
2709 void TGeant3::Gckpar(Int_t ish, Int_t npar, Float_t* par)
2710 {
2711   //
2712   // Check the parameters of a shape
2713   //
2714   gckpar(ish,npar,par);
2715 }
2716
2717 //_____________________________________________________________________________
2718 void TGeant3::Gckmat(Int_t itmed, char* natmed)
2719 {
2720   //
2721   // Check the parameters of a tracking medium
2722   //
2723   gckmat(itmed, PASSCHARD(natmed) PASSCHARL(natmed));
2724 }
2725
2726 //_____________________________________________________________________________
2727 void TGeant3::Gdelete(Int_t iview)
2728
2729   //
2730   //  IVIEW  View number
2731   //
2732   //  It deletes a view bank from memory.
2733   //
2734   gdelet(iview);
2735 }
2736  
2737 //_____________________________________________________________________________
2738 void TGeant3::Gdopen(Int_t iview)
2739
2740   //
2741   //  IVIEW  View number
2742   //
2743   //  When a drawing is very complex and requires a long time to be
2744   //  executed, it can be useful to store it in a view bank: after a
2745   //  call to DOPEN and the execution of the drawing (nothing will
2746   //  appear on the screen), and after a necessary call to DCLOSE,
2747   //  the contents of the bank can be displayed in a very fast way
2748   //  through a call to DSHOW; therefore, the detector can be easily
2749   //  zoomed many times in different ways. Please note that the pictures
2750   //  with solid colours can now be stored in a view bank or in 'PICTURE FILES'
2751   //
2752   InitHIGZ();
2753   higz->Clear();
2754   gdopen(iview);
2755 }
2756  
2757 //_____________________________________________________________________________
2758 void TGeant3::Gdclose()
2759
2760   //
2761   //  It closes the currently open view bank; it must be called after the
2762   //  end of the drawing to be stored.
2763   //
2764   gdclos();
2765 }
2766  
2767 //_____________________________________________________________________________
2768 void TGeant3::Gdshow(Int_t iview)
2769
2770   //
2771   //  IVIEW  View number
2772   //
2773   //  It shows on the screen the contents of a view bank. It
2774   //  can be called after a view bank has been closed.
2775   //
2776   gdshow(iview);
2777
2778
2779 //_____________________________________________________________________________
2780 void TGeant3::Gdopt(const char *name,const char *value)
2781
2782   //
2783   //  NAME   Option name
2784   //  VALUE  Option value
2785   //
2786   //  To set/modify the drawing options.
2787   //     IOPT   IVAL      Action
2788   //  
2789   //     THRZ    ON       Draw tracks in R vs Z
2790   //             OFF (D)  Draw tracks in X,Y,Z
2791   //             180
2792   //             360
2793   //     PROJ    PARA (D) Parallel projection
2794   //             PERS     Perspective
2795   //     TRAK    LINE (D) Trajectory drawn with lines
2796   //             POIN       " " with markers
2797   //     HIDE    ON       Hidden line removal using the CG package
2798   //             OFF (D)  No hidden line removal
2799   //     SHAD    ON       Fill area and shading of surfaces.
2800   //             OFF (D)  Normal hidden line removal.
2801   //     RAYT    ON       Ray-tracing on.
2802   //             OFF (D)  Ray-tracing off.
2803   //     EDGE    OFF      Does not draw contours when shad is on.
2804   //             ON  (D)  Normal shading.
2805   //     MAPP    1,2,3,4  Mapping before ray-tracing.
2806   //             0   (D)  No mapping.
2807   //     USER    ON       User graphics options in the raytracing.
2808   //             OFF (D)  Automatic graphics options.
2809   //  
2810   InitHIGZ();
2811   char vname[5];
2812   Vname(name,vname);
2813   char vvalue[5];
2814   Vname(value,vvalue);
2815   gdopt(PASSCHARD(vname), PASSCHARD(vvalue) PASSCHARL(vname)
2816         PASSCHARL(vvalue)); 
2817
2818  
2819 //_____________________________________________________________________________
2820 void TGeant3::Gdraw(const char *name,Float_t theta, Float_t phi, Float_t psi,
2821                     Float_t u0,Float_t v0,Float_t ul,Float_t vl)
2822
2823   //
2824   //  NAME   Volume name
2825   //  +
2826   //  THETA  Viewing angle theta (for 3D projection)
2827   //  PHI    Viewing angle phi (for 3D projection)
2828   //  PSI    Viewing angle psi (for 2D rotation)
2829   //  U0     U-coord. (horizontal) of volume origin
2830   //  V0     V-coord. (vertical) of volume origin
2831   //  SU     Scale factor for U-coord.
2832   //  SV     Scale factor for V-coord.
2833   //
2834   //  This function will draw the volumes,
2835   //  selected with their graphical attributes, set by the Gsatt
2836   //  facility. The drawing may be performed with hidden line removal
2837   //  and with shading effects according to the value of the options HIDE
2838   //  and SHAD; if the option SHAD is ON, the contour's edges can be
2839   //  drawn or not. If the option HIDE is ON, the detector can be
2840   //  exploded (BOMB), clipped with different shapes (CVOL), and some
2841   //  of its parts can be shifted from their original
2842   //  position (SHIFT). When HIDE is ON, if
2843   //  the drawing requires more than the available memory, the program
2844   //  will evaluate and display the number of missing words
2845   //  (so that the user can increase the
2846   //  size of its ZEBRA store). Finally, at the end of each drawing (with HIDE on),
2847   //  the program will print messages about the memory used and
2848   //  statistics on the volumes' visibility.
2849   //  The following commands will produce the drawing of a green
2850   //  volume, specified by NAME, without using the hidden line removal
2851   //  technique, using the hidden line removal technique,
2852   //  with different linewidth and colour (red), with
2853   //  solid colour, with shading of surfaces, and without edges.
2854   //  Finally, some examples are given for the ray-tracing. (A possible
2855   //  string for the NAME of the volume can be found using the command DTREE).
2856   //
2857   InitHIGZ();
2858   higz->Clear();
2859   char vname[5];
2860   Vname(name,vname);
2861   if (fGcvdma->raytra != 1) {
2862     gdraw(PASSCHARD(vname), theta,phi,psi,u0,v0,ul,vl PASSCHARL(vname)); 
2863   } else {
2864     gdrayt(PASSCHARD(vname), theta,phi,psi,u0,v0,ul,vl PASSCHARL(vname)); 
2865   }
2866
2867  
2868 //_____________________________________________________________________________
2869 void TGeant3::Gdrawc(const char *name,Int_t axis, Float_t cut,Float_t u0,
2870                      Float_t v0,Float_t ul,Float_t vl)
2871
2872   //
2873   //  NAME   Volume name
2874   //  CAXIS  Axis value
2875   //  CUTVAL Cut plane distance from the origin along the axis
2876   //  +
2877   //  U0     U-coord. (horizontal) of volume origin
2878   //  V0     V-coord. (vertical) of volume origin
2879   //  SU     Scale factor for U-coord.
2880   //  SV     Scale factor for V-coord.
2881   //
2882   //  The cut plane is normal to caxis (X,Y,Z), corresponding to iaxis (1,2,3),
2883   //  and placed at the distance cutval from the origin.
2884   //  The resulting picture is seen from the the same axis.
2885   //  When HIDE Mode is ON, it is possible to get the same effect with
2886   //  the CVOL/BOX function.
2887   //  
2888   InitHIGZ();
2889   higz->Clear();
2890   char vname[5];
2891   Vname(name,vname);
2892   gdrawc(PASSCHARD(vname), axis,cut,u0,v0,ul,vl PASSCHARL(vname)); 
2893
2894  
2895 //_____________________________________________________________________________
2896 void TGeant3::Gdrawx(const char *name,Float_t cutthe, Float_t cutphi,
2897                      Float_t cutval, Float_t theta, Float_t phi, Float_t u0,
2898                      Float_t v0,Float_t ul,Float_t vl)
2899
2900   //
2901   //  NAME   Volume name
2902   //  CUTTHE Theta angle of the line normal to cut plane
2903   //  CUTPHI Phi angle of the line normal to cut plane
2904   //  CUTVAL Cut plane distance from the origin along the axis
2905   //  +
2906   //  THETA  Viewing angle theta (for 3D projection)
2907   //  PHI    Viewing angle phi (for 3D projection)
2908   //  U0     U-coord. (horizontal) of volume origin
2909   //  V0     V-coord. (vertical) of volume origin
2910   //  SU     Scale factor for U-coord.
2911   //  SV     Scale factor for V-coord.
2912   //
2913   //  The cut plane is normal to the line given by the cut angles
2914   //  cutthe and cutphi and placed at the distance cutval from the origin.
2915   //  The resulting picture is seen from the viewing angles theta,phi.
2916   //
2917   InitHIGZ();
2918   higz->Clear();
2919   char vname[5];
2920   Vname(name,vname);
2921   gdrawx(PASSCHARD(vname), cutthe,cutphi,cutval,theta,phi,u0,v0,ul,vl
2922          PASSCHARL(vname)); 
2923 }
2924  
2925 //_____________________________________________________________________________
2926 void TGeant3::Gdhead(Int_t isel, const char *name, Float_t chrsiz)
2927
2928   //
2929   //  Parameters
2930   //  +
2931   //  ISEL   Option flag  D=111110
2932   //  NAME   Title
2933   //  CHRSIZ Character size (cm) of title NAME D=0.6
2934   //
2935   //  ISEL =
2936   //   0      to have only the header lines
2937   //   xxxxx1 to add the text name centered on top of header
2938   //   xxxx1x to add global detector name (first volume) on left
2939   //   xxx1xx to add date on right
2940   //   xx1xxx to select thick characters for text on top of header
2941   //   x1xxxx to add the text 'EVENT NR x' on top of header
2942   //   1xxxxx to add the text 'RUN NR x' on top of header
2943   //  NOTE that ISEL=x1xxx1 or ISEL=1xxxx1 are illegal choices,
2944   //  i.e. they generate overwritten text.
2945   //
2946   gdhead(isel,PASSCHARD(name),chrsiz PASSCHARL(name));
2947 }
2948
2949 //_____________________________________________________________________________
2950 void TGeant3::Gdman(Float_t u, Float_t v, const char *type)
2951
2952   //
2953   //  Draw a 2D-man at position (U0,V0)
2954   //  Parameters
2955   //  U      U-coord. (horizontal) of the centre of man' R
2956   //  V      V-coord. (vertical) of the centre of man' R
2957   //  TYPE   D='MAN' possible values: 'MAN,WM1,WM2,WM3'
2958   // 
2959   //   CALL GDMAN(u,v),CALL GDWMN1(u,v),CALL GDWMN2(u,v),CALL GDWMN2(u,v)
2960   //  It superimposes the picure of a man or of a woman, chosen among
2961   //  three different ones, with the same scale factors as the detector
2962   //  in the current drawing.
2963   //
2964   TString opt = type;
2965    if (opt.Contains("WM1")) {
2966      gdwmn1(u,v);
2967    } else if (opt.Contains("WM3")) {
2968      gdwmn3(u,v);
2969    } else if (opt.Contains("WM2")) {
2970      gdwmn2(u,v);
2971    } else {
2972      gdman(u,v);
2973    }
2974 }
2975  
2976 //_____________________________________________________________________________
2977 void TGeant3::Gdspec(const char *name)
2978
2979   //
2980   //  NAME   Volume name
2981   //
2982   //  Shows 3 views of the volume (two cut-views and a 3D view), together with
2983   //  its geometrical specifications. The 3D drawing will
2984   //  be performed according the current values of the options HIDE and
2985   //  SHAD and according the current SetClipBox clipping parameters for that
2986   //  volume.
2987   //  
2988   InitHIGZ();
2989   higz->Clear();
2990   char vname[5];
2991   Vname(name,vname);
2992   gdspec(PASSCHARD(vname) PASSCHARL(vname)); 
2993
2994  
2995 //_____________________________________________________________________________
2996 void TGeant3::DrawOneSpec(const char *name)
2997
2998   //
2999   //  Function called when one double-clicks on a volume name
3000   //  in a TPavelabel drawn by Gdtree.
3001   //
3002   THIGZ *higzSave = higz;
3003   higzSave->SetName("higzSave");
3004   THIGZ *higzSpec = (THIGZ*)gROOT->FindObject("higzSpec");
3005   //printf("DrawOneSpec, higz=%x, higzSpec=%x\n",higz,higzSpec);
3006   if (higzSpec) higz     = higzSpec;
3007   else          higzSpec = new THIGZ(defSize);
3008   higzSpec->SetName("higzSpec");
3009   higzSpec->cd();
3010   higzSpec->Clear();
3011   char vname[5];
3012   Vname(name,vname);
3013   gdspec(PASSCHARD(vname) PASSCHARL(vname)); 
3014   higzSpec->Update();
3015   higzSave->cd();
3016   higzSave->SetName("higz");
3017   higz = higzSave;
3018
3019
3020 //_____________________________________________________________________________
3021 void TGeant3::Gdtree(const char *name,Int_t levmax, Int_t isel)
3022
3023   //
3024   //  NAME   Volume name
3025   //  LEVMAX Depth level
3026   //  ISELT  Options
3027   //
3028   //  This function draws the logical tree,
3029   //  Each volume in the tree is represented by a TPaveTree object.
3030   //  Double-clicking on a TPaveTree draws the specs of the corresponding volume.
3031   //  Use TPaveTree pop-up menu to select:
3032   //    - drawing specs
3033   //    - drawing tree
3034   //    - drawing tree of parent
3035   //  
3036   InitHIGZ();
3037   higz->Clear();
3038   char vname[5];
3039   Vname(name,vname);
3040   gdtree(PASSCHARD(vname), levmax, isel PASSCHARL(vname)); 
3041   higz->fPname = "";
3042
3043
3044 //_____________________________________________________________________________
3045 void TGeant3::GdtreeParent(const char *name,Int_t levmax, Int_t isel)
3046
3047   //
3048   //  NAME   Volume name
3049   //  LEVMAX Depth level
3050   //  ISELT  Options
3051   //
3052   //  This function draws the logical tree of the parent of name.
3053   //  
3054   InitHIGZ();
3055   higz->Clear();
3056   // Scan list of volumes in JVOLUM
3057   char vname[5];
3058   Int_t gname, i, jvo, in, nin, jin, num;
3059   strncpy((char *) &gname, name, 4);
3060   for(i=1; i<=fGcnum->nvolum; i++) {
3061     jvo = fZlq[fGclink->jvolum-i];
3062     nin = Int_t(fZq[jvo+3]);
3063     if (nin == -1) nin = 1;
3064     for (in=1;in<=nin;in++) {
3065       jin = fZlq[jvo-in];
3066       num = Int_t(fZq[jin+2]);
3067       if(gname == fZiq[fGclink->jvolum+num]) {
3068         strncpy(vname,(char*)&fZiq[fGclink->jvolum+i],4);
3069         vname[4] = 0;           
3070         gdtree(PASSCHARD(vname), levmax, isel PASSCHARL(vname)); 
3071         higz->fPname = "";
3072         return;
3073       }
3074     }
3075   }
3076
3077  
3078 //_____________________________________________________________________________
3079 void TGeant3::SetABAN(Int_t par)
3080 {
3081   //
3082   // par = 1 particles will be stopped according to their residual
3083   //         range if they are not in a sensitive material and are
3084   //         far enough from the boundary
3085   //       0 particles are transported normally
3086   //
3087   fGcphys->dphys1 = par;
3088 }
3089  
3090  
3091 //_____________________________________________________________________________
3092 void TGeant3::SetANNI(Int_t par)
3093 {
3094   //
3095   //   To control positron annihilation.
3096   //    par =0 no annihilation
3097   //        =1 annihilation. Decays processed.
3098   //        =2 annihilation. No decay products stored.
3099   //
3100   fGcphys->ianni = par;
3101 }
3102  
3103  
3104 //_____________________________________________________________________________
3105 void TGeant3::SetAUTO(Int_t par)
3106 {
3107   //
3108   //  To control automatic calculation of tracking medium parameters:
3109   //   par =0 no automatic calculation;
3110   //       =1 automati calculation.
3111   //  
3112   fGctrak->igauto = par;
3113 }
3114  
3115  
3116 //_____________________________________________________________________________
3117 void TGeant3::SetBOMB(Float_t boom)
3118 {
3119   //
3120   //  BOOM  : Exploding factor for volumes position 
3121   // 
3122   //  To 'explode' the detector. If BOOM is positive (values smaller
3123   //  than 1. are suggested, but any value is possible)
3124   //  all the volumes are shifted by a distance
3125   //  proportional to BOOM along the direction between their centre
3126   //  and the origin of the MARS; the volumes which are symmetric
3127   //  with respect to this origin are simply not shown.
3128   //  BOOM equal to 0 resets the normal mode.
3129   //  A negative (greater than -1.) value of
3130   //  BOOM will cause an 'implosion'; for even lower values of BOOM
3131   //  the volumes' positions will be reflected respect to the origin.
3132   //  This command can be useful to improve the 3D effect for very
3133   //  complex detectors. The following commands will make explode the
3134   //  detector:
3135   //
3136   InitHIGZ();
3137   setbomb(boom);
3138 }
3139  
3140 //_____________________________________________________________________________
3141 void TGeant3::SetBREM(Int_t par)
3142 {
3143   //
3144   //  To control bremstrahlung.
3145   //   par =0 no bremstrahlung
3146   //       =1 bremstrahlung. Photon processed.
3147   //       =2 bremstrahlung. No photon stored.
3148   //  
3149   fGcphys->ibrem = par;
3150 }
3151  
3152  
3153 //_____________________________________________________________________________
3154 void TGeant3::SetCKOV(Int_t par)
3155 {
3156   //
3157   //  To control Cerenkov production
3158   //   par =0 no Cerenkov;
3159   //       =1 Cerenkov;
3160   //       =2 Cerenkov with primary stopped at each step.
3161   //  
3162   fGctlit->itckov = par;
3163 }
3164  
3165  
3166 //_____________________________________________________________________________
3167 void  TGeant3::SetClipBox(const char *name,Float_t xmin,Float_t xmax,
3168                           Float_t ymin,Float_t ymax,Float_t zmin,Float_t zmax)
3169 {
3170   //
3171   //  The hidden line removal technique is necessary to visualize properly
3172   //  very complex detectors. At the same time, it can be useful to visualize
3173   //  the inner elements of a detector in detail. This function allows
3174   //  subtractions (via boolean operation) of BOX shape from any part of
3175   //  the detector, therefore showing its inner contents.
3176   //  If "*" is given as the name of the
3177   //  volume to be clipped, all volumes are clipped by the given box.
3178   //  A volume can be clipped at most twice.
3179   //  if a volume is explicitely clipped twice,
3180   //  the "*" will not act on it anymore. Giving "." as the name
3181   //  of the volume to be clipped will reset the clipping.
3182   //  Parameters
3183   //  NAME   Name of volume to be clipped 
3184   //  +
3185   //  XMIN   Lower limit of the Shape X coordinate
3186   //  XMAX   Upper limit of the Shape X coordinate
3187   //  YMIN   Lower limit of the Shape Y coordinate
3188   //  YMAX   Upper limit of the Shape Y coordinate
3189   //  ZMIN   Lower limit of the Shape Z coordinate
3190   //  ZMAX   Upper limit of the Shape Z coordinate
3191   //
3192   //  This function performs a boolean subtraction between the volume
3193   //  NAME and a box placed in the MARS according the values of the given
3194   //  coordinates.
3195   
3196   InitHIGZ();
3197   char vname[5];
3198   Vname(name,vname);
3199   setclip(PASSCHARD(vname),xmin,xmax,ymin,ymax,zmin,zmax PASSCHARL(vname));   
3200
3201
3202 //_____________________________________________________________________________
3203 void TGeant3::SetCOMP(Int_t par)
3204 {
3205   //
3206   //  To control Compton scattering
3207   //   par =0 no Compton
3208   //       =1 Compton. Electron processed.
3209   //       =2 Compton. No electron stored.
3210   //  
3211   //
3212   fGcphys->icomp = par;
3213 }
3214   
3215 //_____________________________________________________________________________
3216 void TGeant3::SetCUTS(Float_t cutgam,Float_t cutele,Float_t cutneu,
3217                       Float_t cuthad,Float_t cutmuo ,Float_t bcute ,
3218                       Float_t bcutm ,Float_t dcute ,Float_t dcutm ,
3219                       Float_t ppcutm, Float_t tofmax)
3220 {
3221   //
3222   //  CUTGAM   Cut for gammas              D=0.001
3223   //  CUTELE   Cut for electrons           D=0.001
3224   //  CUTHAD   Cut for charged hadrons     D=0.01
3225   //  CUTNEU   Cut for neutral hadrons     D=0.01
3226   //  CUTMUO   Cut for muons               D=0.01
3227   //  BCUTE    Cut for electron brems.     D=-1.
3228   //  BCUTM    Cut for muon brems.         D=-1.
3229   //  DCUTE    Cut for electron delta-rays D=-1.
3230   //  DCUTM    Cut for muon delta-rays     D=-1.
3231   //  PPCUTM   Cut for e+e- pairs by muons D=0.01
3232   //  TOFMAX   Time of flight cut          D=1.E+10
3233   //
3234   //   If the default values (-1.) for       BCUTE ,BCUTM ,DCUTE ,DCUTM
3235   //   are not modified, they will be set to CUTGAM,CUTGAM,CUTELE,CUTELE
3236   //   respectively.
3237   //  If one of the parameters from CUTGAM to PPCUTM included
3238   //  is modified, cross-sections and energy loss tables must be
3239   //  recomputed via the function Gphysi.
3240   //
3241   fGccuts->cutgam = cutgam;
3242   fGccuts->cutele = cutele;
3243   fGccuts->cutneu = cutneu;
3244   fGccuts->cuthad = cuthad;
3245   fGccuts->cutmuo = cutmuo;
3246   fGccuts->bcute  = bcute;
3247   fGccuts->bcutm  = bcutm;
3248   fGccuts->dcute  = dcute;
3249   fGccuts->dcutm  = dcutm;
3250   fGccuts->ppcutm = ppcutm;
3251   fGccuts->tofmax = tofmax;   
3252 }
3253
3254 //_____________________________________________________________________________
3255 void TGeant3::SetDCAY(Int_t par)
3256 {
3257   //
3258   //  To control Decay mechanism.
3259   //   par =0 no decays.
3260   //       =1 Decays. secondaries processed.
3261   //       =2 Decays. No secondaries stored.
3262   //  
3263   fGcphys->idcay = par;
3264 }
3265  
3266  
3267 //_____________________________________________________________________________
3268 void TGeant3::SetDEBU(Int_t emin, Int_t emax, Int_t emod)
3269 {
3270   //
3271   // Set the debug flag and frequency
3272   // Selected debug output will be printed from
3273   // event emin to even emax each emod event
3274   //
3275   fGcflag->idemin = emin;
3276   fGcflag->idemax = emax;
3277   fGcflag->itest  = emod;
3278 }
3279  
3280  
3281 //_____________________________________________________________________________
3282 void TGeant3::SetDRAY(Int_t par)
3283 {
3284   //
3285   //  To control delta rays mechanism.
3286   //   par =0 no delta rays.
3287   //       =1 Delta rays. secondaries processed.
3288   //       =2 Delta rays. No secondaries stored.
3289   //  
3290   fGcphys->idray = par;
3291 }
3292  
3293 //_____________________________________________________________________________
3294 void TGeant3::SetERAN(Float_t ekmin, Float_t ekmax, Int_t nekbin)
3295 {
3296   //
3297   //  To control cross section tabulations
3298   //   ekmin = minimum kinetic energy in GeV
3299   //   ekmax = maximum kinetic energy in GeV
3300   //   nekbin = number of logatithmic bins (<200)
3301   //  
3302   fGcmulo->ekmin = ekmin;
3303   fGcmulo->ekmax = ekmax;
3304   fGcmulo->nekbin = nekbin;
3305 }
3306  
3307 //_____________________________________________________________________________
3308 void TGeant3::SetHADR(Int_t par)
3309 {
3310   //
3311   //  To control hadronic interactions.
3312   //   par =0 no hadronic interactions.
3313   //       =1 Hadronic interactions. secondaries processed.
3314   //       =2 Hadronic interactions. No secondaries stored.
3315   //  
3316   fGcphys->ihadr = par;
3317 }
3318  
3319 //_____________________________________________________________________________
3320 void TGeant3::SetKINE(Int_t kine, Float_t xk1, Float_t xk2, Float_t xk3,
3321                       Float_t xk4, Float_t xk5, Float_t xk6, Float_t xk7,
3322                       Float_t xk8, Float_t xk9, Float_t xk10)
3323 {
3324   //
3325   // Set the variables in /GCFLAG/ IKINE, PKINE(10)
3326   // Their meaning is user defined
3327   //
3328   fGckine->ikine    = kine;
3329   fGckine->pkine[0] = xk1;
3330   fGckine->pkine[1] = xk2;
3331   fGckine->pkine[2] = xk3;
3332   fGckine->pkine[3] = xk4;
3333   fGckine->pkine[4] = xk5;
3334   fGckine->pkine[5] = xk6;
3335   fGckine->pkine[6] = xk7;
3336   fGckine->pkine[7] = xk8;
3337   fGckine->pkine[8] = xk9;
3338   fGckine->pkine[9] = xk10;
3339 }
3340  
3341 //_____________________________________________________________________________
3342 void TGeant3::SetLOSS(Int_t par)
3343 {
3344   //
3345   //  To control energy loss.
3346   //   par =0 no energy loss;
3347   //       =1 restricted energy loss fluctuations;
3348   //       =2 complete energy loss fluctuations;
3349   //       =3 same as 1;
3350   //       =4 no energy loss fluctuations.
3351   //  If the value ILOSS is changed, then cross-sections and energy loss
3352   //  tables must be recomputed via the command 'PHYSI'.
3353   //  
3354   fGcphys->iloss = par;
3355 }
3356  
3357  
3358 //_____________________________________________________________________________
3359 void TGeant3::SetMULS(Int_t par)
3360 {
3361   //
3362   //  To control multiple scattering.
3363   //   par =0 no multiple scattering.
3364   //       =1 Moliere or Coulomb scattering.
3365   //       =2 Moliere or Coulomb scattering.
3366   //       =3 Gaussian scattering.
3367   //  
3368   fGcphys->imuls = par;
3369 }
3370  
3371  
3372 //_____________________________________________________________________________
3373 void TGeant3::SetMUNU(Int_t par)
3374 {
3375   //
3376   //  To control muon nuclear interactions.
3377   //   par =0 no muon-nuclear interactions.
3378   //       =1 Nuclear interactions. Secondaries processed.
3379   //       =2 Nuclear interactions. Secondaries not processed.
3380   //  
3381   fGcphys->imunu = par;
3382 }
3383  
3384 //_____________________________________________________________________________
3385 void TGeant3::SetOPTI(Int_t par)
3386 {
3387   //
3388   //  This flag controls the tracking optimisation performed via the
3389   //  GSORD routine:
3390   //      1 no optimisation at all; GSORD calls disabled;
3391   //      0 no optimisation; only user calls to GSORD kept;
3392   //      1 all non-GSORDered volumes are ordered along the best axis;
3393   //      2 all volumes are ordered along the best axis.
3394   //  
3395   fGcopti->ioptim = par;
3396 }
3397  
3398 //_____________________________________________________________________________
3399 void TGeant3::SetPAIR(Int_t par)
3400 {
3401   //
3402   //  To control pair production mechanism.
3403   //   par =0 no pair production.
3404   //       =1 Pair production. secondaries processed.
3405   //       =2 Pair production. No secondaries stored.
3406   //  
3407   fGcphys->ipair = par;
3408 }
3409  
3410  
3411 //_____________________________________________________________________________
3412 void TGeant3::SetPFIS(Int_t par)
3413 {
3414   //
3415   //  To control photo fission mechanism.
3416   //   par =0 no photo fission.
3417   //       =1 Photo fission. secondaries processed.
3418   //       =2 Photo fission. No secondaries stored.
3419   //  
3420   fGcphys->ipfis = par;
3421 }
3422   
3423 //_____________________________________________________________________________
3424 void TGeant3::SetPHOT(Int_t par)
3425 {
3426   //
3427   //  To control Photo effect.
3428   //   par =0 no photo electric effect.
3429   //       =1 Photo effect. Electron processed.
3430   //       =2 Photo effect. No electron stored.
3431   //  
3432   fGcphys->iphot = par;
3433 }
3434  
3435 //_____________________________________________________________________________
3436 void TGeant3::SetRAYL(Int_t par)
3437 {
3438   //
3439   //  To control Rayleigh scattering.
3440   //   par =0 no Rayleigh scattering.
3441   //       =1 Rayleigh.
3442   //  
3443   fGcphys->irayl = par;
3444 }
3445  
3446 //_____________________________________________________________________________
3447 void TGeant3::SetSWIT(Int_t sw, Int_t val)
3448 {
3449   //
3450   //  sw    Switch number
3451   //  val   New switch value
3452   //
3453   //  Change one element of array ISWIT(10) in /GCFLAG/
3454   //  
3455   if (sw <= 0 || sw > 10) return;
3456   fGcflag->iswit[sw-1] = val;
3457 }
3458  
3459  
3460 //_____________________________________________________________________________
3461 void TGeant3::SetTRIG(Int_t nevents)
3462 {
3463   //
3464   // Set number of events to be run
3465   //
3466   fGcflag->nevent = nevents;
3467 }
3468  
3469 //_____________________________________________________________________________
3470 void TGeant3::SetUserDecay(Int_t pdg)
3471 {
3472   //
3473   // Force the decays of particles to be done with Pythia
3474   // and not with the Geant routines. 
3475   // just kill pointers doing mzdrop
3476   //
3477   Int_t ipart = IdFromPDG(pdg);
3478   if(ipart<0) {
3479     printf("Particle %d not in geant\n",pdg);
3480     return;
3481   }
3482   Int_t jpart=fGclink->jpart;
3483   Int_t jpa=fZlq[jpart-ipart];
3484   //
3485   if(jpart && jpa) {
3486     Int_t jpa1=fZlq[jpa-1];
3487     if(jpa1)
3488       mzdrop(fGcbank->ixcons,jpa1,PASSCHARD(" ") PASSCHARL(" "));
3489     Int_t jpa2=fZlq[jpa-2];
3490     if(jpa2)
3491       mzdrop(fGcbank->ixcons,jpa2,PASSCHARD(" ") PASSCHARL(" "));
3492   }
3493 }
3494
3495 //______________________________________________________________________________
3496 void TGeant3::Vname(const char *name, char *vname)
3497 {
3498   //
3499   //  convert name to upper case. Make vname at least 4 chars
3500   //
3501   Int_t l = strlen(name);
3502   Int_t i;
3503   l = l < 4 ? l : 4;
3504   for (i=0;i<l;i++) vname[i] = toupper(name[i]);
3505   for (i=l;i<4;i++) vname[i] = ' ';
3506   vname[4] = 0;      
3507 }
3508  
3509 //______________________________________________________________________________
3510 void TGeant3::Ertrgo()
3511 {
3512   ertrgo();
3513 }
3514
3515 //______________________________________________________________________________
3516 void TGeant3::Ertrak(const Float_t *const x1, const Float_t *const p1, 
3517                         const Float_t *x2, const Float_t *p2,
3518                         Int_t ipa,  Option_t *chopt)
3519 {
3520   ertrak(x1,p1,x2,p2,ipa,PASSCHARD(chopt) PASSCHARL(chopt));
3521 }
3522         
3523 //_____________________________________________________________________________
3524 void TGeant3::WriteEuclid(const char* filnam, const char* topvol,
3525                           Int_t number, Int_t nlevel)
3526 {
3527   //
3528   //
3529   //     ******************************************************************
3530   //     *                                                                *
3531   //     *  Write out the geometry of the detector in EUCLID file format  *
3532   //     *                                                                *
3533   //     *       filnam : will be with the extension .euc                 *
3534   //     *       topvol : volume name of the starting node                *
3535   //     *       number : copy number of topvol (relevant for gsposp)     *
3536   //     *       nlevel : number of  levels in the tree structure         *
3537   //     *                to be written out, starting from topvol         *
3538   //     *                                                                *
3539   //     *       Author : M. Maire                                        *
3540   //     *                                                                *
3541   //     ******************************************************************
3542   //
3543   //     File filnam.tme is written out with the definitions of tracking
3544   //     medias and materials.
3545   //     As to restore original numbers for materials and medias, program
3546   //     searches in the file euc_medi.dat and comparing main parameters of
3547   //     the mat. defined inside geant and the one in file recognizes them
3548   //     and is able to take number from file. If for any material or medium,
3549   //     this procedure fails, ordering starts from 1.
3550   //     Arrays IOTMED and IOMATE are used for this procedure
3551   //
3552   const char shape[][5]={"BOX ","TRD1","TRD2","TRAP","TUBE","TUBS","CONE",
3553                          "CONS","SPHE","PARA","PGON","PCON","ELTU","HYPE",
3554                          "GTRA","CTUB"};
3555   Int_t i, end, itm, irm, jrm, k, nmed;
3556   Int_t imxtmed=0;
3557   Int_t imxmate=0;
3558   FILE *lun;
3559   char *filext, *filetme;
3560   char natmed[21], namate[21];
3561   char natmedc[21], namatec[21];
3562   char key[5], name[5], mother[5], konly[5];
3563   char card[133];
3564   Int_t iadvol, iadtmd, iadrot, nwtot, iret;
3565   Int_t mlevel, numbr, natt, numed, nin, ndata;
3566   Int_t iname, ivo, ish, jvo, nvstak, ivstak;
3567   Int_t jdiv, ivin, in, jin, jvin, irot;
3568   Int_t jtm, imat, jma, flag=0, imatc;
3569   Float_t az, dens, radl, absl, a, step, x, y, z;
3570   Int_t npar, ndvmx, left;
3571   Float_t zc, densc, radlc, abslc, c0, tmaxfd;
3572   Int_t nparc, numb;
3573   Int_t iomate[100], iotmed[100];
3574   Float_t par[50], att[20], ubuf[50];
3575   Float_t *qws;
3576   Int_t   *iws;
3577   Int_t level, ndiv, iaxe;
3578   Int_t itmedc, nmatc, isvolc, ifieldc, nwbufc, isvol, nmat, ifield, nwbuf;
3579   Float_t fieldmc, tmaxfdc, stemaxc, deemaxc, epsilc, stminc, fieldm;
3580   Float_t tmaxf, stemax, deemax, epsil, stmin;
3581   const char *f10000="!\n%s\n!\n";
3582   //Open the input file
3583   end=strlen(filnam);
3584   for(i=0;i<end;i++) if(filnam[i]=='.') {
3585     end=i;
3586     break;
3587   }
3588   filext=new char[end+5];
3589   filetme=new char[end+5];
3590   strncpy(filext,filnam,end);
3591   strncpy(filetme,filnam,end);
3592   //
3593   // *** The output filnam name will be with extension '.euc'
3594   strcpy(&filext[end],".euc");
3595   strcpy(&filetme[end],".tme");
3596   lun=fopen(filext,"w");
3597   //
3598   // *** Initialisation of the working space
3599   iadvol=fGcnum->nvolum;
3600   iadtmd=iadvol+fGcnum->nvolum;
3601   iadrot=iadtmd+fGcnum->ntmed;
3602   if(fGclink->jrotm) {
3603     fGcnum->nrotm=fZiq[fGclink->jrotm-2];
3604   } else {
3605     fGcnum->nrotm=0;
3606   }
3607   nwtot=iadrot+fGcnum->nrotm;
3608   qws = new float[nwtot+1];
3609   for (i=0;i<nwtot+1;i++) qws[i]=0;
3610   iws = (Int_t*) qws;
3611   mlevel=nlevel;
3612   if(nlevel==0) mlevel=20;
3613   //
3614   // *** find the top volume and put it in the stak
3615   numbr = number>0 ? number : 1;
3616   Gfpara(topvol,numbr,1,npar,natt,par,att);
3617   if(npar <= 0) {
3618     printf(" *** GWEUCL *** top volume : %s number : %3d can not be a valid root\n",
3619            topvol, numbr);
3620     return;
3621   }
3622   //
3623   // ***  authorized shape ?
3624   strncpy((char *)&iname, topvol, 4);
3625   ivo=0;
3626   for(i=1; i<=fGcnum->nvolum; i++) if(fZiq[fGclink->jvolum+i]==iname) {
3627     ivo=i;
3628     break;
3629   }
3630   jvo = fZlq[fGclink->jvolum-ivo];
3631   ish = Int_t (fZq[jvo+2]);
3632   if(ish > 12) {
3633     printf(" *** GWEUCL *** top volume : %s number : %3d can not be a valid root\n",
3634            topvol, numbr);
3635   }
3636   //
3637   level = 1;
3638   nvstak = 1;
3639   iws[nvstak]     = ivo;
3640   iws[iadvol+ivo] = level;
3641   ivstak = 0;
3642   //
3643   //*** flag all volumes and fill the stak
3644   //
3645  L10:
3646   //
3647   //    pick the next volume in stak
3648   ivstak += 1;
3649   ivo   = TMath::Abs(iws[ivstak]);
3650   jvo   = fZlq[fGclink->jvolum - ivo];
3651   //
3652   //     flag the tracking medium
3653   numed =  Int_t (fZq[jvo + 4]);
3654   iws[iadtmd + numed] = 1;
3655   //
3656   //    get the daughters ...
3657   level = iws[iadvol+ivo];
3658   if (level < mlevel) {
3659     level +=  1;
3660     nin = Int_t (fZq[jvo + 3]);
3661     //
3662     //       from division ...
3663     if (nin < 0) {
3664       jdiv = fZlq[jvo  - 1];
3665       ivin =  Int_t (fZq[jdiv + 2]);
3666       nvstak += 1;
3667       iws[nvstak]      = -ivin;
3668       iws[iadvol+ivin] =  level;
3669       //
3670       //       from position ...
3671     } else if (nin > 0) {
3672       for(in=1; in<=nin; in++) {
3673         jin  = fZlq[jvo - in];
3674         ivin =  Int_t (fZq[jin + 2 ]);
3675         jvin = fZlq[fGclink->jvolum - ivin];
3676         ish  =  Int_t (fZq[jvin + 2]);
3677         //              authorized shape ?
3678         if (ish <= 12) {
3679           //                 not yet flagged ?
3680           if (iws[iadvol+ivin]==0) {
3681             nvstak += 1;
3682             iws[nvstak]      = ivin;
3683             iws[iadvol+ivin] = level;
3684           }
3685           //                 flag the rotation matrix
3686           irot = Int_t ( fZq[jin + 4 ]);
3687           if (irot > 0) iws[iadrot+irot] = 1;
3688         }
3689       }
3690     }
3691   }
3692   //
3693   //     next volume in stak ?
3694   if (ivstak < nvstak) goto L10;
3695   //
3696   // *** restore original material and media numbers
3697   // file euc_medi.dat is needed to compare materials and medias
3698   //
3699   FILE* luncor=fopen("euc_medi.dat","r");
3700   //
3701   if(luncor) {
3702     for(itm=1; itm<=fGcnum->ntmed; itm++) {
3703       if (iws[iadtmd+itm] > 0) {
3704         jtm = fZlq[fGclink->jtmed-itm];
3705         strncpy(natmed,(char *)&fZiq[jtm+1],20);
3706         imat =  Int_t (fZq[jtm+6]);
3707         jma  = fZlq[fGclink->jmate-imat];
3708         if (jma <= 0) {
3709           printf(" *** GWEUCL *** material not defined for tracking medium %5i %s\n",itm,natmed);
3710           flag=1;
3711         } else {
3712           strncpy(namate,(char *)&fZiq[jma+1],20);
3713         }
3714         //*
3715         //** find the material original number
3716         rewind(luncor);
3717       L23:
3718         iret=fscanf(luncor,"%4s,%130s",key,card);
3719         if(iret<=0) goto L26;
3720         flag=0;
3721         if(!strcmp(key,"MATE")) {
3722           sscanf(card,"%d %s %f %f %f %f %f %d",&imatc,namatec,&az,&zc,&densc,&radlc,&abslc,&nparc);
3723           Gfmate(imat,namate,a,z,dens,radl,absl,par,npar);
3724           if(!strcmp(namatec,namate)) {
3725             if(az==a && zc==z && densc==dens && radlc==radl 
3726                && abslc==absl && nparc==nparc) {
3727               iomate[imat]=imatc;
3728               flag=1;
3729               printf("*** GWEUCL *** material : %3d '%s' restored as %3d\n",imat,namate,imatc);
3730             } else {
3731               printf("*** GWEUCL *** different definitions for material: %s\n",namate);
3732             }
3733           }
3734         }
3735         if(strcmp(key,"END") && !flag) goto L23;
3736         if (!flag) {
3737           printf("*** GWEUCL *** cannot restore original number for material: %s\n",namate);
3738         }
3739         //*
3740         //*
3741         //***  restore original tracking medium number
3742         rewind(luncor);
3743       L24:
3744         iret=fscanf(luncor,"%4s,%130s",key,card);
3745         if(iret<=0) goto L26;
3746         flag=0;
3747         if (!strcmp(key,"TMED")) {
3748           sscanf(card,"%d %s %d %d %d %f %f %f %f %f %f %d\n",
3749                  &itmedc,natmedc,&nmatc,&isvolc,&ifieldc,&fieldmc,
3750                  &tmaxfdc,&stemaxc,&deemaxc,&epsilc,&stminc,&nwbufc);
3751           Gftmed(itm,natmed,nmat,isvol,ifield,fieldm,tmaxf,stemax,deemax,
3752                         epsil,stmin,ubuf,&nwbuf);
3753           if(!strcmp(natmedc,natmed)) {
3754             if (iomate[nmat]==nmatc && nwbuf==nwbufc) {
3755               iotmed[itm]=itmedc;
3756               flag=1;
3757               printf("*** GWEUCL *** medium   : %3d '%20s' restored as %3d\n",
3758                      itm,natmed,itmedc);
3759             } else {
3760               printf("*** GWEUCL *** different definitions for tracking medium: %s\n",natmed);
3761             }
3762           }
3763         }
3764         if(strcmp(key,"END") && !flag) goto L24;
3765         if(!flag) {
3766           printf("cannot restore original number for medium : %s\n",natmed);
3767           goto L27;
3768         }
3769       }
3770     }
3771     goto L29;
3772     //*
3773   }
3774  L26:   printf("*** GWEUCL *** cannot read the data file\n");
3775  L27:   flag=2;
3776  L29:   if(luncor) fclose (luncor);
3777   //
3778   //
3779   // *** write down the tracking medium definition
3780   //
3781   strcpy(card,"!       Tracking medium");
3782   fprintf(lun,f10000,card);
3783   //
3784   for(itm=1;itm<=fGcnum->ntmed;itm++) {
3785     if (iws[iadtmd+itm]>0) {
3786       jtm  = fZlq[fGclink->jtmed-itm];
3787       strncpy(natmed,(char *)&fZiq[jtm+1],20);
3788       natmed[20]='\0';
3789       imat =  Int_t (fZq[jtm+6]);
3790       jma  = fZlq[fGclink->jmate-imat];
3791       //*  order media from one, if comparing with database failed
3792       if (flag==2) {
3793         iotmed[itm]=++imxtmed;
3794         iomate[imat]=++imxmate;
3795       }
3796       //*
3797       if(jma<=0) {
3798         strcpy(namate,"                  ");
3799         printf(" *** GWEUCL *** material not defined for tracking medium %5d %s\n",
3800                itm,natmed);
3801       } else {
3802         strncpy(namate,(char *)&fZiq[jma+1],20);
3803         namate[20]='\0';
3804       }
3805       fprintf(lun,"TMED %3d '%20s' %3d '%20s'\n",iotmed[itm],natmed,iomate[imat],namate);
3806     }
3807   }
3808   //*
3809       //* *** write down the rotation matrix
3810   //*
3811   strcpy(card,"!       Reperes");
3812   fprintf(lun,f10000,card);
3813   //
3814   for(irm=1;irm<=fGcnum->nrotm;irm++) {
3815     if (iws[iadrot+irm]>0) {
3816       jrm  = fZlq[fGclink->jrotm-irm];
3817       fprintf(lun,"ROTM %3d",irm);
3818       for(k=11;k<=16;k++) fprintf(lun," %8.3f",fZq[jrm+k]);
3819       fprintf(lun,"\n");
3820     }
3821   }
3822   //*
3823   //* *** write down the volume definition
3824   //*
3825   strcpy(card,"!       Volumes");
3826   fprintf(lun,f10000,card);
3827   //*
3828   for(ivstak=1;ivstak<=nvstak;ivstak++) {
3829     ivo = iws[ivstak];
3830     if (ivo>0) {
3831       strncpy(name,(char *)&fZiq[fGclink->jvolum+ivo],4);
3832       name[4]='\0';
3833       jvo  = fZlq[fGclink->jvolum-ivo];
3834       ish   = Int_t (fZq[jvo+2]);
3835       nmed  = Int_t (fZq[jvo+4]);
3836       npar  = Int_t (fZq[jvo+5]);
3837       if (npar>0) {
3838         if (ivstak>1) for(i=0;i<npar;i++) par[i]=fZq[jvo+7+i];
3839         Gckpar (ish,npar,par);
3840         fprintf(lun,"VOLU '%4s' '%4s' %3d %3d\n",name,shape[ish-1],iotmed[nmed],npar);
3841         for(i=0;i<(npar-1)/6+1;i++) {
3842           fprintf(lun,"     ");
3843           left=npar-i*6;
3844           for(k=0;k<(left<6?left:6);k++) fprintf(lun," %11.5f",par[i*6+k]);
3845           fprintf(lun,"\n");
3846         }
3847       } else {
3848         fprintf(lun,"VOLU '%4s' '%4s' %3d %3d\n",name,shape[ish-1],iotmed[nmed],npar);
3849       }
3850     }
3851   }
3852   //*
3853   //* *** write down the division of volumes
3854   //*
3855   fprintf(lun,f10000,"!       Divisions");
3856   for(ivstak=1;ivstak<=nvstak;ivstak++) {
3857     ivo = TMath::Abs(iws[ivstak]);
3858     jvo  = fZlq[fGclink->jvolum-ivo];
3859     ish  = Int_t (fZq[jvo+2]);
3860     nin  = Int_t (fZq[jvo+3]);
3861     //*        this volume is divided ...
3862     if (nin<0) {
3863       jdiv = fZlq[jvo-1];
3864       iaxe = Int_t ( fZq[jdiv+1]);
3865       ivin = Int_t ( fZq[jdiv+2]);
3866       ndiv = Int_t ( fZq[jdiv+3]);
3867       c0   =  fZq[jdiv+4];
3868       step =  fZq[jdiv+5];
3869       jvin = fZlq[fGclink->jvolum-ivin];
3870       nmed = Int_t ( fZq[jvin+4]);
3871       strncpy(mother,(char *)&fZiq[fGclink->jvolum+ivo ],4);
3872       mother[4]='\0';
3873       strncpy(name,(char *)&fZiq[fGclink->jvolum+ivin],4);
3874       name[4]='\0';
3875       if ((step<=0.)||(ish>=11)) {
3876         //*              volume with negative parameter or gsposp or pgon ...
3877         fprintf(lun,"DIVN '%4s' '%4s' %3d %3d\n",name,mother,ndiv,iaxe);
3878       } else if ((ndiv<=0)||(ish==10)) {
3879         //*              volume with negative parameter or gsposp or para ...
3880         ndvmx = TMath::Abs(ndiv);
3881         fprintf(lun,"DIVT '%4s' '%4s' %11.5f %3d %3d %3d\n",
3882                 name,mother,step,iaxe,iotmed[nmed],ndvmx);
3883       } else {
3884         //*              normal volume : all kind of division are equivalent
3885         fprintf(lun,"DVT2 '%4s' '%4s' %11.5f %3d %11.5f %3d %3d\n",
3886                 name,mother,step,iaxe,c0,iotmed[nmed],ndiv);
3887       }
3888     }
3889   }
3890   //*
3891   //* *** write down the the positionnement of volumes
3892   //*
3893   fprintf(lun,f10000,"!       Positionnements\n");
3894   //
3895   for(ivstak = 1;ivstak<=nvstak;ivstak++) {
3896     ivo = TMath::Abs(iws[ivstak]);
3897     strncpy(mother,(char*)&fZiq[fGclink->jvolum+ivo ],4);
3898     mother[4]='\0';
3899     jvo  = fZlq[fGclink->jvolum-ivo];
3900     nin  = Int_t( fZq[jvo+3]);
3901     //*        this volume has daughters ...
3902     if (nin>0) {
3903       for (in=1;in<=nin;in++) {
3904         jin  = fZlq[jvo-in];
3905         ivin =  Int_t (fZq[jin +2]);
3906         numb =  Int_t (fZq[jin +3]);
3907         irot =  Int_t (fZq[jin +4]);
3908         x    =  fZq[jin +5];
3909         y    =  fZq[jin +6];
3910         z    =  fZq[jin +7];
3911         strcpy(konly,"ONLY");
3912         if (fZq[jin+8]!=1.) strcpy(konly,"MANY");
3913         strncpy(name,(char*)&fZiq[fGclink->jvolum+ivin],4);
3914         name[4]='\0';
3915         jvin = fZlq[fGclink->jvolum-ivin];
3916         ish  = Int_t (fZq[jvin+2]);
3917         //*              gspos or gsposp ?
3918         ndata = fZiq[jin-1];
3919         if (ndata==8) {
3920           fprintf(lun,"POSI '%4s' %4d '%4s' %11.5f %11.5f %11.5f %3d '%4s'\n",
3921                   name,numb,mother,x,y,z,irot,konly);
3922         } else {
3923           npar =  Int_t (fZq[jin+9]);
3924           for(i=0;i<npar;i++) par[i]=fZq[jin+10+i];
3925           Gckpar (ish,npar,par);
3926           fprintf(lun,"POSP '%4s' %4d '%4s' %11.5f %11.5f %11.5f %3d '%4s' %3d\n",
3927                   name,numb,mother,x,y,z,irot,konly,npar);
3928           fprintf(lun,"     ");
3929           for(i=0;i<npar;i++) fprintf(lun," %11.5f",par[i]);
3930           fprintf(lun,"\n");
3931         }
3932       }
3933     }
3934   }
3935   //*
3936   fprintf(lun,"END\n");
3937   fclose(lun);
3938   //*
3939   //****** write down the materials and medias *****
3940   //*
3941   lun=fopen(filetme,"w");
3942   //*
3943   for(itm=1;itm<=fGcnum->ntmed;itm++) {
3944     if (iws[iadtmd+itm]>0) {
3945       jtm  = fZlq[fGclink->jtmed-itm];
3946       strncpy(natmed,(char*)&fZiq[jtm+1],4);
3947       imat =  Int_t (fZq[jtm+6]);
3948       jma  =  Int_t (fZlq[fGclink->jmate-imat]);
3949       //*  material
3950       Gfmate (imat,namate,a,z,dens,radl,absl,par,npar);
3951       fprintf(lun,"MATE %4d '%20s'%11.5E %11.5E %11.5E %11.5E %11.5E %3d\n",
3952              iomate[imat],namate,a,z,dens,radl,absl,npar);
3953       //*
3954       if (npar>0) {
3955           fprintf(lun,"     ");
3956           for(i=0;i<npar;i++) fprintf(lun," %11.5f",par[i]);
3957           fprintf(lun,"\n");
3958       }
3959       //*  medium
3960       Gftmed(itm,natmed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par,&npar);
3961       fprintf(lun,"TMED %4d '%20s' %3d %1d %3d %11.5f %11.5f %11.5f %11.5f %11.5f %11.5f %3d\n",
3962               iotmed[itm],natmed,iomate[nmat],isvol,ifield,
3963               fieldm,tmaxfd,stemax,deemax,epsil,stmin,npar);
3964       //*
3965       if (npar>0) {
3966           fprintf(lun,"     ");
3967           for(i=0;i<npar;i++) fprintf(lun," %11.5f",par[i]);
3968           fprintf(lun,"\n");
3969       }
3970       
3971     }
3972   }
3973   fprintf(lun,"END\n");
3974   fclose(lun);
3975   printf(" *** GWEUCL *** file: %s is now written out\n",filext);
3976   printf(" *** GWEUCL *** file: %s is now written out\n",filetme);
3977   // Clean up
3978   delete [] filext;
3979   delete [] filetme;
3980   delete [] qws;
3981   iws=0;
3982   return;
3983 }
3984
3985 //_____________________________________________________________________________
3986 void TGeant3::Streamer(TBuffer &R__b)
3987 {
3988   //
3989   // Stream an object of class TGeant3.
3990   //
3991   if (R__b.IsReading()) {
3992     Version_t R__v = R__b.ReadVersion(); if (R__v) { }
3993     AliMC::Streamer(R__b);
3994     R__b >> fNextVol;
3995     R__b >> fNPDGCodes;
3996     R__b.ReadStaticArray(fPDGCode);
3997   } else {
3998     R__b.WriteVersion(TGeant3::IsA());
3999     AliMC::Streamer(R__b);
4000     R__b << fNextVol;
4001     R__b << fNPDGCodes;
4002     R__b.WriteArray(fPDGCode, fNPDGCodes);
4003   }
4004 }
4005
4006