366052_1.root (1.5 MB)I tried hard to draw simple variable in a tree. When I use SetBranchAddress, it always returns 0 and gives me empty histogram???. I really appreciate your help. I saw similar posts but no luck.Here is the code.
[code]void myDimuon3()
{
TCanvas *csq2 = new TCanvas("csq2","csq2",1,1,1000,800);
TFile* file = new TFile("366052_1.root");
TTree* tree = (TTree*)file->Get("T");
TH1F *h1_pz = new TH1F("h1_pz","h1_pz",100,0,20);
Float_t px,py,pz,pt,p,xst1,yst1,xst2,yst2,xst3,yst3,dphi23,dw23,Evt_bbcZ;
tree->SetBranchAddress(“pz”, &pz);
int nevts=tree->GetEntries();
cout << "nevts = " << nevts << endl;
for(int ievt=0; ievt<nevts; ievt++)
{
tree->GetEntry(ievt);
cout<<"pz"<<" = " << pz << endl;
h1_pz->Fill(pz);
}
h1_pz->Draw();
}[/code]