ImportFromFile() function

Hi All. I am just starting with Roofit and my first task is to fit a mass distribution. I create a model to fit the mass distribution (basically -> exponential + gaussian) and I also generate a toy data set and I did the fitting following the instructions in the tutorials and it works great. Now I want to use a root file which contains data organized in several trees and several branches and what I want to do is import the data from that root file to a RooDataSet. I used

RooDataSet ds(“ds”,“ds”,RooArgSet(m,type,mkk,prob,fls3d),ImportFromFile(“data.root”, ““candAnaBs2JpsiPhi/events””),Cut(“prob>0.3”));

to import the data but I get a segmentation violation error which I have no clue how to fix.

my code is:

#ifndef CINT
#include “RooGlobalFunc.h”
#endif
#include “RooDataHist.h”
#include “RooCategory.h”
#include “RooConstVar.h”
#include “TH1.h”
#include “TTree.h”
#include “TRandom.h”
#include “RooRealVar.h”
#include “RooDataSet.h”
#include “RooGaussian.h”
#include “RooExponential.h”
#include “RooAddPdf.h”
#include “TCanvas.h”
#include “RooPlot.h”
#include “TAxis.h”
#include “RooCmdConfig.h”
#include "TFile.h"
using namespace RooFit ;

void expgaus()
{

// — Observable —
//RooRealVar x(“x”,“gauss PDF”,-10,10) ;
RooRealVar m(“m”,“mass”,4.8,6) ;
RooRealVar type(“type”,“type”,300531,300532) ;
RooRealVar mkk(“mkk”,“mkk”,1.01,1.03) ;
RooRealVar prob(“prob”,“prob”,0,1) ;
RooRealVar fls3d(“fls3d”,“fls3d”,0,100);

// — Parameters —
//RooRealVar mean(“mean”,“sigma”,0,-1,1) ;
//RooRealVar width(“width”,“width”,1,0,5) ;
RooRealVar mean(“mean”,“sigma”,5.3,5.,5.5) ;
RooRealVar width(“width”,“width”,0.05,0,.2) ;

// — Build Gaussian PDF —
RooGaussian signal(“signal”,“signal PDF”,m,mean,width) ;

// — Build exponential background PDF —
RooRealVar alpha(“alpha”,“alpha”,-5,-50.,0.);
RooExponential background(“expo”,“exponential PDF”,m,alpha);

// — Construct signal+background PDF —
RooRealVar nsig(“nsig”,"#signal events",100,0.,10000) ;
RooRealVar nbkg(“nbkg”,"#background events",100,0.,10000) ;
RooAddPdf model(“model”,“gauss+expo PDF”,RooArgList(signal,background),RooArgList(nsig,nbkg)) ;

// — Generate a toyMC sample from composite PDF —
//RooDataSet *data = model.generate(x,2000) ;
//////////////////////////////////////////////////////////////////

RooDataSet ds2(“ds”,“ds”,RooArgSet(m,type,mkk,prob,fls3d),ImportFromFile(“data.root”, “candAnaBs2JpsiPhi/events”,Cut(“prob>0.3”));
ds2.Print() ;

// — Perform extended ML fit of composite PDF to toy data —
model.fitTo(ds2) ;

// — Plot toy data and composite PDF overlaid —
RooPlot* mframe = m.frame() ;

ds2.plotOn(mframe) ;
model.plotOn(mframe) ;
model.plotOn(mframe,Components(background),LineStyle(kDashed)) ;

mframe->Draw() ;

}

and the stack trace is:

===========================================================
There was a crash (#6 0xb71b914b in SigHandler(ESignals) () from /usr/local/lib/root/libCore.so.5.34).
This is the entire stack trace of all threads:

#0 0xb7715428 in __kernel_vsyscall ()
#1 0xb6ceb8f3 in waitpid () from /lib/i386-linux-gnu/libc.so.6
#2 0xb6c72c23 in ?? () from /lib/i386-linux-gnu/libc.so.6
#3 0xb71b1d9b in TUnixSystem::Exec(char const*) () from /usr/local/lib/root/libCore.so.5.34
#4 0xb71b64d0 in TUnixSystem::StackTrace() () from /usr/local/lib/root/libCore.so.5.34
#5 0xb71b9037 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/root/libCore.so.5.34
#6 0xb71b914b in SigHandler(ESignals) () from /usr/local/lib/root/libCore.so.5.34
#7 0xb71afe42 in sighandler(int) () from /usr/local/lib/root/libCore.so.5.34
#8 0xb71e2fc5 in textinput::TerminalConfigUnix::HandleSignal(int) () from /usr/local/lib/root/libCore.so.5.34
#9 0xb71e3004 in (anonymous namespace)::TerminalConfigUnix__handleSignal(int) () from /usr/local/lib/root/libCore.so.5.34
#10
#11 0xb5645e4e in RooTreeDataStore::loadValues(TTree const*, RooFormulaVar const*, char const*, int, int) () from /usr/local/lib/root/libRooFitCore.so.5.34
#12 0xb5541fc9 in RooDataSet::RooDataSet(char const*, char const*, RooArgSet const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) () from /usr/local/lib/root/libRooFitCore.so.5.34
#13 0xb5f07d29 in expgaus() () from /home/jmonroy/Documentos/analysis/roofit/./expgaus_C.so
#14 0xb5f08844 in G__expgaus_C_ACLiC_dict__0_4455(G__value*, char const*, G__param*, int) () from /home/jmonroy/Documentos/analysis/roofit/./expgaus_C.so
#15 0xb669085c in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/local/lib/root/libCint.so.5.34
#16 0xb6741cb0 in G__execute_call () from /usr/local/lib/root/libCint.so.5.34
#17 0xb6742074 in G__call_cppfunc () from /usr/local/lib/root/libCint.so.5.34
#18 0xb671eb47 in G__interpret_func () from /usr/local/lib/root/libCint.so.5.34
#19 0xb670c8e8 in G__getfunction () from /usr/local/lib/root/libCint.so.5.34
#20 0xb66e3515 in G__getitem () from /usr/local/lib/root/libCint.so.5.34
#21 0xb66ea038 in G__getexpr () from /usr/local/lib/root/libCint.so.5.34
#22 0xb66f6023 in G__calc_internal () from /usr/local/lib/root/libCint.so.5.34
#23 0xb6787094 in G__process_cmd () from /usr/local/lib/root/libCint.so.5.34
#24 0xb7172b4a in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/local/lib/root/libCore.so.5.34
#25 0xb716e33f in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /usr/local/lib/root/libCore.so.5.34
#26 0xb70c8c47 in TApplication::ExecuteFile(char const*, int*, bool) () from /usr/local/lib/root/libCore.so.5.34
#27 0xb70c901c in TApplication::ProcessFile(char const*, int*, bool) () from /usr/local/lib/root/libCore.so.5.34
#28 0xb70c7657 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/local/lib/root/libCore.so.5.34
#29 0xb6f91d0f in TRint::Run(bool) () from /usr/local/lib/root/libRint.so.5.34
#30 0x08048c9f 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
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.

#11 0xb5645e4e in RooTreeDataStore::loadValues(TTree const*, RooFormulaVar const*, char const*, int, int) () from /usr/local/lib/root/libRooFitCore.so.5.34
#12 0xb5541fc9 in RooDataSet::RooDataSet(char const*, char const*, RooArgSet const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) () from /usr/local/lib/root/libRooFitCore.so.5.34
#13 0xb5f07d29 in expgaus() () from /home/jmonroy/Documentos/analysis/roofit/./expgaus_C.so

Any suggestion/comment is welcome. Thanks

Did you solve the problem? I have a similar problem…

Hi,
Can you please post the simplest macro reproducing your problem

Thank you

Lorenzo