Commit in lcsim/src/org/lcsim/recon/muon on MAIN
BarrelCalSegmentFinder.java+404-3991.27 -> 1.28
C. Milstene-10October2006-extension to the endcaps

lcsim/src/org/lcsim/recon/muon
BarrelCalSegmentFinder.java 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- BarrelCalSegmentFinder.java	3 Oct 2006 05:25:54 -0000	1.27
+++ BarrelCalSegmentFinder.java	11 Oct 2006 01:18:54 -0000	1.28
@@ -3,6 +3,7 @@
 import hep.physics.vec.BasicHep3Vector;
 import hep.physics.vec.Hep3Vector;
 import org.lcsim.event.*;
+import java.io.*; // not in last
 import java.util.*;
 import org.lcsim.util.step.TrackStepper;  //  C.M. Stepper
 import org.lcsim.recon.cluster.util.Samplexmlclass;
@@ -13,420 +14,424 @@
 import org.lcsim.geometry.segmentation.SegmentationBase;
 import org.lcsim.geometry.util.IDEncoder;
 import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.geometry.layer.LayerSlice;   // not in last
 import org.lcsim.recon.cluster.util.CalHitMapMgr;
 import org.lcsim.geometry.layer.*;
 import org.lcsim.geometry.Layered;
 import org.lcsim.geometry.LayeredSubdetector;
+import org.lcsim.geometry.field.FieldOverlay;
 import org.lcsim.geometry.Subdetector;
 /**
  * @author Rich Markeloff,
  * Modified by Caroline Milstene - January-02-04 - To include the electromagnetic calorimeter
  * and to include the loss of energy by the De/Dx and the effect of the magnetic field by using
  * stepper - January-05.
- *
- * New modifications by Judith Odili - 06/22/06 - For the lcsim format -
- * To read the detector information directly from the \
- * Compact.xml file by calling the Samplexmlclass methods
- *
  * New modifications by Judith Odili and Caroline Milstene - 07/13/06 -
- * Modified so the Stepper information get read
- * directly from StepConditions class.
+ * Modified so the Stepper information get read directly from StepConditions class.
+ * Muon Segment Finder for barrel calorimeter
+ * Modified to include the EM Calorimeter- C.Milstene
+ *  Modified to use the Stepper.class in org.lcsim.util.step,whenever the Swimmer class was used
+ * and in between elements as well- C. Milstene-January-02-04
+ * moved from stepperConditions to a StepperCondition.Class in util/step directory
  */
