Print

Print


Commit in java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal on MAIN
FADCEcalReadoutDriver.java+73-10862 -> 863
FADCTriggerDriver.java+1-1862 -> 863
SimpleEcalReadoutDriver.java+11-31862 -> 863
TimeEvolutionEcalReadoutDriver.java+6-28862 -> 863
+91-70
4 modified files
New verified version, a bit more user friendly

java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
FADCEcalReadoutDriver.java 862 -> 863
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-08-14 23:35:36 UTC (rev 862)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-08-18 08:04:57 UTC (rev 863)
@@ -15,9 +15,18 @@
 import java.util.PriorityQueue;
 import java.util.Set;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalChannel.GeometryId;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
 import org.hps.recon.ecal.ECalUtils;
-import org.hps.recon.ecal.HPSCalorimeterHit;
 import org.hps.recon.ecal.HPSRawCalorimeterHit;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
@@ -46,6 +55,9 @@
     private static final int ECAL_PULSE_INTEGRAL_MODE = 3;
     String ecalName = "Ecal";
     Subdetector ecal;
+    EcalConditions ecalConditions = null;
+    IIdentifierHelper helper = null;
+    EcalChannelCollection channels = null; 
     //buffer for preamp signals (units of volts, no pedestal)
     private Map<Long, RingBuffer> signalMap = null;
     //ADC pipeline for readout (units of ADC counts)
@@ -230,9 +242,12 @@
 
             FADCPipeline pipeline = pipelineMap.get(cellID);
             pipeline.step();
+            
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
 
             double currentValue = signalBuffer.currentValue() * ((Math.pow(2, nBit) - 1) / maxVolt); //12-bit ADC with maxVolt V range
-            int pedestal = (int) Math.round(EcalConditions.physicalToPedestal(cellID));
+            int pedestal = (int) Math.round(channelData.getCalibration().getPedestal());
             int digitizedValue = Math.min((int) Math.round(pedestal + currentValue), (int) Math.pow(2, nBit)); //ADC can't return a value larger than 4095; 4096 (overflow) is returned for any input >2V
             pipeline.writeValue(digitizedValue);
             int pedestalSubtractedValue = digitizedValue - pedestal;
@@ -375,6 +390,10 @@
             int pointerOffset = 0;
             int numSamplesToRead = 0;
             int thresholdCrossing = 0;
+            
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
+            
             for (int i = 0; i < readoutWindow; i++) {
                 if (numSamplesToRead != 0) {
                     adcValues[adcValues.length - numSamplesToRead] = window[i - pointerOffset];
@@ -382,7 +401,7 @@
                     if (numSamplesToRead == 0) {
                         hits.add(new BaseRawTrackerHit(cellID, thresholdCrossing, adcValues));
                     }
-                } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
+                } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
                     thresholdCrossing = i;
                     pointerOffset = Math.min(numSamplesBefore, i);
                     numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -402,6 +421,10 @@
             int pointerOffset = 0;
             int numSamplesToRead = 0;
             int thresholdCrossing = 0;
