Skip to content

Commit 93d2051

Browse files
committed
further fixes
1 parent 530aacb commit 93d2051

File tree

1 file changed

+17
-51
lines changed

1 file changed

+17
-51
lines changed

tree/dataframe/src/RDataFrame.cxx

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,7 @@ tree->Draw("x", "y > 2");
19381938
<td>
19391939
~~~{.cpp}
19401940
ROOT::RDataFrame df("myTree", file);
1941-
auto h = df.Filter("y > 2").Histo1D("x");
1942-
h->Draw();
1941+
df.Filter("y > 2").Histo1D("x")->Draw();
19431942
~~~
19441943
</td>
19451944
</tr>
@@ -1952,10 +1951,7 @@ tree->Draw("jet_eta", "weight*(event == 1)");
19521951
</td>
19531952
<td>
19541953
~~~{.cpp}
1955-
df.Filter("event == 1").Histo1D("jet_eta", "weight");
1956-
1957-
// or the fully compiled version:
1958-
df.Filter([] (ULong64_t e) { return e == 1; }, {"event"}).Histo1D<RVec<float>>("jet_eta", "weight");
1954+
df.Filter("event == 1").Histo1D("jet_eta", "weight")->Draw();
19591955
~~~
19601956
</td>
19611957
</tr>
@@ -1964,15 +1960,13 @@ df.Filter([] (ULong64_t e) { return e == 1; }, {"event"}).Histo1D<RVec<float>>("
19641960
~~~{cpp}
19651961
// Draw a histogram using the method of the class that is being used.
19661962
tree->Draw("event.GetNtrack()");
1967-
// note: this will not work in RDataFrame version
1968-
// tree->Draw("GetNtrack()");
19691963
19701964
~~~
19711965
</td>
19721966
<td>
19731967
~~~{cpp}
19741968
auto df1 = df.Define("NTrack","event.GetNtrack()");
1975-
auto df2 = df1.Histo1D<int>("NTrack");
1969+
df1.Histo1D("NTrack")->Draw();
19761970
~~~
19771971
</td>
19781972
</tr>
@@ -1986,22 +1980,21 @@ tree->Draw("fNtrack","fEvtHdr.fEvtNum%10 == 0");
19861980
<td>
19871981
~~~{cpp}
19881982
// Use the Filter operation together with the special RDF column: `rdfentry_`
1989-
auto histo = df.Filter("rdfentry_ % 10 == 0").Histo1D<int>("fNtrack");
1990-
histo->Draw();
1983+
df.Filter("rdfentry_ % 10 == 0").Histo1D("fNtrack")->Draw();
19911984
~~~
19921985
</td>
19931986
</tr>
19941987
<tr>
19951988
<td>
19961989
~~~{cpp}
19971990
// object selection: for each event, fill histogram with array of selected pts
1998-
tree->Draw('Muon_pt', 'Muon_pt > 100')
1991+
tree->Draw('Muon_pt', 'Muon_pt > 100');
19991992
~~~
20001993
</td>
20011994
<td>
20021995
~~~{cpp}
20031996
// with RDF, arrays are read as ROOT::VecOps::RVec objects
2004-
df.Define("good_pt", "Muon_pt[Muon_pt > 100]").Histo1D<float>("good_pt");
1997+
df.Define("good_pt", "Muon_pt[Muon_pt > 100]").Histo1D("good_pt")->Draw();
20051998
~~~
20061999
</td>
20072000
</tr>
@@ -2021,14 +2014,8 @@ TH1F *hnew = (TH1F*)gPad->GetPrimitive("hnew");
20212014
</td>
20222015
<td>
20232016
~~~{cpp}
2024-
// Save the histogram to a file
2025-
TFile f("myhistos.root","new");
2026-
auto hist = df.Filter("y>0").Histo1D<float>({"myhisto","myhisto",10, 0, 10},"x");
2027-
f.WriteTObject(hist.GetPtr());
2028-
2029-
// Retrieve the histogram
2030-
TFile f("myhistos.root");
2031-
TH1D *h = (TH1D*)f.Get("myhisto");
2017+
// We pass histogram constructor arguments to the Histo1D operation, to easily give the histogram a name
2018+
auto hist = df.Filter("y>0").Histo1D({"hnew","hnew",10, 0, 10},"x");
20322019
~~~
20332020
</td>
20342021
</tr>
@@ -2044,11 +2031,12 @@ tree->Draw("z:y:x","","prof");
20442031
</td>
20452032
<td>
20462033
~~~{cpp}
2034+
20472035
// Draw a 1D Profile histogram
2048-
auto profile1D = df.Profile1D<int, float>({"profName", "profTitle", 10, 0, 10}, "x", "y");
2036+
auto profile1D = df.Profile1D("x", "y");
20492037
20502038
// Draw a 2D Profile histogram
2051-
auto profile2D = df.Profile2D<int, float, double>({"profName", "profTitle", 10u, 0, 10, 10, 0, 10}, "x", "y", "z");
2039+
auto profile2D = df.Profile2D("x", "y", "z");
20522040
~~~
20532041
</td>
20542042
</tr>
@@ -2077,45 +2065,23 @@ tree->Draw("vec_list.X()");
20772065
</td>
20782066
<td>
20792067
~~~{cpp}
2080-
auto getX = [](vector< ROOT::Math::DisplacementVector3D> &v){RVec<double> out; for( auto p: v) out.push_back(p.X()); return out;};
2081-
auto histo = df.Define("X",getX,{"vec_list"}).Histo1D<double>("x");
2068+
auto histo = df.Define("x", R"(ROOT::RVecD out; for(const auto &el: vec_list) out.push_back(el.X()); return out;)").Histo1D("x");
20822069
histo->Draw();
20832070
~~~
20842071
</td>
20852072
</tr>
20862073
<tr>
20872074
<td>
20882075
~~~{cpp}
2089-
// Draw 2D arrays
2090-
tree->Draw("fMatrix");
2091-
tree->Draw("fMatrix[ ][ ]");
2092-
tree->Draw("fMatrix[2][2]");
2093-
tree->Draw("fMatrix[][0]");
2094-
// and so on:
2095-
// fMatrix[1][0], fMatrix[2][0], fMatrix[3][0], ... , fMatrix[n][0]
2096-
2097-
~~~
2098-
</td>
2099-
<td>
2100-
~~~{cpp}
2101-
Reading multi-dimensional arrays is not supported in RDF.
2102-
GH issue exists. If such feature is needed, please add a comment: "https://github.com/root-project/root/issues/15068"
2103-
~~~
2104-
</td>
2105-
</tr>
2106-
<tr>
2107-
<td>
2108-
~~~{cpp}
2109-
// Count number of entries in a specific dataset branch
2110-
tree->Draw("pt");
2111-
TH1* myH {static_cast<TH1*>(gPad->GetPrimitive(\"htemp\"))};
2112-
myH->GetEntries();
2076+
// Count number of entries in a specific dataset branch in case this branch has fewer entries than the full dataset
2077+
tree->Draw("pt>>histo");
2078+
TH1D histo = (TH1D)gDirectory->Get("histo");
2079+
histo->GetEntries();
21132080
~~~
21142081
</td>
21152082
<td>
21162083
~~~{cpp}
2117-
auto df = ROOT::RDataFrame("tree", "file.root");
2118-
df.Histo1D<double>("pt")->GetEntries();
2084+
df.Histo1D("pt")->GetEntries();
21192085
~~~
21202086
</td>
21212087
</tr>

0 commit comments

Comments
 (0)