Commit in java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal on MAIN
FADCEcalReadoutDriver.java+30-71523 -> 524
Working version of FADCEcalReadoutDriver using the new conditions

java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal
FADCEcalReadoutDriver.java 523 -> 524
--- java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-04-29 00:52:58 UTC (rev 523)
+++ java/branches/ecal-readout-sim_HPSJAVA-93/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-04-29 11:22:34 UTC (rev 524)
@@ -15,12 +15,16 @@
 import java.util.PriorityQueue;
 import java.util.Set;
 
+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.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.HPSRawCalorimeterHit;
 import org.lcsim.event.CalorimeterHit;
@@ -34,13 +38,7 @@
 import org.lcsim.geometry.subdetector.HPSEcal3;
 import org.hps.util.RandomGaussian;
 import org.lcsim.lcio.LCIOConstants;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.IIdentifierHelper;
-import org.lcsim.detector.identifier.Identifier;
 
-
-
-
 /**
  * Performs readout of ECal hits. Simulates time evolution of preamp output
  * pulse.
@@ -56,11 +54,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)
@@ -99,14 +95,9 @@
     //output collection name for hits read out from trigger
     private String ecalReadoutCollectionName = "EcalReadoutHits";
     private int mode = ECAL_PULSE_INTEGRAL_MODE;
-
     private int readoutThreshold = 10;
     private int triggerThreshold = 10;
-    //amplitude ADC counts/GeV
-//    private double gain = 0.5*1000 * 80.0 / 60;
-    private double scaleFactor = 128;
-
-
+    private double scaleFactor = 1;
     private double fixedGain = -1;
     private boolean constantTriggerWindow = true;
     private boolean addNoise = false;
@@ -241,33 +232,24 @@
     public Map<Long, FADCPipeline> getPipelineMap() {
         return pipelineMap;
     }
+
     @Override
     protected void readHits(List<RawCalorimeterHit> hits) {
 
         for (Long cellID : signalMap.keySet()) {
-        	
             RingBuffer signalBuffer = signalMap.get(cellID);
+
             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
- 
-            /*
-            double pedestal = channelData.getCalibration().getPedestal();
-            pipeline.writeValue(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
-*/
-
-// Pedestals will likely be expressed in number of fADC counts, so they should be int.
-            int pedestal = (int) channelData.getCalibration().getPedestal();
+            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
-
-// I think that it is easier to read the code when digitizedValue is present, is there any coding reason not to do so?
             pipeline.writeValue(digitizedValue);
             int pedestalSubtractedValue = digitizedValue - pedestal;
-            
             //System.out.println(signalBuffer.currentValue() + "   " + currentValue + "   " + pipeline.currentValue());
 
             Integer sum = sumMap.get(cellID);
@@ -402,15 +384,15 @@
 //		System.out.println("Reading FADC data");
         List<RawTrackerHit> hits = new ArrayList<RawTrackerHit>();
         for (Long cellID : pipelineMap.keySet()) {
-        
-            // Get the channel data.
-            EcalChannelConstants channelData = findChannel(cellID);
-            
             short[] window = getWindow(cellID);
             short[] adcValues = null;
             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];
@@ -433,15 +415,15 @@
 //		System.out.println("Reading FADC data");
         List<RawCalorimeterHit> hits = new ArrayList<RawCalorimeterHit>();
         for (Long cellID : pipelineMap.keySet()) {
-        	       
-            // Get the channel data.
-            EcalChannelConstants channelData = findChannel(cellID); 
-        	
             short[] window = getWindow(cellID);
             int adcSum = 0;
             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) {
@@ -472,18 +454,12 @@
             RingBuffer eDepBuffer = signalMap.get(hit.getCellID());
             double energyAmplitude = hit.getRawEnergy();
             // Get the channel data.
-            EcalChannelConstants channelData = findChannel(hit.getCellID()); 
-            
+            EcalChannelConstants channelData = findChannel(hit.getCellID());
             if (addNoise) {
                 //add preamp noise and photoelectron Poisson noise in quadrature
                 double noise;
-<<<<<<< .mine
-                if (!useCRRCShape) {
-                    noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
-=======
                 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));
->>>>>>> .r508
+                    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(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
                 }
@@ -507,14 +483,14 @@
     @Override
     public void detectorChanged(Detector detector) {
         // Get the Subdetector.
-        //ecal = detector.getSubdetector(ecalName);
+        ecal = detector.getSubdetector(ecalName);
         
         // ECAL combined conditions object.
         ecalConditions = ConditionsManager.defaultInstance()
                 .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
         
         // List of channels.
-        channels = ecalConditions.getChannelMap();
+        channels = ecalConditions.getChannelCollection();
         
         // ID helper.
         helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
@@ -530,7 +506,7 @@
         pipelineMap = new HashMap<Long, FADCPipeline>();
         Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
         for (Long cellID : cells) {
-            EcalChannelConstants channelData = findChannel(cellID);
+        	EcalChannelConstants channelData = findChannel(cellID);
             signalMap.put(cellID, new RingBuffer(bufferLength));
             pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(channelData.getCalibration().getPedestal())));
         }
@@ -538,24 +514,18 @@
     }
 
     private double pulseAmplitude(double time, long cellID) {
-<<<<<<< .mine
     	
-        // Get the channel data.
-        EcalChannelConstants channelData = findChannel(cellID); 
+    	EcalChannelConstants channelData = findChannel(cellID);
     	
-        if (useCRRCShape) {
-            if (time <= 0.0) {
-                return 0.0;
-=======
         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);
->>>>>>> .r508
+                corrGain = 1.0 / channelData.getGain().getGain();
             }
+
             return corrGain * readoutGain * pulseAmplitude(time, pulseShape, tp);
         } else {
             //normalization constant from cal gain (MeV/integral bit) to amplitude gain (amplitude bit/GeV)
@@ -570,15 +540,6 @@
         }
     }
 
-<<<<<<< .mine
-            //if fixedGain is set, multiply the default gain by this factor
-            double corrGain = 1.0;
-            if (fixedGain > 0) {
-                corrGain = fixedGain;
-            } else {
-                corrGain = 1.0 / channelData.getGain().getGain();
-            }
-=======
     /**
      * Returns pulse amplitude at the given time (relative to hit time).
      * Amplitude is normalized so the pulse integral is 1.
@@ -599,7 +560,6 @@
                 //According to measurements the output signal can be fitted by two gaussians, one for the rise of the signal, one for the fall
                 //peak at 3*riseTime
                 //peak value 1/norm
->>>>>>> .r508
 
                 double norm = ((riseTime + fallTime) / 2) * Math.sqrt(2 * Math.PI); //to ensure the total integral is equal to 1: = 33.8
                 return funcGaus(time - 3 * riseTime, (time < 3 * riseTime) ? riseTime : fallTime) / norm;
@@ -664,20 +624,19 @@
             return array[((ptr - pos) % size + size) % size];
         }
     }
-
+    
     // Convert physical ID to gain value.
     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();
-        geometryId.x = x;
-        geometryId.y = y;
+        GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
         
         // Find the ECAL channel.
 //        return channels.findChannel(geometryId);
@@ -685,6 +644,6 @@
         // Get the channel data.
         return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
     }
-
-
+    
 }
+
SVNspam 0.1