Density distribution in looplike coronal transients: A comparison of observations and a theoretical model