<commit_before># @(#)root/gdml:$Name:  $:$Id: ROOTwriter.py,v 1.4 2006/07/10 16:06:09 brun Exp $
# Author: <NAME>   05/06/2006

from math import *
from units import *

import libPyROOT
import ROOT
import math

# This class provides ROOT binding for the 'writer' class. It implements specific
# methods for all the supported TGeo classes which call the appropriate 'add-element'
# methods from the 'writer' class.

# The list of presently supported classes is the following:

# Materials:
# TGeoElement
# TGeoMaterial
# GeoMixture

# Solids:
# TGeoBBox
# TGeoArb8
# TGeoTubeSeg
# TGeoConeSeg
# TGeoCtub
# TGeoPcon
# TGeoTrap
# TGeoGtra
# TGeoTrd2
# TGeoSphere
# TGeoPara
# TGeoTorus
# TGeoHype
# TGeoPgon
# TGeoXtru
# TGeoEltu
# TGeoParaboloid
# TGeoCompositeShape (subtraction, union, intersection)

# Geometry:
# TGeoVolume

# In addition the class contains three methods 'dumpMaterials', 'dumpSolids' and 'examineVol'
# which retrieve from the memory the materials, the solids and the geometry tree
# respectively. The user should instanciate this class passing and instance of 'writer'
# class as argument. In order to export the geometry in the form of a GDML file,
# the three methods (dumpMaterials, dumpSolids and examineVol) should be called.
# The argument of 'dumpMaterials' method should be the list of materials,
# the argument of the 'dumpSolids' method should be the list of solids and
# the argument of the 'examineVol' method should be the top volume of
# the geometry tree.

# For any question or remarks concerning this code, please send an email to
# <EMAIL>.

class ROOTwriter(object):

    def __init__(self, writer):
        self.writer = writer
        self.elements = []
	self.volumeCount = 0
	self.nodeCount = 0
	self.shapesCount = 0	
	self.bvols = []
	self.vols = []
	self.volsUseCount = {}
	self.sortedVols = []
	self.nodes = []
	self.bnodes = []
	self.solList = []
        self.geomgr = ROOT.gGeoManager
        geomgr.SetAllIndex()
        pass

    def rotXYZ(self, r):            
        cosb = math.sqrt( r[0]*r[0] + r[1]*r[1] )
        if cosb > 0.00001 : #I didn't find a proper constant to use here, so I just put a value that works with all the examples on a linux machine (P4)
            a = atan2( r[5], r[8] ) * rad
            b = atan2( -r[2], cosb ) * rad
            c = atan2( r[1], r[0] ) * rad
        else:
            a = atan2( -r[7], r[4] ) * rad
            b = atan2( -r[2], cosb ) * rad
            c = 0.
        return (a, b, c)

    def TGeoBBox(self, solid):
        self.writer.addBox(solid.GetName()+'_'+str(libPyROOT.AddressOf(solid)[0]), 2*solid.GetDX(), 2*solid.GetDY(), 2*solid.GetDZ())

    def TGeoParaboloid(self, solid):
        self.writer.addParaboloid(solid.GetName()+'_'+str(libPyROOT.AddressOf(solid)[0]), solid.GetRlo(), solid.GetRhi(), solid.GetDz())
<commit_msg>Fix a bug in the python script.<commit_after># @(#)root/gdml:$Name:  $:$Id: ROOTwriter.py,v 1.5 2006/08/07 14:29:01 brun Exp $
# Author: <NAME>   05/06/2006

from math import *
from units import *

import libPyROOT
import ROOT
import math

# This class provides ROOT binding for the 'writer' class. It implements specific
# methods for all the supported TGeo classes which call the appropriate 'add-element'
# methods from the 'writer' class.

# The list of presently supported classes is the following:

# Materials:
# TGeoElement
# TGeoMaterial
# GeoMixture

# Solids:
# TGeoBBox
# TGeoArb8
# TGeoTubeSeg
# TGeoConeSeg
# TGeoCtub
# TGeoPcon
# TGeoTrap
# TGeoGtra
# TGeoTrd2
# TGeoSphere
# TGeoPara
# TGeoTorus
# TGeoHype
# TGeoPgon
# TGeoXtru
# TGeoEltu
# TGeoParaboloid
# TGeoCompositeShape (subtraction, union, intersection)

# Geometry:
# TGeoVolume

# In addition the class contains three methods 'dumpMaterials', 'dumpSolids' and 'examineVol'
# which retrieve from the memory the materials, the solids and the geometry tree
# respectively. The user should instanciate this class passing and instance of 'writer'
# class as argument. In order to export the geometry in the form of a GDML file,
# the three methods (dumpMaterials, dumpSolids and examineVol) should be called.
# The argument of 'dumpMaterials' method should be the list of materials,
# the argument of the 'dumpSolids' method should be the list of solids and
# the argument of the 'examineVol' method should be the top volume of
# the geometry tree.

# For any question or remarks concerning this code, please send an email to
# <EMAIL>.

class ROOTwriter(object):

    def __init__(self, writer):
        self.writer = writer
        self.elements = []
	self.volumeCount = 0
	self.nodeCount = 0
	self.shapesCount = 0	
	self.bvols = []
	self.vols = []
	self.volsUseCount = {}
	self.sortedVols = []
	self.nodes = []
	self.bnodes = []
	self.solList = []
        self.geomgr = ROOT.gGeoManager
        self.geomgr.SetAllIndex()
        pass

    def rotXYZ(self, r):            
        cosb = math.sqrt( r[0]*r[0] + r[1]*r[1] )
        if cosb > 0.00001 : #I didn't find a proper constant to use here, so I just put a value that works with all the examples on a linux machine (P4)
            a = atan2( r[5], r[8] ) * rad
            b = atan2( -r[2], cosb ) * rad
            c = atan2( r[1], r[0] ) * rad
        else:
            a = atan2( -r[7], r[4] ) * rad
            b = atan2( -r[2], cosb ) * rad
            c = 0.
        return (a, b, c)

    def TGeoBBox(self, solid):
        self.writer.addBox(solid.GetName()+'_'+str(libPyROOT.AddressOf(solid)[0]), 2*solid.GetDX(), 2*solid.GetDY(), 2*solid.GetDZ())

    def TGeoParaboloid(self, solid):
        self.writer.addParaboloid(solid.GetName()+'_'+str(libPyROOT.AddressOf(solid)[0]), solid.GetRlo(), solid.GetRhi(), solid.GetDz())

{'fraction_non_alphanumeric': 0.11261182248728294, 'fraction_numerical': 0.02069812313629188, 'mean_word_length': 3.2647718773373224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5729405', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1972, 'n_words': 630}