It would be best to make sure a short mention of the issue is on the TCutG page, it could link to the more extensive example on TGraphPainter.
Here is an improved example showing the affect of interpolating the cut. The example is becoming a bit long.
{
//Create some data
TH2D *h = new TH2D("h","",100,1,10,100,1,10);
h->SetStats(false);
for (int i=0;i<5000;i++) {
double rand = gRandom->Gaus(10,5);
h->Fill(rand, 1.15 * exp(0.3 * rand));
}
//Create a cut (this could be done in the gui).
TCutG* cut = new TCutG("cut", 5);
cut->SetPoint(0, 2, 2.5);
cut->SetPoint(1, 5.9, 7.18);
cut->SetPoint(2, 6.6, 7.18);
cut->SetPoint(3, 2.7, 2.5);
cut->SetPoint(4, 2, 2.5);
cut->SetLineStyle(2);
cut->SetLineColor(kRed);
//Create a new interpolated cut, to compensate for log plotting.
TCutG* interpolatedCut = new TCutG("cut2");
interpolatedCut->SetLineColor(kBlue);
interpolatedCut->SetLineStyle(3);
const int numSteps = 100; //Number of interpolation steps between each point.
//Loop over points in original cut
for (int i=0;i<cut->GetN() - 1;i++) {
//Compute the linear interpolation
double slope = (cut->GetY()[i+1] - cut->GetY()[i]) /
(cut->GetX()[i+1] - cut->GetX()[i]);
double intercept = cut->GetY()[i] - slope * cut->GetX()[i];
//Set a new point for each interpolation step
// (should do this in logarithmic steps)
double x = cut->GetX()[i];
double stepSize = (cut->GetX()[i+1] - x) / numSteps;
for (int j=0;j<numSteps;j++) {
double y = slope * x + intercept;
interpolatedCut->SetPoint(numSteps * i + j, x, y);
x += stepSize;
}
}
//Include final point.
interpolatedCut->SetPoint(interpolatedCut->GetN(),
cut->GetX()[cut->GetN()-1], cut->GetY()[cut->GetN()-1]);
TCanvas *c = new TCanvas("c", "C");
c->DivideSquare(4);
//Plot all data in log space.
c->cd(1)->SetLogy();
h->Draw("");
cut->Draw("SAME");
interpolatedCut->Draw("SAME");
//Plot selected data in log space.
c->cd(2)->SetLogy();
h->Draw("[cut]");
cut->Draw("SAME");
interpolatedCut->Draw("SAME");
//Plot all data in lin space.
c->cd(3);
h->Draw("");
cut->Draw("SAME");
interpolatedCut->Draw("SAME");
//Plot selected data in lin space.
c->cd(4);
h->Draw("[cut]");
cut->Draw("SAME");
interpolatedCut->Draw("SAME");
}
