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