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:

r3970 - /java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java

From:

[log in to unmask]

Reply-To:

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

Date:

Sat, 21 Nov 2015 05:12:09 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (145 lines)

Author: [log in to unmask]
Date: Fri Nov 20 21:12:03 2015
New Revision: 3970

Log:
code give an rf time but does not fit-only using initial values

Modified:
    java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java

Modified: java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/baltzell/RfFitterDriver.java	Fri Nov 20 21:12:03 2015
@@ -29,6 +29,7 @@
 	static final int SLOT=13;
 	static final int CHANNELS[]={0,1};
 	static final double NSPERSAMPLE=4;
+		
 
 	// boilerplate:
     AIDA aida = AIDA.defaultInstance();
@@ -61,8 +62,9 @@
 					
 					// we found a RF readout, fit it:
 					foundRf=true;
-					IFitResult fit=fitPulse(hit);
-  				    times[ii]=NSPERSAMPLE*fit.fittedParameter("time");
+					times[ii] = fitPulse(hit);
+					//System.out.println("rf times:\t"+times[ii]);
+  				    
 					break;
 				}
 			}
@@ -79,30 +81,93 @@
 	/*
 	 * Perform the fit to the RF pulse:
 	 */
-	public IFitResult fitPulse(FADCGenericHit hit) {
-
+	public double 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);
+		//stores the location of the peak bins
+		int iz=0;
+		int peakBin[]={-999,-999,-999};
+		final int threshold = 300;	
+		double fitThresh[]={-999,-999,-999};
+		double pedVal[]={-999,-999,-999};
+		for (int ii=4; ii<(adcSamples.length-1); ii++) {
+			//looks for peak bins in time spectra (not more than 3)
+			//System.out.println("Samp:\t"+ii+"\t"+adcSamples[ii]);
+			if (iz==3){break;}
+			if (adcSamples[ii+1]>0 && adcSamples[ii-1]>0 && adcSamples[ii]>threshold && ii>12){
+				if ((adcSamples[ii]>adcSamples[ii+1] && adcSamples[ii]>adcSamples[ii-1])
+						||((adcSamples[ii]>adcSamples[ii+1] && adcSamples[ii]==adcSamples[ii-1])
+								||(adcSamples[ii]==adcSamples[ii+1] && adcSamples[ii]>adcSamples[ii-1]))){
+					//System.out.println("peak:\t"+iz);
+					peakBin[iz]=ii;
+					iz++;
+				}
+			}
 		}
 		
-		// TODO: properly initialize fit parameters:
-		fitFunction.setParameter("time",0.0);
-		fitFunction.setParameter("pedestal",0.0);
-		fitFunction.setParameter("slope",100.0);
+		int jj=0;
+		//each signal will always have 2-3 pulses in the window. ik=1 selects the second pulse (closest to middle of window)
+		int ik=1;
+		pedVal[ik] = (adcSamples[peakBin[ik]-6]+adcSamples[peakBin[ik]-7]+adcSamples[peakBin[ik]-8]+adcSamples[peakBin[ik]-9])/4.0;
+		fitThresh[ik]= (adcSamples[peakBin[ik]]-pedVal[ik])/3.0;
+		
+		//calc initial values along the way:
+		double itime = -999;
+		double islope = -999; 
+			
+		//find the points of the peak bin to peak bin-5
+		for (int ll=0; ll<5; ll++){	
+			if ((adcSamples[peakBin[ik]-5+ll]) > fitThresh[ik]){
+				//get one below fit threshold and two points above	
+				if(jj==0 && (adcSamples[peakBin[ik]-6+ll] > pedVal[ik])){
+					final int zz=fitData.size();	
+					fitData.addPoint();
+					//System.out.println("fit points:\t"+zz+"\t"+(peakBin[ik]-6+ll));
+					fitData.point(zz).coordinate(0).setValue(peakBin[ik]-6+ll);
+					fitData.point(zz).coordinate(1).setValue(adcSamples[peakBin[ik]-6+ll]);
+					fitData.point(zz).coordinate(1).setErrorMinus(0.0);
+					fitData.point(zz).coordinate(1).setErrorPlus(0.0);		
+					jj++;	
+				}
+				final int zz=fitData.size();	
+				fitData.addPoint();
+				//System.out.println("fit points:\t"+zz+"\t"+(peakBin[ik]-5+ll));
+				if (zz==1){
+					itime = peakBin[ik]-5+ll;
+					islope =((double) (adcSamples[peakBin[ik]-5+ll]-adcSamples[peakBin[ik]-6+ll]))/(peakBin[ik]-5+ll-(peakBin[ik]-6+ll));	
+				}
+				fitData.point(zz).coordinate(0).setValue(peakBin[ik]-5+ll);
+				fitData.point(zz).coordinate(1).setValue(adcSamples[peakBin[ik]-5+ll]);
+				fitData.point(zz).coordinate(1).setErrorMinus(0.0);
+				fitData.point(zz).coordinate(1).setErrorPlus(0.0);
+						
+				jj++;
+				if (jj==3) {break;}					
+			}
+		}
+			
+		double icept = itime*(1-islope);
+		//System.out.println("initial parameters, icept:\t"+icept+"\t islope:\t"+islope+"\t itime:\t"+itime);
+		// properly initialize fit parameters:
+		fitFunction.setParameter("time",itime);
+		fitFunction.setParameter("intercept",icept);
+		fitFunction.setParameter("slope",islope);
 	
 		// 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);
+		IFitResult fitResults = fitter.fit(fitData,fitFunction);
+		
+		//choose to get the time value at this location on the fit:
+		double halfVal = (adcSamples[peakBin[1]]+pedVal[1])/2.0;	
+		System.out.println("Fit results:\t"+fitResults.fittedParameter("intercept")+"\t"+fitResults.fittedParameter("slope"));
+		System.out.println("Half height:\t"+halfVal);
+		return NSPERSAMPLE*(halfVal-fitResults.fittedParameter("intercept"))/fitResults.fittedParameter("slope");
+		
+		
 	}
 	
+	
+	
+	
 }

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