Casting Data type of an array

Hi everyone,

I was wondering if someone could help me with a problem i’m having running a ROOT macro that I’ve written.

Basically, the macro reads in a few leafs (which are Ntuples) from a TTree, and then plots one of the Ntuple variables in different bins of another NTuple variable.
It was running fine, but I foolishly declared one of the Ntuple variables (in the source code that makes the NTuples) as an array of double, whereas the others were all arrays of floats. As a result if I try to get my macro to plot something in bins of the double variable, I get a segmentation violation because the memory demands are too high (the ntuple has around 23,000 entries).

What I would like to know is: is there a way to cast the data in the Ntuple from double to float? I tired casting each entry just before it was used but this didn’t help, I guess the segmentation violation is caused by reading in the Ntuple, so I’d like to cast the Ntuple first, and then read it in.

I have attached the ROOT macro (called Luis.C) that I use. I would greatly appreciate any help anyone can give me on this as I need to finish this work soon before I go on holiday!


Laurence Carson
Luis.C (3.58 KB)

I am really not sure of what you tried and how it fails … why is the following not working for you:


Dear Phillipe

I’m not sure I understand what your suggestion is trying to do… FirstHitZ_lab[jcand] already is a double; I tried converting it to float using the static_cast to save memory, but it doesn’t work. I think this is because the memory problems occur when it tries to read in the branch.

I think this problem could be solved if I could tell ROOT at startup to use more memory…

|> root.exe -

Does anyone know if such a command exists?



Hello everyone,

I misdiagnosed the problem… I declared the local variable as FirstHitZ as a float_t, when it should have been double_t… oops. Now the code runs fine.

Thanks and sorry,