following the example of TTreeReader found here, suppose I have the following:
TTreeReaderArray<double> jetPt(reader, "jetpT");
TTreeReaderArray<double> jetEta(reader, "jetEta");
TTreeReaderArray<double> jetPhi(reader, "jetPhi");
// and so on...
Now I want to sort them all as the elements of the jetPt decrease. Clearly, I cannot do it with
int n = sizeof(jetPt)/sizeof(jetPt[0]);
sort(jetPt, jetPt+n, std::greater<double>());
, because it will sort only the jetPt array, and I won’t be able to find which index of sorted jetPt corresponds to index of the unsorted jetPhi. Is there any way to do what I want?
To do the sort you can use a collection of indices, for example.
size_t n = jetPt.GetSize();
std::vector<long> index;
for(size_t i = 0; i < n; ++i) index.push_back(i);
sort(index.begin(), index.end(), [&jetPt](long a, long b) -> bool
{
return jetPt[a] > jetPt[b];
})
[corrected the lambda capture syntax]
then you can use index to access the elements of all 3 arrays.