Search/Navigation:
Related:
SLAC/EPP/HPS Public
Jefferson Lab/Hall B/HPS Run Wiki
S30XL-LESA/LDMX
In HPS Java terminology, a Driver processes events and can read or add collection data. A Driver can create histograms from physics data or implement a step of physics reconstruction. Drivers are executed in order, and a Driver can have child Drivers to implement complex behavior. A chain of Drivers is activated by the "mother of all drivers" which contains a list of the top level Drivers as children.
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) { } protected void detectorChanged(Detector detector) { } protected void endOfData() { } protected void startOfData() { } public void setValue(int value) { this.value = value; } }
Order | Method | Explanation |
---|---|---|
1 | Driver constructor | no argument constructor activated when Driver created |
2 | Driver setters called | set methods called individually for different parameters (by JobManager) |
3 | startOfData | data processing has started but detector conditions not initialized yet |
4 | detectorChanged | activates after detector conditions are initialized so Driver can perform any necessary setup |
5 | process | called once for every event in the job default behavior of parent class executes child drivers |
6 | endOfData | end of data processing hook histograms can 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.
The lcsim xml format can describe drivers and their parameters at runtime using an XML data description. The Guidelines for Creating Compatible Drivers describes how to write a Driver so that it can be using in the XML steering files.
Here is sample XML which calls the ExampleDriver and sets a parameter value on it.
<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>
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 collections of a given type by not providing a collection name which will return a "list of lists."
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.
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()); } }
New collections can be added to the event using the put method of EventHeader.
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 an integer bit mask with values defined in the LCIOConstants class.