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