ROOT - Graphics - Universidad de Oviedo

Transcripción

ROOT - Graphics - Universidad de Oviedo
Técnicas Fundamentales de Simulación,
Reconstrucción y Análisis de Datos en
Física Experimental de Partículas
7
ROOT TOOLKIT
(Graphics, I/O, Data Structures)
Isidro González Caballero (Universidad de Oviedo)
Valencia, 07-11/05/20102
2
Graphics & GUI
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp.
de Partículas
TPad: main graphics container
3
root[0]
root[1]
root[2]
root[3]



TLine line(.1,.9,.6,.6)
line.Draw()
TText text(.5,.2,”Hello”)
text.Draw()
The Draw() method adds the object
to the list of primitives of the current
pad.
If no pad exists, a pad is automatically
created with a default range [0,1].
When the pad needs to be drawn or
redrawn, the object Paint() function
is called.
Hello
Only objects deriving
from TObject may be
drawn
in a pad
Root Objects or User
objects
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Basic Primitives
4
TLine
TArrow
TEllipse
TCurvyLine
TButton
TBox
TDiamond
TText
TPave
TMarker
TPavesText
TPaveLabel
TCrown
TCurlyArc
TPolyLine
TLatex
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Lots of examples in /opt/root/tutorials/graphics
Full LateX
support
on screen
and
postscript
latex3.C
Formula or
diagrams
can be
edited with
the mouse
Feynman.C
TCurlyArc
TCurlyLine
TWavyLine
and other building
blocks for
Feynmann diagrams
5
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp.
de Partículas
Graphs
6
TGraph(n,x,y)
TCutG(n,x,y)
TMultiGraph
$ROOTSYS/tutorials/graphs/gerrors2.C
TGraphErrors(n,x,y,ex,ey)
TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh)
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Graphics examples
7
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
More graphics examples
8
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
More graphics examples
9
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
10
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Graphics (2D-3D)
11
TH3
TGLParametric
“LEGO”
“SURF”
TF3
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
ASImage: Image processor
12
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
GUI (Graphical User Interface)
13
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Canvas tool bar/menus/help
14
Select Toolbar to
activate the primitives
toolbar
$ROOTSYS/tutorials/fit/fit1.C
Select Toottip to
activate some info when
overlying objects
Click on Ev. Statusbar to
activate some info at the
bottom
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Object editor
15
You can save it
as file.C to
explore the C++
command to
change options
Select Editor
to activate the
objects edition
panel
Click on any
object to show
its edition
options
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
GUI C++ code generator
16


When pressing ctrl+S on any
widget it is saved as a C++
macro file thanks to the
SavePrimitive methods
implemented in all GUI classes.
The generated macro can be
edited and then executed via
CINT
Executing the macro restores the
complete original GUI as well as
all created signal/slot
connections in a global way
root [0] .x example.C
// transient frame
TGTransientFrame *frame2 = new TGTransientFrame(gClient>GetRoot(),760,590);
// group frame
TGGroupFrame *frame3 = new TGGroupFrame(frame2,"curve");
TGRadioButton *frame4 = new TGRadioButton(frame3,"gaus",10);
frame3->AddFrame(frame4);
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
The GUI Builder
17

The GUI builder
provides GUI tools for
developing user
interfaces based on
the ROOT GUI
classes. It includes
over 30 advanced
widgets and an
automatic C++ code
generator.
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
More GUI Examples
$ROOTSYS/tutorials/gui
18
$ROOTSYS/test/RootShower
$ROOTSYS/test/RootIDE
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Geometry
19
The GEOMetry package is used
to model very complex
detectors (LHC). It includes
-a visualization system
-a navigator (where am I,
distances, overlaps, etc)
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
OpenGL
20
see $ROOTSYS/tutorials/geom
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Math libraries
21
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Peak Finder + Deconvolutions
22
TSpectrum
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Fitters
23
Minuit
Fumili
LinearFitter
RobustFitter
Roofit
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Fit Panel
24
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Roofit: a powerful fitting framework
25
see $ROOTSYS/tutorials/fit/RoofitDemo.C
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Ejercicio propuesto 1
26

ROOT has several function classes.



The most basic is the TF1. Note that all class names in ROOT start with "T“
"F" is for function, and "1" is for one-dimensional.
Locate the class description page for TF1 on the ROOT website.
http://root.cern.ch/root/html/TF1.html

You will see several constructors, one of which has four arguments.
TF1::TF1(const char* name, const char* formula,
Double_t xmin=0, Double_t xmax=1);

