Crashes while randomly filling TH2D with personalized TF2

Dear ROOTer,

At first, I must say that I am using root v5.22 on a Mac OS X Tiger 10.5.6

I am trying to randomly filled a 2 dimensional histogram from a personalized TF2 function [Convolution of a Gaussian(X,Y) with exp(-|x|/h-|y|/h’)].

Here, is my programs, embedded into an header file:

[code]//*************************************************************
// FUNCTION TO CREATE HISTOGRAMM RANDOMLY FILLED BY The CONFOLUTION OF DECAYING EXPONANTIAL WITH GAUSSIAN
//*************************************************************
TH2D *FillExpG2D(TH2 *IN, double Xmean, double XSig0, double XSig1, double Ymean, double YSig0, double YSig1)
{

// IN -> the histogram to be filled (LIMIT MUST BE [0,360] or [-180,180] for the X axis and [-90,90] for the Y axis).
// Xmean -> the averaged X position
// XSig0 -> Sigma of the gaussian
// XSig1 -> Scale height of the decaying exponential exp(-0.5|x|/XSig1)
// IDEM FOR Ymean, YSig0, YSig1

bool IsCentered0 = false;
if(IN->GetXaxis()->GetXmin() < 0) IsCentered0 = true;

double Xmax, Xmin, NXbin;
double Ymax, Ymin, NYbin;
double X,Y;

Xmax = IN->GetXaxis()->GetXmax();
Xmin = IN->GetXaxis()->GetXmin();
NXbin= IN->GetNbinsX();

Ymax = IN->GetYaxis()->GetXmax();
Ymin = IN->GetYaxis()->GetXmin();
NYbin= IN->GetNbinsY();
	
TF2 *Exp2 = new TF2("Exp2",ExpGausConvolution,
					Xmin-10*(XSig0+XSig1),Xmax+10*(XSig0+XSig1),Ymin-10*(YSig0+YSig1),Ymax+10*(YSig0+YSig1), 7);

//// IN CASE OF THE 2D Gaussian :
//// TF2 Exp2 = new TF2(“G2”,“xygaus”,Xmin-10XSig,Xmax+10XSig,Ymin-10YSig,Ymax+10YSig);
Exp2->SetNpx(int((Xmax-Xmin+2
(10*(XSig0+XSig1)))/(Xmax-Xmin)NXbin));
Exp2->SetNpy(int((Ymax-Ymin+2
(10*(YSig0+YSig1)))/(Ymax-Ymin)*NYbin));

Exp2->SetParameters(1.,Xmean,XSig0, XSig1,Ymean,YSig0,YSig1);
//// IN CASE OF THE 2D Gaussian :
//// Exp2->SetParameters(1.,Xmean,XSig0,Ymean,YSig0);

TH2D *TEMP= (TH2D*) IN->Clone("TEMP");
TEMP->Scale(0);
TEMP->SetEntries(0);

for(int i=1; i<= 1000; i++)
{
	Exp2->GetRandom2(X,Y);
	if(!IsCentered0)
	{
		if(fabs(Y) > 90) {Y = 180.-Y; X+=IN->GetXaxis()->GetXmax()/2.;}
		while(X > IN->GetXaxis()->GetXmax()) X -=IN->GetXaxis()->GetXmax();
		while(X < 0) X +=IN->GetXaxis()->GetXmax();
	}
	else
	{
		if(fabs(Y) > 90) {Y = 180.-Y; X+=IN->GetXaxis()->GetXmax();}
		while(X > IN->GetXaxis()->GetXmax()) X =IN->GetXaxis()->GetXmin() + (IN->GetXaxis()->GetXmin() + X);
		while(X < IN->GetXaxis()->GetXmin()) X =IN->GetXaxis()->GetXmax() + (IN->GetXaxis()->GetXmax() + X);
	}
	TEMP->Fill(X,Y);
}

TEMP->Scale(1./TEMP->Integral("W"));
TEMP->SetEntries(1);

delete Exp2;
return TEMP;

}

