Skip to content

Instantly share code, notes, and snippets.

@xealits
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xealits/b8fb7f7b6ba4d024b979 to your computer and use it in GitHub Desktop.
Save xealits/b8fb7f7b6ba4d024b979 to your computer and use it in GitHub Desktop.
ROOT opening a tbranch of a ttree from a tfile, doing a calculation, writing a histogram
#include "TFile.h"
#include "TTree.h"
#include "TH1D.h"
#include <iostream>
void histo2()
{
std::cout << "fetch file\n" ;
// runs 349, 357, 365
//TFile *f = TFile::Open("run357_quartic.root");
//TTreeReader myReader("tdc", f);
TFile *f = new TFile("run365_quartic.root","READ");
std::cout << "fetch tree\n" ;
TTree *tree = (TTree*)f->Get("tdc");
tree->Print();
std::cout << "fetch branch\n" ;
Double_t leading_edge = 0.0;
tree->SetBranchAddress("leading_edge", &leading_edge);
std::cout << "start calculation\n" ;
Int_t entries = tree->GetEntries();
std::cout << entries << "\n" ;
for (Int_t i = 0; i<entries; i++) {
tree->GetEntry(i);
cout << leading_edge << "\n";
}
std::cout << "calculation ended\n" ;
f->Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment