I have a simple macro that fills a “flat” TTree (“flat” in the sense that I fill in a bunch of floats and integers, there’s no class that defines any kind of structure):
TTree* all = new TTree("all", "all");
int vR[3];
float vB[7];
float vD[7];
float vT[8];
float vZ[5];
char* formatR = "run/I:evt/I:rs/I";
char* formatB = "mass/F:masserr/F:chi2/F:pt/F:d0/F:lxy/F:lxyerr/F";
char* formatD = "mass/F:chi2/F:pt/F:d0/F:lxy/F:lxyerr/F:blxy/F";
char* formatT = "pt1/F:d01/F:pt2/F:d02/F:pt3/F:d03/F:pt4/F:d04/F";
char* formatZ = "dr/F:cos/F:mkpi1/F:mkpi2/F:pvz/F";
all->Branch("R", vR, formatR);
all->Branch("B", vB, formatB);
all->Branch("D", vD, formatD);
all->Branch("T", vT, formatT);
all->Branch("Z", vZ, formatZ);
... (filling arrays vR, vB, vD, vT, vZ) ...
all->Fill();
...
I then write it (TTree called “all”) out to a file named mc.root and I can read it back, plot individual variables with CINT commands (i.e., interactively), etc. However, if I make the above macro code part of compiled library/excutable, run it and try try to plot some variables I get a crash:
root [1] TFile* fileMC = TFile::Open("mc.root");
root [2] TTree* treeMC = (TTree*)fileMC->Get("all");
root [3] treeMC->SetDirectory(0);
root [4] fileMC->Close();
root [7] treeMC->Draw("R.run")
*** Break *** segmentation violation
The same thing happens if I do
all->GetEvent(i);
in a for loop (that’s what the real problem is). Interestingly enough I can get around the problem by starting a TBrowser and doing StartViewer on the tree (I hope this can lit some light on the problem):
root [3] tv__tree = (TTree *) gROOT->FindObject("all");
tv__tree_list->Add(tv__tree);
tv__tree->Draw("R.run")
but the good-old way (with all->GetEvent(i)) does not work… Please tell me what’s going on.