1

I have an XY map of event positions in a particle detector, and those events have dozens of variables which characterize them. Take energy, for instance: I can find the average energy of an event in a small region of the detector by making three TH2F's in ROOT:

TH2F* h_xy  = new TH2F("h_xy","h_xy",100,-10,10,100,-10,10);
TH2F* h_xyw = new TH2F("h_xyw","h_xyw",100,-10,10,100,-10,10);
TH2F* h_avg = new TH2F("h_avg","h_avg",100,-10,10,100,-10,10);

I fill h_xy with all of my events, distributed over xy. Each entry in the histogram is weighted to 1. Then, I fill h_xyw with all of my events, weighted by the energy. Dividing h_xyw by h_xy gives the average energy per bin, which I put into h_avg. I do all of this on the ROOT command line, so it's really easy to just:

tree->Draw("energy>>h_xy","","colz")

And then pull the information right out of the histograms. Next, I'd like to be able to plot the standard deviation of the weights in each bin, in addition to the average. I know I can do this by writing a compiled script, but I'm wondering if there's an easy way to do this command-line that I just haven't thought of.

awwsmm
  • 1,353
  • 1
  • 18
  • 28
  • How did you do the division of two Hisograms? You need to do a loop to do the division or you have command line to accomplish this? Thanks. – Huanian Zhang Jul 28 '16 at 19:55
  • @HuanianZhang (this is probably way too late to be useful for you), but TH2 inherits all methods from TH1 and [TH1 has a Divide() method](https://root.cern.ch/doc/master/classTH1.html#a4ef2329285beb6091515b836e160bd9f). – awwsmm Mar 18 '18 at 19:43

1 Answers1

1

Similar to your existing commands, you can fill another histogram h_xyww with the energy squared as weigths. Then you divide h_xyww by h_xy (average squared energy), multiply the histogram with the average energies by itself (square of average energy), and then subtract the two from each other.

std_dev^2 = <E^2> - <E>^2
pseyfert
  • 3,263
  • 3
  • 21
  • 47
  • Ah, that's so simple! I was completely ignoring that definition of the standard deviation -- focusing on the event-by-event sum. This is exactly what I needed, thanks! – awwsmm May 04 '16 at 12:13