Why are you using comments? Nothing is less maintained then comments.
As you are using this comments to describe what code is supposed to do, you can simply place this code into a function and give the function the describing name you have in the comment:
I guess you want to use torque rather than alignAxisToVect
so you replace the call to owner.alignAxisToVect(mathutils.Vector(groundNormal), Z_AXIS, 1.0)
with a call to an own function applyRotationToVector(owner, mathutils.Vector(groundNormal), Z_AXIS, 1.0)
if you use ray of brick you not need of rayCast, just transform the hitNormal that return from the ray in to a vector.
import bge
from mathutils import Vector
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
sen = cont.sensors[0]
hitNormal = sen.hitNormal
if hitNormal: # check before if the ray hit something
hitNormal = Vector(hitNormal) # transform in to Vector
axisZ = own.worldOrientation.col[2]
v1 = axisZ
v2 = hitNormal
rotDif = Vector(v1.rotation_difference(v2).to_euler())
rot = own.localAngularVelocity
rot += rotDif * 0.50 #"elasticity"
rot *= 0.98 # inertia
own.applyForce(-hitNormal*9.8)#gravity to the normal