I have a TGraph2D that looks quite nice with the options myG2D->Draw(“surf fb bb”);. I am making a cut at y=2 on this graph and was hoping to find a 2D equivalent to TLine.
I have tried creating a TF2 that changes value like a delta function at y=2, and I can draw a plane using a combination of TF2::SetNpy(400) and TF2::Draw(lego 0), but the surface does not hide lines that are behind the plane. The plane looks 100% opaque, but is 0% opaque for the drawn lines of the surface, if you know what I mean. The surface is always in front, despite perspective being handled well in other respects. As a more minor issue, even if I SetNpx(1) I get 4 lego columns so the plane has 3 vertical stripes when I would prefer none.
I would really like to have a semi-transparent plane cutting through the surface. Is there a way to accomplish what I’m trying to do?
The following example.cpp illustrates my attempts.
// My attempt to create a flat plane at y = 2
Double_t plane(Double_t *x, Double_t *par){
if (1.98<x[1] && x[1]<2.02) return 1000.;
return 0.;
}
void example(){
// Create a simple 2D function as an example
TF2 *f2 = new TF2("f2","(x-710.)*(x-710.)+y*100.",695.,726.,-0.1,4.);
// Try to create a vertical plane
TF2 *myPlane = new TF2("myPlane",plane,695.,726.,-0.1,4.,0);
myPlane->SetLineColor(1);
myPlane->SetNpx(1); // Try to remove vertical lines from plane (doesn't work)
myPlane->SetNpy(400);// Make sure the plane will not get skipped by y-resolution effects
// Let's try a few combinations
TCanvas *myCanvas1 = new TCanvas("myCanvas1", "myCanvas1",164,187,600,400);
myCanvas1->SetTheta(23.04363);
myCanvas1->SetPhi(-33.92543);
TCanvas *myCanvas2 = new TCanvas("myCanvas2", "myCanvas2",164,187,600,400);
myCanvas2->SetTheta(23.04363);
myCanvas2->SetPhi(-33.92543);
TCanvas *myCanvas3 = new TCanvas("myCanvas3", "myCanvas3",164,187,600,400);
myCanvas3->SetTheta(23.04363);
myCanvas3->SetPhi(-33.92543);
myCanvas1->cd();
f2->Draw("surf fb bb");
myPlane->Draw("lego1 0 same");
myCanvas2->cd();
myPlane->Draw("lego1 0");
f2->Draw("surf fb bb same");
myCanvas3->cd();
f2->Draw("surf fb bb");
myPlane->Draw("lego 0 same");
}
// My attempt to create a flat plane at y = 2
Double_t plane(Double_t *x, Double_t *par){
if (1.98<x[1] && x[1]<2.02) return 1000.;
return 0.;
}
void example(){
// Create a simple 2D function as an example
TF2 *f2 = new TF2("f2","(x-710.)*(x-710.)+y*100.",695.,726.,-0.1,4.);
// Try to create a vertical plane
TF2 *myPlane = new TF2("myPlane",plane,695.,726.,-0.1,4.,0);
myPlane->SetLineColor(1);
myPlane->SetNpy(400);// Make sure the plane will not get skipped by y-resolution effects
myPlane->SetNpx(2);
// Let's try a few combinations
TCanvas *myCanvas1 = new TCanvas("myCanvas1", "myCanvas1",164,187,600,400);
myCanvas1->SetTheta(23.04363);
myCanvas1->SetPhi(-33.92543);
myCanvas1->cd();
f2->Draw("surf fb bb");
myPlane->Draw("lego4 0 same");
myPlane->SetFillColorAlpha(kBlue, 0.05);
myPlane->SetLineColorAlpha(kBlue, 0.);
myCanvas1->Print("myCanvas1.png");
myCanvas1->Print("myCanvas1.pdf");
}