Root Editor GetEntry Error and Total Energy Deposited

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.

I cannot immediately see what’s wrong with your example.

Could you take a look in one of the existing tutorials, for instance here.

I would imagine that inadvertently some special character were introduced in the source file … this characters must be such that your editor is rendering is correctly but the compiler/interpreter can not. (For example there could some ‘backspace’ like characters).

Cheers,
Philippe.

Looks like that was it I initially wrote the macro as a text file so I guess that must have been where it happened. I went through and very carefully typed the macro out without using backspace or tab and it got passed that error. Thanks for the help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.