Can someone tell me how to put objects behing another object in the background itself ?
When you are tracing a live footage (in your example - to cut it out so you can place the live footage on top of a CG, or to put the CG behind the live footage) it's called Rotoscoping. look here for a little history: https://www.fxguide.com/featured/the-art-of-roto-2011/
in Ae there are many tools to do this. the most straight forward approach would be masks - which is great for simple rotoscoping. the more complex would be Rotobrush which can produce amazing results but requires a lot of practice and the learning curve is steep.
for a comprehensive course I will suggest you learn from the master Mark Christiansen on his course on Lynda:
there are of course other source of information right in the adobe help files:
about 3D Tracker. actually using 3D tracking for rotoscoping is a bit complex because you are essentially masking a 2D layer with a 3D information and using masks and alpha mattes in 3D space can get messy. you usually use 3D tracking for placing the CG elements in the scene (the ponys, or maybe audio waveform on the wall for the DJ if the camera was moving) but the Roto you usually do in 2D.
about the examples you provided: the 1st has no camera movement so this is straight forward masking or rotobrush, the second video will require 2D or 3D tracking to put the ponys in there, but the roto could be 2D. for example the tree 00:18 could just be a duplicated footage of the tree with a mask on it that will trace it as long as it's on top of the pony.