Ejemplo n.º 1
0
    def draw(self):
        from mlreco.visualization import plotly_layout3d
        from mlreco.visualization.voxels import scatter_voxels, scatter_label
        import plotly.plotly as py
        import plotly.graph_objs as go
        from plotly.offline import init_notebook_mode, iplot
        init_notebook_mode(connected=False)

        # Create labels for the voxels
        # Use a different color for each cluster
        labels = np.full(len(self.output['energy'][:,-1]), -1)
        for i, s in enumerate(self.output['showers']):
            labels[s.voxels] = i

        # Draw voxels with cluster labels
        voxels = self.output['energy'][:,:3]
        graph_voxels = scatter_label(voxels, labels, 2)[0]
        graph_voxels.name = 'Shower ID'
        graph_data = [graph_voxels]

        if len(self.output['showers']):
            # Add EM primary points
            points = np.array([s.start for s in self.output['showers']])
            graph_start = scatter_voxels(points)[0]
            graph_start.name = 'Shower starts'
            graph_data.append(graph_start)
            
            # Add EM primary directions
            dirs = np.array([s.direction for s in self.output['showers']])
            arrows = go.Cone(x=points[:,0], y=points[:,1], z=points[:,2], 
                             u=dirs[:,0], v=dirs[:,1], w=dirs[:,2],
                             sizemode='absolute', sizeref=0.25, anchor='tail',
                             showscale=False, opacity=0.4)
            graph_data.append(arrows)

            # Add a vertex if matches, join vertex to start points
            for i, m in enumerate(self.output['matches']):
                v = self.output['vertices'][i]
                s1, s2 = self.output['showers'][m[0]].start, self.output['showers'][m[1]].start
                points = [v, s1, v, s2]
                line = scatter_voxels(np.array(points))[0]
                line.name = 'Pi0 Decay'
                line.mode = 'lines,markers'
                graph_data.append(line)

        # Draw
        iplot(go.Figure(data=graph_data,layout=plotly_layout3d()))
Ejemplo n.º 2
0
    def draw(self, **kargs):
        import plotly
        from mlreco.visualization.points import scatter_points
        import plotly.graph_objs as go
        from plotly.offline import iplot

        graph_data = []
        # Draw voxels with cluster labels
        energy = self.output['energy']
        shower_mask = self.output['shower_mask']
        graph_data += scatter_points(energy,
                                     markersize=2,
                                     color=energy[:, -1],
                                     colorscale='Inferno')
        graph_data[-1].name = 'Energy'

        colors = plotly.colors.qualitative.Light24
        for i, s in enumerate(self.output['showers']):
            points = energy[shower_mask][s.voxels]
            color = colors[i % (len(colors))]
            graph_data += scatter_points(points, markersize=2, color=color)
            graph_data[-1].name = 'Shower %d (id=%d)' % (i, s.pid)

        if len(self.output['showers']):

            # Add EM primary points
            points = np.array([s.start for s in self.output['showers']])
            graph_data += scatter_points(points)
            graph_data[-1].name = 'Shower Starts'

            # Add EM primary directions
            dirs = np.array([s.direction for s in self.output['showers']])
            cone_start = points[:, :3]
            arrows = go.Cone(x=cone_start[:, 0],
                             y=cone_start[:, 1],
                             z=cone_start[:, 2],
                             u=-dirs[:, 0],
                             v=-dirs[:, 1],
                             w=-dirs[:, 2],
                             sizemode='absolute',
                             sizeref=1.0,
                             anchor='tip',
                             showscale=False,
                             opacity=0.4)
            graph_data.append(arrows)

            # Add a vertex if matches, join vertex to start points
            if 'matches' in self.output:
                for i, match in enumerate(self.output['matches']):
                    v = self.output['vertices'][i]
                    idx1, idx2 = match
                    s1, s2 = self.output['showers'][idx1].start, self.output[
                        'showers'][idx2].start
                    points = [v, s1, v, s2]
                    graph_data += scatter_points(np.array(points), color='red')
                    graph_data[
                        -1].name = 'Pi0 (%.2f MeV)' % self.output['masses'][i]
                    graph_data[-1].mode = 'lines,markers'

        # Draw
        #go.Figure(data=graph_data,layout=self.layout(**kargs))
        from mlreco.visualization import plotly_layout3d
        fig = go.Figure(data=graph_data, layout=plotly_layout3d())
        camera = dict(up=dict(x=0, y=0, z=0),
                      center=dict(x=0, y=0, z=-0.3),
                      eye=dict(x=0.4, y=0.4, z=0.4))
        fig.update_layout(scene_camera=camera, showlegend=False)
        iplot(fig)