To write an event generator, you must create a Java class that extends hep.analysis.EventGenerator, compile it, and load it into the application. A wizard will help by creating most of a source file. You don't 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.
To open the program page wizard, select 'Program Using Wizard...' from the 'New' submenu of the 'File' menu. On the first page, enter a name for your class. This must be a legal java identifier (the wizard will notify you if the text you entered is not legal). This will be used as the name for the file and for the class. The 'Next' button will not be enabled if there is text in the class name field. Below, select the EventGenerator option, which allows you to write an event generator. (If you want an event analyzer instead, read the step-by-step example for event analyzers.) Click on 'Next' to go to the EventGenerator setup page.
A button at the bottom allows you to preview what you have asked the wizard to create.
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, and Java language rules require that the file name be the same as the class name if the class is public, and the class must be public in order to be readable from the application.
In my example, I will use the wizard to create an
event generator. First, I select a name for my class and select the EventGenerator
option of the first page of the wizard.

Then I click on 'Next' to open the EventGenerator setup page. Below are the
settings I will use:

On the first line, I have just left the name as the default. On the second line, I have indicated that there will be 500 events. On the third line, I indicated that I wanted one histogram called 'speed'. Below that, I indicated that I wanted the wizard to create an EventData class for me because I don't want to define my own. I've indicated that event data has two fields (time and distance) and that I will be using double-precision data. I click in 'Finish' and save the file. See how to set up timed backups for text files. See printing to print the page.
Because I have made use of all of the wizard options, all I need to change is the
generateEvent() method to include the simulation I want. Once I have done that, I
will have a syntactically correct file I can compile and load. Below is the
generateEvent() method the wizard has given me:
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 I have to do is complete the calculations where comments indicate. I have
changed the method definition to what is below, and I am now ready to compile.
public EventData generateEvent() throws EndofDataException
{
if (currentEvent++ >= nEvents) throw new EndOfDataException();
time = 5.0 * Math.random() * Math.random();
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;
}
Of course these numbers are meaningless, but they should create a lovely histogram for illustration.
Now I can compile the source file and load the class file into the application. I click on
the 'Run' button on the toolbar and show
the histogram on the selected plot. If I have set up a local
job, then the event generation will take place on my machine. If, however, I
have set up a remote job, the event generation will take
place on the server I selected. My results looked like this:

On the new histogram I can add functions and fitters to analyze the results.
Page maintained by Jonas Gifford. Last updated 01/14/04.