#include "PadCoordinatesConversion.h" #include #include #include #include #include #define AssertRel(x, y) \ { \ const bool ok = TMath::AreEqualRel(x, y, 1e-7); \ if (!ok) \ cout << (x) << " not close to " << (y) << endl; \ } \ assert(TMath::AreEqualRel(x, y, 1e-7)) #define AssertAbs(x, y) \ { \ const bool ok = TMath::AreEqualAbs(x, y, 1e-10); \ if (!ok) \ cout << (x) << " not close to " << (y) << endl; \ } \ assert(TMath::AreEqualAbs(x, y, 1e-10)) using namespace phi; using namespace std; int main() { TCanvas* can = new TCanvas("can", "can", 1000, 600); can->SetFillStyle(1001); can->SetFillColor(kBlue - 7); const double xmin = -0.03; const double xmax = 0.012; const double ymin = 0.001; const double ymax = 20.0; TH2* h1 = new TH2D("", "", 10, xmin, xmax, 10, ymin, ymax); TPad* p3 = new TPad("", "", 0.2, 0.1, 0.7, 0.6); const double l = 0.06; const double r = 0.05; const double t = 0.12; const double b = 0.11; p3->SetMargin(l, r, b, t); p3->SetLogy(); p3->Draw(); p3->cd(); h1->Draw(); AssertRel(XtoNDC(xmin), l); AssertRel(XtoNDC(xmax), 1 - r); AssertRel(YtoNDC(ymin), b); AssertRel(YtoNDC(ymax), 1 - t); AssertRel(NDCtoX(l), xmin); AssertRel(NDCtoX(1 - r), xmax); AssertRel(NDCtoY(b), ymin); AssertRel(NDCtoY(1 - t), ymax); const double w = GetGPadWidth(); const double h = GetGPadHeight(); AssertRel(NDCtoPixelX(0), 0); AssertRel(NDCtoPixelX(1), w); AssertRel(NDCtoPixelY(0), h); AssertRel(NDCtoPixelY(1), 0); AssertRel(PixelXtoNDC(0), 0); AssertRel(PixelXtoNDC(w), 1); AssertRel(PixelYtoNDC(h), 0); AssertRel(PixelYtoNDC(0), 1); AssertRel(PixelToX(0), gPad->PixeltoX(0)); AssertRel(PixelToX(w), gPad->PixeltoX(w + 1)); // why +1 neede?? AssertRel(PixelToX(XtoPixel(xmin)), xmin); AssertRel(PixelToX(XtoPixel(xmax)), xmax); AssertRel(XtoPixel(PixelToX(w)), w); AssertAbs(XtoPixel(PixelToX(0)), 0); p3->SetLogy(0); // below test fails for logy ?! suspect something wrong with gPad->PixeltoY() // Furthermore gPad->PixeltoY() (as is documented in ROOT Users Guide) inverts // pixel Y axis... AssertRel(PixelToY(0), gPad->PixeltoY(-h)); AssertRel(PixelToY(h), gPad->PixeltoY(0)); AssertRel(PixelToY(YtoPixel(ymin)), ymin); AssertRel(PixelToY(YtoPixel(ymax)), ymax); AssertRel(YtoPixel(PixelToY(h)), h); AssertAbs(YtoPixel(PixelToY(0)), 0); cout << "All tests passed" << endl; return 0; }