Find closest value in a column of a TNtuple?

I have a TNtuple with 40 columns. With those 40 columns, I’d like to produce a list of triplets, each element of a triplet being contributed by a different column, and each triplet made so as to minimize the difference between the elements in the triplet. So, I’d like a list of triplets {a,b,c} where max{a,b,c} - min{a,b,c} is minimized.

Currently, I’m storing the data in a 40 (yes, 40!) C++ vectors. I’ve written a binary search algorithm which, instead of returning the index of a found element, makes a comparison of elements neighboring the “closest” element, and returns the overall closest. I store these triplets in a vector of vectors, then sort by max(a,b,c) - min(a,b,c). Finally, to ensure every triplet is unique (no two share an element), I iterate over the sorted vector of vectors, storing “used” elements in a cache and, with every iteration, checking that an element of that triplet isn’t in the cache before keeping it.

This won’t, of course, work with a TNtuple. Is there a nice “ROOT” way to do this?

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

May be RDataFrame can provide some way to do that. If yes, @eguiraud can tell you I guess.

I’m afraid RDF does not have an algorithm for that, it’s a very specific usecase :smiley:

Loading your data into memory (e.g. in C++ vectors of vectors, or maybe better in a vector<Triplet> using a simple custom Triplet struct) is a perfectly valid way to proceed, unless you expect the total amount of triplets to exceed what you can store in RAM.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.