Exercise 10: A more practical function

Your task is to repeat Exercise 8: A bit more physics by writing a function to compute \(E_{loss}\):

\[ \begin{align}\begin{aligned}E_{meas}^{2} = p_{x}^{2} + p_{y}^{2} + p_{z}^{2}\\E_{loss} = E_{beam} - E_{meas}\end{aligned}\end{align} \]

You’ll create a new eloss column in the n-tuple, but that’s the only new column you’re going to create. You are to write a function that will take the needed columns from the n-tuple and return a value for \(E_{loss}\), use that function in a Define, then make a scatterplot of this new column against zv.1

Hint

Look at the available columns in the n-tuple. Compare that with above formulas. Which of those columns will you need to compute those equations? How many arguments will your function take?

xkcd equations

Figure 49: https://xkcd.com/2034/ by Randall Munroe


1

You can try to be clever and do this:

eloss_df = dataframe.Define("eloss","ebeam-sqrt(px*px+py*py+pz*pz)")

But you know that’s not what I’m asking for. For a real physics project, you’re going to be asked to performed calculations that can’t be shoved into a simple one-line text string. Write an actual function so you can learn how it’s done.

No, you don’t have to use a lambda expression. Unless, of course, you want to show how cool you are.