Use templated function TDirectory::Get<T>
Since ROOT 6.18 the function TDirectory::Get(const char*) exist which either returns a properly checked and casted object from a TFile/TDirectory or returns a nullptr.
Test if the object exist after is was read from file and stop the execution if the object doesn't exist.
Also tests which checks if a valid file pointer exist were added at several places.