Skip to content
Snippets Groups Projects
Commit 37ea6903 authored by Axel Naumann's avatar Axel Naumann
Browse files

[treereader] Improve / fix doc example:

parent f85f0e2f
No related branches found
No related tags found
No related merge requests found
...@@ -45,10 +45,10 @@ A simpler analysis example can be found below: it histograms a function of the p ...@@ -45,10 +45,10 @@ A simpler analysis example can be found below: it histograms a function of the p
~~~{.cpp} ~~~{.cpp}
// A simple TTreeReader use: read data from hsimple.root (written by hsimple.C) // A simple TTreeReader use: read data from hsimple.root (written by hsimple.C)
#include "TFile.h #include "TFile.h"
#include "TH1F.h #include "TH1F.h"
#include "TTreeReader.h #include "TTreeReader.h"
#include "TTreeReaderValue.h #include "TTreeReaderValue.h"
void hsimpleReader() { void hsimpleReader() {
// Create a histogram for the values we read. // Create a histogram for the values we read.
...@@ -133,12 +133,17 @@ bool analyze(TFile* file) { ...@@ -133,12 +133,17 @@ bool analyze(TFile* file) {
TH1F("hist", "TTreeReader example histogram", 10, 0., 100.); TH1F("hist", "TTreeReader example histogram", 10, 0., 100.);
bool firstEntry = true;
while (reader.Next()) { while (reader.Next()) {
if (!CheckValue(weight)) return false; if (firstEntry) {
if (!CheckValue(triggerInfo)) return false; // Check that branches exist and their types match our expectation.
if (!CheckValue(muons)) return false; if (!CheckValue(weight)) return false;
if (!CheckValue(jetPt)) return false; if (!CheckValue(triggerInfo)) return false;
if (!CheckValue(taus)) return false; if (!CheckValue(muons)) return false;
if (!CheckValue(jetPt)) return false;
if (!CheckValue(taus)) return false;
firstentry = false;
}
// Access the TriggerInfo object as if it's a pointer. // Access the TriggerInfo object as if it's a pointer.
if (!triggerInfo->hasMuonL1()) if (!triggerInfo->hasMuonL1())
...@@ -164,6 +169,9 @@ bool analyze(TFile* file) { ...@@ -164,6 +169,9 @@ bool analyze(TFile* file) {
} }
} }
} // TTree entry / event loop } // TTree entry / event loop
// Return true if we have iterated through all entries.
return reader.GetEntryStatus() == TTreeReader::kEntryBeyondEnd;
} }
~~~ ~~~
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment