• John
  • Felde
  • University of Maryland
  • USA

Latest Posts

  • USLHC
  • USLHC
  • USA

  • James
  • Doherty
  • Open University
  • United Kingdom

Latest Posts

  • Andrea
  • Signori
  • Nikhef
  • Netherlands

Latest Posts

  • CERN
  • Geneva
  • Switzerland

Latest Posts

  • Aidan
  • Randle-Conde
  • Université Libre de Bruxelles
  • Belgium

Latest Posts

  • TRIUMF
  • Vancouver, BC
  • Canada

Latest Posts

  • Laura
  • Gladstone
  • MIT
  • USA

Latest Posts

  • Steven
  • Goldfarb
  • University of Michigan

Latest Posts

  • Fermilab
  • Batavia, IL
  • USA

Latest Posts

  • Seth
  • Zenz
  • Imperial College London
  • UK

Latest Posts

  • Nhan
  • Tran
  • Fermilab
  • USA

Latest Posts

  • Alex
  • Millar
  • University of Melbourne
  • Australia

Latest Posts

  • Ken
  • Bloom
  • USLHC
  • USA

Latest Posts


Warning: file_put_contents(/srv/bindings/215f6720ac674a2d94a96e55caf4a892/code/wp-content/uploads/cache.dat): failed to open stream: No such file or directory in /home/customer/www/quantumdiaries.org/releases/3/web/wp-content/plugins/quantum_diaries_user_pics_header/quantum_diaries_user_pics_header.php on line 170

Posts Tagged ‘ROOT’

Since deciding to become a high energy physicist I’ve had a much harder time answering a question often asked of scientists, “What’s the practical application.”  After all, High Energy Physics is, for the most part, a basic science; meaning its long term goals are to increase our understanding of the natural world.  Whereas in applied science (such as hydrogen fuel cell research) there is usually a targeted application from the get go (i.e. hydrogen powered automobiles).

When asked what’s the practical application of my research, I have a tough time answering.  After all, I study experimental Quantum Chromodynamics; and a “practical application” such as the light bulb (application of electromagnetism) or the transistor (quantum mechanics) may not arise in my lifetime.  But what I can say is the technologies developed to perform my research have a noticeable impact on our society (much like the benefits of the Space Program).

I thought today it might be interesting to talk about one such technology….namely the software used by high energy physicists.

Now each experiment at the LHC has its own unique software and computing environment (this is by design).  I can’t speak for the other experiments, but researchers within the CMS Collaboration have created something called CMSSW (or the CMS Software frameWork).  This software framework uses C++ plugins in a python based environment to analyze all experimental data taken by the CMS detector, and all simulated data created by the CMS Collaboration.  However, to use CMSSW (and the software of the other LHC experiments) you must be a member of the collaboration.

But rather then discussing CMSSW, I would like to discuss something common to all LHC experiments (and available to the general public), ROOT.  It is this “practical application” that I’d like to bring your attention to.

(Readers less experienced with programming languages may want to see the “Coding” section of one of my older posts for some background info).

 

What is ROOT?

ROOT is a object oriented software framework that uses a C++ interpreter to write scripts/macros for data analysis.  There are many pre-defined classes and methods available in ROOT; these are designed to enable a user to quickly & efficiently access large amounts of data, and perform analysis.  ROOT has both a command line interface and a graphical user interface, so modifications can be made either “on the fly” or by re-running a script/macro.

ROOT is very powerful, and it is possible to incorporate other libraries (such as the C++ Standard Template Library & others) into ROOT scripts/programs.

But, programming jargon aside, what can you actually do with ROOT?  Simple answer: lots.

ROOT is perfect for creating graphics, namely graphs & plots of interesting data.  But it can also be used to perform more useful tasks, such as numeric integration or differentiation.  ROOT also has several aspects from linear algebra built in (so you can do matrix multiplication/addition with it).  ROOT even enables a user to perform high level custom curve fits.

In fact, in some ways ROOT is very similar to programs like Mathematica & MATLAB.

