Hi,
I need to get the Graph from a contour that has the highest number of elements. I know that with this
TObjArray *contours = gROOT->GetListOfSpecials()->FindObject(“contours”)
Int_t ncontours = contours->GetSize();
TList list = (TList )contours->At(i);
list->GetSize();
I can get the number of TGraphs, and then get the first one with
TGraph gr1 = (TGraph )list->First();
But I am counting the number of elements in each graph in a for loop (with GetN () )and in the end I need to get the graph with the highest number of elements. Would someone know how to do that?
hegner
March 11, 2016, 8:22am
2
Hi,
if you want to loop through a TList, here are all the options for doing so
root.cern.ch/doc/master/classTList.html
Then you just create two variables:
int highestCount(0);
TGraph* graphWithHighestNumberOfElements;
And in the loop you do
int currentCount = (TGraph*)iter->GenN();
if (currentCount > highestCount) {
highestCount = currentCount:
graphWithHighestNumberOfElements =(TGraph*)(*iter);
}
You can do it shorter, but I made it verbose and lengthy as to make it easier to understand.
couet
March 11, 2016, 9:44am
3
[quote=“hegner”]Hi,
if you want to loop through a TList, here are all the options for doing so
root.cern.ch/doc/master/classTList.html
Then you just create two variables:
int highestCount(0);
TGraph* graphWithHighestNumberOfElements;
And in the loop you do
int currentCount = (TGraph*)iter->GenN();
if (currentCount > highestCount) {
highestCount = currentCount:
graphWithHighestNumberOfElements =(TGraph*)(*iter);
}
You can do it shorter, but I made it verbose and lengthy as to make it easier to understand.[/quote]
Million thanks!