[Feedback][Day 1][Day 2][Welcome Page]

shoeline2[1].gif (1488 bytes)

Creating N-tuples

AIDA supports creating N-tuples on the fly, and using JAS3 you can either analyze them immediately, or save them and analyze them later. The simple example below should help you get started.

import hep.lcd.event.*;
import hep.lcd.util.driver.*;
import hep.physics.jets.*;
import hep.physics.predicate.*;
import hep.physics.*;
import java.util.*;
import hep.aida.*;

final public class TupleJet extends Driver
{
   private ITuple tuple;
   // Create a JadeEJetFinder with a ycut of 0.02
   private AbstractJetFinder jetFinder = new JadeEJetFinder(0.02);
   // Create a Predicate that accepts final state charged particles 
   Predicate predicate = new Predicate()
   {
      public boolean accept(Object in)
      {
         Particle p = (Particle) in;
         if (p.getStatusCode() != Particle.FINALSTATE) return false;
         if (p.getType().getCharge() == 0) return false;
         return true;
      }
   };
   public void beforeFirstEvent()
   {  
      super.beforeFirstEvent();
      ITupleFactory tf = analysisFactory().createTupleFactory(tree());
      String[] columnNames  = { "totalJetEnergy", "totalParticleEnergy", "nJets", "jetsFolder = { int nPtc, float eTot, float jetEnergy }" };
      Class[] columnClasses = { Float.TYPE, Float.TYPE, Integer.TYPE, ITuple.class };
      
      tuple = tf.create( "jets", "Jet Example", columnNames, columnClasses);
   }  
   public void process(LCDEvent event)
   {
      // We will use the MC truth in this example to find jets
      ParticleVector pv = event.getMCParticles();

      jetFinder.setEvent(pv.particles(),predicate);
      // Fill some diagnostic histograms 
      cloud1D("Njets").fill(jetFinder.njets());
      cloud1D("Fewest Tracks").fill(jetFinder.fewestTracks());

      double totalJetEnergy = 0;
      double totalParticleEnergy = 0;
      ITuple jetFolder = tuple.getTuple(3); 
      for (int ijet =0; ijet<jetFinder.njets(); ijet++)
      {
         totalJetEnergy += jetFinder.jet(ijet).t();
         cloud1D("Jet Energy").fill(jetFinder.jet(ijet).t());
         cloud1D("Particles in Jet").fill(jetFinder.nParticlesPerJet(ijet));
         // loop over all the tracks in the jet, and add up there energy
         // (should be the same as the jet energy)
         double etot = 0;
         Enumeration e = jetFinder.particlesInJet(ijet);
         while (e.hasMoreElements()) 
            etot += ((Particle) e.nextElement()).getEnergy();
         cloud1D("Etot").fill(etot);
         totalParticleEnergy += etot;

         jetFolder.fill(0,jetFinder.nParticlesPerJet(ijet));
         jetFolder.fill(1,(float)etot);
         jetFolder.fill(2,(float)jetFinder.jet(ijet).t());
         jetFolder.addRow();
      }
      cloud1D("Total Jet Energy").fill(totalJetEnergy);
      cloud1D("Total Particle Energy").fill(totalParticleEnergy);

      tuple.fill(0,(float) totalJetEnergy);
      tuple.fill(1,(float) totalParticleEnergy);
      tuple.fill(2,jetFinder.njets());
      tuple.addRow();
   }
}

Once you have created your tuple you can use the tuple explorer features built-into JAS to make plots and cuts. AIDA supports creating tuples with nested structures, so you could add a second level tuple with one row for each yet.