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  November 2015

HPS-SVN November 2015

Subject:

r3964 - in /java/trunk: recon/src/main/java/org/hps/recon/filtering/ users/src/main/java/org/hps/users/baltzell/

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 17 Nov 2015 00:51:19 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (215 lines)

Author: [log in to unmask]
Date: Mon Nov 16 16:51:15 2015
New Revision: 3964

Log:
prepping for adding extracted RF time

Added:
    java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitFunction.java
    java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java
    java/trunk/users/src/main/java/org/hps/users/baltzell/RfHit.java
Modified:
    java/trunk/recon/src/main/java/org/hps/recon/filtering/PulserTriggerFilterDriver.java

Modified: java/trunk/recon/src/main/java/org/hps/recon/filtering/PulserTriggerFilterDriver.java
 =============================================================================
--- java/trunk/recon/src/main/java/org/hps/recon/filtering/PulserTriggerFilterDriver.java	(original)
+++ java/trunk/recon/src/main/java/org/hps/recon/filtering/PulserTriggerFilterDriver.java	Mon Nov 16 16:51:15 2015
@@ -7,7 +7,14 @@
 import org.hps.record.scalers.ScalerData;
 import org.hps.record.triggerbank.AbstractIntData;
 import org.hps.record.triggerbank.TIData;
