#include #include #include "EllipticalCut.h" ClassImp(EllipticalCut); #ifndef SQR_FUNC #define SQR_FUNC 1 Double_t sqr(Double_t x) { return x*x; } #endif Int_t EllipticalCut::fMaxNpoint2d = 3; Double_t *EllipticalCut::fPoint2d[2] = {0,0}; Int_t EllipticalCut::fNpoint2d = 0; TCanvas *EllipticalCut::fCanvas = 0; EllipticalCut::EllipticalCut() { if (fPoint2d[0] == 0) { fPoint2d[0] = (Double_t *) new Double_t[fMaxNpoint2d]; fPoint2d[1] = (Double_t *) new Double_t[fMaxNpoint2d]; } SetFillStyle(0); SetLineWidth(3); } EllipticalCut::EllipticalCut(Double_t x0, Double_t y0, Double_t amajor, Double_t aminor, Double_t theta) : TEllipse(x0,y0,amajor,aminor,0,360,theta) { if (fPoint2d[0] == 0) { fPoint2d[0] = (Double_t *) new Double_t[fMaxNpoint2d]; fPoint2d[1] = (Double_t *) new Double_t[fMaxNpoint2d]; } SetFillStyle(0); SetLineWidth(3); } void EllipticalCut::Pick(TCanvas *c) { fNpoint2d = 0; fCanvas = c; c->DeleteExec("EllipticalCut::PointPicker"); c->AddExec("EllipticalCut::PointPicker","EllipticalCut::PointPicker();"); std::cout << "Now pick the center of the ellipse, " << "followed by intercepts with the major and minor axes." << std::endl; } void EllipticalCut::Print(const Option_t *option) const { std::cout << "The points were:" << std::endl; for (int i=0; iGetSelected(); if (!select) { return; } if (!select->InheritsFrom("TH2")) { return; } if (fCanvas->GetEvent() != 1) { return; } if (fNpoint2d == fMaxNpoint2d) { return; } int px = fCanvas->GetEventX(); int py = fCanvas->GetEventY(); fPoint2d[0][fNpoint2d] = fCanvas->AbsPixeltoX(px); fPoint2d[1][fNpoint2d] = fCanvas->AbsPixeltoY(py); std::cout << "EllipticalCut::PointPicker - " << ++fNpoint2d << " points selected." << std::endl; } void EllipticalCut::Set(Double_t x0, Double_t y0, Double_t amajor, Double_t aminor, Double_t theta) { SetX1(x0); SetY1(y0); SetR1(amajor); SetR2(aminor); SetTheta(theta); } void EllipticalCut::Set() { if (fNpoint2d < 3) { std::cerr << "Error from EllipticalCut::Set() - " << "insufficient number of points selected, " << "must be at least 3." << std::endl; return; } SetX1(fPoint2d[0][0]); SetY1(fPoint2d[1][0]); SetR1(sqrt(sqr(fPoint2d[0][1]-fPoint2d[0][0])+sqr(fPoint2d[1][1]-fPoint2d[1][0]))); SetR2(sqrt(sqr(fPoint2d[0][2]-fPoint2d[0][0])+sqr(fPoint2d[1][2]-fPoint2d[1][0]))); SetTheta(atan2(fPoint2d[1][1]-fPoint2d[1][0],fPoint2d[0][1]-fPoint2d[0][0])*180/TMath::Pi()); } Double_t EllipticalCut::Dist(Double_t x, Double_t y) const { x -= GetX1(); y -= GetY1(); Double_t theta = GetTheta()*TMath::Pi()/180; Double_t cost = cos(theta); Double_t sint = sin(theta); Double_t u = x*cost+y*sint; Double_t v = y*cost-x*sint; return sqrt(sqr(u/GetR1())+sqr(v/GetR2())); } void EllipticalCut::Draw(const Option_t *option) { DrawEllipse(GetX1(),GetY1(),GetR1(),GetR2(),0,360,GetTheta()); } void EllipticalCut::Streamer(TBuffer &b) { TEllipse::Streamer(b); }