Not getting transform controls position correctly for every selected object

Hi,

After selecting an object through raycaster in the scene,I want to show transform controls(gizmo) on that object. But I am getting gizmo somewhere else, how to know pivot point of object inside the scene and set the same pivot point to transform controls. Kindly suggest me something related.

let transformControls = new TransformControls( camera, renderer.domElement );

transformControls.setMode( ‘rotate’ );
transformControls.attach(selectedObject);
scene.add( transformControls );

Thanks