Hello everyone, I am having a problem with something I expected to be working quite easily, and I am quite lost as to what is happening.
I have some data in a ROOT tree that i want to modify (apply calibrations, …) and store in another tree, on which I want to perform the rest of the analysis.
I used 2 different selectors, one called Filter for the first tree and another called Sort for the second.
I found it convenient to use a “CalEvent” object (defined in Event.C and Event.h) to store all the data I wanted in the new tree, so I used this syntax to create the branch (in Filter::Begin):
ev = new CalEvent();
// ...
outputtreefile = new TFile("work/tmptreeout.root","recreate");
outputtree = new TTree("data","data");
outputtree->Bronch("e.","CalEvent",&ev);
In Filter::Process I then calculate the values of the members of ev and call the Fill method of outputtree, and in Filter::End I save the file.
I made sure I could read the data stored in tmptreeout.root correctly by writing this in the ROOT command line:
TChain *c = new TChain("data")
c->Add("work/tmptreeout.root")
TBranch *b
b = c->GetBranch("e.")
.L Event.C++
CalEvent *e = 0;
b->SetAddress(&e)
c->GetEntry(6)
cout<<e->Si_E.pad[5][5]<<endl;
the last line outputs the correct value for the variable in that event.
I then made a macro called RunSort to open the tree and lauch the Process method with the Sort selector and some options, loading the Event class before that.
void RunSort()
{
gROOT->LoadMacro("Event.C++");
TChain *c = new TChain("data");
inputfilename = "work/tmptreeout.root";
files_added = c->Add(inputfilename);
c->Process("Sort.C++",cline);
}
This is a snippet form Sort.h:
class Sort : public TSelector {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
TBranch *b_ev; //!
CalEvent *ev;
ClassDef(Sort,0);
};
void Sort::Init(TTree *tree)
{
if (!tree) return;
fChain = tree;
fChain->SetMakeClass(1);
if (!TClassTable::GetDict("CalEvent")) {
cout<<"Dict for CalEvent not found!"<<endl;
}
b_ev = fChain->GetBranch("e.");
if(!b_ev) cout<<"!b_ev"<<endl;
b_ev->SetAddress(&ev);
cout<<"BranchStatus "<<fChain->GetBranchStatus("e.")<<endl;
}
As far as I can see, this should be more or less equivalent to what I wrote in the ROOT command line. The problem is that if I put
in Sort::Process, the ouput value is completely wrong (it’s always 6.78869e+199, for any event).
I am completely lost as to what could be the reason, any suggestion?
I made sure that none of the pointers I am using is null (also because I don’t have any segmentation fault or other runtime error, the macro executes fine)
Thanks for the attention
Roberto