diff --git a/CMakeLists.txt b/CMakeLists.txt index 0975373..522771d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,97 +1,97 @@ # Top level CMakeLists.txt for Laura++ # Enforce an out-of-source build. # Should be the first action in the top level CMakeLists.txt if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(STATUS "Laura++ requires an out-of-source build.") message(STATUS "Please remove these files from ${CMAKE_BINARY_DIR} first:") message(STATUS " CMakeCache.txt") message(STATUS " CMakeFiles") message(STATUS "Once these files are removed, create a separate directory") message(STATUS "and run CMake from there, pointing it to:") message(STATUS " ${CMAKE_SOURCE_DIR}") message(FATAL_ERROR "in-source build detected") endif() # Also require a minimum version of CMake cmake_minimum_required(VERSION 3.12.0) # Project setup project(Laura++ VERSION 3.6.0 DESCRIPTION "A maximum likelihood fitting package for performing Dalitz-plot analysis." HOMEPAGE_URL "https://laura.hepforge.org" ) -# Option to enable/disable compilation of the RooFit slave class -option(LAURA_BUILD_ROOFIT_SLAVE "Enable/disable compilation of RooFit slave class" OFF) +# Option to enable/disable compilation of the RooFit task class +option(LAURA_BUILD_ROOFIT_TASK "Enable/disable compilation of RooFit task class" OFF) # Option to enable/disable building of the Doxygen documentation option(LAURA_BUILD_DOCS "Enable/disable building of Doxygen documentation" OFF) # Options to enable/disable compilation of the example/test executables option(LAURA_BUILD_EXAMPLES "Enable/disable compilation of example executables" OFF) option(LAURA_BUILD_TESTS "Enable/disable compilation of test executables" OFF) -message(STATUS "Laura++: Optional compilation of RooFit slave class LAURA_BUILD_ROOFIT_SLAVE ${LAURA_BUILD_ROOFIT_SLAVE}") +message(STATUS "Laura++: Optional compilation of RooFit task class LAURA_BUILD_ROOFIT_TASK ${LAURA_BUILD_ROOFIT_TASK}") message(STATUS "Laura++: Optional building of Doxygen documentation LAURA_BUILD_DOCS ${LAURA_BUILD_DOCS}") message(STATUS "Laura++: Optional building of example executables LAURA_BUILD_EXAMPLES ${LAURA_BUILD_EXAMPLES}") message(STATUS "Laura++: Optional building of test executables LAURA_BUILD_TESTS ${LAURA_BUILD_TESTS}") # Prepend this project's custom module path(s) to CMAKE_MODULE_PATH set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH}) # Include needed modules and perform any custom setup # Install paths include(GNUInstallDirs) # Compilation/linking flags and related settings include(LauraCompilerFlags) # External dependencies include(LauraExternalDependencies) # Create the documentation if(LAURA_BUILD_DOCS) add_subdirectory(doc) endif() # Install the headers add_subdirectory(inc) # Now build and install the library add_subdirectory(src) # Build and install the executables in the examples directory if(LAURA_BUILD_EXAMPLES) add_subdirectory(examples) endif() if(LAURA_BUILD_TESTS) add_subdirectory(test) endif() # Generate CMake config files, which can be used by other projects include(CMakePackageConfigHelpers) set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) set(DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}) configure_package_config_file(cmake/Templates/LauraConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LauraConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/cmake PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR DATA_INSTALL_DIR ) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/LauraConfigVersion.cmake COMPATIBILITY AnyNewerVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LauraConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/LauraConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/cmake ) install( EXPORT "LauraTargets" NAMESPACE "Laura::" DESTINATION ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/cmake ) diff --git a/README.md b/README.md index b77c73d..904ae6d 100644 --- a/README.md +++ b/README.md @@ -1,474 +1,474 @@ # Laura++ README ## Introduction This package is a C++ development of LAURA, the FORTRAN "Likelihood Analysis Unofficial RooFitDalitz Alternative" code written by Paul Harrison for performing Dalitz plot analyses of 3-body decays of B mesons at BaBar. This C++ version was originally developed by John Back and is now mainly developed by Tom Latham with continuting contributions from John Back and others. ## Structure of the Package The package consists of the following directories and files: ``` laura.git ├── CMakeLists.txt - the top-level CMake configuration file ├── LICENSE-2.0 - the Apache License, Version 2.0 ├── README.md - this README file ├── cmake - directory containing custom CMake modules and templates │   ├── Modules │   │   ├── LauraCompilerFlags.cmake │   │   └── LauraExternalDependencies.cmake │   └── Templates │   └── LauraConfig.cmake.in ├── doc - directory related to building Doxygen documentation │   ├── CMakeLists.txt - CMake configuration file │   ├── Doxyfile.in - Doxygen configuration file │   ├── mainpage.dox.in - front page of the Doxygen documents │   └── ReleaseNotes.md - history of commits to the package ├── examples - directory containing code examples and their associated data files and job scripts │   ├── B3piKMNoAdler.dat │   ├── B3piKMPoles.dat │   ├── B3piKMSVPs.dat │   ├── B3piKMatrixCoeff.dat │   ├── B3piKMatrixMassProj.cc │   ├── B3piKMatrixPlots.cc │   ├── CMakeLists.txt │   ├── CalcChiSq.cc │   ├── DToKspipiKMatrixCoeff.dat │   ├── FOCUSD3pi.dat │   ├── GenFit3K.cc │   ├── GenFit3KS.cc │   ├── GenFit3pi.cc │   ├── GenFit3pi.py │   ├── GenFitBelleCPKpipi.cc │   ├── GenFitDs2KKpi.cc │   ├── GenFitEFKLLM.cc │   ├── GenFitKpipi.cc │   ├── GenFitNoDP.cc │   ├── GenFitNoDPMultiDim.cc │   ├── KMatrixDto3pi.cc │   ├── KMatrixExample.cc │   ├── LauKMatrixCoeff.dat │   ├── LauKMatrixCoeff2.dat -│   ├── Master.cc │   ├── MergeDataFiles.cc │   ├── PlotKMatrixTAmp.cc │   ├── PlotResults.cc │   ├── ResultsExtractor.cc -│   ├── Slave.cc -│   ├── SlaveRooFit.cc +│   ├── SimFitCoordinator.cc +│   ├── SimFitTask.cc +│   ├── SimFitTaskRooFit.cc │   ├── chiSqInput.txt │   ├── mixedSampleTest.cc │   ├── point2PointTestSample.cc -│   ├── runMasterRooFitSlave.sh -│   ├── runMasterSlave.sh +│   ├── runCoordinatorRooFitTask.sh +│   ├── runCoordinatorTask.sh │   ├── runPoint2PointTest.sh │   └── usfactor.dat ├── inc - directory containing the header files for the Laura++ library │   ├── CMakeLists.txt │   ├── Lau1DCubicSpline.hh │   ├── Lau1DHistPdf.hh │   ├── Lau2DAbsDP.hh │   ├── Lau2DAbsDPPdf.hh │   ├── Lau2DAbsHistDP.hh │   ├── Lau2DAbsHistDPPdf.hh │   ├── Lau2DCubicSpline.hh │   ├── Lau2DHistDP.hh │   ├── Lau2DHistDPPdf.hh │   ├── Lau2DHistPdf.hh │   ├── Lau2DSplineDP.hh │   ├── Lau2DSplineDPPdf.hh │   ├── LauAbsBkgndDPModel.hh │   ├── LauAbsCoeffSet.hh │   ├── LauAbsEffModel.hh │   ├── LauAbsFitModel.hh │   ├── LauAbsFitter.hh │   ├── LauAbsIncohRes.hh │   ├── LauAbsModIndPartWave.hh │   ├── LauAbsPdf.hh │   ├── LauAbsRValue.hh │   ├── LauAbsResonance.hh │   ├── LauArgusPdf.hh │   ├── LauAsymmCalc.hh │   ├── LauBelleCPCoeffSet.hh │   ├── LauBelleNR.hh │   ├── LauBelleSymNR.hh │   ├── LauBifurcatedGaussPdf.hh │   ├── LauBkgndDPModel.hh │   ├── LauBlattWeisskopfFactor.hh │   ├── LauBlind.hh │   ├── LauBreitWignerRes.hh │   ├── LauCPFitModel.hh │   ├── LauCacheData.hh │   ├── LauCalcChiSq.hh │   ├── LauCartesianCPCoeffSet.hh │   ├── LauCartesianGammaCPCoeffSet.hh │   ├── LauChebychevPdf.hh │   ├── LauCleoCPCoeffSet.hh │   ├── LauComplex.hh │   ├── LauConstants.hh │   ├── LauCruijffPdf.hh │   ├── LauCrystalBallPdf.hh │   ├── LauDPDepBifurGaussPdf.hh │   ├── LauDPDepCruijffPdf.hh │   ├── LauDPDepGaussPdf.hh │   ├── LauDPDepMapPdf.hh │   ├── LauDPDepSumPdf.hh │   ├── LauDPPartialIntegralInfo.hh │   ├── LauDabbaRes.hh │   ├── LauDatabasePDG.hh │   ├── LauDaughters.hh │   ├── LauEFKLLMRes.hh │   ├── LauEffModel.hh │   ├── LauEmbeddedData.hh │   ├── LauExponentialPdf.hh │   ├── LauFitDataTree.hh │   ├── LauFitNtuple.hh │   ├── LauFitObject.hh │   ├── LauFitter.hh │   ├── LauFlatNR.hh │   ├── LauFlatteRes.hh │   ├── LauFormulaPar.hh │   ├── LauGaussIncohRes.hh │   ├── LauGaussPdf.hh │   ├── LauGenNtuple.hh │   ├── LauGounarisSakuraiRes.hh │   ├── LauIntegrals.hh │   ├── LauIsobarDynamics.hh │   ├── LauKMatrixProdPole.hh │   ├── LauKMatrixProdSVP.hh │   ├── LauKMatrixPropFactory.hh │   ├── LauKMatrixPropagator.hh │   ├── LauKappaRes.hh │   ├── LauKinematics.hh │   ├── LauLASSBWRes.hh │   ├── LauLASSNRRes.hh │   ├── LauLASSRes.hh │   ├── LauLinearPdf.hh │   ├── LauMagPhaseCPCoeffSet.hh │   ├── LauMagPhaseCoeffSet.hh │   ├── LauMergeDataFiles.hh │   ├── LauMinuit.hh │   ├── LauModIndPartWaveMagPhase.hh │   ├── LauModIndPartWaveRealImag.hh │   ├── LauNRAmplitude.hh │   ├── LauNovosibirskPdf.hh │   ├── LauParamFixed.hh │   ├── LauParameter.hh │   ├── LauParametricStepFuncPdf.hh │   ├── LauParticlePDG.hh │   ├── LauPolNR.hh │   ├── LauPolarFormFactorNR.hh │   ├── LauPolarFormFactorSymNR.hh │   ├── LauPolarGammaCPCoeffSet.hh │   ├── LauPoleRes.hh │   ├── LauPrint.hh │   ├── LauRandom.hh │   ├── LauRealImagCPCoeffSet.hh │   ├── LauRealImagCoeffSet.hh │   ├── LauRealImagGammaCPCoeffSet.hh │   ├── LauRelBreitWignerRes.hh │   ├── LauRescattering2Res.hh │   ├── LauRescatteringRes.hh │   ├── LauResonanceInfo.hh │   ├── LauResonanceMaker.hh │   ├── LauResultsExtractor.hh │   ├── LauRhoOmegaMix.hh -│   ├── LauRooFitSlave.hh +│   ├── LauRooFitTask.hh │   ├── LauSPlot.hh │   ├── LauScfMap.hh │   ├── LauSigmaRes.hh │   ├── LauSigmoidPdf.hh -│   ├── LauSimFitMaster.hh -│   ├── LauSimFitSlave.hh +│   ├── LauSimFitCoordinator.hh +│   ├── LauSimFitTask.hh │   ├── LauSimpleFitModel.hh │   ├── LauString.hh │   ├── LauSumPdf.hh │   ├── LauTextFileParser.hh │   ├── LauVetoes.hh │   ├── LauWeightedSumEffModel.hh │   └── Laura++_LinkDef.h ├── macros - directory containing some ROOT macro files for plotting results, etc. │   ├── makeFitFile.C │   ├── plotComplexVars.C │   ├── plotCorrs.C │   ├── plotCorrsFromToy.C │   └── plotDataIsobars.C ├── src - directory containing the source files for the Laura++ library │   ├── CMakeLists.txt │   ├── Lau1DCubicSpline.cc │   ├── Lau1DHistPdf.cc │   ├── Lau2DAbsHistDP.cc │   ├── Lau2DAbsHistDPPdf.cc │   ├── Lau2DCubicSpline.cc │   ├── Lau2DHistDP.cc │   ├── Lau2DHistDPPdf.cc │   ├── Lau2DHistPdf.cc │   ├── Lau2DSplineDP.cc │   ├── Lau2DSplineDPPdf.cc │   ├── LauAbsBkgndDPModel.cc │   ├── LauAbsCoeffSet.cc │   ├── LauAbsFitModel.cc │   ├── LauAbsIncohRes.cc │   ├── LauAbsModIndPartWave.cc │   ├── LauAbsPdf.cc │   ├── LauAbsResonance.cc │   ├── LauArgusPdf.cc │   ├── LauAsymmCalc.cc │   ├── LauBelleCPCoeffSet.cc │   ├── LauBelleNR.cc │   ├── LauBelleSymNR.cc │   ├── LauBifurcatedGaussPdf.cc │   ├── LauBkgndDPModel.cc │   ├── LauBlattWeisskopfFactor.cc │   ├── LauBlind.cc │   ├── LauBreitWignerRes.cc │   ├── LauCPFitModel.cc │   ├── LauCacheData.cc │   ├── LauCalcChiSq.cc │   ├── LauCartesianCPCoeffSet.cc │   ├── LauCartesianGammaCPCoeffSet.cc │   ├── LauChebychevPdf.cc │   ├── LauCleoCPCoeffSet.cc │   ├── LauComplex.cc │   ├── LauCruijffPdf.cc │   ├── LauCrystalBallPdf.cc │   ├── LauDPDepBifurGaussPdf.cc │   ├── LauDPDepCruijffPdf.cc │   ├── LauDPDepGaussPdf.cc │   ├── LauDPDepMapPdf.cc │   ├── LauDPDepSumPdf.cc │   ├── LauDPPartialIntegralInfo.cc │   ├── LauDabbaRes.cc │   ├── LauDatabasePDG.cc │   ├── LauDaughters.cc │   ├── LauEFKLLMRes.cc │   ├── LauEffModel.cc │   ├── LauEmbeddedData.cc │   ├── LauExponentialPdf.cc │   ├── LauFitDataTree.cc │   ├── LauFitNtuple.cc │   ├── LauFitObject.cc │   ├── LauFitter.cc │   ├── LauFlatNR.cc │   ├── LauFlatteRes.cc │   ├── LauFormulaPar.cc │   ├── LauGaussIncohRes.cc │   ├── LauGaussPdf.cc │   ├── LauGenNtuple.cc │   ├── LauGounarisSakuraiRes.cc │   ├── LauIntegrals.cc │   ├── LauIsobarDynamics.cc │   ├── LauKMatrixProdPole.cc │   ├── LauKMatrixProdSVP.cc │   ├── LauKMatrixPropFactory.cc │   ├── LauKMatrixPropagator.cc │   ├── LauKappaRes.cc │   ├── LauKinematics.cc │   ├── LauLASSBWRes.cc │   ├── LauLASSNRRes.cc │   ├── LauLASSRes.cc │   ├── LauLinearPdf.cc │   ├── LauMagPhaseCPCoeffSet.cc │   ├── LauMagPhaseCoeffSet.cc │   ├── LauMergeDataFiles.cc │   ├── LauMinuit.cc │   ├── LauModIndPartWaveMagPhase.cc │   ├── LauModIndPartWaveRealImag.cc │   ├── LauNRAmplitude.cc │   ├── LauNovosibirskPdf.cc │   ├── LauParameter.cc │   ├── LauParametricStepFuncPdf.cc │   ├── LauParticlePDG.cc │   ├── LauPolNR.cc │   ├── LauPolarFormFactorNR.cc │   ├── LauPolarFormFactorSymNR.cc │   ├── LauPolarGammaCPCoeffSet.cc │   ├── LauPoleRes.cc │   ├── LauPrint.cc │   ├── LauRandom.cc │   ├── LauRealImagCPCoeffSet.cc │   ├── LauRealImagCoeffSet.cc │   ├── LauRealImagGammaCPCoeffSet.cc │   ├── LauRelBreitWignerRes.cc │   ├── LauRescattering2Res.cc │   ├── LauRescatteringRes.cc │   ├── LauResonanceInfo.cc │   ├── LauResonanceMaker.cc │   ├── LauResultsExtractor.cc │   ├── LauRhoOmegaMix.cc -│   ├── LauRooFitSlave.cc +│   ├── LauRooFitTask.cc │   ├── LauSPlot.cc │   ├── LauScfMap.cc │   ├── LauSigmaRes.cc │   ├── LauSigmoidPdf.cc -│   ├── LauSimFitMaster.cc -│   ├── LauSimFitSlave.cc +│   ├── LauSimFitCoordinator.cc +│   ├── LauSimFitTask.cc │   ├── LauSimpleFitModel.cc │   ├── LauString.cc │   ├── LauSumPdf.cc │   ├── LauTextFileParser.cc │   ├── LauVetoes.cc │   └── LauWeightedSumEffModel.cc └── test - directory containing code for some test executables ├── CMakeLists.txt ├── TestCovariant.cc ├── TestCovariant2.cc └── TestNewKinematicsMethods.cc ``` ## Building the library ### Prerequisites Compilation of Laura++ on a UNIX operating system requires: * the [CMake](https://www.cmake.org) build tool * a C++14 compatible compiler ([GCC](https://gcc.gnu.org) 8 or better, [Clang](https://clang.llvm.org) 8 or better are recommended) * [GNU Make](https://www.gnu.org/software/make/) or [Ninja](https://ninja-build.org) (not currently tested) The package depends only on [ROOT](https://root.cern.ch). Before building the code, it is necessary that the ROOT package be findable by CMake, which can be achieved by doing one of the following: - the `ROOTSYS` environment variable is set to the directory of the ROOT package - the directory containing the `root-config` program is in the `PATH` environment variable - the ROOT cmake directory is in the `CMAKE_PREFIX_PATH` environment variable In order to setup an environment that satifies all of the above requirements we highly recommend use of the [LCG views](https://lcginfo.cern.ch). For example, on a machine with the [CVMFS client](https://cvmfs.readthedocs.io/en/stable/) installed, one can do: ``` source /cvmfs/sft.cern.ch/lcg/views/setupViews.(c)sh ``` for example: ``` source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_96b x86_64-centos7-gcc9-opt ``` ### Build procedure To build from a clone of this repository, open a terminal window and change directory into that holding this README file. Create a build directory in which to run `cmake` and the build, and change into it by doing the following: ``` $ mkdir ../laura.build $ cd ../laura.build ``` It is best to install the package after building. You can either install into an existing location or you can create an install directory specifically for Laura++ (we assume the latter in the following instructions): ``` $ mkdir ../laura.install ``` Run `cmake` in this directory, pointing it to the directory holding this README, and consequently the top level CMake script for the project: ``` $ cmake ../ -DCMAKE_INSTALL_PREFIX=../laura.install ... system specific output ... -- Configuring done -- Generating done -- Build files have been written to: ... your build dir path ... $ ``` The exact output will depend on your system, compiler and build directory location, but you should not see any errors. CMake will generate Makefiles by default on UNIX platforms, so to build, simply run `make` in the build directory: ``` $ make ... verbose output ... [100%] Built target Laura++ ... $ make install Install the project... ... verbose output ... $ ``` Again, the exact output will be system specific, but you should see the `Laura++` target built without error and that the installation was successful. If compiling with gcc 5, see [the corresponding note](#notes). ## Examples and documentation Example code is included in the examples directory. To enable the building and installation of the example executables you need to supply the following option when running `cmake`: ``` -DLAURA_BUILD_EXAMPLES=ON ``` After building and installing, the example executables will be in the `bin` directory in the install location. To build the Doxygen documentation you need to supply the following option when running `cmake`: ``` -DLAURA_BUILD_DOCS=ON ``` After building and installing, you can load the `share/doc/Laura++/html/index.html` file (found in the install location) into your web browser. ## Building your own code If you wish to build your own code that uses the Laura++ library you should add the Laura++ installation area to the `CMAKE_PREFIX_PATH` environment variable. You can then add lines like the following to your own `CMakeLists.txt` file: ```cmake # Find ROOT and Laura++ find_package(Laura REQUIRED) find_package(ROOT REQUIRED) # Now build the executable add_executable(MyExe MyExe.cc) target_link_libraries(MyExe PRIVATE Laura::Laura++) ``` ## Authors and contributors As mentioned in the Introduction above, the authors of the package are: Thomas Latham John Back Paul Harrison The authors would also like to thank the following people for their invaluable contributions: Sian Morgan Tim Gershon Pablo del Amo Sanchez Jelena Ilic Eugenia Puccio Mark Whitehead Daniel Craik Rafael Coutinho Charlotte Wallace Juan Otalora Wenbin Qian Daniel O'Hanlon Many thanks also go to numerous members of the BaBar, Belle, and LHCb collaborations for their helpful input. Contact: Tom Latham (laura@projects.hepforge.org) ## Notes {#notes} * [It has been reported](https://laura.hepforge.org/trac/ticket/67) that when compiling on Ubuntu 16.04 LTS with gcc 5.4.0 the build will fail due to, apparently spurious, "variable defined but not used" errors related to the constants defined in the `LauConstants.hh` header file. The workaround is to add the option `-Wno-error=unused-variable` to the `CMAKE_CXX_FLAGS` variable in the file: cmake/Modules/LauraCompilerFlags.cmake diff --git a/cmake/Modules/LauraExternalDependencies.cmake b/cmake/Modules/LauraExternalDependencies.cmake index 4a0bfc6..e0a7527 100644 --- a/cmake/Modules/LauraExternalDependencies.cmake +++ b/cmake/Modules/LauraExternalDependencies.cmake @@ -1,32 +1,32 @@ # Laura++ needs ROOT, we just require that it is a version that exports CMake targets properly # We may depend on other things in the future, e.g. JSON or YAML for easier configuration of particle properties etc. if(DEFINED ENV{ROOTSYS}) list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS}) endif() -if(LAURA_BUILD_ROOFIT_SLAVE) +if(LAURA_BUILD_ROOFIT_TASK) find_package(ROOT 6.14 REQUIRED COMPONENTS EG RooFitCore RooFit) else() find_package(ROOT 6.14 REQUIRED COMPONENTS EG) endif() #message(STATUS "ROOT include directories: ${ROOT_INCLUDE_DIRS}") #message(STATUS "ROOT libraries: ${ROOT_LIBRARIES}") #message(STATUS "ROOT definitions: ${ROOT_DEFINITIONS}") #message(STATUS "ROOT CXX flags: ${ROOT_CXX_FLAGS}") #message(STATUS "ROOT CC flags: ${ROOT_CC_FLAGS}") #message(STATUS "ROOT use file: ${ROOT_USE_FILE}") # Don't want to do this because it uses old-style CMake #include(${ROOT_USE_FILE}) if(EXISTS "${ROOT_DIR}/RootMacros.cmake") message(STATUS "Laura++: Including ROOT macros module: ${ROOT_DIR}/RootMacros.cmake") include(${ROOT_DIR}/RootMacros.cmake) elseif(EXISTS "${ROOT_DIR}/modules/RootNewMacros.cmake") message(STATUS "Laura++: Including ROOT macros module: ${ROOT_DIR}/modules/RootNewMacros.cmake") include(${ROOT_DIR}/modules/RootNewMacros.cmake) else() message(WARNING "Laura++: Cannot locate ROOT macros module in ${ROOT_DIR}") endif() diff --git a/doc/ReleaseNotes.md b/doc/ReleaseNotes.md index 7d6f709..929c9ce 100644 --- a/doc/ReleaseNotes.md +++ b/doc/ReleaseNotes.md @@ -1,824 +1,828 @@ # Laura++ release notes +17th September 2020 Mark Whitehead +* Begin updates to use inclusive language. Simultaneous fits now handled by Coordinator and Tasks + - see https://phab.hepforge.org/T112 + 19th August 2020 Thomas Latham * Remove explicit normalisation of numerator Blatt-Weisskopf factors - See https://phab.hepforge.org/T93 22nd May 2020 Thomas Latham * Fix uninitialised variable (related to rho-omega mixin) in LauIsobarDynamics 12th December 2019 Thomas Latham & Daniel Johnson * Fix issue with generation of events for categories with small expected yield - See https://phab.hepforge.org/T76 21st November 2019 Thomas Latham * Add QuasiFlatSqDalitz example, which generates toy according to EvtGen's FLATSQDALITZ model 6th - 20th November 2019 Thomas Latham * Adopt CMake as the build system === ## Laura++ v3r5 6th August 2019 Thomas Latham * Add some extra charmonium states to list of known resonances * Minor modifications to code for importing parameter values from file 17th May 2019 Thomas Latham * Fix licences and Doxygen in pole, nonresonant form factors, and rescattering line shapes * Add journal reference for pole line shape * Fix class names and add Doxygen to LauCalcChiSq, LauResultsExtractor, LauMergeDataFiles * Update Doxyfile from more recent Doxygen version * Make consistent the use of ClassDef and ClassImp everywhere * Add functions to return the "sanitised" names of parent and daughters 8th January 2019 Thomas Latham * Workaround for issue with splitting toy MC files when generating large number of experiments 5th December 2018 Thomas Latham * Move sources and headers for the utilities library into the main library - makes examples dir executables only (in preparation for CMake build) 22nd, 23rd July and 4th August 2018 Juan Otalora * Add pole, nonresonant form factors, and rescattering line shapes 17th April 2018 Daniel O'Hanlon * Fix bug in rho-omega mixing fit-fraction calculation: rho fit-fraction was not normalised to the total DP rate 23rd March 2018 Thomas Latham * Some fixes in LauRhoOmegaMix that propagate the following settings to the subcomponents: - spinType_ - flipHelicity_ - ignoreMomenta_ - ignoreSpin_ - ignoreBarrierScaling_ 23rd February 2018 Thomas Latham * Add section on structure of package to README file (requested by CPC technial editor) * Add copyright notice to files in test directory 21st February 2018 Thomas Latham * Improve comments in functions calculating helicity angles in LauKinematics 19th February 2018 Daniel O'Hanlon * Fix bug in LauCPFitModel introduced in code for importing parameters (25/01/18) - When parameters are asked to be randomised via useRandomInitFitPars, those parameters that were already fixed in the model, in addition to those that are fixed on import, were being freed. 19th February 2018 Daniel O'Hanlon * Bug fixes in rho/omega fit fractions calculation 25th January 2018 Daniel O'Hanlon * Add feature for importing parameters into LauCPFitModels from previous fit output files. 23rd January 2018 Daniel O'Hanlon * Calculate separate rho and omega fit-fractions for LauRhoOmegaMix, when turned on with calculateRhoOmegaFitFractions in LauIsobarDynamics. === ## Laura++ v3r4 16th January 2018 Thomas Latham * Update licence for all files to the Apache Software License Version 2.0 14th December 2017 Thomas Latham * Correct LauFlatteRes to use the exact formulae from the papers that report the default parameter values for each supported resonance - Deals correctly now with the cases where the m0 is absorbed into the couplings - Now uses the correct value of g1 for the a_0(980) (needed to be squared) - Also sets the mass values to those reported in those papers - Added printout to specify what is being done in each case * Improve the consistency between the weightEvents functions in LauSimpleFitModel and LauCPFitModel - Also remove the unecessary division by ASqMax in LauIsobarDynamics::getEventWeight 4th December 2017 Thomas Latham * Allow background yields to be specified as any LauAbsRValue (i.e. LauParameter or now also LauFormulaPar) 30th November 2017 Thomas Latham * In LauFitDataTree::readExperimentData add a check that the tree contains the branch "iExpt" and if not: - If the requested experiment is 0 then read all data in the tree (and print a warning) - Otherwise print an error message and return 29th November 2017 Thomas Latham * Improve error messages in LauCPFitModel::weightEvents === ## Laura++ v3r3 23rd November 2017 Thomas Latham * Add an example written as a python script: GenFit3pi.py * Various improvements to the other example code 23rd November 2017 Thomas Latham * Fix bug in the LauAbsResonance constructor used by the K-matrix - "resonance" charge is now set to the sum of the daughter charges 1st November 2017 Thomas Latham * Fix bug in LauFlatteRes - m_0 factor multiplying the width was, if useAdlerTerm_ is true, replaced by f_Adler rather than being multiplied by it - only affected case where using LauFlatteRes to describe K_0*(1430) === ## Laura++ v3r2 18th October 2017 Thomas Latham * Modify LauDaughters::testDPSymmetry to: - produce an ERROR message and exit if the symmetric DP does not have its daughters arranged correctly - detect also flavour-conjugate DPs and set a corresponding flag that can be retrieved via LauDaughters::gotFlavourConjugateDP - in this case if the daughters are sub-optimally arranged print a WARNING * Modify LauIsobarDynamics::calcDPNormalisationScheme so that any narrow resonance regions are symmetrised appropriately if the DP is fully-symmetric, symmetric or is flavour-conjugate (and in this last case, symmetrisation of the integration has been forced via a new boolean function) 11th October 2017 Thomas Latham * Allow the user to specify the randomiser to be used to randomise the initial values of the isobar parameters - simply use the new static function LauAbsCoeffSet::setRandomiser - if not specified it defaults to the current use of LauRandom::zeroSeedRandom 10th October 2017 Thomas Latham * Make symmetrisation of vetoes automatic in LauVetoes for symmetric DPs - but add new allowed indices (4 and 5) to allow vetoes to be applied to mMin or mMax if desired * Also apply to fully symmetric DPs * In addition implement the more efficient calculation of the amplitude in the fully symmetric case 23rd September 2017 Thomas Latham * Fix expressions for Covariant option for Blatt-Weisskopf momentum for spin > 1 * Make use of setSpinFormalism to set the formalism to Legendre for NR types (instead of kludging with ignoreMomentum) 15th September 2017 Thomas Latham * Various improvements to the examples 6th September 2017 Thomas Latham * Improve doxygen comments for event-embedding functions in fit models 5th September 2017 Thomas Latham * Improve efficiency of Covariant spin factor calculations 31st August 2017 Thomas Latham * Add further option for parent Blatt-Weisskopf momentum - Covariant (corresponding to Covariant spin factor) 8th August 2017 Thomas Latham * Implement expressions for the spin factor based on covariant tensor formalism * Make it much simpler to switch between formalism options via new functions in LauResonanceMaker: - setSpinFormalism, setBWType, setBWBachelorRestFrame - default settings are unchanged (and are equivalent to setting LauAbsResonance::Zemach_P, LauBlattWeisskopfFactor::BWPrimeBarrier, LauBlattWeisskopfFactor::ResonanceFrame, respectively) 21st July 2017 Thomas Latham * Add note to README file about compilation issue on Ubuntu 16.04 LTS 21st July 2017 Thomas Latham * Create public functions to update the kinematics based on one invariant mass and the corresponding helicity angle 20th June 2017 Daniel O'Hanlon * Terminate when asked to read a non-existent K-matrix parameter file 8th June 2017 Thomas Latham * Fix compilation error on gcc 4.9 30th May 2017 Thomas Latham * Permit different efficiency histograms to be defined in classic/square DP and force enable calculation of square DP coords (here and for background PDFs) if required 29th May 2017 Thomas Latham * Propagate information on EDM from the minimiser to the fit models and into the fit results ntuple 29th May 2017 Thomas Latham * Ensure that the kinematics will calculate the square DP co-ordinates if the integration requires them 29th May 2017 Thomas Latham * Reintegrate the RooFit-slave branch into the trunk (and delete the branch) 28th March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Rename cacheFitData to verifyFitData in all fit models and RF-slave 28th March 2017 Daniel O'Hanlon * Fix bug in LauCPFitModel::weightEvents 24th March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Refactor code between fit models, master, slave and fit-object classes 22nd March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Make the compilation of the RF-based slave class, and its associated example binary, optional 22nd March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Complete working example of RooFit-based slave - Have identified some scope for refactoring of code - Also want to make the compilation of this class, and its associated example binary, optional 15th March 2017 Mark Whitehead (in branch for developing time-dependent model) * Handle event-by-event mistag probabilities 7th March 2017 Thomas Latham * Rename the command for weighting events from "reweight" to "weight" 3rd March 2017 Daniel O'Hanlon * Implement LauCPFitModel::weightEvents based on the same function in LauSimpleFitModel 1st March 2017 Thomas Latham (in branch for developing RooFit-based slave) * Fix root-cling related errors 28th February 2017 Thomas Latham (in branch for developing RooFit-based slave) * Start work on creation of RooFit-based slave class - Will allow RooFit-based fitters to plug-in straightforwardly to the simultaneous fitting (JFit) framework 20th February 2017 Thomas Latham * Add warning messages to LauBkgndDPModel::setBkgndHisto when supplied backgroud histogram pointers are null 31st January 2017 Thomas Latham * Audit of the code to automate the creation of the integration binning scheme. - Fix one bug, some tidy-ups, and reintroduce a couple of lost features: - the use of a single square-DP grid if a narrow resonance is found in m12 - extension of region down to threshold if the narrow resonance is close to threshold 22nd January 2017 Daniel O'Hanlon * Fix bug in automated integration scheme where resonances were assumed to have been added in order of ascending mass 14th December 2016 Daniel O'Hanlon * Add several light resonances to the list in LauResonanceMaker 13th December 2016 Daniel O'Hanlon * Automate the determination of the integration scheme for an arbitrary number of narrow resonances in m13 and m23 12th December 2016 Daniel O'Hanlon * Efficiency saving from modifying the behaviour of LauIsobarDynamics::calculateAmplitudes, LauIsobarDynamics::resAmp and LauIsobarDynamics::incohResAmp in the case of symmetric DPs - Previously, there were 2N calls to LauKinematics::flipAndUpdateKinematics for N resonances, now reduced to 2 21st November 2016 John Back * Added two K-matrix examples for creating pedagogical plots (with associated data files): - B3piKMatrixPlots for K-matrix elements, propagator, and pole and SVP production terms - B3piKMatrixMassProj for pole and SVP mass projections generated over the DP 17th November 2016 John Back * Modifications of the K matrix implementation: - Changed the format of the parameter file to use keywords, with updated examples - The scattering coefficients are now symmetrised, unless "ScattSymmetry 0" is used - Allow the option to use the Adler zero suppression term for the production poles and SVPs (default = off). These are specified with the useProdAdler boolean in the LauKMatrixProdPole/SVP constructors - Added a few helper functions for obtaining coefficients and (internal) matrices - Added a method to return the Lorentz-invariant transition amplitude for plots/tests 1st November 2016 Wenbin Qian * Add calculation of so-called covariant factors for spin amplitude === ## Laura++ v3r1 9th September 2016 Thomas Latham * Modification of LauFitNtuple to check the size of the covariance matrix wrt known number of parameters and act accordingly: - If it is empty, just fill a diagonal correlation matrix and issue a warning. - If it results from a failed first stage of a two-stage fit then the correlation matrix is padded with 1s and 0s for the parameters that were fixed in the first stage. * Remove the feature that allows parameters to float in first stage of a two-stage fit but to be fixed in second. * Minor fix to LauAbsCoeffSet: the names of parameters would be mangled if they were the same as the basename, e.g. A1_A would become A1_ while A1_B would be correct. 8th September 2016 Thomas Latham * Modifications to LauResonanceInfo to allow customisation of which extra parameters are shared between charge conjugate or shared-parameter records. - Where the parameters are not shared they are independently created instead of being cloned. * Modification of LauRhoOmegaMix to take advantage of the above to have the magB and phiB parameters independent. * Addition to LauResonanceMaker of rho(770)_COPY record that is a shared record with rho(770) - this allows the above new feature to be used. * Minor unrelated improvement to information messages in LauIsobarDynamics. 25th August 2016 John Back * Modified LauRhoOmegaMix to allow either a RelBW or GS lineshape for the rho, as well as allowing the option to set the second-order denominator term to be equal to unity. Also fixed the bug where the spinTerm was not included in the rho-omega amplitude. Changed the LauAbsResonance enum from RhoOmegaMix to RhoOmegaMix_GS, RhoOmegaMix_RBW, RhoOmegaMix_GS_1 and RhoOmegaMix_RBW_1, where _1 sets the denominator term to unity and _GS or _RBW sets the appropriate rho lineshape. The omega is always a RelBW. * Added to LauAbsResonance: ignoreSpin and ignoreBarrierScaling boolean flags, which ignore either the spin terms or the barrier scaling factors for the amplitude. The latter does not turn off the resonance barrier factor for mass-dependent widths * Added to LauResonanceMaker: getResInfo(resonanceName), which retrieves the resonance information. This is used to obtain the PDG omega values for initialising LauRhoOmegaMix * Made LauRelBreitWignerRes ignore momentum-dependent terms for the resonance width if ignoreMomenta is set. This is used in the LauRhoOmegaMix for the omega lineshape where its width does not depend on momentum 23rd May 2016 John Back * Added new lineshape model for rho-omega mass mixing, LauRhoOmegaMix. 12th April 2016 Thomas Latham * Switch to integrating in square DP when narrow resonances are found in m12. - The integration grid size can be specified by the user 19th January 2016 John Back * Correct the f(m^2) factor in the denominator of the LauGounarisSakuraiRes lineshape to use Gamma_0 instead of Gamma(m) 14th January 2016 Thomas Latham * Documentation improvements 7th December 2015 Thomas Latham * Resolve bug that meant the order of resonances in LauIsobarDynamics was assumed to match with the order in which the complex coefficients are supplied to the fit model - The ordering of resonances is defined by LauIsobarDynamics: - Firstly all coherent resonances in order of addition - Followed by all incoherent resonances in order of addition - The complex coefficients are now rearranged to match that order - Printout of the model summary at the end of initialisation has been enhanced to indicate the ordering - Doxygen updated to reflect these changes 12th November 2015 Daniel Craik * Added support for Akima splines and linear interpolation to Lau1DCubicSpline * LauAbsModIndPartWave, LauModIndPartWaveRealImag and LauModIndPartWaveMagPhase updated to allow choice of spline interpolation method * LauEFKLLMRes updated to use Akima splines 10th November 2015 Thomas Latham & Daniel Craik * Add the EFKLLM form-factor model for the Kpi S-wave and an example using this lineshape * Modify LauResonanceMaker::getResonance to use a switch for greater clarity and easier checking on missing cases 4th November 2015 Daniel Craik * Add checks to LauIsobarDynamics::addResonance and LauIsobarDynamics::addIncohResonance to stop the wrong type of LauResonanceModel being used - LauAbsResonance::isIncoherentModel method added to identify incoherent models 8th September 2015 Mark Whitehead * Add the ability to modify the error of parameters via the CoeffSet - setParameterError added to LauAbsCoeffSet * Tweak the handling of initial error values passed to MINUIT (to determine initial step size) in LauMinuit 7th September 2015 Mark Whitehead * Add the ability to Gaussian constrain parameters via the CoeffSet - addGaussianConstraint added to LauAbsCoeffSet 12th June 2015 Thomas Latham * Modifications to Belle-style nonresonant models - LauBelleNR modified to use pure Legendre polynomials of cos(theta) in the spin term (i.e. to remove the q*p factors) - New form added to LauBelleSymNR (LauAbsResonance::BelleSymNRNoInter) that removes the interference term between the two DP halves - The new form also works with non-zero spin (warning added if non-zero spin specified for BelleSymNR and TaylorNR) 8th June 2015 Thomas Latham * Further work on the blinding mechanism: - New method added LauParameter::blindParameter that activates the blinding. - The rest of the framework updated to use another new method LauParameter::unblindedValue in all likelihood calculations etc. - Example GenFitNoDP updated to include lines to optionally blind the yield parameters. 29th May 2015 Daniel Craik * Added LauBlind class for blinding and unblinding a value with an offset based on a blinding string 26th May 2015 Daniel Craik * Stopped LauCPFitModel passing fixed signal/background yields or asymmetries to Minuit to avoid hitting limit of 101 fixed parameters 22nd April 2015 Daniel Craik * Updated MIPW classes to use Lau1DCubicSpline 19th April 2015 Daniel Craik * Added Lau1DCubicSpline class for 1D spline interpolation 26th March 2015 Thomas Latham * Reworked MIPW code into abstract base class and derived classes to allow different representations of the amplitude at each knot 31st December 2015 Daniel Craik * Added unbinned goodness of fit tests to examples 12th January 2015 Daniel Craik * Calculate effective masses for virtual resonances above the upper kinematic limit 10th December 2014 Daniel Craik * Added coefficient sets to extract gamma from a simultaneous fit to CP and nonCP final states, such as the B0->D_CP K pi and B0->D0bar K pi Dalitz plots, as proposed in Phys. Rev. D79, 051301 (2009) - LauPolarGammaCPCoeffSet uses the CP parameters r, delta and gamma directly - LauRealImagGammaCPCoeffSet parameterises CPV as X_CP+/- and Y_CP+/- - LauCartesianGammaCPCoeffSet parameterises CPV as X_CP, Y_CP DeltaX_CP DeltaY_CP - Fixed CP parameters are not passed to the fitter so the same coefficient sets can be used for both the CP and nonCP Dalitz plots - LauPolarGammaCPCoeffSet allows for a single gamma parameter to be shared between multiple resonances - LauAbsCoeffSet::adjustName made virtual to allow global variables such as gamma to not receive a prefix === ## Laura++ v3r0p1 19th June 2015 Thomas Latham * Factor out the JFit slave code from LauAbsFitModel into a new base class LauSimFitSlave 19th June 2015 Thomas Latham * Fix check in LauIsobarDynamics::calcDPNormalisationScheme to avoid using hardcoded number === ## Laura++ v3r0 24th October 2014 Thomas Latham * Fixed bug in floating of Blatt-Weisskopf barrier radii - The values at the pole mass were not being updated when the radii changed 21st October 2014 Daniel Craik * Fixed bug in LauIsobarDynamics where multiple incoherent amplitudes led to nonsensical fit fractions 17th October 2014 John Back * Added the ability to calculate the transition amplitude matrix T in LauKMatrixPropagator, as well as a few other minor speed-up changes and code checks. Example/PlotKMatrixTAmp.cc can be used to check the T amplitude variation, phase shift and inelasticity, for a given K matrix channel, as a function of the invariant mass squared variable s 15th October 2014 Thomas Latham * Add methods to LauIsobarDynamics to make the integration binning more tunable by the user: - setNarrowResonanceThreshold - modify the value below which a resonance is considered to be narrow (defaults to 0.02 GeV/c2) - setIntegralBinningFactor - modify the factor by which the narrow resonance width is divided to obtain the bin size (defaults to 100) * Print warning messages if the memory usage is likely to be very large 13th October 2014 Thomas Latham * Modify Makefile to allow compilation with ROOT 6 (in addition to maintaining support for ROOT 5) * Fix a few compilation errors on MacOSX 10.9 13th October 2014 Daniel Craik * Update LauModIndPartWave to allow knots at kinematic limits to be modified - Add new method setKnotAmp to modify existing knots (and the knot at the upper kinematic limit which is automatically added at initialisation) * Update doxygen for LauIsobarDynamics::addIncoherentResonance to mention that incoherent resonances must be added last 10th October 2014 Thomas Latham * Add new method to LauResonanceMaker to set whether the radius of a given Blatt-Weisskopf category should be fixed of floated * Modify the methods of LauResonanceMaker to set the radius value and whether it should be floated so that they work before and after the resonances have been created 9th October 2014 John Back * Corrected the eta-eta' and 4pi phase space factors in LauKMatrixPropagator, which is used for the K-matrix amplitude: - calcEtaEtaPRho() does not include the mass difference term m_eta - m_eta' following the recommendation in hep-ph/0204328 and from advice from M Pennington - calcFourPiRho() incorporates a better parameterisation of the double integral of Eq 4 in hep-ph/0204328 which avoids the exponential increase for small values of s (~< 0.1) - More detailed comments are provided in the above two functions to explain what is going on and the reason for the choices made 6th October 2014 Thomas Latham * Implement the mechanism for floating Blatt-Weisskopf barrier factor radius parameters 30th September 2014 Thomas Latham * Fix issue in the checks on toy MC generation validity - in the case of exceeding max iterations it was possible to enter an infinite loop - the checks now detect all three possible states: - aSqMaxSet_ is too low (generation is biased) => increase aSqMaxSet_ value - aSqMaxSet_ is too high => reduce aSqMaxSet_ value to improve efficiency - aSqMaxSet_ is high (causing low efficiency) but cannot be lowered without biasing => increase iterationsMax_ limit * Update resonance parameter in LauResonanceMaker to match PDG 2014 * Modify behaviour when TTree objects are saved into files to avoid having multiple cycle numbers present 29th September 2014 Daniel Craik * Add support for incoherent resonances in the signal model - LauIsobarDynamics updated to include incoherent terms - ABC for incoherent resonances, LauAbsIncohRes, added deriving from LauAbsResonance - LauGaussIncohRes added to implement a Gaussian incoherent resonance, deriving from LauAbsIncohRes - Small changes to various other classes to enable incoherent terms * Fixed small bug in LauMagPhaseCoeffSet which could hang if phase is exactly pi or -pi * Added charged version of the BelleNR resonances to LauResonanceMaker * Updated parameters in LauConstants to match PDG 2014 14th July 2014 Thomas Latham * Add intial support for fully-symmetric final states such as B0 -> KS KS KS - Performs the symmetrisation of the signal model - Background (and efficiency) histogram classes need some work if the user wants to provide folded histograms 8th July 2014 Daniel Craik * Add class for model-independent partial wave - Uses splines to produce a smooth amplitude from a set of magnitude and phase values at given invariant masses - The individual magnitudes and phases can be floated in the fit 16th June 2014 Thomas Latham * Allow floating of resonance parameters in simultaneous fits 13th June 2014 Thomas Latham * Fix bug in LauResonanceInfo cloning method, where the width parameter was given a clone of the mass 10th June 2014 Thomas Latham * Add new function to allow sharing of resonance parameters between components that are not charged conjugates, e.g. LASS_BW and LASS_NR 9th June 2014 Thomas Latham and Daniel Craik * Fix bug in the new integration scheme - Was not accounting for cases where several resonances share a floating parameter - Meant that the integrals and caches for that resonance were not being updated * Introduce a change in the implementation of the helicity flip for neutral parent decays - Prior to this change the helicity was flipped for any neutral resonance in the decay of a neutral particle. - Now the flip no longer occurs in flavour-specific decays (such as Bs0 -> D0bar K- pi+ or B0 -> K+ pi- pi0) since it is only required in flavour-conjugate modes (such as B0 -> KS pi+ pi-). - This does not affect any physical results but it does contribute a pi phase flip to some odd-spin resonances (for example K*(892)0 in Bs0->D0barKpi). - Therefore results are not necessarily comparable between fits run before and after this changeset. - This change will first be released in v3r0. === ## Laura++ v2r2 5th June 2014 Thomas Latham * Fix issue in asymmetric efficiency histogram errors - Fluctuation of bins was incorrectly sampling - assumed area each side of peak was the same 5th June 2014 Thomas Latham (in branch for release in v3r0) * Introduce intelligent calculation of amplitudes during recalculation of integrals and recaching of data points - Floating resonance parameters is now much more efficient * Make resonance parameters second-stage, also improves fit timing when floating them 3rd June 2014 Rafael Coutinho * Implement generation of toy MC from fit results in fitSlave 27th May 2014 Thomas Latham (in branch for release in v3r0) * Complete audit of special functions * Remove unncessary LauAbsDPDynamics base class and move all functionality into LauIsobarDynamics 20th May 2014 Daniel Craik (in branch for release in v3r0) * Add support for K*_0(1430) and a_0(980) to LauFlatteRes 16th-19th May 2014 Thomas Latham and Daniel Craik (in branch for release in v3r0) * Update all other lineshapes so that their parameters can float - The only resonance parameters that now cannot float are the Blatt-Weisskopf barrier factor radii 15th May 2014 Thomas Latham (in branch for release in v3r0) * Change the mechanism for getting floating resonance parameters into the fit - Moved from LauResonanceMaker to the resonances themselves - Lays some groundwork for improving the efficiency of recalculating the integrals - LauBelleNR and LauBelleSymNR lineshape parameters can now be floated 13th May 2014 Daniel Craik (in branch for release in v3r0) * Fix bug where illegal characters were being propagated from resonance names into TBranch names 6th May 2014 Thomas Latham (in branch for release in v3r0) * Provide accessors for mass and width parameters 5th May 2014 Louis Henry * Fix compilation problem by making LauDatabasePDG destructor virtual 4th May 2014 Thomas Latham * Provide a new argument to LauSimpleFitModel::splitSignalComponent and LauCPFitModel::splitSignalComponent to allow fluctuation of the bins on the SCF fraction histogram 29th April 2014 Thomas Latham * Fix bug in the determination of the integration scheme - Nearby narrow resonances caused problems if their "zones" overlap - These zones are now merged together 29th April 2014 Thomas Latham (in branch for release in v3r0) * Some improvments to integration scheme storage 26th April 2014 Juan Otalora (in branch for release in v3r0) * Make integation scheme fixed after first determination - is stored in a new class LauDPPartialIntegralInfo - used on subsequent re-evaluations of the integrals 23rd April 2014 Thomas Latham * Attempt to improve clarity of LauIsobarDynamics::addResonance function - the 3rd argument is now an enumeration of the various resonance models - removed the optional arguments regarding the change of mass, width & spin - the same functionality can be obtained by using the returned pointer and calling changeResonance - the resonance name now only affects the lineshape in the LauPolNR case - the BelleSymNR / TaylorNR choice is now made in the 3rd argument - similarly for the BelleNR / (newly introduced) PowerLawNR choice * Add new PowerLawNR nonresonant model (part of LauBelleNR) * All examples updated to use new interface 23rd April 2014 Thomas Latham * Address issue of setting values of resonance parameters for all models - decided to do away with need to have LauIsobarDynamics know everything - LauIsobarDynamics::addResonance now returns a pointer to LauAbsResonance - parameters can be changed through LauAbsResonance::setResonanceParameter - LauIsobarDynamics still knows about Blatt-Weisskopf factors - better to only need to set this once - Update GenFit3pi example to demonstrate mechanism 22nd April 2014 Thomas Latham * Allow Gaussian constraints to be added in simultaneous fitting - constraints will be ignored by the slaves - those added directly to fit parameters will be propogated to the master and handled there - those on combinations of parameters should be added in the master process 22nd April 2014 Mark Whitehead * Update Laura to cope with resonances of spin 4 and spin 5 - Zemach spin terms added to src/LauAbsResonance.cc - BW barrier factors added to src/LauRelBreitWignerRes.cc 19th April 2014 Daniel Craik * Add LauWeightedSumEffModel which gives an efficiency model from the weighted sum of several LauEffModel objects. * Added pABC, LauAbsEffModel, for LauEffModel and LauWeightedSumEffModel. * Various classes updated to use pointers to LauAbsEffModel instead of LauEffModel. 15th April 2014 Daniel Craik * Enable LauEfficiencyModel to contain several Lau2DAbsDP objects with the total efficiency calculated as the product. 10th April 2014 Mark Whitehead * Fix an issue with the likelihood penalty term for Gaussian constraints - Factor two missing in the denominator - New penalty term is: ( x-mean )^2 / 2*(width^2) 4th April 2014 Thomas Latham * Add storage of fit fractions that have not been efficiency corrected === ## Laura++ v2r1 1st April 2014 Thomas Latham * Fix issue in LauFitter that prevents compilation with g++ 4.8 - Missing virtual destructor - Take opportunity to audit other special functions 31st March 2014 Mark Whitehead (in branch for release in v2r1) * Added an efficiency branch to the ntuple produced for toy data samples - Both LauSimpleFitModel and LauCPFitModel updated 28th March 2014 Daniel Craik (in branch for release in v2r2) * Added support for asymmetric errors to Lau2DHistDP, Lau2DSplineDP and LauEffModel. 27th March 2014 Daniel Craik * Changed histogram classes to use seeded random number generator for fluctuation and raising or lowering of bins and updated doxygen. 20th March 2014 Mark Whitehead (in branch for release in v2r1) * Added the ability to add Gaussian contraints to LauFormulaPars of fit parameters - User supplies the information but the LauFormulaPar is constructed behind the scenes 18th March 2014 Thomas Latham * Improve behaviour of toy generation from fit results 13th March 2014 Juan Otalora (in branch for release in v3r0) * Extended ability to float mass and width to other resonance lineshapes (Flatte, LASS and G-S) 11th March 2014 Mark Whitehead (in branch for release in v2r1) * Added the functionality to make LauFormulaPars usable in fits - Added a new class LauAbsRValue which LauParameter and LauFormularPar inherit from - Many files updated to accept LauAbsRValues instead of LauParameters * Fairly major clean up of obsolete functions in LauAbsPdf - Only LauLinearPdf used any of them, this has now been updated 10th March 2014 Thomas Latham (in branch for release in v3r0) * First attempt at floating resonance parameters (work mostly from Juan) - Only works for RelBW lineshape - Can only float mass and width - Works nicely! - Still needs much work to generalise and make more efficient === ## Laura++ v2r0 8th March 2014 Thomas Latham * Some additional functionality for the CoeffSet classes: - allow the parameter values to be set (optionally setting the initial and generated values as well) - allow the parameters to be set to float or to be fixed in the fit These are needed when cloning but wanting some of the parameters to have different values and/or floating behaviour from the cloned set. * Improve the printout of the setting of the coefficient values in the fit models and the creation of resonances * Add LauFlatNR for the unform NR model - ends its rather strange special treatment * Fix bug setting resAmpInt to 0 for LauPolNR * Many other improvements to the info/warning/error printouts * Modify GenFitBelleCPKpipi example to demonstrate cloning in action * Add -Werror to compiler flags (treats warnings as errors) 5th March 2014 Thomas Latham * Some improvements to LauPolNR to speed up amplitude calculation 2nd March 2014 Thomas Latham * A number of updates to the CoeffSet classes: - allow specification of the basename just after construction (before being given to the fit model) - allow configuration of the parameter fit ranges (through static methods of base class) - more adaptable cloning of the parameters (e.g. can only clone phase but allow magnitude to float independently) - allow CP-violating parameters to be second-stage in Belle and CLEO formats * Some improvements to the Doxygen and runtime information printouts 20th February 2014 Louis Henry * Add LauPolNR - class for modelling the nonresonant contribution based on BaBar 3K model (arXiv:1201.5897) 6th February 2014 Thomas Latham * Correct helicity convention information in Doxygen for LauKinematics === ## Laura++ v1r2 5th February 2014 Thomas Latham * Add rule to the Makefile that creates a rootmap file for the library 4th February 2014 Daniel Craik * Fixed bug in Lau2DSplineDPPdf - normalisation was not being calculated * Added out-of-range warning in LauBkgndDPModel and supressed excessive warnings 3rd February 2014 Mark Whitehead (in branch for release in v2r0) * Added a new class to allow parameters to be a function of other parameters - inc/LauFormulaPar.hh - src/LauFormulaPar.cc 28th January 2014 Daniel Craik * Improved out-of-range efficiency warnings in LauEffModel and supressed excessive errors * Modified LauIsobarDynamics to allow LASS parameters to be configured for LauLASSBWRes and LauLASSNRRes 27th January 2014 Daniel Craik * Added spline interpolation to DP backgrounds - Added Lau2DSplineDPPdf which uses a spline to model a normalised PDF across a DP - Added pABC, Lau2DAbsDPPdf, for Lau2DHistDPPdf and Lau2DSplineDPPdf and moved common code in Lau2DHistDPPdf and Lau2DSplineDPPdf into ABC Lau2DAbsHistDPPdf - LauBkgndDPModel, modified to use Lau2DAbsDPPdf instead of Lau2DHistDPPdf - setBkgndSpline method added to LauBkgndDPModel to allow use of splines 22nd January 2014 Thomas Latham * Improve some error checks and corresponding warning messages in LauCPFitModel::setSignalDPParameters 16th January 2014 Thomas Latham * Add LauRealImagCPCoeffSet, which provides an (x,y), (xbar,ybar) way of parametrising the complex coefficients. * Try to improve timing in the *CoeffSet classes by making the complex coeffs into member variables. 20th December 2013 Daniel Craik * Added Lau2DCubicSpline which provides cubic spline interpolation of a histogram - Added Lau2DSplineDP which uses a spline to model variation across a DP (eg efficiency) - Added pABC, Lau2DAbsDP, for Lau2DHistDP and Lau2DSplineDP and moved common code in Lau2DHistDP and Lau2DSplineDP into ABC Lau2DAbsHistDP - LauEffModel, LauDPDepSumPdf and LauDPDepMapPdf modified to use Lau2DAbsDP instead of Lau2DHistDP - setEffSpline method added to LauEffModel and useSpline flag added to constructor for LauDPDepSumPdf to allow use of splines 18th December 2013 Mark Whitehead (in branch for release in v2r0) * Added functionality to include Gaussian constraints on floated parameters in the fit. The files updated are: - inc/LauAbsFitModel.hh - inc/LauParameter.hh - src/LauAbsFitModel.cc - src/LauParameter.cc 5th December 2013 Thomas Latham * Fix small bug in GenFitKpipi example where background asymmetry parameter had its limits the wrong way around 4th December 2013 Daniel Craik * Updated 2D chi-squared code to use adaptive binning. 3rd December 2013 Thomas Latham * Generalise the Makefile in the examples directory - results in minor changes to the names of 3 of the binaries 3rd December 2013 Thomas Latham (in branch for release in v2r0) * Have the master save an ntuple with all fitter parameters and the full correlation matrix information. 29th November 2013 Thomas Latham * Fixed bug in ResultsExtractor where the output file was not written 29th November 2013 Thomas Latham (in branch for release in v2r0) * Allow the slave ntuples to store the partial covariance matrices in the simultaneous fitting 26th November 2013 Thomas Latham (in branch for release in v2r0) * Added first version of the simultaneous fitting framework === ## Laura++ v1r1p1 22nd November 2013 Thomas Latham * Fixed bug in LauCPFitModel where values of q = -1 extra PDFs were used regardless of the event charge. === ## Laura++ v1r1 20th November 2013 Mark Whitehead * Changed convention for the barrier factors, swapping from p* to p. This seems to give more physically reasonable results. The files updated are: - src/LauGounarisSakuraiRes.cc - src/LauRelBreitWignerRes.cc 18th October 2013 Thomas Latham * Fix dependency problem in Makefile 8th October 2013 Thomas Latham * Some fixes to yield implementation * Minor bug fix in DP background histogram class 7th October 2013 Mark Whitehead * Update to accept the yields and yield asymmetries as LauParameters. All examples have been updated to reflect this change. This updated the following files: - inc/LauCPFitModel.hh - inc/LauSimpleFitModel.hh - inc/LauAbsFitModel.hh - src/LauCPFitModel.cc - src/LauSimpleFitModel.cc * Addition of the following particles to src/LauResonanceMaker.cc Ds*+-, Ds0*(2317)+-, Ds2*(2573)+-, Ds1*(2700)+- and Bs*0 === ## Laura++ v1r0 13th September 2013 Thomas Latham * Initial import of the package into HEPforge diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index adea995..8cec73f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,42 +1,42 @@ list(APPEND EXAMPLE_SOURCES B3piKMatrixMassProj B3piKMatrixPlots CalcChiSq GenFit3K GenFit3KS GenFit3pi GenFitBelleCPKpipi GenFitDs2KKpi GenFitEFKLLM GenFitKpipi GenFitNoDP GenFitNoDPMultiDim KMatrixDto3pi KMatrixExample - Master MergeDataFiles mixedSampleTest PlotKMatrixTAmp PlotResults point2PointTestSample QuasiFlatSqDalitz ResultsExtractor - Slave - SlaveRooFit + SimFitCoordinator + SimFitTask + SimFitTaskRooFit ) -if(NOT LAURA_BUILD_ROOFIT_SLAVE) - list(REMOVE_ITEM EXAMPLE_SOURCES SlaveRooFit) +if(NOT LAURA_BUILD_ROOFIT_TASK) + list(REMOVE_ITEM EXAMPLE_SOURCES SimFitTaskRooFit) endif() foreach( _example ${EXAMPLE_SOURCES}) add_executable(${_example} ${_example}.cc) target_link_libraries(${_example} PRIVATE Laura++) install(TARGETS ${_example} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endforeach() # Also install the python script version of GenFit3pi configure_file(GenFit3pi.py.in GenFit3pi.py @ONLY) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/GenFit3pi.py DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/Master.cc b/examples/SimFitCoordinator.cc similarity index 79% rename from examples/Master.cc rename to examples/SimFitCoordinator.cc index 0ad9ac5..b8efdc4 100644 --- a/examples/Master.cc +++ b/examples/SimFitCoordinator.cc @@ -1,79 +1,79 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TRandom.h" #include "TString.h" #include "TSystem.h" -#include "LauSimFitMaster.hh" +#include "LauSimFitCoordinator.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; - out< [firstExpt = 0] [numSlaves = 2] [port = 0]\n"; + out< [firstExpt = 0] [numTasks = 2] [port = 0]\n"; } int main(const int argc, const char ** argv) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } UInt_t iFit = atoi( argv[1] ); UInt_t nExpt = atoi( argv[2] ); UInt_t firstExpt = 0; - UInt_t nSlaves = 2; + UInt_t nTasks = 2; UInt_t port = 0; Bool_t useAsymmErrors = kFALSE; Bool_t twoStageFit = kFALSE; if ( argc > 3 ) { firstExpt = atoi( argv[3] ); if ( argc > 4 ) { - nSlaves = atoi( argv[4] ); + nTasks = atoi( argv[4] ); if ( argc > 5 ) { port = atoi( argv[5] ); } } } - TString ntupleName = "master-ntuple-"; + TString ntupleName = "coordinator-ntuple-"; ntupleName += iFit; ntupleName += ".root"; - LauSimFitMaster master( nSlaves, port ); - master.runSimFit( ntupleName, nExpt, firstExpt, useAsymmErrors, twoStageFit ); + LauSimFitCoordinator coordinator( nTasks, port ); + coordinator.runSimFit( ntupleName, nExpt, firstExpt, useAsymmErrors, twoStageFit ); return EXIT_SUCCESS; } diff --git a/examples/Slave.cc b/examples/SimFitTask.cc similarity index 94% rename from examples/Slave.cc rename to examples/SimFitTask.cc index 8863a1c..6974754 100644 --- a/examples/Slave.cc +++ b/examples/SimFitTask.cc @@ -1,254 +1,254 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TH2.h" #include "TString.h" #include "TTree.h" #include "LauSimpleFitModel.hh" #include "LauBkgndDPModel.hh" #include "LauDaughters.hh" #include "LauEffModel.hh" #include "LauIsobarDynamics.hh" #include "LauMagPhaseCoeffSet.hh" #include "LauRandom.hh" #include "LauVetoes.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]\n"; out<<"or\n"; out< [hostname] [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] + // ./SimFitTask gen [nExpt = 1] [firstExpt = 0] // or - // ./Slave fit [nExpt = 1] [firstExpt = 0] + // ./SimFitTask fit [nExpt = 1] [firstExpt = 0] if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); TString category = argv[2]; if ( category != "DD" && category != "LL" ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } Int_t iFit(0); UInt_t port(5000); TString hostname("localhost"); Int_t nExpt(1); Int_t firstExpt(0); if ( command == "gen" ) { if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else if ( command == "fit" ) { if ( argc < 5 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } iFit = atoi( argv[3] ); port = atoi( argv[4] ); if ( argc > 5 ) { hostname = argv[5]; if ( argc > 6 ) { nExpt = atoi( argv[6] ); if ( argc > 7 ) { firstExpt = atoi( argv[7] ); } } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } LauRandom::setSeed(0); // If you want to use square DP histograms for efficiency, // backgrounds or you just want the square DP co-ordinates // stored in the toy MC ntuple then set this to kTRUE Bool_t squareDP = kFALSE; // This defines the DP => decay is B0 -> pi0 pi0 K_S0 // Particle 1 = pi0 // Particle 2 = pi0 // Particle 3 = KS_0 // The DP is defined in terms of m13Sq and m23Sq LauDaughters* daughters = new LauDaughters("B0", "pi0", "pi0", "K_S0", squareDP); // Optionally apply some vetoes to the DP LauVetoes* vetoes = new LauVetoes(); // Define the efficiency model (defaults to unity everywhere) // Can optionally provide a histogram to model variation over DP // (example syntax given in commented-out section) LauEffModel* effModel = new LauEffModel(daughters, vetoes); //TFile *effHistFile = TFile::Open("histoFiles/efficiency.root", "read"); //TH2* effHist = dynamic_cast(effHistFile->Get("effHist")); //Bool_t useInterpolation = kTRUE; //Bool_t fluctuateBins = kFALSE; //Bool_t useUpperHalf = kTRUE; //effModel->setEffHisto(effHist, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalf, squareDP); // Create the isobar model LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel); LauAbsResonance* res(0); res = sigModel->addResonance("f_0(980)", 3, LauAbsResonance::Flatte); // resPairAmpInt = 3 => resonance mass is m12. res = sigModel->addResonance("f_2(1270)", 3, LauAbsResonance::RelBW); res = sigModel->addResonance("K*0(892)", 1, LauAbsResonance::RelBW); res->fixMass(kFALSE); res = sigModel->addResonance("K*0_0(1430)", 1, LauAbsResonance::LASS); // Reset the maximum signal DP ASq value // This will be automatically adjusted to avoid bias or extreme // inefficiency if you get the value wrong but best to set this by // hand once you've found the right value through some trial and // error. sigModel->setASqMaxValue(1.25); TString integralsFileName("integ-"); integralsFileName += category; integralsFileName += ".dat"; sigModel->setIntFileName( integralsFileName ); // Create the fit model LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel); // Create the complex coefficients for the isobar model // Here we're using the magnitude and phase form: // c_j = a_j exp(i*delta_j) std::vector coeffset; coeffset.push_back( new LauMagPhaseCoeffSet("f_0(980)", 1.00, 0.00, kTRUE, kTRUE) ); coeffset.push_back( new LauMagPhaseCoeffSet("f_2(1270)", 0.53, 1.39, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0(892)", 0.87, 1.99, kFALSE, kFALSE) ); coeffset.push_back( new LauMagPhaseCoeffSet("K*0_0(1430)", 1.17, -1.59, kFALSE, kFALSE) ); for (std::vector::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) { fitModel->setAmpCoeffSet(*iter); } // Set the signal yield and define whether it is fixed or floated TString sigEventsName = "signalEvents" + category; Double_t nSig(500.0); if ( category == "DD" ) { nSig = 750.0; } LauParameter * nSigEvents = new LauParameter(sigEventsName,nSig,-2.0*nSig,2.0*nSig,kFALSE); fitModel->setNSigEvents(nSigEvents); // Set the number of experiments to generate or fit and which // experiment to start with fitModel->setNExpts( nExpt, firstExpt ); // Optionally load in continuum background DP model histogram // (example syntax given in commented-out section) std::vector bkgndNames(1); bkgndNames[0] = "comb" + category; fitModel->setBkgndClassNames( bkgndNames ); Double_t nBkgnd = 1200.0; if ( category == "DD" ) { nBkgnd = 2500.0; } LauParameter* nBkgndEvents = new LauParameter(bkgndNames[0],nBkgnd,-2.0*nBkgnd,2.0*nBkgnd,kFALSE); fitModel->setNBkgndEvents( nBkgndEvents ); //TString bkgndFileName("histoFiles/bkgndDPs.root"); //TFile* bkgndFile = TFile::Open(bkgndFileName.Data(), "read"); //TH2* bkgndDP = dynamic_cast(bkgndFile->Get("AllmTheta")); // m', theta' LauBkgndDPModel* bkgndModel = new LauBkgndDPModel(daughters, vetoes); //bkgndModel->setBkgndHisto(bkgndDP, useInterpolation, fluctuateBins, useUpperHalf, squareDP); fitModel->setBkgndDPModel( bkgndNames[0], bkgndModel ); // Randomise initial fit values for the signal mode fitModel->useRandomInitFitPars(kTRUE); const Bool_t haveBkgnds = ( fitModel->nBkgndClasses() > 0 ); // Switch on/off Poissonian smearing of total number of events fitModel->doPoissonSmearing(haveBkgnds); // Switch on/off Extended ML Fit option fitModel->doEMLFit(haveBkgnds); // Activate two-stage fit fitModel->twoStageFit(kTRUE); // Generate toy from the fitted parameters //TString fitToyFileName("fitToyMC_"); //fitToyFileName += category; - //fitToyFileName += "-Slave_"; + //fitToyFileName += "-Task_"; //fitToyFileName += iFit; //fitToyFileName += ".root"; //fitModel->compareFitData(100, fitToyFileName); // Write out per-event likelihoods and sWeights //TString splotFileName("splot_"); //splotFileName += category; - //splotFileName += "-Slave_"; + //splotFileName += "-Task_"; //splotFileName += iFit; //splotFileName += ".root"; //fitModel->writeSPlotData(splotFileName, "splot", kFALSE); // Set the names of the files to read/write - TString dataFile("gen-"); dataFile += category; dataFile += "-Slave.root"; + TString dataFile("gen-"); dataFile += category; dataFile += "-Task.root"; TString treeName("genResults"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { - rootFileName = "fit"; rootFileName += category; rootFileName += "-Slave_"; rootFileName += iFit; + rootFileName = "fit"; rootFileName += category; rootFileName += "-Task_"; rootFileName += iFit; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; - tableFileName = "fit"; tableFileName += category; tableFileName += "SlaveResults_"; tableFileName += iFit; + tableFileName = "fit"; tableFileName += category; tableFileName += "TaskResults_"; tableFileName += iFit; } else { rootFileName = "dummy.root"; - tableFileName = "gen"; tableFileName += category; tableFileName += "SlaveResults_"; + tableFileName = "gen"; tableFileName += category; tableFileName += "TaskResults_"; } // Execute the generation/fit if ( command == "fit" ) { - fitModel->runSlave( dataFile, treeName, rootFileName, tableFileName, hostname, port ); + fitModel->runTask( dataFile, treeName, rootFileName, tableFileName, hostname, port ); } else { fitModel->run( command, dataFile, treeName, rootFileName, tableFileName ); } return EXIT_SUCCESS; } diff --git a/examples/SlaveRooFit.cc b/examples/SimFitTaskRooFit.cc similarity index 92% rename from examples/SlaveRooFit.cc rename to examples/SimFitTaskRooFit.cc index 6466821..1df41e0 100644 --- a/examples/SlaveRooFit.cc +++ b/examples/SimFitTaskRooFit.cc @@ -1,170 +1,170 @@ /* Copyright 2017 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "RooRealVar.h" #include "RooGaussian.h" #include "RooAddPdf.h" #include "RooExponential.h" #include "RooDataSet.h" #include "RooArgList.h" #include "RooArgSet.h" #include "TFile.h" #include "TString.h" #include "TTree.h" -#include "LauRooFitSlave.hh" +#include "LauRooFitTask.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [nExpt = 1] [firstExpt = 0]\n"; out<<"or\n"; out< [nExpt = 1] [firstExpt = 0]"< [nExpt = 1] [firstExpt = 0] + // ./SimFitTaskRooFit gen [nExpt = 1] [firstExpt = 0] // or - // ./SlaveRooFit fit [nExpt = 1] [firstExpt = 0] + // ./SimFitTaskRooFit fit [nExpt = 1] [firstExpt = 0] if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } TString command = argv[1]; command.ToLower(); TString category = argv[2]; category.ToUpper(); if ( category != "DD" && category != "LL" ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } UInt_t port(5000); Int_t nExpt(1); Int_t firstExpt(0); if ( command == "gen" ) { if ( argc > 3 ) { nExpt = atoi( argv[3] ); if ( argc > 4 ) { firstExpt = atoi( argv[4] ); } } } else if ( command == "fit" ) { if ( argc < 4 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } port = atoi( argv[3] ); if ( argc > 4 ) { nExpt = atoi( argv[4] ); if ( argc > 5 ) { firstExpt = atoi( argv[5] ); } } } else { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } // Set the names of the files to read/write TString dataFile = TString::Format("data-%s.root",category.Data()); TString treeName("fitTree"); TString rootFileName(""); TString tableFileName(""); if (command == "fit") { rootFileName = "fit"; rootFileName += category; rootFileName += "_expt_"; rootFileName += firstExpt; rootFileName += "-"; rootFileName += (firstExpt+nExpt-1); rootFileName += ".root"; tableFileName = "fitResults"; } else { rootFileName = "dummy.root"; tableFileName = "genResults"; } // Create the RooFit model std::cout << "Building the model..." << std::endl; RooRealVar mB("mB", "m_{B}", 5.150, 5.600, "GeV/c^{2}"); Double_t sig_mb_mean1_value = 5.279; Double_t sig_mb_sigma1_value = 0.02; Double_t sig_mb_sigma2_value = 0.07; if ( category == "DD" ) { sig_mb_sigma1_value *= 1.05; sig_mb_sigma2_value *= 1.05; } Double_t sig_mb_frac_value = 0.90; RooRealVar sig_mb_mean1("sig_mb_mean1", "", sig_mb_mean1_value, 5.200, 5.300); RooRealVar sig_mb_sigma1("sig_mb_sigma1", "", sig_mb_sigma1_value, 0.000, 0.100); RooRealVar sig_mb_sigma2("sig_mb_sigma2", "", sig_mb_sigma2_value, 0.000, 0.200); RooRealVar sig_mb_frac("sig_mb_frac", "", sig_mb_frac_value, 0.000, 1.000); sig_mb_mean1.setConstant(kFALSE); sig_mb_sigma1.setConstant(kTRUE); sig_mb_sigma2.setConstant(kTRUE); sig_mb_frac.setConstant(kTRUE); RooGaussian gauss1( "gauss1", "", mB, sig_mb_mean1, sig_mb_sigma1 ); RooGaussian gauss2( "gauss2", "", mB, sig_mb_mean1, sig_mb_sigma2 ); RooAddPdf sigPDF( "sigPDF", "", gauss1, gauss2, sig_mb_frac ); RooRealVar comb_mb_slope("comb_mb_slope", "", -1.5, -10.0, 2.0); comb_mb_slope.setConstant(kFALSE); RooExponential combPDF( "combPDF", "", mB, comb_mb_slope ); Double_t nSigEvents = 5000.0; if ( category == "DD" ) { nSigEvents *= 1.5; } Double_t nCombBgEvents = 7000.0; if ( category == "DD" ) { nCombBgEvents *= 1.7; } Double_t nTotEvents = nSigEvents + nCombBgEvents; RooRealVar sigYield( "signalEvents"+category, "", nSigEvents, -2.0*nTotEvents, 2.0*nTotEvents ); RooRealVar combYield( "CombinatorialEvents"+category, "", nCombBgEvents, -2.0*nTotEvents, 2.0*nTotEvents ); RooAddPdf model( "model", "", RooArgList( sigPDF, combPDF ), RooArgList( sigYield, combYield ) ); // Execute the generation/fit if ( command == "fit" ) { - // Create the slave instance - LauRooFitSlave fitModel(model, kTRUE, RooArgSet(mB)); - fitModel.runSlave( dataFile, treeName, rootFileName, tableFileName, "localhost", port ); + // Create the task instance + LauRooFitTask fitModel(model, kTRUE, RooArgSet(mB)); + fitModel.runTask( dataFile, treeName, rootFileName, tableFileName, "localhost", port ); } else { std::cerr << "Can't do this yet" << std::endl; //RooDataSet* data = model.generate( RooArgSet(mB), nTotEvents ); } return EXIT_SUCCESS; } diff --git a/examples/runMasterRooFitSlave.sh b/examples/runCoordinatorRooFitTask.sh similarity index 67% rename from examples/runMasterRooFitSlave.sh rename to examples/runCoordinatorRooFitTask.sh index 6bea7bf..ad6b6f0 100755 --- a/examples/runMasterRooFitSlave.sh +++ b/examples/runCoordinatorRooFitTask.sh @@ -1,64 +1,64 @@ #!/bin/bash # Copyright 2017 University of Warwick # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Laura++ package authors: # John Back # Paul Harrison # Thomas Latham if [ $# -lt 1 ] then - echo "Usage: $0 [firstExpt = 0] [numSlaves = 2]" + echo "Usage: $0 [firstExpt = 0] [numTasks = 2]" exit 1 fi nexpt=$1 firstexpt=0 -numslaves=2 +numtasks=2 if [ $# -gt 1 ] then firstexpt=$2 if [ $# -gt 2 ] then - numslaves=$3 + numtasks=$3 fi fi # Do whatever you need to do to setup your ROOT environment # Generate the toy MC #echo "Generating MC" -#./SlaveRooFit gen DD $nexpt $firstexpt > gen-log-DD.out 2>&1 -#./SlaveRooFit gen LL $nexpt $firstexpt > gen-log-LL.out 2>&1 +#./SimFitTaskRooFit gen DD $nexpt $firstexpt > gen-log-DD.out 2>&1 +#./SimFitTaskRooFit gen LL $nexpt $firstexpt > gen-log-LL.out 2>&1 # Do the simultaneous fit -./Master 0 $nexpt $firstexpt $numslaves > master-log.out 2>&1 & +./SimFitCoordinator 0 $nexpt $firstexpt $numtasks > coordinator-log.out 2>&1 & sleep 5 -port=`tail -1 master-log.out | awk '{print $NF}'` +port=`tail -1 coordinator-log.out | awk '{print $NF}'` echo $port -./SlaveRooFit fit DD $port > slave-dd-log.out 2>&1 & +./SimFitTaskRooFit fit DD $port > task-dd-log.out 2>&1 & sleep 1 -./SlaveRooFit fit LL $port > slave-ll-log.out 2>&1 +./SimFitTaskRooFit fit LL $port > task-ll-log.out 2>&1 diff --git a/examples/runMasterSlave.sh b/examples/runCoordinatorTask.sh similarity index 65% rename from examples/runMasterSlave.sh rename to examples/runCoordinatorTask.sh index 0c7468e..5d5de00 100755 --- a/examples/runMasterSlave.sh +++ b/examples/runCoordinatorTask.sh @@ -1,88 +1,88 @@ #!/bin/bash # Copyright 2013 University of Warwick # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Laura++ package authors: # John Back # Paul Harrison # Thomas Latham if [ $# -lt 1 ] then echo "Usage: $0 [firstExpt = 0]" exit 1 fi nexpt=$1 firstexpt=0 -numslaves=2 +numtasks=2 if [ $# -gt 1 ] then firstexpt=$2 fi # Do whatever you need to do to setup your ROOT environment # Generate the toy MC -if [ ! -e gen-DD-Slave.root ] +if [ ! -e gen-DD-Task.root ] then echo "Generating MC for DD category" - ./Slave gen DD $nexpt $firstexpt > gen-log-DD.out 2>&1 + ./SimFitTask gen DD $nexpt $firstexpt > gen-log-DD.out 2>&1 fi -if [ ! -e gen-LL-Slave.root ] +if [ ! -e gen-LL-Task.root ] then echo "Generating MC for LL category" - ./Slave gen LL $nexpt $firstexpt > gen-log-LL.out 2>&1 + ./SimFitTask gen LL $nexpt $firstexpt > gen-log-LL.out 2>&1 fi # Do the simultaneous fit for ifit in `seq 0 19` do echo "Running fit $ifit" - ./Master $ifit $nexpt $firstexpt $numslaves > master-log-$ifit.out 2>&1 & + ./SimFitCoordinator $ifit $nexpt $firstexpt $numtasks > coordinator-log-$ifit.out 2>&1 & sleep 5 - NUMOFLINES=$(wc -l < "master-log-$ifit.out") + NUMOFLINES=$(wc -l < "coordinator-log-$ifit.out") while [ $NUMOFLINES -lt 1 ] do sleep 5 - NUMOFLINES=$(wc -l < "master-log-$ifit.out") + NUMOFLINES=$(wc -l < "coordinator-log-$ifit.out") done - port=`tail -1 master-log-$ifit.out | awk '{print $NF}'` + port=`tail -1 coordinator-log-$ifit.out | awk '{print $NF}'` - ./Slave fit DD $ifit $port localhost > slave-dd-log-$ifit.out 2>&1 & + ./SimFitTask fit DD $ifit $port localhost > task-dd-log-$ifit.out 2>&1 & sleep 1 - ./Slave fit LL $ifit $port localhost > slave-ll-log-$ifit.out 2>&1 + ./SimFitTask fit LL $ifit $port localhost > task-ll-log-$ifit.out 2>&1 done # Extract the best fit echo "Extracting the best fit results" ls fitDD*.root > input-list-DD.txt ls fitLL*.root > input-list-LL.txt -ls master-ntuple-*.root > input-list-master.txt +ls coordinator-ntuple-*.root > input-list-coordinator.txt ./ResultsExtractorMain $nexpt input-list-DD.txt best-fits-DD.root > resultsextractor-DD.out 2>&1 ./ResultsExtractorMain $nexpt input-list-LL.txt best-fits-LL.root > resultsextractor-LL.out 2>&1 -./ResultsExtractorMain $nexpt input-list-master.txt best-fits-master.root > resultsextractor-master.out 2>&1 +./ResultsExtractorMain $nexpt input-list-coordinator.txt best-fits-coordinator.root > resultsextractor-coordinator.out 2>&1 diff --git a/inc/LauAbsFitModel.hh b/inc/LauAbsFitModel.hh index 1c99548..287544e 100644 --- a/inc/LauAbsFitModel.hh +++ b/inc/LauAbsFitModel.hh @@ -1,834 +1,834 @@ /* Copyright 2004 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauAbsFitModel.hh \brief File containing declaration of LauAbsFitModel class. */ /*! \class LauAbsFitModel \brief Abstract interface to the fitting and toy MC model Abstract interface to the fitting and toy MC model Any class inheriting from this must implement the following functions: - cacheInputFitVars() - checkInitFitParams() - finaliseFitResults() - fixdSpeciesNames() - freeSpeciesNames() - genExpt() - getEventSum() - getTotEvtLikelihood() - initialise() - initialiseDPModels() - propagateParUpdates() - recalculateNormalisation() - scfDPSmear() - setAmpCoeffSet() - setNBkgndEvents() - setNSigEvents() - setupBkgndVectors() - setupGenNtupleBranches() - setupSPlotNtupleBranches() - splitSignal() - storePerEvtLlhds() - twodimPDFs() - updateCoeffs() - variableNames() - weightEvents() - writeOutTable() */ #ifndef LAU_ABS_FIT_MODEL #define LAU_ABS_FIT_MODEL #include "TMatrixDfwd.h" #include "TString.h" #include "TStopwatch.h" #include #include #include #include "LauFitObject.hh" #include "LauFormulaPar.hh" -#include "LauSimFitSlave.hh" +#include "LauSimFitTask.hh" // LauSPlot included to get LauSPlot::NameSet typedef #include "LauSPlot.hh" class LauAbsCoeffSet; class LauAbsPdf; class LauFitDataTree; class LauGenNtuple; class LauAbsRValue; class LauParameter; -class LauAbsFitModel : public LauSimFitSlave { +class LauAbsFitModel : public LauSimFitTask { public: //! Constructor LauAbsFitModel(); //! Destructor virtual ~LauAbsFitModel(); //! Is the Dalitz plot term in the likelihood Bool_t useDP() const { return usingDP_; } //! Switch on/off the Dalitz plot term in the Likelihood (allows fits to other quantities, e.g. B mass) /*! \param [in] usingDP the boolean flag */ void useDP(Bool_t usingDP) { usingDP_ = usingDP; } //! Return the flag to store the status of using an sFit or not Bool_t doSFit() const { return doSFit_; } //! Do an sFit (use sWeights to isolate signal decays rather than using background histograms) /*! \param [in] sWeightBranchName name of the branch of the tree containing the sWeights \param [in] scaleFactor scaling factor to get the uncertainties correct */ void doSFit( const TString& sWeightBranchName, Double_t scaleFactor = 1.0 ); //! Determine whether an extended maximum likelihood fit it being performed Bool_t doEMLFit() const {return emlFit_;} //! Choice to perform an extended maximum likelihood fit /*! \param [in] emlFit boolean specifying whether or not to perform the EML */ void doEMLFit(Bool_t emlFit) {emlFit_ = emlFit;} //! Determine whether Poisson smearing is enabled for the toy MC generation Bool_t doPoissonSmearing() const {return poissonSmear_;} //! Turn Poisson smearing (for the toy MC generation) on or off /*! \param [in] poissonSmear boolean specifying whether or not to do Poisson smearing */ void doPoissonSmearing(Bool_t poissonSmear) {poissonSmear_ = poissonSmear;} //! Determine whether embedding of events is enabled in the generation Bool_t enableEmbedding() const {return enableEmbedding_;} //! Turn on or off embedding of events in the generation /*! \param [in] enable boolean specifying whether to embed events */ void enableEmbedding(Bool_t enable) {enableEmbedding_ = enable;} //! Determine whether writing out of the latex table is enabled Bool_t writeLatexTable() const {return writeLatexTable_;} //! Turn on or off the writing out of the latex table /*! \param [in] writeTable boolean specifying whether or not the latex table should be written out */ void writeLatexTable(Bool_t writeTable) {writeLatexTable_ = writeTable;} //! save files containing graphs of the resonance's PDFs Bool_t saveFilePDF() const {return savePDF_;} //! Turn on or off the save of files containing graphs of the resonance's PDFs /*! \param [in] savePDF boolean specifying whether or not the save of files containing graphs of the resonance's PDFs */ void saveFilePDF(Bool_t savePDF) {savePDF_ = savePDF;} //! Set up the sPlot ntuple /*! \param [in] fileName the sPlot file name \param [in] treeName the sPlot tree name \param [in] storeDPEfficiency whether or not to store the efficiency information too \param [in] verbosity define the level of output */ void writeSPlotData(const TString& fileName, const TString& treeName, Bool_t storeDPEfficiency, const TString& verbosity = "q"); //! Determine whether the sPlot data is to be written out Bool_t writeSPlotData() const {return writeSPlotData_;} //! Determine whether the efficiency information should be stored in the sPlot ntuple Bool_t storeDPEff() const {return storeDPEff_;} //! Determine whether the initial values of the fit parameters, in particular the isobar coefficient parameters, are to be randomised Bool_t useRandomInitFitPars() const {return randomFit_;} //! Randomise the initial values of the fit parameters, in particular the isobar coefficient parameters void useRandomInitFitPars(Bool_t boolean) {randomFit_ = boolean;} //! Setup the background class names /*! \param [in] names a vector of all the background names */ virtual void setBkgndClassNames( const std::vector& names ); //! Returns the number of background classes inline UInt_t nBkgndClasses() const {return bkgndClassNames_.size();} //! Set the number of signal events /*! \param [in] nSigEvents contains the signal yield and option to fix it */ virtual void setNSigEvents(LauParameter* nSigEvents) = 0; //! Set the number of background events /*! The name of the parameter must be that of the corresponding background category (so that it can be correctly assigned) \param [in] nBkgndEvents contains the name, yield and option to fix the yield of the background */ virtual void setNBkgndEvents(LauAbsRValue* nBkgndEvents) = 0; //! Set the DP amplitude coefficients /*! The name of the coeffSet must match the name of one of the resonances in the DP model. The supplied order of coefficients will be rearranged to match the order in which the resonances are stored in the dynamics, see LauIsobarDynamics::addResonance. \param [in] coeffSet the set of coefficients */ virtual void setAmpCoeffSet(LauAbsCoeffSet* coeffSet) = 0; //! Specify that a toy MC sample should be created for a successful fit to an experiment /*! Generation uses the fitted parameters so that the user can compare the fit to the data \param [in] toyMCScale the scale factor to get the number of events to generate \param [in] mcFileName the file name where the toy sample will be stored \param [in] tableFileName name of the output tex file \param [in] poissonSmearing turn smearing on or off */ void compareFitData(UInt_t toyMCScale = 10, const TString& mcFileName = "fitToyMC.root", const TString& tableFileName = "fitToyMCTable.tex", Bool_t poissonSmearing = kTRUE); //! Start the toy generation / fitting /*! \param [in] applicationCode specifies what to do, perform a fit ("fit") or generate toy MC ("gen") \param [in] dataFileName the name of the input data file \param [in] dataTreeName the name of the tree containing the data \param [in] histFileName the file name for the output histograms \param [in] tableFileName the file name for the latex output file */ void run(const TString& applicationCode, const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileName = ""); //! This function sets the parameter values from Minuit /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar); //! Calculates the total negative log-likelihood /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! */ virtual Double_t getTotNegLogLikelihood(); //! Set model parameters from a file /*! \param [in] fileName the name of the file with parameters to set \param [in] treeName the name of the tree in the file corresponding to the parameters to set \param [in] fix whether to fix (set constant) the loaded parameters, or leave them floating */ void setParametersFromFile(const TString& fileName, const TString& treeName, const Bool_t fix); //! Set model parameters from a given std::map /*! Only parameters named in the map are imported, all others are set to their values specified in the model configuration. \param [in] parameters map from parameter name to imported value \param [in] fix whether to fix (set constant) the loaded parameters, or leave them floating */ void setParametersFromMap(const std::map& parameters, const Bool_t fix); //! Set named model parameters from a file /*! Identical to setParametersFromFile, but only import parameters named from parameters set. All others are set to their values specified in the model configuration. \param [in] fileName the name of the file with parameters to set \param [in] treeName the name of the tree in the file corresponding to the parameters to set \param [in] parameters the set of parameters to import from the file \param [in] fix whether to fix (set constant) the loaded parameters, or leave them floating */ void setNamedParameters(const TString& fileName, const TString& treeName, const std::set& parameters, const Bool_t fix); //! Set named model parameters from a given std::map, with fallback to those from a file /*! Parameters named in the map are imported with their specified values. All other parameters are set to the values corresponding to the value in the given file. \param [in] fileName the name of the file with parameters to set \param [in] treeName the name of the tree in the file corresponding to the parameters to set \param [in] parameters map from parameter name to imported value (override parameters form the file) \param [in] fix whether to fix (set constant) the loaded parameters, or leave them floating */ void setParametersFileFallback(const TString& fileName, const TString& treeName, const std::map& parameters, const Bool_t fix); protected: // Some typedefs //! List of Pdfs typedef std::vector LauPdfList; //! List of parameter pointers typedef std::vector LauParameterPList; //! List of parameter pointers typedef std::vector LauAbsRValuePList; //! Set of parameter pointers typedef std::set LauParameterPSet; //! List of parameters typedef std::vector LauParameterList; //! A type to store background classes typedef std::map LauBkgndClassMap; //! Clear the vectors containing fit parameters void clearFitParVectors(); //! Clear the vectors containing extra ntuple variables void clearExtraVarVectors(); //! Weighting - allows e.g. MC events to be weighted by the DP model /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the tree containing the data */ virtual void weightEvents( const TString& dataFileName, const TString& dataTreeName ) = 0; //! Generate toy MC /*! \param [in] dataFileName the name of the file where the generated events are stored \param [in] dataTreeName the name of the tree used to store the variables \param [in] histFileName the name of the histogram output file (currently not used) \param [in] tableFileNameBase the name the latex output file */ virtual void generate(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileNameBase); //! The method that actually generates the toy MC events for the given experiment /*! \return the success/failure flag of the generation procedure */ virtual Bool_t genExpt() = 0; //! Perform the total fit /*! \param [in] dataFileName the name of the data file \param [in] dataTreeName the name of the tree containing the data \param [in] histFileName the name of the histogram output file \param [in] tableFileNameBase the name the of latex output file */ void fit(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileNameBase); //! Routine to perform the actual fit for a given experiment void fitExpt(); //! Routine to perform the minimisation /*! \return the success/failure flag of the fit */ Bool_t runMinimisation(); //! Create a toy MC sample from the fitted parameters /*! \param [in] mcFileName the file name where the toy sample will be stored \param [in] tableFileName name of the output tex file */ void createFitToyMC(const TString& mcFileName, const TString& tableFileName); //! Read in the data for the current experiment /*! \return the number of events read in */ virtual UInt_t readExperimentData(); //! Open the input file and verify that all required variables are present /*! \param [in] dataFileName the name of the input file \param [in] dataTreeName the name of the input tree */ virtual Bool_t verifyFitData(const TString& dataFileName, const TString& dataTreeName); //! Cache the input data values to calculate the likelihood during the fit virtual void cacheInputFitVars() = 0; //! Cache the value of the sWeights to be used in the sFit virtual void cacheInputSWeights(); //! Initialise the fit par vectors /*! Each class that inherits from this one must implement this sensibly for all vectors specified in clearFitParVectors, i.e. specify parameter names, initial, min, max and fixed values */ virtual void initialise() = 0; //! Recalculate normalisation the signal DP model(s) virtual void recalculateNormalisation() = 0; //! Initialise the DP models virtual void initialiseDPModels() = 0; /*! For each amp in the fit this function takes its particular parameters and from them calculates the single complex number that is its coefficient. The vector of these coeffs can then be passed to the signal dynamics. */ virtual void updateCoeffs() = 0; //! This function (specific to each model) calculates anything that depends on the fit parameter values virtual void propagateParUpdates() = 0; //! Calculate the sum of the log-likelihood over the specified events /*! \param [in] iStart the event number of the first event to be considered \param [in] iEnd the event number of the final event to be considered */ Double_t getLogLikelihood( UInt_t iStart, UInt_t iEnd ); //! Calculate the penalty terms to the log likelihood from Gaussian constraints Double_t getLogLikelihoodPenalty(); //! Calculates the likelihood for a given event /*! \param [in] iEvt the event number */ virtual Double_t getTotEvtLikelihood(UInt_t iEvt) = 0; //! Returns the sum of the expected events over all hypotheses; used in the EML fit scenario virtual Double_t getEventSum() const = 0; //! Prints the values of all the fit variables for the specified event - useful for diagnostics /*! \param [in] iEvt the event number */ virtual void printEventInfo(UInt_t iEvt) const; //! Same as printEventInfo, but printing out the values of the variables in the fit virtual void printVarsInfo() const; //! Update initial fit parameters if required virtual void checkInitFitParams() = 0; //! Setup saving of fit results to ntuple/LaTeX table etc. /*! \param [in] histFileName the file name for the output histograms \param [in] tableFileName the file name for the latex output file */ virtual void setupResultsOutputs( const TString& histFileName, const TString& tableFileName ); - //! Package the initial fit parameters for transmission to the master + //! Package the initial fit parameters for transmission to the coordinator /*! \param [out] array the array to be filled with the LauParameter objects */ virtual void prepareInitialParArray( TObjArray& array ); //! Perform all finalisation actions /*! - - Receive the results of the fit from the master + - Receive the results of the fit from the coordinator - Perform any finalisation routines - - Package the finalised fit parameters for transmission back to the master + - Package the finalised fit parameters for transmission back to the coordinator \param [in] fitStat the status of the fit, e.g. status code, EDM, NLL - \param [in] parsFromMaster the parameters at the fit minimum + \param [in] parsFromCoordinator the parameters at the fit minimum \param [in] covMat the fit covariance matrix - \param [out] parsToMaster the array to be filled with the finalised LauParameter objects + \param [out] parsToCoordinator the array to be filled with the finalised LauParameter objects */ - virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ); + virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ); //! Write the results of the fit into the ntuple /*! \param [in] tableFileName the structure containing the results of the fit */ virtual void finaliseFitResults(const TString& tableFileName) = 0; //! Save the pdf Plots for all the resonances of experiment number fitExp /*! \param [in] label prefix for the file name to be saved */ virtual void savePDFPlots(const TString& label) = 0; //! Save the pdf Plots for the sum of ressonances correspondint to "sin" of experiment number fitExp /*! \param [in] label prefix for the file name to be saved \param [in] spin spin of the wave to be saved */ virtual void savePDFPlotsWave(const TString& label, const Int_t& spin) = 0; //! Write the latex table /*! \param [in] outputFile the name of the output file */ virtual void writeOutTable(const TString& outputFile) = 0; //! Store the per-event likelihood values virtual void storePerEvtLlhds() = 0; //! Calculate the sPlot data virtual void calculateSPlotData(); //! Make sure all parameters hold their genValue as the current value void setGenValues(); //! Method to set up the storage for background-related quantities called by setBkgndClassNames virtual void setupBkgndVectors() = 0; //! Check if the given background class is in the list /*! \param [in] className the name of the class to check \return true or false */ Bool_t validBkgndClass( const TString& className ) const; //! The number assigned to a background class /*! \param [in] className the name of the class to check \return the background class ID number */ UInt_t bkgndClassID( const TString& className ) const; //! Get the name of a background class from the number /*! \param [in] classID the ID number of the background class \return the class name */ const TString& bkgndClassName( UInt_t classID ) const; //! Setup the generation ntuple branches virtual void setupGenNtupleBranches() = 0; //! Add a branch to the gen tree for storing an integer /*! \param [in] name the name of the branch */ virtual void addGenNtupleIntegerBranch(const TString& name); //! Add a branch to the gen tree for storing a double /*! \param [in] name the name of the branch */ virtual void addGenNtupleDoubleBranch(const TString& name); //! Set the value of an integer branch in the gen tree /*! \param [in] name the name of the branch \param [in] value the value to be stored */ virtual void setGenNtupleIntegerBranchValue(const TString& name, Int_t value); //! Set the value of a double branch in the gen tree /*! \param [in] name the name of the branch \param [in] value the value to be stored */ virtual void setGenNtupleDoubleBranchValue(const TString& name, Double_t value); //! Get the value of an integer branch in the gen tree /*! \param [in] name the name of the branch \return the value of the parameter */ virtual Int_t getGenNtupleIntegerBranchValue(const TString& name) const; //! Get the value of a double branch in the gen tree /*! \param [in] name the name of the branch \return the value of the parameter */ virtual Double_t getGenNtupleDoubleBranchValue(const TString& name) const; //! Fill the gen tuple branches virtual void fillGenNtupleBranches(); //! Setup the branches of the sPlot tuple virtual void setupSPlotNtupleBranches() = 0; //! Add a branch to the sPlot tree for storing an integer /*! \param [in] name the name of the branch */ virtual void addSPlotNtupleIntegerBranch(const TString& name); //! Add a branch to the sPlot tree for storing a double /*! \param [in] name the name of the branch */ virtual void addSPlotNtupleDoubleBranch(const TString& name); //! Set the value of an integer branch in the sPlot tree /*! \param [in] name the name of the branch \param [in] value the value to be stored */ virtual void setSPlotNtupleIntegerBranchValue(const TString& name, Int_t value); //! Set the value of a double branch in the sPlot tree /*! \param [in] name the name of the branch \param [in] value the value to be stored */ virtual void setSPlotNtupleDoubleBranchValue(const TString& name, Double_t value); //! Fill the sPlot tuple virtual void fillSPlotNtupleBranches(); //! Returns the names of all variables in the fit virtual LauSPlot::NameSet variableNames() const = 0; //! Returns the names and yields of species that are free in the fit virtual LauSPlot::NumbMap freeSpeciesNames() const = 0; //! Returns the names and yields of species that are fixed in the fit virtual LauSPlot::NumbMap fixdSpeciesNames() const = 0; //! Returns the species and variables for all 2D PDFs in the fit virtual LauSPlot::TwoDMap twodimPDFs() const = 0; //! Check if the signal is split into well-reconstructed and mis-reconstructed types virtual Bool_t splitSignal() const = 0; //! Check if the mis-reconstructed signal is to be smeared in the DP virtual Bool_t scfDPSmear() const = 0; //! Add parameters of the PDFs in the list to the list of all fit parameters /*! \param [in] pdfList a list of Pdfs \return the number of parameters added */ UInt_t addFitParameters(LauPdfList& pdfList); //! Add parameters to the list of Gaussian constrained parameters void addConParameters(); //! Print the fit parameters for all PDFs in the list /*! \param [in] pdfList a list of Pdfs \param [in] fout the output stream to write to */ void printFitParameters(const LauPdfList& pdfList, std::ostream& fout) const; //! Update the fit parameters for all PDFs in the list /*! \param [in] pdfList a list of Pdfs */ void updateFitParameters(LauPdfList& pdfList); //! Have all PDFs in the list cache the data /*! \param [in] pdfList the list of pdfs \param [in] theData the data from the fit */ void cacheInfo(LauPdfList& pdfList, const LauFitDataTree& theData); //! Calculate the product of the per-event likelihoods of the PDFs in the list /*! \param [in] pdfList the list of pdfs \param [in] iEvt the event number */ Double_t prodPdfValue(LauPdfList& pdfList, UInt_t iEvt); //! Do any of the PDFs have a dependence on the DP? /*! \return the flag to indicated if there is a DP dependence */ Bool_t pdfsDependOnDP() const {return pdfsDependOnDP_;} //! Do any of the PDFs have a dependence on the DP? /*! \param [in] dependOnDP the flag to indicated if there is a DP dependence */ void pdfsDependOnDP(Bool_t dependOnDP) { pdfsDependOnDP_ = dependOnDP; } //! Const access the fit variables const LauParameterPList& fitPars() const {return fitVars_;} //! Access the fit variables LauParameterPList& fitPars() {return fitVars_;} //! Const access the fit variables which affect the DP normalisation const LauParameterPSet& resPars() const {return resVars_;} //! Access the fit variables which affect the DP normalisation LauParameterPSet& resPars() {return resVars_;} //! Const access the extra variables const LauParameterList& extraPars() const {return extraVars_;} //! Access the extra variables LauParameterList& extraPars() {return extraVars_;} //! Const access the Gaussian constrained variables const LauAbsRValuePList& conPars() const {return conVars_;} //! Access the Gaussian constrained variables LauAbsRValuePList& conPars() {return conVars_;} //! Const access the gen ntuple const LauGenNtuple* genNtuple() const {return genNtuple_;} //! Access the gen ntuple LauGenNtuple* genNtuple() {return genNtuple_;} //! Const access the sPlot ntuple const LauGenNtuple* sPlotNtuple() const {return sPlotNtuple_;} //! Access the sPlot ntuple LauGenNtuple* sPlotNtuple() {return sPlotNtuple_;} //! Const access the data store const LauFitDataTree* fitData() const {return inputFitData_;} //! Access the data store LauFitDataTree* fitData() {return inputFitData_;} //! Imported parameters file name TString fixParamFileName_; //! Imported parameters tree name TString fixParamTreeName_; //! Map from imported parameter name to value std::map fixParamMap_; //! Imported parameter names std::set fixParamNames_; //! Whether to fix the loaded parameters (kTRUE) or leave them floating (kFALSE) Bool_t fixParams_; //! The set of parameters that are imported (either from a file or by value) and not // set to be fixed in the fit. In addition to those from fixParamNames_, these // include those imported from a file. std::set allImportedFreeParams_; private: //! Copy constructor (not implemented) LauAbsFitModel(const LauAbsFitModel& rhs); //! Copy assignment operator (not implemented) LauAbsFitModel& operator=(const LauAbsFitModel& rhs); // Various control booleans //! Option to make toy from 1st successful experiment Bool_t compareFitData_; //! Option to output a .C file of PDF's Bool_t savePDF_; //! Option to output a Latex format table Bool_t writeLatexTable_; //! Option to write sPlot data Bool_t writeSPlotData_; //! Option to store DP efficiencies in the sPlot ntuple Bool_t storeDPEff_; //! Option to randomise the initial values of the fit parameters Bool_t randomFit_; //! Option to perform an extended ML fit Bool_t emlFit_; //! Option to perform Poisson smearing Bool_t poissonSmear_; //! Option to enable embedding Bool_t enableEmbedding_; //! Option to include the DP as part of the fit Bool_t usingDP_; //! Option to state if pdfs depend on DP position Bool_t pdfsDependOnDP_; // Info on number of experiments and number of events //! Internal vector of fit parameters LauParameterPList fitVars_; //! Internal set of fit parameters upon which the DP normalisation depends LauParameterPSet resVars_; //! Extra variables that aren't in the fit but are stored in the ntuple LauParameterList extraVars_; //! Internal vectors of Gaussian parameters LauAbsRValuePList conVars_; // Input data and output ntuple //! The input data LauFitDataTree* inputFitData_; //! The generated ntuple LauGenNtuple* genNtuple_; //! The sPlot ntuple LauGenNtuple* sPlotNtuple_; // Background class names //! The background class names LauBkgndClassMap bkgndClassNames_; //! An empty string const TString nullString_; // sFit related variables //! Option to perfom the sFit Bool_t doSFit_; //! The name of the sWeight branch TString sWeightBranchName_; //! The vector of sWeights std::vector sWeights_; //! The sWeight scaling factor Double_t sWeightScaleFactor_; // Fit timers //! The fit timer TStopwatch timer_; //! The total fit timer TStopwatch cumulTimer_; //! The output table name TString outputTableName_; // Comparison toy MC related variables //! The output file name for Toy MC TString fitToyMCFileName_; //! The output table name for Toy MC TString fitToyMCTableName_; //! The scaling factor (toy vs data statistics) UInt_t fitToyMCScale_; //! Option to perform Poisson smearing Bool_t fitToyMCPoissonSmear_; // sPlot related variables //! The name of the sPlot file TString sPlotFileName_; //! The name of the sPlot tree TString sPlotTreeName_; //! Control the verbosity of the sFit TString sPlotVerbosity_; ClassDef(LauAbsFitModel,0) // Abstract interface to fit/toyMC model }; #endif diff --git a/inc/LauRooFitSlave.hh b/inc/LauRooFitTask.hh similarity index 80% rename from inc/LauRooFitSlave.hh rename to inc/LauRooFitTask.hh index b0dc61f..84b627b 100644 --- a/inc/LauRooFitSlave.hh +++ b/inc/LauRooFitTask.hh @@ -1,172 +1,172 @@ /* Copyright 2017 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ -/*! \file LauRooFitSlave.hh - \brief File containing declaration of LauRooFitSlave class. +/*! \file LauRooFitTask.hh + \brief File containing declaration of LauRooFitTask class. */ -/*! \class LauRooFitSlave - \brief A class for creating a RooFit-based slave process for simultaneous/combined fits +/*! \class LauRooFitTask + \brief A class for creating a RooFit-based task process for simultaneous/combined fits Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. */ -#ifndef LAU_ROO_FIT_SLAVE -#define LAU_ROO_FIT_SLAVE +#ifndef LAU_ROO_FIT_TASK +#define LAU_ROO_FIT_TASK #include #include #include "RooAbsPdf.h" #include "RooAbsData.h" #include "RooCategory.h" #include "RooNLLVar.h" #include "TMatrixDfwd.h" #include "TString.h" -#include "LauSimFitSlave.hh" +#include "LauSimFitTask.hh" class LauParameter; -class LauRooFitSlave : public LauSimFitSlave { +class LauRooFitTask : public LauSimFitTask { public: //! Constructor - LauRooFitSlave( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName = "" ); + LauRooFitTask( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName = "" ); //! Destructor - virtual ~LauRooFitSlave(); + virtual ~LauRooFitTask(); //! Initialise the fit model virtual void initialise(); //! This function sets the parameter values from Minuit /*! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar); //! Calculates the total negative log-likelihood virtual Double_t getTotNegLogLikelihood(); protected: - //! Package the initial fit parameters for transmission to the master + //! Package the initial fit parameters for transmission to the coordinator /*! \param [out] array the array to be filled with the LauParameter objects */ virtual void prepareInitialParArray( TObjArray& array ); //! Convert a RooRealVar into a LauParameter /*! \param [in] rooParameter the RooRealVar to be converted \return the newly created LauParameter */ LauParameter* convertToLauParameter( const RooRealVar* rooParameter ) const; //! Convert a RooFormulaVar into LauParameters /*! \param [in] rooFormula the RooFormulaVar to be converted \return the vector of pointers to the RooRealVars and newly created LauParameters */ std::vector< std::pair > convertToLauParameters( const RooFormulaVar* rooFormula ) const; //! Perform all finalisation actions /*! - - Receive the results of the fit from the master + - Receive the results of the fit from the coordinator - Perform any finalisation routines - - Package the finalised fit parameters for transmission back to the master + - Package the finalised fit parameters for transmission back to the coordinator \param [in] fitStat the status of the fit, e.g. status code, EDM, NLL - \param [in] parsFromMaster the parameters at the fit minimum + \param [in] parsFromCoordinator the parameters at the fit minimum \param [in] covMat the fit covariance matrix - \param [out] parsToMaster the array to be filled with the finalised LauParameter objects + \param [out] parsToCoordinator the array to be filled with the finalised LauParameter objects */ - virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ); + virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ); //! Open the input file and verify that all required variables are present /*! \param [in] dataFileName the name of the input file \param [in] dataTreeName the name of the input tree */ virtual Bool_t verifyFitData(const TString& dataFileName, const TString& dataTreeName); //! Read in the data for the current experiment /*! \return the number of events read in */ virtual UInt_t readExperimentData(); //! Cache the input data values to calculate the likelihood during the fit virtual void cacheInputFitVars(); private: //! Cleanup the data void cleanData(); //! Copy constructor (not implemented) - LauRooFitSlave(const LauRooFitSlave& rhs); + LauRooFitTask(const LauRooFitTask& rhs); //! Copy assignment operator (not implemented) - LauRooFitSlave& operator=(const LauRooFitSlave& rhs); + LauRooFitTask& operator=(const LauRooFitTask& rhs); //! The model RooAbsPdf& model_; //! The dataset variables RooArgSet dataVars_; //! The name of the (optional) weight variable in the dataset TString weightVarName_; //! The data file TFile* dataFile_; //! The data tree TTree* dataTree_; //! The data for the current experiment RooAbsData* exptData_; //! Is the PDF extended? const Bool_t extended_; //! The experiment category variable RooCategory iExptCat_; //! The NLL variable RooNLLVar* nllVar_; //! The fit parameters (as RooRealVar's) std::vector fitVars_; //! The fit parameters (as LauParameter's) std::vector fitPars_; - ClassDef(LauRooFitSlave,0); + ClassDef(LauRooFitTask,0); }; #endif diff --git a/inc/LauSimFitMaster.hh b/inc/LauSimFitCoordinator.hh similarity index 70% rename from inc/LauSimFitMaster.hh rename to inc/LauSimFitCoordinator.hh index 1d1d211..533784a 100644 --- a/inc/LauSimFitMaster.hh +++ b/inc/LauSimFitCoordinator.hh @@ -1,235 +1,235 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ -/*! \file LauSimFitMaster.hh - \brief File containing declaration of LauSimFitMaster class. +/*! \file LauSimFitCoordinator.hh + \brief File containing declaration of LauSimFitCoordinator class. */ -/*! \class LauSimFitMaster - \brief The master process for simultaneous/combined fits +/*! \class LauSimFitCoordinator + \brief The coordinator process for simultaneous/combined fits Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. - This class acts as the interface between the slave processes and the minimiser. + This class acts as the interface between the task processes and the minimiser. */ -#ifndef LAU_SIM_FIT_MASTER -#define LAU_SIM_FIT_MASTER +#ifndef LAU_SIM_FIT_COORDINATOR +#define LAU_SIM_FIT_COORDINATOR #include #include #include "TMatrixD.h" #include "TStopwatch.h" #include "TString.h" #include "LauFitObject.hh" class TMessage; class TMonitor; class TSocket; class LauAbsRValue; class LauParameter; class LauFitNtuple; -class LauSimFitMaster : public LauFitObject { +class LauSimFitCoordinator : public LauFitObject { public: //! Constructor /*! - \param [in] numSlaves the number of slaves processes to expect connections from - \param [in] port the port on which to listen for connections from the slaves + \param [in] numTasks the number of tasks processes to expect connections from + \param [in] port the port on which to listen for connections from the tasks */ - LauSimFitMaster( UInt_t numSlaves, UInt_t port = 9090 ); + LauSimFitCoordinator( UInt_t numTasks, UInt_t port = 9090 ); //! Destructor - virtual ~LauSimFitMaster(); + virtual ~LauSimFitCoordinator(); //! Run the fit /*! \param [in] fitNtupleFileName the file to which the ntuple containing the fit results should be written \param [in] nExp the number of experiments to be fitted \param [in] firstExp the ID of the first experiment to be fitted \param [in] useAsymmErrors should asymmetric errors be calculated or not \param [in] doTwoStageFit should the fit be performed in two stages or not */ void runSimFit( const TString& fitNtupleFileName, const UInt_t nExp, const UInt_t firstExp = 0, const Bool_t useAsymmErrors = kFALSE, const Bool_t doTwoStageFit = kFALSE ); //! Mark that the fit is calculating asymmetric errors /*! This function has to be public since it is called by the fitter interface to mark when entering and exiting the asymmetric error calculation. It should not be called otherwise! \param [in] inAsymErrCalc boolean marking that the fit is calculating the asymmetric errors */ virtual void withinAsymErrorCalc(const Bool_t inAsymErrCalc); // Need to unshadow the query method defined in the base class using LauFitObject::withinAsymErrorCalc; //! This function sets the parameter values from Minuit /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar); //! Calculate the new value of the negative log likelihood /*! This function has to be public since it is called from the global FCN. It should not be called otherwise! */ virtual Double_t getTotNegLogLikelihood(); protected: //! Print information on the parameters void printParInfo() const; //! Initialise void initialise(); - //! Initialise socket connections for the slaves + //! Initialise socket connections for the tasks void initSockets(); - //! Determine/update the parameter initial values from all slaves - void getParametersFromSlaves(); + //! Determine/update the parameter initial values from all tasks + void getParametersFromTasks(); - //! Determine the parameter names and initial values from all slaves - void getParametersFromSlavesFirstTime(); + //! Determine the parameter names and initial values from all tasks + void getParametersFromTasksFirstTime(); - //! Update and verify the parameter initial values from all slaves - void updateParametersFromSlaves(); + //! Update and verify the parameter initial values from all tasks + void updateParametersFromTasks(); //! Check for compatibility between two same-named parameters, which should therefore be identical void checkParameter( const LauParameter* param, UInt_t index ) const; //! Add parameters to the list of Gaussian constrained parameters void addConParameters(); //! Calculate the penalty terms to the log likelihood from Gaussian constraints Double_t getLogLikelihoodPenalty(); - //! Instruct the slaves to read the input data for the given experiment + //! Instruct the tasks to read the input data for the given experiment /*! \return success/failure of the reading operations */ Bool_t readData(); - //! Instruct the slaves to perform the caching + //! Instruct the tasks to perform the caching /*! \return success/failure of the caching operations */ Bool_t cacheInputData(); //! Perform the fit for the current experiment void fitExpt(); - //! Instruct the slaves to update the initial fit parameter values, if required + //! Instruct the tasks to update the initial fit parameter values, if required void checkInitFitParams(); - //! Return the final parameters to the slaves and instruct them to perform their finalisation + //! Return the final parameters to the tasks and instruct them to perform their finalisation Bool_t finalise(); - //! Instruct the slaves to write out the fit results + //! Instruct the tasks to write out the fit results Bool_t writeOutResults(); private: //! Copy constructor (not implemented) - LauSimFitMaster(const LauSimFitMaster& rhs); + LauSimFitCoordinator(const LauSimFitCoordinator& rhs); //! Copy assignment operator (not implemented) - LauSimFitMaster& operator=(const LauSimFitMaster& rhs); + LauSimFitCoordinator& operator=(const LauSimFitCoordinator& rhs); //! Store the constraints for fit parameters until initialisation is complete std::vector storeCon_; - //! The number of slaves - const UInt_t nSlaves_; + //! The number of tasks + const UInt_t nTasks_; //! The requested port const UInt_t reqPort_; - //! The covariance sub-matrices for each slave + //! The covariance sub-matrices for each task std::vector covMatrices_; //! Parallel setup monitor TMonitor* socketMonitor_; - //! Sockets for each of the slaves - std::vector sSlaves_; + //! Sockets for each of the tasks + std::vector socketTasks_; - //! Messages to slaves - std::vector messagesToSlaves_; + //! Messages to tasks + std::vector messagesToTasks_; - //! Message from slaves to the master - TMessage* messageFromSlave_; + //! Message from tasks to the coordinator + TMessage* messageFromTask_; //! Map of parameter names to index in the values vector std::map< TString, UInt_t > parIndices_; //! Reverse map of index in the values vector to parameter names std::map< UInt_t, TString > parNames_; //! Parameters std::vector params_; //! Gaussian constraints std::vector conVars_; //! Parameter values std::vector parValues_; - //! Lists of indices for each slave - std::vector< std::vector > slaveIndices_; + //! Lists of indices for each task + std::vector< std::vector > taskIndices_; - //! Lists of indices of free parameters for each slave - std::vector< std::vector > slaveFreeIndices_; + //! Lists of indices of free parameters for each task + std::vector< std::vector > taskFreeIndices_; - //! Parameter values to send to the slaves + //! Parameter values to send to the tasks std::vector vectorPar_; - //! Likelihood values returned from the slaves + //! Likelihood values returned from the tasks std::vector vectorRes_; //! The fit timer TStopwatch timer_; //! The total fit timer TStopwatch cumulTimer_; //! The fit results ntuple LauFitNtuple* fitNtuple_; - ClassDef(LauSimFitMaster,0); + ClassDef(LauSimFitCoordinator,0); }; #endif diff --git a/inc/LauSimFitSlave.hh b/inc/LauSimFitTask.hh similarity index 64% rename from inc/LauSimFitSlave.hh rename to inc/LauSimFitTask.hh index 6a7cd28..1441807 100644 --- a/inc/LauSimFitSlave.hh +++ b/inc/LauSimFitTask.hh @@ -1,190 +1,190 @@ /* Copyright 2015 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ -/*! \file LauSimFitSlave.hh - \brief File containing declaration of LauSimFitSlave class. +/*! \file LauSimFitTask.hh + \brief File containing declaration of LauSimFitTask class. */ -/*! \class LauSimFitSlave - \brief The base class for any slave process for simultaneous/combined fits +/*! \class LauSimFitTask + \brief The base class for any task process for simultaneous/combined fits Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. - This class acts as the base class from which slaves should inherit. + This class acts as the base class from which tasks should inherit. This allows any fitting framework to plug in to the JFit method. */ -#ifndef LAU_SIM_FIT_SLAVE -#define LAU_SIM_FIT_SLAVE +#ifndef LAU_SIM_FIT_TASK +#define LAU_SIM_FIT_TASK #include "TMatrixDfwd.h" #include "LauFitObject.hh" class TMessage; class TSocket; class TString; class LauFitNtuple; -class LauSimFitSlave : public LauFitObject { +class LauSimFitTask : public LauFitObject { public: //! Constructor - LauSimFitSlave(); + LauSimFitTask(); //! Destructor - virtual ~LauSimFitSlave(); + virtual ~LauSimFitTask(); - //! Obtain the number of slaves - UInt_t nSlaves() const {return nSlaves_;} + //! Obtain the number of tasks + UInt_t nTasks() const {return nTasks_;} - //! Obtain the ID number of this slave - UInt_t slaveId() const {return slaveId_;} + //! Obtain the ID number of this task + UInt_t taskId() const {return taskId_;} - //! Start the slave process for simultaneous fitting + //! Start the task process for simultaneous fitting /*! \param [in] dataFileName the name of the input data file \param [in] dataTreeName the name of the tree containing the data \param [in] histFileName the file name for the output histograms \param [in] tableFileName the file name for the latex output file - \param [in] addressMaster the hostname of the machine running the master process - \param [in] portMaster the port number on which the master process is listening + \param [in] addressCoordinator the hostname of the machine running the coordinator process + \param [in] portCoordinator the port number on which the coordinator process is listening */ - virtual void runSlave(const TString& dataFileName, const TString& dataTreeName, + virtual void runTask(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileName = "", - const TString& addressMaster = "localhost", const UInt_t portMaster = 9090); + const TString& addressCoordinator = "localhost", const UInt_t portCoordinator = 9090); //! Initialise the fit model /*! Each class that inherits from this one must implement this to do what is appropriate */ virtual void initialise() = 0; //! This function sets the parameter values from Minuit /*! \param [in] par an array storing the various parameter values \param [in] npar the number of free parameters */ virtual void setParsFromMinuit(Double_t* par, Int_t npar) = 0; //! Calculates the total negative log-likelihood virtual Double_t getTotNegLogLikelihood() = 0; protected: //! Const access to the fit ntuple const LauFitNtuple* fitNtuple() const {return fitNtuple_;} //! Access to the fit ntuple LauFitNtuple* fitNtuple() {return fitNtuple_;} - //! Establish the connection to the master process + //! Establish the connection to the coordinator process /*! - \param [in] addressMaster the hostname of the machine running the master process - \param [in] portMaster the port number on which the master process is listening + \param [in] addressCoordinator the hostname of the machine running the coordinator process + \param [in] portCoordinator the port number on which the coordinator process is listening */ - void connectToMaster( const TString& addressMaster, const UInt_t portMaster ); + void connectToCoordinator( const TString& addressCoordinator, const UInt_t portCoordinator ); - //! Listen for requests from the master and act accordingly - void processMasterRequests(); + //! Listen for requests from the coordinator and act accordingly + void processCoordinatorRequests(); //! Setup saving of fit results to ntuple/LaTeX table etc. /*! Provide here a default implementation that produces an ntuple only. Derived classes can override as they wish. \param [in] histFileName the file name for the output histograms \param [in] tableFileName the file name for the latex output file */ virtual void setupResultsOutputs( const TString& histFileName, const TString& tableFileName ); - //! Package the initial fit parameters for transmission to the master + //! Package the initial fit parameters for transmission to the coordinator /*! \param [out] array the array to be filled with the LauParameter objects */ virtual void prepareInitialParArray( TObjArray& array ) = 0; //! Perform all finalisation actions /*! - - Receive the results of the fit from the master + - Receive the results of the fit from the coordinator - Perform any finalisation routines - - Package the finalised fit parameters for transmission back to the master + - Package the finalised fit parameters for transmission back to the coordinator \param [in] fitStat the status of the fit, e.g. status code, EDM, NLL - \param [in] parsFromMaster the parameters at the fit minimum + \param [in] parsFromCoordinator the parameters at the fit minimum \param [in] covMat the fit covariance matrix - \param [out] parsToMaster the array to be filled with the finalised LauParameter objects + \param [out] parsToCoordinator the array to be filled with the finalised LauParameter objects */ - virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ) = 0; + virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) = 0; //! Open the input file and verify that all required variables are present /*! \param [in] dataFileName the name of the input file \param [in] dataTreeName the name of the input tree */ virtual Bool_t verifyFitData(const TString& dataFileName, const TString& dataTreeName) = 0; //! Read in the data for the current experiment /*! \return the number of events read in */ virtual UInt_t readExperimentData() = 0; //! Cache the input data values to calculate the likelihood during the fit virtual void cacheInputFitVars() = 0; //! Write out any fit results virtual void writeOutAllFitResults(); private: //! Copy constructor (not implemented) - LauSimFitSlave(const LauSimFitSlave& rhs); + LauSimFitTask(const LauSimFitTask& rhs); //! Copy assignment operator (not implemented) - LauSimFitSlave& operator=(const LauSimFitSlave& rhs); + LauSimFitTask& operator=(const LauSimFitTask& rhs); //! A socket to enable parallel setup - TSocket* sMaster_; + TSocket* socketCoordinator_; - //! Message from master to the slaves - TMessage* messageFromMaster_; + //! Message from coordinator to the tasks + TMessage* messageFromCoordinator_; - //! Slave id number - UInt_t slaveId_; + //! Task id number + UInt_t taskId_; - //! The total number of slaves - UInt_t nSlaves_; + //! The total number of tasks + UInt_t nTasks_; - //! Parameter values array (for reading from the master) + //! Parameter values array (for reading from the coordinator) Double_t* parValues_; //! The fit ntuple LauFitNtuple* fitNtuple_; - ClassDef(LauSimFitSlave,0); + ClassDef(LauSimFitTask,0); }; #endif diff --git a/inc/Laura++_LinkDef.h b/inc/Laura++_LinkDef.h index 4f3296b..46826db 100644 --- a/inc/Laura++_LinkDef.h +++ b/inc/Laura++_LinkDef.h @@ -1,155 +1,155 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #ifdef __CINT__ #pragma link off all globals; #pragma link off all classes; #pragma link off all functions; #pragma link C++ class Lau1DCubicSpline+; #pragma link C++ class Lau1DHistPdf+; #pragma link C++ class Lau2DAbsDP+; #pragma link C++ class Lau2DAbsDPPdf+; #pragma link C++ class Lau2DAbsHistDP+; #pragma link C++ class Lau2DAbsHistDPPdf+; #pragma link C++ class Lau2DCubicSpline+; #pragma link C++ class Lau2DHistDP+; #pragma link C++ class Lau2DHistDPPdf+; #pragma link C++ class Lau2DHistPdf+; #pragma link C++ class Lau2DSplineDP+; #pragma link C++ class Lau2DSplineDPPdf+; #pragma link C++ class LauAbsBkgndDPModel+; #pragma link C++ class LauAbsCoeffSet+; #pragma link C++ class LauAbsEffModel+; #pragma link C++ class LauAbsFitter+; #pragma link C++ class LauAbsFitModel+; #pragma link C++ class LauAbsIncohRes+; #pragma link C++ class LauAbsModIndPartWave+; #pragma link C++ class LauAbsPdf+; #pragma link C++ class LauAbsResonance+; #pragma link C++ class LauAbsRValue+; #pragma link C++ class LauArgusPdf+; #pragma link C++ class LauAsymmCalc+; #pragma link C++ class LauBelleCPCoeffSet+; #pragma link C++ class LauBelleNR+; #pragma link C++ class LauBelleSymNR+; #pragma link C++ class LauBifurcatedGaussPdf+; #pragma link C++ class LauBkgndDPModel+; #pragma link C++ class LauBlattWeisskopfFactor+; #pragma link C++ class LauBlind+; #pragma link C++ class LauBreitWignerRes+; #pragma link C++ class LauCacheData+; #pragma link C++ class LauCalcChiSq+; #pragma link C++ class LauCartesianCPCoeffSet+; #pragma link C++ class LauCartesianGammaCPCoeffSet+; #pragma link C++ class LauChebychevPdf+; #pragma link C++ class LauCleoCPCoeffSet+; #pragma link C++ class LauComplex+; #pragma link C++ class LauCPFitModel+; #pragma link C++ class LauCruijffPdf+; #pragma link C++ class LauCrystalBallPdf+; #pragma link C++ class LauDabbaRes+; #pragma link C++ class LauDatabasePDG+; #pragma link C++ class LauDaughters+; #pragma link C++ class LauDPDepBifurGaussPdf+; #pragma link C++ class LauDPDepCruijffPdf+; #pragma link C++ class LauDPDepGaussPdf+; #pragma link C++ class LauDPDepMapPdf+; #pragma link C++ class LauDPDepSumPdf+; #pragma link C++ class LauEffModel+; #pragma link C++ class LauEFKLLMRes+; #pragma link C++ class LauEmbeddedData+; #pragma link C++ class LauExponentialPdf+; #pragma link C++ class LauFitDataTree+; #pragma link C++ class LauFitNtuple+; #pragma link C++ class LauFitter+; #pragma link C++ class LauFitObject+; #pragma link C++ class LauFlatteRes+; #pragma link C++ class LauFlatNR+; #pragma link C++ class LauFormulaPar+; #pragma link C++ class LauGaussIncohRes+; #pragma link C++ class LauGaussPdf+; #pragma link C++ class LauGenNtuple+; #pragma link C++ class LauGounarisSakuraiRes+; #pragma link C++ class LauIntegrals+; #pragma link C++ class LauDPPartialIntegralInfo+; #pragma link C++ class LauIsobarDynamics+; #pragma link C++ class LauKappaRes+; #pragma link C++ class LauKinematics+; #pragma link C++ class LauKMatrixProdPole+; #pragma link C++ class LauKMatrixProdSVP+; #pragma link C++ class LauKMatrixPropagator+; #pragma link C++ class LauKMatrixPropFactory+; #pragma link C++ class LauLASSBWRes+; #pragma link C++ class LauLASSNRRes+; #pragma link C++ class LauLASSRes+; #pragma link C++ class LauLinearPdf+; #pragma link C++ class LauMagPhaseCoeffSet+; #pragma link C++ class LauMagPhaseCPCoeffSet+; #pragma link C++ class LauMergeDataFiles+; #pragma link C++ class LauMinuit+; #pragma link C++ class LauModIndPartWaveMagPhase+; #pragma link C++ class LauModIndPartWaveRealImag+; #pragma link C++ class LauNovosibirskPdf+; #pragma link C++ class LauNRAmplitude+; #pragma link C++ class LauParameter+; #pragma link C++ class LauParametricStepFuncPdf+; #pragma link C++ class LauParamFixed+; #pragma link C++ class LauParticlePDG+; #pragma link C++ class LauPolNR+; #pragma link C++ class LauPoleRes+; #pragma link C++ class LauPolarFormFactorNR+; #pragma link C++ class LauPolarFormFactorSymNR+; #pragma link C++ class LauPolarGammaCPCoeffSet+; #pragma link C++ class LauPrint+; #pragma link C++ class LauRealImagCoeffSet+; #pragma link C++ class LauRealImagCPCoeffSet+; #pragma link C++ class LauRealImagGammaCPCoeffSet+; #pragma link C++ class LauRelBreitWignerRes+; #pragma link C++ class LauResonanceInfo+; #pragma link C++ class LauRescatteringRes+; #pragma link C++ class LauRescattering2Res+; #pragma link C++ class LauResonanceMaker+; #pragma link C++ class LauResultsExtractor+; #pragma link C++ class LauRhoOmegaMix+; -#ifdef DOLAUROOFITSLAVE -#pragma link C++ class LauRooFitSlave+; +#ifdef DOLAUROOFITTASK +#pragma link C++ class LauRooFitTask+; #endif #pragma link C++ class LauScfMap+; #pragma link C++ class LauSigmaRes+; #pragma link C++ class LauSigmoidPdf+; #pragma link C++ class LauSimpleFitModel+; -#pragma link C++ class LauSimFitMaster+; -#pragma link C++ class LauSimFitSlave+; +#pragma link C++ class LauSimFitCoordinator+; +#pragma link C++ class LauSimFitTask+; #pragma link C++ class LauSPlot+; #pragma link C++ class LauString+; #pragma link C++ class LauSumPdf+; #pragma link C++ class LauTextFileParser+; #pragma link C++ class LauVetoes+; #pragma link C++ class LauWeightedSumEffModel+; #pragma link C++ namespace LauConstants+; #pragma link C++ namespace LauRandom+; #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 237c787..2d70d5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,54 +1,54 @@ # Set the include directory (unfortunately this old-style stuff is necessary for the ROOT_GENERATE_DICTIONARY macro) include_directories(${PROJECT_SOURCE_DIR}/inc) # Use glob to find the headers and sources file(GLOB LAURA_HEADERS ${PROJECT_SOURCE_DIR}/inc/*.hh) file(GLOB LAURA_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) -if (NOT LAURA_BUILD_ROOFIT_SLAVE) - list(REMOVE_ITEM LAURA_HEADERS ${PROJECT_SOURCE_DIR}/inc/LauRooFitSlave.hh) - list(REMOVE_ITEM LAURA_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LauRooFitSlave.cc) +if (NOT LAURA_BUILD_ROOFIT_TASK) + list(REMOVE_ITEM LAURA_HEADERS ${PROJECT_SOURCE_DIR}/inc/LauRooFitTask.hh) + list(REMOVE_ITEM LAURA_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LauRooFitTask.cc) endif() # Generate the rootcint file set(LAURA_LINKDEF ${PROJECT_SOURCE_DIR}/inc/Laura++_LinkDef.h) set(LAURA_DICTIONARY_ROOT G__Laura++) set(LAURA_DICTIONARY ${LAURA_DICTIONARY_ROOT}.cxx) -if (LAURA_BUILD_ROOFIT_SLAVE) +if (LAURA_BUILD_ROOFIT_TASK) ROOT_GENERATE_DICTIONARY( ${LAURA_DICTIONARY_ROOT} ${LAURA_HEADERS} LINKDEF ${LAURA_LINKDEF} - OPTIONS -DDOLAUROOFITSLAVE + OPTIONS -DDOLAUROOFITTASK ) else() ROOT_GENERATE_DICTIONARY( ${LAURA_DICTIONARY_ROOT} ${LAURA_HEADERS} LINKDEF ${LAURA_LINKDEF} ) endif() # Build the shared library add_library(Laura++ SHARED ${LAURA_SOURCES} ${LAURA_DICTIONARY}) set_target_properties(Laura++ PROPERTIES OUTPUT_NAME Laura++) set_target_properties(Laura++ PROPERTIES VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}) set_target_properties(Laura++ PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) target_include_directories(Laura++ PUBLIC $ $) target_link_libraries(Laura++ ROOT::Core ROOT::Hist ROOT::Matrix ROOT::Physics ROOT::Minuit ROOT::EG ROOT::Tree) -if (LAURA_BUILD_ROOFIT_SLAVE) +if (LAURA_BUILD_ROOFIT_TASK) target_link_libraries(Laura++ ROOT::RooFit ROOT::RooFitCore) endif() # Install the libraries install( TARGETS Laura++ EXPORT "LauraTargets" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) # Install the pcm and rootmap files generated by ROOT_GENERATE_DICTIONARY install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libLaura++.rootmap ${CMAKE_CURRENT_BINARY_DIR}/libLaura++_rdict.pcm DESTINATION ${CMAKE_INSTALL_LIBDIR} ) diff --git a/src/LauAbsFitModel.cc b/src/LauAbsFitModel.cc index 6bd4899..bebdc84 100644 --- a/src/LauAbsFitModel.cc +++ b/src/LauAbsFitModel.cc @@ -1,1090 +1,1090 @@ /* Copyright 2004 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ /*! \file LauAbsFitModel.cc \brief File containing implementation of LauAbsFitModel class. */ #include #include #include #include "TMessage.h" #include "TMonitor.h" #include "TServerSocket.h" #include "TSocket.h" #include "TSystem.h" #include "TVirtualFitter.h" #include "LauAbsFitModel.hh" #include "LauAbsFitter.hh" #include "LauAbsPdf.hh" #include "LauComplex.hh" #include "LauFitter.hh" #include "LauFitDataTree.hh" #include "LauGenNtuple.hh" #include "LauParameter.hh" #include "LauParamFixed.hh" #include "LauPrint.hh" #include "LauSPlot.hh" ClassImp(LauAbsFitModel) LauAbsFitModel::LauAbsFitModel() : fixParams_(kFALSE), compareFitData_(kFALSE), savePDF_(kFALSE), writeLatexTable_(kFALSE), writeSPlotData_(kFALSE), storeDPEff_(kFALSE), randomFit_(kFALSE), emlFit_(kFALSE), poissonSmear_(kFALSE), enableEmbedding_(kFALSE), usingDP_(kTRUE), pdfsDependOnDP_(kFALSE), inputFitData_(0), genNtuple_(0), sPlotNtuple_(0), nullString_(""), doSFit_(kFALSE), sWeightBranchName_(""), sWeightScaleFactor_(1.0), outputTableName_(""), fitToyMCFileName_("fitToyMC.root"), fitToyMCTableName_("fitToyMCTable"), fitToyMCScale_(10), fitToyMCPoissonSmear_(kFALSE), sPlotFileName_(""), sPlotTreeName_(""), sPlotVerbosity_("") { } LauAbsFitModel::~LauAbsFitModel() { delete inputFitData_; inputFitData_ = 0; delete genNtuple_; genNtuple_ = 0; delete sPlotNtuple_; sPlotNtuple_ = 0; // Remove the components created to apply constraints to fit parameters for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ if ( !(*iter)->isLValue() ){ delete (*iter); (*iter) = 0; } } } void LauAbsFitModel::run(const TString& applicationCode, const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileName) { // Chose whether you want to generate or fit events in the Dalitz plot. // To generate events choose applicationCode = "gen", to fit events choose // applicationCode = "fit". TString runCode(applicationCode); runCode.ToLower(); TString histFileNameCopy(histFileName); TString tableFileNameCopy(tableFileName); TString dataFileNameCopy(dataFileName); TString dataTreeNameCopy(dataTreeName); // Initialise the fit par vectors. Each class that inherits from this one // must implement this sensibly for all vectors specified in clearFitParVectors, // i.e. specify parameter names, initial, min, max and fixed values this->initialise(); // Add variables to Gaussian constrain to a list this->addConParameters(); if (dataFileNameCopy == "") {dataFileNameCopy = "data.root";} if (dataTreeNameCopy == "") {dataTreeNameCopy = "genResults";} if (runCode.Contains("gen")) { if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";} if (tableFileNameCopy == "") {tableFileNameCopy = "genResults";} this->setGenValues(); this->generate(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy); } else if (runCode.Contains("fit")) { if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";} if (tableFileNameCopy == "") {tableFileNameCopy = "fitResults";} this->fit(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy); } else if (runCode.Contains("plot")) { this->savePDFPlots("plot"); } else if (runCode.Contains("weight")) { this->weightEvents(dataFileNameCopy, dataTreeNameCopy); } } void LauAbsFitModel::doSFit( const TString& sWeightBranchName, Double_t scaleFactor ) { if ( sWeightBranchName == "" ) { std::cerr << "WARNING in LauAbsFitModel::doSFit : sWeight branch name is empty string, not setting-up sFit." << std::endl; return; } doSFit_ = kTRUE; sWeightBranchName_ = sWeightBranchName; sWeightScaleFactor_ = scaleFactor; } void LauAbsFitModel::setBkgndClassNames( const std::vector& names ) { if ( !bkgndClassNames_.empty() ) { std::cerr << "WARNING in LauAbsFitModel::setBkgndClassNames : Names already stored, not changing them." << std::endl; return; } UInt_t nBkgnds = names.size(); for ( UInt_t i(0); i < nBkgnds; ++i ) { bkgndClassNames_.insert( std::make_pair( i, names[i] ) ); } this->setupBkgndVectors(); } Bool_t LauAbsFitModel::validBkgndClass( const TString& className ) const { if ( bkgndClassNames_.empty() ) { return kFALSE; } Bool_t found(kFALSE); for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) { if ( iter->second == className ) { found = kTRUE; break; } } return found; } UInt_t LauAbsFitModel::bkgndClassID( const TString& className ) const { if ( ! this->validBkgndClass( className ) ) { std::cerr << "ERROR in LauAbsFitModel::bkgndClassID : Request for ID for invalid background class \"" << className << "\"." << std::endl; return (bkgndClassNames_.size() + 1); } UInt_t bgID(0); for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) { if ( iter->second == className ) { bgID = iter->first; break; } } return bgID; } const TString& LauAbsFitModel::bkgndClassName( UInt_t classID ) const { LauBkgndClassMap::const_iterator iter = bkgndClassNames_.find( classID ); if ( iter == bkgndClassNames_.end() ) { std::cerr << "ERROR in LauAbsFitModel::bkgndClassName : Request for name of invalid background class ID " << classID << "." << std::endl; return nullString_; } return iter->second; } void LauAbsFitModel::clearFitParVectors() { std::cout << "INFO in LauAbsFitModel::clearFitParVectors : Clearing fit variable vectors" << std::endl; // Remove the components created to apply constraints to fit parameters for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ if ( !(*iter)->isLValue() ){ delete (*iter); (*iter) = 0; } } conVars_.clear(); fitVars_.clear(); } void LauAbsFitModel::clearExtraVarVectors() { std::cout << "INFO in LauAbsFitModel::clearExtraVarVectors : Clearing extra ntuple variable vectors" << std::endl; extraVars_.clear(); } void LauAbsFitModel::setGenValues() { // makes sure each parameter holds its genValue as its current value for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) { (*iter)->value((*iter)->genValue()); } this->propagateParUpdates(); } void LauAbsFitModel::writeSPlotData(const TString& fileName, const TString& treeName, Bool_t storeDPEfficiency, const TString& verbosity) { if (this->writeSPlotData()) { std::cerr << "ERROR in LauAbsFitModel::writeSPlotData : Already have an sPlot ntuple setup, not doing it again." << std::endl; return; } writeSPlotData_ = kTRUE; sPlotFileName_ = fileName; sPlotTreeName_ = treeName; sPlotVerbosity_ = verbosity; storeDPEff_ = storeDPEfficiency; } // TODO : histFileName isn't used here at the moment but could be used for // storing the values of the parameters used in the generation. // These could then be read and used for setting the "true" values // in a subsequent fit. void LauAbsFitModel::generate(const TString& dataFileName, const TString& dataTreeName, const TString& /*histFileName*/, const TString& tableFileNameBase) { // Create the ntuple for storing the results std::cout << "INFO in LauAbsFitModel::generate : Creating generation ntuple." << std::endl; if (genNtuple_ != 0) {delete genNtuple_; genNtuple_ = 0;} genNtuple_ = new LauGenNtuple(dataFileName,dataTreeName); // add branches for storing the experiment number and the number of // the event within the current experiment this->addGenNtupleIntegerBranch("iExpt"); this->addGenNtupleIntegerBranch("iEvtWithinExpt"); this->setupGenNtupleBranches(); // Start the cumulative timer cumulTimer_.Start(); const UInt_t firstExp = this->firstExpt(); const UInt_t nExp = this->nExpt(); Bool_t genOK(kTRUE); do { // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each experiment takes to generate timer_.Start(); // Store the experiment number in the ntuple this->setGenNtupleIntegerBranchValue("iExpt",iExp); // Do the generation for this experiment std::cout << "INFO in LauAbsFitModel::generate : Generating experiment number " << iExp << std::endl; genOK = this->genExpt(); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); if (!genOK) { // delete and recreate an empty tree genNtuple_->deleteAndRecreateTree(); // then break out of the experiment loop std::cerr << "WARNING in LauAbsFitModel::generate : Problem in toy MC generation. Starting again with updated parameters..." << std::endl; break; } if (this->writeLatexTable()) { TString tableFileName(tableFileNameBase); tableFileName += "_"; tableFileName += iExp; tableFileName += ".tex"; this->writeOutTable(tableFileName); } } // Loop over number of experiments } while (!genOK); // Print out total timing info. cumulTimer_.Stop(); std::cout << "INFO in LauAbsFitModel::generate : Finished generating all experiments." << std::endl; std::cout << "INFO in LauAbsFitModel::generate : Cumulative timing:" << std::endl; cumulTimer_.Print(); // Build the event index std::cout << "INFO in LauAbsFitModel::generate : Building experiment:event index." << std::endl; // TODO - can test this return value? //Int_t nIndexEntries = genNtuple_->buildIndex("iExpt","iEvtWithinExpt"); // Write out toy MC ntuple std::cout << "INFO in LauAbsFitModel::generate : Writing data to file " << dataFileName << "." << std::endl; genNtuple_->writeOutGenResults(); } void LauAbsFitModel::addGenNtupleIntegerBranch(const TString& name) { genNtuple_->addIntegerBranch(name); } void LauAbsFitModel::addGenNtupleDoubleBranch(const TString& name) { genNtuple_->addDoubleBranch(name); } void LauAbsFitModel::setGenNtupleIntegerBranchValue(const TString& name, Int_t value) { genNtuple_->setIntegerBranchValue(name,value); } void LauAbsFitModel::setGenNtupleDoubleBranchValue(const TString& name, Double_t value) { genNtuple_->setDoubleBranchValue(name,value); } Int_t LauAbsFitModel::getGenNtupleIntegerBranchValue(const TString& name) const { return genNtuple_->getIntegerBranchValue(name); } Double_t LauAbsFitModel::getGenNtupleDoubleBranchValue(const TString& name) const { return genNtuple_->getDoubleBranchValue(name); } void LauAbsFitModel::fillGenNtupleBranches() { genNtuple_->fillBranches(); } void LauAbsFitModel::addSPlotNtupleIntegerBranch(const TString& name) { sPlotNtuple_->addIntegerBranch(name); } void LauAbsFitModel::addSPlotNtupleDoubleBranch(const TString& name) { sPlotNtuple_->addDoubleBranch(name); } void LauAbsFitModel::setSPlotNtupleIntegerBranchValue(const TString& name, Int_t value) { sPlotNtuple_->setIntegerBranchValue(name,value); } void LauAbsFitModel::setSPlotNtupleDoubleBranchValue(const TString& name, Double_t value) { sPlotNtuple_->setDoubleBranchValue(name,value); } void LauAbsFitModel::fillSPlotNtupleBranches() { sPlotNtuple_->fillBranches(); } void LauAbsFitModel::fit(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileNameBase) { // Routine to perform the total fit. const UInt_t firstExp = this->firstExpt(); const UInt_t nExp = this->nExpt(); std::cout << "INFO in LauAbsFitModel::fit : First experiment = " << firstExp << std::endl; std::cout << "INFO in LauAbsFitModel::fit : Number of experiments = " << nExp << std::endl; // Start the cumulative timer cumulTimer_.Start(); this->resetFitCounters(); // Create and setup the fit results ntuple this->setupResultsOutputs( histFileName, tableFileNameBase ); // Create and setup the sPlot ntuple if (this->writeSPlotData()) { std::cout << "INFO in LauAbsFitModel::fit : Creating sPlot ntuple." << std::endl; if (sPlotNtuple_ != 0) {delete sPlotNtuple_; sPlotNtuple_ = 0;} sPlotNtuple_ = new LauGenNtuple(sPlotFileName_,sPlotTreeName_); this->setupSPlotNtupleBranches(); } // This reads in the given dataFile and creates an input // fit data tree that stores them for all events and experiments. Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName); if (!dataOK) { std::cerr << "ERROR in LauAbsFitModel::fit : Problem caching the fit data." << std::endl; gSystem->Exit(EXIT_FAILURE); } // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each fit takes timer_.Start(); this->setCurrentExperiment( iExp ); UInt_t nEvents = this->readExperimentData(); if (nEvents < 1) { std::cerr << "WARNING in LauAbsFitModel::fit : Zero events in experiment " << iExp << ", skipping..." << std::endl; timer_.Stop(); continue; } // Now the sub-classes must implement whatever they need to do // to cache any more input fit data they need in order to // calculate the likelihoods during the fit. // They need to use the inputFitData_ tree as input. For example, // inputFitData_ contains m13Sq and m23Sq. The appropriate fit model // then caches the resonance dynamics for the signal model, as // well as the background likelihood values in the Dalitz plot this->cacheInputFitVars(); if ( this->doSFit() ) { this->cacheInputSWeights(); } // Do the fit for this experiment this->fitExpt(); // Write the results into the ntuple this->finaliseFitResults( outputTableName_ ); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); // Store the per-event likelihood values if ( this->writeSPlotData() ) { this->storePerEvtLlhds(); } // Create a toy MC sample using the fitted parameters so that // the user can compare the fit to the data. if (compareFitData_ == kTRUE && this->statusCode() == 3) { this->createFitToyMC(fitToyMCFileName_, fitToyMCTableName_); } } // Loop over number of experiments // Print out total timing info. cumulTimer_.Stop(); std::cout << "INFO in LauAbsFitModel::fit : Cumulative timing:" << std::endl; cumulTimer_.Print(); // Print out stats on OK fits. const UInt_t nOKFits = this->numberOKFits(); const UInt_t nBadFits = this->numberBadFits(); std::cout << "INFO in LauAbsFitModel::fit : Number of OK Fits = " << nOKFits << std::endl; std::cout << "INFO in LauAbsFitModel::fit : Number of Failed Fits = " << nBadFits << std::endl; Double_t fitEff(0.0); if (nExp != 0) {fitEff = nOKFits/(1.0*nExp);} std::cout << "INFO in LauAbsFitModel::fit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl; // Write out any fit results (ntuples etc...). this->writeOutAllFitResults(); if ( this->writeSPlotData() ) { this->calculateSPlotData(); } } void LauAbsFitModel::setupResultsOutputs( const TString& histFileName, const TString& tableFileName ) { - this->LauSimFitSlave::setupResultsOutputs( histFileName, tableFileName ); + this->LauSimFitTask::setupResultsOutputs( histFileName, tableFileName ); outputTableName_ = tableFileName; } Bool_t LauAbsFitModel::verifyFitData(const TString& dataFileName, const TString& dataTreeName) { // From the input data stream, store the variables into the // internal tree inputFitData_ that can be used by the sub-classes // in calculating their likelihood functions for the fit delete inputFitData_; inputFitData_ = new LauFitDataTree(dataFileName,dataTreeName); Bool_t dataOK = inputFitData_->findBranches(); if (!dataOK) { delete inputFitData_; inputFitData_ = 0; } return dataOK; } void LauAbsFitModel::cacheInputSWeights() { Bool_t hasBranch = inputFitData_->haveBranch( sWeightBranchName_ ); if ( ! hasBranch ) { std::cerr << "ERROR in LauAbsFitModel::cacheInputSWeights : Input data does not contain variable \"" << sWeightBranchName_ << "\".\n"; std::cerr << " : Turning off sFit!" << std::endl; doSFit_ = kFALSE; return; } UInt_t nEvents = this->eventsPerExpt(); sWeights_.clear(); sWeights_.reserve( nEvents ); for (UInt_t iEvt = 0; iEvt < nEvents; ++iEvt) { const LauFitData& dataValues = inputFitData_->getData(iEvt); LauFitData::const_iterator iter = dataValues.find( sWeightBranchName_ ); sWeights_.push_back( iter->second * sWeightScaleFactor_ ); } } void LauAbsFitModel::fitExpt() { // Routine to perform the actual fit for the given experiment // Update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Initialise the fitter LauFitter::fitter()->useAsymmFitErrors( this->useAsymmFitErrors() ); LauFitter::fitter()->twoStageFit( this->twoStageFit() ); LauFitter::fitter()->initialise( this, fitVars_ ); this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() ); // Now ready for minimisation step std::cout << "\nINFO in LauAbsFitModel::fitExpt : Start minimisation...\n"; LauAbsFitter::FitStatus fitResult = LauFitter::fitter()->minimise(); // If we're doing a two stage fit we can now release (i.e. float) // the 2nd stage parameters and re-fit if (this->twoStageFit()) { if ( fitResult.status != 3 ) { std::cerr << "WARNING in LauAbsFitModel:fitExpt : Not running second stage fit since first stage failed." << std::endl; LauFitter::fitter()->releaseSecondStageParameters(); } else { LauFitter::fitter()->releaseSecondStageParameters(); this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() ); fitResult = LauFitter::fitter()->minimise(); } } const TMatrixD& covMat = LauFitter::fitter()->covarianceMatrix(); this->storeFitStatus( fitResult, covMat ); // Store the final fit results and errors into protected internal vectors that // all sub-classes can use within their own finalFitResults implementation // used below (e.g. putting them into an ntuple in a root file) LauFitter::fitter()->updateParameters(); } void LauAbsFitModel::calculateSPlotData() { if (sPlotNtuple_ != 0) { sPlotNtuple_->addFriendTree(inputFitData_->fileName(), inputFitData_->treeName()); sPlotNtuple_->writeOutGenResults(); LauSPlot splot(sPlotNtuple_->fileName(), sPlotNtuple_->treeName(), this->firstExpt(), this->nExpt(), this->variableNames(), this->freeSpeciesNames(), this->fixdSpeciesNames(), this->twodimPDFs(), this->splitSignal(), this->scfDPSmear()); splot.runCalculations(sPlotVerbosity_); splot.writeOutResults(); } } void LauAbsFitModel::compareFitData(UInt_t toyMCScale, const TString& mcFileName, const TString& tableFileName, Bool_t poissonSmearing) { compareFitData_ = kTRUE; fitToyMCScale_ = toyMCScale; fitToyMCFileName_ = mcFileName; fitToyMCTableName_ = tableFileName; fitToyMCPoissonSmear_ = poissonSmearing; } void LauAbsFitModel::createFitToyMC(const TString& mcFileName, const TString& tableFileName) { // Create a toy MC sample so that the user can compare the fitted // result with the data. // Generate more toy MC to reduce statistical fluctuations: // - use the rescaling value fitToyMCScale_ // Store the info on the number of experiments, first expt and current expt const UInt_t oldNExpt(this->nExpt()); const UInt_t oldFirstExpt(this->firstExpt()); const UInt_t oldIExpt(this->iExpt()); // Turn off Poisson smearing if required const Bool_t poissonSmearing(this->doPoissonSmearing()); this->doPoissonSmearing(fitToyMCPoissonSmear_); // Turn off embedding, since we need toy MC, not reco'ed events const Bool_t enableEmbeddingOrig(this->enableEmbedding()); this->enableEmbedding(kFALSE); // Need to make sure that the generation of the DP co-ordinates is // switched on if any of our PDFs depend on it const Bool_t origUseDP = this->useDP(); if ( !origUseDP && this->pdfsDependOnDP() ) { this->useDP( kTRUE ); this->initialiseDPModels(); } // Construct a unique filename for this experiment TString exptString("_expt"); exptString += oldIExpt; TString fileName( mcFileName ); fileName.Insert( fileName.Last('.'), exptString ); // Generate the toy MC std::cout << "INFO in LauAbsFitModel::createFitToyMC : Generating toy MC in " << fileName << " to compare fit with data..." << std::endl; std::cout << " : Number of experiments to generate = " << fitToyMCScale_ << "." << std::endl; std::cout << " : This is to allow the toy MC to be made with reduced statistical fluctuations." << std::endl; // Set the genValue of each parameter to its current (fitted) value // but first store the original genValues for restoring later std::vector origGenValues; origGenValues.reserve(this->nTotParams()); Bool_t blind(kFALSE); for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) { origGenValues.push_back((*iter)->genValue()); (*iter)->genValue((*iter)->unblindValue()); if ( (*iter)->blind() ) { blind = kTRUE; } } if ( blind ) { std::cerr << "WARNING in LauAbsFitModel::createFitToyMC : One or more parameters are blind but the toy will be created using the unblind values - use with caution!!" << std::endl; } // If we're asked to generate more than 100 experiments then split it // up into multiple files since otherwise can run into memory issues // when building the index // TODO - this obviously depends on the number of events per experiment as well, so should do this properly UInt_t totalExpts = fitToyMCScale_; if ( totalExpts > 100 ) { UInt_t nFiles = totalExpts/100; if ( totalExpts%100 ) { nFiles += 1; } TString fileNameBase {fileName}; for ( UInt_t iFile(0); iFile < nFiles; ++iFile ) { UInt_t firstExp( iFile*100 ); // Set number of experiments and first experiment to generate UInt_t nExp = ((firstExp + 100)>totalExpts) ? totalExpts-firstExp : 100; this->setNExpts(nExp, firstExp); // Create a unique filename and generate the events fileName = fileNameBase; TString extraname = "_file"; extraname += iFile; fileName.Insert( fileName.Last('.'), extraname ); this->generate(fileName, "genResults", "dummy.root", tableFileName); } } else { // Set number of experiments to new value this->setNExpts(fitToyMCScale_, 0); // Generate the toy this->generate(fileName, "genResults", "dummy.root", tableFileName); } // Reset number of experiments to original value this->setNExpts(oldNExpt, oldFirstExpt); this->setCurrentExperiment(oldIExpt); // Restore the Poisson smearing to its former value this->doPoissonSmearing(poissonSmearing); // Restore the embedding status this->enableEmbedding(enableEmbeddingOrig); // Restore "useDP" to its former status this->useDP( origUseDP ); // Restore the original genValue to each parameter for (UInt_t i(0); inTotParams(); ++i) { fitVars_[i]->genValue(origGenValues[i]); } std::cout << "INFO in LauAbsFitModel::createFitToyMC : Finished in createFitToyMC." << std::endl; } Double_t LauAbsFitModel::getTotNegLogLikelihood() { // Calculate the total negative log-likelihood over all events. // This function assumes that the fit parameters and data tree have // already been set-up correctly. // Loop over the data points to calculate the log likelihood Double_t logLike = this->getLogLikelihood( 0, this->eventsPerExpt() ); // Include the Poisson term in the extended likelihood if required if (this->doEMLFit()) { logLike -= this->getEventSum(); } // Calculate any penalty terms from Gaussian constrained variables if ( ! conVars_.empty() ){ logLike -= this->getLogLikelihoodPenalty(); } Double_t totNegLogLike = -logLike; return totNegLogLike; } Double_t LauAbsFitModel::getLogLikelihoodPenalty() { Double_t penalty(0.0); for ( LauAbsRValuePList::const_iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter ) { Double_t val = (*iter)->unblindValue(); Double_t mean = (*iter)->constraintMean(); Double_t width = (*iter)->constraintWidth(); Double_t term = ( val - mean )*( val - mean ); penalty += term/( 2*width*width ); } return penalty; } Double_t LauAbsFitModel::getLogLikelihood( UInt_t iStart, UInt_t iEnd ) { // Calculate the total negative log-likelihood over all events. // This function assumes that the fit parameters and data tree have // already been set-up correctly. // Loop over the data points to calculate the log likelihood Double_t logLike(0.0); const Double_t worstLL = this->worstLogLike(); // Loop over the number of events in this experiment Bool_t ok(kTRUE); for (UInt_t iEvt = iStart; iEvt < iEnd; ++iEvt) { Double_t likelihood = this->getTotEvtLikelihood(iEvt); if (likelihood > std::numeric_limits::min()) { // Is the likelihood zero? Double_t evtLogLike = TMath::Log(likelihood); if ( doSFit_ ) { evtLogLike *= sWeights_[iEvt]; } logLike += evtLogLike; } else { ok = kFALSE; std::cerr << "WARNING in LauAbsFitModel::getLogLikelihood : Strange likelihood value for event " << iEvt << ": " << likelihood << "\n"; this->printEventInfo(iEvt); this->printVarsInfo(); //Write the values of the floated variables for which the likelihood is zero break; } } if (!ok) { std::cerr << " : Returning worst NLL found so far to force MINUIT out of this region." << std::endl; logLike = worstLL; } else if (logLike < worstLL) { this->worstLogLike( logLike ); } return logLike; } void LauAbsFitModel::setParsFromMinuit(Double_t* par, Int_t npar) { // This function sets the internal parameters based on the values // that Minuit is using when trying to minimise the total likelihood function. // MINOS reports different numbers of free parameters depending on the // situation, so disable this check if ( ! this->withinAsymErrorCalc() ) { const UInt_t nFreePars = this->nFreeParams(); if (static_cast(npar) != nFreePars) { std::cerr << "ERROR in LauAbsFitModel::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; gSystem->Exit(EXIT_FAILURE); } } // Despite npar being the number of free parameters // the par array actually contains all the parameters, // free and floating... // Update all the floating ones with their new values // Also check if we have any parameters on which the DP integrals depend // and whether they have changed since the last iteration Bool_t recalcNorm(kFALSE); const LauParameterPSet::const_iterator resVarsEnd = resVars_.end(); for (UInt_t i(0); inTotParams(); ++i) { if (!fitVars_[i]->fixed()) { if ( resVars_.find( fitVars_[i] ) != resVarsEnd ) { if ( fitVars_[i]->value() != par[i] ) { recalcNorm = kTRUE; } } fitVars_[i]->value(par[i]); } } // If so, then recalculate the normalisation if (recalcNorm) { this->recalculateNormalisation(); } this->propagateParUpdates(); } UInt_t LauAbsFitModel::addFitParameters(LauPdfList& pdfList) { UInt_t nParsAdded(0); for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { LauAbsPdf* pdf = (*pdf_iter); if ( pdf->isDPDependent() ) { this->pdfsDependOnDP( kTRUE ); } LauAbsRValuePList& pars = pdf->getParameters(); for (LauAbsRValuePList::iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || ( this->twoStageFit() && (*params_iter)->secondStage() ) ) ) { fitVars_.push_back(*params_iter); ++nParsAdded; } } } } return nParsAdded; } void LauAbsFitModel::addConParameters() { for ( LauParameterPList::const_iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { if ( (*iter)->gaussConstraint() ) { conVars_.push_back( *iter ); std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl; } } // Add penalties from the constraints to fit parameters const std::vector& storeCon = this->constraintsStore(); for ( std::vector::const_iterator iter = storeCon.begin(); iter != storeCon.end(); ++iter ) { const std::vector& names = (*iter).conPars_; std::vector params; for ( std::vector::const_iterator iternames = names.begin(); iternames != names.end(); ++iternames ) { for ( LauParameterPList::const_iterator iterfit = fitVars_.begin(); iterfit != fitVars_.end(); ++iterfit ) { if ( (*iternames) == (*iterfit)->name() ){ params.push_back(*iterfit); } } } // If the parameters are not found, skip it if ( params.size() != (*iter).conPars_.size() ) { std::cerr << "WARNING in LauAbsFitModel::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl; continue; } LauFormulaPar* formPar = new LauFormulaPar( (*iter).formula_, (*iter).formula_, params ); formPar->addGaussianConstraint( (*iter).mean_, (*iter).width_ ); conVars_.push_back(formPar); std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to formula\n"; std::cout << " : Formula: " << (*iter).formula_ << std::endl; for ( std::vector::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) { std::cout << " : Parameter: " << (*iterparam)->name() << std::endl; } } } void LauAbsFitModel::updateFitParameters(LauPdfList& pdfList) { for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->updatePulls(); } } void LauAbsFitModel::printFitParameters(const LauPdfList& pdfList, std::ostream& fout) const { LauPrint print; for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { const LauAbsRValuePList& pars = (*pdf_iter)->getParameters(); for (LauAbsRValuePList::const_iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) { LauParameterPList params = (*pars_iter)->getPars(); for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) { if (!(*params_iter)->clone()) { fout << (*params_iter)->name() << " & $"; print.printFormat(fout, (*params_iter)->value()); if ((*params_iter)->fixed() == kTRUE) { fout << "$ (fixed) \\\\"; } else { fout << " \\pm "; print.printFormat(fout, (*params_iter)->error()); fout << "$ \\\\" << std::endl; } } } } } } void LauAbsFitModel::cacheInfo(LauPdfList& pdfList, const LauFitDataTree& theData) { for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->cacheInfo(theData); } } Double_t LauAbsFitModel::prodPdfValue(LauPdfList& pdfList, UInt_t iEvt) { Double_t pdfVal = 1.0; for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) { (*pdf_iter)->calcLikelihoodInfo(iEvt); pdfVal *= (*pdf_iter)->getLikelihood(); } return pdfVal; } void LauAbsFitModel::printEventInfo(UInt_t iEvt) const { const LauFitData& data = inputFitData_->getData(iEvt); std::cerr << " : Input data values for this event:" << std::endl; for (LauFitData::const_iterator iter = data.begin(); iter != data.end(); ++iter) { std::cerr << " " << iter->first << " = " << iter->second << std::endl; } } void LauAbsFitModel::printVarsInfo() const { std::cerr << " : Current values of fit parameters:" << std::endl; for (UInt_t i(0); inTotParams(); ++i) { std::cerr << " " << (fitVars_[i]->name()).Data() << " = " << fitVars_[i]->value() << std::endl; } } void LauAbsFitModel::prepareInitialParArray( TObjArray& array ) { // Update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Store the total number of parameters and the number of free parameters UInt_t nPars = fitVars_.size(); UInt_t nFreePars = 0; // Send the fit parameters for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { if ( ! (*iter)->fixed() ) { ++nFreePars; } array.Add( *iter ); } this->startNewFit( nPars, nFreePars ); } -void LauAbsFitModel::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ) +void LauAbsFitModel::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) { // Copy the fit status information this->storeFitStatus( fitStat, *covMat ); // Now process the parameters const UInt_t nPars = this->nTotParams(); - UInt_t nParsFromMaster = parsFromMaster->GetEntries(); - if ( nParsFromMaster != nPars ) { - std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Unexpected number of parameters received from master" << std::endl; - std::cerr << " : Received " << nParsFromMaster << " when expecting " << nPars << std::endl; + UInt_t nParsFromCoordinator = parsFromCoordinator->GetEntries(); + if ( nParsFromCoordinator != nPars ) { + std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Unexpected number of parameters received from coordinator" << std::endl; + std::cerr << " : Received " << nParsFromCoordinator << " when expecting " << nPars << std::endl; gSystem->Exit( EXIT_FAILURE ); } - for ( UInt_t iPar(0); iPar < nParsFromMaster; ++iPar ) { - LauParameter* parameter = dynamic_cast( (*parsFromMaster)[iPar] ); + for ( UInt_t iPar(0); iPar < nParsFromCoordinator; ++iPar ) { + LauParameter* parameter = dynamic_cast( (*parsFromCoordinator)[iPar] ); if ( ! parameter ) { - std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from master" << std::endl; + std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } if ( parameter->name() != fitVars_[iPar]->name() ) { - std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from master" << std::endl; + std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } *(fitVars_[iPar]) = *parameter; } // Write the results into the ntuple this->finaliseFitResults( outputTableName_ ); // Store the per-event likelihood values if ( this->writeSPlotData() ) { this->storePerEvtLlhds(); } // Create a toy MC sample using the fitted parameters so that // the user can compare the fit to the data. if (compareFitData_ == kTRUE && fitStat.status == 3) { this->createFitToyMC(fitToyMCFileName_, fitToyMCTableName_); } // Send the finalised fit parameters for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) { - parsToMaster.Add( *iter ); + parsToCoordinator.Add( *iter ); } } UInt_t LauAbsFitModel::readExperimentData() { // retrieve the data and find out how many events have been read const UInt_t exptIndex = this->iExpt(); inputFitData_->readExperimentData( exptIndex ); const UInt_t nEvent = inputFitData_->nEvents(); this->eventsPerExpt( nEvent ); return nEvent; } void LauAbsFitModel::setParametersFromFile(const TString& fileName, const TString& treeName, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParams_ = fix; } void LauAbsFitModel::setParametersFromMap(const std::map& parameters, const Bool_t fix) { fixParamMap_ = parameters; fixParams_ = fix; } void LauAbsFitModel::setNamedParameters(const TString& fileName, const TString& treeName, const std::set& parameters, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParamNames_ = parameters; fixParams_ = fix; } void LauAbsFitModel::setParametersFileFallback(const TString& fileName, const TString& treeName, const std::map& parameters, const Bool_t fix) { fixParamFileName_ = fileName; fixParamTreeName_ = treeName; fixParamMap_ = parameters; fixParams_ = fix; } diff --git a/src/LauRooFitSlave.cc b/src/LauRooFitTask.cc similarity index 75% rename from src/LauRooFitSlave.cc rename to src/LauRooFitTask.cc index 78e3737..e6eed0e 100644 --- a/src/LauRooFitSlave.cc +++ b/src/LauRooFitTask.cc @@ -1,393 +1,393 @@ /* Copyright 2017 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ -/*! \file LauRooFitSlave.cc - \brief File containing implementation of LauRooFitSlave class. +/*! \file LauRooFitTask.cc + \brief File containing implementation of LauRooFitTask class. */ #include #include #include "RooRealVar.h" #include "RooDataSet.h" #include "TFile.h" #include "TString.h" #include "TSystem.h" #include "TTree.h" #include "LauFitNtuple.hh" #include "LauParameter.hh" -#include "LauSimFitSlave.hh" -#include "LauRooFitSlave.hh" +#include "LauSimFitTask.hh" +#include "LauRooFitTask.hh" -ClassImp(LauRooFitSlave) +ClassImp(LauRooFitTask) -LauRooFitSlave::LauRooFitSlave( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName ) : - LauSimFitSlave(), +LauRooFitTask::LauRooFitTask( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName ) : + LauSimFitTask(), model_(model), dataVars_(vars), weightVarName_(weightVarName), dataFile_(0), dataTree_(0), exptData_(0), extended_(extended), iExptCat_("iExpt","Expt Number"), nllVar_(0) { } -LauRooFitSlave::~LauRooFitSlave() +LauRooFitTask::~LauRooFitTask() { delete nllVar_; nllVar_ = 0; this->cleanData(); } -void LauRooFitSlave::cleanData() +void LauRooFitTask::cleanData() { if ( dataFile_ != 0 ) { dataFile_->Close(); delete dataFile_; dataTree_ = 0; dataFile_ = 0; } delete exptData_; exptData_ = 0; } -void LauRooFitSlave::initialise() +void LauRooFitTask::initialise() { if ( weightVarName_ != "" ) { Bool_t weightVarFound = kFALSE; RooFIter argset_iter = dataVars_.fwdIterator(); RooAbsArg* param(0); while ( (param = argset_iter.next()) ) { TString name = param->GetName(); if ( name == weightVarName_ ) { weightVarFound = kTRUE; break; } } if ( ! weightVarFound ) { - std::cerr << "ERROR in LauRooFitSlave::initialise : The set of data variables does not contain the weighting variable \"" << weightVarName_ << std::endl; + std::cerr << "ERROR in LauRooFitTask::initialise : The set of data variables does not contain the weighting variable \"" << weightVarName_ << std::endl; std::cerr << " : Weighting will be disabled." << std::endl; weightVarName_ = ""; } } } -Bool_t LauRooFitSlave::verifyFitData(const TString& dataFileName, const TString& dataTreeName) +Bool_t LauRooFitTask::verifyFitData(const TString& dataFileName, const TString& dataTreeName) { // Clean-up from any previous runs if ( dataFile_ != 0 ) { this->cleanData(); } // Open the data file dataFile_ = TFile::Open( dataFileName ); if ( ! dataFile_ ) { - std::cerr << "ERROR in LauRooFitSlave::verifyFitData : Problem opening data file \"" << dataFileName << "\"" << std::endl; + std::cerr << "ERROR in LauRooFitTask::verifyFitData : Problem opening data file \"" << dataFileName << "\"" << std::endl; return kFALSE; } // Retrieve the tree dataTree_ = dynamic_cast( dataFile_->Get( dataTreeName ) ); if ( ! dataTree_ ) { - std::cerr << "ERROR in LauRooFitSlave::verifyFitData : Problem retrieving tree \"" << dataTreeName << "\" from data file \"" << dataFileName << "\"" << std::endl; + std::cerr << "ERROR in LauRooFitTask::verifyFitData : Problem retrieving tree \"" << dataTreeName << "\" from data file \"" << dataFileName << "\"" << std::endl; dataFile_->Close(); delete dataFile_; dataFile_ = 0; return kFALSE; } // Check that the tree contains branches for all the fit variables RooFIter argset_iter = dataVars_.fwdIterator(); RooAbsArg* param(0); Bool_t allOK(kTRUE); while ( (param = argset_iter.next()) ) { TString name = param->GetName(); TBranch* branch = dataTree_->GetBranch( name ); if ( branch == 0 ) { - std::cerr << "ERROR in LauRooFitSlave::verifyFitData : The data tree does not contain a branch for fit variable \"" << name << std::endl; + std::cerr << "ERROR in LauRooFitTask::verifyFitData : The data tree does not contain a branch for fit variable \"" << name << std::endl; allOK = kFALSE; } } if ( ! allOK ) { return kFALSE; } // Check whether the tree has the branch iExpt TBranch* branch = dataTree_->GetBranch("iExpt"); if ( branch == 0 ) { - std::cout << "WARNING in LauRooFitSlave::verifyFitData : Cannot find branch \"iExpt\" in the tree, will treat all data as being from a single experiment" << std::endl; + std::cout << "WARNING in LauRooFitTask::verifyFitData : Cannot find branch \"iExpt\" in the tree, will treat all data as being from a single experiment" << std::endl; } else { // Define the valid values for the iExpt RooCategory iExptCat_.clearTypes(); const UInt_t firstExp = dataTree_->GetMinimum("iExpt"); const UInt_t lastExp = dataTree_->GetMaximum("iExpt"); for ( UInt_t iExp = firstExp; iExp <= lastExp; ++iExp ) { iExptCat_.defineType( TString::Format("expt%d",iExp), iExp ); } } return kTRUE; } -void LauRooFitSlave::prepareInitialParArray( TObjArray& array ) +void LauRooFitTask::prepareInitialParArray( TObjArray& array ) { // Check that the NLL variable has been initialised if ( ! nllVar_ ) { - std::cerr << "ERROR in LauRooFitSlave::prepareInitialParArray : NLL var not initialised" << std::endl; + std::cerr << "ERROR in LauRooFitTask::prepareInitialParArray : NLL var not initialised" << std::endl; return; } // If we already prepared the entries in the fitPars_ vector then we only need to add the contents to the array if ( ! fitPars_.empty() ) { for ( std::vector::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { array.Add(*iter); } return; } // Store the set of parameters and the total number of parameters RooArgSet* varSet = nllVar_->getParameters( exptData_ ); UInt_t nFreePars(0); // Loop through the fit parameters RooFIter argset_iter = varSet->fwdIterator(); RooAbsArg* param(0); while ( (param = argset_iter.next()) ) { // Only consider the free parameters if ( ! param->isConstant() ) { // Add the parameter RooRealVar* rrvar = dynamic_cast( param ); if ( rrvar != 0 ) { // Count the number of free parameters ++nFreePars; // Do the conversion and add it to the array LauParameter* lpar = this->convertToLauParameter( rrvar ); fitVars_.push_back( rrvar ); fitPars_.push_back( lpar ); array.Add( lpar ); } else { RooFormulaVar* rfvar = dynamic_cast( param ); if ( rfvar == 0 ) { - std::cerr << "ERROR in LauRooFitSlave::prepareInitialParArray : The parameter is neither a RooRealVar nor a RooFormulaVar, don't know what to do" << std::endl; + std::cerr << "ERROR in LauRooFitTask::prepareInitialParArray : The parameter is neither a RooRealVar nor a RooFormulaVar, don't know what to do" << std::endl; continue; } std::vector< std::pair > lpars = this->convertToLauParameters( rfvar ); for ( std::vector< std::pair >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { RooRealVar* rrv = iter->first; LauParameter* lpar = iter->second; if ( ! rrv->isConstant() ) { continue; } // Count the number of free parameters ++nFreePars; // Add the parameter to the array fitVars_.push_back( rrvar ); fitPars_.push_back( lpar ); array.Add( lpar ); } } } } delete varSet; this->startNewFit( nFreePars, nFreePars ); } -LauParameter* LauRooFitSlave::convertToLauParameter( const RooRealVar* rooParameter ) const +LauParameter* LauRooFitTask::convertToLauParameter( const RooRealVar* rooParameter ) const { return new LauParameter( rooParameter->GetName(), rooParameter->getVal(), rooParameter->getMin(), rooParameter->getMax(), rooParameter->isConstant() ); } -std::vector< std::pair > LauRooFitSlave::convertToLauParameters( const RooFormulaVar* rooFormula ) const +std::vector< std::pair > LauRooFitTask::convertToLauParameters( const RooFormulaVar* rooFormula ) const { // Create the empty vector std::vector< std::pair > lauParameters; Int_t parIndex(0); RooAbsArg* rabsarg(0); RooRealVar* rrvar(0); RooFormulaVar* rfvar(0); // Loop through all the parameters of the formula while ( (rabsarg = rooFormula->getParameter(parIndex)) ) { // First try converting to a RooRealVar rrvar = dynamic_cast( rabsarg ); if ( rrvar ) { // Do the conversion and add it to the array LauParameter* lpar = this->convertToLauParameter( rrvar ); lauParameters.push_back( std::make_pair(rrvar,lpar) ); continue; } // If that didn't work, try converting to a RooFormulaVar rfvar = dynamic_cast( rabsarg ); if ( rfvar ) { // Do the conversion and add these to the array std::vector< std::pair > lpars = this->convertToLauParameters( rfvar ); for ( std::vector< std::pair >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { lauParameters.push_back( *iter ); } continue; } // If neither of those worked we don't know what to do, so print an error message and continue - std::cerr << "ERROR in LauRooFitSlave::convertToLauParameters : One of the parameters is not a RooRealVar nor a RooFormulaVar, it is a: " << rabsarg->ClassName() << std::endl; + std::cerr << "ERROR in LauRooFitTask::convertToLauParameters : One of the parameters is not a RooRealVar nor a RooFormulaVar, it is a: " << rabsarg->ClassName() << std::endl; std::cerr << " : Do not know how to process that - it will be skipped." << std::endl; } return lauParameters; } -Double_t LauRooFitSlave::getTotNegLogLikelihood() +Double_t LauRooFitTask::getTotNegLogLikelihood() { Double_t nLL = (nllVar_ != 0) ? nllVar_->getVal() : 0.0; return nLL; } -void LauRooFitSlave::setParsFromMinuit(Double_t* par, Int_t npar) +void LauRooFitTask::setParsFromMinuit(Double_t* par, Int_t npar) { // This function sets the internal parameters based on the values // that Minuit is using when trying to minimise the total likelihood function. // MINOS reports different numbers of free parameters depending on the // situation, so disable this check const UInt_t nFreePars = this->nFreeParams(); if ( ! this->withinAsymErrorCalc() ) { if (static_cast(npar) != nFreePars) { - std::cerr << "ERROR in LauRooFitSlave::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; + std::cerr << "ERROR in LauRooFitTask::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; gSystem->Exit(EXIT_FAILURE); } } // Despite npar being the number of free parameters // the par array actually contains all the parameters, // free and floating... // Update all the floating ones with their new values for (UInt_t i(0); ifixed()) { // Set both the RooRealVars and the LauParameters fitPars_[i]->value(par[i]); fitVars_[i]->setVal(par[i]); } } } -UInt_t LauRooFitSlave::readExperimentData() +UInt_t LauRooFitTask::readExperimentData() { // check that we're being asked to read a valid index const UInt_t exptIndex = this->iExpt(); if ( iExptCat_.numTypes() == 0 && exptIndex != 0 ) { - std::cerr << "ERROR in LauRooFitSlave::readExperimentData : Invalid experiment number " << exptIndex << ", data contains only one experiment" << std::endl; + std::cerr << "ERROR in LauRooFitTask::readExperimentData : Invalid experiment number " << exptIndex << ", data contains only one experiment" << std::endl; return 0; } else if ( ! iExptCat_.isValidIndex( exptIndex ) ) { - std::cerr << "ERROR in LauRooFitSlave::readExperimentData : Invalid experiment number " << exptIndex << std::endl; + std::cerr << "ERROR in LauRooFitTask::readExperimentData : Invalid experiment number " << exptIndex << std::endl; return 0; } // cleanup the data from any previous experiment delete exptData_; // retrieve the data and find out how many events have been read if ( iExptCat_.numTypes() == 0 ) { exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", dataTree_, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); } else { const TString selectionString = TString::Format("iExpt==%d",exptIndex); TTree* exptTree = dataTree_->CopyTree(selectionString); exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", exptTree, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); delete exptTree; } const UInt_t nEvent = exptData_->numEntries(); this->eventsPerExpt( nEvent ); return nEvent; } -void LauRooFitSlave::cacheInputFitVars() +void LauRooFitTask::cacheInputFitVars() { // cleanup the old NLL info delete nllVar_; // construct the new NLL variable for this dataset nllVar_ = new RooNLLVar("nllVar", "", model_, *exptData_, extended_); } -void LauRooFitSlave::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ) +void LauRooFitTask::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) { // Copy the fit status information this->storeFitStatus( fitStat, *covMat ); // Now process the parameters const UInt_t nFreePars = this->nFreeParams(); - UInt_t nPars = parsFromMaster->GetEntries(); + UInt_t nPars = parsFromCoordinator->GetEntries(); if ( nPars != nFreePars ) { - std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Unexpected number of parameters received from master" << std::endl; + std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Unexpected number of parameters received from coordinator" << std::endl; std::cerr << " : Received " << nPars << " when expecting " << nFreePars << std::endl; gSystem->Exit( EXIT_FAILURE ); } for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { - LauParameter* parameter = dynamic_cast( (*parsFromMaster)[iPar] ); + LauParameter* parameter = dynamic_cast( (*parsFromCoordinator)[iPar] ); if ( ! parameter ) { - std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Error reading parameter from master" << std::endl; + std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } if ( parameter->name() != fitPars_[iPar]->name() ) { - std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Error reading parameter from master" << std::endl; + std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Error reading parameter from coordinator" << std::endl; gSystem->Exit( EXIT_FAILURE ); } *(fitPars_[iPar]) = *parameter; RooRealVar* rrv = fitVars_[iPar]; rrv->setVal( parameter->value() ); rrv->setError( parameter->error() ); rrv->setAsymError( parameter->negError(), parameter->posError() ); } // Update the pulls and add each finalised fit parameter to the list to - // send back to the master + // send back to the coordinator for ( std::vector::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { (*iter)->updatePull(); - parsToMaster.Add( *iter ); + parsToCoordinator.Add( *iter ); } // Write the results into the ntuple std::vector extraVars; LauFitNtuple* ntuple = this->fitNtuple(); ntuple->storeParsAndErrors(fitPars_, extraVars); // find out the correlation matrix for the parameters ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); // Fill the data into ntuple ntuple->updateFitNtuple(); } diff --git a/src/LauSimFitMaster.cc b/src/LauSimFitCoordinator.cc similarity index 55% rename from src/LauSimFitMaster.cc rename to src/LauSimFitCoordinator.cc index 1160f74..b943917 100644 --- a/src/LauSimFitMaster.cc +++ b/src/LauSimFitCoordinator.cc @@ -1,1050 +1,1050 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ -/*! \file LauSimFitMaster.cc - \brief File containing implementation of LauSimFitMaster class. +/*! \file LauSimFitCoordinator.cc + \brief File containing implementation of LauSimFitCoordinator class. */ #include #include #include #include "TMath.h" #include "TMatrixD.h" #include "TMessage.h" #include "TMonitor.h" #include "TObjArray.h" #include "TObjString.h" #include "TServerSocket.h" #include "TSocket.h" #include "TSystem.h" #include "LauAbsFitter.hh" #include "LauFitNtuple.hh" #include "LauFitter.hh" #include "LauFormulaPar.hh" #include "LauParameter.hh" #include "LauParamFixed.hh" -#include "LauSimFitMaster.hh" +#include "LauSimFitCoordinator.hh" -ClassImp(LauSimFitMaster) +ClassImp(LauSimFitCoordinator) -LauSimFitMaster::LauSimFitMaster( UInt_t numSlaves, UInt_t port ) : - nSlaves_(numSlaves), +LauSimFitCoordinator::LauSimFitCoordinator( UInt_t numTasks, UInt_t port ) : + nTasks_(numTasks), reqPort_(port), socketMonitor_(0), - messageFromSlave_(0), + messageFromTask_(0), fitNtuple_(0) { - messagesToSlaves_.resize( nSlaves_ ); - for ( UInt_t iSlave(0); iSlave < nSlaves_; ++iSlave ) { - messagesToSlaves_[iSlave] = new TMessage(); + messagesToTasks_.resize( nTasks_ ); + for ( UInt_t iTask(0); iTask < nTasks_; ++iTask ) { + messagesToTasks_[iTask] = new TMessage(); } } -LauSimFitMaster::~LauSimFitMaster() +LauSimFitCoordinator::~LauSimFitCoordinator() { delete socketMonitor_; socketMonitor_ = 0; - // Tell all slaves that they are finished and delete corresponding socket + // Tell all tasks that they are finished and delete corresponding socket TString msgStr("Finish"); TMessage message( kMESS_STRING ); message.WriteTString(msgStr); - for ( std::vector::iterator iter = sSlaves_.begin(); iter != sSlaves_.end(); ++iter ) { + for ( std::vector::iterator iter = socketTasks_.begin(); iter != socketTasks_.end(); ++iter ) { (*iter)->Send(message); (*iter)->Close(); delete (*iter); } - sSlaves_.clear(); + socketTasks_.clear(); // Remove the components created to apply constraints to fit parameters for (std::vector::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){ if ( !(*iter)->isLValue() ){ delete (*iter); (*iter) = 0; } } conVars_.clear(); // Remove all fit parameters for ( std::vector::iterator iter = params_.begin(); iter != params_.end(); ++iter ) { delete *iter; } params_.clear(); for ( std::vector::iterator iter = vectorPar_.begin(); iter != vectorPar_.end(); ++iter ) { delete[] (*iter); } vectorPar_.clear(); - delete messageFromSlave_; messageFromSlave_ = 0; + delete messageFromTask_; messageFromTask_ = 0; - for ( std::vector::iterator iter = messagesToSlaves_.begin(); iter != messagesToSlaves_.end(); ++iter ) { + for ( std::vector::iterator iter = messagesToTasks_.begin(); iter != messagesToTasks_.end(); ++iter ) { delete (*iter); } - messagesToSlaves_.clear(); + messagesToTasks_.clear(); delete fitNtuple_; } -void LauSimFitMaster::initSockets() +void LauSimFitCoordinator::initSockets() { if ( socketMonitor_ != 0 ) { - std::cerr << "ERROR in LauSimFitMaster::initSockets : Sockets already initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::initSockets : Sockets already initialised." << std::endl; return; } //initialise socket connection, then accept a connection and return a full-duplex communication socket. socketMonitor_ = new TMonitor(); TServerSocket *ss = new TServerSocket( reqPort_, kFALSE ); UInt_t actual_port = ss->GetLocalPort(); - std::cout << "INFO in LauSimFitMaster::initSockets : Waiting for connection with " << nSlaves_ << " workers on port " << actual_port << std::endl; + std::cout << "INFO in LauSimFitCoordinator::initSockets : Waiting for connection with " << nTasks_ << " workers on port " << actual_port << std::endl; - sSlaves_.resize(nSlaves_); - for ( UInt_t iSlave(0); iSlaveAccept(); - std::cout << " : Added slave " << iSlave << std::endl; + socketTasks_.resize(nTasks_); + for ( UInt_t iTask(0); iTaskAccept(); + std::cout << " : Added task " << iTask << std::endl; } // tell the clients to start - std::cout << "INFO in LauSimFitMaster::initSockets : Initialising slaves" << std::endl; - for ( UInt_t iSlave(0); iSlaveuseAsymmFitErrors()); - sSlaves_[iSlave]->Send(message); + socketTasks_[iTask]->Send(message); - socketMonitor_->Add(sSlaves_[iSlave]); + socketMonitor_->Add(socketTasks_[iTask]); } std::cout << " : Now start fit\n" << std::endl; ss->Close(); delete ss; } /* * OLD VERSION THAT JUST GETS THE NAMES - COULD HAVE A SERIES OF EXCHANGES TO GET THE NAMES, INIT VALUES, RANGES, ETC. INSTEAD OF PASSING PARAMETERS - * THIS INCREASES THE GENERALITY OF THE CODE, I.E. THERE IS NO NEED FOR THE SLAVES TO KNOW ANY LAURA++ CLASS BUT THIS ONE, BUT MAKES IT RATHER MORE DENSE + * THIS INCREASES THE GENERALITY OF THE CODE, I.E. THERE IS NO NEED FOR THE TASKS TO KNOW ANY LAURA++ CLASS BUT THIS ONE, BUT MAKES IT RATHER MORE DENSE * FOR THE MOMENT I WILL STICK WITH THE METHOD OF PASSING LAUPARAMETER OBJECTS AROUND AND CONSIDER GOING BACK TO THIS GENERAL METHOD ONCE EVERYTHING IS WORKING * -void LauSimFitMaster::getParametersFromSlavesFirstTime() +void LauSimFitCoordinator::getParametersFromTasksFirstTime() { - slaveIndices_.resize( nSlaves_ ); + taskIndices_.resize( nTasks_ ); TSocket* sActive(0); - for ( UInt_t iSlave(0); iSlaveSend(message); + socketTasks_[iTask]->Send(message); - // Wait to receive the response and check that it has come from the slave we just requested from + // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); - if ( sActive != sSlaves_[iSlave] ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Received message from a different slave than expected!" << std::endl; + if ( sActive != socketTasks_[iTask] ) { + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names - sSlaves_[iSlave]->Recv( messageFromSlave_ ); - TObjArray * objarray = dynamic_cast( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) ); + socketTasks_[iTask]->Recv( messageFromTask_ ); + TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter names from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } Int_t nPars = objarray->GetEntries(); for ( Int_t iPar(0); iPar < nPars; ++iPar ) { TObjString* objstring = dynamic_cast( (*objarray)[iPar] ); if ( ! objstring ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter names from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } TString parname = objstring->GetString(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter != parIndices_.end() ) { UInt_t index = iter->second; - slaveIndices_[iSlave].push_back( index ); + taskIndices_[iTask].push_back( index ); } else { UInt_t index = parIndices_.size(); parIndices_.insert( std::make_pair( parname, index ) ); parNames_.insert( std::make_pair( index, parname ) ); - slaveIndices_[iSlave].push_back( index ); + taskIndices_[iTask].push_back( index ); } } delete objarray; objarray = 0; - delete messageFromSlave_; messageFromSlave_ = 0; + delete messageFromTask_; messageFromTask_ = 0; } UInt_t nPars = parNames_.size(); parValues_.resize( nPars ); } */ -void LauSimFitMaster::getParametersFromSlaves() +void LauSimFitCoordinator::getParametersFromTasks() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlaves : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasks : Sockets not initialised." << std::endl; return; } if ( params_.empty() ) { - this->getParametersFromSlavesFirstTime(); + this->getParametersFromTasksFirstTime(); // Add variables to Gaussian constrain to a list this->addConParameters(); } else { - this->updateParametersFromSlaves(); + this->updateParametersFromTasks(); } } -void LauSimFitMaster::updateParametersFromSlaves() +void LauSimFitCoordinator::updateParametersFromTasks() { TSocket* sActive(0); // Construct a message, requesting the list of parameter names TString msgStr = "Send Parameters"; TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); - for ( UInt_t iSlave(0); iSlaveSend(message); + for ( UInt_t iTask(0); iTaskSend(message); - // Wait to receive the response and check that it has come from the slave we just requested from + // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); - if ( sActive != sSlaves_[iSlave] ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Received message from a different slave than expected!" << std::endl; + if ( sActive != socketTasks_[iTask] ) { + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names - sSlaves_[iSlave]->Recv( messageFromSlave_ ); - TObjArray * objarray = dynamic_cast( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) ); + socketTasks_[iTask]->Recv( messageFromTask_ ); + TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Error reading parameter names from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Error reading parameter names from task" << std::endl; gSystem->Exit(1); } // We want to auto-delete the supplied parameters since we only copy their values in this case objarray->SetOwner(kTRUE); const UInt_t nPars = objarray->GetEntries(); - if ( nPars != slaveIndices_[iSlave].size() ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected number of parameters received from slave" << std::endl; + if ( nPars != taskIndices_[iTask].size() ) { + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected number of parameters received from task" << std::endl; gSystem->Exit(1); } for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Error reading parameter from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Error reading parameter from task" << std::endl; gSystem->Exit(1); } TString parname = parameter->name(); Double_t parvalue = parameter->initValue(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter == parIndices_.end() ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected parameter name received from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected parameter name received from task" << std::endl; gSystem->Exit(1); } const UInt_t index = iter->second; - if ( slaveIndices_[iSlave][iPar] != index ) { - std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected parameter received from slave" << std::endl; + if ( taskIndices_[iTask][iPar] != index ) { + std::cerr << "ERROR in LauSimFitCoordinator::updateParametersFromTasks : Unexpected parameter received from task" << std::endl; gSystem->Exit(1); } params_[index]->initValue( parvalue ); parValues_[index] = parvalue; - vectorPar_[iSlave][iPar] = parvalue; + vectorPar_[iTask][iPar] = parvalue; this->checkParameter( parameter, index ); } delete objarray; objarray = 0; - delete messageFromSlave_; messageFromSlave_ = 0; + delete messageFromTask_; messageFromTask_ = 0; } } -void LauSimFitMaster::getParametersFromSlavesFirstTime() +void LauSimFitCoordinator::getParametersFromTasksFirstTime() { - slaveIndices_.resize( nSlaves_ ); - slaveFreeIndices_.resize( nSlaves_ ); - vectorPar_.resize( nSlaves_ ); - vectorRes_.resize( nSlaves_ ); + taskIndices_.resize( nTasks_ ); + taskFreeIndices_.resize( nTasks_ ); + vectorPar_.resize( nTasks_ ); + vectorRes_.resize( nTasks_ ); TSocket* sActive(0); // Construct a message, requesting the list of parameter names TString msgStr = "Send Parameters"; TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); - for ( UInt_t iSlave(0); iSlaveSend(message); + for ( UInt_t iTask(0); iTaskSend(message); - // Wait to receive the response and check that it has come from the slave we just requested from + // Wait to receive the response and check that it has come from the task we just requested from sActive = socketMonitor_->Select(); - if ( sActive != sSlaves_[iSlave] ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Received message from a different slave than expected!" << std::endl; + if ( sActive != socketTasks_[iTask] ) { + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Received message from a different task than expected!" << std::endl; gSystem->Exit(1); } // Read the object and extract the parameter names - sSlaves_[iSlave]->Recv( messageFromSlave_ ); - TObjArray * objarray = dynamic_cast( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) ); + socketTasks_[iTask]->Recv( messageFromTask_ ); + TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameters from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameters from task" << std::endl; gSystem->Exit(1); } const UInt_t nPars = objarray->GetEntries(); - vectorPar_[iSlave] = new Double_t[nPars]; + vectorPar_[iTask] = new Double_t[nPars]; for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { - std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getParametersFromTasksFirstTime : Error reading parameter from task" << std::endl; gSystem->Exit(1); } TString parname = parameter->name(); Double_t parvalue = parameter->initValue(); Bool_t parfixed = parameter->fixed(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter != parIndices_.end() ) { UInt_t index = iter->second; - slaveIndices_[iSlave].push_back( index ); + taskIndices_[iTask].push_back( index ); if ( ! parfixed ) { - slaveFreeIndices_[iSlave].push_back( index ); + taskFreeIndices_[iTask].push_back( index ); } this->checkParameter( parameter, index ); } else { UInt_t index = parIndices_.size(); parIndices_.insert( std::make_pair( parname, index ) ); parNames_.insert( std::make_pair( index, parname ) ); - slaveIndices_[iSlave].push_back( index ); + taskIndices_[iTask].push_back( index ); if ( ! parfixed ) { - slaveFreeIndices_[iSlave].push_back( index ); + taskFreeIndices_[iTask].push_back( index ); } params_.push_back( parameter ); parValues_.push_back( parvalue ); } - vectorPar_[iSlave][iPar] = parvalue; + vectorPar_[iTask][iPar] = parvalue; } delete objarray; objarray = 0; - delete messageFromSlave_; messageFromSlave_ = 0; + delete messageFromTask_; messageFromTask_ = 0; } } -void LauSimFitMaster::printParInfo() const +void LauSimFitCoordinator::printParInfo() const { - for ( UInt_t iSlave(0); iSlave& indices = slaveIndices_[iSlave]; + for ( UInt_t iTask(0); iTask& indices = taskIndices_[iTask]; - std::cout << "INFO in LauSimFitMaster::printParInfo : Slave " << iSlave << " has the following parameters:\n"; + std::cout << "INFO in LauSimFitCoordinator::printParInfo : Task " << iTask << " has the following parameters:\n"; for ( std::vector::const_iterator iter = indices.begin(); iter != indices.end(); ++iter ) { const TString& parName = parNames_.find(*iter)->second; Double_t parValue = parValues_[*iter]; const LauParameter* par = params_[*iter]; if ( par->name() != parName || par->initValue() != parValue ) { - std::cerr << "ERROR in LauSimFitMaster::printParInfo : Discrepancy in parameter name and value records, this is very strange!!" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::printParInfo : Discrepancy in parameter name and value records, this is very strange!!" << std::endl; } std::cout << " : " << parName << " = " << parValue << " and has index " << *iter << "\n"; } std::cout << std::endl; } - std::cout << "INFO in LauSimFitMaster::printParInfo : " << "There are " << params_.size() << " parameters in total" << std::endl; + std::cout << "INFO in LauSimFitCoordinator::printParInfo : " << "There are " << params_.size() << " parameters in total" << std::endl; } -void LauSimFitMaster::checkParameter( const LauParameter* param, UInt_t index ) const +void LauSimFitCoordinator::checkParameter( const LauParameter* param, UInt_t index ) const { const LauParameter* storedPar = params_[index]; TString parName = storedPar->name(); if ( param->name() != parName ) { - std::cerr << "ERROR in LauSimFitMaster::checkParameter : Parameter name is different!! This shouldn't happen!!" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::checkParameter : Parameter name is different!! This shouldn't happen!!" << std::endl; } if ( param->initValue() != storedPar->initValue() ) { - std::cerr << "WARNING in LauSimFitMaster::checkParameter : Initial value for parameter " << parName << " is different, will use the value first set: " << storedPar->initValue() << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Initial value for parameter " << parName << " is different, will use the value first set: " << storedPar->initValue() << std::endl; } if ( param->minValue() != storedPar->minValue() ) { - std::cerr << "WARNING in LauSimFitMaster::checkParameter : Minimum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->minValue() << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Minimum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->minValue() << std::endl; } if ( param->maxValue() != storedPar->maxValue() ) { - std::cerr << "WARNING in LauSimFitMaster::checkParameter : Maximum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->maxValue() << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Maximum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->maxValue() << std::endl; } if ( param->fixed() != storedPar->fixed() ) { - std::cerr << "WARNING in LauSimFitMaster::checkParameter : Fixed/floating property of parameter " << parName << " is different, will use the value first set: " << (storedPar->fixed() ? "fixed" : "floating") << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Fixed/floating property of parameter " << parName << " is different, will use the value first set: " << (storedPar->fixed() ? "fixed" : "floating") << std::endl; } if ( param->secondStage() != storedPar->secondStage() ) { - std::cerr << "WARNING in LauSimFitMaster::checkParameter : Second stage property of parameter " << parName << " is different, will use the value first set: " << (storedPar->secondStage() ? "true" : "false") << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::checkParameter : Second stage property of parameter " << parName << " is different, will use the value first set: " << (storedPar->secondStage() ? "true" : "false") << std::endl; } } -void LauSimFitMaster::initialise() +void LauSimFitCoordinator::initialise() { this->initSockets(); } -void LauSimFitMaster::runSimFit( const TString& fitNtupleFileName, const UInt_t nExp, const UInt_t firstExp, const Bool_t useAsymmErrors, const Bool_t doTwoStageFit ) +void LauSimFitCoordinator::runSimFit( const TString& fitNtupleFileName, const UInt_t nExp, const UInt_t firstExp, const Bool_t useAsymmErrors, const Bool_t doTwoStageFit ) { // Routine to perform the total fit. // First, initialise this->useAsymmFitErrors(useAsymmErrors); this->twoStageFit(doTwoStageFit); this->initialise(); - std::cout << "INFO in LauSimFitMaster::runSimFit : First experiment = " << firstExp << std::endl; - std::cout << "INFO in LauSimFitMaster::runSimFit : Number of experiments = " << nExp << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : First experiment = " << firstExp << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of experiments = " << nExp << std::endl; // Start the cumulative timer cumulTimer_.Start(); this->resetFitCounters(); // Create and setup the fit results ntuple - std::cout << "INFO in LauSimFitMaster::runSimFit : Creating fit ntuple." << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Creating fit ntuple." << std::endl; if (fitNtuple_ != 0) {delete fitNtuple_; fitNtuple_ = 0;} fitNtuple_ = new LauFitNtuple(fitNtupleFileName, useAsymmErrors); // Loop over the number of experiments for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) { // Start the timer to see how long each fit takes timer_.Start(); this->setCurrentExperiment( iExp ); - // Instruct the slaves to read the data for this experiment + // Instruct the tasks to read the data for this experiment Bool_t readOK = this->readData(); if ( ! readOK ) { - std::cerr << "ERROR in LauSimFitMaster::runSimFit : One or more slaves reported problems with reading data for experiment " << iExp << ", skipping..." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::runSimFit : One or more tasks reported problems with reading data for experiment " << iExp << ", skipping..." << std::endl; timer_.Stop(); continue; } - // Instruct the slaves to perform the caching + // Instruct the tasks to perform the caching this->cacheInputData(); // Do the fit this->fitExpt(); // Stop the timer and see how long the program took so far timer_.Stop(); timer_.Print(); - // Instruct the slaves to finalise the results + // Instruct the tasks to finalise the results this->finalise(); } // Print out total timing info. - std::cout << "INFO in LauSimFitMaster::runSimFit : Cumulative timing:" << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Cumulative timing:" << std::endl; cumulTimer_.Stop(); cumulTimer_.Print(); // Print out stats on OK fits. const UInt_t nOKFits = this->numberOKFits(); const UInt_t nBadFits = this->numberBadFits(); - std::cout << "INFO in LauSimFitMaster::runSimFit : Number of OK Fits = " << nOKFits << std::endl; - std::cout << "INFO in LauSimFitMaster::runSimFit : Number of Failed Fits = " << nBadFits << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of OK Fits = " << nOKFits << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Number of Failed Fits = " << nBadFits << std::endl; Double_t fitEff(0.0); if (nExp != 0) {fitEff = nOKFits/(1.0*nExp);} - std::cout << "INFO in LauSimFitMaster::runSimFit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl; + std::cout << "INFO in LauSimFitCoordinator::runSimFit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl; - // Instruct the slaves to write out any fit results (ntuples etc...). + // Instruct the tasks to write out any fit results (ntuples etc...). this->writeOutResults(); } -void LauSimFitMaster::withinAsymErrorCalc(const Bool_t inAsymErrCalc) +void LauSimFitCoordinator::withinAsymErrorCalc(const Bool_t inAsymErrCalc) { this->LauFitObject::withinAsymErrorCalc(inAsymErrCalc); if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::withinAsymErrorCalc : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::withinAsymErrorCalc : Sockets not initialised." << std::endl; return; } - // Construct a message, informing the slaves whether or not we are now within the asymmetric error calculation + // Construct a message, informing the tasks whether or not we are now within the asymmetric error calculation TString msgStr("Asym Error Calc"); const Bool_t asymErrorCalc( this->withinAsymErrorCalc() ); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); message.WriteBool( asymErrorCalc ); - // Send the message to the slaves - for ( UInt_t iSlave(0); iSlaveSend(message); + // Send the message to the tasks + for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); - // Extract from the message the ID of the slave and the number of events read + // Extract from the message the ID of the task and the number of events read Bool_t response(kTRUE); - UInt_t iSlave(0); - sActive->Recv( messageFromSlave_ ); - messageFromSlave_->ReadUInt( iSlave ); - messageFromSlave_->ReadBool( response ); + UInt_t iTask(0); + sActive->Recv( messageFromTask_ ); + messageFromTask_->ReadUInt( iTask ); + messageFromTask_->ReadBool( response ); if ( response != asymErrorCalc ) { - std::cerr << "WARNING in LauSimFitMaster::withinAsymErrorCalc : Problem informing slave " << iSlave << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::withinAsymErrorCalc : Problem informing task " << iTask << std::endl; } ++responsesReceived; } } -Bool_t LauSimFitMaster::readData() +Bool_t LauSimFitCoordinator::readData() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::readData : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::readData : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting to read the data for the given experiment TString msgStr("Read Expt"); const UInt_t iExp( this->iExpt() ); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); message.WriteUInt( iExp ); - // Send the message to the slaves - for ( UInt_t iSlave(0); iSlaveSend(message); + // Send the message to the tasks + for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); Bool_t ok(kTRUE); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); - // Extract from the message the ID of the slave and the number of events read - sActive->Recv( messageFromSlave_ ); - UInt_t iSlave(0); + // Extract from the message the ID of the task and the number of events read + sActive->Recv( messageFromTask_ ); + UInt_t iTask(0); UInt_t nEvents(0); - messageFromSlave_->ReadUInt( iSlave ); - messageFromSlave_->ReadUInt( nEvents ); + messageFromTask_->ReadUInt( iTask ); + messageFromTask_->ReadUInt( nEvents ); if ( nEvents <= 0 ) { - std::cerr << "ERROR in LauSimFitMaster::readData : Slave " << iSlave << " reports no events found for experiment " << iExp << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::readData : Task " << iTask << " reports no events found for experiment " << iExp << std::endl; ok = kFALSE; } else { - std::cerr << "INFO in LauSimFitMaster::readData : Slave " << iSlave << " reports " << nEvents << " events found for experiment " << iExp << std::endl; + std::cerr << "INFO in LauSimFitCoordinator::readData : Task " << iTask << " reports " << nEvents << " events found for experiment " << iExp << std::endl; } ++responsesReceived; } return ok; } -Bool_t LauSimFitMaster::cacheInputData() +Bool_t LauSimFitCoordinator::cacheInputData() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::cacheInputData : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::cacheInputData : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting it to read the data for the given experiment TString msgStr("Cache"); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); - for ( UInt_t iSlave(0); iSlaveSend(message); + for ( UInt_t iTask(0); iTaskSend(message); } TSocket* sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); - // Extract from the message the ID of the slave and the success/failure flag - sActive->Recv( messageFromSlave_ ); - UInt_t iSlave(0); + // Extract from the message the ID of the task and the success/failure flag + sActive->Recv( messageFromTask_ ); + UInt_t iTask(0); Bool_t ok(kTRUE); - messageFromSlave_->ReadUInt( iSlave ); - messageFromSlave_->ReadBool( ok ); + messageFromTask_->ReadUInt( iTask ); + messageFromTask_->ReadBool( ok ); if ( ! ok ) { - std::cerr << "ERROR in LauSimFitMaster::cacheInputData : Slave " << iSlave << " reports an error performing caching" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::cacheInputData : Task " << iTask << " reports an error performing caching" << std::endl; allOK = kFALSE; } ++responsesReceived; } return allOK; } -void LauSimFitMaster::checkInitFitParams() +void LauSimFitCoordinator::checkInitFitParams() { - this->getParametersFromSlaves(); + this->getParametersFromTasks(); this->printParInfo(); } -void LauSimFitMaster::fitExpt() +void LauSimFitCoordinator::fitExpt() { // Routine to perform the actual fit for the given experiment - // Instruct the slaves to update initial fit parameters if required (e.g. if using random numbers). + // Instruct the tasks to update initial fit parameters if required (e.g. if using random numbers). this->checkInitFitParams(); // Initialise the fitter LauFitter::fitter()->useAsymmFitErrors( this->useAsymmFitErrors() ); LauFitter::fitter()->twoStageFit( this->twoStageFit() ); LauFitter::fitter()->initialise( this, params_ ); this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() ); // Now ready for minimisation step - std::cout << "\nINFO in LauSimFitMaster::fitExpt : Start minimisation...\n"; + std::cout << "\nINFO in LauSimFitCoordinator::fitExpt : Start minimisation...\n"; LauAbsFitter::FitStatus fitResult = LauFitter::fitter()->minimise(); // If we're doing a two stage fit we can now release (i.e. float) // the 2nd stage parameters and re-fit if (this->twoStageFit()) { if ( fitResult.status != 3 ) { - std::cerr << "ERROR in LauSimFitMaster:fitExpt : Not running second stage fit since first stage failed." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator:fitExpt : Not running second stage fit since first stage failed." << std::endl; LauFitter::fitter()->releaseSecondStageParameters(); } else { LauFitter::fitter()->releaseSecondStageParameters(); this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() ); fitResult = LauFitter::fitter()->minimise(); } } const TMatrixD& covMat = LauFitter::fitter()->covarianceMatrix(); this->storeFitStatus( fitResult, covMat ); // Store the final fit results and errors into protected internal vectors that // all sub-classes can use within their own finalFitResults implementation // used below (e.g. putting them into an ntuple in a root file) LauFitter::fitter()->updateParameters(); } -void LauSimFitMaster::setParsFromMinuit(Double_t* par, Int_t npar) +void LauSimFitCoordinator::setParsFromMinuit(Double_t* par, Int_t npar) { // This function sets the internal parameters based on the values // that Minuit is using when trying to minimise the total likelihood function. // MINOS reports different numbers of free parameters depending on the // situation, so disable this check if ( ! this->withinAsymErrorCalc() ) { const UInt_t nFreePars = this->nFreeParams(); if (static_cast(npar) != nFreePars) { - std::cerr << "ERROR in LauSimFitMaster::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; + std::cerr << "ERROR in LauSimFitCoordinator::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; gSystem->Exit(EXIT_FAILURE); } } // Despite npar being the number of free parameters // the par array actually contains all the parameters, // free and floating... // Update all the parameters with their new values. - // Change the value in the array to be sent out to the slaves and the + // Change the value in the array to be sent out to the tasks and the // parameters themselves (so that constraints are correctly calculated) for (UInt_t i(0); inTotParams(); ++i) { if (!params_[i]->fixed()) { parValues_[i] = par[i]; params_[i]->value(par[i]); } } } -Double_t LauSimFitMaster::getTotNegLogLikelihood() +Double_t LauSimFitCoordinator::getTotNegLogLikelihood() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::getTotNegLogLikelihood : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::getTotNegLogLikelihood : Sockets not initialised." << std::endl; return 0.0; } - // Send current values of the parameters to the slaves. - for ( UInt_t iSlave(0); iSlave& indices = slaveIndices_[iSlave]; - std::vector& freeIndices = slaveFreeIndices_[iSlave]; + std::vector& indices = taskIndices_[iTask]; + std::vector& freeIndices = taskFreeIndices_[iTask]; UInt_t nPars = indices.size(); UInt_t nFreePars = freeIndices.size(); for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { - vectorPar_[iSlave][iPar] = parValues_[ indices[iPar] ]; + vectorPar_[iTask][iPar] = parValues_[ indices[iPar] ]; } - TMessage* message = messagesToSlaves_[iSlave]; + TMessage* message = messagesToTasks_[iTask]; message->Reset( kMESS_ANY ); message->WriteUInt( nPars ); message->WriteUInt( nFreePars ); - message->WriteFastArray( vectorPar_[iSlave], nPars ); + message->WriteFastArray( vectorPar_[iTask], nPars ); - sSlaves_[iSlave]->Send(*message); + socketTasks_[iTask]->Send(*message); } Double_t negLogLike(0.0); TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { sActive = socketMonitor_->Select(); - sActive->Recv(messageFromSlave_); + sActive->Recv(messageFromTask_); - messageFromSlave_->ReadDouble( vectorRes_[responsesReceived] ); + messageFromTask_->ReadDouble( vectorRes_[responsesReceived] ); Double_t& nLL = vectorRes_[responsesReceived]; if ( nLL == 0.0 || TMath::IsNaN(nLL) || !TMath::Finite(nLL) ) { allOK = kFALSE; } negLogLike += vectorRes_[responsesReceived]; ++responsesReceived; } // Calculate any penalty terms from Gaussian constrained variables if ( ! conVars_.empty() ){ negLogLike += this->getLogLikelihoodPenalty(); } const Double_t worstNegLogLike = -1.0*this->worstLogLike(); if ( ! allOK ) { - std::cerr << "WARNING in LauSimFitMaster::getTotNegLogLikelihood : Strange NLL value returned by one or more slaves\n"; + std::cerr << "WARNING in LauSimFitCoordinator::getTotNegLogLikelihood : Strange NLL value returned by one or more tasks\n"; std::cerr << " : Returning worst NLL found so far to force MINUIT out of this region." << std::endl; negLogLike = worstNegLogLike; } else if ( negLogLike > worstNegLogLike ) { this->worstLogLike( -negLogLike ); } return negLogLike; } -Double_t LauSimFitMaster::getLogLikelihoodPenalty() +Double_t LauSimFitCoordinator::getLogLikelihoodPenalty() { Double_t penalty(0.0); for ( std::vector::const_iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter ) { Double_t val = (*iter)->unblindValue(); Double_t mean = (*iter)->constraintMean(); Double_t width = (*iter)->constraintWidth(); Double_t term = ( val - mean )*( val - mean ); penalty += term/( 2*width*width ); } return penalty; } -void LauSimFitMaster::addConParameters() +void LauSimFitCoordinator::addConParameters() { // Add penalties from the constraints to fit parameters // First, constraints on the fit parameters themselves for ( std::vector::const_iterator iter = params_.begin(); iter != params_.end(); ++iter ) { if ( (*iter)->gaussConstraint() ) { conVars_.push_back( *iter ); - std::cout << "INFO in LauSimFitMaster::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl; + std::cout << "INFO in LauSimFitCoordinator::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl; } } // Second, constraints on arbitrary combinations const std::vector& storeCon = this->constraintsStore(); for ( std::vector::const_iterator iter = storeCon.begin(); iter != storeCon.end(); ++iter ) { const std::vector& names = (*iter).conPars_; std::vector params; for ( std::vector::const_iterator iternames = names.begin(); iternames != names.end(); ++iternames ) { for ( std::vector::const_iterator iterfit = params_.begin(); iterfit != params_.end(); ++iterfit ) { if ( (*iternames) == (*iterfit)->name() ){ params.push_back(*iterfit); } } } // If the parameters are not found, skip it if ( params.size() != (*iter).conPars_.size() ) { - std::cerr << "WARNING in LauSimFitMaster::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl; + std::cerr << "WARNING in LauSimFitCoordinator::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl; continue; } LauFormulaPar* formPar = new LauFormulaPar( (*iter).formula_, (*iter).formula_, params ); formPar->addGaussianConstraint( (*iter).mean_, (*iter).width_ ); conVars_.push_back(formPar); - std::cout << "INFO in LauSimFitMaster::addConParameters : Added Gaussian constraint to formula\n"; + std::cout << "INFO in LauSimFitCoordinator::addConParameters : Added Gaussian constraint to formula\n"; std::cout << " : Formula: " << (*iter).formula_ << std::endl; for ( std::vector::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) { std::cout << " : Parameter: " << (*iterparam)->name() << std::endl; } } } -Bool_t LauSimFitMaster::finalise() +Bool_t LauSimFitCoordinator::finalise() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Sockets not initialised." << std::endl; return kFALSE; } // Prepare the covariance matrices const TMatrixD& covMatrix = this->covarianceMatrix(); - covMatrices_.resize( nSlaves_ ); + covMatrices_.resize( nTasks_ ); LauParamFixed pred; std::map freeParIndices; UInt_t counter(0); for ( UInt_t iPar(0); iPar < this->nTotParams(); ++iPar ) { const LauParameter* par = params_[iPar]; if ( ! pred(par) ) { freeParIndices.insert( std::make_pair(iPar,counter) ); ++counter; } } - for ( UInt_t iSlave(0); iSlave freeIndices; freeIndices.reserve( nPar ); for ( UInt_t iPar(0); iPar < nPar; ++iPar ) { - UInt_t index = slaveIndices_[iSlave][iPar]; + UInt_t index = taskIndices_[iTask][iPar]; std::map::iterator freeIter = freeParIndices.find(index); if ( freeIter == freeParIndices.end() ) { continue; } UInt_t freeIndex = freeIter->second; freeIndices.push_back( freeIndex ); } const UInt_t nFreePars = freeIndices.size(); - TMatrixD& covMat = covMatrices_[iSlave]; + TMatrixD& covMat = covMatrices_[iTask]; covMat.ResizeTo( nFreePars, nFreePars ); for ( UInt_t iPar(0); iPar < nFreePars; ++iPar ) { for ( UInt_t jPar(0); jPar < nFreePars; ++jPar ) { UInt_t i = freeIndices[iPar]; UInt_t j = freeIndices[jPar]; covMat( iPar, jPar ) = covMatrix( i, j ); } } } // The array to hold the parameters TObjArray array; - // Send messages to all slaves containing the final parameters and fit status, NLL - for ( UInt_t iSlave(0); iSlave& indices = slaveIndices_[iSlave]; + std::vector& indices = taskIndices_[iTask]; UInt_t nPars = indices.size(); for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { array.Add( params_[ indices[iPar] ] ); } const Int_t status = this->statusCode(); const Double_t NLL = this->nll(); const Double_t EDM = this->edm(); - TMatrixD& covMat = covMatrices_[iSlave]; + TMatrixD& covMat = covMatrices_[iTask]; - TMessage* message = messagesToSlaves_[iSlave]; + TMessage* message = messagesToTasks_[iTask]; message->Reset( kMESS_OBJECT ); message->WriteInt( status ); message->WriteDouble( NLL ); message->WriteDouble( EDM ); message->WriteObject( &array ); message->WriteObject( &covMat ); - sSlaves_[iSlave]->Send(*message); + socketTasks_[iTask]->Send(*message); } TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); - // Extract from the message the ID of the slave and the number of events read - sActive->Recv( messageFromSlave_ ); - UInt_t iSlave(0); + // Extract from the message the ID of the task and the number of events read + sActive->Recv( messageFromTask_ ); + UInt_t iTask(0); Bool_t ok(kTRUE); - messageFromSlave_->ReadUInt( iSlave ); - messageFromSlave_->ReadBool( ok ); + messageFromTask_->ReadUInt( iTask ); + messageFromTask_->ReadBool( ok ); if ( ok ) { - TObjArray * objarray = dynamic_cast( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) ); + TObjArray * objarray = dynamic_cast( messageFromTask_->ReadObject( messageFromTask_->GetClass() ) ); if ( ! objarray ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Error reading finalised parameters from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Error reading finalised parameters from task" << std::endl; allOK = kFALSE; } else { // We want to auto-delete the supplied parameters since we only copy their values in this case objarray->SetOwner(kTRUE); const UInt_t nPars = objarray->GetEntries(); - if ( nPars != slaveIndices_[iSlave].size() ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected number of finalised parameters received from slave" << std::endl; + if ( nPars != taskIndices_[iTask].size() ) { + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected number of finalised parameters received from task" << std::endl; allOK = kFALSE; } else { for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { LauParameter* parameter = dynamic_cast( (*objarray)[iPar] ); if ( ! parameter ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Error reading parameter from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Error reading parameter from task" << std::endl; allOK = kFALSE; continue; } TString parname = parameter->name(); std::map< TString, UInt_t >::iterator iter = parIndices_.find( parname ); if ( iter == parIndices_.end() ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected parameter name received from slave" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected parameter name received from task" << std::endl; allOK = kFALSE; continue; } const UInt_t index = iter->second; - if ( slaveIndices_[iSlave][iPar] != index ) { - std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected parameter received from slave" << std::endl; + if ( taskIndices_[iTask][iPar] != index ) { + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Unexpected parameter received from task" << std::endl; allOK = kFALSE; continue; } Double_t parvalue = parameter->value(); params_[index]->value( parvalue ); parValues_[index] = parvalue; - vectorPar_[iSlave][iPar] = parvalue; + vectorPar_[iTask][iPar] = parvalue; } } delete objarray; } } else { - std::cerr << "ERROR in LauSimFitMaster::finalise : Slave " << iSlave << " reports an error performing finalisation" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::finalise : Task " << iTask << " reports an error performing finalisation" << std::endl; allOK = kFALSE; } ++responsesReceived; } // Fill our ntuple as well if ( fitNtuple_ != 0 ) { for ( std::vector::iterator iter = params_.begin(); iter != params_.end(); ++iter ) { if (!(*iter)->fixed()) { (*iter)->updatePull(); } } std::vector extraVars; fitNtuple_->storeParsAndErrors( params_, extraVars ); fitNtuple_->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); fitNtuple_->updateFitNtuple(); } return allOK; } -Bool_t LauSimFitMaster::writeOutResults() +Bool_t LauSimFitCoordinator::writeOutResults() { if ( socketMonitor_ == 0 ) { - std::cerr << "ERROR in LauSimFitMaster::writeOutResults : Sockets not initialised." << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::writeOutResults : Sockets not initialised." << std::endl; return kFALSE; } // Construct a message, requesting to write out the fit results TString msgStr("Write Results"); TMessage message( kMESS_STRING ); message.WriteTString( msgStr ); - // Send the message to the slaves - for ( UInt_t iSlave(0); iSlaveSend(message); + // Send the message to the tasks + for ( UInt_t iTask(0); iTaskSend(message); } TSocket *sActive(0); UInt_t responsesReceived(0); Bool_t allOK(kTRUE); - while ( responsesReceived != nSlaves_ ) { + while ( responsesReceived != nTasks_ ) { // Get the next queued response sActive = socketMonitor_->Select(); - // Extract from the message the ID of the slave and the number of events read - sActive->Recv( messageFromSlave_ ); - UInt_t iSlave(0); + // Extract from the message the ID of the task and the number of events read + sActive->Recv( messageFromTask_ ); + UInt_t iTask(0); Bool_t ok(kTRUE); - messageFromSlave_->ReadUInt( iSlave ); - messageFromSlave_->ReadBool( ok ); + messageFromTask_->ReadUInt( iTask ); + messageFromTask_->ReadBool( ok ); if ( ! ok ) { - std::cerr << "ERROR in LauSimFitMaster::writeOutResults : Slave " << iSlave << " reports an error performing finalisation" << std::endl; + std::cerr << "ERROR in LauSimFitCoordinator::writeOutResults : Task " << iTask << " reports an error performing finalisation" << std::endl; allOK = kFALSE; } ++responsesReceived; } // Write out our ntuple as well if (fitNtuple_ != 0) { fitNtuple_->writeOutFitResults(); } return allOK; } diff --git a/src/LauSimFitSlave.cc b/src/LauSimFitSlave.cc deleted file mode 100644 index b1b7f90..0000000 --- a/src/LauSimFitSlave.cc +++ /dev/null @@ -1,310 +0,0 @@ - -/* -Copyright 2015 University of Warwick - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Laura++ package authors: -John Back -Paul Harrison -Thomas Latham -*/ - -/*! \file LauSimFitSlave.cc - \brief File containing implementation of LauSimFitSlave class. -*/ - -#include -#include - -#include "TMatrixD.h" -#include "TMessage.h" -#include "TObjArray.h" -#include "TObjString.h" -#include "TSocket.h" -#include "TSystem.h" - -#include "LauSimFitSlave.hh" -#include "LauFitNtuple.hh" - - -ClassImp(LauSimFitSlave) - - -LauSimFitSlave::LauSimFitSlave() : - sMaster_(0), - messageFromMaster_(0), - slaveId_(0), - nSlaves_(0), - parValues_(0), - fitNtuple_(0) -{ -} - -LauSimFitSlave::~LauSimFitSlave() -{ - delete sMaster_; - delete messageFromMaster_; - delete[] parValues_; - delete fitNtuple_; -} - -void LauSimFitSlave::runSlave(const TString& dataFileName, const TString& dataTreeName, - const TString& histFileName, const TString& tableFileName, - const TString& addressMaster, const UInt_t portMaster) -{ - // Establish the connection to the master process - this->connectToMaster( addressMaster, portMaster ); - - // Initialise the fit model - this->initialise(); - - // NB call to addConParameters() is intentionally not included here cf. - // LauAbsFitModel::run() since this has to be dealt with by the master - // to avoid multiple inclusions of each penalty term - // Print a warning if constraints on combinations of parameters have been specified - const std::vector& storeCon = this->constraintsStore(); - if ( ! storeCon.empty() ) { - std::cerr << "WARNING in LauSimFitSlave::runSlave : Constraints have been added but these will be ignored - they should have been added to the master process" << std::endl; - } - - // Setup saving of fit results to ntuple/LaTeX table etc. - this->setupResultsOutputs( histFileName, tableFileName ); - - // This reads in the given dataFile and creates an input - // fit data tree that stores them for all events and experiments. - Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName); - if (!dataOK) { - std::cerr << "ERROR in LauSimFitSlave::runSlave : Problem caching the fit data." << std::endl; - return; - } - - // Now process the various requests from the master - this->processMasterRequests(); - - std::cout << "INFO in LauSimFitSlave::runSlave : Fit slave " << this->slaveId() << " has finished successfully" << std::endl; -} - -void LauSimFitSlave::setupResultsOutputs( const TString& histFileName, const TString& /*tableFileName*/ ) -{ - // Create and setup the fit results ntuple - std::cout << "INFO in LauSimFitSlave::setupResultsOutputs : Creating fit ntuple." << std::endl; - if (fitNtuple_ != 0) {delete fitNtuple_; fitNtuple_ = 0;} - fitNtuple_ = new LauFitNtuple(histFileName, this->useAsymmFitErrors()); -} - -void LauSimFitSlave::connectToMaster( const TString& addressMaster, const UInt_t portMaster ) -{ - if ( sMaster_ != 0 ) { - std::cerr << "ERROR in LauSimFitSlave::connectToMaster : master socket already present" << std::endl; - return; - } - - // Open connection to master - sMaster_ = new TSocket(addressMaster, portMaster); - sMaster_->Recv( messageFromMaster_ ); - - messageFromMaster_->ReadUInt( slaveId_ ); - messageFromMaster_->ReadUInt( nSlaves_ ); - - Bool_t useAsymErrs(kFALSE); - messageFromMaster_->ReadBool( useAsymErrs ); - this->useAsymmFitErrors(useAsymErrs); - - delete messageFromMaster_; - messageFromMaster_ = 0; - - std::cout << "INFO in LauSimFitSlave::connectToMaster : Established connection to master on port " << portMaster << std::endl; - std::cout << " : We are slave " << slaveId_ << " of " << nSlaves_ << std::endl; - if ( useAsymErrs ) { - std::cout << " : The fit will determine asymmetric errors" << std::endl; - } -} - -void LauSimFitSlave::processMasterRequests() -{ - // Listen for requests from the master and act accordingly - - TMessage messageToMaster(kMESS_ANY); - - while ( kTRUE ) { - - sMaster_->Recv( messageFromMaster_ ); - - if ( messageFromMaster_->What() == kMESS_STRING ) { - - TString msgStr; - messageFromMaster_->ReadTString( msgStr ); - - std::cout << "INFO in LauSimFitSlave::processMasterRequests : Received message from master: " << msgStr << std::endl; - - if ( msgStr == "Send Parameters" ) { - - // Send the fit parameters - - TObjArray array; - this->prepareInitialParArray( array ); - - // Create array to efficiently exchange parameter values with master - if ( parValues_ != 0 ) { - delete[] parValues_; - parValues_ = 0; - } - UInt_t nPar = array.GetEntries(); - parValues_ = new Double_t[nPar]; - - messageToMaster.Reset( kMESS_OBJECT ); - messageToMaster.WriteObject( &array ); - sMaster_->Send( messageToMaster ); - - } else if ( msgStr == "Read Expt" ) { - - // Read the data for this experiment - UInt_t iExp(0); - messageFromMaster_->ReadUInt( iExp ); - - this->setCurrentExperiment( iExp ); - - UInt_t nEvents = this->readExperimentData(); - if ( nEvents < 1 ) { - std::cerr << "WARNING in LauSimFitSlave::processMasterRequests : Zero events in experiment " << iExp << ", the master should skip this experiment..." << std::endl; - } - - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteUInt( slaveId_ ); - messageToMaster.WriteUInt( nEvents ); - sMaster_->Send( messageToMaster ); - - } else if ( msgStr == "Cache" ) { - - // Perform the caching - - this->cacheInputFitVars(); - - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteUInt( slaveId_ ); - messageToMaster.WriteBool( kTRUE ); - sMaster_->Send( messageToMaster ); - - } else if ( msgStr == "Asym Error Calc" ) { - - Bool_t asymErrorCalc(kFALSE); - messageFromMaster_->ReadBool( asymErrorCalc ); - this->withinAsymErrorCalc( asymErrorCalc ); - - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteUInt( slaveId_ ); - messageToMaster.WriteBool( asymErrorCalc ); - sMaster_->Send( messageToMaster ); - - } else if ( msgStr == "Write Results" ) { - - this->writeOutAllFitResults(); - - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteUInt( slaveId_ ); - messageToMaster.WriteBool( kTRUE ); - sMaster_->Send( messageToMaster ); - - } else if ( msgStr == "Finish" ) { - - std::cout << "INFO in LauSimFitSlave::processMasterRequests : Message from master to finish" << std::endl; - break; - - } else { - - std::cerr << "ERROR in LauSimFitSlave::processMasterRequests : Unexpected message from master" << std::endl; - gSystem->Exit( EXIT_FAILURE ); - - } - - } else if ( messageFromMaster_->What() == kMESS_OBJECT ) { - - std::cout << "INFO in LauSimFitSlave::processMasterRequests : Received message from master: Finalise" << std::endl; - - Int_t status(0); - Double_t NLL(0.0); - Double_t EDM(0.0); - messageFromMaster_->ReadInt( status ); - messageFromMaster_->ReadDouble( NLL ); - messageFromMaster_->ReadDouble( EDM ); - - TObjArray * objarray = dynamic_cast( messageFromMaster_->ReadObject( messageFromMaster_->GetClass() ) ); - if ( ! objarray ) { - std::cerr << "ERROR in LauSimFitSlave::processMasterRequests : Error reading parameters from master" << std::endl; - gSystem->Exit( EXIT_FAILURE ); - } - - TMatrixD * covMat = dynamic_cast( messageFromMaster_->ReadObject( messageFromMaster_->GetClass() ) ); - if ( ! covMat ) { - std::cerr << "ERROR in LauSimFitSlave::processMasterRequests : Error reading covariance matrix from master" << std::endl; - gSystem->Exit( EXIT_FAILURE ); - } - - TObjArray array; - LauAbsFitter::FitStatus fitStat { status, NLL, EDM }; - this->finaliseExperiment( fitStat, objarray, covMat, array ); - - delete objarray; objarray = 0; - delete covMat; covMat = 0; - - // Send the finalised parameters back to the master - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteUInt( slaveId_ ); - messageToMaster.WriteBool( kTRUE ); - messageToMaster.WriteObject( &array ); - sMaster_->Send( messageToMaster ); - - } else if ( messageFromMaster_->What() == kMESS_ANY ) { - - UInt_t nPars(0); - UInt_t nFreePars(0); - messageFromMaster_->ReadUInt( nPars ); - messageFromMaster_->ReadUInt( nFreePars ); - - if ( nPars != this->nTotParams() ) { - std::cerr << "ERROR in LauSimFitSlave::processMasterRequests : Unexpected number of parameters received from master" << std::endl; - std::cerr << " : Received " << nPars << " when expecting " << this->nTotParams() << std::endl; - gSystem->Exit( EXIT_FAILURE ); - } - - messageFromMaster_->ReadFastArray( parValues_, nPars ); - - this->setParsFromMinuit( parValues_, nFreePars ); - - Double_t negLogLike = this->getTotNegLogLikelihood(); - - messageToMaster.Reset( kMESS_ANY ); - messageToMaster.WriteDouble( negLogLike ); - sMaster_->Send( messageToMaster ); - - } else { - std::cerr << "ERROR in LauSimFitSlave::processMasterRequests : Unexpected message type" << std::endl; - gSystem->Exit( EXIT_FAILURE ); - } - - delete messageFromMaster_; - messageFromMaster_ = 0; - } -} - -void LauSimFitSlave::writeOutAllFitResults() -{ - // Write out histograms at end - if (fitNtuple_ != 0) { - fitNtuple_->writeOutFitResults(); - } -} - diff --git a/src/LauSimFitTask.cc b/src/LauSimFitTask.cc new file mode 100644 index 0000000..2589a8d --- /dev/null +++ b/src/LauSimFitTask.cc @@ -0,0 +1,310 @@ + +/* +Copyright 2015 University of Warwick + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Laura++ package authors: +John Back +Paul Harrison +Thomas Latham +*/ + +/*! \file LauSimFitTask.cc + \brief File containing implementation of LauSimFitTask class. +*/ + +#include +#include + +#include "TMatrixD.h" +#include "TMessage.h" +#include "TObjArray.h" +#include "TObjString.h" +#include "TSocket.h" +#include "TSystem.h" + +#include "LauSimFitTask.hh" +#include "LauFitNtuple.hh" + + +ClassImp(LauSimFitTask) + + +LauSimFitTask::LauSimFitTask() : + socketCoordinator_(0), + messageFromCoordinator_(0), + taskId_(0), + nTasks_(0), + parValues_(0), + fitNtuple_(0) +{ +} + +LauSimFitTask::~LauSimFitTask() +{ + delete socketCoordinator_; + delete messageFromCoordinator_; + delete[] parValues_; + delete fitNtuple_; +} + +void LauSimFitTask::runTask(const TString& dataFileName, const TString& dataTreeName, + const TString& histFileName, const TString& tableFileName, + const TString& addressCoordinator, const UInt_t portCoordinator) +{ + // Establish the connection to the coordinator process + this->connectToCoordinator( addressCoordinator, portCoordinator ); + + // Initialise the fit model + this->initialise(); + + // NB call to addConParameters() is intentionally not included here cf. + // LauAbsFitModel::run() since this has to be dealt with by the coordinator + // to avoid multiple inclusions of each penalty term + // Print a warning if constraints on combinations of parameters have been specified + const std::vector& storeCon = this->constraintsStore(); + if ( ! storeCon.empty() ) { + std::cerr << "WARNING in LauSimFitTask::runTask : Constraints have been added but these will be ignored - they should have been added to the coordinator process" << std::endl; + } + + // Setup saving of fit results to ntuple/LaTeX table etc. + this->setupResultsOutputs( histFileName, tableFileName ); + + // This reads in the given dataFile and creates an input + // fit data tree that stores them for all events and experiments. + Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName); + if (!dataOK) { + std::cerr << "ERROR in LauSimFitTask::runTask : Problem caching the fit data." << std::endl; + return; + } + + // Now process the various requests from the coordinator + this->processCoordinatorRequests(); + + std::cout << "INFO in LauSimFitTask::runTask : Fit task " << this->taskId() << " has finished successfully" << std::endl; +} + +void LauSimFitTask::setupResultsOutputs( const TString& histFileName, const TString& /*tableFileName*/ ) +{ + // Create and setup the fit results ntuple + std::cout << "INFO in LauSimFitTask::setupResultsOutputs : Creating fit ntuple." << std::endl; + if (fitNtuple_ != 0) {delete fitNtuple_; fitNtuple_ = 0;} + fitNtuple_ = new LauFitNtuple(histFileName, this->useAsymmFitErrors()); +} + +void LauSimFitTask::connectToCoordinator( const TString& addressCoordinator, const UInt_t portCoordinator ) +{ + if ( socketCoordinator_ != 0 ) { + std::cerr << "ERROR in LauSimFitTask::connectToCoordinator : coordinator socket already present" << std::endl; + return; + } + + // Open connection to coordinator + socketCoordinator_ = new TSocket(addressCoordinator, portCoordinator); + socketCoordinator_->Recv( messageFromCoordinator_ ); + + messageFromCoordinator_->ReadUInt( taskId_ ); + messageFromCoordinator_->ReadUInt( nTasks_ ); + + Bool_t useAsymErrs(kFALSE); + messageFromCoordinator_->ReadBool( useAsymErrs ); + this->useAsymmFitErrors(useAsymErrs); + + delete messageFromCoordinator_; + messageFromCoordinator_ = 0; + + std::cout << "INFO in LauSimFitTask::connectToCoordinator : Established connection to coordinator on port " << portCoordinator << std::endl; + std::cout << " : We are task " << taskId_ << " of " << nTasks_ << std::endl; + if ( useAsymErrs ) { + std::cout << " : The fit will determine asymmetric errors" << std::endl; + } +} + +void LauSimFitTask::processCoordinatorRequests() +{ + // Listen for requests from the coordinator and act accordingly + + TMessage messageToCoordinator(kMESS_ANY); + + while ( kTRUE ) { + + socketCoordinator_->Recv( messageFromCoordinator_ ); + + if ( messageFromCoordinator_->What() == kMESS_STRING ) { + + TString msgStr; + messageFromCoordinator_->ReadTString( msgStr ); + + std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Received message from coordinator: " << msgStr << std::endl; + + if ( msgStr == "Send Parameters" ) { + + // Send the fit parameters + + TObjArray array; + this->prepareInitialParArray( array ); + + // Create array to efficiently exchange parameter values with coordinator + if ( parValues_ != 0 ) { + delete[] parValues_; + parValues_ = 0; + } + UInt_t nPar = array.GetEntries(); + parValues_ = new Double_t[nPar]; + + messageToCoordinator.Reset( kMESS_OBJECT ); + messageToCoordinator.WriteObject( &array ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( msgStr == "Read Expt" ) { + + // Read the data for this experiment + UInt_t iExp(0); + messageFromCoordinator_->ReadUInt( iExp ); + + this->setCurrentExperiment( iExp ); + + UInt_t nEvents = this->readExperimentData(); + if ( nEvents < 1 ) { + std::cerr << "WARNING in LauSimFitTask::processCoordinatorRequests : Zero events in experiment " << iExp << ", the coordinator should skip this experiment..." << std::endl; + } + + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteUInt( taskId_ ); + messageToCoordinator.WriteUInt( nEvents ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( msgStr == "Cache" ) { + + // Perform the caching + + this->cacheInputFitVars(); + + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteUInt( taskId_ ); + messageToCoordinator.WriteBool( kTRUE ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( msgStr == "Asym Error Calc" ) { + + Bool_t asymErrorCalc(kFALSE); + messageFromCoordinator_->ReadBool( asymErrorCalc ); + this->withinAsymErrorCalc( asymErrorCalc ); + + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteUInt( taskId_ ); + messageToCoordinator.WriteBool( asymErrorCalc ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( msgStr == "Write Results" ) { + + this->writeOutAllFitResults(); + + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteUInt( taskId_ ); + messageToCoordinator.WriteBool( kTRUE ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( msgStr == "Finish" ) { + + std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Message from coordinator to finish" << std::endl; + break; + + } else { + + std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected message from coordinator" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + + } + + } else if ( messageFromCoordinator_->What() == kMESS_OBJECT ) { + + std::cout << "INFO in LauSimFitTask::processCoordinatorRequests : Received message from coordinator: Finalise" << std::endl; + + Int_t status(0); + Double_t NLL(0.0); + Double_t EDM(0.0); + messageFromCoordinator_->ReadInt( status ); + messageFromCoordinator_->ReadDouble( NLL ); + messageFromCoordinator_->ReadDouble( EDM ); + + TObjArray * objarray = dynamic_cast( messageFromCoordinator_->ReadObject( messageFromCoordinator_->GetClass() ) ); + if ( ! objarray ) { + std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Error reading parameters from coordinator" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + TMatrixD * covMat = dynamic_cast( messageFromCoordinator_->ReadObject( messageFromCoordinator_->GetClass() ) ); + if ( ! covMat ) { + std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Error reading covariance matrix from coordinator" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + TObjArray array; + LauAbsFitter::FitStatus fitStat { status, NLL, EDM }; + this->finaliseExperiment( fitStat, objarray, covMat, array ); + + delete objarray; objarray = 0; + delete covMat; covMat = 0; + + // Send the finalised parameters back to the coordinator + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteUInt( taskId_ ); + messageToCoordinator.WriteBool( kTRUE ); + messageToCoordinator.WriteObject( &array ); + socketCoordinator_->Send( messageToCoordinator ); + + } else if ( messageFromCoordinator_->What() == kMESS_ANY ) { + + UInt_t nPars(0); + UInt_t nFreePars(0); + messageFromCoordinator_->ReadUInt( nPars ); + messageFromCoordinator_->ReadUInt( nFreePars ); + + if ( nPars != this->nTotParams() ) { + std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected number of parameters received from coordinator" << std::endl; + std::cerr << " : Received " << nPars << " when expecting " << this->nTotParams() << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + messageFromCoordinator_->ReadFastArray( parValues_, nPars ); + + this->setParsFromMinuit( parValues_, nFreePars ); + + Double_t negLogLike = this->getTotNegLogLikelihood(); + + messageToCoordinator.Reset( kMESS_ANY ); + messageToCoordinator.WriteDouble( negLogLike ); + socketCoordinator_->Send( messageToCoordinator ); + + } else { + std::cerr << "ERROR in LauSimFitTask::processCoordinatorRequests : Unexpected message type" << std::endl; + gSystem->Exit( EXIT_FAILURE ); + } + + delete messageFromCoordinator_; + messageFromCoordinator_ = 0; + } +} + +void LauSimFitTask::writeOutAllFitResults() +{ + // Write out histograms at end + if (fitNtuple_ != 0) { + fitNtuple_->writeOutFitResults(); + } +} +