Commit in lcsim/test/org/lcsim/digisim on MAIN
DigiSimCalorimeterHitIOTest.java+76added 1.1
JM: Add test to write and read back CalorimeterHit with digisim to check that position information is not corrupted.

lcsim/test/org/lcsim/digisim
DigiSimCalorimeterHitIOTest.java added at 1.1
diff -N DigiSimCalorimeterHitIOTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ DigiSimCalorimeterHitIOTest.java	18 Aug 2007 00:07:43 -0000	1.1
@@ -0,0 +1,76 @@
+package org.lcsim.digisim;
+
+import hep.physics.vec.BasicHep3Vector;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.recon.cluster.util.CalHitMapDriver;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCIODriver;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+/**
+ * 
+ * Tests whether CalorimeterHits can be written out by DigiSim and read back in with position information maintained correctly. 
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ *
+ */
+public class DigiSimCalorimeterHitIOTest extends TestCase
+{
+	public void testWrite() throws Exception
+	{	
+		FileCache cache = new FileCache();
+		File file = cache.getCachedFile(new URL("http://www.lcsim.org/test/lcio/gamma_Theta90_1GeV_SLIC_v2r0p0_acme0605-0-2.slcio"));
+		LCSimLoop loop = new LCSimLoop();
+		loop.setLCIORecordSource(file);
+		loop.add(new SimToCalorimeterHitDriver());
+		loop.loop(2);
+		loop.dispose();
+		
+		loop = new LCSimLoop();
+		loop.setLCIORecordSource(new TestOutputFile("DigiSimWriteTest.slcio"));
+		loop.add(new CalorimeterHitPositionCheckDriver());
+		loop.loop(2);
+		loop.dispose();
+	}
+	
+	class CalorimeterHitPositionCheckDriver extends Driver
+	{
+		protected void process(EventHeader event)
+		{
+			List<CalorimeterHit> hits = event.get(CalorimeterHit.class,"EcalBarrDigiHits");
+			for (CalorimeterHit hit : hits)
+			{
+				double pos[] = hit.getPosition();
+				assertTrue(pos != null);
+				assertTrue(new BasicHep3Vector(pos[0],pos[1],pos[2]).magnitude() != 0.);
+			}
+		}		
+	}
+	
+	class SimToCalorimeterHitDriver extends Driver {		
+	    public SimToCalorimeterHitDriver() {
+	        // CalHitMapDriver is needed by DigiSim
+	        add(new CalHitMapDriver());
+	       
+	        // DigiSim: SimCalHits -> RawCalHits	      
+	        add(new DigiSimDriver());
+	       
+	        // RawCalHits -> CalorimeterHits
+	        add( new CalorimeterHitsDriver() );
+	       
+	        // Write output to test area.
+	        File output = new TestOutputFile("DigiSimWriteTest.slcio");
+	        add(new LCIODriver(output));       	      
+	    }
+	} 
+}
\ No newline at end of file
CVSspam 0.2.8