Hi all,
Before I get into this, I’m a complete novice with Root so I’d appreciate layman’s terms if possible.
First off, I’m trying to write a macro in the TBrowser to export specific branches of a tree but I keep getting an error when compiling it. Here’s the macro,
#include <iostream>
#include "TFile.h"
#include "TTree.h"
#include <fstream>
using namespace std;
void RootToTxt(){
TFile *f=new TFile("NeutronTestStand.root");
TTree *tr=(TTree*)f->Get("tree");
float a,b,c;
tr->SetBranchAddress("E_prim",&a);
tr->SetBranchAddress("SD_Edep",&b);
tr->SetBranchAddress("TD_Edep",&c);
ofstream *my;
my->open ("example.txt");
*my << "E_prim SD_Edep TD_Edep\n";
for (int i=0;i<tr->GetEntries();i++){
// loop over the tree
tr->GetEntry(i); //This line gives me the error
cout << a << " " << b << " " << c << endl;
*my << a << " " << b << " " << c<<"\n";
}
my->close();
}
From the errors it seems that the compiler is reading the GetEntry line as,
tr->Get);try(i);
Is there any known reason for this text change or a way I can work around it? The text displays properly in the browser.
P.S. Is there a way to directly take my histogram of energy deposited values and add them all together to get a total energy deposited in all of my detectors? If this has a simple answer then the above question can be ignored.