My fiiting function for convolution crashes


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18

I am trying to fit a convolution function using this the attached code. It crashes and gives me this error below:

Conv_or.C (409 Bytes)

There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f89d863d07a in __GI___waitpid (pid=7877, stat_loc=stat_loc
entry=0x7ffc2b336ac0, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f89d85b5fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f89d922aa12 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x72f3f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/unix/src/TUnixSystem.cxx:2106
#3  TUnixSystem::StackTrace (this=0x72f3f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/unix/src/TUnixSystem.cxx:2400
#4  0x00007f89d922d2e3 in TUnixSystem::DispatchSignals (this=0x72f3f0, sig=kSigSegmentationViolation) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/unix/src/TUnixSystem.cxx:3631
#5  <signal handler called>
#6  0x00007f89cc66ad51 in FT_Done_Glyph () from /usr/lib/x86_64-linux-gnu/libfreetype.so.6
#7  0x00007f89ccfc5418 in TTF::LayoutGlyphs () at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TTF.cxx:215
#8  0x00007f89ccfc5adf in TTF::GetTextExtent (w=
0x7ffc2b339788: 0, h=
0x7ffc2b33978c: 0, text=0x100d470 "20000") at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TTF.cxx:138
#9  0x00007f89ccf90031 in TLatex::Analyse (this=0x1ba9140, x=x
entry=0, y=y
entry=0, spec=..., t=<optimized out>, length=5) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:1897
#10 0x00007f89ccf91681 in TLatex::Anal1 (this=<optimized out>, spec=..., t=<optimized out>, length=<optimized out>) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:492
#11 0x00007f89ccf90528 in TLatex::Analyse (this=this
entry=0x1ba9140, x=x
entry=0, y=y
entry=0, spec=..., t=t
entry=0x7ffc2b33a7a9 "#minus20000", length=11) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:1188
#12 0x00007f89ccf91681 in TLatex::Anal1 (this=this
entry=0x1ba9140, spec=..., t=t
entry=0x7ffc2b33a7a9 "#minus20000", length=<optimized out>) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:492
#13 0x00007f89ccf91839 in TLatex::FirstParse (this=this
entry=0x1ba9140, angle=angle
entry=0, size=size
entry=0.035000000149011612, text=text
entry=0x7ffc2b33a7a9 "#minus20000") at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:2484
#14 0x00007f89ccf923ac in TLatex::PaintLatex1 (this=this
entry=0x1ba9140, x=-2147483648, x
entry=-nan(0x8000000000000), y=-2147483648, y
entry=-nan(0x8000000000000), angle=angle
entry=0, size=size
entry=0.035000000149011612, text1=text1
entry=0x7ffc2b33ac79 "#minus20000") at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:2198
#15 0x00007f89ccf9379b in TLatex::PaintLatex (this=0x1ba9140, x=-nan(0x8000000000000), y=-nan(0x8000000000000), angle=0, size=0.035000000149011612, text1=0x7ffc2b33ac79 "#minus20000") at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TLatex.cxx:2126
#16 0x00007f89ccf7b052 in TGaxis::PaintAxis (this=this
entry=0x7ffc2b33afe0, xmin=xmin
entry=-30000, ymin=ymin
entry=-0.3010299956639812, xmax=xmax
entry=30000, ymax=ymax
entry=-0.3010299956639812, wmin=
0x7ffc2b33afc0: -30000, wmax=
0x7ffc2b33afc8: 30000, ndiv=
0x7ffc2b33afb8: 510, chopt=chopt
entry=0x7f89c9624d68 <THistPainter::PaintAxis(bool)::chopt> "SDH", gridlength=<optimized out>, gridlength
entry=0, drawGridOnly=drawGridOnly
entry=false) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/graf/src/TGaxis.cxx:1988
#17 0x00007f89c93eb389 in THistPainter::PaintAxis (this=0x1b8f3f0, drawGridOnly=<optimized out>) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/hist/histpainter/src/THistPainter.cxx:4821
#18 0x00007f89c93dd826 in THistPainter::Paint (this=0x1b8f3f0, option=0x1a36d31 "") at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/hist/histpainter/src/THistPainter.cxx:4540
#19 0x00007f89cd2dcedb in TPad::PaintModified (this=0xb68e60) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/gpad/src/TPad.cxx:3687
#20 0x00007f89cd29de5c in TCanvas::Update (this=0xb68e60) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/graf2d/gpad/src/TCanvas.cxx:2323
#21 0x00007f89d3d01f99 in TCling::UpdateAllCanvases () at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/metacling/src/TCling.cxx:6411
#22 0x00007f89d3d0aa20 in TCling::ProcessLine (this=0x78e990, line=<optimized out>, error=0x0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/metacling/src/TCling.cxx:2195
#23 0x00007f89d3cfead9 in TCling::ProcessLineSynch (error=0x0, line=0x7f89d5d4595d "TRint::EndOfLineAction();", this=0x78e990) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/metacling/src/TCling.cxx:3176
#24 TCling::EndOfLineAction (this=0x78e990) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/metacling/src/TCling.cxx:2807
#25 0x00007f89d959a70b in TRint::HandleTermInput (this=0x77b6f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/rint/src/TRint.cxx:642
#26 0x00007f89d922c6ec in TUnixSystem::CheckDescriptors (this=this
entry=0x72f3f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/unix/src/TUnixSystem.cxx:1309
#27 0x00007f89d922dc6a in TUnixSystem::DispatchOneEvent (this=0x72f3f0, pendingOnly=<optimized out>) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/unix/src/TUnixSystem.cxx:1064
#28 0x00007f89d9149541 in TSystem::InnerLoop (this=0x72f3f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/base/src/TSystem.cxx:412
#29 TSystem::Run (this=0x72f3f0) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/base/src/TSystem.cxx:362
#30 0x00007f89d90d894f in TApplication::Run (this=this
entry=0x77b6f0, retrn=retrn
entry=false) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/base/src/TApplication.cxx:1178
#31 0x00007f89d959bcbe in TRint::Run (this=this
entry=0x77b6f0, retrn=retrn
entry=false) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/core/rint/src/TRint.cxx:460
#32 0x000000000040099a in main (argc=1, argv=0x7ffc2b33dc38) at /home/lumkilemsebi/MYPROGRAM/root-6.18.02/main/src/rmain.cxx:30
===========================================================

