Plotting Histograms in root

There are three steps to plotting a histogram:

1) Declare the histogram before the event loop
where histogram_name is a name you choose, while Nbins, left_edge, right_edge are values (Nbins is an integer, while left_edge and right_edge can value, integer or real).

2) Fill the histogram in the event loop
where fill_value is whatever you want to fill the histogram with in this event.

3) Write out the histogram after the event loop

Now run the job

Opening a histogram file in root

Once you have run the job, there should be a file: QuarkNet_test_RPV2012_Tag.root (the middle term might be something other than "test" depending on the data file). To open this file in root:

Some commands to use within root

To quit out of root.
root>

.q



To get a help list of all the "dot" commands in root
root>

.?



To list all the histograms there are to look at
root>

.ls



To draw a histogram called histogram_name (if it exists)
root>

histogram_name->Draw()



You can also do a tab-complete for a command. If you type
root>

histogram_name->[Tab]


then it will list all the things you can do with that histogram name (for instance: Draw(), Rebin(x), etc).

  • To open root, simply type:

root

  • Within root:

TLorentzVector blah0;

(Declares a 4-Vector named blah0)

blah0.SetPtEtaPhiM(myPt, myEta, myPhi, myMass);

(Sets the values of blah0 as shown)

blah0.SetPxPyPzE(myPx, myPy, myPz, myEnergy);

(Alternate way to blah0)

blah0.Px();

(Prints the Px of the 4-vector blah0)

TH1D* histogram_name = new TH1D("histogram_name","histogram_name",Nbins,left_edge,right_edge);

histogram_name->Fill(fill_value);

histogram_name->Write();

root QuarkNet_test_RPV2012_Tag.root