Error while extracting getRealValue of RooRealVar (defined with range)

Dear Experts,
I am using the script :

to
***1. fit background (expo or BkgKer) and signal (signalRes) to data. ***
2. generating toyMC using combined pdf (model) of signal and background

The issue I am facing is that, I am getting error
Break *** segmentation violation
in the 2nd part
2. generating toyMC using combined pdf (model) of signal and background

when I define RooRealVar with range (line 363-375)

=================================================================
RooRealVar m0( “m0”, “m0”, 91.188, 80,100);
RooRealVar width( “width”, “width”, 2.495, 0, 15);
RooBreitWigner bw(“bw”, “”, mass_axis, m0, width); // Breit Wigner
RooRealVar mean(“mean”, “” ,0.,-1,1);
RooRealVar sigma(“sigma”, “”,2.4 , 0.0, 15.0);
//RooRealVar sigma(“sigma”, “”, 1.0, 0, 2);
RooRealVar alpha(“alpha”, “”, 1.0, 0.0, 20.0);
RooRealVar n(“n”,"", 1.0, 0.0, 20.0);
RooRealVar alpha2(“2ndalpha”,"", 1.0, 0.0, 20.0);
RooRealVar n2(“2ndn”, “”, 1.0, 0.0, 20.0);
RooDCBShape *cb; // Double-sided crystal ball
cb = new RooDCBShape(“cb”,“cb”, mass_axis, mean, sigma, alpha, n, alpha2, n2);

======================================================================
The exact crashing of code, happens at (line 488)
double toynSig = mcstudy->fitParDataSet().get(i)->getRealValue(“nSig”,0,kFALSE);

It break while extracting getRealValue of RooRealVar with range.

It runs without any error (for both part) when I define RooRealVars without any range. (line 349-360)

======================================================================
RooRealVar m0( “m0”, “m0”, 91.188 );
RooRealVar width( “width”, “width”, 2.495 );
RooBreitWigner bw(“bw”, “”, mass_axis, m0, width); // Breit Wigner

RooRealVar mean( “mean”, “mean”, 0. );
RooRealVar sigma( “sigma”, “sigma”, 2.4 );
RooRealVar alpha( “alpha”, “alpha”, 1.0 );
RooRealVar n( “n”, “n”, 1.0 );
RooRealVar alpha2(“2ndalpha”,"", 1.0);
RooRealVar n2(“2ndn”, “”, 1.0);
RooDCBShape *cb;
cb = new RooDCBShape(“cb”, “cb”, mass_axis, mean, sigma, alpha, n, alpha2, n2);

But fit of background (expo or BkgKer) and signal (signalRes) to data looks very worse this way.

Could you please suggest how to fix this error, ?
Is there any alternative to getRealValue operator useful here ?

Thanks
Tribeni

Hi @tmishra2018!

It would be good to have a bit more information here. Can you provide the full stack trace of the error? And how do you run this code? I see that you include some SUSY analysis libraries, where are they from?

Finally, it would of course be best for me to also have the .root files to reproduce the error. If you can’t share them on the forum, we can also find another solution like cernbox if this is okay for you.

Cheers,
Jonas

Hi @jonas
Thank you.

