# Converting a Log to Linear Histogram

**URL:** <https://root-forum.cern.ch/t/converting-a-log-to-linear-histogram/55635>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [July 12, 2023, 1:04pm UTC](https://root-forum.cern.ch/t/converting-a-log-to-linear-histogram/55635 "2023-07-12T13:04:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xavier\_James](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xavier_james/32/32932_2.png) [@Xavier\_James](https://root-forum.cern.ch/u/Xavier_James)\
**Post date:** [July 12, 2023, 1:04pm UTC](https://root-forum.cern.ch/t/converting-a-log-to-linear-histogram/55635/1 "2023-07-12T13:04:28Z")

</div>

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 🙂

[linear\_histogram.C](https://root-forum.cern.ch/uploads/short-url/4927pZoITGtFoawj0AJ9d6l1xXS.C) (3.3 KB)

---

<div class="post-metadata">

**Author:** ![Xavier\_James](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xavier_james/32/32932_2.png) [@Xavier\_James](https://root-forum.cern.ch/u/Xavier_James)\
**Post date:** [July 12, 2023, 1:58pm UTC](https://root-forum.cern.ch/t/converting-a-log-to-linear-histogram/55635/2 "2023-07-12T13:58:19Z")

</div>

```auto
~/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/libCore.so
#4 0x00007f8520314795 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/libCore.so
#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 https://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://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.
===========================================================
#6 0x0000558cde6e07d2 in DrawLinearHistogram() ()
#7 0x0000558cde6e0c48 in main ()
===========================================================

```

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

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 13, 2023, 8:54am UTC](https://root-forum.cern.ch/t/converting-a-log-to-linear-histogram/55635/3 "2023-07-13T08:54:22Z")

</div>

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

```auto
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

```auto
TCanvas c;
c.SetLogy();

```

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

Cheers,  
Vincenzo