Try replacing:

et_1->Draw();
et_1->Fit("fit");

by:

hist->Draw();
hist->Fit("fit");

I tried the problem still persists.

Could you provide your data file, to allow us to try your macro?

Without you data file we cannot run your macro. I tried to “simulate” the “hist” histogram by creating one filled as a gaussian. See the following macro.

{
   auto hist = new TH1D("hist", "hist", 100, -5,5);
   hist->FillRandom("gaus",20000);
   auto fit = new TF1("fit","([0]/(2*[3]))*exp((pow([2],2))/(2*pow([3],2))-(x-[1])/[3])*TMath::Erfc((1/sqrt(2))*(([2]/[3])-((x-[1])/[2])))",-30000,30000);

   fit->SetParameters(1.868E04,350,0,0);
   fit->SetParLimits(0,1.487E04,1.868E04);
   fit->SetParLimits(1,250,350);

   hist->Fit("fit");
}

It does not work but does not crash. I get:

root [0] 
Processing Conv_or.C...
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
 FCN=inf FROM HESSE     STATUS=NOT POSDEF     51 CALLS         343 TOTAL
                     EDM=nan    STRATEGY= 1      ERR MATRIX NOT POS-DEF
  EXT PARAMETER                APPROXIMATE        STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  p0           1.86800e+04           nan   5.00000e-01           nan
   2  p1           3.50000e+02           nan   5.00000e-01           nan
   3  p2           0.00000e+00           nan   1.40599e-09           nan
   4  p3           0.00000e+00           nan   1.40599e-09           inf
Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: c1 height changed from 0 to 10

So, yes, as @bellenot said, to help you further we will need your data file.

Hi,
evaluating your function results already with the
starting parameters in NaN (divide by 0).

Parameter 1 starts at is limit (350)

So provide reasonable values for [1], [2] and [3]

It is good practice to “Draw” the formula before trying to fit
if it is more complicated than:

"[0]*x"

Cheers
Otto

1 Like

I attach my data file and will appreciate further help.

gate244_Eu.root (30.1 KB)

Conv_or.C (557 Bytes)

Dear Wile_E_Coyote

Thank you very much it works perfectly fine.
Please can you explain what this “fit->SetNpx(100000);” does please?

TF1::SetNpx

BTW. Maybe a better idea would be to use something like:
fit->SetNpx(TMath::Max(100, 3 * hist->GetNbinsX())); // at least 100 points

Thanks a lot. Much appreciated.

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