SND@LHC Software
Loading...
Searching...
No Matches
getGeoInformation.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#prints z-coordinators of SHiP detector volumes
3#WARNING: printing the entire geometry takes a lot of time
4#24-02-2015 comments to EvH
5
6from __future__ import print_function, division
7from builtins import range
8import operator, sys
9from argparse import ArgumentParser
10from array import array
11import os,ROOT
12
14 Info={}
15 nav = ROOT.gGeoManager.GetCurrentNavigator()
16 nav.cd(n)
17 Info['node'] = nav.GetCurrentNode()
18 Info['path'] = n
19 tmp = Info['node'].GetVolume().GetShape()
20 Info['material'] = Info['node'].GetVolume().GetMaterial().GetName()
21 if options.moreInfo:
22 x = ROOT.gGeoManager.GetVerboseLevel()
23 ROOT.gGeoManager.SetVerboseLevel(0)
24 Info['weight']=Info['node'].GetVolume().Weight() # kg
25 Info['cubicmeter']=Info['node'].GetVolume().Capacity()/1000000. #
26 ROOT.gGeoManager.SetVerboseLevel(x)
27 o = [tmp.GetOrigin()[0],tmp.GetOrigin()[1],tmp.GetOrigin()[2]]
28 Info['locorign'] = o
29 local = array('d',o)
30 globOrigin = array('d',[0,0,0])
31 nav.LocalToMaster(local,globOrigin)
32 Info['origin'] = globOrigin
33 shifts = [ [-tmp.GetDX()+o[0],o[1],o[2]],
34 [tmp.GetDX()+o[0],o[1],o[2]],
35 [o[0],-tmp.GetDY()+o[1],o[2]],
36 [o[0],tmp.GetDY()+o[1],o[2]],
37 [o[0],o[1],-tmp.GetDZ()+o[2]],[o[0],o[1],tmp.GetDZ()+o[2]]
38 ]
39 shifted = []
40 for s in shifts:
41 local = array('d',s)
42 glob = array('d',[0,0,0])
43 nav.LocalToMaster(local,glob)
44 shifted.append([glob[0],glob[1],glob[2]])
45 Info['boundingbox']={}
46 for j in range(3):
47 jmin = 1E30
48 jmax = -1E30
49 for s in shifted:
50 if s[j]<jmin: jmin = s[j]
51 if s[j]>jmax: jmax = s[j]
52 Info['boundingbox'][j]=[jmin,jmax]
53 return Info
54
55def print_info(path, node, level, currentlevel, print_sub_det_info=False):
56 sub_nodes = {}
57 fullInfo = {}
58 for subnode in node.GetNodes():
59 name = subnode.GetName()
60 fullInfo[name] = local2Global(path + '/' + name)
61 sub_nodes[name] = fullInfo[name]['origin'][2]
62
63 for name, _ in sorted(list(sub_nodes.items()), key=operator.itemgetter(1)):
64 boundingbox = fullInfo[name]['boundingbox']
65
66 format_string = "{:<28s}: z={:10.4F}cm dZ={:10.4F}cm [{:10.4F} {:10.4F}]"+\
67 " dx={:10.4F}cm [{:10.4F} {:10.4F}] dy={:10.4F}cm [{:10.4F} {:10.4F}] {:>20s}"
68
69 format_variable = [" " * int(currentlevel) + name, fullInfo[name]['origin'][2],
70 abs(boundingbox[2][0]-boundingbox[2][1])/2., boundingbox[2][0],boundingbox[2][1],
71 abs(boundingbox[0][0]-boundingbox[0][1])/2., boundingbox[0][0],boundingbox[0][1],
72 abs(boundingbox[1][0]-boundingbox[1][1])/2., boundingbox[1][0],boundingbox[1][1],
73 fullInfo[name]['material']]
74
75 if options.moreInfo:
76 cubicmeter = fullInfo[name]['cubicmeter']
77 weight = fullInfo[name]['weight']
78 format_string += " {:10.1F}kg {:10.1F}m3"
79 format_variable.extend([weight, cubicmeter])
80
81 print (format_string.format(*format_variable))
82
83 if options.volume in ["", name]:
84 print_sub_det_info = True
85
86 if print_sub_det_info and currentlevel < level and fullInfo[name]['node'].GetNodes():
87 print_info(fullInfo[name]['path'], fullInfo[name]['node'], level, currentlevel + 1,
88 print_sub_det_info)
89
90 if currentlevel == 0:
91 print_sub_det_info = False
92
93
94parser = ArgumentParser()
95parser.add_argument("-g", "--geometry", dest="geometry", help="input geometry file",
96 required=True)
97parser.add_argument("-l", "--level", dest="level", help="max subnode level", default=0)
98parser.add_argument("-v", "--volume", dest="volume", help="name of volume to expand", default="")
99parser.add_argument("-X", "--moreInfo", dest="moreInfo", help="print weight and capacity", default=False)
100
101options = parser.parse_args()
102fname = options.geometry
103if fname.startswith('/eos/'):
104 fname = os.environ['EOSSHIP'] + fname
105fgeom = ROOT.TFile.Open(fname)
106fGeo = fgeom.FAIRGeom
107top = fGeo.GetTopVolume()
108
109
110if options.moreInfo:
111 print (" Detector element z(midpoint) halflength volume-start volume-end dx"\
112 " x-start x-end dy y-start y-end material weight capacity")
113else:
114 print (" Detector element z(midpoint) halflength volume-start volume-end dx"\
115 " x-start x-end dy y-start y-end material")
116
117currentlevel = 0
118print_info("", top, int(options.level), currentlevel)
print_info(path, node, level, currentlevel, print_sub_det_info=False)