{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Filling an n-tuple (simulating the conductivity of a material in different conditions of pressure and temperature) and writing it to a file\n", "
\n", "Ported to Notebook by: Theis Hansen\n", "\n", "To use the ROOT toolkit, we need to import ROOT onto our Notebook, which we also set to C++" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The Tuple\n", "We create a file which will contain our ntuple and the tuple itself." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "TFile ofile(\"conductivity_experiment.root\",\"RECREATE\");\n", "TNtuple cond_data(\"cond_data\",\"Example N-Tuple\",\"Potential:Current:Temperature:Pressure\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then we fill it randomly (to simulate acquired data) using the TRandom3 random generator.\n", "We are also applying some \"smearing\" (measurement errors): 1% error on voltage (pot), pressure and current and 1.3 absolute error on temperature.\n", "At the end of the loop body we fill the ntuple." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "TRandom3 rndm;\n", "float pot,cur,temp,pres;\n", "for (int i=0;i<10000;++i){\n", " pot=rndm.Uniform(0.,10.);\n", " temp=rndm.Uniform(250.,350.);\n", " pres=rndm.Uniform(0.5,1.5);\n", " cur=pot/(10.+0.05*(temp-300.)-0.2*(pres-1));\n", " \n", " pot*=rndm.Gaus(1.,0.01);\n", " temp+=rndm.Gaus(0.,0.3);\n", " pres*=rndm.Gaus(1.,0.02);\n", " cur*=rndm.Gaus(1.,0.01); \n", " \n", " cond_data.Fill(pot,cur,temp,pres);\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save the TNtuple and close the file." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cond_data.Write();\n", "ofile.Close();" ] } ], "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": 0 }