In order to run your driver outside of JAS3, for instance as a batch job or in an IDE, you will need to add a main() method to your driver. In this main method you must create an LCSimLoop object, add any datasets, add your driver, and then run the loop. Here is an example:
Code Block |
---|
|
import java.io.File;
import java.io.IOException;
import org.freehep.record.loop.LoopException;
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 org.lcsim.util.loop.FileList;
import org.lcsim.util.loop.LCIOEventSource;
import org.lcsim.util.loop.LCSimLoop;
/**
* An example LCSim driver
* @author tonyj
*/
public class ExampleDriver extends Driver
{
private static AIDA aida = AIDA.defaultInstance();
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.histogram1D("nTracks",50,0,200).fill(particles.size());
// Loop over the particles
for (MCParticle particle : particles)
{
aida.histogram1D("energy",50,0,100).fill(particle.getEnergy());
aida.histogram1D("cosTheta",50,-1,1).fill(VecOp.cosTheta(particle.getMomentum()));
aida.histogram1D("phi",50,-Math.PI,Math.PI).fill(VecOp.phi(particle.getMomentum()));
}
}
public static void main(String[] args) throws IOException, LoopException
{
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(new File("myFile.slcio"));
// Or to read a stdhep file
//loop.setStdhepRecordSource(new File("myFile.stdhep"),"sid01");
// Or to read a list of files
//loop.setLCIORecordSource(new LCIOEventSource(new FileList(new File("myFileList.filelist"),"My File List")));
loop.add(new ExampleDriver());
loop.loop(100); // 0 means loop forever
loop.dispose();
aida.saveAs("myFile.aida");
}
}
|
See Also