Skip to content

Commit 262ba35

Browse files
committed
[docs][DF] Some improvements to rosetta table
1 parent 2e655ef commit 262ba35

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

tree/dataframe/src/RDataFrame.cxx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,7 @@ tree->Draw("event.GetNtrack()");
19671967
</td>
19681968
<td>
19691969
~~~{cpp}
1970-
auto df1 = df.Define("NTrack","event.GetNtrack()");
1971-
df1.Histo1D("NTrack")->Draw();
1970+
df.Define("NTrack","event.GetNtrack()").Histo1D("NTrack")->Draw();
19721971
~~~
19731972
</td>
19741973
</tr>
@@ -2008,16 +2007,13 @@ df.Define("good_pt", "Muon_pt[Muon_pt > 100]").Histo1D("good_pt")->Draw();
20082007
tree->Draw("sqrt(x)>>hnew","y>0");
20092008
20102009
// Retrieve hnew from the current directory
2011-
TH1F *hnew = (TH1F*)gDirectory->Get("hnew");
2012-
2013-
// Retrieve hnew from the current Pad
2014-
TH1F *hnew = (TH1F*)gPad->GetPrimitive("hnew");
2010+
auto hnew = gDirectory->Get<TH1F>("hnew");
20152011
~~~
20162012
</td>
20172013
<td>
20182014
~~~{cpp}
20192015
// We pass histogram constructor arguments to the Histo1D operation, to easily give the histogram a name
2020-
auto hist = df.Filter("y>0").Histo1D({"hnew","hnew",10, 0, 10},"x");
2016+
auto hist = df.Define("sqrt_x", "sqrt(x)").Filter("y>0").Histo1D({"hnew","hnew", 10, 0, 10}, "sqrt_x");
20212017
~~~
20222018
</td>
20232019
</tr>
@@ -2035,10 +2031,10 @@ tree->Draw("z:y:x","","prof");
20352031
~~~{cpp}
20362032
20372033
// Draw a 1D Profile histogram
2038-
auto profile1D = df.Profile1D("x", "y");
2034+
df.Profile1D("x", "y")->Draw();
20392035
20402036
// Draw a 2D Profile histogram
2041-
auto profile2D = df.Profile2D("x", "y", "z");
2037+
df.Profile2D("x", "y", "z")->Draw();
20422038
~~~
20432039
</td>
20442040
</tr>
@@ -2052,8 +2048,7 @@ tree->Draw("x", "","", 2, 5);
20522048
<td>
20532049
~~~{cpp}
20542050
// Range function with arguments begin, end
2055-
auto histo_range = df.Range(5,7).Histo1D<int>("x");
2056-
histo_range->Draw();
2051+
df.Range(5,7).Histo1D("x")->Draw();
20572052
~~~
20582053
</td>
20592054
</tr>
@@ -2067,8 +2062,7 @@ tree->Draw("vec_list.X()");
20672062
</td>
20682063
<td>
20692064
~~~{cpp}
2070-
auto histo = df.Define("x", "ROOT::RVecD out; for(const auto &el: vec_list) out.push_back(el.X()); return out;").Histo1D("x");
2071-
histo->Draw();
2065+
df.Define("x", "ROOT::RVecD out; for(const auto &el: vec_list) out.push_back(el.X()); return out;").Histo1D("x")->Draw();
20722066
~~~
20732067
</td>
20742068
</tr>
@@ -2078,7 +2072,7 @@ histo->Draw();
20782072
// Gather all values from a branch holding a collection per event, `pt`,
20792073
// and fill a histogram so that we can count the total number of values across all events
20802074
tree->Draw("pt>>histo");
2081-
TH1D *histo = (TH1D *)gDirectory->Get("histo");
2075+
auto histo = gDirectory->Get<TH1D>("histo");
20822076
histo->GetEntries();
20832077
~~~
20842078
</td>

0 commit comments

Comments
 (0)