Examples

Often the fastest way to get an impression on the API is through examples.

Measuring cross-correlation

The code below shows a simple but operational example of how to perform a cross-correlation measurement with the Time Tagger API. In fact, such simple code is already sufficient to perform real-world experiments in a lab.

# Create an instance of the TimeTagger
tagger = createTimeTagger()

# Adjust trigger level on channel 2 to 0.25 Volt
tagger.setTriggerLevel(2, 0.25)

# Add time delay of 123 picoseconds on the channel 3
tagger.setInputDelay(3, 123)

# Create Correlation measurement for events in channels 2 and 3
corr = Correlation(tagger, 2, 3, binwidth=10, n_bins=1000)

# Run Correlation for 1 second to accumulate the data
corr.startFor(int(1e12), clear=True)
corr.waitUntilFinished()

# Read the correlation data
data = corr.getData()

Using virtual channels

Time Tagger API implements on-the-fly time-tag processing through virtual channels. The following example shows how time-tags from two different real channels can be combined into one virtual channel.

tagger = createTimeTagger()

# Enable internal generator to channels 1 and 2. Frequency ~800 kHz.
tagger.setTestSignal([1,2], True)

# Create virtual channel that combines time-tags from real inputs 1 and 2
vc = Combiner(tagger, [1, 2])

# Create countrate measurement at channels 1, 2 and the "combiner" channel
rate = Countrate(tagger, [1, 2, vc.getChannel()])

# Run Countrate for 1 second and print the result for all three channels
rate.startFor(int(1e12), clear=True)
rate.waitUntilFinished()
print(rate.getData())

>> [ 800008.81  800008.81 1600017.62]

From the results, we see that the combined event rate is a sum of the event rates at both input channels, as expected.

Using multiple Time Taggers

You can use multiple Time Taggers on one computer simultaneously. In this case, you usually want to associate your instance of the TimeTagger class to the Time Tagger device. This is done by specifying the serial number of the device, an optional parameter, to the factory function createTimeTagger().

tagger_1 = createTimeTagger("123456789ABC")
tagger_2 = createTimeTagger("123456789XYZ")

The serial number of a physical Time Tagger is a string of digits and letters (every Time Tagger has a unique hardware serial number). It is printed on the label at the bottom of the Time Tagger hardware. In addition, the scanTimeTagger() method shows the serial numbers of the connected but not instantiated Time Taggers. It is also possible to read the serial number for a connected device using TimeTagger.getSerial() method.

You can find more examples supplied with the TimeTagger software. Please see the examples\<language> subfolder of your Time Tagger installation. Usually, the installation folder is C:\Program Files\Swabian Instruments\Time Tagger.

Using Time Tagger remotely

Using Network Time Tagger you can stream the time-tags to a remote computer(s) and process them independently. You can easily work with your Time Tagger device over the network as if your remote computer is connected directly to the hardware. This example shows how you can start the server, connect a client to it and perform a simple countrate measurement.

You can start the server by calling TimeTagger.startServer() on a existing TimeTagger object.

# Connected to the hardware as usual
tagger = createTimeTagger()

# Start the server with full remote control enabled
tagger.startServer(AccessMode.Control)

# Keep this process running
input('Press ENTER to exit the server process...')

# Stop the server if user pressed ENTER key
tagger.stopServer()

# Disconnect from the hardware
freeTimeTagger(tagger)

For simplicity of the example we assume that the server is running as a separate process on the same computer. Therefore, we run the client code on the same computer and use localhost as a server address. You can also adjust the server address and try the client code on another PC.

# Server address, we assume it runs on the same computer
address = 'localhost'

# Connect to the server
ttn = createTimeTaggerNetwork(address)

# Enable test signal on the remote hardware
ttn.setTestSignal(1, True)
ttn.setTestSignal(2, True)

# Create `Countrate` measurement and run it for a fixed duration
cr = Countrate(ttn, [1,2,3])
cr.startFor(1e12)
cr.waitUntilFinished()

# Print the resulting data
print(cr.getData())

# Close the connection to the server
freeTimeTagger(ttn)