Commit in lcsim/src/org/lcsim/contrib/NickSinev/PixSim on MAIN
PixilatedSensor.java+55-61.1 -> 1.2
PixilatedSensorManager.java+163-1611.1 -> 1.2
+218-167
2 modified files
Fixed problems of dealing with new DE and Hit collection names names, and with 
new orientation of local coordinate system for endcaps .

lcsim/src/org/lcsim/contrib/NickSinev/PixSim
PixilatedSensor.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- PixilatedSensor.java	1 Jul 2008 21:40:03 -0000	1.1
+++ PixilatedSensor.java	15 Jul 2008 01:18:29 -0000	1.2
@@ -40,9 +40,9 @@
   private double x0 = 0.;
   private double y0 = 0.;
   private double z0 = 0.;
-  private double lenX = 0.;
-  private double lenY = 0.;
-  private double bulk_thick = 0.1;
+  public double lenX = 0.;
+  public double lenY = 0.;
+  public double bulk_thick = 0.1;
   private double sthick = 0.02;
   private boolean is_endcap = false;
   private boolean cyl_coord = false;
@@ -149,6 +149,9 @@
 
   private void setBoundaries()
   {
+   ITransform3D glocal = null;
+   ITransform3D gglobal = null; 
+   Hep3Vector zv = new BasicHep3Vector(0.,0.,0.);
    pixel_configuration = _cpr.getPixelConfiguration();
    _tss = new TrackSegmentSimulation(_cpr);
    if(parent != null)
@@ -156,8 +159,24 @@
     if(parent.hasGeometryInfo())
     {
      geometry_info = parent.getGeometry();
-     local = geometry_info.getGlobalToLocal();
-     global = geometry_info.getLocalToGlobal();
+     glocal = geometry_info.getGlobalToLocal();
+     gglobal = geometry_info.getLocalToGlobal();
+     if(!is_endcap)
+     {
+      local =  glocal;
+      global = gglobal;
+     } 
+     boolean zrotated = false;
+     if(is_endcap)
+     {
+      double zrot = (glocal.getRotation()).getComponent(2,2);
+      if(Math.abs(zrot) <0.999) zrotated = true; 
+      Hep3Vector dec = gglobal.transformed(zv);
+      Hep3Vector idec = new BasicHep3Vector(-dec.x(),-dec.y(),-dec.z());
+      ITranslation3D ltr = new Translation3D(idec);
+      local = new Transform3D(ltr);
+      global = local.inverse();
+     }
      ILogicalVolume lv = geometry_info.getLogicalVolume();
      ISolid body = lv.getSolid();
      if(body instanceof Box)
@@ -166,7 +185,37 @@
       lenX = 2.* ((Box) body).getXHalfLength();
       lenY = 2.* ((Box) body).getYHalfLength();
       bulk_thick = 2. * ((Box) body).getZHalfLength();
-     }   
+      if(is_endcap && zrotated)
+      {
+       lenY = 2. * ((Box) body).getZHalfLength();
+       bulk_thick = 2.* ((Box) body).getYHalfLength();
+      }
+     }
+     if((body instanceof Trd) || (body instanceof Trap))
+     {
+      List<Point3D> globv = null;
+      if(body instanceof Trd) globv = ((Trd) body).getVertices();
+      if(body instanceof Trap) globv = ((Trap) body).getVertices();
+      double minlx=0.;
+      double maxlx=0.;
+      double minly=0.;
+      double maxly=0.;
+      double minlz=0.;
+      double maxlz=0.;
+      for(Point3D vert:globv)
+      {
+       Point3D lvp = vert.transformed(gglobal);
+       if(lvp.x() < minlx) minlx=lvp.x();
+       if(lvp.x() > maxlx) maxlx=lvp.x();
+       if(lvp.y() < minly) minly=lvp.y();
+       if(lvp.y() > maxly) maxly=lvp.y();
+       if(lvp.z() < minlz) minlz=lvp.z();
+       if(lvp.z() > maxlz) maxlz=lvp.z();
+      }
+      lenX=maxlx-minlx;
+      lenY=maxly-minly;
+      bulk_thick = maxlz-minlz;  
+     }    
      if((body instanceof Tube) && is_endcap)
      {
       cyl_coord = false;

lcsim/src/org/lcsim/contrib/NickSinev/PixSim
PixilatedSensorManager.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- PixilatedSensorManager.java	1 Jul 2008 21:40:03 -0000	1.1
+++ PixilatedSensorManager.java	15 Jul 2008 01:18:29 -0000	1.2
@@ -19,7 +19,7 @@
  * for each event (only sensors which have hits in them are created)
  *
  * @author Nick Sinev
- * @version $Id: PixilatedSensorManager.java,v 1.1 2008/07/01 21:40:03 sinev Exp $
+ * @version $Id: PixilatedSensorManager.java,v 1.2 2008/07/15 01:18:29 sinev Exp $
  */
 
 public class PixilatedSensorManager extends Driver
@@ -470,135 +470,89 @@
    IDetectorElement tde = det.getDetectorElement();
    if(tde != null)
    {
-//    System.out.println("Detector elements: ");
     List<IDetectorElement> chlds= (List<IDetectorElement>) tde.getChildren();
     for(IDetectorElement chld:chlds)
     {
      String name = chld.getName();
-//     System.out.println(name);
      if((name.indexOf("Vtx")!=-1) || (name.indexOf("Vertex") != -1))
      {
-//      System.out.println(" processing "+name);
+       int tot=0;
+       int lvl=0;
+       int[] ind = new int[10];
+       for(int i=0; i<10; i++) ind[i]=0;
+       boolean found = false;
+       List<IDetectorElement> children = new ArrayList<IDetectorElement>();
+       IDetectorElement child = chld;
+       IDetectorElement[] parent = new IDetectorElement[10];
+       parent[0]=child;
+       int[] nchldrn = new int[10];
+       children= parent[0].getChildren();
+       nchldrn[0] = children.size();
+
       if(name.indexOf("Barrel") !=-1)
       {
-       if(!chld.hasChildren()) vxbrels.add(chld);
-       else
+       while((lvl > -1) && (tot<2000) && (ind[lvl] <= nchldrn[lvl]))
        {
-        List<IDetectorElement> chlds1= (List<IDetectorElement>) chld.getChildren();
-        for(IDetectorElement chld1:chlds1)
+        while((ind[lvl] == nchldrn[lvl]) && (lvl > -1))
+        {
+         ind[lvl]=0; 
+         lvl--;
+         if(lvl > -1) ind[lvl]++;
+         if(lvl < 0) break;
+        }
+        if(lvl < 0) break;
+        while(parent[lvl].hasChildren())
         {
-         if(!chld1.hasChildren()) vxbrels.add(chld1);
-         else
-         {
-          List<IDetectorElement> chlds2= (List<IDetectorElement>) chld1.getChildren();
-          for(IDetectorElement chld2:chlds2)
-          {
-           if(!chld2.hasChildren()) vxbrels.add(chld2);
-           else
-           {
-            List<IDetectorElement> chlds3= (List<IDetectorElement>) chld2.getChildren();
-            for(IDetectorElement chld3:chlds3)
-            {
-             if(!chld3.hasChildren()) vxbrels.add(chld3);
-             else
-             {
-              List<IDetectorElement> chlds4= (List<IDetectorElement>) chld3.getChildren();
-              for(IDetectorElement chld4:chlds4)
-              {
-               if(!chld4.hasChildren()) vxbrels.add(chld4);
-               else
-               {
-                System.out.println("Can't reach bottom of descendants chain!");
-               }
-              }
-             }
-            }
-           }
-          }
-         }
+         children=parent[lvl].getChildren();
+         child = children.get(ind[lvl]);
+         nchldrn[lvl]= children.size();
+         lvl++;
+         parent[lvl]=child;
         }
-       } 
-      } 
+        if(!child.hasChildren())
+        {
+         lvl--;
+         vxbrels.add(child);
+         ind[lvl]++;
+        }
+       } // end of while
+      }
       if(name.indexOf("Endcap") !=-1)
       {
-//       System.out.println("It is endcap!");
-       if(!chld.hasChildren())
-       {
-//        System.out.println("It does not have children!");
-        if(name.indexOf("positive") != -1)
-         vxecpels.add(chld);
-        if(name.indexOf("negative") != -1)
-         vxecmels.add(chld);
-       } 
-       else
+       while((lvl > -1) && (tot<2000) && (ind[lvl] <= nchldrn[lvl]))
        {
-        List<IDetectorElement> chlds1= (List<IDetectorElement>) chld.getChildren();
-        for(IDetectorElement chld1:chlds1)
+        while((ind[lvl] == nchldrn[lvl]) && (lvl > -1))
         {
-         if(!chld1.hasChildren())
-         {
-          name = chld1.getName();
-//          System.out.println("  "+name); 
-          if(name.indexOf("positive") != -1)
-           vxecpels.add(chld1);
-          if(name.indexOf("negative") != -1)
-           vxecmels.add(chld1);
-         }
-         else
-         {
-          List<IDetectorElement> chlds2= (List<IDetectorElement>) chld1.getChildren();
-          for(IDetectorElement chld2:chlds2)
-          {
-           if(!chld2.hasChildren())
-           {
-            name = chld2.getName();
-//            System.out.println("    "+name); 
-            if(name.indexOf("positive") != -1)
-             vxecpels.add(chld2);
-            if(name.indexOf("negative") != -1)
-             vxecmels.add(chld2);
-           }
-           else
-           {
-            List<IDetectorElement> chlds3= (List<IDetectorElement>) chld2.getChildren();
-            for(IDetectorElement chld3:chlds3)
-            {
-             if(!chld3.hasChildren())
-             {
-              if(name.indexOf("positive") != -1)
-               vxecpels.add(chld3);
-              if(name.indexOf("negative") != -1)
-               vxecmels.add(chld3);
-             }  
-             else
-             {
-              List<IDetectorElement> chlds4= (List<IDetectorElement>) chld3.getChildren();
-              for(IDetectorElement chld4:chlds4)
-              {
-               if(!chld4.hasChildren())
-               {
-                if(name.indexOf("positive") != -1)
-                 vxecpels.add(chld4);
-                if(name.indexOf("negative") != -1)
-                 vxecmels.add(chld4);
-               }
-               else
-               {
-                System.out.println("Can't reach bottom of descendants chain!");
-               }
-              }
-             }
-            }
-           }
-          }
-         }
+         ind[lvl]=0; 
+         lvl--;
+         if(lvl > -1) ind[lvl]++;
+         if(lvl < 0) break;
         }
-       } 
-      } 
+        if(lvl < 0) break;
+        while(parent[lvl].hasChildren())
+        {
+         children=parent[lvl].getChildren();
+         child = children.get(ind[lvl]);
+         nchldrn[lvl]= children.size();
+         lvl++;
+         parent[lvl]=child;
+        }
+        if(!child.hasChildren())
+        {
+         lvl--;
+         name = child.getName();
+         if(name.indexOf("positive") != -1)
+           vxecpels.add(child);
+         if(name.indexOf("negative") != -1)
+          vxecmels.add(child);
+         ind[lvl]++;
+        }
+       } // end of while
+      }
      } // end of if((name.indexOf("Vtx")!=-1) || (name.indexOf("Vertex") != -1))
     } // end of for(IDetectorElement chld:chlds)
    } // end of if(tde != null)
