La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

ROOT TOOLKIT (Graphics, I/O, Data Structures) Técnicas Fundamentales de Simulación, Reconstrucción y Análisis de Datos en Física Experimental de Partículas.

Presentaciones similares


Presentación del tema: "ROOT TOOLKIT (Graphics, I/O, Data Structures) Técnicas Fundamentales de Simulación, Reconstrucción y Análisis de Datos en Física Experimental de Partículas."— Transcripción de la presentación:

1 ROOT TOOLKIT (Graphics, I/O, Data Structures) Técnicas Fundamentales de Simulación, Reconstrucción y Análisis de Datos en Física Experimental de Partículas Isidro González Caballero ( Universidad de Oviedo) Valencia, 07-11/05/20102 7 7

2 Graphics & GUI Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 2

3 TPad: main graphics container 3 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas Hello root[0] TLine line(.1,.9,.6,.6) root[1] line.Draw() root[2] TText text(.5,.2,”Hello”) root[3] 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. Only objects deriving from TObject may be drawn in a pad Root Objects or User objects

4 Basic Primitives 4 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas TButton TLineTArrow TEllipse TCurvyLine TPaveLabel TPave TDiamond TPavesText TPolyLine TLatex TCrown TMarker TText TCurlyArc TBox

5 5 Full LateX support on screen and postscript TCurlyArc TCurlyLine TWavyLine and other building blocks for Feynmann diagrams Formula or diagrams can be edited with the mouse Feynman.C latex3.C Lots of examples in /opt/root/tutorials/graphics Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

6 Graphs 6 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas TGraph(n,x,y) TCutG(n,x,y) TGraphErrors(n,x,y,ex,ey) TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh) TMultiGraph $ROOTSYS/tutorials/graphs/gerrors2.C

7 Graphics examples Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 7

8 More graphics examples 8 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

9 More graphics examples 9 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

10 10

11 Graphics (2D-3D) 11 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas “SURF” “LEGO” TF3 TH3 TGLParametric

12 ASImage: Image processor Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 12

13 GUI (Graphical User Interface) Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 13

14 Canvas tool bar/menus/help 14 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas Select Toolbar to activate the primitives toolbar Click on Ev. Statusbar to activate some info at the bottom Select Toottip to activate some info when overlying objects $ROOTSYS/tutorials/fit/fit1.C

15 Object editor 15 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas Click on any object to show its edition options Select Editor to activate the objects edition panel You can save it as file.C to explore the C++ command to change options

16 GUI C++ code generator  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 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 16 // 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); root [0].x example.C

17 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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. The GUI Builder

18 More GUI Examples 18 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas $ROOTSYS/tutorials/gui $ROOTSYS/test/RootShower $ROOTSYS/test/RootIDE

19 Geometry Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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)

20 OpenGL Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 20 see $ROOTSYS/tutorials/geom

21 Math libraries 21 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

22 Peak Finder + Deconvolutions Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 22 TSpectrum

23 Fitters Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 23 Minuit Fumili LinearFitter RobustFitter Roofit

24 Fit Panel 24 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

25 Roofit: a powerful fitting framework 25 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas see $ROOTSYS/tutorials/fit/RoofitDemo.C

26 Ejercicio propuesto 1  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 http://root.cern.ch/root/html/TF1.html  You will see several constructors, one of which has four arguments.  Create the following 1-D function and draw it with:  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: Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 26 root [0] TF1 f1("f1","sin(x)/x",0,10); root [1] f1.Draw(); root [2] f1. TF1::TF1(const char* name, const char* formula, Double_t xmin=0, Double_t xmax=1);

27 Ejercicio propuesto 2  Find the class description page for TGraph to answer the following questions: http://root.cern.ch/root/html/TGraph.html 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 6 th 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 27

28 Ejercicio propuesto 3  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 28

29 Input/Output Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 29

30 I/O 30 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas Object in Memory Streamer: No need for transient / persistent classes http sockets File on disk Net File Web File XML XML File SQL DataBase Local Buffer

31 Object Oriented Concepts Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 31  Members: a “has a” relationship to the class.  Inheritance: an “is a” relationship to the class.  Class: the description of a “thing” in the system  Object: instance of a class  Methods: functions for a class TObject JetsTracksEvNum Momentum Segments Charge Event IsA HasA

32 TFile / TDirectory Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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.

33 Self-describing files Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 33  Dictionary for persistent classes written to the file.  ROOT files can be read by foreign readers  Support for Backward and Forward compatibility  Files 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++");