However, ROOT has a distinct advantage over these products, its free.  ROOT can be downloaded by anyone; and has a rather detailed User’s Guide, and set of Tutorials/HowTo’s that can show new users how to perform a specific task.

But, enough boasting, let’s show some examples so you can get a feel for what ROOT can do!  I’m going to show some simple commands and their outputs, if you’d like to try them out yourself feel free.  My goal with this post is to get you interested in ROOT, not necessarily show you how to use it (guides such as that already exist! See links above!).

 

Example: Visualization

Suppose I was interested in observing the jet topology (or how the jets appear in space) in a particular proton-proton collision event.  There are several ways I could do this.  The first of which is to make what’s called a “lego plot.”  In a lego plot, I place the jet in space based on its angular coordinates; the polar angle, θ, and the azimuthal angle, Φ; and then each point is “weighted” by its momentum component in the xy-plane (termed pT).  To see how these angles & the xy-plane are defined in CMS, see the diagram below:

 

But in high energy physics θ is not very useful; instead we use a related variable called η, which is proportional to θ (η = 0 is still on the positive z-axis).

So in a lego plot I take all the jets in my event, and I plot them by their eta & phi values.  This is very simple to do in ROOT, and for this task I’m going to make a two dimensional histogram:

TH2D *LegoPlot = new TH2D(“LegoPlot”,”Jet Topology”);

LegoPlot->Fill( Jet.eta(), Jet.phi(), Jet.pt() );

Where the first line creates an instance of a two dimensional histogram object, and the second line stores the jet’s η, Φ, & pT as an (x,y) point; but let’s call this an (η,φ) point instead.  This is literally all I need to type.  Of course this is just for one jet, I could put the second line within a loop structure so that I could enter all my jets in my event.

To visualize this output, I simply need to type:

LegoPlot->Draw(“lego2”);

Where “lego2” is an option of the Draw command.  The output of this command is then:

 

Three Jet Event in CMS

 

Here ROOT will automatically open up a new window, and draw the plot for us…it even gave us some statistics regarding the plot (upper right corner).

And all this was done with one line of code!

But, unfortunately the plot isn’t labeled, so we can’t make sense of it quiet yet.  We could use the graphical interface to add a label, or we can use the command line approach.  The GUI is great, but if I have to make this plot over and over again from multiple data files; I’m going to get really tired of using the GUI each time.  So instead, I could use the command line interface and write a script to have ROOT do this for me.  The commands I would use are:

