Termination with 'std::bad_alloc' with RooThresholdCategory

Hello Experts,

I am posting here the following piece of my code. It crashes with bad memory allocation while calling data.addColumn() function -

RooRealVar Mass(“Mass”,“Mass”,2.4,4.0);
Mass.setBins(100);
RooDataSet data(“data”,“data”,RooArgSet(PsProperDL,Pt,Mass),Import(*nt));
RooThresholdCategory massCat(“massCat”, “region of Mass”, Mass, “Background”);
data.addColumn(massCat); // Code Crashes on this line

It display the following error -

terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc

Everything is fine if I remove data.addColumn() line.
Could you please suggest what could go wrong here?

I think @moneta can help you.

Hi,
It looks like you have a memory problem, how big is the data you are importing ?
I would need anyway to have a minimal reproducible (running) example to reproduce your problem

Lorenzo

Thanks @moneta
It looks to me as well that it is a memory problem, because I tested for the small entries. If I have 29889232 (~30Million) entries in the dataset.
If I use all of them I get this error.

terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc

But if I use fewer entries (~200k counts) then I get the following crash.

Error in RooFormula::Compile: Bad numerical expression : “massCat”
[#0] ERROR:InputArguments – RooFormula::RooFormula(massCat==massCat::SB1): compile error
[#0] ERROR:InputArguments – RooDataSet::data:fillHistogram: invalid cuts “massCat==massCat::SB1”
[#0] ERROR:Plotting – RooDataSet::data:plotOn: fillHistogram() failed
*** Break *** segmentation violation
Generating stack trace…
0x00002adbc0871778 in RooPlot::getAttLine(char const*) const at /memfs/15572288/root-6.16.00/roofit/roofitcore/src/RooPlot.cxx:735 from /net/software/local/root/6.16.00/lib/libRooFitCore.so
0x00002adbc0734bf2 in RooAbsData::plotOn(RooPlot*, RooLinkedList const&) const at /memfs/15572288/root-6.16.00/roofit/roofitcore/src/RooAbsData.cxx:1697 from /net/software/local/root/6.16.00/lib/libRooFitCore.so
0x00002adbc0734275 in RooAbsData::plotOn(RooPlot*, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) const at /memfs/15572288/root-6.16.00/roofit/roofitcore/src/RooAbsData.cxx:540 from /net/software/local/root/6.16.00/lib/libRooFitCore.so
0x00002adbadbed922 in
0x00002adbadbeb066 in
0x00002adbb404e53d in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) + 0x4ed from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb404d927 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0xd7 from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb41a2b43 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0xbb3 from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb41b57ae in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x1de from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb41b5174 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x64 from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb41b4f19 in cling::MetaParser::isMetaCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x29 from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb41a0d59 in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0xe9 from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb3f9be4c in from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb3fa1366 in from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbb3fa026e in from /net/software/local/root/6.16.00/lib/libCling.so
0x00002adbae288470 in TApplication::ExecuteFile(char const*, int*, bool) at /memfs/15572288/root-6.16.00/core/base/src/TApplication.cxx:1167 from /net/software/local/root/6.16.00/lib/libCore.so
0x00002adbae28625e in TApplication::ProcessLine(char const*, bool, int*) at /memfs/15572288/root-6.16.00/core/base/src/TApplication.cxx:1012 from /net/software/local/root/6.16.00/lib/libCore.so
0x00002adbaddfcbef in TRint::ProcessLineNr(char const*, char const*, int*) at /memfs/15572288/root-6.16.00/core/rint/src/TRint.cxx:761 from /net/software/local/root/6.16.00/lib/libRint.so
0x00002adbaddfc900 in TRint::Run(bool) at /memfs/15572288/root-6.16.00/core/rint/src/TRint.cxx:421 from /net/software/local/root/6.16.00/lib/libRint.so
0x0000000000402d54 in from /net/software/local/root/6.16.00/bin/root.exe
0x00002adbaf04a505 in __libc_start_main + 0xf5 from /lib64/libc.so.6
0x0000000000402be9 in from /net/software/local/root/6.16.00/bin/root.exe

Here I attached the same macro with the test file (hope it work for you).

Out.root (1.4 MB) testError.C (1.6 KB)

And please suggest something so that this macro can work for 30M entries where it gives the memory error?

Thanks

The second problem is solved easily:
The dataset where you want to apply the cut doesn’t have a column named massCat, so you cannot cut on it. I replaced the line as follows:

- data.plotOn(massFrame, Cut("massCat==massCat::SB1"), MarkerColor(kRed), LineColor(kRed));
+ data_mRange->plotOn(massFrame, Cut("massCat==massCat::SB1"), MarkerColor(kRed), LineColor(kRed));
1 Like

How can I test the first problem? Should I just try to generate a dataset with 30M events?

Edit:
I did just that. I created a dataset with 30M events, and added the column to it. It just worked.

  • Can you upload a reproducer?
  • In case you use an old ROOT version, can you try a new one?
1 Like

Thank you @StephanH
the second problem works for me now.
I am using RooFit 3.60 this time.

Regarding the first problem, it works for me for around ~20M entries and at the moment it is fine…

Thank you Again for help! :grin:

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