AliPhysics  cf1a5e2 (cf1a5e2)
Graphs with systematic errors

## Classes

class  GraphSysErr

## Detailed Description

This module defines a class for $$(x,y)$$ graphs with an arbitrary set of systematic uncertainties. It provides storage and visualisation of such data, as well as import/export to the HepData format.

### Example

We define a function in a script. It takes one argument - whether to fit the data or not.
void
Example(Bool_t fit=true)
{
The first thing we do, is to check if we have the class GraphSysErr, and if not, we compile the script.
if (!gROOT->GetClass("GraphSysErr"))
Then, we adjust some sizes - the default error along X, how large the end bars should be.
// Adjust size along X of common errors
gStyle->SetErrorX(.2);
// Adjust size of hat, cap, ... - depends on canvas size!
gStyle->SetEndErrorSize(10);
Now we're ready to declare our object.
// Make our object
GraphSysErr* gse = new GraphSysErr("foo", "Gaussian");
The first we do, is set some parameters on the object: That we shouldn't put tick marks ('ends') on the error, and the name of the X and Y axis.
// Draw data with-out ticks
gse->SetXTitle("X");
gse->SetYTitle("Y");
Next, we set some key values. These are mainly for exporting to a Durham database input file. In principle one can define any key, but only a sub-set is written when exporting.
// Set some key/value pairs
gse->SetKey("laboratory", "The Center");
gse->SetKey("accelerator", "Mega Collider");
gse->SetKey("detector", "Huge Experiment");
gse->SetKey("author", "Christensen");
gse->SetKey("reference","Jour.All.Things A1,999");
gse->SetKey("doi","9999-9999-9999-9999");
gse->SetKey("abstract", "The data");
gse->SetKey("location", "In the paper");
gse->SetKey("reackey", "graviton -> tachyons");
gse->SetKey("obskey", "GUT");
Next, we can add as many qualifiers to the data set we want. If one is to export multiple graphs to a table, one should set a RE qualifier to distinguish the columns, or give each graph a distinct title.
Now we can define common errors. That is, errors that are correlated over all points. Common errors only have one negative and one positive value (which may be identical). Common errors can be relative. The member function GraphSysErr:DefineCommon returns a unique identifier. This identifier should be stored for later manipulation of the error.
// Two sources of common errors one relative, one absolue
UInt_t cm1 = gse->DefineCommon("Common 0.05", false, .05);
UInt_t cm2 = gse->DefineCommon("Common 10%", true, .1);
Next is the point-to-point (uncorrelated) systematic errors. Here, we simple give a name and whether the error is relative. The member function GraphSysErr:DeclarePoint2Point returns a unique identifier. This identifier should be stored for later manipulation of the error.
// Two sources of point-to-point errors, one relative, one absolute
UInt_t pp1 = gse->DeclarePoint2Point("Point-to-Point 0.1-0.2", true);
UInt_t pp2 = gse->DeclarePoint2Point("Point-to-Point 5-10%", false);
Now we customize the graphical output of each error
// Set options on summed errors (in case of option COMBINED)
gse->SetSumLineColor(kRed+2);
gse->SetSumLineWidth(2);
gse->SetSumTitle("All errors");
// Set attributes of common errors
gse->SetSysFillColor(cm1, kRed+2);
gse->SetSysFillStyle(cm1, 3001);
gse->SetSysLineColor(cm1, kRed+2);
gse->SetSysFillColor(cm2, kCyan+2);
gse->SetSysFillStyle(cm2, 3001);
// Set attributes of other errors
gse->SetSysLineColor(pp1, kBlue+2);
gse->SetSysLineWidth(pp1, 2);
gse->SetSysLineColor(pp2, kGreen+2);
gse->SetSysLineWidth(pp2, 3);
In this example, we take the data points to from a Gaussian deviate. Technically, we make a histogram of the probability of a given number.
// Fill a histogram with a Guassian random deviate
TH1* h = new TH1F("h", "h", 30, -3, 3);
h->Sumw2();
h->SetDirectory(0);
h->FillRandom("gaus",1000);
h->Scale(1./1000, "width");
Now we can set all our points. We remove our temporary histogram after we're done with it.
// Fill in the data points
for (Int_t i = 0; i < h->GetNbinsX(); i++) {
Int_t bin = i+1;
Double_t x = h->GetXaxis()->GetBinCenter(bin);
Double_t y = h->GetBinContent(bin);
Double_t sta = h->GetBinError(bin);
Double_t w = h->GetXaxis()->GetBinWidth(bin);
// Set data
gse->SetPoint(i, x, y);
gse->SetPointError(i, w/2, w/2);
gse->SetStatError(i, sta);
// Set point-to-point errors
gse->SetSysError(pp1, i, 0., gRandom->Uniform(0.1, 0.2));
gse->SetSysError(pp2, i, 0., 0.,
gRandom->Uniform(0.05, 0.1),
gRandom->Uniform(0.05, 0.1));
}
// Remove temporary histogram
delete h;
Finally, we can build a canvas
// Build our canvas
TCanvas* c = new TCanvas("c","c", 1400, 1000);
c->SetFillColor(0);
c->SetFillStyle(0);
c->SetTopMargin(0.01);
c->SetRightMargin(0.01);
Depending on the single parameter, we either draw or fit a Gaussian distribtion to the data.
// Draw or fit (and draw) a Guassian to the data
const char* option = "STACK stat axis quad split max west";
if (!fit)
gse->Draw(option);
else
gse->Fit("gaus", "SQ", option, -3, 3);
And then we draw and finish
// Make a legend
TLegend* l = c->BuildLegend(0.7,0.7,0.97,0.97);
l->SetFillColor(0);
l->SetFillStyle(0);
l->SetBorderSize(0);
// update the canvas and print
c->Modified();
c->Update();
c->cd();
c->Print("Example.png");
}