(exercise2)= # Exercise 2: Modifying a histogram **(15 minutes)** You're probably still plotting your histograms as a solid curve. Most of the time, your supervisor will want to see histograms with errors. Figure out how to draw one of your histograms (e.g., **`ebeam`**) with error bars. (Here's a {ref}`hint `.) :::{figure-md} ebeam-errors-rdf-fig :class: align-center ebeam histogram What I get when I plot `ebeam` with errors bars turned on. ::: That was pretty easy once you looked at the hint. We'll take it up a notch: Let's be good scientists and set/improve the axis labels; set the x-axis label to "Beam energy [GeV]" and set the y-axis label to "Number of events". This is tricky to do "from scratch" without reading the ROOT documentation in detail as described in {ref}`detective-work`, eventually reaching a description of the [TGAxis class](https://root.cern.ch/doc/master/classTGaxis.html). Fortunately, you've got a faster way, if you {ref}`remember an earlier lesson `. :::{admonition} Need more help? :class: hint Here's another hint if the above hint is too opaque for you: While `RDataFrame` is a useful tool, sometimes the easiest way to answer a question is to go back to the basics. Another thing to remember that if you can {ref}`use Draw on a histogram `, there are other ROOT histogram methods you can use on it. Also remember that histogram names are arbitrary. Maybe someone else calls a histogram something like **`hist__1__1`**, but you can call it **`histebeam`** or whatever you want. One last tip for Python programmers: The `->` used in C++ becomes a simple `.` for you. ::: :::::{admonition} Are you using the command line? :class: note If you're using the command line instead of the {ref}`notebook`, at this point in the tutorial it's going to be more convenient to start editing an external file and executing it from within your command environment. - {command}`root` You may remember this from {ref}`saving-c1`: Create a file containing your C++ code, preferably with the extension `.C`; e.g., `exercise2.C`. You'll want to set up your code as a C++ function; e.g.: :::{code-block} c++ void exercise2() { // This is not the real code for Exercise 2! cout << "Hello, world!" << endl; } ::: You can then execute this file from within {command}`root` with: .x exercise2.C - {command}`ipython` If you're using [interactive Python](https://ipython.readthedocs.io/en/stable/) outside of a notebook, then you'll want to use [the `%run` command](https://ipython.readthedocs.io/en/stable/interactive/magics.html). Create a file containing your Python code, preferably with the extension `.py`; e.g., `exercise2.py`. You can then execute this file from within {command}`ipython` with: %run exercise2.py :::{tip} If you're exiting your command-line environment to edit a file, quitting your editor, then starting up your environment again, there's a simpler way: just start up another {ref}`Terminal window `. Run your command-line environment in one window and edit files in another.[^trite] [^trite]: I apologize if this tip seems trite to you. But you might be surprised how many students have come from a {abbr}`GUI (Graphical User Interface)` environment that did not encourage them to open multiple windows at the same time. ::: :::::