Substract a fixed quantity from Array

Hi Everyone,

This is more a CPP related topic. In my TTree I have a variable in which I need to perform a translation (i.e to subtract the same \DeltaX from each element of the array) to plot a TGraph. Is there any way to do it whitout going though each element of the array?

If your variable is of a standard container type, you can take a look at std::transform. Otherwise not really, but

for(auto &e : arr)
  e -= 3;

is not too bad if you ask me :slight_smile:

Cheers,
Enrico

1 Like

I realized when data is coming from a TTree. I can use TTree::Draw() to perform the operation.

Double_t dx = 1.2;
Int_t n = fTree->Draw(Form("X - %f:Y",dx),"x>0","goff");
Double_t *x = tr1->GetV1();
Double_t *y = tr1->GetV2();
TGraph *gr0a = new TGraph(n,x,y);
gr0a->Draw("al*")

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