# Segmentation violations in RooStats / RooFit, related to variable range?

**URL:** <https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102>\
**Category:** Roofit and RooStats\
**Created:** [May 8, 2016, 4:00pm UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102 "2016-05-08T16:00:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![echapon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@echapon](https://root-forum.cern.ch/u/echapon)\
**Post date:** [May 8, 2016, 4:00pm UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/1 "2016-05-08T16:00:07Z")

</div>

Dear experts,

I am experiencing several segmentation violations, in a context that I will try to describe. I am working with a version of ROOT that I compiled last week after pulling the code from git (6.07/07).

The context is that I’m trying to compute limits, using the RooStats tutorial macro StandardHypoTestInvDemo.C and using the asymptotic calculator. The input workspace contains a combined dataset with two categories (indexed with a RooCategory).

When I run this macro, I get a segmentation violation with the following trace:

> [@](#):
>
> # =========================================================== #5 0x00007f571fe5d63b in std::\_Rb\_tree\<std::string, std::string, std::\_Identitystd::string, std::lessstd::string, std::allocatorstd::string \>::\_M\_erase(std::\_Rb\_tree\_nodestd::string_) () from /home/emilien/root-head/lib/libCore.so #6 0x00007f571fe5d647 in std::\_Rb\_tree\<std::string, std::string, std::\_Identitystd::string, std::lessstd::string, std::allocatorstd::string \>::\_M\_erase(std::\_Rb\_tree\_nodestd::string_) () from /home/emilien/root-head/lib/libCore.so #7 0x00007f57120d4244 in RooAbsArg::~RooAbsArg() () from /home/emilien/root-head/lib/libRooFitCore.so #8 0x00007f5712810ecf in RooGaussian::~RooGaussian() () from /home/emilien/root-head/lib/libRooFit.so #9 0x00007f57120e4cbd in RooAbsCollection::safeDeleteList() () from /home/emilien/root-head/lib/libRooFitCore.so #10 0x00007f57120e4e87 in RooAbsCollection::~RooAbsCollection() () from /home/emilien/root-head/lib/libRooFitCore.so #11 0x00007f5712145ed9 in RooArgSet::~RooArgSet() () from /home/emilien/root-head/lib/libRooFitCore.so #12 0x00007f57120d41e6 in RooAbsArg::~RooAbsArg() () from /home/emilien/root-head/lib/libRooFitCore.so #13 0x00007f5712214349 in RooProdPdf::~RooProdPdf() () from /home/emilien/root-head/lib/libRooFitCore.so #14 0x00007f57120f9572 in RooAbsOptTestStatistic::~RooAbsOptTestStatistic() () from /home/emilien/root-head/lib/libRooFitCore.so #15 0x00007f57121fa7c9 in RooNLLVar::~RooNLLVar() () from /home/emilien/root-head/lib/libRooFitCore.so #16 0x00007f571212b1ef in RooAbsTestStatistic::~RooAbsTestStatistic() () from /home/emilien/root-head/lib/libRooFitCore.so #17 0x00007f57121fa7c9 in RooNLLVar::~RooNLLVar() () from /home/emilien/root-head/lib/libRooFitCore.so #18 0x00007f57120e4cbd in RooAbsCollection::safeDeleteList() () from /home/emilien/root-head/lib/libRooFitCore.so #19 0x00007f57120e4e87 in RooAbsCollection::~RooAbsCollection() () from /home/emilien/root-head/lib/libRooFitCore.so #20 0x00007f5712145ed9 in RooArgSet::~RooArgSet() () from /home/emilien/root-head/lib/libRooFitCore.so #21 0x00007f57120d41e6 in RooAbsArg::~RooAbsArg() () from /home/emilien/root-head/lib/libRooFitCore.so #22 0x00007f5712136379 in RooAddition::~RooAddition() () from /home/emilien/root-head/lib/libRooFitCore.so #23 0x00007f5712be8ef1 in RooStats::AsymptoticCalculator::EvaluateNLL(RooAbsPdf&, RooAbsData&, RooArgSet const\*, RooArgSet const\*) () from /home/emilien/root-head/lib/libRooStats.so #24 0x00007f5712bed57a in RooStats::AsymptoticCalculator::Initialize() const () from /home/emilien/root-head/lib/libRooStats.so #25 0x00007f5712bee1c7 in RooStats::AsymptoticCalculator::AsymptoticCalculator(RooAbsData&, RooStats::ModelConfig const&, RooStats::ModelConfig const&, bool) () from /home/emilien/root-head/lib/libRooStats.so #26 0x00007f572039de98 in ?? () #27 0x00007ffffac0e338 in ?? () #28 0x00007ffffac0e248 in ?? () #29 0x00007ffffac0e158 in ?? () #30 0x00007ffffac0e068 in ?? () #31 0x00007ffffac0b140 in ?? () #32 0x00007f57138ecd64 in decltype (\_S\_construct({parm#1}, {parm#2}, (forward\<std::pair\<std::string const, std::string\>&\>)({parm#3}))) std::allocator\_traits\<std::allocator\<std::\_Rb\_tree\_node\<std::pair\<std::string const, std::string\> \> \> \>::construct\<std::\_Rb\_tree\_node\<std::pair\<std::string const, std::string\> \>, std::pair\<std::string const, std::string\>&\>(std::allocator\<std::\_Rb\_tree\_node\<std::pair\<std::string const, std::string\> \> \>&, std::\_Rb\_tree\_node\<std::pair\<std::string const, std::string\> \>\*, std::pair\<std::string const, std::string\>&) () from /home/emilien/root-head/lib/libMathCore.so #33 0x00007f57203996d1 in ?? () #34 0x0000000000000002 in ?? () #35 0x0000000000000000 in ?? ()

Interestingly, I notice another (probably related) crash, when I try to fit the data myself. The fits converges without error only if I provide at least one of the following options to RooAbsPdf::fitTo(): Range(“MassWindow”), or NumCPU(2). If I don’t, most of the time (but not always?) I get a segmentation violation with a trace like the following one:

> [@](#):
>
> # =========================================================== #5 0x00007f8cc788a10d in RooLinkedListIter::Next() () from /home/emilien/root-head/lib/libRooFitCore.so #6 0x00007f8cc77d129a in RooRealVar::RooRealVar(RooRealVar const&, char const\*) () from /home/emilien/root-head/lib/libRooFitCore.so #7 0x00007f8cc77d3be5 in RooRealVar::clone(char const\*) const () from /home/emilien/root-head/lib/libRooFitCore.so #8 0x00007f8cc767a175 in RooAbsCollection::snapshot(RooAbsCollection&, bool) const () from /home/emilien/root-head/lib/libRooFitCore.so #9 0x00007f8cc767b127 in RooAbsCollection::snapshot(bool) const () from /home/emilien/root-head/lib/libRooFitCore.so #10 0x00007f8cc7775018 in RooMinimizerFcn::RooMinimizerFcn(RooMinimizerFcn const&) () from /home/emilien/root-head/lib/libRooFitCore.so #11 0x00007f8cc77750c1 in RooMinimizerFcn::Clone() const () from /home/emilien/root-head/lib/libRooFitCore.so #12 0x00007f8cc8df653a in ROOT::Fit::Fitter::SetFCN(ROOT::Math::IBaseFunctionMultiDim const&, double const\*, unsigned int, bool) () from /home/emilien/root-head/lib/libMathCore.so #13 0x00007f8cc8df68dd in ROOT::Fit::Fitter::FitFCN(ROOT::Math::IBaseFunctionMultiDim const&, double const\*, unsigned int, bool) () from /home/emilien/root-head/lib/libMathCore.so #14 0x00007f8cc77715d2 in RooMinimizer::minimize(char const\*, char const\*) () from /home/emilien/root-head/lib/libRooFitCore.so #15 0x00007f8cc769a56f in RooAbsPdf::fitTo(RooAbsData&, RooLinkedList const&) () from /home/emilien/root-head/lib/libRooFitCore.so #16 0x00007f8cc7695e88 in RooAbsPdf::fitTo(RooAbsData&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) () from /home/emilien/root-head/lib/libRooFitCore.so #17 0x00007f8cd5932219 in ?? () #18 0x00007ffd9ca7bc58 in ?? () #19 0x00007ffd9ca7bb68 in ?? () #20 0x00007ffd9ca7ba78 in ?? () #21 0x00007f8cc7bab800 in ?? () from /home/emilien/root-head/lib/libRooFitCore.so #22 0x00007ffd9ca78c40 in ?? () #23 0x0100000000000013 in ?? () #24 0x000000000575e1a0 in ?? () #25 0x00007f8cd4cc9249 in std::string::\_Rep::\_S\_create(unsigned long, unsigned long, std::allocator const&) () from /usr/lib/x86\_64-linux-gnu/libstdc++.so.6 #26 0x000000000575e160 in ?? () #27 0x000000000575e1a0 in ?? () #28 0x00007ffd9ca78c01 in ?? () #29 0x00007ffd9ca78b80 in ?? () #30 0x00007f8cc8e7c91c in std::pair\<std::\_Rb\_tree\_iterator\<std::pair\<std::string const, std::string\> \>, bool\> std::map\<std::string, std::string, std::lessstd::string, std::allocator\<std::pair\<std::string const, std::string\> \> \>::insert\<std::pair\<std::string const, std::string\>&, void\>(std::pair\<std::string const, std::string\>&) () from /home/emilien/root-head/lib/libMathCore.so #31 0x00007f8cd592f6d1 in ?? () #32 0x0000000000000002 in ?? () #33 0x0000000000000000 in ?? ()

The second trace in particular makes me think that it is something related to the ranges of my observable (invariant mass, named “invMass”). Indeed, we start from a wide mass window and then reduce the dataset to a narrower one (with a range that we call “MassWindow”). I wonder if it could be that the invMass “version” has different ranges / binnings (different number of them or different names) in the dataset, the pdf, or the different components of them. In any case, I have tried a few things following this assumption, but without success.

Thanks a lot in advance for your help.

Cheers,  
Émilien Chapon

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [May 9, 2016, 8:13am UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/2 "2016-05-09T08:13:25Z")

</div>

Hi,

Can you please post your workspace and a minimal macro fitting your model, so I can reproduce the crash ?Otherwise it is difficult to understand the cause of your problem

Best Regards

Lorenzo

---

<div class="post-metadata">

**Author:** ![echapon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@echapon](https://root-forum.cern.ch/u/echapon)\
**Post date:** [May 9, 2016, 9:33am UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/3 "2016-05-09T09:33:25Z")

</div>

Hi Lorenzo,

Unfortunately my workspace contains CMS data which is not public and that I would rather not release freely on a forum. I have sent you a private message pointing you to an archive with some macros and workspaces to reproduce the issue. If anyone else would want to have a look, I can point them privately to the same archive. I will try to reproduce the issue with dummy data, so that I can make it public.

Cheers,  
Émilien

---

<div class="post-metadata">

**Author:** ![echapon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@echapon](https://root-forum.cern.ch/u/echapon)\
**Post date:** [May 9, 2016, 12:25pm UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/4 "2016-05-09T12:25:08Z")

</div>

I have generated pseudo-data, so that the crash can be reproduced without using CMS data. The archive is accessible at the address [cernbox.cern.ch/index.php/s/eCbv7JjFiP9aOkj](https://cernbox.cern.ch/index.php/s/eCbv7JjFiP9aOkj).

If I summarize our workflow: we consider fits of the invariant mass of two dimuons, separately in pp and PbPb collisions, and then combine these two workspaces into one (using the combinedWorkspace.C macro – the connection between pp and PbPb is that we express the yield of psi prime meson in PbPb as a function as the one in pp). At last we want to derive Feldman-Cousins intervals on our observable (the double ratio [N(psi’)/N(J/psi)]\_PbPb / [N(psi’)/N(J/psi)]\_pp, named RFrac2Svs1S\_PbPbvsPP in the workspace) using runLimit\_RaaNS\_Workspace.C.

You can reproduce the first crash with the following:

```auto

```

You may also reproduce the second crash with the following:

```auto

```

---

<div class="post-metadata">

**Author:** ![echapon](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@echapon](https://root-forum.cern.ch/u/echapon)\
**Post date:** [May 11, 2016, 12:04pm UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/5 "2016-05-11T12:04:31Z")

</div>

Despite further investigation on my side, I haven’t found yet why I get this crash. I thought I’d share one of my findings though: it looks like the crash happens when the program encounters a pointer of the form 0x3ff0000000000000 (which is of course far beyond the range for the memory I have), either for \_htableName in RooLinkedList::~RooLinkedList(), or for elem in void RooLinkedList::Delete(Option\_t \*). But I have no idea how this address gets corrupted…

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [May 11, 2016, 12:07pm UTC](https://root-forum.cern.ch/t/segmentation-violations-in-roostats-roofit-related-to-variable-range/21102/6 "2016-05-11T12:07:46Z")

</div>

Always try to precompile your macro using ACLiC, in order to find source code problems, e.g. try something like (inspect all reported warnings and errors):  
root [0] .L YourRootMacro.cxx++

You can “debug” many problems using “valgrind”. See, for example: [Segmentation Fault depending on linux distribution](https://root-forum.cern.ch/t/segmentation-fault-depending-on-linux-distribution/18020/6)
