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;
[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)??
[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.
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.
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.