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