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