TBranchElement and vectors

Hi,
As a new C++ learner and Root user, I am really stucked for some time. This is the case.
I have a .root file which contains a TTree name ‘clusters’. This contains many TBranch objects like ‘cl_event’ and many TBranchElement objects like ‘st_number’. This ‘st_number’ contains some “leaves” (is this correct term at all?) which are TCollectionPropertyBrowsable like ‘values’, which is the one i want to read. See screenshot.

Also, there has been made a ‘clusters.h’ header with the TTree:MakeClass method, using as input the initial xxxx.root file.
When I open that, I see that in //Declaration of leaf types, there is:
vector<vector< unsigned int> > *st_number;

I thought using a double for-loop to read that 2D vector, like here: http://www.cplusplus.com/forum/general/833/

My access method is this one:

[code] for(size_t iEntry=0; iEntry<nEntries; iEntry++)
{
cl_tree->GetEntry(iEntry);
if (iEntry % 2000 == 0 && iEntry!=0)
cout << “====>>>>>> " << iEntry << " processed so far <<<<<<==== \n”;
for(int num=0;num<(int) cl_tree->cl_chamber_name->size(); num++){
if (cl_tree->cl_chamber_name->at(num)==“Tmm2”)
charge=cl_tree->cl_charge;
for (unsigned int i=0; i<cl_tree->st_number->size(); i++) {
for (unsigned int j=0; j<cl_tree->st_number->size(); j++) {
cout << st_number[i][j];
}

   		}
}

}
[/code]

The error I get is: [quote]for1.C:87:14: error: ‘st_number’ was not declared in this scope cout << st_number[i][j]; [/quote]

If I do st_number->values->size(); I get this error

[quote]for1.C:85:49: error: ‘class std::vector<std::vector<unsigned int> >’ has no member named ‘values’ for (unsigned int i=0; i<cl_tree->st_number->values->size(); i++) {[/quote]
so I suppose I have not figured out what is the correct access method for TBranchElement objects…

I also tried this method: [url]Problem with TBanchElement
No good results. Is it useful for me (given that I already have the ‘clusters.h’ produced with MakeClass)??

Thanks alot for any help!!! :open_mouth: :slight_smile:
Andreas


Hi,

[quote]Also, there has been made a ‘clusters.h’ header with the TTree:MakeClass method, using as input the initial xxxx.root file.
When I open that, I see that in //Declaration of leaf types, there is:
vector<vector< unsigned int> > *st_number;[/quote]TTree::MakeClass does not fully support nested collection like this one (I am slightly surprised that member is not commented out, especially given the error message you see).

You can try TTree::MakeProxy or the TTree::MakeSelector found in v6 of ROOT.

Cheers,
Philippe.

pcanal,

thank you very much. I am trying now with root 6.05/02 and the MakeSelector method. I hope to make it.
thank you again :slight_smile:

If I were to read such an object like the ‘st_number’, what method would be the best? I mean, avoiding doing the MakeSelector method…

Should I use TBranchElement::GetObject()?? Something near that?
(https://root.cern.ch/doc/master/classTBranchElement.html#a5dba28b97ad8d46ee9e5170018c446cb)
:open_mouth:

HI,

The simplest is to extract the declaration part you are interested from the result of MakeSelector in v6 (i.e. use the TTreeReader).

Cheers,
Philippe.

OK Philippe,

I will give it a try, since it is the simplest way to do. Thank you!

solved it with this MakeClass implication using:

for (std::vector < vector<unsigned int> >::iterator it = cl_tree->st_number->begin(); it != cl_tree->st_number->end(); it++){ for (unsigned int j=0; j<(*it).size(); j++) { // alternative (*it) strip_charge_tmm2->Fill((*it)[j]); //cout << (*it)[j] <<endl;

Also, created the .C, .h files with makeselector but didnot use them till now. :confused:

:smiley:

So, to do it using MakeSelector I found this:
root.cern.ch/doc/v606/classTTreeReader.html

is it enough, or should I implement something like that (in a simler form ofcourse) ?
root.cern.ch/doc/v606/h1analysis_8C.html

:slight_smile:

Hi,

The result of MakeSelector is a skeleton that needs to be filled with code specific to your analysis. h1analysis.C is indeed an example of such a flushing out.

Cheers,
Philippe.

than you for the quick(!) reply, I will try it now. :wink:

andreas