Tutorial

These instructions assume that you have already successfully completed parts 1 through 5 of the JAS tutorial.

Part 7: Performing Local Jobs For Event Generation

Tutorial parts 1 through 5 showed you some of the valuable functions of JAS while performing a local job for data analysis. This portion of the tutorial will build on that knowledge by showing you how to perform a local job for event generation. First lets review what a local job for event generation is. 

In a local job all events take place on the user's (local) machine. A local job for event generation will use an event generator to create a data set of events. 

To create a local job for event generation you must activate the New Job Wizard by either:

  • selecting 'New Job' from the 'Jobs' submenu, or
  • selecting 'Job' from the 'New' submenu of the 'File' menu, or
  • clicking on the new job button on the toolbar wpe1F0.jpg (860 bytes)

The New Job Wizard, shown below, will appear.

Enter the job name as 'LocalGenerationJob' and select 'A local job for generating events'. Click 'Next'.

After clicking Next' on the first page of the New Job Wizard, the following setup page will ask you to use the Program Page Wizard to create the event generator code.

Make sure the check box is selected and press 'Finish'.

The opening page of the Program Page Wizard, shown below, will appear. The wizard is used to create custom source files suited to your needs while following Java language requirements and JAS specifications for event  generators.

Enter the name 'MyGeneration' for the class the wizard will generate. Below, you must select whether you are creating an event generator or an event analyzer. Select event generator and click on 'Next'.

Now the program wizard will display the event generation setup page, shown below. To write an event generator in JAS, you must create a Java class that extends the class hep.analysis.EventGenerator, compile it, and load it into the application. As when you performed the data analysis job earlier in the tutorial, the wizard will help by creating most of the generator source file. A user does not have to use the wizard, but if you don't you should be aware of the guidelines for event generators that the wizard normally takes care of for you. The following list provides a brief description of each field in the wizard's event generator setup page and the recommended entries for this tutorial:

Click on 'Finish' when all of the setup is complete.  When you click on 'Finish', the wizard will offer to save the file.  It is a good idea to save it now because you cannot compile it until it is saved. Save it as 'MyGeneration.java'.

Your source file, 'MyGeneration.java', will be created and displayed on a display page. Because you have made use of all of the Event Generator wizard options, all you need to do is change the generateEvent() method to include the simulation you want. Once that is complete, you will have a syntactically correct file that can be compiled and loaded.  Below is the generateEvent() method the wizard has provided:

public EventData generateEvent() throws EndofDataException
{
    if (currentEvent++ >= nEvents) throw new EndOfDataException();

    time = ; // Enter calculation for this field here.
    distance = ; // Enter calculation for this field here.

    speed.fill( /* Enter calculation for this histogram here. */ );

    SimpleEventData eventData = new SimpleEventData();
    eventData.data[time_FieldIndex] = time;
    eventData.data[distance_FieldIndex] = distance;
    return eventData;
}

All you need to do is complete the calculations where comments indicate.

For this tutorial change the method definition to what is below, and save your changes by clicking the save button .

public EventData generateEvent() throws EndOfDataException
{
    if (currentEvent++ >= nEvents) throw new EndOfDataException();

    time = Math.exp(Math.random()) *100;
    distance = Math.PI * Math.exp(Math.random());

    speed.fill(time == 0.0 ? -10000.0 : distance / time); // -10000.0 indicates error

    SimpleEventData eventData = new SimpleEventData();
    eventData.data[time_FieldIndex] = time;
    eventData.data[distance_FieldIndex] = distance;
    return eventData;
}

Now you can compile, load and run the source file as detailed in JAS Tutorial Part 4: Compiling, Loading and Running your Source Code. Remember to consider the different variable names used in part 4 as you will be required to slightly modify the instructions . 

After running your event generation code you can view the results by following the JAS Tutorial Part 5: Viewing Results. Again, you will have to consider the different variable names used.

Once you have completed these steps the histogram plot should appear as below.


Top

Return to Tutorial Part 1: Creating a New Job

Return to Tutorial Part 6: Further Explorations into JAS