From cd9a625958fb187d628e127accd1789a555dc2f6 Mon Sep 17 00:00:00 2001 From: Zaher Salman Date: Thu, 2 Sep 2010 18:50:11 +0000 Subject: [PATCH] Added functions for beta-NMR relaxation curves (beam on/off). --- src/external/libBNMR/Makefile.libBNMR | 60 +++++++++++++++ src/external/libBNMR/TBNMR.cpp | 104 ++++++++++++++++++++++++++ src/external/libBNMR/TBNMR.h | 80 ++++++++++++++++++++ src/external/libBNMR/TBNMR.o | Bin 0 -> 17824 bytes src/external/libBNMR/TBNMRLinkDef.h | 42 +++++++++++ 5 files changed, 286 insertions(+) create mode 100644 src/external/libBNMR/Makefile.libBNMR create mode 100644 src/external/libBNMR/TBNMR.cpp create mode 100644 src/external/libBNMR/TBNMR.h create mode 100644 src/external/libBNMR/TBNMR.o create mode 100644 src/external/libBNMR/TBNMRLinkDef.h diff --git a/src/external/libBNMR/Makefile.libBNMR b/src/external/libBNMR/Makefile.libBNMR new file mode 100644 index 00000000..0762594d --- /dev/null +++ b/src/external/libBNMR/Makefile.libBNMR @@ -0,0 +1,60 @@ +#--------------------------------------------------- +# get compilation flags from root-config + +ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags) + +#--------------------------------------------------- + +OS = LINUX +CXX = g++ +CXXFLAGS = -O3 -Wall -Wno-trigraphs -fPIC +LOCALINCLUDE = . +ROOTINCLUDE = $(ROOTSYS)/include +INCLUDES = -I$(LOCALINCLUDE) -I$(ROOTINCLUDE) +LD = g++ +LDFLAGS = +SOFLAGS = -O -shared + +# the output from the root-config script: +CXXFLAGS += $(ROOTCFLAGS) +LDFLAGS += + +# some definitions: headers (used to generate *Dict* stuff), sources, objects,... +OBJS = +OBJS += TBNMR.o TlibBNMRDict.o + +SHLIB = libBNMR.so + +# make the shared lib: +# +all: $(SHLIB) + +$(SHLIB): $(OBJS) + @echo "---> Building shared library $(SHLIB) ..." + /bin/rm -f $(SHLIB) + $(LD) $(OBJS) $(SOFLAGS) -o $(SHLIB) + @echo "done" + +# clean up: remove all object file (and core files) +# semicolon needed to tell make there is no source +# for this target! +# +clean:; @rm -f $(OBJS) *Dict* core* + @echo "---> removing $(OBJS)" + +# +$(OBJS): %.o: %.cpp + $(CXX) $(INCLUDES) $(CXXFLAGS) -c $< + +# Generate the ROOT CINT dictionary + +TlibBNMRDict.cpp: TBNMR.h TBNMRLinkDef.h + @echo "Generating dictionary $@..." + rootcint -f $@ -c -p -I$(ROOTINCLUDE) $^ + +install: all + @echo "Installing shared lib: libTApproximation.so" +ifeq ($(OS),LINUX) + cp -pv $(SHLIB) $(ROOTSYS)/lib + cp -pv $(LOCALINCLUDE)/*.h $(ROOTSYS)/include +endif diff --git a/src/external/libBNMR/TBNMR.cpp b/src/external/libBNMR/TBNMR.cpp new file mode 100644 index 00000000..5ab52d7f --- /dev/null +++ b/src/external/libBNMR/TBNMR.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + + TBNMR.cpp + + Author: Zaher Salman + e-mail: zaher.salman@psi.ch + + 2010/09/02 + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2010 by Zaher Salman * + * zaher.salman@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "TBNMR.h" +#include "TF1.h" +#include "Math/WrappedTF1.h" +#include "Math/GaussIntegrator.h" + +#define tau_Li 1210 +#define gamma_Li 6.3018 // In units kHz/mT +#define PI 3.14159265358979323846 +#define TWOPI 6.28318530717958647692 + +ClassImp(TBNMR) // for the ROOT-dictionary +ClassImp(ExpRlx) +ClassImp(SExpRlx) + +double TBNMR::operator()(double x, const vector &par) const { + assert(par.size()==1); // make sure the number of parameters handed to the function is correct + + double arg(par[0]*x); + + if(!arg) + return 1.0; + return sin(arg)/arg; +} + +double ExpRlx::operator()(double x, const vector &par) const { + assert(par.size()==2); // make sure the number of parameters handed to the function is correct + + // par[0] time of beam off + // par[1] is the relaxation rate + double tau_p; + double y; + + tau_p = (tau_Li/(1.+par[1]*tau_Li)); + + if ( x <= par[0] && x >= 0) { + y=(tau_p/tau_Li)*(1-exp(-x/tau_p))/(1-exp(-x/tau_Li)); + } else if ( x > par[0] ){ + y=(tau_p/tau_Li)*(1-exp(-par[0]/tau_p))/(1-exp(-par[0]/tau_Li))*exp(-par[1]*(x-par[0])); + } else { + y = 0; + } + + return y; +} + +double SExpRlx::operator()(double x, const vector &par) const { + assert(par.size()==3); // make sure the number of parameters handed to the function is correct + + // par[0] time of beam off + // par[1] is the relaxation rate + // par[2] is the exponent + double tau_p; + double y; + + tau_p = (tau_Li/(1.+par[1]*tau_Li)); + + + if ( x >= 0 && x <= par[0] ) { + TF1 sexp("sexp", "exp(-([0]-x)/[3])*exp(-pow(([1]*([0]-x)),[2]))", 0.0, 10000.0); + sexp.SetParameters(x, par[1], par[2],tau_Li); + sexp.SetNpx(1000); + y=sexp.Integral(0.0,x)/(1-exp(-x/tau_Li))/tau_Li; + } else if ( x > par[0] ) { + TF1 sexp("sexp", "exp(-([3]-x)/[4])*exp(-pow(([1]*([0]-x)),[2]))", 0.0, 10000.0); + sexp.SetParameters(x, par[1], par[2], par[0],tau_Li); + sexp.SetNpx(1000); + y=sexp.Integral(0.0,par[0])/(1-exp(-x/tau_Li))/tau_Li; + } else { + y = 0; + } + return y; +} + diff --git a/src/external/libBNMR/TBNMR.h b/src/external/libBNMR/TBNMR.h new file mode 100644 index 00000000..ba497d87 --- /dev/null +++ b/src/external/libBNMR/TBNMR.h @@ -0,0 +1,80 @@ +/*************************************************************************** + + TBNMR.h + + Author: Zaher Salman + e-mail: zaher.salman@psi.ch + + 2010/09/02 + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2010 by Zaher Salman * + * zaher.salman@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#include "PUserFcnBase.h" +#include +#include +#include + +using namespace std; + +class TBNMR : public PUserFcnBase { + +public: + // default constructor and destructor + TBNMR(){} + ~TBNMR(){} + + // function operator + double operator()(double, const vector&) const; + + // definition of the class for the ROOT-dictionary + ClassDef(TBNMR,1) +}; + +class ExpRlx : public PUserFcnBase { + +public: + // default constructor and destructor + ExpRlx(){} + ~ExpRlx(){} + + // function operator + double operator()(double, const vector&) const; + + // definition of the class for the ROOT-dictionary + ClassDef(ExpRlx,1) +}; + +class SExpRlx : public PUserFcnBase { + +public: + // default constructor and destructor + SExpRlx(){} + ~SExpRlx(){} + + // function operator + double operator()(double, const vector&) const; + + // definition of the class for the ROOT-dictionary + ClassDef(SExpRlx,1) +}; diff --git a/src/external/libBNMR/TBNMR.o b/src/external/libBNMR/TBNMR.o new file mode 100644 index 0000000000000000000000000000000000000000..48125c34b69023ff3698ef409eeb312a4507ac6a GIT binary patch literal 17824 zcmeHP4Rl<^b)NmPBZGsD>rxsFtQ-Ln*s@mta%?JDTA4kTWg)E%wGr#}?vu5!+78w(!qc5^?l*U4?#$fx_RVv?;%jSlI2=qR2XiqSF}8oP&{T6#%C2DnuJ-^F zZ>f|eQeGnEWm1+&d4-hArCcGUSIR0WYoz>=l&hq?Qp!dt*GSncrBBLMDX)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IXvk@QhzJyaqMvq$!f;F4e7p>G5YtV^OlKoY#I-}m!4N6zTb6!g|R7MvNH!` zpmuJ9oL9^E`@?y4_#PP8eH&vhP&p1!oG#!YyaOV6J7bL`_cH#zZXTSrneZKqzpo>H z6nNfB#%`tZJMph!3FCO;0g|wPh{|FAZwZ5MVT@!yLlXACM-uj*hoo^FB#CkS9Z4L7 zA0s`+ae^f5pCY*%@8`ElE&qQoVS{>?Idyhk(TmqNb2tcgz@t7TM|D>82mRR zeoN|)OZDoC#CE=sa;=6MwbF`%6FD zshr+OyCcX$(m3chJC!eiboIz@U$$dh!0z7Z_34c?@k&S!-i&r`JVQI+6|@sSLp$Ip zJ8<9h@!m9j9NZ5ni~)SdSH&5OV?><2IHJNY4ojS!IQEG%6UV6Vlj9HYUY+XUz?Ir{ z+%3LEa@-@%QXF3s``vLb_7~~D&iFZ@1Dh91i#h%f>zm{siGPRSxS#QpEysQl4;({T{(LafBZgal>&vWBr656Y<0G$BYdU{uX05 zlYE@9-6a16|3Hl76Zo!<-tUr2j5s=mK;6DPxb4e2Ouc zVvaw<*)qwe89%>td=F>Rgz@JYl7E4CLGmxL-${O-u>&NbJV^4d7<-N6vxp-k|C+HQ zBvI+7B!9rzQIZI96C{5q;+g}-juTE|pOSo$@$*o}kFZ|}?~(KSk}4UZ@--119E;}mh*d;oZnZB`Ax|A?fYzg|6k1SHaWjza()pM`2M{GixbK5s+{K^ z%XvOzlp}Z)5zj0?Y?o8Kcm71gY3JD@-a6-tcfHw;;NMUrKIN~Du0>e#fVc9!yI#TGxlFoj9~8o literal 0 HcmV?d00001 diff --git a/src/external/libBNMR/TBNMRLinkDef.h b/src/external/libBNMR/TBNMRLinkDef.h new file mode 100644 index 00000000..ab6870bb --- /dev/null +++ b/src/external/libBNMR/TBNMRLinkDef.h @@ -0,0 +1,42 @@ +/*************************************************************************** + + TBNMRLinkDef.h + + Author: Zaher Salman + e-mail: zaher.salman@psi.ch + + 2010/09/02 + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2010 by Zaher Salman * + * zaher.salman@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class TBNMR+; +#pragma link C++ class ExpRlx+; +#pragma link C++ class SExpRlx+; + +#endif //__CINT__