Passing parameters back into macro or function (or help improving spaghetti code)

Hello Colleagues,
One weak-old Root user here. I’ve a written macro that does a fit to a histogram of the exponential decay of the dose (or intensity) of a photon beam traversing a water target in the presence of a magnetic field. The fit at 0 teslas gives me the parameters of the exponential (offset, amplitude and decay constant). The dose at higher magnetic field strengths will be a fraction of the dose at 0 teslas and I then use my parameters of the 0 tesla fit in the fits of the remaining histograms to obtain that fraction.

I have 2 questions, the first general and the second related to the above problem:

  1. The main macro is called ‘dedao.C.’ Within it there is another macro called ‘dedo.C’. I notice that in order to get ‘dedao.C’ to work, I have to first run ‘dedo.C’ so that the order of my commands at the prompt is:

    root[0] L. dedao.C
    root[1] dedo();
    root[2] dedao();

Otherwise I get the error message “Unknown function: dedo.” This seems odd to me, since there is no objection to the function within my macro. Can someone kindly explain?

  1. How can I improve my code? Ideally, I should be able to pass the parameters I have obtained from my 0 tesla fit into a new function or macro which I can then use to fit the remaining histograms. The only way I can think of how to do this is to write the parameters of the 0 tesla fit to a file which I can then open inside the new macro/function, which seems like a clunky work around. Is there a better way?

I have attached my workman-like code. It’s functional, so it’s really just in the interest of learning that I am reaching out for help.

Regards, (146.7 KB)

Your macro did not compile.
I fixed the mistakes:

dedao.C (4.1 KB)

Thanks so much, Couet. But is there any answer to my above question? Did you find that you have to run ‘dedo.C’ first? By the way, I’m using Root version 5.

Somewhere in the beginning of your “dedao” function, add:
if (!(gROOT->GetFunction("dedo"))) dedo();

Thanks Wile_E_Coyote. That’s exactly what I wanted. I take it then that if I have a function that calls another function, then I always need to add that line with the appropriate function as an argument.