# Complement of RVec Take operation

What is the best way to `Take` from an RVec when one has the list of indices that one doesn’t want to keep?

In my particular case I have three collections per event: pt, eta, phi, corresponding to kinematic properties of some generic particles. The goal is select the pt of the particles that are not part of the particle pair with the largest invariant mass. I would appreciate input here to ensure I am doing it as efficiently as possible.

My approach has been to first define the invariant masses column:

``````df.Define("M_pair",[](ROOT::RVec<double>& pt, ROOT::RVec<double>& eta, ROOT::RVec<double>& phi) {
auto c = Combinations(pt,2);
auto m  = ROOT::RVec(pt.size(),0.); // take particles to be massless
return InvariantMasses(Take(pt,c[0]),Take(pt,c[1]),
Take(eta,c[0]),Take(eta,c[1]),
Take(phi,c[0]),Take(phi,c[1]),
Take(m,c[0]),Take(m,c[1]));

},{"pt","eta","phi"})
``````

Then I am selecting the highest mass and selecting the pt of the other particles like this:

``````.Define("other_pt",[](ROOT::RVec<double>& pt,ROOT::RVec<double>& masses) {

auto c = Combinations(pt,2);
auto max_M_pair = Reverse( Argsort( masses ) )[0];
return pt[ (Combinations(pt,1)[0]!=c[0][max_M_pair] && Combinations(pt,1)[0]!=c[1][max_M_pair]) ];
},{"pt","M_pair"})
``````

I feel like this is second part is a bit clunky. Is there a better way to do what I want with vector operations?

Thanks!
Will

@eguiraud, our RDataFrame expert is currently on vacation. I’m sure he’ll reply once back. If it’s really urgent, just let me know, I can try to find someone else…

It can wait!

1 Like

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

I hear you

So basically you’d need `RemoveAt(pt, max_M_pair)`?

yes I think so. Well, its sort of the complement of `Take` , although I dont know if you think `Leave` is too unclear in terms of describing what it does.