{ "cells": [ { "cell_type": "markdown", "id": "1db778d1", "metadata": {}, "source": [ "# gr005_apply\n", "TGraph::Apply applies a function `f` to all the data TGraph points, `f` may be a 1-D function TF1 or 2-d function TF2.\n", "The Y values of the graph are replaced by the new values computed using the function.\n", "\n", "\n", "The Apply() method can be used as well for TGraphErrors and TGraphAsymmErrors.\n", "\n", "\n", "\n", "\n", "**Author:** Miro Helbich \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:37 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "474d40e8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:46.768712Z", "iopub.status.busy": "2026-05-19T20:37:46.768527Z", "iopub.status.idle": "2026-05-19T20:37:47.258949Z", "shell.execute_reply": "2026-05-19T20:37:47.258428Z" } }, "outputs": [], "source": [ "const Int_t npoints=3;\n", "Double_t xaxis[npoints] = {1.,2.,3.};\n", "Double_t yaxis[npoints] = {10.,20.,30.};\n", "\n", "TGraph *gr1 = new TGraph(npoints,xaxis,yaxis);\n", "TF2 *ff = new TF2(\"ff\",\"-1./y\"); //Defining the function `f`\n", "\n", "TCanvas *c1 = new TCanvas(\"c1\",\"c1\", 0,0,700,500);\n", "c1->Divide(2,1);\n", "\n", "c1->cd(1);\n", "gr1->DrawClone(\"A*\"); //Using DrawClone to create a copy of the graph in the canvas.\n", "c1->cd(2);\n", "gr1->Apply(ff); //Applies the function `f` to all the data TGraph points\n", "gr1->Draw(\"A*\"); \n", "/* Without DrawClone, the modifications to gr1 via Apply(ff) are reflected in the original graph\n", "displayed in c1 (the two drawn graphs are not independent). */" ] }, { "cell_type": "markdown", "id": "2e9568b4", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "bbdc3c71", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:47.260805Z", "iopub.status.busy": "2026-05-19T20:37:47.260674Z", "iopub.status.idle": "2026-05-19T20:37:47.472735Z", "shell.execute_reply": "2026-05-19T20:37:47.472227Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }