Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This page holds a few example code-snippets for use in pyana analysis. The analysis is written in python and uses MatPlotLib.PyPlot for plotting of data. Compare with myana user examples to see how the same things can be done using the myana analysis framework.

Acqiris waveform data

This method can be used for any detector/device that has Acqiris waveform data. Edit the self.address field to get the detector of your choice.

Initialize class members:

Code Block

    def __init__ ( self ):
        # initialize data
        self.address =  "AmoITof-0|Acqiris-0"
        self.data = []
        self.counter = 0

If you're curious to see any of the Acqiris configuration, e.g. how many channels do we have, you can inspect the AcqConfig object:

Code Block

    def beginjob ( self, evt, env ) :
        cfg = env.getConfig( _pdsdata.xtc.TypeId.Type.Id_AcqConfig, self.address )
        self.num = cfg.nbrChannels()

The read the event waveform data (an array) and append it to the self.data list:

Code Block

    def event ( self, evt, env ) :
        channel = 0
        acqData = evt.getAcqValue( self.address, channel, env)
        if acqData :
            self.counter+=1
            wf = acqData.waveform()
            self.data.append(wf)

At the end of the job, take the average and plot it:

Code Block

    def endjob( self, env ) :

        data = np.array(self.data)  # this is an array of shape (Nevents, nSamples)

        # take the mean of all events for each sampling time
        xs = np.mean(data, axis=0)

        plt.plot(xs)

        plt.xlabel('Seconds')
        plt.ylabel('Volts')
        plt.show()

Which gives you a plot like this
Image Added

Beamline data (Bld)

To read out energy, charge and position of the beam from the beamline data, use getEBeam(). It returns a class/structure that has the following members/fields:

...