What is ROOT? Why do we use it? Answer: ROOT does what physicists do: It makes plots. - PDF Document

Presentation Transcript

  1. What is ROOT? Why do we use it? Answer: ROOT does what physicists do: It makes plots.

  2. sin(x)*sin(y)/(x*y) 1 0.8 0.6 0.4 0.2 0 0.2 − 10 8 6 4 2 10 0 8 6 2 − 4 2 4 − 0 2 6 − − 4 − 8 6 − − 8 − 10 − 10 −

  3. Number of charged atoms in ’Nights in the Gardens of Spain’ 28 26 24 22 Falla d ions 20 n 18 16 14 12 3 -1 2 10 10 10 1 10 t [secs] Can you spot the pun in this plot?

  4. The typical analysis task that you will be asked to do: Take variables in an n-tuple, perform some computations, and make histograms. So what is a histogram, what is an n-tuple, and how do we perform the computations?

  5. Anatomy of a histogram Properties of a histogram A ROOT command that might be used to define this histogram: Name or Identifier Title (to be displayed on plot) Number of bins Lower bin limit Upper bin limit § TH1F myPlot("Example","Sample histogram",100,-3,3) § § § §

  6. Don't forget the errors! For simple histograms, the error in one bin is the square root of the number of events in that bin.

  7. There's an art to histogram design...

  8. Anatomy of an n-tuple (a simple form of a ROOT Tree) Branches --> <-- Entries An n-tuple is an ordered list of numbers. A ROOT Tree can be an ordered list of any collections of C++ objects. Probably you'll only be asked to work with n-tuples this summer, but in Part Seven of the tutorial you can see what it’s like to work with a ROOT Tree.

  9. Why ROOT? • It knows about n-tuples and histograms and 4-vectors and object persistency and schema evolution and detector geometry and Feynmann diagrams and linear algebra and function-fitting and multi-variable analysis and… • It can handle large volumes of data millions of physics events; files of gigabytes->terabytes in size; multi- threaded and batch processing • Multi-platform (Windows, Mac, many UNIX flavors) • It’s free.

  10. But... • It’s open-source, with a complicated design history. • User-interface issues and documentation are often neglected. • It’s not a pre-packaged “app.” ROOT is not easy to install. • ROOT is pretty much only used in high-energy physics. • You have to know some C++ in order to use ROOT effectively, in order to perform computations. • What does C++ look like? Well...

  11. #define AnalyzeHistogram_cxx #include "AnalyzeHistogram.h" #include <TH2.h> #include <TStyle.h> //******** Definition section ********* TH1* chi2Hist = 0; void AnalyzeHistogram::Begin(TTree * /*tree*/) { TString option = GetOption(); //******** Initialization section ********* chi2Hist = new TH1F("chi2","Histogram of Chi2",100,0,20); chi2Hist->GetXaxis()->SetTitle("chi2"); chi2Hist->GetYaxis()->SetTitle("number of events"); } void AnalyzeHistogram::SlaveBegin(TTree * /*tree*/) { TString option = GetOption(); } Bool_t AnalyzeHistogram::Process(Long64_t entry) { //******** Loop section ********* tree1->GetEntry(entry); chi2Hist->Fill(chi2); return kTRUE; } void AnalyzeHistogram::SlaveTerminate() {} void AnalyzeHistogram::Terminate() { //******** Wrap-up section ********* chi2Hist->Draw(); }

  12. If you prefer Python, there’s pyroot import ROOT # Open the file. myfile = ROOT.TFile( 'experiment.root' ) # Retrieve the n-tuple of interest. mychain = ROOT.gDirectory.Get( 'tree1' ) entries = mychain.GetEntriesFast() # Create a 2D histogram myHist = ROOT.TH2D("hist2D","chi2 vs ebeam",100,0,20,100,149,151) myHist.GetXaxis().SetTitle("chi2") myHist.GetYaxis().SetTitle("ebeam [GeV]") for jentry in xrange( entries ): # Copy next entry into memory and verify. nb = mychain.GetEntry( jentry ) if nb <= 0: continue # Fetch the variables from the entry and fill the histogram. chi2 = mychain.chi2 ebeam = mychain.ebeam myHist.Fill(chi2,ebeam) # Display the scatterplot. myHist.Draw()

  13. Web Links (the only part you should bother to write down) All the documents you've seen (and will see) during the class today and tomorrow can be found at: http://www.nevis.columbia.edu/~seligman/root-class/ ROOT and C++ links, including links to reference books on C++ and statistics, can be found at: http://www.nevis.columbia.edu/~seligman/root-class/links.html

  14. The Hands-on Course: Basic Data Analysis using ROOT ROOT basics Over the next two days, you will learn how to: • look up ROOT command references • plot a function • histogram a variable • fit a histogram • get a variable from an n-tuple • apply cuts • do a quick study using TreeViewer (optional) • create C++ or python code for an n-tuple • use the Jupyter notebook server for quick coding -- but not necessarily in this order! The advanced tutorial (which you may not get to) includes sets of additional exercises to help turn you into a ROOT expert: • Creating an x-y plot • Working with large numbers of histograms • Extracting your own n-tuples

  15. A Brief ROOT Demonstration • Using the command line • Using the notebook server