Error Bar Root
Contents |
//Draw a graph with error bars //
Tgrapherrors Draw Options
To see the output of this macro, click begin_html here. setmarkerstyle root end_html //Author: Rene Brun TCanvas *c1 = new TCanvas("c1","A Simple Graph with error bars",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); const Int_t n = 10; tgrapherrors root Float_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; Float_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; Float_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; Float_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey); gr->SetTitle("TGraphErrors Example"); gr->SetMarkerColor(4); gr->SetMarkerStyle(21); gr->Draw("ALP"); c1->Update(); } gerrors.C:1gerrors.C:2gerrors.C:3gerrors.C:4gerrors.C:5gerrors.C:6gerrors.C:7gerrors.C:8gerrors.C:9gerrors.C:10gerrors.C:11gerrors.C:12gerrors.C:13gerrors.C:14gerrors.C:15gerrors.C:16gerrors.C:17gerrors.C:18gerrors.C:19gerrors.C:20gerrors.C:21gerrors.C:22gerrors.C:23gerrors.C:24gerrors.C:25gerrors.C:26 » Last changed: 2015-09-08 00:33 » Last generated: 2015-09-08 00:33 This page has been automatically generated. For comments or suggestions regarding the documentation or ROOT in general please send a mail to ROOT support.
Member Functions | Protected Attributes | List of all members THistPainter Class ReferenceHistogram Library » Histograms and graphs painting classes. The histogram painter class. Implements
Tgraphasymmerrors
all histograms' drawing's options. Introduction Histograms' plotting options Options supported root tgraph example for 1D and 2D histograms Options supported for 1D histograms Options supported for 2D histograms Options
Root Th2
supported for 3D histograms Options supported for histograms' stacks (THStack) Setting the Style Setting line, fill, marker, and text attributes Setting Tick marks on the histogram https://root.cern.ch/root/html/tutorials/graphs/gerrors.C.html axis Giving titles to the X, Y and Z axis The option "SAME" Limitations Superimposing two histograms with different scales in the same pad Statistics Display Fit Statistics The error bars options The bar chart option The "BAR" and "HBAR" options The SCATter plot option (default for 2D histograms) The ARRow option https://root.cern.ch/doc/master/classTHistPainter.html The BOX option The COLor option The CANDLE option The VIOLIN option The TEXT and TEXTnn Option The CONTour options The LIST option The LEGO options The "SURFace" options Cylindrical, Polar, Spherical and PseudoRapidity/Phi options Base line for bar-charts and lego plots TH2Poly Drawing The SPEC option Option "Z" : Adding the color palette on the right side of the pad Setting the color palette Drawing a sub-range of a 2-D histogram; the [cutg] option Drawing options for 3D histograms Drawing option for histograms' stacks Drawing of 3D implicit functions Associated functions drawing Drawing using OpenGL General information: plot types and supported options TH3 as color boxes TH3 as boxes (spheres) TH3 as iso-surface(s) TF3 (implicit function) Parametric surfaces Interaction with the plots Selectable parts Rotation and zooming Panning Box cut Plot specific interactions (dynamic slicing etc.) Surface with option "GLSURF" TF3 Box Iso Parametric plot Introduction Histograms are drawn via the chart, these histograms will (by default) look more like a graph when plotted, with the value of each bin shown as a marker with an error bar. For your http://diana.parno.net/thoughts/?p=34 histogram to keep track of its statistical (counting) errors, i.e. sqrt(N), you need to https://www.ncsu.edu/labwrite/res/gt/gt-stat-home.html tell it to set aside space for a data structure for this information -- before you start filling it. After you declare the histogram, but before the first fill command, invoke the TH1F::Sumw2() command: myhist->Sumw2(); As you fill it, your histogram will use the allocated space to track the error bars in each bin. Of error bar course, ROOT just keeps track of basic counting errors here. What if your statistical error is more complex? For example, you could be plotting something that's a function of the counts, rather than the counts themselves. Or you might want to add in systematic error. In this case, calculate the error on each bin. (If it's derived from the counting error, you can use the TH1F::GetBinError command, which takes the error bar root bin number as an argument.) Once you've computed the final error, you can set the error value in the histogram; it will be stored in the structure allocated by TH1F::Sumw2(). Suppose that you've stored the error value for the ith bin in the ith element of the my_errs array: myhist->SetBinError(i, my_errs[i]) Now, if you plot myhist (myhist->Draw()), you'll end up with something that looks like a graph: there's a marker at the center of each bin, and the marker has an error bar. You can set the marker color, style, etc, in the same way as you would for a TGraph. But what if you want to plot your histogram as a normal histogram -- bar-chart style? You may want the error structure present in the background, for use in your calculations behind the scenes, but it may be distracting in the plots. There are many histogram draw options that look like they might be useful for this purpose, yet all but one will let you down. To make your error-barred histogram look like a regular one, use the draw option "HIST": myhist->Draw("HIST"); Posted on April 22, 2011July 21, 2011Author Diana ParnoCategories ROOT of all evil Post navigation Previous Previous post: Centering a Histogram TitleNext Next post: Relabeling Though no one of these measurements are likely to be more precise than any other, this group of values, it is hoped, will cluster about the true value you are trying to measure. This distribution of data values is often represented by showing a single data point, representing the mean value of the data, and error bars to represent the overall distribution of the data. Let's take, for example, the impact energy absorbed by a metal at various temperatures. In this case, the temperature of the metal is the independent variable being manipulated by the researcher and the amount of energy absorbed is the dependent variable being recorded. Because there is not perfect precision in recording this absorbed energy, five different metal bars are tested at each temperature level. The resulting data (and graph) might look like this: For clarity, the data for each level of the independent variable (temperature) has been plotted on the scatter plot in a different color and symbol. Notice the range of energy values recorded at each of the temperatures. At -195 degrees, the energy values (shown in blue diamonds) all hover around 0 joules. On the other hand, at both 0 and 20 degrees, the values range quite a bit. In fact, there are a number of measurements at 0 degrees (shown in purple squares) that are very close to measurements taken at 20 degrees (shown in light blue triangles). These ranges in values represent the uncertainty in our measurement. Can we say there is any difference in energy level at 0 and 20 degrees? One way to do this is to use the descriptive statistic, mean. The mean, or average, of a group of values describes a middle point, or central tendency, about which data points vary. Without going into detail, the mean is a way of summarizing a group of data and stating a best guess at what the true value of the dependent variable value is for that independent variable level. In this example, it would be a best guess at what the true energy level was for a given temperature. The above scatter plot can be transformed into a line graph showing the mean energy values: Note that instead of creating a graph using all of the raw data, now only the mean value is plotted for impact energy. The mean was calculated for each temperature by using the AVERAGE function in Excel. You use this function by typing =AVERAGE in the formula bar and then putting the range of cells containing the data you want the mean of within parentheses after the function name, like this: In this case, the values in cells B82 through B86 are averaged (the mean calculated) and the result placed in cell B87. Once you hav