We point out that an accurate in situ determination of the earth matter density ρ is possible in neutrino factory by placing a detector at the magic baseline, L = √ 2π/G F N e where N e denotes electron number density. The accuracy of matter density determination is excellent in a region of relatively large θ 13 with fractional uncertainty δρ/ρ of about 0.43%, 1.3%, and < ∼ 3% at 1σ CL at sin 2 2θ 13 = 0.1, 10 −2 , and 3 × 10 −3 , respectively. At smaller θ 13 the uncertainty depends upon the CP phase δ, but it remains small, 3%-7% in more than 3/4 of the entire region of δ at sin 2 2θ 13 = 10 −4 . The results would allow us to solve the problem of obscured CP violation due to the uncertainty of earth matter density in a wide range of θ 13 and δ. It may provide a test for the geophysical model of the earth, or it may serve as a method for stringent test of the MSW theory of neutrino propagation in matter once an accurate geophysical estimation of the matter density is available.