***Break***segmentation violation error

Hi
i wrote this program for reading a tree:
TFile f= TFile::Open(“s.root”);
TTree T=(TTree) f->Get(“T”);
float E1,E2;
T->SetBranchAddress(“b”,&E1);
T->SetBranchAddress(“b”,&E2);
TH2F h2=new TH2F(“h2”,“hist”,200,0,2000,200,0,2000);
int nentries= (int)T->GetEntries();
for(int i=0; i<nentries; i++){
T->GetEntry(i);
h2->Fill(E1,E2);
}
h2->Draw();
but it doasn’t run and i see this comment:***Break
*segmentation violation
please help me,thanks
(my root version is 5.34.34, ubuntu16)

Hi,

you are assigning two variables to the same branch, “b”: this needs probably to be fixed with the proper branch names.
For the rest, the macro is ok. Are you sure that both the file and the tree with that name exist? You can check that printing out the value of T and f.

hi
thanks for your answer,
i’m sure i have tow variables(or tow leafs) in a branch “b”. and i check the file and tree all are correct.

when i use groot->macro() i have this warning: wrong member access operator and i can’t access variables.

Hi,

please post our file here.

i have the tree “T” whit one branch “b” and four leafs in s.root
void Break101(){
double X[4];
TCanvas *c1 = new TCanvas(“c1”," Canv");

TChain *breakupchain= new TChain(“T”);

breakupchain.Add("/home/s.root");
breakupchain->SetBranchAddress(“b”,X);
}

and

void Break102(){
gROOT->Macro("/home/Break101.cpp");
TH2D *h2 = new TH2D (“h2”,“P_{1};P_{2}”,20,0,200,20,0,200);
double E1,E2;
c1->cd();
h2->Fill(E1,E2);
h2->Draw();
}
i have this warning: wrong member access operator ‘.’ /home/Break101.cpp

Start with an “analysis skeleton” (note: you need to generate it for your TChain, not for your single TTrree): How are multiple TTree->Draw()s done?

hi
in fact i use it for three ttree but i see the same warning and i prefer to use single ttree before removing the warning :frowning: . i use the method of ttree.makeclass to read variable of this tree but i can’t access the variables and i don’t know what is the broblem.

hi,
void Break101(){
gStyle->SetOptStat(10);
gStyle->SetPalette(1);
double X[4];
TCanvas *c1 = new TCanvas(“c1”,“BINA1 Canv”);
c1->SetFillColor(10);
c1->Size(19,25);
TChain *breakupchain= new TChain(“T”);
breakupchain.Add("/home/s.root");
breakupchain->Print();
breakupchain->SetBranchAddress(“b”,&X);
}

void BreakUpKinematic102(){
gROOT->Macro("/home/Break101.cpp");
TH2D *h1h2 = new TH2D (“h1h2”,“E_{1},E_{2};E_{1};E_{2}”,20,0,200,20,0,200);
double E1,E2;
c1->cd();
h1h2->Fill(E1,E2);
h1h2->Draw();
}
whit this s file
s.root (34.6 KB)

Hi,

Can you confirm this is the right code? You do not seem to have a loop over the entries on the chain. Perhaps you might take the opportunity to have a look to the tutorials root.cern/doc/master/group__tutorial__tree.html we provide about reading trees/chains?

While you acquire more experience with the way in which you can interact with trees, you can take advantage of the TTree::Draw (root.cern.ch/doc/v608/classTTre … c468523e45) tool:

void yourMacro() {
   TFile f("s.root");
   TTree* t;
   f.GetObject("T",t);
   t->Draw("E1:E2");
}

Cheers,
D

Hi,
I want to access variables in tree because i don’t use tree::Draw(). i think if i use TChain and groot->macro i can access variable but i don’t know how can i have a loop over the entries. please help me.

program Break 101:
{
double X[4];
TCanvas *c1 = new TCanvas(“c1”,“Canv”);
TChain *breakupchain= new TChain(“T”);
breakupchain.Add("/home/s.root");
breakupchain.Add("/home/s1.root");

breakupchain->SetBranchAddress(“b”,&X);
}

