Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
A Brief ROOT Tutorial
Michael BetancourtMassachusetts Institute of Technology
NEPPSR 2009
“...the insane root That takes the reason prisoner.”
-Shakespeare
Text
A Brief ROOT Tutorial 1
What is ROOT?
Text
A Brief ROOT Tutorial 1
What is ROOT?
‣ NOT a program
Text
A Brief ROOT Tutorial 1
What is ROOT?
‣ NOT a command line interpreter
‣ NOT a program
Text
A Brief ROOT Tutorial 1
What is ROOT?
‣ NOT a command line interpreter
‣ NOT a program
‣ A collection of C++ classes
Text
A Brief ROOT Tutorial 2
What is CINT?
‣ CINT is a dynamic C++ interpreter, in other words it allows one to run C++ code without having to compile it
Text
A Brief ROOT Tutorial 2
What is CINT?
‣ CINT is a dynamic C++ interpreter, in other words it allows one to run C++ code without having to compile it
‣ Advantages: Quick prototyping and testing
Text
A Brief ROOT Tutorial 2
What is CINT?
‣ CINT is a dynamic C++ interpreter, in other words it allows one to run C++ code without having to compile it
‣ Advantages: Quick prototyping and testing
‣ Disadvantages: Slow, awkward properties, limited support outside of ROOT classes
Text
A Brief ROOT Tutorial 3
Some Quick Notes on C++
‣ Common mistake: trying to learn “ROOT” without first learning basic C/C++
Text
A Brief ROOT Tutorial 4
Pointers
Value Address
&
*
Variable Pointer
Text
A Brief ROOT Tutorial 5
Pointers
double variable = 10;double *pointer = &variable;
variable = 10pointer = &variable = 0x482a8e94
*pointer = variable = 10
Text
A Brief ROOT Tutorial 6
Classes
class meal{
public:
meal(unsigned int nServings);~meal();
addIngredient(ingredient newIngredient);prepareMeal();serveMeal();
private:
unsigned int mNumIngredients;vector mIngredients;
};
Text
A Brief ROOT Tutorial 7
Classes In Practice
meal chickenPipian(2);
chickenPipian.addIngredient(tomatillos);...chickenPipian.addIngredient(salt);
chickenPipian.prepareMeal();chickenPipian.serveMeal();
Text
A Brief ROOT Tutorial 8
Classes In Practice
meal *chickenPipian = new meal(2);
(*chickenPipian).prepareMeal();
chickenPipian->prepareMeal();
delete chickenPipian;
Text
A Brief ROOT Tutorial 9
References
‣ Bjarne Stroustrup, The C++ Programming Language
‣ Steve Oualline, Practical C++ Programming
‣ Scott Meyers, Effective C++
‣ http://cplusplus.com
http://cplusplus.comhttp://cplusplus.com
Text
A Brief ROOT Tutorial 10
Common ROOT Classes
TFile inputFile(“input.root”, “read”);
inputFile.ls();
TFile outputFile(“output.root”, “recreate”);
outputFile.Write();outputFile.Close();
Text
A Brief ROOT Tutorial 11
Common ROOT Classes
TTree t(“treeName”, “Tree Title”);t.Branch(“varName”, varAddress, “varName/D”);t.Fill();t.Write();
TTree *t = (TTree*)f.Get(“treeName”);t->Print();
t->SetBranchAddress(“varName”, varAddress);t->GetEntry(n);
Text
A Brief ROOT Tutorial 12
Common ROOT Classes
TH1F histogram(“histName”, “Hist Title”, 100, 0, 50);histogram.Sumw2();
histogram.Fill(variable);
histogram.Draw();
Text
A Brief ROOT Tutorial 13
References
‣ ROOT Class Browser
‣ http://root.cern.ch/root/html522/
‣ http://root.cern.ch/root/html522/TTree.html
‣ ROOT Users’ Guide
‣ http://root.cern.ch/drupal/content/users-guide
http://root.cern.ch/root/html522/http://root.cern.ch/root/html522/http://root.cern.ch/root/html522/TTree.htmlhttp://root.cern.ch/root/html522/TTree.htmlhttp://root.cern.ch/drupal/content/users-guidehttp://root.cern.ch/drupal/content/users-guide
Text
A Brief ROOT Tutorial 14
One Last Note
‣ PyRoot
‣ http://root.cern.ch/root/HowtoPyROOT.html
http://root.cern.ch/root/HowtoPyROOT.htmlhttp://root.cern.ch/root/HowtoPyROOT.html