Campuses:
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
computing:contrib:root:localdoc [2009/02/19 09:30] – strait | computing:contrib:root:localdoc [2009/06/01 15:47] (current) – more strait | ||
---|---|---|---|
Line 71: | Line 71: | ||
void Loop(TTree * awesomedata) | void Loop(TTree * awesomedata) | ||
{ | { | ||
+ | yourdataobject * onedatum = 0; | ||
+ | awesomedata-> | ||
for(int i = 0; i < awesomedata-> | for(int i = 0; i < awesomedata-> | ||
awesomedata-> | awesomedata-> | ||
Line 83: | Line 85: | ||
Loop(awesomedata); | Loop(awesomedata); | ||
} | } | ||
+ | |||
+ | The class " | ||
=== Use Good Names === | === Use Good Names === | ||
Line 100: | Line 104: | ||
It outputs two short nouns stuck together. | It outputs two short nouns stuck together. | ||
+ | |||
+ | === Avoid Unnecessary Pointers === | ||
+ | |||
+ | ROOT examples often declare //every// object as a pointer (with ' | ||
+ | |||
+ | TH1F * queengrid = new TH1F(" | ||
+ | |||
+ | This is dangerous because if you do not call: | ||
+ | |||
+ | delete queengrid; | ||
+ | |||
+ | when you're done with the object, the memory is never released. | ||
+ | |||
+ | TH1F queengrid(" | ||
+ | |||
+ | which, besides being safer, is also less typing. | ||
+ | |||
+ | Now! Graphical objects like histograms that are meant to appear on the screen //do// need to be allocated with ' | ||
+ | |||
+ | For non-graphical objects like TRandom3, it's an easier call. Don't make them pointers unless you have a particular reason to. Despite the example you see that says to do this: | ||
+ | |||
+ | TRandom3 * laserfocus = new TRandom3(); | ||
+ | |||
+ | instead do simply: | ||
+ | |||
+ | TRandom3 laserfocus; | ||
+ | |||
+ | These generate the same random numbers, but the first one stays in memory until you delete it explicitly, while the second stays in memory until the bottom of the function. | ||
+ | |||
+ | // If you declared with ' | ||
+ | void IWantRandomNumbers(TRandom3 * laserfocus) | ||
+ | | ||
+ | // If you simply declared the object: | ||
+ | // This copies the object: the sequence of random | ||
+ | // numbers will not be advanced in the calling function | ||
+ | void IWantRandomNumbers(TRandom3 laserfocus) | ||
+ | | ||
+ | // This uses the object itself: the sequence of random | ||
+ | // numbers *will* be advanced in the calling function | ||
+ | void IWantRandomNumbers(TRandom3 & laserfocus) | ||
===== How to Run Code ===== | ===== How to Run Code ===== | ||
Line 105: | Line 149: | ||
There are three generic options for running ROOT-based code: | There are three generic options for running ROOT-based code: | ||
- | | + | |
- | | + | |
- | | + | |
The first two options are widely used and well documented (?) elsewhere. | The first two options are widely used and well documented (?) elsewhere. | ||
Line 137: | Line 181: | ||
| | ||
- | | + | |
- | cout << "Your random number is " << | + | cout << "Your random number is " << |
| | ||
Line 157: | Line 201: | ||
< | < | ||
- | This has two big advantages. | + | This has two big advantages. |
+ | |||
+ | ====== Making Attractive Plots ====== | ||
+ | |||
+ | The default ROOT plot is quite nice for screen display. | ||
+ | |||
+ | These things can all be modified either by fiddling with the individual objects or by setting things in the active TStyle. | ||
+ | |||
+ | < | ||
+ | void SetOKStyle() | ||
+ | { | ||
+ | TStyle* OKStyle = new TStyle(" | ||
+ | |||
+ | // Colors | ||
+ | |||
+ | //set the background color to white | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | // Get rid of drop shadow on legends | ||
+ | // This doesn' | ||
+ | OKStyle-> | ||
+ | |||
+ | // | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | //use the primary color palette | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the default line color for a histogram to be black | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the default line color for a fit function to be red | ||
+ | OKStyle-> | ||
+ | |||
+ | //make the axis labels black | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the default title color to be black | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the margins | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | //set axis label and title text sizes | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | //set line widths | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | // Misc | ||
+ | |||
+ | //align the titles to be centered | ||
+ | // | ||
+ | |||
+ | //turn off xy grids | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the tick mark style | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | // | ||
+ | OKStyle-> | ||
+ | |||
+ | //set the default stats shown | ||
+ | OKStyle-> | ||
+ | |||
+ | //marker settings | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | // Fonts | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | OKStyle-> | ||
+ | |||
+ | // Set the paper size for output | ||
+ | OKStyle-> | ||
+ | |||
+ | //done | ||
+ | OKStyle-> | ||
+ | |||
+ | cout << "Using OKStyle" | ||
+ | } | ||
+ | </ | ||
+ |