Create the following 1-D function and draw it with:
root [0] TF1 f1("f1","sin(x)/x",0,10);
root [1] f1.Draw();


The constructor arguments are: the name (f1), and expression (sin(x)/x) and a lower and
upper limit (0,10).
You can use the tab key to complete the command or list the argument. For example to list all
the methods accessible trhough f1 type:
root [2] f1.<TAB>
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Ejercicio propuesto 2
27

Find the class description page for TGraph to answer the following questions:
http://root.cern.ch/root/html/TGraph.html

Copy $ROOTSYS/graphs/graph.C to your directory and change it to:


Center the title of the x axis.
Add two more points to the graph at (2.5, 6) and (3,4)

Modify it to draw 2 arrows starting from (1,-5) pointing to the 6th and last points

Use the context menu on the window to change the graph







Line thickness,
Line color
Marker style
Marker color
Change the background of the canvas.
Zoom the graph so that it starts at 0.5 and ends at 3.5.
Pull down the File menu and select “Save as” canvas.png. This creates a graphic file
of the canvas named after the canvas name (c1.png)
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Ejercicio propuesto 3
28


This next exercise will show you how to fill histograms and take time measurements.
Open the file hrandom.C






Note that it is written so it can be compiled
Study how it fills 2 histograms and prints the time it takes to fill them
Execute the script.
Copy hrandom.C to hrandom1.C and modify it to add two more fills using
TRandom2 and TRandom3 to fill them. For each case, print the CPU time spent in the
random generator.
Start a new ROOT session and run the same script using ACLiC. You should see a
considerable improvement in the CUP time:
Copy the hrandom1.C script to hrandom2.C and modify it so to draw the
first histogram and display it after the script has finished


Note problems with scope
Can you make it draw the histogram after each fill?  gPad->Update()
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
29
Input/Output
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp.
de Partículas
I/O
Object in
Memory
Streamer:
No need for
transient / persistent
classes
Buffer
30
sockets
Net File
http
Web File
XML
XML File
SQL
DataBase
Local
File on
disk
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Object Oriented Concepts
31
 Class: the description of a “thing” in the system
 Object: instance of a class
TObject
 Methods: functions for a class
IsA
Event


Members: a “has a”
relationship to the class.
Inheritance: an “is a”
relationship to the class.
HasA
Jets
HasA
HasA
Tracks
HasA
Momentum
HasA
EvNum
HasA
Charge
Segments
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
TFile / TDirectory
32


A TFile object may be divided in a hierarchy of
directories, like a Unix file system.
Two I/O modes are supported
 Key-mode
(TKey). An object is identified by a name (key),
like files in a Unix directory. OK to support up to a few
thousand objects, like histograms, geometries, mag fields,
etc.
 TTree-mode to store event data, when the number of events
may be millions, billions.
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Self-describing files
33

Dictionary for persistent classes written to the file.
 ROOT

Support for Backward and Forward compatibility
 Files

files can be read by foreign readers
created in 2001 must be readable in 2015
Classes (data objects) for all objects in a file can be
regenerated via TFile::MakeProject
root[0] TFile* f = Tfile::Open("demo.root");
root[1] f.MakeProject("dir", "*", "new++");
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Example of key mode
34
void keywrite() {
TFile f("keymode.root", "new");
TH1F h("hist", "test",100,-3,3);
h.FillRandom("gaus",1000);
h.Write();
}
(1) Open a new file (write mode)
(2) Build and fill a histogram
(3) Write it to the active file
(1’) Open an existing file in read
only mode (default)
(2’) Find object by name
void keyRead() {
TFile f(“keymode.root”);
TH1F *h = (TH1F*)f.Get(“hist”);
h.Draw();
}
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Browse file content
35
$ root $ROOTSYS/test/RootBrowser/demos.root
root[0] new Tbrowser;
A Root file demos.root
with no directories
Different objects
stored and
accessible by name
Double click to draw
graphic objects
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Browse file content
36
$ root $ROOTSYS/test/RootBrowser/demos.root
root[0] new Tbrowser;
A Root file demos.root
with no directories
Different objects
stored and
accessible by name
Double click to draw
graphic objects
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
37
ROOT Trees
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp.
de Partículas
Why Trees ?
38






