Search/Navigation:
Related:
SLAC/EPP/HPS Public
Jefferson Lab/Hall B/HPS Run Wiki
S30XL-LESA/LDMX
...
In HPS Java terminology, a Driver driver processes events and can read or add collection data. A Driver can driver may create histograms from physics data or implement a step of physics reconstruction algorithm. Drivers are executed in order, and a Driver can driver may have child Drivers drivers in order to implement complex, hierarchical behavior. A chain of Drivers is activated by the "mother of all drivers" which contains a list of the top level Drivers as children
The following is a toy example of a driver which prints information to the console at certain points in the job processing.
Code Block | ||
---|---|---|
| ||
package org.hps.users.jeremym; import org.lcsim.event.EventHeader; import org.lcsim.geometry.Detector; import org.lcsim.util.Driver; public class ExampleDriver extends Driver { private int value; public void process(EventHeader event) { System.out.println("Processing event " + event.getEventNumber()); } protected void detectorChanged(Detector detector) { System.out.println("Detector name is " + detector.getDetectorName()); } protected void endOfData() { System.out.println("Read all the data."); } protected void startOfData() { System.out.println("Starting the job."); } public void setValue(int value) { this.value = value; } } |
Each driver may implement one or more job processing hooks which are activated by the framework in the following order.
Order | Method | Explanation |
---|---|---|
1 | Driver constructorno argument constructor activated when Driver created | The driver's constructor is activated at the very beginning of the job. it should not take any arguments. |
2 | Driver setters calledset | A driver's setter methods are called individually for different parameters (by JobManager)based on parameters defined in the steering file. |
3 | startOfDatadata processing has started but detector conditions not initialized yet | This is activated at the beginning of the job after drivers are created and configured but before a specific detector configuration is activated. |
4 | detectorChanged | This hook activates after when detector conditions are initialized so Driver that a driver may can perform any necessary setupdetector-specific setup and configuration. |
5 | process | This is the main processing hook which is called once for every event in the job. The default behavior of parent class executes child driversimplementation of this method will execute a driver's child drivers, if it has any. |
6 | endOfData | This is the end of data processing hook. histograms can Histograms may be normalized/scaled in this method |
The startOfData method is activated at the beginning of data processing but before detector conditions are initialized. Any setup that needs to be performed which is independent of the detector information can be implemented here.
The detectorChanged method is called after the conditions system is initialized.
based on the number of events that were processed, for instance. |
The lcsim xml format can describe describes a chain of drivers and their parameters at runtime using an XML data description. The Guidelines for Creating Compatible Drivers documentation describes how to write a Driver driver so that it can be using in the within an XML steering files.
Here is sample XML file which calls the ExampleDriver defined above and sets a parameter value on it.
Code Block | ||||
---|---|---|---|---|
| ||||
<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd"> <execute> <driver name="ExampleDriver"/> </execute> <drivers> <driver name="ExampleDriver" type="org.hps.users.jeremym.ExampleDriver"> <value>1234</value> </driver> </drivers> </lcsim> |
...
Here is an example of accessing the ECal hits collection and printing out the hit energies:
Code Block | ||
---|---|---|
| ||
public void process(EventHeader event) { List<CalorimeterHit> hits = event.get(CalorimeterHit.class, "EcalHits"); for (CalorimeterHit hit : hits) { System.out.println("calorimeter hit has energy " + hit.getCorrectedEnergy() + " GeV."); } } |
You may also get all the collections of with a given type by not providing a collection name which will return a "list of lists."object type:
Code Block | ||
---|---|---|
| ||
public void process(EventHeader event) { List<List<CalorimeterHit>> collections = event.get(CalorimeterHit.class); for (List<CalorimeterHit> hits : collections) { for (CalorimeterHit hit : hits) { System.out.println("calorimeter hit has energy " + hit.getCorrectedEnergy() + " GeV."); } } } |
Each collection in the event has an associated metadata object with information about it.
Code Block | ||
---|---|---|
| ||
public void process(EventHeader event) { List<List<CalorimeterHit>> collections = event.get(CalorimeterHit.class); for (List<CalorimeterHit> hits : collections) { System.out.println("found Calorimeter collection: " + event.getMetaData(hits).getName()); } } |
You must provide the list object as a key in order to retrieve this metadata.
New collections can be added to the event using the put method of EventHeader.
Code Block | ||
---|---|---|
| ||
public void process(EventHeader event) { // Create new collection somehow! List<Track> myFancyTracks = createFancyTracks(event); // Put new collection into the event. int flag = 1 << LCIOConstants.TRBIT_HITS; event.put("MyFancyTracks", fancyTrackCollection, Track.class, flag); } |
Flags is The flags are an integer bit mask with values defined in the LCIOConstants class. This controls some of the IO behavior of the LCIO format.
Histogramming of event data can be done using the AIDA utility class which provides a simplified wrapper to the AIDA plotting interface.
...
AIDA provides facilities for creating 1, 2 and 3D histograms, clouds, profiles, tuples, fitting and other functionality. (many different types of analysis objects such as histogrmas. Refer to the AIDA API documentation for full details.)