From Wikibooks, open books for an open world
Jump to navigation Jump to search

This page lists all exercises of this book. Doing all the exercises is an important part of getting the essence of this book.

Exercise: Trying Interactive ROOT
On an interactive ROOT session: Fill an array of 100 000 000 64Bit floating point numbers of the machine independent ROOT type Double_t with random numbers. Compute the mean of the array and print it to the console. Note the computation time.

Hint: You can get random real numbers by creating a pointer to an instance of the TRandom class. (The constructor takes one arbitrary integer as initialization.) Then you can call the method TRandom::Rndm() to get a simple pseudo random number uniformly distributed between 0 and 1. For example:

TRandom *R = new TRandom(time(0));  // create a pointer to a new instance of TRandom in the heap
cout << R->Rndm() << endl;
Exercise: Interpreted ROOT Macros
  1. Consider the problem solved in the previous exercise. Now write a script that does the same thing and execute it as interpreted macro. Does it run faster?
  2. Modify the script in a way that the user can pass the amount of random numbers to be created as a parameter.
  3. Overload the macro such that the amount of numbers can still be passed but if no parameter is given, 100 000 000 numbers will be generated.
Exercise: Compiled ROOT Macros
Use the script you've written before and modify it so it can be run as compiled macro via ACLiC.
  • Make sure that both, calling with and without parameter, will still work.
  • Can your script still be interpreted by CINT after you've changed it?
  • How is the performance of the compiled macro for 100 000 000 numbers? What is faster for 5 numbers?
Exercise: A Simple Stand-Alone Application
Once again, consider the code you should have previously written to compute the mean of an array of random numbers. Now, last but not least, make it a stand-alone application and run it independently of any ROOT session. Make sure that passing parameters will still work. Check the performance of your application. Take also care that your modifications don't disturb interpretation or on-the-fly compilation by CINT or ACLiC.