...
Code Block | ||
---|---|---|
| ||
import hep.io.stdhep.StdhepEvent; import hep.io.stdhep.StdhepReader; import hep.io.stdhep.StdhepRecord; import hep.io.stdhep.StdhepWriter; import java.io.EOFException; import java.io.IOException; /** * A simple class for filtering stdhep events */ public class StdhepFilter { public static void main( String[] args ) throws IOException { int nRecord = 0; int nIn = 0; int nOut = 0; StdhepReader reader = new StdhepReader("inputfile.stdhep"); StdhepWriter writer = new StdhepWriter("outputfile.stdhep",reader.getTitle(),reader.getComment(),0); try { for (;;) { StdhepRecord record = reader.nextRecord(); nRecord++; if (record instanceof StdhepEvent) { StdhepEvent event = (StdhepEvent) record; nIn++; // Insert your filter code here! if (event.getNHEP() < 100) continue; } writer.writeRecord(record); nOut++; } } catch (EOFException x) { // No problem } finally { writer.close(); reader.close(); System.out.println("Records: "+nRecord+" Events: "+nIn+" Out: "+nOut); } } } |
Documentation on the freehep-stdhep classes is available here:
http://java.freehep.org/freehep-stdhep/apidocs/index.html
Documentation on the freehep-physics classes (only necessary if you want the more OO access to stdhep events is here:
http://java.freehep.org/freehep-physics/apidocs/index.html
Note in particular the StdhepConverter class.