Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
a3d4381c
Commit
a3d4381c
authored
8 years ago
by
Danilo Piparo
Browse files
Options
Downloads
Patches
Plain Diff
[TDF] Add ranges tutorial
parent
b86f9eae
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tutorials/dataframe/tdf006_ranges.C
+83
-0
83 additions, 0 deletions
tutorials/dataframe/tdf006_ranges.C
with
83 additions
and
0 deletions
tutorials/dataframe/tdf006_ranges.C
0 → 100644
+
83
−
0
View file @
a3d4381c
/// \file
/// \ingroup tutorial_tdataframe
/// \notebook -nodraw
/// This tutorial shows how to express the concept of ranges when working with the TDataFrame.
/// \macro_code
///
/// \date March 2017
/// \author Danilo Piparo
#include
"TFile.h"
#include
"TH1F.h"
#include
"TTree.h"
#include
"ROOT/TDataFrame.hxx"
// A simple helper function to fill a test tree: this makes the example
// stand-alone.
void
fill_tree
(
const
char
*
filename
,
const
char
*
treeName
)
{
TFile
f
(
filename
,
"RECREATE"
);
TTree
t
(
treeName
,
treeName
);
int
b1
;
float
b2
;
t
.
Branch
(
"b1"
,
&
b1
);
t
.
Branch
(
"b2"
,
&
b2
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
b1
=
i
;
b2
=
i
*
i
;
t
.
Fill
();
}
t
.
Write
();
f
.
Close
();
return
;
}
int
tdf006_ranges
()
{
// We prepare an input tree to run on
auto
fileName
=
"tdf006_ranges.root"
;
auto
treeName
=
"myTree"
;
fill_tree
(
fileName
,
treeName
);
// We read the tree from the file and create a TDataFrame.
ROOT
::
Experimental
::
TDataFrame
d
(
treeName
,
fileName
);
// ## Usage of ranges
// Now we'll count some entries using ranges
auto
c_all
=
d
.
Count
();
// This is how you can express a range of the first 30 entries
auto
d_0_30
=
d
.
Range
(
0
,
30
);
auto
c_0_30
=
d_0_30
.
Count
();
// This is how you pick all entries from 15 onwards
auto
d_15_end
=
d
.
Range
(
15
,
0
);
auto
c_15_end
=
d_15_end
.
Count
();
// We can use a stride too, in this case we pick an event every 3
auto
d_15_end_3
=
d
.
Range
(
15
,
0
,
3
);
auto
c_15_end_3
=
d_15_end_3
.
Count
();
// The Range is a 1st class citizen in the TDataFrame graph:
// not only actions (like Count) but also filters and new columns can be added to it.
auto
d_0_50
=
d
.
Range
(
0
,
50
);
auto
c_0_50_odd_b1
=
d_0_50
.
Filter
(
"1 == b1 % 2"
).
Count
();
// An important thing to notice is that the counts of a filter are relative to the
// number of entries a filter "sees". Therefore, if a Range depends on a filter,
// the Range will act on the entries passing the filter only.
auto
c_0_3_after_even_b1
=
d
.
Filter
(
"0 == b1 % 2"
).
Range
(
0
,
3
).
Count
();
// Ok, time to wrap up: let's print all counts!
cout
<<
"Usage of ranges:
\n
"
<<
" - All entries: "
<<
*
c_all
<<
endl
<<
" - Entries from 0 to 30: "
<<
*
c_0_30
<<
endl
<<
" - Entries from 15 onwards: "
<<
*
c_15_end
<<
endl
<<
" - Entries from 15 onwards in steps of 3: "
<<
*
c_15_end_3
<<
endl
<<
" - Entries from 0 to 50, odd only: "
<<
*
c_0_50_odd_b1
<<
endl
<<
" - First three entries of all even entries: "
<<
*
c_0_3_after_even_b1
<<
endl
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment