root_helpers¶
ROOT required
This module requires PyROOT. See checking ROOT availability.
analysis_helpers.root_helpers
¶
is_root_available()
¶
require_root()
¶
Raise a clear exception if PyROOT is not available.
LoadCompiledLibraries(libraries=None)
¶
Load C++ Compiled libraries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
libraries
|
list
|
A list of C++ compiled library paths. Defaults to None. |
None
|
Source code in src/analysis_helpers/root_helpers.py
DefineTree(variables, name='tree', title='a tree for my variable')
¶
Given a set of variables in the format of a dictionary, a ROOT TTree object is created.
The variables dictionary should have the form
vname: the name of the variable,
* vtype: the type of the variable, one of the ROOT2ArrayTypes.keys()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
dict
|
a dictionary with variable names and their respective type. |
required |
name
|
str
|
the name of the ROOT TTree object. Defaults to 'tree'. |
'tree'
|
title
|
str
|
the title of the ROOT TTree objects. Defaults to 'a tree for my variable'. |
'a tree for my variable'
|
Source code in src/analysis_helpers/root_helpers.py
GetTreeVariables(t)
¶
Returns the dictionary of variables and types from TTree branches
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TTree
|
The ROOT TTree object |
required |
Source code in src/analysis_helpers/root_helpers.py
SaveTree(t, fname)
¶
Save a TTree into a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TTree
|
A ROOT TTree object |
required |
fname
|
str
|
The file name |
required |
Source code in src/analysis_helpers/root_helpers.py
SaveTrees(trees, fname)
¶
Save many TTrees into a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees
|
list
|
a list of TTree objects |
required |
fname
|
str
|
the file name |
required |
Source code in src/analysis_helpers/root_helpers.py
ReduceTree(t, fname, nentries=None, cut='', firstentry=0, options='')
¶
Reduce a TTree to a new one and save it to a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
TTree
|
A ROOT TTree object |
required |
fname
|
str
|
The file name |
required |
nentries
|
int
|
The number of entries to copy. Defaults to r.kMaxEntries. |
None
|
cut
|
str
|
A selection to be made on the ROOT TTree branches. Defaults to ''. |
''
|
firstentry
|
int
|
The first entry to copy. Defaults to 0. |
0
|
options
|
str
|
Options to run the |
''
|
Source code in src/analysis_helpers/root_helpers.py
ConvertTChain2DataFrame(ch, columns=None)
¶
Convert a TChain to pandas.DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ch
|
TChain
|
a ROOT TChain object |
required |
columns
|
list
|
list of variables to save in the data frame. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
pandas.DataFrame: the output data frame |
Source code in src/analysis_helpers/root_helpers.py
Canvas(name='c1', width=600, height=600, title='')
¶
A dictionary with a ROOT TCanvas and extra objects
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the TCanvas. Defaults to 'c1'. |
'c1'
|
width
|
int
|
the width of the TCanvas. Defaults to 600. |
600
|
height
|
int
|
the height of the TCanvas. Defaults to 600. |
600
|
title
|
str
|
the title of the TCanvas. Defaults to ''. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
{'canvas': ROOT.TCanvas, 'extra': |
Source code in src/analysis_helpers/root_helpers.py
SaveCansAsPdf(pdfName, cans)
¶
Save a list of TCanvas objects into a single PDF file
Source code in src/analysis_helpers/root_helpers.py
TTree2Array(tree, leaves=None)
¶
Transform a ROOT TTree into a numpy array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
TTree
|
the ROOT TTree object |
required |
leaves
|
list
|
the list of leaves to be transformed. Defaults to all leaves. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
array |
The numpy array |
Source code in src/analysis_helpers/root_helpers.py
ROOT2MPLLineStyle(lineStyle)
¶
A function to convert ROOT line styles to Matplotlib line styles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lineStyle
|
int
|
ROOT line style index |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
matplotlib line style |
Source code in src/analysis_helpers/root_helpers.py
ROOT2MPLColor(color)
¶
A function to convert ROOT colors to Matplotlib colors
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
TColor
|
ROOT TColor object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
matplotlib color name |
Source code in src/analysis_helpers/root_helpers.py
ROOT2MPLText(text)
¶
A function to convert ROOT text to Matplotlib text
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
matplotlib text |
Source code in src/analysis_helpers/root_helpers.py
save_np_histograms_uproot(histograms_dict, filename)
¶
Save multiple numpy histograms to a ROOT file with uproot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
histograms_dict
|
dict
|
A dictionary of histograms to save. |
required |
filename
|
str
|
The name of the output ROOT file. |
required |
Source code in src/analysis_helpers/root_helpers.py
load_np_histograms_uproot(filename)
¶
Load numpy histograms from a ROOT file with uproot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the input ROOT file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary of histograms. |