LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  August 2015

HPS-SVN August 2015

Subject:

r3384 - /java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalOnlineRawConverter.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Thu, 20 Aug 2015 20:48:47 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (222 lines)

Author: [log in to unmask]
Date: Thu Aug 20 13:48:45 2015
New Revision: 3384

Log:
Copied EcalRawConverter and kept only the parts used for FADC/SSP/trigger emulation and diagnostics and based on reading DAQConfig on the fly from EVIO.  This is now EcalOnlineRawConverter and only to be used for trigger diagnostics studies with real data.  Eventually all the bits that were put in EcalRawConverter for trigger diagnostics should be removed.

Added:
    java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalOnlineRawConverter.java

Added: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalOnlineRawConverter.java
 =============================================================================
--- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalOnlineRawConverter.java	(added)
+++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalOnlineRawConverter.java	Thu Aug 20 13:48:45 2015
@@ -0,0 +1,206 @@
+package org.hps.recon.ecal;
+
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+import org.hps.recon.ecal.daqconfig.ConfigurationManager;
+import org.hps.recon.ecal.daqconfig.FADCConfig;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.GenericObject;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.event.RawTrackerHit;
+
+/**
+ * 
+ * This is a EcalRawConverter used only for pure firmware emulation for
+ * studying trigger efficiency from real data.  It requires the DAQ
+ * configuration to be read from EVIO in order to set the parameters.
+ * 
+ */
+public class EcalOnlineRawConverter {
+
+    private FADCConfig config = null;
+    private static final int nsPerSample = 4;
+    private int nPeak = 3;
+    
+    public EcalOnlineRawConverter() {
+    	// Track changes in the DAQ configuration.
+    	ConfigurationManager.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				// Get the FADC configuration.
+				config = ConfigurationManager.getInstance().getFADCConfig();
+				// Get the number of peaks.
+				if(config.getMode() == 1) nPeak = Integer.MAX_VALUE;
+				else                      nPeak = config.getMaxPulses();
+				// Print the FADC configuration.
+				System.out.println();
+				System.out.println();
+				System.out.printf("NSA            :: %d ns%n", config.getNSA());
+				System.out.printf("NSB            :: %d ns%n", config.getNSB());
+				System.out.printf("Window Samples :: %d clock-cycles%n", config.getWindowWidth());
+				System.out.printf("Max Peaks      :: %d peaks%n", nPeak);
+				System.out.println("======================================================================");
+				System.out.println("=== FADC Pulse-Processing Settings ===================================");
+				System.out.println("======================================================================");
+				config.printConfig();
+			}
+    	});
+    }
+
+    /**
+     * Get pedestal for entire pulse integral.  Account for clipping if
+     * windowSamples is greater than zero.
+     */
+    public double getPulsePedestal(EventHeader event,long cellID,int windowSamples,int thresholdCrossing) {
+        int firstSample,lastSample;
+        if ( windowSamples>0 && (config.getNSA()+config.getNSB())/nsPerSample >= windowSamples ) {
+            // special case where firmware always integrates entire window
+            firstSample = 0;
+            lastSample = windowSamples-1;
+        } else {
+            firstSample = thresholdCrossing - config.getNSB()/nsPerSample;
+            lastSample  = thresholdCrossing + config.getNSA()/nsPerSample-1;
+            if (windowSamples > 0) {
+                // properly pedestal subtract pulses clipped by edge(s) of readout window:
+                if (firstSample < 0) firstSample=0;
+                if (lastSample >= windowSamples) lastSample=windowSamples-1;
+            }
+        }
+        return (lastSample-firstSample+1)*config.getPedestal(cellID);
+    }
+   
+    
+    /**
+     * Emulate the FADC250 firmware in conversion of Mode-1 waveform to a Mode-3/7 pulse,
+     * given a time for threshold crossing.
+     */
+    public double[] convertWaveformToPulse(RawTrackerHit hit,int thresholdCrossing,boolean mode7) {
+       
+        short samples[] = hit.getADCValues();
+        // choose integration range:
+        int firstSample,lastSample;
+        if ((config.getNSA()+config.getNSB())/nsPerSample >= samples.length) {
+            // firmware treats this case specially:
+            firstSample = 0;
+            lastSample = samples.length-1;
+        } else {
+            firstSample = thresholdCrossing - config.getNSB()/nsPerSample;
+            lastSample  = thresholdCrossing + config.getNSA()/nsPerSample - 1;
+        }
+        
+        // pulse integral:
+        double sumADC = 0;
+        for (int jj=firstSample; jj<=lastSample; jj++) {
+            if (jj<0) continue;
+            if (jj>=samples.length) break;
+            sumADC += samples[jj];
+        }
+
+        // pulse time with 4ns resolution:
+        double pulseTime=thresholdCrossing*nsPerSample;
+        return new double []{pulseTime,sumADC};
+    }
+   
+    
+    /**
+     *
+     */
+    public ArrayList <CalorimeterHit> HitDtoA(EventHeader event, RawTrackerHit hit) {
+        final long cellID = hit.getCellID();
+        final short samples[] = hit.getADCValues();
+        if(samples.length == 0) return null;
+        
+        // threshold is pedestal plus threshold configuration parameter:
+        final int absoluteThreshold;
+        int leadingEdgeThreshold = config.getThreshold(cellID);
+        absoluteThreshold = (int) (config.getPedestal(cellID) + leadingEdgeThreshold);
+        
+        ArrayList <Integer> thresholdCrossings = new ArrayList<Integer>();
+        
+        // special case, first sample is above threshold:
+        if (samples[0] > absoluteThreshold) {
+            thresholdCrossings.add(0);
+        } 
+        
+        // search for threshold crossings:
+        for(int ii = 1; ii < samples.length; ++ii) {
+            if ( samples[ii]   >  absoluteThreshold && 
+                 samples[ii-1] <= absoluteThreshold) {
+                
+                // found one:
+                thresholdCrossings.add(ii);
+
+                // search for next threshold crossing begins at end of this pulse:
+                if (ConfigurationManager.getInstance().getFADCConfig().getMode() == 1) {
+                    // special case, emulating SSP:
+                	ii += 8;
+                } else {
+                    // "normal" case, emulating FADC250:
+                	ii += config.getNSA()/nsPerSample - 1;
+                }
+
+                // firmware limit on # of peaks:
+                if (thresholdCrossings.size() >= nPeak) break;
+            }
+        }
+        
+        // make hits
+        ArrayList <CalorimeterHit> newHits = new ArrayList<CalorimeterHit>();
+        for(int thresholdCrossing : thresholdCrossings) {
+            // do pulse integral:
+            final double[] data = convertWaveformToPulse(hit, thresholdCrossing, false);
+            double time = data[0];
+            double sum = data[1];
+            
+            // do pedestal subtraction:
+            sum -= getPulsePedestal(event, cellID, samples.length, thresholdCrossing);
+          
+            // do gain scaling:
+            double energy = adcToEnergy(sum, cellID);
+            
+            newHits.add(CalorimeterHitUtilities.create(energy,time,cellID));
+        }
+        
+        return newHits;
+    }
+
+    /**
+     * This HitDtoA is for Mode-3 data.
+     */
+    public CalorimeterHit HitDtoA(EventHeader event,RawCalorimeterHit hit, double timeOffset) {
+        if (hit.getTimeStamp() % 64 != 0) {
+            System.out.println("unexpected timestamp " + hit.getTimeStamp());
+        }
+        double time = hit.getTimeStamp() / 16.0;
+        long id = hit.getCellID();
+        double pedestal = getPulsePedestal(event,id,config.getWindowWidth(),(int)time/nsPerSample);
+        double adcSum = hit.getAmplitude() - pedestal;
+        double rawEnergy = adcToEnergy(adcSum, id);
+        return CalorimeterHitUtilities.create(rawEnergy, time + timeOffset, id);
+    }
+
+    /**
+     * This HitDtoA is exclusively for Mode-7 data, hence the GenericObject parameter.
+     */
+    public CalorimeterHit HitDtoA(EventHeader event,RawCalorimeterHit hit, GenericObject mode7Data, double timeOffset) {
+        double time = hit.getTimeStamp() / 16.0; //timestamps use the full 62.5 ps resolution
+        long id = hit.getCellID();
+        double pedestal = getPulsePedestal(event,id,config.getWindowWidth(),(int)time/nsPerSample);
+        double adcSum = hit.getAmplitude() - pedestal;
+        double rawEnergy = adcToEnergy(adcSum, id);       
+        return CalorimeterHitUtilities.create(rawEnergy, time + timeOffset, id);
+    }
+
+
+    /**
+     * return energy (units of GeV) corresponding to the ADC sum and crystal ID
+     */
+    private double adcToEnergy(double adcSum, long cellID) {
+        return config.getGain(cellID) * adcSum * EcalUtils.MeV;
+    }
+
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use