def Physics(self, frame): track = frame[self.track] frame[ 'I3RecoPulseSeriesMap_union'] = dataclasses.I3RecoPulseSeriesMapUnion( frame, self.pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, 'I3RecoPulseSeriesMap_union') tanks_dist, tanks_charge = [], [] for omkey, pulses in pulse_map: # Get distance of clostest approach to DOM from track dist = self.get_dist(track, self.geomap[omkey].position) tanks_dist.append(dist) # Get charge recorded in DOM charge = sum([pulse.charge for pulse in pulses]) tanks_charge.append(charge) # dist_bins = np.linspace(10, 1000, 100) dist_bins = np.logspace(2, 3, 25) if tanks_dist and tanks_charge: # ldf, _ = np.histogram(np.log10(tanks_dist), bins=dist_bins, # weights=tanks_charge) ldf, _ = np.histogram(tanks_dist, bins=dist_bins, weights=tanks_charge) else: ldf = np.zeros(len(dist_bins) - 1, dtype=float) frame['tank_charge_v_dist'] = dataclasses.I3VectorDouble(ldf) del frame['I3RecoPulseSeriesMap_union'] self.PushFrame(frame)
def dstofflinemerge(frame, Output='', Input=[]): rootpulses = [] for i in Input: if not i in frame: continue rootpulses.append(i) frame[Output] = dataclasses.I3RecoPulseSeriesMapUnion(frame, rootpulses)
def Unify(frame, Keys, Output): """ Simple utility to merge RecoPulseSerieses into a single Union. """ extants = [k for k in Keys if k in frame] union = dataclasses.I3RecoPulseSeriesMapUnion(frame, extants) frame[Output] = union
def Physics(self, frame): pulses_key = 'I3RecoPulseSeriesMap_union' frame[pulses_key] = dataclasses.I3RecoPulseSeriesMapUnion( frame, self.pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, pulses_key) tank_x, tank_y, tank_charge = [], [], [] for omkey, pulses in pulse_map: x, y, z = self.geomap[omkey].position tank_x.append(x) tank_y.append(y) # Check for nan charges charge = 0 for pulse in pulses: if pulse.charge != NaN: charge += pulse.charge else: print('pulse.charge is NaN!!') # charge = sum([pulse.charge for pulse in pulses]) tank_charge.append(charge) if tank_x and tank_y and tank_charge: tank_charge = np.nan_to_num(tank_charge) frame['tank_x'] = dataclasses.I3VectorDouble(tank_x) frame['tank_y'] = dataclasses.I3VectorDouble(tank_y) frame['tank_charge'] = dataclasses.I3VectorDouble(tank_charge) # hist, _, _ = np.histogram2d(tanks_x, tanks_y, # bins=[self.xbins, self.ybins], # weights=tanks_charge) # self.hists.append(hist) # event_header = frame['I3EventHeader'] # event_id = '{}_{}_{}_{}'.format(self.sim, # event_header.run_id, # event_header.event_id, # event_header.sub_event_id) # self.event_ids.append(event_id) del frame[pulses_key] self.PushFrame(frame)
def Physics(self, frame): frame[ 'I3RecoPulseSeriesMap_union'] = dataclasses.I3RecoPulseSeriesMapUnion( frame, self.pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, 'I3RecoPulseSeriesMap_union') tanks_x, tanks_y, tanks_charge = [], [], [] for omkey, pulses in pulse_map: x, y, z = self.geomap[omkey].position tanks_x.append(x) tanks_y.append(y) charge = sum([pulse.charge for pulse in pulses]) tanks_charge.append(charge) if tanks_x and tanks_y and tanks_charge: frame['tanks_x'] = dataclasses.I3VectorDouble(tanks_x) frame['tanks_y'] = dataclasses.I3VectorDouble(tanks_y) frame['tanks_charge'] = dataclasses.I3VectorDouble(tanks_charge) del frame['I3RecoPulseSeriesMap_union'] self.PushFrame(frame)
def add_IceTop_tankXYcharge(frame, pulses): frame[ 'I3RecoPulseSeriesMap_union'] = dataclasses.I3RecoPulseSeriesMapUnion( frame, pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, 'I3RecoPulseSeriesMap_union') geomap = frame['I3Geometry'].omgeo tanks_x, tanks_y, tanks_charge = [], [], [] for omkey, pulses in pulse_map: x, y, z = geomap[omkey].position tanks_x.append(x) tanks_y.append(y) charge = sum([pulse.charge for pulse in pulses]) tanks_charge.append(charge) if tanks_x and tanks_y and tanks_charge: frame['tanks_x'] = dataclasses.I3VectorDouble(tanks_x) frame['tanks_y'] = dataclasses.I3VectorDouble(tanks_y) frame['tanks_charge'] = dataclasses.I3VectorDouble(tanks_charge) del frame['I3RecoPulseSeriesMap_union']
def Physics(self, frame): union_key = 'I3RecoPulseSeriesMap_union' frame[union_key] = dataclasses.I3RecoPulseSeriesMapUnion( frame, self.pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, union_key) # tanks_x, tanks_y, tanks_charge = [], [], [] tank_charges = defaultdict(list) # tank_x = defaultdict(list) # tank_y = defaultdict(list) for omkey, omgeo in self.geomap: # Only interested in saving IceTop OM charges if omgeo.omtype.name != 'IceTop': continue # x, y, z = omgeo.position # tank_x[omkey].append(x) # tank_y[omkey].append(y) try: pulses = pulse_map[omkey] charge = sum([pulse.charge for pulse in pulses]) except KeyError: charge = 0 tank_charges[omkey].append(charge) # if tanks_x and tanks_y and tanks_charge: # frame['tanks_x'] = dataclasses.I3VectorDouble(tanks_x) # frame['tanks_y'] = dataclasses.I3VectorDouble(tanks_y) # frame['tanks_charge'] = dataclasses.I3VectorDouble(tanks_charge) # self.tank_charges.append(pd.DataFrame(tank_charges)) del frame[union_key] frame['NNcharges'] = dataclasses.I3MapKeyVectorDouble(tank_charges) print(frame['NNcharges']) # frame['tank_x'] = dataclasses.I3MapKeyVectorDouble(tank_x) # frame['tank_y'] = dataclasses.I3MapKeyVectorDouble(tank_y) self.PushFrame(frame)
def slopunion(frame): slopunion = dataclasses.I3RecoPulseSeriesMapUnion( frame, ["SLOPPOZELA_Pulses", "SLOPPORATOR_Pulses"]) frame["SLOP_Pulses"] = slopunion return True
def Physics(self, frame): track = frame[self.track] x_track, y_track, z_track = track.pos frame[ 'I3RecoPulseSeriesMap_union'] = dataclasses.I3RecoPulseSeriesMapUnion( frame, self.pulses) pulse_map = dataclasses.I3RecoPulseSeriesMap.from_frame( frame, 'I3RecoPulseSeriesMap_union') charges = [] dists = [] for omkey, omgeo in self.geomap: # Only interested in saving IceTop OM charges if omgeo.omtype.name != 'IceTop': continue try: pulses = pulse_map[omkey] charge = sum([pulse.charge for pulse in pulses]) x, y, z = omgeo.position dist = np.sqrt((x - x_track)**2 + (y - y_track)**2) except KeyError: continue charges.append(charge) dists.append(dist) # tanks_dist, tanks_charge = [], [] # for omkey, pulses in pulse_map: # # Get distance of clostest approach to DOM from track # dist = self.get_dist(track, self.geomap[omkey].position) # tanks_dist.append(dist) # # Get charge recorded in DOM # charge = sum([pulse.charge for pulse in pulses]) # tanks_charge.append(charge) if dists and charges: # frame.Put('tanks_charge_{}'.format(self.track), dataclasses.I3VectorDouble(tanks_charge)) # frame.Put('tanks_dist_{}'.format(self.track), dataclasses.I3VectorDouble(tanks_dist)) # frame.Put('IceTop_charge', dataclasses.I3Double( np.sum(charges) )) # Convert to ndarrays for easy array manipulation dists = np.asarray(dists) charges = np.asarray(charges) # Sometimes there are nan pulses...not sure why charges = np.nan_to_num(charges) distance_mask = dists >= self.min_dist total_charge = np.sum(charges[distance_mask]) else: total_charge = 0.0 if np.isnan(total_charge).any(): print('total_charge = {}'.format(total_charge)) print('dists = {}'.format(dists)) print('charges = {}'.format(charges)) print('distance_mask = {}'.format(distance_mask)) print('self.min_dist = {}'.format(self.min_dist)) total_charge = dataclasses.I3Double(total_charge) frame.Put('IceTop_charge_beyond_{}m'.format(self.min_dist), total_charge) # # try: # lap_params = frame['LaputopParams'] # lap_log_s125 = lap_params.value(recclasses.LaputopParameter.Log10_S125) # lap_beta = lap_params.value(recclasses.LaputopParameter.Beta) # tank_dist_mask = tanks_dist > 11 # # beta, log_s125 = fit_DLP_params(tanks_charge[distance_mask], # # tanks_dist[distance_mask], lap_log_s125, lap_beta) # log_s125, beta = fit_DLP_params(tanks_charge[distance_mask], # tanks_dist[distance_mask], lap_log_s125, lap_beta) # # print('lap_beta, refit_beta = {}, {}'.format(lap_beta, beta)) # # print('lap_log_s125, refit_log_s125 = {}, {}'.format(lap_log_s125, log_s125)) # # print('='*20) # except Exception as e: # print('Refitting shower to DLP didn\'t work out. ' # 'Setting to NaN...') # print(e) # log_s125, beta = NaN, NaN # pass # frame.Put('refit_beta', dataclasses.I3Double(beta)) # frame.Put('refit_log_s125', dataclasses.I3Double(log_s125)) # # print('='*20) del frame['I3RecoPulseSeriesMap_union'] self.PushFrame(frame)