-//   System.out.println("Detector contains "+vxbrels.size()+" barrel vertex and "+vxecpels.size()+" endcap detector elements");
+   System.out.println("Detector contains "+vxbrels.size()+" barrel vertex and "+vxecpels.size()+" endcap detector elements");
    int nbe = 0;
    if(read_rest_bar)
    { 
@@ -653,7 +607,8 @@
     }
     nbcm++; 
     psecml.add(pse);
-   }     
+   }
+   System.out.println("Created: "+nbe+" barrel pixilated sensors and "+nbc+" EC positive and "+nbcm+" EC negative pixilated sensors");     
   } // end of if(firstcall)
   if(!ready) return;
   for(IDetectorElement de:vxbrels)
@@ -673,50 +628,43 @@
   for(PixilatedSensor sensor:psecml) sensor.clear();
   phys_time = phys_bc*bunch_period;
   List<List<SimTrackerHit>> evhits = event.get(SimTrackerHit.class);
+  String bhcname=null;
+  String ehcname=null;
   if(evhits != null)
   {
-   List<SimTrackerHit> vxbhts = event.get(SimTrackerHit.class,"VtxBarrelHits");
-   int asshts = 0; 
-   for(SimTrackerHit hit:vxbhts)
-   {
-    double[] hpnt = hit.getPoint();    
-    Hep3Vector vhitp = new BasicHep3Vector(hpnt[0],hpnt[1],hpnt[2]);
-    IDetectorElement hitde = null;
-    for(IDetectorElement vtxp:vxbrels)
-    {
-     IDetectorElement de = vtxp.findDetectorElement(vhitp);
-     if(de !=null) hitde=de;
-    }
-    if(hitde == null) System.out.println("Could not find sensor for hit: "+vhitp.x()+" "+vhitp.y()+" "+vhitp.z());
-    if((hitde != null) && (asshts<MAXHTSPEV))
+//   System.out.println("Event has  "+evhits.size()+" SimTrackerHit collections: ");
+   for(List<SimTrackerHit> sdhits:evhits)
+   {
+    EventHeader.LCMetaData md = event.getMetaData(sdhits);
+    String cname = md.getName();
+    if((cname.indexOf("Vtx")!=-1)||(cname.indexOf("Vertex") != -1))
     {
-     asshts++;  
-     IReadout hts = hitde.getReadout();
-     double t=hit.getTime()*cons.nanosecond;
-     if(assign_bc) t+=phys_time;
-     SimPixelHit spht= new SimPixelHit(hit,t);
-     hts.addHit(hit);
-     for(PixilatedSensor psen:psbrl)
-     {
-      if((psen.getParent() !=null) && (psen.getParent() == hitde)) psen.addSimPixelHit(spht);
-     }
+     if(cname.indexOf("Barrel")!=-1) bhcname=cname;
+     if(cname.indexOf("Endcap")!=-1) ehcname=cname;
     }
    }
-   List<SimTrackerHit> vxehts = event.get(SimTrackerHit.class,"VtxEndcapHits");
-   for(SimTrackerHit hit:vxehts)
+//   System.out.println("Vertex barrel sim hit collection name is: "+bhcname+" and for encap it is: "+ehcname);
+  }
+  int asshts = 0;
+  int nprints = 0; 
+  if(evhits != null)
+  {
+   if(bhcname != null)
    {
-    double[] hpnt = hit.getPoint();    
-    Hep3Vector vhitp = new BasicHep3Vector(hpnt[0],hpnt[1],hpnt[2]);
-    IDetectorElement hitde = null;
-    if(hpnt[2] > 0.)
+    List<SimTrackerHit> vxbhts = event.get(SimTrackerHit.class,bhcname);
+//    System.out.println("SimTrackerHit collection size for barrel: "+vxbhts.size());
+    for(SimTrackerHit hit:vxbhts)
     {
-     for(IDetectorElement vtxp:vxecpels)
+     double[] hpnt = hit.getPoint();    
+     Hep3Vector vhitp = new BasicHep3Vector(hpnt[0],hpnt[1],hpnt[2]);
+     IDetectorElement hitde = null;
+     for(IDetectorElement vtxp:vxbrels)
      {
       IDetectorElement de = vtxp.findDetectorElement(vhitp);
       if(de !=null) hitde=de;
      }
      if(hitde == null) System.out.println("Could not find sensor for hit: "+vhitp.x()+" "+vhitp.y()+" "+vhitp.z());
-     if((hitde != null) && (asshts < MAXHTSPEV))
+     if((hitde != null) && (asshts<MAXHTSPEV))
      {
       asshts++;  
       IReadout hts = hitde.getReadout();
@@ -724,36 +672,90 @@
       if(assign_bc) t+=phys_time;
       SimPixelHit spht= new SimPixelHit(hit,t);
       hts.addHit(hit);
-      for(PixilatedSensor psen:psecpl)
+      for(PixilatedSensor psen:psbrl)
       {
        if((psen.getParent() !=null) && (psen.getParent() == hitde)) psen.addSimPixelHit(spht);
       }
      }
     }
-    if(hpnt[2] < 0.)
+   }
+   if(ehcname != null)
+   {
+    List<SimTrackerHit> vxehts = event.get(SimTrackerHit.class,ehcname);
+//    System.out.println("SimTrackerHit collection size for endcap: "+vxehts.size());
+    for(SimTrackerHit hit:vxehts)
     {
-     for(IDetectorElement vtxp:vxecmels)
+     double[] hpnt = hit.getPoint();    
+     Hep3Vector vhitp = new BasicHep3Vector(hpnt[0],hpnt[1],hpnt[2]);
+     IDetectorElement hitde = null;
+     if(hpnt[2] > 0.)
      {
-      IDetectorElement de = vtxp.findDetectorElement(vhitp);
-      if(de !=null) hitde=de;
+      for(IDetectorElement vtxp:vxecpels)
+      {
+       IDetectorElement de = vtxp.findDetectorElement(vhitp);
+       if(de !=null) hitde=de;
+      }
+      if(hitde == null) System.out.println("Could not find sensor for hit: "+vhitp.x()+" "+vhitp.y()+" "+vhitp.z());
+      if((hitde != null) && (asshts < MAXHTSPEV))
+      {
+       boolean isbox = false;
+       IDetectorElement parent = hitde;
+       if(parent.hasGeometryInfo())
+       {
+        IGeometryInfo geometry_info = parent.getGeometry();
+        ITransform3D local = geometry_info.getGlobalToLocal();
+        ILogicalVolume lv = geometry_info.getLogicalVolume();
+        ISolid body = lv.getSolid();
+        if(body instanceof Box)
+        {
+         isbox = true;
+         double lenX = 2.* ((Box) body).getXHalfLength();
+         double lenY = 2.* ((Box) body).getYHalfLength();
+         double bulk_thick = 2. * ((Box) body).getZHalfLength();
+        }
+       }
+       asshts++;  
+       IReadout hts = hitde.getReadout();
+       double t=hit.getTime()*cons.nanosecond;
+       if(assign_bc) t+=phys_time;
+       SimPixelHit spht= new SimPixelHit(hit,t);
+       hts.addHit(hit);
+       boolean foundmatch = false;
+       for(PixilatedSensor psen:psecpl)
+       {
+        if((psen.getParent() !=null) && (psen.getParent() == hitde)) 
+        { 
+         psen.addSimPixelHit(spht);
+         foundmatch = true;
+        }
+       }
+       if(!foundmatch) System.out.println("Can't find matching pixilated sensor! "); 
+      }
      }
-     if(hitde == null) System.out.println("Could not find sensor for hit: "+vhitp.x()+" "+vhitp.y()+" "+vhitp.z());
-     if((hitde != null) && (asshts < MAXHTSPEV))
+     if(hpnt[2] < 0.)
      {
-      asshts++;  
-      IReadout hts = hitde.getReadout();
-      double t=hit.getTime()*cons.nanosecond;
-      if(assign_bc) t+=phys_time;
-      SimPixelHit spht= new SimPixelHit(hit,t);
-      hts.addHit(hit);
-      for(PixilatedSensor psen:psecml)
+      for(IDetectorElement vtxp:vxecmels)
       {
-       if((psen.getParent() !=null) && (psen.getParent() == hitde)) psen.addSimPixelHit(spht);
+       IDetectorElement de = vtxp.findDetectorElement(vhitp);
+       if(de !=null) hitde=de;
+      }
+      if(hitde == null) System.out.println("Could not find sensor for hit: "+vhitp.x()+" "+vhitp.y()+" "+vhitp.z());
+      if((hitde != null) && (asshts < MAXHTSPEV))
+      {
+       asshts++;  
+       IReadout hts = hitde.getReadout();
+       double t=hit.getTime()*cons.nanosecond;
+       if(assign_bc) t+=phys_time;
+       SimPixelHit spht= new SimPixelHit(hit,t);
+       hts.addHit(hit);
+       for(PixilatedSensor psen:psecml)
+       {
+        if((psen.getParent() !=null) && (psen.getParent() == hitde)) psen.addSimPixelHit(spht);
+       }
       }
      }
     }
-
-   }
+   } 
 //   System.out.println("Total number of assigned vertex hits: "+asshts);
   } // end if(evhits != null)
   List<TrackerHit> ebhits = new ArrayList<TrackerHit>();
CVSspam 0.2.8