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