Full stack trace error here

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f3319d084fc in waitpid () from /lib64/libc.so.6
#1  0x00007f3319c85fb2 in do_system () from /lib64/libc.so.6
#2  0x00007f331a847acb in TUnixSystem::StackTrace() () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCore.so
#3  0x00007f331a84a10c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCore.so
#4  <signal handler called>
#5  0x00007f330c760337 in RooLinkedList::find(char const*) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#6  0x00007f330c6c4bae in RooArgSet::getRealValue(char const*, double, bool) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#7  0x00007f3306b4218a in FitKer(int, int, float, float, int, int) () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKer_C.so
#8  0x00007f331a9d40e8 in ?? ()
#9  0x0000000001d58f10 in ?? ()
#10 0x00000078168c3d78 in ?? ()
#11 0x0000003c00000000 in ?? ()
#12 0x00007f3306b3f120 in ?? () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKer_C.so
#13 0x420c000001fc6138 in ?? ()
#14 0x0000000141f00000 in ?? ()
#15 0x0000000001dbe340 in ?? ()
#16 0x00007f33169c56c0 in ?? () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#17 0x00007fff0b547ba0 in ?? ()
#18 0x00007fff0b547770 in ?? ()
#19 0x00007f331a9d4000 in ?? ()
#20 0x00007f33169491e2 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) [clone .part.248] () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#21 0x00007f331694b8c9 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#22 0x00007f331694bddb in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#23 0x00007f33169e9fdd in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#24 0x00007f33168b755e in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#25 0x00007f33168c4d31 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#26 0x00007f33168bd9e7 in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#27 0x00007f331a719385 in TApplication::ExecuteFile(char const*, int*, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCore.so
#28 0x00007f331a71b052 in TApplication::ProcessLine(char const*, bool, int*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCore.so
#29 0x00007f331ab8d0c2 in TRint::ProcessLineNr(char const*, char const*, int*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRint.so
#30 0x00007f331ab8e6c0 in TRint::Run(bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRint.so
#31 0x0000000000400cac in main ()
===========================================================


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.
===========================================================
#5  0x00007f330c760337 in RooLinkedList::find(char const*) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#6  0x00007f330c6c4bae in RooArgSet::getRealValue(char const*, double, bool) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#7  0x00007f3306b4218a in FitKer(int, int, float, float, int, int) () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKer_C.so
#8  0x00007f331a9d40e8 in ?? ()
#9  0x0000000001d58f10 in ?? ()
#10 0x00000078168c3d78 in ?? ()
#11 0x0000003c00000000 in ?? ()
#12 0x00007f3306b3f120 in ?? () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKer_C.so
#13 0x420c000001fc6138 in ?? ()
#14 0x0000000141f00000 in ?? ()
#15 0x0000000001dbe340 in ?? ()
#16 0x00007f33169c56c0 in ?? () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#17 0x00007fff0b547ba0 in ?? ()
#18 0x00007fff0b547770 in ?? ()
#19 0x00007f331a9d4000 in ?? ()
#20 0x00007f33169491e2 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) [clone .part.248] () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#21 0x00007f331694b8c9 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#22 0x00007f331694bddb in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#23 0x00007f33169e9fdd in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#24 0x00007f33168b755e in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
===========================================================

I run with command :

root -b -q "FitKer.C+(0, 0, 30, 35 ,60,120)"

with script

https://github.com/tmishra2018/SUSYAnalysis/blob/main/test/eleFakePho/fit/fit.sh

The libraries are created using :

https://github.com/tmishra2018/SUSYAnalysis/blob/main/include/Makefile

and a minor working version of my code I have stored here :

https://github.com/tmishra2018/SUSYAnalysis

I have stored the input files in the lxplus public area.

/afs/cern.ch/user/t/trmishra/public/RootForum

Can you access it ?
Please let me know.

Thank you

Tribeni

Hi Tribeni, thanks for sharing all of this!

The problem here is that many of the fits for the toy samples generated by the RooMCStudy are failing because of minimizer errors or warnings. When I run your script, only 3 out of 10 toy fits succeed, and the dataset returned by RooMCStudy::fitParDataSet will only have 3 entries then.

Your fitParDataSet().get(i) will therefore return you a nullptr and you get a crash when you ask ->getRealValue() from it.

If only a small fraction of fits would fail it would be okay, and you can do your Toy study with the succeeding toys. However, with your success rate of 30 % it is clear that something is problematic with the fit. I would set aside the MCStudy for the moment and investigate what goes wrong when fitting the model to the data:

  std::unique_ptr<RooFitResult> result{
      model->fitTo(datahist_data, RooFit::Save())
  };
  result->Print();

  TCanvas mycanv("c_fitMass", "", 600, 600);

  RooPlot* mesframe = mass_axis.frame();
  datahist_data.plotOn(mesframe);
  model->plotOn(mesframe);
  model->plotOn(mesframe, RooFit::Components("pdf"),
        RooFit::LineStyle(ELineStyle::kDashed), RooFit::LineColor(kRed));
  model->plotOn(mesframe, RooFit::Components("expo"),
        RooFit::LineStyle(ELineStyle::kDashed), RooFit::LineColor(kGreen));

  mesframe->Draw();

  mycanv.SaveAs("myplot.pdf");

Here are two problems with the fit that I spotted, maybe this helps you to get started:

  1. There is no really any exponential background in the data, so the background fit is very unstable
  2. Very often, the minimizer hits the parameter limits that you set in the RooRealVar constructor, which causes a warning and the results of the fit to be ignored by RooMCStudy
  3. You often get a background pdf evaluated to infinity, because you set the limits for your lambda parameter too wide (you have the interval -10 to 10). So at the Z-peak, you can get exp(10*90) = inf.

