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 (some of) the same things can be done using the myana analysis framework.

...

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:

Code Block
Code Block
nonenone

def event(self,evt,env):
    try:
   ebeam = evt.getEBeam()
   encoder = evt.get(xtc.TypeId.Type.Id_EncoderData, self.enc_source )
    if ebeam :
            encoder_valuebeamChrg = encoderebeam.value()fEbeamCharge
     except:
       beamEnrg = print "No encoder found in this event"
ebeam.fEbeamL3Energy
            beamPosX  return

You could combine it with phase cavity time, and compute a time delay from it, for example (I don't know the origin of these parameters!):

Code Block
nonenone

= ebeam.fEbeamLTUPosX
        # Encoder Parameters to convertbeamPosY to= picosecondsebeam.fEbeamLTUPosY
       delay_a = -80.0e-6;
    beamAngX = ebeam.fEbeamLTUAngX
        delay_b    beamAngY = 0ebeam.52168;fEbeamLTUAngY
     delay_c = 299792458;
     delay_0beamPkCr = 0;

ebeam.fEbeamPkCurrBC2
      delay_time = (delay_a * encoder_value + delay_b)*1.e-3 / delay_c)  print "ebeam: ", beamChrg, beamEnrg, beamPosX, beamPosY, beamAngX, beamAngY, beamPkCr
    delay_time   = 2else *:
 delay_time / 1.0e-12 + delay_0 + phase_cavity1

Time data

The time of the event can be obtained within the event function:

      print "No EBeam object found"

To read out the energy from the front end enclosure (FEE) gas detector, use getFeeGasDet(). This returns and array of 4 numbers:

Code Block

       fee_energy_array
Code Block
nonenone

def event ( self, evt, env ) :
    event_time = evt.getTimegetFeeGasDet().seconds() + 1.0e-9*evt.getTime().nanoseconds() )

IPIMB diode data

Currently there are two data structures that holds data from the same type of devices. Depending on DAQ
configuration, they are either DetInfo type or BldInfo type. Here are examples for extracting both types
in the user module event function:

Code Block
nonenone

def event(self, evt, env):
    # raw data
    ipmRaw = evt.get(xtc.TypeId.Type.Id_IpimbData, source )
    try:
        ch = [ipmRaw.channel0(),
        gdENRC11 = fee_energy_array[0]
        gdENRC12 = fee_energy_array[1]
        gdENRC21 = fee_energy_array[2]
        gdENRC22 = fee_energy_array[3]
        print "GasDet energy ", gdENRC11,  ipmRaw.channel1(),gdENRC12, gdENRC21, gdENRC22

To read out fit time and charge of the phase cavity, use getPhaseCavity() which returns a structure with the following fields:

Code Block
        pc =     ipmRaw.channel2evt.getPhaseCavity(),
        if pc :
    ipmRaw.channel3() ]
       pcFitTime1 = pc.fFitTime1
            pcFitTime2 = pc.fFitTime2
        ch_volt = [ipmRaw.channel0Volts(),
  pcCharge1 = pc.fCharge1
            pcCharge2 =  ipmRaw.channel1Volts(),pc.fCharge2
            print "PhaseCavity: ", pcFitTime1,  pcFitTime2,  ipmRaw.channel2Volts(),pcCharge1, pcCharge2
        else :
          ipmRaw.channel3Volts() ]
 print "No Phase except:
Cavity object found"

Encoder data (delay scanner)

Code Block
none
none

def event(self,evt,env):
     passtry:

    # feature-extracted data
    ipmFexencoder = evt.get(xtc.TypeId.Type.Id_IpmFexEncoderData, self.enc_source )
    try:
         # array of 4 numbers
         fex_channelencoder_value = ipmFex.channel 

encoder.value()
    except:
     # scalar values
 print "No encoder found in this   fex_sum = ipmFex.sum 
event"
        return

You could combine it with phase cavity time, and compute a time delay from it, for example (I don't know the origin of these parameters!):

Code Block
none
none

     fex_xpos# = ipmFex.xpos
    Encoder Parameters to convert to picoseconds
     fexdelay_yposa = ipmFex.ypos

-80.0e-6;
     except:
delay_b = 0.52168;
     delay_c = 299792458;
    pass

Code Block
nonenone

def event(self, evt, env): delay_0 = 0;

    ipmdelay_time = evt.getSharedIpimbValue("HFX-DG3-IMB-02")(delay_a * encoder_value + delay_b)*1.e-3 / delay_c) 
    #delay_time or= equivalently:
2 * delay_time / # ipm = evt.get(xtc.TypeId.Type.Id_SharedIpimb, "HFX-DG3-IMB-02")
    try: 
        ### Raw1.0e-12 + delay_0 + pcFitTime1

Time data

The time of the event can be obtained within the event function:

Code Block
none
none

def event ( self, evt, env ) : data ###
    event_time = evt.getTime().seconds() + 1.0e-9*evt.getTime().nanoseconds() )

IPIMB diode data

Currently there are two data structures that holds data from the same type of devices. Depending on DAQ
configuration, they are either DetInfo type or BldInfo type. Here are examples for extracting both types
in the user module event function:

Code Block
none
none

