Commit in lcsim/test/org/lcsim on MAIN
PFATest.java+103added 1.1


lcsim/test/org/lcsim
PFATest.java added at 1.1
diff -N PFATest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PFATest.java	23 May 2008 22:37:29 -0000	1.1
@@ -0,0 +1,103 @@
+package org.lcsim;
+
+import org.lcsim.recon.pfa.structural.*;
+
+import java.util.*;
+import org.lcsim.util.Driver;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.*;
+import hep.physics.vec.*;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+/**
+ * Simple PFA Test that checks if computed Z mass is within a certain window
+ * for one known ZZ event in sid01. 
+ * @author jeremym
+ */
+public class PFATest extends TestCase
+{
+    public void testSingleEvent() throws Exception
+    {
+        LCSimLoop loop = new LCSimLoop();
+        loop.setLCIORecordSource((new FileCache()).getCachedFile(new URL("http://www.lcsim.org/test/lcio/ZZ_singleEvent_sid01.slcio")));
+        loop.add(new TestPFA());
+        loop.loop(1);
+        loop.dispose();        
+    }
+
+    /**
+     * Test driver to create PFA ReconstructedParticle objects
+     * from an event containing only 2 jets from a single Z (excluding
+     * neutrinos) and compare generated and reconstructed energy
+     * and mass.
+     * 
+     */
+    public class TestPFA extends Driver
+    {
+        int ievt;
+        String MatReconName = "DTreeReclusteredParticles_withEoverPveto";
+        /** Constructor sets up daughter drivers. */
+        public TestPFA()
+        {
+            ievt = 0;
+            // Prep
+            add(new NonTrivialPFA());
+            add(new SetUpDTreeForReclustering());
+            // Run the PFA
+            add(new ReclusterDTreeDriver("DTreeClusters", "FSReconTracks", "ReconFSParticles"));
+        }
+
+        protected void process(EventHeader event)
+        {
+            //
+            // Find generated Z mass and energy
+            //
+            List<MCParticle> mcl = event.get(MCParticle.class,"MCParticle");
+            double Zmass = 0.;
+            double ZE = 0.;
+            for(MCParticle p:mcl)
+            {
+                int id = Math.abs(p.getPDGID());
+                if( (id == 1 )||(id == 2 )||(id == 3 ) )
+                {
+                    if(p.getParents().get(0).getPDGID() == 23 )
+                    {
+                        Zmass = p.getParents().get(0).getMass();
+                        ZE = p.getParents().get(0).getEnergy();
+                    }
+                }
+            }
+            super.process(event);
+            List<ReconstructedParticle> rpl = event.get(ReconstructedParticle.class,MatReconName);
+            double evtE = 0.;
+            double evtPx = 0.;
+            double evtPy = 0.;
+            double evtPz = 0.;
+            for(ReconstructedParticle p:rpl)
+            {
+                evtE += p.getEnergy();
+                Hep3Vector P = p.getMomentum();
+                evtPx += P.x();
+                evtPy += P.y();
+                evtPz += P.z();
+            }
+            double dE = evtE - ZE;
+            double evtM = Math.sqrt(evtE*evtE - evtPx*evtPx - evtPy*evtPy - evtPz*evtPz);
+            double dM = evtM - Zmass;
+            if( (Math.abs(dE) > 10.)||(Math.abs(dM) > 10.) )
+            {
+                System.err.println("Z energy:Gen,Recon,Residual = "+ZE+", "+evtE+", "+dE);
+                System.err.println("Z mass:Gen,Recon,Residual = "+Zmass+", "+evtM+", "+dM);
+                throw new RuntimeException("Reconstruction results outside of window!");
+            }
+
+            ievt++;
+        }
+    }
+}
CVSspam 0.2.8