I have a ROOT file with a few geometry volumes. If I open file in TBrowser I can see that every TGeoVolumeAssembly object has actual non-null fGeoManager member. Please refer to the screenshot below:
Hi,
When you write individual volumes to a file, the geometry manager is not saved as well, so you need to create it yourself before loading the volumes from file. The pointer inside is not persistent, it is set at construction time (when you read from file) to the current gGeoManager. In your macro loading the volume triggers an automatic creation of an empty TGeoManager object after the volume creation, so at construction time gGeoManager will be uninitialized. So just create the TGeoManager to start with:
TGeoManager *geom = new TGeoManager("EMC","BarrelEMC");
auto f = TFile::Open("emc_module12_2018v1.root");
TGeoVolumeAssembly* assembly = (TGeoVolumeAssembly*)f->Get("BarrelEMC");
TGeoMaterial *mat = new TGeoMaterial("Vacuum",0,0,0);
TGeoMedium *med = new TGeoMedium("Vacuum",1,mat);
TGeoVolume *top=gGeoManager->MakeBox("Top",med,100,100,100);
top->AddNode(assembly,1);
geom->SetTopVolume(top);
geom->CloseGeometry();
top->Draw();