projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java 2014-09-02 05:07:43 UTC (rev 3290)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java 2014-09-02 05:09:36 UTC (rev 3291)
@@ -10,6 +10,7 @@
import org.lcsim.detector.ILogicalVolume;
import org.lcsim.detector.IPhysicalVolume;
import org.lcsim.detector.DetectorIdentifierHelper.SystemMap;
+import org.lcsim.detector.PhysicalVolumeNavigator;
import org.lcsim.detector.PhysicalVolumeStore;
import org.lcsim.detector.converter.compact.HPSTestRunTracker2014JavaBuilder.GhostJavaBaseGeom;
import org.lcsim.detector.converter.compact.HPSTestRunTracker2014JavaBuilder.JavaBaseGeom;
@@ -151,16 +152,19 @@
int nfields = builder.getDetectorIdentifierHelper().getIdentifierDictionary().getNumberOfFields();
IExpandedIdentifier layerPosId = new ExpandedIdentifier(nfields);
-
layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("system"), builder.getSubdetector().getSystemID());
layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
- int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+ //use the old definition of layer number to be consistent
+ //int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+ int layer = HPSTestRunTracker2014Builder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("layer"), layer);
-
+ if(_debug) System.out.printf("%s: layerPosId layer = %d (compare with new layer %d)\n", getClass().getSimpleName(),layer, HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName()));
// create the layer detector element and keep track of it
+ //IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
if(layerDe==null) {
layerDe = new DetectorElement(builder.getSubdetector().getName() + "_layer" + layer, builder.getSubdetector().getDetectorElement(), builder.getDetectorIdentifierHelper().pack(layerPosId));
+ //builder.addLayerDetectorElement(layerDe);
builder.addLayerDetectorElement(layerDe);
} else {
System.out.printf("%s: layerDE exists\n", getClass().getSimpleName());
@@ -186,25 +190,52 @@
if(_debug) {
System.out.printf("%s: create SiTrackerModule with: placementname %s, modulePath %s, moduleNumber %d \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
+ System.out.printf("%s: print all %d physical volumes from the Store\n", getClass().getSimpleName(),PhysicalVolumeStore.getInstance().size());
for(IPhysicalVolume v : PhysicalVolumeStore.getInstance()) {
- System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(),v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume().getName());
+ System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(), v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume()!=null?v.getMotherLogicalVolume().getName():"(no mother)");
}
}
SiTrackerModule moduleDe = new SiTrackerModule(modulePlacementName, layerDe, modulePath, moduleNumber);
- //keep track of the module detector element
- builder.addModuleDetectorElement(moduleDe);
+ //keep track of the module detector element
+ //builder.addModuleDetectorElement(moduleDe);
+
+ if(_debug) System.out.printf("%s: add module DE to existing ones \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
+
+
+ builder.addModuleDetectorElement(moduleDe);
+
+
+
+ } else if(HPSTestRunTracker2014Builder.isSensor(geometryObject.getName())) {
+
+ if(_debug) System.out.printf("%s: this is where I would create a detector element for the sensor %s if needed\n", getClass().getSimpleName(),geometryObject.getName());
+
} else if(HPSTestRunTracker2014Builder.isActiveSensor(geometryObject.getName())) {
- //TODO should this be the active sensor volume????
+ // Setup the active sensor element
+ // to be consistent with old converter I also add the sensor
+ // in the path to the element even though it's not associated with
+ // with a element. I'm not sure why this is done.
- if(_debug) System.out.printf("%s: create the sensor detector element\n", getClass().getSimpleName());
+ if(_debug) System.out.printf("%s: create the active sensor detector element\n", getClass().getSimpleName());
+
+ if(_debug) System.out.printf("%s: find the active sensor phys vol\n", this.getClass().getSimpleName());
- // Sensor physical volume.
- IPhysicalVolume sensorPhysVol = geometryObject.getPhysVolume();
+ // Find active Sensor physical volume.
+ // Keep name consistent with old converter
+ IPhysicalVolume sensorPhysVol = geometryObject.getPhysVolume();
+
+ if(sensorPhysVol==null) throw new RuntimeException("cannot find physVol for " + geometryObject.getName());
+
+ if(_debug) System.out.printf("%s: found %s phys vol\n", this.getClass().getSimpleName(),sensorPhysVol.getName());
+
+ if(_debug) System.out.printf("%s: find the sensor phys vol\n", this.getClass().getSimpleName());
+
+ // find the module detector element
// Helpers
IIdentifierDictionary iddict = builder.getDetectorIdentifierHelper().getIdentifierDictionary();
@@ -212,31 +243,47 @@
// Find the mother: the module detector element
IExpandedIdentifier layerExpId = new ExpandedIdentifier(iddict.getNumberOfFields());
layerExpId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
- layerExpId.setValue(iddict.getFieldIndex("barrel"), 0);
- int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+ layerExpId.setValue(iddict.getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
+ //use the old definition of layer number to be consistent
+ //int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+ int layer = HPSTestRunTracker2014Builder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
layerExpId.setValue(iddict.getFieldIndex("layer"), layer);
+ String half = HPSTestRunTracker2014Builder.getHalfFromName(geometryObject.getName());
+ if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
+ int moduleNumber = half.equals("top") ? 0 : 1;
- // TODO Jeremy, why is the module ID not part of the expanded ID for the module DE but stored as a separate member?
-
- //String half = HPSTestRunTracker2014Builder.getHalfFromName(geometryObject.getName());
- //if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
- //int moduleNumber = half.equals("top") ? 0 : 1;
+ // The expId is the same for the layerDE and moduleDE because the tracker module object stores the
+ // module ID in a member variable. So when searching I need to add this info
+ // TODO Can we change this and add the module ID to the identifier?
+ //IDetectorElement moduleDe = builder.getModuleDetectorElement(layerExpId);
+ //IDetectorElement moduleDe = builder.getSiTrackerModuleDetectorElement(layerExpId, moduleNumber);
- IDetectorElement moduleDe = builder.getModuleDetectorElement(layerExpId);
+ //Find the layer
+ IDetectorElement layerDe = builder.getLayerDetectorElement(layerExpId);
+
+ if(layerDe==null) throw new RuntimeException("Cannot find layer DE");
+ //Find the module
+ IDetectorElement moduleDe = null;
+ for(IDetectorElement e : layerDe.getChildren()) {
+ if(e instanceof SiTrackerModule) {
+ SiTrackerModule m = (SiTrackerModule)e;
+ if(m.getModuleId()==moduleNumber) {
+ moduleDe = m;
+ }
+ }
+ }
+
+
if(moduleDe==null) throw new RuntimeException("Cannot find module DE for " + geometryObject.getName());
- // Find the layer element
- IDetectorElement layerDe = moduleDe.getParent();
-
// Setup SiSensor's identifier.
IExpandedIdentifier expId = new ExpandedIdentifier(iddict.getNumberOfFields());
expId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
expId.setValue(iddict.getFieldIndex("barrel"), 0);
expId.setValue(iddict.getFieldIndex("layer"), builder.getDetectorIdentifierHelper().getValue(layerDe.getIdentifier(), "layer"));
expId.setValue(iddict.getFieldIndex("module"), ((SiTrackerModule) moduleDe).getModuleId());
-
- // TODO: what does this number mean? It's basically just a counter in the old compact
+ // The sensorNumber is always 0 in the old geometry. Keep it that way.
int sensorNumber = 0;
expId.setValue(iddict.getFieldIndex("sensor"), sensorNumber);
@@ -245,10 +292,14 @@
// Sensor paths.
String modulePath = moduleDe.getGeometry().getPathString();
- IPhysicalVolume componentPhysVol = geometryObject.getMother().getPhysVolume();
+ IPhysicalVolume componentPhysVol = geometryObject.getPhysMother().getPhysVolume();
String sensorPath = modulePath.toString() + "/" + componentPhysVol.getName() + "/" + sensorPhysVol.getName();
String sensorName = moduleDe.getName() + "_sensor" + sensorNumber;
-
+
+ if(_debug) System.out.printf("%s: create HpsSiSensor with sensorNumber %d name %s moduleDe %s sensorPath %s sensor Id %d \n", getClass().getSimpleName(),
+ sensorNumber, sensorName, moduleDe.getName(), sensorPath, sensorNumber);
+
+
// Create the sensor.
HpsSiSensor sensor = new HpsSiSensor(sensorNumber, sensorName, moduleDe, sensorPath, sensorId);