PIM sparse mode allows the last hop router to switch from the shared tree to a shortest path tree for a specific source.
This is a default behaviour in Cisco routers and happens after the first multicast packet is received from the rendezvous point from the shared tree, even if the shortest path is through the rendezvous point.
When the last hop router receives the first multicast packet from the rendezvous point, it will become aware of the IP address of the multicast source. The last hop router will check its unicast routing table to see where the shortest path is to the source. It will send a (S,G) PIM join hop-by-hop to the first hop router to form a shortest tree path.
If the shortest tree path upstream is out of an interface that is not currently the reverse path forwarding interface, it will send a PIM prune message to the rendezvous point through the existing RPF interface, and change the RPF interface to the interface that is part of the shortest path tree towards the source of the multicast stream. The pruning of the branch helps stop duplicate traffic from reaching the last hop router from multiple directions.
After the pruning, if the rendezvous has no other interfaces that are interested in receiving the multicast traffic, it will send a prune message towards the direction of the first hop router. If there are routers between the rendezvous point and the first hop router, they will travel along their interfaces.