setContour() for a TGraph2D

Hi

I am trying to add mass lines to an exclusion plot. I have them as TGraph2D. All I am doing is:

root [0] TFile *f = new TFile("DGemt_masses_M1eq100_to500.root") root [1] TH2F *h = (TH2F*)f->Get("C1") root [2] h->SetContour(3)

then I get a segfault:

[code] *** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x0000003a556997b5 in waitpid () from /lib64/libc.so.6
#1 0x0000003a5563c761 in do_system () from /lib64/libc.so.6
#2 0x00002ba06fe60c56 in TUnixSystem::StackTrace() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#3 0x00002ba06fe6052c in TUnixSystem::DispatchSignals(ESignals) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#4
#5 0x0000003a556788e0 in strlen () from /lib64/libc.so.6
#6 0x0000003a55646e77 in vfprintf () from /lib64/libc.so.6
#7 0x0000003a5566875a in vsnprintf () from /lib64/libc.so.6
#8 0x00002ba06fdc40fa in Format(char const*, __va_list_tag*) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#9 0x00002ba06fdc436d in Form(char const*, …) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#10 0x00002ba06fd9f99a in TObject::DoError(int, char const*, char const*, __va_list_tag*) const ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#11 0x00002ba06fd9f6d2 in TObject::Fatal(char const*, char const*, …) const
()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#12 0x00002ba073370f38 in G__G__Hist_102_0_185(G__value*, char const*, G__param*, int) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libHist.so
#13 0x00002ba0706159bf in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#14 0x00002ba0706c7390 in G__execute_call ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#15 0x00002ba0706c819d in G__call_cppfunc ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#16 0x00002ba0706a2de5 in G__interpret_func ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#17 0x00002ba07069079c in G__getfunction ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#18 0x00002ba07078410f in G__getstructmem(int, G__FastAllocString&, char*, int, char*, int*, G__var_array*, int) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#19 0x00002ba07077d4f7 in G__getvariable ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#20 0x00002ba070663b4f in G__getitem ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#21 0x00002ba070667b5c in G__getexpr ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#22 0x00002ba0706f4344 in G__exec_statement ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#23 0x00002ba07064fba6 in G__exec_tempfile_core ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#24 0x00002ba07064fe7e in G__exec_tempfile_fp ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#25 0x00002ba070701869 in G__process_cmd ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCint.so
#26 0x00002ba06fe1d0f5 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#27 0x00002ba06fd70554 in TApplication::ProcessLine(char const*, bool, int*) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#28 0x00002ba0711ecbd2 in TRint::HandleTermInput() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libRint.so
#29 0x00002ba06fe5eb84 in TUnixSystem::CheckDescriptors() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#30 0x00002ba06fe5f1a1 in TUnixSystem::DispatchOneEvent(bool) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#31 0x00002ba06fdd60d6 in TSystem::InnerLoop() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#32 0x00002ba06fdd837c in TSystem::Run() ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#33 0x00002ba06fd6e21f in TApplication::Run(bool) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#34 0x00002ba0711eecc3 in TRint::Run(bool) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libRint.so
#35 0x000000000040105d in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x0000003a556788e0 in strlen () from /lib64/libc.so.6
#6 0x0000003a55646e77 in vfprintf () from /lib64/libc.so.6
#7 0x0000003a5566875a in vsnprintf () from /lib64/libc.so.6
#8 0x00002ba06fdc40fa in Format(char const*, __va_list_tag*) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#9 0x00002ba06fdc436d in Form(char const*, …) ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#10 0x00002ba06fd9f99a in TObject::DoError(int, char const*, char const*, __va_list_tag*) const ()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#11 0x00002ba06fd9f6d2 in TObject::Fatal(char const*, char const*, …) const
()
from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.32.04/x86_64-slc5-gcc43-opt/root/lib/libCore.so

[/code]

When I do this with TH2F (i.e. no casting from TGraph2D to TH2F), it works without problem. But as soon as I am having a TGraph2D as starting point, I keep getting this segfault. Am I doing something wrong? I am using ROOT 5.32/04

Thank you very much for your help, it is much appreciated.

root [0] TFile *f = new TFile("DGemt_masses_M1eq100_to500.root"); root [1] TH2F *h; f->GetObject("C1", h); root [2] if (!h) { std::cout << "TH2F histogram named C1 was NOT found in the file!" << std::endl; }

The TH2F exists of course. Otherwise I don’t think I would get a segfault.

we would need to root file to investigate further.

Yeah, makes sense. Here it is:
twiki.cern.ch/twiki/bin/viewaut … Grids_2011

Sixth bullet (M1eq100 M1eq140 M1eq250 ROOT files containing histograms with neutralino/chargino masses and differences. Can be used to put contours on plots. M2,MU between 100 and 500 GeV (July 31).), the first link (M1eq100).

I get: Access Denied

Can you try this:

ce.lhep.unibe.ch/schneider/DGemt … to500.root

[quote=“basil”]The TH2F exists of course. Otherwise I don’t think I would get a segfault.[/quote] Quite the contrary.
With my source code, if a TH2F object named “C1” does not exist in your ROOT file, the “h” pointer will be set to 0 and you will immediately get a “segmentation fault”, as soon as you try to use it.
What’s much worse with your original source code -> if ANY KIND of object named “C1” exists in your ROOT file, the “h” pointer will point to that object, and you will (usually) get a “segmentation fault”, as soon as you try to use it as a TH2F, if it it’s not really a ROOT file resident TH2F.

root [0] TFile *f = new TFile("DGemt_masses_M1eq100_to500.root") root [1] TH2F *h = (TH2F*)f->Get("anything_that_does_not_exist") root [2] h->SetContour(3) Error: illegal pointer to class object h 0x0 1373 (tmpfile):1: *** Interpreter error recovered *** root [3]

Anyhow, I don’t know how this could help.

Try: TH2F *h = (TH2F*)f->Get("anything_that_exists_and_is_NOT_a_TH2F"); cout << h << endl; and compare with: TH2F *h; f->GetObject("anything_that_exists_and_is_NOT_a_TH2F", h); cout << h << endl;
Hint: substitute that “anything_that_exists_and_is_NOT_a_TH2F” with your “C1”. :mrgreen:

I still don’t see what you are trying to tell me. That I cannot cast a TGraph2D to a TH2F?

Of course you can cast any pointer to any other. Just be prepared to accept the consequences, as well. :mrgreen:

And how can I solve my problem?

Edit: I guess I understand now the problem… Gimme some seconds…

Edit 2: No, doesn’t work.

[quote=“basil”]And how can I solve my problem?

Edit: I guess I understand now the problem… Gimme some seconds…[/quote]

“C1” is NOT a TH2 object, so what’s your problem? Why do you assign TGraph2D * to TH2 * ? These types are unrelated. Do you know, how to use TGraph2D?

Yeah, I think that’s the problem, that I imagined a relation between TH2F and TGraph2D where there isn’t any. I don’t know how to get the same result for a TGraph2D as with TH2F*->SetContour(), but I now know where to look for.

Just found the TGraph2D method GetHistogram(). I think that’s what I was looking for all along but will have to try later.

Thanks everybody for your help!

Try to create a TF2 function from your TGraph2D (with use of the TGraph2D::Interpolate method). Then you could use the TF2::SetContour method. :wink:

Or try to use the output of TGraph2D::GetHistogram (just don’t mix “TH2D*” with “TH2F*”). :wink:

Finally got to test this. GetHistogram() works perfect.

Thanks to all for helping out!