Hello
I have the following problem: I wrote a canvas in a file and now I’d like to get back the histogram from the canvas and do some stuff…
This is the 1st script:
TFile miofile(“Hfra40.root”,“read”);
miofile->ls();
TCanvas c1 = (TCanvas)miofile.Get(“c1”);
c1->Draw();
the c1 canvas is drawn and this is the output:
TFile** Hfra40.root
TFile* Hfra40.root
KEY: TCanvas c1;1 c1
For now OK!
This is the 2nd script:
TFile miofile(“Hfra40.root”,“read”);
TH1F hFra40;
TCanvas c1 = (TCanvas)miofile.Get(“c1”);
hFra40 = (TH1F)c1->GetPrimitive(“hFracEtcorr2Part”);
hFra40->Draw();
No error but no drawing -> not good (the name of the Histo is right!)
3th script:
TFile miofile(“Hfra40.root”,“read”);
TCanvas c1 = (TCanvas)miofile.Get(“c1”);
TObject *obj;
TIter next(c1->GetListOfPrimitives());
while ((obj=next())) {
cout << "Reading: " << obj->GetName() << endl;
if (obj->InheritsFrom(“TH1”)) {
cout << "histo: " << obj->GetName() << endl;
}
}
the ouput of the script is:
Reading: TFrame
Reading: hFracEtcorr2Part
histo: hFracEtcorr2Part
Reading: title
No error -> everything seems OK!
but if I add the line
obj->Draw();
whitin the if statement… no drawing…
Last script:
TFile miofile(“Hfra40.root”,“read”);
TCanvas c1 = (TCanvas)miofile.Get(“c1”);
TObject *obj;
TH1F hFra40;
TIter next(c1->GetListOfPrimitives());
while ((obj=next())) {
cout << "Reading: " << obj->GetName() << endl;
if (obj->InheritsFrom(“TH1”)) {
cout << "histo: " << obj->GetName() << endl;
hFra40 = (TH1F)obj->Clone();
}
}
hFra40->Draw();
again no error… but if I open a Tbroswser and get to the file (maybe this is the problem?) I see now the
histogram with name hFracEtcorr2Part: try to double click on it to draw it and get this bunch of error:
*** Break *** segmentation violation
Generating stack trace…
0x40fb72f4 in TPad::PaintBox(double, double, double, double, char const*) + 0x37e from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
0x40fb637f in TPad::PaintBorder(short, bool) + 0xa1 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
0x40fb6ba0 in TPad::PaintModified() + 0xd0 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
0x40f9be04 in TCanvas::Update() + 0x78 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
0x408152e3 in TH1::Browse(TBrowser*) + 0x3b from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libHist.so
0x412acf37 in TRootBrowser::IconBoxAction(TObject*) + 0x343 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x412ac497 in TRootBrowser::ProcessMessage(long, long, long) + 0xe39 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x4124f4b6 in TGFrame::HandleClientMessage(Event_t*) + 0x4a from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x41251a58 in TGMainFrame::HandleClientMessage(Event_t*) + 0x2c from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x4124f1ea in TGFrame::HandleEvent(Event_t*) + 0x1d0 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x41232f7b in TGClient::HandleEvent(Event_t*) + 0xd7 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x41232c74 in TGClient::ProcessOneEvent() + 0x6e from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x41232cfe in TGClient::HandleInput() + 0x28 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x4123187a in TGInputHandler::Notify() + 0x22 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
0x401c643e in TUnixSystem::DispatchOneEvent(bool) + 0x3a from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
0x401313b3 in TSystem::InnerLoop() + 0x25 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
0x40131341 in TSystem::Run() + 0x7b from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
0x400e19f6 in TApplication::Run(bool) + 0x30 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
0x40e12bdb in TRint::Run(bool) + 0x311 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libRint.so
0x08048890 in main + 0x90 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/bin/root.exe
0x42017589 in __libc_start_main + 0x95 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/bin/root.exe
0x08048711 in _Unwind_Resume + 0x35 from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/bin/root.exe
Any suggestion on how to do?
Thanks
Attilio