lcsim/src/org/lcsim/recon/cluster/util
diff -N QNeutralHadronClusterEnergyCalculator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ QNeutralHadronClusterEnergyCalculator.java 26 Mar 2008 16:40:20 -0000 1.1
@@ -0,0 +1,125 @@
+/*
+ * QNeutralHadronClusterEnergyCalculator.java
+ *
+ */
+
+package org.lcsim.recon.cluster.util;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.conditions.*;
+
+/**
+ *
+ * @author cassell
+ */
+public class QNeutralHadronClusterEnergyCalculator implements ClusterEnergyCalculator
+{
+ private ConditionsManager _mgr;
+
+ /** Creates a new instance of GenericClusterEnergyCalculator */
+ double alpha;
+ String calibrationFilename = "nhQcal-v2r3p10";
+ double[] sf;
+ double[] Em;
+ double[] Ec;
+ int nFrontLayersEcal;
+ public QNeutralHadronClusterEnergyCalculator()
+ {
+ }
+ public QNeutralHadronClusterEnergyCalculator(String calFile)
+ {
+ calibrationFilename = calFile;
+ }
+ private void init()
+ {
+ _mgr = ConditionsManager.defaultInstance();
+ ConditionsSet cs = _mgr.getConditions("hadronCalibration/"+calibrationFilename);
+ sf = cs.getDoubleArray("SFs");
+ Em = cs.getDoubleArray("Emeas");
+ Ec = cs.getDoubleArray("Ecorr");
+ alpha = cs.getDouble("alpha");
+ nFrontLayersEcal = cs.getInt("nFrontLayersEcal");
+ }
+ public double getEnergy(Cluster c)
+ {
+ if (_mgr == null)
+ {
+ init();
+ }
+ double EmeasEst = 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 < nFrontLayersEcal)
+ {
+ index = 0;
+ EmeasEst += hit.getRawEnergy()/sf[index];
+ }
+ else
+ {
+ index = 1;
+ EmeasEst += hit.getRawEnergy()/sf[index];
+ }
+ }
+ else if(detector_index == 6)
+ {
+ int layer = idc.getValue("layer");
+ if(layer < nFrontLayersEcal)
+ {
+ index = 2;
+ EmeasEst += hit.getRawEnergy()/sf[index];
+ }
+ else
+ {
+ index = 3;
+ EmeasEst += hit.getRawEnergy()/sf[index];
+ }
+ }
+ else if(detector_index == 3)
+ {
+ double[] pos = hit.getPosition();
+ double R = Math.sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);
+ double ctheta = Math.abs(pos[2])/R;
+ double st = Math.sqrt(1.-ctheta*ctheta);
+ EmeasEst += 1./(1. + alpha*(1./st - 1.))/sf[4];
+ }
+ else if(detector_index == 7)
+ {
+ double[] pos = hit.getPosition();
+ double R = Math.sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);
+ double st = Math.abs(pos[2])/R;
+ EmeasEst += 1./(1. + alpha*(1./st - 1.))/sf[5];
+ }
+ }
+//
+// Now invert
+//
+ double Emeas = linext(EmeasEst);
+ return Emeas;
+ }
+ private double linext(double Emeas)
+ {
+ double E;
+ if(Emeas <= Em[0])E = Emeas*Ec[0]/Em[0];
+ else if(Emeas >= Em[Em.length-1])E = Emeas*Ec[Em.length-1]/Em[Em.length-1];
+ else
+ {
+ int ib = 0;
+ for(int j=1;j<Em.length;j++)
+ {
+ if(Emeas < Em[j])break;
+ ib++;
+ }
+ E = Ec[ib] + (Emeas - Em[ib])*(Ec[ib+1] - Ec[ib])/(Em[ib+1] - Em[ib]);
+ }
+ return E;
+ }
+
+}
lcsim/src/org/lcsim/recon/cluster/util
diff -N QPhotonClusterEnergyCalculator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ QPhotonClusterEnergyCalculator.java 26 Mar 2008 16:40:20 -0000 1.1
@@ -0,0 +1,122 @@
+/*
+ * QPhotonClusterEnergyCalculator.java
+ *
+ * Created on March 7, 2008, 5:47 AM
+ *
+ */
+
+package org.lcsim.recon.cluster.util;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.conditions.*;
+
+/**
+ * Use a quick calibration for photons
+ *
+ * @author cassell
+ */
+public class QPhotonClusterEnergyCalculator implements ClusterEnergyCalculator
+{
+ private ConditionsManager _mgr;
+
+ /** Creates a new instance of GenericClusterEnergyCalculator */
+ String calibrationFilename = "photonQcal-v2r3p10";
+ double[] sf;
+ double[] Em;
+ double[] Ec;
+ double alpha;
+ int nFrontLayersEcal;
+ public QPhotonClusterEnergyCalculator()
+ {
+ }
+ public QPhotonClusterEnergyCalculator(String calFile)
+ {
+ calibrationFilename = calFile;
+ }
+ private void init()
+ {
+ _mgr = ConditionsManager.defaultInstance();
+ ConditionsSet cs = _mgr.getConditions("photonCalibration/"+calibrationFilename);
+ sf = cs.getDoubleArray("SFs");
+ Em = cs.getDoubleArray("Emeas");
+ Ec = cs.getDoubleArray("Ecorr");
+ alpha = cs.getDouble("alpha");
+ nFrontLayersEcal = cs.getInt("nFrontLayersEcal");
+ }
+ public double getEnergy(Cluster c)
+ {
+ if (_mgr == null)
+ {
+ init();
+ }
+ double EmeasEst = 0.;
+ for(CalorimeterHit hit:c.getCalorimeterHits())
+ {
+ int index = -1;
+ IDDecoder idc = hit.getIDDecoder();
+ idc.setID(hit.getCellID());
+ int detector_index = idc.getValue("system");
+ double[] pos = hit.getPosition();
+ double R = Math.sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);
+ double ctheta = Math.abs(pos[2])/R;
+ double st = Math.sqrt(1.-ctheta*ctheta);
+ double cb = 1. + alpha*(1./st - 1.);
+ double ce = 1. + alpha*(1./ctheta - 1.);
+ double cc = cb;
+ if(detector_index == 2)
+ {
+ int layer = idc.getValue("layer");
+ if(layer < nFrontLayersEcal)
+ {
+ index = 0;
+ }
+ else
+ {
+ index = 1;
+ }
+ }
+ else if(detector_index == 6)
+ {
+ cc = ce;
+ int layer = idc.getValue("layer");
+ if(layer < nFrontLayersEcal)
+ {
+ index = 2;
+ }
+ else
+ {
+ index = 3;
+ }
+ }
+ if(index > -1)
+ {
+ EmeasEst += hit.getRawEnergy()/sf[index]/cc;
+ }
+ }
+//
+// Now invert
+//
+ double Emeas = linext(EmeasEst);
+ return Emeas;
+ }
+ private double linext(double Emeas)
+ {
+ double E;
+ if(Emeas <= Em[0])E = Emeas*Ec[0]/Em[0];
+ else if(Emeas >= Em[Em.length-1])E = Emeas*Ec[Em.length-1]/Em[Em.length-1];
+ else
+ {
+ int ib = 0;
+ for(int j=1;j<Em.length;j++)
+ {
+ if(Emeas < Em[j])break;
+ ib++;
+ }
+ E = Ec[ib] + (Emeas - Em[ib])*(Ec[ib+1] - Ec[ib])/(Em[ib+1] - Em[ib]);
+ }
+ return E;
+ }
+
+
+}