Error: illegal type cast (2) using ROOT macro

Dear ROOT forum,

I am running a piece of Root macro to help me set limits using HypoTestInverter Class. My code is structured like so:

struct results{
float lLimit_1s_fc;
float lLimit_2s_fc;
float uLimit_1s_fc;
float uLimit_2s_fc;
float median_fc;
float observed95ulimit_fc;
float observed95_ulimit_error;
} current_bin;

void upper_tut4(int bin_number, int mult_slice){

struct results current_bin=upperlimit_tut1(obs,bk, syserror, bin_number, mult_slice);


struct results upperlimit_tut1(float nObs, float bVal, float bk_sys,int input_multi, int input_bin){

[code to get the limits based on inputs to function…]

struct results bin={band1sigDown,band2sigDown,band1sigUp,band2sigUp,bandMedian,upperlimit95,upperlimit95_error};

return bin;

However I find that when the code get to the line that returns the bin I get the error message:

Error: illegal type cast (2) upper_tut4.C:668:
*** Interpreter error recovered *

I can’t figure out what the problem is. The strangest thing is that this error only occurs sometimes. To be specific I am running HypoTestInverter to give me confidence intervals and it only occurs if I rebuild the toy intervals using something like:

  SamplingDistribution * limDist = calc.GetUpperLimitDistribution(true,mNToyToRebuild);

Therefore it is not easy for me to duplicate the error as rebuilding toys is a very time consuming process. If I rebuild only 1 or 2 toys (setting mNToyToRebuild=2) this error does not occur it only occurs if I set NToyToRebuild to 20 or greater).

Does anyone have ideas as to what’s going on?

Thank You,



I would recommend that as a first debugging step, you try compiling your script with ACLiC. I.e. replace .L script.C with .L script.C+ (which may require that you update your script to correct any C++ syntax error that CINT might have been lenient on). If you still see problem, I then recommend that you run your example using valgrind ( by running valgrind root.exe … )