You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Explanation of the Analysis101 Driver

Explanation of Driver Code

Below is the complete text of the Analysis101 Driver, stripped of comments.

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;

public class Analysis101 extends Driver
{
   private AIDA aida = AIDA.defaultInstance();
   
   protected void process(EventHeader event)
   {
      List<MCParticle> particles = event.get(MCParticle.class,event.MC_PARTICLES);

      aida.cloud1D("nTracks").fill(particles.size());
      
      for (MCParticle particle : particles)
      {
         aida.cloud1D("energy").fill(particle.getEnergy());
         aida.cloud1D("cosTheta").fill(VecOp.cosTheta(particle.getMomentum()));
         aida.cloud1D("phi").fill(VecOp.phi(particle.getMomentum()));
      }
   }
}

First, as in all Java programs, there are the import statements.

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;

This includes code libraries into the Driver that are needed to do the analysis.

For instance, methods of org.lcsim.util.aida.AIDA are used to book and fill the plots.

The hep.physics.vec.VecOp package is for doing math operations on vectors.

Next is the declaration of the Driver class.

public class Analysis101 extends Driver

The Analysis101 class extends Driver, which means that it can override some or all of Driver's public or protected methods to do some useful work, like filling histograms.

The class stores a reference to the default AIDA object.

private AIDA aida = AIDA.defaultInstance();

This is convenient for creating and filling histograms "on-the-fly".

The single function in this class is called process. Analysis101 inherits this method from Driver.

protected void process(EventHeader event)

Its single argument is the EventHeader of the current LCIO event. All collections in this event are accessible through the EventHeader interface.

EventHeader API

Refer to the EventHeader JavaDoc for information on all the available methods in this interface.

This line retrieves a list of the MCParticles in the event.

List<MCParticle> particles = event.get(MCParticle.class,event.MC_PARTICLES);

This uses the get method to retrieve all collections of type (class) MCParticle. The

event.MC_PARTICLES

constant specifies the name of the (sub)collection to retrieve, so that we get back a list of objects (rather than a list of collections, e.g. a list of lists).

  • No labels