Skip to content

Conversation

@sam-grant
Copy link
Contributor

Added the Print class to mu2epyutils.py

This class contains functions to print the contents of an Awkward array in a human-readable form. These functions are called PrintNEvents and PrintEvent, which work by looping through the events and then recursively searching the event array for fields and subfields.

I have found this to be extremely useful for developing cuts and for inspecting particular events.

Raw Awkward array (not readable):

>>> print(array_) 
`[{run: 1202, subrun: 52, event: 9989, 'crvcoincs.sectorType': [3], ...}, ...]`

Human readable, one event:

>>> from mu2epyutil import Print  
>>> pr = Print()
>>> pr.PrintNEvents(array_, n=1)

-------------------------------------------------------------------------------------
run: 1202
subrun: 52
event: 9989
crvcoincs.sectorType: [3]
crvcoincs.pos.fCoordinates.fX: [-291]
crvcoincs.pos.fCoordinates.fY: [2.71e+03]
crvcoincs.pos.fCoordinates.fZ: [-7.42e+03]
crvcoincs.time: [582]
crvcoincs.timeStart: [593]
crvcoincs.PEs: [693]
crvcoincs.PEsPerLayer[4]: [[177, 191, 135, 191]]
crvcoincs.sidePEsPerLayer[8]: [[91.9, 84.6, 108, 82.8, 61.5, 73.1, 91.8, 99.7]]
crvcoincs.nHits: [18]
crvcoincs.nLayers: [4]
crvcoincs.angle: [-0.705]
trk.status: [1, 1]
trk.nactive: [31, 31]
trk.nhits: [31, 31]
trk.nplanes: [12, 12]
trk.nnullambig: [4, 7]
trk.ndof: [57, 57]
trk.fitcon: [0.00865, 0.884]
trksegs.mom.fCoordinates.fX: [[-62.9, -64.2, -74.9], [-63.1, -64.2, -74.7]]
trksegs.mom.fCoordinates.fY: [[-59.5, -56.2, -39.2], [-59.9, -56.3, -39.3]]
trksegs.mom.fCoordinates.fZ: [[79.6, 80.8, 81.3], [79.6, 80.8, 81.3]]
trksegs.pos.fCoordinates.fX: [[-380, -381, -333], [-380, -382, -334]]
trksegs.pos.fCoordinates.fY: [[185, 195, 237], [186, 195, 236]]
trksegs.pos.fCoordinates.fZ: [[-1.63e+03, 10.1, 1.64e+03], [-1.63e+03, 10.1, 1.64e+03]]
trksegs.time: [[641, 649, 657], [636, 647, 657]]
trksegs.dmom: [[0, 0, 0], [0, 0, 0]]
trksegs.momerr: [[0.0735, 0.0705, 0.0696], [0.0915, 0.087, 0.0867]]
trksegs.inbounds: [[True, True, True], [True, True, True]]
trksegs.gap: [[False, False, False], [False, False, False]]
trksegs.early: [[True, False, False], [True, False, False]]
trksegs.late: [[False, False, True], [False, False, True]]
trksegs.sid: [[0, 1, 2], [0, 1, 2]]
trksegs.sindex: [[0, 0, 0], [0, 0, 0]]
-------------------------------------------------------------------------------------

I also suggest simplifying the class names in general, so pyutils_print -> Print.

@sophiemiddleton sophiemiddleton merged commit 96d2e3f into Mu2e:pyutils-dev Nov 20, 2024
@sam-grant
Copy link
Contributor Author

I should add that the fields being printed depend on the branches that have you have loaded (it picks them up automatically). In this example I am using:

    branch_names_ = [ 
        # Events
        'run',
        'subrun',
        'event',
        # CRV coincidences
        'crvcoincs.sectorType', 
        'crvcoincs.pos.fCoordinates.fX',
        'crvcoincs.pos.fCoordinates.fY',
        'crvcoincs.pos.fCoordinates.fZ',
        'crvcoincs.time', 
        'crvcoincs.timeStart',
        'crvcoincs.PEs',
        'crvcoincs.PEsPerLayer[4]',
        'crvcoincs.sidePEsPerLayer[8]',
        'crvcoincs.nHits',
        'crvcoincs.nLayers', 
        'crvcoincs.angle',
        # Tracks
        'trk.status',
        'trk.nactive',
        'trk.nhits',
        'trk.nplanes',
        'trk.nnullambig',
        'trk.ndof',
        'trk.fitcon',
        # Track segments
        'trksegs'
    ] 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants