Reading value from leaf of a tree

Hello all,

I have a tree in which there is a branch and it contains many leaf and I need to read one leaf and put its values into an array.

For that I am doing the following:**

Please suggest what I may be missing.

Also I am attaching my full code.

Thanks,
Ramkrishna

**
rd51tbgeo->SetBranchAddress(“g1xcl.geoposX”,g1xcl_geoposX);
Long64_t nevent=rd51tbgeo->GetEntries();

for (Int_t i = 0; i<nevent; i++){
rd51tbgeo->GetEntry(i);
cout<<"xpos_cms = "<<g1xcl_geoposX[i]<<endl;
}
Resolution_formula.C (818 Bytes)

A small example “CRC” file needed.

Sorry by mistake I uploaded wrong root file. The CRC file that I am using is heavy (21MB) file and I am not able to upload it.

TTree “rd51tbgeo” does not exist in the file that you posted.
I need a file with your TTree (just several events are sufficient).

[quote=“Wile E. Coyote”]TTree “rd51tbgeo” does not exist in the file that you posted.
I need a file with your TTree (just several events are sufficient).[/quote]

Thanks Coyote for quick reply.

But I am not able to upload the correct root file.

I am sending the screen shot of my root file. May be that will help.

Thanks & regards,


Try:
root […] rd51tbgeo->Print(); > rd51tbgeo.Print.out.txt
and post the “rd51tbgeo.Print.out.txt” file.

[quote=“Wile E. Coyote”]Try:
root […] rd51tbgeo->Print(); > rd51tbgeo.Print.out.txt
and post the “rd51tbgeo.Print.out.txt” file.[/quote]

I am attaching the file rd51tbgeo.Print.out.txt.

Thanks.
rd51tbgeo.Print.out.txt (104 KB)

Try the attached macro.

However, my advice would be that you try (then see “MyClass.C” and “MyClass.h” files) … root [0] TFile *f = new TFile("CRC-Run065_Icomp100_Th15_MSPL1_lat32-32_I781uA_I771uA_asynchrous-121114_075331-0_ZeroOffSet.root"); root [1] rd51tbgeo->MakeClass("MyClass"); … and / or (then see “MySelector.C” and “MySelector.h” files) … root [0] TFile *f = new TFile("CRC-Run065_Icomp100_Th15_MSPL1_lat32-32_I781uA_I771uA_asynchrous-121114_075331-0_ZeroOffSet.root"); root [1] rd51tbgeo->MakeSelector("MySelector");
Resolution_formula.C (1.48 KB)

Hello Coyote,

I tried it but there I am getting segmentation violation. So, to troubleshoot that I just commented everything inside for loop except GetEntry line. As follows:

std::cout << "####### nevent = " << nevent << std::endl;

for (Long64_t i = 0; i < nevent; i++) {
std::cout << "i = " << i << std::endl;
rd51tbgeo->GetEntry(i);
/*
std::cout << "g1xcl_ = " << g1xcl_ << std::endl;
for (Int_t j = 0; j < g1xcl_; j++) {
std::cout << “geoposX[” << j << "] = " << geoposX[j] << std::endl;
}
*/
}

This is printing the value of first i but after that there is some problem. I am attaching the log file for this run.
segmentation_log.txt (5.01 KB)

I need your root file (put it somewhere, from where I can download it; e.g. it can be any “public” area of “afs” or any “www” or “dropbox”, and so on).

What you can try is … comment out the line:
rd51tbgeo->SetBranchAddress(“g1xcl.geoposX”, geoposX);
but, in the event loop, leave the line:
std::cout << "g1xcl_ = " << g1xcl_ << std::endl;
(see if you get reasonable “g1xcl_” values, note the max value that appeared).

Hello Coyote
you can get root file form

  1. public area of cern
    /afs/cern.ch/user/r/rasharma/public

or,

  1. can be downloaded from the link
    docs.google.com/file/d/0B2Yvp8x … dqSG8/edit

The maximum value of MAX_POSSIBLE_G1XCL is 30045.

Thanks & regards,

See my previous reply here with the “Resolution_formula.C” macro again (I fixed the “segmentation violation” problem there).

BTW. “MakeClass” and “MakeSelector” say that “MAX_POSSIBLE_G1XCL” is actually “kMaxg1xcl = 13”.

Thank you very much Coyote.

This solved my problem.

But now I have one more problem. When I tried to fill it into a histogram like below, it is not filling it.

TH1F *h1 = new TH1F(“h1”,“h1”,100,0,100);
TCanvas *c1 = new TCanvas(“c1”,“c1”,1);
Float_t y;
for (Long64_t i = 0; i < nevent; i++) {
rd51tbgeo->GetEntry(i);
for (Int_t j = 0; j < g1xcl_; j++) {
y = geoposX[j];
std::cout<<"y = "<<y<<endl;
// h1->Fill(geoposX[j]);
h1->Fill(y);
}
}
c1->Draw();
c1->SaveAs(“g1_geoposX.pdf”);

Instead of:
c1->Draw();
try:
h1->Draw();
c1->Modified(); c1->Update();

Thank you very much Coyote. Problem solved.