+            
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
+            
             if (window != null) {
                 for (int i = 0; i < readoutWindow; i++) {
                     if (numSamplesToRead != 0) {
@@ -413,7 +436,7 @@
                         if (numSamplesToRead == 0) {
                             hits.add(new BaseRawCalorimeterHit(cellID, adcSum, 64 * thresholdCrossing));
                         }
-                    } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
+                    } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
                         thresholdCrossing = i;
                         pointerOffset = Math.min(numSamplesBefore, i);
                         numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -431,13 +454,15 @@
         for (CalorimeterHit hit : hits) {
             RingBuffer eDepBuffer = signalMap.get(hit.getCellID());
             double energyAmplitude = hit.getRawEnergy();
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(hit.getCellID());
             if (addNoise) {
                 //add preamp noise and photoelectron Poisson noise in quadrature
                 double noise;
                 if (use2014Gain) {
-                    noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
+                    noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
                 } else {
-                    noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
+                    noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
                 }
                 energyAmplitude += RandomGaussian.getGaussian(0, noise);
             }
@@ -460,6 +485,17 @@
     public void detectorChanged(Detector detector) {
         // Get the Subdetector.
         ecal = detector.getSubdetector(ecalName);
+        
+        // ECAL combined conditions object.
+        ecalConditions = ConditionsManager.defaultInstance()
+                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+        
+        // List of channels.
+        channels = ecalConditions.getChannelCollection();
+        
+        // ID helper.
+        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+        
         resetFADCBuffers();
     }
 
@@ -471,20 +507,25 @@
         pipelineMap = new HashMap<Long, FADCPipeline>();
         Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
         for (Long cellID : cells) {
+        	EcalChannelConstants channelData = findChannel(cellID);
             signalMap.put(cellID, new RingBuffer(bufferLength));
-            pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(EcalConditions.physicalToPedestal(cellID))));
+            pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(channelData.getCalibration().getPedestal())));
         }
         return true;
     }
 
     private double pulseAmplitude(double time, long cellID) {
+    	
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(cellID);
+    	
         if (use2014Gain) {
             //if fixedGain is set, multiply the default gain by this factor
             double corrGain;
             if (fixedGain > 0) {
                 corrGain = fixedGain;
             } else {
-                corrGain = 1.0 / EcalConditions.physicalToGain(cellID);
+                corrGain = 1.0 / channelData.getGain().getGain();
             }
 
             return corrGain * readoutGain * pulseAmplitude(time, pulseShape, tp);
@@ -494,7 +535,7 @@
             if (fixedGain > 0) {
                 gain = readoutPeriod / (fixedGain * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
             } else {
-                gain = readoutPeriod / (EcalConditions.physicalToGain(cellID) * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
+                gain = readoutPeriod / (channelData.getGain().getGain() * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
             }
 
             return gain * pulseAmplitude(time, pulseShape, tp);
@@ -585,4 +626,26 @@
             return array[((ptr - pos) % size + size) % size];
         }
     }
+    
+    /** 
+     * Convert physical ID to gain value.
+     * @param cellID (long)
+     * @return channel constants (EcalChannelConstants)
+     */
+    private EcalChannelConstants findChannel(long cellID) {
+        // Make an ID object from raw hit ID.
+        IIdentifier id = new Identifier(cellID);
+        
+        // Get physical field values.
+        int system = helper.getValue(id, "system");
+        int x = helper.getValue(id, "ix");
+        int y = helper.getValue(id, "iy");
+        
+        // Create an ID to search for in channel collection.
+        GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
+                
+        // Get the channel data.
+        return ecalConditions.getChannelConstants(channels.findChannel(geometryId));    
+    }
+    
 }

java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
FADCTriggerDriver.java 862 -> 863
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCTriggerDriver.java	2014-08-14 23:35:36 UTC (rev 862)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCTriggerDriver.java	2014-08-18 08:04:57 UTC (rev 863)
@@ -121,7 +121,7 @@
         } else if (detector.getName().contains("6pt6")) {
             return 6.6;
         } else {
-            return 2.2;
+            return -1.0;
         }
     }
 

java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
SimpleEcalReadoutDriver.java 862 -> 863
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java	2014-08-14 23:35:36 UTC (rev 862)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java	2014-08-18 08:04:57 UTC (rev 863)
@@ -4,12 +4,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.hps.conditions.TableConstants;
-import org.hps.conditions.ecal.EcalConditions;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
 import org.hps.recon.ecal.HPSCalorimeterHit;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.geometry.Detector;
 
@@ -24,36 +19,20 @@
     //buffer for deposited energy
     Map<Long, Double> eDepMap = null;
     
-    HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+    Detector detector = null;
     
