Print

Print


Commit in lcsim/src/org/lcsim/contrib/seedtracker on MAIN
MaterialManager.java+191-611.5 -> 1.6
CD - Fix transforms

lcsim/src/org/lcsim/contrib/seedtracker
MaterialManager.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- MaterialManager.java	14 Mar 2008 17:49:09 -0000	1.5
+++ MaterialManager.java	6 Jun 2008 00:24:41 -0000	1.6
@@ -9,10 +9,10 @@
 
 package org.lcsim.contrib.seedtracker;
 
+import hep.physics.vec.Hep3Vector;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
-
 import org.lcsim.event.EventHeader;
 import org.lcsim.detector.DetectorIdentifierHelper;
 import org.lcsim.detector.IDetectorElement;
@@ -20,6 +20,10 @@
 import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.detector.ILogicalVolume;
 import org.lcsim.detector.IPhysicalVolume;
+import org.lcsim.detector.IPhysicalVolumeNavigator;
+import org.lcsim.detector.IPhysicalVolumePath;
+import org.lcsim.detector.ITransform3D;
+import org.lcsim.detector.PhysicalVolumePath;
 import org.lcsim.detector.material.IMaterial;
 import org.lcsim.detector.solids.Box;
 import org.lcsim.detector.solids.ISolid;
@@ -37,7 +41,7 @@
     List<MaterialCylinder> _matcyl = new ArrayList<MaterialCylinder>();
     List<MaterialDisk> _matdsk = new ArrayList<MaterialDisk>();
     double _rmax;
-    
+      
     /** Creates a new instance of MaterialManager */
     public MaterialManager() {
     }
@@ -50,13 +54,19 @@
         //
         //  First find the logical volume associated with the tracker
         Detector det = event.getDetector();
+        IPhysicalVolumeNavigator nav = det.getNavigator(); 
         ILogicalVolume ltrkr = det.getTrackingVolume().getLogicalVolume();
         //  Loop over the volumes defined at the compact.xml level
         for (IPhysicalVolume pvtree : ltrkr.getDaughters()) {
             //  Flatten the geometry tree to get all daughters with material
-            List<IPhysicalVolume> pvflat = Flatten(pvtree);
-            //  Calculate the total volume of material, skip this object if 0
-            double vtot = TotalVolume(pvflat);
+            //List<IPhysicalVolume> pvflat = Flatten(pvtree);
+            List<UniquePV> pvflat = Flatten(pvtree,nav); 
+            
+//           System.out.println(pvflat.size()); 
+           //  Calculate the total volume of material, skip this object if 0
+           double vtot = TotalVolume(pvflat);
+          
+            
             if (vtot > 0.) {
                 //  Calculate the average radiation length for this volume
                 double X0 = RadiationLength(pvflat);
@@ -68,12 +78,28 @@
                     double zmax = zmax(pvtree, pvflat);
                     double zlen = zmax - zmin;
                     double thickness = vtot / (2. * Math.PI * rwgt * zlen * X0);
+                    
+                    if (false){
+                        System.out.println(pvtree.getName()); 
+                        System.out.println("x0: "+X0 + "| zmin: "+zmin + "| zmax: "+zmax + "| vtot: "+vtot + "| thickness: "+thickness + 
+                                "| rmin: "+(rmin(pvflat)) + "| rmax: "+rmax(pvflat)); 
+                        System.out.println(); 
+                    }
+                    
                     _matcyl.add(new MaterialCylinder(pvtree, rwgt, zmin, zmax, thickness));
                 } else {
                     double zwgt = WeightedZ(pvtree, pvflat);
                     double rmin = rmin(pvflat);
                     double rmax = rmax(pvflat);
                     double thickness = vtot / (Math.PI * (rmax*rmax - rmin*rmin) * X0);
+                    
+                    if (false){
+                        System.out.println(pvtree.getName()); 
+                        System.out.println("x0: "+X0 + "| zmin: "+zmin(pvtree,pvflat) + "| zmax: "+zmax(pvtree,pvflat) + "| vtot: "+vtot + "| thickness: "+thickness + 
+                                "| rmin: "+rmin + "| rmax: "+rmax); 
+                        System.out.println(); 
+                    }
+                    
                     _matdsk.add(new MaterialDisk(pvtree, rmin, rmax, zwgt, thickness));
                 }
             }
