forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
g2root.f
1625 lines (1571 loc) · 51.2 KB
/
g2root.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*CMZ : 2.22/00 08/04/99 18.41.30 by Rene Brun
*CMZ : 2.21/05 08/02/99 12.19.15 by Rene Brun
*CMZ : 2.00/11 22/08/98 15.25.26 by Rene Brun
*CMZ : 2.00/10 28/07/98 13.32.42 by Rene Brun
*-- Author :
Program g2root
*
**********************************************************************
*
* Program to convert an existing GEANT geometry/RZ file
* into a ROOT macro (C++ file).
*
* Author: Rene Brun
* modified by Nikolay I. Root <nroot@inp.nsk.su> to support map_names
* modified by Mihaela Gheata for the new geometry format
*
* To use this conversion program (in $ROOTSYS/bin),
* g2root [-f <map_names>] <geant_rzfile> <macro_name> [lrecl]
* run g2root without parameters to see the usage info.
*
* for example
* g2root brahms.geom brahms.C
* will convert the GEANT RZ file brahms.geom into a ROOT macro brahms.C
*
* The default value for lrecl is 1024. The parameter lrecl must be specified
* if the record length of the Zebra file is greater than 1024.
*
*
* To generate the Geometry structure within Root, do:
*
* root[0]> .x brahms.C;
* root[0]> new TBrowser();
*
* An interactive session
* ------------------------
*
* Provided that a geometry was successfully built and closed , the manager class will
* register itself to ROOT and the logical/physical structures will become immediately
* browsable. The ROOT browser will display starting from the geometry folder : the list of
* transformations and materials, the top volume and the top logical node. These last
* two can be fully expanded, any intermediate volume/node in the browser being subject
* of direct access context menu operations (right mouse button click). All user
* utilities of classes TGeoManager, TGeoVolume and TGeoNode can be called via the
* context menu.
*
* see http://root.cern.ch/root/htmldoc/gif/t_browser.jpg
*
* --- Drawing the geometry
*
* Any logical volume can be drawn via TGeoVolume::Draw() member function.
* This can be direcly accessed from the context menu of the volume object
* directly from the browser.
* There are several drawing options that can be set with
* TGeoManager::SetVisOption(Int_t opt) method :
* opt=0 - only the content of the volume is drawn, N levels down (default N=3).
* This is the default behavior. The number of levels to be drawn can be changed
* via TGeoManager::SetVisLevel(Int_t level) method.
*
* see http://root.cern.ch/root/htmldoc/gif/t_frame0.jpg
*
* opt=1 - the final leaves (e.g. daughters with no containment) of the branch
* starting from volume are drawn down to the current number of levels.
* WARNING : This mode is memory consuming
* depending of the size of geometry, so drawing from top level within this mode
* should be handled with care for expensive geometries. In future there will be
* a limitation on the maximum number of nodes to be visualized.
*
* see http://root.cern.ch/root/htmldoc/gif/t_frame1.jpg
*
* opt=2 - only the clicked volume is visualized. This is automatically set by
* TGeoVolume::DrawOnly() method
* opt=3 - only a given path is visualized. This is automatically set by
* TGeoVolume::DrawPath(const char *path) method
*
* The current view can be exploded in cartesian, cylindrical or spherical
* coordinates :
* TGeoManager::SetExplodedView(Int_t opt). Options may be :
* - 0 - default (no bombing)
* - 1 - cartesian coordinates. The bomb factor on each axis can be set with
* TGeoManager::SetBombX(Double_t bomb) and corresponding Y and Z.
* - 2 - bomb in cylindrical coordinates. Only the bomb factors on Z and R
* are considered
*
* see http://root.cern.ch/root/htmldoc/gif/t_frameexpl.jpg
*
* - 3 - bomb in radial spherical coordinate : TGeoManager::SetBombR()
*
* Volumes themselves support different visualization settings :
* - TGeoVolume::SetVisibility() : set volume visibility.
* - TGeoVolume::VisibleDaughters() : set daughters visibility.
* All these actions automatically updates the current view if any.
*
* --- Checking the geometry
*
* Several checking methods are accesible from the volume context menu. They
* generally apply only to the visible parts of the drawn geometry in order to
* ease geometry checking, and their implementation is in the TGeoChecker class
* from the painting package.
*
* 1. Checking a given point.
* Can be called from TGeoManager::CheckPoint(Double_t x, Double_t y, Double_t z).
* This method is drawing the daughters of the volume containing the point one
* level down, printing the path to the deepest physical node holding this point.
* It also computes the closest distance to any boundary. The point will be drawn
* in red.
*
* see http://root.cern.ch/root/htmldoc/gif/t_checkpoint.jpg
*
* 2. Shooting random points.
* Can be called from TGeoVolume::RandomPoints() (context menu function) and
* it will draw this volume with current visualization settings. Random points
* are generated in the bounding box of the top drawn volume. The points are
* classified and drawn with the color of their deepest container. Only points
* in visible nodes will be drawn.
*
* see http://root.cern.ch/root/htmldoc/gif/t_random1.jpg
*
*
* 3. Raytracing.
* Can be called from TGeoVolume::RandomRays() (context menu of volumes) and
* will shoot rays from a given point in the local reference frame with random
* directions. The intersections with displayed nodes will appear as segments
* having the color of the touched node. Drawn geometry will be then made invisible
* in order to enhance rays.
*
* see http://root.cern.ch/root/htmldoc/gif/t_random2.jpg
*
* IMPORTANT NOTE
* To be compiled, this program requires a Fortran compiler supporting
* recursive calls.
*
**********************************************************************
* NOT YET MAPPED FROM OLD g2root
**********************************************************************
* The following lines starting with the 2 characters ** are an example
* of (map_names> file.
* To make a valid <map_names> file, remove these 2 characters.
*
**#
**# formal definitions :
**#
**# 'comments' - the things that are ignored by the parser.
**# The lines starting with '#' or ' ' - comments
**# 'map' - first two words of 'non-comments'
**# ==> the trailing part of this lines - also 'comments'
**
**# next lines are the 'map' examples :
**
**CMD2 Detector Names translation map for CMD2 detector
**VALL Internals Internal part of detector.
**VTBE TubeBe
**VTAL TubeAL
**VTML DCInner
**DC0_ DCOuter
**DRIF DCCell
**
** first part of map ('key') consists of exactly 4 characters,
** including trailing blanks. This part of map is a key of
** GEANT3 volumes/detectors.
** The second part - 'name' - is just a sequence of non-blank chars.
** 'name' is used as a replacement of 'key' in g2root output file.
**
** 'alias' - is a map with 'key' and 'name'
** having one 'stab character' - '%'.
**
**DCC% DCSector% - example of alias.
**
** For above example - any 'keys' that have first 3 chars 'DCC'
** would be matched by this alias.
** The last char of 'key' - 'stab' - used as substitution for
** '%' in 'name' (like gmake rules, but not so complicated).
**
** Keys are matched against aliases only if they do not
** match any explicit 'map'. First found alias, that match
** the key - is used for substitution.
**
** ==> The order of aliases is important for matching !
**
** The last alias may be like this :
**
**% Block% Match any key !
**
**% % <- assumed by default.
*
**********************************************************************
parameter (nwpaw=4000000)
common/pawc/paw(nwpaw)
character *80 gname
character *80 fname
character *8 chtop
character *8 crecl
integer npar, lrecl
call hlimit(nwpaw)
npar = iargc()
if (npar.eq.0) then
print *,
+ 'Invoke g2root [-f map_name] geant_name macro_name [lrecl]'
go to 90
endif
narg = 1
call getarg(narg,gname)
narg = narg + 1
npar = npar - 1
if(gname .eq. "-f") then
if(npar .eq. 0) then
print *,'Invoke g2root [-f map_name] geant_name macro_name'
print *,' Parse error: you need specify <map_name>'
go to 90
endif
call getarg(narg,gname)
call create_map(gname)
narg = narg + 1
npar = npar - 1
if(npar .eq. 0) then
print *,'Invoke g2root [-f map_name] geant_name macro_name'
print *,' Parse error: you need specify <geant_name>'
go to 90
endif
call getarg(narg,gname)
narg = narg + 1
npar = npar - 1
endif
if (npar.ge.1) then
call getarg(narg,fname)
narg = narg + 1
else
idot=index(gname,'.')
fname = gname(1:idot-1)//'.C'
endif
lrecl = 1024
if (npar.ge.2) then
call getarg(narg,crecl)
read (crecl,'(I6)') lrecl
endif
call rzopen(1,chtop,gname,'W',lrecl,istat)
if (istat.ne.0) then
print *,'Cannot open file'
go to 90
endif
call rzfile(1,chtop,' ')
* call rzldir(' ',' ')
call g2rin
call toroot(fname)
lg = lenocc(gname)
lf = lenocc(fname)
print 1000,gname(1:lg),fname(1:lf)
1000 format(' GEANT file: ',a, ' converted to ROOT macro: ',a)
90 continue
end
Subroutine toroot(fname)
*
**********************************************************************
*
* Rotation matrices (structure JROTM) are saved into a linked
* list of class objects TRotMatrix.
* The JVOLUM structure generates the following lists:
* - the TMaterial list (material definition only).
* - the TRotmatrix list (Rotation matrices definition only).
* - the TShape list (volume definition only).
* - the TNode list assembling all detector elements
* the TNode list is a real tree.
* The Node list contains two variants TNode and TNodeDiv
* corresponding to the GSPOS and GSDIV mechanisms.
*
* Author: Rene Brun
**********************************************************************
*
*KEEP,HCBOOK.
parameter (nwpaw=4000000)
common/pawc/paw(nwpaw)
INTEGER IQ(2), LQ(8000)
REAL Q(2)
EQUIVALENCE (LQ(1),paw(11)),(IQ(1),paw(19)),(Q(1),paw(19))
INTEGER JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
COMMON/GCLINK/JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
*KEEP,GCNUM.
COMMON/GCNUM/NMATE ,NVOLUM,NROTM,NTMED,NTMULT,NTRACK,NPART
+ ,NSTMAX,NVERTX,NHEAD,NBIT
*
common/cnodes/nnodes
parameter (MAXPOS=250000)
* parameter (MAXPOS=50000)
common/cnpos/nodepos(MAXPOS),nodediv(MAXPOS),nvflags(MAXPOS),
+npflags(MAXPOS),nppflags(MAXPOS)
CHARACTER*4 KSHAP(30),klshap(30)
character*20 matname,medname
character*16 cname,mname,pname, rname
character*(*) fname
character*256 line
character*128 creals
character*16 astring,astring2,ptrname
dimension pmixt(3)
logical map_found
DATA KSHAP/'BRIK','TRD1','TRD2','TRAP','TUBE','TUBS','CONE',
+ 'CONS','SPHE','PARA','PGON','PCON','ELTU','HYPE',
+ 13*' ','GTRA','CTUB',' '/
*________________________________________________________________________
*
open(unit=51,file=fname,status='unknown')
*
* Create new Geometry object
* ==========================
nch=lenocc(fname)
idot=index(fname,'.')
nct=idot-1
write(51,1111)fname(1:nct)
1111 format('void ',a,'()',/,'{',/,
+'//',/,
+'// This file has been generated automatically via the root',/,
+'// utility g2root from an interactive version of GEANT',/,
+'// (see ROOT class TGeoManager for an example of use)',/,
+'//',/,
+'gSystem->Load("libGeom");',/,
+'TGeoRotation *rot;',/,
+'TGeoNode *Node, *Node1;')
do 1 i=1,30
klshap(i) = kshap(i)
call cutol(klshap(i))
1 continue
do 2 i=1,MAXPOS
nodepos(i) = 0
nodediv(i) = 0
2 continue
nodepos(1) = 1
nodediv(1) = 1
write(51,490)fname(1:nct),fname(1:nct),fname(1:nch)
490 format(/,'TGeoManager *',a,' = new TGeoManager("',a,'","',a,'");'
+,/)
IF(JVOLUM.NE.0 ) NVOLUM = IQ(JVOLUM-2)
IF(JMATE.NE.0 ) NMATE = IQ(JMATE-2)
IF(JTMED.NE.0 ) NTMED = IQ(JTMED-2)
IF(JROTM.NE.0 ) NROTM = IQ(JROTM-2)
* Print Materials
* =======================
write(51,3019)
3019 format(/,
+'//-----------List of Materials and Mixtures--------------',/)
do 300 imat=1,nmate
jma=lq(jmate-imat)
if(jma.eq.0)go to 300
nmixt=q(jma+11)
call uhtoc(iq(jma+1),4,matname,20)
ncn=lenocc(matname)
call toint(imat,astring,nc)
nm=abs(nmixt)
*-* Case of a simple material
if (nm.le.1)then
call toreals(3,q(jma+6),creals,ncr)
if(q(jma+6).lt.1.and.q(jma+7).lt.1)then
creals=',0,0,0'
ncr=lenocc(creals)
endif
line=' '
write(line,3000)astring(1:nc),matname(1:ncn),creals(1:ncr)
3000 format('TGeoMaterial *mat',a,' = new TGeoMaterial("',a,
+ '"',a,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
write(line,3005) astring(1:nc),imat
3005 format(4x,'mat',a,'->SetUniqueID(',i4,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
*-* Case of a mixture
else
call toint(nm,creals,ncm)
jmixt=lq(jma-5)
if(nmixt.gt.0)then
mname=creals(1:ncm)
else
mname='-'//creals(1:ncm)
ncm=ncm+1
endif
line=' '
write(line,3010)astring(1:nc),matname(1:ncn),mname(1:ncm),
+ q(jma+8)
3010 format('TGeoMixture *mat',a,' = new TGeoMixture("',a,'",',a,
+ ',',g14.6,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
write(line,3011) astring(1:nc),imat
3011 format(4x,'mat',a,'->SetUniqueID(',i4,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
do 292 im=1,nm
call toint(im-1,astring2,nc2)
pmixt(1) = q(jmixt+im)
pmixt(2) = q(jmixt+nm+im)
pmixt(3) = q(jmixt+2*nm+im)
call toreals(3,pmixt,creals,ncr)
line=' '
write(line,3020)astring(1:nc),astring2(1:nc2),
+ creals(1:ncr)
3020 format(4x,'mat',a,'->DefineElement(',a,a,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
292 continue
endif
300 continue
* Print Tracking Media
* ====================
write(51,3069)
3069 format(/,
+'//-----------List of Tracking Media--------------',/)
do 350 itmed=1,ntmed
jtm=lq(jtmed-itmed)
if(jtm.eq.0)go to 350
imat=q(jtm+6)
call toint(imat,astring2,ncm)
call uhtoc(iq(jtm+1),4,medname,20)
ncn=lenocc(medname)
call toint(itmed,astring,nc)
call toreals(8,q(jtm+7),creals,ncr)
line=' '
write(line,3050)astring(1:nc),medname(1:ncn),astring(1:nc),
+ astring2(1:ncm),creals(1:ncr)
3050 format('TGeoMedium *med',a,' = new TGeoMedium("',a,'",',a,
+ ',',a,a,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
350 continue
* Print Rotation matrices
* =======================
write(51,3021)
3021 format(/,'//-----------List of Rotation matrices--------------',/)
do 100 irot=1,nrotm
jr=lq(jrotm-irot)
if(jr.eq.0)go to 100
call toint(irot,astring,nc)
call toreals(6,q(jr+11),creals,ncr)
line=' '
ptrname = 'rot'//astring(1:nc)
nch = nc+3
write(line,1000)ptrname(1:nch),ptrname(1:nch),
+ creals(1:ncr)
1000 format('TGeoRotation *',a,
+ ' = new TGeoRotation("',a,'"',a,');')
nch = lenocc(line)
write(51,'(a)')line(1:nch)
100 continue
* Print volume definition (ROOT shapes)
* =======================
write(51,3022)
3022 format(/,'//-----------List of Volumes--------------',/)
Print *,' nvolum= ',nvolum, ' jvolum=',jvolum
C
C ???? Convert GEANT3 keys to legal C++ names ?????
C
do 50 ivo = 1,nvolum
if (lq(jvolum-ivo).eq.0)go to 50 ! <-- That's
cname=' ' ! 'real'
* write(cname,'(a4)')iq(jvolum+ivo) ! trick !!!
call uhtoc(iq(jvolum+ivo),4,cname,4) ! <--
do 29 i=1,4
if (ichar(cname(i:i)).eq.0)cname(i:i) = ' '
29 continue
n1=lenocc(cname)
if(n1.lt.4)then
do 30 i=n1+1,4
cname(i:i)='_'
30 continue
endif
50 continue
C----------------------------------------------
do 77 ivo = 1,nvolum
77 nvflags(ivo) = 0
nlevel = 0
call markdiv(1,1)
do 200 ivo = 1,nvolum
if (nvflags(ivo).eq.2) goto 200
jv=lq(jvolum-ivo)
if (jv.eq.0)go to 200
cname=' '
if(.not.map_found(iq(jvolum+ivo),cname)) then
write(cname,'(a4)')iq(jvolum+ivo)
endif
call volume(cname,q(jv+1),0,0)
200 continue
do 88 ivo = 1,nvolum
nvflags(ivo) = 0
npflags(ivo) = 0
nppflags(ivo) = 0
88 continue
* Print volume positioning (ROOT nodes)
* ========================
nnodes = 1
nlevel = 0
if (nvolum.gt.0) then
call node(1,1,1)
write(51,3023)
3023 format(/,'//-----------List of Nodes--------------',/)
do 89 ivo = 1,nvolum
89 nvflags(ivo) = 0
call node(1,1,0)
endif
write(51,2223)
write(51,2222)
2222 format('}')
2223 format(' gGeoManager->CloseGeometry();')
close(51)
end
*_______________________________________________________________________
Subroutine markdiv2(ivo,nuserm)
call markdiv(ivo,nuserm)
End
*_______________________________________________________________________
Subroutine markdiv(ivo,nuserm)
*
* Process one node (volume with contents)
*KEEP,HCBOOK.
parameter (nwpaw=4000000)
parameter (MAXPOS=250000)
common/pawc/paw(nwpaw)
INTEGER IQ(2), LQ(8000)
REAL Q(2)
EQUIVALENCE (LQ(1),paw(11)),(IQ(1),paw(19)),(Q(1),paw(19))
INTEGER JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
COMMON/GCLINK/JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
common/cnodes/nnodes
common/clevel/nodeold(20),nlevel
common/cnpos/nodepos(MAXPOS),nodediv(MAXPOS),nvflags(MAXPOS),
+npflags(MAXPOS),nppflags(MAXPOS)
* dimension qjv(1000)
character*16 cname
*---------------------------------------------------------------------
nlevel = nlevel + 1
nodeold(nlevel) = nnodes
jv=lq(jvolum-ivo)
ishape = q(jv+2)
nin = q(jv+3)
*- Loop subnodes
if(nin.eq.0)then
nlevel=nlevel-1
return
endif
call cdnode(nodeold(nlevel))
if(nin.gt.0)then
if (nvflags(ivo).ne.0) then
goto 996
endif
nvflags(ivo)=1
* Volume has positioned contents
do 300 in=1,nin
jin=lq(jv-in)
ivom=q(jin+2)
nuser = q(jin+3)
jinvom = lq(jvolum-ivom)
ninvom = q(jinvom+3)
cname=' '
write(cname,'(a4)')iq(jvolum+ivom)
n1=lenocc(cname)
if(ninvom.ge.0)then
nnodes = nnodes+1
if (nnodes.gt.MAXPOS) then
print *,'Too many nodes =',nnodes
go to 300
endif
if (nodepos(nnodes).eq.0) then
nodepos(nnodes) = 1
endif
endif
if(ninvom.ne.0) then
call markdiv2(ivom,nuser)
endif
300 continue
else
nnodes = nnodes+1
if (nodediv(nnodes).eq.0) then
nodediv(nnodes) = 1
endif
jin=lq(jv-1)
ivod=q(jin+2)
if (nvflags(ivod).gt.0) goto 996
cname=' '
write(cname,'(a4)')iq(jvolum+ivod)
n1=lenocc(cname)
Print 200, cname(1:n1)
200 format('Division volume', a4)
call markdiv2(ivod,0)
nvflags(ivod) = 2
endif
996 continue
nlevel = nlevel - 1
if (nlevel.gt.0)call cdnode(nodeold(nlevel))
end
*_______________________________________________________________________
subroutine volume(cname,qjv,iposp,ifirst)
*KEEP,HCBOOK.
parameter (nwpaw=4000000)
parameter (MAXPOS=250000)
common/pawc/paw(nwpaw)
INTEGER IQ(2), LQ(8000)
REAL Q(2)
EQUIVALENCE (LQ(1),paw(11)),(IQ(1),paw(19)),(Q(1),paw(19))
INTEGER JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
COMMON/GCLINK/JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
common/cnpos/nodepos(MAXPOS),nodediv(MAXPOS),nvflags(MAXPOS),
+npflags(MAXPOS),nppflags(MAXPOS)
character *(*) cname
character*16 astring,cmater, pname, rname
character*128 creals
character*256 line
real qjv(100)
double precision RADDEG
dimension dummypars(100)
DIMENSION NPARS(30)
CHARACTER*6 KSHAP(30)
data dummypars/100*0./
DATA KSHAP/'Box','Trd1','Trd2','Trap','Tube','Tubs','Cone',
+ 'Cons','Sphere','Para','Pgon','Pcon','Eltu','Hype',
+ 13*' ','Gtra','Ctub',' '/
DATA NPARS/3,4,5,11,3,5,5,7,6,6,10,9,3,4,13*0,12,11,0/
*________________________________________________________________________
*
RADDEG = 57.2957795130823209
n1=lenocc(cname)
** print *, 'VOLUME n1=',n1,' cname=',cname(1:n1)
ishape = qjv(2)
numed = qjv(4)
jtm = lq(jtmed-numed)
call toint(numed,astring,nc)
cmater='med'//astring(1:nc)
ncmat = lenocc(cmater)
nord = qjv(1)
nin = qjv(3)
npar = qjv(5)
npar0 = npars(ishape)
**TRAP
jpar = 6
if (ishape.eq.4) then
ph = 0.
if (qjv(jpar+2).ne.0.)ph=atan2(qjv(jpar+3),qjv(jpar+2))*RADDEG
tt = sqrt(qjv(jpar+2)**2+qjv(jpar+3)**2)
qjv(jpar+2) = atan(tt)*RADDEG
if (ph.lt.0.0) ph = ph+360.0
qjv(jpar+3) = ph
qjv(jpar+7) = atan(qjv(jpar+7))*RADDEG
if (qjv(jpar+7).gt.90.0) qjv(jpar+7) = qjv(jpar+7)-180.0
qjv(jpar+11)= atan(qjv(jpar+11))*RADDEG
if (qjv(jpar+11).gt.90.0) qjv(jpar+11) = qjv(jpar+11)-180.0
endif
**PARA
if (ishape.eq.10) then
ph = 0.
if (qjv(jpar+5).ne.0.)ph=atan2(qjv(jpar+6),qjv(jpar+5))*RADDEG
tt = sqrt(qjv(jpar+5)**2+qjv(jpar+6)**2)
qjv(jpar+4) = atan(qjv(jpar+4))*RADDEG
if (qjv(jpar+4).gt.90.0) qjv(jpar+4) = qjv(jpar+4)-180.0
qjv(jpar+5) = atan(tt)*RADDEG
if (ph.lt.0.0) ph = ph+360.0
qjv(jpar+6) = ph
endif
if(ishape.eq.11)npar0=4
if(ishape.eq.12)npar0=3
**HYPE
if (ishape.eq.14) then
hyrmin = qjv(jpar+1)
hyrmax = qjv(jpar+2)
hydz = qjv(jpar+3)
hyst = qjv(jpar+4)
dummypars(1) = hyrmin
dummypars(2) = hyst
dummypars(3) = hyrmax
dummypars(4) = hyst
dummypars(5) = hydz
npar0 = -5
endif
* print 2351, cname(1:n1),kshap(ishape)
* 2351 format('Volume:',a, ' shape=',a)
if (npar.le.0) then
** print 2352, cname(1:n1),kshap(ishape)
** 2352 format('Warning, volume with 0 parameters:',a, ' shape=',a)
return
endif
if(npar0.le.0)then
call toreals(-npar0,dummypars(1),creals,ncr)
else
call toreals(npar0,qjv(7),creals,ncr)
endif
line=' '
nshape = lenocc(kshap(ishape))
call ptname(cname, pname)
np = lenocc(pname)
call realname(cname, rname)
nrr = lenocc(rname)
if (iposp.eq.0) then
write(line,2000)pname(1:np),kshap(ishape)(1:nshape)
+ ,rname(1:nrr),cmater(1:ncmat),creals(1:ncr)
else
if (ifirst.eq.1) then
write(line,2001)pname(1:np),rname(1:nrr),cmater(1:ncmat)
nch=lenocc(line)
write(51,'(a)')line(1:nch)
endif
line=' '
write(line,2002)pname(1:np),kshap(ishape)(1:nshape)
+ ,rname(1:nrr),cmater(1:ncmat),creals(1:ncr)
nch=lenocc(line)
write(51,'(a)')line(1:nch)
endif
2000 format(
+ 'TGeoVolume',' *',a,' = gGeoManager->Make',a,'("',a,'",'
+,a,a,');')
2001 format('TGeoVolumeMulti *',a,' = gGeoManager->MakeVolumeMulti("'
+,a,'", ',a,');')
2002 format(' ',a,'->AddVolume(gGeoManager->Make',a,'("',a,'",',
+a,a,'));')
nch = lenocc(line)
if (iposp.eq.0) write(51,'(a)')line(1:nch)
if(ishape.eq.11)then
ndz=qjv(10)
do iz=1,ndz
call toreals(3,qjv(11+(iz-1)*3),creals,ncr)
line=' '
call toint(iz-1,astring,nci)
if (iposp.eq.0) then
write(line,2010)pname(1:np),astring(1:nci),creals(1:ncr)
else
write(line,2011)pname(1:np),astring(1:nci),creals(1:ncr)
endif
nch = lenocc(line)
write(51,'(a)')line(1:nch)
enddo
endif
if(ishape.eq.12)then
ndz=qjv(9)
do iz=1,ndz
call toreals(3,qjv(10+(iz-1)*3),creals,ncr)
line=' '
call toint(iz-1,astring,nci)
if (iposp.eq.0) then
write(line,2010)pname(1:np),astring(1:nci),creals(1:ncr)
else
write(line,2011)pname(1:np),astring(1:nci),creals(1:ncr)
endif
nch = lenocc(line)
write(51,'(a)')line(1:nch)
enddo
endif
2010 format(2x,'((TGeoPcon*)',a,'->GetShape())->DefineSection(',
+ a,a,');')
2011 format(2x,'((TGeoPcon*)',a,'->GetLastShape())->DefineSection(',
+ a,a,');')
* Any attributes set ?
lseen = qjv(npar+8)
lstyle = qjv(npar+9)
lwidth = qjv(npar+10)
lcolor = qjv(npar+11)
lfill = qjv(npar+12)
if (lstyle.le.0) lstyle = 1
if (lwidth.le.0) lwidth = 1
if (lcolor.lt.0) lcolor = 1
if (lfill.lt.0) lfill = 0
* if(ivo.eq.1)lseen=0
* if(nord.lt.0)then
* print *,'ordering : ',-nord
* call toint(-nord,creals,ncr)
* endif
if ((iposp.eq.0).or.(ifirst.eq.1)) then
if(lseen.ne.1)then
call toint(lseen,creals,ncr)
write(51,195)pname(1:np),creals(1:ncr)
195 format(2x,a,'->SetVisibility(',a,');')
endif
if(lstyle.ne.1)then
call toint(lstyle,creals,ncr)
write(51,196)pname(1:np),creals(1:ncr)
196 format(2x,a,'->SetLineStyle(',a,');')
endif
if(lwidth.ne.1)then
call toint(lwidth,creals,ncr)
write(51,197)pname(1:np),creals(1:ncr)
197 format(2x,a,'->SetLineWidth(',a,');')
endif
if(lcolor.ne.1)then
call toint(lcolor,creals,ncr)
write(51,198)pname(1:np),creals(1:ncr)
198 format(2x,a,'->SetLineColor(',a,');')
endif
if(lfill.ne.0)then
call toint(lfill,creals,ncr)
write(51,199)pname(1:np),creals(1:ncr)
199 format(2x,a,'->SetFillStyle(',a,');')
endif
endif
end
*_______________________________________________________________________
Subroutine node2(ivo,nuserm,iposp)
call node(ivo,nuserm,iposp)
End
*_______________________________________________________________________
Subroutine node(ivo,nuserm,iposp)
*
* Process one node (volume with contents)
*KEEP,HCBOOK.
parameter (nwpaw=4000000)
parameter (MAXPOS=250000)
common/pawc/paw(nwpaw)
INTEGER IQ(2), LQ(8000)
REAL Q(2)
EQUIVALENCE (LQ(1),paw(11)),(IQ(1),paw(19)),(Q(1),paw(19))
INTEGER JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
COMMON/GCLINK/JDIGI ,JDRAW ,JHEAD ,JHITS ,JKINE ,JMATE ,JPART
+ ,JROTM ,JRUNG ,JSET ,JSTAK ,JGSTAT,JTMED ,JTRACK,JVERTX
+ ,JVOLUM,JXYZ ,JGPAR ,JGPAR2,JSKLT
C
common/cnodes/nnodes
common/clevel/nodeold(20),nlevel
common/cnpos/nodepos(MAXPOS),nodediv(MAXPOS),nvflags(MAXPOS),
+npflags(MAXPOS),nppflags(MAXPOS)
dimension qjv(1000)
character*16 cnode,cname,mname,anode,mother,pname, rname
integer nmother
character*256 line
character*128 creals
character*16 astring,astring1
character*16 matrix
character*256 matrixs
character *16 cblank
Logical map_found
data cblank/' '/
*---------------------------------------------------------------------
cblank = ' '
nlevel = nlevel + 1
nodeold(nlevel) = nnodes
jv=lq(jvolum-ivo)
ishape = q(jv+2)
nin = q(jv+3)
mname=' '
if(.not.map_found(iq(jvolum+ivo),mname)) then
write(mname,'(a4)')iq(jvolum+ivo)
endif
n2=lenocc(mname)
call toint(nuserm,astring,nci)
*- If top volume, create the top node
call ptname(mname, mother)
nmother = lenocc(mother)
if((ivo.eq.1).and.(iposp.eq.0))then
write(51,510)mother(1:nmother)
* write(51,510)
510 format('gGeoManager->SetTopVolume(',a,');')
endif
*- Generate subnodes of this node (if any)
** print 2346, iq(jvolum+ivo), nin
2346 format('Processing node:',a4,' nin=',i4)
if(nin.eq.0)then
nlevel=nlevel-1
return
endif
call cdnode(nodeold(nlevel))
* print 520, mother(1:nmother), ivo
520 format('mother ',a,' index ',i9)
if(nin.gt.0)then
if (nvflags(ivo).ne.0) then
goto 996
endif
nvflags(ivo)=1
* Volume has positioned contents
do 300 in=1,nin
ifirst = 0
icurrent = 0
imulti = 0
nci1 = 0
jin=lq(jv-in)
ivom=q(jin+2)
nuser = q(jin+3)
imany = q(jin+8)
* print *,'in=',in,' nuser=',nuser
jinvom = lq(jvolum-ivom)
npar = q(jinvom+5)
ninvom = q(jinvom+3)
cname=' '
if(.not.map_found(iq(jvolum+ivom),cname)) then
write(cname,'(a4)')iq(jvolum+ivom)
endif
n1=lenocc(cname)
if (npar.gt.0) then
jpar = jinvom+6
else
jpar = jin+9
if (iposp.eq.1) then
if (npflags(ivom).eq.0) then
ifirst = 1
npflags(ivom) = 1
else
npflags(ivom) = npflags(ivom)+1
endif
else
icurrent = nppflags(ivom)
call toint(icurrent,astring1,nci1)
imulti = 1
nppflags(ivom) = nppflags(ivom)+1
endif
npar = q(jin+9)
call ucopy(q(jinvom+1),qjv(1),6)
qjv(5) = npar
call ucopy(q(jin+10),qjv(7),npar)
call ucopy(q(jinvom+7),qjv(7+npar),6)
call toint(in,astring,nci)
mname=cname(1:n1)//astring(1:nci)
if (iposp.eq.1) call volume(cname,qjv,iposp,ifirst)
endif
if(ninvom.ge.0)then
nnodes = nnodes+1
if (nnodes.gt.MAXPOS) then
print *,'Too many nodes =',nnodes
go to 300
endif
call toint(nnodes,anode,ncd)
cnode = 'Node'//anode(1:ncd)
if (nodepos(nnodes).eq.0) then
* write(51,4444)cblank(1:nlevel),anode(1:ncd)
4444 format(a,'TNode *Node',a,';')
nodepos(nnodes) = 1
endif
else
cnode = 'Node'
endif
nd=lenocc(cnode)
call toreals(3,q(jin+5),creals,ncr)
itrans = 1
if ((abs(q(jin+5)).lt.1E-30).and.
+ (abs(q(jin+6)).lt.1E-30).and.
+ (abs(q(jin+7)).lt.1E-30)) then
itrans = 0
endif
irot=q(jin+4)
matrixs=' '
if(irot.eq.0)then
matrix='0'
ncmatrix=1
if (itrans.eq.0) then
matrixs='gGeoIdentity'
else
matrixs='new TGeoTranslation('//creals(2:ncr)//')'
endif
else
call toint(irot,astring,nci)
matrix='rot'//astring(1:nci)