Seg Fault using TCutG IntegralHist() method

Hello Everyone,

I tried using the IntegralHist() method of the TCutG class but I get a SegFault error on line 105 of 2Dhist.cpp. It’s basically SegFaulting when I use IntegralHist() and pass in the arguments of a TH2F object. I uploaded my code below together with a file called test.root to reproduce the segfault.

To compile: g++ `root-config --cflags --glibs` -std=c++0x -g -Wall -Werror 2Dhist.cpp -o 2Dhist.exe

To run: ./2Dhist.exe ~/path/to/test.root ~/path/to/store/generated/plots

2Dhist.cpp (4.1 KB)
test.root (122.5 KB)


Please read tips for efficient and successful posting and posting code

ROOT Version: 5.34
Platform: Ubuntu 18.04 LTS
Compiler: g++ 4.4.7


Maybe @couet can take a look. Did you try with ROOT 6?

Well the server I’m working in has the v5.34, but I just installed ROOT 6.22 on my local computer and it doesn’t compile. It shows the following errors where Pi0PtvsPi0RecZ.cpp is the same as 2Dhist.cpp:

g++ `root-config --cflags --glibs` -std=c++0x -g -Wall -Werror  PTvsRecZplot.cpp  -o PTvsRecZplot.exe 
/tmp/ccAliWNf.o: In function `main':
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:38: undefined reference to `TCanvas::TCanvas(char const*, char const*, int, int)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:41: undefined reference to `TChain::TChain(char const*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:46: undefined reference to `TH2F::TH2F(char const*, char const*, int, double, double, int, double, double)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:59: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:60: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:61: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:64: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:65: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:66: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:157: undefined reference to `gStyle'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:157: undefined reference to `TStyle::SetOptStat(int)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:38: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:41: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:46: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:59: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:60: undefined reference to `TObject::operator delete(void*)'
/tmp/ccAliWNf.o:/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:61: more undefined references to `TObject::operator delete(void*)' follow
/tmp/ccAliWNf.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/juan/root/include/TVersionCheck.h:31: undefined reference to `TVersionCheck::TVersionCheck(int)'
/tmp/ccAliWNf.o: In function `TObject::operator new(unsigned long)':
/home/juan/root/include/TObject.h:152: undefined reference to `TStorage::ObjectAlloc(unsigned long)'
/tmp/ccAliWNf.o: In function `TAxis::CenterTitle(bool)':
/home/juan/root/include/TAxis.h:186: undefined reference to `TObject::SetBit(unsigned int, bool)'
collect2: error: ld returned 1 exit status
Makefile:19: recipe for target 'PTvsRecZplot.exe' failed
make: *** [PTvsRecZplot.exe] Error 1

But it might be a mistake on my end since I just installed this version locally. If someone can run it in their version of ROOT6 then we can confirm if this is the usual behavior for this file on ROOT6.

Well, it doesn’t work either with ROOT 6 (I just tried).
BTW, what’s the output of root-config --cflags --glibs with ROOT 6?

The output of the previous reply was with the root-config --cflags --glibs flags being used.

Well, I meant: what is the output if you type root-config --cflags --glibs in the command line (in the terminal)
Anyway, since it is not related, let’s wait for @couet, He knows TCutG better than me…

Ok no problem. By any chance did you get the same behavior that I did when you ran it on ROOT6? Just trying to check if I’ve set up ROOT6 incorrectly.

EDIT: This is the output I get by typing root-config --cflags --glibs in the terminal: -pthread -std=c++11 -m64 -I/home/juan/root/include -L/home/juan/root/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -pthread -lm -ldl -rdynamic

I work on Windows :wink:

I tired your program on Mac as you explained in your first post.
I do not get a crash.

With ROOT 5.34?

I do not have it anymore on Mac. I will not have time to install it this morning.

I’m trying to reproduce the results with ROOT6 on a local computer, but I am not getting the behavior I should when I’m executing the program, instead I get the following error at compile time:

/tmp/cc0WJDZJ.o: In function `main':
/home/juan/Desktop/Work/test/2Dhist.cpp:36: undefined reference to `TCanvas::TCanvas(char const*, char const*, int, int)'
/home/juan/Desktop/Work/test/2Dhist.cpp:39: undefined reference to `TChain::TChain(char const*, char const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:44: undefined reference to `TH2F::TH2F(char const*, char const*, int, double, double, int, double, double)'
/home/juan/Desktop/Work/test/2Dhist.cpp:57: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:58: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:59: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:62: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:63: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:64: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:119: undefined reference to `gStyle'
/home/juan/Desktop/Work/test/2Dhist.cpp:119: undefined reference to `TStyle::SetOptStat(int)'
/home/juan/Desktop/Work/test/2Dhist.cpp:36: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:39: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:44: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:57: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/test/2Dhist.cpp:58: undefined reference to `TObject::operator delete(void*)'
/tmp/cc0WJDZJ.o:/home/juan/Desktop/Work/test/2Dhist.cpp:59: more undefined references to `TObject::operator delete(void*)' follow
/tmp/cc0WJDZJ.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/juan/root/include/TVersionCheck.h:31: undefined reference to `TVersionCheck::TVersionCheck(int)'
/tmp/cc0WJDZJ.o: In function `TObject::operator new(unsigned long)':
/home/juan/root/include/TObject.h:152: undefined reference to `TStorage::ObjectAlloc(unsigned long)'
/tmp/cc0WJDZJ.o: In function `TAxis::CenterTitle(bool)':
/home/juan/root/include/TAxis.h:186: undefined reference to `TObject::SetBit(unsigned int, bool)'
collect2: error: ld returned 1 exit status

Which is weird, because it seems that I didn’t install ROOT6 properly since the compiler doesn’t recognize the class calls.

I installed ROOT6.22 by the followig sequence of commands in my Ubuntu 18.04 LTS machine:

$ wget https://root.cern/download/root_v6.22.00.Linux-ubuntu18-x86_64-gcc7.5.tar.gz
$ tar -xzvf root_v6.22.00.Linux-ubuntu18-x86_64-gcc7.5.tar.gz
$ source root/bin/thisroot.sh

These are the instructions that appeared on the website for installing ROOT6 on Ubuntu. I also added the source command to my .bashrc. I also installed all the required packages for running ROOT6 on Ubuntu. I ran the interpreter and it works just fine as well. Is there something else I’m missing from the installation process?

This looks like your system installed one. Is it the ROOT 6 one? Can you make sure it is corrcetly set in your environment? Can you make sure this gives the correct output:

$ source root/bin/thisroot.sh
$ root-config --cflags --glibs

And then compile your code in the same console

Correct, that one was with ROOT6 installed. I ran the commands you showed and it seems that everything is correctly installed but when I compiled the code the same error arose.The output is as follows:

juan@juan-ThinkPad-X260:~/Desktop/Work/DCVcuts/Pi0PtvsRecZ$ source ~/root/bin/thisroot.sh
juan@juan-ThinkPad-X260:~/Desktop/Work/DCVcuts/Pi0PtvsRecZ$ root-config --cflags --glibs
-pthread -std=c++11 -m64 -I/home/juan/root/include -L/home/juan/root/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -pthread -lm -ldl -rdynamic
juan@juan-ThinkPad-X260:~/Desktop/Work/DCVcuts/Pi0PtvsRecZ$ g++ `root-config --cflags --glibs` -std=c++0x -g -Wall -Werror PTvsRecZplot.cpp -o PTvsRecZplot.exe
/tmp/ccoGu9xq.o: In function `main':
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:39: undefined reference to `TCanvas::TCanvas(char const*, char const*, int, int)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:42: undefined reference to `TChain::TChain(char const*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:47: undefined reference to `TH2F::TH2F(char const*, char const*, int, double, double, int, double, double)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:60: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:61: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:62: undefined reference to `TPolyLine::TPolyLine(int, double*, double*, char const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:65: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:66: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:67: undefined reference to `TCutG::TCutG(char const*, int, double const*, double const*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:158: undefined reference to `gStyle'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:158: undefined reference to `TStyle::SetOptStat(int)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:39: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:42: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:47: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:60: undefined reference to `TObject::operator delete(void*)'
/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:61: undefined reference to `TObject::operator delete(void*)'
/tmp/ccoGu9xq.o:/home/juan/Desktop/Work/DCVcuts/Pi0PtvsRecZ/PTvsRecZplot.cpp:62: more undefined references to `TObject::operator delete(void*)' follow
/tmp/ccoGu9xq.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/juan/root/include/TVersionCheck.h:31: undefined reference to `TVersionCheck::TVersionCheck(int)'
/tmp/ccoGu9xq.o: In function `TObject::operator new(unsigned long)':
/home/juan/root/include/TObject.h:152: undefined reference to `TStorage::ObjectAlloc(unsigned long)'
/tmp/ccoGu9xq.o: In function `TAxis::CenterTitle(bool)':
/home/juan/root/include/TAxis.h:186: undefined reference to `TObject::SetBit(unsigned int, bool)'
collect2: error: ld returned 1 exit status

Weird, it looks like it doesn’t take in account the ROOT libraries. Note that you can try to specify the flags and libraries by hand (just copy and paste)

I copy pasted the output of root-config --cflags --glibs but the same output appears. I had a hunch that if I tried running it with sudo privilages it might had done the trick but it didn’t.

Then I really don’t know what could be wrong…

It’s ok, thanks for giving it a shot.

Sorry for not being able to help more…

I managed to get it working in version 5.34, although I discovered a strange behavior.

If I use the IntegralHist() function for a TCutG object that is not signalPerimeter, then it will SegFault. Otherwise, if I use the IntegralHist() method just for signalPerimeter then it won’t segfault.

Also I had to have the second argument as "" even though the documentation says that it already declares it to "" by default.