added a full user function example to doc/examples which should help a user to understand how to deal with the subclass plugin mechanism.
This commit is contained in:
parent
2f91278871
commit
852043f286
60
doc/examples/UserFcn/Makefile.PUserFcn
Normal file
60
doc/examples/UserFcn/Makefile.PUserFcn
Normal file
@ -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 += PUserFcn.o PUserFcnDict.o
|
||||
|
||||
SHLIB = libPUserFcn.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
|
||||
|
||||
PUserFcnDict.cpp: PUserFcn.h PUserFcnLinkDef.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
|
59
doc/examples/UserFcn/PUserFcn.cpp
Normal file
59
doc/examples/UserFcn/PUserFcn.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/***************************************************************************
|
||||
|
||||
PUserFcn.cpp
|
||||
|
||||
Author: Andreas Suter
|
||||
e-mail: andreas.suter@psi.ch
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007-2016 by Andreas Suter *
|
||||
* andreas.suter@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 <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "PUserFcn.h"
|
||||
|
||||
ClassImp(PUserFcn)
|
||||
|
||||
//------------------------------------------------------
|
||||
/**
|
||||
* <p> user function example: polynome of 3rd order
|
||||
*
|
||||
* \f[ = \sum_{k=0}^3 c_k t^k \f]
|
||||
*
|
||||
* <b>meaning of paramValues:</b> \f$c_0\f$, \f$c_1\f$, \f$c_2\f$, \f$c_3\f$
|
||||
*
|
||||
* <b>return:</b> function value
|
||||
*
|
||||
* \param t time in \f$(\mu\mathrm{s})\f$, or x-axis value for non-muSR fit
|
||||
* \param param parameter vector
|
||||
*/
|
||||
Double_t PUserFcn::operator()(Double_t t, const std::vector<Double_t> ¶m) const
|
||||
{
|
||||
// expected parameters: c0, c1, c2, c3
|
||||
|
||||
assert(param.size() == 4);
|
||||
|
||||
return param[0] + param[1]*t + param[2]*t*t + param[3]*t*t*t;
|
||||
}
|
58
doc/examples/UserFcn/PUserFcn.h
Normal file
58
doc/examples/UserFcn/PUserFcn.h
Normal file
@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
|
||||
PUserFcn.h
|
||||
|
||||
Author: Andreas Suter
|
||||
e-mail: andreas.suter@psi.ch
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2007-2016 by Andreas Suter *
|
||||
* andreas.suter@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. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _PUSERFCN_H_
|
||||
#define _PUSERFCN_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "PUserFcnBase.h"
|
||||
|
||||
/**
|
||||
* <p>User function example class. Polynome of 3rd order.
|
||||
*/
|
||||
class PUserFcn : public PUserFcnBase
|
||||
{
|
||||
public:
|
||||
PUserFcn() {}
|
||||
~PUserFcn() {}
|
||||
|
||||
// global user-function-access functions, here without any functionality
|
||||
Bool_t NeedGlobalPart() const { return false; }
|
||||
void SetGlobalPart(vector<void*> &globalPart, UInt_t idx) { }
|
||||
Bool_t GlobalPartIsValid() const { return true; }
|
||||
|
||||
// function operator
|
||||
Double_t operator()(Double_t t, const std::vector<Double_t> ¶m) const;
|
||||
|
||||
// definition of the class for the ROOT dictionary
|
||||
ClassDef(PUserFcn, 1)
|
||||
};
|
||||
|
||||
#endif // _PUSERFCN_H_
|
15
doc/examples/UserFcn/PUserFcnLinkDef.h
Normal file
15
doc/examples/UserFcn/PUserFcnLinkDef.h
Normal file
@ -0,0 +1,15 @@
|
||||
/***************************************************************************
|
||||
|
||||
PUserFcnLinkDef.h
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef __CINT__
|
||||
|
||||
#pragma link off all globals;
|
||||
#pragma link off all classes;
|
||||
#pragma link off all functions;
|
||||
|
||||
#pragma link C++ class PUserFcn+;
|
||||
|
||||
#endif //__CINT__
|
89
doc/examples/UserFcn/README
Normal file
89
doc/examples/UserFcn/README
Normal file
@ -0,0 +1,89 @@
|
||||
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
|
||||
|
||||
Simple Example for a User Function without Global Part
|
||||
|
||||
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
|
||||
|
||||
Goal: define a user function which implements a polynom
|
||||
of 3rd order.
|
||||
|
||||
For details see: http://lmu.web.psi.ch/musrfit/user/MUSR/MusrFit.html#A_6_User_Functions
|
||||
|
||||
Implementation:
|
||||
3 Files are needed:
|
||||
|
||||
1) A header file which defines your user function
|
||||
interface.
|
||||
|
||||
In the example here it is called PUserFcn.h
|
||||
|
||||
Please rename it in your case to something more
|
||||
sensible, e.g. PMyPoly.h. At the same time also
|
||||
rename correspondingly the class name in your
|
||||
header file, i.e. PUserFcn -> PMyPoly. This will
|
||||
be at 4 places in the header file of this example.
|
||||
|
||||
2) The source file which defines your user function.
|
||||
|
||||
In the example here it is called PUserFcn.cpp
|
||||
|
||||
Please rename it accordingly to the header file.
|
||||
In case the header file is called PMyPoly.h, the
|
||||
source file will need to be called PMyPoly.cpp.
|
||||
As for the header file, the class names need to
|
||||
be adopted: PUserFcn -> PMyPoly.
|
||||
|
||||
In the source file change the operator implementation
|
||||
(Double_t PUserFcn::operator()(Double_t t,
|
||||
const std::vector<Double_t> ¶m) const)
|
||||
to whatever you need.
|
||||
|
||||
3) There is another header file needed to generate
|
||||
the necessary ROOT dictionary.
|
||||
|
||||
In this example it is called PUserFcnLinkDef.h
|
||||
|
||||
Here you only will need to find PUserFcn+ and
|
||||
replace it with your class name, e.g. PMyPoly+
|
||||
|
||||
Generate Code:
|
||||
You will find the Makefil.PUserFcn which generates
|
||||
the needed shared library for your user function.
|
||||
|
||||
Again, if your user function is called PMyPoly, you
|
||||
will need to replace things accordingly in the
|
||||
Makefile, i.e.
|
||||
|
||||
Makefile.PUserFcn -> Makefile.PMyPoly
|
||||
|
||||
In the Makefile:
|
||||
|
||||
PUserFcn.o -> PMyPoly.o
|
||||
PUserFcnDict.o -> PMyPolyDict.o
|
||||
libPUserFcn.so -> libPMyPoly.so
|
||||
|
||||
To create the shared library do:
|
||||
|
||||
make -f Makefile.PUserFcn
|
||||
|
||||
on the command line. This should create a file
|
||||
libPUserFcn.so.
|
||||
|
||||
Next call on the command line:
|
||||
|
||||
make -f Makefile.PUserFcn install
|
||||
|
||||
This will copy the shared library to the correct
|
||||
place.
|
||||
|
||||
You also will need to make sure that the system is
|
||||
finding the shared library, either by setting
|
||||
LD_LIBRARY_PATH or by calling /sbin/ldconfig as
|
||||
superuser/root assuming you are using linux.
|
||||
|
||||
Example msr-file:
|
||||
You will find an example msr-file test-asy-MUS.msr
|
||||
which is using PUserFcn. The example is UN-PHYSICALLY
|
||||
it is just to show how to use a user function.
|
||||
|
||||
|
BIN
doc/examples/UserFcn/data/000100.msr
Normal file
BIN
doc/examples/UserFcn/data/000100.msr
Normal file
Binary file not shown.
55
doc/examples/UserFcn/test-asy-MUD.msr
Normal file
55
doc/examples/UserFcn/test-asy-MUD.msr
Normal file
@ -0,0 +1,55 @@
|
||||
MgB12H12 No2 ZF T=150
|
||||
###############################################################
|
||||
FITPARAMETER
|
||||
# Nr. Name Value Step Pos_Error Boundaries
|
||||
1 alpha 1 0 none 0 2
|
||||
2 asy 0.1650 0.0027 none 0 0.33
|
||||
3 c0 1.047 0.016 none
|
||||
4 c1 -0.1957 0.0038 none
|
||||
5 c2 0.0216 0.0011 none
|
||||
6 c3 -0.00119 0.00011 none
|
||||
|
||||
###############################################################
|
||||
THEORY
|
||||
asymmetry 2
|
||||
userFcn libPUserFcn PUserFcn 3 4 5 6
|
||||
|
||||
###############################################################
|
||||
RUN data/000100 XXXX TRIUMF MUD (name beamline institute data-file-format)
|
||||
fittype 2 (asymmetry fit)
|
||||
alpha 1
|
||||
map 0 0 0 0 0 0 0 0 0 0 0
|
||||
forward 1
|
||||
backward 2
|
||||
background 79 391 80 409 # estimated bkg: 21.0833 / 17.2249
|
||||
data 438 12785 436 12787
|
||||
t0 432.0 431.0
|
||||
fit 0 8
|
||||
packing 100
|
||||
|
||||
###############################################################
|
||||
COMMANDS
|
||||
MINIMIZE
|
||||
MINOS
|
||||
#HESSE
|
||||
SAVE
|
||||
|
||||
###############################################################
|
||||
FOURIER
|
||||
units Gauss # units either 'Gauss', 'Tesla', 'MHz', or 'Mc/s'
|
||||
fourier_power 12
|
||||
apodization NONE # NONE, WEAK, MEDIUM, STRONG
|
||||
plot POWER # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE
|
||||
phase 8
|
||||
#range_for_phase_correction 50.0 70.0
|
||||
range 0 2000
|
||||
dc-corrected true
|
||||
|
||||
###############################################################
|
||||
PLOT 2 (asymmetry plot)
|
||||
runs 1
|
||||
range 0 9 0 0.22
|
||||
|
||||
###############################################################
|
||||
STATISTIC --- 2016-06-22 09:34:01
|
||||
chisq = 152.4, NDF = 97, chisq/NDF = 1.571461
|
Loading…
x
Reference in New Issue
Block a user