Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

However, 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.

The following program can be compiled and run in JAS3 if you have the org.lcsim plugin installed. You will need to modify the input and output file specifications.

Code Block
titleStdhepFilter.java
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);
      }
   }
}

...