def process_frame(frame, gcdfile='/cvmfs/icecube.opensciencegrid.org/data/GCD/GeoCalibDetectorStatus_2013.56429_V0.i3.gz', charge_scale=1.0, time_scale=1e-3): """ Processes a frame to create an event graph and metadata out of it. Parameters: ----------- frame : I3Frame The data frame to extract an event graph with features from. gcd_file : str Path to the gcd file. charge_scale : float The normalization constant for charge. time_scale : float The normalization constant for time. """ ### Meta data of the event for analysis of the classifier and creation of ground truth primary = dataclasses.get_most_energetic_neutrino(frame['I3MCTree']) if primary is None: get_weighted_primary(frame, MCPrimary='MCPrimary') primary = frame['MCPrimary'] # Obtain the PDG Encoding for ground truth #frame['PDGEncoding'] = dataclasses.I3Double(primary.pdg_encoding) #frame['InteractionType'] = dataclasses.I3Double(frame['I3MCWeightDict']['InteractionType']) frame['RunID'] = icetray.I3Int(frame['I3EventHeader'].run_id) frame['EventID'] = icetray.I3Int(frame['I3EventHeader'].event_id) frame['PrimaryEnergy'] = dataclasses.I3Double(primary.energy) ### Create features for each event features, coordinates, _ = get_events_from_frame(frame, charge_scale=charge_scale, time_scale=time_scale) for feature_name in vertex_features: frame[feature_name] = dataclasses.I3VectorFloat(features[feature_name]) ### Create offset lookups for the flattened feature arrays per event frame['NumberVertices'] = icetray.I3Int(len(features[features.keys()[0]])) ### Create coordinates for each vertex C = np.vstack(coordinates.values()).T #C, C_mean, C_std = normalize_coordinates(C, weights=None, copy=True) #C_cog, C_mean_cog, C_std_cog = normalize_coordinates(C, weights=features['TotalCharge'], copy=True) frame['VertexX'] = dataclasses.I3VectorFloat(C[:, 0]) frame['VertexY'] = dataclasses.I3VectorFloat(C[:, 1]) frame['VertexZ'] = dataclasses.I3VectorFloat(C[:, 2]) ### Output centering and true debug information frame['PrimaryX'] = dataclasses.I3Double(primary.pos.x) frame['PrimaryY'] = dataclasses.I3Double(primary.pos.y) frame['PrimaryZ'] = dataclasses.I3Double(primary.pos.z) frame['PrimaryAzimuth'] = dataclasses.I3Double(primary.dir.azimuth) frame['PrimaryZenith'] = dataclasses.I3Double(primary.dir.zenith) ### Apply labeling classify_wrapper(frame, None, gcdfile=gcdfile) return True
def add_weighted_primary(phy_frame): if reco_q.is_data(phy_frame): return True if not 'MCPrimary1' in phy_frame.keys(): get_weighted_primary(phy_frame, MCPrimary='MCPrimary1') return
def find_primary(frame): get_weighted_primary(frame)
def add_weighted_primary(phy_frame): if not 'MCPrimary' in phy_frame.keys(): get_weighted_primary(phy_frame, MCPrimary='MCPrimary') return
def getweights(frame, generator, flux): get_weighted_primary(frame) energy = frame['MCPrimary'].energy ptype = frame['MCPrimary'].type weight = (flux(energy, ptype) / generator(energy, ptype)) frame['Weight'] = dataclasses.I3Double(weight)