Code Monkey home page Code Monkey logo

Comments (2)

jpivarski avatar jpivarski commented on August 19, 2024

Hi! Sorry I'm getting back to this late—I'm catching up to issues from the weekend.

The idea of uproot-methods was to be user-contributed—not because I'm trying to offload work, but because the scope that it represents (Pythonic method for any ROOT classes that users need) is very open-ended.

You've seen the code: each of these methods assumes Numpy-like arrays (which can be awkward arrays, thanks to their shared behavior) and performs vectorized calculations on them. The corresponding rotation code for TVector3 (https://github.com/scikit-hep/uproot-methods/blob/master/uproot_methods/classes/TVector3.py#L32-L80) is much more complicated than it would be for TVector2, since that just takes a scalar angle.

It would be something like this:

    def rotate(self, angle):
        cosangle = self.awkward.numpy.cos(angle)
        sinangle = self.awkward.numpy.sin(angle)
        xprime = self.x*cosangle - self.y*sinangle
        yprime = self.x*sinangle + self.y*cosangle
        return TVector2Array.from_cartesian(xprime, yprime)

Okay, I guess there's a slight complication from the fact that we want to get numpy from an object attached to the array itself (so that in the future, this can be swapped for cupy for GPU processing).

Also, looking into it, I wonder how deep your use-case goes—if you're only interested in Numpy arrays of 2-vectors or any level of jaggedness. The TLorentzVector.from_cartesian constructor has been expanded to handle arbitrary jaggedness, but not the TVector2.from_cartesian constructor. (Oh, TVector3 uses a different trick to get both flat-Numpy and jagged arrays; it uses empty_like(): https://github.com/scikit-hep/uproot-methods/blob/master/uproot_methods/classes/TVector3.py#L119-L125 . Maybe we could do the same here.)

See what I mean about the open-ended scope? If you try to implement this for your case (and open a pull request), I'll help you with any issues you run into. Thanks!

from uproot3-methods.

phylsix avatar phylsix commented on August 19, 2024

Hi, I open a PR #64, mimicking what TVector3 is implemented. What do you think? Thanks!

from uproot3-methods.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.