LegoPlot->SetXTitle(“#eta”);

LegoPlot->SetYTitle(“#phi (Radians)”);

LegoPlot->SetZTitle(“p_{T} (GeV/c)”);

Then upon running my script ROOT would automatically add these titles to the plot.

The use of “#” signs in the above lines let ROOT know that I don’t just want the axis to say “eta” but that I want the axis to display the symbol “η.”  The underscore with the {} brackets inform ROOT that I also want a subscript (superscripts are done with ^{ …text….} ).  So with a few lines of code in the ROOT framework I have not only stored data, but shown it graphically.

I never had to compile anything, and I didn’t need to spend time building my GUI!

The final plot result is shown here:

Thee Jet Event in CMS, with Labels!

 

But this η-Φ plot really hasn’t helped me visualize the jets in 3D; after all CMS is a giant Cylinder.  The above plot would be if I took a pair of scissors to the cylinder (starting at the x-axis) and cut down a line parallel to the z-axis.  This would then “un-roll” the cylinder into the flat plane above.

But what if I wanted to view this plot in actual “η-Φ” space?  Well ROOT can do that too, and in one line of code!

LegoPlot->Draw(“psrlego2”)

The familiar “lego2” is still there, but now I’ve added “psr” to the options of the draw command.  ROOT understands psr to mean 3D pseudorapidity coordinates.  The output of this options is shown here:

 

Three Jet Event in CMS, in eta-phi space
Again, in a simple command I’ve been able to do some very intense plotting.  Of course these are just a few brief examples.  I am by no means trying to give an all inclusive guide to how to use ROOT.  As I’ve mentioned, those already exist (see the user’s guide, tutorials & how-to’s I’ve linked above).
d
c

Example: Curve Fitting

I think one of the most challenging things in all of science is curve fitting.  The reason I believe it is challenging is two-fold: first, you have to know what kind of curves would do well in describing your data; second, curve-fitting software is usually very expensive!

However, as I mentioned, ROOT is free!  And can perform very powerful curve-fitting techniques very simply.

Suppose I’ve made a histogram of an observable, and kept track of the number of counts per each value of my observable (this is my measurement).  Let’s say it looks like this:

 

Example Measurement

Now let’s say I’m interested fitting a curve to this data.  Ordinary office programs such as Open Office Spreadsheet or Microsoft Excel have the ability to do simple fits such as polynomials, or simple exponentials.  But beyond a correlation coefficient, I’m not going to get much out of a fit from one of those programs.  I also don’t really get much functionality from them either.

Let me elaborate further on that part.  The above graph, it has a horizontal asymptote at one.  Let’s say I want to incorporate this behavior into my fit.  Well I happen to know that the function:

Has this asymptotic behavior.  This is a relatively simple function, but I couldn’t use the “out-of-the box” Microsoft Excel for this fit.

But, the above function is just to simplistic, it doesn’t allow for any “shifts” or changes in the data from that expression.  Instead, let’s toss in a few parameters, called A & B; these parameters will give us some more flexibility in our fitting procedure:

This is again simplistic, but staying simple is usually a good rule of thumb in science.

But we’ve settled on a function to fit to our data.  How do we implement it in ROOT?  Again, it is very simplistic, we use the function class already available in the ROOT framework:

TF1 *func = new TF1(“func”,”1.0 – exp( [0] * x [1] )”, 0, 40);

Here, I’ve setup a new function.  The first word in quotes is my function’s name, “func.”  The second set of quotes is the mathematical expression I want the function to use; with [0] and [1] being our parameters A & B.  Then the last two numbers are the range of the x-variable that the function will be defined for.

This should immediately illustrate the power of ROOT.  In one line, I can tell ROOT symbolically what mathematical expression I want it to use for fitting.  I can construct any function imaginable, with any number of parameters, just by typing it out to ROOT.  ROOT will even recognize trigonometric functions, along with others.  I can even construct numeric functions (but this takes more code then one line).

Now to perform the fit I just tell the histogram above (call it “Histo”) that I want to fit a function to it.  This is done by:

Histo->Fit(func,””,””,3,40);

The quotes in the above expression tell ROOT how to perform the fit.  Right now there’s nothing in the quotes, so ROOT will just use its default fitting method (chi-squared minimization), in the range of x equals 3 to 40.

Executing this command causes ROOT to perform the fit and spit back the values for my parameters A & B along with their errors:

 

Fit Output

Here the parameters [0] and [1] are labeled as “p0” and “p1.”  There is a column for their values (“VALUE”), and a column for their errors (“ERROR”).  Up at the top I can see that the fit converged, and that ROOT took 86 attempts/iterations in its fitting process.

The “Histo->Fit….” command will also plot the original histogram with the fit overlaid, as shown here:

 

Result of Fit

 

ROOT has also the fit parameters in the statistics box.  From the Χ2/ndf we see that the fit wasn’t a very good fit mathematically; but we weren’t really trying here either.  With a better fit function, and selecting a more advanced fitting procedure we can get Χ2/ndf ~ 1.0 (exactly what we want to have!).

 

In Closing

My goal with this post was to illustrate a product that has come about because of High Energy Physics research, and show that it could be beneficial for the rest of society.  Hopefully this will spark your interest in ROOT for science/engineering/mathematics applications.  There is an extensive ROOT community and support system that you may turn to if you decide to learn ROOT and encounter problems/questions.

I would highly recommend ROOT for any of our readers who are students with technical majors (at all levels).

 

Until next time,

-Brian

Share