LCSIM Example
This example is taken from the SVN repository: ./Examples/LCSIM/MainLoop.java.
This loads an existing SLCIO file, and copies it into a ROOT file.
// MainLoop.java // Java wrapper to enable running outside of JAS3 // 16-JUL-2005 Jan Strube // from a response to the JAS mailing list by Tony Johnson import java.io.*; import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA; import org.lcsim.util.loop.LCIODriver; import org.lcsim.util.loop.LCSimLoop; import org.lcsim.thirdparty.javaROOT.*; public class MainLoop { public static void main( String[] args ) throws Exception { // Load the library try { System.loadLibrary( "javaROOT" ); } catch( UnsatisfiedLinkError javaROOT_linkError ) { System.err.println( "javaROOT native library failed to load.!!!\n" + javaROOT_linkError +"\n" ); System.exit( -1 ); } // Program accepts one argument, an SLCIO file's filename. if( args.length != 1 ) { System.err.println( "This program needs to be passed an SLCIO filename." ); System.exit( -1 ); } RootSessionField sess = new RootSessionField( "org_lcsim.root", "RECREATE", "MainLoop" ); LCSimLoop loop = new LCSimLoop(); File input; try { input = new File( args[ 0 ] ); loop.setLCIORecordSource( input ); loop.add( new Analysis101( sess ) ); loop.loop( -1 ); AIDA.defaultInstance().saveAs( "org_lcsim.aida" ); } catch( IOException e ) { System.err.println( "Could not open SLCIO file: " + e ); } finally { sess.delete(); } } }
./Examples/LCSIM/Analysis101.java.
import org.lcsim.util.aida.AIDA; import hep.physics.vec.VecOp; import java.util.List; import org.lcsim.event.EventHeader; import org.lcsim.event.MCParticle; import org.lcsim.util.Driver; import java.io.Console; import org.lcsim.thirdparty.javaROOT.*; /** * An example showing how to access MCParticles from the EventHeader and * make some simple histograms from the data. * * @author Norman Graf * @version $Id: Analysis101.java,v 1.1 2008/10/30 23:38:19 jeremy Exp $ */ public class Analysis101 extends Driver { private AIDA aida = AIDA.defaultInstance(); private RootSessionField sess; public Analysis101(RootSessionField session) { sess = session; sess.newTTree("analysis101", "Test", 99); sess.branchTTreeFloat("analysis101", "energy"); sess.branchTTreeFloat("analysis101", "cosTheta"); sess.branchTTreeFloat("analysis101", "phi"); sess.setupTTree("analysis101"); sess.newTH1F( "nTracks", "Number of Tracks", 10, 0, 200 ); } protected void process(EventHeader event) { // Get the list of MCParticles from the event List<MCParticle> particles = event.get(MCParticle.class,event.MC_PARTICLES); // Histogram the number of particles per event aida.cloud1D("nTracks").fill(particles.size()); sess.fillTH1F( "nTracks", particles.size() ); // Loop over the particles for( int i = 0; i < particles.size(); i++ ) { sess.fillBranchFloat( "analysis101", "energy", (float)particles.get( i ).getEnergy() ); sess.fillBranchFloat( "analysis101", "cosTheta", (float)VecOp.cosTheta(particles.get( i ).getMomentum()) ); sess.fillBranchFloat( "analysis101", "phi", (float)VecOp.phi(particles.get( i ).getMomentum()) ); sess.fillTTree( "analysis101" ); aida.cloud1D("energy").fill(particles.get( i ).getEnergy()); aida.cloud1D("cosTheta").fill(VecOp.cosTheta(particles.get( i ).getMomentum())); aida.cloud1D("phi").fill(VecOp.phi(particles.get( i ).getMomentum())); } System.out.println("Event : "+ event); } }