GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.20 -r1.21
--- NonprojectiveCylinder.java 3 Feb 2006 18:43:59 -0000 1.20
+++ NonprojectiveCylinder.java 9 Feb 2006 19:18:07 -0000 1.21
@@ -1,5 +1,7 @@
/*
- * NonprojectiveCylinder.java Created on March 30, 2005, 3:09 PM
+ * NonprojectiveCylinder.java
+ *
+ * Created on March 30, 2005, 3:09 PM
*/
package org.lcsim.geometry.segmentation;
@@ -18,8 +20,10 @@
import org.lcsim.geometry.util.IDEncoder;
/**
- * @author jeremym Nonprojective segmentation of a cylinder with delta z and phi
- * as parameters.
+ * @author jeremym
+ *
+ * Nonprojective segmentation of a cylinder with delta z and phi as parameters.
+ *
*/
public class NonprojectiveCylinder extends BarrelCylinderSegmentationBase
{
@@ -80,15 +84,11 @@
public double getX()
{
- // return detector.getLayering().getDistanceToLayerSensorMid( getLayer()
- // ) * cos( getPhi() );
- return getDistanceToSensitive(getLayer()) * cos(getPhi());
+ return getDistanceToSensitive( getLayer() ) * cos( getPhi() );
}
public double getY()
{
- // return detector.getLayering().getDistanceToLayerSensorMid( getLayer()
- // ) * sin( getPhi() );
return getDistanceToSensitive(getLayer()) * sin(getPhi());
}
@@ -99,9 +99,6 @@
public double computeDeltaPhiForLayer(int layer)
{
- // double circ =
- // detector.getLayering().getDistanceToLayerSensorMid(layer) * ( 2 * PI
- // );
double circ = getDistanceToSensitive(layer) * (2 * PI);
int nphi = (int) Math.floor(circ / gridSizePhi);
double deltaPhi = (2 * PI) / nphi;
@@ -129,21 +126,18 @@
* Find neighbouring cells to the current cell. Cell neighbors are found
* based on the direction (theta,phi) of the reference cell w.r.t the
* origin.
- *
+ *
* @see org.lcsim.geometry.segmentation.SegmentationBase#setID()
* @return array of cellIDs for the neighbouring cells
*/
public long[] getNeighbourIDs(int layerRange, int zRange, int phiRange)
{
- // System.out.println("Entering getNeighbourIDs: dl="+layerRange
- // +", dz="+zRange+", dphi="+phiRange+", id="+printID(decoder,encoder)
- // );
IDEncoder gnEncoder = new IDEncoder(descriptor);
BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
gnEncoder.setValues(values);
gnDecoder.setID(gnEncoder.getID());
- int nMax = (2 * layerRange + 1) * (2 * zRange + 1) * (2 * phiRange + 1) - 1;
+ int nMax = (2*layerRange + 1)*(2*zRange + 1)*(2*phiRange + 1) - 1;
long[] result = new long[nMax];
// theta and phi are used to find central neighbors in other layers
@@ -169,9 +163,8 @@
double y = cylR * Math.sin(phi);
double z = cylR / Math.tan(theta);
- long id = this.findCellContainingXYZ(x, y, z);
- if (id == 0)
- continue;
+ long id = this.findCellContainingXYZ(x,y,z);
+ if(id==0) continue;
// save indices in a new array, as values[] keeps the original ref
gnDecoder.setID(id);
@@ -186,24 +179,21 @@
for (int k = -phiRange; k <= phiRange; ++k)
{
// skip reference cell (not a neighbor of its own)
- if (i == 0 && j == 0 && k == 0)
- continue;
+ if (i==0 && j==0 && k==0) continue;
int iphi = gnDecoder.getValue(phiIndex) + k;
// phi is cyclic
- if (iphi < 0)
- iphi += phiBins;
- if (iphi >= phiBins)
- iphi -= phiBins;
+ if (iphi < 0) iphi += phiBins;
+ if (iphi >= phiBins) iphi -= phiBins;
- if (iphi < 0 || iphi >= phiBins)
- continue;
+ if (iphi < 0 || iphi >= phiBins) continue;
gnEncoder.setValue(phiIndex, iphi);
result[size++] = gnEncoder.getID();
}
}
}
+ // resize resulting array if necessary
if (size < result.length)
{
long[] temp = new long[size];
@@ -216,7 +206,7 @@
/**
* Return the cell which contains a given point (x,y,z), or zero.
- *
+ *
* @param x,y,z
* cartesian coordinates of the point
* @return ID of cell containing the point (maybe either in absorber or live
@@ -226,23 +216,18 @@
{
// validate point
- if (z < getZMin())
- return 0;
- if (z > getZMax())
- return 0;
+ if (z < getZMin()) return 0;
+ if (z > getZMax()) return 0;
double rho = Math.sqrt(x * x + y * y);
- if (rho < getRMin())
- return 0;
- if (rho > getRMax())
- return 0;
+ if (rho < getRMin()) return 0;
+ if (rho > getRMax()) return 0;
// ok, point is valid, so a valid ID should be returned
int ilay = getLayerBin(rho);
int iz = getZBin(z);
double phi = Math.atan2(y, x);
- if (phi < 0)
- phi += 2 * Math.PI;
+ if (phi < 0) phi += 2 * Math.PI;
int iphi = getPhiBin(ilay, phi);
IDEncoder enc = new IDEncoder(descriptor);
@@ -277,7 +262,7 @@
/**
* Returns cylindrical radius to center of sensitive slice of any layer
- *
+ *
* @param layer
* layer index
*/
@@ -292,45 +277,4 @@
return this.getRMin() + preLayers + layer.getThicknessToSensitiveMid();
}
-
- // private String printID(IDDecoder dec, IDEncoder enc) {
- // String ret = "decoder: <"+dec.getValue("layer")
- // +" "+dec.getValue("z")
- // +" "+dec.getValue("phi")+">";
- // ret += " --- encoder: "+printID(enc.getID());
- // return ret;
- // }
- //
- // public static String printID(long id) {
- // return new String("<"+Long.toHexString(id)
- // +": "+Integer.toString( getSysBE(id) )
- // +" "+Integer.toString( getLayer(id) )
- // +" "+Integer.toString( getThetaBin(id))
- // +" "+Integer.toString( getPhiBin(id) )
- // +">");
- // }
-
- // public static int getSysBE( long cellid ) {
- // return (int)((cellid>>16) & 0x3f);
- // }
- //
- // public static int getLayer( long cellid ) {
- // int layer = (int)((cellid>>0) & 0xffff);
- // return layer;
- // }
- //
- // public static int getThetaBin( long cellid ) {
- // int max = 1<<16; // for 11 bits
- // int thetabin = (int)((cellid>>48) & 0xffff);
- // if( thetabin > max/2-1 ) thetabin = thetabin - max;
- // return thetabin;
- // }
- //
- // public static int getPhiBin( long cellid ) {
- // // int max = 1<<11; // for 11 bits
- // // int phibin = (int)((cellid>>43) & 0x7ff);
- // // if( phibin > max/2-1 ) phibin = phibin - max;
- // // return phibin;
- // return (int)((cellid>>32) & 0xffff);
- // }
}
GeomConverter/src/org/lcsim/geometry/segmentation
diff -u -r1.22 -r1.23
--- ProjectiveCylinder.java 3 Feb 2006 18:43:59 -0000 1.22
+++ ProjectiveCylinder.java 9 Feb 2006 19:18:07 -0000 1.23
@@ -45,10 +45,10 @@
return getDistanceToSensitive(getLayer()) * Math.sin(getPhi());
}
- public double getZ()
- {
- double cosTheta = Math.cos(getTheta());
- return getDistanceToSensitive(getLayer()) * cosTheta / Math.sqrt(1 - cosTheta * cosTheta);
+ public double getZ()
+ {
+ double cosTheta = Math.cos(getTheta());
+ return getDistanceToSensitive(getLayer()) * cosTheta / Math.sqrt(1 - cosTheta * cosTheta);
}
public void setIDDescription(IDDescriptor id)
@@ -69,33 +69,30 @@
IDEncoder encoder = new IDEncoder(descriptor);
encoder.setValues(values);
- int nMax = (2 * deltaLayer + 1) * (2 * deltaTheta + 1) * (2 * deltaPhi + 1) - 1;
+ int nMax = (2*deltaLayer + 1)*(2*deltaTheta + 1)*(2*deltaPhi + 1) - 1;
int size = 0;
long[] result = new long[nMax];
for (int i = -deltaLayer; i <= deltaLayer; i++)
{
int l = values[layerIndex] + i;
- if (l < 0 || l >= getNumberOfLayers())
- continue;
- encoder.setValue(layerIndex, l);
+ if (l<0 || l>= getNumberOfLayers() ) continue;
+ encoder.setValue(layerIndex,l);
for (int j = -deltaTheta; j <= deltaTheta; j++)
{
int t = values[thetaIndex] + j;
- if (t < 0 || t >= thetaBins)
- continue;
- encoder.setValue(thetaIndex, t);
+ if (t<0 || t>=thetaBins) continue;
+ encoder.setValue(thetaIndex,t);
for (int k = -deltaPhi; k <= deltaPhi; k++)
{
- if (i == 0 && j == 0 && k == 0)
- continue;
+ if (i==0 && j==0 && k==0) continue;
int p = values[phiIndex] + k;
- if (p < 0 || p >= phiBins)
- continue;
+ if(p<0) p+=phiBins;
+ if(p>=phiBins) p-=phiBins;
result[size++] = encoder.setValue(phiIndex, p);
}
@@ -122,25 +119,21 @@
/**
* Return the cell which contains a given point (x,y,z), or zero.
- *
+ *
* @param x,y,z
* cartesian coordinates of the point
- * @return ID of cell containing the point (maybe either in absorber or live
- * material)
+ * @return ID of cell containing the point (maybe either in absorber
+ * or live material)
*/
public long findCellContainingXYZ(double x, double y, double z)
{
// validate point
- if (z < getZMin())
- return 0;
- if (z > getZMax())
- return 0;
- double rho = Math.sqrt(x * x + y * y);
- if (rho < getRMin())
- return 0;
- if (rho > getRMax())
- return 0;
+ if(z<getZMin()) return 0;
+ if(z>getZMax()) return 0;
+ double rho = Math.sqrt(x*x+y*y);
+ if(rho<getRMin()) return 0;
+ if(rho>getRMax()) return 0;
// ok, point is valid, so a valid ID should be returned
int ilay = getLayerBin(rho);