diff options
-rwxr-xr-x | utils/plot-energy | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/utils/plot-energy b/utils/plot-energy index 49ede76..9000f4a 100755 --- a/utils/plot-energy +++ b/utils/plot-energy @@ -249,6 +249,9 @@ if __name__ == '__main__': ev = pd.concat([pd.read_hdf(filename, "ev") for filename in args.filenames],ignore_index=True) fits = pd.concat([pd.read_hdf(filename, "fits") for filename in args.filenames],ignore_index=True) + rhdr = pd.concat([pd.read_hdf(filename, "rhdr") for filename in args.filenames],ignore_index=True) + + first_gtid = rhdr.set_index('run').to_dict()['first_gtid'] # First, remove junk events since orphans won't have a 50 MHz clock and so # could screw up the 50 MHz clock unwrapping @@ -260,16 +263,24 @@ if __name__ == '__main__': # 50 MHz clock because it also wraps around. Finally, I'm hesitant to sort # by the 10 MHz clock since it can be unreliable. # - # Therefore, we just assume that the events are already in order in the - # zdab file. Later, we check that the GTIDs make sense. + # Update: Phil proposed a clever way to get the events in order using the + # GTID: # - # Note: There are no sub run IDs in the runs before run 10614, so it's - # necessary to specify those on the command line in the order of the - # subrun. + # > The GTID rollover should be easy to handle because there should never + # > be two identical GTID's in a run. So if you order the events by GTID, + # > you can assume that events with GTID's that come logically before the + # > first GTID in the run must have occurred after the other events. # - # Note: We use mergesort here since it's the only stable sort and we want - # to preserve the order of the events. - ev = ev.sort_values(by=['run','sub_run'],kind='mergesort') + # Therefore, we can just add 0x1000000 to all GTIDs before the first GTID + # in the event and sort on that. We get the first GTID from the RHDR bank. + ev['gtid_sort'] = ev['gtid'].copy() + for run, ev_run in ev.groupby('run'): + if run not in first_gtid: + print_warning("No RHDR bank for run %i! Assuming first event is the first GTID." % run) + first_gtid[run] = ev_run.gtid[0] + ev_run.loc[ev_run.gtid < first_gtid[run],'gtid_sort'] += 0x1000000 + + ev = ev.sort_values(by=['run','gtid_sort'],kind='mergesort') for run, ev_run in ev.groupby('run'): # Warn about 50 MHz clock jumps since they could indicate that the |