208 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
209 TAttMarker(), fNpoints(0)
226 fFunctions =
new TList;
234 TGraph2D::TGraph2D(Int_t n, Int_t *x, Int_t *y, Int_t *z)
235 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
236 TAttMarker(), fNpoints(n)
241 for (Int_t i = 0; i < fNpoints; ++i) {
242 fX[i] = (Double_t)x[i];
243 fY[i] = (Double_t)y[i];
244 fZ[i] = (Double_t)z[i];
252 TGraph2D::TGraph2D(Int_t n, Float_t *x, Float_t *y, Float_t *z)
253 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
254 TAttMarker(), fNpoints(n)
259 for (Int_t i = 0; i < fNpoints; ++i) {
270 TGraph2D::TGraph2D(Int_t n, Double_t *x, Double_t *y, Double_t *z)
271 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
272 TAttMarker(), fNpoints(n)
277 for (Int_t i = 0; i < fNpoints; ++i) {
290 TGraph2D::TGraph2D(TH2 *h2)
291 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
292 TAttMarker(), fNpoints(0)
294 Build(h2->GetNbinsX()*h2->GetNbinsY());
296 TString gname =
"Graph2D_from_" + TString(h2->GetName());
299 SetTitle(h2->GetTitle());
303 TAxis *xaxis = h2->GetXaxis();
304 TAxis *yaxis = h2->GetYaxis();
305 Int_t xfirst = xaxis->GetFirst();
306 Int_t xlast = xaxis->GetLast();
307 Int_t yfirst = yaxis->GetFirst();
308 Int_t ylast = yaxis->GetLast();
314 for (Int_t i = xfirst; i <= xlast; i++) {
315 for (Int_t j = yfirst; j <= ylast; j++) {
316 x = xaxis->GetBinCenter(i);
317 y = yaxis->GetBinCenter(j);
318 z = h2->GetBinContent(i, j);
319 Double_t ez = h2->GetBinError(i, j);
320 if (z != 0. || ez != 0) {
321 SetPoint(k, x, y, z);
337 TGraph2D::TGraph2D(
const char *name,
const char *title,
338 Int_t n, Double_t *x, Double_t *y, Double_t *z)
339 : TNamed(name, title), TAttLine(1, 1, 1), TAttFill(0, 1001),
340 TAttMarker(), fNpoints(n)
345 for (Int_t i = 0; i < fNpoints; ++i) {
357 TGraph2D::TGraph2D(Int_t n)
358 : TNamed(
"Graph2D",
"Graph2D"), TAttLine(1, 1, 1), TAttFill(0, 1001),
359 TAttMarker(), fNpoints(n)
362 for (Int_t i = 0; i < fNpoints; i++) {
379 TGraph2D::TGraph2D(
const char *filename,
const char *format, Option_t *option)
380 : TNamed(
"Graph2D", filename), TAttLine(1, 1, 1), TAttFill(0, 1001),
381 TAttMarker(), fNpoints(0)
384 TString fname = filename;
385 gSystem->ExpandPathName(fname);
387 std::ifstream infile(fname.Data());
388 if (!infile.good()) {
390 Error(
"TGraph2D",
"Cannot open file: %s, TGraph2D is Zombie", filename);
398 if (strcmp(option,
"") == 0) {
400 while (std::getline(infile, line,
'\n')) {
401 if (3 != sscanf(line.c_str(), format, &x, &y, &z)) {
404 SetPoint(np, x, y, z);
411 TString format_ = TString(format) ;
412 format_.ReplaceAll(
" ",
"") ;
413 format_.ReplaceAll(
"\t",
"") ;
414 format_.ReplaceAll(
"lg",
"") ;
415 format_.ReplaceAll(
"s",
"") ;
416 format_.ReplaceAll(
"%*",
"0") ;
417 format_.ReplaceAll(
"%",
"1") ;
418 if (!format_.IsDigit()) {
419 Error(
"TGraph2D",
"Incorrect input format! Allowed format tags are {\"%%lg\",\"%%*lg\" or \"%%*s\"}");
422 Int_t ntokens = format_.Length() ;
424 Error(
"TGraph2D",
"Incorrect input format! Only %d tag(s) in format whereas 3 \"%%lg\" tags are expected!", ntokens);
427 Int_t ntokensToBeSaved = 0 ;
428 Bool_t * isTokenToBeSaved =
new Bool_t [ntokens] ;
429 for (Int_t idx = 0; idx < ntokens; idx++) {
430 isTokenToBeSaved[idx] = TString::Format(
"%c", format_[idx]).Atoi() ;
431 if (isTokenToBeSaved[idx] == 1) {
435 if (ntokens >= 3 && ntokensToBeSaved != 3) {
436 Error(
"TGraph2D",
"Incorrect input format! There are %d \"%%lg\" tag(s) in format whereas 3 and only 3 are expected!", ntokensToBeSaved);
437 delete [] isTokenToBeSaved ;
442 Bool_t isLineToBeSkipped = kFALSE ;
443 char * token = NULL ;
444 TString token_str =
"" ;
445 Int_t token_idx = 0 ;
446 Double_t * value =
new Double_t [3] ;
447 Int_t value_idx = 0 ;
451 while (std::getline(infile, line,
'\n')) {
453 if (line[line.size() - 1] == char(13)) {
454 line.erase(line.end() - 1, line.end()) ;
456 token = R__STRTOK_R(const_cast<char*>(line.c_str()), option, &rest);
457 while (token != NULL && value_idx < 3) {
458 if (isTokenToBeSaved[token_idx]) {
459 token_str = TString(token) ;
460 token_str.ReplaceAll(
"\t",
"") ;
461 if (!token_str.IsFloat()) {
462 isLineToBeSkipped = kTRUE ;
465 value[value_idx] = token_str.Atof() ;
469 token = R__STRTOK_R(NULL, option, &rest);
472 if (!isLineToBeSkipped && value_idx == 3) {
476 SetPoint(np, x, y, z) ;
480 isLineToBeSkipped = kFALSE ;
487 delete [] isTokenToBeSaved ;
499 TGraph2D::TGraph2D(
const TGraph2D &g)
500 : TNamed(g), TAttLine(g), TAttFill(g), TAttMarker(g),
502 fHistogram(0), fDirectory(0), fPainter(0)
504 fFunctions =
new TList();
510 if (TH1::AddDirectoryStatus()) {
511 fDirectory = gDirectory;
514 fDirectory->Append(
this);
525 TGraph2D::~TGraph2D()
534 TGraph2D& TGraph2D::operator=(
const TGraph2D &g)
536 if (
this == &g)
return *
this;
539 if (fX)
delete [] fX;
540 if (fY)
delete [] fY;
541 if (fZ)
delete [] fZ;
542 if (fHistogram && !fUserHisto) {
544 fHistogram =
nullptr;
548 fNpoints = g.fNpoints;
551 fMaxIter = g.fMaxIter;
553 fX = (fSize > 0) ?
new Double_t[fSize] : 0;
554 fY = (fSize > 0) ?
new Double_t[fSize] : 0;
555 fZ = (fSize > 0) ?
new Double_t[fSize] : 0;
556 fMinimum = g.fMinimum;
557 fMaximum = g.fMaximum;
560 fUserHisto = g.fUserHisto;
562 fHistogram = (fUserHisto ) ? g.fHistogram :
new TH2D(*g.fHistogram);
567 for (Int_t n = 0; n < fSize; n++) {
579 void TGraph2D::Build(Int_t n)
582 Error(
"TGraph2D",
"Invalid number of points (%d)", n);
595 fX =
new Double_t[fSize];
596 fY =
new Double_t[fSize];
597 fZ =
new Double_t[fSize];
600 fFunctions =
new TList;
604 if (TH1::AddDirectoryStatus()) {
605 fDirectory = gDirectory;
607 fDirectory->Append(
this, kTRUE);
616 void TGraph2D::Browse(TBrowser *)
626 void TGraph2D::Clear(Option_t * )
628 if (fX)
delete [] fX;
630 if (fY)
delete [] fY;
632 if (fZ)
delete [] fZ;
634 fSize = fNpoints = 0;
635 if (fHistogram && !fUserHisto) {
637 fHistogram =
nullptr;
641 fFunctions->SetBit(kInvalidObject);
642 fFunctions->Delete();
647 fDirectory->Remove(
this);
660 void TGraph2D::DirectoryAutoAdd(TDirectory *dir)
662 Bool_t addStatus = TH1::AddDirectoryStatus();
666 ResetBit(kCanDelete);
675 Int_t TGraph2D::DistancetoPrimitive(Int_t px, Int_t py)
677 Int_t distance = 9999;
678 if (fHistogram) distance = fHistogram->DistancetoPrimitive(px, py);
707 void TGraph2D::Draw(Option_t *option)
709 TString opt = option;
712 if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
713 if (!opt.Contains(
"same")) {
716 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(
this);
720 AppendPad(opt.Data());
727 void TGraph2D::ExecuteEvent(Int_t event, Int_t px, Int_t py)
729 if (fHistogram) fHistogram->ExecuteEvent(event, px, py);
736 TObject *TGraph2D::FindObject(
const char *name)
const
738 if (fFunctions)
return fFunctions->FindObject(name);
746 TObject *TGraph2D::FindObject(
const TObject *obj)
const
748 if (fFunctions)
return fFunctions->FindObject(obj);
760 TFitResultPtr TGraph2D::Fit(
const char *fname, Option_t *option, Option_t *)
764 linear = (
char*)strstr(fname,
"++");
767 TF2 f2(fname, fname);
768 return Fit(&f2, option,
"");
770 TF2 * f2 = (TF2*)gROOT->GetFunction(fname);
772 Printf(
"Unknown function: %s", fname);
775 return Fit(f2, option,
"");
915 TFitResultPtr TGraph2D::Fit(TF2 *f2, Option_t *option, Option_t *)
919 Option_t *goption =
"";
920 ROOT::Fit::FitOptionsMake(ROOT::Fit::kGraph, option, fitOption);
923 ROOT::Fit::DataRange range(2);
924 ROOT::Math::MinimizerOptions minOption;
925 return ROOT::Fit::FitObject(
this, f2 , fitOption , minOption, goption, range);
934 void TGraph2D::FitPanel()
937 gROOT->MakeDefCanvas();
940 Error(
"FitPanel",
"Unable to create a default canvas");
945 TPluginHandler *handler = gROOT->GetPluginManager()->FindHandler(
"TFitEditor");
946 if (handler && handler->LoadPlugin() != -1) {
947 if (handler->ExecPlugin(2, gPad,
this) == 0)
948 Error(
"FitPanel",
"Unable to crate the FitPanel");
950 Error(
"FitPanel",
"Unable to find the FitPanel plug-in");
958 TAxis *TGraph2D::GetXaxis()
const
960 TH1 *h = ((TGraph2D*)
this)->GetHistogram(
"empty");
962 return h->GetXaxis();
969 TAxis *TGraph2D::GetYaxis()
const
971 TH1 *h = ((TGraph2D*)
this)->GetHistogram(
"empty");
973 return h->GetYaxis();
980 TAxis *TGraph2D::GetZaxis()
const
982 TH1 *h = ((TGraph2D*)
this)->GetHistogram(
"empty");
984 return h->GetZaxis();
993 TList *TGraph2D::GetContourList(Double_t contour)
996 Error(
"GetContourList",
"Empty TGraph2D");
1000 if (!fHistogram) GetHistogram(
"empty");
1002 if (!fPainter) fPainter = fHistogram->GetPainter();
1004 return fPainter->GetContourList(contour);
1012 Double_t TGraph2D::GetErrorX(Int_t)
const
1022 Double_t TGraph2D::GetErrorY(Int_t)
const
1032 Double_t TGraph2D::GetErrorZ(Int_t)
const
1041 void TGraph2D::CreateInterpolator(Bool_t oldInterp)
1044 TList *hl = fHistogram->GetListOfFunctions();
1047 TGraphDelaunay *dt =
new TGraphDelaunay(
this);
1048 dt->SetMaxIter(fMaxIter);
1049 dt->SetMarginBinsContent(fZout);
1051 SetBit(kOldInterpolation);
1052 if (!hl->FindObject(
"TGraphDelaunay")) hl->Add(fDelaunay);
1054 TGraphDelaunay2D *dt =
new TGraphDelaunay2D(
this);
1055 dt->SetMarginBinsContent(fZout);
1057 ResetBit(kOldInterpolation);
1058 if (!hl->FindObject(
"TGraphDelaunay2D")) hl->Add(fDelaunay);
1076 TH2D *TGraph2D::GetHistogram(Option_t *option)
1079 if (fNpoints <= 0) {
1081 Bool_t add = TH1::AddDirectoryStatus();
1082 TH1::AddDirectory(kFALSE);
1083 fHistogram =
new TH2D(GetName(), GetTitle(), fNpx , 0., 1., fNpy, 0., 1.);
1084 TH1::AddDirectory(add);
1085 fHistogram->SetBit(TH1::kNoStats);
1090 TString opt = option;
1092 Bool_t empty = opt.Contains(
"empty");
1093 Bool_t oldInterp = opt.Contains(
"old");
1096 if (!empty && fHistogram->GetEntries() == 0) {
1099 fHistogram =
nullptr;
1100 fDelaunay =
nullptr;
1102 }
else if (fHistogram->GetEntries() == 0)
1105 else if ( (TestBit(kOldInterpolation) && !oldInterp) || ( !TestBit(kOldInterpolation) && oldInterp ) ) {
1107 fHistogram =
nullptr;
1108 fDelaunay =
nullptr;
1116 Double_t hxmax, hymax, hxmin, hymin;
1120 Bool_t add = TH1::AddDirectoryStatus();
1121 TH1::AddDirectory(kFALSE);
1122 Double_t xmax = GetXmaxE();
1123 Double_t ymax = GetYmaxE();
1124 Double_t xmin = GetXminE();
1125 Double_t ymin = GetYminE();
1126 hxmin = xmin - fMargin * (xmax - xmin);
1127 hymin = ymin - fMargin * (ymax - ymin);
1128 hxmax = xmax + fMargin * (xmax - xmin);
1129 hymax = ymax + fMargin * (ymax - ymin);
1130 if (TMath::Abs(hxmax - hxmin) < 0.0001) {
1131 if (TMath::Abs(hxmin) < 0.0001) {
1135 hxmin = hxmin-TMath::Abs(hxmin)*0.01;
1136 hxmax = hxmax+TMath::Abs(hxmax)*0.01;
1139 if (TMath::Abs(hymax - hymin) < 0.0001) {
1140 if (TMath::Abs(hymin) < 0.0001) {
1144 hymin = hymin-TMath::Abs(hymin)*0.01;
1145 hymax = hymax+TMath::Abs(hymax)*0.01;
1149 fHistogram->GetXaxis()->SetLimits(hxmin, hxmax);
1150 fHistogram->GetYaxis()->SetLimits(hymin, hymax);
1152 fHistogram =
new TH2D(GetName(), GetTitle(),
1153 fNpx , hxmin, hxmax,
1154 fNpy, hymin, hymax);
1155 CreateInterpolator(oldInterp);
1157 TH1::AddDirectory(add);
1158 fHistogram->SetBit(TH1::kNoStats);
1160 hxmin = fHistogram->GetXaxis()->GetXmin();
1161 hymin = fHistogram->GetYaxis()->GetXmin();
1162 hxmax = fHistogram->GetXaxis()->GetXmax();
1163 hymax = fHistogram->GetYaxis()->GetXmax();
1168 Double_t hzmax, hzmin;
1169 if (fMinimum != -1111) {
1174 if (fMaximum != -1111) {
1179 if (hzmin == hzmax) {
1180 Double_t hz = hzmin;
1182 hzmin = hz - 0.01 * hz;
1183 hzmax = hz + 0.01 * hz;
1185 fHistogram->SetMinimum(hzmin);
1186 fHistogram->SetMaximum(hzmax);
1190 Double_t dx = (hxmax - hxmin) / fNpx;
1191 Double_t dy = (hymax - hymin) / fNpy;
1195 for (Int_t ix = 1; ix <= fNpx; ix++) {
1196 x = hxmin + (ix - 0.5) * dx;
1197 for (Int_t iy = 1; iy <= fNpy; iy++) {
1198 y = hymin + (iy - 0.5) * dy;
1201 z = ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1203 z = ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1205 fHistogram->Fill(x, y, z);
1210 if (fMinimum != -1111) fHistogram->SetMinimum(fMinimum);
1211 if (fMaximum != -1111) fHistogram->SetMaximum(fMaximum);
1220 Double_t TGraph2D::GetXmax()
const
1223 for (Int_t i = 1; i < fNpoints; i++) if (fX[i] > v) v = fX[i];
1231 Double_t TGraph2D::GetXmin()
const
1234 for (Int_t i = 1; i < fNpoints; i++)
if (fX[i] < v) v = fX[i];
1242 Double_t TGraph2D::GetYmax()
const
1245 for (Int_t i = 1; i < fNpoints; i++) if (fY[i] > v) v = fY[i];
1253 Double_t TGraph2D::GetYmin()
const
1256 for (Int_t i = 1; i < fNpoints; i++)
if (fY[i] < v) v = fY[i];
1264 Double_t TGraph2D::GetZmax()
const
1267 for (Int_t i = 1; i < fNpoints; i++) if (fZ[i] > v) v = fZ[i];
1275 Double_t TGraph2D::GetZmin()
const
1278 for (Int_t i = 1; i < fNpoints; i++)
if (fZ[i] < v) v = fZ[i];
1286 Int_t TGraph2D::GetPoint(Int_t i, Double_t &x, Double_t &y, Double_t &z)
const
1288 if (i < 0 || i >= fNpoints)
return -1;
1289 if (!fX || !fY || !fZ)
return -1;
1300 Double_t TGraph2D::Interpolate(Double_t x, Double_t y)
1302 if (fNpoints <= 0) {
1303 Error(
"Interpolate",
"Empty TGraph2D");
1307 if (!fHistogram) GetHistogram(
"empty");
1309 TList *hl = fHistogram->GetListOfFunctions();
1310 if (!TestBit(kOldInterpolation) ) {
1311 fDelaunay = hl->FindObject(
"TGraphDelaunay2D");
1312 if (!fDelaunay) fDelaunay = hl->FindObject(
"TGraphDelaunay");
1316 fDelaunay = hl->FindObject(
"TGraphDelaunay");
1317 if (!fDelaunay) fDelaunay = hl->FindObject(
"TGraphDelaunay2D");
1321 if (!fDelaunay)
return TMath::QuietNaN();
1323 if (fDelaunay->IsA() == TGraphDelaunay2D::Class() )
1324 return ((TGraphDelaunay2D*)fDelaunay)->ComputeZ(x, y);
1325 else if (fDelaunay->IsA() == TGraphDelaunay::Class() )
1326 return ((TGraphDelaunay*)fDelaunay)->ComputeZ(x, y);
1330 return TMath::QuietNaN();
1337 void TGraph2D::Paint(Option_t *option)
1339 if (fNpoints <= 0) {
1340 Error(
"Paint",
"Empty TGraph2D");
1344 TString opt = option;
1346 if (opt.Contains(
"p") && !opt.Contains(
"tri")) {
1347 if (!opt.Contains(
"pol") &&
1348 !opt.Contains(
"sph") &&
1349 !opt.Contains(
"psr")) opt.Append(
"tri0");
1352 if (opt.Contains(
"line") && !opt.Contains(
"tri")) opt.Append(
"tri0");
1354 if (opt.Contains(
"err") && !opt.Contains(
"tri")) opt.Append(
"tri0");
1356 if (opt.Contains(
"tri0")) {
1357 GetHistogram(
"empty");
1358 }
else if (opt.Contains(
"old")) {
1359 GetHistogram(
"old");
1364 fHistogram->SetLineColor(GetLineColor());
1365 fHistogram->SetLineStyle(GetLineStyle());
1366 fHistogram->SetLineWidth(GetLineWidth());
1367 fHistogram->SetFillColor(GetFillColor());
1368 fHistogram->SetFillStyle(GetFillStyle());
1369 fHistogram->SetMarkerColor(GetMarkerColor());
1370 fHistogram->SetMarkerStyle(GetMarkerStyle());
1371 fHistogram->SetMarkerSize(GetMarkerSize());
1372 fHistogram->Paint(opt.Data());
1379 void TGraph2D::Print(Option_t *)
const
1381 for (Int_t i = 0; i < fNpoints; i++) {
1382 printf(
"x[%d]=%g, y[%d]=%g, z[%d]=%g\n", i, fX[i], i, fY[i], i, fZ[i]);
1396 TH1 *TGraph2D::Project(Option_t *option)
const
1398 if (fNpoints <= 0) {
1399 Error(
"Project",
"Empty TGraph2D");
1403 TString opt = option;
1407 if (opt.Contains(
"x")) pcase = 1;
1408 if (opt.Contains(
"y")) pcase = 2;
1409 if (opt.Contains(
"xy")) pcase = 3;
1410 if (opt.Contains(
"yx")) pcase = 4;
1415 Int_t nch = strlen(GetName()) + opt.Length() + 2;
1416 char *name =
new char[nch];
1417 snprintf(name, nch,
"%s_%s", GetName(), option);
1418 nch = strlen(GetTitle()) + opt.Length() + 2;
1419 char *title =
new char[nch];
1420 snprintf(title, nch,
"%s_%s", GetTitle(), option);
1422 Double_t hxmin = GetXmin();
1423 Double_t hxmax = GetXmax();
1424 Double_t hymin = GetYmin();
1425 Double_t hymax = GetYmax();
1430 h1 =
new TH1D(name, title, fNpx, hxmin, hxmax);
1434 h1 =
new TH1D(name, title, fNpy, hymin, hymax);
1438 h2 =
new TH2D(name, title, fNpx, hxmin, hxmax, fNpy, hymin, hymax);
1442 h2 =
new TH2D(name, title, fNpy, hymin, hymax, fNpx, hxmin, hxmax);
1450 if (h == 0)
return 0;
1453 Double_t entries = 0;
1454 for (Int_t n = 0; n < fNpoints; n++) {
1458 h1->Fill(fX[n], fZ[n]);
1462 h1->Fill(fY[n], fZ[n]);
1466 h2->Fill(fX[n], fY[n], fZ[n]);
1470 h2->Fill(fY[n], fX[n], fZ[n]);
1475 h->SetEntries(entries);
1483 Int_t TGraph2D::RemovePoint(Int_t ipoint)
1485 if (ipoint < 0)
return -1;
1486 if (ipoint >= fNpoints)
return -1;
1489 Double_t *newX =
new Double_t[fNpoints];
1490 Double_t *newY =
new Double_t[fNpoints];
1491 Double_t *newZ =
new Double_t[fNpoints];
1493 for (Int_t i = 0; i < fNpoints + 1; i++) {
1494 if (i == ipoint)
continue;
1509 fHistogram =
nullptr;
1510 fDelaunay =
nullptr;
1519 void TGraph2D::SavePrimitive(std::ostream &out, Option_t *option )
1522 out <<
" " << std::endl;
1523 if (gROOT->ClassSaved(TGraph2D::Class())) {
1526 out <<
" TGraph2D *";
1529 out <<
"graph2d = new TGraph2D(" << fNpoints <<
");" << std::endl;
1530 out <<
" graph2d->SetName(" << quote << GetName() << quote <<
");" << std::endl;
1531 out <<
" graph2d->SetTitle(" << quote << GetTitle() <<
";"
1532 << GetXaxis()->GetTitle() <<
";"
1533 << GetYaxis()->GetTitle() <<
";"
1534 << GetZaxis()->GetTitle() << quote <<
");" << std::endl;
1536 if (fDirectory == 0) {
1537 out <<
" graph2d->SetDirectory(0);" << std::endl;
1540 SaveFillAttributes(out,
"graph2d", 0, 1001);
1541 SaveLineAttributes(out,
"graph2d", 1, 1, 1);
1542 SaveMarkerAttributes(out,
"graph2d", 1, 1, 1);
1544 for (Int_t i = 0; i < fNpoints; i++) {
1545 out <<
" graph2d->SetPoint(" << i <<
"," << fX[i] <<
"," << fY[i] <<
"," << fZ[i] <<
");" << std::endl;
1549 TIter next(fFunctions);
1551 while ((obj = next())) {
1552 obj->SavePrimitive(out,
"nodraw");
1553 out <<
" graph2d->GetListOfFunctions()->Add(" << obj->GetName() <<
");" << std::endl;
1554 if (obj->InheritsFrom(
"TPaveStats")) {
1555 out <<
" ptstats->SetParent(graph2d->GetListOfFunctions());" << std::endl;
1556 }
else if (obj->InheritsFrom(
"TF1")) {
1557 out <<
" " << obj->GetName() <<
"->SetParent(graph);\n";
1562 out <<
" graph2d->Draw(" << quote << option << quote <<
");" << std::endl;
1571 void TGraph2D::Set(Int_t n)
1574 if (n == fNpoints)
return;
1575 if (n > fNpoints) SetPoint(n, 0, 0, 0);
1587 void TGraph2D::SetDirectory(TDirectory *dir)
1589 if (fDirectory == dir)
return;
1590 if (fDirectory) fDirectory->Remove(
this);
1592 if (fDirectory) fDirectory->Append(
this);
1608 void TGraph2D::SetHistogram(TH2 *h)
1611 fHistogram = (TH2D*)h;
1612 fNpx = h->GetNbinsX();
1613 fNpy = h->GetNbinsY();
1614 CreateInterpolator(kTRUE);
1621 void TGraph2D::SetMargin(Double_t m)
1623 if (m < 0 || m > 1) {
1624 Warning(
"SetMargin",
"The margin must be >= 0 && <= 1, fMargin set to 0.1");
1631 fHistogram =
nullptr;
1632 fDelaunay =
nullptr;
1641 void TGraph2D::SetMarginBinsContent(Double_t z)
1646 fHistogram =
nullptr;
1647 fDelaunay =
nullptr;
1655 void TGraph2D::SetMaximum(Double_t maximum)
1658 TH1 * h = GetHistogram();
1659 if (h) h->SetMaximum(maximum);
1666 void TGraph2D::SetMinimum(Double_t minimum)
1669 TH1 * h = GetHistogram();
1670 if (h) h->SetMinimum(minimum);
1677 void TGraph2D::SetName(
const char *name)
1681 if (fDirectory) fDirectory->Remove(
this);
1683 if (fDirectory) fDirectory->Append(
this);
1691 void TGraph2D::SetNameTitle(
const char *name,
const char *title)
1695 if (fDirectory) fDirectory->Remove(
this);
1698 if (fDirectory) fDirectory->Append(
this);
1705 void TGraph2D::SetNpx(Int_t npx)
1708 Warning(
"SetNpx",
"Number of points must be >4 && < 500, fNpx set to 4");
1710 }
else if (npx > 500) {
1711 Warning(
"SetNpx",
"Number of points must be >4 && < 500, fNpx set to 500");
1718 fHistogram =
nullptr;
1719 fDelaunay =
nullptr;
1727 void TGraph2D::SetNpy(Int_t npy)
1730 Warning(
"SetNpy",
"Number of points must be >4 && < 500, fNpy set to 4");
1732 }
else if (npy > 500) {
1733 Warning(
"SetNpy",
"Number of points must be >4 && < 500, fNpy set to 500");
1740 fHistogram =
nullptr;
1741 fDelaunay =
nullptr;
1751 void TGraph2D::SetPoint(Int_t n, Double_t x, Double_t y, Double_t z)
1755 if (!fX || !fY || !fZ || n >= fSize) {
1757 Int_t newN = TMath::Max(2 * fSize, n + 1);
1758 Double_t *savex =
new Double_t [newN];
1759 Double_t *savey =
new Double_t [newN];
1760 Double_t *savez =
new Double_t [newN];
1762 memcpy(savex, fX, fSize *
sizeof(Double_t));
1763 memset(&savex[fSize], 0, (newN - fSize)*
sizeof(Double_t));
1767 memcpy(savey, fY, fSize *
sizeof(Double_t));
1768 memset(&savey[fSize], 0, (newN - fSize)*
sizeof(Double_t));
1772 memcpy(savez, fZ, fSize *
sizeof(Double_t));
1773 memset(&savez[fSize], 0, (newN - fSize)*
sizeof(Double_t));
1784 fNpoints = TMath::Max(fNpoints, n + 1);
1798 void TGraph2D::SetTitle(
const char* title)
1801 if (fHistogram) fHistogram->SetTitle(title);
1808 void TGraph2D::Streamer(TBuffer &b)
1810 if (b.IsReading()) {
1812 Version_t R__v = b.ReadVersion(&R__s, &R__c);
1813 b.ReadClassBuffer(TGraph2D::Class(),
this, R__v, R__s, R__c);
1815 ResetBit(kMustCleanup);
1817 b.WriteClassBuffer(TGraph2D::Class(),
this);