A simple example of how to access the SimTrackerHits in an event.
Download the attachment for a compilable version of the following annotated code.
Explanation of the TrackerHitAccessDriver Driver Code
First, as in all Java programs, there are the import statements:
EventHeader provides access to the event data.
SimTrackerHit is the tracker detector hit.
LCMetaData and TrackerIDDecoder provide access to tracker detector information encoded in the hit IDs. Note that we cast from the default IDDecoder which the meta data returns.
Driver is a steering routine which can deal with event processing.
The aida classes are used for histogramming.
Next is the declaration of the Driver class.
To be run from within JAS3, one needs a no-argument constructor.
In our case we use this to instantiate the aida tree.
We choose here only to override the process() method of Driver. This is called once per event during the event loop. Its single argument is the EventHeader of the current LCIO event.
All collections in this event are accessible through the EventHeader interface.
We are interested in accessing the SimTrackerHits for the tracking detectors. We could use the method getSimTrackerHits(String name), but we choose not to in this example, since we do not, a priori, know the names of the collections in an arbitrary LCIO file. Instead, we fetch all the collections which contain objects of type SimTrackerHit, viz.
Here we are using the event.get(java.lang.Class) method, which returns a list of lists of tracker hits. That is, each tracker subdetector provides a list of SimTrackerHits.
Next, we loop over this list of SimTracker collections using the Java 1.5 loop syntax
Each collection contains metadata which provides more information about the content. We fetch this via
and obtain a hit ID decoder, which will be used later to access additional information about the tracker hits. We cast this to a TrackerIDDecoder since we know that we are dealing with tracker hits.
Finally we loop over the SimTrackerHits in the collection:
Each hit contains a packed ID, which we can interpret using the IDDecoder obtained from the collection metadata.
For illustration, we plot the x vs. y position of the tracker hits.
First, we fetch the position
We currently return an array of doubles, which we interpret as the (x,y,z) position. This should, of course, be encapsulated into a space point class to remove this ambiguity of interpretation. Look for this in a future release.
Finally we fill the histogram:
This one line contains a lot of functionality, so merits some extra attention.
First, a cloud2D is a two-dimensional tuple. The cloud2D method of the AIDA object takes a string which is the title. We construct the title from the name of the tracker collection (obtained from the metadata via its getName() method) and add the layer number as well. For example, we might end up with a tuple titled "TkrBarrHits layer 0 x vs y" for the x,y hit position of SimTrackerHits on layer 0 of the collection TkrBarrHits. If this cloud does not already exist, it will be created, else the instance is returned. We then fill the tuple with the cloud2D fill() method, where pos and pos are understood to be the x and y position, respectively.
Here is an example plot showing the x vs y hit position for layer 0 of a silicon strip barrel detector:
Not too exciting, but now you know how to access the tracker hit information in an event.