{ "cells": [ { "cell_type": "markdown", "id": "a8277fda", "metadata": {}, "source": [ "# tree110_copy\n", "Copy a subset of a Tree to a new Tree\n", "\n", "The input file has been generated by the program in `$ROOTSYS/test/Event`\n", "with `Event 1000 1 1 1`.\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \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:18 PM." ] }, { "cell_type": "code", "execution_count": null, "id": "fa583445", "metadata": { "collapsed": false }, "outputs": [], "source": [ "#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------\n", "\n", "#include \"./Event.h\" // now safe to include Event, its dictionary is loaded\n", "\n", "#else // -------- First pass: build dictionary + rerun macro --------" ] }, { "cell_type": "markdown", "id": "f1c355ad", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": null, "id": "023edd91", "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%cpp -d\n", "void run()\n", "{\n", " TFile oldfile(\"tree108.root\");\n", " TTree *oldtree;\n", " oldfile.GetObject(\"t4\", oldtree);\n", "\n", " // Deactivate all branches\n", " oldtree->SetBranchStatus(\"*\", 0);\n", "\n", " // Activate only four of them\n", " for (auto activeBranchName : {\"event_split\", \"fNtrack\", \"fNseg\", \"fH\"})\n", " oldtree->SetBranchStatus(activeBranchName, 1);\n", "\n", " // Create a new file + a clone of old tree in new file\n", " TFile newfile(\"tree110.root\", \"recreate\");\n", " auto newtree = oldtree->CloneTree();\n", "\n", " newtree->Print();\n", " newfile.Write();\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "e657aed0", "metadata": { "collapsed": false }, "outputs": [], "source": [ "TString tutdir = gROOT->GetTutorialDir();\n", "gROOT->ProcessLine(\".L \" + tutdir + \"/io/tree/Event.cxx+\");\n", "gROOT->ProcessLine(\"#define ACTUAL_RUN yes\");\n", "gROOT->ProcessLine(\"#include \\\"\" __FILE__ \"\\\"\");\n", "gROOT->ProcessLine(\"run()\");" ] } ], "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 }