lcsim/src/org/lcsim/contrib/uiowa
diff -N MatPhotonClusterEnergyCalculator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MatPhotonClusterEnergyCalculator.java 19 Nov 2007 21:28:13 -0000 1.1
@@ -0,0 +1,115 @@
+package org.lcsim.contrib.uiowa;
+import java.util.*;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.conditions.*;
+import org.lcsim.recon.cluster.util.*;
+
+/** Modified version of Ron's PhotonClusterEnergyCalculator
+ * class. The main changes are that:
+ * 1) Some things that were private are now protected
+ * At some point these changes should be merged back into the main tree.
+ *
+ * @version $Id: MatPhotonClusterEnergyCalculator.java,v 1.1 2007/11/19 21:28:13 mcharles Exp $
+ */
+
+public class MatPhotonClusterEnergyCalculator implements ClusterEnergyCalculator
+{
+ protected ConditionsManager _mgr;
+ double[] gparms;
+ double[] hitEcut;
+ double[] hitTcut;
+ double norm;
+ double angcoef;
+ /** Creates a new instance of PhotonClusterEnergyCalculator */
+ public MatPhotonClusterEnergyCalculator()
+ {
+ }
+ protected void init() {
+ _mgr = ConditionsManager.defaultInstance();
+ ConditionsSet cs = _mgr.getConditions("photonCalibration/ZpoleInversion");
+ hitEcut = cs.getDoubleArray("hitEcut");
+ hitTcut = cs.getDoubleArray("hitTcut");
+ gparms = cs.getDoubleArray("parameters");
+ norm = cs.getDouble("normalization");
+ angcoef = cs.getDouble("angleCoef");
+ }
+ public double getEnergy(Cluster c)
+ {
+ if (_mgr == null) {
+ init();
+ }
+
+ double Energy = 0.;
+ double[] pos = c.getPosition();
+ double rsq = pos[0]*pos[0] + pos[1]*pos[1];
+ double zsq = pos[2]*pos[2];
+ double Rsq = rsq + zsq;
+ double ratio = Math.sqrt(rsq/Rsq);
+ if(ratio < .707)ratio = Math.sqrt(zsq/Rsq);
+ double factor = 1. + angcoef*(ratio - 1.);
+ double[] esums = {0.,0.,0.,0.,0.,0.};
+ int[] hitsums = {0,0,0,0,0,0};
+ for(CalorimeterHit hit:c.getCalorimeterHits())
+ {
+ int index = -1;
+ IDDecoder idc = hit.getIDDecoder();
+ idc.setID(hit.getCellID());
+ int detector_index = idc.getValue("system");
+ if(detector_index == 2)
+ {
+ int layer = idc.getValue("layer");
+ if(layer < 20)
+ {
+ index = 0;
+ }
+ else
+ {
+ index = 1;
+ }
+ }
+ else if(detector_index == 6)
+ {
+ int layer = idc.getValue("layer");
+ if(layer < 20)
+ {
+ index = 2;
+ }
+ else
+ {
+ index = 3;
+ }
+ }
+ else if(detector_index == 3)
+ {
+ index = 4;
+ }
+ else if(detector_index == 7)
+ {
+ index = 5;
+ }
+ if(index > -1)
+ {
+ if(hit.getTime() < hitTcut[index])
+ {
+ if(hit.getRawEnergy() > hitEcut[index])
+ {
+ hitsums[index]++;
+ esums[index] += hit.getRawEnergy();
+ }
+ }
+ }
+ }
+ for(int i=0;i<4;i++)
+ {
+ if(hitsums[i] > 0)Energy += gparms[2*i]*esums[i] + gparms[2*i+1];
+ }
+ for(int i=4;i<6;i++)
+ {
+ if(hitsums[i] > 0)Energy += gparms[2*i]*hitsums[i]/factor + gparms[2*i+1];
+ }
+ return Energy*norm;
+ }
+
+}