Git Product home page Git Product logo

hepaccelerate-cms's People

Contributors

irenedutta23 avatar jpata avatar kondratyevd avatar nanlu06 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hepaccelerate-cms's Issues

Bug in muon FSR correction with offsets

I was setting up some tests (PR #55) on an unskimmed 2016 sync file and I noticed an issue with the muon FSR correction code on hmumu_utils.py#L1228. You can see the automatic test failing here.

It's not correct to assume that one can use offsets[0:-1] to index into the underlying data array. In particular, if e.g. the last event has 0 muons, the offsets will be [ ... 181229 181231 181231], where the muon data array has length 181231. This did not show up in testing as we apply a skim on the HLT bit, which removes such events. I think that there should be no physics effect from this bug if there is no error, but I'm not 100% sure. In this case, the error arises because we are doing manual offset manipulation. I think offset manipulation would be best left to either:

  1. an explicit Numba loop, which will throw an error/assert and can be checked more easily
  2. use awkward-array library (we so far use it minimally as it does not support GPUs yet)

One can test this with the following script:

import uproot

tt = uproot.open("data/myNanoProdMc2016_NANO.root").get("Events")
mu_pt = tt.array("Muon_pt")
print(mu_pt.content.shape)
print(mu_pt.offsets)

for iev in range(len(mu_pt.offsets) - 1):
    imu1 = mu_pt.offsets[iev]
    imu2 = mu_pt.offsets[iev+1]
    print(f"Event {iev} has {imu2-imu1} muons (offsets {imu1}:{imu2})")
    for imu in range(imu1, imu2):
        print(imu, mu_pt.content[imu])

mu_pt.content[mu_pt.offsets[0:-1]]

Test file: myNanoProdMc2016_NANO.root

@kondratyevd if you have time next week, could you take a look at this? To me, a CPU-only numba function such as the following:

#Corrects the muon momentum and isolation, if a matched FSR photon with dR<0.4 is found
@numba.njit
def correct_muon_with_fsr(
        muons_offsets, fsr_offsets,
        muons_pt, muons_eta, muons_phi, muons_mass, muons_iso, muons_fsrIndex
        fsr_pt, fsr_eta, fsr_phi, fsr_mass,
        out_muons_pt, out_muons_eta, out_muons_phi, out_muons_mass, out_muons_iso
    ):
    for iev in numba.prange(len(muons_offsets) - 1):

        #loop over muons in event
        mu1 = muons_offsets[iev]
        mu2 = muons_offsets[iev + 1]

        for imu in range(mu1, mu2):

            #relative FSR index in the event 
            fsr_idx_relative = muons_fsrIndex[imu]
            if fsr_idx_relative >= 0:
                #absolute index in the full FSR vector for all events
                ifsr = fsr_offsets[iev] + fsr_idx_relative

                this_mu_pt = muons_pt[imu]
                ... (and others)

                this_fsr_pt = fsr_pt[ifsr]
                ... (and others)

                #compute dR between muon and FSR, check <0.4
                #compute and set corrected isolation
                #compute and set corrected momentum

would perhaps be easier to follow and debug. What do you think? I'm also open to alternatives...

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.