When opening reading a stdhep file with the org.lcsim classes the file is events are immediately converted into an org.lcsim "EventHeader" object, after which it is hard objects, however a pointer to the original stdhep file is kept, so it is possible to write the original event back out as a stdhep file.
The example below shows a Driver which will write out only events with >100 MC particles:
Code Block | ||
---|---|---|
| ||
import org.lcsim.event.EventHeader;
import org.lcsim.util.Driver;
import org.lcsim.util.loop.StdhepDriver;
public class StdhepFilter extends Driver
{
public StdhepFilter()
{
// Add a child driver which will write out the event
add(new StdhepDriver("myfile.stdhep","My Title","My Comment",0));
}
protected void process(EventHeader event)
{
int n = event.getMCParticles().size();
if (n>100)
{
// If the event is accepted call super.process() which calls the
// child drivers, and thus writes out the event
super.process(event);
}
}
}
|
Alternative approach
If you only want to make trivial cuts on a stdhep file, then it may be more efficient to use the stdhep reading/writing classes directlyHowever, org.lcsim contains underlying libraries (freehep-io-stdhep and freehep-physics) which can be used to read and write stdhep files. There are two representations of stdhep events available, a true Object-Oriented approach using Particle and Event objects, and a lower level interface which reflects the Stdhep "common-block" format. If you want to read stdhep files, apply a simple filter, and write them out again, the "common-block" style interface, while a little less pretty, is probably considerably more efficient.
...