CXArrow.cpp 2.4 KB
Newer Older
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1
#include "CXArrow.h"
2 3 4 5 6 7

#include "TLatex.h"
#include "TBox.h"
#include "TH1.h"
#include "TVirtualPad.h"

Jérémie Dudouet's avatar
Jérémie Dudouet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "CXFit.h"

CXArrow::CXArrow(CXFit *fit, Double_t E,Double_t y1 ,Double_t y2,Float_t arrowsize,Option_t *option) : TArrow(E, y1, E, y2, arrowsize, option)
{
    fFit = fit;
}

CXArrow::~CXArrow()
{
}

void CXArrow::SetEnergy(Float_t E)
{
    SetX1(E);
    SetX2(E);
}

void CXArrow::Set(Double_t X, Double_t Y1, Double_t Y2)
{
    fX1=X;
    fX2=X ;
    fY1=Y1;
    fY2=Y2;
}

void CXArrow::RemoveArrow()
{
    if(fFit)
        fFit->RemoveArrow(this);
}

void CXArrow::RemoveFit()
{
    if(fFit)
        delete fFit;
}

Int_t CXArrow::Compare(const TObject *obj) const
{
    if(obj->InheritsFrom(CXArrow::Class())) {
        CXArrow *arr = (CXArrow*)obj;
        return (GetEnergy() > arr->GetEnergy()) ? 1 : -1;
    }
    else return 0;
}

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
void CXArrow::SetText(TH1 *hist, TString text, TString tooltip)
{
    Int_t XMinbin = hist->GetXaxis()->GetFirst();
    Int_t XMaxbin = hist->GetXaxis()->GetLast();
    Int_t XMin = hist->GetBinLowEdge(XMinbin);
    Int_t XMax = hist->GetBinLowEdge(XMaxbin);

    if(fBox) delete fBox;

    fBox = new CXArrowBox(this);
    fBox->SetX1(fX1-(XMax-XMin)/300.);
    fBox->SetX2(fX1+(XMax-XMin)/300.);
    fBox->SetY1(fY1);
    fBox->SetY2(fY2);

    fBox->SetFillStyle(0);
    fBox->SetFillColor(0);
    fBox->SetLineWidth(0);
    fBox->SetLineColor(0);
    fBox->SetLineStyle(3);

    if(fLatex) delete fLatex;
    fLatex = new TLatex(fX1,fY2,text);
    fLatex->SetTextAngle(90);
    fLatex->SetTextFont(132);
    fLatex->SetTextSize(fTextSize);
    fLatex->SetTextColor(hist->GetLineColor());
    fLatex->SetBit(TObject::kCannotPick);
    fLatex->Draw();

    fBox->SetToolTipText(tooltip.Data(),500);
    fBox->Draw();

    Float_t MaxGlob = hist->GetMaximum();
    Float_t Y = fLatex->GetY()-(gPad->AbsPixeltoY(fLatex->GetBBox().fY+fLatex->GetBBox().fWidth)-gPad->AbsPixeltoY(fLatex->GetBBox().fY));
    if(gPad->GetUymax()< Y)
        hist->GetYaxis()->SetRangeUser(gPad->GetUymin(),Y+MaxGlob/50.);
}

93
void CXArrow::ClearPad(TVirtualPad *pad, bool refresh)
94 95 96 97 98 99 100
{
    if(pad==nullptr) pad = gPad;

    pad->GetListOfPrimitives()->Remove(fLatex);
    pad->GetListOfPrimitives()->Remove(fBox);
    pad->GetListOfPrimitives()->Remove(this);

101 102 103 104
    if(refresh) {
        pad->Modified();
        pad->Update();
    }
105 106 107 108 109 110 111 112 113
}


void CXArrow::Paint(Option_t *option)
{
    TArrow::Paint(option);
}


Jérémie Dudouet's avatar
Jérémie Dudouet committed
114
ClassImp(CXArrow);