Commit in lcsim/test/org/lcsim on MAIN
Sidloi3SimplePfaTest.java+41-71.1 -> 1.2
update test

lcsim/test/org/lcsim
Sidloi3SimplePfaTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Sidloi3SimplePfaTest.java	17 Nov 2010 00:14:31 -0000	1.1
+++ Sidloi3SimplePfaTest.java	30 Nov 2010 00:55:20 -0000	1.2
@@ -2,6 +2,7 @@
 
 import java.io.File;
 import java.net.URL;
+import java.text.DecimalFormat;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -12,8 +13,22 @@
 import org.lcsim.util.cache.FileCache;
 import org.lcsim.util.loop.LCSimLoop;
 
+import static java.lang.Math.abs;
+
+/**
+ * This test runs the PFA on a few single jet events with the sidloi3 detector.
+ * It checks that the energy sum is within a reasonable range and also that the
+ * sums match an answer key based on a "known good" configuration.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: Sidloi3SimplePfaTest.java,v 1.2 2010/11/30 00:55:20 jeremy Exp $
+ */
 public class Sidloi3SimplePfaTest extends TestCase
 {
+    // Answer key with values rounded to one decimal place.
+    // JM Nov-29-2010
+    private static final double esums[] = { 184.13, 190.13 };
+
     public void testSingleEvent() throws Exception
     {
         URL url = new URL( "http://www.lcsim.org/test/lcio/pythia_uds_nobeam_nobrem-00-500_SLIC-v2r8p3_geant4-v9r3p1_QGSP_BERT_sidloi3.slcio" );
@@ -30,20 +45,39 @@
 
     static class PfaCheckDriver extends Driver
     {
+        int eventn;
+
         public void process( EventHeader event )
         {
-            List<ReconstructedParticle> particles = event.get( ReconstructedParticle.class, EventHeader.RECONSTRUCTEDPARTICLES );
-            if (particles.size() == 0)
+            List< ReconstructedParticle > particles = event.get(
+                    ReconstructedParticle.class,
+                    EventHeader.RECONSTRUCTEDPARTICLES );
+            if ( particles.size() == 0 )
                 throw new RuntimeException( "No ReconstructedParticles were created by the PFA." );
             double esum = 0;
-            for (ReconstructedParticle particle : particles)
+            for ( ReconstructedParticle particle : particles )
             {
                 esum += particle.getEnergy();
             }
-            System.out.println( "event <" + event.getEventNumber() + "> esum = " + esum );
-            // Check that energy sum is within 20 GeV of expected total.
-            if (esum < 180. || esum > 220.)
-                throw new RuntimeException("Esum is more than 20 GeV off from 200 GeV event energy.");
+            
+            // Compute difference of total from answer key.
+            double ediff = abs( esum - esums[eventn] );
+            
+            // Print energy sum and difference from key.
+            System.out.println( "event <" + event.getEventNumber() + "> - esum <" + esum + ">, ediff <" + ediff + ">");
+                                    
+            // Check that the energy is within a 20 GeV window of the expected total.
+            if ( esum < 180. || esum > 220. )
+                throw new RuntimeException( "esum <" + esum + "> is more than 20 GeV off from 200 GeV event energy." );
+
+            // Check that energy matches a cached value within a reasonable tolerance. 
+            // A difference here could be okay if changes are made to the PFA that 
+            // alter the reconstructed energy significantly.  In this case, the answer 
+            // table should be changed to match the new, correct values.
+            if ( ediff > 0.1 )
+                throw new RuntimeException( "esum <" + esum + "> does not match stored value <" + esums[ eventn ] + "> within 0.01 GeV tolerance." );
+
+            ++eventn;
         }
     }
 }
\ No newline at end of file
CVSspam 0.2.8