#include "Riostream.h"
#include "TROOT.h"
#include "TClass.h"
#include "TGraph2DErrors.h"
#include "TMath.h"
#include "TPolyMarker.h"
#include "TVirtualPad.h"
#include "TVirtualFitter.h"
#include "THLimitsFinder.h"
#include "TStyle.h"
ClassImp(TGraph2DErrors)
TGraph2DErrors::TGraph2DErrors(): TGraph2D()
{
fEX = 0;
fEY = 0;
fEZ = 0;
}
TGraph2DErrors::TGraph2DErrors(Int_t n)
: TGraph2D(n)
{
if (n <= 0) {
Error("TGraph2DErrors", "Invalid number of points (%d)", n);
return;
}
fEX = new Double_t[n];
fEY = new Double_t[n];
fEZ = new Double_t[n];
for (Int_t i=0;i<n;i++) {
fEX[i] = 0;
fEY[i] = 0;
fEZ[i] = 0;
}
}
TGraph2DErrors::TGraph2DErrors(Int_t n, Double_t *x, Double_t *y, Double_t *z,
Double_t *ex, Double_t *ey, Double_t *ez, Option_t *)
:TGraph2D(n, x, y, z)
{
if (n <= 0) {
Error("TGraphErrors", "Invalid number of points (%d)", n);
return;
}
fEX = new Double_t[n];
fEY = new Double_t[n];
fEZ = new Double_t[n];
for (Int_t i=0;i<n;i++) {
if (ex) fEX[i] = ex[i];
else fEX[i] = 0;
if (ey) fEY[i] = ey[i];
else fEY[i] = 0;
if (ez) fEZ[i] = ez[i];
else fEZ[i] = 0;
}
}
TGraph2DErrors::~TGraph2DErrors()
{
delete [] fEX;
delete [] fEY;
delete [] fEZ;
}
TGraph2DErrors::TGraph2DErrors(const TGraph2DErrors &g)
: TGraph2D(g), fEX(0), fEY(0), fEZ(0)
{
if (fSize > 0) {
fEX = new Double_t[fSize];
fEY = new Double_t[fSize];
fEZ = new Double_t[fSize];
for (Int_t n = 0; n < fSize; n++) {
fEX[n] = g.fEX[n];
fEY[n] = g.fEY[n];
fEZ[n] = g.fEZ[n];
}
}
}
TGraph2DErrors & TGraph2DErrors::operator=(const TGraph2DErrors &g)
{
if (this == &g) return *this;
this->TGraph2D::operator=(static_cast<const TGraph2D&>(g) );
if (fEX) delete [] fEX;
if (fEY) delete [] fEY;
if (fEZ) delete [] fEZ;
fEX = (fSize > 0) ? new Double_t[fSize] : 0;
fEY = (fSize > 0) ? new Double_t[fSize] : 0;
fEZ = (fSize > 0) ? new Double_t[fSize] : 0;
for (Int_t n = 0; n < fSize; n++) {
fEX[n] = g.fEX[n];
fEY[n] = g.fEY[n];
fEZ[n] = g.fEZ[n];
}
return *this;
}
Double_t TGraph2DErrors::GetErrorX(Int_t i) const
{
if (i < 0 || i >= fNpoints) return -1;
if (fEX) return fEX[i];
return -1;
}
Double_t TGraph2DErrors::GetErrorY(Int_t i) const
{
if (i < 0 || i >= fNpoints) return -1;
if (fEY) return fEY[i];
return -1;
}
Double_t TGraph2DErrors::GetErrorZ(Int_t i) const
{
if (i < 0 || i >= fNpoints) return -1;
if (fEZ) return fEZ[i];
return -1;
}
Double_t TGraph2DErrors::GetXmaxE() const
{
Double_t v = fX[0]+fEX[0];
for (Int_t i=1; i<fNpoints; i++) if (fX[i]+fEX[i]>v) v=fX[i]+fEX[i];
return v;
}
Double_t TGraph2DErrors::GetXminE() const
{
Double_t v = fX[0]-fEX[0];
for (Int_t i=1; i<fNpoints; i++) if (fX[i]-fEX[i]<v) v=fX[i]-fEX[i];
return v;
}
Double_t TGraph2DErrors::GetYmaxE() const
{
Double_t v = fY[0]+fEY[0];
for (Int_t i=1; i<fNpoints; i++) if (fY[i]+fEY[i]>v) v=fY[i]+fEY[i];
return v;
}
Double_t TGraph2DErrors::GetYminE() const
{
Double_t v = fY[0]+fEY[0];
for (Int_t i=1; i<fNpoints; i++) if (fY[i]-fEY[i]<v) v=fY[i]-fEY[i];
return v;
}
Double_t TGraph2DErrors::GetZmaxE() const
{
Double_t v = fZ[0]+fEZ[0];
for (Int_t i=1; i<fNpoints; i++) if (fZ[i]+fEZ[i]>v) v=fZ[i]+fEZ[i];
return v;
}
Double_t TGraph2DErrors::GetZminE() const
{
Double_t v = fZ[0]+fEZ[0];
for (Int_t i=1; i<fNpoints; i++) if (fZ[i]-fEZ[i]<v) v=fZ[i]-fEZ[i];
return v;
}
void TGraph2DErrors::Set(Int_t n)
{
if (n < 0) n = 0;
if (n == fNpoints) return;
if (n > fNpoints) SetPointError(n,0,0,0);
fNpoints = n;
}
void TGraph2DErrors::SetPoint(Int_t i, Double_t x, Double_t y, Double_t z)
{
if (i < 0) return;
if (i >= fNpoints) {
Double_t *savex = new Double_t[i+1];
Double_t *savey = new Double_t[i+1];
Double_t *savez = new Double_t[i+1];
Double_t *saveex = new Double_t[i+1];
Double_t *saveey = new Double_t[i+1];
Double_t *saveez = new Double_t[i+1];
if (fNpoints > 0) {
memcpy(savex, fX, fNpoints*sizeof(Double_t));
memcpy(savey, fY, fNpoints*sizeof(Double_t));
memcpy(savez, fZ, fNpoints*sizeof(Double_t));
memcpy(saveex,fEX,fNpoints*sizeof(Double_t));
memcpy(saveey,fEY,fNpoints*sizeof(Double_t));
memcpy(saveez,fEZ,fNpoints*sizeof(Double_t));
}
if (fX) delete [] fX;
if (fY) delete [] fY;
if (fZ) delete [] fZ;
if (fEX) delete [] fEX;
if (fEY) delete [] fEY;
if (fEZ) delete [] fEZ;
fX = savex;
fY = savey;
fZ = savez;
fEX = saveex;
fEY = saveey;
fEZ = saveez;
fNpoints = i+1;
}
fX[i] = x;
fY[i] = y;
fZ[i] = z;
}
void TGraph2DErrors::SetPointError(Int_t i, Double_t ex, Double_t ey, Double_t ez)
{
if (i < 0) return;
if (i >= fNpoints) {
TGraph2DErrors::SetPoint(i,0,0,0);
}
fEX[i] = ex;
fEY[i] = ey;
fEZ[i] = ez;
}
void TGraph2DErrors::Streamer(TBuffer &b)
{
if (b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = b.ReadVersion(&R__s, &R__c);
b.ReadClassBuffer(TGraph2DErrors::Class(), this, R__v, R__s, R__c);
} else {
b.WriteClassBuffer(TGraph2DErrors::Class(),this);
}
}