Break - segment violation - fit Histogram with Gaussian

I receive the break — segment violation ---- error when I attempt to run this code:

TFile* f = new TFile("MC_Signal_Event.root", "READ");
TH1* h = (TH1*)f->Get("M_phi");
RooRealVar x("x","x",-10,10) ;

RooDataHist data("data", "dataset", x, h);
RooPlot* frame = x.frame(Title("test"));
data.plotOn(frame);

RooRealVar mean ("mean", "mean",1.02,0.1,1.4);
RooRealVar sigma("sigma", "sigma",0.01,0,0.1);  
RooGaussian g("g", "g", x, mean, sigma);
g.fitTo(data);
g.plotOn(frame);

Can someone help me understand what is happening?
Thanks in advance!

Can you post the traceback you get ?

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f8c38890687 in __GI___waitpid (pid=11455, stat_loc=stat_loc
entry=0x7ffd571ef7e8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007f8c387fb067 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007f8c3948e80b in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x556c266707c0) at /home/b/root-6.14.00/core/unix/src/TUnixSystem.cxx:2119
#3  TUnixSystem::StackTrace (this=0x556c266707c0) at /home/b/root-6.14.00/core/unix/src/TUnixSystem.cxx:2413
#4  0x00007f8c394911f4 in TUnixSystem::DispatchSignals (this=0x556c266707c0, sig=kSigSegmentationViolation) at /home/b/root-6.14.00/core/unix/src/TUnixSystem.cxx:3644
#5  <signal handler called>
#6  RooDataHist::RooDataHist (this=0x7ffd571f3570, name=0x7f8c39c3e12b "data", title=0x7f8c39c3e130 "dataset", vars=..., hist=0x0, wgt=1) at /home/b/root-6.14.00/roofit/roofitcore/src/RooDataHist.cxx:224
#7  0x00007f8c39c3f1f5 in ?? ()
#8  0x00007ffd571f2540 in ?? ()
#9  0x0000ffff000000d2 in ?? ()
#10 0x00007ffd571f23d0 in ?? ()
#11 0x00007f8c3693d9a0 in llvm::X86Insts () from /home/b/mybuild/lib/libCling.so
#12 0x0000556c27667500 in ?? ()
#13 0x00007f8c38e4854c in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x00007ffd571f2580 in ?? ()
#15 0x00007ffd571f2450 in ?? ()
#16 0x00007ffd571f2468 in ?? ()
#17 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
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.
===========================================================
#6  RooDataHist::RooDataHist (this=0x7ffd571f3570, name=0x7f8c39c3e12b "data", title=0x7f8c39c3e130 "dataset", vars=..., hist=0x0, wgt=1) at /home/b/root-6.14.00/roofit/roofitcore/src/RooDataHist.cxx:224
#7  0x00007f8c39c3f1f5 in ?? ()
#8  0x00007ffd571f2540 in ?? ()
#9  0x0000ffff000000d2 in ?? ()
#10 0x00007ffd571f23d0 in ?? ()
#11 0x00007f8c3693d9a0 in llvm::X86Insts () from /home/b/mybuild/lib/libCling.so
#12 0x0000556c27667500 in ?? ()
#13 0x00007f8c38e4854c in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x00007ffd571f2580 in ?? ()
#15 0x00007ffd571f2450 in ?? ()
#16 0x00007ffd571f2468 in ?? ()
#17 0x0000000000000000 in ?? ()
===========================================================

it seems RooDataHist is the faulty part of you code.
Are you sure you give it correct parameters ?

I’ve been looking at https://root.cern.ch/root/html/tutorials/roofit/rf102_dataimport.C.html and I can’t see what I’ve done differently. I’m new to this type of coding and the instructions are a little hard to understand

I think that my problem might be that my TH1 is not retrieving my M_phi file from the ttree. I have fixed the violation but it now says that the TH1 is null

warning: null passed to a callee that requires a non-null argument [-Wnonnull]
RooDataHist data("data", "data", ntupleVarSet, Import(*h));

What do you get when you do:

TFile* f = new TFile("MC_Signal_Event.root", "READ");
f->ls();

Hi couet,

I fixed the problem. Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.