Hi, I’ve a root file (see attachment). It’s a tree having ntuple. I have to plot the Calo_Time and Calo_EnDep values.
I’ve to do this
I choose 2 detectors (for example 8 and 9) and I’ve to plot the Calo_Time differenes between them
Calo_Time[8]-Calo_Time[9]; then I’ve to fit the plot by a gaussian function and to get mean value and sigma. Then I’ve to plot the Calo_EnDep[8] and Calo_EnDep[9] values just for the events that are in the range [mu-3*sigma; mu + 3sigma] where mu and sigma are the fit parameters getted by first plot.

I wrote the macro (see attachment) but I get error due to the "if " lines.

For next time, please state the ROOT version you use, and the actual error message you get (copy and paste, ideally with some lines before and after).

I suspect that the error reported is here:

if ("Calo_Time[%d]-Calo_Time[%d]",a,b))> (p1-3*p2) && (Form("Calo_Time[%d]-Calo_Time[%d]",a,b)) < (p1+3*p2)

This is not valid C++.

I don’t understand the calls to Form, or why this should be a string. I suspect that you meant to write Calo_Time[a]-Calo_Time[b]> p1-3*p2 && Calo_Time[a]-Calo_Time[b] < p1+3*p2?

Similarly, t->Draw(Form("Calo_Time[%d]-Calo_Time[%d]",a,b)); makes very little sense: you fill a histogram with a string, where I suspect you want to fill it with a value (the difference between the two Calo_Time values). This would then be t->Draw(Calo_Time[a]-Calo_Time[b]);

In general, you might benefit from some help from your advisor; this would allow you to make progress quicker than with this forum.

Yes, I want to write Calo_Time[a]-Calo_Time[b]> p1-3*p2 && Calo_Time[a]-Calo_Time[b] < p1+3*p2?, I used the call to Form because of I defined the variables a,b at the beginning of the macro so that I can modify them quickly (this because I also will study Calo_Time[10]-Calo_Time[15], etc. etc]. The Form function works fine in the row t->Draw(Form("Calo_Time[%d]-Calo_Time[%d]",a,b)); (cuet wrote me this code here Differences between arrays)

I just saw that the error was given because of I forgot the Form here if ("Calo_Time[%d]-Calo_Time[%d]",a,b))> (p1-3*p2) && (Form("Calo_Time[%d]-Calo_Time[%d]",a,b)) < (p1+3*p2)

now, by replacing this line with

if (Form("Calo_Time[%d]-Calo_Time[%d]",a,b))> (p1-3*p2) && (Form("Calo_Time[%d]-Calo_Time[%d]",a,b)) < (p1+3*p2)

I don’t get the error (In the attachment the macro after the bug fixed) calo.cpp (6.2 KB)

Even if I don’t get the error, I don’t get the right results, because of the total events are 6119 and I get 6119 also by using the cut selection (I should get a lower number of events because of I reject the events out of the range )

Hi Wile, thanks for your reply. By following your message, I replaced
this line //if (Form("Calo_Time[%d]-Calo_Time[%d]",a,b))> (p1-3*p2) && (Form("Calo_Time[%d]-Calo_Time[%d]",a,b)) < (p1+3*p2)
with

if ( ((Calo_Time[8]-Calo_Time[9]) > (p1-3.*p2)) && ((Calo_Time[8]-Calo_Time[9]) < (p1+3.*p2)) )