Converting a Log to Linear Histogram

Hi all,

I have been trying to convert my log histograms to linear and have been having some difficulty. Once the script is executed, nothing happens. I might be over complicating the script but I have tried the SetLogy() command as well. Any help is appreciated. Thank you :slight_smile:

linear_histogram.C (3.3 KB)

~/carolina/build/8.7MeV_coincidence_gates_labr_labr/gated_coincidences_total_projections/projx$ ./linear_histogram 
Warning in <TFile::Append>: Replacing existing TH1: gate (Potential memory leak).

 *** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:
#0  0x00007f851eeea45a in __GI___wait4 (pid=10602, stat_loc=stat_loc
entry=0x7fffa0aff618, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007f851eeea41b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7fffa0aff618, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007f851ee50bcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007f8520317494 in TUnixSystem::StackTrace() () from /usr/local/lib/
#4  0x00007f8520314795 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/
#5  <signal handler called>
#6  0x0000558cde6e07d2 in DrawLinearHistogram() ()
#7  0x0000558cde6e0c48 in main ()

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#6  0x0000558cde6e07d2 in DrawLinearHistogram() ()
#7  0x0000558cde6e0c48 in main ()

P.S. please use ``` symbols to format your console output

Dear @Xavier_James ,

First off, I just wanted to point out that your code contains many new without the corresponding delete. This is recipe for disaster. Please refrain from using this pattern in your C++ code. Instead of new you should use stack-based variables or std::unique_ptr.

That said, I don’t understand what you are trying to do exactly. Your initial post said

I have been trying to convert my log histograms to linear

But I don’t see this being done in the script. The histogram you retrieve from the file with this line

linearHist = (TH1D*)file->Get("gate");

is called linearHist. So I assume it’s already “linear” and you don’t need to convert it “from log to linear”.

Second, the stack trace you provide in your second post doesn’t tell us a lot, since you are probably not using a ROOT build with debug symbols enabled (and that’s not really the point here), but it may very well be just due to usage of a dangling pointer or use-after-free (again another point in favor of discouraging the use of new in your code).

SetLogy() should be probably called on the canvas, directly after creation

TCanvas c;

But again, I’m not sure that’s what you are trying to do in the first place. Let me know.


1 Like