driver expression dot.product function I´m coming from 3ds max and I would like to rebuild a scene in blender.
It has a controller that outputs the angle between a bone and
the world z-axis via the dot product function. That´s pretty simple in 3ds Max with e.g

&gt; myvec=$.transform.row1 globalz=[0,0,1] theAngle = acos(dot (normalize
&gt; myvec) (normalize globalz))


The script controller calculates the angle between the bones X-axis(roll axis) and the world z-axis. This works for realtime tranformations and animations as well.

How could I make this with a blender driver?

So far I have written a script which is running in the console line by line(sorry for the noobish syntax)

import bpy
import mathutils
import math

from mathutils import Matrix, Vector

myvec=bpy.data.objects['Armature'].pose.bones['Bone'].matrix.col[1]
gloma= Matrix()
ori=gloma.col[2]
ori=ori.dot(myvec)
ori=math.acos(ori)
ori=math.degrees(ori)
print (ori)


After I had created a driver function with bpy.app.driver_namespace that driver didn´t got evaluated. Any help would be very appreciated.
Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2


Settings:

Turn on register in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45




Additions: 
Original script has two mistakes.
1. Transformation matrix for converting to world space is 

object.matrix_world @ pose_bone.matrix


2. Vector myvec needs to be normalized.