34 Example of key mode 34 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas void keywrite() { TFile f("keymode.root", "new"); TH1F h("hist", "test",100,-3,3); h.FillRandom("gaus",1000); h.Write(); } void keyRead() { TFile f(“keymode.root”); TH1F *h = (TH1F*)f.Get(“hist”); h.Draw(); } (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

35 Browse file content 35 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas $ 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

36 Browse file content 36 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas $ 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

37 ROOT Trees Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 37

38 Why Trees ? Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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

39 Memory Tree Each Node is a branch in the Tree 39 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas tr 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 T.Fill() T.GetEntry(6) T Memory

40 Inspecting a tree 40 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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: TTreebg_filtered;1Filtered background (WW) events KEY: TTreesig_filtered;1Filtered 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

41 Inspecting a tree (TreeViewer) 41 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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

42 Writing/Reading a Tree 42 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas class Event : public Something { Header fHeader; std::list fVertices; std::vector fTracks; TOF fTOF; Calor *fCalor; } int WriteTree() { Event *event = 0; TFile f("demo.root", "recreate"); int split = 99; //maximnum split TTree *T = new TTree("T", "demo Tree"); T->Branch("event", "Event",&event,split); for (int ev=0;ev<1000;ev++) { event = new Event(…); T->Fill(); delete event; } t->AutoSave(); } int ReadTree() { Event *event = 0; TFile f(“demo.root”); TTree *T = (TTree*)f.Get”T”); T->SetBranchAddress(“event”,&event); Long64_t N = T->GetEntries(); for (Long64_t ev=0;ev<N;ev++) { T->GetEntry(ev); // do something with event event->… } Event.h

43 TTree Selection Syntax Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 43 Prints the first 8 variables of the tree. Prints all the variables of the tree. Specific variables of the tree can be explicit selected by list them in column separated list: Prints the values of var1, var2 and var3. A selection can be applied in the second argument: Prints the values of var1, var2 and var3 for the entries where var1 is exactly 0. MyTree->Scan(); MyTree->Scan("*"); MyTree->Scan("var1:var2:var3"); MyTree->Scan("var1:var2:var3", "var1==0");

44 Drawing tree variables  Draw a given variable:  Draw a given variable applying a cut  Draw a 2D histogram from 2 variables with a cut  Draw and store in a histogram (myh2d):  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 44 MyTree->Draw("var1:var2 >> myh2d", "", "surf2"); MyTree->Draw("var1:var2", "var3==0"); MyTree->Draw("var1", "var2>10"); MyTree->Draw("var1");

45 Data Volume & Organisation Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 45 100MB1GB10GB1TB100GB100TB1PB10TB 11500005000500505 TTree TChain A TChain is a collection of TTrees or/and TChains A TFile typically contains 1 TTree A TChain is typically the result of a query to the file catalogue

46 Chains of Trees Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 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"); }

47 Fitting Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 47

48 Fit techniques in ROOT  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 48

49 Fit method 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 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 49

50 Fit panel 50 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas Fitting function Function name Set initial values of parameters Do not overwrite previous fits Select fit range

51 RooFit  The RooFit library provides a toolkit for modeling the expected distribution of events in a physics analysis.  Models can be used to perform unbinned maximum likelihood fits  Produce plots  And generate "toy Monte Carlo" samples for various studies.  It is primarily designed as a particle physics data analysis tool…  …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 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 51

52 Exercise: fitting Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas 52  Get your script graph2.C from previous exercises.  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.  At first fit the graph with the GUI 1. Select the graph with the mouse 2. Right-click to bring up the context menu. 3. 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  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?

53 Práctica 1  Descargarse el fichero http://www.hep.uniovi.es/iglez/Clases/Valencia/ROOT/Practica/descargar.tgz 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 53 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

54 Práctica 2  Crear un puntero al TTree del archivo abierto: mytree = (TTree *) gROOT->FindObject("h1000");  Pintar la componente 5 de la variable vector Pcomb  Establecer escala logarítmica  Superponer en la misma grafica la componente 4 de la variable vector Pcomb  Cambiar a color rojo la ultima grafica superpuesta  Pintar la variable Xsum4c4 si abs(Xdiff4c4)< 10 54 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

55 Práctica 3  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 55 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

56 56 Resultado 56 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

57 Ejercicios  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 57 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas

58 58 Deberíais obtener algo así… 58 Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas


Descargar ppt "ROOT TOOLKIT (Graphics, I/O, Data Structures) Técnicas Fundamentales de Simulación, Reconstrucción y Análisis de Datos en Física Experimental de Partículas."

Presentaciones similares


Anuncios Google