- Scriptcontext debugged to be working
- Added a drivable adapter to scriptcontext nodes - Added subsampling to simulated histograms (and as a general option) in order to support Gumtree testing.
This commit is contained in:
255
fomerge.c
255
fomerge.c
@ -17,6 +17,8 @@
|
||||
Mark Koennecke, March 2000
|
||||
|
||||
extended to support nxscripted file writing: Mark Koennecke, May 2004
|
||||
|
||||
extended to support GTSE, Mark Koennecke, May 2008
|
||||
--------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -27,6 +29,7 @@
|
||||
#include "fortify.h"
|
||||
#include "scan.h"
|
||||
#include "fitcenter.h"
|
||||
#include "sicsdata.h"
|
||||
|
||||
static pFit fitter = NULL;
|
||||
|
||||
@ -594,6 +597,98 @@ static int putSum(SicsInterp *pSics, SConnection *pCon,
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int TOFLambda(SicsInterp *pSics, SConnection *pCon,
|
||||
int argc, char *argv[]){
|
||||
int status, iTime, iDet, i;
|
||||
const float *fTimeBin = NULL;
|
||||
int *sum = NULL;
|
||||
long *lSum = NULL;
|
||||
pHistMem pMem = NULL;
|
||||
float fCenter, fFWHM, fStdDev, fVal;
|
||||
float fMon, fData, distMonoDet, distFermiDet, tdiff, lambda;
|
||||
|
||||
pMem = (pHistMem)FindCommandData(pSics,"hm1","HistMem");
|
||||
if(pMem == NULL)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"ERROR: need lower detector bank for lambda calculation",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* locate elastic position in data
|
||||
*/
|
||||
fTimeBin = GetHistTimeBin(pMem,&iTime);
|
||||
iDet = getFMdim(LOWER);
|
||||
sum = calculateTimeSum(GetHistogramPointer(pMem,pCon),iDet,iTime);
|
||||
if(!sum)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory calculating lambda",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if(fitter == NULL)
|
||||
{
|
||||
fitter = CreateFitCenter(NULL);
|
||||
if(!fitter)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: cannot allocate fitting structure",eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
copy sum to make compiler happy
|
||||
*/
|
||||
lSum = (long *)malloc(iTime*sizeof(long));
|
||||
if(lSum == NULL)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in TOFLambda",eError);
|
||||
free(sum);
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < iTime; i++)
|
||||
{
|
||||
lSum[i] = sum[i];
|
||||
}
|
||||
status = CalculateFitFromData(fitter,(float *)fTimeBin,lSum,iTime);
|
||||
if(status < 0)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: no peak in data",eError);
|
||||
free(sum);
|
||||
free(lSum);
|
||||
return 0;
|
||||
}
|
||||
GetFitResults(fitter,&fCenter,&fStdDev,&fFWHM,&fVal);
|
||||
fData = fCenter;
|
||||
|
||||
/*
|
||||
* locate elastic position in tofmon
|
||||
*/
|
||||
GetHistogram(pMem, pCon, 0, iTime*iDet, iTime*(iDet+1),
|
||||
sum, iTime*sizeof(HistInt));
|
||||
for(i = 0; i < iTime; i++)
|
||||
{
|
||||
lSum[i] = sum[i];
|
||||
}
|
||||
status = CalculateFitFromData(fitter,(float *)fTimeBin,lSum,iTime);
|
||||
GetFitResults(fitter,&fCenter,&fStdDev,&fFWHM,&fVal);
|
||||
fMon = fCenter;
|
||||
free(sum);
|
||||
free(lSum);
|
||||
|
||||
/*
|
||||
* calculate
|
||||
*/
|
||||
distFermiDet = 3000.;
|
||||
distMonoDet = distFermiDet - 215.7;
|
||||
tdiff = fData - fMon;
|
||||
lambda = tdiff/(252.78*distMonoDet*.001);
|
||||
SCPrintf(pCon,eValue, "toflambda = %f", lambda);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int putElastic(SicsInterp *pSics, SConnection *pCon,
|
||||
pNXScript pNexus, char *alias, float fElastic)
|
||||
{
|
||||
@ -663,12 +758,157 @@ static int putElastic(SicsInterp *pSics, SConnection *pCon,
|
||||
return status;
|
||||
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int FMputTTH(SConnection *pCon, int argc, char *argv[]){
|
||||
pSICSData data = NULL;
|
||||
int length = -1, i;
|
||||
float *tthData = NULL;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,"ERROR: insufficient no of arguments to FMputTTH",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
data = (pSICSData)FindCommandData(pServ->pSics,argv[3],"SICSData");
|
||||
if(data == NULL){
|
||||
SCWrite(pCon,"ERROR: SICSData object not found", eError);
|
||||
return 0;
|
||||
}
|
||||
if(strcmp(argv[2],"upper") == 0)
|
||||
{
|
||||
length = getFMdim(UPPER);
|
||||
tthData = getFMBankTheta(UPPER);
|
||||
}
|
||||
else if(strcmp(argv[2],"middle") == 0)
|
||||
{
|
||||
length = getFMdim(MIDDLE);
|
||||
tthData = getFMBankTheta(MIDDLE);
|
||||
}
|
||||
else if(strcmp(argv[2],"lower") == 0)
|
||||
{
|
||||
length = getFMdim(LOWER);
|
||||
tthData = getFMBankTheta(LOWER);
|
||||
}
|
||||
else if(strcmp(argv[2],"merged") == 0)
|
||||
{
|
||||
length = getFMdim(MERGED);
|
||||
tthData = getFMBankTheta(MERGED);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"ERROR: requested two_theta for invalid detector bank",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if(length < 0 || tthData == NULL){
|
||||
SCWrite(pCon,"ERROR: requested two_theta for invalid detector bank",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
clearSICSData(data);
|
||||
for(i = 0; i < length; i++){
|
||||
setSICSDataFloat(data,i,tthData[i]);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int FMcopyMerged(SConnection *pCon, int argc, char *argv[]){
|
||||
pSICSData data = NULL;
|
||||
int i, length;
|
||||
HistInt *hmData = NULL;
|
||||
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: insufficient no of arguments to FMcopyMerged",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
data = (pSICSData)FindCommandData(pServ->pSics,argv[2],"SICSData");
|
||||
if(data == NULL){
|
||||
SCWrite(pCon,"ERROR: SICSData object not found", eError);
|
||||
return 0;
|
||||
}
|
||||
if(!updateHMFMData(pServ->pSics, pCon)){
|
||||
SCWrite(pCon,"ERROR: not enough HM's to merge or bad names in fomerge.c",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
clearSICSData(data);
|
||||
length = getFMdim(MERGED)*getFMdim(TIMEBIN);
|
||||
hmData = getFMBankPointer(MERGED);
|
||||
if(hmData == NULL){
|
||||
SCWrite(pCon,"ERROR: merged data not available", eError);
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < length; i++){
|
||||
setSICSDataInt(data,i,hmData[i]);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int FMcopyMergedSum(SConnection *pCon, int argc, char *argv[]){
|
||||
pSICSData data = NULL;
|
||||
int i, length, tbin, j, row;
|
||||
HistInt *hmData = NULL, *sumData = NULL;
|
||||
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: insufficient no of arguments to FMcopyMerged",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
data = (pSICSData)FindCommandData(pServ->pSics,argv[2],"SICSData");
|
||||
if(data == NULL){
|
||||
SCWrite(pCon,"ERROR: SICSData object not found", eError);
|
||||
return 0;
|
||||
}
|
||||
if(!updateHMFMData(pServ->pSics, pCon)){
|
||||
SCWrite(pCon,"ERROR: not enough HM's to merge or bad names in fomerge.c",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
clearSICSData(data);
|
||||
length = getFMdim(MERGED);
|
||||
tbin = getFMdim(TIMEBIN);
|
||||
hmData = getFMBankPointer(MERGED);
|
||||
if(hmData == NULL){
|
||||
SCWrite(pCon,"ERROR: merged data not available", eError);
|
||||
return 0;
|
||||
}
|
||||
sumData = malloc(tbin*sizeof(int));
|
||||
if(sumData == NULL){
|
||||
SCWrite(pCon,"ERROR: out-of-memory in FMcopyMergedSum", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(sumData,0,tbin*sizeof(int));
|
||||
for(j = 0; j < length; j++){
|
||||
row = j*tbin;
|
||||
for(i = 0; i < tbin; i++){
|
||||
sumData[i] += hmData[row+i];
|
||||
}
|
||||
}
|
||||
for(i = 0; i < tbin; i++){
|
||||
setSICSDataInt(data,i,sumData[i]);
|
||||
}
|
||||
free(sumData);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------
|
||||
Usage:
|
||||
focusmerge puttwotheta nxscriptmod bankname alias
|
||||
focusmerge puttth bankname sicsdataname
|
||||
focusmerge copymerged sicsdataname
|
||||
focusmerge copymergedsum sicsdataname
|
||||
focusmerge putmerged nxscriptmod alias
|
||||
focusmerge putsum nxscriptmod bankname alias
|
||||
focusmerge putelastic nxscriptmod alias theoelastic
|
||||
focusmerge toflambda
|
||||
|
||||
nxscriptmod = name of the nxscript module used for writing, must be open
|
||||
alias = The alias under which to write the data item
|
||||
@ -690,6 +930,21 @@ int FocusMergeAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
|
||||
strtolower(argv[1]);
|
||||
|
||||
if(strcmp(argv[1],"puttth") == 0){
|
||||
return FMputTTH(pCon,argc,argv);
|
||||
}
|
||||
|
||||
if(strcmp(argv[1],"copymerged") == 0){
|
||||
return FMcopyMerged(pCon,argc,argv);
|
||||
}
|
||||
if(strcmp(argv[1],"copymergedsum") == 0){
|
||||
return FMcopyMergedSum(pCon,argc,argv);
|
||||
}
|
||||
if(strcmp(argv[1],"toflambda") == 0){
|
||||
return TOFLambda(pSics, pCon,argc,argv);
|
||||
}
|
||||
|
||||
if(strcmp(argv[1],"puttwotheta") == 0)
|
||||
{
|
||||
if(argc < 4)
|
||||
|
Reference in New Issue
Block a user