-
+/**
+ * Keep pulser triggered events.
+ * Also keep EPICS events, and Scaler events.
+ * Drop all other events.
+ * 
+ * @author baltzell
+ *
+ */
 public class PulserTriggerFilterDriver extends Driver
 {
   public void process(EventHeader event) {

Added: java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitFunction.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitFunction.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitFunction.java	Mon Nov 16 16:51:15 2015
@@ -0,0 +1,36 @@
+package org.hps.users.baltzell;
+
+import hep.aida.ref.function.AbstractIFunction;
+
+/*
+ * Function for fitting the leading edge of the RF waveform.
+ */
+public class RfFitFunction extends AbstractIFunction {
+	protected double pedestal=0;
+	protected double time=0;
+	protected double slope=0;
+	public RfFitFunction() {
+		this("");
+	}
+	public RfFitFunction(String title) {
+		super();
+		this.variableNames=new String[]{"time"};
+		this.parameterNames=new String[]{"pedestal","time","slope"};
+		init(title);
+	}
+	public double value(double [] v) {
+		return  pedestal + (v[0]-time)*slope;
+	}
+	public void setParameters(double[] pars) throws IllegalArgumentException {
+		super.setParameters(pars);
+		pedestal=pars[0];
+		time=pars[1];
+		slope=pars[2];
+	}
+	public void setParameter(String key,double value) throws IllegalArgumentException{
+		super.setParameter(key,value);
+		if      (key.equals("pedestal")) pedestal=value;
+		else if (key.equals("time"))     time=value;
+		else if (key.equals("slope"))    slope=value;
+	}
+}

Added: java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java	Mon Nov 16 16:51:15 2015
@@ -0,0 +1,108 @@
+package org.hps.users.baltzell;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IDataPointSet;
+import hep.aida.IFitFactory;
+import hep.aida.IFitResult;
+import hep.aida.IFitter;
+import hep.aida.IFunction;
+import hep.aida.IFunctionFactory;
+
+import org.hps.recon.ecal.FADCGenericHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.GenericObject;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/*
+ * Extract RF time from waveform and put into lcsim event.
+ */
+public class RfFitterDriver extends Driver {
+
+	static final double NOISE=2.0; // units = FADC
+	static final int CRATE=46;
+	static final int SLOT=13;
+	static final int CHANNELS[]={0,1};
+	static final double NSPERSAMPLE=4;
+
+	// boilerplate:
+    AIDA aida = AIDA.defaultInstance();
+    IAnalysisFactory analysisFactory = aida.analysisFactory();
+    IFunctionFactory functionFactory = analysisFactory.createFunctionFactory(null);
+    IFitFactory fitFactory = analysisFactory.createFitFactory();
+    IFitter fitter=fitFactory.createFitter();
+    IDataPointSet fitData=aida.analysisFactory().createDataPointSetFactory(null).create("RF ADC DataPointSet", 2);
+    
+    // the function used to fit the RF pulse:
+    IFunction fitFunction=new RfFitFunction();
+
+    /*
+     * Check the event for an RF pulse, and, if found, fit it to get
+     * RF time and then dump it in the lcsim event.
+     */
+	public void process(EventHeader event) {
+		if (!event.hasCollection(GenericObject.class,"FADCGenericHits")) return;
+		
+		boolean foundRf=false;
+    	double times[]={-9999,-9999};
+    	
+    	for (GenericObject gob : event.get(GenericObject.class,"FADCGenericHits")) {
+			FADCGenericHit hit=(FADCGenericHit)gob;
+    		
+			// ignore hits not from proper RF signals based on crate/slot/channel:
+			if (hit.getCrate()!=CRATE || hit.getSlot()!=SLOT) continue;
+    		for (int ii=0; ii<CHANNELS.length; ii++) {
+				if (hit.getChannel()==CHANNELS[ii]) {
+					
+					// we found a RF readout, fit it:
+					foundRf=true;
+					IFitResult fit=fitPulse(hit);
+  				    times[ii]=NSPERSAMPLE*fit.fittedParameter("time");
+					break;
+				}
+			}
+		}
+		
+    	// if we found an RF readout, dump the fit result in the event:  
+    	if (foundRf) {
+    		List <RfHit> rfHits=new ArrayList<RfHit>();
+    		rfHits.add(new RfHit(times));
+	    	event.put("RFHits", rfHits, RfHit.class, 1);
+		}
+	}
+
+	/*
+	 * Perform the fit to the RF pulse:
+	 */
+	public IFitResult fitPulse(FADCGenericHit hit) {
+
+		fitData.clear();
+		final int adcSamples[]=hit.getData();
+		
+		// TODO: only add those ADC values which are to be fitted:
+		for (int ii=0; ii<adcSamples.length; ii++) {
+			final int jj=fitData.size();
+			fitData.addPoint();
+			fitData.point(jj).coordinate(0).setValue(ii);
+			fitData.point(jj).coordinate(1).setValue(adcSamples[ii]);
+			fitData.point(jj).coordinate(1).setErrorMinus(NOISE);
+			fitData.point(jj).coordinate(1).setErrorPlus(NOISE);
+		}
+		
+		// TODO: properly initialize fit parameters:
+		fitFunction.setParameter("time",0.0);
+		fitFunction.setParameter("pedestal",0.0);
+		fitFunction.setParameter("slope",100.0);
+	
+		// this used to be turned on somewhere else on every event, dunno if it still is:
+		//Logger.getLogger("org.freehep.math.minuit").setLevel(Level.OFF);
+		
+		return fitter.fit(fitData,fitFunction);
+	}
+	
+}

Added: java/trunk/users/src/main/java/org/hps/users/baltzell/RfHit.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/RfHit.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/RfHit.java	Mon Nov 16 16:51:15 2015
@@ -0,0 +1,18 @@
+package org.hps.users.baltzell;
+
+import org.lcsim.event.GenericObject;
+
+/*
+ * class to store RF times after extracting from waveform.
+ */
+public class RfHit implements GenericObject {
+	private double[] times;
+	public RfHit(double[] times) { this.times=times; }
+	public int getNInt()    { return 0; }
+	public int getNFloat()  { return 0; }
+	public int getNDouble() { return times.length; }
+	public double getDoubleVal(int ii) { return times[ii]; }
+	public float  getFloatVal (int ii) { return 0; }
+	public int    getIntVal   (int ii) { return 0; }
+	public boolean isFixedSize() { return false; }
+}

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