// AN APPROXIMATION OF THE ERROR FUNCTION
double ERF(double x)
{
double Pi=acos(-1);
double a=-8./(3.Pi)(Pi-3.)/(Pi-4.);
double erf = 1. - exp(-pow(x,2.)(4./Pi+apow(x,2.))/(1+apow(x,2.)));
if(fabs(x) > 0) return fabs(x)/x
sqrt(erf);
else return sqrt(erf);
}

// THE CONVOLUTION OF THE GAUSSIAN WITH exp(-|x|/h-|y|/h’)
double ExpGausConvolution(double *x, double *par)
{
double ConvX, ConvY;
double Norm=par[0], X0=par[1], Sx=par[2], Hx=par[3],
Y0=par[4], Sy=par[5], Hy=par[6];
double X=x[0]-X0, Y=x[1]-Y0;

ConvX	= exp((4*Hx*X+pow(Sx,2.))/(8*pow(Hx,2)))*(1-ERF(sqrt(2)/4.*(2*Hx*X+pow(Sx,2.))/(Sx*Hx)))
		+ exp(-(4*Hx*X-pow(Sx,2.))/(8*pow(Hx,2)))*(1+ERF(sqrt(2)/4.*(2*Hx*X-pow(Sx,2.))/(Sx*Hx)));
ConvY	= exp((4*Hy*Y+pow(Sy,2.))/(8*pow(Hy,2)))*(1-ERF(sqrt(2)/4.*(2*Hy*Y+pow(Sy,2.))/(Sy*Hy)))
		+ exp(-(4*Hy*Y-pow(Sy,2.))/(8*pow(Hy,2)))*(1+ERF(sqrt(2)/4.*(2*Hy*Y-pow(Sy,2.))/(Sy*Hy)));

if(ConvX*ConvY > 0) return Norm*ConvX*ConvY;
else return 0;

}
[/code]

when I run it,

#include<MyHeader.h>
TH2D *IN = new TH2D("TETS","TEST",183,0,360,82,-90,90);
TH2D *OUT=(TH2D*) FillExpG2D(IN,130,1.,1.5,-10,1,1.5);

it crashes while it try to get the random number at the line Exp2->GetRandom2(X,Y). The error message is quite long but it start as follow:

*** Break *** bus error /Volumes/USERS-DATA/gillard/PAMELA/CR-MAP/ELECTRON/DAYLY/32103: No such file or directory. Attaching to process 32103. Reading symbols for shared libraries . done Reading symbols for shared libraries ............. done 0x906c0189 in wait4 () ...

It seems the problem occur when at the Exp2->GetRandom(X,Y) function and, the Exp2 TF2 object seems to be responsible of the problem. If now I change my personalized function by a simple “gaussxy”, the program run fine.

However, if I create the Exp2 function from the ROOT shell directly (see code below) and try to plot it, or obtain 1000 random number X and Y, I do not have problems.

double X, Y;
TF2 *Exp2 = new TF2("Exp2",ExpGausConvolution,0,360,-90,90,7);
Exp2->SetParameters(1.,180,1, 5.5,0,1,5.5);
Exp2->Draw("COLZ");
for(int i=0;i<1000;i++) {Exp2->GetRandom2(X,Y); cout<<"  "<<X<<"    "<<Y<<endl;}

So, if someone can help me to solve my problem, I will be very grateful.

I cannot reproduce the crash. However
-I recommend to not delete the TF2 object and instead draw it.
-you will see that the definition limits are far too large.
-restrict the function definition range to the area where it makes sense

Rene

[quote=“Rene”]I cannot reproduce the crash. However
-I recommend to not delete the TF2 object and instead draw it.
-you will see that the definition limits are far too large.
-restrict the function definition range to the area where it makes sense
[/quote]

Many thanks for this advice, the random generation is more quicker with restricted interval for the function TF2.

Removing the “delete TF2” does not solve the problem and, if you want more details, I send you the full error message.

However, I run this routine onto a Linux computer with root v5.24 and on which I’m also not able reproduce the crash. I am suspecting this “bug” is coming either from the Mac OS or form the version 5.22 of root. Nonetheless it is still strange that it does no crash (what ever the OS or the root version) when I am using a more simpler TF2 function, such as a 2D Gaussian or a 2D decay exponential. Unfortunately, I can not check on my Mac with root v5.24 since that, after several attempts, I am still not able to build the root v5.24.