program Break102:
void BreakUpKinematic102(){
gROOT->Macro("/home/Break101.cpp");
TH2D h2 = new TH2D (“h2”,“E_{1},E_{2};E_{1};E_{2}”,20,0,200,20,0,200);
double E1,E2;
double Ein=E1
E2;
c1->cd();
h1h2->Fill(Ein,E2);
h1h2->Draw();
}

Hi,

Perhaps you might take the opportunity to have a look to the tree tutorials root.cern.ch/doc/master/tree1_8C.html .

D

Hi,
I use this program but my program can’t get the variable and my histogram shows 0 for all entries. :frowning:

code]#include
#include
#include
#include <math.h>
#include <TH2D.h>
#include <TROOT.h>
#include <TRandom.h>
#include <TTree.h>
#include <TFile.h>
#include <TChain.h>
#include “break.h"
using namespace std;
void Break102(){
gROOT->Macro(”/home/break101.cpp");
TH2D *h2 = new TH2D (“h2”,“E_{1},E_{2};E_{1};E_{2}”,20,0,200,20,0,200);
chain->Print();
double E1,E2;
break *event=0;
chain->SetBranchAddress(“b3”,&Y);
int nevent = chain->GetEntries();
for (Int_t i=0;i<nevent;i++) {
chain->GetEntry(i);
cout<<E1<<"\n";
h1h2->Fill(E1,E2);
}
h1h2->Draw(“COLZ”)
}

and break 101:
{
Double_t Y[87];
TCanvas *c1 = new TCanvas(“c1”,“BINA1 Canv”);
TChain *chain= new TChain(“break”);
chain.Add("/home/s.root");
chain.Add("/home/s1.root");
}

Hi,
I have a problem when I using 6 histogram in a loop i use this code:

TH2D M[6];
for(int i=0;i<6; i++){
sprintf(cha[1],“d%d”,i);
sprintf(cha[2],“E%d”,i);
M[i]=new TH2D(cha[1],cha[2],150,0,1500,150,0,1500);
if (SE2>=100
i+300 && SE2>=100*i+400){
M[i]->Fill(SE1,SE2);
}
ps->NewPage();
c1->cd();
M[i]->Draw();
c1->Update();
}
and i see this error :can’t call TH2D::Fill(SE1,SE2) in current scope
please help me

I made your example reproducible, e.g. removing pieces which are relative to your full setup, and it runs just fine:

double SE1, SE2;
SE1=SE2 = 4;
TH2D *M[6];
for(int i=0;i<6; i++){
   M[i]=new TH2D("","",150,0,1500,150,0,1500);
   M[i]->Fill(SE1,SE2);
   M[i]->Draw();
}

Hi,
Thanks, in the below program i have tow ntuple an i open this ntuple and E1,E2 are input but when i draw M[i] i have one entry :frowning: but for h2 i have all of entries and i have a correct histogram i don’t know what is the problem, please help me.

TH2D *h2=new TH2D(“h2”,“hiat”,150,0,1500,150,0,1500);
TH2D *M[6];
int i;
void Break(){
gROOT->Macro("/home/openntuple.cxx");
char ch[2][600];
TPostScript *ps = new TPostScript(“file3.ps”,111); ps->Range(18,27);
sprintf(ch[0], “theta2<=27 && theta2>=23”);
sprintf(ch[1],“Calib(E1,E2,theta2,theta1));
breakchain->Draw(ch[1], ch[0],”",2e5);

histo();
for(int i=0;i<6; i++){
ps->NewPage();
c1->cd();
M[i]->Draw();
c1->Update();
}
c2->cd();
h2->Draw(“colz”);
}
int Calib(double E1,double E2 double theta2, double theta1){

histo();
for(int i=0;i<6; i++){
M[i]->Fill(E1,E2);
}

if (E2>300 && E2<400){
h2->Fill(E1,E2);
}
}

void histo(){
for(int i=0;i<6; i++){
M[i]=new TH2D("","",150,0,1500,150,0,1500);
}
}

Hi,

You are creating new histograms for every single entry in the tree: Calib gets called for each entry, and Calib calkls histo. So all you see in M is the last entry.

Cheers, Axel.