-// Muon Segment Finder for barrel calorimeter
-// Modified to include the EM Calorimeter- C.Milstene
-// Modified to use the Stepper.class in org.lcsim.util.step,
-// whenever the Swimmer class was used and in between
-// elements as well- C. Milstene-January-02-04
-// moved from stepperConditions to a StepperCondition.Class in util/step directory
-// NEXT to be done: finish to debugg at 2GeV/c
-//
 public class BarrelCalSegmentFinder extends SegmentFinder
 {
-   public BarrelCalSegmentFinder(Detector aDet, String subdetectorName)
-   {
+     public BarrelCalSegmentFinder(Detector aDet, String subdetectorName)
+     {
 
-      AIDA aida = AIDA.defaultInstance();
+        AIDA aida = AIDA.defaultInstance();
 
-      if(dedx==null) dedx = DeDx.instance();
-      subdetName = subdetectorName;
+        if(dedx==null) dedx = DeDx.instance();
+        subdetName = subdetectorName;
 
-      // Get the parameters that describe this detector component
-      det = aDet;
-      String a_nam = det.getHeader().getDetectorName();
-      calsub = (CylindricalBarrelCalorimeter)det.getSubdetectors().get(subdetName);
-
-      Layering layers = ((Layered) calsub).getLayering();
-
-
-      rmin = calsub.getInnerRadius();
-      rmax = calsub.getOuterRadius();
-      zmax = calsub.getZMax();
-      nLayers = layers.getLayerCount();
-      rLayer0Mid = calsub.getLayering().getDistanceToLayerSensorMid(0);
-
-      dataMgr = CalHitMapMgr.getInstance();
-      segm = (SegmentationBase)calsub.getReadout().getSegmentation();
-      // Set the nearest neighbor cuts to default values
-      if(subdetName.equals(ecalSubdetName))
-      {
-         phiNNCut   = 2; // 2;
-         thetaNNCut = 2; // 2;
-      }
-      else if(subdetName.equals(hcalSubdetName))
-      {
-         phiNNCut   = 3; // 3;
-         thetaNNCut = 2; // 2;
-      }
-
-      Subdetector subDet = aDet.getSubdetector(subdetName);
-      int nLayers = ((Layered) subDet).getLayering().getLayerCount();
-      SegmentationBase base = ((SegmentationBase) subDet.getIDDecoder());
-      if(debug)System.out.println("BCSF constructor: subdetName="+subdetName);
-   }
-   //----------------------------------!!!
-   public void findSegment(EventHeader event, TrackStepper inStpr)
-   //----------------------------------!!!
-   {
-      stpr    = inStpr;
-      int nr = 0;					// layer counter
-      int nLayerStepped=0;       // curlback layers included
-      double dr = (rmax - rmin)/nLayers;		// layer thickness
-      numLayersHit = 0;
-      double r;
-      // C.M. Dec-03- Tkparams to stepper
-      double tmpxyz ; double tmpp;
-      String materialName;
-      r=rmin;
-      // UPDATE Phase-Space
-      rpVect  = stpr.getNewRp();
-      if(debug) System.out.println("findSegment: subd="+subdetName);
-      if(stpr.getStopTkELow())return;
-      double[] field = det.getFieldMap().getField(rpVect); // C.M.-June-03
-      BField = field[2];
-      if(subdetName.equals(ecalSubdetName))
-      {
-         // Then do the Tracker up to r=rmin
-         double dTracker=(r-stpr.partR(rpVect));
-         materialName = "Air";
-         stpr.tkSteps( r, zmax,det, materialName );
-         if(debug)System.out.println("Tracker r=" +r+" zmax="+zmax+"Barrel:out of Tracker");
-         rpVect   = stpr.getNewRp();
-         if(debug)System.out.println(" CHECK NOW at Exit of Tracker rmin="+rmin+" dr="+dr) ;
-         if(r<(rmin-dr))return; // does not enter ECAL
-      }
-      if(subdetName.equals(hcalSubdetName))
-      {
-         if(debug)System.out.println(" !!!=== rmin="+rmin+" r="+r);
-         // Then air to r=rmin
-         rpVect   = stpr.getNewRp();
-         double d_EMHD = Math.abs(r-stpr.partR(rpVect));
-         stpr.setDTOF(rpVect,d_EMHD);
-         double dt_EMHD=stpr.getDTOF();
-         if(debug)System.out.println(" distance between calorimeters EM-HD "+d_EMHD);
-         materialName = "Air";
-         stpr.tkSteps( r, zmax,det, materialName );
-         rpVect  = stpr.getNewRp();
-         // if(r<(rmin-dr))return; // does not enter HCAL
-      }
-      if(debug)System.out.println("Stepper pos ENTRY of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
-
-      // Forms a muon segment by looking for calorimeter hits that match
-      // cells which the track passes through
-      // Begin by finding intersection of track with innermost layer
-      if(debug)System.out.println("subdet="+subdetName+", sensormid="+rLayer0Mid);
-      r    = rLayer0Mid;
-      stpr.tkSteps(r, zmax,det, subdetName, nr);
-      rpVect  = stpr.getNewRp();
-      if(debug)System.out.println(subdetName+" !!!!!! rmin="+rmin);
-      // Get intersections with successive layers as long as track is
-      // within the detector, and create a list of the cells that
-      // the track passes through
-      nLayerStepped=0;
-      while ((Math.abs(rpVect[2]) <= zmax )&& (nr < nLayers))
-      {
-         Hep3Vector v = new BasicHep3Vector(rpVect[0],rpVect[1],rpVect[2]);
-         hitPos.add(v);
-         long virtualID = segm.findCellContainingXYZ( rpVect );
-         cellList.add(virtualID);
-         if(stpr.getStopTkELow()) break;
-
-         if(stpr.getCurlBack())
-         {
-            if(debug &&(stpr.partR(rpVect)-dr)<(r-dr) )
-               System.out.println("!!!BCF:CURLINGBACK old r="+r+" New r="+(r-dr));
-            if(stpr.partR(rpVect)<r) r=r-dr   ;
-         }
-         else if(nr!=(nLayers-1)) r = r + dr;
-         else
-         {
-            r = rmin + nLayers * dr;
-            if(debug)System.out.println("BCF: AT Exit of "+subdetName+", r="+r);
-         }
-         stpr.tkSteps(r, zmax,det, subdetName, nr);
-         rpVect = stpr.getNewRp();
-         // double dThk=(nr!=(nLayers-1))?dr:(dr+dr-(rLayer0Mid-rmin));
-
-         if(!stpr.getCurlBack())nr++;
-         nLayerStepped++;
-      }//End of : Go on to the next layer
-      // Save number of layers track passed through
-      numLayersHit = nr;
-      if(debug)System.out.println("Stepper pos EXIT of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
-      rpVect= stpr.getNewRp();
-      if((rpVect[2]>=zmax)||stpr.getStopTkELow())
-      {// Record Last Layer and Info at Break
-         Hep3Vector v =new BasicHep3Vector(rpVect[0],rpVect[1],rpVect[2]);
-         hitPos.add(v);
-         long virtualID = segm.findCellContainingXYZ( rpVect );
-         cellList.add(virtualID);
-      }
-
-      double rr=stpr.partR(rpVect);
-      // Now match the cells on this list to calorimeter hits
-      if(subdetName.equals(hcalSubdetName))  //C.M.-27Jan03
-      {
-
-  	 if (debug) System.out.println("BCSF: Doing matchHits in HCal");
-         matchHitsFast(segm, dataMgr.getCollHitMap(hcalHitmapName) );
-
-      }
-      else if(subdetName.equals(ecalSubdetName)) //
-      {
-  	 if (debug) System.out.println("BCSF: Doing matchHits in ECal");
-         matchHitsFast(segm, dataMgr.getCollHitMap(ecalHitmapName) );
-      }
-
-      event.put(subdetName+"FoundHits",foundHits);
-   }
-
-   public void reset()
-   {
-      // Erase lists of hits and cells
-      hitList.removeAllElements();
-      cellList.removeAllElements();
-
-   }
-
-
-   public void setPhiNNCut(int cut)
-   {
-
-      // Set the number of nearest neighbors cut in phi. Cells
-      // with abs(phi_track - phi_cell) <=  cut will be added
-      // to the list
-
-      phiNNCut = cut;
-   }
-
-   public void setThetaNNCut(int cut)
-   {
-
-      // Set the number of nearest neighbors cut in theta. Cells
-      // with abs(theta_track - theta_cell) <=  cut will be added
-      // to the list
-
-      thetaNNCut = cut;
-   }
-
-   public double[] getNNCuts()
-   {
-      // Return the number of nearest neighbors cuts in phi and theta
-
-      return(new double[]
-      {phiNNCut, thetaNNCut});
-   }
-
-   public int getNLayersHit()
-   {
-      // Return the number of layers the track passed through
-
-      return(numLayersHit);
-   }
-
-
-//     public int xyzToPhiBin(double[] r)
-//     {
-//         // Determine phi bin corresponding to this Cartesian coordinate
-
-//         double phi;
-//         int bin;
-//         nc++;
-// 	double r1=r[1]/10; double r0=r[0]/10;
-//         phi = Math.atan2(r1, r0);
-//         if (phi < 0.) phi = phi + 2*Math.PI;
-//         bin = (int)(phi/phiBinSize);
-//         return(bin);
-//     }
-
-//     public int xyzToThetaBin(double[] r)
-//     {
-//         // Determine theta bin corresponding to this Cartesian coordinate
-//         double rho, theta;
-//         int bin;
-//         double r1=r[1]/10; double r0=r[0]/10; double r2=r[2]/10;
-//         rho = Math.sqrt(r0*r0 + r1*r1);
-//         theta = Math.atan2(rho, r2);
-//         if (theta < 0.) theta = theta + Math.PI;
-//         bin = (int)(theta/thetaBinSize);
-//         return(bin);
-//     }
-
-
-   // The following two methods implement the CalorimeterHits interface
-
-   public Enumeration getHits()
-   {
-      return(hitList.elements());
-   }
-   public Enumeration getHitsPos()
-   {
-      return(hitPos.elements());
-   }
-
-   public int getNHits()
-   {
-      return(hitList.size());
-   }
-   public int getNHitsPos()
-   {
-      return(hitPos.size());
-   }
-
-   protected void matchHitsFast(SegmentationBase cell,
-           Map<Long,CalorimeterHit> calHits)
-   {
-      this.matchHitsFast(cell, calHits, false);
-   }
-
-   protected void matchHitsFast(SegmentationBase cell,
-           Map<Long,CalorimeterHit> calHits,
-           boolean debug)
-   {
-      if(debug)System.out.println("Segm:::: "  + cell);
-      AIDA aida = AIDA.defaultInstance();
-      int nhitsTotal = 0;
-//       ProjectiveCylinder projCal = (ProjectiveCylinder)segm;
-      if(debug) System.out.println("matchhits: nhits = "+calHits.size());
-      for( Long cellid : cellList )
-      {
-// 	if(segm instanceof ProjectiveCylinder) {
-         // check cell itself
-
-         CalorimeterHit hit = calHits.get(cellid);
-         segm.setID(cellid);
-         int ilay = segm.getLayer();
-         if(hit!=null)
-         {
-            // found real hit at virtual cell
-            if(debug) System.out.println("matchHits: Adding hit: "+Long.toHexString(cellid));
-            if(debug)
-            {
-               double dall=0.;
-               for(int j=0;j<nLayers;j=j+4)
-               {
-                  if(ilay==j)
-                  {
-                     aida.cloud1D(subdetName+" dphi layer "+ilay).fill(dall);
-                     aida.cloud1D(subdetName+" dtheta layer "+ilay).fill(dall);
-                  }
-               }
-            }
-            foundHits.add(new BasicHep3Vector(segm.getX(),segm.getY(),segm.getZ()));
-            hitList.add(hit);
-            nhitsTotal++;
-         }
-         // now check for the neighbors
-         segm.setID(cellid);
-         int iphi = segm.getValue("phi");
-         int ithe = -99999;
-         try
-         {
-            //ithe = segm.getValue("theta");
-            ithe = segm.getValue("z");
-         }
-         catch(IllegalArgumentException x)
-         {
-            ithe = segm.getValue("z");
-         }
-         ilay = segm.getLayer();
-         long[] neighs = segm.getNeighbourIDs(0, thetaNNCut, phiNNCut );
-         for(int i=0; i<neighs.length; ++i)
-         {
-            hit = calHits.get(neighs[i]);
-
-//  	    if(debug) System.out.println("neighb: cellid="+MyTools.printID(neighs[i])+", hit="+hit);
-            if(hit!=null)
-            {
-               if(debug) System.out.println("matchHits: Adding hit: "+Long.toHexString(neighs[i]));
-               segm.setID( neighs[i] );
-               int jphi = segm.getValue("phi");
-               int jthe = 0;
-               try
-               {
-                  //jthe = segm.getValue("theta");
-                   jthe = segm.getValue("z");
-               }
-               catch(IllegalArgumentException x)
-               {
-                  jthe = segm.getValue("z");
-               }
-
-               int jlay = segm.getLayer();
-               if(debug)
-               {
-                  for(int j=0;j<nLayers;j=j+4)
-                  {
-                     if(ilay==j)
-                     {
-                        aida.cloud1D(subdetName+" dphi layer "+ilay).fill(jphi-iphi);
-                        aida.cloud1D(subdetName+" dtheta layer "+ilay).fill(jthe-ithe);
-                     }
-                  }
-               }
-               foundHits.add(new BasicHep3Vector(segm.getX(),segm.getY(),segm.getZ()));
-               hitList.add(hit);
-               nhitsTotal++;
-            }
-         }
-      }
-//  	}
-      if(debug) System.out.println("Total # hits: virtual="+cellList.size()
-      +", real="+nhitsTotal);
-   }
-
-
-   protected Detector det;
-   protected CylindricalBarrelCalorimeter calsub;
-   protected SegmentationBase segm;
-   protected IDEncoder encoder;
-   protected CalHitMapMgr dataMgr;
-   protected String ecalHitmapName = "EcalBarrHits";
-   protected String hcalHitmapName = "HcalBarrHits";
-   protected String ecalSubdetName = "EMBarrel";
-   protected String hcalSubdetName = "HADBarrel";
-   protected String muSubdetName = "MuonBarrel";
-   protected boolean debug = true;
-   protected int nc=0;
-   protected double BField ;// C.M.-Jan03
-   protected DeDx dedx;
-   protected double []rpVect       = new double[8] ;         // C.M.-4-Vector
-   protected String subdetName;      // C.M.-Jan03
-   protected double rmin;
-   protected double rLayer0Mid, totalthickness;
-   protected double rmax;
-   protected double zmax;
-   protected int nLayers;
-   protected int nPhi;
-   protected int nTheta;
-   protected double phiBinSize;
-   protected double thetaBinSize;
-   protected int numLayersHit;
-   protected Vector<Long> cellList = new Vector<Long>(); // list of cell indices
-   protected TrackStepper stpr     = new TrackStepper(); //C.M.-Stepper Instance
-   protected double [] stepConditions = new double[4];
-   protected Map<String, Double> materials;
-   public static Samplexmlclass xmlReader = new Samplexmlclass();
-   private int phiNNCut;
-   private int thetaNNCut;
-   private List<Hep3Vector> foundHits = new ArrayList<Hep3Vector>();
+        // Get the parameters that describe this detector component
+        det = aDet;
+        String a_nam = det.getHeader().getDetectorName();
+        calsub = (CylindricalBarrelCalorimeter)det.getSubdetectors().get(subdetName);
+
+        Layering layers = ((Layered) calsub).getLayering();
+
+        rmin = calsub.getInnerRadius();
+        rmax = calsub.getOuterRadius();
+        zmax = calsub.getZMax();
+        nLayers = layers.getLayerCount();
+        rLayer0Mid = calsub.getLayering().getDistanceToLayerSensorMid(0);
+
+        dataMgr = CalHitMapMgr.getInstance();
+        segm = (SegmentationBase)calsub.getReadout().getSegmentation();
+        // Set the nearest neighbor cuts to default values
+        if(subdetName.equals(ecalSubdetName))
+        {
+           phiNNCut   = 2; // 2;
+           thetaNNCut = 2; // 2;
+        }
+        else if(subdetName.equals(hcalSubdetName))
+        {
+           phiNNCut   = 3; // 3;
+           thetaNNCut = 2; // 2;
+        }
+
+        Subdetector subDet = aDet.getSubdetector(subdetName);
+        int nLayers = ((Layered) subDet).getLayering().getLayerCount();
+        SegmentationBase base = ((SegmentationBase) subDet.getIDDecoder());
+  	// Set system and barrel/endcap values
+  	if(debug)System.out.println("BCSF constructor: subdetName="+subdetName);
+     }
+     //----------------------------------!!!
+     public void findSegment(EventHeader event, TrackStepper inStpr)
+     //----------------------------------!!!
+     {
+
+        stpr    = inStpr;
+        int nr = 0;					// layer counter
+        int nLayerStepped=0;       // curlback layers included
+        double dr = (rmax - rmin)/nLayers;		// layer thickness
+        numLayersHit = 0;
+        double r;
+        // C.M. Dec-03- Tkparams to stepper
+        double tmpxyz ; double tmpp;
+        String materialName;
+        r=rmin;
+        // UPDATE Phase-Space
+        rpVect  = stpr.getNewRp();
+        System.out.println("BCF: Stepper pos Entry of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+        if(debug) System.out.println("findSegment: subd="+subdetName);
+        if(stpr.getStopTkELow())return;
+        double [] bField = det.getFieldMap().getField(rpVect); // C.M.-June-03
+        System.out.println("BCF:1- MagField="+bField[2]);
+
+        if(subdetName.equals(ecalSubdetName))
+        {
+           // Then do the Tracker up to r=rmin
+           double dTracker=(r-stpr.partR(rpVect));
+           bField=det.getFieldMap().getField(rpVect);
+           System.out.println("BCF: 2-bField[2]="+bField[2]);
+           materialName = "Air";
+            System.out.println("BCF: Stepper pos air before Entry of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+           stpr.tkSteps( r, zmax,"Barrel",bField[2], materialName );
+           if(debug)System.out.println("Tracker r=" +r+" zmax="+zmax+"Barrel:out of Tracker");
+           rpVect   = stpr.getNewRp();
+           System.out.println("BCF: Stepper pos after air before Entry of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+           if(debug)System.out.println(" CHECK NOW at Exit of Tracker rmin="+rmin+" dr="+dr) ;
+           if(r<(rmin-dr))return; // does not enter ECAL
+        System.out.println("Stepper pos EXIT of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+        }
+        if(subdetName.equals(hcalSubdetName))
+        {
+           if(debug)System.out.println(" !!!=== rmin="+rmin+" r="+r);
+           // Then air to r=rmin
+           rpVect   = stpr.getNewRp();
+           double d_EMHD = Math.abs(r-stpr.partR(rpVect));
+           stpr.setDTOF(rpVect,d_EMHD);
+           double dt_EMHD=stpr.getDTOF();
+           bField=det.getFieldMap().getField(rpVect);
+           System.out.println("BCF: 3-bField[2]="+bField[2]);
+           if(debug)System.out.println(" distance between calorimeters EM-HD "+d_EMHD);
+           materialName = "Air";
+           stpr.tkSteps( r, zmax,"Barrel",bField[2], materialName );
+           rpVect  = stpr.getNewRp();
+           // if(r<(rmin-dr))return; // does not enter HCAL
+        }
+        if(debug)System.out.println("Stepper pos ENTRY of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+
+        // Forms a muon segment by looking for calorimeter hits that match
+        // cells which the track passes through
+        // Begin by finding intersection of track with innermost layer
+        if(debug)System.out.println("subdet="+subdetName+", sensormid="+rLayer0Mid);
+        r    = rLayer0Mid;
+        stpr.tkSteps(r, zmax,det, subdetName, nr);
+        rpVect  = stpr.getNewRp();
+        System.out.println("BCF: 4-bField[2]="+bField[2]);
+        if(debug)System.out.println(subdetName+" !!!!!! rmin="+rmin);
+        // Get intersections with successive layers as long as track is
+        // within the detector, and create a list of the cells that
+        // the track passes through
+        nLayerStepped=0;
+        while ((Math.abs(rpVect[2]) <= zmax )&& (nr < nLayers))
+        {
+           Hep3Vector v = new BasicHep3Vector(rpVect[0],rpVect[1],rpVect[2]);
+           hitPos.add(v);
+           long virtualID = segm.findCellContainingXYZ( rpVect );
+           cellList.add(virtualID);
+           if(stpr.getStopTkELow()) break;
+
+           if(stpr.getCurlBack())
+  		 {
+  		    if(debug &&stpr.partR(rpVect)<r )
+  		    System.out.println("!!!BCF:CURLINGBACK old r="+r+" New r="+(r-dr));
+  		    if(stpr.partR(rpVect)<r) r=r-dr   ;
+  		  }
+  		  else if(nr!=(nLayers-1)) r = r + dr;
+  		  else
+  		  {
+  		    r = rmin + nLayers * dr;
+  		    if(debug)System.out.println("BCF: AT Exit of "+subdetName+", r="+r);
+           }
+           stpr.tkSteps(r, zmax,det, subdetName, nr);
+           rpVect = stpr.getNewRp();
+           // double dThk=(nr!=(nLayers-1))?dr:(dr+dr-(rLayer0Mid-rmin));
+
+           if(!stpr.getCurlBack())nr++;
+           nLayerStepped++;
+        }//End of : Go on to the next layer
+        // Save number of layers track passed through
+        numLayersHit = nr;
+        if(debug)System.out.println("Stepper pos EXIT of:("+subdetName+" "+rpVect[0]+"; "+rpVect[1]+"; "+rpVect[2]+"), r="+stpr.partR(rpVect));
+        rpVect= stpr.getNewRp();
+        if((rpVect[2]>=zmax)||stpr.getStopTkELow())
+        {// Record Last Layer and Info at Break
+           Hep3Vector v =new BasicHep3Vector(rpVect[0],rpVect[1],rpVect[2]);
+           hitPos.add(v);
+           long virtualID = segm.findCellContainingXYZ( rpVect );
+           cellList.add(virtualID);
+        }
+
+        double rr=stpr.partR(rpVect);
+        // Now match the cells on this list to calorimeter hits
+        if(subdetName.equals(hcalSubdetName))  //C.M.-27Jan03
+        {
+
+    	 if (debug) System.out.println("BCSF: Doing matchHits in HCal");
+           matchHitsFast(segm, dataMgr.getCollHitMap(hcalHitmapName) );
+
+        }
+        else if(subdetName.equals(ecalSubdetName)) //
+        {
+    	 if (debug) System.out.println("BCSF: Doing matchHits in ECal");
+           matchHitsFast(segm, dataMgr.getCollHitMap(ecalHitmapName) );
+        }
+
+        event.put(subdetName+"FoundHits",foundHits);
+     }
+
+     public void reset()
+     {
+        // Erase lists of hits and cells
+        hitList.removeAllElements();
+        cellList.removeAllElements();
+
+     }
+
+
+     public void setPhiNNCut(int cut)
+     {
+
+        // Set the number of nearest neighbors cut in phi. Cells
+        // with abs(phi_track - phi_cell) <=  cut will be added
+        // to the list
+
+        phiNNCut = cut;
+     }
+
+     public void setThetaNNCut(int cut)
+     {
+
+        // Set the number of nearest neighbors cut in theta. Cells
+        // with abs(theta_track - theta_cell) <=  cut will be added
+        // to the list
+
+        thetaNNCut = cut;
+     }
+
+     public double[] getNNCuts()
+     {
+        // Return the number of nearest neighbors cuts in phi and theta
+
+        return(new double[]
+        {phiNNCut, thetaNNCut});
+     }
+
+     public int getNLayersHit()
+     {
+        // Return the number of layers the track passed through
+
+        return(numLayersHit);
+     }
+
+
+  //     public int xyzToPhiBin(double[] r)
+  //     {
+  //         // Determine phi bin corresponding to this Cartesian coordinate
+
+  //         double phi;
+  //         int bin;
+  //         nc++;
+  // 	double r1=r[1]/10; double r0=r[0]/10;
+  //         phi = Math.atan2(r1, r0);
+  //         if (phi < 0.) phi = phi + 2*Math.PI;
+  //         bin = (int)(phi/phiBinSize);
+  //         return(bin);
+  //     }
+
+  //     public int xyzToThetaBin(double[] r)
+  //     {
+  //         // Determine theta bin corresponding to this Cartesian coordinate
+  //         double rho, theta;
+  //         int bin;
+  //         double r1=r[1]/10; double r0=r[0]/10; double r2=r[2]/10;
+  //         rho = Math.sqrt(r0*r0 + r1*r1);
+  //         theta = Math.atan2(rho, r2);
+  //         if (theta < 0.) theta = theta + Math.PI;
+  //         bin = (int)(theta/thetaBinSize);
+  //         return(bin);
+  //     }
+
+
+     // The following two methods implement the CalorimeterHits interface
+
+     public Enumeration getHits()
+     {
+        return(hitList.elements());
+     }
+     public Enumeration getHitsPos()
+     {
+        return(hitPos.elements());
+     }
+
+     public int getNHits()
+     {
+        return(hitList.size());
+     }
+     public int getNHitsPos()
+     {
+        return(hitPos.size());
+     }
+
+     protected void matchHitsFast(SegmentationBase cell,
+             Map<Long,CalorimeterHit> calHits)
+     {
+        this.matchHitsFast(cell, calHits, false);
+     }
+
+     protected void matchHitsFast(SegmentationBase cell,
+             Map<Long,CalorimeterHit> calHits,
+             boolean debug)
+     {
+        if(debug)System.out.println("Segm:::: "  + cell);
+        AIDA aida = AIDA.defaultInstance();
+        int nhitsTotal = 0;
+  //       ProjectiveCylinder projCal = (ProjectiveCylinder)segm;
+        if(debug) System.out.println("matchhits: nhits = "+calHits.size());
+        for( Long cellid : cellList )
+        {
+  // 	if(segm instanceof ProjectiveCylinder) {
+           // check cell itself
+
+           CalorimeterHit hit = calHits.get(cellid);
+           segm.setID(cellid);
+           int ilay = segm.getLayer();
+           if(hit!=null)
+           {
+              // found real hit at virtual cell
+              if(debug) System.out.println("matchHits: Adding hit: "+Long.toHexString(cellid));
+              if(debug)
+              {
+                 double dall=0.;
+                 for(int j=0;j<nLayers;j=j+4)
+                 {
+                    if(ilay==j)
+                    {
+                       aida.cloud1D(subdetName+" dphi layer "+ilay).fill(dall);
+                       aida.cloud1D(subdetName+" dtheta layer "+ilay).fill(dall);
+                    }
+                 }
+              }
+              foundHits.add(new BasicHep3Vector(segm.getX(),segm.getY(),segm.getZ()));
+              hitList.add(hit);
+              nhitsTotal++;
+           }
+           // now check for the neighbors
+           segm.setID(cellid);
+           int iphi = segm.getValue("phi");
+           int ithe = -99999;
+           try
+           {
+              //ithe = segm.getValue("theta");
+              ithe = segm.getValue("z");
+           }
+           catch(IllegalArgumentException x)
+           {
+              ithe = segm.getValue("z");
+           }
+           ilay = segm.getLayer();
+           long[] neighs = segm.getNeighbourIDs(0, thetaNNCut, phiNNCut );
+  // 	     System.out.println("VirtualID="+MyTools.printID(cellid)
+  // 			     +", #neighbors="+neighs.length+" "+thetaNNCut+" "+phiNNCut);
+           for(int i=0; i<neighs.length; ++i)
+           {
+              hit = calHits.get(neighs[i]);
+
+  //  	    if(debug) System.out.println("neighb: cellid="+MyTools.printID(neighs[i])+", hit="+hit);
+              if(hit!=null)
+              {
+                 if(debug) System.out.println("matchHits: Adding hit: "+Long.toHexString(neighs[i]));
+                 segm.setID( neighs[i] );
+                 int jphi = segm.getValue("phi");
+                 int jthe = 0;
+                 try
+                 {
+                    //jthe = segm.getValue("theta");
+                     jthe = segm.getValue("z");
+                 }
+                 catch(IllegalArgumentException x)
+                 {
+                    jthe = segm.getValue("z");
+                 }
+
+                 int jlay = segm.getLayer();
+                 if(debug)
+                 {
+                    for(int j=0;j<nLayers;j=j+4)
+                    {
+                       if(ilay==j)
+                       {
+                          aida.cloud1D(subdetName+" dphi layer "+ilay).fill(jphi-iphi);
+                          aida.cloud1D(subdetName+" dtheta layer "+ilay).fill(jthe-ithe);
+                       }
+                    }
+                 }
+                 foundHits.add(new BasicHep3Vector(segm.getX(),segm.getY(),segm.getZ()));
+                 hitList.add(hit);
+                 nhitsTotal++;
+              }
+           }
+        }
+  //  	}
+        if(debug) System.out.println("Total # hits: virtual="+cellList.size()
+        +", real="+nhitsTotal);
+     }
+     protected Detector det;
+     protected CylindricalBarrelCalorimeter calsub;
+     protected SegmentationBase segm;
+     protected IDEncoder encoder;
+     protected CalHitMapMgr dataMgr;
+     protected String ecalHitmapName = "EcalBarrHits";
+     protected String hcalHitmapName = "HcalBarrHits";
+     protected String ecalSubdetName = "EMBarrel";
+     protected String hcalSubdetName = "HADBarrel";
+     protected String muSubdetName = "MuonBarrel";
+     protected boolean debug = true;
+     protected int nc=0;
+     protected DeDx dedx;
+     protected double []rpVect       = new double[8] ;         // C.M.-4-Vector
+     protected String subdetName;      // C.M.-Jan03
+     protected double rmin;
+     protected double rLayer0Mid, totalthickness;
+     protected double rmax;
+     protected double zmax;
+     protected int nLayers;
+     protected int nPhi;
+     protected int nTheta;
+     protected double phiBinSize;
+     protected double thetaBinSize;
+     protected int numLayersHit;
+     protected Vector<Long> cellList = new Vector<Long>(); // list of cell indices
+     protected TrackStepper stpr     = new TrackStepper(); //C.M.-Stepper Instance
+     protected double [] stepConditions = new double[4];
+     protected Map<String, Double> materials;
+    // public static Samplexmlclass xmlReader = new Samplexmlclass();
+     private int phiNNCut;
+     private int thetaNNCut;
+     private List<Hep3Vector> foundHits = new ArrayList<Hep3Vector>();
+     protected FieldOverlay Field = new FieldOverlay();
 }
CVSspam 0.2.8