[code] *** Break *** bus error
/Volumes/USERS-DATA/gillard/PAMELA/CR-MAP/ELECTRON/DAYLY/66606: No such file or directory.
Attaching to process 66606.
Reading symbols for shared libraries . done
Reading symbols for shared libraries … done
0x906c0189 in wait4 ()

========== STACKS OF ALL THREADS ==========

Thread 1 (process 66606 thread 0x10b):
#0 0x906c0189 in wait4 ()
#1 0x906bdcd4 in system$UNIX2003 ()
#2 0x0086cada in TUnixSystem::StackTrace ()
#3 0x00870cc5 in TUnixSystem::DispatchSignals ()
#4 0x00870e38 in SigHandler ()
#5
#6 0x010a05ad in G__ASM_GET_INT_P10 ()
#7 0x00f81f29 in G__exec_asm ()
#8 0x00f8a851 in G__exec_bytecode ()
#9 0x0100a233 in G__interpret_func ()
#10 0x00f6613d in Cint::G__CallFunc::ExecInterpretedFunc ()
#11 0x00f66358 in Cint::G__CallFunc::Execute ()
#12 0x00856894 in TCint::CallFunc_ExecDouble ()
#13 0x0084f5de in TMethodCall::Execute ()
#14 0x02579843 in TF1::EvalPar ()
#15 0x02582bf6 in ROOT::Math::WrappedMultiFunction<TF1&>::DoEval ()
#16 0x00179590 in ROOT::Math::AdaptiveIntegratorMultiDim::Integral ()
#17 0x0257b566 in TF1::IntegralMultiple ()
#18 0x02586ac6 in TF2::Integral ()
#19 0x02588646 in TF2::GetRandom2 ()
#20 0x0266c9c3 in G__G__Hist_138_0_23 ()
#21 0x00f63512 in Cint::G__ExceptionWrapper ()
#22 0x0102e8b3 in G__execute_call ()
#23 0x0103542d in G__call_cppfunc ()
#24 0x01009c8e in G__interpret_func ()
#25 0x00ff509b in G__getfunction ()
#26 0x0110659b in G__getstructmem ()
#27 0x010fc25b in G__getvariable ()
#28 0x00fc1e61 in G__getitem ()
#29 0x00fc4dd9 in G__getexpr ()
#30 0x0106fcc1 in G__exec_statement ()
#31 0x0107082f in G__exec_loop ()
#32 0x0106892b in G__exec_statement ()
#33 0x0100bed5 in G__interpret_func ()
#34 0x00ff5615 in G__getfunction ()
#35 0x00fc1fa7 in G__getitem ()
#36 0x00fc4dd9 in G__getexpr ()
#37 0x00ff490b in G__getfunction ()
#38 0x00fc1fa7 in G__getitem ()
#39 0x00fc4dd9 in G__getexpr ()
#40 0x00fb0954 in G__define_var ()
#41 0x0106827e in G__exec_statement ()
#42 0x00fabaef in G__exec_tempfile_core ()
#43 0x00fabe97 in G__exec_tempfile_fp ()
#44 0x01077ab1 in G__process_cmd ()
#45 0x008584a4 in TCint::ProcessLine ()
#46 0x007ac8d7 in TApplication::ProcessLine ()
#47 0x0002fe26 in TRint::HandleTermInput ()
#48 0x0002f4c0 in TTermInputHandler::Notify ()
#49 0x00031424 in TTermInputHandler::ReadNotify ()
#50 0x00870fd0 in TUnixSystem::CheckDescriptors ()
#51 0x008716fb in TUnixSystem::DispatchOneEvent ()
#52 0x007fc430 in TSystem::InnerLoop ()
#53 0x007febcb in TSystem::Run ()
#54 0x007ab523 in TApplication::Run ()
#55 0x0003071e in TRint::Run ()
#56 0x00001bae in main ()[/code]

Hi,

[quote]Unfortunately, I can not check on my Mac with root v5.24 since that, after several attempts, I am still not able to build the root v5.24. [/quote]Can you try again with v5.25/04? If the build fail, please let us know how it fails (i.e. it really should be working out of the box :slight_smile:).

