I want to simulate the electron drift, and set the geometry using GeometrySimple, but after I saved the canvas into root file and open the file run “canvas->Draw()”, I got sag fault. Can someone tell me where I did wrong? Here is the code:
Hi,
I can’t run your code as is since I don’t have the class which this function is part of, but I ran a simple test program which you’ll find attached. Saving the canvas to a ROOT file and reopening seems to work fine with this program.
From the error message above seems the geometry is not saved and automatically created when I draw the canvas through root file, but I don’t know how it works to save Garfield class into root file…
The code you sent and the test program do not save a Garfield class to a ROOT file. ViewGeometry uses the ROOT TGeo package to draw the geometry. What is saved to the ROOT file is a TCanvas and its contents (ROOT geometry).
As I said, I’m afraid I can’t reproduce the empty canvas problem. Does it work if you open it in a TBrowser?
Ah, I hadn’t realised you are using ROOT7.
I don’t think the issue is related to Garfield++ though. Can you try with the attached ROOT-only program? test.C (961 Bytes)
I successfully compiled and ran the test.C program, and still got sag fault when I open the root file and use
c->Draw()
error message:
siyuan@SiyuandeMacBook-Pro Downloads % `root-config --cxx --cflags --libs` -lMinuit2 -lGeom -o test test.C
siyuan@SiyuandeMacBook-Pro Downloads % ./test
Info in <TGeoManager::TGeoManager>: Geometry Geometry, default geometry created
Info in <TGeoManager::SetTopVolume>: Top volume is World. Master volume is World
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100
Info in <TGeoManager::CheckGeometry>: Fixing runtime shapes...
Info in <TGeoManager::CheckGeometry>: ...Nothing to fix
Info in <TGeoManager::CloseGeometry>: Counting nodes...
Info in <TGeoManager::Voxelize>: Voxelizing...
Info in <TGeoManager::CloseGeometry>: Building cache...
Info in <TGeoManager::CountLevels>: max level = 1, max placements = 1
Info in <TGeoManager::CloseGeometry>: 2 nodes/ 2 volume UID's in default geometry
Info in <TGeoManager::CloseGeometry>: ----------------modeler ready----------------
siyuan@SiyuandeMacBook-Pro Downloads % root -l geo.root
root [0]
Attaching file geo.root as _file0...
(TFile *) 0x14773f3f0
root [1] .ls
TFile** geo.root
TFile* geo.root
KEY: TCanvas c;1
root [2] c->Draw()
Info in <TGeoManager::TGeoManager>: Geometry Geometry, default geometry created
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGeom.so] TGeoVolume::Paint(char const*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGeom.so] TGeoVolume::Paint(char const*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGpad.so] TPad::PaintModified() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGpad.so] TCanvas::Update() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGui.so] TRootCanvas::HandleContainerConfigure(Event_t*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGui.so] TRootContainer::HandleConfigureNotify(Event_t*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGui.so] TGFrame::HandleEvent(Event_t*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] ROOT::MacOSX::X11::EventTranslator::GenerateConfigureNotifyEvent(NSView<X11Window>*, CGRect const&) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzView configureNotifyTree] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzView configureNotifyTree] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzView configureNotifyTree] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzView configureNotifyTree] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzView configureNotifyTree] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] -[QuartzWindow mapRaised] (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGCocoa.so] TGCocoa::MapRaised(unsigned long) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGui.so] TGFrame::MapRaised() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libGpad.so] TCanvas::Draw(char const*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libRint.so] TRint::HandleTermInput() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCore.so] TUnixSystem::CheckDescriptors() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCore.so] TSystem::InnerLoop() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCore.so] TSystem::Run() (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libCore.so] TApplication::Run(bool) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/lib/root/libRint.so] TRint::Run(bool) (no debug info)
[/opt/homebrew/Cellar/root/6.26.02/bin/root.exe] main (no debug info)
[/usr/lib/dyld] start (no debug info)
Hi, this won’t work, unfortunately. Geometry volumes are contextual objects that cannot be drawn in the absence of the geometry containing them, and this (TGeoManager class) is not written with the canvas. I’m afraid you need to load the geometry and replay the visualization settings rather than saving the canvas.
Eh…Sorry I don’t really understand, I’m actually a newbie of this, for example the macro written by @hschindl above, that should not work if I only draw the Canvas?
If so, is that normal I got a sag fault?