Trees have been designed to support very large
collections of objects. The overhead in memory is in
general less than 4 bytes per entry.
Trees allow direct and random access to any entry
(sequential access is the best)
Trees have branches and leaves. One can read a
subset of all branches.
High level functions like TTree::Draw loop on all entries
with selection expressions.
Trees can be browsed via TBrowser
Trees can be analyzed via TTreeViewer
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Memory <--> Tree
Each Node is a branch in the Tree
39
Memory
0
T.GetEntry(6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
T.Fill()
T
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Inspecting a tree
40
root [0] TFile* f = TFile::Open("/opt/root/tutorials/mlp/mlpHiggs.root")
root [1] f->ls()
TFile**
/opt/root/tutorials/mlp/mlpHiggs.root
TFile*
/opt/root/tutorials/mlp/mlpHiggs.root
KEY: TTree
bg_filtered;1
Filtered background (WW) events
KEY: TTree
sig_filtered;1
Filtered signal events
root [2] bg_filtered->Print()
******************************************************************************
*Tree
:bg_filtered: Filtered background (WW) events
*
*Entries :
1350 : Total =
42606 bytes File Size =
27556 *
*
:
: Tree compression factor =
1.00
*
******************************************************************************
*Br
0 :acolin
: acolin/F
*
*Entries :
1350 : Total Size=
25838 bytes One basket in memory
*
*Baskets :
0 : Basket Size=
32000 bytes Compression=
1.00
*
*............................................................................*
*Br
1 :acopl
: acopl/F
*
*Entries :
1350 : Total Size=
25832 bytes One basket in memory
*
*Baskets :
0 : Basket Size=
32000 bytes Compression=
1.00
*
…………
root [3] bg_filtered->StartViewer()
File name : /opt/root/tutorials/mlp/mlpHiggs.root
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Inspecting a tree (TreeViewer)
41
Double click on
branch to draw a
histogram from its
values
Drag and drop
branches to X
and Y, then
click here and
draw 2D histos
More
functionality
available: Cuts,
Draw options,
scanning,
saving
session,…
Check here
Use this to add a cut
We can also use
just TBrowser
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
class Event : public Something
Writing/Reading a Tree
Header
{
fHeader;
std::list<Vertex*> fVertices;
std::vector<Track> fTracks;
42
TOF
Calor
int WriteTree() {
*fCalor;
}
Event *event = 0;
Event.h
TFile f("demo.root", "recreate");
int split = 99;
fTOF;
//maximnum split
TTree *T = new TTree("T", "demo Tree");
T->Branch("event", "Event",&event,split);
int ReadTree() {
Event *event = 0;
for (int ev=0;ev<1000;ev++) {
TFile f(“demo.root”);
event = new Event(…);
TTree *T = (TTree*)f.Get”T”);
T->Fill();
T->SetBranchAddress(“event”,&event);
delete event;
Long64_t N = T->GetEntries();
}
for (Long64_t ev=0;ev<N;ev++) {
t->AutoSave();
T->GetEntry(ev);
}
// do something with event
event->…
}
}
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
TTree Selection Syntax
43
Prints the first 8 variables of the tree.
MyTree->Scan();
Prints all the variables of the tree.
Specific variables of the tree can be explicit selected by list them in
column separated list:
MyTree->Scan("*");
Prints the values of var1, var2 and var3.
A selection can be applied in the second argument:
MyTree->Scan("var1:var2:var3");
Prints the values of var1, var2 and var3 for the entries where var1 is
exactly 0.
MyTree->Scan("var1:var2:var3", "var1==0");
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Drawing tree variables
44

Draw a given variable:
MyTree->Draw("var1");

Draw a given variable applying a cut
MyTree->Draw("var1", "var2>10");

Draw a 2D histogram from 2 variables with a cut
MyTree->Draw("var1:var2", "var3==0");

Draw and store in a histogram (myh2d):
MyTree->Draw("var1:var2 >> myh2d", "", "surf2");

One can also select the number of entries to process and
the starting event to read
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Data Volume & Organisation
45
100MB
1
1GB
1
10GB
100GB
5
50
1TB
500
10TB
100TB
5000
50000
1PB
TTree
TChain
A TFile typically contains 1 TTree
A TChain is a collection of TTrees or/and TChains
A TChain is typically the result of a query to the file catalogue
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Chains of Trees
46


A TChain is a collection of Trees.
Same semantics for TChains and TTrees
{
//creates a TChain to be used by the h1analysis.C class
//the symbol H1 must point to a directory where the H1 data sets
//have been installed
TChain chain("h42");
chain.Add("$H1/dstarmb.root");
chain.Add("$H1/dstarp1a.root");
chain.Add("$H1/dstarp1b.root");
chain.Add("$H1/dstarp2.root");
}
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
47
Fitting
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp.
de Partículas
Fit techniques in ROOT
48

