I have 2 TGraph2D (gHadron_2D_1 and gHadron_2D_2) , one has a range of 0-1.5 in x-axis and the other has a range of 1.5-4 in x-axis. I want to connect these 2 Graphes. I tried to do this following code but the output is wrong. It doesn’t take the full range of x-axis. Can somebody help me?
Double_t x,y,z;
Int_t nPredefinedPointsHadron = gHadron_2D_2->GetN();
for(Int_t k= nPredefinedPointsHadron; k < gHadron_2D_1->GetN() + nPredefinedPointsHadron; ++k){
gHadron_2D_1->GetPoint(k-nPredefinedPointsHadron,x,y,z);
gHadron_2D_2->SetPoint(k,x,y,z);
cout << "Point: " << k << " m: " << x << " pt: " << y << " yield: " << z << endl;
}
The problem is that gHadron_2D_1 range of points is gonna be from 7000 to 8000.
In my case the gHadron_2D_1 has 7000 points and gHadron_2D_2 1000 points.
I did a cout in the for loop and it shows me only the values from 7000 to 8000.
Can you maybe provide a minimal reproducer along with its textual output? It’s a bit difficult to understand what is it exactly you are doing (and observing)…
@zmomtaz The loop in the source code provided by @yus is adding points from the “gHadron_2D_1” to the “gHadron_2D_2” (so your “cout” shows only the “newly added” values).
int n1 = gHadron_2D_1->GetN();
int n2 = gHadron_2D_l2->GetN();
int n = n1+n2;
auto g = new TGraph2D (n);
double x,y,z;
int k;
for(k=0; k < n1; k++){
gHadron_2D_1->GetPoint(k,x,y,z);
g->SetPoint(k,x,y,z);
or
g->SetPoint(g->GetN(), x, y, z);
}
for(k=0; k < n2; k++){
gHadron_2D_l2->GetPoint(k,x,y,z);
g->SetPoint(k+n1,x,y,z);
or
g->SetPoint(g->GetN(), x, y, z);
}