ROOT Tutorial for 2023 EIEIO Workshop
All the macros shown in the slides are in the examples directory. These can be run as:
root -l macro_name.C
and should produce the outputs shown in the slides.
Example solutions to the five exercises can be found in the exercises directory. There's always a lot of different ways you can go about any of these problems, so try them out yourself and check these solutions if you get stuck. The first two exercises are fairly basic and open ended, so don't have solutions.
A solution to the project can be found in the project directory.
The solution scripts can be run like the examples:
Getting used to the ROOT command lineroot -l exercises_solution.C
- Open ROOT
- Declare some variables and do some calculations
- Draw a TCanvas
- Open the TBrowser and explore!
- In a macro, declare a histogram
- Fill it with some values, in any way you choose
- Declare a new TFile, and save the histogram
- Open the new ROOT file and draw the histogram
- Play with the aesthetics of the plot via the GUI
- Plot the Poisson distribution for λ = 5, 10, 25, 50, 100
- For each, also plot the Gaussian distribution with μ = λ, σ = √λ
- Use a different colour for each λ, and different line styles for Poisson and Gaussian
- Save the canvas to a PDF file
- You will have to judge the bin contents of the two histograms
This is a bonus exercise in case we run out of material. The idea is to collect numerical data of some sort, and then make some plots.
- Ask your friends >= 5 questions about themselves with numeric answers (eg, birthdate, age, height, shoe size, favourite number, number of pets/pairs of shoes/hammocks they own). Get creative!
- Record each answer in a text file, separated by a space, with a new line for a new friend
- Read this into a TTree, and save the TTree to file
- Open the file and plot different variables against each other. You can cut on variables (including ones your not plotting)
- See if you can pull out any amusing correlations!
- But remember this does not necessarily imply causation!!!
- Imagine you have a 5m radius spherical target mass, surrounded by PMTs
- Generate x, y, z and energy for 1000 events
- Assume this signal is uniformly distributed in position
- Assume an energy of, say, 2.5 MeV
- You can use ROOT's TRandom3 class to generate random numbers - Now generate x, y, z and energy for 1000 background events
- Let’s say it has the same energy as our signal
- But radially drops off as 1/r^2 away from the edge of the detector. Maybe there’s some external radiation that leaches into the target mass but only penetrates so far - Now let’s generate some reconstructed values
- Assume a position resolution of 100 mm in each coordinate
- Assume an energy resolution of 3 %
- What if the resolution is a weak function of the radius?
- This smearing of the true values with the width of the resolution is a common way to account for detector effects in simulation - Now repeat for 100,000 events and save these values in a TTree in a file
- Check the radial distributions look as expected
- Plot True vs Reconstructed R for all events
- Plot the bias in energy [(Reconstructed E - True E) / True E] as a function of True R
- We are now going to try and reject those background events by cutting on radius
- Make a ROC curve (purity against sacrifice) for different values for a radial cut
- Now repeat this whole process but for a background rate reduced by a factor of 10. How does the ROC curve change?