I am analysing gamma ray spectra and create histograms out of them. Those spectra get fitted multiple times because each peak gets fitted individually. I save my original spectrum (hSpectrumUncalibrated), the one where I fitted the peaks on (hSpectrumCalibration) and the calibrated spectrum (hSpectrumCalibrated) into a .root file. I can also open the created file (analysis.root) and use the Draw() method to draw all above mentioned objects with the exception of 'hSpectrumCalibration" (the histogram where I fitted the peaks).
The code I get is the following:
root analysis/analysis.root
root [0]
Attaching file analysis/analysis.root as _file0...
(TFile *) 0x2164100
root [1] hSpectrumCalibration->Draw()
Error in <TClingCallFunc::make_wrapper>: Failed to compile
==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
if (ret) {
new (ret) (double) (TFormula____id3464724124191079635(*(double**)args[0], *(double**)args[1]));
return;
}
else {
TFormula____id3464724124191079635(*(double**)args[0], *(double**)args[1]);
return;
}
}
#pragma clang diagnostic pop
==== SOURCE END ====
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f0aa18e7dbc in waitpid () from /lib64/libc.so.6
#1 0x00007f0aa186acc2 in do_system () from /lib64/libc.so.6
#2 0x00007f0aa28f863f in TUnixSystem::StackTrace (this=0xed28e0) at /tmp/root-6.10.06/core/unix/src/TUnixSystem.cxx:2412
#3 0x00007f0aa28fad8c in TUnixSystem::DispatchSignals (this=0xed28e0, sig=kSigSegmentationViolation) at /tmp/root-6.10.06/core/unix/src/TUnixSystem.cxx:3643
#4 <signal handler called>
#5 0x0000000000000000 in ?? ()
#6 0x00007f0a98c9fe70 in TFormula::DoEval (this=0x2623930, x=x
entry=0x7ffe0ba3a4d0, params=params
entry=0x0) at /tmp/root-6.10.06/hist/hist/src/TFormula.cxx:2700
#7 0x00007f0a98ca0035 in TFormula::Eval (this=<optimized out>, x=<optimized out>, y=<optimized out>, z=<optimized out>, t=<optimized out>) at /tmp/root-6.108
#8 0x00007f0a98c7bd2c in TF1::Eval (this=0x25e9120, x=<optimized out>, y=<optimized out>, z=<optimized out>, t=<optimized out>) at /tmp/root-6.10.06/hist/hi9
#9 0x00007f0a94e3c1e9 in THistPainter::PaintInit (this=0x29fd350) at /tmp/root-6.10.06/hist/histpainter/src/THistPainter.cxx:6669
#10 0x00007f0a94e38b2e in THistPainter::Paint (this=0x29fd350, option=0x2583c51 "") at /tmp/root-6.10.06/hist/histpainter/src/THistPainter.cxx:4164
#11 0x00007f0a98574a89 in TPad::PaintModified (this=0x285b730) at /tmp/root-6.10.06/graf2d/gpad/src/TPad.cxx:3626
#12 0x00007f0a98544f4b in TCanvas::Update (this=0x285b730) at /tmp/root-6.10.06/graf2d/gpad/src/TCanvas.cxx:2244
#13 0x00007f0a9dad71dc in TCling::UpdateAllCanvases () at /tmp/root-6.10.06/core/metacling/src/TCling.cxx:5748
#14 0x00007f0a9dadca03 in TCling::ProcessLine (this=0xf30df0, line=<optimized out>, error=0x0) at /tmp/root-6.10.06/core/metacling/src/TCling.cxx:1936
#15 0x00007f0a9daccfdb in TCling::ProcessLineSynch (this=0xf30df0, line=0x7f0a9f3be917 "TRint::EndOfLineAction();", error=0x0) at /tmp/root-6.10.06/core/meta7
#16 0x00007f0aa2c42ae1 in TRint::HandleTermInput (this=0xf1ff80) at /tmp/root-6.10.06/core/rint/src/TRint.cxx:637
#17 0x00007f0aa28fa395 in TUnixSystem::CheckDescriptors (this=this
entry=0xed28e0) at /tmp/root-6.10.06/core/unix/src/TUnixSystem.cxx:1321
#18 0x00007f0aa28fb4ba in TUnixSystem::DispatchOneEvent (this=0xed28e0, pendingOnly=<optimized out>) at /tmp/root-6.10.06/core/unix/src/TUnixSystem.cxx:1076
#19 0x00007f0aa2847956 in TSystem::InnerLoop (this=0xed28e0) at /tmp/root-6.10.06/core/base/src/TSystem.cxx:410
#20 0x00007f0aa2848560 in TSystem::Run (this=0xed28e0) at /tmp/root-6.10.06/core/base/src/TSystem.cxx:360
#21 0x00007f0aa27eb97f in TApplication::Run (this=this
entry=0xf1ff80, retrn=retrn
entry=false) at /tmp/root-6.10.06/core/base/src/TApplication.cxx:1153
#22 0x00007f0aa2c440a4 in TRint::Run (this=0xf1ff80, retrn=<optimized out>) at /tmp/root-6.10.06/core/rint/src/TRint.cxx:455
#23 0x0000000000400bac in main (argc=1, argv=0x7ffe0ba3d038) at /tmp/root-6.10.06/main/src/rmain.cxx:30´´´
===========================================================
The lines below might hint at the cause of the ´´´<a class="attachment" href="/uploads/default/original/3X/d/0/d01b0021f6ff524ae51bec5d20fce7e444bc6043.C">macro01.C</a> (8.5 KB)
<a class="attachment" href="/uploads/default/original/3X/e/2/e297168655f675b689c47bc6ce950d8adb0f627d.h">macro01.h</a> (17.2 KB)
<a class="attachment" href="/uploads/default/original/3X/8/9/897cb6cc19e7648010e684ebd1c35a7f5b1dc5ee.root">analysis.root</a> (72.9 KB)
crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x0000000000000000 in ?? ()
#6 0x00007f0a98c9fe70 in TFormula::DoEval (this=0x2623930, x=x
entry=0x7ffe0ba3a4d0, params=params
entry=0x0) at /tmp/root-6.10.06/hist/hist/src/TFormula.cxx:2700
#7 0x00007f0a98ca0035 in TFormula::Eval (this=<optimized out>, x=<optimized out>, y=<optimized out>, z=<optimized out>, t=<optimized out>) at /tmp/root-6.108
#8 0x00007f0a98c7bd2c in TF1::Eval (this=0x25e9120, x=<optimized out>, y=<optimized out>, z=<optimized out>, t=<optimized out>) at /tmp/root-6.10.06/hist/hi9
#9 0x00007f0a94e3c1e9 in THistPainter::PaintInit (this=0x29fd350) at /tmp/root-6.10.06/hist/histpainter/src/THistPainter.cxx:6669
#10 0x00007f0a94e38b2e in THistPainter::Paint (this=0x29fd350, option=0x2583c51 "") at /tmp/root-6.10.06/hist/histpainter/src/THistPainter.cxx:4164
#11 0x00007f0a98574a89 in TPad::PaintModified (this=0x285b730) at /tmp/root-6.10.06/graf2d/gpad/src/TPad.cxx:3626
#12 0x00007f0a98544f4b in TCanvas::Update (this=0x285b730) at /tmp/root-6.10.06/graf2d/gpad/src/TCanvas.cxx:2244
#13 0x00007f0a9dad71dc in TCling::UpdateAllCanvases () at /tmp/root-6.10.06/core/metacling/src/TCling.cxx:5748
===========================================================
Weirdly however I can view said histogram in the TBrowser without any problem and even more stunning, I can Draw() the histogram once I double clicked on it in a TBrowser and closed said TBrowser again.
I really don’t know what is happening here and would like to ask kindly for your advice.
Here follows some additional information:
ROOT version 6.10.06
regarding the platform: when I enter cat /proc/version
I get
Linux version 4.15.0-50-generic (buildd@lcy01-amd64-013) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019
however I execute ROOT on a server with which I am connected to via ssh and when I ask for the version there it says
Linux version 3.10.0-693.2.2.el7.x86_64 (mockbuild@x86-039.build.eng.bos.redhat.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Sat Sep 9 03:55:24 EDT 2017
I don’t know about the compiler and how ROOT has been installed (university server).
Maybe I should also add that I used the TSelector class to create a macro01.C and macro01.h file with which I execute a TChain to generate the analysis.root file. The part of code which causes the problem lies in the .h file and runs as:
std::vector<Double_t> fitPeaks(TH1F * hSpectrumCalibration, std::vector<Double_t> coarsePeakPositions, Int_t margin) {
std::vector<Double_t> precisePeakPositions (coarsePeakPositions.size());
TF1 * f1;
char funcName[10];
for (Int_t i=0; i<coarsePeakPositions.size(); i++) {
sprintf(funcName, "f%d", i);
f1 = new TF1(funcName, "gaus + [3] * TMath::Erf( (x - [1])/sqrt(2)/[2] )/2 + [4]", coarsePeakPositions[i]-margin, coarsePeakPositions[i]+margin);
// set start parameters and parameter limits
f1->SetParameter(0, hSpectrumCalibration->GetMaximum()); // height
f1->SetParameter(1, coarsePeakPositions[i]); // mean
f1->SetParameter(2, 5);
f1->SetParLimits(0, 0, 2 * hSpectrumCalibration->GetMaximum()); // sigma
f1->SetParLimits(1, coarsePeakPositions[i]-margin, coarsePeakPositions[i]+margin);
f1->SetParLimits(2, 0, 100);
hSpectrumCalibration->Fit(f1, "R0+Q"); // "R" = 'use function rage for fitting'; CRUCIAL!
//f1->Draw("SAME"); // draw all fitted function onto the histogram
precisePeakPositions[i] = f1->GetParameter(1);
}
return precisePeakPositions;
}
(How do I know that this causes the problem? When I remove the line in macro01.C where I call the fitPeaks function I can Draw() my histogram as usual)
However the position of the code should be irrelevant, as the error persists when moving the fitPeaks function to macro01.C.
I also uploaded macro01.C, macro01.h for reference.
macro01.C (8.5 KB)
macro01.h (17.2 KB)