lcsim/src/org/lcsim/digisim
diff -u -r1.4 -r1.5
--- CellSelector.java 27 Jun 2005 21:45:32 -0000 1.4
+++ CellSelector.java 28 Jun 2005 21:55:35 -0000 1.5
@@ -21,7 +21,7 @@
* any cell in a given subdetector.
*
* @author Guilherme Lima
- * @version $Id: CellSelector.java,v 1.4 2005/06/27 21:45:32 lima Exp $
+ * @version $Id: CellSelector.java,v 1.5 2005/06/28 21:55:35 lima Exp $
*/
public class CellSelector
{
@@ -39,12 +39,11 @@
_segm = (SegmentationImpl)_calsub.getReadout().getSegmentation();
try {
-// IDDescriptor desc = new IDDescriptor(description);
- IDDescriptor desc = _calsub.getReadout().getIDDescriptor();
- _encoder = new IDEncoder(desc);
+ IDDescriptor desc = _calsub.getReadout().getIDDescriptor();
+ _encoder = new IDEncoder(desc);
}
catch(Exception e) {
- System.out.println("Some exception caught! "+e);
+ System.out.println("Some exception caught! "+e);
}
if( _calsub instanceof CylindricalCalorimeter ) {
@@ -57,59 +56,28 @@
}
_nlayers = cal.getLayerCount();
- double zmin = cal.getZMin();
- double zmax = cal.getZMax();
+ _maxTransvBins = new int[_nlayers];
+ _maxLongitBins = new int[_nlayers];
+ _minLongitBins = new int[_nlayers];
if( _segm instanceof ProjectiveCylinder ) {
// Here for projective cylinder
- if(_debug) {
- System.out.println("_segm is a ProjectiveCylinder");
- }
- ProjectiveCylinder proj = (ProjectiveCylinder)_segm;
- int nphi = proj.getPhiBins();
- int ntheta = proj.getThetaBins();
-
- _maxPhiBins = new int[_nlayers];
- _maxThetaBins = new int[_nlayers];
- _minThetaBins = new int[_nlayers];
- _numCells = 0;
- for(int i=0; i<_nlayers; ++i) {
- double thetamin = Math.PI/2 + Math.atan2(zmin, cal.getDistanceToLayerSensorMid(i));
- double thetamax = Math.PI/2 + Math.atan2(zmax, cal.getDistanceToLayerSensorMid(i));
- _minThetaBins[i] = (int)(ntheta*thetamin/Math.PI);
- _maxThetaBins[i] = (int)(ntheta*thetamax/Math.PI);
- _maxPhiBins[i] = nphi;
- _numCells += nphi * (_maxThetaBins[i]-_minThetaBins[i]+1);
-// System.out.println("for i="+i+", itheta in range: ["
-// +_minThetaBins[i]+" to "+_maxThetaBins[i]+"]");
- }
- } // if(_segm instanceof ProjectiveCylinder)
+ if(_debug) System.out.println("_segm is a ProjectiveCylinder");
+ useProjectiveCylinder(cal);
+ }
- if( _segm instanceof NonprojectiveCylinder ) {
+ else if( _segm instanceof NonprojectiveCylinder ) {
// Here for nonprojective cylinder
- System.out.println("_segm is a NonprojectiveCylinder");
-// NonprojectiveCylinder nonproj = (NonprojectiveCylinder)_segm;
-// double delphi = nonproj.getGridSizePhi();
-// double delz = nonproj.getGridSizeZ();
-
-// _maxPhiBins = new int[_nlayers];
-// _maxThetaBins = new int[_nlayers];
-// _minThetaBins = new int[_nlayers];
-// for(int i=0; i<_nlayers; ++i) {
-// double thetamin = Math.PI/2 + Math.atan2(zmin, cal.getRadiusForLayer(i));
-// double thetamax = Math.PI/2 + Math.atan2(zmax, cal.getRadiusForLayer(i));
-// _minThetaBins[i] = ???(int)(ntheta*thetamin/Math.PI);
-// _maxThetaBins[i] = ???(int)(ntheta*thetamax/Math.PI);
-// _maxPhiBins[i] = ???(int)(ntheta*thetamax/Math.PI);
-// // System.out.println("for i="+i+", itheta in range: ["
-// // +_minThetaBins[i]+" to "+_maxThetaBins[i]+"]");
-// }
- } // if(_segm instanceof NonprojectiveCylinder)
+ System.out.println("_segm is a NonprojectiveCylinder");
+ useNonprojectiveCylinder(cal);
+ }
- } // if(_calsub instanceof CylindricalCalorimeter)
+ System.out.println(cal.getName()+": Total # cells: "+_numCells);
+ } // endif(_calsub instanceof CylindricalCalorimeter)
// else if( _calsub instanceof CylindricalEndcapCalorimeter ) {
// System.out.println("CylindricalEndcapCalorimeter");
// }
+
}
public void setSystemBarrel(final int system, final int barend) {
@@ -127,9 +95,9 @@
if( _segm instanceof ProjectiveCylinder ) {
// This for cylindrical projective calorimeters
int ilayer = (int)(_nlayers * _random.nextDouble());
- int iphi = (int)(_maxPhiBins[ilayer] * _random.nextDouble());
- int nThetaInLayer = _maxThetaBins[ilayer]-_minThetaBins[ilayer]+1;
- int ithe = (int)(nThetaInLayer*_random.nextDouble() + _minThetaBins[ilayer]);
+ int iphi = (int)(_maxTransvBins[ilayer] * _random.nextDouble());
+ int nThetaInLayer = _maxLongitBins[ilayer]-_minLongitBins[ilayer]+1;
+ int ithe = (int)(nThetaInLayer*_random.nextDouble() + _minLongitBins[ilayer]);
// System.out.println("ilay="+ilayer+", ithe="+ithe+", iphi="+iphi);
_encoder.setValue("layer",ilayer);
@@ -137,21 +105,22 @@
_encoder.setValue("phi",iphi);
}
else {
- // This for cylindrical projective calorimeters
-// int ilayer = (int)(_nlayers * _random.nextDouble());
-// int nThetaInLayer = _maxThetaBins[ilayer]-_minThetaBins[ilayer]+1;
-// int ithe = (int)(nThetaInLayer*_random.nextDouble() + _minThetaBins[ilayer]);
-// int nPhiInLayer = _maxPhiBins[ilayer];
-// int iphi = (int)(nPhiInLayer*_random.nextDouble());
-// // System.out.println("ilay="+ilayer+", ithe="+ithe+", iphi="+iphi);
-
-// _encoder.setValue("layer",ilayer);
-// _encoder.setValue("theta",ithe);
-// _encoder.setValue("phi",iphi);
+ // This for cylindrical nonprojective calorimeters
+ int ilayer = (int)(_nlayers * _random.nextDouble());
+ int nZInLayer = _maxLongitBins[ilayer]-_minLongitBins[ilayer] + 1;
+ int iz = (int)(nZInLayer*_random.nextDouble())
+ + _minLongitBins[ilayer];
+ int nPhiInLayer = _maxTransvBins[ilayer]+1;
+ int iphi = (int)(nPhiInLayer*_random.nextDouble());
+// System.out.println("ilay="+ilayer+", ithe="+ithe+", iphi="+iphi);
+
+ _encoder.setValue("layer",ilayer);
+ _encoder.setValue("z",iz);
+ _encoder.setValue("phi",iphi);
}
}
else {
- System.out.println("*** calsub is not cylindrical");
+ System.out.println("*** CellSelector: calsub is not cylindrical");
}
// List<SimCalorimeterHit> data = _evt.get(SimCalorimeterHit.class,
@@ -184,6 +153,56 @@
return _numCells;
}
+ /** Initialize fields from a ProjectiveCylinder */
+ private void useProjectiveCylinder(CylindricalCalorimeter cal) {
+ ProjectiveCylinder proj = (ProjectiveCylinder)_segm;
+ int nphi = proj.getPhiBins();
+ int ntheta = proj.getThetaBins();
+ double zmin = cal.getZMin();
+ double zmax = cal.getZMax();
+
+ _numCells = 0;
+ for(int i=0; i<_nlayers; ++i) {
+ double radius = cal.getDistanceToLayerSensorMid(i);
+ double thetamin = Math.atan( radius/zmax );
+ double thetamax = Math.atan( radius/zmin ) + Math.PI;
+
+ _minLongitBins[i] = (int)Math.floor(ntheta*thetamin/Math.PI);
+ _maxLongitBins[i] = (int)Math.floor(ntheta*thetamax/Math.PI)+1;
+ _maxTransvBins[i] = nphi-1;
+ _numCells += nphi * (_maxLongitBins[i]-_minLongitBins[i]+1);
+// System.out.println("for i="+i+", itheta in range: ["
+// +_minLongitBins[i]+" to "+_maxLongitBins[i]+"]");
+ }
+ }
+
+ /** Initialize fields from a ProjectiveCylinder */
+ private void useNonprojectiveCylinder(CylindricalCalorimeter cal) {
+ NonprojectiveCylinder nonproj = (NonprojectiveCylinder)_segm;
+ double delz = nonproj.getGridSizeZ();
+ double zmin = cal.getZMin();
+ double zmax = cal.getZMax();
+ int numz = (int)Math.floor((zmax-zmin)/delz);
+ System.out.println("In z: "+zmin+" "+zmax+" "+delz+" "+numz);
+
+ for(int i=0; i<_nlayers; ++i) {
+ // assume indices run from 0
+ _minLongitBins[i] = 0;
+ _maxLongitBins[i] = numz-1;
+
+ double radius = cal.getDistanceToLayerSensorMid(i);
+ double delphi = nonproj.computeDeltaPhiForLayer(i);
+ _maxTransvBins[i] = (int)Math.floor(2*Math.PI / delphi) - 1;
+ int numphi = _maxTransvBins[i]+1;
+
+ _numCells += numphi * numz;
+// System.out.println("for i="+i+", iz in ["
+// +_minLongitBins[i]+" to "+_maxLongitBins[i]+"]"
+// +", iphi in [0 to "+_maxTransvBins[i]+"], add "
+// +(numphi*numz)+" cells-> "+_numCells);
+ }
+ }
+
//=== FIELDS ===
/** debugging flag */
@@ -207,11 +226,11 @@
private int _nlayers;
/** Max phiBins per layer */
- private int[] _maxPhiBins;
+ private int[] _maxTransvBins;
/** Min thetaBins per layer */
- private int[] _minThetaBins;
+ private int[] _minLongitBins;
/** Max thetaBins per layer */
- private int[] _maxThetaBins;
+ private int[] _maxLongitBins;
/** Total number of cells */
private int _numCells;