@@ -122,27 +148,53 @@
         return _rmax;
     }
     
-    private List<IPhysicalVolume> Flatten(IPhysicalVolume xmlvol) {
-        //  Flatten the geometry tree to find all the physical volumes for
-        //  this tracker element that have no daughters
-        LinkedList<IPhysicalVolume> pvtree = new LinkedList<IPhysicalVolume>();
-        pvtree.add(xmlvol);
-        List<IPhysicalVolume> pvflat = new ArrayList<IPhysicalVolume>();
-        while (pvtree.size()>0) {
-            IPhysicalVolume pv = pvtree.poll();
+//    private List<IPhysicalVolume> Flatten(IPhysicalVolume xmlvol) {        //  Flatten the geometry tree to find all the physical volumes for
+//        //  this tracker element that have no daughters
+//        LinkedList<IPhysicalVolume> pvtree = new LinkedList<IPhysicalVolume>();
+//        pvtree.add(xmlvol);
+//        List<IPhysicalVolume> pvflat = new ArrayList<IPhysicalVolume>();
+//        while (pvtree.size()>0) {
+//            IPhysicalVolume pv = pvtree.poll();
+//            if (pv.getLogicalVolume().getNumberOfDaughters()==0) {
+//                pvflat.add(pv);
+//            } else {
+//                pvtree.addAll(pv.getLogicalVolume().getDaughters());
+//            }
+//        }
+//        return pvflat;
+//    }
+    
+    private List<UniquePV> Flatten(IPhysicalVolume vol, IPhysicalVolumeNavigator nav){
+        
+        LinkedList<UniquePV> pvtree = new LinkedList<UniquePV>(); 
+        List<UniquePV> pvflat = new ArrayList<UniquePV>(); 
+        pvtree.add(new UniquePV(vol,nav)); 
+        
+        while(pvtree.size()>0) {
+            
+            UniquePV upv = pvtree.poll(); 
+            IPhysicalVolume pv = upv.getPV(); 
+            
             if (pv.getLogicalVolume().getNumberOfDaughters()==0) {
-                pvflat.add(pv);
-            } else {
-                pvtree.addAll(pv.getLogicalVolume().getDaughters());
+//                if(pvflat.contains(upv)) System.out.println("DUPE!!!!"); 
+                pvflat.add(upv); 
+            }
+            
+            else {
+                for(IPhysicalVolume p : pv.getLogicalVolume().getDaughters()) {
+                   pvtree.add(upv.createDaughterUniquePV(p)); 
+                }        
             }
         }
-        return pvflat;
+        
+        return pvflat; 
     }
     
-    private double TotalVolume(List<IPhysicalVolume> pvlist) {
+    
+    private double TotalVolume(List<UniquePV> pvlist) {
         double vtot = 0.;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
             
             vtot += safeCubicVolume(solid);
             
@@ -150,16 +202,16 @@
         return vtot;
     }
     
-    private double RadiationLength(List<IPhysicalVolume> pvlist) {
+    private double RadiationLength(List<UniquePV> pvlist) {
         double X0wgt = 0.;
         double invX0 = 0.;
         double vtot = 0.;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
             
             double vol = safeCubicVolume(solid);
             vtot += vol;
-            IMaterial mat = pv.getLogicalVolume().getMaterial();
+            IMaterial mat = pv.getPV().getLogicalVolume().getMaterial();
             double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
             if (X0 > 0.) invX0 += vol / X0;
             
@@ -168,30 +220,29 @@
         return X0wgt;
     }
     
-    private double rmin(List<IPhysicalVolume> pvlist) {
+    private double rmin(List<UniquePV> pvlist) {
         double rmin = 1.e10;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
-            rmin = Math.min(rmin, calculateRMinSolid(solid));
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
+            rmin = Math.min(rmin, calculateRMinSolid(solid,pv));
         }
-        return rmin;
+        return rmin; 
     }
     
-    private double rmax(List<IPhysicalVolume> pvlist) {
+    private double rmax(List<UniquePV> pvlist) {
         double rmax = 0.;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
-            rmax = Math.max(rmax, calculateRMaxSolid(solid));
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
+            rmax = Math.max(rmax, calculateRMaxSolid(solid,pv));
         }
         return rmax;
     }
     
-    private double zmin(IPhysicalVolume pvtree, List<IPhysicalVolume> pvlist) {
+    private double zmin(IPhysicalVolume pvtree, List<UniquePV> pvlist) {
         double zmin = 1.e10;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
-            
-            
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
+
             double z0 = pvtree.getTranslation().z();
             if (solid instanceof Tube) {
                 Tube tube = (Tube) solid;
@@ -199,7 +250,25 @@
             }
             else if (solid instanceof Box) {
                 Box box = (Box) solid; 
-                zmin = Math.min(zmin, z0-box.getZHalfLength());
+                
+//                if (pvtree.getName().equals("SiTrackerBarrel_layer0")) {
+//                    System.out.println("====new box====");
+//                    System.out.println(pv.toString());
+//                    System.out.println("Claimed dimensions: "+2*box.getXHalfLength()+"x"+2*box.getYHalfLength()+"x"+2*box.getZHalfLength()); 
+//                
+//                }
+                for (Point3D p : box.getVertices()){
+                    Hep3Vector transformed = pv.localToGlobal(p.getHep3Vector()); 
+                    
+//                    if (pvtree.getName().equals("SiTrackerBarrel_layer0")) {
+//                        System.out.println(transformed.toString());
+//                    } 
+                    
+                    zmin = Math.min(transformed.z(), zmin); 
+//                    if (zmin==transformed.z()){
+                        //System.out.println("New zmin for "+pvtree.getName()+" at "+zmin+". Part name is "+pv.getName()); 
+//                    }
+                }
             }
             else if (solid instanceof Polycone) {
                 Polycone polycone = (Polycone) solid;
@@ -209,19 +278,23 @@
         return zmin;
     }
     
-    private double zmax(IPhysicalVolume pvtree, List<IPhysicalVolume> pvlist) {
+    private double zmax(IPhysicalVolume pvtree, List<UniquePV> pvlist) {
         double zmax = -1.e10;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
-         
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
+            
             double z0 = pvtree.getTranslation().z();
+
             if (solid instanceof Tube) {
                 Tube tube = (Tube) solid;
                 zmax = Math.max(zmax, z0+tube.getZHalfLength());
             }
             else if (solid instanceof Box) {
                 Box box = (Box) solid;
-                zmax = Math.max(zmax, z0+box.getZHalfLength());
+                for (Point3D p : box.getVertices()){
+                    Hep3Vector transformed = pv.localToGlobal(p.getHep3Vector());
+                    zmax = Math.max(transformed.z(), zmax); 
+                }
             }
             else if (solid instanceof Polycone) {
                 Polycone polycone = (Polycone) solid;
@@ -231,7 +304,7 @@
         return zmax;
     }
     
-    private boolean isCylinder(IPhysicalVolume pvtree, List<IPhysicalVolume> pvlist) {
+    private boolean isCylinder(IPhysicalVolume pvtree, List<UniquePV> pvlist) {
         double rmin = rmin(pvlist);
         double rmax = rmax(pvlist);
         double zmin = zmin(pvtree, pvlist);
@@ -239,16 +312,16 @@
         return (rmax - rmin) * Math.abs(zmax + zmin) < (zmax - zmin) * (rmax + rmin);
     }
     
-    private double WeightedRadius(List<IPhysicalVolume> pvlist) {
+    private double WeightedRadius(List<UniquePV> pvlist) {
         double rwgt = 0.;
         double totwgt = 0.;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
             
-            double rmin = calculateRMinSolid(solid);
-            double rmax = calculateRMaxSolid(solid);
+            double rmin = calculateRMinSolid(solid, pv);
+            double rmax = calculateRMaxSolid(solid, pv);
             double vol = safeCubicVolume(solid);
-            IMaterial mat = pv.getLogicalVolume().getMaterial();
+            IMaterial mat = pv.getPV().getLogicalVolume().getMaterial();
             double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
             double wgt = vol / X0;
             rwgt += 0.5 * (rmin + rmax) * wgt;
@@ -259,15 +332,15 @@
         return rwgt;
     }
     
-    private double WeightedZ(IPhysicalVolume pvtree, List<IPhysicalVolume> pvlist) {
+    private double WeightedZ(IPhysicalVolume pvtree, List<UniquePV> pvlist) {
         double zwgt = 0.;
         double totwgt = 0.;
-        for (IPhysicalVolume pv : pvlist) {
-            ISolid solid = pv.getLogicalVolume().getSolid();
+        for (UniquePV pv : pvlist) {
+            ISolid solid = pv.getPV().getLogicalVolume().getSolid();
             
             double z0 = pvtree.getTranslation().z();
             double vol = safeCubicVolume(solid);
-            IMaterial mat = pv.getLogicalVolume().getMaterial();
+            IMaterial mat = pv.getPV().getLogicalVolume().getMaterial();
             double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
             double wgt = vol / X0;
             zwgt += z0 * wgt;
@@ -291,9 +364,10 @@
         }
     }
     
+ 
     
     //functions that give the rmin and rmax of a solid... 
-    private double calculateRMinSolid(ISolid solid){
+    private double calculateRMinSolid(ISolid solid, UniquePV pv){
         
         double rmin = 1e10; 
         if (solid instanceof Tube) {
@@ -301,13 +375,16 @@
            return tube.getInnerRadius();
         }
         
-        //this essentially finds the vertex with the minimum magnitude
+        
         else if (solid instanceof Box) {
            Box box = (Box) solid;  
            List<Point3D> vtx = box.getVertices();
            
            for (Point3D p : vtx) {
-               rmin = Math.min(rmin, p.magnitude()); 
+               
+               Hep3Vector transformed = pv.localToGlobal(p.getHep3Vector());
+               double r = Math.sqrt(transformed.x()*transformed.x() + transformed.y()*transformed.y()); 
+               rmin = Math.min(rmin,r);
            }
            return rmin; 
         }
@@ -321,8 +398,8 @@
         return rmin;
     }
     
-    //this (hopefully) does the exact opposite of calculateRMinSolid
-    private double calculateRMaxSolid(ISolid solid){
+    
+    private double calculateRMaxSolid(ISolid solid, UniquePV pv){
         
         double rMax = 0; 
         if (solid instanceof Tube) {
@@ -335,7 +412,10 @@
            List<Point3D> vtx = box.getVertices();
            
            for (Point3D p : vtx) {
-               rMax = Math.max(rMax, p.magnitude());
+               
+               Hep3Vector transformed = pv.localToGlobal(p.getHep3Vector());
+               double r = Math.sqrt(transformed.x()*transformed.x() + transformed.y()*transformed.y()); 
+               rMax = Math.max(r, rMax); 
            }
            return rMax; 
         }
@@ -348,4 +428,54 @@
         return rMax;
     }
     
+ 
+    
+    class UniquePV{
+        
+        IPhysicalVolumePath path; 
+        IPhysicalVolumeNavigator nav; 
+        ITransform3D transform = null; 
+        
+        public UniquePV(IPhysicalVolume root, IPhysicalVolumeNavigator navigator){
+            path = new PhysicalVolumePath(); 
+            nav = navigator; 
+            path.add(root); 
+            
+        }
+        
+        public UniquePV(IPhysicalVolumePath path, IPhysicalVolumeNavigator navigator){
+            this.path = path; 
+            nav = navigator; 
+        }
+
+        public IPhysicalVolume getPV(){
+            return path.getLeafVolume();
+        }
+        
+        public UniquePV createDaughterUniquePV(IPhysicalVolume daughter){
+            
+            IPhysicalVolumePath np = new PhysicalVolumePath();  
+            np.addAll(path); 
+            np.add(daughter);        
+            return new UniquePV(np,nav); 
+        }
+        
+        
+        public Hep3Vector localToGlobal(Hep3Vector v) {
+            
+            if(transform == null){
+                transform = nav.getTransform(path); 
+            }
+            return transform.transformed(v); 
+              
+        }
+        
+        @Override 
+        public String toString(){
+            return path.toString(); 
+        }
+    }
+            
+            
+            
 }
CVSspam 0.2.8