1 / 68

ROOT

ROOT. An object oriented HEP analysis framework. Day 2 http://www-pat.fnal.gov/root/ The ROOT system website is at: http://root.cern.ch/. Day 2. Last time GUI, Command line Today Command Line (CINT) Scripts (CINT & ACLiC) Exercises Functions and Fitting TreeViewer. Command line.

allisonm
Download Presentation

ROOT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ROOT An object oriented HEP analysis framework. Day 2 http://www-pat.fnal.gov/root/ The ROOT system website is at: http://root.cern.ch/ ROOT Day 2, Suzanne Panacek

  2. Day 2 • Last time • GUI, Command line • Today • Command Line (CINT) • Scripts (CINT & ACLiC) • Exercises • Functions and Fitting • TreeViewer ROOT Day 2, Suzanne Panacek

  3. Command line • Environment Settings • Command types • CINT Commands • Global Variables • TObject ROOT Day 2, Suzanne Panacek

  4. Environment Settings • Environment setting file: • $ROOTSYS/etc/system.rootrc • looks first in current directory for .rootrc • second in $HOME/.rootrc • third in $ROOTSYS/etc/system.rootrc • Find the current settings • root[] gEnv->Print() ROOT Day 2, Suzanne Panacek

  5. Environment Settings (cont.) The .rootrc file: • The Macro Path • Unix.*.Root.MacroPath:.:$(HOME)/myRootMacros • Options in .rootrc • Root.ShowPath: false History File • $HOME/.root_hist Automatically Executing Macros • rootlogon.C • rootlogoff.C • rootalias.C ROOT Day 2, Suzanne Panacek

  6. Command Line Options • > root -/? • Usage: root [-l] [-b] [-n] [-q] [file1.C ... fileN.C] • Options: • -b : run in batch mode without graphics • -n : do not execute logon and logoff macros as specified in .rootrc • -q : exit after processing command line macro files • -l : do not show splash screen ROOT Day 2, Suzanne Panacek

  7. Three Types of Commands • CINT commands start with “.” • root[0].? • this command will list all the CINT commands • root[1].X [filename] • load [filename] and execute function [filename] • root[2].L [filename] • load [filename] • SHELL commands start with “.!” for example:root[3] .! ls ROOT Day 2, Suzanne Panacek

  8. Three Types of Commands 3. C++ syntax (almost) root [0] TBrowser *b = new TBrowser()or root [0] TBrowser *b = new TBrowser(); The optional Semicolon: Leave off the semicolon to see the return value of the command. root [0] 23+5 // show return value (int)28 root [1] 23+5; // no return value root [2] ROOT Day 2, Suzanne Panacek

  9. Command Line Help • Use the Tab feature to get help … root [0] b = new TB <TAB> root [1] b = new TBrow<TAB> root [2] b = new TBrowser(<TAB> • Find List of Methods • Find Parameter list ROOT Day 2, Suzanne Panacek

  10. Coding Conventions Based on Taligent • Classes begin withT TTree, TBrowser • Non-class types end with_t Int_t • Data members begin with f fTree • Member functions begin with a capital Loop() • Constants begin with k kInitialSize, kRed • Static variables begin with g gEnv • Static data members begin with fg fgTokenClient ROOT Day 2, Suzanne Panacek

  11. CINT Types ROOT Day 2, Suzanne Panacek

  12. CINT Extensions to C++ • 1. Declaration can be omitted • f = new TFile("Example.root") • 2. "." notation rather than "->"f.ls() • 3. Search for an object by its name • TH1F *smallHisto = new TH1F ("small","fPx 100",100,-5,5); small->Draw(); Warning: These will not work in compiled code! ROOT Day 2, Suzanne Panacek

  13. CINT Commands • [expression] evaluates the expression • root[3] 3*4 • (int)12 • .files show loaded source files • .class [name] show class definition • .g prints all objects in the root session • .ls ls on current directory • .pwd list the current directory, canvas, and style. ROOT Day 2, Suzanne Panacek

  14. Demo on CINT Commands .class root [0] .L $ROOTSYS/test/libEvent.so root [1] .class Event .g root [2] .g... 0x104c7560 Event e , size=56 0x0 private: Int_t fNtrack 0x0 private: Int_t fNseg 0x0 private: Int_t fNvertex ... ROOT Day 2, Suzanne Panacek

  15. CINT Multi-line Command Start with "{" For example: root [] { end with '}'> Int_t j = 0; end with '}'> for (Int_t i = 0; i < 3; i++) end with '}'> { end with '}'> j= j + i; end with '}'> cout <<"i = " <<i<<", j = " <<j<<endl; end with '}'> } end with '}'> } i = 0, j = 0 i = 1, j = 1 i = 2, j = 3 ROOT Day 2, Suzanne Panacek

  16. Global Variables • gRandom • gRandom->Gaus(1,2) • You can replace the random generator with your own:delete gRandom;gRandom = new TRandom2(0); //seed=0 • gFile • gFile->GetName() • gDirectory • gDirectory->GetName() • gSystem • gSystem->HostName() ROOT Day 2, Suzanne Panacek

  17. gROOT • global ROOT session object • gROOT->GetListOf< list type >(); • gROOT->LoadMacro(); • gROOT->Time(); • gROOT->ProcessLine() ROOT Day 2, Suzanne Panacek

  18. gROOT->FindObject() TH1F *smallHisto = new TH1F ("small","fPx 100",100,-5,5); • "small" is the Object Name gROOT->FindObject("small") (class TObject*)0x104c7528 • "smallHisto" is the Variable Name gROOT->FindObject("smallHisto") (class TObject*)0x0// null pointer • FindObject needs the Object Name. ROOT Day 2, Suzanne Panacek

  19. gROOT->FindObject() ++ FindObject returns a pointer to TObject. This generates an error: gROOT->FindObject("small")->GetBinContent(2) This is OK: gROOT->FindObject("small")->ClassName() TH1F* histo=(TH1F*) gROOT->FindObject("small") histo->GetBinContent(2) ROOT Day 2, Suzanne Panacek

  20. gROOT->FindObject() cont. Due to CINT magic this is also OK: TH1F *smallHisto = new TH1F ("small","fPx 100",100,-5,5); small->GetBinContent(2); • CINT implicitly executes a FindObject("small") • Casts it to the correct class • Creates a variable called "small" of the correct class Warning: This will not work in compiled code! ROOT Day 2, Suzanne Panacek

  21. Demonstration: FindObject FindObject(): root [3] f = TFile("Example.root") root [4] .ls root [5] gROOT->FindObject("myTree") root [6] myTree ROOT Day 2, Suzanne Panacek

  22. TObject: The Mother of all Root objects • Defines protocol and default behavior for all objects in ROOT. • I/O • Drawing/Painting • TObjects can be stored in collection classes. • Introspection, Reflection, Runt Time Type Identification ROOT Day 2, Suzanne Panacek

  23. TObjectRTTI • RTTI = the ability of a class to reflect upon itself or to "look inside itself" at run time. • TClass implement RTTI • To get the TClass from a TObject descendent:obj->Class() • TClass can find the: • Methods • Data members • Base classes ROOT Day 2, Suzanne Panacek

  24. Summary (Command Line) • Environment Settings • Command types • CINT Commands • Global Variables • TObject ROOT Day 2, Suzanne Panacek

  25. Writing Scripts • Named and Un-named Scripts • Debugging • ACLiC ROOT Day 2, Suzanne Panacek

  26. Scripts • Un-named Script • Start with "{" and end with "}" • All variables are in the global scope • No class definitions • No function declarations • No parameters • Named Script • C++ functions • Scope rules follow standard C++ • Function with the same name as the file is executed with a .x Parameters Class definitions (derived from a compiled class at your own risk) ROOT Day 2, Suzanne Panacek

  27. Scripts Examples • Un-named Script: hello.C { cout << "Hello" << endl; } • Named Script:say.C void say(char * what = "Hello") { cout << what << endl; } • Executing the Named Script root [3] .x say.C Hello root [4] .x say.C("Hi there") Hi there ROOT Day 2, Suzanne Panacek

  28. Resetting the Environment • gROOT->Reset() • Calls destructors of all objects created on the stack • Objects on Heap are not deleted, but pointer variable is disassociated ROOT Day 2, Suzanne Panacek

  29. Debugging: Stepping .s set the step mode to step into function .S set the step mode to go over function or loop .e continue to end of the function .c continue to next breakpoint .c 45 continue to line 45 .p <var> print the value of var ROOT Day 2, Suzanne Panacek

  30. Debugging: Breakpoints .trace MyClass prints the executing code to window .deltrace MyClass removes the trace .break MyClass breaks at each method of MyClass .delbreak MyClass removes the break .b 34 sets a break point at line 34 .db 34 removes the break point at line 34 ROOT Day 2, Suzanne Panacek

  31. Debugging: Inspecting DrawClass() Graphic list of methods including ancestors Inspect() Draw the current contents of an object Dump() Lists the current contents of an object gDebug = 1 Prints debugging information ROOT Day 2, Suzanne Panacek

  32. Tracking Memory Leaks • Counting Objects and Memory use • In the .rootrc or system.rootrc file: Root.MemStat: 1 Root.ObjectStat:1 • Print the Object count and Memory use gObjectTable->Print(); ROOT Day 2, Suzanne Panacek

  33. Tracking Memory Leaks+ • Example output: Before .x FirstContour.C: count on heap size total size heap size Total: 1,079 1,046 3,160 49,99245,824 After: Total: 1,783 1,749 17,920 118,912 114,568 • Put gObjectTable->Print() before and after code segment in your script to find memory leaks. ROOT Day 2, Suzanne Panacek

  34. ACLiC: Automatic Compiler of Libraries for CINT • Use an external compiler to create a shared library from a macro. • Use root [0] .L MyMacro.C++ Always recompile root [0] .L MyMacro.C+ Recompile as needed ROOT Day 2, Suzanne Panacek

  35. ACLiC Use Restriction: can not use path name with .L .L ../root_base/MyMacro.C+ Instead do: gSystem->cd("../directory"); gSystem->CompileMacro("MyMacro.C") Options are: k : keep the shared library after the session end. f : force recompilation. To set the Include path: .include "-I$HOME/mypackage/include"; ROOT Day 2, Suzanne Panacek

  36. ACLiC Advantages • Advantages : • syntax checking • about five times faster • full C++ feature set • Disadvantage: • On KCC, you can load each C++ shared library only once ROOT Day 2, Suzanne Panacek

  37. ACLiC Demo • .L ScriptCompilerDemo.C++ root [0] gROOT->Time() root [1] .L ACLiCDemo.C++ root [2] .files root [3] Demo() • Compare performance with CINT root [0] gROOT->Time() root [1] .L ACLiCDemo.C root [3] Demo() ROOT Day 2, Suzanne Panacek

  38. Summary (Scripts) • Named and Un-named Scripts • Debugging • ACLiC ROOT Day 2, Suzanne Panacek

  39. Getting started with the Exercises • Go to: http://patwww.fnal.gov/root/class/Setup.htm for setup instructions using Reflection and ssh on fcdfsgi2 and d0mino and minos1. • Find the exercises on line at: http://patwww.fnal.gov/root/class/exercises.htm ROOT Day 2, Suzanne Panacek

  40. Exercise Overview • Session A • Use ROOT command line • Write a named and un-named script • Use the GUI to create objects and change their attributes • Save your canvas to a PostScript file • Fit a graph • Session B • Fit and rotate a histogram • Use the Object Browser and the Tree Viewer • Make a profile and contour graphs • Build an event list from a cut • Fill a histograms with random numbers • Use ACLiC ROOT Day 2, Suzanne Panacek

  41. Exercise Session C • Session C: • Study an example analysis from DESY • Learn about the TTree::MakeSelector method to automatically create a class that loops over each entry in a tree. • Save and retrieve a canvas to and from a ROOT file • Compute the integral of a histogram • Compute the integral of a function within a range ROOT Day 2, Suzanne Panacek

  42. Solutions to the Exercises http://patwww.fnal.gov/root/class/solutions.htm ROOT Day 2, Suzanne Panacek

  43. ROOT contacts at Fermi Philippe Canal , x2545 pcanal@fnal.gov Suzanne Panacek, x8334 spanacek@fnal.gov Jeff Kallenbach, x2210 • jeffk@fnal.gov ROOT Day 2, Suzanne Panacek

  44. Mailing Lists • the ROOT mailing list: roottalk@root.cern.ch • archives: http://root.cern.ch/root/roottalk/AboutRootTalk.html • Fermilab mailing list: about-root@fnal.gov • archives: http://listserv.fnal.gov/archives/about-root.html ROOT Day 2, Suzanne Panacek

  45. Functions and Fitting • Function Objects (TF1) • Three constructors for TF1 • User Defined Functions • Fitting • Fit() • Fitting with a user defined function • Fitting subranges and combining functions • Demonstration of background and signal function ROOT Day 2, Suzanne Panacek

  46. Function Objects (TF1) • Built in function objects • see this link for a full list of built in functions http://root.cern.ch/root/html/TFormula.html#TFormula:TFormula • use the Fit Panel • Creating your own function objects • TF1, TF2, TF3 • Three Signatures for the TF1 constructor ROOT Day 2, Suzanne Panacek

  47. TF1 Constructors 1. A C++ like expression using x with a fixed set of operators and functions defined in TFormula TF1 *f1 = new TF1("f1","sin(x)/x",0,10); f1->Draw(); TF1 *f2 = new TF1("f2","f1 * 2",0,10); ROOT Day 2, Suzanne Panacek

  48. TF1 Constructors (cont.) • 2. Same as the previous TF1 with Parameters • Call the constructor with parameter indices • TF1 *f1 = new TF1 • ("f1","[0]*x*sin( [1]*x)",-3,3);See TFormula for valid expressions • Set the parameters explicitly • f1->SetParameter(0,10);f1->SetParameter(1,5);f1->Draw(); ROOT Day 2, Suzanne Panacek

  49. TF1 Constructors (cont.) • 3. Use a defined function • Define a functionDouble_t MyFunction(Double_t *x, Double_t *par){ Float_t xx = x[0]; Double_t val = TMath::Abs(par[0]*sin(par[1]*xx)/xx); return val;} • TF1 constructor TF1 *f1 = new TF1("f1",MyFunction,0,10,2); • NOTE: The 2 is the number of parameters in MyFunction. • Set the parametersf1->SetParameters(2,1); ROOT Day 2, Suzanne Panacek

  50. Fitting To fit a histogram: TF1 *fn1 = new TF1 • ("f1","[0]*x*sin([1]*x)",-3,3); • f1->SetParameters(10,5);aHistogram->Fit("f1"); //name • aHistogram->Fit(fn1); // pointer ROOT Day 2, Suzanne Panacek

More Related