def event(self, evt, env):
    # raw data
    ipmRaw = evt.get(xtc.TypeId.Type.Id_IpimbData, source )
    try: # arrays of 4 numbers:
        ch = [ipm.ipimbData.channel0(),
              ipm.ipimbData.channel1(),
              ipm.ipimbData.channel2(),
              ipm.ipimbData.channel3()]
        ch_volt = [ipmipmRaw.ipimbData.channel0Voltschannel0(),
                   ipm.ipimbData.channel1VoltsipmRaw.channel1(),
                   ipm.ipimbData.channel2VoltsipmRaw.channel2(),
                   ipm.ipimbData.channel3Volts()]

      ipmRaw.channel3() ]
 ### Feature-extracted data ###
        # array of 4 numbers:
        fexch_channelsvolt = ipm.ipmFexData.channel [ipmRaw.channel0Volts(),
        
        # scalars:
  ipmRaw.channel1Volts(),
      fex_sum = ipm.ipmFexData.sum 
        fex_xpos = ipm.ipmFexData.xposipmRaw.channel2Volts(),
        fex_ypos = ipm.ipmFexData.ypos

     except:
    ipmRaw.channel3Volts() ]
    pass

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
except:
    def __init__ ( self ):
        # initialize data    pass

    # feature-extracted data
    ipmFex = evt.get(xtc.TypeId.Type.Id_IpmFex, source )
    try:
        self.address =#  "AmoITof-0|Acqiris-0"array of 4 numbers
        self.data fex_channel = []
ipmFex.channel 

         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
scalar values
    def  beginjob ( self, evt, env ) :
 fex_sum = ipmFex.sum 
         cfgfex_xpos = env.getConfig( _pdsdata.xtc.TypeId.Type.Id_AcqConfig, self.address )ipmFex.xpos
         fex_ypos = ipmFex.ypos

     except:
        self.num = cfg.nbrChannels()

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

 pass

Code Block
none
none

def event(self, evt, env):
    ipm = evt.getSharedIpimbValue("HFX-DG3-IMB-02")
Code Block
    def# eventor (equivalently:
 self, evt, env )# :
ipm = evt.get(xtc.TypeId.Type.Id_SharedIpimb, "HFX-DG3-IMB-02")
     channel = 0try: 
        acqData = evt.getAcqValue( self.address, channel, env)
### Raw data ###
        # arrays ifof acqData4 numbers:
        ch    self.counter+=1= [ipm.ipimbData.channel0(),
            wf = acqDataipm.ipimbData.waveformchannel1(),
      #    returns a waveform array of numpy.ndarray type.
 ipm.ipimbData.channel2(),
              selfipm.dataipimbData.appendchannel3(wf)

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

Code Block

]
      def endjob( self, env ) :

  ch_volt = [ipm.ipimbData.channel0Volts(),
       data = np.array(self.data)    # this is an array of shape ipm.ipimbData.channel1Volts(Nevents),
 nSamples)

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

        pltipm.ipimbData.plotchannel3Volts(xs)]

        ### Feature-extracted  plt.xlabel('Seconds')
data ###
         plt.ylabel('Volts')# array of 4 numbers:
        plt.show()

Which gives you a plot like this
Image Removed

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:

Code Block

fex_channels = ipm.ipmFexData.channel 
        
        # scalars:
        ebeamfex_sum = evt.getEBeam() ipm.ipmFexData.sum 
        iffex_xpos ebeam :
= ipm.ipmFexData.xpos
        fex_ypos = ipm.ipmFexData.ypos

   beamChrg = ebeam.fEbeamChargeexcept:
            beamEnrg = ebeam.fEbeamL3Energy pass

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__ (      beamPosX = ebeam.fEbeamLTUPosXself ):
        #    beamPosY = ebeam.fEbeamLTUPosY
      initialize data
      beamAngX = ebeamself.fEbeamLTUAngX
address =  "AmoITof-0|Acqiris-0"
         beamAngYself.data = ebeam.fEbeamLTUAngY[]
        self.counter    beamPkCr = ebeam.= 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
fEbeamPkCurrBC2
    def beginjob ( self, evt, env   print) "ebeam: ", beamChrg, beamEnrg, beamPosX, beamPosY, beamAngX, beamAngY, beamPkCr
        else ::
        cfg = env.getConfig( _pdsdata.xtc.TypeId.Type.Id_AcqConfig, self.address )
        self.num    print "No EBeam object found"
= cfg.nbrChannels()

The read the event waveform data (an array) and append it to the self.data listTo read out the energy from the front end enclosure (FEE) gas detector, use getFeeGasDet(). This returns and array of 4 numbers:

Code Block
    def event (  fee_energy_array = evt.getFeeGasDet()self, evt, env ) :
        gdENRC11channel = fee_energy_array[0]
        gdENRC12acqData = fee_energy_array[1]
        gdENRC21 = fee_energy_array[2]evt.getAcqValue( self.address, channel, env)
        gdENRC22if = fee_energy_array[3]acqData :
        print "GasDet energy ", gdENRC11, gdENRC12, gdENRC21, gdENRC22

To read out fit time and charge of the phase cavity, use getPhaseCavity() which returns a structure with the following fields:

Code Block

 self.counter+=1
            pcwf = evtacqData.getPhaseCavitywaveform()
   # returns a waveform array ifof pc :
numpy.ndarray type.
            self.data.append(wf)

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

Code Block

   pcFitTime1 = pc.fFitTime1
    def endjob( self, env ) :

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

  pcCharge1 = pc.fCharge1
    # take the mean of all events for pcCharge2each =sampling pc.fCharge2time
        xs = np.mean(data, axis=0)

  print "PhaseCavity: ", pcFitTime1,  pcFitTime2, pcCharge1, pcCharge2 plt.plot(xs)

        else :plt.xlabel('Seconds')
        plt.ylabel('Volts')
    print "No Phase Cavity object found"
 plt.show()

Which gives you a plot like this
Image Added

Display images from princeton camera

...