Hello all,
I’m a novice with ROOT, so apologies in advance if this is a trivial issue.
I’m using a modified ROOT version 4.04/02g, that is linked with some class definitions from our experiment.
Simply, I’m trying to have ROOT print out the entries in a branch one at a time, similar to the results of using Scan. I’ve attached the root file “small.root”.
In the tree “Experiment”, the branch I want to print out is “TGlobalTankHeaderChunk.data_.RUN_NUM”. When I use MakeClass to set up my macro, I successfully print out the variables for each event one at a time. I’ve attached these as Experiment.C and Experiment.h. Experiment.C looks like
#define Experiment_cxx
#include "Experiment.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
void Experiment::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Int_t run_num;
Experiment->SetBranchAddress("TGlobalTankHeaderChunk.data_.RUN_NUM", &run_num);
Int_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
//
cout<< run_num<<endl;
}
}
But when I try to write my own macro from scratch, I end up getting 0’s for every event. I’ve attached that file as readdata.C. I tried to keep things close to Experiment.C, but it doesn’t work. Here is readdata.C
void readdata(){
TFile *f = new TFile("small.root");
TTree* Experiment = (TTree*)f->Get("Experiment");
Int_t run_num;
Experiment->SetBranchAddress("TGlobalTankHeaderChunk.data_.RUN_NUM", &run_num);
Long64_t nentries = Experiment->GetEntries();
for ( Long64_t jentry = 0 ; jentry < nentries; ++jentry){
Experiment->GetEntry(jentry);
std::cout<<run_num<<std::endl;
}
return;
}
I also noticed that when I used Experiment->Print()
, it looks like the branch I’m interested in is an array, with length 1. I tried changing the lines
Int_t run_num;
...
Experiment->SetBranchAddress("TGlobalTankHeaderChunk.data_.RUN_NUM", &run_num);
...
std::cout<<run_num<<std::endl;
to
Int_t run_num[1];
...
Experiment->SetBranchAddress("TGlobalTankHeaderChunk.data_.RUN_NUM", run_num);
...
std::cout<<run_num[0]<<std::endl;
But that didn’t seem to work.
Does anybody have any tips?
I hope this isn’t too silly, but I’ve spent quiet a bit of time trying to figure this out.
small.root (36.9 KB)
Experiment.h (4.0 KB)
Experiment.C (1.6 KB)
readdata.C (636 Bytes)