So to summarize: you should improve your model such that most of the toy fits succeed, and then only use the successful fit results for the study.

Also, please consider using RooMCStudy::fitParams(), which you pass the index directly and it will give a more readable error when the index is out of bounds.

I hope this helps, don’t hesitate to ask if you have further questions or if something is not clear!

Cheers,
Jonas

HI @jonas
Thanks
I got your explanation and will work on it.

Best,
Tribeni

Hi @jonas
I tried to optimise the parameters, and its range,

RooRealVar m0( “m0”, “m0”, 91.2, 90.0,93.0);
RooRealVar width( “width”, “width”, 0.7, 0, 5);
RooBreitWigner bw(“bw”, “”, mass_axis, m0, width); // Breit Wigner

RooRealVar mean( “mean”, “mean”, -1.0, -1.5, -0.5);
RooRealVar sigma( “sigma”, “sigma”, 2.69, 0.0, 4.0 );
RooRealVar alpha( “alpha”, “alpha”, 0.7, 0.0, 5.0);
RooRealVar n( “n”, “n”, 4.0, 0.0, 20.0);
RooRealVar alpha2(“2ndalpha”,"", 1.0, 0.0, 20.0);
RooRealVar n2(“2ndn”, “”, 1.0,0.0,20.0);
RooDCBShape *cb;
cb = new RooDCBShape(“cb”, “cb”, mass_axis, mean, sigma, alpha, n, alpha2, n2);

here is the updated version.

The fit looks good now.

There is no “break segmentation error” anymore.

The toyMC are generated successfully, but I see another error here :

/cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/bin/root.exe: symbol lookup error: /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKer_C.so: undefined symbol: _ZlsRSoRK9RooAbsArg

Do you have any suggestion ? What is ZlsRSoRK9RooAbsArg ?

Thanks
Best
Tribeni

Hi @tmishra2018,

great that you could tweak the model such that fitting the toys always succeeds!

The new error is because of these cout that you added in you update. You can’t cout a RooRealVar directly, if you want to print the value you have to call getVal() first.

For example, cout<<m0<<endl should be replaced with cout<<m0.getVal()<<endl. and the same with the other variables you print.

Let me see if I can change something in ROOT such that the error is more understandable.

Actually, that was a bug in ROOT! cout<<m0 should have been possible, but the implementation didn’t have the correct function signature!

I fixed this in the current ROOT development cycle:

Thanks again for reporting!

Hi @jonas
Thank you.
The issue did not solve after removing all the “cout” statements you pointed.

cout<<m0<<endl

Again there is “break segmentation error”, once I remove those cout statements.

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.

#5 0x00007f648625a337 in RooLinkedList::find(char const*) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#6 0x00007f64861bebae in RooArgSet::getRealValue(char const*, double, bool) const () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libRooFitCore.so
#7 0x00007f648063b9b9 in FitKerr(int, int, float, float, int, int) () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKerr_C.so
#8 0x00007f64944ce0e8 in ?? ()
#9 0x00000000023c3f10 in ?? ()
#10 0x00000078903bdd78 in ?? ()
#11 0x0000003c00000000 in ?? ()
#12 0x00007f64806383b0 in ?? () from /uscms/homes/t/tmishra/work/CMSSW_10_2_22/src/SUSYAnalysis/test/eleFakePho/fit/FitKerr_C.so
#13 0x420c0000028c3668 in ?? ()
#14 0x0000000141f00000 in ?? ()
#15 0x0000000002429390 in ?? ()
#16 0x00007f64904bf6c0 in ?? () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#17 0x00007fffdc8318d0 in ?? ()
#18 0x00007fffdc8314a0 in ?? ()
#19 0x00007f64944ce000 in ?? ()
#20 0x00007f64904431e2 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) [clone .part.248] () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#21 0x00007f64904458c9 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#22 0x00007f6490445ddb in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#23 0x00007f64904e3fdd in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so
#24 0x00007f64903b155e in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /cvmfs/cms.cern.ch/slc7_amd64_gcc700/lcg/root/6.12.07-gnimlf7/lib/libCling.so

Is it possible for you to reproduce the error, by deleting those cout statements.
Is the crash I am seeing is related to the “bug” in ROOT, you mentioned.

Thanks
Tribeni

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