- Added an edge function to peakcenter for NARZISS

- Fixed ei interrupt bug in tasdrive.c
- Made eiger A2 driving work
- Added force start facility to devexec for POLDI HV


SKIPPED:
	psi/eigera2.c
	psi/polterwrite.c
This commit is contained in:
koennecke
2011-12-19 12:24:58 +00:00
parent a207ebf46d
commit 14f257c2ab
14 changed files with 361 additions and 43 deletions

View File

@ -6,6 +6,11 @@
copyright: see copyright.h
Mark Koennecke, October 1997
Added center of edge finding
Mark Koennecke, Octover 2011
-----------------------------------------------------------------------------*/
#include <limits.h>
#include <math.h>
@ -221,6 +226,51 @@ static int CalculateFitIntern(pFit self)
return iRet;
}
/*-------------------------------------------------------------------------*/
static int CalculateEdgeIntern(pFit self)
{
int i, iRet, iPeak, nSlope = 0;;
long lCount;
float fNenner,fSum, fCI;
/* find the maximum counts */
iRet = FindMax(self);
self->lPeak = self->lCounts[iRet];
/* a default fit is the peak maximum. This
helps optimise to do the right thing if no proper calculation
could be performed
*/
if (self->lPeak < 3) {
return -3;
}
/*
* calculate the COG between .9*max < counts < .1*max
*/
fSum = 0.;
fNenner = 0.;
for (i = 0; i < self->iNP; i++) {
lCount = self->lCounts[i];
if(lCount > self->lPeak *.20 && lCount < self->lPeak * .80){
fSum += lCount * self->fAxis[i];
fNenner += lCount;
nSlope++;
}
}
if(fNenner > .0001){
fCI = fSum / fNenner;
} else {
return -3;
}
self->fCenter = fCI;
self->fStddev = 1.0;
if(nSlope < 3) {
iRet = -7;
}
return iRet;
}
/*--------------------------------------------------------------------------*/
int CalculateFit(pFit self)
@ -328,7 +378,7 @@ int FitFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
pDummy pDum = NULL;
CommandList *pCom = NULL;
char pBueffel[132];
int iRet, iRet1;
int iRet, iRet1, iRet2;
if (argc < 2) {
SCWrite(pCon,
@ -365,6 +415,7 @@ int FitFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
iRet = AddCommand(pSics, "peak", FitWrapper, DeleteFitCenter, self);
iRet1 = AddCommand(pSics, "center", CenterWrapper, NULL, self);
iRet2 = AddCommand(pSics, "edge", EdgeWrapper, NULL, self);
if (!iRet || !iRet1) {
snprintf(pBueffel,sizeof(pBueffel)-1,
"ERROR: duplicate commands peak and center not created");
@ -374,7 +425,6 @@ int FitFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
}
return 1;
}
/*--------------------------------------------------------------------------*/
int FitWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
@ -451,7 +501,65 @@ int FitWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
return 1;
}
/*---------------------------------------------------------------------------*/
int EdgeWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
pFit self = NULL;
int iRet;
char pBueffel[256];
pDynString buf = NULL;
self = (pFit) pData;
assert(self);
Init(self);
iRet = CalculateEdgeIntern(self);
switch (iRet) {
case 0:
SCWrite(pCon, "ERROR: failure to fit your data!", eError);
return 0;
break;
case -3:
SCWrite(pCon, "ERROR: No counts found in Fit!", eError);
return 0;
break;
case -4:
SCWrite(pCon, "ERROR: Insufficient counts in peak", eError);
return 0;
break;
case -7:
SCWrite(pCon,
"WARNING: not enough points in slope, results may be inreliable, remeasure with smaller step width",
eWarning);
break;
}
/*
This is a little feature to get the peak without rubbish for
the TAS routines
*/
if (argc > 1) {
strtolower(argv[1]);
if (strcmp(argv[1], "value") == 0) {
snprintf(pBueffel,sizeof(pBueffel)-1, "%f", self->fCenter);
SCWrite(pCon, pBueffel, eValue);
return 1;
}
}
/* print results */
SCStartBuffering(pCon);
snprintf(pBueffel,sizeof(pBueffel)-1, "Estimated Edge Center: %f\n",
self->fCenter);
SCWrite(pCon, pBueffel, eValue);
buf = SCEndBuffering(pCon);
if (buf != NULL) {
SCWrite(pCon, GetCharArray(buf), eValue);
}
return 1;
}
/*---------------------------------------------------------------------------*/
int CenterWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])