1 added + 3 modified, total 4 files
lcsim/src/org/lcsim/detector
diff -u -r1.1 -r1.2
--- ReadoutCleanupDriver.java 27 Apr 2007 12:37:46 -0000 1.1
+++ ReadoutCleanupDriver.java 27 Apr 2007 23:38:18 -0000 1.2
@@ -1,21 +1,62 @@
package org.lcsim.detector;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.lcsim.event.EventHeader;
import org.lcsim.util.Driver;
import org.lcsim.detector.DetectorElementStore;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IDetectorElementStore;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.compact.Subdetector;
+/**
+ * This Driver clears the DetectorElement Readout
+ * associated with a given collection in the event header.
+ * It accepts a list of collection names and ignores
+ * others.
+ *
+ * @author <a href="mail:[log in to unmask]>Jeremy McCormick</a>
+ *
+ */
public class ReadoutCleanupDriver
extends Driver
{
+ Map<String,String> collectionMap = new HashMap<String,String>();
+
+ public ReadoutCleanupDriver(List<String> collectionNames)
+ {
+ for ( String collection : collectionNames )
+ {
+ this.collectionMap.put(collection, collection);
+ }
+ }
+
+ public ReadoutCleanupDriver(String[] collectionNames)
+ {
+ for ( String collection : collectionNames )
+ {
+ this.collectionMap.put(collection, collection);
+ }
+ }
+
protected void process(EventHeader event)
- {
- for ( IDetectorElement de : DetectorElementStore.getInstance() )
- {
- if ( de.hasReadout() ) {
- de.getReadout().clear();
- }
- }
+ {
+ Detector detector = event.getDetector();
+
+ for ( Subdetector subdet : detector.getSubdetectors().values() )
+ {
+ if ( handleCollection( subdet.getReadout().getName() ) )
+ {
+ subdet.getDetectorElement().clearReadouts();
+ }
+ }
}
+
+ private boolean handleCollection( String collectionName )
+ {
+ return collectionMap.get( collectionName ) != null;
+ }
}
lcsim/src/org/lcsim/detector/tracker
diff -u -r1.2 -r1.3
--- SimTrackerHitPositionalReadoutDriver.java 27 Apr 2007 12:37:46 -0000 1.2
+++ SimTrackerHitPositionalReadoutDriver.java 27 Apr 2007 23:38:18 -0000 1.3
@@ -2,36 +2,64 @@
import hep.physics.vec.BasicHep3Vector;
-import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import org.lcsim.detector.DetectorElement;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IReadout;
import org.lcsim.detector.Readout;
+import org.lcsim.detector.ReadoutCleanupDriver;
import org.lcsim.event.EventHeader;
import org.lcsim.event.SimTrackerHit;
import org.lcsim.util.Driver;
public class SimTrackerHitPositionalReadoutDriver extends Driver
{
- public SimTrackerHitPositionalReadoutDriver()
- {}
+ Map<String,String> collectionMap = new HashMap<String,String>();;
+
+ public SimTrackerHitPositionalReadoutDriver(List<String> collectionNames)
+ {
+ add( new ReadoutCleanupDriver( collectionNames ) );
+ for ( String collection : collectionNames )
+ {
+ this.collectionMap.put(collection, collection);
+ }
+ }
+
+ public SimTrackerHitPositionalReadoutDriver(String[] collectionNames)
+ {
+ add( new ReadoutCleanupDriver( collectionNames ) );
+ for ( String collection : collectionNames )
+ {
+ this.collectionMap.put(collection, collection);
+ }
+ }
protected void process(EventHeader header)
+ {
+ super.process(header);
+ List<List<SimTrackerHit>> collections = header.get(SimTrackerHit.class);
+ for ( List<SimTrackerHit> collection : collections )
+ {
+ if ( handleCollection( header.getMetaData( collection ).getName() ) )
+ {
+ for ( SimTrackerHit hit : collection )
+ {
+ IDetectorElement deSubdet = hit.getSubdetector().getDetectorElement();
+ DetectorElement deHit =
+ (DetectorElement)deSubdet.findDetectorElement( new BasicHep3Vector( hit.getPoint() ) );
+ hit.setDetectorElement( deHit );
+ Readout<SimTrackerHit> ro = (Readout<SimTrackerHit>)deHit.getReadout();
+ ro.addHit( hit );
+ }
+ }
+ }
+ }
+
+ private boolean handleCollection( String collectionName )
{
- List<List<SimTrackerHit>> collections = header.get(SimTrackerHit.class);
- for ( List<SimTrackerHit> collection : collections )
- {
- for ( SimTrackerHit hit : collection )
- {
- IDetectorElement deSubdet = hit.getSubdetector().getDetectorElement();
- DetectorElement deHit =
- (DetectorElement)deSubdet.findDetectorElement( new BasicHep3Vector( hit.getPoint() ) );
- hit.setDetectorElement( deHit );
- Readout<SimTrackerHit> ro = (Readout<SimTrackerHit>)deHit.getReadout();
- ro.addHit( hit );
- }
- }
- }
+ return collectionMap.get( collectionName ) != null;
+ }
}
lcsim/test/org/lcsim/detector/tracker
diff -N SiTrackerBarrelReadLcioTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SiTrackerBarrelReadLcioTest.java 27 Apr 2007 23:38:18 -0000 1.1
@@ -0,0 +1,41 @@
+package org.lcsim.detector.tracker;
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.detector.tracker.SimTrackerHitPositionalReadoutDriver;
+
+public class SiTrackerBarrelReadLcioTest
+extends TestCase
+{
+ public SiTrackerBarrelReadLcioTest(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(SiTrackerBarrelReadLcioTest.class);
+ }
+
+ public void testReadLcio() throws Exception
+ {
+ URL url =
+ new URL("http://www.lcsim.org/test/lcio/mu-_10GeV_10_SLIC_v2r1p7_geant4-v8r2p0_SiTrackerBarrelTest00.slcio");
+ FileCache cache = new FileCache();
+ File file = cache.getCachedFile(url);
+
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(file);
+ loop.add( new SimTrackerHitPositionalReadoutDriver(
+ new String[] { "SiTrackerBarrel_RO" } ) );
+ loop.loop(2);
+ loop.dispose();
+ }
+}
\ No newline at end of file
lcsim/test/org/lcsim/detector/tracker
diff -u -r1.3 -r1.4
--- SimTrackerHitPositionalReadoutDriverTest.java 27 Apr 2007 12:37:46 -0000 1.3
+++ SimTrackerHitPositionalReadoutDriverTest.java 27 Apr 2007 23:38:18 -0000 1.4
@@ -29,55 +29,70 @@
{
public SimTrackerHitPositionalReadoutDriverTest(String testName)
{
- super(testName);
+ super(testName);
}
-
+
public static Test suite()
{
- return new TestSuite(SimTrackerHitPositionalReadoutDriverTest.class);
+ return new TestSuite(SimTrackerHitPositionalReadoutDriverTest.class);
}
public void setUp()
{
- java.lang.Runtime.getRuntime().gc();
+ java.lang.Runtime.getRuntime().gc();
}
public void testReadout() throws Exception
{
- URL url = new URL("http://www.lcsim.org/test/lcio/mu_5.0GeV_Theta90_sid01_polyhedra.slcio");
+ URL url =
+ new URL("http://www.lcsim.org/test/lcio/mu-_10GeV_10_SLIC_v2r1p7_geant4-v8r2p0_SiTrackerBarrelTest00.slcio");
FileCache cache = new FileCache();
- File file = cache.getCachedFile(url);
+ File file = cache.getCachedFile(url);
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(file);
- loop.add( new SimTrackerHitPositionalReadoutDriver() );
+ loop.add( new SimTrackerHitPositionalReadoutDriver(new String[] {"SiTrackerBarrel_RO"} ) );
loop.add( new TestDriver() );
- loop.add( new ReadoutCleanupDriver() );
loop.loop(2);
loop.dispose();
}
-
+
class TestDriver
extends Driver
{
protected void process(EventHeader header)
- {
- List<List<SimTrackerHit>> collections = header.get(SimTrackerHit.class);
- for ( List<SimTrackerHit> collection : collections )
- {
- for ( SimTrackerHit hit : collection )
- {
- IDetectorElement de = hit.getDetectorElement();
- IReadout<SimTrackerHit> ro = de.getReadout();
- List<SimTrackerHit> hits = ro.getHits();
- for ( SimTrackerHit deHit : hits )
- {
- assertEquals( "SimTrackerHit ids did not match!", hit.getCellID(), deHit.getCellID() );
- assertTrue( de.getGeometry().isInside( new BasicHep3Vector( hit.getPoint() ) ) );
- }
- }
+ {
+ for ( SimTrackerHit hit : header.get(SimTrackerHit.class, "SiTrackerBarrel_RO") )
+ {
+ IDetectorElement de = hit.getDetectorElement();
+ //System.out.println("detectorElement="+de.getName());
+ IReadout<SimTrackerHit> ro = de.getReadout();
+ List<SimTrackerHit> hits = ro.getHits();
+ for ( SimTrackerHit deHit : hits )
+ {
+ assertEquals( "CellIDs do not match!", hit.getCellID(), deHit.getCellID() );
+ assertTrue( "SimTrackerHit not inside its DetectorElement!", de.getGeometry().isInside( new BasicHep3Vector( hit.getPoint() ) ) );
+
+ SimTrackerHit lkpHit = findHitByPosition( hit, hits );
+ assertTrue( "Didn't find hit by position on the Readout!", lkpHit != null );
+ }
}
}
+
+ private SimTrackerHit findHitByPosition( SimTrackerHit findHit, List<SimTrackerHit> hits)
+ {
+ double[] findHitPos = findHit.getPoint();
+ for ( SimTrackerHit hit : hits )
+ {
+ double[] hitPos = hit.getPoint();
+ if ( findHitPos[0] == hitPos[0] &&
+ findHitPos[1] == hitPos[1] &&
+ findHitPos[2] == hitPos[2] )
+ {
+ return hit;
+ }
+ }
+ return null;
+ }
}
-}
-
+}
\ No newline at end of file
CVSspam 0.2.8