If the problem still persist with v5.25/04, can you send us a complete running example showing the problem?

Cheers,
Philippe.

Hi,

Thanks for this news. However, I still did not managed to install the new root version. I think it come from one package I tried to install but I am not able to identify it.

I create a bash script which allow me to install root with similare configuration as the previous version (5.20) I installed on my Mac (OS X Leopard). Here is the file

[code]#!/bin/bash

DEFINE SOME COLOR TO PRINT ON THE SHELL. MORE EASY TO READ

black=’\E[30;1m’
red=’\E[31;1m’
brun=’\E[31;0m’
green=’\E[32;1m’
yellow=’\E[33;1m’
blue=’\E[34;1m’
magenta=’\E[35;1m’
cyan=’\E[36;1m’
white=’\E[37;1m’

reset=tput sgr0

CHECK FOR THE INPUT PARAMETERS OF THE SCRIPT

if [ $# -ne “1” ] ; then
echo -e “$red RootCFG - Not enough number of Argument.” $reset
echo " PLEASE enter root version to be installed"
exit 127
fi

#PATH OF THE ROOT TO BE INSTALLED
IDVER=$1
INSTALLDIR=/SCIENCE/ROOT/$IDVER

echo ““
echo “CONFIGURE will set up the ROOT instalation to install ROOT $IDVER"
echo -e " ROOTSYS directory set as $blue $INSTALLDIR” $reset
echo -e " INCLUDE directory set as $blue $INSTALLDIR/include” $reset
echo -e " LIB directory set as $blue $INSTALLDIR/lib” $reset
echo -e " DATA directory set as $blue $INSTALLDIR/data" $reset
echo -e " DOC directory set as $blue $INSTALLDIR/doc" $reset
echo -e " etc directory set as $blue $INSTALLDIR/etc" $reset
echo -e " FONTS directory set as $blue $INSTALLDIR/fonts" $reset
echo -e " ICONS directory set as $blue $INSTALLDIR/icons" $reset
echo -e " MACRO directory set as $blue $INSTALLDIR/macros" $reset
echo -e " MAN directory set as $blue $INSTALLDIR/man" $reset
echo -e " src directory set as $blue /SCIENCE/ROOT/src/root-$IDVER" $reset
echo -e " TEST directory set as $blue $INSTALLDIR/test" $reset
echo -e " TUTORIAL directory set as $blue $INSTALLDIR/tutorials" $reset
echo ""
6
cd /SCIENCE/ROOT/src/root-$IDVER

#START CONFIGURATION OF THE ROOT INSTALL
./configure macosx --prefix=$INSTALLDIR --cintincdir=$INSTALLDIR/include --datadir=$INSTALLDIR/data --docdir=$INSTALLDIR/doc --etcdir=$INSTALLDIR/etc --fontdir=$INSTALLDIR/fonts --iconpath=$INSTALLDIR/icons --libdir=$INSTALLDIR/lib --macrodir=$INSTALLDIR/macros --mandir=$INSTALLDIR/man --srcdir=/SCIENCE/ROOT/src/root-$IDVER --testdir=$INSTALLDIR/test --tutdir=$INSTALLDIR/tutorials --enable-explicitlink --enable-fftw3 --enable-g4root --enable-genvector --enable-mathmore --enable-minuit2 --enable-memstat --enable-mysql --enable-opengl --enable-pythia6 --enable-pythia8 --enable-qt --enable-roofit --enable-shadowpw --enable-table --enable-unuran --enable-xft --with-fftw3-incdir=/usr/include --with-fftw3-libdir=/usr/lib --with-g4-incdir=/SCIENCE/GEANT4/v4.9.2/include/geant4 --with-g4-libdir=/SCIENCE/GEANT4/v4.9.2/lib/geant4/Darwin-g++/ --with-clhep-incdir=/SCIENCE/CLHEP/v2.0.4/include/ --with-gsl-incdir=/SCIENCE/GSL/v1.12/include/ --with-gsl-libdir=/SCIENCE/GSL/v1.12/lib/ --with-mysql-incdir=/usr/local/mysql/include/ --with-mysql-libdir=/usr/local/mysql/lib --with-opengl-incdir=/usr/X11/include --with-opengl-libdir=/usr/X11/lib --with-pythia6-libdir=/SCIENCE/PYTHIA/v6.409/lib --with-pythia8-libdir=/SCIENCE/PYTHIA/v8.120/lib/ --with-pythia8-incdir=/SCIENCE/PYTHIA/v8.120/include/ --with-qt-incdir=/usr/local/Trolltech/Qt-4.4.3/include --with-qt-libdir=/usr/local/Trolltech/Qt-4.4.3/lib --with-x11-libdir=/usr/X11/lib --with-krb5-incdir=/Developer/SDKs/MacOSX10.5.sdk/usr/include/krb5 --with-krb5-libdir=/Developer/SDKs/MacOSX10.5.sdk/usr/lib --disable-xrootd --disable-bonjour --with-dicttype=cint --with-xml-incdir=/usr/include/libxml2 --with-xml-libdir=/usr/lib

echo ""
echo -e “$red Before make, please check that ./configure set up all package correctly and find all system library” $reset
echo “”

exit 127[/code]

The input parameters os this script being the version of the root I want to install. Note that my mac is 64 bits but, I am using program from my collaboration which has been developed on 32 bits. Therefore, I need to install root in 32 bits in order to run our collaboration analyses software.

Here is the final error which crash the make of root:

g++ -dynamiclib -single_module -undefined dynamic_lookup -install_name /SCIENCE/ROOT/v5.25/lib/libHbook.so -O2 -m32 -o lib/libHbook.so hist/hbook/src/THbookBranch.o hist/hbook/src/THbookFile.o hist/hbook/src/THbookKey.o hist/hbook/src/THbookTree.o hist/hbook/src/G__Hbook.o -ldl -Llib -lHist -lMatrix -lTree -lGraf -lTreePlayer -lRIO -lminicern -Llib -lCore -lCint ==> lib/libHbook.so done bin/rmkdepend -R -fnet/rpdutils/src/rpdutils.d -Y -w 1000 -- -m32 -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Iinclude -DR__HAVE_CONFIG -D__DARWIN_UNIX03=1 -D_REENTRANT -pthread -DR__KRB5 -DR__SSL -DOPENSSL_NO_KRB5 -DR__SHADOWPW -I/Developer/SDKs/MacOSX10.5.sdk/usr/include/krb5 -D__cplusplus -- net/rpdutils/src/rpdutils.cxx g++ -O2 -m32 -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Iinclude -DR__HAVE_CONFIG -D__DARWIN_UNIX03=1 -D_REENTRANT -pthread -DR__KRB5 -DR__SSL -DOPENSSL_NO_KRB5 -DR__SHADOWPW -I/Developer/SDKs/MacOSX10.5.sdk/usr/include/krb5 -o net/rpdutils/src/rpdutils.o -c net/rpdutils/src/rpdutils.cxx net/rpdutils/src/rpdutils.cxx: In function 'int ROOT::RpdPass(const char*, int)': net/rpdutils/src/rpdutils.cxx:3697: error: 'getspnam' was not declared in this scope net/rpdutils/src/rpdutils.cxx:3703: error: invalid use of undefined type 'struct ROOT::spwd' net/rpdutils/src/rpdutils.cxx:3617: error: forward declaration of 'struct ROOT::spwd' net/rpdutils/src/rpdutils.cxx: In function 'int ROOT::RpdUser(const char*)': net/rpdutils/src/rpdutils.cxx:4619: error: 'getspnam' was not declared in this scope net/rpdutils/src/rpdutils.cxx:4625: error: invalid use of undefined type 'struct ROOT::spwd' net/rpdutils/src/rpdutils.cxx:4617: error: forward declaration of 'struct ROOT::spwd' make: *** [net/rpdutils/src/rpdutils.o] Error 1 rm core/utils/src/RStl_tmp.cxx core/utils/src/rootcint_tmp.cxx

Hi,

remove --enable-shadowpw from your config script. Shadow passwords are not supported on MacOS X and I’ve fixed the ./configure script to not allow you to turn it on on platforms that don’t support it.

Cheers, Fons.

[quote=“rdm”] remove --enable-shadowpw from your config script. Shadow passwords are not supported on MacOS X and I’ve fixed the ./configure script to not allow you to turn it on on platforms that don’t support it.
[/quote]

Thanks, I am now able to build the ROOT package. However, when I
"make install" I got an error. And I do not know exactly what happen. In the following code, you may find the text write on the shell when I try to install root :

dirac:root-v5.25 admin$ sudo make install Installing binaries in /SCIENCE/ROOT/v5.25/bin Installing libraries in /SCIENCE/ROOT/v5.25/lib Installing headers in /SCIENCE/ROOT/v5.25/include/root Installing main/src/rmain.cxx in /SCIENCE/ROOT/v5.25/include/root Installing cint/cint/include cint/cint/lib and cint/cint/stl in /SCIENCE/ROOT/v5.25/include Installing cint/cint7/include cint/cint7/lib and cint/cint7/stl in /SCIENCE/ROOT/v5.25/include Installing icons in /SCIENCE/ROOT/v5.25/icons Installing fonts in /SCIENCE/ROOT/v5.25/fonts Installing misc docs in /SCIENCE/ROOT/v5.25/doc Installing tutorials in /SCIENCE/ROOT/v5.25/tutorials Installing tests in /SCIENCE/ROOT/v5.25/test Installing macros in /SCIENCE/ROOT/v5.25/macros Installing man(1) pages in /SCIENCE/ROOT/v5.25/man Installing config files in /SCIENCE/ROOT/v5.25/etc Installing Autoconf macro in /SCIENCE/ROOT/v5.25/share/aclocal Installing Emacs Lisp library in /SCIENCE/ROOT/v5.25/share/emacs/site-lisp Installing GDML conversion scripts in /SCIENCE/ROOT/v5.25/lib make: *** [install] Error 1

I tryed to “make distclean” and build again the root package.
Then, I remove the source from my hard drive, download them again and try to build and install root from scratches.

It seems root run. But, I guess, some libraries or tools have not been copied in the proper directory and I may not be able to use all the root capabilities (at least, according to the option I set up) since the installing processes crashes.

Any help would be great full.

Can you check that the two last statement in the install: target of the Makefile execute correctly:

       find $(DESTDIR)$(DATADIR) -name CVS -exec rm -rf {} \; >/dev/null 2>&1; \
       find $(DESTDIR)$(DATADIR) -name .svn -exec rm -rf {} \; >/dev/null 2>&1; \

Cheers, Fons.

[quote=“rdm”]Can you check that the two last statement in the install: target of the Makefile execute correctly:

       find $(DESTDIR)$(DATADIR) -name CVS -exec rm -rf {} \; >/dev/null 2>&1; \
       find $(DESTDIR)$(DATADIR) -name .svn -exec rm -rf {} \; >/dev/null 2>&1; \

[/quote]

I write this on my shell

dirac:root-v5.24 admin$ find /SCIENCE/ROOT/v5.24/data -name CVS -exec rm -rf {} \; >/dev/null 2>&1; dirac:root-v5.24 admin$ find /SCIENCE/ROOT/v5.24/data -name .svn -exec rm -rf {} \; >/dev/null 2>&1; \

where “/SCIENCE/ROOT/v5.24” is my “DESTDIR” and “data” is my “DATADIR” and I do not received any error message from the shell. Therefore, I will say that thies two lines work.

I added the two lines bellow to the showbuild target of the make file :

@echo "DATADIR = $(DATADIR)" @echo "DESTDIR = $(DESTDIR)"
and ran a “make showbuild” which give me

DATADIR = /SCIENCE/ROOT/v5.24/data DESTDIR =
as expected (slightly different to that I was expected, but the result should be the same).

Well in the same way could you try to find which statement in the install target generates the error?

Cheers, Fons.

In the install target, I add add the following code, just before closing the @if statment :

find $(DESTDIR)$(DATADIR) -name .svn -exec rm -rf {} \; >/dev/null 2>&1; \ echo "svn SUCCESSFULLY REMOVED"; \
And I do not get the error message now. This seems to solve the problem but I do not understand what was the problem.

Any way. Many thanks for your help.