Differences between arrays

Hi everyone, I’ve an array Calo_Time[n], I’ like to plot the Graph of the diffences between some of them:

I can do it writing, for example:

t->Draw("Calo_Time[9]-Calo_Time[8]");

But I’d like

  1. To store the diffence in a variable,
    I tried

diff=Calo_Time[9]-Calo_Time[8]

but it doesn’t work. Moreover,

  1. I’d like to define 2 variables a,b at the begin of the macro, and to write something like this
float a=9;
float b=8;

diff=Calo_Time[a]-Calo_Time[b]`

How to fix it?


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


  1. t->Draw("Calo_Time[9]-Calo_Time[8]"); will create a histogram filled from the difference of the two variables. That what you want ?

  2. t->Draw(Form("Calo_Time[%d]-Calo_Time[%d]",a,b)); when a and b are int, not float.

Hi cuet, yes, it was what I wanted for the plots…but is it also possible to store the differences in a txt file?

with root 6:

root [0] t->SetScanField(0);
root [1] .> a.txt
t->Scan("x-y");
.>

with root 5:

root [0] t->SetScanField(0);
root [1] t->Scan("x-y"); > a.txt

Hi couet, thank for your reply. By using the code (obviously by changing the variable names)

t->Scan("x-y"); a.txt

I get error, but I found another code, so I wrote:

	lemma->SetScanField(0);
   		((TTreePlayer*)(t->GetPlayer()))->SetScanRedirect(true); 
		((TTreePlayer*)(t->GetPlayer()))->SetScanFileName(mydatavalueouta); 
   	t->Scan(Form("Calo_Time[%d]",a));

and it worked!
Anyway thank you for your interest!

This is wrong with ROOT 5. You missed the “>” character.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.