-    Detector detector = null;    
-    static EcalConditions ecalConditions = null;
-    static IIdentifierHelper helper = null;
-    static EcalChannelCollection channels = null; 
-    
-    @Override
-    public void detectorChanged(Detector detector) {
-    	
-    	h1.setDetector(detector);
-    	
-        // ECAL combined conditions object.
-        ecalConditions = ConditionsManager.defaultInstance()
-                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
-        
-        // List of channels.
-        channels = ecalConditions.getChannelCollection();
-        
-        // ID helper.
-        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
-        
-        System.out.println("You are now using the database conditions for SimpleEcalReadoutDriver.");
-    }
-    
+    HPSCalorimeterHit h = null;
+
 	public SimpleEcalReadoutDriver() {
 		hitClass = HPSCalorimeterHit.class;
 	}
 
     @Override
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
+    }
+	
+    @Override
     protected void readHits(List<HPSCalorimeterHit> hits) {
         for (Long cellID : eDepMap.keySet()) {
 //            int ix = dec.getValue("ix");
@@ -63,8 +42,9 @@
 //            if (iy == 1 && ix*side >= -10 && ix*side <= -2)
 //                continue;
             if (eDepMap.get(cellID) > threshold)
-            	h1.setParameters(eDepMap.get(cellID), readoutTime(), cellID, hitType);
-                hits.add(h1);
+            	h = new HPSCalorimeterHit(eDepMap.get(cellID), readoutTime(), cellID, hitType); 
+                h.setDetector(detector);
+                hits.add(h);
         }
         //reset hit integration
         eDepMap = new HashMap<Long, Double>();

java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
TimeEvolutionEcalReadoutDriver.java 862 -> 863
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java	2014-08-14 23:35:36 UTC (rev 862)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java	2014-08-18 08:04:57 UTC (rev 863)
@@ -4,12 +4,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.hps.conditions.TableConstants;
-import org.hps.conditions.ecal.EcalConditions;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
 import org.hps.recon.ecal.HPSCalorimeterHit;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.geometry.Detector;
 
@@ -21,6 +16,8 @@
  * @version $Id: TimeEvolutionEcalReadoutDriver.java,v 1.1 2013/02/25 22:39:26 meeg Exp $
  */
 public class TimeEvolutionEcalReadoutDriver extends EcalReadoutDriver<HPSCalorimeterHit> {
+
+	Detector detector = null;
 	
     //buffer for deposited energy
     Map<Long, RingBuffer> eDepMap = null;
@@ -29,29 +26,9 @@
     //shaper time constant in ns; negative values generate square pulses of the given width
     double t0 = 18.0;
     
-    HPSCalorimeterHit h1 = new HPSCalorimeterHit();
-    
-    Detector detector = null;    
-    static EcalConditions ecalConditions = null;
-    static IIdentifierHelper helper = null;
-    static EcalChannelCollection channels = null; 
-    
     @Override
     public void detectorChanged(Detector detector) {
-    	
-    	h1.setDetector(detector);
-    	
-        // ECAL combined conditions object.
-        ecalConditions = ConditionsManager.defaultInstance()
-                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
-        
-        // List of channels.
-        channels = ecalConditions.getChannelCollection();
-        
-        // ID helper.
-        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
-        
-        System.out.println("You are now using the database conditions for TimeEvolutionEcalReadoutDriver.");
+    	this.detector = detector;
     }
 
     public TimeEvolutionEcalReadoutDriver() {
@@ -76,8 +53,9 @@
 //                int iy = dec.getValue("iy");
 //                if (iy == 1 && ix == -2)
 //                    System.out.printf("Time %f, output signal %f\n", ClockSingleton.getTime(), eDepBuffer.currentValue());
-                h1.setParameters(eDepBuffer.currentValue(), readoutTime(), cellID, hitType);
-            	hits.add(h1);
+            	HPSCalorimeterHit h = new HPSCalorimeterHit(eDepBuffer.currentValue(), readoutTime(), cellID, hitType);
+            	h.setDetector(detector);
+            	hits.add(h);
             }
             eDepBuffer.step();
         }
SVNspam 0.1