Two ways of fitting a o fit a histogram, graph,…
 Fit
Panel on a visible histogram via the context menu
 Good
for prototyping
 Object needs to be drawn in a pad before the Fit Panel is
invoked
 Fit
method in TH* and TGraph classes
 More
powerful and is used in scripts and programs.
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Fit method
49
void Fit(const char *fname, Option_t *option,
Option_t *goption, Axis_t xxmin, Axis_t xxmax)

fname: Name of the fitted function.


It may be one of ROOT pre-defined function names or a user-defined function
Some predefined functions are:




"gaus“: gaussian function with 3 parameters:
f(x) = p0*exp(-0.5*((x-p1)/p2)^2))
"expo“: Exponential with 2 parameters:
f(x) = exp(p0+p1*x)
"polN“: polynomial of degree N:
f(x) = p0 + p1*x + p2*x2 +...
"landau“: Landau function with mean and sigma

option: Many possible values. Read documentation
http://root.cern.ch/root/html/TH1#TH1:Fit
goption: Draw options. Same as in Draw
xxmin, xxmax: Fit interval

Also possible to fit to function objects (ex. TF1) or user defined functions.


Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Fit panel
50
Function name
Fitting function
Set initial values of parameters
Do not overwrite previous fits
Select fit range
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
RooFit
51

The RooFit library provides a toolkit for modeling the expected
distribution of events in a physics analysis.




It is primarily designed as a particle physics data analysis
tool…



Models can be used to perform unbinned maximum likelihood fits
Produce plots
And generate "toy Monte Carlo" samples for various studies.
…but its general nature and open architecture make it useful for
other types of data analysis also
Originally developed by BaBar it is now part of ROOT
distribution
Detailed documentation in
http://root.cern.ch/drupal/content/roofit
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Exercise: fitting
52

Get your script graph2.C from previous exercises.



At first fit the graph with the GUI
1.
2.
3.





Select the graph with the mouse
Right-click to bring up the context menu.
Select FitPanel.
Use the slider to fit the first part with a polynomial of degree 4…
…and the second part with a polynomial of degree 1


We would like to add a fit for each section of the graph.
Look at the TGraph::Fit method on the TGraph class description page.
Use the "Add to list" and “SAME" drawing option to see both fits on the graph
Now try to do the same within the script by using the Fit method
You can access the list of fitted functions for the graph with:
TList *lfits = gr->GetListOfFunctions();
lfits->ls();
To get each of the functions fitted and to print the parameter values you can do
TF1* f1 = (TH1F*) lfits->At(0);
f1->Print();
See $ROOTSYS/tutorials/fit/multifit.C for an example on how to fit histograms in multiple sub ranges

Can you fit the last bit of the histogram?
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Práctica 1
53

Descargarse el fichero
http://www.hep.uniovi.es/iglez/Clases/Valencia/ROOT/Practica/descargar.tgz






y descomprimirlo
Abrir un TTree y examinar sus variables:
Buscar y abrir uno de los ficheros root
Explorar el arbol “h1000”
Dividir el canvas en 2 mitades
Pintar la variables It4tag y Pcomb en escala
logaritmica
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Práctica 2
54

Crear un puntero al TTree del archivo abierto:
mytree = (TTree *) gROOT->FindObject("h1000");

Pintar la componente 5 de la variable vector Pcomb
 Establecer

Superponer en la misma grafica la componente 4 de la
variable vector Pcomb
 Cambiar

escala logarítmica
a color rojo la ultima grafica superpuesta
Pintar la variable Xsum4c4 si abs(Xdiff4c4)< 10
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Práctica 3
55

Usando la clase Xmass, pintar con la macro ejemplo.C
las distribuciones de suma de masas de dijet con menor
diferencia de masas iguales, para datos y fondos
QCD, WW+ZZ, a distintos niveles de corte de la
variable pcomb[5] : 0, 0.1, 0.5 y 2
root [0] .L Xmass.C
root [1] .x ejemplo.C

Guardar la grafica en formato .C, .eps y .png
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Resultado
56
56
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Ejercicios
57

Pintar una leyenda que describa el tipo de fondos y datos

Dibujar la estadística de datos y fondos

Resolver el problema del “memory leak”

La evaluación de esta parte de la asignatura se hará en
base a la presentación de estos ejercicios
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Deberíais obtener algo así…
58
58
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

Documentos relacionados