diff --git a/.clang-format b/.clang-format index 666a2ba79..de5e2ce74 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ Language: Cpp BasedOnStyle: LLVM # AccessModifierOffset: -2 # AlignAfterOpenBracket: Align -# AlignConsecutiveAssignments: false +AlignConsecutiveAssignments: true # AlignConsecutiveDeclarations: false # AlignEscapedNewlinesLeft: false # AlignOperands: true @@ -16,7 +16,7 @@ BasedOnStyle: LLVM # AlwaysBreakAfterDefinitionReturnType: None # AlwaysBreakAfterReturnType: None # AlwaysBreakBeforeMultilineStrings: false -# AlwaysBreakTemplateDeclarations: false +AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false # BraceWrapping: @@ -31,10 +31,10 @@ BinPackParameters: false # BeforeCatch: false # BeforeElse: false # IndentBraces: false -# BreakBeforeBinaryOperators: None +BreakBeforeBinaryOperators: All # BreakBeforeBraces: Attach # BreakBeforeTernaryOperators: true -# BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializersBeforeComma: true # BreakAfterJavaFieldAnnotations: false # BreakStringLiterals: true ColumnLimit: 120 @@ -53,7 +53,7 @@ IndentWidth: 4 # IndentWrappedFunctionNames: false # JavaScriptQuotes: Leave # JavaScriptWrapImports: true -# KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtTheStartOfBlocks: false # MacroBlockBegin: '' # MacroBlockEnd: '' # MaxEmptyLinesToKeep: 1 @@ -71,7 +71,7 @@ IndentWidth: 4 # ReflowComments: true SortIncludes: false # SpaceAfterCStyleCast: false -# SpaceAfterTemplateKeyword: true +SpaceAfterTemplateKeyword: false # SpaceBeforeAssignmentOperators: true SpaceBeforeParens: Never # SpaceInEmptyParentheses: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cffc874d..857be0d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ endif() if(CMAKE_VERSION VERSION_GREATER 3.6) # Add clang-tidy if available -option(GOOFIT_TIDY_FIX "Perform fixes for Clang-Tidy (resets to OFF)" OFF) +option(GOOFIT_TIDY_FIX "Perform fixes for Clang-Tidy - changes source inplace" OFF) find_program( CLANG_TIDY_EXE NAMES "clang-tidy" @@ -305,10 +305,15 @@ endif() # Adding simple libraries add_subdirectory("extern/CLI11") +mark_as_advanced(CLI_EXAMPLES CLI_SINGLE_FILE CLI_SINGLE_FILE_TESTS CLI_TESTING) add_subdirectory("extern/FeatureDetector") set_target_properties(FeatureDetector PROPERTIES FOLDER extern) + +## Format add_subdirectory("extern/fmt") set_target_properties(fmt PROPERTIES FOLDER extern) +mark_as_advanced(FMT_CPPFORMAT FMT_DOC FMT_INSTALL FMT_PEDANTIC FMT_TEST FMT_USE_CPP11) + add_library(rang INTERFACE) target_include_directories(rang INTERFACE "${PROJECT_SOURCE_DIR}/extern/rang/include") @@ -486,4 +491,3 @@ if(GOOFIT_TESTS) add_subdirectory(tests) endif() -set(GOOFIT_TIDY_FIX OFF CACHE BOOL "Perform fixes for Clang-Tidy (resets to OFF)" FORCE) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a57c6ca5..34cdfec93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,27 @@ See [adding a package](doc/ADDING_EXTERN.md). +## C++ + +You should verify that the LLVM 4.0 based requirements pass. To fix the clang-tidy requirements: + +```bash +cmake -DGOOFIT_TIDY_FIX=ON .. +make -j1 +``` + +To run `clang-format` to correct source code spacing: + +```bash +git ls-files -- '*.cu' '*.cc' '*.h' '*.cpp' | xargs clang-format -i -style=file +``` + +The modernize script should also not make any changes: + +```bash +git ls-files -- '*.cu' '*.cc' '*.h' '*.cpp' | xargs ModernizeGoofit.py +``` + ## Git GooFit is hosted as a [git](http://git-scm.com) repository on [GitHub](https://github.com). @@ -27,6 +48,7 @@ There's no point in repeating all that info specifically for GooFit here, we do If you don't have time to learn about git and pull requests, we still do want your contribution to GooFit. In that case please make an issue on GitHub and link to your updated files or patches e.g. in [gists](https://gist.github.com). Note that this way you won't get credit for you contribution though in the commit history, so we prefer you make a GitHub pull request or ask for help in a GitHub issue on where you got stuck (fork -> clone -> branch -> edit -> commit -> push -> pull request) with making the pull request. + ## Contact Please use [Issues](https://github.com/GooFit/GooFit/issues) for suggestions, diff --git a/README.md b/README.md index 423ab8c9a..694fd8e55 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Advanced Options: * `-DGOOFIT_PYTHON=OFF`: Preliminary python bindings using [PyBind11]. * `-DGOOFIT_MAXPAR=1800`: The maximum number of parameters to allow. May cause memory issues if too large. * You can enable sanitizers on non-CUDA builds with `-DSANITIZE_ADDRESS=ON`, `-DSANITIZE_MEMORY=ON`, `-DSANITIZE_THREAD=ON` or `-DSANITIZE_UNDEFINED=ON`. -* If `clang-tidy` is available, it will automatically be used to check the source. If you set `-DGOOFIT_TIDY_FIX=ON`, fixes will be applied to the GooFit source (This must be passed on command line, will not be cached). +* If `clang-tidy` is available, it will automatically be used to check the source. If you set `-DGOOFIT_TIDY_FIX=ON`, fixes will be applied to the GooFit source. Note for targeting Tesla P100 or any `arch=6.0` device: * Please use `-DGOOFIT_SEPARATE_COMP=ON` flags to compile. diff --git a/docs/SYSTEM_INSTALL.md b/docs/SYSTEM_INSTALL.md index 02e4622c0..79bb8322e 100644 --- a/docs/SYSTEM_INSTALL.md +++ b/docs/SYSTEM_INSTALL.md @@ -34,7 +34,7 @@ source root-6/bin/thisroot.sh A truly minimal system, Alpine gives you a working Docker system under 3 MB. ```bash -docker run -it alpine sh +docker run -it alpine apk add --no-cache make cmake g++ git libexecinfo-dev git clone --recursive https://github.com/GooFit/GooFit.git cd GooFit @@ -48,7 +48,7 @@ ctest In the spirit of minimality, this is less instructive and contains more magic, but also would also work: ```bash -docker run -it alpine sh +docker run -it alpine apk add --no-cache make cmake g++ git git clone https://github.com/GooFit/GooFit.git cd GooFit diff --git a/examples/2d_plot/2d_plot.cu b/examples/2d_plot/2d_plot.cu index 17712e07c..72fb87bbd 100644 --- a/examples/2d_plot/2d_plot.cu +++ b/examples/2d_plot/2d_plot.cu @@ -18,16 +18,15 @@ using namespace std; using namespace GooFit; -int main(int argc, char** argv) { - +int main(int argc, char **argv) { GooFit::Application app("2D plot example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } - + // In real code, use a random device here std::mt19937 gen(137); std::normal_distribution<> dx(0.2, 1.1); @@ -50,13 +49,16 @@ int main(int argc, char** argv) { Variable yvar{"yvar", -5, 5}; UnbinnedDataSet data({&xvar, &yvar}); - TH2F dataHist("dataHist", "", - xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit(), - yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); - TH1F xvarHist("xvarHist", "", - xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit()); - TH1F yvarHist("yvarHist", "", - yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); + TH2F dataHist("dataHist", + "", + xvar.getNumBins(), + xvar.getLowerLimit(), + xvar.getUpperLimit(), + yvar.getNumBins(), + yvar.getLowerLimit(), + yvar.getUpperLimit()); + TH1F xvarHist("xvarHist", "", xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit()); + TH1F yvarHist("yvarHist", "", yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); dataHist.SetStats(false); xvarHist.SetStats(false); @@ -77,33 +79,36 @@ int main(int argc, char** argv) { } } - Variable xmean {"xmean", 0, 1, -10, 10}; - Variable xsigm {"xsigm", 1, 0.5, 1.5}; + Variable xmean{"xmean", 0, 1, -10, 10}; + Variable xsigm{"xsigm", 1, 0.5, 1.5}; GaussianPdf xgauss("xgauss", &xvar, &xmean, &xsigm); Variable ymean{"ymean", 0, 1, -10, 10}; - Variable ysigm {"ysigm", 0.4, 0.1, 0.6}; + Variable ysigm{"ysigm", 0.4, 0.1, 0.6}; GaussianPdf ygauss{"ygauss", &yvar, &ymean, &ysigm}; ProdPdf total("total", {&xgauss, &ygauss}); total.setData(&data); - + FitManager fitter(&total); fitter.fit(); - TH2F pdfHist("pdfHist", "", - xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit(), - yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); - TH1F xpdfHist("xpdfHist", "", - xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit()); - TH1F ypdfHist("ypdfHist", "", - yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); + TH2F pdfHist("pdfHist", + "", + xvar.getNumBins(), + xvar.getLowerLimit(), + xvar.getUpperLimit(), + yvar.getNumBins(), + yvar.getLowerLimit(), + yvar.getUpperLimit()); + TH1F xpdfHist("xpdfHist", "", xvar.getNumBins(), xvar.getLowerLimit(), xvar.getUpperLimit()); + TH1F ypdfHist("ypdfHist", "", yvar.getNumBins(), yvar.getLowerLimit(), yvar.getUpperLimit()); pdfHist.SetStats(false); xpdfHist.SetStats(false); ypdfHist.SetStats(false); - UnbinnedDataSet grid = total.makeGrid(); + UnbinnedDataSet grid = total.makeGrid(); std::vector> pdfVals = total.getCompProbsAtDataPoints(); TCanvas foo; @@ -121,23 +126,23 @@ int main(int argc, char** argv) { } for(int i = 0; i < xvar.getNumBins(); ++i) { - double val = xpdfHist.GetBinContent(i+1); + double val = xpdfHist.GetBinContent(i + 1); val /= totalPdf; val *= totalData; - xpdfHist.SetBinContent(i+1, val); + xpdfHist.SetBinContent(i + 1, val); } for(int i = 0; i < yvar.getNumBins(); ++i) { - double val = ypdfHist.GetBinContent(i+1); + double val = ypdfHist.GetBinContent(i + 1); val /= totalPdf; val *= totalData; - ypdfHist.SetBinContent(i+1, val); + ypdfHist.SetBinContent(i + 1, val); for(int j = 0; j < xvar.getNumBins(); ++j) { - val = pdfHist.GetBinContent(j+1, i+1); + val = pdfHist.GetBinContent(j + 1, i + 1); val /= totalPdf; val *= totalData; - pdfHist.SetBinContent(j+1, i+1, val); + pdfHist.SetBinContent(j + 1, i + 1, val); } } @@ -146,11 +151,11 @@ int main(int argc, char** argv) { for(int i = 0; i < yvar.getNumBins(); ++i) { for(int j = 0; j < xvar.getNumBins(); ++j) { - double pval = pdfHist.GetBinContent(j+1, i+1); - double dval = dataHist.GetBinContent(j+1, i+1); + double pval = pdfHist.GetBinContent(j + 1, i + 1); + double dval = dataHist.GetBinContent(j + 1, i + 1); pval -= dval; pval /= std::max(1.0, sqrt(dval)); - pdfHist.SetBinContent(j+1, i+1, pval); + pdfHist.SetBinContent(j + 1, i + 1, pval); } } @@ -174,6 +179,5 @@ int main(int argc, char** argv) { ypdfHist.Draw("lsame"); foo.SaveAs("yhist.png"); - return fitter; } diff --git a/examples/DP4/DP4.cu b/examples/DP4/DP4.cu index b42456f81..2928f547d 100644 --- a/examples/DP4/DP4.cu +++ b/examples/DP4/DP4.cu @@ -12,32 +12,31 @@ using namespace std; using namespace GooFit; -const fptype _mD0 = 1.8645; +const fptype _mD0 = 1.8645; const fptype piPlusMass = 0.13957018; -const fptype KmMass = .493677; +const fptype KmMass = .493677; // Constants used in more than one PDF component. -int main(int argc, char** argv) { - +int main(int argc, char **argv) { GooFit::Application app("Dalitz 4 daughter example", argc, argv); - for(int i = 0; i vars; + std::vector vars; vars.push_back(m12); vars.push_back(m34); vars.push_back(cos12); @@ -59,137 +58,152 @@ int main(int argc, char** argv) { printf("read in %i events\n", MCevents); - DecayInfo_DP* DK3P_DI = new DecayInfo_DP(); - DK3P_DI->meson_radius =1.5; + DecayInfo_DP *DK3P_DI = new DecayInfo_DP(); + DK3P_DI->meson_radius = 1.5; DK3P_DI->particle_masses.push_back(_mD0); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(KmMass); DK3P_DI->particle_masses.push_back(piPlusMass); - Variable* RhoMass = new Variable("rho_mass", 0.77526); - Variable* RhoWidth = new Variable("rho_width", 0.1478); - Variable* KstarM = new Variable("KstarM", 0.89581); - Variable* KstarW = new Variable("KstarW", 0.0474); - Variable* f600M = new Variable("f600M", 0.519); - Variable* f600W = new Variable("f600W", 0.454); - Variable* a1M = new Variable("a1M", 1.23); - Variable* a1W = new Variable("a1W", 0.42); - Variable* K1M = new Variable("K1M", 1.272); - Variable* K1W = new Variable("K1W", 0.09); - Variable* K1430M = new Variable("K1430M", 1.414); - Variable* K1430W = new Variable("K1430W", 0.29); - - //Spin factors: we have two due to the bose symmetrization of the two pi+ - std::vector SFKRS; + Variable *RhoMass = new Variable("rho_mass", 0.77526); + Variable *RhoWidth = new Variable("rho_width", 0.1478); + Variable *KstarM = new Variable("KstarM", 0.89581); + Variable *KstarW = new Variable("KstarW", 0.0474); + Variable *f600M = new Variable("f600M", 0.519); + Variable *f600W = new Variable("f600W", 0.454); + Variable *a1M = new Variable("a1M", 1.23); + Variable *a1W = new Variable("a1W", 0.42); + Variable *K1M = new Variable("K1M", 1.272); + Variable *K1W = new Variable("K1W", 0.09); + Variable *K1430M = new Variable("K1430M", 1.414); + Variable *K1430W = new Variable("K1430W", 0.29); + + // Spin factors: we have two due to the bose symmetrization of the two pi+ + std::vector SFKRS; SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 0, 1, 2, 3)); SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 3, 1, 2, 0)); - std::vector SFKRP; + std::vector SFKRP; SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 0, 1, 2, 3)); SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 3, 1, 2, 0)); - std::vector SFKRD; + std::vector SFKRD; SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 0, 1, 2, 3)); SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 3, 1, 2, 0)); - std::vector SFKF; + std::vector SFKF; SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 3, 0, 1)); SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 0, 3, 1)); - std::vector SFKK; + std::vector SFKK; SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 0, 1, 3, 2)); SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 3, 1, 0, 2)); - std::vector SFK1R; + std::vector SFK1R; SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 3, 2, 0, 1)); SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 0, 2, 3, 1)); - std::vector SFA1R; + std::vector SFA1R; SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 3, 0, 1)); SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 0, 3, 1)); - std::vector SFA1RD; + std::vector SFA1RD; SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 3, 0, 1)); SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 0, 3, 1)); - //Lineshapes, also for both pi+ configurations - std::vector LSKRS; + // Lineshapes, also for both pi+ configurations + std::vector LSKRS; LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKRP; + std::vector LSKRP; LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKRD; + std::vector LSKRD; LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKF; + std::vector LSKF; LSKF.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKF.push_back(new Lineshape("f600", f600M, f600W, 0, M_12, LS::Bugg)); LSKF.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); LSKF.push_back(new Lineshape("f600", f600M, f600W, 0, M_24, LS::Bugg)); - std::vector LSKK; + std::vector LSKK; LSKK.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 1, M_34_2, LS::SBW)); LSKK.push_back(new Lineshape("K(0)*(1430)bar", K1430M, K1430W, 0, M_34, LS::Lass)); LSKK.push_back(new Lineshape("K(1)(1270)bar2", K1M, K1W, 1, M_13_2, LS::SBW)); LSKK.push_back(new Lineshape("K(0)*(1430)bar2", K1430M, K1430W, 0, M_13, LS::Lass)); - std::vector LSK1R; + std::vector LSK1R; LSK1R.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 0, M_12_3, LS::SBW)); LSK1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSK1R.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 0, M_24_3, LS::SBW)); LSK1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - std::vector LSA1R; + std::vector LSA1R; LSA1R.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 0, M_12_4, LS::SBW)); LSA1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSA1R.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 0, M_24_1, LS::SBW)); LSA1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - std::vector LSA1RD; + std::vector LSA1RD; LSA1RD.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 2, M_12_4, LS::SBW)); LSA1RD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSA1RD.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 2, M_24_1, LS::SBW)); LSA1RD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - // the very last parameter means that we have two permutations. so the first half of the Lineshapes // and the first half of the spinfactors are amplitude 1, rest is amplitude - // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" order + // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" + // order // Amplitudes with the correct fixed values. - // Amplitude* Bose_symmetrized_AMP_S = new Amplitude( "K*(892)rho(770)_S", new Variable("amp_real1", -0.115177), new Variable("amp_imag1", 0.153976), LSKRS, SFKRS, 2); - // Amplitude* Bose_symmetrized_AMP_P = new Amplitude( "K*(892)rho(770)_P", new Variable("amp_real2", -0.0298697), new Variable("amp_imag2", -0.0722874), LSKRP, SFKRP, 2); - // Amplitude* Bose_symmetrized_AMP_D = new Amplitude( "K*(892)rho(770)_D", new Variable("amp_real3", -0.452212), new Variable("amp_imag3", 0.426521), LSKRD, SFKRD, 2); - - //Amplitudes with floating slightliy different values to be fitted. - Amplitude* Bose_symmetrized_AMP_S = new Amplitude("K*(892)rho(770)_S", new Variable("amp_real1", -0.1, 0.001, 0, 0), - new Variable("amp_imag1", 0.1, 0.001, 0, 0), LSKRS, SFKRS, 2); - Amplitude* Bose_symmetrized_AMP_P = new Amplitude("K*(892)rho(770)_P", new Variable("amp_real2", -0.02, 0.001, 0, 0), - new Variable("amp_imag2", -0.07, 0.001, 0, 0), LSKRP, SFKRP, 2); - Amplitude* Bose_symmetrized_AMP_D = new Amplitude("K*(892)rho(770)_D", new Variable("amp_real3", -0.4, 0.001, 0, 0), - new Variable("amp_imag3", 0.4, 0.001, 0, 0), LSKRD, SFKRD, 2); - - Amplitude* Bose_symmetrized_KF = new Amplitude("KF", new Variable("amp_real4", 0.0120787), new Variable("amp_imag4", - -0.0332525), LSKF, SFKF, 2); - Amplitude* Bose_symmetrized_KK = new Amplitude("LSKK", new Variable("amp_real5", 0.0109033), - new Variable("amp_imag5", -0.00186219), LSKK, SFKK, 2); - Amplitude* Bose_symmetrized_K1R = new Amplitude("LSK1R", new Variable("amp_real6", -0.10728), - new Variable("amp_imag6", -0.130213), LSK1R, SFK1R, 2); - Amplitude* Bose_symmetrized_A1R = new Amplitude("LSA1R", new Variable("amp_real7", 1.0), new Variable("amp_imag7", - 0.0), LSA1R, SFA1R, 2); - Amplitude* Bose_symmetrized_A1RD = new Amplitude("LSA1RD", new Variable("amp_real8", -0.94921), - new Variable("amp_imag8", -1.73407), LSA1RD, SFA1RD, 2); + // Amplitude* Bose_symmetrized_AMP_S = new Amplitude( "K*(892)rho(770)_S", new Variable("amp_real1", -0.115177), new + // Variable("amp_imag1", 0.153976), LSKRS, SFKRS, 2); + // Amplitude* Bose_symmetrized_AMP_P = new Amplitude( "K*(892)rho(770)_P", new Variable("amp_real2", -0.0298697), + // new Variable("amp_imag2", -0.0722874), LSKRP, SFKRP, 2); + // Amplitude* Bose_symmetrized_AMP_D = new Amplitude( "K*(892)rho(770)_D", new Variable("amp_real3", -0.452212), new + // Variable("amp_imag3", 0.426521), LSKRD, SFKRD, 2); + + // Amplitudes with floating slightliy different values to be fitted. + Amplitude *Bose_symmetrized_AMP_S = new Amplitude("K*(892)rho(770)_S", + new Variable("amp_real1", -0.1, 0.001, 0, 0), + new Variable("amp_imag1", 0.1, 0.001, 0, 0), + LSKRS, + SFKRS, + 2); + Amplitude *Bose_symmetrized_AMP_P = new Amplitude("K*(892)rho(770)_P", + new Variable("amp_real2", -0.02, 0.001, 0, 0), + new Variable("amp_imag2", -0.07, 0.001, 0, 0), + LSKRP, + SFKRP, + 2); + Amplitude *Bose_symmetrized_AMP_D = new Amplitude("K*(892)rho(770)_D", + new Variable("amp_real3", -0.4, 0.001, 0, 0), + new Variable("amp_imag3", 0.4, 0.001, 0, 0), + LSKRD, + SFKRD, + 2); + + Amplitude *Bose_symmetrized_KF = new Amplitude( + "KF", new Variable("amp_real4", 0.0120787), new Variable("amp_imag4", -0.0332525), LSKF, SFKF, 2); + Amplitude *Bose_symmetrized_KK = new Amplitude( + "LSKK", new Variable("amp_real5", 0.0109033), new Variable("amp_imag5", -0.00186219), LSKK, SFKK, 2); + Amplitude *Bose_symmetrized_K1R = new Amplitude( + "LSK1R", new Variable("amp_real6", -0.10728), new Variable("amp_imag6", -0.130213), LSK1R, SFK1R, 2); + Amplitude *Bose_symmetrized_A1R + = new Amplitude("LSA1R", new Variable("amp_real7", 1.0), new Variable("amp_imag7", 0.0), LSA1R, SFA1R, 2); + Amplitude *Bose_symmetrized_A1RD = new Amplitude( + "LSA1RD", new Variable("amp_real8", -0.94921), new Variable("amp_imag8", -1.73407), LSA1RD, SFA1RD, 2); DK3P_DI->amplitudes.push_back(Bose_symmetrized_KF); DK3P_DI->amplitudes.push_back(Bose_symmetrized_AMP_S); @@ -232,12 +246,12 @@ int main(int argc, char** argv) { (*res)->setParameterConstantness(true); } - Variable* constantOne = new Variable("constantOne", 1); - Variable* constantZero = new Variable("constantZero", 0); + Variable *constantOne = new Variable("constantOne", 1); + Variable *constantZero = new Variable("constantZero", 0); - vector observables; - vector coefficients; - vector offsets; + vector observables; + vector coefficients; + vector offsets; observables.push_back(m12); observables.push_back(m34); @@ -249,15 +263,15 @@ int main(int argc, char** argv) { offsets.push_back(constantZero); coefficients.push_back(constantOne); - PolynomialPdf* eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); - DPPdf* dp = new DPPdf("test", observables, DK3P_DI, eff, 1e6); + PolynomialPdf *eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); + DPPdf *dp = new DPPdf("test", observables, DK3P_DI, eff, 1e6); - Variable* constant = new Variable("constant", 0.1); - Variable* constant2 = new Variable("constant2", 1.0); + Variable *constant = new Variable("constant", 0.1); + Variable *constant2 = new Variable("constant2", 1.0); vars.clear(); vars.push_back(constant); PolynomialPdf backgr("backgr", m12, vars); - AddPdf* signal = new AddPdf("signal", constant2, dp, &backgr); + AddPdf *signal = new AddPdf("signal", constant2, dp, &backgr); signal->setData(&currData); dp->setDataSize(currData.getNumEvents(), 6); diff --git a/examples/SigGen/SigGen.cu b/examples/SigGen/SigGen.cu index da2832bfa..9ed11065f 100644 --- a/examples/SigGen/SigGen.cu +++ b/examples/SigGen/SigGen.cu @@ -1,4 +1,4 @@ -//ROOT +// ROOT #include #include @@ -16,142 +16,154 @@ using namespace std; using namespace GooFit; // Constants used in more than one PDF component. -const fptype _mD0 = 1.8645; +const fptype _mD0 = 1.8645; const fptype piPlusMass = 0.13957018; -const fptype KmMass = .493677; +const fptype KmMass = .493677; -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Signal Generator Example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } - DecayInfo_DP* DK3P_DI = new DecayInfo_DP(); - DK3P_DI->meson_radius =1.5; + DecayInfo_DP *DK3P_DI = new DecayInfo_DP(); + DK3P_DI->meson_radius = 1.5; DK3P_DI->particle_masses.push_back(_mD0); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(KmMass); DK3P_DI->particle_masses.push_back(piPlusMass); - Variable* RhoMass = new Variable("rho_mass", 0.77526, 0.01, 0.7, 0.8); - Variable* RhoWidth = new Variable("rho_width", 0.1478, 0.01, 0.1, 0.2); - Variable* KstarM = new Variable("KstarM", 0.89581, 0.01, 0.9, 0.1); - Variable* KstarW = new Variable("KstarW", 0.0474, 0.01, 0.1, 0.2); - Variable* f600M = new Variable("f600M", 0.519, 0.01, 0.75, 0.85); - Variable* f600W = new Variable("f600W", 0.454, 0.01, 0.75, 0.85); - Variable* a1M = new Variable("a1M", 1.23, 0.01, 1.2, 1.3); - Variable* a1W = new Variable("a1W", 0.42, 0.01, 0.37, 0.47); - Variable* K1M = new Variable("K1M", 1.272, 0.01, 1.2, 1.3); - Variable* K1W = new Variable("K1W", 0.09, 0.01, 0.08, 0.1); - Variable* K1430M = new Variable("K1430M", 1.414, 0.01, 1.4, 1.5); - Variable* K1430W = new Variable("K1430W", .29, 0.01, 0.25, 0.35); - - //Spin factors: we have two due to the bose symmetrization of the two pi+ - std::vector SFKRS; + Variable *RhoMass = new Variable("rho_mass", 0.77526, 0.01, 0.7, 0.8); + Variable *RhoWidth = new Variable("rho_width", 0.1478, 0.01, 0.1, 0.2); + Variable *KstarM = new Variable("KstarM", 0.89581, 0.01, 0.9, 0.1); + Variable *KstarW = new Variable("KstarW", 0.0474, 0.01, 0.1, 0.2); + Variable *f600M = new Variable("f600M", 0.519, 0.01, 0.75, 0.85); + Variable *f600W = new Variable("f600W", 0.454, 0.01, 0.75, 0.85); + Variable *a1M = new Variable("a1M", 1.23, 0.01, 1.2, 1.3); + Variable *a1W = new Variable("a1W", 0.42, 0.01, 0.37, 0.47); + Variable *K1M = new Variable("K1M", 1.272, 0.01, 1.2, 1.3); + Variable *K1W = new Variable("K1W", 0.09, 0.01, 0.08, 0.1); + Variable *K1430M = new Variable("K1430M", 1.414, 0.01, 1.4, 1.5); + Variable *K1430W = new Variable("K1430W", .29, 0.01, 0.25, 0.35); + + // Spin factors: we have two due to the bose symmetrization of the two pi+ + std::vector SFKRS; SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 0, 1, 2, 3)); SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 3, 1, 2, 0)); - std::vector SFKRP; + std::vector SFKRP; SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 0, 1, 2, 3)); SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 3, 1, 2, 0)); - std::vector SFKRD; + std::vector SFKRD; SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 0, 1, 2, 3)); SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 3, 1, 2, 0)); - std::vector SFKF; + std::vector SFKF; SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 3, 0, 1)); SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 0, 3, 1)); - std::vector SFKK; + std::vector SFKK; SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 0, 1, 3, 2)); SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 3, 1, 0, 2)); - std::vector SFK1R; + std::vector SFK1R; SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 3, 2, 0, 1)); SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 0, 2, 3, 1)); - std::vector SFA1R; + std::vector SFA1R; SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 3, 0, 1)); SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 0, 3, 1)); - std::vector SFA1RD; + std::vector SFA1RD; SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 3, 0, 1)); SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 0, 3, 1)); - //Lineshapes, also for both pi+ configurations - std::vector LSKRS; + // Lineshapes, also for both pi+ configurations + std::vector LSKRS; LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKRP; + std::vector LSKRP; LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKRD; + std::vector LSKRD; LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); - std::vector LSKF; + std::vector LSKF; LSKF.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW)); LSKF.push_back(new Lineshape("f600", f600M, f600W, 0, M_12, LS::Bugg)); LSKF.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW)); LSKF.push_back(new Lineshape("f600", f600M, f600W, 0, M_24, LS::Bugg)); - std::vector LSKK; + std::vector LSKK; LSKK.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 1, M_34_2, LS::SBW)); LSKK.push_back(new Lineshape("K(0)*(1430)bar", K1430M, K1430W, 0, M_34, LS::Lass)); LSKK.push_back(new Lineshape("K(1)(1270)bar2", K1M, K1W, 1, M_13_2, LS::SBW)); LSKK.push_back(new Lineshape("K(0)*(1430)bar2", K1430M, K1430W, 0, M_13, LS::Lass)); - std::vector LSK1R; + std::vector LSK1R; LSK1R.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 0, M_12_3, LS::SBW)); LSK1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSK1R.push_back(new Lineshape("K(1)(1270)bar", K1M, K1W, 0, M_24_3, LS::SBW)); LSK1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - std::vector LSA1R; + std::vector LSA1R; LSA1R.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 0, M_12_4, LS::SBW)); LSA1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSA1R.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 0, M_24_1, LS::SBW)); LSA1R.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - std::vector LSA1RD; + std::vector LSA1RD; LSA1RD.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 2, M_12_4, LS::SBW)); LSA1RD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW)); LSA1RD.push_back(new Lineshape("a(1)(1260)+", a1M, a1W, 2, M_24_1, LS::SBW)); LSA1RD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW)); - // the very last parameter means that we have two permutations. so the first half of the Lineshapes // and the first half of the spinfactors are amplitude 1, rest is amplitude 2 - // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" order - Amplitude* Bose_symmetrized_AMP_S = new Amplitude("K*(892)rho(770)_S", new Variable("amp_real1", -0.115177), - new Variable("amp_imag1", 0.153976), LSKRS, SFKRS, 2); - Amplitude* Bose_symmetrized_AMP_P = new Amplitude("K*(892)rho(770)_P", new Variable("amp_real2", -0.0298697), - new Variable("amp_imag2", -0.0722874), LSKRP, SFKRP, 2); - Amplitude* Bose_symmetrized_AMP_D = new Amplitude("K*(892)rho(770)_D", new Variable("amp_real3", -0.452212), - new Variable("amp_imag3", 0.426521), LSKRD, SFKRD, 2); - Amplitude* Bose_symmetrized_KF = new Amplitude("KF", new Variable("amp_real3", 0.0120787), new Variable("amp_imag3", - -0.0332525), LSKF, SFKF, 2); - Amplitude* Bose_symmetrized_KK = new Amplitude("LSKK", new Variable("amp_real3", 0.0109033), - new Variable("amp_imag3", -0.00186219), LSKK, SFKK, 2); - Amplitude* Bose_symmetrized_K1R = new Amplitude("LSK1R", new Variable("amp_real3", -0.10728), - new Variable("amp_imag3", -0.130213), LSK1R, SFK1R, 2); - Amplitude* Bose_symmetrized_A1R = new Amplitude("LSA1R", new Variable("amp_real3", 1.0), new Variable("amp_imag3", - 0.0), LSA1R, SFA1R, 2); - Amplitude* Bose_symmetrized_A1RD = new Amplitude("LSA1RD", new Variable("amp_real3", -0.94921), - new Variable("amp_imag3", -1.73407), LSA1RD, SFA1RD, 2); + // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" + // order + Amplitude *Bose_symmetrized_AMP_S = new Amplitude("K*(892)rho(770)_S", + new Variable("amp_real1", -0.115177), + new Variable("amp_imag1", 0.153976), + LSKRS, + SFKRS, + 2); + Amplitude *Bose_symmetrized_AMP_P = new Amplitude("K*(892)rho(770)_P", + new Variable("amp_real2", -0.0298697), + new Variable("amp_imag2", -0.0722874), + LSKRP, + SFKRP, + 2); + Amplitude *Bose_symmetrized_AMP_D = new Amplitude("K*(892)rho(770)_D", + new Variable("amp_real3", -0.452212), + new Variable("amp_imag3", 0.426521), + LSKRD, + SFKRD, + 2); + Amplitude *Bose_symmetrized_KF = new Amplitude( + "KF", new Variable("amp_real3", 0.0120787), new Variable("amp_imag3", -0.0332525), LSKF, SFKF, 2); + Amplitude *Bose_symmetrized_KK = new Amplitude( + "LSKK", new Variable("amp_real3", 0.0109033), new Variable("amp_imag3", -0.00186219), LSKK, SFKK, 2); + Amplitude *Bose_symmetrized_K1R = new Amplitude( + "LSK1R", new Variable("amp_real3", -0.10728), new Variable("amp_imag3", -0.130213), LSK1R, SFK1R, 2); + Amplitude *Bose_symmetrized_A1R + = new Amplitude("LSA1R", new Variable("amp_real3", 1.0), new Variable("amp_imag3", 0.0), LSA1R, SFA1R, 2); + Amplitude *Bose_symmetrized_A1RD = new Amplitude( + "LSA1RD", new Variable("amp_real3", -0.94921), new Variable("amp_imag3", -1.73407), LSA1RD, SFA1RD, 2); DK3P_DI->amplitudes.push_back(Bose_symmetrized_KF); DK3P_DI->amplitudes.push_back(Bose_symmetrized_AMP_S); @@ -162,18 +174,18 @@ int main(int argc, char** argv) { DK3P_DI->amplitudes.push_back(Bose_symmetrized_A1R); DK3P_DI->amplitudes.push_back(Bose_symmetrized_A1RD); - Variable* m12 = new Variable("m12", 0, 3); - Variable* m34 = new Variable("m34", 0, 3); - Variable* cos12 = new Variable("cos12", -1, 1); - Variable* cos34 = new Variable("m12", -1, 1); - Variable* phi = new Variable("phi", -3.5, 3.5); - CountingVariable* eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); - Variable* constantOne = new Variable("constantOne", 1); - Variable* constantZero = new Variable("constantZero", 0); + Variable *m12 = new Variable("m12", 0, 3); + Variable *m34 = new Variable("m34", 0, 3); + Variable *cos12 = new Variable("cos12", -1, 1); + Variable *cos34 = new Variable("m12", -1, 1); + Variable *phi = new Variable("phi", -3.5, 3.5); + CountingVariable *eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); + Variable *constantOne = new Variable("constantOne", 1); + Variable *constantZero = new Variable("constantZero", 0); - vector observables; - vector coefficients; - vector offsets; + vector observables; + vector coefficients; + vector offsets; observables.push_back(m12); observables.push_back(m34); @@ -185,35 +197,35 @@ int main(int argc, char** argv) { offsets.push_back(constantZero); coefficients.push_back(constantOne); - PolynomialPdf* eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); - DPPdf* dp = new DPPdf("test", observables, DK3P_DI, eff, 5); - + PolynomialPdf *eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); + DPPdf *dp = new DPPdf("test", observables, DK3P_DI, eff, 5); - TFile* file = new TFile("SigGen.root", "RECREATE"); - TTree* tree = new TTree("events", "events"); + TFile *file = new TFile("SigGen.root", "RECREATE"); + TTree *tree = new TTree("events", "events"); double tm12, tm34, tc12, tc34, tphi; - tree->Branch("m12", &tm12, "m12/D"); - tree->Branch("m34", &tm34, "m34/D"); - tree->Branch("c12", &tc12, "c12/D"); - tree->Branch("c34", &tc34, "c34/D"); - tree->Branch("phi", &tphi, "phi/D"); + tree->Branch("m12", &tm12, "m12/D"); + tree->Branch("m34", &tm34, "m34/D"); + tree->Branch("c12", &tc12, "c12/D"); + tree->Branch("c34", &tc34, "c34/D"); + tree->Branch("phi", &tphi, "phi/D"); for(int k = 0; k < 4; ++k) { int numEvents = 1e6; - dp->setGenerationOffset(k*numEvents); + dp->setGenerationOffset(k * numEvents); auto tuple = dp->GenerateSig(numEvents); auto particles = std::get<0>(tuple); auto variables = std::get<1>(tuple); - auto weights = std::get<2>(tuple); - auto flags = std::get<3>(tuple); - int accepted = thrust::count_if(flags.begin(), flags.end(), thrust::identity()); + auto weights = std::get<2>(tuple); + auto flags = std::get<3>(tuple); + int accepted = thrust::count_if(flags.begin(), flags.end(), thrust::identity()); fprintf(stderr, "Using accept-reject method would leave you with %i out of %i events\n", accepted, numEvents); for(int i = 0; i < weights.size(); ++i) { if(flags[i] == 1) { - //printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g\n", (*(variables[0]))[i], (*(variables[1]))[i], (*(variables[2]))[i], (*(variables[3]))[i], (*(variables[4]))[i], weights[i], flags[i]); + // printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g\n", (*(variables[0]))[i], (*(variables[1]))[i], + // (*(variables[2]))[i], (*(variables[3]))[i], (*(variables[4]))[i], weights[i], flags[i]); tm12 = (*(variables[0]))[i]; tm34 = (*(variables[1]))[i]; tc12 = (*(variables[2]))[i]; diff --git a/examples/TDDP4/TDDP4.cu b/examples/TDDP4/TDDP4.cu index 83c86e673..286e3e2ea 100644 --- a/examples/TDDP4/TDDP4.cu +++ b/examples/TDDP4/TDDP4.cu @@ -1,4 +1,4 @@ -//ROOT +// ROOT #include #include @@ -18,121 +18,115 @@ using namespace std; using namespace GooFit; // Constants used in more than one PDF component. -const fptype _mD0 = 1.8645; +const fptype _mD0 = 1.8645; const fptype piPlusMass = 0.13957018; -const fptype KmMass = .493677; - -int main(int argc, char** argv) { +const fptype KmMass = .493677; +int main(int argc, char **argv) { GooFit::Application app("Time dependent Dalitz plot, 4 particles", argc, argv); - + TString output = "test_10_15.output"; - app.add_option("-o,--output,output", output, - "File to output", true)->check(GooFit::NonexistentPath); - + app.add_option("-o,--output,output", output, "File to output", true)->check(GooFit::NonexistentPath); + int trials = 100; - app.add_option("-t,--trials,output", trials, - "Number of trials", true); + app.add_option("-t,--trials,output", trials, "Number of trials", true); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } - - DecayInfo_DP* DK3P_DI = new DecayInfo_DP(); - DK3P_DI->meson_radius =1.5; + DecayInfo_DP *DK3P_DI = new DecayInfo_DP(); + DK3P_DI->meson_radius = 1.5; DK3P_DI->particle_masses.push_back(_mD0); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(piPlusMass); DK3P_DI->particle_masses.push_back(KmMass); DK3P_DI->particle_masses.push_back(piPlusMass); - Variable* RhoMass = new Variable("rho_mass", 0.77526, 0.01, 0.7, 0.8); - Variable* RhoWidth = new Variable("rho_width", 0.1478, 0.01, 0.1, 0.2); - Variable* KstarM = new Variable("KstarM", 0.89581, 0.01, 0.9, 0.1); - Variable* KstarW = new Variable("KstarW", 0.0474, 0.01, 0.1, 0.2); - //Variable* f600M = new Variable("f600M", 0.519, 0.01, 0.75, 0.85); - //Variable* f600W = new Variable("f600W", 0.454, 0.01, 0.75, 0.85); - //Variable* a1M = new Variable("a1M", 1.23, 0.01, 1.2, 1.3); - //Variable* a1W = new Variable("a1W", 0.42, 0.01, 0.37, 0.47); - //Variable* K1M = new Variable("K1M", 1.272, 0.01, 1.2, 1.3); - //Variable* K1W = new Variable("K1W", 0.09, 0.01, 0.08, 0.1); - //Variable* K1430M = new Variable("K1430M", 1.414, 0.01, 1.4, 1.5); - //Variable* K1430W = new Variable("K1430W", .29, 0.01, 0.25, 0.35); - - //Spin factors: we have two due to the bose symmetrization of the two pi+ - std::vector SFKRS; + Variable *RhoMass = new Variable("rho_mass", 0.77526, 0.01, 0.7, 0.8); + Variable *RhoWidth = new Variable("rho_width", 0.1478, 0.01, 0.1, 0.2); + Variable *KstarM = new Variable("KstarM", 0.89581, 0.01, 0.9, 0.1); + Variable *KstarW = new Variable("KstarW", 0.0474, 0.01, 0.1, 0.2); + // Variable* f600M = new Variable("f600M", 0.519, 0.01, 0.75, 0.85); + // Variable* f600W = new Variable("f600W", 0.454, 0.01, 0.75, 0.85); + // Variable* a1M = new Variable("a1M", 1.23, 0.01, 1.2, 1.3); + // Variable* a1W = new Variable("a1W", 0.42, 0.01, 0.37, 0.47); + // Variable* K1M = new Variable("K1M", 1.272, 0.01, 1.2, 1.3); + // Variable* K1W = new Variable("K1W", 0.09, 0.01, 0.08, 0.1); + // Variable* K1430M = new Variable("K1430M", 1.414, 0.01, 1.4, 1.5); + // Variable* K1430W = new Variable("K1430W", .29, 0.01, 0.25, 0.35); + + // Spin factors: we have two due to the bose symmetrization of the two pi+ + std::vector SFKRS; SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 0, 1, 2, 3)); SFKRS.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_S, 3, 1, 2, 0)); - std::vector SFKRP; + std::vector SFKRP; SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 0, 1, 2, 3)); SFKRP.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_P, 3, 1, 2, 0)); - std::vector SFKRD; + std::vector SFKRD; SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 0, 1, 2, 3)); SFKRD.push_back(new SpinFactor("SF", SF_4Body::DtoV1V2_V1toP1P2_V2toP3P4_D, 3, 1, 2, 0)); - std::vector SFKF; + std::vector SFKF; SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 3, 0, 1)); SFKF.push_back(new SpinFactor("SF", SF_4Body::DtoVS_VtoP1P2_StoP3P4, 2, 0, 3, 1)); - std::vector SFKK; + std::vector SFKK; SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 0, 1, 3, 2)); SFKK.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoSP2_StoP3P4, 3, 1, 0, 2)); - std::vector SFK1R; + std::vector SFK1R; SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 3, 2, 0, 1)); SFK1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 0, 2, 3, 1)); - std::vector SFA1R; + std::vector SFA1R; SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 3, 0, 1)); SFA1R.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2_VtoP3P4, 2, 0, 3, 1)); - std::vector SFA1RD; + std::vector SFA1RD; SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 3, 0, 1)); SFA1RD.push_back(new SpinFactor("SF", SF_4Body::DtoAP1_AtoVP2Dwave_VtoP3P4, 2, 0, 3, 1)); - //Lineshapes, also for both pi+ configurations - std::vector LSKRS; + // Lineshapes, also for both pi+ configurations + std::vector LSKRS; LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW, FF::BL2)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW, FF::BL2)); LSKRS.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW, FF::BL2)); LSKRS.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW, FF::BL2)); - std::vector LSKRP; + std::vector LSKRP; LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW, FF::BL2)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW, FF::BL2)); LSKRP.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW, FF::BL2)); LSKRP.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW, FF::BL2)); - std::vector LSKRD; + std::vector LSKRD; LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_12, LS::BW, FF::BL2)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_34, LS::BW, FF::BL2)); LSKRD.push_back(new Lineshape("rho(770)", RhoMass, RhoWidth, 1, M_24, LS::BW, FF::BL2)); LSKRD.push_back(new Lineshape("K*(892)bar", KstarM, KstarW, 1, M_13, LS::BW, FF::BL2)); - - // the very last parameter means that we have two permutations. so the first half of the Lineshapes // and the first half of the spinfactors are amplitude 1, rest is amplitude 2 - // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" order - Amplitude* Bose_symmetrized_AMP_S = new Amplitude("K*(892)rho(770)_S", new Variable("amp_real1", 1.0), - new Variable("amp_imag1", 0.0), LSKRS, SFKRS, 2); - Amplitude* Bose_symmetrized_AMP_P = new Amplitude("K*(892)rho(770)_P", new Variable("amp_real2", 0.526), - new Variable("amp_imag2", -0.626), LSKRP, SFKRP, 2); - Amplitude* Bose_symmetrized_AMP_D = new Amplitude("K*(892)rho(770)_D", new Variable("amp_real3", 26.537), - new Variable("amp_imag3", 12.284), LSKRD, SFKRD, 2); - - Amplitude* Bose_symmetrized_AMP_S_B = new Amplitude("B_K*(892)rho(770)_S", new Variable("amp_real1", 1.0), - new Variable("amp_imag1", 0), LSKRS, SFKRS, 2); - Amplitude* Bose_symmetrized_AMP_P_B = new Amplitude("B_K*(892)rho(770)_P", new Variable("amp_real2", -0.145), - new Variable("amp_imag2", 0.86), LSKRP, SFKRP, 2); - Amplitude* Bose_symmetrized_AMP_D_B = new Amplitude("B_K*(892)rho(770)_D", new Variable("amp_real3", 24.343), - new Variable("amp_imag3", 5.329), LSKRD, SFKRD, 2); - + // This means that it is important for symmetrized amplitueds that the spinfactors and lineshapes are in the "right" + // order + Amplitude *Bose_symmetrized_AMP_S = new Amplitude( + "K*(892)rho(770)_S", new Variable("amp_real1", 1.0), new Variable("amp_imag1", 0.0), LSKRS, SFKRS, 2); + Amplitude *Bose_symmetrized_AMP_P = new Amplitude( + "K*(892)rho(770)_P", new Variable("amp_real2", 0.526), new Variable("amp_imag2", -0.626), LSKRP, SFKRP, 2); + Amplitude *Bose_symmetrized_AMP_D = new Amplitude( + "K*(892)rho(770)_D", new Variable("amp_real3", 26.537), new Variable("amp_imag3", 12.284), LSKRD, SFKRD, 2); + + Amplitude *Bose_symmetrized_AMP_S_B = new Amplitude( + "B_K*(892)rho(770)_S", new Variable("amp_real1", 1.0), new Variable("amp_imag1", 0), LSKRS, SFKRS, 2); + Amplitude *Bose_symmetrized_AMP_P_B = new Amplitude( + "B_K*(892)rho(770)_P", new Variable("amp_real2", -0.145), new Variable("amp_imag2", 0.86), LSKRP, SFKRP, 2); + Amplitude *Bose_symmetrized_AMP_D_B = new Amplitude( + "B_K*(892)rho(770)_D", new Variable("amp_real3", 24.343), new Variable("amp_imag3", 5.329), LSKRD, SFKRD, 2); DK3P_DI->amplitudes_B.push_back(Bose_symmetrized_AMP_S); DK3P_DI->amplitudes_B.push_back(Bose_symmetrized_AMP_P); @@ -142,25 +136,25 @@ int main(int argc, char** argv) { DK3P_DI->amplitudes.push_back(Bose_symmetrized_AMP_P_B); DK3P_DI->amplitudes.push_back(Bose_symmetrized_AMP_D_B); - DK3P_DI->_tau = new Variable("tau", 0.4101, 0.001, 0.300, 0.500); - DK3P_DI->_xmixing = new Variable("xmixing", 0.005, 0.001, 0, 0); - DK3P_DI->_ymixing = new Variable("ymixing", 0.01, 0.001, 0, 0); - DK3P_DI->_SqWStoRSrate = new Variable("SqWStoRSrate", 1.0/sqrt(300.0)); - - Variable* m12 = new Variable("m12", 0, 3); - Variable* m34 = new Variable("m34", 0, 3); - Variable* cos12 = new Variable("cos12", -1, 1); - Variable* cos34 = new Variable("m12", -1, 1); - Variable* phi = new Variable("phi", -3.5, 3.5); - CountingVariable* eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); - Variable* dtime = new Variable("dtime", 0, 10); - Variable* sigmat = new Variable("sigmat", -3, 3); - Variable* constantOne = new Variable("constantOne", 1); - Variable* constantZero = new Variable("constantZero", 0); - - vector observables; - vector coefficients; - vector offsets; + DK3P_DI->_tau = new Variable("tau", 0.4101, 0.001, 0.300, 0.500); + DK3P_DI->_xmixing = new Variable("xmixing", 0.005, 0.001, 0, 0); + DK3P_DI->_ymixing = new Variable("ymixing", 0.01, 0.001, 0, 0); + DK3P_DI->_SqWStoRSrate = new Variable("SqWStoRSrate", 1.0 / sqrt(300.0)); + + Variable *m12 = new Variable("m12", 0, 3); + Variable *m34 = new Variable("m34", 0, 3); + Variable *cos12 = new Variable("cos12", -1, 1); + Variable *cos34 = new Variable("m12", -1, 1); + Variable *phi = new Variable("phi", -3.5, 3.5); + CountingVariable *eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); + Variable *dtime = new Variable("dtime", 0, 10); + Variable *sigmat = new Variable("sigmat", -3, 3); + Variable *constantOne = new Variable("constantOne", 1); + Variable *constantZero = new Variable("constantZero", 0); + + vector observables; + vector coefficients; + vector offsets; observables.push_back(m12); observables.push_back(m34); @@ -174,71 +168,73 @@ int main(int argc, char** argv) { offsets.push_back(constantZero); coefficients.push_back(constantOne); - TruthResolution* dat = new TruthResolution(); - PolynomialPdf* eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); - TDDP4* dp = new TDDP4("test", observables, DK3P_DI, dat, eff, 0, 1); + TruthResolution *dat = new TruthResolution(); + PolynomialPdf *eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); + TDDP4 *dp = new TDDP4("test", observables, DK3P_DI, dat, eff, 0, 1); - TFile* file = new TFile(output, "RECREATE"); - TTree* tree = new TTree("events", "events"); + TFile *file = new TFile(output, "RECREATE"); + TTree *tree = new TTree("events", "events"); double tm12, tm34, tc12, tc34, tphi, tdtime, D0_E, D0_Px, D0_Py, D0_Pz, Kplus_E, Kplus_Px, Kplus_Py, Kplus_Pz, - Piminus1_E, Piminus1_Px, Piminus1_Py, Piminus1_Pz, Piminus2_E, Piminus2_Px, Piminus2_Py, Piminus2_Pz, Piplus_E, - Piplus_Px, Piplus_Py, Piplus_Pz; + Piminus1_E, Piminus1_Px, Piminus1_Py, Piminus1_Pz, Piminus2_E, Piminus2_Px, Piminus2_Py, Piminus2_Pz, Piplus_E, + Piplus_Px, Piplus_Py, Piplus_Pz; int D0_pdg, Kplus_pdg, Piminus1_pdg, Piminus2_pdg, Piplus_pdg; - tree->Branch("m12", &tm12, "m12/D"); - tree->Branch("m34", &tm34, "m34/D"); - tree->Branch("c12", &tc12, "c12/D"); - tree->Branch("c34", &tc34, "c34/D"); - tree->Branch("phi", &tphi, "phi/D"); - tree->Branch("dtime", &tdtime, "dtime/D"); - tree->Branch("D0_E", &D0_E, "D0_E/D"); - tree->Branch("D0_Px", &D0_Px, "D0_Px/D"); - tree->Branch("D0_Py", &D0_Py, "D0_Py/D"); - tree->Branch("D0_Pz", &D0_Pz, "D0_Pz/D"); - tree->Branch("D0_pdg", &D0_pdg, "D0_pdg/I"); - tree->Branch("Kplus_E", &Kplus_E, "Kplus_E/D"); - tree->Branch("Kplus_Px", &Kplus_Px, "Kplus_Px/D"); - tree->Branch("Kplus_Py", &Kplus_Py, "Kplus_Py/D"); - tree->Branch("Kplus_Pz", &Kplus_Pz, "Kplus_Pz/D"); - tree->Branch("Kplus_pdg", &Kplus_pdg, "Kplus_pdg/I"); - tree->Branch("Piminus1_E", &Piminus1_E, "Piminus1_E/D"); - tree->Branch("Piminus1_Px", &Piminus1_Px, "Piminus1_Px/D"); - tree->Branch("Piminus1_Py", &Piminus1_Py, "Piminus1_Py/D"); - tree->Branch("Piminus1_Pz", &Piminus1_Pz, "Piminus1_Pz/D"); + tree->Branch("m12", &tm12, "m12/D"); + tree->Branch("m34", &tm34, "m34/D"); + tree->Branch("c12", &tc12, "c12/D"); + tree->Branch("c34", &tc34, "c34/D"); + tree->Branch("phi", &tphi, "phi/D"); + tree->Branch("dtime", &tdtime, "dtime/D"); + tree->Branch("D0_E", &D0_E, "D0_E/D"); + tree->Branch("D0_Px", &D0_Px, "D0_Px/D"); + tree->Branch("D0_Py", &D0_Py, "D0_Py/D"); + tree->Branch("D0_Pz", &D0_Pz, "D0_Pz/D"); + tree->Branch("D0_pdg", &D0_pdg, "D0_pdg/I"); + tree->Branch("Kplus_E", &Kplus_E, "Kplus_E/D"); + tree->Branch("Kplus_Px", &Kplus_Px, "Kplus_Px/D"); + tree->Branch("Kplus_Py", &Kplus_Py, "Kplus_Py/D"); + tree->Branch("Kplus_Pz", &Kplus_Pz, "Kplus_Pz/D"); + tree->Branch("Kplus_pdg", &Kplus_pdg, "Kplus_pdg/I"); + tree->Branch("Piminus1_E", &Piminus1_E, "Piminus1_E/D"); + tree->Branch("Piminus1_Px", &Piminus1_Px, "Piminus1_Px/D"); + tree->Branch("Piminus1_Py", &Piminus1_Py, "Piminus1_Py/D"); + tree->Branch("Piminus1_Pz", &Piminus1_Pz, "Piminus1_Pz/D"); tree->Branch("Piminus1_pdg", &Piminus1_pdg, "Piminus1_pdg/I"); - tree->Branch("Piminus2_E", &Piminus2_E, "Piminus2_E/D"); - tree->Branch("Piminus2_Px", &Piminus2_Px, "Piminus2_Px/D"); - tree->Branch("Piminus2_Py", &Piminus2_Py, "Piminus2_Py/D"); - tree->Branch("Piminus2_Pz", &Piminus2_Pz, "Piminus2_Pz/D"); + tree->Branch("Piminus2_E", &Piminus2_E, "Piminus2_E/D"); + tree->Branch("Piminus2_Px", &Piminus2_Px, "Piminus2_Px/D"); + tree->Branch("Piminus2_Py", &Piminus2_Py, "Piminus2_Py/D"); + tree->Branch("Piminus2_Pz", &Piminus2_Pz, "Piminus2_Pz/D"); tree->Branch("Piminus2_pdg", &Piminus2_pdg, "Piminus2_pdg/I"); - tree->Branch("Piplus_E", &Piplus_E, "Piplus_E/D"); - tree->Branch("Piplus_Px", &Piplus_Px, "Piplus_Px/D"); - tree->Branch("Piplus_Py", &Piplus_Py, "Piplus_Py/D"); - tree->Branch("Piplus_Pz", &Piplus_Pz, "Piplus_Pz/D"); - tree->Branch("Piplus_pdg", &Piplus_pdg, "Piplus_pdg/I"); + tree->Branch("Piplus_E", &Piplus_E, "Piplus_E/D"); + tree->Branch("Piplus_Px", &Piplus_Px, "Piplus_Px/D"); + tree->Branch("Piplus_Py", &Piplus_Py, "Piplus_Py/D"); + tree->Branch("Piplus_Pz", &Piplus_Pz, "Piplus_Pz/D"); + tree->Branch("Piplus_pdg", &Piplus_pdg, "Piplus_pdg/I"); for(int k = 0; k < trials; ++k) { int numEvents = .8e6; - dp->setGenerationOffset(k*numEvents); + dp->setGenerationOffset(k * numEvents); auto tuple = dp->GenerateSig(numEvents); auto particles = std::get<0>(tuple); auto variables = std::get<1>(tuple); - auto weights = std::get<2>(tuple); - auto flags = std::get<3>(tuple); - int accepted = thrust::count_if(flags.begin(), flags.end(), thrust::identity()); - GOOFIT_INFO("Run #{}: Using accept-reject method would leave you with {} out of {} events", k, accepted, numEvents); + auto weights = std::get<2>(tuple); + auto flags = std::get<3>(tuple); + int accepted = thrust::count_if(flags.begin(), flags.end(), thrust::identity()); + GOOFIT_INFO( + "Run #{}: Using accept-reject method would leave you with {} out of {} events", k, accepted, numEvents); for(int i = 0; i < weights.size(); ++i) { if(flags[i] == 1) { - // printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g\n", (*(variables[0]))[i], (*(variables[1]))[i], (*(variables[2]))[i], (*(variables[3]))[i], (*(variables[4]))[i], weights[i], flags[i]); - tm12 = (*(variables[0]))[i]; - tm34 = (*(variables[1]))[i]; - tc12 = (*(variables[2]))[i]; - tc34 = (*(variables[3]))[i]; - tphi = (*(variables[4]))[i]; - tdtime = (*(variables[5]))[i]; + // printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g\n", (*(variables[0]))[i], (*(variables[1]))[i], + // (*(variables[2]))[i], (*(variables[3]))[i], (*(variables[4]))[i], weights[i], flags[i]); + tm12 = (*(variables[0]))[i]; + tm34 = (*(variables[1]))[i]; + tc12 = (*(variables[2]))[i]; + tc34 = (*(variables[3]))[i]; + tphi = (*(variables[4]))[i]; + tdtime = (*(variables[5]))[i]; D0_E = 1864; D0_Px = 0.0; D0_Py = 0.0; @@ -265,7 +261,6 @@ int main(int argc, char** argv) { Piplus_Pz = 1000 * (*(particles[1]))[i].get(3); Piplus_pdg = -211; - tree->Fill(); } } @@ -286,5 +281,4 @@ int main(int argc, char** argv) { tree->Write(); file->Close(); return 0; - } diff --git a/examples/addition/addition.cu b/examples/addition/addition.cu index 60e04d683..3ff2fb32a 100644 --- a/examples/addition/addition.cu +++ b/examples/addition/addition.cu @@ -19,12 +19,12 @@ using namespace std; using namespace GooFit; -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Addition example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -41,13 +41,12 @@ int main(int argc, char** argv) { gStyle->SetLineColor(1); gStyle->SetPalette(1, 0); - vector vars; - Variable* xvar = new Variable("xvar", -5, 5); + vector vars; + Variable *xvar = new Variable("xvar", -5, 5); vars.push_back(xvar); UnbinnedDataSet data(vars); - TH1F xvarHist("xvarHist", "", - xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); + TH1F xvarHist("xvarHist", "", xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); xvarHist.SetStats(false); @@ -70,21 +69,21 @@ int main(int argc, char** argv) { totalData++; } - Variable* xmean = new Variable("xmean", 0, 1, -10, 10); - Variable* xsigm = new Variable("xsigm", 1, 0.5, 1.5); + Variable *xmean = new Variable("xmean", 0, 1, -10, 10); + Variable *xsigm = new Variable("xsigm", 1, 0.5, 1.5); GaussianPdf signal("signal", xvar, xmean, xsigm); vars.clear(); - Variable* constant = new Variable("constant", 1.0); + Variable *constant = new Variable("constant", 1.0); vars.push_back(constant); PolynomialPdf backgr("backgr", xvar, vars); - vector comps; + vector comps; comps.push_back(&signal); comps.push_back(&backgr); vars.clear(); - Variable* sigFrac = new Variable("sigFrac", 0.9, 0.75, 1.00); + Variable *sigFrac = new Variable("sigFrac", 0.9, 0.75, 1.00); vars.push_back(sigFrac); AddPdf total("total", vars, comps); @@ -92,12 +91,9 @@ int main(int argc, char** argv) { FitManager fitter(&total); fitter.fit(); - TH1F pdfHist("pdfHist", "", - xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); - TH1F sigHist("sigHist", "", - xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); - TH1F bkgHist("bkgHist", "", - xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); + TH1F pdfHist("pdfHist", "", xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); + TH1F sigHist("sigHist", "", xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); + TH1F bkgHist("bkgHist", "", xvar->getNumBins(), xvar->getLowerLimit(), xvar->getUpperLimit()); pdfHist.SetStats(false); sigHist.SetStats(false); @@ -106,7 +102,7 @@ int main(int argc, char** argv) { UnbinnedDataSet grid(xvar); for(int i = 0; i < xvar->getNumBins(); ++i) { - double step = (xvar->getUpperLimit() - xvar->getLowerLimit())/xvar->getNumBins(); + double step = (xvar->getUpperLimit() - xvar->getLowerLimit()) / xvar->getNumBins(); xvar->setValue(xvar->getLowerLimit() + (i + 0.5) * step); grid.addEvent(); } @@ -127,20 +123,20 @@ int main(int argc, char** argv) { } for(int i = 0; i < xvar->getNumBins(); ++i) { - double val = pdfHist.GetBinContent(i+1); + double val = pdfHist.GetBinContent(i + 1); val /= totalPdf; val *= totalData; - pdfHist.SetBinContent(i+1, val); - val = sigHist.GetBinContent(i+1); + pdfHist.SetBinContent(i + 1, val); + val = sigHist.GetBinContent(i + 1); val /= totalPdf; val *= sigFrac->getValue(); val *= totalData; - sigHist.SetBinContent(i+1, val); - val = bkgHist.GetBinContent(i+1); + sigHist.SetBinContent(i + 1, val); + val = bkgHist.GetBinContent(i + 1); val /= totalPdf; val *= (1.0 - sigFrac->getValue()); val *= totalData; - bkgHist.SetBinContent(i+1, val); + bkgHist.SetBinContent(i + 1, val); } xvarHist.SetMarkerStyle(8); @@ -158,7 +154,5 @@ int main(int argc, char** argv) { bkgHist.Draw("lsame"); foo.SaveAs("xhist.png"); - - return 0; } diff --git a/examples/chisquare/chisquare.cu b/examples/chisquare/chisquare.cu index 27d1980d1..990e56251 100644 --- a/examples/chisquare/chisquare.cu +++ b/examples/chisquare/chisquare.cu @@ -25,62 +25,59 @@ timeval startTime, stopTime, totalTime; using namespace std; using namespace GooFit; -Variable* decayTime = 0; -Variable* constaCoef = 0; -Variable* linearCoef = 0; -Variable* secondCoef = 0; +Variable *decayTime = 0; +Variable *constaCoef = 0; +Variable *linearCoef = 0; +Variable *secondCoef = 0; -double integralExpCon(double lo, double hi) { - return (exp(-lo) - exp(-hi)); -} +double integralExpCon(double lo, double hi) { return (exp(-lo) - exp(-hi)); } -double integralExpLin(double lo, double hi) { - return ((lo + 1)*exp(-lo) - (hi + 1)*exp(-hi)); -} +double integralExpLin(double lo, double hi) { return ((lo + 1) * exp(-lo) - (hi + 1) * exp(-hi)); } double integralExpSqu(double lo, double hi) { - return ((lo*lo + 2*lo + 2)*exp(-lo) - (hi*hi + 2*hi + 2)*exp(-hi)); + return ((lo * lo + 2 * lo + 2) * exp(-lo) - (hi * hi + 2 * hi + 2) * exp(-hi)); } -void generateEvents(vector& rsEvtVec, vector& wsEvtVec, - Variable const* const decayTime, +void generateEvents(vector &rsEvtVec, + vector &wsEvtVec, + Variable const *const decayTime, double conCoef, double linCoef, double squCoef, int eventsToGenerate) { - static TRandom donram(24); double totalRSintegral = integralExpCon(0, 100); - double step = (decayTime->getUpperLimit() - decayTime->getLowerLimit()) / decayTime->getNumBins(); + double step = (decayTime->getUpperLimit() - decayTime->getLowerLimit()) / decayTime->getNumBins(); for(int i = 0; i < decayTime->getNumBins(); ++i) { - double binStart = i*step; + double binStart = i * step; binStart += decayTime->getLowerLimit(); double binFinal = binStart + step; double rsIntegral = integralExpCon(binStart, binFinal); double wsIntegral = conCoef * integralExpCon(binStart, binFinal); - wsIntegral += linCoef * integralExpLin(binStart, binFinal); - wsIntegral += squCoef * integralExpSqu(binStart, binFinal); + wsIntegral += linCoef * integralExpLin(binStart, binFinal); + wsIntegral += squCoef * integralExpSqu(binStart, binFinal); - double expectedRSevts = eventsToGenerate*rsIntegral / totalRSintegral; - double expectedWSevts = eventsToGenerate*wsIntegral / totalRSintegral; + double expectedRSevts = eventsToGenerate * rsIntegral / totalRSintegral; + double expectedWSevts = eventsToGenerate * wsIntegral / totalRSintegral; - int rsEvts = donram.Poisson(expectedRSevts); - int wsEvts = donram.Poisson(expectedWSevts); + int rsEvts = donram.Poisson(expectedRSevts); + int wsEvts = donram.Poisson(expectedWSevts); rsEvtVec[i] = rsEvts; wsEvtVec[i] = wsEvts; if(0 == (i % 10)) - std::cout << "Events in bin " << i << " : " << rsEvts << " (" << expectedRSevts << ") " - << wsEvts << " (" << expectedWSevts << ")\n"; + std::cout << "Events in bin " << i << " : " << rsEvts << " (" << expectedRSevts << ") " << wsEvts << " (" + << expectedWSevts << ")\n"; } } -int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "") { - TH1D* ratioHist = new TH1D("ratioHist", "", decayTime->getNumBins(), decayTime->getLowerLimit(), decayTime->getUpperLimit()); +int fitRatio(vector &rsEvts, vector &wsEvts, std::string plotName = "") { + TH1D *ratioHist + = new TH1D("ratioHist", "", decayTime->getNumBins(), decayTime->getLowerLimit(), decayTime->getUpperLimit()); - BinnedDataSet* ratioData = new BinnedDataSet(decayTime); + BinnedDataSet *ratioData = new BinnedDataSet(decayTime); for(unsigned int i = 0; i < wsEvts.size(); ++i) { double ratio = wsEvts[i]; @@ -94,13 +91,13 @@ int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "" wsEvts[i] = 1; // Avoid zero errors double error = wsEvts[i] / pow(rsEvts[i], 2); - error += pow(wsEvts[i], 2) / pow(rsEvts[i], 3); - error = sqrt(error); + error += pow(wsEvts[i], 2) / pow(rsEvts[i], 3); + error = sqrt(error); ratioData->setBinContent(i, ratio); ratioData->setBinError(i, error); - ratioHist->SetBinContent(i+1, ratio); - ratioHist->SetBinError(i+1, error); + ratioHist->SetBinContent(i + 1, ratio); + ratioHist->SetBinError(i + 1, error); } if(0 == constaCoef) { @@ -115,15 +112,15 @@ int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "" secondCoef->setError(0.01); } - vector weights; + vector weights; weights.push_back(constaCoef); weights.push_back(linearCoef); weights.push_back(secondCoef); - PolynomialPdf* poly = new PolynomialPdf("poly", decayTime, weights); + PolynomialPdf *poly = new PolynomialPdf("poly", decayTime, weights); poly->setFitControl(new BinnedErrorFit()); poly->setData(ratioData); - FitManager datapdf {poly}; + FitManager datapdf{poly}; gettimeofday(&startTime, nullptr); datapdf.fit(); @@ -133,7 +130,7 @@ int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "" TH1D pdfHist("pdfHist", "", decayTime->getNumBins(), decayTime->getLowerLimit(), decayTime->getUpperLimit()); for(int i = 0; i < values.size(); ++i) { - pdfHist.SetBinContent(i+1, values[i]); + pdfHist.SetBinContent(i + 1, values[i]); } ratioHist->SetMarkerStyle(8); @@ -142,13 +139,16 @@ int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "" ratioHist->Draw("p"); char strbuffer[1000]; - sprintf(strbuffer, "Constant [10^{-2}] : %.3f #pm %.3f", 1e2*constaCoef->getValue(), constaCoef->getError()*1e2); + sprintf( + strbuffer, "Constant [10^{-2}] : %.3f #pm %.3f", 1e2 * constaCoef->getValue(), constaCoef->getError() * 1e2); TLatex res1(0.14, 0.83, strbuffer); res1.SetNDC(true); - sprintf(strbuffer, "Linear [10^{-4}] : %.3f #pm %.3f", 1e4*linearCoef->getValue(), linearCoef->getError()*1e4); + sprintf( + strbuffer, "Linear [10^{-4}] : %.3f #pm %.3f", 1e4 * linearCoef->getValue(), linearCoef->getError() * 1e4); TLatex res2(0.14, 0.73, strbuffer); res2.SetNDC(true); - sprintf(strbuffer, "Quadratic [10^{-6}]: %.3f #pm %.3f", 1e6*secondCoef->getValue(), secondCoef->getError()*1e6); + sprintf( + strbuffer, "Quadratic [10^{-6}]: %.3f #pm %.3f", 1e6 * secondCoef->getValue(), secondCoef->getError() * 1e6); TLatex res3(0.14, 0.63, strbuffer); res3.SetNDC(true); @@ -162,28 +162,25 @@ int fitRatio(vector& rsEvts, vector& wsEvts, std::string plotName = "" pdfHist.Draw("lsame"); foo.SaveAs(plotName.c_str()); - std::cout << "Polynomial function: " - << poly->getCoefficient(2) << " * t^2 + " - << poly->getCoefficient(1) << " * t + " - << poly->getCoefficient(0) << std::endl; + std::cout << "Polynomial function: " << poly->getCoefficient(2) << " * t^2 + " << poly->getCoefficient(1) + << " * t + " << poly->getCoefficient(0) << std::endl; delete ratioHist; delete ratioData; delete poly; - + return datapdf; } - -double dzero_con = 0; -double dzero_lin = 0; -double dzero_qua = 0; +double dzero_con = 0; +double dzero_lin = 0; +double dzero_qua = 0; double dzero_con_err = 0; double dzero_lin_err = 0; double dzero_qua_err = 0; -double d0bar_con = 0; -double d0bar_lin = 0; -double d0bar_qua = 0; +double d0bar_con = 0; +double d0bar_lin = 0; +double d0bar_qua = 0; double d0bar_con_err = 0; double d0bar_lin_err = 0; double d0bar_qua_err = 0; @@ -191,25 +188,26 @@ double d0bar_qua_err = 0; vector ratios; vector errors; -void cpvFitFcn(int& npar, double* gin, double& fun, double* fp, int iflag) { +void cpvFitFcn(int &npar, double *gin, double &fun, double *fp, int iflag) { double conCoef = fp[0]; double linCoef = fp[1]; double squCoef = fp[2]; double chisq = 0; - double step = (decayTime->getUpperLimit() - decayTime->getLowerLimit()) / decayTime->getNumBins(); + double step = (decayTime->getUpperLimit() - decayTime->getLowerLimit()) / decayTime->getNumBins(); for(unsigned int i = 0; i < ratios.size(); ++i) { - double currDTime = decayTime->getLowerLimit() + (i+0.5)*step; - double pdfval = conCoef + linCoef*currDTime + squCoef*currDTime*currDTime; + double currDTime = decayTime->getLowerLimit() + (i + 0.5) * step; + double pdfval = conCoef + linCoef * currDTime + squCoef * currDTime * currDTime; chisq += pow((pdfval - ratios[i]) / errors[i], 2); } fun = chisq; } -void fitRatioCPU(vector& rsEvts, vector& wsEvts) { - TH1D* ratioHist = new TH1D("ratioHist", "", decayTime->getNumBins(), decayTime->getLowerLimit(), decayTime->getUpperLimit()); +void fitRatioCPU(vector &rsEvts, vector &wsEvts) { + TH1D *ratioHist + = new TH1D("ratioHist", "", decayTime->getNumBins(), decayTime->getLowerLimit(), decayTime->getUpperLimit()); ratios.resize(wsEvts.size()); errors.resize(wsEvts.size()); @@ -226,16 +224,16 @@ void fitRatioCPU(vector& rsEvts, vector& wsEvts) { wsEvts[i] = 1; // Avoid zero errors double error = wsEvts[i] / pow(rsEvts[i], 2); - error += pow(wsEvts[i], 2) / pow(rsEvts[i], 3); - error = sqrt(error); + error += pow(wsEvts[i], 2) / pow(rsEvts[i], 3); + error = sqrt(error); ratios[i] = ratio; errors[i] = error; - ratioHist->SetBinContent(i+1, ratio); - ratioHist->SetBinError(i+1, error); + ratioHist->SetBinContent(i + 1, ratio); + ratioHist->SetBinError(i + 1, error); } - TMinuit* minuit = new TMinuit(3); + TMinuit *minuit = new TMinuit(3); minuit->DefineParameter(0, "constaCoef", 0.03, 0.01, -1, 1); minuit->DefineParameter(1, "linearCoef", 0, 0.01, -1, 1); minuit->DefineParameter(2, "secondCoef", 0, 0.01, -1, 1); @@ -246,9 +244,7 @@ void fitRatioCPU(vector& rsEvts, vector& wsEvts) { gettimeofday(&stopTime, nullptr); } - -int main(int argc, char** argv) { - +int main(int argc, char **argv) { GooFit::Application app("Chi-square example", argc, argv); int numbins = 100; @@ -256,7 +252,7 @@ int main(int argc, char** argv) { try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -279,11 +275,11 @@ int main(int argc, char** argv) { vector d0barEvtsWS(decayTime->getNumBins()); vector d0barEvtsRS(decayTime->getNumBins()); - double dZeroLinearCoef = magPQ*sqrt(rSubD)*(y_mix*cos(delta+wpPhi) - x_mix*sin(delta+wpPhi)); - double d0barLinearCoef = magQP*sqrt(rBarD)*(y_mix*cos(delta-wpPhi) - x_mix*sin(delta-wpPhi)); + double dZeroLinearCoef = magPQ * sqrt(rSubD) * (y_mix * cos(delta + wpPhi) - x_mix * sin(delta + wpPhi)); + double d0barLinearCoef = magQP * sqrt(rBarD) * (y_mix * cos(delta - wpPhi) - x_mix * sin(delta - wpPhi)); - double dZeroSecondCoef = 0.25*magPQ*magPQ*(x_mix*x_mix+y_mix*y_mix); - double d0barSecondCoef = 0.25*magQP*magQP*(x_mix*x_mix+y_mix*y_mix); + double dZeroSecondCoef = 0.25 * magPQ * magPQ * (x_mix * x_mix + y_mix * y_mix); + double d0barSecondCoef = 0.25 * magQP * magQP * (x_mix * x_mix + y_mix * y_mix); generateEvents(dZeroEvtsRS, dZeroEvtsWS, decayTime, rSubD, dZeroLinearCoef, dZeroSecondCoef, eventsToGenerate); generateEvents(d0barEvtsRS, d0barEvtsWS, decayTime, rBarD, d0barLinearCoef, d0barSecondCoef, eventsToGenerate); @@ -296,24 +292,21 @@ int main(int argc, char** argv) { if(retval != 0) return retval; timersub(&stopTime, &startTime, &totalTime); - gpuTime += totalTime.tv_sec + totalTime.tv_usec/1000000.0; + gpuTime += totalTime.tv_sec + totalTime.tv_usec / 1000000.0; retval = fitRatio(d0barEvtsRS, d0barEvtsWS, "dzbarEvtRatio.png"); if(retval != 0) return retval; timersub(&stopTime, &startTime, &totalTime); - gpuTime += totalTime.tv_sec + totalTime.tv_usec/1000000.0; - + gpuTime += totalTime.tv_sec + totalTime.tv_usec / 1000000.0; fitRatioCPU(dZeroEvtsRS, dZeroEvtsWS); timersub(&stopTime, &startTime, &totalTime); - cpuTime += totalTime.tv_sec + totalTime.tv_usec/1000000.0; + cpuTime += totalTime.tv_sec + totalTime.tv_usec / 1000000.0; fitRatioCPU(d0barEvtsRS, d0barEvtsWS); timersub(&stopTime, &startTime, &totalTime); - cpuTime += totalTime.tv_sec + totalTime.tv_usec/1000000.0; + cpuTime += totalTime.tv_sec + totalTime.tv_usec / 1000000.0; - std::cout << "GPU time [seconds] : " << gpuTime - << "\nCPU time [seconds] : " << cpuTime - << std::endl; + std::cout << "GPU time [seconds] : " << gpuTime << "\nCPU time [seconds] : " << cpuTime << std::endl; return 0; } diff --git a/examples/convolution/convolution.cu b/examples/convolution/convolution.cu index d90e697b8..390c37fba 100644 --- a/examples/convolution/convolution.cu +++ b/examples/convolution/convolution.cu @@ -13,17 +13,17 @@ using namespace GooFit; double cpu_bw(double x, double x0, double gamma) { double ret = gamma; - ret /= (2*sqrt(M_PI)); - ret /= ((x-x0)*(x-x0) + 0.25*gamma*gamma); + ret /= (2 * sqrt(M_PI)); + ret /= ((x - x0) * (x - x0) + 0.25 * gamma * gamma); return ret; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Convolution example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -44,7 +44,7 @@ int main(int argc, char** argv) { xvar.setValue(donram.Uniform(20) - 10); double bwvalue = cpu_bw(xvar.getValue(), x0.getValue(), gamma.getValue()); - double roll = donram.Uniform() * (2.0 / (sqrt(M_PI)*gamma.getValue())); + double roll = donram.Uniform() * (2.0 / (sqrt(M_PI) * gamma.getValue())); if(roll > bwvalue) { --i; diff --git a/examples/dalitz/dalitz.cu b/examples/dalitz/dalitz.cu index dabaa3877..2a4ed5ff9 100644 --- a/examples/dalitz/dalitz.cu +++ b/examples/dalitz/dalitz.cu @@ -31,44 +31,50 @@ using namespace std; using namespace GooFit; -TCanvas* foo; -TCanvas* foodal; -UnbinnedDataSet* data = 0; - -Variable* m12 = 0; -Variable* m13 = 0; -CountingVariable* eventNumber = 0; -bool fitMasses = false; -Variable* fixedRhoMass = new Variable("rho_mass", 0.7758, 0.01, 0.7, 0.8); -Variable* fixedRhoWidth = new Variable("rho_width", 0.1503, 0.01, 0.1, 0.2); - -const fptype _mD0 = 1.86484; -const fptype _mD02 = _mD0 *_mD0; -const fptype _mD02inv = 1./_mD02; +TCanvas *foo; +TCanvas *foodal; +UnbinnedDataSet *data = 0; + +Variable *m12 = 0; +Variable *m13 = 0; +CountingVariable *eventNumber = 0; +bool fitMasses = false; +Variable *fixedRhoMass = new Variable("rho_mass", 0.7758, 0.01, 0.7, 0.8); +Variable *fixedRhoWidth = new Variable("rho_width", 0.1503, 0.01, 0.1, 0.2); + +const fptype _mD0 = 1.86484; +const fptype _mD02 = _mD0 * _mD0; +const fptype _mD02inv = 1. / _mD02; const fptype piPlusMass = 0.13957018; const fptype piZeroMass = 0.1349766; // Constants used in more than one PDF component. -Variable* motherM = new Variable("motherM", _mD0); -Variable* chargeM = new Variable("chargeM", piPlusMass); -Variable* neutrlM = new Variable("neutrlM", piZeroMass); -Variable* massSum = new Variable("massSum", _mD0*_mD0 + 2*piPlusMass*piPlusMass + piZeroMass* piZeroMass); // = 3.53481 -Variable* constantOne = new Variable("constantOne", 1); -Variable* constantZero = new Variable("constantZero", 0); +Variable *motherM = new Variable("motherM", _mD0); +Variable *chargeM = new Variable("chargeM", piPlusMass); +Variable *neutrlM = new Variable("neutrlM", piZeroMass); +Variable *massSum + = new Variable("massSum", _mD0 *_mD0 + 2 * piPlusMass * piPlusMass + piZeroMass * piZeroMass); // = 3.53481 +Variable *constantOne = new Variable("constantOne", 1); +Variable *constantZero = new Variable("constantZero", 0); -GooPdf* kzero_veto = 0; +GooPdf *kzero_veto = 0; fptype cpuGetM23(fptype massPZ, fptype massPM) { - return (_mD02 + piZeroMass*piZeroMass + piPlusMass*piPlusMass + piPlusMass*piPlusMass - massPZ - massPM); + return (_mD02 + piZeroMass * piZeroMass + piPlusMass * piPlusMass + piPlusMass * piPlusMass - massPZ - massPM); } void getToyData(std::string toyFileName, GooFit::Application &app) { - toyFileName = app.get_filename(toyFileName, "examples/dalitz"); - - TH2F dalitzplot("dalitzplot", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), m13->getLowerLimit(), + + TH2F dalitzplot("dalitzplot", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), m13->getUpperLimit()); - std::vector vars; + std::vector vars; vars.push_back(m12); vars.push_back(m13); vars.push_back(eventNumber); @@ -90,8 +96,8 @@ void getToyData(std::string toyFileName, GooFit::Application &app) { while(!reader.eof()) { reader >> dummy; - reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. - reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) + reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. + reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) reader >> *m13; // Errors on Dalitz variables @@ -134,191 +140,182 @@ void getToyData(std::string toyFileName, GooFit::Application &app) { foodal->SaveAs("dalitzplot.png"); } -GooPdf* makeKzeroVeto() { +GooPdf *makeKzeroVeto() { if(kzero_veto) return kzero_veto; - VetoInfo* kVetoInfo = new VetoInfo(); + VetoInfo *kVetoInfo = new VetoInfo(); kVetoInfo->cyclic_index = PAIR_23; - kVetoInfo->minimum = new Variable("veto_min", 0.475*0.475); - kVetoInfo->maximum = new Variable("veto_max", 0.505*0.505); - vector vetos; + kVetoInfo->minimum = new Variable("veto_min", 0.475 * 0.475); + kVetoInfo->maximum = new Variable("veto_max", 0.505 * 0.505); + vector vetos; vetos.push_back(kVetoInfo); kzero_veto = new DalitzVetoPdf("kzero_veto", m12, m13, motherM, neutrlM, chargeM, chargeM, vetos); return kzero_veto; } -DalitzPlotPdf* makeSignalPdf(GooPdf* eff = 0) { - DecayInfo* dtop0pp = new DecayInfo(); - dtop0pp->motherMass = _mD0; - dtop0pp->daug1Mass = piZeroMass; - dtop0pp->daug2Mass = piPlusMass; - dtop0pp->daug3Mass = piPlusMass; - dtop0pp->meson_radius = 1.5; - - ResonancePdf* rhop = new ResonancePdf("rhop", - new Variable("rhop_amp_real", 1), - new Variable("rhop_amp_imag", 0), - fixedRhoMass, - fixedRhoWidth, - 1, - PAIR_12); - +DalitzPlotPdf *makeSignalPdf(GooPdf *eff = 0) { + DecayInfo *dtop0pp = new DecayInfo(); + dtop0pp->motherMass = _mD0; + dtop0pp->daug1Mass = piZeroMass; + dtop0pp->daug2Mass = piPlusMass; + dtop0pp->daug3Mass = piPlusMass; + dtop0pp->meson_radius = 1.5; + + ResonancePdf *rhop = new ResonancePdf("rhop", + new Variable("rhop_amp_real", 1), + new Variable("rhop_amp_imag", 0), + fixedRhoMass, + fixedRhoWidth, + 1, + PAIR_12); bool fixAmps = false; - ResonancePdf* rhom = new ResonancePdf("rhom", - fixAmps ? new Variable("rhom_amp_real", 0.714) : - new Variable("rhom_amp_real", 0.714, 0.001, 0, 0), - fixAmps ? new Variable("rhom_amp_imag", -0.025) : - new Variable("rhom_amp_imag", -0.025, 0.1, 0, 0), - fixedRhoMass, - fixedRhoWidth, - 1, - PAIR_13); - - ResonancePdf* rho0 = new ResonancePdf("rho0", - fixAmps ? new Variable("rho0_amp_real", 0.565) : - new Variable("rho0_amp_real", 0.565, 0.001, 0, 0), - fixAmps ? new Variable("rho0_amp_imag", 0.164) : - new Variable("rho0_amp_imag", 0.164, 0.1, 0, 0), - fixedRhoMass, - fixedRhoWidth, - 1, - PAIR_23); - - Variable* sharedMass = new Variable("rhop_1450_mass", 1.465, 0.01, 1.0, 2.0); - Variable* shareWidth = new Variable("rhop_1450_width", 0.400, 0.01, 0.01, 5.0); - - ResonancePdf* rhop_1450 = new ResonancePdf("rhop_1450", - fixAmps ? new Variable("rhop_1450_amp_real", -0.174) : - new Variable("rhop_1450_amp_real", -0.174, 0.001, 0, 0), - fixAmps ? new Variable("rhop_1450_amp_imag", -0.117) : - new Variable("rhop_1450_amp_imag", -0.117, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_12); - - ResonancePdf* rho0_1450 = new ResonancePdf("rho0_1450", - fixAmps ? new Variable("rho0_1450_amp_real", 0.325) : - new Variable("rho0_1450_amp_real", 0.325, 0.001, 0, 0), - fixAmps ? new Variable("rho0_1450_amp_imag", 0.057) : - new Variable("rho0_1450_amp_imag", 0.057, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_23); - - ResonancePdf* rhom_1450 = new ResonancePdf("rhom_1450", - fixAmps ? new Variable("rhom_1450_amp_real", 0.788) : - new Variable("rhom_1450_amp_real", 0.788, 0.001, 0, 0), - fixAmps ? new Variable("rhom_1450_amp_imag", 0.226) : - new Variable("rhom_1450_amp_imag", 0.226, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_13); - - sharedMass = new Variable("rhop_1700_mass", 1.720, 0.01, 1.6, 1.9); + ResonancePdf *rhom = new ResonancePdf( + "rhom", + fixAmps ? new Variable("rhom_amp_real", 0.714) : new Variable("rhom_amp_real", 0.714, 0.001, 0, 0), + fixAmps ? new Variable("rhom_amp_imag", -0.025) : new Variable("rhom_amp_imag", -0.025, 0.1, 0, 0), + fixedRhoMass, + fixedRhoWidth, + 1, + PAIR_13); + + ResonancePdf *rho0 = new ResonancePdf( + "rho0", + fixAmps ? new Variable("rho0_amp_real", 0.565) : new Variable("rho0_amp_real", 0.565, 0.001, 0, 0), + fixAmps ? new Variable("rho0_amp_imag", 0.164) : new Variable("rho0_amp_imag", 0.164, 0.1, 0, 0), + fixedRhoMass, + fixedRhoWidth, + 1, + PAIR_23); + + Variable *sharedMass = new Variable("rhop_1450_mass", 1.465, 0.01, 1.0, 2.0); + Variable *shareWidth = new Variable("rhop_1450_width", 0.400, 0.01, 0.01, 5.0); + + ResonancePdf *rhop_1450 = new ResonancePdf( + "rhop_1450", + fixAmps ? new Variable("rhop_1450_amp_real", -0.174) : new Variable("rhop_1450_amp_real", -0.174, 0.001, 0, 0), + fixAmps ? new Variable("rhop_1450_amp_imag", -0.117) : new Variable("rhop_1450_amp_imag", -0.117, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_12); + + ResonancePdf *rho0_1450 = new ResonancePdf( + "rho0_1450", + fixAmps ? new Variable("rho0_1450_amp_real", 0.325) : new Variable("rho0_1450_amp_real", 0.325, 0.001, 0, 0), + fixAmps ? new Variable("rho0_1450_amp_imag", 0.057) : new Variable("rho0_1450_amp_imag", 0.057, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_23); + + ResonancePdf *rhom_1450 = new ResonancePdf( + "rhom_1450", + fixAmps ? new Variable("rhom_1450_amp_real", 0.788) : new Variable("rhom_1450_amp_real", 0.788, 0.001, 0, 0), + fixAmps ? new Variable("rhom_1450_amp_imag", 0.226) : new Variable("rhom_1450_amp_imag", 0.226, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_13); + + sharedMass = new Variable("rhop_1700_mass", 1.720, 0.01, 1.6, 1.9); shareWidth = new Variable("rhop_1700_width", 0.250, 0.01, 0.1, 1.0); - - ResonancePdf* rhop_1700 = new ResonancePdf("rhop_1700", - fixAmps ? new Variable("rhop_1700_amp_real", 2.151) : - new Variable("rhop_1700_amp_real", 2.151, 0.001, 0, 0), - fixAmps ? new Variable("rhop_1700_amp_imag", -0.658) : - new Variable("rhop_1700_amp_imag", -0.658, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_12); - - ResonancePdf* rho0_1700 = new ResonancePdf("rho0_1700", - fixAmps ? new Variable("rho0_1700_amp_real", 2.400) : - new Variable("rho0_1700_amp_real", 2.400, 0.001, 0, 0), - fixAmps ? new Variable("rho0_1700_amp_imag", -0.734) : - new Variable("rho0_1700_amp_imag", -0.734, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_23); - - ResonancePdf* rhom_1700 = new ResonancePdf("rhom_1700", - fixAmps ? new Variable("rhom_1700_amp_real", 1.286) : - new Variable("rhom_1700_amp_real", 1.286, 0.001, 0, 0), - fixAmps ? new Variable("rhom_1700_amp_imag", -1.532) : - new Variable("rhom_1700_amp_imag", -1.532, 0.1, 0, 0), - sharedMass, - shareWidth, - 1, - PAIR_13); - - ResonancePdf* f0_980 = new ResonancePdf("f0_980", - fixAmps ? new Variable("f0_980_amp_real", 0.008 * (-_mD02)) : - new Variable("f0_980_amp_real", 0.008 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_980_amp_imag", -0.013 * (-_mD02)) : - new Variable("f0_980_amp_imag", -0.013 * (-_mD02), 0.1, 0, 0), - new Variable("f0_980_mass", 0.980, 0.01, 0.8, 1.2), - new Variable("f0_980_width", 0.044, 0.001, 0.001, 0.08), - 0, - PAIR_23); - - ResonancePdf* f0_1370 = new ResonancePdf("f0_1370", - fixAmps ? new Variable("f0_1370_amp_real", -0.058 * (-_mD02)) : - new Variable("f0_1370_amp_real", -0.058 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1370_amp_imag", 0.026 * (-_mD02)) : - new Variable("f0_1370_amp_imag", 0.026 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1370_mass", 1.434, 0.01, 1.2, 1.6), - new Variable("f0_1370_width", 0.173, 0.01, 0.01, 0.4), - 0, - PAIR_23); - - ResonancePdf* f0_1500 = new ResonancePdf("f0_1500", - fixAmps ? new Variable("f0_1500_amp_real", 0.057 * (-_mD02)) : - new Variable("f0_1500_amp_real", 0.057 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1500_amp_imag", 0.012 * (-_mD02)) : - new Variable("f0_1500_amp_imag", 0.012 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1500_mass", 1.507, 0.01, 1.3, 1.7), - new Variable("f0_1500_width", 0.109, 0.01, 0.01, 0.3), - 0, - PAIR_23); - - ResonancePdf* f0_1710 = new ResonancePdf("f0_1710", - fixAmps ? new Variable("f0_1710_amp_real", 0.070 * (-_mD02)) : - new Variable("f0_1710_amp_real", 0.070 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1710_amp_imag", 0.087 * (-_mD02)) : - new Variable("f0_1710_amp_imag", 0.087 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1710_mass", 1.714, 0.01, 1.5, 2.9), - new Variable("f0_1710_width", 0.140, 0.01, 0.01, 0.5), - 0, - PAIR_23); - - ResonancePdf* f2_1270 = new ResonancePdf("f2_1270", - fixAmps ? new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv)) : - new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv), 0.001, 0, 0), - fixAmps ? new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv)) : - new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv), 0.1, 0, 0), - new Variable("f2_1270_mass", 1.2754, 0.01, 1.0, 1.5), - new Variable("f2_1270_width", 0.1851, 0.01, 0.01, 0.4), - 2, - PAIR_23); - - ResonancePdf* f0_600 = new ResonancePdf("f0_600", - fixAmps ? new Variable("f0_600_amp_real", 0.068 * (-_mD02)) : - new Variable("f0_600_amp_real", 0.068 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_600_amp_imag", 0.010 * (-_mD02)) : - new Variable("f0_600_amp_imag", 0.010 * (-_mD02), 0.1, 0, 0), - new Variable("f0_600_mass", 0.500, 0.01, 0.3, 0.7), - new Variable("f0_600_width", 0.400, 0.01, 0.2, 0.6), - 0, - PAIR_23); - - ResonancePdf* nonr = new ResonancePdf("nonr", - fixAmps ? new Variable("nonr_amp_real", 0.5595 * (-1)) : - new Variable("nonr_amp_real", 0.5595 * (-1), 0.001, 0, 0), - fixAmps ? new Variable("nonr_amp_imag", -0.108761 * (-1)) : - new Variable("nonr_amp_imag", -0.108761* (-1), 0.1, 0, 0)); + ResonancePdf *rhop_1700 = new ResonancePdf( + "rhop_1700", + fixAmps ? new Variable("rhop_1700_amp_real", 2.151) : new Variable("rhop_1700_amp_real", 2.151, 0.001, 0, 0), + fixAmps ? new Variable("rhop_1700_amp_imag", -0.658) : new Variable("rhop_1700_amp_imag", -0.658, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_12); + + ResonancePdf *rho0_1700 = new ResonancePdf( + "rho0_1700", + fixAmps ? new Variable("rho0_1700_amp_real", 2.400) : new Variable("rho0_1700_amp_real", 2.400, 0.001, 0, 0), + fixAmps ? new Variable("rho0_1700_amp_imag", -0.734) : new Variable("rho0_1700_amp_imag", -0.734, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_23); + + ResonancePdf *rhom_1700 = new ResonancePdf( + "rhom_1700", + fixAmps ? new Variable("rhom_1700_amp_real", 1.286) : new Variable("rhom_1700_amp_real", 1.286, 0.001, 0, 0), + fixAmps ? new Variable("rhom_1700_amp_imag", -1.532) : new Variable("rhom_1700_amp_imag", -1.532, 0.1, 0, 0), + sharedMass, + shareWidth, + 1, + PAIR_13); + + ResonancePdf *f0_980 = new ResonancePdf("f0_980", + fixAmps ? new Variable("f0_980_amp_real", 0.008 * (-_mD02)) + : new Variable("f0_980_amp_real", 0.008 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_980_amp_imag", -0.013 * (-_mD02)) + : new Variable("f0_980_amp_imag", -0.013 * (-_mD02), 0.1, 0, 0), + new Variable("f0_980_mass", 0.980, 0.01, 0.8, 1.2), + new Variable("f0_980_width", 0.044, 0.001, 0.001, 0.08), + 0, + PAIR_23); + + ResonancePdf *f0_1370 = new ResonancePdf("f0_1370", + fixAmps ? new Variable("f0_1370_amp_real", -0.058 * (-_mD02)) + : new Variable("f0_1370_amp_real", -0.058 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1370_amp_imag", 0.026 * (-_mD02)) + : new Variable("f0_1370_amp_imag", 0.026 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1370_mass", 1.434, 0.01, 1.2, 1.6), + new Variable("f0_1370_width", 0.173, 0.01, 0.01, 0.4), + 0, + PAIR_23); + + ResonancePdf *f0_1500 = new ResonancePdf("f0_1500", + fixAmps ? new Variable("f0_1500_amp_real", 0.057 * (-_mD02)) + : new Variable("f0_1500_amp_real", 0.057 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1500_amp_imag", 0.012 * (-_mD02)) + : new Variable("f0_1500_amp_imag", 0.012 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1500_mass", 1.507, 0.01, 1.3, 1.7), + new Variable("f0_1500_width", 0.109, 0.01, 0.01, 0.3), + 0, + PAIR_23); + + ResonancePdf *f0_1710 = new ResonancePdf("f0_1710", + fixAmps ? new Variable("f0_1710_amp_real", 0.070 * (-_mD02)) + : new Variable("f0_1710_amp_real", 0.070 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1710_amp_imag", 0.087 * (-_mD02)) + : new Variable("f0_1710_amp_imag", 0.087 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1710_mass", 1.714, 0.01, 1.5, 2.9), + new Variable("f0_1710_width", 0.140, 0.01, 0.01, 0.5), + 0, + PAIR_23); + + ResonancePdf *f2_1270 + = new ResonancePdf("f2_1270", + fixAmps ? new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv)) + : new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv), 0.001, 0, 0), + fixAmps ? new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv)) + : new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv), 0.1, 0, 0), + new Variable("f2_1270_mass", 1.2754, 0.01, 1.0, 1.5), + new Variable("f2_1270_width", 0.1851, 0.01, 0.01, 0.4), + 2, + PAIR_23); + + ResonancePdf *f0_600 = new ResonancePdf("f0_600", + fixAmps ? new Variable("f0_600_amp_real", 0.068 * (-_mD02)) + : new Variable("f0_600_amp_real", 0.068 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_600_amp_imag", 0.010 * (-_mD02)) + : new Variable("f0_600_amp_imag", 0.010 * (-_mD02), 0.1, 0, 0), + new Variable("f0_600_mass", 0.500, 0.01, 0.3, 0.7), + new Variable("f0_600_width", 0.400, 0.01, 0.2, 0.6), + 0, + PAIR_23); + + ResonancePdf *nonr = new ResonancePdf("nonr", + fixAmps ? new Variable("nonr_amp_real", 0.5595 * (-1)) + : new Variable("nonr_amp_real", 0.5595 * (-1), 0.001, 0, 0), + fixAmps ? new Variable("nonr_amp_imag", -0.108761 * (-1)) + : new Variable("nonr_amp_imag", -0.108761 * (-1), 0.1, 0, 0)); dtop0pp->resonances.push_back(nonr); dtop0pp->resonances.push_back(rhop); @@ -338,16 +335,17 @@ DalitzPlotPdf* makeSignalPdf(GooPdf* eff = 0) { dtop0pp->resonances.push_back(f0_600); if(!fitMasses) { - for(vector::iterator res = dtop0pp->resonances.begin(); res != dtop0pp->resonances.end(); ++res) { + for(vector::iterator res = dtop0pp->resonances.begin(); res != dtop0pp->resonances.end(); + ++res) { (*res)->setParameterConstantness(true); } } if(!eff) { // By default create a constant efficiency. - vector offsets; - vector observables; - vector coefficients; + vector offsets; + vector observables; + vector coefficients; observables.push_back(m12); observables.push_back(m13); @@ -377,7 +375,7 @@ int runToyFit(std::string toyFileName, GooFit::Application &app) { // EXERCISE 3: Make the efficiency a product of the two functions // from the previous exercises. - DalitzPlotPdf* signal = makeSignalPdf(); + DalitzPlotPdf *signal = makeSignalPdf(); signal->setData(data); signal->setDataSize(data->getNumEvents()); FitManager datapdf(signal); @@ -386,17 +384,15 @@ int runToyFit(std::string toyFileName, GooFit::Application &app) { return datapdf; } -int main(int argc, char** argv) { - +int main(int argc, char **argv) { GooFit::Application app("Dalitz example", argc, argv); std::string filename = "dalitz_toyMC_000.txt"; - app.add_option("-f,--filename,filename", filename, - "File to read in", true)->check(GooFit::ExistingFile); + app.add_option("-f,--filename,filename", filename, "File to read in", true)->check(GooFit::ExistingFile); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -412,13 +408,13 @@ int main(int argc, char** argv) { gStyle->SetLineWidth(1); gStyle->SetLineColor(1); gStyle->SetPalette(1, 0); - foo = new TCanvas(); + foo = new TCanvas(); foodal = new TCanvas(); foodal->Size(10, 10); try { return runToyFit(filename, app); - } catch(const std::runtime_error& e) { + } catch(const std::runtime_error &e) { std::cerr << e.what() << std::endl; return 7; } diff --git a/examples/exponential/exponential.cu b/examples/exponential/exponential.cu index 1592123b4..0a60053e9 100644 --- a/examples/exponential/exponential.cu +++ b/examples/exponential/exponential.cu @@ -6,31 +6,32 @@ #include #include -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Exponential example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } // Independent variable. - GooFit::Variable xvar{"xvar", 0, log(1 + RAND_MAX/2)}; + GooFit::Variable xvar{"xvar", 0, log(1 + RAND_MAX / 2)}; // Data set GooFit::UnbinnedDataSet data(&xvar); // Generate toy events. - + CLI::Timer gen_timer{"Generating took"}; - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { try { - xvar.setValue( xvar.getUpperLimit() - log(1+rand()/2)); + xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2)); data.addEvent(); - } catch (const GooFit::OutOfRange &) {} + } catch(const GooFit::OutOfRange &) { + } } - + std::cout << GooFit::magenta << gen_timer << GooFit::reset << std::endl; // Fit parameter @@ -41,7 +42,7 @@ int main(int argc, char** argv) { GooFit::FitManager fitter{&exppdf}; fitter.fit(); - + if(alpha.getValue() < -1.01 || alpha.getValue() > -0.99) return 1; diff --git a/examples/exponential/exponential1.cu b/examples/exponential/exponential1.cu index a9a1528d2..4fb0c3165 100644 --- a/examples/exponential/exponential1.cu +++ b/examples/exponential/exponential1.cu @@ -8,27 +8,28 @@ using namespace std; using namespace GooFit; -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Exponential example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } // Independent variable. - Variable xvar{"xvar", 0, log(1 + RAND_MAX/2)}; + Variable xvar{"xvar", 0, log(1 + RAND_MAX / 2)}; // Data set UnbinnedDataSet data(&xvar); // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { try { - xvar.setValue( xvar.getUpperLimit() - log(1+rand()/2)); + xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2)); data.addEvent(); - } catch (const GooFit::OutOfRange &) {} + } catch(const GooFit::OutOfRange &) { + } } // Fit parameter diff --git a/examples/exponential/exponential2.cu b/examples/exponential/exponential2.cu index a1c30b079..053f8c590 100644 --- a/examples/exponential/exponential2.cu +++ b/examples/exponential/exponential2.cu @@ -15,29 +15,30 @@ using namespace std; using namespace GooFit; -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Exponential example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } Minuit2::MnPrint::SetLevel(3); - + // Independent variable. - Variable xvar{"xvar", 0, log(1 + RAND_MAX/2)}; + Variable xvar{"xvar", 0, log(1 + RAND_MAX / 2)}; // Data set UnbinnedDataSet data(&xvar); // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { try { - xvar.setValue( xvar.getUpperLimit() - log(1+rand()/2)); + xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2)); data.addEvent(); - } catch (const GooFit::OutOfRange &) {} + } catch(const GooFit::OutOfRange &) { + } } // Fit parameter @@ -53,6 +54,6 @@ int main(int argc, char** argv) { Minuit2::FunctionMinimum min = migrad(); std::cout << "min= " << min << std::endl; - + return 0; } diff --git a/examples/pipipi0DPFit/pipipi0DPFit.cu b/examples/pipipi0DPFit/pipipi0DPFit.cu index d446bdbc8..014e78482 100644 --- a/examples/pipipi0DPFit/pipipi0DPFit.cu +++ b/examples/pipipi0DPFit/pipipi0DPFit.cu @@ -52,166 +52,167 @@ using namespace std; using namespace GooFit; -TCanvas* foo; -TCanvas* foodal; +TCanvas *foo; +TCanvas *foodal; -UnbinnedDataSet* data = 0; -UnbinnedDataSet* effdata = 0; -BinnedDataSet* binEffData = 0; -TH2F* weightHistogram = 0; -TH2F* underlyingBins = 0; +UnbinnedDataSet *data = 0; +UnbinnedDataSet *effdata = 0; +BinnedDataSet *binEffData = 0; +TH2F *weightHistogram = 0; +TH2F *underlyingBins = 0; // I hate having to use globals, but this is the best way for now -GooFit::Application* app_ptr; +GooFit::Application *app_ptr; bool minuit1; -Variable* m12 = 0; -Variable* m13 = 0; -CountingVariable* eventNumber = 0; -Variable* massd0 = 0; -Variable* deltam = 0; -Variable* dtime = 0; -Variable* sigma = 0; -Variable* wSig0 = 0; -Variable* wBkg1 = 0; -Variable* wBkg2 = 0; -Variable* wBkg3 = 0; -Variable* wBkg4 = 0; -bool fitMasses = false; -Variable* fixedRhoMass = new Variable("rho_mass", 0.7758, 0.01, 0.7, 0.8); -Variable* fixedRhoWidth = new Variable("rho_width", 0.1503, 0.01, 0.1, 0.2); +Variable *m12 = 0; +Variable *m13 = 0; +CountingVariable *eventNumber = 0; +Variable *massd0 = 0; +Variable *deltam = 0; +Variable *dtime = 0; +Variable *sigma = 0; +Variable *wSig0 = 0; +Variable *wBkg1 = 0; +Variable *wBkg2 = 0; +Variable *wBkg3 = 0; +Variable *wBkg4 = 0; +bool fitMasses = false; +Variable *fixedRhoMass = new Variable("rho_mass", 0.7758, 0.01, 0.7, 0.8); +Variable *fixedRhoWidth = new Variable("rho_width", 0.1503, 0.01, 0.1, 0.2); // Systematic variables -double luckyFrac = 0.5; -double mesonRad = 1.5; -int normBinning = 240; -int blindSeed = 4; -int mdslices = 1; -double md0offset = 0; -int md0_lower_window = -2; -int md0_upper_window = 2; +double luckyFrac = 0.5; +double mesonRad = 1.5; +int normBinning = 240; +int blindSeed = 4; +int mdslices = 1; +double md0offset = 0; +int md0_lower_window = -2; +int md0_upper_window = 2; double deltam_lower_window = -2; double deltam_upper_window = 2; -double lowerTime = -2; -double upperTime = 3; -double maxSigma = 0.8; -bool polyEff = false; -bool saveEffPlot = true; -bool useHistogramSigma = false; -enum Bkg2Model {Histogram, Parameter, Sideband}; -Bkg2Model bkg2Model = Sideband; -std::string bkg2Model_str = "sideband"; +double lowerTime = -2; +double upperTime = 3; +double maxSigma = 0.8; +bool polyEff = false; +bool saveEffPlot = true; +bool useHistogramSigma = false; +enum Bkg2Model { Histogram, Parameter, Sideband }; +Bkg2Model bkg2Model = Sideband; +std::string bkg2Model_str = "sideband"; bool notUseBackground3Hist = false; bool notUseBackground4Hist = false; -bool makePlots = false; -int m23Slices = 6; -bool drop_rho_1450 = false; -bool drop_rho_1700 = false; -bool drop_f0_980 = false; -bool drop_f0_1370 = false; -bool drop_f0_1500 = false; -bool drop_f0_1710 = false; -bool drop_f2_1270 = false; -bool drop_f0_600 = false; -bool gaussBkgTime = false; -bool mikhailSetup = false; -int bkgHistBins = 80; -string paramUp = ""; -string paramDn = ""; -int bkgHistRandSeed = -1; - -const fptype _mD0 = 1.86484; -const fptype _mD02 = _mD0 *_mD0; -const fptype _mD02inv = 1./_mD02; +bool makePlots = false; +int m23Slices = 6; +bool drop_rho_1450 = false; +bool drop_rho_1700 = false; +bool drop_f0_980 = false; +bool drop_f0_1370 = false; +bool drop_f0_1500 = false; +bool drop_f0_1710 = false; +bool drop_f2_1270 = false; +bool drop_f0_600 = false; +bool gaussBkgTime = false; +bool mikhailSetup = false; +int bkgHistBins = 80; +string paramUp = ""; +string paramDn = ""; +int bkgHistRandSeed = -1; + +const fptype _mD0 = 1.86484; +const fptype _mD02 = _mD0 * _mD0; +const fptype _mD02inv = 1. / _mD02; const fptype piPlusMass = 0.13957018; const fptype piZeroMass = 0.1349766; enum Resolutions { DplotRes = 1, TimeRes = 2, Efficiency = 4 }; -Variable* motherM = new Variable("motherM", 1.86484); -Variable* chargeM = new Variable("chargeM", 0.13957018); -Variable* neutrlM = new Variable("neutrlM", 0.1349766); -Variable* constantBigM = new Variable("constantBigM", _mD02 + 2 * piPlusMass * piPlusMass + piZeroMass* piZeroMass); +Variable *motherM = new Variable("motherM", 1.86484); +Variable *chargeM = new Variable("chargeM", 0.13957018); +Variable *neutrlM = new Variable("neutrlM", 0.1349766); +Variable *constantBigM = new Variable("constantBigM", _mD02 + 2 * piPlusMass * piPlusMass + piZeroMass * piZeroMass); // Constants used in more than one PDF component. -Variable* constantOne = new Variable("constantOne", 1); -Variable* constantTwo = new Variable("constantTwo", 2); -Variable* constantZero = new Variable("constantZero", 0); -Variable* constantMinusOne = new Variable("constantMinusOne", -1); -Variable* minDalitzX = new Variable("minDalitzX", pow(piPlusMass + piZeroMass, 2)); -Variable* maxDalitzX = new Variable("maxDalitzX", pow(_mD0 - piPlusMass, 2)); -Variable* minDalitzY = new Variable("minDalitzY", pow(piPlusMass + piZeroMass, 2)); -Variable* maxDalitzY = new Variable("maxDalitzY", pow(_mD0 - piPlusMass, 2)); -Variable* minDalitzZ = new Variable("minDalitzZ", pow(piPlusMass + piPlusMass, 2)); -Variable* maxDalitzZ = new Variable("maxDalitzZ", pow(_mD0 - piZeroMass, 2)); - -std::vector weights; -std::vector comps; -TH1F* dataTimePlot = nullptr; -TH1F* loM23Sigma = nullptr; -TH1F* hiM23Sigma = nullptr; -TddpPdf* signalDalitz = nullptr; -IncoherentSumPdf* incsum1 = nullptr; -IncoherentSumPdf* incsum2 = nullptr; -IncoherentSumPdf* incsum3 = nullptr; -IncoherentSumPdf* incsum4 = nullptr; -IncoherentSumPdf* incsum5 = nullptr; -IncoherentSumPdf* incsum6 = nullptr; -GooPdf* sig0_jsugg = nullptr; -GooPdf* bkg2_jsugg = nullptr; -GooPdf* bkg3_jsugg = nullptr; -GooPdf* bkg4_jsugg = nullptr; -Variable* massSum = new Variable("massSum", _mD0*_mD0 + 2*piPlusMass*piPlusMass + piZeroMass* piZeroMass); // = 3.53481 -GooPdf* kzero_veto = nullptr; - -bool doToyStudy = false; -float md0_toy_width = 0.0075; -float md0_toy_mean = 1.8654; +Variable *constantOne = new Variable("constantOne", 1); +Variable *constantTwo = new Variable("constantTwo", 2); +Variable *constantZero = new Variable("constantZero", 0); +Variable *constantMinusOne = new Variable("constantMinusOne", -1); +Variable *minDalitzX = new Variable("minDalitzX", pow(piPlusMass + piZeroMass, 2)); +Variable *maxDalitzX = new Variable("maxDalitzX", pow(_mD0 - piPlusMass, 2)); +Variable *minDalitzY = new Variable("minDalitzY", pow(piPlusMass + piZeroMass, 2)); +Variable *maxDalitzY = new Variable("maxDalitzY", pow(_mD0 - piPlusMass, 2)); +Variable *minDalitzZ = new Variable("minDalitzZ", pow(piPlusMass + piPlusMass, 2)); +Variable *maxDalitzZ = new Variable("maxDalitzZ", pow(_mD0 - piZeroMass, 2)); + +std::vector weights; +std::vector comps; +TH1F *dataTimePlot = nullptr; +TH1F *loM23Sigma = nullptr; +TH1F *hiM23Sigma = nullptr; +TddpPdf *signalDalitz = nullptr; +IncoherentSumPdf *incsum1 = nullptr; +IncoherentSumPdf *incsum2 = nullptr; +IncoherentSumPdf *incsum3 = nullptr; +IncoherentSumPdf *incsum4 = nullptr; +IncoherentSumPdf *incsum5 = nullptr; +IncoherentSumPdf *incsum6 = nullptr; +GooPdf *sig0_jsugg = nullptr; +GooPdf *bkg2_jsugg = nullptr; +GooPdf *bkg3_jsugg = nullptr; +GooPdf *bkg4_jsugg = nullptr; +Variable *massSum + = new Variable("massSum", _mD0 *_mD0 + 2 * piPlusMass * piPlusMass + piZeroMass * piZeroMass); // = 3.53481 +GooPdf *kzero_veto = nullptr; + +bool doToyStudy = false; +float md0_toy_width = 0.0075; +float md0_toy_mean = 1.8654; const float toySigFraction = 0.6; const float toyBkgTimeMean = 0.0; -const float toyBkgTimeRMS = 0.7; +const float toyBkgTimeRMS = 0.7; std::string toyFileName; char strbuffer[1000]; -SmoothHistogramPdf* makeBackgroundHistogram(int bkgnum, std::string overridename = ""); -void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_toy_mixfit/") ; +SmoothHistogramPdf *makeBackgroundHistogram(int bkgnum, std::string overridename = ""); +void makeToyDalitzPlots(GooPdf *overallSignal, std::string plotdir = "./plots_from_toy_mixfit/"); void getBackgroundFile(int bkgType); double intGaus = -1; double calcGauInteg(double x1, double x2) { if(x1 > x2) { double swp = x2; - x2 = x1; - x1 = swp; + x2 = x1; + x1 = swp; } double sum1 = x1, sum2 = x2; double value1 = x1, value2 = x2; - for(int i=1; i<100; i++) { - value1 = value1*x1*x1/(2*i+1); + for(int i = 1; i < 100; i++) { + value1 = value1 * x1 * x1 / (2 * i + 1); sum1 += value1; - value2 = value2*x2*x2/(2*i+1); + value2 = value2 * x2 * x2 / (2 * i + 1); sum2 += value2; } - return sum2*exp(-(x2*x2)/2) - sum1*exp(-(x1*x1)/2); + return sum2 * exp(-(x2 * x2) / 2) - sum1 * exp(-(x1 * x1) / 2); } double calcToyWeight(double sigratio, double m) { if(intGaus < 0) - intGaus = calcGauInteg(0.0075*md0_lower_window/md0_toy_width, 0.0075*md0_upper_window/md0_toy_width); + intGaus = calcGauInteg(0.0075 * md0_lower_window / md0_toy_width, 0.0075 * md0_upper_window / md0_toy_width); - double t = (m-md0_toy_mean)/md0_toy_width; - double fsig = sigratio*exp(-t*t/2.)/intGaus; - double fbkg = (1-sigratio)/((md0_upper_window-md0_lower_window)*0.0075/md0_toy_width); - return fsig/(fsig+fbkg); + double t = (m - md0_toy_mean) / md0_toy_width; + double fsig = sigratio * exp(-t * t / 2.) / intGaus; + double fbkg = (1 - sigratio) / ((md0_upper_window - md0_lower_window) * 0.0075 / md0_toy_width); + return fsig / (fsig + fbkg); } void printMemoryStatus(std::string file, int line); -void loadDataFile(std::string fname, UnbinnedDataSet** setToFill = 0, int effSkip = 3); +void loadDataFile(std::string fname, UnbinnedDataSet **setToFill = 0, int effSkip = 3); int runBackgroundDalitzFit(int bkgType, bool plots = false); -void normalize(TH1F* dat) { +void normalize(TH1F *dat) { double integral = 0; for(int i = 1; i <= dat->GetNbinsX(); ++i) { @@ -221,13 +222,13 @@ void normalize(TH1F* dat) { integral = 1.0 / integral; for(int i = 1; i <= dat->GetNbinsX(); ++i) { - dat->SetBinContent(i, integral*dat->GetBinContent(i)); - dat->SetBinError(i, integral*dat->GetBinError(i)); + dat->SetBinContent(i, integral * dat->GetBinContent(i)); + dat->SetBinError(i, integral * dat->GetBinError(i)); } } fptype cpuGetM23(fptype massPZ, fptype massPM) { - return (_mD02 + piZeroMass*piZeroMass + piPlusMass*piPlusMass + piPlusMass*piPlusMass - massPZ - massPM); + return (_mD02 + piZeroMass * piZeroMass + piPlusMass * piPlusMass + piPlusMass * piPlusMass - massPZ - massPM); } bool cpuDalitz(fptype m12, fptype m13, fptype bigM, fptype dm1, fptype dm2, fptype dm3) { @@ -235,19 +236,21 @@ bool cpuDalitz(fptype m12, fptype m13, fptype bigM, fptype dm1, fptype dm2, fpty return false; // This m12 cannot exist, it's less than the square of the (1,2) particle mass. if(m12 > pow(bigM - dm3, 2)) - return false; // This doesn't work either, there's no room for an at-rest 3 daughter. + return false; // This doesn't work either, there's no room for an at-rest 3 daughter. // Calculate energies of 1 and 3 particles in m12 rest frame. - fptype e1star = 0.5 * (m12 - dm2*dm2 + dm1*dm1) / sqrt(m12); - fptype e3star = 0.5 * (bigM*bigM - m12 - dm3*dm3) / sqrt(m12); + fptype e1star = 0.5 * (m12 - dm2 * dm2 + dm1 * dm1) / sqrt(m12); + fptype e3star = 0.5 * (bigM * bigM - m12 - dm3 * dm3) / sqrt(m12); // Bounds for m13 at this value of m12. - fptype minimum = pow(e1star + e3star, 2) - pow(sqrt(e1star*e1star - dm1*dm1) + sqrt(e3star*e3star - dm3*dm3), 2); + fptype minimum + = pow(e1star + e3star, 2) - pow(sqrt(e1star * e1star - dm1 * dm1) + sqrt(e3star * e3star - dm3 * dm3), 2); if(m13 < minimum) return false; - fptype maximum = pow(e1star + e3star, 2) - pow(sqrt(e1star*e1star - dm1*dm1) - sqrt(e3star*e3star - dm3*dm3), 2); + fptype maximum + = pow(e1star + e3star, 2) - pow(sqrt(e1star * e1star - dm1 * dm1) - sqrt(e3star * e3star - dm3 * dm3), 2); if(m13 > maximum) return false; @@ -280,15 +283,17 @@ void plotLoHiSigma() { foo->SaveAs("./plots_from_mixfit/sigmacomp.png"); } -void plotFit(Variable* var, UnbinnedDataSet* dat, GooPdf* fit) { - int numEvents = dat->getNumEvents(); - TH1F* dat_hist = new TH1F((var->getName() + "_dathist").c_str(), "", var->getNumBins(), var->getLowerLimit(), var->getUpperLimit()); +void plotFit(Variable *var, UnbinnedDataSet *dat, GooPdf *fit) { + int numEvents = dat->getNumEvents(); + TH1F *dat_hist = new TH1F( + (var->getName() + "_dathist").c_str(), "", var->getNumBins(), var->getLowerLimit(), var->getUpperLimit()); for(int i = 0; i < numEvents; ++i) { dat_hist->Fill(dat->getValue(var, i)); } - TH1F* pdf_hist = new TH1F((var->getName() + "_pdfhist").c_str(), "", var->getNumBins(), var->getLowerLimit(), var->getUpperLimit()); + TH1F *pdf_hist = new TH1F( + (var->getName() + "_pdfhist").c_str(), "", var->getNumBins(), var->getLowerLimit(), var->getUpperLimit()); std::vector values = fit->evaluateAtPoints(var); double totalPdf = 0; @@ -298,7 +303,7 @@ void plotFit(Variable* var, UnbinnedDataSet* dat, GooPdf* fit) { } for(int i = 0; i < var->getNumBins(); ++i) { - pdf_hist->SetBinContent(i+1, values[i] * numEvents / totalPdf); + pdf_hist->SetBinContent(i + 1, values[i] * numEvents / totalPdf); } pdf_hist->SetStats(false); @@ -318,8 +323,8 @@ void plotFit(Variable* var, UnbinnedDataSet* dat, GooPdf* fit) { foo->SetLogy(false); } -bool readWrapper(std::ifstream& reader, std::string fname = strbuffer) { - std::cout<<"Now open file "< vars; + std::vector vars; vars.push_back(m12); vars.push_back(m13); vars.push_back(dtime); vars.push_back(sigma); vars.push_back(eventNumber); vars.push_back(wSig0); -// vars.push_back(wBkg1); -// vars.push_back(wBkg2); + // vars.push_back(wBkg1); + // vars.push_back(wBkg2); data = new UnbinnedDataSet(vars); } @@ -354,15 +359,15 @@ void getToyData(float sigweight = 0.9) { TRandom3 donram(0); - int nsig = 0; + int nsig = 0; double sigprob = 0; - double dummy = 0; - double md0 = md0_toy_mean; + double dummy = 0; + double md0 = md0_toy_mean; while(!reader.eof()) { reader >> dummy; - reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. - reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) + reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. + reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) reader >> *m13; // Errors on Dalitz variables @@ -385,128 +390,122 @@ void getToyData(float sigweight = 0.9) { reader >> dummy; reader >> dummy; - //if (dtime->getValue() < dtime->getLowerLimit()) continue; - //if (dtime->getValue() > dtime->getUpperLimit()) continue; + // if (dtime->getValue() < dtime->getLowerLimit()) continue; + // if (dtime->getValue() > dtime->getUpperLimit()) continue; double resolution = donram.Gaus(0, 1); - dtime->setValue(dtime->getValue() + resolution*sigma->getValue()); + dtime->setValue(dtime->getValue() + resolution * sigma->getValue()); eventNumber->setValue(data->getNumEvents()); do { md0 = donram.Gaus(md0_toy_mean, md0_toy_width); - } while(md0 <= 1.8654 + 0.0075*md0_lower_window||md0 >= 1.8654 + 0.0075*md0_upper_window); + } while(md0 <= 1.8654 + 0.0075 * md0_lower_window || md0 >= 1.8654 + 0.0075 * md0_upper_window); -// wSig0->getValue() = sigweight; + // wSig0->getValue() = sigweight; wSig0->setValue(calcToyWeight(sigweight, md0)); sigprob += wSig0->getValue(); data->addEvent(); - nsig ++; - + nsig++; if(data->getNumEvents() < 10) { - std::cout << data->getNumEvents() << " : " - << m12->getValue() << " " - << m13->getValue() << " " - << dtime->getValue() << " " - << sigma->getValue() << " " - << std::endl; + std::cout << data->getNumEvents() << " : " << m12->getValue() << " " << m13->getValue() << " " + << dtime->getValue() << " " << sigma->getValue() << " " << std::endl; } - //else break; + // else break; } - for(int ib = 0; ib < nsig*(1-sigweight)/sigweight; ib++) { + for(int ib = 0; ib < nsig * (1 - sigweight) / sigweight; ib++) { do { - m12->setValue(donram.Uniform()*(m12->getUpperLimit() - m12->getLowerLimit())+m12->getLowerLimit()); - m13->setValue(donram.Uniform()*(m13->getUpperLimit() - m13->getLowerLimit())+m13->getLowerLimit()); + m12->setValue(donram.Uniform() * (m12->getUpperLimit() - m12->getLowerLimit()) + m12->getLowerLimit()); + m13->setValue(donram.Uniform() * (m13->getUpperLimit() - m13->getLowerLimit()) + m13->getLowerLimit()); } while(!cpuDalitz(m12->getValue(), m13->getValue(), _mD0, piZeroMass, piPlusMass, piPlusMass)); do { dtime->setValue(donram.Gaus(toyBkgTimeMean, toyBkgTimeRMS)); - } while(!(dtime->getValue() > dtime->getLowerLimit()&&dtime->getValue() < dtime->getUpperLimit())); + } while(!(dtime->getValue() > dtime->getLowerLimit() && dtime->getValue() < dtime->getUpperLimit())); eventNumber->setValue(data->getNumEvents()); - md0 = donram.Uniform(1.8654 + 0.0075*md0_lower_window, 1.8654 + 0.0075*md0_upper_window); -// wSig0->getValue() = sigweight; + md0 = donram.Uniform(1.8654 + 0.0075 * md0_lower_window, 1.8654 + 0.0075 * md0_upper_window); + // wSig0->getValue() = sigweight; wSig0->setValue(calcToyWeight(sigweight, md0)); sigprob += wSig0->getValue(); data->addEvent(); } reader.close(); - } -GooPdf* makeEfficiencyPdf() { - Variable* effSmoothing = new Variable("effSmoothing", 1.0, 0.1, 0, 1.25); - //Variable* effSmoothing = new Variable("effSmoothing", 0); - SmoothHistogramPdf* ret = new SmoothHistogramPdf("efficiency", binEffData, effSmoothing); +GooPdf *makeEfficiencyPdf() { + Variable *effSmoothing = new Variable("effSmoothing", 1.0, 0.1, 0, 1.25); + // Variable* effSmoothing = new Variable("effSmoothing", 0); + SmoothHistogramPdf *ret = new SmoothHistogramPdf("efficiency", binEffData, effSmoothing); return ret; } -GooPdf* makeKzeroVeto() { +GooPdf *makeKzeroVeto() { if(kzero_veto) return kzero_veto; - VetoInfo* kVetoInfo = new VetoInfo(); + VetoInfo *kVetoInfo = new VetoInfo(); kVetoInfo->cyclic_index = PAIR_23; - kVetoInfo->minimum = new Variable("veto_min", 0.475*0.475); - kVetoInfo->maximum = new Variable("veto_max", 0.505*0.505); - vector vetos; + kVetoInfo->minimum = new Variable("veto_min", 0.475 * 0.475); + kVetoInfo->maximum = new Variable("veto_max", 0.505 * 0.505); + vector vetos; vetos.push_back(kVetoInfo); kzero_veto = new DalitzVetoPdf("kzero_veto", m12, m13, motherM, neutrlM, chargeM, chargeM, vetos); return kzero_veto; } -GooPdf* makeEfficiencyPoly() { +GooPdf *makeEfficiencyPoly() { if(!kzero_veto) makeKzeroVeto(); - vector offsets; - vector observables; - vector coefficients; + vector offsets; + vector observables; + vector coefficients; offsets.push_back(constantOne); offsets.push_back(constantOne); observables.push_back(m12); observables.push_back(m13); - coefficients.push_back(new Variable("x0y0", 1.0)); - coefficients.push_back(new Variable("x1y0", 0.07999, 0.01, -0.5, 0.5)); + coefficients.push_back(new Variable("x0y0", 1.0)); + coefficients.push_back(new Variable("x1y0", 0.07999, 0.01, -0.5, 0.5)); coefficients.push_back(new Variable("x2y0", -0.23732, 0.01, -0.5, 0.5)); - coefficients.push_back(new Variable("x3y0", 0.10369, 0.01, -1.5, 0.5)); - coefficients.push_back(new Variable("x0y1", 0.10248, 0.01, -1.5, 0.5)); + coefficients.push_back(new Variable("x3y0", 0.10369, 0.01, -1.5, 0.5)); + coefficients.push_back(new Variable("x0y1", 0.10248, 0.01, -1.5, 0.5)); coefficients.push_back(new Variable("x1y1", -0.28543, 0.01, -0.5, 0.5)); - coefficients.push_back(new Variable("x2y1", 0.15058, 0.01, -1.5, 0.5)); + coefficients.push_back(new Variable("x2y1", 0.15058, 0.01, -1.5, 0.5)); coefficients.push_back(new Variable("x0y2", -0.20648, 0.01, -0.5, 0.5)); - coefficients.push_back(new Variable("x1y2", 0.14567, 0.01, -1.5, 0.5)); - coefficients.push_back(new Variable("x0y3", 0.06231, 0.01, -0.5, 0.5)); + coefficients.push_back(new Variable("x1y2", 0.14567, 0.01, -1.5, 0.5)); + coefficients.push_back(new Variable("x0y3", 0.06231, 0.01, -0.5, 0.5)); - PolynomialPdf* poly = new PolynomialPdf("efficiency", observables, coefficients, offsets, 3); + PolynomialPdf *poly = new PolynomialPdf("efficiency", observables, coefficients, offsets, 3); poly->setParameterConstantness(true); - Variable* decXmin = new Variable("decXmin", 6.22596); - Variable* decYmin = new Variable("decYmin", 6.30722); - Variable* decZmin = new Variable("decZmin", 10.82390); - Variable* conXmin = new Variable("conXmin", 0.65621); - Variable* conYmin = new Variable("conYmin", 0.69527); - Variable* conZmin = new Variable("conZmin", 0.31764); - Variable* decXmax = new Variable("decXmax", 0.79181); - Variable* decYmax = new Variable("decYmax", 5.91211); - Variable* decZmax = new Variable("decZmax", 1.52031); - Variable* conXmax = new Variable("conXmax", 0.80918); - Variable* conYmax = new Variable("conYmax", 0.22158); - Variable* conZmax = new Variable("conZmax", 0.41866); + Variable *decXmin = new Variable("decXmin", 6.22596); + Variable *decYmin = new Variable("decYmin", 6.30722); + Variable *decZmin = new Variable("decZmin", 10.82390); + Variable *conXmin = new Variable("conXmin", 0.65621); + Variable *conYmin = new Variable("conYmin", 0.69527); + Variable *conZmin = new Variable("conZmin", 0.31764); + Variable *decXmax = new Variable("decXmax", 0.79181); + Variable *decYmax = new Variable("decYmax", 5.91211); + Variable *decZmax = new Variable("decZmax", 1.52031); + Variable *conXmax = new Variable("conXmax", 0.80918); + Variable *conYmax = new Variable("conYmax", 0.22158); + Variable *conZmax = new Variable("conZmax", 0.41866); - TrigThresholdPdf* loX = new TrigThresholdPdf("loX", m12, minDalitzX, decXmin, conXmin, false); - TrigThresholdPdf* hiX = new TrigThresholdPdf("hiX", m12, maxDalitzX, decXmax, conXmax, true); + TrigThresholdPdf *loX = new TrigThresholdPdf("loX", m12, minDalitzX, decXmin, conXmin, false); + TrigThresholdPdf *hiX = new TrigThresholdPdf("hiX", m12, maxDalitzX, decXmax, conXmax, true); - TrigThresholdPdf* loY = new TrigThresholdPdf("loY", m13, minDalitzY, decYmin, conYmin, false); - TrigThresholdPdf* hiY = new TrigThresholdPdf("hiY", m13, maxDalitzY, decYmax, conYmax, true); + TrigThresholdPdf *loY = new TrigThresholdPdf("loY", m13, minDalitzY, decYmin, conYmin, false); + TrigThresholdPdf *hiY = new TrigThresholdPdf("hiY", m13, maxDalitzY, decYmax, conYmax, true); - TrigThresholdPdf* loZ = new TrigThresholdPdf("loZ", m12, m13, minDalitzZ, decZmin, conZmin, massSum, false); - TrigThresholdPdf* hiZ = new TrigThresholdPdf("hiZ", m12, m13, maxDalitzZ, decZmax, conZmax, massSum, true); + TrigThresholdPdf *loZ = new TrigThresholdPdf("loZ", m12, m13, minDalitzZ, decZmin, conZmin, massSum, false); + TrigThresholdPdf *hiZ = new TrigThresholdPdf("hiZ", m12, m13, maxDalitzZ, decZmax, conZmax, massSum, true); comps.clear(); comps.push_back(poly); @@ -517,30 +516,30 @@ GooPdf* makeEfficiencyPoly() { comps.push_back(loZ); comps.push_back(hiZ); comps.push_back(kzero_veto); - ProdPdf* ret = new ProdPdf("efficiency_total", comps); + ProdPdf *ret = new ProdPdf("efficiency_total", comps); - //return poly; + // return poly; return ret; } -Variable* ptr_to_xmix = 0; -Variable* ptr_to_ymix = 0; -Variable* ptr_to_dtau = 0; +Variable *ptr_to_xmix = 0; +Variable *ptr_to_ymix = 0; +Variable *ptr_to_dtau = 0; -TddpPdf* makeSignalPdf(MixingTimeResolution* resolution = 0, GooPdf* eff = 0) { - DecayInfo* dtop0pp = new DecayInfo(); - dtop0pp->motherMass = _mD0; - dtop0pp->daug1Mass = piZeroMass; - dtop0pp->daug2Mass = piPlusMass; - dtop0pp->daug3Mass = piPlusMass; - dtop0pp->meson_radius = mesonRad; +TddpPdf *makeSignalPdf(MixingTimeResolution *resolution = 0, GooPdf *eff = 0) { + DecayInfo *dtop0pp = new DecayInfo(); + dtop0pp->motherMass = _mD0; + dtop0pp->daug1Mass = piZeroMass; + dtop0pp->daug2Mass = piPlusMass; + dtop0pp->daug3Mass = piPlusMass; + dtop0pp->meson_radius = mesonRad; -// dtop0pp->_tau = new Variable("tau", 0.4116, 0.001, 0.300, 0.500); + // dtop0pp->_tau = new Variable("tau", 0.4116, 0.001, 0.300, 0.500); dtop0pp->_tau = new Variable("tau", 0.4101, 0.001, 0.300, 0.500); // Setting limits causes trouble with MNHESSE - why is this? - //dtop0pp->_xmixing = new Variable("xmixing", 0.01, 0.001, -0.05, 0.05); - //dtop0pp->_ymixing = new Variable("ymixing", 0.01, 0.001, -0.05, 0.05); + // dtop0pp->_xmixing = new Variable("xmixing", 0.01, 0.001, -0.05, 0.05); + // dtop0pp->_ymixing = new Variable("ymixing", 0.01, 0.001, -0.05, 0.05); dtop0pp->_xmixing = new Variable("xmixing", 0.0016, 0.001, 0, 0); dtop0pp->_ymixing = new Variable("ymixing", 0.0055, 0.001, 0, 0); @@ -548,171 +547,164 @@ TddpPdf* makeSignalPdf(MixingTimeResolution* resolution = 0, GooPdf* eff = 0) { ptr_to_ymix = dtop0pp->_ymixing; ptr_to_dtau = dtop0pp->_tau; - //ptr_to_dtau->fixed = true; - //ptr_to_xmix->fixed = true; - //ptr_to_ymix->fixed = true; + // ptr_to_dtau->fixed = true; + // ptr_to_xmix->fixed = true; + // ptr_to_ymix->fixed = true; - ResonancePdf* rhop = new ResonancePdf("rhop", - new Variable("rhop_amp_real", 1), - new Variable("rhop_amp_imag", 0), - fixedRhoMass, - fixedRhoWidth, - 1, - PAIR_12); + ResonancePdf *rhop = new ResonancePdf("rhop", + new Variable("rhop_amp_real", 1), + new Variable("rhop_amp_imag", 0), + fixedRhoMass, + fixedRhoWidth, + 1, + PAIR_12); bool fixAmps = false; - ResonancePdf* rhom = new ResonancePdf("rhom", - fixAmps ? new Variable("rhom_amp_real", 0.714) : - new Variable("rhom_amp_real", 0.714, 0.001, 0, 0), - fixAmps ? new Variable("rhom_amp_imag", -0.025) : - new Variable("rhom_amp_imag", -0.025, 0.1, 0, 0), - fixedRhoMass, - fixedRhoWidth, - 1, - PAIR_13); - - ResonancePdf* rho0 = new ResonancePdf("rho0", - fixAmps ? new Variable("rho0_amp_real", 0.565) : - new Variable("rho0_amp_real", 0.565, 0.001, 0, 0), - fixAmps ? new Variable("rho0_amp_imag", 0.164) : - new Variable("rho0_amp_imag", 0.164, 0.1, 0, 0), - 1, - fixedRhoMass, - fixedRhoWidth, - PAIR_23); - - Variable* rho1450Mass = new Variable("rhop_1450_mass", 1.465, 0.01, 1.0, 2.0); - Variable* rho1450Width = new Variable("rhop_1450_width", 0.400, 0.01, 0.01, 5.0); - - ResonancePdf* rhop_1450 = new ResonancePdf("rhop_1450", - fixAmps ? new Variable("rhop_1450_amp_real", -0.174) : - new Variable("rhop_1450_amp_real", -0.174, 0.001, 0, 0), - fixAmps ? new Variable("rhop_1450_amp_imag", -0.117) : - new Variable("rhop_1450_amp_imag", -0.117, 0.1, 0, 0), - rho1450Mass, - rho1450Width, - 1, - PAIR_12); - - ResonancePdf* rho0_1450 = new ResonancePdf("rho0_1450", - fixAmps ? new Variable("rho0_1450_amp_real", 0.325) : - new Variable("rho0_1450_amp_real", 0.325, 0.001, 0, 0), - fixAmps ? new Variable("rho0_1450_amp_imag", 0.057) : - new Variable("rho0_1450_amp_imag", 0.057, 0.1, 0, 0), - rho1450Mass, - rho1450Width, - 1, - PAIR_23); - - ResonancePdf* rhom_1450 = new ResonancePdf("rhom_1450", - fixAmps ? new Variable("rhom_1450_amp_real", 0.788) : - new Variable("rhom_1450_amp_real", 0.788, 0.001, 0, 0), - fixAmps ? new Variable("rhom_1450_amp_imag", 0.226) : - new Variable("rhom_1450_amp_imag", 0.226, 0.1, 0, 0), - rho1450Mass, - rho1450Width, - 1, - PAIR_13); - - Variable* rho1700Mass = new Variable("rhop_1700_mass", 1.720, 0.01, 1.6, 1.9); - Variable* rho1700Width = new Variable("rhop_1700_width", 0.250, 0.01, 0.1, 1.0); - - ResonancePdf* rhop_1700 = new ResonancePdf("rhop_1700", - fixAmps ? new Variable("rhop_1700_amp_real", 2.151) : - new Variable("rhop_1700_amp_real", 2.151, 0.001, 0, 0), - fixAmps ? new Variable("rhop_1700_amp_imag", -0.658) : - new Variable("rhop_1700_amp_imag", -0.658, 0.1, 0, 0), - rho1700Mass, - rho1700Width, - 1, - PAIR_12); - - ResonancePdf* rho0_1700 = new ResonancePdf("rho0_1700", - fixAmps ? new Variable("rho0_1700_amp_real", 2.400) : - new Variable("rho0_1700_amp_real", 2.400, 0.001, 0, 0), - fixAmps ? new Variable("rho0_1700_amp_imag", -0.734) : - new Variable("rho0_1700_amp_imag", -0.734, 0.1, 0, 0), - rho1700Mass, - rho1700Width, - 1, - PAIR_23); - - ResonancePdf* rhom_1700 = new ResonancePdf("rhom_1700", - fixAmps ? new Variable("rhom_1700_amp_real", 1.286) : - new Variable("rhom_1700_amp_real", 1.286, 0.001, 0, 0), - fixAmps ? new Variable("rhom_1700_amp_imag", -1.532) : - new Variable("rhom_1700_amp_imag", -1.532, 0.1, 0, 0), - rho1700Mass, - rho1700Width, - 1, - PAIR_13); - - ResonancePdf* f0_980 = new ResonancePdf("f0_980", - fixAmps ? new Variable("f0_980_amp_real", 0.008 * (-_mD02)) : - new Variable("f0_980_amp_real", 0.008 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_980_amp_imag", -0.013 * (-_mD02)) : - new Variable("f0_980_amp_imag", -0.013 * (-_mD02), 0.1, 0, 0), - new Variable("f0_980_mass", 0.980, 0.01, 0.8, 1.2), - new Variable("f0_980_width", 0.044, 0.001, 0.001, 0.08), - 0, - PAIR_23); - - ResonancePdf* f0_1370 = new ResonancePdf("f0_1370", - fixAmps ? new Variable("f0_1370_amp_real", -0.058 * (-_mD02)) : - new Variable("f0_1370_amp_real", -0.058 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1370_amp_imag", 0.026 * (-_mD02)) : - new Variable("f0_1370_amp_imag", 0.026 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1370_mass", 1.434, 0.01, 1.2, 1.6), - new Variable("f0_1370_width", 0.173, 0.01, 0.01, 0.4), - 0, - PAIR_23); - - ResonancePdf* f0_1500 = new ResonancePdf("f0_1500", - fixAmps ? new Variable("f0_1500_amp_real", 0.057 * (-_mD02)) : - new Variable("f0_1500_amp_real", 0.057 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1500_amp_imag", 0.012 * (-_mD02)) : - new Variable("f0_1500_amp_imag", 0.012 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1500_mass", 1.507, 0.01, 1.3, 1.7), - new Variable("f0_1500_width", 0.109, 0.01, 0.01, 0.3), - 0, - PAIR_23); - - ResonancePdf* f0_1710 = new ResonancePdf("f0_1710", - fixAmps ? new Variable("f0_1710_amp_real", 0.070 * (-_mD02)) : - new Variable("f0_1710_amp_real", 0.070 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_1710_amp_imag", 0.087 * (-_mD02)) : - new Variable("f0_1710_amp_imag", 0.087 * (-_mD02), 0.1, 0, 0), - new Variable("f0_1710_mass", 1.714, 0.01, 1.5, 2.9), - new Variable("f0_1710_width", 0.140, 0.01, 0.01, 0.5), - 0, - PAIR_23); - - ResonancePdf* f2_1270 = new ResonancePdf("f2_1270", - fixAmps ? new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv)) : - new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv), 0.001, 0, 0), - fixAmps ? new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv)) : - new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv), 0.1, 0, 0), - new Variable("f2_1270_mass", 1.2754, 0.01, 1.0, 1.5), - new Variable("f2_1270_width", 0.1851, 0.01, 0.01, 0.4), - 2, - PAIR_23); - - ResonancePdf* f0_600 = new ResonancePdf("f0_600", - fixAmps ? new Variable("f0_600_amp_real", 0.068 * (-_mD02)) : - new Variable("f0_600_amp_real", 0.068 * (-_mD02), 0.001, 0, 0), - fixAmps ? new Variable("f0_600_amp_imag", 0.010 * (-_mD02)) : - new Variable("f0_600_amp_imag", 0.010 * (-_mD02), 0.1, 0, 0), - new Variable("f0_600_mass", 0.500, 0.01, 0.3, 0.7), - new Variable("f0_600_width", 0.400, 0.01, 0.2, 0.6), - 0, - PAIR_23); - - ResonancePdf* nonr = new ResonancePdf("nonr", - fixAmps ? new Variable("nonr_amp_real", 0.5595 * (-1)) : - new Variable("nonr_amp_real", 0.5595 * (-1), 0.001, 0, 0), - fixAmps ? new Variable("nonr_amp_imag", -0.108761 * (-1)) : - new Variable("nonr_amp_imag", -0.108761* (-1), 0.1, 0, 0)); + ResonancePdf *rhom = new ResonancePdf( + "rhom", + fixAmps ? new Variable("rhom_amp_real", 0.714) : new Variable("rhom_amp_real", 0.714, 0.001, 0, 0), + fixAmps ? new Variable("rhom_amp_imag", -0.025) : new Variable("rhom_amp_imag", -0.025, 0.1, 0, 0), + fixedRhoMass, + fixedRhoWidth, + 1, + PAIR_13); + + ResonancePdf *rho0 = new ResonancePdf( + "rho0", + fixAmps ? new Variable("rho0_amp_real", 0.565) : new Variable("rho0_amp_real", 0.565, 0.001, 0, 0), + fixAmps ? new Variable("rho0_amp_imag", 0.164) : new Variable("rho0_amp_imag", 0.164, 0.1, 0, 0), + 1, + fixedRhoMass, + fixedRhoWidth, + PAIR_23); + + Variable *rho1450Mass = new Variable("rhop_1450_mass", 1.465, 0.01, 1.0, 2.0); + Variable *rho1450Width = new Variable("rhop_1450_width", 0.400, 0.01, 0.01, 5.0); + + ResonancePdf *rhop_1450 = new ResonancePdf( + "rhop_1450", + fixAmps ? new Variable("rhop_1450_amp_real", -0.174) : new Variable("rhop_1450_amp_real", -0.174, 0.001, 0, 0), + fixAmps ? new Variable("rhop_1450_amp_imag", -0.117) : new Variable("rhop_1450_amp_imag", -0.117, 0.1, 0, 0), + rho1450Mass, + rho1450Width, + 1, + PAIR_12); + + ResonancePdf *rho0_1450 = new ResonancePdf( + "rho0_1450", + fixAmps ? new Variable("rho0_1450_amp_real", 0.325) : new Variable("rho0_1450_amp_real", 0.325, 0.001, 0, 0), + fixAmps ? new Variable("rho0_1450_amp_imag", 0.057) : new Variable("rho0_1450_amp_imag", 0.057, 0.1, 0, 0), + rho1450Mass, + rho1450Width, + 1, + PAIR_23); + + ResonancePdf *rhom_1450 = new ResonancePdf( + "rhom_1450", + fixAmps ? new Variable("rhom_1450_amp_real", 0.788) : new Variable("rhom_1450_amp_real", 0.788, 0.001, 0, 0), + fixAmps ? new Variable("rhom_1450_amp_imag", 0.226) : new Variable("rhom_1450_amp_imag", 0.226, 0.1, 0, 0), + rho1450Mass, + rho1450Width, + 1, + PAIR_13); + + Variable *rho1700Mass = new Variable("rhop_1700_mass", 1.720, 0.01, 1.6, 1.9); + Variable *rho1700Width = new Variable("rhop_1700_width", 0.250, 0.01, 0.1, 1.0); + + ResonancePdf *rhop_1700 = new ResonancePdf( + "rhop_1700", + fixAmps ? new Variable("rhop_1700_amp_real", 2.151) : new Variable("rhop_1700_amp_real", 2.151, 0.001, 0, 0), + fixAmps ? new Variable("rhop_1700_amp_imag", -0.658) : new Variable("rhop_1700_amp_imag", -0.658, 0.1, 0, 0), + rho1700Mass, + rho1700Width, + 1, + PAIR_12); + + ResonancePdf *rho0_1700 = new ResonancePdf( + "rho0_1700", + fixAmps ? new Variable("rho0_1700_amp_real", 2.400) : new Variable("rho0_1700_amp_real", 2.400, 0.001, 0, 0), + fixAmps ? new Variable("rho0_1700_amp_imag", -0.734) : new Variable("rho0_1700_amp_imag", -0.734, 0.1, 0, 0), + rho1700Mass, + rho1700Width, + 1, + PAIR_23); + + ResonancePdf *rhom_1700 = new ResonancePdf( + "rhom_1700", + fixAmps ? new Variable("rhom_1700_amp_real", 1.286) : new Variable("rhom_1700_amp_real", 1.286, 0.001, 0, 0), + fixAmps ? new Variable("rhom_1700_amp_imag", -1.532) : new Variable("rhom_1700_amp_imag", -1.532, 0.1, 0, 0), + rho1700Mass, + rho1700Width, + 1, + PAIR_13); + + ResonancePdf *f0_980 = new ResonancePdf("f0_980", + fixAmps ? new Variable("f0_980_amp_real", 0.008 * (-_mD02)) + : new Variable("f0_980_amp_real", 0.008 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_980_amp_imag", -0.013 * (-_mD02)) + : new Variable("f0_980_amp_imag", -0.013 * (-_mD02), 0.1, 0, 0), + new Variable("f0_980_mass", 0.980, 0.01, 0.8, 1.2), + new Variable("f0_980_width", 0.044, 0.001, 0.001, 0.08), + 0, + PAIR_23); + + ResonancePdf *f0_1370 = new ResonancePdf("f0_1370", + fixAmps ? new Variable("f0_1370_amp_real", -0.058 * (-_mD02)) + : new Variable("f0_1370_amp_real", -0.058 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1370_amp_imag", 0.026 * (-_mD02)) + : new Variable("f0_1370_amp_imag", 0.026 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1370_mass", 1.434, 0.01, 1.2, 1.6), + new Variable("f0_1370_width", 0.173, 0.01, 0.01, 0.4), + 0, + PAIR_23); + + ResonancePdf *f0_1500 = new ResonancePdf("f0_1500", + fixAmps ? new Variable("f0_1500_amp_real", 0.057 * (-_mD02)) + : new Variable("f0_1500_amp_real", 0.057 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1500_amp_imag", 0.012 * (-_mD02)) + : new Variable("f0_1500_amp_imag", 0.012 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1500_mass", 1.507, 0.01, 1.3, 1.7), + new Variable("f0_1500_width", 0.109, 0.01, 0.01, 0.3), + 0, + PAIR_23); + + ResonancePdf *f0_1710 = new ResonancePdf("f0_1710", + fixAmps ? new Variable("f0_1710_amp_real", 0.070 * (-_mD02)) + : new Variable("f0_1710_amp_real", 0.070 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_1710_amp_imag", 0.087 * (-_mD02)) + : new Variable("f0_1710_amp_imag", 0.087 * (-_mD02), 0.1, 0, 0), + new Variable("f0_1710_mass", 1.714, 0.01, 1.5, 2.9), + new Variable("f0_1710_width", 0.140, 0.01, 0.01, 0.5), + 0, + PAIR_23); + + ResonancePdf *f2_1270 + = new ResonancePdf("f2_1270", + fixAmps ? new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv)) + : new Variable("f2_1270_amp_real", -1.027 * (-_mD02inv), 0.001, 0, 0), + fixAmps ? new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv)) + : new Variable("f2_1270_amp_imag", -0.162 * (-_mD02inv), 0.1, 0, 0), + new Variable("f2_1270_mass", 1.2754, 0.01, 1.0, 1.5), + new Variable("f2_1270_width", 0.1851, 0.01, 0.01, 0.4), + 2, + PAIR_23); + + ResonancePdf *f0_600 = new ResonancePdf("f0_600", + fixAmps ? new Variable("f0_600_amp_real", 0.068 * (-_mD02)) + : new Variable("f0_600_amp_real", 0.068 * (-_mD02), 0.001, 0, 0), + fixAmps ? new Variable("f0_600_amp_imag", 0.010 * (-_mD02)) + : new Variable("f0_600_amp_imag", 0.010 * (-_mD02), 0.1, 0, 0), + new Variable("f0_600_mass", 0.500, 0.01, 0.3, 0.7), + new Variable("f0_600_width", 0.400, 0.01, 0.2, 0.6), + 0, + PAIR_23); + + ResonancePdf *nonr = new ResonancePdf("nonr", + fixAmps ? new Variable("nonr_amp_real", 0.5595 * (-1)) + : new Variable("nonr_amp_real", 0.5595 * (-1), 0.001, 0, 0), + fixAmps ? new Variable("nonr_amp_imag", -0.108761 * (-1)) + : new Variable("nonr_amp_imag", -0.108761 * (-1), 0.1, 0, 0)); dtop0pp->resonances.push_back(nonr); dtop0pp->resonances.push_back(rhop); @@ -750,16 +742,16 @@ TddpPdf* makeSignalPdf(MixingTimeResolution* resolution = 0, GooPdf* eff = 0) { dtop0pp->resonances.push_back(f0_600); if(!fitMasses) { - for(vector::iterator res = dtop0pp->resonances.begin(); res != dtop0pp->resonances.end(); ++res) { + for(vector::iterator res = dtop0pp->resonances.begin(); res != dtop0pp->resonances.end(); + ++res) { (*res)->setParameterConstantness(true); } } - if(!eff) { - vector offsets; - vector observables; - vector coefficients; + vector offsets; + vector observables; + vector coefficients; observables.push_back(m12); observables.push_back(m13); @@ -769,51 +761,72 @@ TddpPdf* makeSignalPdf(MixingTimeResolution* resolution = 0, GooPdf* eff = 0) { eff = new PolynomialPdf("constantEff", observables, coefficients, offsets, 0); } - std::vector resList; + std::vector resList; if(!resolution) { if(massd0) { for(int i = 0; i < mdslices; ++i) { sprintf(strbuffer, "coreFrac_%i", i); - Variable* coreFrac = new Variable(strbuffer, 0.90, 0.001, 0.55, 0.999); + Variable *coreFrac = new Variable(strbuffer, 0.90, 0.001, 0.55, 0.999); sprintf(strbuffer, "coreBias_%i", i); -// Variable* coreBias = new Variable(strbuffer, 0.1, 0.001, -0.20, 0.30); - Variable* coreBias = new Variable(strbuffer, -0.1, 0.001, -0.20, 0.30); + // Variable* coreBias = new Variable(strbuffer, 0.1, 0.001, -0.20, 0.30); + Variable *coreBias = new Variable(strbuffer, -0.1, 0.001, -0.20, 0.30); sprintf(strbuffer, "coreScaleFactor_%i", i); - Variable* coreScaleFactor = new Variable(strbuffer, 0.96, 0.001, 0.20, 1.50); + Variable *coreScaleFactor = new Variable(strbuffer, 0.96, 0.001, 0.20, 1.50); sprintf(strbuffer, "tailScaleFactor_%i", i); - Variable* tailScaleFactor = new Variable(strbuffer, 1.63, 0.001, 0.90, 6.00); - resolution = new ThreeGaussResolution(coreFrac, constantOne, coreBias, coreScaleFactor, constantZero, tailScaleFactor, - constantZero, constantOne); + Variable *tailScaleFactor = new Variable(strbuffer, 1.63, 0.001, 0.90, 6.00); + resolution = new ThreeGaussResolution(coreFrac, + constantOne, + coreBias, + coreScaleFactor, + constantZero, + tailScaleFactor, + constantZero, + constantOne); resList.push_back(resolution); } } else { - Variable* coreFrac = new Variable("coreFrac", 0.90, 0.001, 0.35, 0.999); - //Variable* tailFrac = new Variable("tailFrac", 0.90, 0.001, 0.80, 1.00); - Variable* coreBias = new Variable("coreBias", 0.0, 0.001, -0.20, 0.30); - Variable* coreScaleFactor = new Variable("coreScaleFactor", 0.96, 0.001, 0.20, 1.50); - //Variable* tailBias = new Variable("tailBias", 0); - Variable* tailScaleFactor = new Variable("tailScaleFactor", 1.63, 0.001, 0.90, 6.00); - //Variable* outlBias = new Variable("outlBias", 0); - //Variable* outlScaleFactor = new Variable("outlScaleFactor", 5.0, 0.01, 0.1, 10.0); - //resolution = new ThreeGaussResolution(coreFrac, tailFrac, coreBias, coreScaleFactor, tailBias, tailScaleFactor, outlBias, outlScaleFactor); - -// resolution = new ThreeGaussResolution(coreFrac, constantOne, coreBias, coreScaleFactor, constantZero, tailScaleFactor, constantZero, constantOne); -// resolution = new ThreeGaussResolution(coreFrac, constantOne, constantZero, coreScaleFactor, constantZero, tailScaleFactor, constantZero, constantOne); + Variable *coreFrac = new Variable("coreFrac", 0.90, 0.001, 0.35, 0.999); + // Variable* tailFrac = new Variable("tailFrac", 0.90, 0.001, 0.80, 1.00); + Variable *coreBias = new Variable("coreBias", 0.0, 0.001, -0.20, 0.30); + Variable *coreScaleFactor = new Variable("coreScaleFactor", 0.96, 0.001, 0.20, 1.50); + // Variable* tailBias = new Variable("tailBias", 0); + Variable *tailScaleFactor = new Variable("tailScaleFactor", 1.63, 0.001, 0.90, 6.00); + // Variable* outlBias = new Variable("outlBias", 0); + // Variable* outlScaleFactor = new Variable("outlScaleFactor", 5.0, 0.01, 0.1, 10.0); + // resolution = new ThreeGaussResolution(coreFrac, tailFrac, coreBias, coreScaleFactor, tailBias, + // tailScaleFactor, outlBias, outlScaleFactor); + + // resolution = new ThreeGaussResolution(coreFrac, constantOne, coreBias, coreScaleFactor, + // constantZero, tailScaleFactor, constantZero, constantOne); + // resolution = new ThreeGaussResolution(coreFrac, constantOne, constantZero, coreScaleFactor, + // constantZero, tailScaleFactor, constantZero, constantOne); if(!doToyStudy) - resolution = new ThreeGaussResolution(coreFrac, constantOne, coreBias, coreScaleFactor, coreBias, tailScaleFactor, - constantZero, constantOne); + resolution = new ThreeGaussResolution(coreFrac, + constantOne, + coreBias, + coreScaleFactor, + coreBias, + tailScaleFactor, + constantZero, + constantOne); else { coreBias->setValue(0); coreScaleFactor->setValue(1); coreScaleFactor->setFixed(false); - resolution = new ThreeGaussResolution(constantOne, constantOne, coreBias, coreScaleFactor, constantZero, constantOne, - constantZero, constantOne); + resolution = new ThreeGaussResolution(constantOne, + constantOne, + coreBias, + coreScaleFactor, + constantZero, + constantOne, + constantZero, + constantOne); } } } - TddpPdf* mixPdf = 0; + TddpPdf *mixPdf = 0; if(massd0) mixPdf = new TddpPdf("mixPdf", dtime, sigma, m12, m13, eventNumber, dtop0pp, resList, eff, massd0, wBkg1); @@ -823,24 +836,24 @@ TddpPdf* makeSignalPdf(MixingTimeResolution* resolution = 0, GooPdf* eff = 0) { return mixPdf; } -GooPdf* makeFlatBkgDalitzPdf(bool fixem = true) { - vector offsets; - vector observables; - vector coefficients; +GooPdf *makeFlatBkgDalitzPdf(bool fixem = true) { + vector offsets; + vector observables; + vector coefficients; offsets.push_back(constantZero); offsets.push_back(constantZero); observables.push_back(m12); observables.push_back(m13); coefficients.push_back(constantOne); - PolynomialPdf* poly = new PolynomialPdf("flatbkgPdf", observables, coefficients, offsets, 0); - Variable* g_mean = new Variable("g_mean", toyBkgTimeMean, 0.01, -0.2, 0.5); - Variable* g_sigma = new Variable("g_sigma", toyBkgTimeRMS, 0.01, 0.15, 1.5); - GooPdf* gt = new GaussianPdf("flatbkg_timepdf", dtime, g_mean, g_sigma); + PolynomialPdf *poly = new PolynomialPdf("flatbkgPdf", observables, coefficients, offsets, 0); + Variable *g_mean = new Variable("g_mean", toyBkgTimeMean, 0.01, -0.2, 0.5); + Variable *g_sigma = new Variable("g_sigma", toyBkgTimeRMS, 0.01, 0.15, 1.5); + GooPdf *gt = new GaussianPdf("flatbkg_timepdf", dtime, g_mean, g_sigma); comps.clear(); comps.push_back(poly); comps.push_back(gt); - GooPdf* ret = new ProdPdf("flatbkg_total", comps); + GooPdf *ret = new ProdPdf("flatbkg_total", comps); if(fixem) ret->setParameterConstantness(true); @@ -848,62 +861,60 @@ GooPdf* makeFlatBkgDalitzPdf(bool fixem = true) { return ret; } - int runToyFit(int ifile, int nfile, bool noPlots = true) { - if(!nfile || ifile<0|| ifile >=100) + if(!nfile || ifile < 0 || ifile >= 100) return 7; // No File or file error doToyStudy = true; -// dtime = new Variable("dtime", lowerTime, upperTime); + // dtime = new Variable("dtime", lowerTime, upperTime); dtime = new Variable("dtime", -3, 5); - dtime->setNumBins( floor((upperTime - lowerTime) / 0.05 + 0.5)); - //dtime->getNumBins() = 200; - //sigma = new Variable("sigma", 0, 0.8); + dtime->setNumBins(floor((upperTime - lowerTime) / 0.05 + 0.5)); + // dtime->getNumBins() = 200; + // sigma = new Variable("sigma", 0, 0.8); sigma = new Variable("sigma", 0.099, 0.101); - sigma->setNumBins(1) ; - // Cheating way to avoid Punzi effect for toy MC. The normalisation integral is now a delta function! - m12 = new Variable("m12", 0, 3); + sigma->setNumBins(1); + // Cheating way to avoid Punzi effect for toy MC. The normalisation integral is now a delta function! + m12 = new Variable("m12", 0, 3); m12->setNumBins(240); - m13 = new Variable("m13", 0, 3); + m13 = new Variable("m13", 0, 3); m13->setNumBins(240); eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); - wSig0 = new Variable("wSig0", 0, 1); + wSig0 = new Variable("wSig0", 0, 1); - for(int i =0 ; iget_filename(strbuffer, "examples/pipipi0DPFit"); getToyData(toySigFraction); } - - //TruthResolution* dat = new TruthResolution(); - //TddpPdf* mixPdf = makeSignalPdf(dat); + // TruthResolution* dat = new TruthResolution(); + // TddpPdf* mixPdf = makeSignalPdf(dat); signalDalitz = makeSignalPdf(); signalDalitz->setDataSize(data->getNumEvents(), 6); // Default 5 is fine for toys sig0_jsugg = new ExpPdf("sig0_jsugg", sigma, constantZero); -// sig0_jsugg = makeBkg_sigma_strips(0); + // sig0_jsugg = makeBkg_sigma_strips(0); sig0_jsugg->addSpecialMask(PdfBase::ForceSeparateNorm); sig0_jsugg->setParameterConstantness(true); comps.clear(); comps.push_back(signalDalitz); -// comps.push_back(sig0_jsugg); + // comps.push_back(sig0_jsugg); std::cout << "Creating overall PDF\n"; - //ProdPdf* overallSignal = new ProdPdf("overallSignal", comps); - GooPdf* bkgPdf = makeFlatBkgDalitzPdf(); + // ProdPdf* overallSignal = new ProdPdf("overallSignal", comps); + GooPdf *bkgPdf = makeFlatBkgDalitzPdf(); bkgPdf->setParameterConstantness(true); - std::vector evtWeights; + std::vector evtWeights; evtWeights.push_back(wSig0); -// evtWeights.push_back(wBkg2); - std::vector components; + // evtWeights.push_back(wBkg2); + std::vector components; components.push_back(signalDalitz); components.push_back(bkgPdf); - EventWeightedAddPdf* mixPdf = new EventWeightedAddPdf("total", evtWeights, components); -// GooPdf* mixPdf = overallSignal; + EventWeightedAddPdf *mixPdf = new EventWeightedAddPdf("total", evtWeights, components); + // GooPdf* mixPdf = overallSignal; mixPdf->setData(data); - + int retval; if(minuit1) { GooFit::FitManagerMinuit1 datapdf(mixPdf); @@ -916,25 +927,28 @@ int runToyFit(int ifile, int nfile, bool noPlots = true) { datapdf.fit(); retval = datapdf; } - - printf("Fit results:\ntau : (%.3f $\\pm$ %.3f) fs\nxmixing: (%.3f $\\pm$ %.3f)%%\nymixing: (%.3f $\\pm$ %.3f)%%\n", - 1000*ptr_to_dtau->getValue(), 1000*ptr_to_dtau->getError(), - 100*ptr_to_xmix->getValue(), 100*ptr_to_xmix->getError(), - 100*ptr_to_ymix->getValue(), 100*ptr_to_ymix->getError()); - + + printf( + "Fit results:\ntau : (%.3f $\\pm$ %.3f) fs\nxmixing: (%.3f $\\pm$ %.3f)%%\nymixing: (%.3f $\\pm$ %.3f)%%\n", + 1000 * ptr_to_dtau->getValue(), + 1000 * ptr_to_dtau->getError(), + 100 * ptr_to_xmix->getValue(), + 100 * ptr_to_xmix->getError(), + 100 * ptr_to_ymix->getValue(), + 100 * ptr_to_ymix->getError()); + if(!noPlots) makeToyDalitzPlots(mixPdf); - + // makeToyDalitzPlots(signalDalitz); return retval; } -void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { - +void loadDataFile(std::string fname, UnbinnedDataSet **setToFill, int effSkip) { if(!setToFill) setToFill = &data; - std::vector vars; + std::vector vars; vars.push_back(m12); vars.push_back(m13); vars.push_back(dtime); @@ -966,9 +980,9 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { double integralWeights[5] = {0, 0, 0, 0, 0}; double dummy = 0; - double mass = 0; - double delm = 0; - int events = 0; + double mass = 0; + double delm = 0; + int events = 0; while(!reader.eof()) { reader >> dummy; @@ -976,8 +990,8 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { if(reader.eof()) break; - reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. - reader >> *m12; // Already swapped according to D* charge + reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. + reader >> *m12; // Already swapped according to D* charge reader >> *m13; // Errors on Dalitz variables @@ -1016,10 +1030,10 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { continue; } else { // Enforce signal box on all data sets! - if(mass <= 1.8654 + 0.0075*md0_lower_window + md0offset) + if(mass <= 1.8654 + 0.0075 * md0_lower_window + md0offset) continue; - if(mass >= 1.8654 + 0.0075*md0_upper_window + md0offset) + if(mass >= 1.8654 + 0.0075 * md0_upper_window + md0offset) continue; } @@ -1030,10 +1044,10 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { if(deltam->getValue() <= deltam->getLowerLimit()) continue; } else { - if(delm >= 0.1454 + 0.0003*deltam_upper_window) + if(delm >= 0.1454 + 0.0003 * deltam_upper_window) continue; - if(delm <= 0.1454 + 0.0003*deltam_lower_window) + if(delm <= 0.1454 + 0.0003 * deltam_lower_window) continue; } @@ -1051,22 +1065,23 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { integralWeights[2] += wBkg2->getValue(); integralWeights[3] += wBkg3->getValue(); integralWeights[4] += wBkg4->getValue(); - eventNumber->setValue( (*setToFill)->getNumEvents()); + eventNumber->setValue((*setToFill)->getNumEvents()); // See comments in TddpPdf.hh for explanation of this. double mistag = wSig0->getValue() + wBkg1->getValue() * luckyFrac; wSig0->setValue(wSig0->getValue() + wBkg1->getValue()); - wBkg1->setValue( mistag / wSig0->getValue()); + wBkg1->setValue(mistag / wSig0->getValue()); if((binEffData) && (0 == events % effSkip)) { double weight = weightHistogram->GetBinContent(weightHistogram->FindBin(m12->getValue(), m13->getValue())); - //weight = 1; + // weight = 1; binEffData->addWeightedEvent(weight); - //binEffData->addEvent(); + // binEffData->addEvent(); if(underlyingBins) underlyingBins->Fill(m12->getValue(), m13->getValue(), weight); - } else(*setToFill)->addEvent(); + } else + (*setToFill)->addEvent(); events++; @@ -1078,37 +1093,33 @@ void loadDataFile(std::string fname, UnbinnedDataSet** setToFill, int effSkip) { else hiM23Sigma->Fill(sigma->getValue()); - //std::cout << "Filled sigma with " << sigma->getValue() << " " << currM23 << std::endl; + // std::cout << "Filled sigma with " << sigma->getValue() << " " << currM23 << std::endl; } if(wSig0->getValue() > 1.0) - std::cout << "Problem with event " << (*setToFill)->getNumEvents() << ", too-large signal weight " << wSig0->getValue() << - std::endl; + std::cout << "Problem with event " << (*setToFill)->getNumEvents() << ", too-large signal weight " + << wSig0->getValue() << std::endl; /* if ((*setToFill)->getNumEvents() < 10) { std::cout << (*setToFill)->getNumEvents() << " : " - << m12->getValue() << " " - << m13->getValue() << " " - << dtime->getValue() << " " - << sigma->getValue() << " " - << wSig0->getValue() << " " - << wBkg1->getValue() << " " - << wBkg2->getValue() << " " - << wBkg3->getValue() << " " - << wBkg4->getValue() << " " - << std::endl; + << m12->getValue() << " " + << m13->getValue() << " " + << dtime->getValue() << " " + << sigma->getValue() << " " + << wSig0->getValue() << " " + << wBkg1->getValue() << " " + << wBkg2->getValue() << " " + << wBkg3->getValue() << " " + << wBkg4->getValue() << " " + << std::endl; } */ } std::cout << "Loaded " << (*setToFill)->getNumEvents() << " events.\n"; - std::cout << "Integrals: " << integralWeights[0] << " " - << integralWeights[1] << " " - << integralWeights[2] << " " - << integralWeights[3] << " " - << integralWeights[4] << "\n"; - + std::cout << "Integrals: " << integralWeights[0] << " " << integralWeights[1] << " " << integralWeights[2] << " " + << integralWeights[3] << " " << integralWeights[4] << "\n"; } void makeFullFitVariables() { @@ -1120,72 +1131,72 @@ void makeFullFitVariables() { exists = true; dtime = new Variable("dtime", lowerTime, upperTime); - dtime->setNumBins( floor((upperTime - lowerTime) / 0.05 + 0.5)); + dtime->setNumBins(floor((upperTime - lowerTime) / 0.05 + 0.5)); sigma = new Variable("sigma", 0, maxSigma); sigma->setNumBins(floor((maxSigma / 0.01) + 0.5)); - m12 = new Variable("m12", 0, 3); - m13 = new Variable("m13", 0, 3); + m12 = new Variable("m12", 0, 3); + m13 = new Variable("m13", 0, 3); m12->setNumBins(normBinning); m13->setNumBins(normBinning); eventNumber = new CountingVariable("eventNumber", 0, INT_MAX); - wSig0 = new Variable("wSig0", 0, 1); - wBkg1 = new Variable("wBkg1", 0, 1); - wBkg2 = new Variable("wBkg2", 0, 1); - wBkg3 = new Variable("wBkg3", 0, 1); - wBkg4 = new Variable("wBkg4", 0, 1); + wSig0 = new Variable("wSig0", 0, 1); + wBkg1 = new Variable("wBkg1", 0, 1); + wBkg2 = new Variable("wBkg2", 0, 1); + wBkg3 = new Variable("wBkg3", 0, 1); + wBkg4 = new Variable("wBkg4", 0, 1); } -GooPdf* makeSignalJSU_gg(int idx, bool fixem = true) { +GooPdf *makeSignalJSU_gg(int idx, bool fixem = true) { // Values from TSigma, 'Mikhail default'. static int jsugg_num = -1; jsugg_num++; sprintf(strbuffer, "js_meana_%i", jsugg_num); - Variable* js_meana = new Variable(strbuffer, 0.0593, 0.01, 0, 0.2); + Variable *js_meana = new Variable(strbuffer, 0.0593, 0.01, 0, 0.2); js_meana->setFixed(fixem); sprintf(strbuffer, "js_sigma_%i", jsugg_num); - Variable* js_sigma = new Variable(strbuffer, 0.000474, 0.0001, 0, 0.001); + Variable *js_sigma = new Variable(strbuffer, 0.000474, 0.0001, 0, 0.001); js_sigma->setFixed(fixem); sprintf(strbuffer, "js_gamma_%i", jsugg_num); - Variable* js_gamma = new Variable(strbuffer, -10.1942, 1, -30, 0); + Variable *js_gamma = new Variable(strbuffer, -10.1942, 1, -30, 0); js_gamma->setFixed(fixem); sprintf(strbuffer, "js_delta_%i", jsugg_num); - Variable* js_delta = new Variable(strbuffer, 1.4907, 0.1, 0.5, 5); + Variable *js_delta = new Variable(strbuffer, 1.4907, 0.1, 0.5, 5); js_delta->setFixed(fixem); sprintf(strbuffer, "frac_jsu_%i", jsugg_num); - Variable* frac_jsu = new Variable(strbuffer, 0.9516, 0.01, 0.5, 1.0); + Variable *frac_jsu = new Variable(strbuffer, 0.9516, 0.01, 0.5, 1.0); frac_jsu->setFixed(fixem); sprintf(strbuffer, "frac_ga1_%i", jsugg_num); - Variable* frac_ga1 = new Variable(strbuffer, 0.001845, 0.0005, 0.0001, 0.3); + Variable *frac_ga1 = new Variable(strbuffer, 0.001845, 0.0005, 0.0001, 0.3); frac_ga1->setFixed(fixem); sprintf(strbuffer, "g1_meana_%i", jsugg_num); - Variable* g1_meana = new Variable(strbuffer, 0.2578, 0.003, 0.1, 0.5); + Variable *g1_meana = new Variable(strbuffer, 0.2578, 0.003, 0.1, 0.5); g1_meana->setFixed(fixem); sprintf(strbuffer, "g1_sigma_%i", jsugg_num); - Variable* g1_sigma = new Variable(strbuffer, 0.03086, 0.01, 0.005, 0.25); + Variable *g1_sigma = new Variable(strbuffer, 0.03086, 0.01, 0.005, 0.25); g1_sigma->setFixed(fixem); sprintf(strbuffer, "g2_meana_%i", jsugg_num); - Variable* g2_meana = new Variable(strbuffer, 0.32, 0.01, 0.1, 0.5); + Variable *g2_meana = new Variable(strbuffer, 0.32, 0.01, 0.1, 0.5); g2_meana->setFixed(fixem); sprintf(strbuffer, "g2_sigma_%i", jsugg_num); - Variable* g2_sigma = new Variable(strbuffer, 0.05825, 0.01, 0.01, 0.1); + Variable *g2_sigma = new Variable(strbuffer, 0.05825, 0.01, 0.01, 0.1); g2_sigma->setFixed(fixem); - //Variable* g2_sigma = new Variable("g2_sigma", 0.5825); + // Variable* g2_sigma = new Variable("g2_sigma", 0.5825); sprintf(strbuffer, "js_%i", jsugg_num); - JohnsonSUPdf* js = new JohnsonSUPdf(strbuffer, sigma, js_meana, js_sigma, js_gamma, js_delta); + JohnsonSUPdf *js = new JohnsonSUPdf(strbuffer, sigma, js_meana, js_sigma, js_gamma, js_delta); sprintf(strbuffer, "g1_%i", jsugg_num); - GaussianPdf* g1 = new GaussianPdf(strbuffer, sigma, g1_meana, g1_sigma); + GaussianPdf *g1 = new GaussianPdf(strbuffer, sigma, g1_meana, g1_sigma); sprintf(strbuffer, "g2_%i", jsugg_num); - //GaussianPdf* g2 = new GaussianPdf(strbuffer, sigma, g2_meana, g2_sigma); + // GaussianPdf* g2 = new GaussianPdf(strbuffer, sigma, g2_meana, g2_sigma); weights.clear(); weights.push_back(frac_jsu); - //weights.push_back(frac_ga1); + // weights.push_back(frac_ga1); comps.clear(); comps.push_back(js); comps.push_back(g1); - //comps.push_back(g2); + // comps.push_back(g2); // Deal with special indices to get different starting points switch(idx) { @@ -1197,12 +1208,12 @@ GooPdf* makeSignalJSU_gg(int idx, bool fixem = true) { frac_jsu->setValue(0.80); break; - //case 5: - //g1_sigma->getLowerLimit() = 0.005; - //break; + // case 5: + // g1_sigma->getLowerLimit() = 0.005; + // break; case 7: frac_jsu->setValue(0.80); - //frac_ga1->getValue() = 0.05; + // frac_ga1->getValue() = 0.05; break; case 11: @@ -1215,41 +1226,41 @@ GooPdf* makeSignalJSU_gg(int idx, bool fixem = true) { } sprintf(strbuffer, "signal_sigma_%i", jsugg_num); - AddPdf* signal_sigma = new AddPdf(strbuffer, weights, comps); + AddPdf *signal_sigma = new AddPdf(strbuffer, weights, comps); return signal_sigma; } -GooPdf* makeMikhailJSU_gg(bool fixem = true) { +GooPdf *makeMikhailJSU_gg(bool fixem = true) { // Values from TSigma, 'Mikhail default'. - Variable* js_meana = new Variable("js_meana", 0.0593279, 0.01, 0, 0.2); + Variable *js_meana = new Variable("js_meana", 0.0593279, 0.01, 0, 0.2); js_meana->setFixed(fixem); - Variable* js_sigma = new Variable("js_sigma", 0.000474171, 0.0001, 0, 0.001); + Variable *js_sigma = new Variable("js_sigma", 0.000474171, 0.0001, 0, 0.001); js_sigma->setFixed(fixem); - Variable* js_gamma = new Variable("js_gamma", -10.1942, 1, -30, 0); + Variable *js_gamma = new Variable("js_gamma", -10.1942, 1, -30, 0); js_gamma->setFixed(fixem); - Variable* js_delta = new Variable("js_delta", 1.4907, 0.1, 0.5, 5); + Variable *js_delta = new Variable("js_delta", 1.4907, 0.1, 0.5, 5); js_delta->setFixed(fixem); - Variable* frac_jsu = new Variable("frac_jsu", 0.951638, 0.01, 0.5, 1.0); + Variable *frac_jsu = new Variable("frac_jsu", 0.951638, 0.01, 0.5, 1.0); frac_jsu->setFixed(fixem); - Variable* frac_ga1 = new Variable("frac_ga1", 0.0184522, 0.00001, 0.001, 0.3); + Variable *frac_ga1 = new Variable("frac_ga1", 0.0184522, 0.00001, 0.001, 0.3); frac_ga1->setFixed(fixem); - Variable* g1_meana = new Variable("g1_meana", 0.257796, 0.003, 0.1, 0.5); + Variable *g1_meana = new Variable("g1_meana", 0.257796, 0.003, 0.1, 0.5); g1_meana->setFixed(fixem); - Variable* g1_sigma = new Variable("g1_sigma", 0.0308619, 0.01, 0.005, 0.25); + Variable *g1_sigma = new Variable("g1_sigma", 0.0308619, 0.01, 0.005, 0.25); g1_sigma->setFixed(fixem); - Variable* g2_meana = new Variable("g2_meana", 0.319952, 0.01, 0.1, 0.5); + Variable *g2_meana = new Variable("g2_meana", 0.319952, 0.01, 0.1, 0.5); g2_meana->setFixed(fixem); - Variable* g2_sigma = new Variable("g2_sigma", 0.0582524, 0.01, 0.01, 0.1); + Variable *g2_sigma = new Variable("g2_sigma", 0.0582524, 0.01, 0.01, 0.1); g2_sigma->setFixed(fixem); - //Variable* g2_sigma = new Variable("g2_sigma", 0.5825); + // Variable* g2_sigma = new Variable("g2_sigma", 0.5825); frac_ga1->setValue(frac_ga1->getValue() * (1 - frac_jsu->getValue())); - JohnsonSUPdf* js = new JohnsonSUPdf("js", sigma, js_meana, js_sigma, js_gamma, js_delta); - GaussianPdf* g1 = new GaussianPdf("g1", sigma, g1_meana, g1_sigma); - GaussianPdf* g2 = new GaussianPdf("g2", sigma, g2_meana, g2_sigma); + JohnsonSUPdf *js = new JohnsonSUPdf("js", sigma, js_meana, js_sigma, js_gamma, js_delta); + GaussianPdf *g1 = new GaussianPdf("g1", sigma, g1_meana, g1_sigma); + GaussianPdf *g2 = new GaussianPdf("g2", sigma, g2_meana, g2_sigma); weights.clear(); weights.push_back(frac_jsu); @@ -1259,32 +1270,34 @@ GooPdf* makeMikhailJSU_gg(bool fixem = true) { comps.push_back(g1); comps.push_back(g2); - GooPdf* ret = new AddPdf("signal_sigma", weights, comps); + GooPdf *ret = new AddPdf("signal_sigma", weights, comps); return ret; } -const int numSigmaBins = 36; -TH1F** sigma_dat_hists = 0; -TH1F** sigma_pdf_hists = 0; -UnbinnedDataSet** sigma_data = 0; -vector jsuList; +const int numSigmaBins = 36; +TH1F **sigma_dat_hists = 0; +TH1F **sigma_pdf_hists = 0; +UnbinnedDataSet **sigma_data = 0; +vector jsuList; -GooPdf* makeSigmaMap() { - sigma_dat_hists = new TH1F*[numSigmaBins]; - sigma_pdf_hists = new TH1F*[numSigmaBins]; - sigma_data = new UnbinnedDataSet*[numSigmaBins]; +GooPdf *makeSigmaMap() { + sigma_dat_hists = new TH1F *[numSigmaBins]; + sigma_pdf_hists = new TH1F *[numSigmaBins]; + sigma_data = new UnbinnedDataSet *[numSigmaBins]; - std::vector vars; + std::vector vars; vars.push_back(sigma); for(int i = 0; i < numSigmaBins; ++i) { sprintf(strbuffer, "sigma_data_hist_%i", i); - sigma_dat_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_dat_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_dat_hists[i]->SetStats(false); sigma_dat_hists[i]->SetMarkerStyle(8); sigma_dat_hists[i]->SetMarkerSize(0.7); sprintf(strbuffer, "sigma_pdf_hist_%i", i); - sigma_pdf_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_pdf_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_pdf_hists[i]->SetStats(false); sigma_pdf_hists[i]->SetLineWidth(3); sigma_pdf_hists[i]->SetLineColor(kBlue); @@ -1295,26 +1308,24 @@ GooPdf* makeSigmaMap() { int numEvents = data->getNumEvents(); for(int i = 0; i < numEvents; ++i) { - m12->setValue( data->getValue(m12, i)); - m13->setValue( data->getValue(m13, i)); - sigma->setValue( data->getValue(sigma, i)); + m12->setValue(data->getValue(m12, i)); + m13->setValue(data->getValue(m13, i)); + sigma->setValue(data->getValue(sigma, i)); - int xbin = (int) floor(m12->getValue() / 0.5); - int ybin = (int) floor(m13->getValue() / 0.5); - int overallbin = ybin*6 + xbin; + int xbin = (int)floor(m12->getValue() / 0.5); + int ybin = (int)floor(m13->getValue() / 0.5); + int overallbin = ybin * 6 + xbin; sigma_dat_hists[overallbin]->Fill(sigma->getValue()); sigma_data[overallbin]->addEvent(); } - - - //vector jsuList; + // vector jsuList; for(int i = 0; i < numSigmaBins; ++i) { - GooPdf* js = makeSignalJSU_gg(i, false); + GooPdf *js = makeSignalJSU_gg(i, false); jsuList.push_back(js); - //int xbin = i % 6; - //int ybin = i / 6; + // int xbin = i % 6; + // int ybin = i / 6; /*int inDalitzPlot = 0; if (cpuDalitz(0.5*(xbin+0), 0.5*(ybin+0), _mD0, piZeroMass, piPlusMass, piPlusMass)) inDalitzPlot++; @@ -1335,12 +1346,12 @@ GooPdf* makeSigmaMap() { currpdf.fit(); } js->setParameterConstantness(true); - //js->clearCurrentFit(); + // js->clearCurrentFit(); std::cout << "Done with sigma box " << i << "\n"; } } - vector obses; + vector obses; obses.push_back(m12); obses.push_back(m13); vector limits; @@ -1352,28 +1363,29 @@ GooPdf* makeSigmaMap() { vector numBins; numBins.push_back(6); numBins.push_back(6); - BinTransformPdf* mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); + BinTransformPdf *mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); return new MappedPdf("sigmaMap", mapFunction, jsuList); } -GooPdf* make1BinSigmaMap() { - - sigma_dat_hists = new TH1F*[1]; - sigma_pdf_hists = new TH1F*[1]; - sigma_data = new UnbinnedDataSet*[1]; +GooPdf *make1BinSigmaMap() { + sigma_dat_hists = new TH1F *[1]; + sigma_pdf_hists = new TH1F *[1]; + sigma_data = new UnbinnedDataSet *[1]; - std::vector vars; + std::vector vars; vars.push_back(sigma); for(int i = 0; i < 1; ++i) { sprintf(strbuffer, "sigma_data_hist_%i", i); - sigma_dat_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_dat_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_dat_hists[i]->SetStats(false); sigma_dat_hists[i]->SetMarkerStyle(8); sigma_dat_hists[i]->SetMarkerSize(0.7); sprintf(strbuffer, "sigma_pdf_hist_%i", i); - sigma_pdf_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_pdf_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_pdf_hists[i]->SetStats(false); sigma_pdf_hists[i]->SetLineWidth(3); sigma_pdf_hists[i]->SetLineColor(kBlue); @@ -1384,20 +1396,18 @@ GooPdf* make1BinSigmaMap() { int numEvents = data->getNumEvents(); for(int i = 0; i < numEvents; ++i) { - m12->setValue( data->getValue(m12, i)); - m13->setValue( data->getValue(m13, i)); - sigma->setValue( data->getValue(sigma, i)); + m12->setValue(data->getValue(m12, i)); + m13->setValue(data->getValue(m13, i)); + sigma->setValue(data->getValue(sigma, i)); int overallbin = 0; sigma_dat_hists[overallbin]->Fill(sigma->getValue()); sigma_data[overallbin]->addEvent(); } - - - //vector jsuList; + // vector jsuList; for(int i = 0; i < 1; ++i) { - GooPdf* js = makeSignalJSU_gg(i, false); + GooPdf *js = makeSignalJSU_gg(i, false); jsuList.push_back(js); if(0 == sigma_data[i]->getNumEvents()) @@ -1413,12 +1423,12 @@ GooPdf* make1BinSigmaMap() { currpdf.fit(); } js->setParameterConstantness(true); - //js->clearCurrentFit(); + // js->clearCurrentFit(); std::cout << "Done with sigma box " << i << "\n"; } } - vector obses; + vector obses; obses.push_back(m12); obses.push_back(m13); vector limits; @@ -1430,27 +1440,29 @@ GooPdf* make1BinSigmaMap() { vector numBins; numBins.push_back(1); numBins.push_back(1); - BinTransformPdf* mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); + BinTransformPdf *mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); return new MappedPdf("sigmaMap", mapFunction, jsuList); } -GooPdf* make4BinSigmaMap() { - sigma_dat_hists = new TH1F*[4]; - sigma_pdf_hists = new TH1F*[4]; - sigma_data = new UnbinnedDataSet*[4]; +GooPdf *make4BinSigmaMap() { + sigma_dat_hists = new TH1F *[4]; + sigma_pdf_hists = new TH1F *[4]; + sigma_data = new UnbinnedDataSet *[4]; - std::vector vars; + std::vector vars; vars.push_back(sigma); for(int i = 0; i < 4; ++i) { sprintf(strbuffer, "sigma_data_hist_%i", i); - sigma_dat_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_dat_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_dat_hists[i]->SetStats(false); sigma_dat_hists[i]->SetMarkerStyle(8); sigma_dat_hists[i]->SetMarkerSize(0.7); sprintf(strbuffer, "sigma_pdf_hist_%i", i); - sigma_pdf_hists[i] = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); + sigma_pdf_hists[i] + = new TH1F(strbuffer, "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); sigma_pdf_hists[i]->SetStats(false); sigma_pdf_hists[i]->SetLineWidth(3); sigma_pdf_hists[i]->SetLineColor(kBlue); @@ -1465,18 +1477,16 @@ GooPdf* make4BinSigmaMap() { m13->setValue(data->getValue(m13, i)); sigma->setValue(data->getValue(sigma, i)); - int xbin = (int) floor(m12->getValue() / 1.5); - int ybin = (int) floor(m13->getValue() / 1.5); - int overallbin = ybin*2 + xbin; + int xbin = (int)floor(m12->getValue() / 1.5); + int ybin = (int)floor(m13->getValue() / 1.5); + int overallbin = ybin * 2 + xbin; sigma_dat_hists[overallbin]->Fill(sigma->getValue()); sigma_data[overallbin]->addEvent(); } - - - //vector jsuList; + // vector jsuList; for(int i = 0; i < 4; ++i) { - GooPdf* js = makeSignalJSU_gg(i, false); + GooPdf *js = makeSignalJSU_gg(i, false); jsuList.push_back(js); if(0 == sigma_data[i]->getNumEvents()) @@ -1492,12 +1502,12 @@ GooPdf* make4BinSigmaMap() { currpdf.fit(); } js->setParameterConstantness(true); - //js->clearCurrentFit(); + // js->clearCurrentFit(); std::cout << "Done with sigma box " << i << "\n"; } } - vector obses; + vector obses; obses.push_back(m12); obses.push_back(m13); vector limits; @@ -1509,12 +1519,12 @@ GooPdf* make4BinSigmaMap() { vector numBins; numBins.push_back(2); numBins.push_back(2); - BinTransformPdf* mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); + BinTransformPdf *mapFunction = new BinTransformPdf("mapFunction", obses, limits, binSizes, numBins); return new MappedPdf("sigmaMap", mapFunction, jsuList); } -void coarseBin(TH2F& dalitzHist, int grain) { +void coarseBin(TH2F &dalitzHist, int grain) { // Move from too-fine-to-see binning down to reasonable binning in Dalitz plots. for(int i = 1; i < m12->getNumBins(); i += grain) { for(int j = 1; j < m13->getNumBins(); j += grain) { @@ -1540,27 +1550,27 @@ struct BigBin { int ybin; int width; int height; - double getContent(TH2F* plot); + double getContent(TH2F *plot); }; -double BigBin::getContent(TH2F* plot) { +double BigBin::getContent(TH2F *plot) { double ret = 0; - //std::cout << "getContent with " << width << " " << height << " " << xbin << " " << ybin < plot->GetNbinsX()) + // std::cout << i << ", " << j << std::endl; + if(xbin + i > plot->GetNbinsX()) continue; - if(ybin+j > plot->GetNbinsY()) + if(ybin + j > plot->GetNbinsY()) continue; - ret += plot->GetBinContent(xbin+i, ybin+j); + ret += plot->GetBinContent(xbin + i, ybin + j); } } - //std::cout << "Total " << ret << std::endl; + // std::cout << "Total " << ret << std::endl; return ret; } @@ -1568,18 +1578,17 @@ struct ChisqInfo { ChisqInfo(); double chisq; int dof; - TH2F* contribPlot; + TH2F *contribPlot; }; ChisqInfo::ChisqInfo() : chisq(0) , dof(0) - , contribPlot(0) -{} + , contribPlot(0) {} -ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { +ChisqInfo *getAdaptiveChisquare(TH2F *datPlot, TH2F *pdfPlot) { bool acceptable = false; - int binSize = 1; + int binSize = 1; vector binlist; double limit = 26; @@ -1589,10 +1598,10 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { for(int xbin = 1; xbin <= datPlot->GetNbinsX(); xbin += binSize) { for(int ybin = 1; ybin <= datPlot->GetNbinsY(); ybin += binSize) { - double lox = datPlot->GetXaxis()->GetBinLowEdge(xbin+0); - double hix = datPlot->GetXaxis()->GetBinLowEdge(xbin+1+binSize); - double loy = datPlot->GetYaxis()->GetBinLowEdge(ybin+0); - double hiy = datPlot->GetYaxis()->GetBinLowEdge(ybin+1+binSize); + double lox = datPlot->GetXaxis()->GetBinLowEdge(xbin + 0); + double hix = datPlot->GetXaxis()->GetBinLowEdge(xbin + 1 + binSize); + double loy = datPlot->GetYaxis()->GetBinLowEdge(ybin + 0); + double hiy = datPlot->GetYaxis()->GetBinLowEdge(ybin + 1 + binSize); bool corner = false; if(cpuDalitz(lox, loy, _mD0, piZeroMass, piPlusMass, piPlusMass)) @@ -1608,8 +1617,8 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { continue; BigBin curr; - curr.xbin = xbin; - curr.ybin = ybin; + curr.xbin = xbin; + curr.ybin = ybin; curr.width = curr.height = binSize; binlist.push_back(curr); } @@ -1638,7 +1647,7 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { vector newbins; for(vector::iterator bin = binlist.begin(); bin != binlist.end(); ++bin) { - if(1 == (*bin).width*(*bin).height) { + if(1 == (*bin).width * (*bin).height) { newbins.push_back(*bin); continue; } @@ -1649,21 +1658,21 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { BigBin hirig; lolef.xbin = (*bin).xbin; hilef.xbin = (*bin).xbin; - lorig.xbin = (*bin).xbin + (*bin).width/2; - hirig.xbin = (*bin).xbin + (*bin).width/2; + lorig.xbin = (*bin).xbin + (*bin).width / 2; + hirig.xbin = (*bin).xbin + (*bin).width / 2; lolef.ybin = (*bin).ybin; - hilef.ybin = (*bin).ybin + (*bin).height/2; + hilef.ybin = (*bin).ybin + (*bin).height / 2; lorig.ybin = (*bin).ybin; - hirig.ybin = (*bin).ybin + (*bin).height/2; + hirig.ybin = (*bin).ybin + (*bin).height / 2; - lolef.width = (*bin).width/2; - lorig.width = (*bin).width/2; - hilef.width = (*bin).width/2; - hirig.width = (*bin).width/2; - lolef.height = (*bin).height/2; - lorig.height = (*bin).height/2; - hilef.height = (*bin).height/2; - hirig.height = (*bin).height/2; + lolef.width = (*bin).width / 2; + lorig.width = (*bin).width / 2; + hilef.width = (*bin).width / 2; + hirig.width = (*bin).width / 2; + lolef.height = (*bin).height / 2; + lorig.height = (*bin).height / 2; + hilef.height = (*bin).height / 2; + hirig.height = (*bin).height / 2; int mask = 0; @@ -1698,9 +1707,10 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { std::cout << "Split " << numSplits << " bins.\n"; } - ChisqInfo* ret = new ChisqInfo(); - ret->dof = binlist.size(); - ret->contribPlot = new TH2F("contribPlot", "", + ChisqInfo *ret = new ChisqInfo(); + ret->dof = binlist.size(); + ret->contribPlot = new TH2F("contribPlot", + "", datPlot->GetNbinsX(), datPlot->GetXaxis()->GetBinLowEdge(1), datPlot->GetXaxis()->GetBinLowEdge(datPlot->GetNbinsX() + 1), @@ -1712,10 +1722,10 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { double totalPdf = 0; for(vector::iterator bin = binlist.begin(); bin != binlist.end(); ++bin) { - double dat = (*bin).getContent(datPlot); - double pdf = (*bin).getContent(pdfPlot); + double dat = (*bin).getContent(datPlot); + double pdf = (*bin).getContent(pdfPlot); double term = (dat - pdf) / sqrt(dat); - ret->chisq += term*term; + ret->chisq += term * term; /* std::cout << "Bin (" << (*bin).xbin << ", " << (*bin).ybin << ") " @@ -1726,10 +1736,10 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { for(int i = 0; i < (*bin).width; ++i) { for(int j = 0; j < (*bin).height; ++j) { bool corner = false; - double lox = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin+i); - double hix = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin+i+1); - double loy = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin+j); - double hiy = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin+j+1); + double lox = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin + i); + double hix = datPlot->GetXaxis()->GetBinLowEdge((*bin).xbin + i + 1); + double loy = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin + j); + double hiy = datPlot->GetYaxis()->GetBinLowEdge((*bin).ybin + j + 1); if(cpuDalitz(lox, loy, _mD0, piZeroMass, piPlusMass, piPlusMass)) corner = true; @@ -1754,7 +1764,7 @@ ChisqInfo* getAdaptiveChisquare(TH2F* datPlot, TH2F* pdfPlot) { return ret; } -void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { +void makeToyDalitzPlots(GooPdf *overallSignal, std::string plotdir) { std::string call = "mkdir -p " + plotdir; system(call.c_str()); @@ -1779,24 +1789,23 @@ void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { dtime_bg_hist.SetLineColor(kMagenta); dtime_bg_hist.SetLineWidth(3); - - double totalPdf = 0; + double totalPdf = 0; double totalPdf_sig = 0; - double totalPdf_bg = 0; - double totalDat = 0; + double totalPdf_bg = 0; + double totalDat = 0; double totalSigProb = 0; - double totalBGProb = 0; + double totalBGProb = 0; for(unsigned int evt = 0; evt < data->getNumEvents(); ++evt) { double currTime = data->getValue(dtime, evt); dtime_dat_hist.Fill(currTime); totalSigProb += data->getValue(wSig0, evt); - totalBGProb += 1-data->getValue(wSig0, evt); + totalBGProb += 1 - data->getValue(wSig0, evt); totalDat++; } std::cout << "totalData = " << totalDat << ", totalSigProb = " << totalSigProb << std::endl; - std::vector vars; + std::vector vars; vars.push_back(m12); vars.push_back(m13); vars.push_back(dtime); @@ -1804,22 +1813,25 @@ void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { vars.push_back(eventNumber); vars.push_back(wSig0); UnbinnedDataSet currData(vars); - sigma->setValue( 0.1); - wSig0->setValue( totalSigProb / totalDat); + sigma->setValue(0.1); + wSig0->setValue(totalSigProb / totalDat); int evtCounter = 0; for(int i = 0; i < m12->getNumBins(); ++i) { - m12->setValue(m12->getLowerLimit() + (m12->getUpperLimit() - m12->getLowerLimit())*(i + 0.5) / m12->getNumBins()); + m12->setValue(m12->getLowerLimit() + + (m12->getUpperLimit() - m12->getLowerLimit()) * (i + 0.5) / m12->getNumBins()); for(int j = 0; j < m13->getNumBins(); ++j) { - m13->setValue( m13->getLowerLimit() + (m13->getUpperLimit() - m13->getLowerLimit())*(j + 0.5) / m13->getNumBins()); + m13->setValue(m13->getLowerLimit() + + (m13->getUpperLimit() - m13->getLowerLimit()) * (j + 0.5) / m13->getNumBins()); if(!cpuDalitz(m12->getValue(), m13->getValue(), _mD0, piZeroMass, piPlusMass, piPlusMass)) continue; for(int l = 0; l < dtime->getNumBins(); ++l) { - dtime->setValue( dtime->getLowerLimit() + (dtime->getUpperLimit() - dtime->getLowerLimit())*(l + 0.5) / dtime->getNumBins()); - eventNumber->setValue( evtCounter); + dtime->setValue(dtime->getLowerLimit() + + (dtime->getUpperLimit() - dtime->getLowerLimit()) * (l + 0.5) / dtime->getNumBins()); + eventNumber->setValue(evtCounter); evtCounter++; currData.addEvent(); } @@ -1827,7 +1839,7 @@ void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { } GOOFIT_INFO("Adding {} signal events from toy", currData.getNumEvents()); - + overallSignal->setData(&currData); signalDalitz->setDataSize(currData.getNumEvents(), 6); std::vector> pdfValues = overallSignal->getCompProbsAtDataPoints(); @@ -1835,15 +1847,15 @@ void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { for(unsigned int j = 0; j < pdfValues[0].size(); ++j) { double currTime = currData.getValue(dtime, j); dtime_sig_hist.Fill(currTime, pdfValues[1][j]); - dtime_bg_hist .Fill(currTime, pdfValues[2][j]); - totalPdf += pdfValues[0][j]; + dtime_bg_hist.Fill(currTime, pdfValues[2][j]); + totalPdf += pdfValues[0][j]; totalPdf_sig += pdfValues[1][j]; - totalPdf_bg += pdfValues[2][j]; + totalPdf_bg += pdfValues[2][j]; } for(int i = 1; i <= dtime->getNumBins(); ++i) { - dtime_sig_hist.SetBinContent(i, dtime_sig_hist.GetBinContent(i)*totalSigProb/totalPdf_sig); - dtime_bg_hist.SetBinContent(i, dtime_bg_hist.GetBinContent(i)*totalBGProb/totalPdf_bg); + dtime_sig_hist.SetBinContent(i, dtime_sig_hist.GetBinContent(i) * totalSigProb / totalPdf_sig); + dtime_bg_hist.SetBinContent(i, dtime_bg_hist.GetBinContent(i) * totalBGProb / totalPdf_bg); dtime_pdf_hist.SetBinContent(i, dtime_sig_hist.GetBinContent(i) + dtime_bg_hist.GetBinContent(i)); } @@ -1861,9 +1873,8 @@ void makeToyDalitzPlots(GooPdf* overallSignal, std::string plotdir) { foo->SetLogy(false); } - -void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_mixfit/") { - std::string mkplotdir {"mkdir " + plotdir}; +void makeDalitzPlots(GooPdf *overallSignal, std::string plotdir = "./plots_from_mixfit/") { + std::string mkplotdir{"mkdir " + plotdir}; system(mkplotdir.c_str()); foo->cd(); @@ -1922,35 +1933,71 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ m23_pdf_hist.SetLineColor(kBlue); m23_pdf_hist.SetLineWidth(3); - TH2F dalitzpm_dat_hist("dalitzpm_dat_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzpm_dat_hist("dalitzpm_dat_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzpm_dat_hist.SetStats(false); dalitzpm_dat_hist.GetXaxis()->SetTitle("m^{2}(#pi^{+} #pi^{0}) [GeV]"); dalitzpm_dat_hist.GetYaxis()->SetTitle("m^{2}(#pi^{-} #pi^{0}) [GeV]"); - TH2F dalitzpm_pdf_hist("dalitzpm_pdf_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzpm_pdf_hist("dalitzpm_pdf_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzpm_pdf_hist.SetStats(false); - TH2F dalitzp0_dat_hist("dalitzp0_dat_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzp0_dat_hist("dalitzp0_dat_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzp0_dat_hist.SetStats(false); dalitzp0_dat_hist.GetXaxis()->SetTitle("m^{2}(#pi^{+} #pi^{0}) [GeV]"); dalitzp0_dat_hist.GetYaxis()->SetTitle("m^{2}(#pi^{-} #pi^{+}) [GeV]"); - TH2F dalitzp0_pdf_hist("dalitzp0_pdf_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzp0_pdf_hist("dalitzp0_pdf_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzp0_pdf_hist.SetStats(false); - TH2F dalitzm0_dat_hist("dalitzm0_dat_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzm0_dat_hist("dalitzm0_dat_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzm0_dat_hist.SetStats(false); dalitzm0_dat_hist.GetXaxis()->SetTitle("m^{2}(#pi^{-} #pi^{0}) [GeV]"); dalitzm0_dat_hist.GetYaxis()->SetTitle("m^{2}(#pi^{+} #pi^{-}) [GeV]"); - TH2F dalitzm0_pdf_hist("dalitzm0_pdf_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitzm0_pdf_hist("dalitzm0_pdf_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitzm0_pdf_hist.SetStats(false); - TH1F* bkg3_pdfs[6]; - TH1F* bkg3_data[6]; + TH1F *bkg3_pdfs[6]; + TH1F *bkg3_data[6]; double num_sigma_dat[6]; double num_sigma_pdf[6]; @@ -1974,7 +2021,6 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ bkg3_pdfs[i]->SetLineWidth(3); } - double totalPdf = 0; double totalDat = 0; @@ -2001,14 +2047,14 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ totalDat++; - int m23bin = (int) floor(currm23 / 0.5); + int m23bin = (int)floor(currm23 / 0.5); bkg3_data[m23bin]->Fill(currSigma); num_sigma_dat[m23bin]++; } double maxBinContent = 0; - int bestI = 0; - int bestJ = 0; + int bestI = 0; + int bestJ = 0; for(int i = 1; i <= m12->getNumBins(); ++i) { for(int j = 1; j <= m13->getNumBins(); ++j) { @@ -2018,26 +2064,26 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ continue; maxBinContent = curr; - bestI = i; - bestJ = j; + bestI = i; + bestJ = j; } } std::cout << "Max bin content: " << maxBinContent << " (" << bestI << ", " << bestJ << ")\n"; - bool dependsOnSigma = true; - std::vector obses = overallSignal->getObservables(); + bool dependsOnSigma = true; + std::vector obses = overallSignal->getObservables(); if(std::find(obses.begin(), obses.end(), sigma) == obses.end()) dependsOnSigma = false; - //overallSignal->setDebugMask(1); + // overallSignal->setDebugMask(1); wBkg1->setValue(0); const int division = 2; for(int half = 0; half < division; ++half) { - std::vector vars; + std::vector vars; vars.push_back(m12); vars.push_back(m13); vars.push_back(dtime); @@ -2051,17 +2097,21 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ int evtCounter = 0; for(int i = 0; i < m12->getNumBins(); ++i) { - m12->setValue( m12->getLowerLimit() + (m12->getUpperLimit() - m12->getLowerLimit())*(i + 0.5) / m12->getNumBins()); + m12->setValue(m12->getLowerLimit() + + (m12->getUpperLimit() - m12->getLowerLimit()) * (i + 0.5) / m12->getNumBins()); for(int j = 0; j < m13->getNumBins(); ++j) { - m13->setValue( m13->getLowerLimit() + (m13->getUpperLimit() - m13->getLowerLimit())*(j + 0.5) / m13->getNumBins()); + m13->setValue(m13->getLowerLimit() + + (m13->getUpperLimit() - m13->getLowerLimit()) * (j + 0.5) / m13->getNumBins()); if(!cpuDalitz(m12->getValue(), m13->getValue(), _mD0, piZeroMass, piPlusMass, piPlusMass)) continue; for(int l = half; l < dtime->getNumBins(); l += division) { - dtime->setValue(dtime->getLowerLimit() + (dtime->getUpperLimit() - dtime->getLowerLimit())*(l + 0.5) / dtime->getNumBins()); - eventNumber->setValue( evtCounter); + dtime->setValue(dtime->getLowerLimit() + + (dtime->getUpperLimit() - dtime->getLowerLimit()) * (l + 0.5) + / dtime->getNumBins()); + eventNumber->setValue(evtCounter); evtCounter++; currData.addEvent(); } @@ -2069,7 +2119,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ } for(int k = 0; k < sigma->getNumBins(); ++k) { - sigma->setValue( sigma->getLowerLimit() + (sigma->getUpperLimit() - sigma->getLowerLimit())*(k + 0.5) / sigma->getNumBins()); + sigma->setValue(sigma->getLowerLimit() + + (sigma->getUpperLimit() - sigma->getLowerLimit()) * (k + 0.5) / sigma->getNumBins()); if(0 == k % 10) std::cout << "sigma iteration " << half << " " << k << std::endl; @@ -2129,9 +2180,7 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ totalPdf += pdfValues[0][j]; if(std::isnan(pdfValues[0][j])) { - std::cout << "Major problem: " - << k << " " << j - << std::endl; + std::cout << "Major problem: " << k << " " << j << std::endl; assert(false); } @@ -2147,7 +2196,7 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ } } - //std::cout << "Final values: " << totalDat << " " << totalPdf << std::endl; + // std::cout << "Final values: " << totalDat << " " << totalPdf << std::endl; for(int i = 1; i <= dtime->getNumBins(); ++i) { dtime_pdf_hist.SetBinContent(i, dtime_pdf_hist.GetBinContent(i) * totalDat / totalPdf); @@ -2178,9 +2227,9 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ } } - ChisqInfo* chisq = getAdaptiveChisquare(&dalitzpm_dat_hist, &dalitzpm_pdf_hist); + ChisqInfo *chisq = getAdaptiveChisquare(&dalitzpm_dat_hist, &dalitzpm_pdf_hist); - std::cout << "Chisquare: " << chisq->chisq << " / " << chisq->dof << std::endl; + std::cout << "Chisquare: " << chisq->chisq << " / " << chisq->dof << std::endl; foodal->cd(); foodal->SetLogz(false); chisq->contribPlot->SetStats(false); @@ -2223,7 +2272,6 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ foo->SetLogy(false); } - m13_dat_hist.Draw("p"); m13_pdf_hist.Draw("lsame"); foo->SaveAs((plotdir + "/m13_fit.png").c_str()); @@ -2256,7 +2304,7 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ dalitzpm_dat_hist.Draw("colz"); for(int slice = 0; slice < 6; ++slice) { - double line_m12 = cpuGetM23(0, 0.5*(slice+1)); + double line_m12 = cpuGetM23(0, 0.5 * (slice + 1)); TLine sliceLine; sliceLine.SetLineWidth(2); sliceLine.DrawLine(0, line_m12, line_m12, 0); @@ -2309,11 +2357,14 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ pull_pm_hist.GetYaxis()->SetTitle("Bins / 0.1"); for(int i = 1; i <= m12->getNumBins(); ++i) { - double m12loedge = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i-1); - double m12hiedge = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i); + double m12loedge + = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i - 1); + double m12hiedge + = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i); for(int j = 1; j <= m13->getNumBins(); ++j) { - double m13loedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j-1); + double m13loedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j - 1); if(!cpuDalitz(m12loedge, m13loedge, _mD0, piZeroMass, piPlusMass, piPlusMass)) { dalitzpm_dat_hist.SetBinContent(i, j, 0); @@ -2325,7 +2376,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ continue; } - double m13hiedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); + double m13hiedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); if(!cpuDalitz(m12loedge, m13hiedge, _mD0, piZeroMass, piPlusMass, piPlusMass)) { dalitzpm_dat_hist.SetBinContent(i, j, 0); @@ -2346,7 +2398,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ } for(int j = 1; j <= m13->getNumBins(); ++j) { - double m23loedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j-1); + double m23loedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j - 1); // To get 12, 23 instead of 12, 13, just exchange 1 and 2. if(!cpuDalitz(m12loedge, m23loedge, _mD0, piPlusMass, piZeroMass, piPlusMass)) { @@ -2359,7 +2412,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ continue; } - double m23hiedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); + double m23hiedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); if(!cpuDalitz(m12loedge, m23hiedge, _mD0, piPlusMass, piZeroMass, piPlusMass)) { dalitzp0_dat_hist.SetBinContent(i, j, 0); @@ -2379,7 +2433,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ // NB, this exploits symmetry 12 and 13 by treating the outer loop as 13. for(int j = 1; j <= m13->getNumBins(); ++j) { - double m23loedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j-1); + double m23loedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j - 1); if(!cpuDalitz(m12loedge, m23loedge, _mD0, piPlusMass, piZeroMass, piPlusMass)) { dalitzm0_dat_hist.SetBinContent(i, j, 0); @@ -2391,7 +2446,8 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ continue; } - double m23hiedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); + double m23hiedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); if(!cpuDalitz(m12loedge, m23hiedge, _mD0, piPlusMass, piZeroMass, piPlusMass)) { dalitzm0_dat_hist.SetBinContent(i, j, 0); @@ -2426,7 +2482,7 @@ void makeDalitzPlots(GooPdf* overallSignal, std::string plotdir = "./plots_from_ foo->SaveAs((plotdir + "/pull_pm_hist.png").c_str()); } -GooPdf* make_m23_transform() { +GooPdf *make_m23_transform() { // This is complicated. I want to make a function such that the parameters // depend on position in the Dalitz plot. I want to use stripes of m23, because // that seems to be the real shape of the dependence, and I haven't got so much @@ -2435,10 +2491,10 @@ GooPdf* make_m23_transform() { // Finally I need a transform from bin number to function. Keep the tongue straight // in the mouth, now! - vector obses; - vector offsets; - vector coefficients; - vector components; + vector obses; + vector offsets; + vector coefficients; + vector components; vector limits; vector binSizes; vector numBins; @@ -2453,7 +2509,7 @@ GooPdf* make_m23_transform() { coefficients.push_back(constantMinusOne); offsets.push_back(constantZero); offsets.push_back(constantZero); - PolynomialPdf* m23_transform = new PolynomialPdf("m23_transform", obses, coefficients, offsets, 1); + PolynomialPdf *m23_transform = new PolynomialPdf("m23_transform", obses, coefficients, offsets, 1); // Now create the BinTransform which will make bins out of m23 values. obses.clear(); @@ -2462,15 +2518,15 @@ GooPdf* make_m23_transform() { limits.push_back(0); // Bins of m23 start at 0. binSizes.push_back(3.0 / m23Slices); numBins.push_back(m23Slices); - BinTransformPdf* m23_binMap = new BinTransformPdf("m23_binMap", obses, limits, binSizes, numBins); + BinTransformPdf *m23_binMap = new BinTransformPdf("m23_binMap", obses, limits, binSizes, numBins); // Now make a composite, so that the BinTransform takes the Polynomial result as input. - CompositePdf* m23_composite = new CompositePdf("m23_composite", m23_transform, m23_binMap); + CompositePdf *m23_composite = new CompositePdf("m23_composite", m23_transform, m23_binMap); return m23_composite; } -GooPdf* makeSigmaHists() { - GooPdf* m23_composite = make_m23_transform(); +GooPdf *makeSigmaHists() { + GooPdf *m23_composite = make_m23_transform(); std::vector> sigmaHists; for(int i = 0; i < m23Slices; ++i) @@ -2491,7 +2547,7 @@ GooPdf* makeSigmaHists() { } double dummy = 0; - double m23 = 0; + double m23 = 0; while(!reader.eof()) { reader >> dummy; @@ -2522,44 +2578,43 @@ GooPdf* makeSigmaHists() { if(dtime->getValue() > dtime->getUpperLimit()) continue; - int bin = (int) floor((m23 / 3.0) * m23Slices); + int bin = (int)floor((m23 / 3.0) * m23Slices); sigmaHists[bin]->addEvent(); } - vector jsuList; + vector jsuList; for(int i = 0; i < m23Slices; ++i) { sprintf(strbuffer, "signal_sigma_hist_%i", i); - SmoothHistogramPdf* hist = new SmoothHistogramPdf(strbuffer, sigmaHists[i].get(), constantZero); + SmoothHistogramPdf *hist = new SmoothHistogramPdf(strbuffer, sigmaHists[i].get(), constantZero); jsuList.push_back(hist); } return new MappedPdf("signalSigmaHist", m23_composite, jsuList); } -GooPdf* makeBkg_sigma_strips(int bkgnum) { - GooPdf* m23_composite = make_m23_transform(); +GooPdf *makeBkg_sigma_strips(int bkgnum) { + GooPdf *m23_composite = make_m23_transform(); - vector jsuList; - vector convList; + vector jsuList; + vector convList; bool useShare = false; for(int i = 0; i < m23Slices; ++i) { sprintf(strbuffer, "bkg%i_sigma_slice%i_expalpha", bkgnum, i); - Variable* exp_alpha = new Variable(strbuffer, 7.50, 0.10, 0, 10.00); + Variable *exp_alpha = new Variable(strbuffer, 7.50, 0.10, 0, 10.00); sprintf(strbuffer, "bkg%i_sigma_slice%i_gauss_meana", bkgnum, i); - Variable* g_meana = new Variable(strbuffer, 0.20, 0.01, 0.00, 0.80); + Variable *g_meana = new Variable(strbuffer, 0.20, 0.01, 0.00, 0.80); sprintf(strbuffer, "bkg%i_sigma_slice%i_gauss_sigma", bkgnum, i); - Variable* g_sigma = new Variable(strbuffer, 0.03, 0.01, 0.01, 0.20); + Variable *g_sigma = new Variable(strbuffer, 0.03, 0.01, 0.01, 0.20); sprintf(strbuffer, "bkg%i_sigma_slice%i_conv", bkgnum, i); - ExpGausPdf* expfunc = new ExpGausPdf(strbuffer, sigma, g_meana, g_sigma, exp_alpha); + ExpGausPdf *expfunc = new ExpGausPdf(strbuffer, sigma, g_meana, g_sigma, exp_alpha); jsuList.push_back(expfunc); } - if(useShare) { - for(vector::iterator conv = convList.begin(); conv != convList.end(); ++conv) { + for(vector::iterator conv = convList.begin(); conv != convList.end(); ++conv) { (*conv)->registerOthers(convList); } } @@ -2569,8 +2624,14 @@ GooPdf* makeBkg_sigma_strips(int bkgnum) { } void createWeightHistogram() { - weightHistogram = new TH2F("weightHistogram", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + weightHistogram = new TH2F("weightHistogram", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); weightHistogram->SetStats(false); double step12 = (m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins(); double step13 = (m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins(); @@ -2578,12 +2639,14 @@ void createWeightHistogram() { for(int i = 1; i <= m12->getNumBins(); ++i) { for(int j = 1; j < m13->getNumBins(); ++j) { double maxCount = 0; - double count = 0; - - for(double currM12 = m12->getLowerLimit() + step12*(i-1) + 0.05*step12; currM12 < m12->getLowerLimit() + step12*i; - currM12 += 0.1*step12) { - for(double currM13 = m13->getLowerLimit() + step13*(j-1) + 0.05*step13; currM13 < m13->getLowerLimit() + step13*j; - currM13 += 0.1*step13) { + double count = 0; + + for(double currM12 = m12->getLowerLimit() + step12 * (i - 1) + 0.05 * step12; + currM12 < m12->getLowerLimit() + step12 * i; + currM12 += 0.1 * step12) { + for(double currM13 = m13->getLowerLimit() + step13 * (j - 1) + 0.05 * step13; + currM13 < m13->getLowerLimit() + step13 * j; + currM13 += 0.1 * step13) { maxCount++; if(!cpuDalitz(currM12, currM13, _mD0, piZeroMass, piPlusMass, piPlusMass)) @@ -2601,15 +2664,18 @@ void createWeightHistogram() { } } - underlyingBins = new TH2F("underlyingBins", "", - m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), - m13->getNumBins(), m13->getLowerLimit(), m13->getUpperLimit()); + underlyingBins = new TH2F("underlyingBins", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); underlyingBins->SetStats(false); - - } -GooPdf* makeOverallSignal() { +GooPdf *makeOverallSignal() { makeKzeroVeto(); int oldBins1 = m12->getNumBins(); @@ -2617,7 +2683,7 @@ GooPdf* makeOverallSignal() { // Too fine a binning here leads to bad results due to fluctuations. m12->setNumBins(120); m13->setNumBins(120); - vector lvars; + vector lvars; lvars.push_back(m12); lvars.push_back(m13); binEffData = new BinnedDataSet(lvars); @@ -2636,7 +2702,7 @@ GooPdf* makeOverallSignal() { foo->cd(); } - GooPdf* eff = 0; + GooPdf *eff = 0; // Polynomial version if(polyEff) @@ -2646,7 +2712,7 @@ GooPdf* makeOverallSignal() { eff = makeEfficiencyPdf(); eff->setData(effdata); - + if(minuit1) { GooFit::FitManagerMinuit1 effpdf(eff); effpdf.fit(); @@ -2667,24 +2733,24 @@ GooPdf* makeOverallSignal() { comps.clear(); comps.push_back(eff); comps.push_back(kzero_veto); - ProdPdf* effWithVeto = new ProdPdf("effWithVeto", comps); + ProdPdf *effWithVeto = new ProdPdf("effWithVeto", comps); std::cout << "Creating signal PDF\n"; signalDalitz = makeSignalPdf(0, effWithVeto); std::cout << "Creating sigma PDF\n"; - //sig0_jsugg = makeSigmaMap(); - //sig0_jsugg = make1BinSigmaMap(); - //sig0_jsugg = make4BinSigmaMap(); - //sig0_jsugg = makeMikhailJSU_gg(); + // sig0_jsugg = makeSigmaMap(); + // sig0_jsugg = make1BinSigmaMap(); + // sig0_jsugg = make4BinSigmaMap(); + // sig0_jsugg = makeMikhailJSU_gg(); if(useHistogramSigma) sig0_jsugg = makeSigmaHists(); else sig0_jsugg = makeBkg_sigma_strips(0); sig0_jsugg->addSpecialMask(PdfBase::ForceSeparateNorm); - //sig0_jsugg = makeSignalJSU_gg(-1, false); + // sig0_jsugg = makeSignalJSU_gg(-1, false); /* sig0_jsugg->setData(data); @@ -2704,7 +2770,7 @@ GooPdf* makeOverallSignal() { comps.push_back(signalDalitz); comps.push_back(sig0_jsugg); std::cout << "Creating overall PDF\n"; - ProdPdf* overallSignal = new ProdPdf("overallSignal", comps); + ProdPdf *overallSignal = new ProdPdf("overallSignal", comps); return overallSignal; } @@ -2713,12 +2779,12 @@ int runTruthMCFit(std::string fname, bool noPlots = true) { std::cout << "Loading MC data from " << fname << std::endl; loadDataFile(fname); - GooPdf* overallSignal = makeOverallSignal(); + GooPdf *overallSignal = makeOverallSignal(); signalDalitz->setDataSize(data->getNumEvents()); // Default 5 is ok here, no event weighting overallSignal->setData(data); - //overallSignal->setDebugMask(1); - + // overallSignal->setDebugMask(1); + int retval; if(minuit1) { GooFit::FitManagerMinuit1 datapdf(overallSignal); @@ -2730,12 +2796,12 @@ int runTruthMCFit(std::string fname, bool noPlots = true) { retval = datapdf; } - //overallSignal->setDebugMask(0); + // overallSignal->setDebugMask(0); std::cout << "Fit results: \n" << "tau : " << ptr_to_dtau->getValue() << " $\\pm$ " << ptr_to_dtau->getError() << "\n" - << "xmixing: (" << 100*ptr_to_xmix->getValue() << " $\\pm$ " << 100*ptr_to_xmix->getError() << ")%\n" - << "ymixing: (" << 100*ptr_to_ymix->getValue() << " $\\pm$ " << 100*ptr_to_ymix->getError() << ")%\n"; + << "xmixing: (" << 100 * ptr_to_xmix->getValue() << " $\\pm$ " << 100 * ptr_to_xmix->getError() << ")%\n" + << "ymixing: (" << 100 * ptr_to_ymix->getValue() << " $\\pm$ " << 100 * ptr_to_ymix->getError() << ")%\n"; if(noPlots) return retval; @@ -2753,11 +2819,10 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { loadDataFile(fname); TRandom donram(42); - std::vector vars = data->getVariables(); - UnbinnedDataSet* smearedData = new UnbinnedDataSet(vars); + std::vector vars = data->getVariables(); + UnbinnedDataSet *smearedData = new UnbinnedDataSet(vars); if(0 != genResolutions) { - int numEvents = data->getNumEvents(); for(int i = 0; i < numEvents; ++i) { @@ -2774,7 +2839,8 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { smear2 = donram.Gaus(0, dplotres); } - //if (cpuDalitz(m12->getValue() + smear1, m13->getValue() + smear2, _mD0, piZeroMass, piPlusMass, piPlusMass)) { + // if (cpuDalitz(m12->getValue() + smear1, m13->getValue() + smear2, _mD0, piZeroMass, piPlusMass, + // piPlusMass)) { m12->setValue(m12->getValue() + smear1); m13->setValue(m13->getValue() + smear2); @@ -2785,8 +2851,8 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { smearedData->addEvent(); } - //delete data; - //data = smearedData; + // delete data; + // data = smearedData; } else smearedData = data; @@ -2796,8 +2862,10 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { lvars.push_back(m13); binEffData = new BinnedDataSet(lvars); - TH2F genEff("genEff", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), m13->getLowerLimit(), m13->getUpperLimit()); - TH2F resEff("resEff", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), m13->getLowerLimit(), m13->getUpperLimit()); + TH2F genEff("genEff", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), + m13->getLowerLimit(), m13->getUpperLimit()); + TH2F resEff("resEff", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), + m13->getLowerLimit(), m13->getUpperLimit()); double xstep = (m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins(); double ystep = (m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins(); @@ -2864,29 +2932,28 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { weightHistogram->Draw("colz"); foodal->SaveAs("./plots_from_mixfit/efficiency_weights.png"); - vector lvars; + vector lvars; lvars.push_back(m12); lvars.push_back(m13); binEffData = new BinnedDataSet(lvars); - fname = app_ptr->get_filename("dataFiles/efficiency_gen.txt", "examples/pipipi0DPFit"); + fname = app_ptr->get_filename("dataFiles/efficiency_gen.txt", "examples/pipipi0DPFit"); loadDataFile(fname, &effdata, 1); - GooPdf* eff = makeEfficiencyPdf(); + GooPdf *eff = makeEfficiencyPdf(); m12->setNumBins(oldBins1); m13->setNumBins(oldBins2); - //eff->setData(effdata); - //FitManager effpdf(eff); - //effpdf.fit(); - //eff->setParameterConstantness(true); - //binEffData = 0; - //delete effdata; effdata = 0; + // eff->setData(effdata); + // FitManager effpdf(eff); + // effpdf.fit(); + // eff->setParameterConstantness(true); + // binEffData = 0; + // delete effdata; effdata = 0; - TruthResolution* res = new TruthResolution(); - signalDalitz = makeSignalPdf(res, eff); + TruthResolution *res = new TruthResolution(); + signalDalitz = makeSignalPdf(res, eff); signalDalitz->setDataSize(smearedData->getNumEvents()); // Default 5 is ok here, no event weighting signalDalitz->setData(smearedData); - /* std::vector > pdfValues1; signalDalitz->getCompProbsAtDataPoints(pdfValues1); @@ -2904,10 +2971,12 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { data->loadEvent(i); if ((100 > i) || (fabs(pdfValues1[0][i] - pdfValues2[0][i]) > 0.5)) { double eff1 = binEffData->getBinContent(binEffData->getBinNumber()); - std::cout << i << ": " << m12->getValue() << " " << m13->getValue() << " -> " << pdfValues1[0][i] << " " << eff1 << " " << binEffData->getBinNumber(); + std::cout << i << ": " << m12->getValue() << " " << m13->getValue() << " -> " << pdfValues1[0][i] << " " << eff1 + << " " << binEffData->getBinNumber(); smearedData->loadEvent(i); eff1 = binEffData->getBinContent(binEffData->getBinNumber()); - std::cout << " | " << m12->getValue() << " " << m13->getValue() << " -> " << pdfValues2[0][i] << " " << eff1 << " " << binEffData->getBinNumber(); + std::cout << " | " << m12->getValue() << " " << m13->getValue() << " -> " << pdfValues2[0][i] << " " << eff1 + << " " << binEffData->getBinNumber(); std::cout << std::endl; } } @@ -2929,12 +2998,12 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { std::cout << "Fit results: \n" << "tau : " << ptr_to_dtau->getValue() << " $\\pm$ " << ptr_to_dtau->getError() << "\n" - << "xmixing: (" << 100*ptr_to_xmix->getValue() << " $\\pm$ " << 100*ptr_to_xmix->getError() << ")%\n" - << "ymixing: (" << 100*ptr_to_ymix->getValue() << " $\\pm$ " << 100*ptr_to_ymix->getError() << ")%\n"; + << "xmixing: (" << 100 * ptr_to_xmix->getValue() << " $\\pm$ " << 100 * ptr_to_xmix->getError() << ")%\n" + << "ymixing: (" << 100 * ptr_to_ymix->getValue() << " $\\pm$ " << 100 * ptr_to_ymix->getError() << ")%\n"; // All this relies on exact formatting of the input data files; it's fragile. - double inputx = 1; - double inputy = 1; + double inputx = 1; + double inputy = 1; std::string::size_type pos = fname.find("mm"); if(pos != std::string::npos) @@ -2960,41 +3029,42 @@ int runGeneratedMCFit(std::string fname, int genResolutions, double dplotres) { sprintf(strbuffer, "result_%s_%f", ident.c_str(), dplotres); ofstream writer; writer.open(strbuffer); - writer << inputx << " " << 100*ptr_to_xmix->getValue() << " " << 100*ptr_to_xmix->getError() << " " - << inputy << " " << 100*ptr_to_ymix->getValue() << " " << 100*ptr_to_ymix->getError() << std::endl; + writer << inputx << " " << 100 * ptr_to_xmix->getValue() << " " << 100 * ptr_to_xmix->getError() << " " << inputy + << " " << 100 * ptr_to_ymix->getValue() << " " << 100 * ptr_to_ymix->getError() << std::endl; writer.close(); return retval; - //makeDalitzPlots(signalDalitz, "plots_from_mixfit/generated/"); + // makeDalitzPlots(signalDalitz, "plots_from_mixfit/generated/"); } -GooPdf* makeBkg2_sigma() { - //Variable* bkg2_sigma_js_meana = new Variable("bkg2_sigma_js_meana", 0.01, 0.01, -0.30, 0.30); - //Variable* bkg2_sigma_js_sigma = new Variable("bkg2_sigma_js_sigma", 0.09, 0.01, 0, 0.4); - //Variable* bkg2_sigma_js_gamma = new Variable("bkg2_sigma_js_gamma",-5.00, 0.10, -30, 0); - //Variable* bkg2_sigma_js_delta = new Variable("bkg2_sigma_js_delta", 1.49, 0.01, 0.50, 5.00); - //Variable* bkg2_sigma_frac_jsu = new Variable("bkg2_sigma_frac_jsu", 0.85, 0.01, 0.01, 1.00); - //Variable* bkg2_sigma_frac_ga1 = new Variable("bkg2_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); - - Variable* bkg2_sigma_num_jsu = new Variable("bkg2_sigma_num_jsu", 9100, 200, 1000, 15000); - Variable* bkg2_sigma_num_ga1 = new Variable("bkg2_sigma_num_ga1", 2400, 200, 500, 7000); - Variable* bkg2_sigma_num_ga2 = new Variable("bkg2_sigma_num_ga2", 2900, 200, 500, 7000); - - Variable* bkg2_sigma_g1_meana = new Variable("bkg2_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); - Variable* bkg2_sigma_g1_sigma = new Variable("bkg2_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55); - Variable* bkg2_sigma_g2_meana = new Variable("bkg2_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50); - Variable* bkg2_sigma_g2_sigma = new Variable("bkg2_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75); - //JohnsonSUPdf* bkg2_sigma_js = new JohnsonSUPdf("bkg2_sigma_js", sigma, bkg2_sigma_js_meana, bkg2_sigma_js_sigma, bkg2_sigma_js_gamma, bkg2_sigma_js_delta); - - Variable* bkg2_sigma_js_meana = new Variable("bkg2_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); - Variable* bkg2_sigma_js_sigma = new Variable("bkg2_sigma_js_sigma", 0.09, 0.01, 0, 0.4); - Variable* bkg2_sigma_js_gamma = new Variable("bkg2_sigma_js_gamma", 2.00, 0.10, 0, 10); - Variable* bkg2_sigma_js_delta = new Variable("bkg2_sigma_js_delta", 2); - CrystalBallPdf* bkg2_sigma_js = new CrystalBallPdf("bkg2_sigma_js", sigma, bkg2_sigma_js_meana, bkg2_sigma_js_sigma, - bkg2_sigma_js_gamma, bkg2_sigma_js_delta); - - GaussianPdf* bkg2_sigma_g1 = new GaussianPdf("bkg2_sigma_g1", sigma, bkg2_sigma_g1_meana, bkg2_sigma_g1_sigma); - GaussianPdf* bkg2_sigma_g2 = new GaussianPdf("bkg2_sigma_g2", sigma, bkg2_sigma_g2_meana, bkg2_sigma_g2_sigma); +GooPdf *makeBkg2_sigma() { + // Variable* bkg2_sigma_js_meana = new Variable("bkg2_sigma_js_meana", 0.01, 0.01, -0.30, 0.30); + // Variable* bkg2_sigma_js_sigma = new Variable("bkg2_sigma_js_sigma", 0.09, 0.01, 0, 0.4); + // Variable* bkg2_sigma_js_gamma = new Variable("bkg2_sigma_js_gamma",-5.00, 0.10, -30, 0); + // Variable* bkg2_sigma_js_delta = new Variable("bkg2_sigma_js_delta", 1.49, 0.01, 0.50, 5.00); + // Variable* bkg2_sigma_frac_jsu = new Variable("bkg2_sigma_frac_jsu", 0.85, 0.01, 0.01, 1.00); + // Variable* bkg2_sigma_frac_ga1 = new Variable("bkg2_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); + + Variable *bkg2_sigma_num_jsu = new Variable("bkg2_sigma_num_jsu", 9100, 200, 1000, 15000); + Variable *bkg2_sigma_num_ga1 = new Variable("bkg2_sigma_num_ga1", 2400, 200, 500, 7000); + Variable *bkg2_sigma_num_ga2 = new Variable("bkg2_sigma_num_ga2", 2900, 200, 500, 7000); + + Variable *bkg2_sigma_g1_meana = new Variable("bkg2_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); + Variable *bkg2_sigma_g1_sigma = new Variable("bkg2_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55); + Variable *bkg2_sigma_g2_meana = new Variable("bkg2_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50); + Variable *bkg2_sigma_g2_sigma = new Variable("bkg2_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75); + // JohnsonSUPdf* bkg2_sigma_js = new JohnsonSUPdf("bkg2_sigma_js", sigma, bkg2_sigma_js_meana, bkg2_sigma_js_sigma, + // bkg2_sigma_js_gamma, bkg2_sigma_js_delta); + + Variable *bkg2_sigma_js_meana = new Variable("bkg2_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); + Variable *bkg2_sigma_js_sigma = new Variable("bkg2_sigma_js_sigma", 0.09, 0.01, 0, 0.4); + Variable *bkg2_sigma_js_gamma = new Variable("bkg2_sigma_js_gamma", 2.00, 0.10, 0, 10); + Variable *bkg2_sigma_js_delta = new Variable("bkg2_sigma_js_delta", 2); + CrystalBallPdf *bkg2_sigma_js = new CrystalBallPdf( + "bkg2_sigma_js", sigma, bkg2_sigma_js_meana, bkg2_sigma_js_sigma, bkg2_sigma_js_gamma, bkg2_sigma_js_delta); + + GaussianPdf *bkg2_sigma_g1 = new GaussianPdf("bkg2_sigma_g1", sigma, bkg2_sigma_g1_meana, bkg2_sigma_g1_sigma); + GaussianPdf *bkg2_sigma_g2 = new GaussianPdf("bkg2_sigma_g2", sigma, bkg2_sigma_g2_meana, bkg2_sigma_g2_sigma); weights.clear(); weights.push_back(bkg2_sigma_num_jsu); @@ -3005,38 +3075,39 @@ GooPdf* makeBkg2_sigma() { comps.push_back(bkg2_sigma_g1); comps.push_back(bkg2_sigma_g2); - GooPdf* ret = new AddPdf("bkg2_jsugg", weights, comps); + GooPdf *ret = new AddPdf("bkg2_jsugg", weights, comps); return ret; - //return bkg2_sigma_js; + // return bkg2_sigma_js; } -GooPdf* makeBkg4_sigma() { - //Variable* bkg4_sigma_js_meana = new Variable("bkg4_sigma_js_meana", 0.01, 0.01, -0.30, 0.30); - //Variable* bkg4_sigma_js_sigma = new Variable("bkg4_sigma_js_sigma", 0.09, 0.01, 0, 0.4); - //Variable* bkg4_sigma_js_gamma = new Variable("bkg4_sigma_js_gamma",-5.00, 0.10, -30, 0); - //Variable* bkg4_sigma_js_delta = new Variable("bkg4_sigma_js_delta", 1.49, 0.01, 0.50, 5.00); - //Variable* bkg4_sigma_frac_jsu = new Variable("bkg4_sigma_frac_jsu", 0.85, 0.01, 0.01, 1.00); - //Variable* bkg4_sigma_frac_ga1 = new Variable("bkg4_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); - - Variable* bkg4_sigma_num_jsu = new Variable("bkg4_sigma_num_jsu", 9100, 200, 1000, 15000); - Variable* bkg4_sigma_num_ga1 = new Variable("bkg4_sigma_num_ga1", 2400, 200, 500, 7000); - Variable* bkg4_sigma_num_ga2 = new Variable("bkg4_sigma_num_ga2", 2900, 200, 500, 7000); - - Variable* bkg4_sigma_g1_meana = new Variable("bkg4_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); - Variable* bkg4_sigma_g1_sigma = new Variable("bkg4_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55); - Variable* bkg4_sigma_g2_meana = new Variable("bkg4_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50); - Variable* bkg4_sigma_g2_sigma = new Variable("bkg4_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75); - //JohnsonSUPdf* bkg4_sigma_js = new JohnsonSUPdf("bkg4_sigma_js", sigma, bkg4_sigma_js_meana, bkg4_sigma_js_sigma, bkg4_sigma_js_gamma, bkg4_sigma_js_delta); - - Variable* bkg4_sigma_js_meana = new Variable("bkg4_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); - Variable* bkg4_sigma_js_sigma = new Variable("bkg4_sigma_js_sigma", 0.09, 0.01, 0, 0.4); - Variable* bkg4_sigma_js_gamma = new Variable("bkg4_sigma_js_gamma", 2.00, 0.10, 0, 10); - Variable* bkg4_sigma_js_delta = new Variable("bkg4_sigma_js_delta", 2); - CrystalBallPdf* bkg4_sigma_js = new CrystalBallPdf("bkg4_sigma_js", sigma, bkg4_sigma_js_meana, bkg4_sigma_js_sigma, - bkg4_sigma_js_gamma, bkg4_sigma_js_delta); - - GaussianPdf* bkg4_sigma_g1 = new GaussianPdf("bkg4_sigma_g1", sigma, bkg4_sigma_g1_meana, bkg4_sigma_g1_sigma); - GaussianPdf* bkg4_sigma_g2 = new GaussianPdf("bkg4_sigma_g2", sigma, bkg4_sigma_g2_meana, bkg4_sigma_g2_sigma); +GooPdf *makeBkg4_sigma() { + // Variable* bkg4_sigma_js_meana = new Variable("bkg4_sigma_js_meana", 0.01, 0.01, -0.30, 0.30); + // Variable* bkg4_sigma_js_sigma = new Variable("bkg4_sigma_js_sigma", 0.09, 0.01, 0, 0.4); + // Variable* bkg4_sigma_js_gamma = new Variable("bkg4_sigma_js_gamma",-5.00, 0.10, -30, 0); + // Variable* bkg4_sigma_js_delta = new Variable("bkg4_sigma_js_delta", 1.49, 0.01, 0.50, 5.00); + // Variable* bkg4_sigma_frac_jsu = new Variable("bkg4_sigma_frac_jsu", 0.85, 0.01, 0.01, 1.00); + // Variable* bkg4_sigma_frac_ga1 = new Variable("bkg4_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); + + Variable *bkg4_sigma_num_jsu = new Variable("bkg4_sigma_num_jsu", 9100, 200, 1000, 15000); + Variable *bkg4_sigma_num_ga1 = new Variable("bkg4_sigma_num_ga1", 2400, 200, 500, 7000); + Variable *bkg4_sigma_num_ga2 = new Variable("bkg4_sigma_num_ga2", 2900, 200, 500, 7000); + + Variable *bkg4_sigma_g1_meana = new Variable("bkg4_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); + Variable *bkg4_sigma_g1_sigma = new Variable("bkg4_sigma_g1_sigma", 0.30, 0.01, 0.05, 0.55); + Variable *bkg4_sigma_g2_meana = new Variable("bkg4_sigma_g2_meana", 0.80, 0.01, 0.01, 1.50); + Variable *bkg4_sigma_g2_sigma = new Variable("bkg4_sigma_g2_sigma", 0.90, 0.01, 0.01, 2.75); + // JohnsonSUPdf* bkg4_sigma_js = new JohnsonSUPdf("bkg4_sigma_js", sigma, bkg4_sigma_js_meana, bkg4_sigma_js_sigma, + // bkg4_sigma_js_gamma, bkg4_sigma_js_delta); + + Variable *bkg4_sigma_js_meana = new Variable("bkg4_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); + Variable *bkg4_sigma_js_sigma = new Variable("bkg4_sigma_js_sigma", 0.09, 0.01, 0, 0.4); + Variable *bkg4_sigma_js_gamma = new Variable("bkg4_sigma_js_gamma", 2.00, 0.10, 0, 10); + Variable *bkg4_sigma_js_delta = new Variable("bkg4_sigma_js_delta", 2); + CrystalBallPdf *bkg4_sigma_js = new CrystalBallPdf( + "bkg4_sigma_js", sigma, bkg4_sigma_js_meana, bkg4_sigma_js_sigma, bkg4_sigma_js_gamma, bkg4_sigma_js_delta); + + GaussianPdf *bkg4_sigma_g1 = new GaussianPdf("bkg4_sigma_g1", sigma, bkg4_sigma_g1_meana, bkg4_sigma_g1_sigma); + GaussianPdf *bkg4_sigma_g2 = new GaussianPdf("bkg4_sigma_g2", sigma, bkg4_sigma_g2_meana, bkg4_sigma_g2_sigma); weights.clear(); weights.push_back(bkg4_sigma_num_jsu); @@ -3047,78 +3118,81 @@ GooPdf* makeBkg4_sigma() { comps.push_back(bkg4_sigma_g1); comps.push_back(bkg4_sigma_g2); - GooPdf* ret = new AddPdf("bkg4_jsugg", weights, comps); + GooPdf *ret = new AddPdf("bkg4_jsugg", weights, comps); return ret; } - -GooPdf* makeBkg3_sigma() { - //Variable* bkg3_sigma_js_meana = new Variable("bkg3_sigma_js_meana", 0.05, 0.01, -0.30, 0.30); - //Variable* bkg3_sigma_js_sigma = new Variable("bkg3_sigma_js_sigma", 0.013, 0.01, 0, 0.2); - //Variable* bkg3_sigma_js_gamma = new Variable("bkg3_sigma_js_gamma",-6.00, 1.00, -30, 0); - //Variable* bkg3_sigma_js_delta = new Variable("bkg3_sigma_js_delta", 1.99, 0.10, 0.50, 5.00); - Variable* bkg3_sigma_frac_jsu = new Variable("bkg3_sigma_frac_jsu", 0.50, 0.01, 0.01, 1.00); - Variable* bkg3_sigma_frac_ga1 = new Variable("bkg3_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); - - //Variable* bkg3_sigma_num_jsu = new Variable("bkg3_sigma_num_jsu", 11000, 200, 1000, 35000); - //Variable* bkg3_sigma_num_ga1 = new Variable("bkg3_sigma_num_ga1", 9400, 200, 500, 10000); - //Variable* bkg3_sigma_num_ga2 = new Variable("bkg3_sigma_num_ga2", 3900, 200, 500, 17000); - //Variable* bkg3_sigma_num_ga3 = new Variable("bkg3_sigma_num_ga3", 3900, 200, 500, 7000); - - Variable* bkg3_sigma_g1_meana = new Variable("bkg3_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); - Variable* bkg3_sigma_g1_sigma = new Variable("bkg3_sigma_g1_sigma", 0.10, 0.01, 0.01, 0.55); - Variable* bkg3_sigma_g2_meana = new Variable("bkg3_sigma_g2_meana", 0.20, 0.01, 0.01, 1.50); - Variable* bkg3_sigma_g2_sigma = new Variable("bkg3_sigma_g2_sigma", 0.10, 0.01, 0.001, 0.15); - Variable* bkg3_sigma_g2_gamma = new Variable("bkg3_sigma_g2_gamma", -2.00, 1.00, -10, 10); - Variable* bkg3_sigma_g2_delta = new Variable("bkg3_sigma_g2_delta", 2, 0.10, 0.50, 5.00); - //Variable* bkg3_sigma_g3_meana = new Variable("bkg3_sigma_g3_meana", 0.20, 0.01, 0.01, 1.50); - //Variable* bkg3_sigma_g3_sigma = new Variable("bkg3_sigma_g3_sigma", 0.20, 0.01, 0.01, 0.75); - //Variable* bkg3_sigma_g2_width = new Variable("bkg3_sigma_g2_width", 0.10, 0.01, 0.01, 0.75); - //JohnsonSUPdf* bkg3_sigma_js = new JohnsonSUPdf("bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, bkg3_sigma_js_gamma, bkg3_sigma_js_delta); - - Variable* bkg3_sigma_js_meana = new Variable("bkg3_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); - Variable* bkg3_sigma_js_sigma = new Variable("bkg3_sigma_js_sigma", 0.09, 0.01, 0, 0.40); - Variable* bkg3_sigma_js_gamma = new Variable("bkg3_sigma_js_gamma", 2.00, 0.10, 0, 10); - Variable* bkg3_sigma_js_delta = new Variable("bkg3_sigma_js_delta", 2); - CrystalBallPdf* bkg3_sigma_js = new CrystalBallPdf("bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, - bkg3_sigma_js_gamma, bkg3_sigma_js_delta); - //JohnsonSUPdf* bkg3_sigma_js = new JohnsonSUPdf("bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, bkg3_sigma_js_gamma, bkg3_sigma_js_delta); - - GaussianPdf* bkg3_sigma_g1 = new GaussianPdf("bkg3_sigma_g1", sigma, bkg3_sigma_g1_meana, bkg3_sigma_g1_sigma); - //GaussianPdf* bkg3_sigma_g2 = new GaussianPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma); - //CrystalBallPdf* bkg3_sigma_g2 = new CrystalBallPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, bkg3_sigma_g2_gamma, bkg3_sigma_g2_delta); - JohnsonSUPdf* bkg3_sigma_g2 = new JohnsonSUPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, - bkg3_sigma_g2_gamma, bkg3_sigma_g2_delta); - //GaussianPdf* bkg3_sigma_g3 = new GaussianPdf("bkg3_sigma_g3", sigma, bkg3_sigma_g3_meana, bkg3_sigma_g3_sigma); - //VoigtianPdf* bkg3_sigma_g2 = new VoigtianPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, bkg3_sigma_g2_width); +GooPdf *makeBkg3_sigma() { + // Variable* bkg3_sigma_js_meana = new Variable("bkg3_sigma_js_meana", 0.05, 0.01, -0.30, 0.30); + // Variable* bkg3_sigma_js_sigma = new Variable("bkg3_sigma_js_sigma", 0.013, 0.01, 0, 0.2); + // Variable* bkg3_sigma_js_gamma = new Variable("bkg3_sigma_js_gamma",-6.00, 1.00, -30, 0); + // Variable* bkg3_sigma_js_delta = new Variable("bkg3_sigma_js_delta", 1.99, 0.10, 0.50, 5.00); + Variable *bkg3_sigma_frac_jsu = new Variable("bkg3_sigma_frac_jsu", 0.50, 0.01, 0.01, 1.00); + Variable *bkg3_sigma_frac_ga1 = new Variable("bkg3_sigma_frac_ga1", 0.04, 0.01, 0.01, 0.20); + + // Variable* bkg3_sigma_num_jsu = new Variable("bkg3_sigma_num_jsu", 11000, 200, 1000, 35000); + // Variable* bkg3_sigma_num_ga1 = new Variable("bkg3_sigma_num_ga1", 9400, 200, 500, 10000); + // Variable* bkg3_sigma_num_ga2 = new Variable("bkg3_sigma_num_ga2", 3900, 200, 500, 17000); + // Variable* bkg3_sigma_num_ga3 = new Variable("bkg3_sigma_num_ga3", 3900, 200, 500, 7000); + + Variable *bkg3_sigma_g1_meana = new Variable("bkg3_sigma_g1_meana", 0.35, 0.01, 0.10, 0.50); + Variable *bkg3_sigma_g1_sigma = new Variable("bkg3_sigma_g1_sigma", 0.10, 0.01, 0.01, 0.55); + Variable *bkg3_sigma_g2_meana = new Variable("bkg3_sigma_g2_meana", 0.20, 0.01, 0.01, 1.50); + Variable *bkg3_sigma_g2_sigma = new Variable("bkg3_sigma_g2_sigma", 0.10, 0.01, 0.001, 0.15); + Variable *bkg3_sigma_g2_gamma = new Variable("bkg3_sigma_g2_gamma", -2.00, 1.00, -10, 10); + Variable *bkg3_sigma_g2_delta = new Variable("bkg3_sigma_g2_delta", 2, 0.10, 0.50, 5.00); + // Variable* bkg3_sigma_g3_meana = new Variable("bkg3_sigma_g3_meana", 0.20, 0.01, 0.01, 1.50); + // Variable* bkg3_sigma_g3_sigma = new Variable("bkg3_sigma_g3_sigma", 0.20, 0.01, 0.01, 0.75); + // Variable* bkg3_sigma_g2_width = new Variable("bkg3_sigma_g2_width", 0.10, 0.01, 0.01, 0.75); + // JohnsonSUPdf* bkg3_sigma_js = new JohnsonSUPdf("bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, + // bkg3_sigma_js_gamma, bkg3_sigma_js_delta); + + Variable *bkg3_sigma_js_meana = new Variable("bkg3_sigma_js_meana", 0.35, 0.01, 0.00, 0.60); + Variable *bkg3_sigma_js_sigma = new Variable("bkg3_sigma_js_sigma", 0.09, 0.01, 0, 0.40); + Variable *bkg3_sigma_js_gamma = new Variable("bkg3_sigma_js_gamma", 2.00, 0.10, 0, 10); + Variable *bkg3_sigma_js_delta = new Variable("bkg3_sigma_js_delta", 2); + CrystalBallPdf *bkg3_sigma_js = new CrystalBallPdf( + "bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, bkg3_sigma_js_gamma, bkg3_sigma_js_delta); + // JohnsonSUPdf* bkg3_sigma_js = new JohnsonSUPdf("bkg3_sigma_js", sigma, bkg3_sigma_js_meana, bkg3_sigma_js_sigma, + // bkg3_sigma_js_gamma, bkg3_sigma_js_delta); + + GaussianPdf *bkg3_sigma_g1 = new GaussianPdf("bkg3_sigma_g1", sigma, bkg3_sigma_g1_meana, bkg3_sigma_g1_sigma); + // GaussianPdf* bkg3_sigma_g2 = new GaussianPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma); + // CrystalBallPdf* bkg3_sigma_g2 = new CrystalBallPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, + // bkg3_sigma_g2_sigma, bkg3_sigma_g2_gamma, bkg3_sigma_g2_delta); + JohnsonSUPdf *bkg3_sigma_g2 = new JohnsonSUPdf( + "bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, bkg3_sigma_g2_gamma, bkg3_sigma_g2_delta); + // GaussianPdf* bkg3_sigma_g3 = new GaussianPdf("bkg3_sigma_g3", sigma, bkg3_sigma_g3_meana, bkg3_sigma_g3_sigma); + // VoigtianPdf* bkg3_sigma_g2 = new VoigtianPdf("bkg3_sigma_g2", sigma, bkg3_sigma_g2_meana, bkg3_sigma_g2_sigma, + // bkg3_sigma_g2_width); weights.clear(); - //weights.push_back(bkg3_sigma_num_jsu); - //weights.push_back(bkg3_sigma_num_ga1); - //weights.push_back(bkg3_sigma_num_ga2); - //weights.push_back(bkg3_sigma_num_ga3); + // weights.push_back(bkg3_sigma_num_jsu); + // weights.push_back(bkg3_sigma_num_ga1); + // weights.push_back(bkg3_sigma_num_ga2); + // weights.push_back(bkg3_sigma_num_ga3); weights.push_back(bkg3_sigma_frac_jsu); weights.push_back(bkg3_sigma_frac_ga1); comps.clear(); comps.push_back(bkg3_sigma_js); comps.push_back(bkg3_sigma_g1); comps.push_back(bkg3_sigma_g2); - //comps.push_back(bkg3_sigma_g3); + // comps.push_back(bkg3_sigma_g3); - GooPdf* ret = new AddPdf("bkg3_jsugg", weights, comps); + GooPdf *ret = new AddPdf("bkg3_jsugg", weights, comps); return ret; } -GooPdf* makeGaussianTimePdf(int bkg) { +GooPdf *makeGaussianTimePdf(int bkg) { // Gaussians for decay time. - Variable* frac_ga2; - Variable* frac_ga3; - Variable* g1_meana; - Variable* g1_sigma; - Variable* g2_meana; - Variable* g2_sigma; - Variable* g3_meana; - Variable* g3_sigma; + Variable *frac_ga2; + Variable *frac_ga3; + Variable *g1_meana; + Variable *g1_sigma; + Variable *g2_meana; + Variable *g2_sigma; + Variable *g3_meana; + Variable *g3_sigma; std::string bkgname = ""; @@ -3132,7 +3206,7 @@ GooPdf* makeGaussianTimePdf(int bkg) { g2_sigma = new Variable("bkg4_g2_sigma", 0.63765, 0.01, 0.40, 0.80); g3_meana = new Variable("bkg4_g3_meana", 0.45817, 0.01, 0.20, 0.80); g3_sigma = new Variable("bkg4_g3_sigma", 1.52905, 0.01, 1.40, 1.80); - bkgname = "bkg4"; + bkgname = "bkg4"; break; case 3: @@ -3144,7 +3218,7 @@ GooPdf* makeGaussianTimePdf(int bkg) { g2_sigma = new Variable("bkg3_g2_sigma", 0.65443, 0.01, 0.10, 1.00); g3_meana = new Variable("bkg3_g3_meana", 0.83600, 0.01, 0.50, 1.00); g3_sigma = new Variable("bkg3_g3_sigma", 1.51839, 0.01, 0.10, 2.00); - bkgname = "bkg3"; + bkgname = "bkg3"; break; case 2: @@ -3157,13 +3231,13 @@ GooPdf* makeGaussianTimePdf(int bkg) { g2_sigma = new Variable("g2_sigma", 0.58651, 0.01, 0.5, 1.2); g3_meana = new Variable("g3_meana", 0.17451, 0.01, 0.1, 1.85); g3_sigma = new Variable("g3_sigma", 1.15125, 0.01, 0.5, 1.3); - bkgname = "bkg2"; + bkgname = "bkg2"; break; } - GaussianPdf* g1 = new GaussianPdf((bkgname + "_g1").c_str(), dtime, g1_meana, g1_sigma); - GaussianPdf* g2 = new GaussianPdf((bkgname + "_g2").c_str(), dtime, g2_meana, g2_sigma); - GaussianPdf* g3 = new GaussianPdf((bkgname + "_g3").c_str(), dtime, g3_meana, g3_sigma); + GaussianPdf *g1 = new GaussianPdf((bkgname + "_g1").c_str(), dtime, g1_meana, g1_sigma); + GaussianPdf *g2 = new GaussianPdf((bkgname + "_g2").c_str(), dtime, g2_meana, g2_sigma); + GaussianPdf *g3 = new GaussianPdf((bkgname + "_g3").c_str(), dtime, g3_meana, g3_sigma); weights.clear(); weights.push_back(frac_ga2); @@ -3178,11 +3252,11 @@ GooPdf* makeGaussianTimePdf(int bkg) { comps.push_back(g3); comps.push_back(g1); - AddPdf* bkg_dtime = new AddPdf((bkgname + "_dtime").c_str(), weights, comps); + AddPdf *bkg_dtime = new AddPdf((bkgname + "_dtime").c_str(), weights, comps); return bkg_dtime; } -GooPdf* makeExpGausTimePdf(int bkg) { +GooPdf *makeExpGausTimePdf(int bkg) { std::string bkgname = ""; switch(bkg) { @@ -3200,142 +3274,153 @@ GooPdf* makeExpGausTimePdf(int bkg) { break; } - Variable* g1_mean = new Variable((bkgname + "_dtime_gmean1"), 0, 0.01, -0.5, 0.5); - Variable* g1_sigm = new Variable((bkgname + "_dtime_gsigm1"), 0.2, 0.01, 0.01, 0.8); - Variable* e1_alph = new Variable((bkgname + "_dtime_alpha1"), 2.5, 0.01, 0.01, 7.5); + Variable *g1_mean = new Variable((bkgname + "_dtime_gmean1"), 0, 0.01, -0.5, 0.5); + Variable *g1_sigm = new Variable((bkgname + "_dtime_gsigm1"), 0.2, 0.01, 0.01, 0.8); + Variable *e1_alph = new Variable((bkgname + "_dtime_alpha1"), 2.5, 0.01, 0.01, 7.5); - Variable* g2_mean = new Variable((bkgname + "_dtime_gmean2"), -0.3, 0.01, -0.85, 0.85); - Variable* g2_sigm = new Variable((bkgname + "_dtime_gsigm2"), 0.2, 0.01, 0.01, 0.8); - Variable* e2_alph = new Variable((bkgname + "_dtime_alpha2"), 0.5, 0.01, 0.01, 10.0); + Variable *g2_mean = new Variable((bkgname + "_dtime_gmean2"), -0.3, 0.01, -0.85, 0.85); + Variable *g2_sigm = new Variable((bkgname + "_dtime_gsigm2"), 0.2, 0.01, 0.01, 0.8); + Variable *e2_alph = new Variable((bkgname + "_dtime_alpha2"), 0.5, 0.01, 0.01, 10.0); - ExpGausPdf* exp1 = new ExpGausPdf((bkgname + "_exp1"), dtime, g1_mean, g1_sigm, e1_alph); - ExpGausPdf* exp2 = new ExpGausPdf((bkgname + "_exp2"), dtime, g2_mean, g2_sigm, e2_alph); + ExpGausPdf *exp1 = new ExpGausPdf((bkgname + "_exp1"), dtime, g1_mean, g1_sigm, e1_alph); + ExpGausPdf *exp2 = new ExpGausPdf((bkgname + "_exp2"), dtime, g2_mean, g2_sigm, e2_alph); - Variable* frac1 = new Variable((bkgname + "_dtime_frac1"), 0.1, 0.01, 0, 0.8); + Variable *frac1 = new Variable((bkgname + "_dtime_frac1"), 0.1, 0.01, 0, 0.8); - GooPdf* ret = new AddPdf((bkgname + "_dtime"), frac1, exp1, exp2); + GooPdf *ret = new AddPdf((bkgname + "_dtime"), frac1, exp1, exp2); return ret; } - -GooPdf* makeBkg2DalitzPdf(bool fixem = true) { +GooPdf *makeBkg2DalitzPdf(bool fixem = true) { if(!kzero_veto) makeKzeroVeto(); - GooPdf* bkg2_dalitz = nullptr; + GooPdf *bkg2_dalitz = nullptr; if(Parameter == bkg2Model) { - comps.clear(); - vector offsets; - vector observables; - vector coefficients; + vector offsets; + vector observables; + vector coefficients; offsets.push_back(constantOne); offsets.push_back(constantOne); observables.push_back(m12); observables.push_back(m13); double weightOffset = 3; // Recurring factor 3 offsets division by total weight in AddPdf. - coefficients.push_back(new Variable("bkg2_x0y0", 1.0 * weightOffset)); - coefficients.push_back(new Variable("bkg2_x1y0", 0.13184 * weightOffset, 0.01, 0.01*weightOffset, 0.18*weightOffset)); - coefficients.push_back(new Variable("bkg2_x2y0", 0.02062 * weightOffset, 0.01, 0.00*weightOffset, 0.17*weightOffset)); - coefficients.push_back(new Variable("bkg2_x3y0", 0.04688 * weightOffset, 0.01, 0.00*weightOffset, 0.08*weightOffset)); - coefficients.push_back(new Variable("bkg2_x0y1", -0.02568 * weightOffset, 0.01, -0.15*weightOffset, 0.04*weightOffset)); - coefficients.push_back(new Variable("bkg2_x1y1", 0.06805 * weightOffset, 0.01, 0.02*weightOffset, 0.10*weightOffset)); - coefficients.push_back(new Variable("bkg2_x2y1", 0.38557 * weightOffset, 0.01, 0.30*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg2_x0y2", 0.11252 * weightOffset, 0.01, 0.05*weightOffset, 0.20*weightOffset)); - coefficients.push_back(new Variable("bkg2_x1y2", 0.24896 * weightOffset, 0.01, 0.20*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg2_x0y3", 0.05605 * weightOffset, 0.01, -0.05*weightOffset, 0.15*weightOffset)); - - PolynomialPdf* poly = new PolynomialPdf("bkg2Pdf", observables, coefficients, offsets, 3); - - Variable* bkg2_decZmin = new Variable("bkg2_decZmin", 3.30411); - Variable* bkg2_conZmin = new Variable("bkg2_conZmin", 0.29909); - TrigThresholdPdf* bkg2_loZ = new TrigThresholdPdf("bkg2_loZ", m12, m13, minDalitzZ, bkg2_decZmin, bkg2_conZmin, massSum, - false); - //bkg2_loZ->setDebugMask(1); + coefficients.push_back(new Variable("bkg2_x0y0", 1.0 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x1y0", 0.13184 * weightOffset, 0.01, 0.01 * weightOffset, 0.18 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x2y0", 0.02062 * weightOffset, 0.01, 0.00 * weightOffset, 0.17 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x3y0", 0.04688 * weightOffset, 0.01, 0.00 * weightOffset, 0.08 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x0y1", -0.02568 * weightOffset, 0.01, -0.15 * weightOffset, 0.04 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x1y1", 0.06805 * weightOffset, 0.01, 0.02 * weightOffset, 0.10 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x2y1", 0.38557 * weightOffset, 0.01, 0.30 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x0y2", 0.11252 * weightOffset, 0.01, 0.05 * weightOffset, 0.20 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x1y2", 0.24896 * weightOffset, 0.01, 0.20 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg2_x0y3", 0.05605 * weightOffset, 0.01, -0.05 * weightOffset, 0.15 * weightOffset)); + + PolynomialPdf *poly = new PolynomialPdf("bkg2Pdf", observables, coefficients, offsets, 3); + + Variable *bkg2_decZmin = new Variable("bkg2_decZmin", 3.30411); + Variable *bkg2_conZmin = new Variable("bkg2_conZmin", 0.29909); + TrigThresholdPdf *bkg2_loZ + = new TrigThresholdPdf("bkg2_loZ", m12, m13, minDalitzZ, bkg2_decZmin, bkg2_conZmin, massSum, false); + // bkg2_loZ->setDebugMask(1); comps.clear(); comps.push_back(poly); comps.push_back(bkg2_loZ); comps.push_back(kzero_veto); // Separate PDF to avoid triggering numerical normalisation over all four observables. - ProdPdf* poly_x_veto = new ProdPdf("poly_x_veto", comps); - //poly_x_veto->setDebugMask(1); + ProdPdf *poly_x_veto = new ProdPdf("poly_x_veto", comps); + // poly_x_veto->setDebugMask(1); // One omega->pipipi0 reflection. // Factor 3 in amplitudes is to offset division by total weight in AddPdf. - DecayInfo* special_rho_decay = new DecayInfo(); - special_rho_decay->motherMass = _mD0; - special_rho_decay->daug1Mass = piZeroMass; - special_rho_decay->daug2Mass = piPlusMass; - special_rho_decay->daug3Mass = piPlusMass; - special_rho_decay->meson_radius = 1.5; - - ResonancePdf* bkg2_rho_ref = new ResonancePdf("bkg2_rho_ref", - new Variable("bkg2_rho_ref_amp", 0.00896 * weightOffset, 0.001, 0, 0.015*weightOffset), - 0, - new Variable("bkg2_rho_ref_mass", 0.53172), - new Variable("bkg2_rho_ref_width", 0.06426), - PAIR_13); + DecayInfo *special_rho_decay = new DecayInfo(); + special_rho_decay->motherMass = _mD0; + special_rho_decay->daug1Mass = piZeroMass; + special_rho_decay->daug2Mass = piPlusMass; + special_rho_decay->daug3Mass = piPlusMass; + special_rho_decay->meson_radius = 1.5; + + ResonancePdf *bkg2_rho_ref + = new ResonancePdf("bkg2_rho_ref", + new Variable("bkg2_rho_ref_amp", 0.00896 * weightOffset, 0.001, 0, 0.015 * weightOffset), + 0, + new Variable("bkg2_rho_ref_mass", 0.53172), + new Variable("bkg2_rho_ref_width", 0.06426), + PAIR_13); special_rho_decay->resonances.push_back(bkg2_rho_ref); - Variable* bkg2_rho_poly_offset = new Variable("bkg2_rho_poly_offset", 1.64254); - Variable* bkg2_rho_poly_linear = new Variable("bkg2_rho_poly_linear", 0); - Variable* bkg2_rho_poly_second = new Variable("bkg2_rho_poly_second", -0.48166); + Variable *bkg2_rho_poly_offset = new Variable("bkg2_rho_poly_offset", 1.64254); + Variable *bkg2_rho_poly_linear = new Variable("bkg2_rho_poly_linear", 0); + Variable *bkg2_rho_poly_second = new Variable("bkg2_rho_poly_second", -0.48166); weights.clear(); weights.push_back(constantOne); weights.push_back(bkg2_rho_poly_linear); weights.push_back(bkg2_rho_poly_second); - PolynomialPdf* bkg2_rho_poly = new PolynomialPdf("bkg2_rho_poly", m12, weights, bkg2_rho_poly_offset); + PolynomialPdf *bkg2_rho_poly = new PolynomialPdf("bkg2_rho_poly", m12, weights, bkg2_rho_poly_offset); comps.clear(); comps.push_back(kzero_veto); comps.push_back(bkg2_rho_poly); comps.push_back(bkg2_loZ); - ProdPdf* bkg2_rho_mods = new ProdPdf("bkg2_rho_mods", comps); + ProdPdf *bkg2_rho_mods = new ProdPdf("bkg2_rho_mods", comps); incsum1 = new IncoherentSumPdf("incsum1", m12, m13, eventNumber, special_rho_decay, bkg2_rho_mods); // Three spin-0 rho resonances to be added incoherently. - DecayInfo* incoherent_rho0s = new DecayInfo(); - incoherent_rho0s->motherMass = _mD0; - incoherent_rho0s->daug1Mass = piZeroMass; - incoherent_rho0s->daug2Mass = piPlusMass; - incoherent_rho0s->daug3Mass = piPlusMass; - incoherent_rho0s->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. - - ResonancePdf* bkg2_incRho0 = new ResonancePdf("bkg2_incRho0", - new Variable("bkg2_incRho0_amp", 0.00304 * weightOffset, 0.001, 0.0, 0.006 * weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, // Incoherent rho has effective spin 0. - PAIR_23); + DecayInfo *incoherent_rho0s = new DecayInfo(); + incoherent_rho0s->motherMass = _mD0; + incoherent_rho0s->daug1Mass = piZeroMass; + incoherent_rho0s->daug2Mass = piPlusMass; + incoherent_rho0s->daug3Mass = piPlusMass; + incoherent_rho0s->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. + + ResonancePdf *bkg2_incRho0 = new ResonancePdf( + "bkg2_incRho0", + new Variable("bkg2_incRho0_amp", 0.00304 * weightOffset, 0.001, 0.0, 0.006 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, // Incoherent rho has effective spin 0. + PAIR_23); incoherent_rho0s->resonances.push_back(bkg2_incRho0); - ResonancePdf* bkg2_incRhoP = new ResonancePdf("bkg2_incRhoP", - new Variable("bkg2_incRhoP_amp", 0.00586 * weightOffset, 0.001, 0.0, 0.012*weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, - PAIR_12); + ResonancePdf *bkg2_incRhoP = new ResonancePdf( + "bkg2_incRhoP", + new Variable("bkg2_incRhoP_amp", 0.00586 * weightOffset, 0.001, 0.0, 0.012 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, + PAIR_12); incoherent_rho0s->resonances.push_back(bkg2_incRhoP); - ResonancePdf* bkg2_incRhoM = new ResonancePdf("bkg2_incRhoM", - new Variable("bkg2_incRhoM_amp", 0.00635 * weightOffset, 0.001, 0.0, 0.015*weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, - PAIR_13); + ResonancePdf *bkg2_incRhoM = new ResonancePdf( + "bkg2_incRhoM", + new Variable("bkg2_incRhoM_amp", 0.00635 * weightOffset, 0.001, 0.0, 0.015 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, + PAIR_13); incoherent_rho0s->resonances.push_back(bkg2_incRhoM); comps.clear(); comps.push_back(kzero_veto); comps.push_back(bkg2_loZ); - ProdPdf* bkg2_rho_mods2 = new ProdPdf("bkg2_rho_mods2", comps); + ProdPdf *bkg2_rho_mods2 = new ProdPdf("bkg2_rho_mods2", comps); incsum2 = new IncoherentSumPdf("incsum2", m12, m13, eventNumber, incoherent_rho0s, bkg2_rho_mods2); @@ -3350,7 +3435,7 @@ GooPdf* makeBkg2DalitzPdf(bool fixem = true) { bkg2_dalitz = new AddPdf("bkg2_dalitz", weights, comps); bkg2_dalitz->addSpecialMask(PdfBase::ForceCommonNorm); - //bkg2_dalitz->setDebugMask(1); + // bkg2_dalitz->setDebugMask(1); } else if(Histogram == bkg2Model) { bkg2_dalitz = makeBackgroundHistogram(2); @@ -3363,42 +3448,42 @@ GooPdf* makeBkg2DalitzPdf(bool fixem = true) { comps.push_back(makeBackgroundHistogram(101, fname)); fname = app_ptr->get_filename("dataFiles/sideband2.txt", "examples/pipipi0DPFit"); comps.push_back(makeBackgroundHistogram(102, fname)); - //comps.push_back(makeBackgroundHistogram(103, "./dataFiles/sideband3.txt")); - //comps.push_back(makeBackgroundHistogram(104, "./dataFiles/sideband4.txt")); + // comps.push_back(makeBackgroundHistogram(103, "./dataFiles/sideband3.txt")); + // comps.push_back(makeBackgroundHistogram(104, "./dataFiles/sideband4.txt")); weights.clear(); weights.push_back(new Variable("sband1Weight", 300000, 1000, 100, 750000)); weights.push_back(new Variable("sband2Weight", 100000, 1000, 100, 500000)); - //weights.push_back(new Variable("sband3Weight", 150000, 1000, 100, 500000)); - //weights.push_back(new Variable("sband4Weight", 50000, 1000, 100, 500000)); + // weights.push_back(new Variable("sband3Weight", 150000, 1000, 100, 500000)); + // weights.push_back(new Variable("sband4Weight", 50000, 1000, 100, 500000)); bkg2_dalitz = new AddPdf("bkg2_dalitz", weights, comps); } else { // This cannot possibly happen, and if it does something is wrong. Panic! assert(Sideband == bkg2Model); } - GooPdf* bkg2_dtime = nullptr; + GooPdf *bkg2_dtime = nullptr; if(gaussBkgTime) bkg2_dtime = makeGaussianTimePdf(2); else bkg2_dtime = makeExpGausTimePdf(2); - //bkg2_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. + // bkg2_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. // Separate sigma_t distribution - //bkg2_jsugg = makeBkg2_sigma(); + // bkg2_jsugg = makeBkg2_sigma(); bkg2_jsugg = makeBkg_sigma_strips(2); bkg2_jsugg->addSpecialMask(PdfBase::ForceSeparateNorm); // Finally create overall product. comps.clear(); - //poly->setDebugMask(1); - //bkg2_dalitz->setDebugMask(1); - //incsum2->setDebugMask(1); + // poly->setDebugMask(1); + // bkg2_dalitz->setDebugMask(1); + // incsum2->setDebugMask(1); comps.push_back(bkg2_dalitz); comps.push_back(bkg2_dtime); comps.push_back(bkg2_jsugg); - GooPdf* ret = new ProdPdf("bkg2_total", comps); + GooPdf *ret = new ProdPdf("bkg2_total", comps); if(fixem) ret->setParameterConstantness(true); @@ -3406,7 +3491,7 @@ GooPdf* makeBkg2DalitzPdf(bool fixem = true) { return ret; } -GooPdf* makeBkg3Eff() { +GooPdf *makeBkg3Eff() { // Smoothed histogram from flat-file data. // Only 4500 events, so use large bins. @@ -3419,7 +3504,7 @@ GooPdf* makeBkg3Eff() { m12->setNumBins(30); m13->setNumBins(30); - BinnedDataSet* bkg3_eff_data = new BinnedDataSet(weights); + BinnedDataSet *bkg3_eff_data = new BinnedDataSet(weights); std::ifstream reader; std::string fname = app_ptr->get_filename("dataFiles/efficiency_bkg3_flat.txt", "examples/pipipi0DPFit"); readWrapper(reader, fname); @@ -3442,8 +3527,8 @@ GooPdf* makeBkg3Eff() { if(reader.eof()) break; - reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. - reader >> *m12; // Already swapped according to D* charge + reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. + reader >> *m12; // Already swapped according to D* charge reader >> *m13; // Everything else is irrelevant for this purpose! @@ -3453,9 +3538,9 @@ GooPdf* makeBkg3Eff() { bkg3_eff_data->addEvent(); } - Variable* bkg3_eff_smoothing = new Variable("bkg3_eff_smoothing", 1.0, 0.1, 0, 1.25); - //Variable* bkg3_eff_smoothing = new Variable("bkg3_eff_smoothing", 1.0); - SmoothHistogramPdf* ret = new SmoothHistogramPdf("bkg3_efficiency", bkg3_eff_data, bkg3_eff_smoothing); + Variable *bkg3_eff_smoothing = new Variable("bkg3_eff_smoothing", 1.0, 0.1, 0, 1.25); + // Variable* bkg3_eff_smoothing = new Variable("bkg3_eff_smoothing", 1.0); + SmoothHistogramPdf *ret = new SmoothHistogramPdf("bkg3_efficiency", bkg3_eff_data, bkg3_eff_smoothing); m12->setNumBins(m12bins); m13->setNumBins(m13bins); @@ -3463,7 +3548,7 @@ GooPdf* makeBkg3Eff() { return ret; } -SmoothHistogramPdf* makeBackgroundHistogram(int bkgnum, std::string overridename) { +SmoothHistogramPdf *makeBackgroundHistogram(int bkgnum, std::string overridename) { std::ifstream reader; sprintf(strbuffer, "./dataFiles/bkgDalitz_%i.txt", bkgnum); @@ -3486,14 +3571,14 @@ SmoothHistogramPdf* makeBackgroundHistogram(int bkgnum, std::string overridename weights.clear(); weights.push_back(m12); weights.push_back(m13); - BinnedDataSet* bkg_binned_data = new BinnedDataSet(weights); + BinnedDataSet *bkg_binned_data = new BinnedDataSet(weights); double dummy = 0; while(!reader.eof()) { reader >> dummy; - reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. - reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) + reader >> dummy; // m23, m(pi+ pi-), called m12 in processToyRoot convention. + reader >> *m12; // Already swapped according to D* charge. m12 = m(pi+pi0) reader >> *m13; // Don't need the rest. @@ -3502,15 +3587,16 @@ SmoothHistogramPdf* makeBackgroundHistogram(int bkgnum, std::string overridename bkg_binned_data->addEvent(); - //std::cout << m12->getValue() << " " << m13->getValue() << std::endl; + // std::cout << m12->getValue() << " " << m13->getValue() << std::endl; } std::cout << "Read " << bkg_binned_data->getNumEvents() << " events for background " << bkgnum << std::endl; sprintf(strbuffer, "bkg%i_dalitz_smoothing", bkgnum); - Variable* smoothing = new Variable(strbuffer, 1); + Variable *smoothing = new Variable(strbuffer, 1); if((-1 != bkgHistRandSeed) && ((3 == bkgnum) || (4 == bkgnum))) { - std::cout << "Shuffling background " << bkgnum << " histogram with random seed " << bkgHistRandSeed << std::endl; + std::cout << "Shuffling background " << bkgnum << " histogram with random seed " << bkgHistRandSeed + << std::endl; TRandom donram(bkgHistRandSeed); for(unsigned int bin = 0; bin < bkg_binned_data->getNumBins(); ++bin) { @@ -3529,20 +3615,20 @@ SmoothHistogramPdf* makeBackgroundHistogram(int bkgnum, std::string overridename } sprintf(strbuffer, "bkg%i_dalitz", bkgnum); - SmoothHistogramPdf* bkg_dalitz = new SmoothHistogramPdf(strbuffer, bkg_binned_data, smoothing); - //bkg_dalitz->setDebugMask(1); + SmoothHistogramPdf *bkg_dalitz = new SmoothHistogramPdf(strbuffer, bkg_binned_data, smoothing); + // bkg_dalitz->setDebugMask(1); return bkg_dalitz; } -GooPdf* makeBackground3DalitzParam() { +GooPdf *makeBackground3DalitzParam() { // I can't make this thing describe the background 3 data. - //GooPdf* bkg3_eff = makeBkg3Eff(); + // GooPdf* bkg3_eff = makeBkg3Eff(); weights.clear(); - vector offsets; - vector observables; - vector coefficients; + vector offsets; + vector observables; + vector coefficients; offsets.push_back(constantOne); offsets.push_back(constantOne); @@ -3551,26 +3637,33 @@ GooPdf* makeBackground3DalitzParam() { // Recurring factor 3 offsets division by total weight in AddPdf. double weightOffset = 1; - - coefficients.push_back(new Variable("bkg3_x0y0", 1.00 * weightOffset)); - //coefficients.push_back(new Variable("bkg3_x0y0", 1.10 * weightOffset, 0.01, 0.01 * weightOffset, 1.50 * weightOffset)); - coefficients.push_back(new Variable("bkg3_x1y0", -0.36937 * weightOffset, 0.01, -1.50*weightOffset, 0.00*weightOffset)); - coefficients.push_back(new Variable("bkg3_x2y0", 1.36184 * weightOffset, 0.01, -0.10*weightOffset, 1.60*weightOffset)); - //coefficients.push_back(new Variable("bkg3_x3y0", -0.43177 * weightOffset, 0.01,-1.60*weightOffset, 0.60*weightOffset)); - coefficients.push_back(new Variable("bkg3_x0y1", -0.27691 * weightOffset, 0.01, -1.50*weightOffset, 0.00*weightOffset)); - coefficients.push_back(new Variable("bkg3_x1y1", 2.16029 * weightOffset, 0.01, 0.30*weightOffset, 4.50*weightOffset)); - //coefficients.push_back(new Variable("bkg3_x2y1", -2.04133 * weightOffset, 0.01,-2.50*weightOffset, 1.50*weightOffset)); - coefficients.push_back(new Variable("bkg3_x0y2", 1.33100 * weightOffset, 0.01, 1.00*weightOffset, 2.00*weightOffset)); - //coefficients.push_back(new Variable("bkg3_x1y2", -1.88226 * weightOffset, 0.01,-2.20*weightOffset, 1.00*weightOffset)); - //coefficients.push_back(new Variable("bkg3_x0y3", -0.58920 * weightOffset, 0.01,-1.00*weightOffset, 2.00*weightOffset)); - //PolynomialPdf* poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 3); - PolynomialPdf* poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 2); - - - //coefficients.push_back(new Variable("bkg3_x0y0", 0.10 * weightOffset, 0.01, 0.01 * weightOffset, 0.20 * weightOffset)); - //PolynomialPdf* poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 0); - - + coefficients.push_back(new Variable("bkg3_x0y0", 1.00 * weightOffset)); + // coefficients.push_back(new Variable("bkg3_x0y0", 1.10 * weightOffset, 0.01, 0.01 * weightOffset, 1.50 * + // weightOffset)); + coefficients.push_back( + new Variable("bkg3_x1y0", -0.36937 * weightOffset, 0.01, -1.50 * weightOffset, 0.00 * weightOffset)); + coefficients.push_back( + new Variable("bkg3_x2y0", 1.36184 * weightOffset, 0.01, -0.10 * weightOffset, 1.60 * weightOffset)); + // coefficients.push_back(new Variable("bkg3_x3y0", -0.43177 * weightOffset, 0.01,-1.60*weightOffset, + // 0.60*weightOffset)); + coefficients.push_back( + new Variable("bkg3_x0y1", -0.27691 * weightOffset, 0.01, -1.50 * weightOffset, 0.00 * weightOffset)); + coefficients.push_back( + new Variable("bkg3_x1y1", 2.16029 * weightOffset, 0.01, 0.30 * weightOffset, 4.50 * weightOffset)); + // coefficients.push_back(new Variable("bkg3_x2y1", -2.04133 * weightOffset, 0.01,-2.50*weightOffset, + // 1.50*weightOffset)); + coefficients.push_back( + new Variable("bkg3_x0y2", 1.33100 * weightOffset, 0.01, 1.00 * weightOffset, 2.00 * weightOffset)); + // coefficients.push_back(new Variable("bkg3_x1y2", -1.88226 * weightOffset, 0.01,-2.20*weightOffset, + // 1.00*weightOffset)); + // coefficients.push_back(new Variable("bkg3_x0y3", -0.58920 * weightOffset, 0.01,-1.00*weightOffset, + // 2.00*weightOffset)); + // PolynomialPdf* poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 3); + PolynomialPdf *poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 2); + + // coefficients.push_back(new Variable("bkg3_x0y0", 0.10 * weightOffset, 0.01, 0.01 * weightOffset, 0.20 * + // weightOffset)); + // PolynomialPdf* poly = new PolynomialPdf("bkg3Pdf", observables, coefficients, offsets, 0); // Background 3 does not have a trig threshold in Mikhail's fit // - that is, it has one, but the dec variable is set above the @@ -3578,39 +3671,40 @@ GooPdf* makeBackground3DalitzParam() { // That's Mikhail's fit; I'm putting one in to try to deal with // the asymmetry in the rho+. // Didn't work. - //Variable* bkg3_decZmin = new Variable("bkg3_decZmin", 3.30411, 0.1, 1, 5); - //Variable* bkg3_conZmin = new Variable("bkg3_conZmin", 0.29909, 0.01, 0.1, 0.9); - //TrigThresholdPdf* bkg3_loZ = new TrigThresholdPdf("bkg3_loZ", m12, m13, minDalitzZ, bkg3_decZmin, bkg3_conZmin, massSum, false); - + // Variable* bkg3_decZmin = new Variable("bkg3_decZmin", 3.30411, 0.1, 1, 5); + // Variable* bkg3_conZmin = new Variable("bkg3_conZmin", 0.29909, 0.01, 0.1, 0.9); + // TrigThresholdPdf* bkg3_loZ = new TrigThresholdPdf("bkg3_loZ", m12, m13, minDalitzZ, bkg3_decZmin, bkg3_conZmin, + // massSum, false); comps.clear(); comps.push_back(poly); comps.push_back(kzero_veto); - //comps.push_back(bkg3_eff); - //comps.push_back(bkg3_loZ); + // comps.push_back(bkg3_eff); + // comps.push_back(bkg3_loZ); - ProdPdf* poly_x_veto = new ProdPdf("poly_x_veto", comps); + ProdPdf *poly_x_veto = new ProdPdf("poly_x_veto", comps); // One misIDpi0. // Factor 3 in amplitudes is to offset division by total weight in AddPdf. - DecayInfo* special_pi0_decay = new DecayInfo(); - special_pi0_decay->motherMass = _mD0; - special_pi0_decay->daug1Mass = piZeroMass; - special_pi0_decay->daug2Mass = piPlusMass; - special_pi0_decay->daug3Mass = piPlusMass; - special_pi0_decay->meson_radius = 1.5; - - ResonancePdf* bkg3_pi0_ref = new ResonancePdf("bkg3_pi0_ref", - new Variable("bkg3_pi0_ref_amp", 0.01189 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), - 0, - new Variable("bkg3_pi0_ref_mass", 1.65766, 0.01, 1.4, 1.8), - new Variable("bkg3_pi0_ref_width", 0.05018, 0.01, 0.02, 0.20), - PAIR_23); + DecayInfo *special_pi0_decay = new DecayInfo(); + special_pi0_decay->motherMass = _mD0; + special_pi0_decay->daug1Mass = piZeroMass; + special_pi0_decay->daug2Mass = piPlusMass; + special_pi0_decay->daug3Mass = piPlusMass; + special_pi0_decay->meson_radius = 1.5; + + ResonancePdf *bkg3_pi0_ref = new ResonancePdf( + "bkg3_pi0_ref", + new Variable("bkg3_pi0_ref_amp", 0.01189 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), + 0, + new Variable("bkg3_pi0_ref_mass", 1.65766, 0.01, 1.4, 1.8), + new Variable("bkg3_pi0_ref_width", 0.05018, 0.01, 0.02, 0.20), + PAIR_23); special_pi0_decay->resonances.push_back(bkg3_pi0_ref); // Mikhail defines 'transverse Z' as y - x - (parameter). - //Variable* bkg3_pi0_transZ_offset = new Variable("bkg3_pi0_transZ_offset", -0.04381, 0.001, -0.5, 0.5); - Variable* bkg3_pi0_transZ_offset = new Variable("bkg3_pi0_transZ_offset", -0.04381); + // Variable* bkg3_pi0_transZ_offset = new Variable("bkg3_pi0_transZ_offset", -0.04381, 0.001, -0.5, 0.5); + Variable *bkg3_pi0_transZ_offset = new Variable("bkg3_pi0_transZ_offset", -0.04381); offsets.clear(); observables.clear(); coefficients.clear(); @@ -3621,91 +3715,93 @@ GooPdf* makeBackground3DalitzParam() { coefficients.push_back(constantOne); offsets.push_back(constantZero); offsets.push_back(constantZero); - PolynomialPdf* bkg3_pi0_transZ = new PolynomialPdf("bkg3_pi0_transZ", observables, coefficients, offsets, 1); + PolynomialPdf *bkg3_pi0_transZ = new PolynomialPdf("bkg3_pi0_transZ", observables, coefficients, offsets, 1); // Now we're going to take (1 - tz^2 * (parameter)) and multiply that into the misID pi0. - //Variable* bkg3_pi0_transZ_quad = new Variable("bkg3_pi0_transZ_quad", 2.12277, 0.01, -1.5, 6.0); - Variable* bkg3_pi0_transZ_quad = new Variable("bkg3_pi0_transZ_quad", 2.12277); + // Variable* bkg3_pi0_transZ_quad = new Variable("bkg3_pi0_transZ_quad", 2.12277, 0.01, -1.5, 6.0); + Variable *bkg3_pi0_transZ_quad = new Variable("bkg3_pi0_transZ_quad", 2.12277); coefficients.clear(); coefficients.push_back(constantOne); coefficients.push_back(constantZero); coefficients.push_back(bkg3_pi0_transZ_quad); // Notice the fake dependence of the polynomial on m12; in fact CompositePdf // will send it a fake event, we just have to supply a reasonable index. - PolynomialPdf* bkg3_pi0_shell = new PolynomialPdf("bkg3_pi0_shell", m12, coefficients); - CompositePdf* bkg3_pi0_transZ_total = new CompositePdf("bkg3_pi0_transZ_total", bkg3_pi0_transZ, bkg3_pi0_shell); + PolynomialPdf *bkg3_pi0_shell = new PolynomialPdf("bkg3_pi0_shell", m12, coefficients); + CompositePdf *bkg3_pi0_transZ_total = new CompositePdf("bkg3_pi0_transZ_total", bkg3_pi0_transZ, bkg3_pi0_shell); comps.clear(); comps.push_back(kzero_veto); comps.push_back(bkg3_pi0_transZ_total); - //comps.push_back(bkg3_eff); - //comps.push_back(bkg3_loZ); - //ProdPdf* bkg3_pi0_mods = new ProdPdf("bkg3_pi0_mods", comps); - //incsum3 = new IncoherentSumPdf("incsum3", m12, m13, eventNumber, special_pi0_decay, bkg3_pi0_mods); - + // comps.push_back(bkg3_eff); + // comps.push_back(bkg3_loZ); + // ProdPdf* bkg3_pi0_mods = new ProdPdf("bkg3_pi0_mods", comps); + // incsum3 = new IncoherentSumPdf("incsum3", m12, m13, eventNumber, special_pi0_decay, bkg3_pi0_mods); // Three spin-1 rho resonances to be added incoherently. - DecayInfo* incoherent_rhos = new DecayInfo(); - incoherent_rhos->motherMass = _mD0; - incoherent_rhos->daug1Mass = piZeroMass; - incoherent_rhos->daug2Mass = piPlusMass; - incoherent_rhos->daug3Mass = piPlusMass; - incoherent_rhos->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. - - ResonancePdf* bkg3_incRho0 = new ResonancePdf("bkg3_incRho0", - new Variable("bkg3_incRho0_amp", 0.00807 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), - 0, - new Variable("bkg3_incRho0_mass", 0.800, 0.01, 0.6, 1.0), - new Variable("bkg3_incRho0_width", 0.15, 0.01, 0.10, 0.40), - 1, // These rhos are spin 1, being bad signal. - PAIR_23); + DecayInfo *incoherent_rhos = new DecayInfo(); + incoherent_rhos->motherMass = _mD0; + incoherent_rhos->daug1Mass = piZeroMass; + incoherent_rhos->daug2Mass = piPlusMass; + incoherent_rhos->daug3Mass = piPlusMass; + incoherent_rhos->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. + + ResonancePdf *bkg3_incRho0 = new ResonancePdf( + "bkg3_incRho0", + new Variable("bkg3_incRho0_amp", 0.00807 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), + 0, + new Variable("bkg3_incRho0_mass", 0.800, 0.01, 0.6, 1.0), + new Variable("bkg3_incRho0_width", 0.15, 0.01, 0.10, 0.40), + 1, // These rhos are spin 1, being bad signal. + PAIR_23); incoherent_rhos->resonances.push_back(bkg3_incRho0); - ResonancePdf* bkg3_incRhoP = new ResonancePdf("bkg3_incRhoP", - new Variable("bkg3_incRhoP_amp", 0.01683 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), - 0, - new Variable("bkg3_incRhoP_mass", 0.800, 0.01, 0.6, 1.0), - new Variable("bkg3_incRhoP_width", 0.15, 0.01, 0.10, 0.40), - 1, - PAIR_12); + ResonancePdf *bkg3_incRhoP = new ResonancePdf( + "bkg3_incRhoP", + new Variable("bkg3_incRhoP_amp", 0.01683 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), + 0, + new Variable("bkg3_incRhoP_mass", 0.800, 0.01, 0.6, 1.0), + new Variable("bkg3_incRhoP_width", 0.15, 0.01, 0.10, 0.40), + 1, + PAIR_12); incoherent_rhos->resonances.push_back(bkg3_incRhoP); - ResonancePdf* bkg3_incRhoM = new ResonancePdf("bkg3_incRhoM", - new Variable("bkg3_incRhoM_amp", 0.01645 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), - 0, - new Variable("bkg3_incRhoM_mass", 0.900, 0.01, 0.6, 1.0), - new Variable("bkg3_incRhoM_width", 0.35, 0.01, 0.10, 0.60), - 1, - PAIR_13); + ResonancePdf *bkg3_incRhoM = new ResonancePdf( + "bkg3_incRhoM", + new Variable("bkg3_incRhoM_amp", 0.01645 * weightOffset, 0.01, 0.00 * weightOffset, 0.25 * weightOffset), + 0, + new Variable("bkg3_incRhoM_mass", 0.900, 0.01, 0.6, 1.0), + new Variable("bkg3_incRhoM_width", 0.35, 0.01, 0.10, 0.60), + 1, + PAIR_13); incoherent_rhos->resonances.push_back(bkg3_incRhoM); comps.clear(); comps.push_back(kzero_veto); - //comps.push_back(bkg3_loZ); - //comps.push_back(bkg3_eff); - //ProdPdf* bkg3_rho_mods = new ProdPdf("bkg3_rho_mods", comps); + // comps.push_back(bkg3_loZ); + // comps.push_back(bkg3_eff); + // ProdPdf* bkg3_rho_mods = new ProdPdf("bkg3_rho_mods", comps); - //incsum4 = new IncoherentSumPdf("incsum4", m12, m13, eventNumber, incoherent_rhos, bkg3_rho_mods); - //incsum4 = new IncoherentSumPdf("incsum4", m12, m13, eventNumber, incoherent_rhos, kzero_veto); + // incsum4 = new IncoherentSumPdf("incsum4", m12, m13, eventNumber, incoherent_rhos, bkg3_rho_mods); + // incsum4 = new IncoherentSumPdf("incsum4", m12, m13, eventNumber, incoherent_rhos, kzero_veto); weights.clear(); weights.push_back(constantOne); - //weights.push_back(constantOne); - //weights.push_back(constantOne); + // weights.push_back(constantOne); + // weights.push_back(constantOne); comps.clear(); comps.push_back(poly_x_veto); - //comps.push_back(incsum3); - //comps.push_back(incsum4); + // comps.push_back(incsum3); + // comps.push_back(incsum4); - AddPdf* bkg3_dalitz = new AddPdf("bkg3_dalitz", weights, comps); + AddPdf *bkg3_dalitz = new AddPdf("bkg3_dalitz", weights, comps); bkg3_dalitz->addSpecialMask(PdfBase::ForceCommonNorm); return bkg3_dalitz; } -GooPdf* makeBackground4DalitzParam() { - vector offsets; - vector observables; - vector coefficients; +GooPdf *makeBackground4DalitzParam() { + vector offsets; + vector observables; + vector coefficients; offsets.push_back(constantOne); offsets.push_back(constantOne); @@ -3714,51 +3810,61 @@ GooPdf* makeBackground4DalitzParam() { // Recurring factor 3 offsets division by total weight in AddPdf. double weightOffset = 3; - //coefficients.push_back(new Variable("bkg4_x0y0", 1.0 * weightOffset, 0.01, 0.50*weightOffset, 1.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x0y0", 1.0 * weightOffset)); - coefficients.push_back(new Variable("bkg4_x1y0", -0.18594 * weightOffset, 0.01, -0.50*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x2y0", 0.45459 * weightOffset, 0.01, 0.25*weightOffset, 0.75*weightOffset)); - coefficients.push_back(new Variable("bkg4_x3y0", -0.20869 * weightOffset, 0.01, -0.50*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x0y1", -0.65061 * weightOffset, 0.01, -1.50*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x1y1", 0.11000 * weightOffset, 0.01, 0.00*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x2y1", 0.42009 * weightOffset, 0.01, 0.25*weightOffset, 1.00*weightOffset)); - coefficients.push_back(new Variable("bkg4_x0y2", -0.06151 * weightOffset, 0.01, -0.50*weightOffset, 0.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x1y2", 0.58508 * weightOffset, 0.01, 0.20*weightOffset, 1.50*weightOffset)); - coefficients.push_back(new Variable("bkg4_x0y3", 0.54740 * weightOffset, 0.01, 0.20*weightOffset, 1.50*weightOffset)); - - PolynomialPdf* poly = new PolynomialPdf("bkg4Pdf", observables, coefficients, offsets, 3); - - Variable* bkg4_decZmin = new Variable("bkg4_decZmin", 2.77576); - Variable* bkg4_conZmin = new Variable("bkg4_conZmin", 0.23328); - TrigThresholdPdf* bkg4_loZ = new TrigThresholdPdf("bkg4_loZ", m12, m13, minDalitzZ, bkg4_decZmin, bkg4_conZmin, massSum, - false); + // coefficients.push_back(new Variable("bkg4_x0y0", 1.0 * weightOffset, 0.01, 0.50*weightOffset, + // 1.50*weightOffset)); + coefficients.push_back(new Variable("bkg4_x0y0", 1.0 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x1y0", -0.18594 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x2y0", 0.45459 * weightOffset, 0.01, 0.25 * weightOffset, 0.75 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x3y0", -0.20869 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x0y1", -0.65061 * weightOffset, 0.01, -1.50 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x1y1", 0.11000 * weightOffset, 0.01, 0.00 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x2y1", 0.42009 * weightOffset, 0.01, 0.25 * weightOffset, 1.00 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x0y2", -0.06151 * weightOffset, 0.01, -0.50 * weightOffset, 0.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x1y2", 0.58508 * weightOffset, 0.01, 0.20 * weightOffset, 1.50 * weightOffset)); + coefficients.push_back( + new Variable("bkg4_x0y3", 0.54740 * weightOffset, 0.01, 0.20 * weightOffset, 1.50 * weightOffset)); + + PolynomialPdf *poly = new PolynomialPdf("bkg4Pdf", observables, coefficients, offsets, 3); + + Variable *bkg4_decZmin = new Variable("bkg4_decZmin", 2.77576); + Variable *bkg4_conZmin = new Variable("bkg4_conZmin", 0.23328); + TrigThresholdPdf *bkg4_loZ + = new TrigThresholdPdf("bkg4_loZ", m12, m13, minDalitzZ, bkg4_decZmin, bkg4_conZmin, massSum, false); comps.clear(); comps.push_back(poly); comps.push_back(bkg4_loZ); comps.push_back(kzero_veto); // Separate PDF to avoid triggering numerical normalisation over all four observables. - ProdPdf* poly_x_veto = new ProdPdf("poly_x_veto", comps); + ProdPdf *poly_x_veto = new ProdPdf("poly_x_veto", comps); // One pipi bump. // Factor 3 in amplitudes is to offset division by total weight in AddPdf. - DecayInfo* special_pipi_decay = new DecayInfo(); - special_pipi_decay->motherMass = _mD0; - special_pipi_decay->daug1Mass = piZeroMass; - special_pipi_decay->daug2Mass = piPlusMass; - special_pipi_decay->daug3Mass = piPlusMass; - special_pipi_decay->meson_radius = 1.5; - - ResonancePdf* bkg4_pipi_ref = new ResonancePdf("bkg4_pipi_ref", - new Variable("bkg4_pipi_ref_amp", 0.00147 * weightOffset), - 0, - new Variable("bkg4_pipi_ref_mass", 1.32447), - new Variable("bkg4_pipi_ref_width", 0.04675), - PAIR_23); + DecayInfo *special_pipi_decay = new DecayInfo(); + special_pipi_decay->motherMass = _mD0; + special_pipi_decay->daug1Mass = piZeroMass; + special_pipi_decay->daug2Mass = piPlusMass; + special_pipi_decay->daug3Mass = piPlusMass; + special_pipi_decay->meson_radius = 1.5; + + ResonancePdf *bkg4_pipi_ref = new ResonancePdf("bkg4_pipi_ref", + new Variable("bkg4_pipi_ref_amp", 0.00147 * weightOffset), + 0, + new Variable("bkg4_pipi_ref_mass", 1.32447), + new Variable("bkg4_pipi_ref_width", 0.04675), + PAIR_23); special_pipi_decay->resonances.push_back(bkg4_pipi_ref); // Mikhail defines 'transverse Z' as y - x - (parameter). - Variable* bkg4_pipi_transZ_offset = new Variable("bkg4_pipi_transZ_offset", -0.39877); + Variable *bkg4_pipi_transZ_offset = new Variable("bkg4_pipi_transZ_offset", -0.39877); offsets.clear(); observables.clear(); @@ -3770,69 +3876,69 @@ GooPdf* makeBackground4DalitzParam() { coefficients.push_back(constantOne); offsets.push_back(constantZero); offsets.push_back(constantZero); - PolynomialPdf* bkg4_pipi_transZ = new PolynomialPdf("bkg4_pipi_transZ", observables, coefficients, offsets, 1); + PolynomialPdf *bkg4_pipi_transZ = new PolynomialPdf("bkg4_pipi_transZ", observables, coefficients, offsets, 1); // Now we're going to take (1 - tz^2 * (parameter)) and multiply that into the pipi bump. - Variable* bkg4_pipi_transZ_quad = new Variable("bkg4_pipi_transZ_quad", -0.25640); + Variable *bkg4_pipi_transZ_quad = new Variable("bkg4_pipi_transZ_quad", -0.25640); coefficients.clear(); coefficients.push_back(constantOne); coefficients.push_back(constantZero); coefficients.push_back(bkg4_pipi_transZ_quad); // Notice the fake dependence of the polynomial on m12; in fact CompositePdf // will send it a fake event, we just have to supply a reasonable index. - PolynomialPdf* bkg4_pipi_shell = new PolynomialPdf("bkg4_pipi_shell", m12, coefficients); - CompositePdf* bkg4_pipi_transZ_total = new CompositePdf("bkg4_pipi_transZ_total", bkg4_pipi_transZ, bkg4_pipi_shell); - + PolynomialPdf *bkg4_pipi_shell = new PolynomialPdf("bkg4_pipi_shell", m12, coefficients); + CompositePdf *bkg4_pipi_transZ_total + = new CompositePdf("bkg4_pipi_transZ_total", bkg4_pipi_transZ, bkg4_pipi_shell); comps.clear(); comps.push_back(kzero_veto); comps.push_back(bkg4_loZ); comps.push_back(bkg4_pipi_transZ_total); - ProdPdf* bkg4_pipi_mods = new ProdPdf("bkg4_pipi_mods", comps); + ProdPdf *bkg4_pipi_mods = new ProdPdf("bkg4_pipi_mods", comps); incsum5 = new IncoherentSumPdf("incsum5", m12, m13, eventNumber, special_pipi_decay, bkg4_pipi_mods); // Three spin-0 rho resonances to be added incoherently. - DecayInfo* incoherent_rho0s = new DecayInfo(); - incoherent_rho0s->motherMass = _mD0; - incoherent_rho0s->daug1Mass = piZeroMass; - incoherent_rho0s->daug2Mass = piPlusMass; - incoherent_rho0s->daug3Mass = piPlusMass; - incoherent_rho0s->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. - - ResonancePdf* bkg4_incRho0 = new ResonancePdf("bkg4_incRho0", - new Variable("bkg4_incRho0_amp", 0.00429 * weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, // These rhos are spin 0. - PAIR_23); + DecayInfo *incoherent_rho0s = new DecayInfo(); + incoherent_rho0s->motherMass = _mD0; + incoherent_rho0s->daug1Mass = piZeroMass; + incoherent_rho0s->daug2Mass = piPlusMass; + incoherent_rho0s->daug3Mass = piPlusMass; + incoherent_rho0s->meson_radius = 0; // Mikhail uses zero radius for incoherent resonances. + + ResonancePdf *bkg4_incRho0 = new ResonancePdf("bkg4_incRho0", + new Variable("bkg4_incRho0_amp", 0.00429 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, // These rhos are spin 0. + PAIR_23); incoherent_rho0s->resonances.push_back(bkg4_incRho0); - ResonancePdf* bkg4_incRhoP = new ResonancePdf("bkg4_incRhoP", - new Variable("bkg4_incRhoP_amp", 0.00705 * weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, - PAIR_12); + ResonancePdf *bkg4_incRhoP = new ResonancePdf("bkg4_incRhoP", + new Variable("bkg4_incRhoP_amp", 0.00705 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, + PAIR_12); incoherent_rho0s->resonances.push_back(bkg4_incRhoP); - ResonancePdf* bkg4_incRhoM = new ResonancePdf("bkg4_incRhoM", - new Variable("bkg4_incRhoM_amp", -0.00043 * weightOffset), - 0, - fixedRhoMass, - fixedRhoWidth, - 0, - PAIR_13); + ResonancePdf *bkg4_incRhoM = new ResonancePdf("bkg4_incRhoM", + new Variable("bkg4_incRhoM_amp", -0.00043 * weightOffset), + 0, + fixedRhoMass, + fixedRhoWidth, + 0, + PAIR_13); incoherent_rho0s->resonances.push_back(bkg4_incRhoM); comps.clear(); comps.push_back(kzero_veto); comps.push_back(bkg4_loZ); - ProdPdf* bkg4_incrho_mods = new ProdPdf("bkg4_incrho_mods", comps); + ProdPdf *bkg4_incrho_mods = new ProdPdf("bkg4_incrho_mods", comps); incsum6 = new IncoherentSumPdf("incsum6", m12, m13, eventNumber, incoherent_rho0s, bkg4_incrho_mods); - //incsum6 = new IncoherentSumPdf("incsum6", m12, m13, eventNumber, incoherent_rho0s, kzero_veto); + // incsum6 = new IncoherentSumPdf("incsum6", m12, m13, eventNumber, incoherent_rho0s, kzero_veto); weights.clear(); weights.push_back(constantOne); @@ -3843,12 +3949,12 @@ GooPdf* makeBackground4DalitzParam() { comps.push_back(incsum5); comps.push_back(incsum6); - AddPdf* bkg4_dalitz = new AddPdf("bkg4_dalitz", weights, comps); + AddPdf *bkg4_dalitz = new AddPdf("bkg4_dalitz", weights, comps); bkg4_dalitz->addSpecialMask(PdfBase::ForceCommonNorm); return bkg4_dalitz; } -GooPdf* makeBkg3DalitzPdf(bool fixem = true) { +GooPdf *makeBkg3DalitzPdf(bool fixem = true) { if(!kzero_veto) makeKzeroVeto(); @@ -3862,25 +3968,24 @@ GooPdf* makeBkg3DalitzPdf(bool fixem = true) { // histogram. So I load up all the MC data and use it in the histogram, either // way. - GooPdf* bkg3_dalitz = nullptr; + GooPdf *bkg3_dalitz = nullptr; if(!notUseBackground3Hist) bkg3_dalitz = makeBackgroundHistogram(3); else bkg3_dalitz = makeBackground3DalitzParam(); - //bkg3_dalitz->setDebugMask(1); + // bkg3_dalitz->setDebugMask(1); - GooPdf* bkg3_dtime = nullptr; + GooPdf *bkg3_dtime = nullptr; if(gaussBkgTime) bkg3_dtime = makeGaussianTimePdf(3); else bkg3_dtime = makeExpGausTimePdf(3); - - //bkg3_jsugg = makeBkg3_sigma(); - //bkg3_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. + // bkg3_jsugg = makeBkg3_sigma(); + // bkg3_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. bkg3_jsugg = makeBkg_sigma_strips(3); bkg3_jsugg->addSpecialMask(PdfBase::ForceSeparateNorm); // Otherwise ProdPdf tries to use the default overall integration, @@ -3890,17 +3995,16 @@ GooPdf* makeBkg3DalitzPdf(bool fixem = true) { // because CommonNorm applies to the AddPdf while SeparateNorm // applies to the ProdPdf. - comps.clear(); comps.push_back(bkg3_dalitz); - //bkg3_dalitz->setDebugMask(1); - //incsum3->setDebugMask(1); + // bkg3_dalitz->setDebugMask(1); + // incsum3->setDebugMask(1); comps.push_back(bkg3_dtime); - //bkg3_dtime->setDebugMask(1); - //comps.push_back(bkg3_jsugg); - //sig0_jsugg->setDebugMask(1); + // bkg3_dtime->setDebugMask(1); + // comps.push_back(bkg3_jsugg); + // sig0_jsugg->setDebugMask(1); - GooPdf* ret = new ProdPdf("bkg3_total", comps); + GooPdf *ret = new ProdPdf("bkg3_total", comps); if(fixem) ret->setParameterConstantness(true); @@ -3908,21 +4012,21 @@ GooPdf* makeBkg3DalitzPdf(bool fixem = true) { return ret; } -GooPdf* makeBkg4DalitzPdf(bool fixem = true) { +GooPdf *makeBkg4DalitzPdf(bool fixem = true) { if(!kzero_veto) makeKzeroVeto(); comps.clear(); weights.clear(); - GooPdf* bkg4_dalitz = nullptr; + GooPdf *bkg4_dalitz = nullptr; if(!notUseBackground4Hist) bkg4_dalitz = makeBackgroundHistogram(4); else bkg4_dalitz = makeBackground4DalitzParam(); - GooPdf* bkg4_dtime = nullptr; + GooPdf *bkg4_dtime = nullptr; if(gaussBkgTime) bkg4_dtime = makeGaussianTimePdf(4); @@ -3930,17 +4034,17 @@ GooPdf* makeBkg4DalitzPdf(bool fixem = true) { bkg4_dtime = makeExpGausTimePdf(4); // Separate sigma_t distribution - //bkg4_jsugg = makeBkg4_sigma(); - //bkg4_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. + // bkg4_jsugg = makeBkg4_sigma(); + // bkg4_jsugg = sig0_jsugg; // Mikhail uses same sigma distribution for everything. bkg4_jsugg = makeBkg_sigma_strips(4); bkg4_jsugg->addSpecialMask(PdfBase::ForceSeparateNorm); // See comments to bkg3_jsugg. comps.clear(); comps.push_back(bkg4_dalitz); comps.push_back(bkg4_dtime); - //comps.push_back(bkg4_jsugg); + // comps.push_back(bkg4_jsugg); - ProdPdf* ret = new ProdPdf("bkg4_total", comps); + ProdPdf *ret = new ProdPdf("bkg4_total", comps); if(fixem) ret->setParameterConstantness(true); @@ -3948,19 +4052,18 @@ GooPdf* makeBkg4DalitzPdf(bool fixem = true) { return ret; } - int runCanonicalFit(std::string fname, bool noPlots = true) { makeFullFitVariables(); if(mdslices > 1) - massd0 = new Variable("massd0", 1.8654 + 0.0075*md0_lower_window + md0offset, - 1.8654 + 0.0075*md0_upper_window + md0offset); + massd0 = new Variable( + "massd0", 1.8654 + 0.0075 * md0_lower_window + md0offset, 1.8654 + 0.0075 * md0_upper_window + md0offset); std::cout << "Loading events from " << fname << std::endl; loadDataFile(fname); std::cout << "Creating overall signal PDF\n"; - GooPdf* overallSignal = makeOverallSignal(); + GooPdf *overallSignal = makeOverallSignal(); TRandom donram(blindSeed); // The rain and the sun! @@ -3969,8 +4072,7 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { ptr_to_ymix->setBlind(donram.Gaus(0, 0.005)); } - //overallSignal->setDebugMask(1); - + // overallSignal->setDebugMask(1); int oldBins1 = m12->getNumBins(); int oldBins2 = m13->getNumBins(); @@ -3978,9 +4080,9 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { m12->setNumBins(bkgHistBins); m13->setNumBins(bkgHistBins); std::cout << "Creating background PDFs\n"; - GooPdf* bkg2Pdf = makeBkg2DalitzPdf(); - GooPdf* bkg3Pdf = makeBkg3DalitzPdf(); - GooPdf* bkg4Pdf = makeBkg4DalitzPdf(); + GooPdf *bkg2Pdf = makeBkg2DalitzPdf(); + GooPdf *bkg3Pdf = makeBkg3DalitzPdf(); + GooPdf *bkg4Pdf = makeBkg4DalitzPdf(); m12->setNumBins(oldBins1); m13->setNumBins(oldBins2); @@ -3999,20 +4101,20 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { bkg3Pdf->setParameterConstantness(true); bkg4Pdf->setParameterConstantness(true); - //bkg3Pdf->setDebugMask(1); + // bkg3Pdf->setDebugMask(1); int eventSize = massd0 ? 11 : 10; std::cout << "Setting data size " << eventSize << std::endl; signalDalitz->setDataSize(data->getNumEvents(), eventSize); // Must take into account event weights! - //bkg2Pdf->setDebugMask(1); + // bkg2Pdf->setDebugMask(1); if(incsum1) incsum1->setDataSize(data->getNumEvents(), eventSize); if(incsum2) incsum2->setDataSize(data->getNumEvents(), eventSize); - //bkg3Pdf->setDebugMask(1); + // bkg3Pdf->setDebugMask(1); if(incsum3) incsum3->setDataSize(data->getNumEvents(), eventSize); @@ -4026,29 +4128,29 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { incsum6->setDataSize(data->getNumEvents(), eventSize); std::cout << "Creating overall PDF\n"; - std::vector evtWeights; + std::vector evtWeights; evtWeights.push_back(wSig0); evtWeights.push_back(wBkg2); evtWeights.push_back(wBkg3); evtWeights.push_back(wBkg4); - std::vector components; + std::vector components; components.push_back(overallSignal); components.push_back(bkg2Pdf); components.push_back(bkg3Pdf); components.push_back(bkg4Pdf); - EventWeightedAddPdf* overallPdf = new EventWeightedAddPdf("total", evtWeights, components); - //overallPdf->setDebugMask(1); + EventWeightedAddPdf *overallPdf = new EventWeightedAddPdf("total", evtWeights, components); + // overallPdf->setDebugMask(1); std::cout << "Copying data to GPU\n"; overallPdf->setData(data); if(paramUp != "") { - Variable* target = overallPdf->getParameterByName(paramUp); + Variable *target = overallPdf->getParameterByName(paramUp); assert(target); target->setValue(target->getValue() + target->getError()); } if(paramDn != "") { - Variable* target = overallPdf->getParameterByName(paramDn); + Variable *target = overallPdf->getParameterByName(paramDn); assert(target); target->setValue(target->getValue() - target->getError()); } @@ -4065,21 +4167,24 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { datapdf.fit(); retval = datapdf; } - - //ROOT::Minuit2::FunctionMinimum* min = datapdf.fit(); - //overallSignal->setDebugMask(1); - - //overallSignal->setDebugMask(0); +// ROOT::Minuit2::FunctionMinimum* min = datapdf.fit(); +// overallSignal->setDebugMask(1); + +// overallSignal->setDebugMask(0); #ifdef PROFILING overallPdf->printProfileInfo(); #endif - printf("Fit results:\ntau : (%.3f $\\pm$ %.3f) fs\nxmixing: (%.3f $\\pm$ %.3f)%%\nymixing: (%.3f $\\pm$ %.3f)%%\n", - 1000*ptr_to_dtau->getValue(), 1000*ptr_to_dtau->getError(), - 100*ptr_to_xmix->getValue(), 100*ptr_to_xmix->getError(), - 100*ptr_to_ymix->getValue(), 100*ptr_to_ymix->getError()); + printf( + "Fit results:\ntau : (%.3f $\\pm$ %.3f) fs\nxmixing: (%.3f $\\pm$ %.3f)%%\nymixing: (%.3f $\\pm$ %.3f)%%\n", + 1000 * ptr_to_dtau->getValue(), + 1000 * ptr_to_dtau->getError(), + 100 * ptr_to_xmix->getValue(), + 100 * ptr_to_xmix->getError(), + 100 * ptr_to_ymix->getValue(), + 100 * ptr_to_ymix->getError()); /* std::cout << "Fit results: \n" @@ -4107,12 +4212,11 @@ int runCanonicalFit(std::string fname, bool noPlots = true) { */ if(!noPlots) makeDalitzPlots(overallSignal); - + return retval; - } -int runSigmaFit(const char* fname) { +int runSigmaFit(const char *fname) { makeFullFitVariables(); loM23Sigma = new TH1F("loM23Sigma", "", sigma->getNumBins(), sigma->getLowerLimit(), sigma->getUpperLimit()); @@ -4121,12 +4225,12 @@ int runSigmaFit(const char* fname) { hiM23Sigma->SetStats(false); loadDataFile(fname); - //GooPdf* jsu_gg = makeSignalJSU_gg(-1, false); - //GooPdf* jsu_gg = makeSigmaMap(); - GooPdf* jsu_gg = makeBkg_sigma_strips(0); + // GooPdf* jsu_gg = makeSignalJSU_gg(-1, false); + // GooPdf* jsu_gg = makeSigmaMap(); + GooPdf *jsu_gg = makeBkg_sigma_strips(0); jsu_gg->setData(data); - //jsu_gg->copyParams(); - + // jsu_gg->copyParams(); + int retval; if(minuit1) { GooFit::FitManagerMinuit1 datapdf(jsu_gg); @@ -4138,21 +4242,20 @@ int runSigmaFit(const char* fname) { retval = datapdf; } - sprintf(strbuffer, "signal_sigma_%islices_pdf.txt", m23Slices); writeToFile(jsu_gg, strbuffer); foo->cd(); plotLoHiSigma(); - std::vector gridvars; + std::vector gridvars; gridvars.push_back(m12); gridvars.push_back(m13); gridvars.push_back(sigma); UnbinnedDataSet grid(gridvars); - TH1F* sigma_pdfs[6]; - TH1F* sigma_data[6]; + TH1F *sigma_pdfs[6]; + TH1F *sigma_data[6]; double num_sigma_dat[6]; double num_sigma_pdf[6]; @@ -4181,26 +4284,26 @@ int runSigmaFit(const char* fname) { for(unsigned int evt = 0; evt < data->getNumEvents(); ++evt) { double currSigma = data->getValue(sigma, evt); - double currm12 = data->getValue(m12, evt); - double currm13 = data->getValue(m13, evt); - double currm23 = cpuGetM23(currm12, currm13); - int m23bin = (int) floor(currm23 / 0.5); + double currm12 = data->getValue(m12, evt); + double currm13 = data->getValue(m13, evt); + double currm23 = cpuGetM23(currm12, currm13); + int m23bin = (int)floor(currm23 / 0.5); sigma_data[m23bin]->Fill(currSigma); num_sigma_dat[m23bin]++; totalDat++; } for(int i = 0; i < m12->getNumBins(); ++i) { - m12->setValue( m12->getLowerLimit() + (i + 0.5)*m12->getBinSize()); + m12->setValue(m12->getLowerLimit() + (i + 0.5) * m12->getBinSize()); for(int j = 0; j < m13->getNumBins(); ++j) { - m13->setValue( m13->getLowerLimit() + (j + 0.5)*m13->getBinSize()); + m13->setValue(m13->getLowerLimit() + (j + 0.5) * m13->getBinSize()); if(!cpuDalitz(m12->getValue(), m13->getValue(), _mD0, piZeroMass, piPlusMass, piPlusMass)) continue; for(int k = 0; k < sigma->getNumBins(); ++k) { - sigma->setValue(sigma->getLowerLimit() + (k + 0.5)*sigma->getBinSize()); + sigma->setValue(sigma->getLowerLimit() + (k + 0.5) * sigma->getBinSize()); grid.addEvent(); } } @@ -4214,8 +4317,8 @@ int runSigmaFit(const char* fname) { double currM12 = grid.getValue(m12, j); double currM13 = grid.getValue(m13, j); double currSigma = grid.getValue(sigma, j); - double currm23 = cpuGetM23(currM12, currM13); - int m23bin = (int) floor(currm23 / 0.5); + double currm23 = cpuGetM23(currM12, currM13); + int m23bin = (int)floor(currm23 / 0.5); sigma_pdfs[m23bin]->Fill(currSigma, pdfValues[0][j]); num_sigma_pdf[m23bin] += pdfValues[0][j]; totalPdf += pdfValues[0][j]; @@ -4248,9 +4351,6 @@ int runSigmaFit(const char* fname) { foo->SetLogy(false); } - - - /* // This code assumes you're using the PDF from makeSigmaMap. TCanvas foodal("", "", 600, 600); @@ -4283,7 +4383,7 @@ int runSigmaFit(const char* fname) { } foodal.SaveAs("./plots_from_mixfit/sigma_dalitz.png"); */ - + return retval; } @@ -4291,22 +4391,22 @@ int runEfficiencyFit(int which) { makeFullFitVariables(); if(3 == which) { - m12->setNumBins( m12->getNumBins() / 8); - m13->setNumBins( m13->getNumBins() / 8); + m12->setNumBins(m12->getNumBins() / 8); + m13->setNumBins(m13->getNumBins() / 8); } - vector lvars; + vector lvars; lvars.push_back(m12); lvars.push_back(m13); - //binEffData = new BinnedDataSet(lvars); - //GooPdf* eff = makeEfficiencyPdf(); + // binEffData = new BinnedDataSet(lvars); + // GooPdf* eff = makeEfficiencyPdf(); makeKzeroVeto(); - //GooPdf* eff = makeEfficiencyPoly(); - GooPdf* eff = makeEfficiencyPdf(); - + // GooPdf* eff = makeEfficiencyPoly(); + GooPdf *eff = makeEfficiencyPdf(); + std::string fname_3flat = app_ptr->get_filename("dataFiles/efficiency_bkg3_flat.txt", "examples/pipipi0DPFit"); - std::string fname_flat = app_ptr->get_filename("dataFiles/efficiency_flat.txt", "examples/pipipi0DPFit"); + std::string fname_flat = app_ptr->get_filename("dataFiles/efficiency_flat.txt", "examples/pipipi0DPFit"); if(3 == which) loadDataFile(fname_3flat); @@ -4319,9 +4419,9 @@ int runEfficiencyFit(int which) { foo->SaveAs("./plots_from_mixfit/efficiency_bins.png"); } - //eff->setDebugMask(1); + // eff->setDebugMask(1); eff->setData(data); - + int retval; if(minuit1) { GooFit::FitManagerMinuit1 datapdf(eff); @@ -4332,17 +4432,28 @@ int runEfficiencyFit(int which) { datapdf.fit(); retval = datapdf; } - - - //plotFit(sigma, data, jsu_gg); - TH2F dalitz_dat_hist("dalitz_dat_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + // plotFit(sigma, data, jsu_gg); + + TH2F dalitz_dat_hist("dalitz_dat_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitz_dat_hist.SetStats(false); dalitz_dat_hist.GetXaxis()->SetTitle("m^{2}(#pi^{+} #pi^{0}) [GeV]"); dalitz_dat_hist.GetYaxis()->SetTitle("m^{2}(#pi^{-} #pi^{0}) [GeV]"); - TH2F dalitz_pdf_hist("dalitz_pdf_hist", "", m12->getNumBins(), m12->getLowerLimit(), m12->getUpperLimit(), m13->getNumBins(), - m13->getLowerLimit(), m13->getUpperLimit()); + TH2F dalitz_pdf_hist("dalitz_pdf_hist", + "", + m12->getNumBins(), + m12->getLowerLimit(), + m12->getUpperLimit(), + m13->getNumBins(), + m13->getLowerLimit(), + m13->getUpperLimit()); dalitz_pdf_hist.SetStats(false); double totalPdf = 0; @@ -4350,23 +4461,23 @@ int runEfficiencyFit(int which) { for(unsigned int evt = 0; evt < data->getNumEvents(); ++evt) { double currval = data->getValue(m12, evt); - //m12_dat_hist.Fill(currval); + // m12_dat_hist.Fill(currval); double currval2 = data->getValue(m13, evt); - //m13_dat_hist.Fill(currval2); + // m13_dat_hist.Fill(currval2); dalitz_dat_hist.Fill(currval, currval2); totalDat++; } - std::vector nvars; + std::vector nvars; nvars.push_back(m12); nvars.push_back(m13); UnbinnedDataSet currData(nvars); for(int i = 0; i < m12->getNumBins(); ++i) { - m12->setValue(m12->getLowerLimit() + (i + 0.5)*m12->getBinSize()); + m12->setValue(m12->getLowerLimit() + (i + 0.5) * m12->getBinSize()); for(int j = 0; j < m13->getNumBins(); ++j) { - m13->setValue( m13->getLowerLimit() + (j + 0.5) * m13->getBinSize()); + m13->setValue(m13->getLowerLimit() + (j + 0.5) * m13->getBinSize()); if(!cpuDalitz(m12->getValue(), m13->getValue(), _mD0, piZeroMass, piPlusMass, piPlusMass)) continue; @@ -4377,24 +4488,20 @@ int runEfficiencyFit(int which) { eff->setData(&currData); - //eff->setDebugMask(1); + // eff->setDebugMask(1); std::vector> pdfValues = eff->getCompProbsAtDataPoints(); for(unsigned int j = 0; j < pdfValues[0].size(); ++j) { double currVal = currData.getValue(m12, j); - //m12_pdf_hist.Fill(currVal, pdfValues[0][j]); + // m12_pdf_hist.Fill(currVal, pdfValues[0][j]); double currVal2 = currData.getValue(m13, j); - //m13_pdf_hist.Fill(currVal, pdfValues[0][j]); + // m13_pdf_hist.Fill(currVal, pdfValues[0][j]); dalitz_pdf_hist.Fill(currVal, currVal2, pdfValues[0][j]); totalPdf += pdfValues[0][j]; if(std::isnan(pdfValues[0][j])) { - std::cout << "Major problem: " - << currVal << " " - << currVal2 << " " - << j - << std::endl; + std::cout << "Major problem: " << currVal << " " << currVal2 << " " << j << std::endl; assert(false); } @@ -4438,11 +4545,14 @@ int runEfficiencyFit(int which) { TH1F loM23pullplot("loM23pullplot", "", 100, -5, 5); for(int i = 1; i <= m12->getNumBins(); ++i) { - double m12loedge = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i-1); - double m12hiedge = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i); + double m12loedge + = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i - 1); + double m12hiedge + = m12->getLowerLimit() + ((m12->getUpperLimit() - m12->getLowerLimit()) / m12->getNumBins()) * (i); for(int j = 1; j <= m13->getNumBins(); ++j) { - double m13loedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j-1); + double m13loedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j - 1); if(!cpuDalitz(m12loedge, m13loedge, _mD0, piZeroMass, piPlusMass, piPlusMass)) { dalitz_dat_hist.SetBinContent(i, j, 0); @@ -4454,7 +4564,8 @@ int runEfficiencyFit(int which) { continue; } - double m13hiedge = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); + double m13hiedge + = m13->getLowerLimit() + ((m13->getUpperLimit() - m13->getLowerLimit()) / m13->getNumBins()) * (j); if(!cpuDalitz(m12loedge, m13hiedge, _mD0, piZeroMass, piPlusMass, piPlusMass)) { dalitz_dat_hist.SetBinContent(i, j, 0); @@ -4470,16 +4581,16 @@ int runEfficiencyFit(int which) { double pdf = dalitz_pdf_hist.GetBinContent(i, j); double pull = (dat - pdf) / sqrt(max(1.0, dat)); - //if (fabs(pull) > 5) continue; + // if (fabs(pull) > 5) continue; dalitz_dat_hist.SetBinContent(i, j, pull); pullplot.Fill(pull); double currm12 = dalitz_dat_hist.GetXaxis()->GetBinCenter(i); double currm13 = dalitz_dat_hist.GetYaxis()->GetBinCenter(j); - //double currm23 = cpuGetM23(currm12, currm13); - //if (currm23 > 1.5) hiM23pullplot.Fill(pull); - //else loM23pullplot.Fill(pull); + // double currm23 = cpuGetM23(currm12, currm13); + // if (currm23 > 1.5) hiM23pullplot.Fill(pull); + // else loM23pullplot.Fill(pull); if((currm13 > 2) || (currm12 > 2)) hiM23pullplot.Fill(pull); else @@ -4501,7 +4612,7 @@ int runEfficiencyFit(int which) { loM23pullplot.Draw(); foo->SaveAs("./plots_from_mixfit/loeffpull.png"); - + return retval; } @@ -4509,7 +4620,7 @@ int runBackgroundDalitzFit(int bkgType, bool plots) { makeFullFitVariables(); makeKzeroVeto(); - GooPdf* bkgPdf = 0; + GooPdf *bkgPdf = 0; switch(bkgType) { default: @@ -4531,10 +4642,10 @@ int runBackgroundDalitzFit(int bkgType, bool plots) { loadDataFile(fname); bkgPdf->setData(data); - //bkgPdf->setDebugMask(1); + // bkgPdf->setDebugMask(1); // Incoherent-sum components need to know data size; check which ones exist. - int eventSize = 5; // m12 m13 dtime sigma eventNumber + int eventSize = 5; // m12 m13 dtime sigma eventNumber if(incsum1) incsum1->setDataSize(data->getNumEvents(), eventSize); @@ -4566,12 +4677,10 @@ int runBackgroundDalitzFit(int bkgType, bool plots) { fitter.fit(); retval = fitter; } - - if(plots) { - //sprintf(strbuffer, "./plots_from_mixfit/bkgdalitz_%i/", bkgType); - //makeDalitzPlots(bkgPdf, strbuffer); + // sprintf(strbuffer, "./plots_from_mixfit/bkgdalitz_%i/", bkgType); + // makeDalitzPlots(bkgPdf, strbuffer); getBackgroundFile(bkgType); std::string fname = app_ptr->get_filename(strbuffer, "examples/pipipi0DPFit"); writeToFile(bkgPdf, fname.c_str()); @@ -4592,8 +4701,7 @@ void getBackgroundFile(int bkgType) { } else { std::string pdftype; - if(((3 == bkgType) && (notUseBackground3Hist)) || - ((4 == bkgType) && (notUseBackground4Hist))) + if(((3 == bkgType) && (notUseBackground3Hist)) || ((4 == bkgType) && (notUseBackground4Hist))) pdftype = "_param"; sprintf(strbuffer, "./bkg_%i_pdf%s.txt", bkgType, pdftype.c_str()); @@ -4601,10 +4709,9 @@ void getBackgroundFile(int bkgType) { } } - void makeTimePlots(std::string fname) { makeFullFitVariables(); - massd0 = new Variable("massd0", 1.8654 + 0.0075*md0_lower_window, 1.8654 + 0.0075*md0_upper_window); + massd0 = new Variable("massd0", 1.8654 + 0.0075 * md0_lower_window, 1.8654 + 0.0075 * md0_upper_window); massd0->setNumBins(180); std::cout << "Loading MC data from " << fname << std::endl; loadDataFile(fname); @@ -4614,15 +4721,21 @@ void makeTimePlots(std::string fname) { timeMean.SetLineWidth(3); timeMean.SetXTitle("#pi#pi#pi^{0} mass [GeV]"); timeMean.SetYTitle("Mean of decay time [ps]"); - TH2F timeVsMass("timeVsMass", "", massd0->getNumBins(), massd0->getLowerLimit(), massd0->getUpperLimit(), dtime->getNumBins(), - dtime->getLowerLimit(), dtime->getUpperLimit()); + TH2F timeVsMass("timeVsMass", + "", + massd0->getNumBins(), + massd0->getLowerLimit(), + massd0->getUpperLimit(), + dtime->getNumBins(), + dtime->getLowerLimit(), + dtime->getUpperLimit()); timeVsMass.SetStats(false); timeVsMass.GetXaxis()->SetTitle("#pi#pi#pi^{0} mass [GeV]"); timeVsMass.GetYaxis()->SetTitle("Decay time [ps]"); int colors[6] = {kViolet + 1, kBlue, kCyan, kGreen, kYellow, kRed}; - TH1F* timePlots[6]; - TH1F* massPlots[5]; + TH1F *timePlots[6]; + TH1F *massPlots[5]; for(int i = 0; i < 6; ++i) { sprintf(strbuffer, "timePlot_%i.png", i); @@ -4653,10 +4766,12 @@ void makeTimePlots(std::string fname) { if(massd0->getValue() < massd0->getLowerLimit()) continue; - int slice = (int) floor(6 * (massd0->getValue() - massd0->getLowerLimit()) / (massd0->getUpperLimit() - massd0->getLowerLimit())); + int slice = (int)floor(6 * (massd0->getValue() - massd0->getLowerLimit()) + / (massd0->getUpperLimit() - massd0->getLowerLimit())); timePlots[slice]->Fill(dtime->getValue()); - slice = (int) floor(5 * (dtime->getValue() - dtime->getLowerLimit()) / (dtime->getUpperLimit() - dtime->getLowerLimit())); + slice = (int)floor(5 * (dtime->getValue() - dtime->getLowerLimit()) + / (dtime->getUpperLimit() - dtime->getLowerLimit())); massPlots[slice]->Fill(massd0->getValue()); } @@ -4668,20 +4783,20 @@ void makeTimePlots(std::string fname) { for(int i = 0; i < 6; ++i) { normalize(timePlots[i]); timePlots[i]->Draw("histsame"); - timeMean.SetBinContent(i+1, timePlots[i]->GetMean()); - timeMean.SetBinError(i+1, timePlots[i]->GetMeanError()); + timeMean.SetBinContent(i + 1, timePlots[i]->GetMean()); + timeMean.SetBinError(i + 1, timePlots[i]->GetMeanError()); } foo->SaveAs("timePlots.png"); timeMean.Draw("e"); foo->SaveAs("timeMeanPlot.png"); - //normalize(massPlots[2]); - massPlots[2]->GetYaxis()->SetRangeUser(0, massPlots[2]->GetMaximum()*1.1); + // normalize(massPlots[2]); + massPlots[2]->GetYaxis()->SetRangeUser(0, massPlots[2]->GetMaximum() * 1.1); massPlots[2]->Draw(""); for(int i = 0; i < 5; ++i) { - //normalize(massPlots[i]); + // normalize(massPlots[i]); massPlots[i]->Draw("same"); } @@ -4690,9 +4805,11 @@ void makeTimePlots(std::string fname) { timeVsMass.Draw("colz"); for(int i = 0; i < 6; ++i) { - TLine* currLine = new TLine(massd0->getLowerLimit() + (i+0)*(massd0->getUpperLimit() - massd0->getLowerLimit())/6, - dtime->getLowerLimit()+0.09, - massd0->getLowerLimit() + (i+1)*(massd0->getUpperLimit() - massd0->getLowerLimit())/6, dtime->getLowerLimit()+0.09); + TLine *currLine + = new TLine(massd0->getLowerLimit() + (i + 0) * (massd0->getUpperLimit() - massd0->getLowerLimit()) / 6, + dtime->getLowerLimit() + 0.09, + massd0->getLowerLimit() + (i + 1) * (massd0->getUpperLimit() - massd0->getLowerLimit()) / 6, + dtime->getLowerLimit() + 0.09); currLine->SetLineWidth(12); currLine->SetLineColor(colors[i]); currLine->Draw(); @@ -4701,12 +4818,12 @@ void makeTimePlots(std::string fname) { continue; currLine = new TLine(massd0->getLowerLimit() + 0.00025, - dtime->getLowerLimit() + (i+0)*(dtime->getUpperLimit() - dtime->getLowerLimit())/5, + dtime->getLowerLimit() + (i + 0) * (dtime->getUpperLimit() - dtime->getLowerLimit()) / 5, massd0->getLowerLimit() + 0.00025, - dtime->getLowerLimit() + (i+1)*(dtime->getUpperLimit() - dtime->getLowerLimit())/5); + dtime->getLowerLimit() + (i + 1) * (dtime->getUpperLimit() - dtime->getLowerLimit()) / 5); currLine->SetLineWidth(12); currLine->SetLineColor(colors[i]); -// currLine->Draw(); + // currLine->Draw(); } foo->SaveAs("timeVsMass.png"); @@ -4715,7 +4832,7 @@ void makeTimePlots(std::string fname) { int runBackgroundSigmaFit(int bkgType) { makeFullFitVariables(); - GooPdf* bkgPdf = 0; + GooPdf *bkgPdf = 0; switch(bkgType) { default: @@ -4738,9 +4855,8 @@ int runBackgroundSigmaFit(int bkgType) { loadDataFile(fname); bkgPdf->setData(data); - int retval; - + if(minuit1) { GooFit::FitManagerMinuit1 fitter(bkgPdf); fitter.setMaxCalls(8000); @@ -4752,26 +4868,25 @@ int runBackgroundSigmaFit(int bkgType) { fitter.fit(); retval = fitter; } - - //bkgPdf->setDebugMask(1); + + // bkgPdf->setDebugMask(1); plotFit(sigma, data, bkgPdf); plotLoHiSigma(); - + return retval; - //sprintf(strbuffer, "./plots_from_mixfit/bkgdalitz_%i/", bkgType); - //makeDalitzPlots(bkgPdf, strbuffer); + // sprintf(strbuffer, "./plots_from_mixfit/bkgdalitz_%i/", bkgType); + // makeDalitzPlots(bkgPdf, strbuffer); } void writeBackgroundHistograms(int bkg) { makeFullFitVariables(); - SmoothHistogramPdf* bkg3 = makeBackgroundHistogram(bkg); + SmoothHistogramPdf *bkg3 = makeBackgroundHistogram(bkg); thrust::host_vector host_hist; bkg3->extractHistogram(host_hist); sprintf(strbuffer, "Bkg%i_dalitzhist.txt", bkg); std::string fname = app_ptr->get_filename(strbuffer, "examples/pipipi0DPFit"); writeListOfNumbers(host_hist, fname.c_str()); - } void set_bkg_model_from_string() { @@ -4783,15 +4898,12 @@ void set_bkg_model_from_string() { bkg2Model = Sideband; if(mikhailSetup) { - m23Slices = 1; + m23Slices = 1; gaussBkgTime = true; } - - } void parseArg(GooFit::App *app) { - app->add_option("--luckyFrac", luckyFrac, "", true); app->add_option("--mesonRad", mesonRad, "", true); app->add_option("--normBins", normBinning, "", true); @@ -4828,11 +4940,9 @@ void parseArg(GooFit::App *app) { app->add_option("--varyParameterUp", paramUp, "", true); app->add_option("--varyParameterDn", paramDn, "", true); app->add_flag("--mikhail", mikhailSetup); - } -int main(int argc, char** argv) { - +int main(int argc, char **argv) { gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(10); gStyle->SetFrameFillColor(10); @@ -4845,7 +4955,7 @@ int main(int argc, char** argv) { gStyle->SetLineWidth(1); gStyle->SetLineColor(1); gStyle->SetPalette(1, 0); - foo = new TCanvas(); + foo = new TCanvas(); foodal = new TCanvas(); foodal->Size(10, 10); @@ -4856,106 +4966,76 @@ int main(int argc, char** argv) { app.require_subcommand(); app.add_flag("--minuit1", minuit1, "Use Minuit 1 instead of Minuit 2"); - + std::string data; int sample = 0; - int load = 1; + int load = 1; bool plots; int genResolutions = 0; - double dplotres = 0; - - auto toy = app.add_subcommand("toy", "Toy MC Performance evaluation"); - toy->add_option("-s,--sample,sample", sample, - "Sample number to use", true); - toy->add_option("-l,--load,load", load, - "Number of times to load", true); - toy->add_flag("-p,--plot", plots, - "Also make plots"); - toy->set_callback([&](){ - retval = runToyFit(sample, load, plots); - }); + double dplotres = 0; + auto toy = app.add_subcommand("toy", "Toy MC Performance evaluation"); + toy->add_option("-s,--sample,sample", sample, "Sample number to use", true); + toy->add_option("-l,--load,load", load, "Number of times to load", true); + toy->add_flag("-p,--plot", plots, "Also make plots"); + toy->set_callback([&]() { retval = runToyFit(sample, load, plots); }); auto truth_fit = app.add_subcommand("truth", "Truth Monte Carlo fit"); - truth_fit->add_option("-d,--data,data", data, - "Data to use")->required()->check(GooFit::ExistingFile); - truth_fit->set_callback([&](){ - retval = runTruthMCFit(data, false); - }); - + truth_fit->add_option("-d,--data,data", data, "Data to use")->required()->check(GooFit::ExistingFile); + truth_fit->set_callback([&]() { retval = runTruthMCFit(data, false); }); auto sigma_fit = app.add_subcommand("sigma", "Run sigma fit"); - sigma_fit->add_option("-d,--data,data", data, - "Data to use")->required()->check(GooFit::ExistingFile); - sigma_fit->add_option("-s,--slices,slices", m23Slices, - "m23 slices")->required(); - sigma_fit->set_callback([&](){ - retval = runSigmaFit(data.c_str()); - }); + sigma_fit->add_option("-d,--data,data", data, "Data to use")->required()->check(GooFit::ExistingFile); + sigma_fit->add_option("-s,--slices,slices", m23Slices, "m23 slices")->required(); + sigma_fit->set_callback([&]() { retval = runSigmaFit(data.c_str()); }); auto efficiency_fit = app.add_subcommand("efficiency", "Run efficiency fit"); - efficiency_fit->add_option("-s,--sample,sample", sample, - "Sample number to use", true); - efficiency_fit->set_callback([&](){ - retval = runEfficiencyFit(sample); - }); + efficiency_fit->add_option("-s,--sample,sample", sample, "Sample number to use", true); + efficiency_fit->set_callback([&]() { retval = runEfficiencyFit(sample); }); auto canonical_fit = app.add_subcommand("canonical", "Run the canonical fit"); - canonical_fit->add_option("-d,--data,data", data, - "Data to use")->required()->check(GooFit::ExistingFile); + canonical_fit->add_option("-d,--data,data", data, "Data to use")->required()->check(GooFit::ExistingFile); parseArg(canonical_fit); - canonical_fit->set_callback([&](){ - set_bkg_model_from_string(); - retval = runCanonicalFit(data, !makePlots); - }); + canonical_fit->set_callback([&]() { + set_bkg_model_from_string(); + retval = runCanonicalFit(data, !makePlots); + }); auto background_dalitz_fit = app.add_subcommand("background_dalitz", "Run the background Dalitz fit"); - background_dalitz_fit->add_option("-s,--sample,sample", sample, - "Sample number to use", true); + background_dalitz_fit->add_option("-s,--sample,sample", sample, "Sample number to use", true); parseArg(background_dalitz_fit); - background_dalitz_fit->set_callback([&](){ - set_bkg_model_from_string(); - retval = runBackgroundDalitzFit(sample, true); - }); + background_dalitz_fit->set_callback([&]() { + set_bkg_model_from_string(); + retval = runBackgroundDalitzFit(sample, true); + }); auto background_sigma_fit = app.add_subcommand("background_sigma", "Run background sigma fit"); - background_sigma_fit->add_option("-s,--sample,sample", sample, - "Sample number to use", true); - background_sigma_fit->set_callback([&](){ - retval = runBackgroundSigmaFit(sample); - }); + background_sigma_fit->add_option("-s,--sample,sample", sample, "Sample number to use", true); + background_sigma_fit->set_callback([&]() { retval = runBackgroundSigmaFit(sample); }); auto write_background_histograms = app.add_subcommand("background_histograms", "Write background histograms"); - write_background_histograms->add_option("-s,--sample,sample", sample, - "Sample number to use", true); - write_background_histograms->set_callback([&](){ - writeBackgroundHistograms(sample); - }); + write_background_histograms->add_option("-s,--sample,sample", sample, "Sample number to use", true); + write_background_histograms->set_callback([&]() { writeBackgroundHistograms(sample); }); auto run_gen_mc_fit = app.add_subcommand("run_gen_mc", "Run generated Monte Carlo fit"); - run_gen_mc_fit->add_option("-d,--data,data", data, - "Data to use")->required()->check(GooFit::ExistingFile); + run_gen_mc_fit->add_option("-d,--data,data", data, "Data to use")->required()->check(GooFit::ExistingFile); run_gen_mc_fit->add_option("-g,--genres,gen-resolutions", genResolutions)->required(); run_gen_mc_fit->add_option("-p,--dplotres,dplotres", dplotres); - run_gen_mc_fit->set_callback([&](){ - if(! (DplotRes & genResolutions) ) + run_gen_mc_fit->set_callback([&]() { + if(!(DplotRes & genResolutions)) dplotres = 0; - retval = runGeneratedMCFit(data, genResolutions, dplotres); - }); + retval = runGeneratedMCFit(data, genResolutions, dplotres); + }); auto make_time_plots = app.add_subcommand("make_time_plots", "Make time plots"); - make_time_plots->add_option("-d,--data,data", data, - "Data to use")->required()->check(GooFit::ExistingFile); - make_time_plots->set_callback([&](){ - makeTimePlots(data); - }); + make_time_plots->add_option("-d,--data,data", data, "Data to use")->required()->check(GooFit::ExistingFile); + make_time_plots->set_callback([&]() { makeTimePlots(data); }); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } - return retval; } diff --git a/examples/product/product.cu b/examples/product/product.cu index a9cf65245..6dc3f9baa 100644 --- a/examples/product/product.cu +++ b/examples/product/product.cu @@ -8,24 +8,23 @@ using namespace std; using namespace GooFit; -int main(int argc, char** argv) { - +int main(int argc, char **argv) { GooFit::Application app("Product example", argc, argv); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } - Variable xvar{"xvar", 0, log(1+RAND_MAX/2)}; - Variable yvar{"yvar", 0, log(1+RAND_MAX/2)}; - vector varList = {&xvar, &yvar}; + Variable xvar{"xvar", 0, log(1 + RAND_MAX / 2)}; + Variable yvar{"yvar", 0, log(1 + RAND_MAX / 2)}; + vector varList = {&xvar, &yvar}; UnbinnedDataSet data{varList}; for(int i = 0; i < 100000; ++i) { - xvar.setValue(xvar.getUpperLimit() - log(1+rand()/2)); - yvar.setValue(yvar.getUpperLimit() - log(1+rand()/2)); + xvar.setValue(xvar.getUpperLimit() - log(1 + rand() / 2)); + yvar.setValue(yvar.getUpperLimit() - log(1 + rand() / 2)); data.addEvent(); } @@ -35,7 +34,7 @@ int main(int argc, char** argv) { ExpPdf exp_x{"exp_x", &xvar, &alpha_x}; ExpPdf exp_y{"exp_y", &yvar, &alpha_y}; ProdPdf product{"product", {&exp_x, &exp_y}}; - + product.setData(&data); FitManager fitter(&product); fitter.fit(); diff --git a/examples/simpleFit/simpleFit.cu b/examples/simpleFit/simpleFit.cu index 1dec6c94c..ab31cb57d 100644 --- a/examples/simpleFit/simpleFit.cu +++ b/examples/simpleFit/simpleFit.cu @@ -20,20 +20,20 @@ using namespace GooFit; // CPU-side Novosibirsk evaluation for use in generating toy MC. double novosib(double x, double peak, double width, double tail) { - double qa=0, qb=0, qc=0, qx=0, qy=0; + double qa = 0, qb = 0, qc = 0, qx = 0, qy = 0; if(fabs(tail) < 1.e-7) - qc = 0.5*pow(((x-peak)/width), 2); + qc = 0.5 * pow(((x - peak) / width), 2); else { - qa = tail*sqrt(log(4.)); - qb = sinh(qa)/qa; - qx = (x-peak)/width*qb; - qy = 1.+tail*qx; + qa = tail * sqrt(log(4.)); + qb = sinh(qa) / qa; + qx = (x - peak) / width * qb; + qy = 1. + tail * qx; //---- Cutting curve from right side if(qy > 1.E-7) - qc = 0.5*(pow((log(qy)/tail), 2) + tail*tail); + qc = 0.5 * (pow((log(qy) / tail), 2) + tail * tail); else qc = 15.0; } @@ -43,13 +43,13 @@ double novosib(double x, double peak, double width, double tail) { return exp(-qc); } -TCanvas* foo = 0; +TCanvas *foo = 0; -void fitAndPlot(GooPdf* total, UnbinnedDataSet* data, TH1F& dataHist, Variable* xvar, const char* fname) { +void fitAndPlot(GooPdf *total, UnbinnedDataSet *data, TH1F &dataHist, Variable *xvar, const char *fname) { total->setData(data); FitManager fitter(total); fitter.fit(); - + if(!fitter) std::exit(fitter); @@ -57,7 +57,7 @@ void fitAndPlot(GooPdf* total, UnbinnedDataSet* data, TH1F& dataHist, Variable* pdfHist.SetStats(false); UnbinnedDataSet grid(xvar); - double step = (xvar->getUpperLimit() - xvar->getLowerLimit())/xvar->getNumBins(); + double step = (xvar->getUpperLimit() - xvar->getLowerLimit()) / xvar->getNumBins(); for(int i = 0; i < xvar->getNumBins(); ++i) { xvar->setValue(xvar->getLowerLimit() + (i + 0.5) * step); @@ -65,7 +65,7 @@ void fitAndPlot(GooPdf* total, UnbinnedDataSet* data, TH1F& dataHist, Variable* } total->setData(&grid); - std::vector> pdfVals = total->getCompProbsAtDataPoints(); + std::vector> pdfVals = total->getCompProbsAtDataPoints(); double totalPdf = 0; @@ -76,13 +76,13 @@ void fitAndPlot(GooPdf* total, UnbinnedDataSet* data, TH1F& dataHist, Variable* } for(int i = 0; i < xvar->getNumBins(); ++i) { - double val = pdfHist.GetBinContent(i+1); + double val = pdfHist.GetBinContent(i + 1); val /= totalPdf; val *= data->getNumEvents(); - pdfHist.SetBinContent(i+1, val); + pdfHist.SetBinContent(i + 1, val); } - //foo->SetLogy(true); + // foo->SetLogy(true); dataHist.SetMarkerStyle(8); dataHist.SetMarkerSize(0.5); dataHist.Draw("p"); @@ -92,15 +92,15 @@ void fitAndPlot(GooPdf* total, UnbinnedDataSet* data, TH1F& dataHist, Variable* foo->SaveAs(fname); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app("Simple fit example", argc, argv); size_t numevents = 100000; app.add_option("-n,--num", numevents, "Number of events", true); - + try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -118,7 +118,7 @@ int main(int argc, char** argv) { gStyle->SetPalette(1, 0); // Independent variable. - Variable* xvar = new Variable("xvar", -100, 100); + Variable *xvar = new Variable("xvar", -100, 100); xvar->setNumBins(1000); // For such a large range, want more bins for better accuracy in normalisation. // Data sets for the three fits. @@ -147,12 +147,12 @@ int main(int argc, char** argv) { maxNovo = curr; } - double leftSigma = 13; - double rightSigma = 29; - double leftIntegral = 0.5 / (leftSigma * sqrt(2*M_PI)); - double rightIntegral = 0.5 / (rightSigma * sqrt(2*M_PI)); + double leftSigma = 13; + double rightSigma = 29; + double leftIntegral = 0.5 / (leftSigma * sqrt(2 * M_PI)); + double rightIntegral = 0.5 / (rightSigma * sqrt(2 * M_PI)); double totalIntegral = leftIntegral + rightIntegral; - double bifpoint = -10; + double bifpoint = -10; // Generating three sets of toy MC. while(landdata.getNumEvents() < numevents) { @@ -161,10 +161,11 @@ int main(int argc, char** argv) { xvar->setValue(donram.Landau(20, 1)); landdata.addEvent(); landHist.Fill(xvar->getValue()); - } catch (const GooFit::OutOfRange &) {} + } catch(const GooFit::OutOfRange &) { + } } - - while (bifgdata.getNumEvents() < numevents) { + + while(bifgdata.getNumEvents() < numevents) { // Bifurcated Gaussian double val; if(donram.Uniform() < (leftIntegral / totalIntegral)) { @@ -183,9 +184,8 @@ int main(int argc, char** argv) { bifgdata.addEvent(); bifgHist.Fill(xvar->getValue()); } - - while (novodata.getNumEvents() < numevents) { + while(novodata.getNumEvents() < numevents) { // And Novosibirsk. while(true) { xvar->setValue(donram.Uniform(xvar->getLowerLimit(), xvar->getUpperLimit())); @@ -201,22 +201,21 @@ int main(int argc, char** argv) { foo = new TCanvas(); - Variable* mpv = new Variable("mpv", 40, 0, 150); - Variable* sigma = new Variable("sigma", 5, 0, 30); - GooPdf* landau = new LandauPdf("landau", xvar, mpv, sigma); + Variable *mpv = new Variable("mpv", 40, 0, 150); + Variable *sigma = new Variable("sigma", 5, 0, 30); + GooPdf *landau = new LandauPdf("landau", xvar, mpv, sigma); fitAndPlot(landau, &landdata, landHist, xvar, "landau.png"); - - Variable* nmean = new Variable("nmean", 0.4, -10.0, 10.0); - Variable* nsigm = new Variable("nsigm", 0.6, 0.0, 1.0); - Variable* ntail = new Variable("ntail", 1.1, 0.1, 0.0, 3.0); - GooPdf* novo = new NovosibirskPdf("novo", xvar, nmean, nsigm, ntail); + Variable *nmean = new Variable("nmean", 0.4, -10.0, 10.0); + Variable *nsigm = new Variable("nsigm", 0.6, 0.0, 1.0); + Variable *ntail = new Variable("ntail", 1.1, 0.1, 0.0, 3.0); + GooPdf *novo = new NovosibirskPdf("novo", xvar, nmean, nsigm, ntail); fitAndPlot(novo, &novodata, novoHist, xvar, "novo.png"); - Variable* gmean = new Variable("gmean", 3.0, 1, -15, 15); - Variable* lsigm = new Variable("lsigm", 10, 1, 10, 20); - Variable* rsigm = new Variable("rsigm", 20, 1, 10, 40); - GooPdf* bifur = new BifurGaussPdf("bifur", xvar, gmean, lsigm, rsigm); + Variable *gmean = new Variable("gmean", 3.0, 1, -15, 15); + Variable *lsigm = new Variable("lsigm", 10, 1, 10, 20); + Variable *rsigm = new Variable("rsigm", 20, 1, 10, 40); + GooPdf *bifur = new BifurGaussPdf("bifur", xvar, gmean, lsigm, rsigm); fitAndPlot(bifur, &bifgdata, bifgHist, xvar, "bifur.png"); return 0; diff --git a/examples/zachFit/zachFit.cu b/examples/zachFit/zachFit.cu index 36aff2cba..685ce194e 100644 --- a/examples/zachFit/zachFit.cu +++ b/examples/zachFit/zachFit.cu @@ -29,8 +29,8 @@ using namespace fmt::literals; using namespace GooFit; -TH1D* getMCData(DataSet *data, Variable* var, std::string filename) { - TH1D* mchist = new TH1D{"mc_hist", "", 300, 0.1365, 0.1665}; +TH1D *getMCData(DataSet *data, Variable *var, std::string filename) { + TH1D *mchist = new TH1D{"mc_hist", "", 300, 0.1365, 0.1665}; std::ifstream mcreader{filename}; while(mcreader >> *var) { @@ -50,8 +50,8 @@ TH1D* getMCData(DataSet *data, Variable* var, std::string filename) { return mchist; } -TH1D* getData(DataSet* data, Variable *var, std::string filename) { - TH1D* data_hist = new TH1D("data_hist", "", 300, 0.1365, 0.1665); +TH1D *getData(DataSet *data, Variable *var, std::string filename) { + TH1D *data_hist = new TH1D("data_hist", "", 300, 0.1365, 0.1665); std::ifstream datareader{filename}; while(datareader >> *var) { @@ -72,21 +72,18 @@ TH1D* getData(DataSet* data, Variable *var, std::string filename) { return data_hist; } - -int main(int argc, char** argv) { +int main(int argc, char **argv) { GooFit::Application app{"Zach-Fit example", argc, argv}; - - int mode=0, data = 0; + + int mode = 0, data = 0; bool plot; - app.add_set("-m,--mode,mode", mode, {0,1,2}, - "Program mode: 0-unbinned, 1-binned, 2-binned chisq"); - app.add_set("-d,--data,data", data, {0,1,2}, - "Dataset: 0-simple, 1-kpi, 2-k3pi"); + app.add_set("-m,--mode,mode", mode, {0, 1, 2}, "Program mode: 0-unbinned, 1-binned, 2-binned chisq"); + app.add_set("-d,--data,data", data, {0, 1, 2}, "Dataset: 0-simple, 1-kpi, 2-k3pi"); app.add_flag("-p,--plot", plot, "Make and save plots of results"); try { app.run(); - } catch (const GooFit::ParseError &e) { + } catch(const GooFit::ParseError &e) { return app.exit(e); } @@ -103,17 +100,16 @@ int main(int argc, char** argv) { gStyle->SetLineWidth(1); gStyle->SetLineColor(1); gStyle->SetPalette(1, 0); - + TCanvas foo; foo.SetLogy(true); - // Get the name of the files to use std::string mcfile, datafile; - if (data == 0) { + if(data == 0) { mcfile = app.get_filename("dataFiles/dstwidth_kpi_resMC.dat", "examples/zachFit"); datafile = app.get_filename("dataFiles/dstwidth_kpi_data.dat", "examples/zachFit"); - } else if (data == 1) { + } else if(data == 1) { mcfile = app.get_filename("dataFiles/DstarWidth_D0ToKpi_deltaM_MC.dat", "examples/zachFit"); datafile = app.get_filename("dataFiles/DstarWidth_D0ToKpi_deltaM_Data.dat", "examples/zachFit"); } else { @@ -135,7 +131,7 @@ int main(int argc, char** argv) { data_dataset.reset(new BinnedDataSet{&dm}); } - TH1D* mc_hist = getMCData(mc_dataset.get(), &dm, mcfile); + TH1D *mc_hist = getMCData(mc_dataset.get(), &dm, mcfile); Variable mean1("kpi_mc_mean1", 0.145402, 0.00001, 0.143, 0.148); Variable mean2("kpi_mc_mean2", 0.145465, 0.00001, 0.145, 0.1465); @@ -157,13 +153,10 @@ int main(int argc, char** argv) { GaussianPdf gauss3("gauss3", &dm, &mean3, &sigma3); ArgusPdf argus("argus", &dm, &pimass, &aslope, false, &apower); + AddPdf resolution{"resolution", {&gfrac1, &gfrac2, &afrac}, {&gauss1, &gauss2, &argus, &gauss3}}; - AddPdf resolution{"resolution", - {&gfrac1, &gfrac2, &afrac}, - {&gauss1, &gauss2, &argus, &gauss3}}; - resolution.setData(mc_dataset.get()); - + FitManager mcpdf{&resolution}; GOOFIT_INFO("Done with collecting MC, starting minimisation"); @@ -174,15 +167,15 @@ int main(int argc, char** argv) { mc_hist->SetLineColor(kBlack); mc_hist->Draw("e"); - double step = mc_hist->GetXaxis()->GetBinWidth(2); - auto tot_hist = resolution.plotToROOT(&dm, mc_dataset->getNumEvents()*step); + double step = mc_hist->GetXaxis()->GetBinWidth(2); + auto tot_hist = resolution.plotToROOT(&dm, mc_dataset->getNumEvents() * step); tot_hist->SetLineColor(kGreen); - + tot_hist->Draw("SAME"); foo.SaveAs("MC_plot.png"); } - + // Locking the MC variables mean1.setFixed(true); mean2.setFixed(true); @@ -218,27 +211,23 @@ int main(int argc, char** argv) { signal2.setIntegrationConstants(0.1395, 0.1665, 0.0000027); signal3.setIntegrationConstants(0.1395, 0.1665, 0.0000027); - AddPdf signal{"signal", - {&gfrac1, &gfrac2, &afrac}, - {&signal1, &signal2, &argus, &signal3}}; + AddPdf signal{"signal", {&gfrac1, &gfrac2, &afrac}, {&signal1, &signal2, &argus, &signal3}}; Variable slope("kpi_rd_slope", -1.0, 0.1, -35.0, 25.0); - Variable* bpower = nullptr; + Variable *bpower = nullptr; ArgusPdf bkg("bkg", &dm, &pimass, &slope, false, bpower); Variable bkg_frac("kpi_rd_bkg_frac", 0.03, 0.0, 0.3); - TH1D* data_hist = getData(data_dataset.get(), &dm, datafile); + TH1D *data_hist = getData(data_dataset.get(), &dm, datafile); - AddPdf total("total", - {&bkg_frac}, - {&bkg, &signal}); + AddPdf total("total", {&bkg_frac}, {&bkg, &signal}); total.setData(data_dataset.get()); std::unique_ptr chi_control; if(2 == mode) { - chi_control.reset(new BinnedChisqFit); + chi_control.reset(new BinnedChisqFit); total.setFitControl(chi_control.get()); } @@ -247,18 +236,18 @@ int main(int argc, char** argv) { GOOFIT_INFO("Starting fit"); datapdf.fit(); - + if(plot) { GOOFIT_INFO("Plotting results"); - + data_hist->SetLineColor(kBlack); data_hist->Draw("e"); - + double scale = data_hist->GetXaxis()->GetBinWidth(2) * data_dataset->getNumEvents(); - auto sig_hist = signal.plotToROOT(&dm, (1 - bkg_frac.getValue())*scale); + auto sig_hist = signal.plotToROOT(&dm, (1 - bkg_frac.getValue()) * scale); sig_hist->SetLineColor(kBlue); - auto back_hist =bkg.plotToROOT(&dm, bkg_frac.getValue()*scale); + auto back_hist = bkg.plotToROOT(&dm, bkg_frac.getValue() * scale); back_hist->SetLineColor(kRed); auto tot_hist = total.plotToROOT(&dm, scale); tot_hist->SetLineColor(kGreen); @@ -269,6 +258,6 @@ int main(int argc, char** argv) { foo.SaveAs("ResultFit.png"); } - + return datapdf; } diff --git a/extern/CLI11 b/extern/CLI11 index eedb6771b..d697cb6d8 160000 --- a/extern/CLI11 +++ b/extern/CLI11 @@ -1 +1 @@ -Subproject commit eedb6771be9b1319aea1daed89a505385e119d79 +Subproject commit d697cb6d855d1a90310950ad46c8ef470ad18438 diff --git a/extern/FeatureDetector b/extern/FeatureDetector index 8618f3137..55fe217f6 160000 --- a/extern/FeatureDetector +++ b/extern/FeatureDetector @@ -1 +1 @@ -Subproject commit 8618f3137ce354de2c0c131d7668d1dab7a51662 +Subproject commit 55fe217f66cc39f77c35f149e0488c575ce3cdff diff --git a/extern/MCBooster/mcbooster/Config.h b/extern/MCBooster/mcbooster/Config.h index 289e3e26e..fe6e8e9d1 100644 --- a/extern/MCBooster/mcbooster/Config.h +++ b/extern/MCBooster/mcbooster/Config.h @@ -33,32 +33,29 @@ #define TBB 3 #define CPP 4 -#if (__cplusplus < 201103L) +#if(__cplusplus < 201103L) #error "This library needs a C++11 compliant compiler" #endif - #ifndef MCBOOSTER_BACKEND - #define MCBOOSTER_BACKEND CUDA +#define MCBOOSTER_BACKEND CUDA #endif - -#if MCBOOSTER_BACKEND!=CUDA && MCBOOSTER_BACKEND!=OMP && MCBOOSTER_BACKEND!=TBB && MCBOOSTER_BACKEND!=CPP +#if MCBOOSTER_BACKEND != CUDA && MCBOOSTER_BACKEND != OMP && MCBOOSTER_BACKEND != TBB && MCBOOSTER_BACKEND != CPP #error "MCBooster: Backend not supported. MCBOOSTER_BACKEND = CUDA, OMP, TBB, or CPP" #endif -#if MCBOOSTER_BACKEND==CUDA - #define CUDA_API_PER_THREAD_DEFAULT_STREAM - #include - #include - #include -#elif MCBOOSTER_BACKEND!=CPP +#if MCBOOSTER_BACKEND == CUDA +#define CUDA_API_PER_THREAD_DEFAULT_STREAM +#include +#include +#include +#elif MCBOOSTER_BACKEND != CPP #include #endif - #include #endif /* CONFIG_H_ */ diff --git a/extern/MCBooster/mcbooster/Evaluate.h b/extern/MCBooster/mcbooster/Evaluate.h index 417fbd64b..f8ecdcc25 100644 --- a/extern/MCBooster/mcbooster/Evaluate.h +++ b/extern/MCBooster/mcbooster/Evaluate.h @@ -31,7 +31,6 @@ #ifndef EVALUATE_H_ #define EVALUATE_H_ - #include #include #include @@ -39,462 +38,428 @@ #include #include -namespace mcbooster -{ +namespace mcbooster { /** Template functor for evaluate an arbitrary function object. * Template functor for evaluate an arbitrary function object over the a set of particles stored * in the device. Results are returned to the __host__ via a given mc_host_vector. Datasets with up to nine particles * can be handled. */ template -void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, - mc_host_vector &eval) -{ - - if (pset.size() > 10 || pset.size() < 2) - { - std::cout - << "Can not Calculate(Eval) more than a nine-particle invariant mass." - << std::endl; - return; - } - - mc_device_vector dev_out(eval.begin(), eval.end()); - - if (pset.size() == 2) - { - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 3) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 4) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 5) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 6) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 7) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 8) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 9) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 10) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - mc_device_vector *dev_v9 = pset[9]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin(), dev_v9->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end(), dev_v9->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - thrust::copy(dev_out.begin(), dev_out.end(), eval.begin()); - - return; +void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, mc_host_vector &eval) { + if(pset.size() > 10 || pset.size() < 2) { + std::cout << "Can not Calculate(Eval) more than a nine-particle invariant mass." << std::endl; + return; + } + + mc_device_vector dev_out(eval.begin(), eval.end()); + + if(pset.size() == 2) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 3) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 4) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + + thrust::transform( + thrust::make_zip_iterator( + thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 5) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 6) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin(), dev_v5->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end(), dev_v5->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 7) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 8) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 9) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 10) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + mc_device_vector *dev_v9 = pset[9]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin(), + dev_v9->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end(), + dev_v9->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + thrust::copy(dev_out.begin(), dev_out.end(), eval.begin()); + + return; } /** Template functor for evaluate an arbitrary function object. * Template functor for evaluate an arbitrary function object over the a set of particles stored - * in the device. Results are returned to the __device__ via a given mc_device_vector. Datasets with up to nine particles + * in the device. Results are returned to the __device__ via a given mc_device_vector. Datasets with up to nine + * particles * can be handled. */ template -void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, - mc_device_vector dev_out) -{ - - if (pset.size() > 10 || pset.size() < 2) - { - std::cout - << "Can not Calculate(Eval) more than a nine-particle invariant mass." - << std::endl; - return; - } - - if (pset.size() == 2) - { - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 3) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 4) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 5) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 6) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 7) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 8) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end())), - dev_out.begin(), Calculate(funcObj)); - - } - - if (pset.size() == 9) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - if (pset.size() == 10) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - mc_device_vector *dev_v9 = pset[9]; - - thrust::transform( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin(), dev_v9->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end(), dev_v9->end())), dev_out.begin(), - Calculate(funcObj)); - - } - - return; +void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, mc_device_vector dev_out) { + if(pset.size() > 10 || pset.size() < 2) { + std::cout << "Can not Calculate(Eval) more than a nine-particle invariant mass." << std::endl; + return; + } + + if(pset.size() == 2) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 3) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 4) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + + thrust::transform( + thrust::make_zip_iterator( + thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 5) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 6) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin(), dev_v5->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end(), dev_v5->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 7) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 8) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 9) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + if(pset.size() == 10) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + mc_device_vector *dev_v9 = pset[9]; + + thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin(), + dev_v9->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end(), + dev_v9->end())), + dev_out.begin(), + Calculate(funcObj)); + } + + return; } /** Template functor for evaluate an arbitrary function object. @@ -503,226 +468,199 @@ void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, * Datasets with up to nine particles can be handled. */ template -void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset) -{ - - if (pset.size() > 10 || pset.size() < 2) - { - std::cout - << "Can not Calculate(Eval) more than a nine-particle invariant mass." - << std::endl; - return; - } - - if (pset.size() == 2) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 3) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 4) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 5) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 6) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 7) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 8) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 9) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end())), - Calculate2(funcObj)); - - } - - if (pset.size() == 10) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - mc_device_vector *dev_v9 = pset[9]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), - dev_v2->begin(), dev_v3->begin(), - dev_v4->begin(), dev_v5->begin(), - dev_v6->begin(), dev_v7->begin(), - dev_v8->begin(), dev_v9->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(dev_v0->end(), dev_v1->end(), - dev_v2->end(), dev_v3->end(), dev_v4->end(), - dev_v5->end(), dev_v6->end(), dev_v7->end(), - dev_v8->end(), dev_v9->end())), - Calculate2(funcObj)); - - } - - return; +void Evaluate(const CUSTOMFUNC funcObj, ParticlesSet_d &pset) { + if(pset.size() > 10 || pset.size() < 2) { + std::cout << "Can not Calculate(Eval) more than a nine-particle invariant mass." << std::endl; + return; + } + + if(pset.size() == 2) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 3) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 4) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + + thrust::for_each( + thrust::make_zip_iterator( + thrust::make_tuple(dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 5) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 6) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin(), dev_v5->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end(), dev_v5->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 7) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 8) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 9) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + Calculate2(funcObj)); + } + + if(pset.size() == 10) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + mc_device_vector *dev_v9 = pset[9]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin(), + dev_v9->begin())), + thrust::make_zip_iterator(thrust::make_tuple(dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end(), + dev_v9->end())), + Calculate2(funcObj)); + } + + return; } - } #endif /* EVALUATE_H_ */ diff --git a/extern/MCBooster/mcbooster/EvaluateArray.h b/extern/MCBooster/mcbooster/EvaluateArray.h index 19f988f12..47f5fce0f 100644 --- a/extern/MCBooster/mcbooster/EvaluateArray.h +++ b/extern/MCBooster/mcbooster/EvaluateArray.h @@ -30,7 +30,6 @@ #ifndef EVALUATEARRAY_H_ #define EVALUATEARRAY_H_ - #include #include #include @@ -39,8 +38,7 @@ #include #include -namespace mcbooster -{ +namespace mcbooster { /** Template functor for calculate an array of variables over a given set of particles. * Template functor for evaluate an arbitrary function object over the a set of particles stored @@ -49,280 +47,254 @@ namespace mcbooster */ template -void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, - VariableSet_h &varset) -{ - - if (pset.size() > 10 || pset.size() < 2) - { - std::cout - << "Can not Calculate(Eval) more than a nine-particle invariant mass." - <size(); - - RealVector_d dev_array(arrayWidth * numberEvents); - - strided_range it_array(dev_array.begin(), - dev_array.end(), arrayWidth); - - if (pset.size() == 2) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 3) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 4) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 5) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 6) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 7) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 8) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 9) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin(), dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end(), dev_v8->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 10) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin(), dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end(), dev_v8->end())), - Calculate3(funcObj)); - - } - - -#if MCBOOSTER_BACKEND!=CUDA -#if MCBOOSTER_BACKEND!=CPP -#pragma omp parallel num_threads( arrayWidth ) -{ +void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, VariableSet_h &varset) { + if(pset.size() > 10 || pset.size() < 2) { + std::cout << "Can not Calculate(Eval) more than a nine-particle invariant mass." << std::endl; + return; + } + + GInt_t arrayWidth = varset.size(); + GLong_t numberEvents = varset[0]->size(); + + RealVector_d dev_array(arrayWidth * numberEvents); + + strided_range it_array(dev_array.begin(), dev_array.end(), arrayWidth); + + if(pset.size() == 2) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), dev_v0->begin(), dev_v1->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), dev_v0->end(), dev_v1->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 3) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + + thrust::for_each( + thrust::make_zip_iterator( + thrust::make_tuple(it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 4) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple( + it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 5) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple( + it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 6) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 7) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 8) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 9) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 10) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + Calculate3(funcObj)); + } + +#if MCBOOSTER_BACKEND != CUDA +#if MCBOOSTER_BACKEND != CPP +#pragma omp parallel num_threads(arrayWidth) + { #else - for(size_t val = 0; val it_array(dev_array.begin() + omp_get_thread_num() - , dev_array.end(), arrayWidth); + strided_range it_array( + dev_array.begin() + omp_get_thread_num(), dev_array.end(), arrayWidth); - thrust::copy(it_array.begin(),it_array.end(), - varset[omp_get_thread_num()]->begin()); - } + thrust::copy(it_array.begin(), it_array.end(), varset[omp_get_thread_num()]->begin()); + } #else - cudaStream_t s[arrayWidth]; - - for (GInt_t d = 0; d < arrayWidth; d++) - { - cudaStreamCreate(&s[d]); - - } - strided_range *it[arrayWidth]; - for (GInt_t d = 0; d < arrayWidth; d++) - it[d] = new strided_range(dev_array.begin() + d, - dev_array.end(), arrayWidth); - for (GInt_t d = 0; d < arrayWidth; d++) - { - - thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(), - varset[d]->begin()); - - } - cudaDeviceSynchronize(); - for (GInt_t d = 0; d < arrayWidth; d++) - cudaStreamDestroy(s[d]); - for (GInt_t d = 0; d < arrayWidth; d++) - delete it[d]; + cudaStream_t s[arrayWidth]; + + for(GInt_t d = 0; d < arrayWidth; d++) { + cudaStreamCreate(&s[d]); + } + strided_range *it[arrayWidth]; + for(GInt_t d = 0; d < arrayWidth; d++) + it[d] = new strided_range(dev_array.begin() + d, dev_array.end(), arrayWidth); + for(GInt_t d = 0; d < arrayWidth; d++) { + thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(), varset[d]->begin()); + } + cudaDeviceSynchronize(); + for(GInt_t d = 0; d < arrayWidth; d++) + cudaStreamDestroy(s[d]); + for(GInt_t d = 0; d < arrayWidth; d++) + delete it[d]; #endif - return; + return; } //#if MCBOOSTER_BACKEND==CUDA @@ -330,288 +302,263 @@ void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, /** Template functor for calculate an array of variables over a given set of particles. * Template functor for evaluate an arbitrary function object over the a set of particles stored * in the device. The function is supposed to evaluate at once many variables and the results are returned to the - * __device__ via a given VariableSet_h. Datasets with up to nine particles can be handled. __This function is available + * __device__ via a given VariableSet_h. Datasets with up to nine particles can be handled. __This function is + * available * only for CUDA SYSTEMs.__ */ template -void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, - VariableSet_d &varset) -{ - - if (pset.size() > 10 || pset.size() < 2) - { - std::cout - << "Can not Calculate(Eval) more than a nine-particle invariant mass." - <size(); - - RealVector_d dev_array(arrayWidth * numberEvents); - - strided_range it_array(dev_array.begin(), - dev_array.end(), arrayWidth); - - if (pset.size() == 2) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 3) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 4) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 5) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 6) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 7) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 8) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 9) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin(), dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end(), dev_v8->end())), - Calculate3(funcObj)); - - } - - if (pset.size() == 10) - { - - mc_device_vector *dev_v0 = pset[0]; - mc_device_vector *dev_v1 = pset[1]; - mc_device_vector *dev_v2 = pset[2]; - mc_device_vector *dev_v3 = pset[3]; - mc_device_vector *dev_v4 = pset[4]; - mc_device_vector *dev_v5 = pset[5]; - mc_device_vector *dev_v6 = pset[6]; - mc_device_vector *dev_v7 = pset[7]; - mc_device_vector *dev_v8 = pset[8]; - - thrust::for_each( - thrust::make_zip_iterator( - thrust::make_tuple(it_array.begin(), dev_v0->begin(), - dev_v1->begin(), dev_v2->begin(), - dev_v3->begin(), dev_v4->begin(), - dev_v5->begin(), dev_v6->begin(), - dev_v7->begin(), dev_v8->begin())), - thrust::make_zip_iterator( - thrust::make_tuple(it_array.end(), dev_v0->end(), - dev_v1->end(), dev_v2->end(), dev_v3->end(), - dev_v4->end(), dev_v5->end(), dev_v6->end(), - dev_v7->end(), dev_v8->end())), - Calculate3(funcObj)); - - } -#if MCBOOSTER_BACKEND!=CUDA -#if MCBOOSTER_BACKEND!=CPP -#pragma omp parallel num_threads( arrayWidth ) -{ +void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, VariableSet_d &varset) { + if(pset.size() > 10 || pset.size() < 2) { + std::cout << "Can not Calculate(Eval) more than a nine-particle invariant mass." << std::endl; + return; + } + + GInt_t arrayWidth = varset.size(); + GLong_t numberEvents = varset[0]->size(); + + RealVector_d dev_array(arrayWidth * numberEvents); + + strided_range it_array(dev_array.begin(), dev_array.end(), arrayWidth); + + if(pset.size() == 2) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), dev_v0->begin(), dev_v1->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), dev_v0->end(), dev_v1->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 3) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + + thrust::for_each( + thrust::make_zip_iterator( + thrust::make_tuple(it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 4) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple( + it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 5) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + + thrust::for_each( + thrust::make_zip_iterator(thrust::make_tuple( + it_array.begin(), dev_v0->begin(), dev_v1->begin(), dev_v2->begin(), dev_v3->begin(), dev_v4->begin())), + thrust::make_zip_iterator(thrust::make_tuple( + it_array.end(), dev_v0->end(), dev_v1->end(), dev_v2->end(), dev_v3->end(), dev_v4->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 6) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 7) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 8) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 9) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + Calculate3(funcObj)); + } + + if(pset.size() == 10) { + mc_device_vector *dev_v0 = pset[0]; + mc_device_vector *dev_v1 = pset[1]; + mc_device_vector *dev_v2 = pset[2]; + mc_device_vector *dev_v3 = pset[3]; + mc_device_vector *dev_v4 = pset[4]; + mc_device_vector *dev_v5 = pset[5]; + mc_device_vector *dev_v6 = pset[6]; + mc_device_vector *dev_v7 = pset[7]; + mc_device_vector *dev_v8 = pset[8]; + + thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(it_array.begin(), + dev_v0->begin(), + dev_v1->begin(), + dev_v2->begin(), + dev_v3->begin(), + dev_v4->begin(), + dev_v5->begin(), + dev_v6->begin(), + dev_v7->begin(), + dev_v8->begin())), + thrust::make_zip_iterator(thrust::make_tuple(it_array.end(), + dev_v0->end(), + dev_v1->end(), + dev_v2->end(), + dev_v3->end(), + dev_v4->end(), + dev_v5->end(), + dev_v6->end(), + dev_v7->end(), + dev_v8->end())), + Calculate3(funcObj)); + } +#if MCBOOSTER_BACKEND != CUDA +#if MCBOOSTER_BACKEND != CPP +#pragma omp parallel num_threads(arrayWidth) + { #else - for(size_t val = 0; val it_array(dev_array.begin() + omp_get_thread_num() - , dev_array.end(), arrayWidth); + strided_range it_array( + dev_array.begin() + omp_get_thread_num(), dev_array.end(), arrayWidth); - thrust::copy(it_array.begin(),it_array.end(), - varset[omp_get_thread_num()]->begin()); - } + thrust::copy(it_array.begin(), it_array.end(), varset[omp_get_thread_num()]->begin()); + } #else - cudaStream_t s[arrayWidth]; - - for (GInt_t d = 0; d < arrayWidth; d++) - { - cudaStreamCreate(&s[d]); - - } - strided_range *it[arrayWidth]; - for (GInt_t d = 0; d < arrayWidth; d++) - it[d] = new strided_range(dev_array.begin() + d, - dev_array.end(), arrayWidth); - for (GInt_t d = 0; d < arrayWidth; d++) - { - - thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(), - varset[d]->begin()); - - } - cudaDeviceSynchronize(); - for (GInt_t d = 0; d < arrayWidth; d++) - cudaStreamDestroy(s[d]); - for (GInt_t d = 0; d < arrayWidth; d++) - delete it[d]; + cudaStream_t s[arrayWidth]; + + for(GInt_t d = 0; d < arrayWidth; d++) { + cudaStreamCreate(&s[d]); + } + strided_range *it[arrayWidth]; + for(GInt_t d = 0; d < arrayWidth; d++) + it[d] = new strided_range(dev_array.begin() + d, dev_array.end(), arrayWidth); + for(GInt_t d = 0; d < arrayWidth; d++) { + thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(), varset[d]->begin()); + } + cudaDeviceSynchronize(); + for(GInt_t d = 0; d < arrayWidth; d++) + cudaStreamDestroy(s[d]); + for(GInt_t d = 0; d < arrayWidth; d++) + delete it[d]; #endif - return; + return; } //#endif - } #endif /* EVALUATEARRAY_H_ */ diff --git a/extern/MCBooster/mcbooster/GContainers.h b/extern/MCBooster/mcbooster/GContainers.h index 51910232d..895133ae9 100644 --- a/extern/MCBooster/mcbooster/GContainers.h +++ b/extern/MCBooster/mcbooster/GContainers.h @@ -32,7 +32,6 @@ #ifndef GCONTAINERS_H_ #define GCONTAINERS_H_ - #include #include #include @@ -42,210 +41,366 @@ #include #include -#if MCBOOSTER_BACKEND==CUDA +#if MCBOOSTER_BACKEND == CUDA #include #endif -namespace mcbooster -{ +namespace mcbooster { -#if (MCBOOSTER_BACKEND==OMP || MCBOOSTER_BACKEND==CPP) +#if(MCBOOSTER_BACKEND == OMP || MCBOOSTER_BACKEND == CPP) /*! * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. */ - template - using mc_device_vector = thrust::device_vector; +template +using mc_device_vector = thrust::device_vector; /*! * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. * mc_host_vectot will always allocate page locked memory on CUDA SYSTEMs in order to maximize speed in memory transfers * to the device. */ - template - using mc_host_vector = thrust::host_vector; - -#elif(MCBOOSTER_BACKEND==CUDA) - /*! - * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation - * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. - */ - template - using mc_device_vector = thrust::device_vector; - /*! - * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation - * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. - * mc_host_vectot will always allocate page locked memory on CUDA SYSTEMs in order to maximize speed in memory transfers - * to the device. - */ - template - using mc_host_vector = thrust::host_vector>; - -#elif(MCBOOSTER_BACKEND==TBB) - /*! - * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation - * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. - */ - template - using mc_device_vector = thrust::device_vector; - /*! - * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation - * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. - * mc_host_vectot will always allocate page locked memory on CUDA SYSTEMs in order to maximize speed in memory transfers - * to the device. - */ - template - using mc_host_vector = thrust::host_vector; -#endif +template +using mc_host_vector = thrust::host_vector; +#elif(MCBOOSTER_BACKEND == CUDA) +/*! + * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation + * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. + */ +template +using mc_device_vector = thrust::device_vector; +/*! + * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation + * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. + * mc_host_vectot will always allocate page locked memory on CUDA SYSTEMs in order to maximize speed in memory transfers + * to the device. + */ +template +using mc_host_vector = thrust::host_vector>; + +#elif(MCBOOSTER_BACKEND == TBB) +/*! + * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation + * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. + */ +template +using mc_device_vector = thrust::device_vector; +/*! + * Generic template typedef for thrust::host_vector. Use it instead of Thrust implementation + * in order to avoid problems to compile OpenMP based applications using gcc and without a cuda runtime installation. + * mc_host_vectot will always allocate page locked memory on CUDA SYSTEMs in order to maximize speed in memory transfers + * to the device. + */ +template +using mc_host_vector = thrust::host_vector; +#endif //----------------------------------------------------------------------- -//complex number container +// complex number container typedef thrust::complex GComplex_t; /*! Typedef for complex number.*/ //----------------------------------------------------------------------- -typedef mc_host_vector FourVectors_h; /*! Vector4R host vector. Use it to store four-vectors at __host__.*/ +typedef mc_host_vector FourVectors_h; /*! Vector4R host vector. Use it to store four-vectors at __host__.*/ typedef mc_host_vector ThreeVectors_h; /*! Vector3R host vector. Use it to store four-vectors at __host__.*/ //----------------------------------------------------------------------- -//basic containers on host +// basic containers on host -typedef mc_host_vector BoolVector_h; /*! Typedef for a GBool_t host vector.*/ -typedef mc_host_vector RealVector_h; /*! Typedef for a GReal_t host vector.*/ +typedef mc_host_vector BoolVector_h; /*! Typedef for a GBool_t host vector.*/ +typedef mc_host_vector RealVector_h; /*! Typedef for a GReal_t host vector.*/ typedef mc_host_vector ComplexVector_h; /*! Typedef for a GComplex_t host vector.*/ -typedef mc_host_vector Particles_h;/*! Typedef for a Vector4R host vector.*/ -typedef std::vector ParticlesSet_h;/*! Typedef for a STL vector of pointers to host Particles_h vectors .*/ -typedef std::vector VariableSet_h;/*! Typedef for a STL vector of pointers to host RealVector_h vectors.*/ - +typedef mc_host_vector Particles_h; /*! Typedef for a Vector4R host vector.*/ +typedef std::vector + ParticlesSet_h; /*! Typedef for a STL vector of pointers to host Particles_h vectors .*/ +typedef std::vector + VariableSet_h; /*! Typedef for a STL vector of pointers to host RealVector_h vectors.*/ //----------------------------------------------------------------------- -//basic containers on device -typedef mc_device_vector BoolVector_d; /*! Typedef for a GBool_t device vector.*/ -typedef mc_device_vector RealVector_d; /*! Typedef for a GReal_t device vector.*/ +// basic containers on device +typedef mc_device_vector BoolVector_d; /*! Typedef for a GBool_t device vector.*/ +typedef mc_device_vector RealVector_d; /*! Typedef for a GReal_t device vector.*/ typedef mc_device_vector ComplexVector_d; /*! Typedef for a GComplex_t device vector.*/ -typedef mc_device_vector Particles_d; /*! Typedef for a Vector4R device vector.*/ -typedef std::vector ParticlesSet_d; /*! Typedef for a STL vector of pointers to device Particles_d vectors.*/ -typedef std::vector VariableSet_d; /*! Typedef for a STL vector of pointers to device RealVector_d vectors.*/ - +typedef mc_device_vector Particles_d; /*! Typedef for a Vector4R device vector.*/ +typedef std::vector + ParticlesSet_d; /*! Typedef for a STL vector of pointers to device Particles_d vectors.*/ +typedef std::vector + VariableSet_d; /*! Typedef for a STL vector of pointers to device RealVector_d vectors.*/ /*! GT1 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ typedef thrust::detail::tuple_of_iterator_references GT1; + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type, + thrust::null_type> + GT1; /*! GT2 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT2; - -/*! GT3 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT3; - -/*! GT4 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT4; - -/*! GT5 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GT5; - -/*! GT6 iterator is a typedef for thrust::detail::tuple_of_iterator_references + GT2; + +/*! GT3 iterator is a typedef for thrust::detail::tuple_of_iterator_references + */ +typedef thrust::detail::tuple_of_iterator_references + GT3; + +/*! GT4 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ +typedef thrust::detail::tuple_of_iterator_references + GT4; + +/*! GT5 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GT5; + +/*! GT6 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT6; - -/*! GT7 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT7; - -/*!GT8 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT8; - -/*! GT9 iterator is a typedef for thrust::detail::tuple_of_iterator_references + GT6; + +/*! GT7 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ +typedef thrust::detail::tuple_of_iterator_references + GT7; + +/*!GT8 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ +typedef thrust::detail::tuple_of_iterator_references + GT8; + +/*! GT9 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT9; - -/*! GT10 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GT10; +typedef thrust::detail::tuple_of_iterator_references + GT9; + +/*! GT10 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ +typedef thrust::detail::tuple_of_iterator_references + GT10; /*! * * GTR2 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GTR2; +typedef thrust::detail::tuple_of_iterator_references + GTR2; /*! * * GTR3 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GTR3; +typedef thrust::detail::tuple_of_iterator_references + GTR3; /*! * - * GTR4 iterator is a typedef for thrust::detail::tuple_of_iterator_references + * GTR4 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GTR4; +typedef thrust::detail::tuple_of_iterator_references + GTR4; /*! * - * GTR5 iterator is a typedef for thrust::detail::tuple_of_iterator_references + * GTR5 iterator is a typedef for thrust::detail::tuple_of_iterator_references */ -typedef thrust::detail::tuple_of_iterator_references GTR5; - -/*! GTR6 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GTR6; - -/*! GTR7 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GTR7; - -/*! GTR8 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GTR8; - -/*!GTR9 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GTR9; - -/*! GTR10 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ -typedef thrust::detail::tuple_of_iterator_references GTR10; - +typedef thrust::detail::tuple_of_iterator_references + GTR5; + +/*! GTR6 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GTR6; + +/*! GTR7 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GTR7; + +/*! GTR8 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GTR8; + +/*!GTR9 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GTR9; + +/*! GTR10 iterator is a typedef for thrust::detail::tuple_of_iterator_references*/ +typedef thrust::detail::tuple_of_iterator_references + GTR10; } #endif /* GCONTAINERS_H_ */ diff --git a/extern/MCBooster/mcbooster/GFunctional.h b/extern/MCBooster/mcbooster/GFunctional.h index 09343479e..da9cb2eb4 100644 --- a/extern/MCBooster/mcbooster/GFunctional.h +++ b/extern/MCBooster/mcbooster/GFunctional.h @@ -28,39 +28,29 @@ #ifndef GFUNCTIONAL_H_ #define GFUNCTIONAL_H_ - #include #include #include #include -namespace mcbooster -{ +namespace mcbooster { /** \struct IFunction * IFunction is the base class for arbitrary functions return any type suported by the framwork. */ template -struct IFunction -{ - - __host__ __device__ virtual RESULT operator()(const GInt_t n, - Vector4R** particles)=0; - +struct IFunction { + __host__ __device__ virtual RESULT operator()(const GInt_t n, Vector4R **particles) = 0; }; /** \struct IFunction * IFunctionArray is the base class for arbitrary functions used to evaluate at once an array of variables. */ -struct IFunctionArray -{ - GInt_t dim{0}; - IFunctionArray() = default; - - __host__ __device__ virtual void operator()(const GInt_t np, - Vector4R** particles, GReal_t* variables)=0; +struct IFunctionArray { + GInt_t dim{0}; + IFunctionArray() = default; + __host__ __device__ virtual void operator()(const GInt_t np, Vector4R **particles, GReal_t *variables) = 0; }; - } #endif /* GFUNCTIONAL_H_ */ diff --git a/extern/MCBooster/mcbooster/GTypes.h b/extern/MCBooster/mcbooster/GTypes.h index 2ddad2462..59c45f73c 100644 --- a/extern/MCBooster/mcbooster/GTypes.h +++ b/extern/MCBooster/mcbooster/GTypes.h @@ -22,44 +22,40 @@ * along with MCBooster. If not, see . */ - #ifndef GTYPES_H_ #define GTYPES_H_ -namespace mcbooster -{ +namespace mcbooster { //---- types ------------------------------------------------------------------- -typedef char GChar_t; ///< Signed Character 1 byte (char) -typedef unsigned char GUChar_t; ///< Unsigned Character 1 byte (unsigned char) -typedef short GShort_t; ///< Signed Short integer 2 bytes (short) -typedef unsigned short GUShort_t; /// _Masses, GLong_t _NEvents) : - fNEvents(_NEvents), - fNDaughters(_Masses.size()), - fSeed(0) - { - - if (_Masses.size() < 2 || _Masses.size() > 9) { - std::cout - << "The number of daughter particles can not be (< 2 || > 9) or masses and names need to have the same size." - << std::endl; - exit(1); - - } - - fMasses.resize(_Masses.size()); - thrust::copy(_Masses.begin(), _Masses.end(), fMasses.begin()); - - GReal_t fTeCmTm = 0.0; - - fTeCmTm = _MotherMass; // total energy in C.M. minus the sum of the masses - - for (size_t n = 0; n < fNDaughters; n++) { - fTeCmTm -= _Masses[n]; - } - if (fTeCmTm < 0.0) { - std::cout << "Not enough energy for this decay. Exit." << std::endl; - exit(1); - } - - Allocate(fNEvents); - - } //decay - - - PhaseSpace(GReal_t _MotherMass, std::vector _Masses, GLong_t _NEvents, GLong_t _EvtNumOffset) : PhaseSpace(_MotherMass, _Masses, _NEvents){fSeed = _EvtNumOffset;} - /** - * PhaseSpace() dtor. The destructor explicitly frees all the resources owned by the class. - */ - ~PhaseSpace() { - fMasses.clear(); - fMasses.shrink_to_fit(); - FreeResources(); - - } - - /** - * Free resources. Free resources owned in host and device side by the PhaseSpace object. - */ - inline void FreeResources() { - for (GInt_t i = 0; i < fNDaughters; i++) { - fDaughters[i].clear(); - fDaughters[i].shrink_to_fit(); - - } - - fWeights.clear(); - fWeights.shrink_to_fit(); - //fRandNumbers.clear(); - //fRandNumbers.shrink_to_fit(); - fAccRejFlags.clear(); - fAccRejFlags.shrink_to_fit(); - } - - inline void Generate(Particles_d fMothers); - inline void Generate(const Vector4R fMother); - - /** - * Get the daughter with index 'i' in the mass array. It return a device vector of particles by reference. - * Is responsibility of the user modify or not the particles in the container. - */ - inline Particles_d& GetDaughters(GInt_t i) { - return fDaughters[i]; - } - /** - * Returns the number of daughter particles. - */ - inline GInt_t GetNDaughters() const { - return fNDaughters; - } - - /** - * Returns the number of events. - */ - inline GLong_t GetNEvents() const { - return fNEvents; - } - - inline GLong_t GetNAccepted() const { - return fNAccepted; - } - - inline BoolVector_d GetAccRejFlags() const { - return fAccRejFlags; - } - - /** - * Returns a device vector with the event weights. - */ - inline const RealVector_d& GetWeights() const { - return fWeights; - } - - /** - * Returns the time spent in seconds to process the random numbers and set the phase space four-vectors. - */ - inline GReal_t GetEvtTime() const { - return EVT_Time; - } - - /** - * Returns the time spent in seconds to export the generated events to a Events container. - */ - inline GReal_t GetExpTime() const { - return EXP_Time; - } - - /** - * Returns the time spent in seconds to generate the random numbers necessary for the calculation. - */ - inline GReal_t GetRndTime() const { - return RND_Time; - } - - /** - * Returns the max event weight that can be found in the generated sample. Larger the sample, more accurate - * is this number. - */ - inline GReal_t GetMaxWeight() const { - return fMaxWeight; - } - - inline GInt_t GetSeed() const { - return fSeed; - } - - inline void SetSeed(GInt_t _seed) { - fSeed=_seed; - } - - /** - * Export the events and all related information to host. - */ - void Export(Events *_Events); - inline void ExportUnweighted(Events *_Events); - /** - * Flag the accepted and rejected events - */ - inline GULong_t Unweight(); - - // -public: - - /** - * Allocate resources on the device for event generation. - */ - inline void Allocate(const GLong_t _nevents) { - - for (GInt_t i = 0; i < fNDaughters; i++) - fDaughters[i].resize(_nevents); - fWeights.resize(_nevents); - fAccRejFlags.resize(_nevents); - // fRandNumbers.resize((3 * fNDaughters - 2) * fNEvents); - - } - - /** - * PDK function - */ - inline GReal_t PDK(const GReal_t a, const GReal_t b, const GReal_t c) const { - //the PDK function - GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); - x = sqrt(x) / (2 * a); - return x; - } - -private: - - GLong_t fNEvents; ///< Number of events. - GInt_t fNDaughters;///< Number of daughters. - GUInt_t fSeed {0};///< seed. + public: + /** + * PhaseSpace ctor. Constructor of the phase-space generator takes as input parameters: + * - _MotherMass: the mass of the mother particle in Gev/c*c + * - _Masses: STL vector with the mass of the daughter particles. + * - _NEvents: it is the number of events to be generated. + */ + PhaseSpace(GReal_t _MotherMass, std::vector _Masses, GLong_t _NEvents) + : fNEvents(_NEvents) + , fNDaughters(_Masses.size()) + , fSeed(0) { + if(_Masses.size() < 2 || _Masses.size() > 9) { + std::cout << "The number of daughter particles can not be (< 2 || > 9) or masses and names need to have " + "the same size." + << std::endl; + exit(1); + } + + fMasses.resize(_Masses.size()); + thrust::copy(_Masses.begin(), _Masses.end(), fMasses.begin()); + + GReal_t fTeCmTm = 0.0; + + fTeCmTm = _MotherMass; // total energy in C.M. minus the sum of the masses + + for(size_t n = 0; n < fNDaughters; n++) { + fTeCmTm -= _Masses[n]; + } + if(fTeCmTm < 0.0) { + std::cout << "Not enough energy for this decay. Exit." << std::endl; + exit(1); + } + + Allocate(fNEvents); + + } // decay + + PhaseSpace(GReal_t _MotherMass, std::vector _Masses, GLong_t _NEvents, GLong_t _EvtNumOffset) + : PhaseSpace(_MotherMass, _Masses, _NEvents) { + fSeed = _EvtNumOffset; + } + /** + * PhaseSpace() dtor. The destructor explicitly frees all the resources owned by the class. + */ + ~PhaseSpace() { + fMasses.clear(); + fMasses.shrink_to_fit(); + FreeResources(); + } + + /** + * Free resources. Free resources owned in host and device side by the PhaseSpace object. + */ + inline void FreeResources() { + for(GInt_t i = 0; i < fNDaughters; i++) { + fDaughters[i].clear(); + fDaughters[i].shrink_to_fit(); + } + + fWeights.clear(); + fWeights.shrink_to_fit(); + // fRandNumbers.clear(); + // fRandNumbers.shrink_to_fit(); + fAccRejFlags.clear(); + fAccRejFlags.shrink_to_fit(); + } + + inline void Generate(Particles_d fMothers); + inline void Generate(const Vector4R fMother); + + /** + * Get the daughter with index 'i' in the mass array. It return a device vector of particles by reference. + * Is responsibility of the user modify or not the particles in the container. + */ + inline Particles_d &GetDaughters(GInt_t i) { return fDaughters[i]; } + /** + * Returns the number of daughter particles. + */ + inline GInt_t GetNDaughters() const { return fNDaughters; } + + /** + * Returns the number of events. + */ + inline GLong_t GetNEvents() const { return fNEvents; } + + inline GLong_t GetNAccepted() const { return fNAccepted; } + + inline BoolVector_d GetAccRejFlags() const { return fAccRejFlags; } + + /** + * Returns a device vector with the event weights. + */ + inline const RealVector_d &GetWeights() const { return fWeights; } + + /** + * Returns the time spent in seconds to process the random numbers and set the phase space four-vectors. + */ + inline GReal_t GetEvtTime() const { return EVT_Time; } + + /** + * Returns the time spent in seconds to export the generated events to a Events container. + */ + inline GReal_t GetExpTime() const { return EXP_Time; } + + /** + * Returns the time spent in seconds to generate the random numbers necessary for the calculation. + */ + inline GReal_t GetRndTime() const { return RND_Time; } + + /** + * Returns the max event weight that can be found in the generated sample. Larger the sample, more accurate + * is this number. + */ + inline GReal_t GetMaxWeight() const { return fMaxWeight; } + + inline GInt_t GetSeed() const { return fSeed; } + + inline void SetSeed(GInt_t _seed) { fSeed = _seed; } + + /** + * Export the events and all related information to host. + */ + void Export(Events *_Events); + inline void ExportUnweighted(Events *_Events); + /** + * Flag the accepted and rejected events + */ + inline GULong_t Unweight(); + + // + public: + /** + * Allocate resources on the device for event generation. + */ + inline void Allocate(const GLong_t _nevents) { + for(GInt_t i = 0; i < fNDaughters; i++) + fDaughters[i].resize(_nevents); + fWeights.resize(_nevents); + fAccRejFlags.resize(_nevents); + // fRandNumbers.resize((3 * fNDaughters - 2) * fNEvents); + } + + /** + * PDK function + */ + inline GReal_t PDK(const GReal_t a, const GReal_t b, const GReal_t c) const { + // the PDK function + GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); + x = sqrt(x) / (2 * a); + return x; + } + + private: + GLong_t fNEvents; ///< Number of events. + GInt_t fNDaughters; ///< Number of daughters. + GUInt_t fSeed{0}; ///< seed. GLong_t fNAccepted; - GReal_t RND_Time {0.0};///< Random number generation time interval seconds. - GReal_t EVT_Time {0.0};///< Event generation time interval in seconds. - GReal_t EXP_Time {0.0};///< Events export time interval in seconds. - GReal_t fMaxWeight {0.0};///< Maximum weight in sample. - //device - RealVector_d fMasses;///< Device vector of daughter masses. - RealVector_d fWeights;///< Device vector of weights. - BoolVector_d fAccRejFlags;///< Device vector of Accept/reject flags - Particles_d fDaughters[kMAXP];///< Array of device vectors with the daughter four-vectors - - + GReal_t RND_Time{0.0}; ///< Random number generation time interval seconds. + GReal_t EVT_Time{0.0}; ///< Event generation time interval in seconds. + GReal_t EXP_Time{0.0}; ///< Events export time interval in seconds. + GReal_t fMaxWeight{0.0}; ///< Maximum weight in sample. + // device + RealVector_d fMasses; ///< Device vector of daughter masses. + RealVector_d fWeights; ///< Device vector of weights. + BoolVector_d fAccRejFlags; ///< Device vector of Accept/reject flags + Particles_d fDaughters[kMAXP]; ///< Array of device vectors with the daughter four-vectors }; -inline GULong_t PhaseSpace::Unweight() -{ - /** - * Flag the accepted and rejected events - */ - - GULong_t count = 0; - if(fNDaughters==2) - { - thrust::fill(fAccRejFlags.begin(), fAccRejFlags.end(), kTrue); - count = fNEvents; - } - else - { - - // create iterators - thrust::counting_iterator first(0); - thrust::counting_iterator last = first + fNEvents; - - - thrust::transform(first, last, fWeights.begin(), - fAccRejFlags.begin(), FlagAcceptReject(fMaxWeight, fSeed)); - - count = thrust::count(fAccRejFlags.begin(), fAccRejFlags.end(), - kTrue); - - } - fNAccepted=count; - return count; - +inline GULong_t PhaseSpace::Unweight() { + /** + * Flag the accepted and rejected events + */ + + GULong_t count = 0; + if(fNDaughters == 2) { + thrust::fill(fAccRejFlags.begin(), fAccRejFlags.end(), kTrue); + count = fNEvents; + } else { + // create iterators + thrust::counting_iterator first(0); + thrust::counting_iterator last = first + fNEvents; + + thrust::transform(first, last, fWeights.begin(), fAccRejFlags.begin(), FlagAcceptReject(fMaxWeight, fSeed)); + + count = thrust::count(fAccRejFlags.begin(), fAccRejFlags.end(), kTrue); + } + fNAccepted = count; + return count; } - - inline void PhaseSpace::ExportUnweighted(Events *_Events) { - /** - * Export the events and all related information to an Events object properly initialized. - */ + /** + * Export the events and all related information to an Events object properly initialized. + */ - if(!fNAccepted) Unweight(); + if(!fNAccepted) + Unweight(); + _Events->fMaxWeight = fMaxWeight; - _Events->fMaxWeight = fMaxWeight; - -#if MCBOOSTER_BACKEND!=CUDA -#if MCBOOSTER_BACKEND!=CPP -#pragma omp parallel num_threads( fNDaughters + 1 ) +#if MCBOOSTER_BACKEND != CUDA +#if MCBOOSTER_BACKEND != CPP +#pragma omp parallel num_threads(fNDaughters + 1) { #else - for(size_t val = 0; valfDaughters[omp_get_thread_num()].begin(), isAccepted() ); - } - - if (omp_get_thread_num() == fNDaughters ) - { - thrust::copy_if(fWeights.begin(), fWeights.end(), - fAccRejFlags.begin(), - _Events->fWeights.begin(), isAccepted() ); - - thrust::copy_if(fAccRejFlags.begin(), fAccRejFlags.end(), - fAccRejFlags.begin(), - _Events->fAccRejFlags.begin(), isAccepted() ); - } - } + if(omp_get_thread_num() < fNDaughters) { + thrust::copy_if(fDaughters[omp_get_thread_num()].begin(), + fDaughters[omp_get_thread_num()].end(), + fAccRejFlags.begin(), + _Events->fDaughters[omp_get_thread_num()].begin(), + isAccepted()); + } + + if(omp_get_thread_num() == fNDaughters) { + thrust::copy_if( + fWeights.begin(), fWeights.end(), fAccRejFlags.begin(), _Events->fWeights.begin(), isAccepted()); + + thrust::copy_if(fAccRejFlags.begin(), + fAccRejFlags.end(), + fAccRejFlags.begin(), + _Events->fAccRejFlags.begin(), + isAccepted()); + } + } #else - cudaStream_t s[fNDaughters + 1]; - - for (GInt_t d = 0; d <= fNDaughters; d++) { - - CUDA_CHECK_RETURN( - cudaStreamCreateWithFlags(&s[d], cudaStreamNonBlocking)); - } - - - - thrust::copy_if( thrust::cuda::par.on(s[fNDaughters]), - fWeights.begin(), fWeights.end(), - fAccRejFlags.begin(), - _Events->fWeights.begin(), isAccepted() ); - - - thrust::copy_if( thrust::cuda::par.on(s[fNDaughters]), - fAccRejFlags.begin(), fAccRejFlags.end(), - fAccRejFlags.begin(), - _Events->fAccRejFlags.begin(), isAccepted() ); - - - for (GInt_t d = 0; d < fNDaughters; d++) { - - thrust::copy_if( thrust::cuda::par.on(s[d]), - fDaughters[d].begin(),fDaughters[d].end(), - fAccRejFlags.begin(), - _Events->fDaughters[d].begin(), isAccepted() ); - - } - - cudaDeviceSynchronize(); - for (GInt_t d = 0; d <= fNDaughters; d++) - cudaStreamDestroy(s[d]); + cudaStream_t s[fNDaughters + 1]; + + for(GInt_t d = 0; d <= fNDaughters; d++) { + CUDA_CHECK_RETURN(cudaStreamCreateWithFlags(&s[d], cudaStreamNonBlocking)); + } + + thrust::copy_if(thrust::cuda::par.on(s[fNDaughters]), + fWeights.begin(), + fWeights.end(), + fAccRejFlags.begin(), + _Events->fWeights.begin(), + isAccepted()); + + thrust::copy_if(thrust::cuda::par.on(s[fNDaughters]), + fAccRejFlags.begin(), + fAccRejFlags.end(), + fAccRejFlags.begin(), + _Events->fAccRejFlags.begin(), + isAccepted()); + + for(GInt_t d = 0; d < fNDaughters; d++) { + thrust::copy_if(thrust::cuda::par.on(s[d]), + fDaughters[d].begin(), + fDaughters[d].end(), + fAccRejFlags.begin(), + _Events->fDaughters[d].begin(), + isAccepted()); + } + + cudaDeviceSynchronize(); + for(GInt_t d = 0; d <= fNDaughters; d++) + cudaStreamDestroy(s[d]); #endif - } inline void PhaseSpace::Export(Events *_Events) { - /** - * Export the events and all related information to an Events object properly initialized. - */ - _Events->fMaxWeight = fMaxWeight; - -#if MCBOOSTER_BACKEND!=CUDA -#if MCBOOSTER_BACKEND!=CPP -#pragma omp parallel num_threads( fNDaughters + 1 ) + /** + * Export the events and all related information to an Events object properly initialized. + */ + _Events->fMaxWeight = fMaxWeight; + +#if MCBOOSTER_BACKEND != CUDA +#if MCBOOSTER_BACKEND != CPP +#pragma omp parallel num_threads(fNDaughters + 1) { #else - for(size_t val = 0; valfDaughters[omp_get_thread_num()].begin()); - } - - if (omp_get_thread_num() == fNDaughters ) - { - thrust::copy(fWeights.begin(), - fWeights.end(), _Events->fWeights.begin()); + if(omp_get_thread_num() < fNDaughters) { + thrust::copy(fDaughters[omp_get_thread_num()].begin(), + fDaughters[omp_get_thread_num()].end(), + _Events->fDaughters[omp_get_thread_num()].begin()); + } - thrust::copy(fAccRejFlags.begin(), - fAccRejFlags.end(), _Events->fAccRejFlags.begin()); + if(omp_get_thread_num() == fNDaughters) { + thrust::copy(fWeights.begin(), fWeights.end(), _Events->fWeights.begin()); - } - - } + thrust::copy(fAccRejFlags.begin(), fAccRejFlags.end(), _Events->fAccRejFlags.begin()); + } + } #else - cudaStream_t s[fNDaughters + 1]; - - for (GInt_t d = 0; d <= fNDaughters; d++) { - - CUDA_CHECK_RETURN( - cudaStreamCreateWithFlags(&s[d], cudaStreamNonBlocking)); - } + cudaStream_t s[fNDaughters + 1]; - cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fWeights.data()), - thrust::raw_pointer_cast(fWeights.data()), - fWeights.size() * sizeof(GReal_t), cudaMemcpyDeviceToHost, - s[fNDaughters]); + for(GInt_t d = 0; d <= fNDaughters; d++) { + CUDA_CHECK_RETURN(cudaStreamCreateWithFlags(&s[d], cudaStreamNonBlocking)); + } - cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fAccRejFlags.data()), - thrust::raw_pointer_cast(fAccRejFlags.data()), - fAccRejFlags.size() * sizeof(GBool_t), cudaMemcpyDeviceToHost, - s[fNDaughters]); + cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fWeights.data()), + thrust::raw_pointer_cast(fWeights.data()), + fWeights.size() * sizeof(GReal_t), + cudaMemcpyDeviceToHost, + s[fNDaughters]); - for (GInt_t d = 0; d < fNDaughters; d++) { + cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fAccRejFlags.data()), + thrust::raw_pointer_cast(fAccRejFlags.data()), + fAccRejFlags.size() * sizeof(GBool_t), + cudaMemcpyDeviceToHost, + s[fNDaughters]); - cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fDaughters[d].data()), - thrust::raw_pointer_cast(fDaughters[d].data()), - fDaughters[d].size() * sizeof(Vector4R), cudaMemcpyDeviceToHost, - s[d]); + for(GInt_t d = 0; d < fNDaughters; d++) { + cudaMemcpyAsync(thrust::raw_pointer_cast(_Events->fDaughters[d].data()), + thrust::raw_pointer_cast(fDaughters[d].data()), + fDaughters[d].size() * sizeof(Vector4R), + cudaMemcpyDeviceToHost, + s[d]); + } - } - - cudaDeviceSynchronize(); - for (GInt_t d = 0; d <= fNDaughters; d++) - cudaStreamDestroy(s[d]); + cudaDeviceSynchronize(); + for(GInt_t d = 0; d <= fNDaughters; d++) + cudaStreamDestroy(s[d]); #endif - } inline void PhaseSpace::Generate(const Vector4R fMother) { - /** - * Run the generator and calculate the maximum weight. It takes as input the fourvector of the mother particle - * in any system of reference. The daughters will be generated in this system. - */ +/** + * Run the generator and calculate the maximum weight. It takes as input the fourvector of the mother particle + * in any system of reference. The daughters will be generated in this system. + */ -#if MCBOOSTER_BACKEND==CUDA - cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); +#if MCBOOSTER_BACKEND == CUDA + cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); #endif - /* random number generation */ - - RND_Time = 0; - // create iterators - thrust::counting_iterator first(0); - thrust::counting_iterator last = first + fNEvents; - - //Vai!!! - - /* event generation */ - timespec time_event_start, time_event_end; - clock_gettime(TIMER, &time_event_start); - - switch (fNDaughters) { - - case 2: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin())), fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - - case 3: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin())), - fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - case 4: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin())), fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - case 5: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin(), fDaughters[4].begin())), - fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - //} - break; - case 6: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin(), fDaughters[4].begin(), - fDaughters[5].begin())), fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - case 7: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin(), fDaughters[4].begin(), - fDaughters[5].begin(), fDaughters[6].begin())), - fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - case 8: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin(), fDaughters[4].begin(), - fDaughters[5].begin(), fDaughters[6].begin(), - fDaughters[7].begin())), fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - case 9: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fDaughters[0].begin(), - fDaughters[1].begin(), fDaughters[2].begin(), - fDaughters[3].begin(), fDaughters[4].begin(), - fDaughters[5].begin(), fDaughters[6].begin(), - fDaughters[7].begin(), fDaughters[8].begin())), - fWeights.begin(), - DecayMother(fMother, fMasses, fNDaughters, fSeed)); - - break; - - } - - clock_gettime(TIMER, &time_event_end); - EVT_Time = ((GReal_t) (time_diff(time_event_start, time_event_end).tv_sec - + time_diff(time_event_start, time_event_end).tv_nsec * 1.0e-9)); - - //setting maximum weight - RealVector_d::iterator w = thrust::max_element(fWeights.begin(), - fWeights.end()); - fMaxWeight = *w; - + /* random number generation */ + + RND_Time = 0; + // create iterators + thrust::counting_iterator first(0); + thrust::counting_iterator last = first + fNEvents; + + // Vai!!! + + /* event generation */ + timespec time_event_start, time_event_end; + clock_gettime(TIMER, &time_event_start); + + switch(fNDaughters) { + case 2: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), fDaughters[1].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + + case 3: + + thrust::transform(first, + last, + thrust::make_zip_iterator( + thrust::make_tuple(fDaughters[0].begin(), fDaughters[1].begin(), fDaughters[2].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + case 4: + + thrust::transform( + first, + last, + thrust::make_zip_iterator(thrust::make_tuple( + fDaughters[0].begin(), fDaughters[1].begin(), fDaughters[2].begin(), fDaughters[3].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + case 5: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + //} + break; + case 6: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + case 7: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + case 8: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin(), + fDaughters[7].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + case 9: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin(), + fDaughters[7].begin(), + fDaughters[8].begin())), + fWeights.begin(), + DecayMother(fMother, fMasses, fNDaughters, fSeed)); + + break; + } + + clock_gettime(TIMER, &time_event_end); + EVT_Time = ((GReal_t)(time_diff(time_event_start, time_event_end).tv_sec + + time_diff(time_event_start, time_event_end).tv_nsec * 1.0e-9)); + + // setting maximum weight + RealVector_d::iterator w = thrust::max_element(fWeights.begin(), fWeights.end()); + fMaxWeight = *w; } inline void PhaseSpace::Generate(Particles_d fMothers) { - /** - * Run the generator and calculate the maximum weight. It takes as input the device vector with the four-vectors of the mother particle - * in any system of reference. The daughters will be generated in this system. - */ +/** + * Run the generator and calculate the maximum weight. It takes as input the device vector with the four-vectors of the + * mother particle + * in any system of reference. The daughters will be generated in this system. + */ -#if MCBOOSTER_BACKEND==CUDA - cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); +#if MCBOOSTER_BACKEND == CUDA + cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); #endif - if (fNEvents < fMothers.size()) - std::cout << "fNEvents != fMothers.size()" < first(0); - thrust::counting_iterator last = first + fNEvents; - - - switch (fNDaughters) { - - case 2: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin())), - fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - - case 3: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin())), fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 4: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin())), - fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 5: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin(), - fDaughters[4].begin())), fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 6: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin(), - fDaughters[4].begin(), fDaughters[5].begin())), - fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 7: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin(), - fDaughters[4].begin(), fDaughters[5].begin(), - fDaughters[6].begin())), fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 8: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin(), - fDaughters[4].begin(), fDaughters[5].begin(), - fDaughters[6].begin(), fDaughters[7].begin())), - fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - case 9: - - thrust::transform(first, last, - thrust::make_zip_iterator( - thrust::make_tuple(fMothers.begin(), - fDaughters[0].begin(), fDaughters[1].begin(), - fDaughters[2].begin(), fDaughters[3].begin(), - fDaughters[4].begin(), fDaughters[5].begin(), - fDaughters[6].begin(), fDaughters[7].begin(), - fDaughters[8].begin())), fWeights.begin(), - DecayMothers(fMasses, fNDaughters, fSeed)); - - break; - - } - - clock_gettime(TIMER, &time_event_end); - EVT_Time = ((GReal_t) (time_diff(time_event_start, time_event_end).tv_sec - + time_diff(time_event_start, time_event_end).tv_nsec * 1.0e-9)); - - //setting maximum weight - RealVector_d::iterator w = thrust::max_element(fWeights.begin(), - fWeights.end()); - fMaxWeight = *w; - + if(fNEvents < fMothers.size()) + std::cout << "fNEvents != fMothers.size()" << std::endl; + + /* random number generation */ + /* + timespec time_rnd_start, time_rnd_end; + clock_gettime(TIMER, &time_rnd_start); + + + clock_gettime(TIMER, &time_rnd_end); + + RND_Time = ((GReal_t) (time_diff(time_rnd_start, time_rnd_end).tv_sec + + time_diff(time_rnd_start, time_rnd_end).tv_nsec * 1.0e-9)); + */ + + /* event generation */ + timespec time_event_start, time_event_end; + clock_gettime(TIMER, &time_event_start); + + RND_Time = 0.0; + // create iterators + thrust::counting_iterator first(0); + thrust::counting_iterator last = first + fNEvents; + + switch(fNDaughters) { + case 2: + + thrust::transform(first, + last, + thrust::make_zip_iterator( + thrust::make_tuple(fMothers.begin(), fDaughters[0].begin(), fDaughters[1].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + + case 3: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple( + fMothers.begin(), fDaughters[0].begin(), fDaughters[1].begin(), fDaughters[2].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 4: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 5: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 6: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 7: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 8: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin(), + fDaughters[7].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + case 9: + + thrust::transform(first, + last, + thrust::make_zip_iterator(thrust::make_tuple(fMothers.begin(), + fDaughters[0].begin(), + fDaughters[1].begin(), + fDaughters[2].begin(), + fDaughters[3].begin(), + fDaughters[4].begin(), + fDaughters[5].begin(), + fDaughters[6].begin(), + fDaughters[7].begin(), + fDaughters[8].begin())), + fWeights.begin(), + DecayMothers(fMasses, fNDaughters, fSeed)); + + break; + } + + clock_gettime(TIMER, &time_event_end); + EVT_Time = ((GReal_t)(time_diff(time_event_start, time_event_end).tv_sec + + time_diff(time_event_start, time_event_end).tv_nsec * 1.0e-9)); + + // setting maximum weight + RealVector_d::iterator w = thrust::max_element(fWeights.begin(), fWeights.end()); + fMaxWeight = *w; } - } #endif /* GENERATE_H_ */ diff --git a/extern/MCBooster/mcbooster/Vector3R.h b/extern/MCBooster/mcbooster/Vector3R.h index aeaeb7d10..01f612820 100644 --- a/extern/MCBooster/mcbooster/Vector3R.h +++ b/extern/MCBooster/mcbooster/Vector3R.h @@ -27,8 +27,6 @@ #ifndef VECTOR3R_H_ #define VECTOR3R_H_ - - #include #include #include @@ -36,244 +34,165 @@ #include using std::ostream; -namespace mcbooster -{ -class Vector3R -{ - - __host__ __device__ inline friend Vector3R rotateEuler(const Vector3R& v, - GReal_t phi, GReal_t theta, GReal_t ksi); - - __host__ __device__ inline friend Vector3R operator*(GReal_t c, - const Vector3R& v2); - __host__ __device__ inline friend GReal_t operator*(const Vector3R& v1, - const Vector3R& v2); - __host__ __device__ inline friend Vector3R operator+(const Vector3R& v1, - const Vector3R& v2); - __host__ __device__ inline friend Vector3R operator-(const Vector3R& v1, - const Vector3R& v2); - __host__ __device__ inline friend Vector3R operator*(const Vector3R& v1, - GReal_t c); - __host__ __device__ inline friend Vector3R operator/(const Vector3R& v1, - GReal_t c); - __host__ __device__ inline friend Vector3R cross(const Vector3R& v1, - const Vector3R& v2); - -public: - __host__ __device__ inline Vector3R(); - __host__ __device__ inline Vector3R(GReal_t x, GReal_t y, GReal_t z); - __host__ __device__ inline Vector3R(const Vector3R& other); - __host__ __device__ inline Vector3R& operator*=(const GReal_t c); - __host__ __device__ inline Vector3R& operator/=(const GReal_t c); - __host__ __device__ inline Vector3R& operator+=(const Vector3R& v2); - __host__ __device__ inline Vector3R& operator-=(const Vector3R& v2); - __host__ __device__ inline void set(GInt_t i, GReal_t d); - __host__ __device__ inline void set(GReal_t x, GReal_t y, GReal_t z); - __host__ __device__ inline void applyRotateEuler(GReal_t phi, GReal_t theta, - GReal_t ksi); - __host__ __device__ inline GReal_t get(GInt_t i) const; - __host__ inline friend std::ostream& operator<<(std::ostream& s, - const Vector3R& v); - __host__ __device__ inline GReal_t dot(const Vector3R& v2); - __host__ __device__ inline GReal_t d3mag() const; - -private: - - GReal_t v[3]; - +namespace mcbooster { +class Vector3R { + __host__ __device__ inline friend Vector3R rotateEuler(const Vector3R &v, GReal_t phi, GReal_t theta, GReal_t ksi); + + __host__ __device__ inline friend Vector3R operator*(GReal_t c, const Vector3R &v2); + __host__ __device__ inline friend GReal_t operator*(const Vector3R &v1, const Vector3R &v2); + __host__ __device__ inline friend Vector3R operator+(const Vector3R &v1, const Vector3R &v2); + __host__ __device__ inline friend Vector3R operator-(const Vector3R &v1, const Vector3R &v2); + __host__ __device__ inline friend Vector3R operator*(const Vector3R &v1, GReal_t c); + __host__ __device__ inline friend Vector3R operator/(const Vector3R &v1, GReal_t c); + __host__ __device__ inline friend Vector3R cross(const Vector3R &v1, const Vector3R &v2); + + public: + __host__ __device__ inline Vector3R(); + __host__ __device__ inline Vector3R(GReal_t x, GReal_t y, GReal_t z); + __host__ __device__ inline Vector3R(const Vector3R &other); + __host__ __device__ inline Vector3R &operator*=(const GReal_t c); + __host__ __device__ inline Vector3R &operator/=(const GReal_t c); + __host__ __device__ inline Vector3R &operator+=(const Vector3R &v2); + __host__ __device__ inline Vector3R &operator-=(const Vector3R &v2); + __host__ __device__ inline void set(GInt_t i, GReal_t d); + __host__ __device__ inline void set(GReal_t x, GReal_t y, GReal_t z); + __host__ __device__ inline void applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi); + __host__ __device__ inline GReal_t get(GInt_t i) const; + __host__ inline friend std::ostream &operator<<(std::ostream &s, const Vector3R &v); + __host__ __device__ inline GReal_t dot(const Vector3R &v2); + __host__ __device__ inline GReal_t d3mag() const; + + private: + GReal_t v[3]; }; -inline Vector3R& Vector3R::operator*=(const GReal_t c) -{ - - v[0] *= c; - v[1] *= c; - v[2] *= c; - return *this; -} - -inline Vector3R& Vector3R::operator/=(const GReal_t c) -{ - - v[0] /= c; - v[1] /= c; - v[2] /= c; - return *this; -} - -inline Vector3R& Vector3R::operator+=(const Vector3R& v2) -{ - - v[0] += v2.v[0]; - v[1] += v2.v[1]; - v[2] += v2.v[2]; - return *this; -} - -inline Vector3R& Vector3R::operator-=(const Vector3R& v2) -{ - - v[0] -= v2.v[0]; - v[1] -= v2.v[1]; - v[2] -= v2.v[2]; - return *this; -} - -inline Vector3R operator*(GReal_t c, const Vector3R& v2) -{ - - return Vector3R(v2) *= c; +inline Vector3R &Vector3R::operator*=(const GReal_t c) { + v[0] *= c; + v[1] *= c; + v[2] *= c; + return *this; } -inline Vector3R operator*(const Vector3R& v1, GReal_t c) -{ - - return Vector3R(v1) *= c; +inline Vector3R &Vector3R::operator/=(const GReal_t c) { + v[0] /= c; + v[1] /= c; + v[2] /= c; + return *this; } -inline Vector3R operator/(const Vector3R& v1, GReal_t c) -{ - - return Vector3R(v1) /= c; +inline Vector3R &Vector3R::operator+=(const Vector3R &v2) { + v[0] += v2.v[0]; + v[1] += v2.v[1]; + v[2] += v2.v[2]; + return *this; } -inline GReal_t operator*(const Vector3R& v1, const Vector3R& v2) -{ - - return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2]; +inline Vector3R &Vector3R::operator-=(const Vector3R &v2) { + v[0] -= v2.v[0]; + v[1] -= v2.v[1]; + v[2] -= v2.v[2]; + return *this; } -inline Vector3R operator+(const Vector3R& v1, const Vector3R& v2) -{ +inline Vector3R operator*(GReal_t c, const Vector3R &v2) { return Vector3R(v2) *= c; } - return Vector3R(v1) += v2; -} +inline Vector3R operator*(const Vector3R &v1, GReal_t c) { return Vector3R(v1) *= c; } -inline Vector3R operator-(const Vector3R& v1, const Vector3R& v2) -{ - - return Vector3R(v1) -= v2; +inline Vector3R operator/(const Vector3R &v1, GReal_t c) { return Vector3R(v1) /= c; } +inline GReal_t operator*(const Vector3R &v1, const Vector3R &v2) { + return v1.v[0] * v2.v[0] + v1.v[1] * v2.v[1] + v1.v[2] * v2.v[2]; } -inline GReal_t Vector3R::get(GInt_t i) const -{ - return v[i]; -} +inline Vector3R operator+(const Vector3R &v1, const Vector3R &v2) { return Vector3R(v1) += v2; } -inline void Vector3R::set(GInt_t i, GReal_t d) -{ +inline Vector3R operator-(const Vector3R &v1, const Vector3R &v2) { return Vector3R(v1) -= v2; } - v[i] = d; -} +inline GReal_t Vector3R::get(GInt_t i) const { return v[i]; } -inline void Vector3R::set(GReal_t x, GReal_t y, GReal_t z) -{ +inline void Vector3R::set(GInt_t i, GReal_t d) { v[i] = d; } - v[0] = x; - v[1] = y; - v[2] = z; +inline void Vector3R::set(GReal_t x, GReal_t y, GReal_t z) { + v[0] = x; + v[1] = y; + v[2] = z; } -inline Vector3R::Vector3R() -{ +inline Vector3R::Vector3R() { v[0] = v[1] = v[2] = 0.0; } - v[0] = v[1] = v[2] = 0.0; +inline Vector3R::Vector3R(GReal_t x, GReal_t y, GReal_t z) { + v[0] = x; + v[1] = y; + v[2] = z; } -inline Vector3R::Vector3R(GReal_t x, GReal_t y, GReal_t z) -{ - - v[0] = x; - v[1] = y; - v[2] = z; +inline Vector3R::Vector3R(const Vector3R &other) { + v[0] = other.get(0); + v[1] = other.get(1); + v[2] = other.get(2); } -inline Vector3R::Vector3R(const Vector3R& other) -{ - - v[0] = other.get(0); - v[1] = other.get(1); - v[2] = other.get(2); +inline Vector3R rotateEuler(const Vector3R &v, GReal_t alpha, GReal_t beta, GReal_t gamma) { + Vector3R tmp(v); + tmp.applyRotateEuler(alpha, beta, gamma); + return tmp; } -inline Vector3R rotateEuler(const Vector3R& v, GReal_t alpha, GReal_t beta, - GReal_t gamma) -{ +inline void Vector3R::applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi) { + GReal_t temp[3]; + GReal_t sp, st, sk, cp, ct, ck; - Vector3R tmp(v); - tmp.applyRotateEuler(alpha, beta, gamma); - return tmp; + sp = sin(phi); + st = sin(theta); + sk = sin(ksi); + cp = cos(phi); + ct = cos(theta); + ck = cos(ksi); -} + temp[0] = (ck * ct * cp - sk * sp) * v[0] + (-sk * ct * cp - ck * sp) * v[1] + st * cp * v[2]; + temp[1] = (ck * ct * sp + sk * cp) * v[0] + (-sk * ct * sp + ck * cp) * v[1] + st * sp * v[2]; + temp[2] = -ck * st * v[0] + sk * st * v[1] + ct * v[2]; -inline void Vector3R::applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi) -{ - - GReal_t temp[3]; - GReal_t sp, st, sk, cp, ct, ck; - - sp = sin(phi); - st = sin(theta); - sk = sin(ksi); - cp = cos(phi); - ct = cos(theta); - ck = cos(ksi); - - temp[0] = (ck * ct * cp - sk * sp) * v[0] + (-sk * ct * cp - ck * sp) * v[1] - + st * cp * v[2]; - temp[1] = (ck * ct * sp + sk * cp) * v[0] + (-sk * ct * sp + ck * cp) * v[1] - + st * sp * v[2]; - temp[2] = -ck * st * v[0] + sk * st * v[1] + ct * v[2]; - - v[0] = temp[0]; - v[1] = temp[1]; - v[2] = temp[2]; + v[0] = temp[0]; + v[1] = temp[1]; + v[2] = temp[2]; } -inline ostream& operator<<(ostream& s, const Vector3R& v) -{ - - s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << ")"; - - return s; +inline ostream &operator<<(ostream &s, const Vector3R &v) { + s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << ")"; + return s; } -inline Vector3R cross(const Vector3R& p1, const Vector3R& p2) -{ - - //Calcs the cross product. Added by djl on July 27, 1995. - //Modified for real vectros by ryd Aug 28-96 - - return Vector3R(p1.v[1] * p2.v[2] - p1.v[2] * p2.v[1], - p1.v[2] * p2.v[0] - p1.v[0] * p2.v[2], - p1.v[0] * p2.v[1] - p1.v[1] * p2.v[0]); +inline Vector3R cross(const Vector3R &p1, const Vector3R &p2) { + // Calcs the cross product. Added by djl on July 27, 1995. + // Modified for real vectros by ryd Aug 28-96 + return Vector3R(p1.v[1] * p2.v[2] - p1.v[2] * p2.v[1], + p1.v[2] * p2.v[0] - p1.v[0] * p2.v[2], + p1.v[0] * p2.v[1] - p1.v[1] * p2.v[0]); } inline GReal_t Vector3R::d3mag() const // returns the 3 momentum mag. { - GReal_t temp; + GReal_t temp; - temp = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; - temp = sqrt(temp); + temp = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; + temp = sqrt(temp); - return temp; + return temp; } // r3mag -inline GReal_t Vector3R::dot(const Vector3R& p2) -{ - - GReal_t temp; +inline GReal_t Vector3R::dot(const Vector3R &p2) { + GReal_t temp; - temp = v[0] * p2.v[0]; - temp += v[0] * p2.v[0]; - temp += v[0] * p2.v[0]; + temp = v[0] * p2.v[0]; + temp += v[0] * p2.v[0]; + temp += v[0] * p2.v[0]; - return temp; -} //dot + return temp; +} // dot } #endif /* VECTOR3R_H_ */ diff --git a/extern/MCBooster/mcbooster/Vector4R.h b/extern/MCBooster/mcbooster/Vector4R.h index 543307aac..f82053c1c 100644 --- a/extern/MCBooster/mcbooster/Vector4R.h +++ b/extern/MCBooster/mcbooster/Vector4R.h @@ -36,511 +36,369 @@ using std::ostream; - - -namespace mcbooster -{ +namespace mcbooster { class Vector3R; -class Vector4R -{ - - __host__ __device__ inline friend Vector4R operator*(GReal_t d, - const Vector4R& v2); - __host__ __device__ inline friend Vector4R operator*(const Vector4R& v2, - GReal_t d); - __host__ __device__ inline friend Vector4R operator/(const Vector4R& v2, - GReal_t d); - __host__ __device__ inline friend GReal_t operator*(const Vector4R& v1, - const Vector4R& v2); - __host__ __device__ inline friend Vector4R operator+(const Vector4R& v1, - const Vector4R& v2); - __host__ __device__ inline friend Vector4R operator-(const Vector4R& v1, - const Vector4R& v2); - -public: - __host__ __device__ inline Vector4R(); - __host__ __device__ inline Vector4R(GReal_t e, GReal_t px, GReal_t py, - GReal_t pz); - __host__ __device__ inline Vector4R(const Vector4R& other); - __host__ __device__ inline void set(GInt_t i, GReal_t d); - __host__ __device__ inline void set(GReal_t e, GReal_t px, GReal_t py, - GReal_t pz); - __host__ __device__ inline Vector4R& operator*=(GReal_t c); - __host__ __device__ inline Vector4R& operator/=(GReal_t c); - __host__ __device__ inline Vector4R& operator=(const Vector4R& v2); - __host__ __device__ inline Vector4R& operator+=(const Vector4R& v2); - __host__ __device__ inline Vector4R& operator-=(const Vector4R& v2); - __host__ __device__ inline GReal_t get(GInt_t i) const; - __host__ __device__ inline GReal_t cont(const Vector4R& v4) const; - __host__ inline friend std::ostream& operator<<(std::ostream& s, - const Vector4R& v); - __host__ __device__ inline GReal_t mass2() const; - __host__ __device__ inline GReal_t mass() const; - __host__ __device__ inline void applyRotateEuler(GReal_t alpha, - GReal_t beta, GReal_t gamma); - __host__ __device__ inline void applyBoostTo(const Vector4R& p4, - bool inverse = false); - __host__ __device__ inline void applyBoostTo(const Vector3R& boost, - bool inverse = false); - __host__ __device__ inline void applyBoostTo(const GReal_t bx, - const GReal_t by, const GReal_t bz, bool inverse = false); - __host__ __device__ inline Vector4R cross(const Vector4R& v2); - __host__ __device__ inline GReal_t dot(const Vector4R& v2) const; - __host__ __device__ inline GReal_t d3mag() const; - - // Added by AJB - calculate scalars in the rest frame of the current object - __host__ __device__ inline GReal_t scalartripler3(const Vector4R& p1, - const Vector4R& p2, const Vector4R& p3) const; - __host__ __device__ inline GReal_t dotr3(const Vector4R& p1, - const Vector4R& p2) const; - __host__ __device__ inline GReal_t mag2r3(const Vector4R& p1) const; - __host__ __device__ inline GReal_t magr3(const Vector4R& p1) const; - -private: - - GReal_t v[4]; - - __host__ __device__ inline GReal_t Square(GReal_t x) const - { - return x * x; - } - +class Vector4R { + __host__ __device__ inline friend Vector4R operator*(GReal_t d, const Vector4R &v2); + __host__ __device__ inline friend Vector4R operator*(const Vector4R &v2, GReal_t d); + __host__ __device__ inline friend Vector4R operator/(const Vector4R &v2, GReal_t d); + __host__ __device__ inline friend GReal_t operator*(const Vector4R &v1, const Vector4R &v2); + __host__ __device__ inline friend Vector4R operator+(const Vector4R &v1, const Vector4R &v2); + __host__ __device__ inline friend Vector4R operator-(const Vector4R &v1, const Vector4R &v2); + + public: + __host__ __device__ inline Vector4R(); + __host__ __device__ inline Vector4R(GReal_t e, GReal_t px, GReal_t py, GReal_t pz); + __host__ __device__ inline Vector4R(const Vector4R &other); + __host__ __device__ inline void set(GInt_t i, GReal_t d); + __host__ __device__ inline void set(GReal_t e, GReal_t px, GReal_t py, GReal_t pz); + __host__ __device__ inline Vector4R &operator*=(GReal_t c); + __host__ __device__ inline Vector4R &operator/=(GReal_t c); + __host__ __device__ inline Vector4R &operator=(const Vector4R &v2); + __host__ __device__ inline Vector4R &operator+=(const Vector4R &v2); + __host__ __device__ inline Vector4R &operator-=(const Vector4R &v2); + __host__ __device__ inline GReal_t get(GInt_t i) const; + __host__ __device__ inline GReal_t cont(const Vector4R &v4) const; + __host__ inline friend std::ostream &operator<<(std::ostream &s, const Vector4R &v); + __host__ __device__ inline GReal_t mass2() const; + __host__ __device__ inline GReal_t mass() const; + __host__ __device__ inline void applyRotateEuler(GReal_t alpha, GReal_t beta, GReal_t gamma); + __host__ __device__ inline void applyBoostTo(const Vector4R &p4, bool inverse = false); + __host__ __device__ inline void applyBoostTo(const Vector3R &boost, bool inverse = false); + __host__ __device__ inline void + applyBoostTo(const GReal_t bx, const GReal_t by, const GReal_t bz, bool inverse = false); + __host__ __device__ inline Vector4R cross(const Vector4R &v2); + __host__ __device__ inline GReal_t dot(const Vector4R &v2) const; + __host__ __device__ inline GReal_t d3mag() const; + + // Added by AJB - calculate scalars in the rest frame of the current object + __host__ __device__ inline GReal_t scalartripler3(const Vector4R &p1, const Vector4R &p2, const Vector4R &p3) const; + __host__ __device__ inline GReal_t dotr3(const Vector4R &p1, const Vector4R &p2) const; + __host__ __device__ inline GReal_t mag2r3(const Vector4R &p1) const; + __host__ __device__ inline GReal_t magr3(const Vector4R &p1) const; + + private: + GReal_t v[4]; + + __host__ __device__ inline GReal_t Square(GReal_t x) const { return x * x; } }; -Vector4R rotateEuler(const Vector4R& rs, GReal_t alpha, GReal_t beta, - GReal_t gamma); -Vector4R boostTo(const Vector4R& rs, const Vector4R& p4, bool inverse = false); -Vector4R boostTo(const Vector4R& rs, const Vector3R& boost, - bool inverse = false); - -inline Vector4R& Vector4R::operator=(const Vector4R& v2) -{ - - v[0] = v2.v[0]; - v[1] = v2.v[1]; - v[2] = v2.v[2]; - v[3] = v2.v[3]; - - return *this; -} - -inline Vector4R& Vector4R::operator+=(const Vector4R& v2) -{ - - v[0] += v2.v[0]; - v[1] += v2.v[1]; - v[2] += v2.v[2]; - v[3] += v2.v[3]; - - return *this; -} - -inline Vector4R& Vector4R::operator-=(const Vector4R& v2) -{ - - v[0] -= v2.v[0]; - v[1] -= v2.v[1]; - v[2] -= v2.v[2]; - v[3] -= v2.v[3]; - - return *this; -} - -inline GReal_t Vector4R::mass2() const -{ - - return v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3]; -} +Vector4R rotateEuler(const Vector4R &rs, GReal_t alpha, GReal_t beta, GReal_t gamma); +Vector4R boostTo(const Vector4R &rs, const Vector4R &p4, bool inverse = false); +Vector4R boostTo(const Vector4R &rs, const Vector3R &boost, bool inverse = false); -inline Vector4R operator*(GReal_t c, const Vector4R& v2) -{ +inline Vector4R &Vector4R::operator=(const Vector4R &v2) { + v[0] = v2.v[0]; + v[1] = v2.v[1]; + v[2] = v2.v[2]; + v[3] = v2.v[3]; - return Vector4R(v2) *= c; + return *this; } -inline Vector4R operator*(const Vector4R& v2, GReal_t c) -{ +inline Vector4R &Vector4R::operator+=(const Vector4R &v2) { + v[0] += v2.v[0]; + v[1] += v2.v[1]; + v[2] += v2.v[2]; + v[3] += v2.v[3]; - return Vector4R(v2) *= c; + return *this; } -inline Vector4R operator/(const Vector4R& v2, GReal_t c) -{ +inline Vector4R &Vector4R::operator-=(const Vector4R &v2) { + v[0] -= v2.v[0]; + v[1] -= v2.v[1]; + v[2] -= v2.v[2]; + v[3] -= v2.v[3]; - return Vector4R(v2) /= c; + return *this; } -inline Vector4R& Vector4R::operator*=(GReal_t c) -{ - - v[0] *= c; - v[1] *= c; - v[2] *= c; - v[3] *= c; +inline GReal_t Vector4R::mass2() const { return v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3]; } - return *this; -} - -inline Vector4R& Vector4R::operator/=(GReal_t c) -{ +inline Vector4R operator*(GReal_t c, const Vector4R &v2) { return Vector4R(v2) *= c; } - GReal_t cinv = 1.0 / c; - v[0] *= cinv; - v[1] *= cinv; - v[2] *= cinv; - v[3] *= cinv; +inline Vector4R operator*(const Vector4R &v2, GReal_t c) { return Vector4R(v2) *= c; } - return *this; -} +inline Vector4R operator/(const Vector4R &v2, GReal_t c) { return Vector4R(v2) /= c; } -inline GReal_t operator*(const Vector4R& v1, const Vector4R& v2) -{ +inline Vector4R &Vector4R::operator*=(GReal_t c) { + v[0] *= c; + v[1] *= c; + v[2] *= c; + v[3] *= c; - return v1.v[0] * v2.v[0] - v1.v[1] * v2.v[1] - v1.v[2] * v2.v[2] - - v1.v[3] * v2.v[3]; + return *this; } -inline GReal_t Vector4R::cont(const Vector4R& v4) const -{ +inline Vector4R &Vector4R::operator/=(GReal_t c) { + GReal_t cinv = 1.0 / c; + v[0] *= cinv; + v[1] *= cinv; + v[2] *= cinv; + v[3] *= cinv; - return v[0] * v4.v[0] - v[1] * v4.v[1] - v[2] * v4.v[2] - v[3] * v4.v[3]; + return *this; } -inline Vector4R operator-(const Vector4R& v1, const Vector4R& v2) -{ - - return Vector4R(v1) -= v2; +inline GReal_t operator*(const Vector4R &v1, const Vector4R &v2) { + return v1.v[0] * v2.v[0] - v1.v[1] * v2.v[1] - v1.v[2] * v2.v[2] - v1.v[3] * v2.v[3]; } -inline Vector4R operator+(const Vector4R& v1, const Vector4R& v2) -{ - - return Vector4R(v1) += v2; +inline GReal_t Vector4R::cont(const Vector4R &v4) const { + return v[0] * v4.v[0] - v[1] * v4.v[1] - v[2] * v4.v[2] - v[3] * v4.v[3]; } -inline GReal_t Vector4R::get(GInt_t i) const -{ - return v[i]; -} +inline Vector4R operator-(const Vector4R &v1, const Vector4R &v2) { return Vector4R(v1) -= v2; } -inline void Vector4R::set(GInt_t i, GReal_t d) -{ +inline Vector4R operator+(const Vector4R &v1, const Vector4R &v2) { return Vector4R(v1) += v2; } - v[i] = d; -} +inline GReal_t Vector4R::get(GInt_t i) const { return v[i]; } -__host__ __device__ inline void Vector4R::set(GReal_t e, GReal_t p1, GReal_t p2, - GReal_t p3) -{ +inline void Vector4R::set(GInt_t i, GReal_t d) { v[i] = d; } - v[0] = e; - v[1] = p1; - v[2] = p2; - v[3] = p3; +__host__ __device__ inline void Vector4R::set(GReal_t e, GReal_t p1, GReal_t p2, GReal_t p3) { + v[0] = e; + v[1] = p1; + v[2] = p2; + v[3] = p3; } using std::ostream; -inline Vector4R::Vector4R() -{ - v[0] = 0.0; - v[1] = 0.0; - v[2] = 0.0; - v[3] = 0.0; +inline Vector4R::Vector4R() { + v[0] = 0.0; + v[1] = 0.0; + v[2] = 0.0; + v[3] = 0.0; } -inline Vector4R::Vector4R(GReal_t e, GReal_t p1, GReal_t p2, GReal_t p3) -{ - - v[0] = e; - v[1] = p1; - v[2] = p2; - v[3] = p3; +inline Vector4R::Vector4R(GReal_t e, GReal_t p1, GReal_t p2, GReal_t p3) { + v[0] = e; + v[1] = p1; + v[2] = p2; + v[3] = p3; } -inline Vector4R::Vector4R(const Vector4R& other) -{ - - v[0] = other.get(0); - v[1] = other.get(1); - v[2] = other.get(2); - v[3] = other.get(3); +inline Vector4R::Vector4R(const Vector4R &other) { + v[0] = other.get(0); + v[1] = other.get(1); + v[2] = other.get(2); + v[3] = other.get(3); } -inline GReal_t Vector4R::mass() const -{ - - GReal_t m2 = v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3]; +inline GReal_t Vector4R::mass() const { + GReal_t m2 = v[0] * v[0] - v[1] * v[1] - v[2] * v[2] - v[3] * v[3]; - if (m2 > 0.0) - { - return sqrt(m2); - } - else - { - return 0.0; - } + if(m2 > 0.0) { + return sqrt(m2); + } else { + return 0.0; + } } -inline Vector4R rotateEuler(const Vector4R& rs, GReal_t alpha, GReal_t beta, - GReal_t gamma) -{ - - Vector4R tmp(rs); - tmp.applyRotateEuler(alpha, beta, gamma); - return tmp; - +inline Vector4R rotateEuler(const Vector4R &rs, GReal_t alpha, GReal_t beta, GReal_t gamma) { + Vector4R tmp(rs); + tmp.applyRotateEuler(alpha, beta, gamma); + return tmp; } -inline Vector4R boostTo(const Vector4R& rs, const Vector4R& p4, bool inverse) -{ - - Vector4R tmp(rs); - tmp.applyBoostTo(p4, inverse); - return tmp; - +inline Vector4R boostTo(const Vector4R &rs, const Vector4R &p4, bool inverse) { + Vector4R tmp(rs); + tmp.applyBoostTo(p4, inverse); + return tmp; } -inline Vector4R boostTo(const Vector4R& rs, const Vector3R& boost, bool inverse) -{ - - Vector4R tmp(rs); - tmp.applyBoostTo(boost, inverse); - return tmp; - +inline Vector4R boostTo(const Vector4R &rs, const Vector3R &boost, bool inverse) { + Vector4R tmp(rs); + tmp.applyBoostTo(boost, inverse); + return tmp; } -inline void Vector4R::applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi) -{ - - GReal_t sp = sin(phi); - GReal_t st = sin(theta); - GReal_t sk = sin(ksi); - GReal_t cp = cos(phi); - GReal_t ct = cos(theta); - GReal_t ck = cos(ksi); - - GReal_t x = (ck * ct * cp - sk * sp) * v[1] - + (-sk * ct * cp - ck * sp) * v[2] + st * cp * v[3]; - GReal_t y = (ck * ct * sp + sk * cp) * v[1] - + (-sk * ct * sp + ck * cp) * v[2] + st * sp * v[3]; - GReal_t z = -ck * st * v[1] + sk * st * v[2] + ct * v[3]; +inline void Vector4R::applyRotateEuler(GReal_t phi, GReal_t theta, GReal_t ksi) { + GReal_t sp = sin(phi); + GReal_t st = sin(theta); + GReal_t sk = sin(ksi); + GReal_t cp = cos(phi); + GReal_t ct = cos(theta); + GReal_t ck = cos(ksi); - v[1] = x; - v[2] = y; - v[3] = z; + GReal_t x = (ck * ct * cp - sk * sp) * v[1] + (-sk * ct * cp - ck * sp) * v[2] + st * cp * v[3]; + GReal_t y = (ck * ct * sp + sk * cp) * v[1] + (-sk * ct * sp + ck * cp) * v[2] + st * sp * v[3]; + GReal_t z = -ck * st * v[1] + sk * st * v[2] + ct * v[3]; + v[1] = x; + v[2] = y; + v[3] = z; } -inline ostream& operator<<(ostream& s, const Vector4R& v) -{ - - s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << "," << v.v[3] - << ")"; - - return s; +inline ostream &operator<<(ostream &s, const Vector4R &v) { + s << "(" << v.v[0] << "," << v.v[1] << "," << v.v[2] << "," << v.v[3] << ")"; + return s; } -inline void Vector4R::applyBoostTo(const Vector4R& p4, bool inverse) -{ - - GReal_t e = p4.get(0); +inline void Vector4R::applyBoostTo(const Vector4R &p4, bool inverse) { + GReal_t e = p4.get(0); - Vector3R boost(p4.get(1) / e, p4.get(2) / e, p4.get(3) / e); + Vector3R boost(p4.get(1) / e, p4.get(2) / e, p4.get(3) / e); - applyBoostTo(boost, inverse); - - return; + applyBoostTo(boost, inverse); + return; } -inline void Vector4R::applyBoostTo(const Vector3R& boost, bool inverse) -{ - - GReal_t bx, by, bz, gamma, b2; +inline void Vector4R::applyBoostTo(const Vector3R &boost, bool inverse) { + GReal_t bx, by, bz, gamma, b2; - bx = boost.get(0); - by = boost.get(1); - bz = boost.get(2); + bx = boost.get(0); + by = boost.get(1); + bz = boost.get(2); - GReal_t bxx = bx * bx; - GReal_t byy = by * by; - GReal_t bzz = bz * bz; + GReal_t bxx = bx * bx; + GReal_t byy = by * by; + GReal_t bzz = bz * bz; - b2 = bxx + byy + bzz; + b2 = bxx + byy + bzz; - if (b2 > 0.0 && b2 < 1.0) - { + if(b2 > 0.0 && b2 < 1.0) { + gamma = 1.0 / sqrt(1.0 - b2); - gamma = 1.0 / sqrt(1.0 - b2); + GReal_t gb2 = (gamma - 1.0) / b2; - GReal_t gb2 = (gamma - 1.0) / b2; + GReal_t gb2xy = gb2 * bx * by; + GReal_t gb2xz = gb2 * bx * bz; + GReal_t gb2yz = gb2 * by * bz; - GReal_t gb2xy = gb2 * bx * by; - GReal_t gb2xz = gb2 * bx * bz; - GReal_t gb2yz = gb2 * by * bz; + GReal_t gbx = gamma * bx; + GReal_t gby = gamma * by; + GReal_t gbz = gamma * bz; - GReal_t gbx = gamma * bx; - GReal_t gby = gamma * by; - GReal_t gbz = gamma * bz; + GReal_t e2 = v[0]; + GReal_t px2 = v[1]; + GReal_t py2 = v[2]; + GReal_t pz2 = v[3]; - GReal_t e2 = v[0]; - GReal_t px2 = v[1]; - GReal_t py2 = v[2]; - GReal_t pz2 = v[3]; + if(inverse) { + v[0] = gamma * e2 - gbx * px2 - gby * py2 - gbz * pz2; - if (inverse) - { - v[0] = gamma * e2 - gbx * px2 - gby * py2 - gbz * pz2; + v[1] = -gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; - v[1] = -gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 - + gb2xz * pz2; + v[2] = -gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; - v[2] = -gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 - + gb2yz * pz2; + v[3] = -gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; + } else { + v[0] = gamma * e2 + gbx * px2 + gby * py2 + gbz * pz2; - v[3] = -gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 - + gb2xz * px2; - } - else - { - v[0] = gamma * e2 + gbx * px2 + gby * py2 + gbz * pz2; + v[1] = gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; - v[1] = gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; - - v[2] = gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; - - v[3] = gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; - } - } + v[2] = gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; + v[3] = gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; + } + } } -inline void Vector4R::applyBoostTo(const GReal_t bx, const GReal_t by, - const GReal_t bz, bool inverse) -{ - - GReal_t gamma, b2; - - GReal_t bxx = bx * bx; - GReal_t byy = by * by; - GReal_t bzz = bz * bz; +inline void Vector4R::applyBoostTo(const GReal_t bx, const GReal_t by, const GReal_t bz, bool inverse) { + GReal_t gamma, b2; - b2 = bxx + byy + bzz; + GReal_t bxx = bx * bx; + GReal_t byy = by * by; + GReal_t bzz = bz * bz; - if (b2 > 0.0 && b2 < 1.0) - { + b2 = bxx + byy + bzz; - gamma = 1.0 / sqrt(1.0 - b2); + if(b2 > 0.0 && b2 < 1.0) { + gamma = 1.0 / sqrt(1.0 - b2); - GReal_t gb2 = (gamma - 1.0) / b2; + GReal_t gb2 = (gamma - 1.0) / b2; - GReal_t gb2xy = gb2 * bx * by; - GReal_t gb2xz = gb2 * bx * bz; - GReal_t gb2yz = gb2 * by * bz; + GReal_t gb2xy = gb2 * bx * by; + GReal_t gb2xz = gb2 * bx * bz; + GReal_t gb2yz = gb2 * by * bz; - GReal_t gbx = gamma * bx; - GReal_t gby = gamma * by; - GReal_t gbz = gamma * bz; + GReal_t gbx = gamma * bx; + GReal_t gby = gamma * by; + GReal_t gbz = gamma * bz; - GReal_t e2 = v[0]; - GReal_t px2 = v[1]; - GReal_t py2 = v[2]; - GReal_t pz2 = v[3]; + GReal_t e2 = v[0]; + GReal_t px2 = v[1]; + GReal_t py2 = v[2]; + GReal_t pz2 = v[3]; - if (inverse) - { - v[0] = gamma * e2 - gbx * px2 - gby * py2 - gbz * pz2; + if(inverse) { + v[0] = gamma * e2 - gbx * px2 - gby * py2 - gbz * pz2; - v[1] = -gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 - + gb2xz * pz2; + v[1] = -gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; - v[2] = -gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 - + gb2yz * pz2; + v[2] = -gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; - v[3] = -gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 - + gb2xz * px2; - } - else - { - v[0] = gamma * e2 + gbx * px2 + gby * py2 + gbz * pz2; + v[3] = -gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; + } else { + v[0] = gamma * e2 + gbx * px2 + gby * py2 + gbz * pz2; - v[1] = gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; + v[1] = gbx * e2 + gb2 * bxx * px2 + px2 + gb2xy * py2 + gb2xz * pz2; - v[2] = gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; - - v[3] = gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; - } - } + v[2] = gby * e2 + gb2 * byy * py2 + py2 + gb2xy * px2 + gb2yz * pz2; + v[3] = gbz * e2 + gb2 * bzz * pz2 + pz2 + gb2yz * py2 + gb2xz * px2; + } + } } -inline Vector4R Vector4R::cross(const Vector4R& p2) -{ - - //Calcs the cross product. Added by djl on July 27, 1995. - //Modified for real vectros by ryd Aug 28-96 +inline Vector4R Vector4R::cross(const Vector4R &p2) { + // Calcs the cross product. Added by djl on July 27, 1995. + // Modified for real vectros by ryd Aug 28-96 - Vector4R temp; + Vector4R temp; - temp.v[0] = 0.0; - temp.v[1] = v[2] * p2.v[3] - v[3] * p2.v[2]; - temp.v[2] = v[3] * p2.v[1] - v[1] * p2.v[3]; - temp.v[3] = v[1] * p2.v[2] - v[2] * p2.v[1]; + temp.v[0] = 0.0; + temp.v[1] = v[2] * p2.v[3] - v[3] * p2.v[2]; + temp.v[2] = v[3] * p2.v[1] - v[1] * p2.v[3]; + temp.v[3] = v[1] * p2.v[2] - v[2] * p2.v[1]; - return temp; + return temp; } inline GReal_t Vector4R::d3mag() const // returns the 3 momentum mag. { - GReal_t temp; + GReal_t temp; - temp = v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; + temp = v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; - temp = sqrt(temp); + temp = sqrt(temp); - return temp; + return temp; } // r3mag -inline GReal_t Vector4R::dot(const Vector4R& p2) const -{ - - //Returns the dot product of the 3 momentum. Added by - //djl on July 27, 1995. for real!!! - - GReal_t temp; +inline GReal_t Vector4R::dot(const Vector4R &p2) const { + // Returns the dot product of the 3 momentum. Added by + // djl on July 27, 1995. for real!!! - temp = v[1] * p2.v[1]; - temp += v[2] * p2.v[2]; - temp += v[3] * p2.v[3]; + GReal_t temp; - return temp; + temp = v[1] * p2.v[1]; + temp += v[2] * p2.v[2]; + temp += v[3] * p2.v[3]; -} //dot + return temp; +} // dot // Calculate the 3-d dot product of 4-vectors p1 and p2 in the rest frame of // 4-vector p0 -inline GReal_t Vector4R::dotr3(const Vector4R& p1, const Vector4R& p2) const -{ - return 1 / mass2() * ((*this) * p1) * ((*this) * p2) - p1 * p2; +inline GReal_t Vector4R::dotr3(const Vector4R &p1, const Vector4R &p2) const { + return 1 / mass2() * ((*this) * p1) * ((*this) * p2) - p1 * p2; } // Calculate the 3-d magnitude squared of 4-vector p1 in the rest frame of // 4-vector p0 -inline GReal_t Vector4R::mag2r3(const Vector4R& p1) const -{ - return Square((*this) * p1) / mass2() - p1.mass2(); -} +inline GReal_t Vector4R::mag2r3(const Vector4R &p1) const { return Square((*this) * p1) / mass2() - p1.mass2(); } // Calculate the 3-d magnitude 4-vector p1 in the rest frame of 4-vector p0. -inline GReal_t Vector4R::magr3(const Vector4R& p1) const -{ - return sqrt(mag2r3(p1)); -} +inline GReal_t Vector4R::magr3(const Vector4R &p1) const { return sqrt(mag2r3(p1)); } } #endif /* VECTOR4R_H_ */ diff --git a/extern/MCBooster/mcbooster/functors/Calculate.h b/extern/MCBooster/mcbooster/functors/Calculate.h index d2b79e970..0f2248542 100644 --- a/extern/MCBooster/mcbooster/functors/Calculate.h +++ b/extern/MCBooster/mcbooster/functors/Calculate.h @@ -33,489 +33,393 @@ #include #include -namespace mcbooster -{ +namespace mcbooster { template -struct Calculate -{ +struct Calculate { + FUNCTION Function; - FUNCTION Function; + Calculate() { Function = FUNCTION(); } - Calculate() - { + Calculate(const FUNCTION &_Function) + : Function(_Function) {} - Function = FUNCTION(); + __host__ __device__ inline RESULT operator()(GT2 &particles) { + Vector4R *_Particles[2]; - } - - - Calculate(const FUNCTION& _Function) : - Function(_Function) - { - - } - - - __host__ __device__ inline RESULT operator()(GT2 &particles) - { - - Vector4R* _Particles[2]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - - return Function(2, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT3 &particles) - { - - Vector4R* _Particles[3]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - - return Function(3, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT4 &particles) - { - - Vector4R* _Particles[4]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - - return Function(4, _Particles); - - } - - __host__ __device__ inline RESULT operator()(GT5 &particles) - { - - Vector4R* _Particles[5]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - - return Function(5, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT6 &particles) - { - - Vector4R* _Particles[6]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - - return Function(6, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT7 &particles) - { - - Vector4R* _Particles[7]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - - return Function(7, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT8 &particles) - { - - Vector4R* _Particles[8]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - - return Function(8, _Particles); - - } - - __host__ __device__ inline RESULT operator()(GT9 &particles) - { - - Vector4R* _Particles[9]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - - return Function(9, _Particles); - } - - __host__ __device__ inline RESULT operator()(GT10 &particles) - { - - Vector4R* _Particles[10]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - _Particles[9] = &thrust::get<9>(particles); - - return Function(10, _Particles); - } + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + return Function(2, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT3 &particles) { + Vector4R *_Particles[3]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + + return Function(3, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT4 &particles) { + Vector4R *_Particles[4]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + + return Function(4, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT5 &particles) { + Vector4R *_Particles[5]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + + return Function(5, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT6 &particles) { + Vector4R *_Particles[6]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + + return Function(6, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT7 &particles) { + Vector4R *_Particles[7]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + + return Function(7, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT8 &particles) { + Vector4R *_Particles[8]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + + return Function(8, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT9 &particles) { + Vector4R *_Particles[9]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + + return Function(9, _Particles); + } + + __host__ __device__ inline RESULT operator()(GT10 &particles) { + Vector4R *_Particles[10]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + _Particles[9] = &thrust::get<9>(particles); + + return Function(10, _Particles); + } }; template -struct Calculate2 -{ - - FUNCTION Function; - - Calculate2() - { - Function = FUNCTION(); - - } - - - Calculate2(const FUNCTION& _Function) : - Function(_Function) - { - - } - - - __host__ __device__ inline void operator()(GT2 particles) - { +struct Calculate2 { + FUNCTION Function; - Vector4R* _Particles[2]; + Calculate2() { Function = FUNCTION(); } - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); + Calculate2(const FUNCTION &_Function) + : Function(_Function) {} - Function(2, _Particles); - } + __host__ __device__ inline void operator()(GT2 particles) { + Vector4R *_Particles[2]; - __host__ __device__ inline void operator()(GT3 particles) - { - - Vector4R* _Particles[3]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - - Function(3, _Particles); - } - - __host__ __device__ inline void operator()(GT4 particles) - { - - Vector4R* _Particles[4]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - - Function(4, _Particles); - - } - - __host__ __device__ inline void operator()(GT5 particles) - { - - Vector4R* _Particles[5]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - - Function(5, _Particles); - } - - __host__ __device__ inline void operator()(GT6 particles) - { - - Vector4R* _Particles[6]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - - Function(6, _Particles); - } - - __host__ __device__ inline void operator()(GT7 particles) - { - - Vector4R* _Particles[7]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - - Function(7, _Particles); - } - - __host__ __device__ inline void operator()(GT8 particles) - { - - Vector4R* _Particles[8]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - - Function(8, _Particles); - - } - - __host__ __device__ inline void operator()(GT9 particles) - { - - Vector4R* _Particles[9]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - - Function(9, _Particles); - } - - __host__ __device__ inline void operator()(GT10 particles) - { - - Vector4R* _Particles[10]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - _Particles[9] = &thrust::get<9>(particles); - - Function(10, _Particles); - } + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + Function(2, _Particles); + } + + __host__ __device__ inline void operator()(GT3 particles) { + Vector4R *_Particles[3]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + + Function(3, _Particles); + } + + __host__ __device__ inline void operator()(GT4 particles) { + Vector4R *_Particles[4]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + + Function(4, _Particles); + } + + __host__ __device__ inline void operator()(GT5 particles) { + Vector4R *_Particles[5]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + + Function(5, _Particles); + } + + __host__ __device__ inline void operator()(GT6 particles) { + Vector4R *_Particles[6]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + + Function(6, _Particles); + } + + __host__ __device__ inline void operator()(GT7 particles) { + Vector4R *_Particles[7]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + + Function(7, _Particles); + } + + __host__ __device__ inline void operator()(GT8 particles) { + Vector4R *_Particles[8]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + + Function(8, _Particles); + } + + __host__ __device__ inline void operator()(GT9 particles) { + Vector4R *_Particles[9]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + + Function(9, _Particles); + } + + __host__ __device__ inline void operator()(GT10 particles) { + Vector4R *_Particles[10]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + _Particles[9] = &thrust::get<9>(particles); + + Function(10, _Particles); + } }; template -struct Calculate3 -{ - - FUNCTION Function; - - Calculate3() - { - Function = FUNCTION(); - - } - - - Calculate3(const FUNCTION& _Function) : - Function(_Function) - { - - } - - - __host__ __device__ inline void operator()(GTR3 tuples) - { - - GReal_t* _real; - Vector4R* _Particles[2]; - - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - - Function(2, _Particles, _real); - } - - __host__ __device__ inline void operator()(GTR4 tuples) - { - - GReal_t* _real; - - Vector4R* _Particles[3]; - - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - - Function(3, _Particles, _real); +struct Calculate3 { + FUNCTION Function; - } + Calculate3() { Function = FUNCTION(); } - __host__ __device__ inline void operator()(GTR5 tuples) - { + Calculate3(const FUNCTION &_Function) + : Function(_Function) {} - GReal_t* _real; + __host__ __device__ inline void operator()(GTR3 tuples) { + GReal_t *_real; + Vector4R *_Particles[2]; - Vector4R* _Particles[4]; + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); + Function(2, _Particles, _real); + } - Function(4, _Particles, _real); - } + __host__ __device__ inline void operator()(GTR4 tuples) { + GReal_t *_real; - __host__ __device__ inline void operator()(GTR6 tuples) - { + Vector4R *_Particles[3]; - GReal_t* _real; + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); - Vector4R* _Particles[5]; + Function(3, _Particles, _real); + } - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); - _Particles[4] = &thrust::get<5>(tuples); + __host__ __device__ inline void operator()(GTR5 tuples) { + GReal_t *_real; - Function(5, _Particles, _real); - } + Vector4R *_Particles[4]; - __host__ __device__ inline void operator()(GTR7 tuples) - { + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); - GReal_t* _real; + Function(4, _Particles, _real); + } - Vector4R* _Particles[6]; + __host__ __device__ inline void operator()(GTR6 tuples) { + GReal_t *_real; - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); - _Particles[4] = &thrust::get<5>(tuples); - _Particles[5] = &thrust::get<6>(tuples); + Vector4R *_Particles[5]; - Function(6, _Particles, _real); - } + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); + _Particles[4] = &thrust::get<5>(tuples); - __host__ __device__ inline void operator()(GTR8 tuples) - { + Function(5, _Particles, _real); + } - GReal_t* _real; + __host__ __device__ inline void operator()(GTR7 tuples) { + GReal_t *_real; - Vector4R* _Particles[7]; + Vector4R *_Particles[6]; - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); - _Particles[4] = &thrust::get<5>(tuples); - _Particles[5] = &thrust::get<6>(tuples); - _Particles[6] = &thrust::get<7>(tuples); + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); + _Particles[4] = &thrust::get<5>(tuples); + _Particles[5] = &thrust::get<6>(tuples); - Function(7, _Particles, _real); + Function(6, _Particles, _real); + } - } + __host__ __device__ inline void operator()(GTR8 tuples) { + GReal_t *_real; - __host__ __device__ inline void operator()(GTR9 tuples) - { + Vector4R *_Particles[7]; - GReal_t* _real; + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); + _Particles[4] = &thrust::get<5>(tuples); + _Particles[5] = &thrust::get<6>(tuples); + _Particles[6] = &thrust::get<7>(tuples); - Vector4R* _Particles[8]; + Function(7, _Particles, _real); + } - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); - _Particles[4] = &thrust::get<5>(tuples); - _Particles[5] = &thrust::get<6>(tuples); - _Particles[6] = &thrust::get<7>(tuples); - _Particles[7] = &thrust::get<8>(tuples); + __host__ __device__ inline void operator()(GTR9 tuples) { + GReal_t *_real; - Function(8, _Particles, _real); - } + Vector4R *_Particles[8]; - __host__ __device__ inline void operator()(GTR10 tuples) - { + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); + _Particles[4] = &thrust::get<5>(tuples); + _Particles[5] = &thrust::get<6>(tuples); + _Particles[6] = &thrust::get<7>(tuples); + _Particles[7] = &thrust::get<8>(tuples); - GReal_t* _real; + Function(8, _Particles, _real); + } - Vector4R* _Particles[9]; + __host__ __device__ inline void operator()(GTR10 tuples) { + GReal_t *_real; - _real = &thrust::get<0>(tuples); - _Particles[0] = &thrust::get<1>(tuples); - _Particles[1] = &thrust::get<2>(tuples); - _Particles[2] = &thrust::get<3>(tuples); - _Particles[3] = &thrust::get<4>(tuples); - _Particles[4] = &thrust::get<5>(tuples); - _Particles[5] = &thrust::get<6>(tuples); - _Particles[6] = &thrust::get<7>(tuples); - _Particles[7] = &thrust::get<8>(tuples); - _Particles[8] = &thrust::get<9>(tuples); + Vector4R *_Particles[9]; - Function(9, _Particles, _real); - } + _real = &thrust::get<0>(tuples); + _Particles[0] = &thrust::get<1>(tuples); + _Particles[1] = &thrust::get<2>(tuples); + _Particles[2] = &thrust::get<3>(tuples); + _Particles[3] = &thrust::get<4>(tuples); + _Particles[4] = &thrust::get<5>(tuples); + _Particles[5] = &thrust::get<6>(tuples); + _Particles[6] = &thrust::get<7>(tuples); + _Particles[7] = &thrust::get<8>(tuples); + _Particles[8] = &thrust::get<9>(tuples); + Function(9, _Particles, _real); + } }; } diff --git a/extern/MCBooster/mcbooster/functors/DecayMother.h b/extern/MCBooster/mcbooster/functors/DecayMother.h index 20c6ad7b0..5bfdbbf6f 100644 --- a/extern/MCBooster/mcbooster/functors/DecayMother.h +++ b/extern/MCBooster/mcbooster/functors/DecayMother.h @@ -36,363 +36,304 @@ #include #include -namespace mcbooster -{ +namespace mcbooster { -struct DecayMother -{ +struct DecayMother { const GUInt_t fSeed; - const GInt_t fNDaughters; - GReal_t fTeCmTm; - GReal_t fWtMax; - GReal_t fBeta0; - GReal_t fBeta1; - GReal_t fBeta2; - - - const GReal_t* __restrict__ fMasses; - - //constructor - DecayMother(const Vector4R mother, - const mc_device_vector& _masses, - const GInt_t _ndaughters, const GUInt_t _seed): - fSeed(_seed), - fNDaughters(_ndaughters), - fMasses(thrust::raw_pointer_cast(_masses.data())) - - { - - GReal_t _fTeCmTm = mother.mass(); // total energy in C.M. minus the sum of the masses - - for (size_t n = 0; n < fNDaughters; n++) - { - _fTeCmTm -= _masses.data()[n]; - } - - GReal_t emmax = _fTeCmTm + _masses.data()[0]; - GReal_t emmin = 0.0; - GReal_t wtmax = 1.0; - for (size_t n = 1; n < fNDaughters; n++) - { - emmin += _masses.data()[n - 1]; - emmax += _masses.data()[n]; - wtmax *= pdk(emmax, emmin, _masses.data()[n]); - } - GReal_t _fWtMax = 1.0 / wtmax; - - GReal_t _beta = mother.d3mag() / mother.get(0); - - if (_beta) - { - GReal_t w = _beta / mother.d3mag(); - fBeta0 = mother.get(0) * w; - fBeta1 = mother.get(1) * w; - fBeta2 = mother.get(2) * w; - } - else - fBeta0 = fBeta1 = fBeta2 = 0.0; - - fTeCmTm = _fTeCmTm; - fWtMax = _fWtMax; - - - } - - __host__ __device__ inline GReal_t pdk(const GReal_t a, const GReal_t b, - const GReal_t c) const - { - //the PDK function - GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); - x = sqrt(x) / (2 * a); - return x; - } - - __host__ __device__ inline void bbsort( GReal_t *array, GInt_t n) - { - // Improved bubble sort - - for (GInt_t c = 0; c < n; c++) - { - GInt_t nswap = 0; - - for (GInt_t d = 0; d < n - c - 1; d++) - { - if (array[d] > array[d + 1]) /* For decreasing order use < */ - { - GReal_t swap = array[d]; - array[d] = array[d + 1]; - array[d + 1] = swap; - nswap++; - } - } - if (nswap == 0) - break; - } - - } - - __host__ __device__ inline GUInt_t hash(GUInt_t a) - { - a = (a + 0x7ed55d16) + (a << 12); - a = (a ^ 0xc761c23c) ^ (a >> 19); - a = (a + 0x165667b1) + (a << 5); - a = (a + 0xd3a2646c) ^ (a << 9); - a = (a + 0xfd7046c5) + (a << 3); - a = (a ^ 0xb55a4f09) ^ (a >> 16); - return a; - } - - __host__ __device__ inline GReal_t process(const GInt_t evt, Vector4R** daugters) - { - - thrust::random::default_random_engine randEng( 2863311530 ); - randEng.discard(evt+fSeed); + const GInt_t fNDaughters; + GReal_t fTeCmTm; + GReal_t fWtMax; + GReal_t fBeta0; + GReal_t fBeta1; + GReal_t fBeta2; + + const GReal_t *__restrict__ fMasses; + + // constructor + DecayMother(const Vector4R mother, + const mc_device_vector &_masses, + const GInt_t _ndaughters, + const GUInt_t _seed) + : fSeed(_seed) + , fNDaughters(_ndaughters) + , fMasses(thrust::raw_pointer_cast(_masses.data())) + + { + GReal_t _fTeCmTm = mother.mass(); // total energy in C.M. minus the sum of the masses + + for(size_t n = 0; n < fNDaughters; n++) { + _fTeCmTm -= _masses.data()[n]; + } + + GReal_t emmax = _fTeCmTm + _masses.data()[0]; + GReal_t emmin = 0.0; + GReal_t wtmax = 1.0; + for(size_t n = 1; n < fNDaughters; n++) { + emmin += _masses.data()[n - 1]; + emmax += _masses.data()[n]; + wtmax *= pdk(emmax, emmin, _masses.data()[n]); + } + GReal_t _fWtMax = 1.0 / wtmax; + + GReal_t _beta = mother.d3mag() / mother.get(0); + + if(_beta) { + GReal_t w = _beta / mother.d3mag(); + fBeta0 = mother.get(0) * w; + fBeta1 = mother.get(1) * w; + fBeta2 = mother.get(2) * w; + } else + fBeta0 = fBeta1 = fBeta2 = 0.0; + + fTeCmTm = _fTeCmTm; + fWtMax = _fWtMax; + } + + __host__ __device__ inline GReal_t pdk(const GReal_t a, const GReal_t b, const GReal_t c) const { + // the PDK function + GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); + x = sqrt(x) / (2 * a); + return x; + } + + __host__ __device__ inline void bbsort(GReal_t *array, GInt_t n) { + // Improved bubble sort + + for(GInt_t c = 0; c < n; c++) { + GInt_t nswap = 0; + + for(GInt_t d = 0; d < n - c - 1; d++) { + if(array[d] > array[d + 1]) /* For decreasing order use < */ + { + GReal_t swap = array[d]; + array[d] = array[d + 1]; + array[d + 1] = swap; + nswap++; + } + } + if(nswap == 0) + break; + } + } + + __host__ __device__ inline GUInt_t hash(GUInt_t a) { + a = (a + 0x7ed55d16) + (a << 12); + a = (a ^ 0xc761c23c) ^ (a >> 19); + a = (a + 0x165667b1) + (a << 5); + a = (a + 0xd3a2646c) ^ (a << 9); + a = (a + 0xfd7046c5) + (a << 3); + a = (a ^ 0xb55a4f09) ^ (a >> 16); + return a; + } + + __host__ __device__ inline GReal_t process(const GInt_t evt, Vector4R **daugters) { + thrust::random::default_random_engine randEng(2863311530); + randEng.discard(evt + fSeed); thrust::uniform_real_distribution uniDist(0.0, 1.0); - GReal_t rno[kMAXP]; - rno[0] = 0.0; - rno[fNDaughters - 1] = 1.0; + GReal_t rno[kMAXP]; + rno[0] = 0.0; + rno[fNDaughters - 1] = 1.0; + + if(fNDaughters > 2) { +#pragma unroll 9 + for(GInt_t n = 1; n < fNDaughters - 1; n++) { + rno[n] = uniDist(randEng); + } - if (fNDaughters > 2) - { - #pragma unroll 9 - for (GInt_t n = 1; n < fNDaughters - 1; n++) - { - rno[n] = uniDist(randEng) ; + bbsort(&rno[1], fNDaughters - 2); + } - } + GReal_t invMas[kMAXP], sum = 0.0; + +#pragma unroll 9 + for(size_t n = 0; n < fNDaughters; n++) { + sum += fMasses[n]; + invMas[n] = rno[n] * fTeCmTm + sum; + } - bbsort(&rno[1], fNDaughters -2); + // + //-----> compute the weight of the current event + // - } + GReal_t wt = fWtMax; + + GReal_t pd[kMAXP]; +#pragma unroll 9 + for(size_t n = 0; n < fNDaughters - 1; n++) { + pd[n] = pdk(invMas[n + 1], invMas[n], fMasses[n + 1]); + wt *= pd[n]; + } + + // + //-----> complete specification of event (Raubold-Lynch method) + // + + daugters[0]->set(sqrt(pd[0] * pd[0] + fMasses[0] * fMasses[0]), 0.0, pd[0], 0.0); - GReal_t invMas[kMAXP], sum = 0.0; +#pragma unroll 9 + for(size_t i = 1; i < fNDaughters; i++) { + daugters[i]->set(sqrt(pd[i - 1] * pd[i - 1] + fMasses[i] * fMasses[i]), 0.0, -pd[i - 1], 0.0); - #pragma unroll 9 - for (size_t n = 0; n < fNDaughters; n++) - { - sum += fMasses[n]; - invMas[n] = rno[n] * fTeCmTm + sum; - } - - // - //-----> compute the weight of the current event - // - - GReal_t wt = fWtMax; - - GReal_t pd[kMAXP]; - - #pragma unroll 9 - for (size_t n = 0; n < fNDaughters - 1; n++) - { - pd[n] = pdk(invMas[n + 1], invMas[n], fMasses[n + 1]); - wt *= pd[n]; - } - - // - //-----> complete specification of event (Raubold-Lynch method) - // - - daugters[0]->set(sqrt( pd[0] * pd[0] + fMasses[0] * fMasses[0]), 0.0, - pd[0], 0.0); - - #pragma unroll 9 - for (size_t i = 1; i < fNDaughters; i++) - { - - daugters[i]->set( - sqrt(pd[i - 1] * pd[i - 1] + fMasses[i] * fMasses[i]), 0.0, - -pd[i - 1], 0.0); - - GReal_t cZ = 2 * uniDist(randEng) -1 ; - GReal_t sZ = sqrt(1 - cZ * cZ); - GReal_t angY = 2 * PI* uniDist(randEng); - GReal_t cY = cos(angY); - GReal_t sY = sin(angY); - for (size_t j = 0; j <= i; j++) - { - - GReal_t x = daugters[j]->get(1); - GReal_t y = daugters[j]->get(2); - daugters[j]->set(1, cZ * x - sZ * y); - daugters[j]->set(2, sZ * x + cZ * y); // rotation around Z - - x = daugters[j]->get(1); - GReal_t z = daugters[j]->get(3); - daugters[j]->set(1, cY * x - sY * z); - daugters[j]->set(3, sY * x + cY * z); // rotation around Y - } - - if (i == (fNDaughters - 1)) - break; - - GReal_t beta = pd[i] / sqrt(pd[i] * pd[i] + invMas[i] * invMas[i]); - for (size_t j = 0; j <= i; j++) - { - - daugters[j]->applyBoostTo(Vector3R(0, beta, 0)); - } - - } - - // - //---> final boost of all particles to the mother's frame - // - #pragma unroll 9 - for (size_t n = 0; n < fNDaughters; n++) - { - - daugters[n]->applyBoostTo(Vector3R(fBeta0, fBeta1, fBeta2)); - - } - - // - //---> return the weight of event - // - - return wt; - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT2 &particles) - { - Vector4R* _Particles[2]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT3 &particles) - { - Vector4R* _Particles[3]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT4 &particles) - { - - Vector4R* _Particles[4]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT5 &particles) - { - Vector4R* _Particles[5]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT6 &particles) - { - Vector4R* _Particles[6]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT7 &particles) - { - Vector4R* _Particles[7]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT8 &particles) - { - Vector4R* _Particles[8]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT9 &particles) - { - Vector4R* _Particles[9]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT10 &particles) - { - Vector4R* _Particles[10]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - _Particles[9] = &thrust::get<9>(particles); - - return process(evt, _Particles); - - } + GReal_t cZ = 2 * uniDist(randEng) - 1; + GReal_t sZ = sqrt(1 - cZ * cZ); + GReal_t angY = 2 * PI * uniDist(randEng); + GReal_t cY = cos(angY); + GReal_t sY = sin(angY); + for(size_t j = 0; j <= i; j++) { + GReal_t x = daugters[j]->get(1); + GReal_t y = daugters[j]->get(2); + daugters[j]->set(1, cZ * x - sZ * y); + daugters[j]->set(2, sZ * x + cZ * y); // rotation around Z + + x = daugters[j]->get(1); + GReal_t z = daugters[j]->get(3); + daugters[j]->set(1, cY * x - sY * z); + daugters[j]->set(3, sY * x + cY * z); // rotation around Y + } + + if(i == (fNDaughters - 1)) + break; + + GReal_t beta = pd[i] / sqrt(pd[i] * pd[i] + invMas[i] * invMas[i]); + for(size_t j = 0; j <= i; j++) { + daugters[j]->applyBoostTo(Vector3R(0, beta, 0)); + } + } + +// +//---> final boost of all particles to the mother's frame +// +#pragma unroll 9 + for(size_t n = 0; n < fNDaughters; n++) { + daugters[n]->applyBoostTo(Vector3R(fBeta0, fBeta1, fBeta2)); + } + + // + //---> return the weight of event + // + + return wt; + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT2 &particles) { + Vector4R *_Particles[2]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT3 &particles) { + Vector4R *_Particles[3]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT4 &particles) { + Vector4R *_Particles[4]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT5 &particles) { + Vector4R *_Particles[5]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT6 &particles) { + Vector4R *_Particles[6]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT7 &particles) { + Vector4R *_Particles[7]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT8 &particles) { + Vector4R *_Particles[8]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT9 &particles) { + Vector4R *_Particles[9]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT10 &particles) { + Vector4R *_Particles[10]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + _Particles[9] = &thrust::get<9>(particles); + + return process(evt, _Particles); + } }; - } #endif /* DECAYMOTHER_H_ */ diff --git a/extern/MCBooster/mcbooster/functors/DecayMothers.h b/extern/MCBooster/mcbooster/functors/DecayMothers.h index 33390e128..2de73d7a1 100644 --- a/extern/MCBooster/mcbooster/functors/DecayMothers.h +++ b/extern/MCBooster/mcbooster/functors/DecayMothers.h @@ -27,7 +27,6 @@ #ifndef DECAYMOTHERS_H_ #define DECAYMOTHERS_H_ - #include #include #include @@ -36,338 +35,283 @@ #include #include -namespace mcbooster -{ - -struct DecayMothers -{ - const GInt_t fSeed; - const GInt_t fNDaughters; - const GReal_t* __restrict__ fMasses; - - //constructor - DecayMothers(const mc_device_vector& _masses, - const GInt_t _ndaughters, const GInt_t _seed ): - fSeed(_seed), - fNDaughters(_ndaughters), - fMasses(thrust::raw_pointer_cast(_masses.data())) - { - } - - __host__ __device__ inline GReal_t pdk(const GReal_t a, const GReal_t b, - const GReal_t c) const - { - //the PDK function - GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); - x = sqrt(x) / (2 * a); - return x; - } - - __host__ __device__ inline void bbsort(GReal_t *array, GInt_t n) - { - // Improved bubble sort - for (GInt_t c = 0; c < n; c++) - { - GInt_t nswap = 0; - - for (GInt_t d = 0; d < n - c - 1; d++) - { - if (array[d] > array[d + 1]) /* For decreasing order use < */ - { - GReal_t swap = array[d]; - array[d] = array[d + 1]; - array[d + 1] = swap; - nswap++; - } - } - if (nswap == 0) - break; - } - - } - - __host__ __device__ inline GUInt_t hash(GUInt_t a) - { - a = (a + 0x7ed55d16) + (a << 12); - a = (a ^ 0xc761c23c) ^ (a >> 19); - a = (a + 0x165667b1) + (a << 5); - a = (a + 0xd3a2646c) ^ (a << 9); - a = (a + 0xfd7046c5) + (a << 3); - a = (a ^ 0xb55a4f09) ^ (a >> 16); - return a; - } - - __host__ __device__ inline GReal_t process(const GInt_t evt, Vector4R** particles) - { - - - thrust::random::default_random_engine randEng( hash(evt)*fSeed); - thrust::uniform_real_distribution uniDist(0.0, 1.0); - - GReal_t fTeCmTm = 0.0; - - fTeCmTm = particles[0]->mass(); // total energy in C.M. minus the sum of the masses - - #pragma unroll (9) - for (size_t n = 0; n < fNDaughters; n++) - { - fTeCmTm -= fMasses[n]; - } - - GReal_t emmax = fTeCmTm + fMasses[0]; - GReal_t emmin = 0.0; - GReal_t wtmax = 1.0; - - #pragma unroll (9) - for (size_t n = 1; n < fNDaughters; n++) - { - emmin += fMasses[n - 1]; - emmax += fMasses[n]; - wtmax *= pdk(emmax, emmin, fMasses[n]); - } - // - //----> get the betas of the decaying particle - // - - //GReal_t _beta = particles[0]->d3mag() / particles[0]->get(0); - - GReal_t rno[kMAXP]; - rno[0] = 0.0; - - if (fNDaughters > 2) - { - #pragma unroll (9) - for (size_t n = 1; n < fNDaughters - 1; n++) - rno[n] = uniDist(randEng) ; - bbsort(&rno[1], fNDaughters - 2); - - } - rno[fNDaughters - 1] = 1; - - GReal_t invMas[kMAXP], sum = 0.0; - - #pragma unroll (9) - for (size_t n = 0; n < fNDaughters; n++) - { - sum += fMasses[n]; - invMas[n] = rno[n] * fTeCmTm + sum; - } - - // - //-----> compute the weight of the current event - // - - GReal_t wt = 1.0 / wtmax; - - GReal_t pd[kMAXP]; - - #pragma unroll (9) - for (size_t n = 0; n < fNDaughters - 1; n++) - { - pd[n] = pdk(invMas[n + 1], invMas[n], fMasses[n + 1]); - wt *= pd[n]; - } - - // - //-----> complete specification of event (Raubold-Lynch method) - // - - particles[1]->set(sqrt(pd[0] * pd[0] + fMasses[0] * fMasses[0]), 0.0, - pd[0], 0.0); - - #pragma unroll (9) - for (size_t i = 1; i < fNDaughters; i++) - { - - particles[i + 1]->set( - sqrt(pd[i - 1] * pd[i - 1] + fMasses[i] * fMasses[i]), 0.0, - -pd[i - 1], 0.0); - - GReal_t cZ = 2 * uniDist(randEng) -1 ; - GReal_t sZ = sqrt(1 - cZ * cZ); - GReal_t angY = 2.0 * PI * uniDist(randEng); - GReal_t cY = cos(angY); - GReal_t sY = sin(angY); - for (size_t j = 0; j <= i; j++) - { - - GReal_t x = particles[j + 1]->get(1); - GReal_t y = particles[j + 1]->get(2); - particles[j + 1]->set(1, cZ * x - sZ * y); - particles[j + 1]->set(2, sZ * x + cZ * y); // rotation around Z - - x = particles[j + 1]->get(1); - GReal_t z = particles[j + 1]->get(3); - particles[j + 1]->set(1, cY * x - sY * z); - particles[j + 1]->set(3, sY * x + cY * z); // rotation around Y - } - - if (i == (fNDaughters - 1)) - break; - - GReal_t beta = pd[i] / sqrt(pd[i] * pd[i] + invMas[i] * invMas[i]); - for (size_t j = 0; j <= i; j++) - { - - particles[j + 1]->applyBoostTo(0, beta, 0); - } - - //i++; - } - - // - //---> final boost of all particles to the mother's frame - // - #pragma unroll (9) - for (size_t n = 0; n < fNDaughters; n++) - { - - particles[n + 1]->applyBoostTo(*particles[0]); - - } - - // - //---> return the weight of event - // - - return wt; - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT2 &particles) - { - //do nothing, will never be called - return 0.0; - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT3& particles) - { - Vector4R* _Particles[3]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT4& particles) - { - - Vector4R* _Particles[4]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT5& particles) - { - Vector4R* _Particles[5]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT6& particles) - { - Vector4R* _Particles[6]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT7& particles) - { - Vector4R* _Particles[7]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT8& particles) - { - Vector4R* _Particles[8]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT9& particles) - { - Vector4R* _Particles[9]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - - return process(evt, _Particles); - - } - - __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT10& particles) - { - Vector4R* _Particles[10]; - - _Particles[0] = &thrust::get<0>(particles); - _Particles[1] = &thrust::get<1>(particles); - _Particles[2] = &thrust::get<2>(particles); - _Particles[3] = &thrust::get<3>(particles); - _Particles[4] = &thrust::get<4>(particles); - _Particles[5] = &thrust::get<5>(particles); - _Particles[6] = &thrust::get<6>(particles); - _Particles[7] = &thrust::get<7>(particles); - _Particles[8] = &thrust::get<8>(particles); - _Particles[9] = &thrust::get<9>(particles); - - return process(evt, _Particles); - - } - +namespace mcbooster { + +struct DecayMothers { + const GInt_t fSeed; + const GInt_t fNDaughters; + const GReal_t *__restrict__ fMasses; + + // constructor + DecayMothers(const mc_device_vector &_masses, const GInt_t _ndaughters, const GInt_t _seed) + : fSeed(_seed) + , fNDaughters(_ndaughters) + , fMasses(thrust::raw_pointer_cast(_masses.data())) {} + + __host__ __device__ inline GReal_t pdk(const GReal_t a, const GReal_t b, const GReal_t c) const { + // the PDK function + GReal_t x = (a - b - c) * (a + b + c) * (a - b + c) * (a + b - c); + x = sqrt(x) / (2 * a); + return x; + } + + __host__ __device__ inline void bbsort(GReal_t *array, GInt_t n) { + // Improved bubble sort + for(GInt_t c = 0; c < n; c++) { + GInt_t nswap = 0; + + for(GInt_t d = 0; d < n - c - 1; d++) { + if(array[d] > array[d + 1]) /* For decreasing order use < */ + { + GReal_t swap = array[d]; + array[d] = array[d + 1]; + array[d + 1] = swap; + nswap++; + } + } + if(nswap == 0) + break; + } + } + + __host__ __device__ inline GUInt_t hash(GUInt_t a) { + a = (a + 0x7ed55d16) + (a << 12); + a = (a ^ 0xc761c23c) ^ (a >> 19); + a = (a + 0x165667b1) + (a << 5); + a = (a + 0xd3a2646c) ^ (a << 9); + a = (a + 0xfd7046c5) + (a << 3); + a = (a ^ 0xb55a4f09) ^ (a >> 16); + return a; + } + + __host__ __device__ inline GReal_t process(const GInt_t evt, Vector4R **particles) { + thrust::random::default_random_engine randEng(hash(evt) * fSeed); + thrust::uniform_real_distribution uniDist(0.0, 1.0); + + GReal_t fTeCmTm = 0.0; + + fTeCmTm = particles[0]->mass(); // total energy in C.M. minus the sum of the masses + +#pragma unroll(9) + for(size_t n = 0; n < fNDaughters; n++) { + fTeCmTm -= fMasses[n]; + } + + GReal_t emmax = fTeCmTm + fMasses[0]; + GReal_t emmin = 0.0; + GReal_t wtmax = 1.0; + +#pragma unroll(9) + for(size_t n = 1; n < fNDaughters; n++) { + emmin += fMasses[n - 1]; + emmax += fMasses[n]; + wtmax *= pdk(emmax, emmin, fMasses[n]); + } + // + //----> get the betas of the decaying particle + // + + // GReal_t _beta = particles[0]->d3mag() / particles[0]->get(0); + + GReal_t rno[kMAXP]; + rno[0] = 0.0; + + if(fNDaughters > 2) { +#pragma unroll(9) + for(size_t n = 1; n < fNDaughters - 1; n++) + rno[n] = uniDist(randEng); + bbsort(&rno[1], fNDaughters - 2); + } + rno[fNDaughters - 1] = 1; + + GReal_t invMas[kMAXP], sum = 0.0; + +#pragma unroll(9) + for(size_t n = 0; n < fNDaughters; n++) { + sum += fMasses[n]; + invMas[n] = rno[n] * fTeCmTm + sum; + } + + // + //-----> compute the weight of the current event + // + + GReal_t wt = 1.0 / wtmax; + + GReal_t pd[kMAXP]; + +#pragma unroll(9) + for(size_t n = 0; n < fNDaughters - 1; n++) { + pd[n] = pdk(invMas[n + 1], invMas[n], fMasses[n + 1]); + wt *= pd[n]; + } + + // + //-----> complete specification of event (Raubold-Lynch method) + // + + particles[1]->set(sqrt(pd[0] * pd[0] + fMasses[0] * fMasses[0]), 0.0, pd[0], 0.0); + +#pragma unroll(9) + for(size_t i = 1; i < fNDaughters; i++) { + particles[i + 1]->set(sqrt(pd[i - 1] * pd[i - 1] + fMasses[i] * fMasses[i]), 0.0, -pd[i - 1], 0.0); + + GReal_t cZ = 2 * uniDist(randEng) - 1; + GReal_t sZ = sqrt(1 - cZ * cZ); + GReal_t angY = 2.0 * PI * uniDist(randEng); + GReal_t cY = cos(angY); + GReal_t sY = sin(angY); + for(size_t j = 0; j <= i; j++) { + GReal_t x = particles[j + 1]->get(1); + GReal_t y = particles[j + 1]->get(2); + particles[j + 1]->set(1, cZ * x - sZ * y); + particles[j + 1]->set(2, sZ * x + cZ * y); // rotation around Z + + x = particles[j + 1]->get(1); + GReal_t z = particles[j + 1]->get(3); + particles[j + 1]->set(1, cY * x - sY * z); + particles[j + 1]->set(3, sY * x + cY * z); // rotation around Y + } + + if(i == (fNDaughters - 1)) + break; + + GReal_t beta = pd[i] / sqrt(pd[i] * pd[i] + invMas[i] * invMas[i]); + for(size_t j = 0; j <= i; j++) { + particles[j + 1]->applyBoostTo(0, beta, 0); + } + + // i++; + } + +// +//---> final boost of all particles to the mother's frame +// +#pragma unroll(9) + for(size_t n = 0; n < fNDaughters; n++) { + particles[n + 1]->applyBoostTo(*particles[0]); + } + + // + //---> return the weight of event + // + + return wt; + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT2 &particles) { + // do nothing, will never be called + return 0.0; + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT3 &particles) { + Vector4R *_Particles[3]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT4 &particles) { + Vector4R *_Particles[4]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT5 &particles) { + Vector4R *_Particles[5]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT6 &particles) { + Vector4R *_Particles[6]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT7 &particles) { + Vector4R *_Particles[7]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT8 &particles) { + Vector4R *_Particles[8]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT9 &particles) { + Vector4R *_Particles[9]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + + return process(evt, _Particles); + } + + __host__ __device__ inline GReal_t operator()(const GInt_t evt, GT10 &particles) { + Vector4R *_Particles[10]; + + _Particles[0] = &thrust::get<0>(particles); + _Particles[1] = &thrust::get<1>(particles); + _Particles[2] = &thrust::get<2>(particles); + _Particles[3] = &thrust::get<3>(particles); + _Particles[4] = &thrust::get<4>(particles); + _Particles[5] = &thrust::get<5>(particles); + _Particles[6] = &thrust::get<6>(particles); + _Particles[7] = &thrust::get<7>(particles); + _Particles[8] = &thrust::get<8>(particles); + _Particles[9] = &thrust::get<9>(particles); + + return process(evt, _Particles); + } }; - } #endif /* DECAYMOTHERS_H_ */ diff --git a/extern/MCBooster/mcbooster/functors/FlagAcceptReject.h b/extern/MCBooster/mcbooster/functors/FlagAcceptReject.h index e140b3c5d..07cfa3691 100644 --- a/extern/MCBooster/mcbooster/functors/FlagAcceptReject.h +++ b/extern/MCBooster/mcbooster/functors/FlagAcceptReject.h @@ -2,11 +2,11 @@ * FlagAcceptReject.h * * Copyright 2016 Antonio Augusto Alves Junior - * + * * Created on : 29/03/2016 * Author: Antonio Augusto Alves Junior */ - + /* This file is part of MCBooster. @@ -30,64 +30,54 @@ #ifndef FLAGACCEPTEDREJECTED_H_ #define FLAGACCEPTEDREJECTED_H_ - - #include #include #include -namespace mcbooster -{ +namespace mcbooster { /**\struct FlagAcceptReject * Flags generated events as accepted (1) or rejected (0). */ -struct FlagAcceptReject -{ - - GReal_t wmax; ///< maximum weight - GUInt_t seed; //added for GooFit functionality. - /** - * FlagAcceptReject constructor. It is initialized with the value of the maximum weight - * with which event weights will be compared. - */ - FlagAcceptReject(const GReal_t _wmax) : - wmax(_wmax), seed(0) - { } - FlagAcceptReject(const GReal_t _wmax, GUInt_t _seed) : //Modification for GooFit - wmax(_wmax), seed(_seed) - {} - /** - * hash function. Generate hashs to be used in random number generation initialization - */ - __host__ __device__ inline GUInt_t hash(GUInt_t a) - { - a = (a + 0x7ed55d16) + (a << 12); - a = (a ^ 0xc761c23c) ^ (a >> 19); - a = (a + 0x165667b1) + (a << 5); - a = (a + 0xd3a2646c) ^ (a << 9); - a = (a + 0xfd7046c5) + (a << 3); - a = (a ^ 0xb55a4f09) ^ (a >> 16); - return a; - } - /** - * operator(). Takes the events index and weight and so flag it as accepted and rejected - * - */ - __host__ __device__ inline GBool_t operator ()(GLong_t idx, GReal_t weight) - { +struct FlagAcceptReject { + GReal_t wmax; ///< maximum weight + GUInt_t seed; // added for GooFit functionality. + /** + * FlagAcceptReject constructor. It is initialized with the value of the maximum weight + * with which event weights will be compared. + */ + FlagAcceptReject(const GReal_t _wmax) + : wmax(_wmax) + , seed(0) {} + FlagAcceptReject(const GReal_t _wmax, GUInt_t _seed) + : // Modification for GooFit + wmax(_wmax) + , seed(_seed) {} + /** + * hash function. Generate hashs to be used in random number generation initialization + */ + __host__ __device__ inline GUInt_t hash(GUInt_t a) { + a = (a + 0x7ed55d16) + (a << 12); + a = (a ^ 0xc761c23c) ^ (a >> 19); + a = (a + 0x165667b1) + (a << 5); + a = (a + 0xd3a2646c) ^ (a << 9); + a = (a + 0xfd7046c5) + (a << 3); + a = (a ^ 0xb55a4f09) ^ (a >> 16); + return a; + } + /** + * operator(). Takes the events index and weight and so flag it as accepted and rejected + * + */ + __host__ __device__ inline GBool_t operator()(GLong_t idx, GReal_t weight) { thrust::random::minstd_rand0 randEng(2863311530); thrust::uniform_real_distribution uniDist(0.0, wmax); - randEng.discard(idx+seed); + randEng.discard(idx + seed); GReal_t uni = uniDist(randEng); // printf("accRej idx %li seed%u %.5g %.5g %s\n",idx, seed, uni, weight, (uni #include -namespace mcbooster -{ +namespace mcbooster { -struct isAccepted -{ - __host__ __device__ - inline bool operator()(const int x) - { - return (x == 1 ) ; - } +struct isAccepted { + __host__ __device__ inline bool operator()(const int x) { return (x == 1); } }; - - } - #endif /* ISACCEPTED_H_ */ diff --git a/extern/MCBooster/mcbooster/functors/RandGen.h b/extern/MCBooster/mcbooster/functors/RandGen.h index 4a28306e3..147283a94 100644 --- a/extern/MCBooster/mcbooster/functors/RandGen.h +++ b/extern/MCBooster/mcbooster/functors/RandGen.h @@ -22,7 +22,6 @@ * along with MCBooster. If not, see . */ - #ifndef RANDGEN_H_ #define RANDGEN_H_ @@ -31,81 +30,63 @@ #include #include - -namespace mcbooster -{ +namespace mcbooster { /**\struct RandGen * Fill a given vector with random numbers between 0 and 1. */ -struct RandGen -{ - GInt_t fNDaughters; ///< Number of daughter particles - GReal_t *fRndNumbers;///< Pointer to the array of random numbers - /** - * RandGen ctor. Takes the number of daughter particles and the address of the array - * of to be filled with random numbers - */ - RandGen(const GInt_t _ndaughters, GReal_t *_rnd) - : fNDaughters(_ndaughters) - , fRndNumbers(_rnd) - { - } - - /** - * hash function. Generate hashs to be used in random number generation initialization - */ - __host__ __device__ inline GUInt_t hash(GUInt_t a) - { - a = (a + 0x7ed55d16) + (a << 12); - a = (a ^ 0xc761c23c) ^ (a >> 19); - a = (a + 0x165667b1) + (a << 5); - a = (a + 0xd3a2646c) ^ (a << 9); - a = (a + 0xfd7046c5) + (a << 3); - a = (a ^ 0xb55a4f09) ^ (a >> 16); - return a; - } - - /** - * operator(). Calculate and set random numbers. It takes the index of the event. - */ - __host__ __device__ inline void operator ()(GLong_t idx) - { - GUInt_t seed = hash(idx); - thrust::random::default_random_engine randEng(seed); - thrust::uniform_real_distribution uniDist(0.0, 1.0); - - - fRndNumbers[idx] = uniDist(randEng); - - } - +struct RandGen { + GInt_t fNDaughters; ///< Number of daughter particles + GReal_t *fRndNumbers; ///< Pointer to the array of random numbers + /** + * RandGen ctor. Takes the number of daughter particles and the address of the array + * of to be filled with random numbers + */ + RandGen(const GInt_t _ndaughters, GReal_t *_rnd) + : fNDaughters(_ndaughters) + , fRndNumbers(_rnd) {} + + /** + * hash function. Generate hashs to be used in random number generation initialization + */ + __host__ __device__ inline GUInt_t hash(GUInt_t a) { + a = (a + 0x7ed55d16) + (a << 12); + a = (a ^ 0xc761c23c) ^ (a >> 19); + a = (a + 0x165667b1) + (a << 5); + a = (a + 0xd3a2646c) ^ (a << 9); + a = (a + 0xfd7046c5) + (a << 3); + a = (a ^ 0xb55a4f09) ^ (a >> 16); + return a; + } + + /** + * operator(). Calculate and set random numbers. It takes the index of the event. + */ + __host__ __device__ inline void operator()(GLong_t idx) { + GUInt_t seed = hash(idx); + thrust::random::default_random_engine randEng(seed); + thrust::uniform_real_distribution uniDist(0.0, 1.0); + + fRndNumbers[idx] = uniDist(randEng); + } }; -struct RandGen2 -{ - /** - * RandGen2 ctor. Takes the number of daughter particles and the address of the array - * of to be filled with random numbers - */ - - - /** - * operator(). Calculate and set random numbers. It takes the index of the event. - */ - __host__ __device__ inline GReal_t operator ()(GInt_t idx) - { - - thrust::random::default_random_engine randEng; - randEng.discard(idx); - thrust::uniform_real_distribution uniDist(0.0, 1.0); - - return uniDist(randEng); - - - } - +struct RandGen2 { + /** + * RandGen2 ctor. Takes the number of daughter particles and the address of the array + * of to be filled with random numbers + */ + + /** + * operator(). Calculate and set random numbers. It takes the index of the event. + */ + __host__ __device__ inline GReal_t operator()(GInt_t idx) { + thrust::random::default_random_engine randEng; + randEng.discard(idx); + thrust::uniform_real_distribution uniDist(0.0, 1.0); + + return uniDist(randEng); + } }; - } #endif /* RANDGEN_H_ */ diff --git a/extern/MCBooster/mcbooster/strided_iterator.h b/extern/MCBooster/mcbooster/strided_iterator.h index 910fdac73..9aed9ac79 100644 --- a/extern/MCBooster/mcbooster/strided_iterator.h +++ b/extern/MCBooster/mcbooster/strided_iterator.h @@ -24,7 +24,6 @@ * along with MCBooster. If not, see . */ - #ifndef STRIDED_ITERATOR_H_ #define STRIDED_ITERATOR_H_ @@ -33,64 +32,47 @@ #include #include - -namespace mcbooster -{ +namespace mcbooster { /** \class strided_range * Strided range iterator original code: https://github.com/thrust/thrust/blob/master/examples/strided_range.cu */ template -class strided_range -{ -public: - - typedef typename thrust::iterator_difference::type difference_type; +class strided_range { + public: + typedef typename thrust::iterator_difference::type difference_type; - struct stride_functor: public thrust::unary_function - { - difference_type stride; + struct stride_functor : public thrust::unary_function { + difference_type stride; - stride_functor(difference_type stride) : - stride(stride) - { - } + stride_functor(difference_type stride) + : stride(stride) {} - __host__ __device__ difference_type operator()( - const difference_type& i) const - { - return stride * i; - } - }; + __host__ __device__ difference_type operator()(const difference_type &i) const { return stride * i; } + }; - typedef typename thrust::counting_iterator CountingIterator; - typedef typename thrust::transform_iterator TransformIterator; - typedef typename thrust::permutation_iterator PermutationIterator; + typedef typename thrust::counting_iterator CountingIterator; + typedef typename thrust::transform_iterator TransformIterator; + typedef typename thrust::permutation_iterator PermutationIterator; - /// type of the strided_range iterator - typedef PermutationIterator iterator; + /// type of the strided_range iterator + typedef PermutationIterator iterator; - /// construct strided_range for the range [first,last) - strided_range(Iterator first, Iterator last, difference_type stride) : - first(first), last(last), stride(stride) - { - } + /// construct strided_range for the range [first,last) + strided_range(Iterator first, Iterator last, difference_type stride) + : first(first) + , last(last) + , stride(stride) {} - iterator begin() const - { - return PermutationIterator(first, - TransformIterator(CountingIterator(0), stride_functor(stride))); - } + iterator begin() const { + return PermutationIterator(first, TransformIterator(CountingIterator(0), stride_functor(stride))); + } - iterator end() const - { - return begin() + ((last - first) + (stride - 1)) / stride; - } + iterator end() const { return begin() + ((last - first) + (stride - 1)) / stride; } -protected: - Iterator first; - Iterator last; - difference_type stride; + protected: + Iterator first; + Iterator last; + difference_type stride; }; } diff --git a/extern/MCBooster/src/CompareWithTGenPhaseSpace.cu b/extern/MCBooster/src/CompareWithTGenPhaseSpace.cu index 3dbf943c8..f5f0b3a61 100644 --- a/extern/MCBooster/src/CompareWithTGenPhaseSpace.cu +++ b/extern/MCBooster/src/CompareWithTGenPhaseSpace.cu @@ -2,11 +2,11 @@ * PerformanceTest.cu * * Copyright 2016 Antonio Augusto Alves Junior - * + * * Created on : 10/03/2016 * Author: augalves */ - + /* This file is part of MCBooster. @@ -32,9 +32,9 @@ #include #include #include -//command line +// command line #include -//this lib +// this lib #include #include #include @@ -43,7 +43,7 @@ #include #include -//ROOT +// ROOT #include "TROOT.h" #include "TString.h" #include "TFile.h" @@ -60,315 +60,266 @@ using namespace std; using namespace mcbooster; -GInt_t factorial(GInt_t n) -{ - - return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; -} +GInt_t factorial(GInt_t n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -void splitString(const std::string &s, const char delim, std::vector &elems) -{ - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) - { - elems.push_back(item); - } - //return elems; - return; +void splitString(const std::string &s, const char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(item); + } + // return elems; + return; } -void splitReal(const std::string &s, const char delim, std::vector &elems) -{ - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) - { - elems.push_back(std::stod(item)); - } - //return elems; - return; +void splitReal(const std::string &s, const char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(std::stod(item)); + } + // return elems; + return; } +GInt_t main(int argv, char **argc) { + GULong_t nevents = 0; + string output_dir = ""; + GReal_t mother; + string _names; + string _masses; + + try { + TCLAP::CmdLine cmd("Command line arguments for GenerateSample", '='); + + TCLAP::ValueArg eArg("n", "number-of-events", "Number of events", true, 1e6, "long"); + cmd.add(eArg); + + TCLAP::ValueArg oArg("o", "output-file", "Output file", false, "./phsp.root", "string"); + cmd.add(oArg); + + TCLAP::ValueArg pArg( + "p", + "particles", + "List of particles. First particle is the mother.Example: D0->Kpipi is 'D0;K;pi+;pi-", + true, + "", + "string"); + cmd.add(pArg); - -GInt_t main(int argv, char** argc) -{ - - GULong_t nevents=0; - string output_dir=""; - GReal_t mother; - string _names; - string _masses; - - try { - - TCLAP::CmdLine cmd("Command line arguments for GenerateSample", '='); - - TCLAP::ValueArg eArg("n", "number-of-events", - "Number of events", - true, 1e6, "long"); - cmd.add(eArg); - - - TCLAP::ValueArg oArg("o", "output-file", - "Output file", - false, "./phsp.root", "string"); - cmd.add(oArg); - - - TCLAP::ValueArg pArg("p", "particles", - "List of particles. First particle is the mother.Example: D0->Kpipi is 'D0;K;pi+;pi-", - true, "", "string"); - cmd.add(pArg); - - - TCLAP::ValueArg mArg("m", "masses", - "Particle mass. First particle is the mother. Example: D0->Kpipi is '1.865;0.439;0.139;0.139", - true, "" ,"string"); - cmd.add(mArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nevents = eArg.getValue(); - output_dir = oArg.getValue(); - _masses = mArg.getValue(); - _names = pArg.getValue(); - - } catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - - vector names_temp; - vector masses_temp; - - splitReal(_masses, ';' , masses_temp); - splitString(_names, ';' , names_temp ); - - if(masses_temp.size() < 3 || masses_temp.size()>9) - { - cout << "Exit. Number of particles is (< 2) or (> 9)." < masses(masses_temp.size()-1); - std::copy ( masses_temp.begin() +1, masses_temp.end(), masses.begin() ); - - PhaseSpace phsp(mother_mass, masses, nevents); - Events GenEvents(masses.size(), nevents); - - timespec time1, time2; - phsp.Generate(Vector4R(mother_mass, 0.0, 0.0, 0.0)); - - ///------------------------------------- - //unweight - clock_gettime(CLOCK_REALTIME, &time1); - phsp.Unweight(); - - clock_gettime(CLOCK_REALTIME, &time2); - - GReal_t unweight_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - - //------------------------------------- - clock_gettime(CLOCK_REALTIME, &time1); - - /// Create Events container - phsp.Export(&GenEvents); - - clock_gettime(CLOCK_REALTIME, &time2); - - GReal_t exp_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - - phsp.Export(&GenEvents); - - cout << "-----------------------------------------------------"< H1D; - map H1D_ROOT; - - map min_histo_limits; - map max_histo_limits; - - - for(GInt_t i=0; i=i) continue; - - GInt_t index = i+j*masses.size(); - TString name = TString::Format("M(%s,%s)", names_temp[j+1].c_str(), names_temp[i+1].c_str() ); - GReal_t min = masses[j]+masses[i]; - GReal_t max = mother_mass; - for(GInt_t k=0; k M( "<< names_temp[j+1] << ", " << names_temp[i+1] << ")" <Sumw2(); -h2->Sumw2(); - H1D.insert(std::make_pair(index, h)); - H1D_ROOT.insert(std::make_pair(index, h2)); - - } - } - - - //MCBooster - for(GInt_t event=0; event=i) continue; - - GInt_t index = i+j*masses.size(); - - Vector4R p = GenEvents.fDaughters[j][event] + GenEvents.fDaughters[i][event]; - - H1D[index]->Fill( p.mass(), GenEvents.fWeights[event] ); - - - } - - } - - } - - //ROOT - TGenPhaseSpace phsp_root; - TLorentzVector mother_root(0.0, 0.0, 0.0, mother_mass); - phsp_root.SetDecay(mother_root, masses.size(), masses.data()); - std::vector> particles_root(masses.size(), std::vector(nevents)); - std::vector weigts_root(nevents); - clock_gettime(CLOCK_REALTIME, &time1); - for(GInt_t event=0; event=i) continue; - - GInt_t index = i+j*masses.size(); - - TLorentzVector pr= particles_root[i][event] +particles_root[j][event] ; - H1D_ROOT[index]->Fill( pr.M(), weigts_root[event] ); - - } - } - - - - } - - TLegend *leg; - - for(GInt_t i=0; i=i) continue; - GInt_t index = i+j*masses.size(); - TCanvas *c = new TCanvas( H1D[index]->getName(), H1D[index]->getName(), 600, 500 ); - - H1D[index]->Draw("e0"); - H1D[index]->SetMarkerColor(kBlue); - H1D[index]->SetMarkerSize(1.0); - H1D[index]->SetMarkerStyle(8); - H1D[index]->SetStats(0); - - H1D_ROOT[index]->Draw("HISTsame"); - H1D_ROOT[index]->SetLineColor(kRed); - H1D_ROOT[index]->SetLineWidth(2); - H1D_ROOT[index]->SetStats(0); - - leg = new TLegend(0.60,0.8,0.90,0.9); - leg->AddEntry(H1D[index] ,"mcbooster","l"); - leg->AddEntry(H1D_ROOT[index] ,"TGenPhaseSpace","l"); - leg->Draw(); - - c->Print( TString::Format("./histo_%d%d.pdf", i, j ) ); - - } - - } - - - - - myapp->Run(); - return 0; + TCLAP::ValueArg mArg( + "m", + "masses", + "Particle mass. First particle is the mother. Example: D0->Kpipi is '1.865;0.439;0.139;0.139", + true, + "", + "string"); + cmd.add(mArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nevents = eArg.getValue(); + output_dir = oArg.getValue(); + _masses = mArg.getValue(); + _names = pArg.getValue(); + + } catch(TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + vector names_temp; + vector masses_temp; + + splitReal(_masses, ';', masses_temp); + splitString(_names, ';', names_temp); + + if(masses_temp.size() < 3 || masses_temp.size() > 9) { + cout << "Exit. Number of particles is (< 2) or (> 9)." << std::endl; + exit(0); + } + + if(masses_temp.size() != names_temp.size()) { + cout << "Exit. Number of particles is different of number of names." << std::endl; + exit(0); + } + + // dump configuration + cout << "-----------------------------------------------------" << std::endl; + cout << "---------------------- MCBooster --------------------" << std::endl; + cout << "- Mother name: " << names_temp[0] << " mass: " << masses_temp[0] << std::endl; + for(GInt_t i = 1; i < masses_temp.size(); i++) { + cout << "- Daughter name: " << names_temp[i] << " mass: " << masses_temp[i] << std::endl; + } + cout << "- Number of events: " << nevents << std::endl; + cout << "- Output file: " << output_dir << std::endl; + cout << "-----------------------------------------------------" << std::endl; + + // Generation + GReal_t mother_mass = masses_temp[0]; + vector masses(masses_temp.size() - 1); + std::copy(masses_temp.begin() + 1, masses_temp.end(), masses.begin()); + + PhaseSpace phsp(mother_mass, masses, nevents); + Events GenEvents(masses.size(), nevents); + + timespec time1, time2; + phsp.Generate(Vector4R(mother_mass, 0.0, 0.0, 0.0)); + + ///------------------------------------- + // unweight + clock_gettime(CLOCK_REALTIME, &time1); + phsp.Unweight(); + + clock_gettime(CLOCK_REALTIME, &time2); + + GReal_t unweight_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + //------------------------------------- + clock_gettime(CLOCK_REALTIME, &time1); + + /// Create Events container + phsp.Export(&GenEvents); + + clock_gettime(CLOCK_REALTIME, &time2); + + GReal_t exp_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + phsp.Export(&GenEvents); + + cout << "-----------------------------------------------------" << std::endl; + cout << "----------------------- Timing ----------------------" << std::endl; + cout << "Event generation: " << phsp.GetEvtTime() << std::endl; + cout << "Unweight generation: " << unweight_time_used << std::endl; + cout << "Export events to host: " << exp_time_used << std::endl; + cout << "-----------------------------------------------------" << std::endl; + + TApplication *myapp = new TApplication("myapp", 0, 0); + + GInt_t number_of_combinations = factorial(masses.size()) / (2 * factorial(masses.size() - 2)); + + map H1D; + map H1D_ROOT; + + map min_histo_limits; + map max_histo_limits; + + for(GInt_t i = 0; i < masses.size(); i++) { + for(GInt_t j = 0; j < masses.size(); j++) { + if(j >= i) + continue; + + GInt_t index = i + j * masses.size(); + TString name = TString::Format("M(%s,%s)", names_temp[j + 1].c_str(), names_temp[i + 1].c_str()); + GReal_t min = masses[j] + masses[i]; + GReal_t max = mother_mass; + for(GInt_t k = 0; k < masses.size(); k++) { + if((k != j) && (k != i)) + max -= masses[k]; + } + max_histo_limits[index] = max; + min_histo_limits[index] = min; + cout << "Adding [" << index << "] ---> M( " << names_temp[j + 1] << ", " << names_temp[i + 1] << ")" + << std::endl; + cout << "Histogram " << name.Data() << " min " << min << " max " << max << std::endl; + TH1D *h + = new TH1D(name.Data(), TString::Format(";%s [GeV/c^{2}];Yield", name.Data()).Data(), 100, min, max); + TH1D *h2 = new TH1D(TString::Format("%s_ROOT", name.Data()).Data(), + TString::Format(";%s [GeV/c^{2}];Yield", name.Data()).Data(), + 100, + min, + max); + h->Sumw2(); + h2->Sumw2(); + H1D.insert(std::make_pair(index, h)); + H1D_ROOT.insert(std::make_pair(index, h2)); + } + } + + // MCBooster + for(GInt_t event = 0; event < nevents; event++) { + for(GInt_t i = 0; i < masses.size(); i++) { + for(GInt_t j = 0; j < masses.size(); j++) { + if(j >= i) + continue; + + GInt_t index = i + j * masses.size(); + + Vector4R p = GenEvents.fDaughters[j][event] + GenEvents.fDaughters[i][event]; + + H1D[index]->Fill(p.mass(), GenEvents.fWeights[event]); + } + } + } + + // ROOT + TGenPhaseSpace phsp_root; + TLorentzVector mother_root(0.0, 0.0, 0.0, mother_mass); + phsp_root.SetDecay(mother_root, masses.size(), masses.data()); + std::vector> particles_root(masses.size(), std::vector(nevents)); + std::vector weigts_root(nevents); + clock_gettime(CLOCK_REALTIME, &time1); + for(GInt_t event = 0; event < nevents; event++) { + weigts_root[event] = phsp_root.Generate(); + for(GInt_t i = 0; i < masses.size(); i++) { + TLorentzVector pr = *phsp_root.GetDecay(i); + particles_root[i][event] = pr; + } + } + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t root_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + cout << "-----------------------------------------------------" << std::endl; + cout << "----------------------- Timing ----------------------" << std::endl; + cout << "Event generation in ROOT: " << root_time_used << std::endl; + cout << "-----------------------------------------------------" << std::endl; + cout << "----------------------- Timing ----------------------" << std::endl; + + for(GInt_t event = 0; event < nevents; event++) { + for(GInt_t i = 0; i < masses.size(); i++) { + for(GInt_t j = 0; j < masses.size(); j++) { + if(j >= i) + continue; + + GInt_t index = i + j * masses.size(); + + TLorentzVector pr = particles_root[i][event] + particles_root[j][event]; + H1D_ROOT[index]->Fill(pr.M(), weigts_root[event]); + } + } + } + + TLegend *leg; + + for(GInt_t i = 0; i < masses.size(); i++) { + for(GInt_t j = 0; j < masses.size(); j++) { + if(j >= i) + continue; + GInt_t index = i + j * masses.size(); + TCanvas *c = new TCanvas(H1D[index]->getName(), H1D[index]->getName(), 600, 500); + + H1D[index]->Draw("e0"); + H1D[index]->SetMarkerColor(kBlue); + H1D[index]->SetMarkerSize(1.0); + H1D[index]->SetMarkerStyle(8); + H1D[index]->SetStats(0); + + H1D_ROOT[index]->Draw("HISTsame"); + H1D_ROOT[index]->SetLineColor(kRed); + H1D_ROOT[index]->SetLineWidth(2); + H1D_ROOT[index]->SetStats(0); + + leg = new TLegend(0.60, 0.8, 0.90, 0.9); + leg->AddEntry(H1D[index], "mcbooster", "l"); + leg->AddEntry(H1D_ROOT[index], "TGenPhaseSpace", "l"); + leg->Draw(); + + c->Print(TString::Format("./histo_%d%d.pdf", i, j)); + } + } + + myapp->Run(); + return 0; } diff --git a/extern/MCBooster/src/Generate.cpp b/extern/MCBooster/src/Generate.cpp index 857f770d4..44c8fdf17 100644 --- a/extern/MCBooster/src/Generate.cpp +++ b/extern/MCBooster/src/Generate.cpp @@ -34,7 +34,7 @@ #define CUDA_API_PER_THREAD_DEFAULT_STREAM -//this lib +// this lib #include #include #include @@ -43,7 +43,7 @@ #include #include #include -//root +// root #include #include #include @@ -54,373 +54,308 @@ using namespace std; using namespace mcbooster; +struct Dataset : public IFunctionArray { + Dataset() { dim = 4; } + __host__ __device__ inline GReal_t cosHELANG(const Vector4R p, const Vector4R q, const Vector4R d) { + GReal_t pd = p * d; + GReal_t pq = p * q; + GReal_t qd = q * d; + GReal_t mp2 = p.mass2(); + GReal_t mq2 = q.mass2(); + GReal_t md2 = d.mass2(); -struct Dataset: public IFunctionArray -{ - Dataset() - { - dim = 4; - } + return (pd * mq2 - pq * qd) / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); + } - __host__ __device__ inline GReal_t cosHELANG(const Vector4R p, const Vector4R q, - const Vector4R d) - { - GReal_t pd = p * d; - GReal_t pq = p * q; - GReal_t qd = q * d; - GReal_t mp2 = p.mass2(); - GReal_t mq2 = q.mass2(); - GReal_t md2 = d.mass2(); + __host__ __device__ inline GReal_t deltaAngle(const Vector4R &p4_p, + const Vector4R &p4_d1, + const Vector4R &p4_d2, + const Vector4R &p4_h1, + const Vector4R &p4_h2) { + Vector4R p4_d1p, p4_h1p, p4_h2p, p4_d2p; - return (pd * mq2 - pq * qd) - / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); + Vector4R d1_perp, d1_prime, h1_perp; + Vector4R D; - } + D = p4_d1 + p4_d2; - __host__ __device__ inline GReal_t deltaAngle(const Vector4R& p4_p, - const Vector4R& p4_d1, const Vector4R& p4_d2, const Vector4R& p4_h1, - const Vector4R& p4_h2) - { + d1_perp = p4_d1 - (D.dot(p4_d1) / D.dot(D)) * D; + h1_perp = p4_h1 - (D.dot(p4_h1) / D.dot(D)) * D; - Vector4R p4_d1p, p4_h1p, p4_h2p, p4_d2p; + // orthogonal to both D and d1_perp - Vector4R d1_perp, d1_prime, h1_perp; - Vector4R D; + d1_prime = D.cross(d1_perp); - D = p4_d1 + p4_d2; + d1_perp = d1_perp / d1_perp.d3mag(); + d1_prime = d1_prime / d1_prime.d3mag(); - d1_perp = p4_d1 - (D.dot(p4_d1) / D.dot(D)) * D; - h1_perp = p4_h1 - (D.dot(p4_h1) / D.dot(D)) * D; + GReal_t x, y; - // orthogonal to both D and d1_perp + x = d1_perp.dot(h1_perp); + y = d1_prime.dot(h1_perp); - d1_prime = D.cross(d1_perp); + GReal_t chi = atan2(y, x); - d1_perp = d1_perp / d1_perp.d3mag(); - d1_prime = d1_prime / d1_prime.d3mag(); + if(chi < 0.0) + chi += 2.0 * PI; - GReal_t x, y; + return chi; + } - x = d1_perp.dot(h1_perp); - y = d1_prime.dot(h1_perp); + __host__ __device__ inline void operator()(const GInt_t n, Vector4R **particles, GReal_t *variables) { + Vector4R pJpsi = *particles[0]; + Vector4R pK = *particles[1]; + Vector4R ppi = *particles[2]; + Vector4R pMup = *particles[3]; + Vector4R pMum = *particles[4]; - GReal_t chi = atan2(y, x); - - if (chi < 0.0) - chi += 2.0*PI; - - return chi; - - } - - __host__ __device__ - inline void operator()(const GInt_t n, Vector4R** particles, GReal_t* variables) - { - Vector4R pJpsi = *particles[0]; - Vector4R pK = *particles[1]; - Vector4R ppi = *particles[2]; - Vector4R pMup = *particles[3]; - Vector4R pMum = *particles[4]; - - //K* helicity angle - Vector4R pB0 = pJpsi + pK + ppi; - Vector4R pKpi = pK + ppi; - Vector4R pJpsipi = pJpsi + ppi; - - - variables[0] = pKpi.mass(); - variables[1] = pJpsipi.mass(); - variables[2] = cosHELANG(pB0, pKpi, pK); - variables[3] = cosHELANG(pB0, pJpsi, pMup); - variables[4] = deltaAngle(pB0, pK, ppi, pMup, pMum); - - } + // K* helicity angle + Vector4R pB0 = pJpsi + pK + ppi; + Vector4R pKpi = pK + ppi; + Vector4R pJpsipi = pJpsi + ppi; + variables[0] = pKpi.mass(); + variables[1] = pJpsipi.mass(); + variables[2] = cosHELANG(pB0, pKpi, pK); + variables[3] = cosHELANG(pB0, pJpsi, pMup); + variables[4] = deltaAngle(pB0, pK, ppi, pMup, pMum); + } }; +GInt_t main(void) { + TApplication *myapp = new TApplication("myapp", 0, 0); + GLong_t events = 10000000; + size_t ndaughters = 3; + GReal_t mass0 = 5.2795; -GInt_t main(void) -{ + // Particles mothers(events, Vector4R(5.2795,0.0,0.0,0.0) ); - TApplication *myapp=new TApplication("myapp",0,0); + //{ "J/psi", "K", "pi", "pi" } - GLong_t events = 10000000; - size_t ndaughters = 3; - GReal_t mass0 = 5.2795; + vector namesB0; + namesB0.push_back("J/#psi"); + namesB0.push_back("K"); + namesB0.push_back("pi"); - //Particles mothers(events, Vector4R(5.2795,0.0,0.0,0.0) ); + //{ 3.096916, 0.493677, 0.13957018 } + vector massesB0; + massesB0.push_back(3.096916); + massesB0.push_back(0.493677); + massesB0.push_back(0.13957018); - //{ "J/psi", "K", "pi", "pi" } + // chronometer + timespec time1, time2; - vector namesB0; - namesB0.push_back("J/#psi"); - namesB0.push_back("K"); - namesB0.push_back("pi"); + cout << "=========================================================" << std::endl; + cout << "=================== B0 -> J/psi K pi= ================" << std::endl; + cout << "=========================================================" << std::endl; + std::cout << "Number of events: " << events << std::endl; - //{ 3.096916, 0.493677, 0.13957018 } - vector massesB0; - massesB0.push_back(3.096916); - massesB0.push_back(0.493677); - massesB0.push_back(0.13957018); + clock_gettime(CLOCK_REALTIME, &time1); - //chronometer - timespec time1, time2; + /// Create PhaseSpace object for B0-> K pi J/psi + PhaseSpace phsp(5.2795, massesB0, events); - cout << "=========================================================" < J/psi K pi= ================" < K pi J/psi - PhaseSpace phsp(5.2795, massesB0, events); + cout << "|\t PhaseSpace ctor time [B0]:\t " << phsp_time_used << " s" << std::endl; - clock_gettime(CLOCK_REALTIME, &time2); + clock_gettime(CLOCK_REALTIME, &time1); + /// Generate events B0-> K pi J/psi + phsp.Generate(Vector4R(5.2795, 0.0, 0.0, 0.0)); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t cpu_time_used = phsp.GetEvtTime(); - GReal_t phsp_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); + /* + cpu_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec + + time_diff(time1, time2).tv_nsec * 1.0e-9));*/ - cout << "|\t PhaseSpace ctor time [B0]:\t " << phsp_time_used << " s" - < K pi J/psi - phsp.Generate(Vector4R(5.2795, 0.0, 0.0, 0.0)); - clock_gettime(CLOCK_REALTIME, &time2); - GReal_t cpu_time_used = phsp.GetEvtTime(); + /// Print the first 10 events with corresponding weights + for(GInt_t event = 0; event < 10; event++) { + cout << "Event: " << event << std::endl << "\t| weight " << phsp.GetWeights()[event] << std::endl; - /* - cpu_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9));*/ + for(GInt_t daughter = 0; daughter < 3; daughter++) { + Vector4R v = phsp.GetDaughters(daughter)[event]; - cout << "|\t Generate time [B0]:\t " << cpu_time_used << " s" < namesJpsi; + namesJpsi.push_back("mu+"); + namesJpsi.push_back("mu-"); - /// Print the first 10 events with corresponding weights - for (GInt_t event = 0; event < 10; event++) - { - cout << "Event: " << event < massesJpsi; + massesJpsi.push_back(0.100); + massesJpsi.push_back(0.100); - for (GInt_t daughter = 0; daughter < 3; daughter++) - { - Vector4R v= phsp.GetDaughters(daughter)[event]; + cout << "=========================================================" << std::endl; + cout << "==================== J/psi -> mu mu ==================" << std::endl; + cout << "=========================================================" << std::endl; + std::cout << "Number of events: " << events << std::endl; - cout << " \t| " << namesB0[daughter] << " : mass " - << v.mass() - << " 4-momentum ( " - << v.get(0) << ", " - << v.get(1) << ", " - << v.get(2) << ", " - << v.get(3) << ") " - < namesJpsi; - namesJpsi.push_back("mu+"); - namesJpsi.push_back("mu-"); - - //{ 3.096916, 0.493677, 0.13957018 } - vector massesJpsi; - massesJpsi.push_back(0.100); - massesJpsi.push_back(0.100); - - cout << "=========================================================" < mu mu ==================" <(DataJpsiKpi, JpsiKpiMuMu, Var); - clock_gettime(CLOCK_REALTIME, &time2); - GReal_t Dataset_time = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - cout << "=========================================================" <Fill( result_CosThetaK[event], phsp.GetWeights()[event] ); - cosThetaMu->Fill(result_CosThetaMu[event], phsp.GetWeights()[event] ); - deltaAngle->Fill(result_DeltaAngle[event], phsp.GetWeights()[event] ); - MKpi->Fill(result_MKpi[event],phsp.GetWeights()[event] ); - MJpsipi->Fill(result_MJpsipi[event], phsp.GetWeights()[event] ); - - } - - TCanvas *c_cosThetaK = new TCanvas( "cosThetaK", "", 600, 500 ); - cosThetaK->Draw("HIST"); - cosThetaK->SetLineColor(4); - cosThetaK->SetLineWidth(2); - cosThetaK->SetStats(0); - cosThetaK->SetMinimum(0); - c_cosThetaK->Print( "cosThetaK.pdf" ); - - TCanvas *c_cosThetaMu = new TCanvas( "cosThetaMu", "", 600, 500 ); - cosThetaMu->Draw("HIST"); - cosThetaMu->SetLineColor(4); - cosThetaMu->SetLineWidth(2); - cosThetaMu->SetStats(0); - cosThetaMu->SetMinimum(0); - c_cosThetaMu->Print( "cosThetaMu.pdf" ); - - TCanvas *c_deltaAngle = new TCanvas( "deltaAngle", "", 600, 500 ); - deltaAngle->Draw("HIST"); - deltaAngle->SetLineColor(4); - deltaAngle->SetLineWidth(2); - deltaAngle->SetStats(0); - deltaAngle->SetMinimum(0); - c_deltaAngle->Print( "deltaAngle.pdf" ); - - TCanvas *c_MKpi = new TCanvas( "MKpi", "", 600, 500 ); - MKpi->Draw("HIST"); - MKpi->SetLineColor(4); - MKpi->SetLineWidth(2); - MKpi->SetStats(0); - MKpi->SetMinimum(0); - c_MKpi->Print( "MKpi.pdf" ); - - TCanvas *c_MJpsipi = new TCanvas( "MJpsipi", "", 600, 500 ); - MJpsipi->Draw("HIST"); - MJpsipi->SetLineColor(4); - MJpsipi->SetLineWidth(2); - MJpsipi->SetStats(0); - MJpsipi->SetMinimum(0); - c_MJpsipi->Print( "MJpsipi.pdf" ); - - - - - TH2D *dalitz = new TH2D("dalitz", - TString::Format(";M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]" - , namesB0[0].c_str(), namesB0[1].c_str() - , namesB0[1].c_str(), namesB0[2].c_str() ).Data(), - 100, pow(massesB0[0]+massesB0[2],2), pow(mass0 - massesB0[1],2), - 100, pow(massesB0[1]+massesB0[2],2), pow(mass0 - massesB0[0],2) ); - - - for(GInt_t event=0; eventFill( result_MJpsipi[event]*result_MJpsipi[event], - result_MKpi[event]*result_MKpi[event], - phsp.GetWeights()[event] ); - - } - - TCanvas *c2 = new TCanvas( "dalitz", "", 600, 500 ); - dalitz->Draw("COLZ"); - dalitz->SetStats(0); - c2->Print( "dalitz.pdf" ); - - myapp->Run(); - return 0; + clock_gettime(CLOCK_REALTIME, &time1); + phspJpsi.Generate(phsp.GetDaughters(0)); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t cpu_time_usedJpsi = phspJpsi.GetEvtTime(); + /* + cpu_time_usedJpsi = ((GReal_t) (time_diff(time1, time2).tv_sec + + time_diff(time1, time2).tv_nsec * 1.0e-9));*/ + + cout << "|\t Generate time [J/psi]:\t " << cpu_time_usedJpsi << " s" << std::endl; + + cout << "=========================================================" << std::endl; + + for(GInt_t event = 0; event < 10; event++) { + cout << "Event: " << event << std::endl << "\t| weight " << phspJpsi.GetWeights()[event] << std::endl; + + for(GInt_t daughter = 0; daughter < 2; daughter++) { + Vector4R v = phspJpsi.GetDaughters(daughter)[event]; + cout << " \t| " << namesJpsi[daughter] << " : mass " << v.mass() << " 4-momentum ( " << v.get(0) << ", " + << v.get(1) << ", " << v.get(2) << ", " << v.get(3) << ") " << std::endl; + } + cout << std::endl; + } + + VariableSet_h Var(5); + RealVector_h result_MKpi(events); + RealVector_h result_MJpsipi(events); + RealVector_h result_CosThetaK(events); + RealVector_h result_CosThetaMu(events); + RealVector_h result_DeltaAngle(events); + + Var[0] = &result_MKpi; + Var[1] = &result_MJpsipi; + Var[2] = &result_CosThetaK; + Var[3] = &result_CosThetaMu; + Var[4] = &result_DeltaAngle; + + ParticlesSet_d JpsiKpiMuMu(5); + JpsiKpiMuMu[0] = &phsp.GetDaughters(0); + JpsiKpiMuMu[1] = &phsp.GetDaughters(1); + JpsiKpiMuMu[2] = &phsp.GetDaughters(2); + JpsiKpiMuMu[3] = &phspJpsi.GetDaughters(0); + JpsiKpiMuMu[4] = &phspJpsi.GetDaughters(1); + + Dataset DataJpsiKpi = Dataset(); + + clock_gettime(CLOCK_REALTIME, &time1); + EvaluateArray(DataJpsiKpi, JpsiKpiMuMu, Var); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t Dataset_time = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + cout << "=========================================================" << std::endl; + cout << "================= Evaluate Dataset ===============" << std::endl; + cout << "=========================================================" << std::endl; + cout << "|\t Dataset time : " << Dataset_time << " s" << std::endl; + cout << "=========================================================" << std::endl; + + for(GInt_t event = 0; event < 10; event++) { + std::cout << event << " " << result_MKpi[event] << " " << result_MJpsipi[event] << " " + << result_CosThetaK[event] << " " << result_CosThetaMu[event] << " " << result_DeltaAngle[event] + << std::endl; + } + + TH1D *cosThetaK = new TH1D("cosThetaK", ";Cos(#theta_{K});Events", 100, -1.0, 1.0); + TH1D *cosThetaMu = new TH1D("cosThetaMu", ";Cos(#theta_{#Mu});Events", 100, -1.0, 1.0); + TH1D *deltaAngle = new TH1D("deltaAngle", ";#Delta #phi;Events", 100, 0.0, 6.3); + TH1D *MKpi = new TH1D("MKpi", ";M(K,#pi);Events", 100, massesB0[1] + massesB0[2], mass0 - massesB0[0]); + TH1D *MJpsipi + = new TH1D("MJpsipi", ";M(Jpsi/#psi,#pi);Events", 100, massesB0[0] + massesB0[2], mass0 - massesB0[1]); + + for(GInt_t event = 0; event < events; event++) { + cosThetaK->Fill(result_CosThetaK[event], phsp.GetWeights()[event]); + cosThetaMu->Fill(result_CosThetaMu[event], phsp.GetWeights()[event]); + deltaAngle->Fill(result_DeltaAngle[event], phsp.GetWeights()[event]); + MKpi->Fill(result_MKpi[event], phsp.GetWeights()[event]); + MJpsipi->Fill(result_MJpsipi[event], phsp.GetWeights()[event]); + } + + TCanvas *c_cosThetaK = new TCanvas("cosThetaK", "", 600, 500); + cosThetaK->Draw("HIST"); + cosThetaK->SetLineColor(4); + cosThetaK->SetLineWidth(2); + cosThetaK->SetStats(0); + cosThetaK->SetMinimum(0); + c_cosThetaK->Print("cosThetaK.pdf"); + + TCanvas *c_cosThetaMu = new TCanvas("cosThetaMu", "", 600, 500); + cosThetaMu->Draw("HIST"); + cosThetaMu->SetLineColor(4); + cosThetaMu->SetLineWidth(2); + cosThetaMu->SetStats(0); + cosThetaMu->SetMinimum(0); + c_cosThetaMu->Print("cosThetaMu.pdf"); + + TCanvas *c_deltaAngle = new TCanvas("deltaAngle", "", 600, 500); + deltaAngle->Draw("HIST"); + deltaAngle->SetLineColor(4); + deltaAngle->SetLineWidth(2); + deltaAngle->SetStats(0); + deltaAngle->SetMinimum(0); + c_deltaAngle->Print("deltaAngle.pdf"); + + TCanvas *c_MKpi = new TCanvas("MKpi", "", 600, 500); + MKpi->Draw("HIST"); + MKpi->SetLineColor(4); + MKpi->SetLineWidth(2); + MKpi->SetStats(0); + MKpi->SetMinimum(0); + c_MKpi->Print("MKpi.pdf"); + + TCanvas *c_MJpsipi = new TCanvas("MJpsipi", "", 600, 500); + MJpsipi->Draw("HIST"); + MJpsipi->SetLineColor(4); + MJpsipi->SetLineWidth(2); + MJpsipi->SetStats(0); + MJpsipi->SetMinimum(0); + c_MJpsipi->Print("MJpsipi.pdf"); + + TH2D *dalitz = new TH2D("dalitz", + TString::Format(";M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]", + namesB0[0].c_str(), + namesB0[1].c_str(), + namesB0[1].c_str(), + namesB0[2].c_str()) + .Data(), + 100, + pow(massesB0[0] + massesB0[2], 2), + pow(mass0 - massesB0[1], 2), + 100, + pow(massesB0[1] + massesB0[2], 2), + pow(mass0 - massesB0[0], 2)); + + for(GInt_t event = 0; event < events; event++) { + dalitz->Fill(result_MJpsipi[event] * result_MJpsipi[event], + result_MKpi[event] * result_MKpi[event], + phsp.GetWeights()[event]); + } + + TCanvas *c2 = new TCanvas("dalitz", "", 600, 500); + dalitz->Draw("COLZ"); + dalitz->SetStats(0); + c2->Print("dalitz.pdf"); + + myapp->Run(); + return 0; } diff --git a/extern/MCBooster/src/Generate.cu b/extern/MCBooster/src/Generate.cu index f96c00ff2..8778cec33 100644 --- a/extern/MCBooster/src/Generate.cu +++ b/extern/MCBooster/src/Generate.cu @@ -35,7 +35,7 @@ #define CUDA_API_PER_THREAD_DEFAULT_STREAM -//this lib +// this lib #include #include #include @@ -43,7 +43,7 @@ #include #include #include -//root +// root #include #include #include @@ -54,445 +54,383 @@ using namespace std; using namespace mcbooster; +struct Dataset : public IFunctionArray { + Dataset() { dim = 4; } + __host__ __device__ inline GReal_t cosHELANG(const Vector4R p, const Vector4R q, const Vector4R d) { + GReal_t pd = p * d; + GReal_t pq = p * q; + GReal_t qd = q * d; + GReal_t mp2 = p.mass2(); + GReal_t mq2 = q.mass2(); + GReal_t md2 = d.mass2(); -struct Dataset: public IFunctionArray -{ - Dataset() - { - dim = 4; - } + return (pd * mq2 - pq * qd) / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); + } - __host__ __device__ inline GReal_t cosHELANG(const Vector4R p, const Vector4R q, - const Vector4R d) - { - GReal_t pd = p * d; - GReal_t pq = p * q; - GReal_t qd = q * d; - GReal_t mp2 = p.mass2(); - GReal_t mq2 = q.mass2(); - GReal_t md2 = d.mass2(); + __host__ __device__ inline GReal_t deltaAngle(const Vector4R &p4_p, + const Vector4R &p4_d1, + const Vector4R &p4_d2, + const Vector4R &p4_h1, + const Vector4R &p4_h2) { + Vector4R p4_d1p, p4_h1p, p4_h2p, p4_d2p; - return (pd * mq2 - pq * qd) - / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); + Vector4R d1_perp, d1_prime, h1_perp; + Vector4R D; - } + D = p4_d1 + p4_d2; - __host__ __device__ inline GReal_t deltaAngle(const Vector4R& p4_p, - const Vector4R& p4_d1, const Vector4R& p4_d2, const Vector4R& p4_h1, - const Vector4R& p4_h2) - { + d1_perp = p4_d1 - (D.dot(p4_d1) / D.dot(D)) * D; + h1_perp = p4_h1 - (D.dot(p4_h1) / D.dot(D)) * D; - Vector4R p4_d1p, p4_h1p, p4_h2p, p4_d2p; + // orthogonal to both D and d1_perp - Vector4R d1_perp, d1_prime, h1_perp; - Vector4R D; + d1_prime = D.cross(d1_perp); - D = p4_d1 + p4_d2; + d1_perp = d1_perp / d1_perp.d3mag(); + d1_prime = d1_prime / d1_prime.d3mag(); - d1_perp = p4_d1 - (D.dot(p4_d1) / D.dot(D)) * D; - h1_perp = p4_h1 - (D.dot(p4_h1) / D.dot(D)) * D; + GReal_t x, y; - // orthogonal to both D and d1_perp + x = d1_perp.dot(h1_perp); + y = d1_prime.dot(h1_perp); - d1_prime = D.cross(d1_perp); + GReal_t chi = atan2(y, x); - d1_perp = d1_perp / d1_perp.d3mag(); - d1_prime = d1_prime / d1_prime.d3mag(); + if(chi < 0.0) + chi += 2.0 * CUDART_PI_HI; - GReal_t x, y; + return chi; + } - x = d1_perp.dot(h1_perp); - y = d1_prime.dot(h1_perp); + __host__ __device__ inline void operator()(const GInt_t n, Vector4R **particles, GReal_t *variables) { + Vector4R pJpsi = *particles[0]; + Vector4R pK = *particles[1]; + Vector4R ppi = *particles[2]; + Vector4R pMup = *particles[3]; + Vector4R pMum = *particles[4]; - GReal_t chi = atan2(y, x); - - if (chi < 0.0) - chi += 2.0*CUDART_PI_HI; - - return chi; - - } - - __host__ __device__ - inline void operator()(const GInt_t n, Vector4R** particles, GReal_t* variables) - { - Vector4R pJpsi = *particles[0]; - Vector4R pK = *particles[1]; - Vector4R ppi = *particles[2]; - Vector4R pMup = *particles[3]; - Vector4R pMum = *particles[4]; - - //K* helicity angle - Vector4R pB0 = pJpsi + pK + ppi; - Vector4R pKpi = pK + ppi; - Vector4R pJpsipi = pJpsi + ppi; - - - variables[0] = pKpi.mass(); - variables[1] = pJpsipi.mass(); - variables[2] = cosHELANG(pB0, pKpi, pK); - variables[3] = cosHELANG(pB0, pJpsi, pMup); - variables[4] = deltaAngle(pB0, pK, ppi, pMup, pMum); - - } + // K* helicity angle + Vector4R pB0 = pJpsi + pK + ppi; + Vector4R pKpi = pK + ppi; + Vector4R pJpsipi = pJpsi + ppi; + variables[0] = pKpi.mass(); + variables[1] = pJpsipi.mass(); + variables[2] = cosHELANG(pB0, pKpi, pK); + variables[3] = cosHELANG(pB0, pJpsi, pMup); + variables[4] = deltaAngle(pB0, pK, ppi, pMup, pMum); + } }; +GInt_t main(void) { + TApplication *myapp = new TApplication("myapp", 0, 0); + GLong_t events = 10000000; + size_t ndaughters = 3; + GReal_t mass0 = 5.2795; -GInt_t main(void) -{ - - TApplication *myapp=new TApplication("myapp",0,0); - - GLong_t events = 10000000; - size_t ndaughters = 3; - GReal_t mass0 = 5.2795; - - //Particles mothers(events, Vector4R(5.2795,0.0,0.0,0.0) ); + // Particles mothers(events, Vector4R(5.2795,0.0,0.0,0.0) ); - //{ "J/psi", "K", "pi", "pi" } + //{ "J/psi", "K", "pi", "pi" } - vector namesB0; - namesB0.push_back("J/#psi"); - namesB0.push_back("K"); - namesB0.push_back("pi"); + vector namesB0; + namesB0.push_back("J/#psi"); + namesB0.push_back("K"); + namesB0.push_back("pi"); - //{ 3.096916, 0.493677, 0.13957018 } - vector massesB0; - massesB0.push_back(3.096916); - massesB0.push_back(0.493677); - massesB0.push_back(0.13957018); + //{ 3.096916, 0.493677, 0.13957018 } + vector massesB0; + massesB0.push_back(3.096916); + massesB0.push_back(0.493677); + massesB0.push_back(0.13957018); - //chronometer - timespec time1, time2; + // chronometer + timespec time1, time2; - cout << "=========================================================" < J/psi K pi= ================" < J/psi K pi= ================" << std::endl; + cout << "=========================================================" << std::endl; + cout << "Number of events: " << events << std::endl; - clock_gettime(CLOCK_REALTIME, &time1); + clock_gettime(CLOCK_REALTIME, &time1); - /// Create PhaseSpace object for B0-> K pi J/psi - PhaseSpace phsp(5.2795, massesB0, events); + /// Create PhaseSpace object for B0-> K pi J/psi + PhaseSpace phsp(5.2795, massesB0, events); - clock_gettime(CLOCK_REALTIME, &time2); + clock_gettime(CLOCK_REALTIME, &time2); - GReal_t phsp_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); + GReal_t phsp_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); - cout << "|\t PhaseSpace ctor time [B0]:\t " << phsp_time_used << " s" - < K pi J/psi - phsp.Generate(Vector4R(5.2795, 0.0, 0.0, 0.0)); + /// Generate events B0-> K pi J/psi + phsp.Generate(Vector4R(5.2795, 0.0, 0.0, 0.0)); - clock_gettime(CLOCK_REALTIME, &time2); + clock_gettime(CLOCK_REALTIME, &time2); - phsp.Unweight(); + phsp.Unweight(); - GReal_t cpu_time_used= phsp.GetEvtTime(); - /* - cpu_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); + GReal_t cpu_time_used = phsp.GetEvtTime(); + /* + cpu_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec + + time_diff(time1, time2).tv_nsec * 1.0e-9)); */ - cout << "|\t Generate time [B0]:\t " << cpu_time_used << " s" <fWeights[event] - << "\t| flag " << MyEvents->fAccRejFlags[event] <fDaughters[daughter][event].mass() - << " 4-momentum ( " - << MyEvents->fDaughters[daughter][event].get(0) << ", " - << MyEvents->fDaughters[daughter][event].get(1) << ", " - << MyEvents->fDaughters[daughter][event].get(2) << ", " - << MyEvents->fDaughters[daughter][event].get(3) << ") " - < namesJpsi; - namesJpsi.push_back("mu+"); - namesJpsi.push_back("mu-"); - - //{ 3.096916, 0.493677, 0.13957018 } - vector massesJpsi; - massesJpsi.push_back(0.100); - massesJpsi.push_back(0.100); - - cout << "=========================================================" < mu mu ==================" <fWeights[event] - << "\t| flag " << MyEventsJpsi->fAccRejFlags[event] <fDaughters[daughter][event].mass() - << " 4-momentum ( " - << MyEventsJpsi->fDaughters[daughter][event].get(0) << ", " - << MyEventsJpsi->fDaughters[daughter][event].get(1) << ", " - << MyEventsJpsi->fDaughters[daughter][event].get(2) << ", " - << MyEventsJpsi->fDaughters[daughter][event].get(3) << ") " - <(DataJpsiKpi, JpsiKpiMuMu, Var); - clock_gettime(CLOCK_REALTIME, &time2); - GReal_t Dataset_time = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - cout << "=========================================================" <Fill( result_CosThetaK[event], MyEvents->fWeights[event] ); - cosThetaMu->Fill(result_CosThetaMu[event], MyEvents->fWeights[event] ); - deltaAngle->Fill(result_DeltaAngle[event], MyEvents->fWeights[event] ); - MKpi->Fill(result_MKpi[event], MyEvents->fWeights[event] ); - MJpsipi->Fill(result_MJpsipi[event], MyEvents->fWeights[event] ); - - } - - TCanvas *c_cosThetaK = new TCanvas( "cosThetaK", "", 600, 500 ); - cosThetaK->Draw("HIST"); - cosThetaK->SetLineColor(4); - cosThetaK->SetLineWidth(2); - cosThetaK->SetStats(0); - cosThetaK->SetMinimum(0); - c_cosThetaK->Print( "cosThetaK.pdf" ); - - TCanvas *c_cosThetaMu = new TCanvas( "cosThetaMu", "", 600, 500 ); - cosThetaMu->Draw("HIST"); - cosThetaMu->SetLineColor(4); - cosThetaMu->SetLineWidth(2); - cosThetaMu->SetStats(0); - cosThetaMu->SetMinimum(0); - c_cosThetaMu->Print( "cosThetaMu.pdf" ); - - TCanvas *c_deltaAngle = new TCanvas( "deltaAngle", "", 600, 500 ); - deltaAngle->Draw("HIST"); - deltaAngle->SetLineColor(4); - deltaAngle->SetLineWidth(2); - deltaAngle->SetStats(0); - deltaAngle->SetMinimum(0); - c_deltaAngle->Print( "deltaAngle.pdf" ); - - TCanvas *c_MKpi = new TCanvas( "MKpi", "", 600, 500 ); - MKpi->Draw("HIST"); - MKpi->SetLineColor(4); - MKpi->SetLineWidth(2); - MKpi->SetStats(0); - MKpi->SetMinimum(0); - c_MKpi->Print( "MKpi.pdf" ); - - TCanvas *c_MJpsipi = new TCanvas( "MJpsipi", "", 600, 500 ); - MJpsipi->Draw("HIST"); - MJpsipi->SetLineColor(4); - MJpsipi->SetLineWidth(2); - MJpsipi->SetStats(0); - MJpsipi->SetMinimum(0); - c_MJpsipi->Print( "MJpsipi.pdf" ); + clock_gettime(CLOCK_REALTIME, &time1); + /// Create Events container + Events *MyEvents = new Events(ndaughters, events); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t evt_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); - TH2D *dalitz = new TH2D("dalitz", - TString::Format("Weigted;M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]" - , namesB0[0].c_str(), namesB0[1].c_str() - , namesB0[1].c_str(), namesB0[2].c_str() ).Data(), - 100, pow(massesB0[0]+massesB0[2],2), pow(mass0 - massesB0[1],2), - 100, pow(massesB0[1]+massesB0[2],2), pow(mass0 - massesB0[0],2) ); + cout << "|\t Event ctor time [B0]:\t " << evt_time_used << " s" << std::endl; + clock_gettime(CLOCK_REALTIME, &time1); - for(GInt_t event=0; eventFill( result_MJpsipi[event]*result_MJpsipi[event], - result_MKpi[event]*result_MKpi[event], - MyEvents->fWeights[event] ); + clock_gettime(CLOCK_REALTIME, &time2); - } + GReal_t exp_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); - TCanvas *c2 = new TCanvas( "dalitz", "", 600, 500 ); - dalitz->Draw("COLZ"); - dalitz->SetStats(0); - c2->Print( "dalitzW.pdf" ); + cout << "|\t Export time [B0]:\t\t " << exp_time_used << " s" << std::endl; - TH2D *dalitz2 = new TH2D("dalitz2", - TString::Format("Unweigted;M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]" - , namesB0[0].c_str(), namesB0[1].c_str() - , namesB0[1].c_str(), namesB0[2].c_str() ).Data(), - 100, pow(massesB0[0]+massesB0[2],2), pow(mass0 - massesB0[1],2), - 100, pow(massesB0[1]+massesB0[2],2), pow(mass0 - massesB0[0],2) ); + cout << "=========================================================" << std::endl; + /// Print the first 10 events with corresponding weights + for(GInt_t event = 0; event < 10; event++) { + cout << "Event: " << event << std::endl + << "\t| weight " << MyEvents->fWeights[event] << "\t| flag " << MyEvents->fAccRejFlags[event] << endl; - for(GInt_t event=0; eventfDaughters[daughter][event].mass() + << " 4-momentum ( " << MyEvents->fDaughters[daughter][event].get(0) << ", " + << MyEvents->fDaughters[daughter][event].get(1) << ", " << MyEvents->fDaughters[daughter][event].get(2) + << ", " << MyEvents->fDaughters[daughter][event].get(3) << ") " << std::endl; + } + cout << std::endl; + } - dalitz2->Fill( result_MJpsipi[event]*result_MJpsipi[event], - result_MKpi[event]*result_MKpi[event], - MyEvents->fAccRejFlags[event] ); + //{ "J/psi", "K", "pi", "pi" } - } + vector namesJpsi; + namesJpsi.push_back("mu+"); + namesJpsi.push_back("mu-"); + //{ 3.096916, 0.493677, 0.13957018 } + vector massesJpsi; + massesJpsi.push_back(0.100); + massesJpsi.push_back(0.100); - TCanvas *c3 = new TCanvas( "dalitz2", "", 600, 500 ); - dalitz2->Draw("COLZ"); - dalitz2->SetStats(0); - c2->Print( "dalitzU.pdf" ); + cout << "=========================================================" << std::endl; + cout << "==================== J/psi -> mu mu ==================" << std::endl; + cout << "=========================================================" << std::endl; + std::cout << "Number of events: " << events << std::endl; + clock_gettime(CLOCK_REALTIME, &time1); + Events *MyEventsJpsi = new Events(2, events); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t evt_time_usedJpsi = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + cout << "|\t Event ctor time [J/psi]:\t " << evt_time_usedJpsi << " s" << std::endl; - myapp->Run(); - return 0; + // Decays trees(mothers, names, masses ); + clock_gettime(CLOCK_REALTIME, &time1); + PhaseSpace phspJpsi(3.096916, massesJpsi, events); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t phsp_time_usedJpsi = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + cout << "|\t PhaseSpace ctor time [J/psi]:\t " << phsp_time_usedJpsi << " s" << std::endl; + + clock_gettime(CLOCK_REALTIME, &time1); + phspJpsi.Generate(phsp.GetDaughters(0)); + clock_gettime(CLOCK_REALTIME, &time2); + + phspJpsi.Unweight(); + + GReal_t cpu_time_usedJpsi = phspJpsi.GetEvtTime(); + /* + cpu_time_usedJpsi = ((GReal_t) (time_diff(time1, time2).tv_sec + + time_diff(time1, time2).tv_nsec * 1.0e-9));*/ + + cout << "|\t Generate time [J/psi]:\t " << cpu_time_usedJpsi << " s" << std::endl; + + clock_gettime(CLOCK_REALTIME, &time1); + phspJpsi.Export(MyEventsJpsi); + clock_gettime(CLOCK_REALTIME, &time2); + + GReal_t exp_time_usedJpsi = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + cout << "|\t Export time [J/psi]:\t\t " << exp_time_usedJpsi << " s" << std::endl; + + cout << "=========================================================" << std::endl; + + for(GInt_t event = 0; event < 10; event++) { + cout << "Event: " << event << std::endl + << "\t| weight " << MyEventsJpsi->fWeights[event] << "\t| flag " << MyEventsJpsi->fAccRejFlags[event] + << endl; + + for(GInt_t daughter = 0; daughter < 2; daughter++) { + cout << " \t| " << namesJpsi[daughter] << " : mass " << MyEventsJpsi->fDaughters[daughter][event].mass() + << " 4-momentum ( " << MyEventsJpsi->fDaughters[daughter][event].get(0) << ", " + << MyEventsJpsi->fDaughters[daughter][event].get(1) << ", " + << MyEventsJpsi->fDaughters[daughter][event].get(2) << ", " + << MyEventsJpsi->fDaughters[daughter][event].get(3) << ") " << std::endl; + } + cout << std::endl; + } + + VariableSet_h Var(5); + RealVector_h result_MKpi(events); + RealVector_h result_MJpsipi(events); + RealVector_h result_CosThetaK(events); + RealVector_h result_CosThetaMu(events); + RealVector_h result_DeltaAngle(events); + + Var[0] = &result_MKpi; + Var[1] = &result_MJpsipi; + Var[2] = &result_CosThetaK; + Var[3] = &result_CosThetaMu; + Var[4] = &result_DeltaAngle; + + ParticlesSet_d JpsiKpiMuMu(5); + JpsiKpiMuMu[0] = &phsp.GetDaughters(0); + JpsiKpiMuMu[1] = &phsp.GetDaughters(1); + JpsiKpiMuMu[2] = &phsp.GetDaughters(2); + JpsiKpiMuMu[3] = &phspJpsi.GetDaughters(0); + JpsiKpiMuMu[4] = &phspJpsi.GetDaughters(1); + + Dataset DataJpsiKpi = Dataset(); + + clock_gettime(CLOCK_REALTIME, &time1); + EvaluateArray(DataJpsiKpi, JpsiKpiMuMu, Var); + clock_gettime(CLOCK_REALTIME, &time2); + GReal_t Dataset_time = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + cout << "=========================================================" << std::endl; + cout << "================= Evaluate Dataset ===============" << std::endl; + cout << "=========================================================" << std::endl; + cout << "|\t Dataset time : " << Dataset_time << " s" << std::endl; + cout << "=========================================================" << std::endl; + + for(GInt_t event = 0; event < 10; event++) { + std::cout << event << " " << result_MKpi[event] << " " << result_MJpsipi[event] << " " + << result_CosThetaK[event] << " " << result_CosThetaMu[event] << " " << result_DeltaAngle[event] + << std::endl; + } + + TH1D *cosThetaK = new TH1D("cosThetaK", ";Cos(#theta_{K});Events", 100, -1.0, 1.0); + TH1D *cosThetaMu = new TH1D("cosThetaMu", ";Cos(#theta_{#Mu});Events", 100, -1.0, 1.0); + TH1D *deltaAngle = new TH1D("deltaAngle", ";#Delta #phi;Events", 100, 0.0, 6.3); + TH1D *MKpi = new TH1D("MKpi", ";M(K,#pi);Events", 100, massesB0[1] + massesB0[2], mass0 - massesB0[0]); + TH1D *MJpsipi + = new TH1D("MJpsipi", ";M(Jpsi/#psi,#pi);Events", 100, massesB0[0] + massesB0[2], mass0 - massesB0[1]); + + for(GInt_t event = 0; event < events; event++) { + cosThetaK->Fill(result_CosThetaK[event], MyEvents->fWeights[event]); + cosThetaMu->Fill(result_CosThetaMu[event], MyEvents->fWeights[event]); + deltaAngle->Fill(result_DeltaAngle[event], MyEvents->fWeights[event]); + MKpi->Fill(result_MKpi[event], MyEvents->fWeights[event]); + MJpsipi->Fill(result_MJpsipi[event], MyEvents->fWeights[event]); + } + + TCanvas *c_cosThetaK = new TCanvas("cosThetaK", "", 600, 500); + cosThetaK->Draw("HIST"); + cosThetaK->SetLineColor(4); + cosThetaK->SetLineWidth(2); + cosThetaK->SetStats(0); + cosThetaK->SetMinimum(0); + c_cosThetaK->Print("cosThetaK.pdf"); + + TCanvas *c_cosThetaMu = new TCanvas("cosThetaMu", "", 600, 500); + cosThetaMu->Draw("HIST"); + cosThetaMu->SetLineColor(4); + cosThetaMu->SetLineWidth(2); + cosThetaMu->SetStats(0); + cosThetaMu->SetMinimum(0); + c_cosThetaMu->Print("cosThetaMu.pdf"); + + TCanvas *c_deltaAngle = new TCanvas("deltaAngle", "", 600, 500); + deltaAngle->Draw("HIST"); + deltaAngle->SetLineColor(4); + deltaAngle->SetLineWidth(2); + deltaAngle->SetStats(0); + deltaAngle->SetMinimum(0); + c_deltaAngle->Print("deltaAngle.pdf"); + + TCanvas *c_MKpi = new TCanvas("MKpi", "", 600, 500); + MKpi->Draw("HIST"); + MKpi->SetLineColor(4); + MKpi->SetLineWidth(2); + MKpi->SetStats(0); + MKpi->SetMinimum(0); + c_MKpi->Print("MKpi.pdf"); + + TCanvas *c_MJpsipi = new TCanvas("MJpsipi", "", 600, 500); + MJpsipi->Draw("HIST"); + MJpsipi->SetLineColor(4); + MJpsipi->SetLineWidth(2); + MJpsipi->SetStats(0); + MJpsipi->SetMinimum(0); + c_MJpsipi->Print("MJpsipi.pdf"); + + TH2D *dalitz = new TH2D("dalitz", + TString::Format("Weigted;M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]", + namesB0[0].c_str(), + namesB0[1].c_str(), + namesB0[1].c_str(), + namesB0[2].c_str()) + .Data(), + 100, + pow(massesB0[0] + massesB0[2], 2), + pow(mass0 - massesB0[1], 2), + 100, + pow(massesB0[1] + massesB0[2], 2), + pow(mass0 - massesB0[0], 2)); + + for(GInt_t event = 0; event < events; event++) { + dalitz->Fill(result_MJpsipi[event] * result_MJpsipi[event], + result_MKpi[event] * result_MKpi[event], + MyEvents->fWeights[event]); + } + + TCanvas *c2 = new TCanvas("dalitz", "", 600, 500); + dalitz->Draw("COLZ"); + dalitz->SetStats(0); + c2->Print("dalitzW.pdf"); + + TH2D *dalitz2 = new TH2D("dalitz2", + TString::Format("Unweigted;M^{2}(%s,%s) [GeV^{2}/c^{4}]; M^{2}(%s,%s) [GeV^{2}/c^{4}]", + namesB0[0].c_str(), + namesB0[1].c_str(), + namesB0[1].c_str(), + namesB0[2].c_str()) + .Data(), + 100, + pow(massesB0[0] + massesB0[2], 2), + pow(mass0 - massesB0[1], 2), + 100, + pow(massesB0[1] + massesB0[2], 2), + pow(mass0 - massesB0[0], 2)); + + for(GInt_t event = 0; event < events; event++) { + dalitz2->Fill(result_MJpsipi[event] * result_MJpsipi[event], + result_MKpi[event] * result_MKpi[event], + MyEvents->fAccRejFlags[event]); + } + + TCanvas *c3 = new TCanvas("dalitz2", "", 600, 500); + dalitz2->Draw("COLZ"); + dalitz2->SetStats(0); + c2->Print("dalitzU.pdf"); + + myapp->Run(); + return 0; } diff --git a/extern/MCBooster/src/GenerateSample.cu b/extern/MCBooster/src/GenerateSample.cu index 5d9870473..c939c00be 100644 --- a/extern/MCBooster/src/GenerateSample.cu +++ b/extern/MCBooster/src/GenerateSample.cu @@ -2,11 +2,11 @@ * PerformanceTest.cu * * Copyright 2016 Antonio Augusto Alves Junior - * + * * Created on : 10/03/2016 * Author: augalves */ - + /* This file is part of MCBooster. @@ -31,9 +31,9 @@ #include #include #include -//command line +// command line #include -//this lib +// this lib #include #include #include @@ -42,7 +42,7 @@ #include #include -//ROOT +// ROOT #include "TString.h" #include "TTree.h" #include "TFile.h" @@ -52,201 +52,175 @@ using namespace std; using namespace mcbooster; - -void splitString(const std::string &s, const char delim, std::vector &elems) -{ - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) - { - elems.push_back(item); - } - //return elems; - return; +void splitString(const std::string &s, const char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(item); + } + // return elems; + return; } -void splitReal(const std::string &s, const char delim, std::vector &elems) -{ - std::stringstream ss(s); - std::string item; - while (std::getline(ss, item, delim)) - { - elems.push_back(std::stod(item)); - } - //return elems; - return; +void splitReal(const std::string &s, const char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while(std::getline(ss, item, delim)) { + elems.push_back(std::stod(item)); + } + // return elems; + return; } +GInt_t main(int argv, char **argc) { + GULong_t nevents = 0; + string output_dir = ""; + GReal_t mother; + string _names; + string _masses; + + try { + TCLAP::CmdLine cmd("Command line arguments for GenerateSample", '='); + + TCLAP::ValueArg eArg("n", "number-of-events", "Number of events", true, 1e6, "long"); + cmd.add(eArg); + + TCLAP::ValueArg oArg("o", "output-file", "Output file", false, "./phsp.root", "string"); + cmd.add(oArg); + + TCLAP::ValueArg pArg( + "p", + "particles", + "List of particles. First particle is the mother.Example: D0->Kpipi is 'D0;K;pi+;pi-", + true, + "", + "string"); + cmd.add(pArg); + + TCLAP::ValueArg mArg( + "m", + "masses", + "Particle mass. First particle is the mother. Example: D0->Kpipi is '1.865;0.439;0.139;0.139", + true, + "", + "string"); + cmd.add(mArg); + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nevents = eArg.getValue(); + output_dir = oArg.getValue(); + _masses = mArg.getValue(); + _names = pArg.getValue(); + + } catch(TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + vector names_temp; + vector masses_temp; + + splitReal(_masses, ';', masses_temp); + splitString(_names, ';', names_temp); + + if(masses_temp.size() < 3 || masses_temp.size() > 9) { + cout << "Exit. Number of particles is (< 2) or (> 9)." << std::endl; + exit(0); + } + + if(masses_temp.size() != names_temp.size()) { + cout << "Exit. Number of particles is different of number of names." << std::endl; + exit(0); + } + + // dump configuration + cout << "-----------------------------------------------------" << std::endl; + cout << "---------------------- MCBooster --------------------" << std::endl; + cout << "- Mother name: " << names_temp[0] << " mass: " << masses_temp[0] << std::endl; + for(GInt_t i = 1; i < masses_temp.size(); i++) { + cout << "- Daughter name: " << names_temp[i] << " mass: " << masses_temp[i] << std::endl; + } + cout << "- Number of events: " << nevents << std::endl; + cout << "- Output file: " << output_dir << std::endl; + cout << "-----------------------------------------------------" << std::endl; + + // Generation + GReal_t mother_mass = masses_temp[0]; + vector masses(masses_temp.size() - 1); + std::copy(masses_temp.begin() + 1, masses_temp.end(), masses.begin()); + + PhaseSpace phsp(mother_mass, masses, nevents); + Events GenEvents(masses.size(), nevents); + + timespec time1, time2; + phsp.Generate(Vector4R(mother_mass, 0.0, 0.0, 0.0)); + + ///------------------------------------- + // unweight + clock_gettime(CLOCK_REALTIME, &time1); + phsp.Unweight(); + + clock_gettime(CLOCK_REALTIME, &time2); + + GReal_t unweight_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + //------------------------------------- + clock_gettime(CLOCK_REALTIME, &time1); + + /// Create Events container + phsp.Export(&GenEvents); + + clock_gettime(CLOCK_REALTIME, &time2); + + GReal_t exp_time_used = ((GReal_t)(time_diff(time1, time2).tv_sec + time_diff(time1, time2).tv_nsec * 1.0e-9)); + + phsp.Export(&GenEvents); + + cout << "-----------------------------------------------------" << std::endl; + cout << "----------------------- Timing ----------------------" << std::endl; + cout << "Event generation: " << phsp.GetEvtTime() << std::endl; + cout << "Unweight generation: " << unweight_time_used << std::endl; + cout << "Export events to host: " << exp_time_used << std::endl; + cout << "-----------------------------------------------------" << std::endl; + + TFile *file = new TFile(output_dir.c_str(), "RECREATE"); + TTree *tree = new TTree("events", "events"); + + TLorentzVector *decayVectors = new TLorentzVector[masses.size() + 1]; + + for(GInt_t p = 0; p < masses.size(); p++) { + tree->Branch(names_temp[p + 1].c_str(), names_temp[p + 1].c_str(), &decayVectors[p]); + } + + GReal_t wevt, wmax; + GInt_t flag; + + tree->Branch("weightEvt", &wevt, "weightEvt/D"); + tree->Branch("weightMax", &wmax, "weightMax/D"); + tree->Branch("AccRej", &flag, "AccRej/I"); -GInt_t main(int argv, char** argc) -{ - - GULong_t nevents=0; - string output_dir=""; - GReal_t mother; - string _names; - string _masses; - - try { - - TCLAP::CmdLine cmd("Command line arguments for GenerateSample", '='); - - TCLAP::ValueArg eArg("n", "number-of-events", - "Number of events", - true, 1e6, "long"); - cmd.add(eArg); - - - TCLAP::ValueArg oArg("o", "output-file", - "Output file", - false, "./phsp.root", "string"); - cmd.add(oArg); - - - TCLAP::ValueArg pArg("p", "particles", - "List of particles. First particle is the mother.Example: D0->Kpipi is 'D0;K;pi+;pi-", - true, "", "string"); - cmd.add(pArg); - - - TCLAP::ValueArg mArg("m", "masses", - "Particle mass. First particle is the mother. Example: D0->Kpipi is '1.865;0.439;0.139;0.139", - true, "" ,"string"); - cmd.add(mArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nevents = eArg.getValue(); - output_dir = oArg.getValue(); - _masses = mArg.getValue(); - _names = pArg.getValue(); - - } catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - - vector names_temp; - vector masses_temp; - - splitReal(_masses, ';' , masses_temp); - splitString(_names, ';' , names_temp ); - - if(masses_temp.size() < 3 || masses_temp.size()>9) - { - cout << "Exit. Number of particles is (< 2) or (> 9)." < masses(masses_temp.size()-1); - std::copy ( masses_temp.begin() +1, masses_temp.end(), masses.begin() ); - - PhaseSpace phsp(mother_mass, masses, nevents); - Events GenEvents(masses.size(), nevents); - - timespec time1, time2; - phsp.Generate(Vector4R(mother_mass, 0.0, 0.0, 0.0)); - - ///------------------------------------- - //unweight - clock_gettime(CLOCK_REALTIME, &time1); - phsp.Unweight(); - - clock_gettime(CLOCK_REALTIME, &time2); - - GReal_t unweight_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - - //------------------------------------- - clock_gettime(CLOCK_REALTIME, &time1); - - /// Create Events container - phsp.Export(&GenEvents); - - clock_gettime(CLOCK_REALTIME, &time2); - - GReal_t exp_time_used = ((GReal_t) (time_diff(time1, time2).tv_sec - + time_diff(time1, time2).tv_nsec * 1.0e-9)); - - phsp.Export(&GenEvents); - - cout << "-----------------------------------------------------"<Branch(names_temp[p+1].c_str(), names_temp[p+1].c_str(), &decayVectors[p]); - } - - GReal_t wevt, wmax; - GInt_t flag; - - tree->Branch("weightEvt", &wevt, "weightEvt/D"); - tree->Branch("weightMax", &wmax, "weightMax/D"); - tree->Branch("AccRej" , &flag, "AccRej/I"); - - cout << "\n Storing events in Tree..."<Fill(); - - } - cout << "Done. \n"<Write(); - file->Close(); + tree->Fill(); + } + cout << "Done. \n" << endl; + tree->Write(); + file->Close(); - return 0; + return 0; } diff --git a/extern/MCBooster/src/PerformanceTest.cpp b/extern/MCBooster/src/PerformanceTest.cpp index ac2999f9b..fcf85c1ae 100644 --- a/extern/MCBooster/src/PerformanceTest.cpp +++ b/extern/MCBooster/src/PerformanceTest.cpp @@ -2,11 +2,11 @@ * PerformanceTest.cpp * * Copyright 2016 Antonio Augusto Alves Junior - * + * * Created on : 10/03/2016 * Author: augalves */ - + /* This file is part of MCBooster. @@ -31,9 +31,9 @@ #include #include -//command line +// command line #include -//this lib +// this lib #include #include #include @@ -42,7 +42,7 @@ #include #include -//root +// root #include #include #include @@ -60,262 +60,227 @@ using namespace std; using namespace mcbooster; -void RunMCGen (GInt_t nfinal, GInt_t nevents, Double_t *time ) -{ - - - vector names; - vector masses; +void RunMCGen(GInt_t nfinal, GInt_t nevents, Double_t *time) { + vector names; + vector masses; - for(GInt_t i=0; i eArg("e", "events", "Number of events in time profile", - false, 1e6, "long integer"); - cmd.add(eArg); - - TCLAP::ValueArg sArg("s", "suffix", - "Suffix for plots name", - false, "", "string"); - cmd.add(sArg); - - TCLAP::ValueArg oArg("o", "output_dir", "output directory", - false, ".", "string"); - cmd.add(oArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nevents_scan = eArg.getValue(); - suffix = sArg.getValue(); - output_dir = oArg.getValue(); - - } catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - vector _NParticles; - vector _NEvents; - - vector _Rnd_Time1; - vector _Evt_Time1; - vector _Out_Time1; - vector _Cpu_Time1; - - vector _Rnd_Time2; - vector _Evt_Time2; - vector _Out_Time2; - vector _Cpu_Time2; - - - - - GDouble_t _time[4]; - - for(GInt_t i=1;i<40;i++) - { - GULong_t nevt = i*500000; - - RunMCGen(3, nevt , &_time[0] ); - - _NEvents.push_back( nevt ); - _Rnd_Time1.push_back( _time[0] ); - _Evt_Time1.push_back( _time[1] ); - _Out_Time1.push_back( _time[2] ); - _Cpu_Time1.push_back( _time[3] ); - - } - - for(GInt_t i=2;i<10;i++) - { - - - RunMCGen(i, nevents_scan , &_time[0] ); - _NParticles.push_back( i ); - _Rnd_Time2.push_back( _time[0] ); - _Evt_Time2.push_back( _time[1] ); - _Out_Time2.push_back( _time[2] ); - _Cpu_Time2.push_back( _time[3] ); - - } - - - - - TApplication *myapp=new TApplication("myapp",0,0); - - TGraph *Rnd_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Rnd_Time1.data()); - TGraph *Evt_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Evt_Time1.data()); - TGraph *Out_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Out_Time1.data()); - TGraph *Cpu_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Cpu_Time1.data()); - - TCanvas *c1 = new TCanvas( "Rnd_Time1", "Rnd_Time1", 600, 500 ); - Rnd_Time1->SetLineColor(2); - Rnd_Time1->SetLineWidth(4); - Rnd_Time1->SetMarkerColor(4); - Rnd_Time1->SetMarkerSize(1.0); - Rnd_Time1->SetMarkerStyle(21); - Rnd_Time1->SetTitle("Randon number generation time"); - Rnd_Time1->GetXaxis()->SetTitle("Number of events"); - Rnd_Time1->GetYaxis()->SetTitle("Time (s)"); - Rnd_Time1->GetYaxis()->SetTitleOffset(1.4); - Rnd_Time1->Draw("ACP"); - - TCanvas *c2 = new TCanvas( "Evt_Time1", "Evt_Time1", 600, 500 ); - Evt_Time1->SetLineColor(2); - Evt_Time1->SetLineWidth(4); - Evt_Time1->SetMarkerColor(4); - Evt_Time1->SetMarkerSize(1.0); - Evt_Time1->SetMarkerStyle(21); - Evt_Time1->SetTitle("Events generation time"); - Evt_Time1->GetXaxis()->SetTitle("Number of events"); - Evt_Time1->GetYaxis()->SetTitle("Time (s)"); - Evt_Time1->GetYaxis()->SetTitleOffset(1.4); - Evt_Time1->Draw("ACP"); - - - TCanvas *c3 = new TCanvas( "Out_Time1", "Out_Time1", 600, 500 ); - Out_Time1->SetLineColor(2); - Out_Time1->SetLineWidth(4); - Out_Time1->SetMarkerColor(4); - Out_Time1->SetMarkerSize(1.0); - Out_Time1->SetMarkerStyle(21); - Out_Time1->SetTitle("Output time"); - Out_Time1->GetXaxis()->SetTitle("Number of events"); - Out_Time1->GetYaxis()->SetTitle("Time (s)"); - Out_Time1->GetYaxis()->SetTitleOffset(1.4); - Out_Time1->Draw("ACP"); - - TCanvas *c4 = new TCanvas( "Cpu_Time", "Cpu_Time", 600, 500 ); - Cpu_Time1->SetLineColor(2); - Cpu_Time1->SetLineWidth(4); - Cpu_Time1->SetMarkerColor(4); - Cpu_Time1->SetMarkerSize(1.0); - Cpu_Time1->SetMarkerStyle(21); - Cpu_Time1->SetTitle("Generation time"); - Cpu_Time1->GetXaxis()->SetTitle("Number of events"); - Cpu_Time1->GetYaxis()->SetTitle("Time (s)"); - Cpu_Time1->GetYaxis()->SetTitleOffset(1.4); - Cpu_Time1->Draw("ACP"); - - c1->SaveAs(TString::Format("%s/Rnd_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c2->SaveAs(TString::Format("%s/Evt_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c3->SaveAs(TString::Format("%s/Out_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c4->SaveAs(TString::Format("%s/Cpu_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - - - - TGraph *Rnd_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Rnd_Time2.data()); - TGraph *Evt_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Evt_Time2.data()); - TGraph *Out_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Out_Time2.data()); - TGraph *Cpu_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Cpu_Time2.data()); - - TCanvas *d1 = new TCanvas( "Rnd_Time2", "Rnd_Time2", 600, 500 ); - Rnd_Time2->SetLineColor(2); - Rnd_Time2->SetLineWidth(4); - Rnd_Time2->SetMarkerColor(4); - Rnd_Time2->SetMarkerSize(1.0); - Rnd_Time2->SetMarkerStyle(21); - Rnd_Time2->SetTitle("Randon number generation time"); - Rnd_Time2->GetXaxis()->SetTitle("Number of particles"); - Rnd_Time2->GetYaxis()->SetTitle("Time (s)"); - Rnd_Time2->GetYaxis()->SetTitleOffset(1.4); - Rnd_Time2->Draw("ACP"); - - TCanvas *d2 = new TCanvas( "Evt_Time2", "Evt_Time2", 600, 500 ); - Evt_Time2->SetLineColor(2); - Evt_Time2->SetLineWidth(4); - Evt_Time2->SetMarkerColor(4); - Evt_Time2->SetMarkerSize(1.0); - Evt_Time2->SetMarkerStyle(21); - Evt_Time2->SetTitle("Events generation time"); - Evt_Time2->GetXaxis()->SetTitle("Number of particles"); - Evt_Time2->GetYaxis()->SetTitle("Time (s)"); - Evt_Time2->GetYaxis()->SetTitleOffset(1.4); - Evt_Time2->Draw("ACP"); - - - TCanvas *d3 = new TCanvas( "Out_Time2", "Out_Time2", 600, 500 ); - Out_Time2->SetLineColor(2); - Out_Time2->SetLineWidth(4); - Out_Time2->SetMarkerColor(4); - Out_Time2->SetMarkerSize(1.0); - Out_Time2->SetMarkerStyle(21); - Out_Time2->SetTitle("Output time"); - Out_Time2->GetXaxis()->SetTitle("Number of particles"); - Out_Time2->GetYaxis()->SetTitle("Time (s)"); - Out_Time2->GetYaxis()->SetTitleOffset(1.4); - Out_Time2->Draw("ACP"); - - TCanvas *d4 = new TCanvas( "Cpu_Time2", "Cpu_Time", 600, 500 ); - Cpu_Time2->SetLineColor(2); - Cpu_Time2->SetLineWidth(4); - Cpu_Time2->SetMarkerColor(4); - Cpu_Time2->SetMarkerSize(1.0); - Cpu_Time2->SetMarkerStyle(21); - Cpu_Time2->SetTitle("Generation time"); - Cpu_Time2->GetXaxis()->SetTitle("Number of particles"); - Cpu_Time2->GetYaxis()->SetTitle("Time (s)"); - Cpu_Time2->GetYaxis()->SetTitleOffset(1.4); - Cpu_Time2->Draw("ACP"); - - d1->SaveAs(TString::Format("%s/Rnd_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d2->SaveAs(TString::Format("%s/Evt_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d3->SaveAs(TString::Format("%s/Out_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d4->SaveAs(TString::Format("%s/Cpu_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - - - myapp->Run(); - return 0; +GInt_t main(int argv, char **argc) { + GULong_t nevents_scan = 0; + string suffix = ""; + string output_dir = ""; + + try { + TCLAP::CmdLine cmd("Command line arguments for PerformanceTest", ' ', "0.9"); + + TCLAP::ValueArg eArg("e", "events", "Number of events in time profile", false, 1e6, "long integer"); + cmd.add(eArg); + + TCLAP::ValueArg sArg("s", "suffix", "Suffix for plots name", false, "", "string"); + cmd.add(sArg); + + TCLAP::ValueArg oArg("o", "output_dir", "output directory", false, ".", "string"); + cmd.add(oArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nevents_scan = eArg.getValue(); + suffix = sArg.getValue(); + output_dir = oArg.getValue(); + + } catch(TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + vector _NParticles; + vector _NEvents; + + vector _Rnd_Time1; + vector _Evt_Time1; + vector _Out_Time1; + vector _Cpu_Time1; + + vector _Rnd_Time2; + vector _Evt_Time2; + vector _Out_Time2; + vector _Cpu_Time2; + + GDouble_t _time[4]; + + for(GInt_t i = 1; i < 40; i++) { + GULong_t nevt = i * 500000; + + RunMCGen(3, nevt, &_time[0]); + + _NEvents.push_back(nevt); + _Rnd_Time1.push_back(_time[0]); + _Evt_Time1.push_back(_time[1]); + _Out_Time1.push_back(_time[2]); + _Cpu_Time1.push_back(_time[3]); + } + + for(GInt_t i = 2; i < 10; i++) { + RunMCGen(i, nevents_scan, &_time[0]); + _NParticles.push_back(i); + _Rnd_Time2.push_back(_time[0]); + _Evt_Time2.push_back(_time[1]); + _Out_Time2.push_back(_time[2]); + _Cpu_Time2.push_back(_time[3]); + } + + TApplication *myapp = new TApplication("myapp", 0, 0); + + TGraph *Rnd_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Rnd_Time1.data()); + TGraph *Evt_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Evt_Time1.data()); + TGraph *Out_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Out_Time1.data()); + TGraph *Cpu_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Cpu_Time1.data()); + + TCanvas *c1 = new TCanvas("Rnd_Time1", "Rnd_Time1", 600, 500); + Rnd_Time1->SetLineColor(2); + Rnd_Time1->SetLineWidth(4); + Rnd_Time1->SetMarkerColor(4); + Rnd_Time1->SetMarkerSize(1.0); + Rnd_Time1->SetMarkerStyle(21); + Rnd_Time1->SetTitle("Randon number generation time"); + Rnd_Time1->GetXaxis()->SetTitle("Number of events"); + Rnd_Time1->GetYaxis()->SetTitle("Time (s)"); + Rnd_Time1->GetYaxis()->SetTitleOffset(1.4); + Rnd_Time1->Draw("ACP"); + + TCanvas *c2 = new TCanvas("Evt_Time1", "Evt_Time1", 600, 500); + Evt_Time1->SetLineColor(2); + Evt_Time1->SetLineWidth(4); + Evt_Time1->SetMarkerColor(4); + Evt_Time1->SetMarkerSize(1.0); + Evt_Time1->SetMarkerStyle(21); + Evt_Time1->SetTitle("Events generation time"); + Evt_Time1->GetXaxis()->SetTitle("Number of events"); + Evt_Time1->GetYaxis()->SetTitle("Time (s)"); + Evt_Time1->GetYaxis()->SetTitleOffset(1.4); + Evt_Time1->Draw("ACP"); + + TCanvas *c3 = new TCanvas("Out_Time1", "Out_Time1", 600, 500); + Out_Time1->SetLineColor(2); + Out_Time1->SetLineWidth(4); + Out_Time1->SetMarkerColor(4); + Out_Time1->SetMarkerSize(1.0); + Out_Time1->SetMarkerStyle(21); + Out_Time1->SetTitle("Output time"); + Out_Time1->GetXaxis()->SetTitle("Number of events"); + Out_Time1->GetYaxis()->SetTitle("Time (s)"); + Out_Time1->GetYaxis()->SetTitleOffset(1.4); + Out_Time1->Draw("ACP"); + + TCanvas *c4 = new TCanvas("Cpu_Time", "Cpu_Time", 600, 500); + Cpu_Time1->SetLineColor(2); + Cpu_Time1->SetLineWidth(4); + Cpu_Time1->SetMarkerColor(4); + Cpu_Time1->SetMarkerSize(1.0); + Cpu_Time1->SetMarkerStyle(21); + Cpu_Time1->SetTitle("Generation time"); + Cpu_Time1->GetXaxis()->SetTitle("Number of events"); + Cpu_Time1->GetYaxis()->SetTitle("Time (s)"); + Cpu_Time1->GetYaxis()->SetTitleOffset(1.4); + Cpu_Time1->Draw("ACP"); + + c1->SaveAs(TString::Format("%s/Rnd_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c2->SaveAs(TString::Format("%s/Evt_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c3->SaveAs(TString::Format("%s/Out_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c4->SaveAs(TString::Format("%s/Cpu_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + + TGraph *Rnd_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Rnd_Time2.data()); + TGraph *Evt_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Evt_Time2.data()); + TGraph *Out_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Out_Time2.data()); + TGraph *Cpu_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Cpu_Time2.data()); + + TCanvas *d1 = new TCanvas("Rnd_Time2", "Rnd_Time2", 600, 500); + Rnd_Time2->SetLineColor(2); + Rnd_Time2->SetLineWidth(4); + Rnd_Time2->SetMarkerColor(4); + Rnd_Time2->SetMarkerSize(1.0); + Rnd_Time2->SetMarkerStyle(21); + Rnd_Time2->SetTitle("Randon number generation time"); + Rnd_Time2->GetXaxis()->SetTitle("Number of particles"); + Rnd_Time2->GetYaxis()->SetTitle("Time (s)"); + Rnd_Time2->GetYaxis()->SetTitleOffset(1.4); + Rnd_Time2->Draw("ACP"); + + TCanvas *d2 = new TCanvas("Evt_Time2", "Evt_Time2", 600, 500); + Evt_Time2->SetLineColor(2); + Evt_Time2->SetLineWidth(4); + Evt_Time2->SetMarkerColor(4); + Evt_Time2->SetMarkerSize(1.0); + Evt_Time2->SetMarkerStyle(21); + Evt_Time2->SetTitle("Events generation time"); + Evt_Time2->GetXaxis()->SetTitle("Number of particles"); + Evt_Time2->GetYaxis()->SetTitle("Time (s)"); + Evt_Time2->GetYaxis()->SetTitleOffset(1.4); + Evt_Time2->Draw("ACP"); + + TCanvas *d3 = new TCanvas("Out_Time2", "Out_Time2", 600, 500); + Out_Time2->SetLineColor(2); + Out_Time2->SetLineWidth(4); + Out_Time2->SetMarkerColor(4); + Out_Time2->SetMarkerSize(1.0); + Out_Time2->SetMarkerStyle(21); + Out_Time2->SetTitle("Output time"); + Out_Time2->GetXaxis()->SetTitle("Number of particles"); + Out_Time2->GetYaxis()->SetTitle("Time (s)"); + Out_Time2->GetYaxis()->SetTitleOffset(1.4); + Out_Time2->Draw("ACP"); + + TCanvas *d4 = new TCanvas("Cpu_Time2", "Cpu_Time", 600, 500); + Cpu_Time2->SetLineColor(2); + Cpu_Time2->SetLineWidth(4); + Cpu_Time2->SetMarkerColor(4); + Cpu_Time2->SetMarkerSize(1.0); + Cpu_Time2->SetMarkerStyle(21); + Cpu_Time2->SetTitle("Generation time"); + Cpu_Time2->GetXaxis()->SetTitle("Number of particles"); + Cpu_Time2->GetYaxis()->SetTitle("Time (s)"); + Cpu_Time2->GetYaxis()->SetTitleOffset(1.4); + Cpu_Time2->Draw("ACP"); + + d1->SaveAs(TString::Format("%s/Rnd_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d2->SaveAs(TString::Format("%s/Evt_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d3->SaveAs(TString::Format("%s/Out_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d4->SaveAs(TString::Format("%s/Cpu_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + + myapp->Run(); + return 0; } diff --git a/extern/MCBooster/src/PerformanceTest.cu b/extern/MCBooster/src/PerformanceTest.cu index 90a3520fc..f234b66e4 100644 --- a/extern/MCBooster/src/PerformanceTest.cu +++ b/extern/MCBooster/src/PerformanceTest.cu @@ -2,11 +2,11 @@ * PerformanceTest.cu * * Copyright 2016 Antonio Augusto Alves Junior - * + * * Created on : 10/03/2016 * Author: augalves */ - + /* This file is part of MCBooster. @@ -31,9 +31,9 @@ #include #include -//command line +// command line #include -//this lib +// this lib #include #include #include @@ -42,7 +42,7 @@ #include #include -//root +// root #include #include #include @@ -60,264 +60,229 @@ using namespace std; using namespace mcbooster; -void RunMCGen (GInt_t nfinal, GInt_t nevents, Double_t *time ) -{ - - - vector names; - vector masses; +void RunMCGen(GInt_t nfinal, GInt_t nevents, Double_t *time) { + vector names; + vector masses; - for(GInt_t i=0; i eArg("e", "events", "Number of events in time profile", - false, 1e6, "long integer"); - cmd.add(eArg); - - TCLAP::ValueArg sArg("s", "suffix", - "Suffix for plots name", - false, "", "string"); - cmd.add(sArg); - - TCLAP::ValueArg oArg("o", "output_dir", "output directory", - false, ".", "string"); - cmd.add(oArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nevents_scan = eArg.getValue(); - suffix = sArg.getValue(); - output_dir = oArg.getValue(); - - } catch (TCLAP::ArgException &e) // catch any exceptions - { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - vector _NParticles; - vector _NEvents; - - vector _Rnd_Time1; - vector _Evt_Time1; - vector _Out_Time1; - vector _Cpu_Time1; - - vector _Rnd_Time2; - vector _Evt_Time2; - vector _Out_Time2; - vector _Cpu_Time2; - - - - - GDouble_t _time[4]; - - for(GInt_t i=1;i<100;i++) - { - GULong_t nevt = i*500000; - - RunMCGen(3, nevt , &_time[0] ); - - _NEvents.push_back( nevt ); - _Rnd_Time1.push_back( _time[0] ); - _Evt_Time1.push_back( _time[1] ); - _Out_Time1.push_back( _time[2] ); - _Cpu_Time1.push_back( _time[3] ); - - } - - for(GInt_t i=2;i<10;i++) - { - - - RunMCGen(i, nevents_scan , &_time[0] ); - _NParticles.push_back( i ); - _Rnd_Time2.push_back( _time[0] ); - _Evt_Time2.push_back( _time[1] ); - _Out_Time2.push_back( _time[2] ); - _Cpu_Time2.push_back( _time[3] ); - - } - - - - - TApplication *myapp=new TApplication("myapp",0,0); - - TGraph *Rnd_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Rnd_Time1.data()); - TGraph *Evt_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Evt_Time1.data()); - TGraph *Out_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Out_Time1.data()); - TGraph *Cpu_Time1 = new TGraph( _NEvents.size(), _NEvents.data(), _Cpu_Time1.data()); - - TCanvas *c1 = new TCanvas( "Rnd_Time1", "Rnd_Time1", 600, 500 ); - Rnd_Time1->SetLineColor(2); - Rnd_Time1->SetLineWidth(4); - Rnd_Time1->SetMarkerColor(4); - Rnd_Time1->SetMarkerSize(1.0); - Rnd_Time1->SetMarkerStyle(21); - Rnd_Time1->SetTitle("Randon number generation time"); - Rnd_Time1->GetXaxis()->SetTitle("Number of events"); - Rnd_Time1->GetYaxis()->SetTitle("Time (s)"); - Rnd_Time1->GetYaxis()->SetTitleOffset(1.4); - Rnd_Time1->Draw("ACP"); - - TCanvas *c2 = new TCanvas( "Evt_Time1", "Evt_Time1", 600, 500 ); - Evt_Time1->SetLineColor(2); - Evt_Time1->SetLineWidth(4); - Evt_Time1->SetMarkerColor(4); - Evt_Time1->SetMarkerSize(1.0); - Evt_Time1->SetMarkerStyle(21); - Evt_Time1->SetMinimum(0.0); - Evt_Time1->SetTitle("Sample generation time"); - Evt_Time1->GetXaxis()->SetTitle("Number of events"); - Evt_Time1->GetYaxis()->SetTitle("Time (s)"); - Evt_Time1->GetYaxis()->SetTitleOffset(1.4); - Evt_Time1->Draw("ACP"); - - - TCanvas *c3 = new TCanvas( "Out_Time1", "Out_Time1", 600, 500 ); - Out_Time1->SetLineColor(2); - Out_Time1->SetLineWidth(4); - Out_Time1->SetMarkerColor(4); - Out_Time1->SetMarkerSize(1.0); - Out_Time1->SetMarkerStyle(21); - Out_Time1->SetTitle("Output time"); - Out_Time1->GetXaxis()->SetTitle("Number of events"); - Out_Time1->GetYaxis()->SetTitle("Time (s)"); - Out_Time1->GetYaxis()->SetTitleOffset(1.4); - Out_Time1->Draw("ACP"); - - TCanvas *c4 = new TCanvas( "Cpu_Time", "Cpu_Time", 600, 500 ); - Cpu_Time1->SetLineColor(2); - Cpu_Time1->SetLineWidth(4); - Cpu_Time1->SetMarkerColor(4); - Cpu_Time1->SetMarkerSize(1.0); - Cpu_Time1->SetMarkerStyle(21); - Cpu_Time1->SetTitle("Generation time"); - Cpu_Time1->GetXaxis()->SetTitle("Number of events"); - Cpu_Time1->GetYaxis()->SetTitle("Time (s)"); - Cpu_Time1->GetYaxis()->SetTitleOffset(1.4); - Cpu_Time1->Draw("ACP"); - - c1->SaveAs(TString::Format("%s/Rnd_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c2->SaveAs(TString::Format("%s/Evt_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c3->SaveAs(TString::Format("%s/Out_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - c4->SaveAs(TString::Format("%s/Cpu_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); - - - - TGraph *Rnd_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Rnd_Time2.data()); - TGraph *Evt_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Evt_Time2.data()); - TGraph *Out_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Out_Time2.data()); - TGraph *Cpu_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Cpu_Time2.data()); - - TCanvas *d1 = new TCanvas( "Rnd_Time2", "Rnd_Time2", 600, 500 ); - Rnd_Time2->SetLineColor(2); - Rnd_Time2->SetLineWidth(4); - Rnd_Time2->SetMarkerColor(4); - Rnd_Time2->SetMarkerSize(1.0); - Rnd_Time2->SetMarkerStyle(21); - Rnd_Time2->SetTitle("Randon number generation time"); - Rnd_Time2->GetXaxis()->SetTitle("Number of particles"); - Rnd_Time2->GetYaxis()->SetTitle("Time (s)"); - Rnd_Time2->GetYaxis()->SetTitleOffset(1.4); - Rnd_Time2->Draw("ACP"); - - TCanvas *d2 = new TCanvas( "Evt_Time2", "Evt_Time2", 600, 500 ); - Evt_Time2->SetLineColor(2); - Evt_Time2->SetLineWidth(4); - Evt_Time2->SetMarkerColor(4); - Evt_Time2->SetMarkerSize(1.0); - Evt_Time2->SetMarkerStyle(21); - Evt_Time2->SetMinimum(0.0); - Evt_Time2->SetTitle("Sample generation time"); - Evt_Time2->GetXaxis()->SetTitle("Number of particles"); - Evt_Time2->GetYaxis()->SetTitle("Time (s)"); - Evt_Time2->GetYaxis()->SetTitleOffset(1.4); - Evt_Time2->Draw("ACP"); - - - TCanvas *d3 = new TCanvas( "Out_Time2", "Out_Time2", 600, 500 ); - Out_Time2->SetLineColor(2); - Out_Time2->SetLineWidth(4); - Out_Time2->SetMarkerColor(4); - Out_Time2->SetMarkerSize(1.0); - Out_Time2->SetMarkerStyle(21); - Out_Time2->SetTitle("Output time"); - Out_Time2->GetXaxis()->SetTitle("Number of particles"); - Out_Time2->GetYaxis()->SetTitle("Time (s)"); - Out_Time2->GetYaxis()->SetTitleOffset(1.4); - Out_Time2->Draw("ACP"); - - TCanvas *d4 = new TCanvas( "Cpu_Time2", "Cpu_Time", 600, 500 ); - Cpu_Time2->SetLineColor(2); - Cpu_Time2->SetLineWidth(4); - Cpu_Time2->SetMarkerColor(4); - Cpu_Time2->SetMarkerSize(1.0); - Cpu_Time2->SetMarkerStyle(21); - Cpu_Time2->SetTitle("Generation time"); - Cpu_Time2->GetXaxis()->SetTitle("Number of particles"); - Cpu_Time2->GetYaxis()->SetTitle("Time (s)"); - Cpu_Time2->GetYaxis()->SetTitleOffset(1.4); - Cpu_Time2->Draw("ACP"); - - d1->SaveAs(TString::Format("%s/Rnd_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d2->SaveAs(TString::Format("%s/Evt_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d3->SaveAs(TString::Format("%s/Out_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - d4->SaveAs(TString::Format("%s/Cpu_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); - - - myapp->Run(); - return 0; +GInt_t main(int argv, char **argc) { + GULong_t nevents_scan = 0; + string suffix = ""; + string output_dir = ""; + + try { + TCLAP::CmdLine cmd("Command line arguments for PerformanceTest", ' ', "0.9"); + + TCLAP::ValueArg eArg("e", "events", "Number of events in time profile", false, 1e6, "long integer"); + cmd.add(eArg); + + TCLAP::ValueArg sArg("s", "suffix", "Suffix for plots name", false, "", "string"); + cmd.add(sArg); + + TCLAP::ValueArg oArg("o", "output_dir", "output directory", false, ".", "string"); + cmd.add(oArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nevents_scan = eArg.getValue(); + suffix = sArg.getValue(); + output_dir = oArg.getValue(); + + } catch(TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + vector _NParticles; + vector _NEvents; + + vector _Rnd_Time1; + vector _Evt_Time1; + vector _Out_Time1; + vector _Cpu_Time1; + + vector _Rnd_Time2; + vector _Evt_Time2; + vector _Out_Time2; + vector _Cpu_Time2; + + GDouble_t _time[4]; + + for(GInt_t i = 1; i < 100; i++) { + GULong_t nevt = i * 500000; + + RunMCGen(3, nevt, &_time[0]); + + _NEvents.push_back(nevt); + _Rnd_Time1.push_back(_time[0]); + _Evt_Time1.push_back(_time[1]); + _Out_Time1.push_back(_time[2]); + _Cpu_Time1.push_back(_time[3]); + } + + for(GInt_t i = 2; i < 10; i++) { + RunMCGen(i, nevents_scan, &_time[0]); + _NParticles.push_back(i); + _Rnd_Time2.push_back(_time[0]); + _Evt_Time2.push_back(_time[1]); + _Out_Time2.push_back(_time[2]); + _Cpu_Time2.push_back(_time[3]); + } + + TApplication *myapp = new TApplication("myapp", 0, 0); + + TGraph *Rnd_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Rnd_Time1.data()); + TGraph *Evt_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Evt_Time1.data()); + TGraph *Out_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Out_Time1.data()); + TGraph *Cpu_Time1 = new TGraph(_NEvents.size(), _NEvents.data(), _Cpu_Time1.data()); + + TCanvas *c1 = new TCanvas("Rnd_Time1", "Rnd_Time1", 600, 500); + Rnd_Time1->SetLineColor(2); + Rnd_Time1->SetLineWidth(4); + Rnd_Time1->SetMarkerColor(4); + Rnd_Time1->SetMarkerSize(1.0); + Rnd_Time1->SetMarkerStyle(21); + Rnd_Time1->SetTitle("Randon number generation time"); + Rnd_Time1->GetXaxis()->SetTitle("Number of events"); + Rnd_Time1->GetYaxis()->SetTitle("Time (s)"); + Rnd_Time1->GetYaxis()->SetTitleOffset(1.4); + Rnd_Time1->Draw("ACP"); + + TCanvas *c2 = new TCanvas("Evt_Time1", "Evt_Time1", 600, 500); + Evt_Time1->SetLineColor(2); + Evt_Time1->SetLineWidth(4); + Evt_Time1->SetMarkerColor(4); + Evt_Time1->SetMarkerSize(1.0); + Evt_Time1->SetMarkerStyle(21); + Evt_Time1->SetMinimum(0.0); + Evt_Time1->SetTitle("Sample generation time"); + Evt_Time1->GetXaxis()->SetTitle("Number of events"); + Evt_Time1->GetYaxis()->SetTitle("Time (s)"); + Evt_Time1->GetYaxis()->SetTitleOffset(1.4); + Evt_Time1->Draw("ACP"); + + TCanvas *c3 = new TCanvas("Out_Time1", "Out_Time1", 600, 500); + Out_Time1->SetLineColor(2); + Out_Time1->SetLineWidth(4); + Out_Time1->SetMarkerColor(4); + Out_Time1->SetMarkerSize(1.0); + Out_Time1->SetMarkerStyle(21); + Out_Time1->SetTitle("Output time"); + Out_Time1->GetXaxis()->SetTitle("Number of events"); + Out_Time1->GetYaxis()->SetTitle("Time (s)"); + Out_Time1->GetYaxis()->SetTitleOffset(1.4); + Out_Time1->Draw("ACP"); + + TCanvas *c4 = new TCanvas("Cpu_Time", "Cpu_Time", 600, 500); + Cpu_Time1->SetLineColor(2); + Cpu_Time1->SetLineWidth(4); + Cpu_Time1->SetMarkerColor(4); + Cpu_Time1->SetMarkerSize(1.0); + Cpu_Time1->SetMarkerStyle(21); + Cpu_Time1->SetTitle("Generation time"); + Cpu_Time1->GetXaxis()->SetTitle("Number of events"); + Cpu_Time1->GetYaxis()->SetTitle("Time (s)"); + Cpu_Time1->GetYaxis()->SetTitleOffset(1.4); + Cpu_Time1->Draw("ACP"); + + c1->SaveAs(TString::Format("%s/Rnd_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c2->SaveAs(TString::Format("%s/Evt_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c3->SaveAs(TString::Format("%s/Out_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + c4->SaveAs(TString::Format("%s/Cpu_Time_%s.pdf", output_dir.c_str(), suffix.c_str())); + + TGraph *Rnd_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Rnd_Time2.data()); + TGraph *Evt_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Evt_Time2.data()); + TGraph *Out_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Out_Time2.data()); + TGraph *Cpu_Time2 = new TGraph(_NParticles.size(), _NParticles.data(), _Cpu_Time2.data()); + + TCanvas *d1 = new TCanvas("Rnd_Time2", "Rnd_Time2", 600, 500); + Rnd_Time2->SetLineColor(2); + Rnd_Time2->SetLineWidth(4); + Rnd_Time2->SetMarkerColor(4); + Rnd_Time2->SetMarkerSize(1.0); + Rnd_Time2->SetMarkerStyle(21); + Rnd_Time2->SetTitle("Randon number generation time"); + Rnd_Time2->GetXaxis()->SetTitle("Number of particles"); + Rnd_Time2->GetYaxis()->SetTitle("Time (s)"); + Rnd_Time2->GetYaxis()->SetTitleOffset(1.4); + Rnd_Time2->Draw("ACP"); + + TCanvas *d2 = new TCanvas("Evt_Time2", "Evt_Time2", 600, 500); + Evt_Time2->SetLineColor(2); + Evt_Time2->SetLineWidth(4); + Evt_Time2->SetMarkerColor(4); + Evt_Time2->SetMarkerSize(1.0); + Evt_Time2->SetMarkerStyle(21); + Evt_Time2->SetMinimum(0.0); + Evt_Time2->SetTitle("Sample generation time"); + Evt_Time2->GetXaxis()->SetTitle("Number of particles"); + Evt_Time2->GetYaxis()->SetTitle("Time (s)"); + Evt_Time2->GetYaxis()->SetTitleOffset(1.4); + Evt_Time2->Draw("ACP"); + + TCanvas *d3 = new TCanvas("Out_Time2", "Out_Time2", 600, 500); + Out_Time2->SetLineColor(2); + Out_Time2->SetLineWidth(4); + Out_Time2->SetMarkerColor(4); + Out_Time2->SetMarkerSize(1.0); + Out_Time2->SetMarkerStyle(21); + Out_Time2->SetTitle("Output time"); + Out_Time2->GetXaxis()->SetTitle("Number of particles"); + Out_Time2->GetYaxis()->SetTitle("Time (s)"); + Out_Time2->GetYaxis()->SetTitleOffset(1.4); + Out_Time2->Draw("ACP"); + + TCanvas *d4 = new TCanvas("Cpu_Time2", "Cpu_Time", 600, 500); + Cpu_Time2->SetLineColor(2); + Cpu_Time2->SetLineWidth(4); + Cpu_Time2->SetMarkerColor(4); + Cpu_Time2->SetMarkerSize(1.0); + Cpu_Time2->SetMarkerStyle(21); + Cpu_Time2->SetTitle("Generation time"); + Cpu_Time2->GetXaxis()->SetTitle("Number of particles"); + Cpu_Time2->GetYaxis()->SetTitle("Time (s)"); + Cpu_Time2->GetYaxis()->SetTitleOffset(1.4); + Cpu_Time2->Draw("ACP"); + + d1->SaveAs(TString::Format("%s/Rnd_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d2->SaveAs(TString::Format("%s/Evt_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d3->SaveAs(TString::Format("%s/Out_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + d4->SaveAs(TString::Format("%s/Cpu_Time2_%s.pdf", output_dir.c_str(), suffix.c_str())); + + myapp->Run(); + return 0; } diff --git a/include/goofit/Application.h b/include/goofit/Application.h index 9c79dc9b2..dc6d8d5c2 100644 --- a/include/goofit/Application.h +++ b/include/goofit/Application.h @@ -23,16 +23,14 @@ #include - - namespace GooFit { - -void signal_handler(int s){ + +void signal_handler(int s) { std::cout << std::endl << reset << red << bold; std::cout << "GooFit: Control-C detected, exiting..." << reset << std::endl; std::exit(1); // will call the correct exit func, no unwinding of the stack though } - + // Importing into the GooFit namespace the main classes from CLI11 using CLI::ParseError; using CLI::FileError; @@ -45,21 +43,22 @@ using CLI::NonexistentPath; using CLI::ExitCodes; class Application : public CLI::App { -protected: + protected: int gpuDev_ = 0; bool show_gpus_; bool quiet_; int argc_; - char** argv_; + char **argv_; /// Handle control-c codes struct sigaction sigIntHandler; - -public: - /// Make a new Application - Application(std::string discription, - int argc, char** argv) : App(discription), argc_(argc), argv_(argv) { + public: + /// Make a new Application + Application(std::string discription, int argc, char **argv) + : App(discription) + , argc_(argc) + , argv_(argv) { #ifdef GOOFIT_MPI MPI_Init(&argc_, &argv_); @@ -67,7 +66,7 @@ class Application : public CLI::App { MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Comm_rank(MPI_COMM_WORLD, &myId); -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA int deviceCount; cudaGetDeviceCount(&deviceCount); @@ -80,26 +79,26 @@ class Application : public CLI::App { nodes = 1; int procsPerNode = numProcs / nodes; - int localRank = myId % procsPerNode; + int localRank = myId % procsPerNode; - //Note, this will (probably) be overwritten by gpu-set-device calls... + // Note, this will (probably) be overwritten by gpu-set-device calls... if(deviceCount == 1 && localRank > 1) { - //Multi-process to one GPU! + // Multi-process to one GPU! gpuDev_ = 0; } else if(procsPerNode > 1 && deviceCount > 1) { if(localRank <= deviceCount) { - //setting multiple processes to multiple GPU's + // setting multiple processes to multiple GPU's gpuDev_ = localRank; } else { - //More multiple processes than GPU's, distribute sort of evenly! + // More multiple processes than GPU's, distribute sort of evenly! gpuDev_ = localRank % deviceCount; } } else { - //multiple GPU's, using one process + // multiple GPU's, using one process gpuDev_ = 0; } - std::cout << "MPI using CUDA device: " << gpuDev_ << std::endl; + std::cout << "MPI using CUDA device: " << gpuDev_ << std::endl; cudaSetDevice(gpuDev_); #endif #endif @@ -118,33 +117,26 @@ class Application : public CLI::App { add_config("--config", "config.ini", "An ini file with command line options in it")->group("GooFit"); // Reset color on exit (but not control-c) - std::atexit([]() { - std::cout << GooFit::reset; - }); - + std::atexit([]() { std::cout << GooFit::reset; }); + sigIntHandler.sa_handler = signal_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, nullptr); - } /// Shortcut for the lazy - Application(int argc, char** argv) : Application("", argc, argv) {} + Application(int argc, char **argv) + : Application("", argc, argv) {} /// Get the set GPU device - int get_device() const { - return gpuDev_; - } + int get_device() const { return gpuDev_; } /// simple run since argc and argv are stored - void run() { - parse(argc_, argv_); - } + void run() { parse(argc_, argv_); } /// Gets called in parse void pre_callback() override { - set_device(); if(!quiet_) { @@ -153,13 +145,13 @@ class Application : public CLI::App { #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA cudaDeviceProp devProp; cudaGetDeviceProperties(&devProp, gpuDev_); - + GOOFIT_INFO("CUDA: Device {}: {}", get_device(), devProp.name); - + GOOFIT_INFO("CUDA: Compute {}.{}", devProp.major, devProp.minor); GOOFIT_INFO("CUDA: Total global memory: {} GB", devProp.totalGlobalMem / 1.0e9); GOOFIT_INFO("CUDA: Multiprocessors: {}", devProp.multiProcessorCount); - + GOOFIT_DEBUG("CUDA: Total amount of shared memory per block: {}", devProp.sharedMemPerBlock); GOOFIT_DEBUG("CUDA: Total registers per block: {}", devProp.regsPerBlock); GOOFIT_DEBUG("CUDA: Warp size: {}", devProp.warpSize); @@ -189,9 +181,8 @@ class Application : public CLI::App { for(int i = 0; i < deviceCount; i++) { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, i); - std::cout << "CUDA: Device " << i << " has compute capability " - << deviceProp.major << "." << deviceProp.minor - << std::endl; + std::cout << "CUDA: Device " << i << " has compute capability " << deviceProp.major << "." + << deviceProp.minor << std::endl; } throw GooFit::Success(); @@ -200,16 +191,16 @@ class Application : public CLI::App { #endif } - int exit(const CLI::Error& e) { + int exit(const CLI::Error &e) { #ifdef GOOFIT_MPI int myId; MPI_Comm_rank(MPI_COMM_WORLD, &myId); - if(myId>0) + if(myId > 0) return e.get_exit_code(); #endif - std::cout << (e.get_exit_code()==0 ? blue : red); + std::cout << (e.get_exit_code() == 0 ? blue : red); int rval = CLI::App::exit(e); std::cout << GooFit::reset; return rval; @@ -218,7 +209,6 @@ class Application : public CLI::App { /// Call if the application might fork, otherwise automatic /// For example, if explicitly using omp void set_device() const { - #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA if(gpuDev_ != 0) { @@ -234,21 +224,20 @@ class Application : public CLI::App { MPI_Finalize(); #endif } - + /// Get a file from the current directory, looks up one and in the true current directory /// Base gives a relative path from the source directory - std::string get_filename(const std::string& input_str, std::string base = "") const { - + std::string get_filename(const std::string &input_str, std::string base = "") const { // Run from current directory if(CLI::ExistingFile(input_str)) return input_str; - + // Run from a different directory - std::string prog_name {argv_[0]}; + std::string prog_name{argv_[0]}; size_t loc = prog_name.rfind("/"); if(loc != std::string::npos) { - std::string cdir = prog_name.substr(0,loc); - std::string new_input {cdir + "/" + input_str}; + std::string cdir = prog_name.substr(0, loc); + std::string new_input{cdir + "/" + input_str}; if(CLI::ExistingFile(new_input)) { std::cout << "Found file at " << new_input << std::endl; return new_input; @@ -263,10 +252,9 @@ class Application : public CLI::App { return new_input; } } - + // Could not find file throw GooFit::FileError(input_str); } }; - } diff --git a/include/goofit/BinnedDataSet.h b/include/goofit/BinnedDataSet.h index 485837c32..aee15c155 100644 --- a/include/goofit/BinnedDataSet.h +++ b/include/goofit/BinnedDataSet.h @@ -7,57 +7,49 @@ namespace GooFit { - class BinnedDataSet : public DataSet { // Class for rectangularly binned datasets - every bin the same size. -public: + public: using DataSet::addEvent; - - BinnedDataSet(Variable* var, std::string n = ""); - BinnedDataSet(std::vector& vars, std::string n = ""); - BinnedDataSet(std::set& vars, std::string n = ""); - BinnedDataSet(std::initializer_list vars, std::string n=""); + + BinnedDataSet(Variable *var, std::string n = ""); + BinnedDataSet(std::vector &vars, std::string n = ""); + BinnedDataSet(std::set &vars, std::string n = ""); + BinnedDataSet(std::initializer_list vars, std::string n = ""); ~BinnedDataSet() override = default; void addEvent() override; void addWeightedEvent(double weight) override; - fptype getBinContent(size_t bin) const { - return binvalues.at(bin); - } + fptype getBinContent(size_t bin) const { return binvalues.at(bin); } fptype getBinCenter(size_t ivar, size_t bin) const; - fptype getBinCenter(Variable* var, size_t bin) const; + fptype getBinCenter(Variable *var, size_t bin) const; fptype getBinSize(size_t ivar) const; - + size_t getBinNumber() const; fptype getBinVolume(size_t bin) const; fptype getBinError(size_t bin) const; - + size_t getNumBins() const; - + /// This includes weights fptype getNumWeightedEvents() const; - void setBinContent(unsigned int bin, fptype value) { - binvalues.at(bin) = value; - } + void setBinContent(unsigned int bin, fptype value) { binvalues.at(bin) = value; } void setBinError(unsigned int bin, fptype error); -private: - - std::vector convertValuesToBins(const std::vector& vals) const; - size_t localToGlobal(const std::vector& locals) const; + private: + std::vector convertValuesToBins(const std::vector &vals) const; + size_t localToGlobal(const std::vector &locals) const; std::vector globalToLocal(size_t global) const; - + /// Capture the number of bins on all variables void collectBins(); std::vector binsizes; std::vector binvalues; std::vector binerrors; - }; } // namespace GooFit - diff --git a/include/goofit/Color.h b/include/goofit/Color.h index 73fe3679e..edd91268b 100644 --- a/include/goofit/Color.h +++ b/include/goofit/Color.h @@ -5,17 +5,16 @@ namespace GooFit { // Handy colors -constexpr rang::fg const black = rang::fg::black; -constexpr rang::fg const red = rang::fg::red; -constexpr rang::fg const green = rang::fg::green; -constexpr rang::fg const yellow = rang::fg::yellow; -constexpr rang::fg const blue = rang::fg::blue; -constexpr rang::fg const magenta = rang::fg::magenta; -constexpr rang::fg const cyan = rang::fg::cyan; -constexpr rang::fg const gray = rang::fg::gray; -constexpr rang::style const reset = rang::style::reset; -constexpr rang::style const bold = rang::style::bold; -constexpr rang::style const dim = rang::style::dim; +constexpr rang::fg const black = rang::fg::black; +constexpr rang::fg const red = rang::fg::red; +constexpr rang::fg const green = rang::fg::green; +constexpr rang::fg const yellow = rang::fg::yellow; +constexpr rang::fg const blue = rang::fg::blue; +constexpr rang::fg const magenta = rang::fg::magenta; +constexpr rang::fg const cyan = rang::fg::cyan; +constexpr rang::fg const gray = rang::fg::gray; +constexpr rang::style const reset = rang::style::reset; +constexpr rang::style const bold = rang::style::bold; +constexpr rang::style const dim = rang::style::dim; constexpr rang::style const italic = rang::style::italic; - } diff --git a/include/goofit/DataSet.h b/include/goofit/DataSet.h index df6136011..f9c185222 100644 --- a/include/goofit/DataSet.h +++ b/include/goofit/DataSet.h @@ -12,67 +12,57 @@ namespace GooFit { - class DataSet { -public: - DataSet(Variable* var, std::string n = ""); - - DataSet(std::vector& vars, std::string n = ""); - DataSet(std::set& vars, std::string n = ""); - DataSet(std::initializer_list vars, std::string n = ""); - + public: + DataSet(Variable *var, std::string n = ""); + + DataSet(std::vector &vars, std::string n = ""); + DataSet(std::set &vars, std::string n = ""); + DataSet(std::initializer_list vars, std::string n = ""); + virtual ~DataSet() = default; virtual void addEvent() = 0; // Must increment numEventsAdded - + virtual void addWeightedEvent(fptype weight); - /// This is a helper that allows multiple values to be passed in instead of relying on the content of the Variables. template void addEvent(fptype value, Args... args) { - std::vector values {value, static_cast(args)...}; - + std::vector values{value, static_cast(args)...}; + if(values.size() != variables.size()) throw GooFit::GeneralError("You must pass the correct number of values ({}) to addEvent", variables.size()); - - for(size_t i=0; isetValue(values[i]); addEvent(); } - - const std::vector& getVariables() const; + const std::vector &getVariables() const; - size_t numVariables() const { - return variables.size(); - } - - size_t getNumEvents() const { - return numEventsAdded; - } + size_t numVariables() const { return variables.size(); } - std::string getName() const { - return name; - } + size_t getNumEvents() const { return numEventsAdded; } -protected: + std::string getName() const { return name; } + + protected: std::vector getCurrentValues() const; - size_t indexOfVariable(Variable* var) const; - size_t numEventsAdded {0}; - + size_t indexOfVariable(Variable *var) const; + size_t numEventsAdded{0}; + /// Throw an error if any variables are out of range, call in addEvent void checkAllVars() const; - -private: + + private: /// Make a name, does not change the exising name. Called by all constructors. void generateName(); - + std::string name; -protected: - std::vector variables; + protected: + std::vector variables; }; } // namespace GooFit - diff --git a/include/goofit/Error.h b/include/goofit/Error.h index 644b0ad0e..2a72b96a9 100644 --- a/include/goofit/Error.h +++ b/include/goofit/Error.h @@ -9,13 +9,12 @@ namespace GooFit { /// Thrown when a general error is encountered struct GeneralError : public CLI::Error { template - GeneralError(std::string name, Args&&... args) - : Error("GeneralError", fmt::format(name, std::forward(args)...), 2) {} - + GeneralError(std::string name, Args &&... args) + : Error("GeneralError", fmt::format(name, std::forward(args)...), 2) {} }; struct OutOfRange : public GeneralError { OutOfRange(std::string name, double value, double min, double max) - : GeneralError("{} value {} is not in range {} to {}", name, value, min, max) {} + : GeneralError("{} value {} is not in range {} to {}", name, value, min, max) {} }; } diff --git a/include/goofit/Faddeeva.h b/include/goofit/Faddeeva.h index d008889b2..1b381eecb 100644 --- a/include/goofit/Faddeeva.h +++ b/include/goofit/Faddeeva.h @@ -4,8 +4,6 @@ namespace GooFit { - fptype cpuvoigtian(fptype x, fptype m, fptype w, fptype s); } // namespace GooFit - diff --git a/include/goofit/FitControl.h b/include/goofit/FitControl.h index b7c54b1ee..dcf48ed4a 100644 --- a/include/goofit/FitControl.h +++ b/include/goofit/FitControl.h @@ -8,66 +8,58 @@ namespace GooFit { - class PdfBase; class FitControl { -public: + public: FitControl(bool bin, std::string mn) - : binned(bin) - , metricName(mn) {} + : binned(bin) + , metricName(mn) {} - inline bool binnedFit() const { - return binned; - } - inline bool binErrors() const { - return errorsOnBins; - } - inline bool metricIsPdf() const { - return !errorsOnBins; - } - inline std::string getMetric() const { - return metricName; - } - inline PdfBase* getOwner() const { - return owner; - } - void setOwner(PdfBase* dat) { + inline bool binnedFit() const { return binned; } + inline bool binErrors() const { return errorsOnBins; } + inline bool metricIsPdf() const { return !errorsOnBins; } + inline std::string getMetric() const { return metricName; } + inline PdfBase *getOwner() const { return owner; } + void setOwner(PdfBase *dat) { if(dat == nullptr) throw GooFit::GeneralError("Owner will be nullptr"); owner = dat; } -protected: - bool errorsOnBins {false}; + protected: + bool errorsOnBins{false}; -private: + private: bool binned; std::string metricName; - PdfBase* owner {nullptr}; + PdfBase *owner{nullptr}; }; class UnbinnedNllFit : public FitControl { -public: - UnbinnedNllFit() : FitControl(false, "ptr_to_NLL") {} + public: + UnbinnedNllFit() + : FitControl(false, "ptr_to_NLL") {} }; class BinnedNllFit : public FitControl { -public: - BinnedNllFit() : FitControl(true, "ptr_to_BinAvg") {} + public: + BinnedNllFit() + : FitControl(true, "ptr_to_BinAvg") {} }; class BinnedErrorFit : public FitControl { -public: - BinnedErrorFit() : FitControl(true, "ptr_to_BinWithError") { + public: + BinnedErrorFit() + : FitControl(true, "ptr_to_BinWithError") { errorsOnBins = true; } }; class BinnedChisqFit : public FitControl { -public: - BinnedChisqFit() : FitControl(true, "ptr_to_Chisq") {} + public: + BinnedChisqFit() + : FitControl(true, "ptr_to_Chisq") {} }; } // namespace GooFit - diff --git a/include/goofit/FitManager.h b/include/goofit/FitManager.h index 7c2dfd10e..8ee844204 100644 --- a/include/goofit/FitManager.h +++ b/include/goofit/FitManager.h @@ -6,8 +6,6 @@ namespace GooFit { - using FitManager = GooFit::FitManagerMinuit2; } // namespace GooFit - diff --git a/include/goofit/FunctorWriter.h b/include/goofit/FunctorWriter.h index b2aa369cf..144758f43 100644 --- a/include/goofit/FunctorWriter.h +++ b/include/goofit/FunctorWriter.h @@ -2,18 +2,16 @@ #include -#include "goofit/GlobalCudaDefines.h" // Need this for 'fptype' +#include "goofit/GlobalCudaDefines.h" // Need this for 'fptype' namespace GooFit { - class PdfBase; -void writeToFile(PdfBase* pdf, const char* fname); -void readFromFile(PdfBase* pdf, const char* fname); +void writeToFile(PdfBase *pdf, const char *fname); +void readFromFile(PdfBase *pdf, const char *fname); -void writeListOfNumbers(thrust::host_vector& target, const char* fname); -void readListOfNumbers(thrust::host_vector& target, const char* fname); +void writeListOfNumbers(thrust::host_vector &target, const char *fname); +void readListOfNumbers(thrust::host_vector &target, const char *fname); } // namespace GooFit - diff --git a/include/goofit/GlobalCudaDefines.h b/include/goofit/GlobalCudaDefines.h index 964175c1f..5c2e7f2fd 100644 --- a/include/goofit/GlobalCudaDefines.h +++ b/include/goofit/GlobalCudaDefines.h @@ -1,7 +1,7 @@ #pragma once #include // __host__, __device__ defines -#include // Error types +#include // Error types #include #include @@ -11,7 +11,7 @@ extern int host_callnumber; } // Non-cuda defines -#if THRUST_DEVICE_SYSTEM!=THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CUDA #define __align__(n) #define __shared__ #define __constant__ @@ -19,50 +19,51 @@ extern int host_callnumber; // Use char* here because I need +1 to mean "offset by one byte", not "by one sizeof(whatever)". // Can't use void* because then the compiler doesn't know how to do pointer arithmetic. // This will fail if sizeof(char) is more than 1. But that should never happen, right? -#define MEMCPY(target, source, count, direction) memcpy((char*) target, source, count) -#define MEMCPY_TO_SYMBOL(target, source, count, offset, direction) memcpy(((char*) target)+offset, source, count) -#define MEMCPY_FROM_SYMBOL(target, source, count, offset, direction) memcpy((char*) target, ((char*) source)+offset, count) -#define GET_FUNCTION_ADDR(fname) host_fcn_ptr = (void*) fname +#define MEMCPY(target, source, count, direction) memcpy((char *)target, source, count) +#define MEMCPY_TO_SYMBOL(target, source, count, offset, direction) memcpy(((char *)target) + offset, source, count) +#define MEMCPY_FROM_SYMBOL(target, source, count, offset, direction) \ + memcpy((char *)target, ((char *)source) + offset, count) +#define GET_FUNCTION_ADDR(fname) host_fcn_ptr = (void *)fname #define BLOCKIDX (1) inline void cudaDeviceSynchronize() {} // Create my own error type to avoid __host__ redefinition // conflict in Thrust from including driver_types.h -enum gooError {gooSuccess = 0, gooErrorMemoryAllocation}; +enum gooError { gooSuccess = 0, gooErrorMemoryAllocation }; #define RO_CACHE(x) x #endif -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_OMP || THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_TBB +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_OMP || THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_TBB #include #define THREADIDX (omp_get_thread_num()) #define BLOCKDIM (omp_get_num_threads()) #define THREAD_SYNCH _Pragma("omp barrier") -#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CPP +#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CPP #define THREADIDX (1) #define BLOCKDIM (1) -#define THREAD_SYNCH +#define THREAD_SYNCH -#elif THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA // CUDA target - defaults #define THREAD_SYNCH __syncthreads(); #define MEMCPY(target, source, count, direction) cudaMemcpy(target, source, count, direction) -#define MEMCPY_TO_SYMBOL(target, source, count, offset, direction) cudaMemcpyToSymbol(target, source, count, offset, direction) +#define MEMCPY_TO_SYMBOL(target, source, count, offset, direction) \ + cudaMemcpyToSymbol(target, source, count, offset, direction) // This automatically selects the correct CUDA arch and expands the intrinsic to work on arbitrary types #include #define RO_CACHE(x) __ldg(&x) -#define GET_FUNCTION_ADDR(fname) cudaMemcpyFromSymbol((void**) &host_fcn_ptr, fname, sizeof(void*)) -#define MEMCPY_FROM_SYMBOL(target, source, count, offset, direction) cudaMemcpyFromSymbol(target, source, count, offset, direction) +#define GET_FUNCTION_ADDR(fname) cudaMemcpyFromSymbol((void **)&host_fcn_ptr, fname, sizeof(void *)) +#define MEMCPY_FROM_SYMBOL(target, source, count, offset, direction) \ + cudaMemcpyFromSymbol(target, source, count, offset, direction) // For CUDA case, just use existing errors, renamed -#include // Needed for cudaError_t +#include // Needed for cudaError_t -enum gooError {gooSuccess = cudaSuccess, - gooErrorMemoryAllocation = cudaErrorMemoryAllocation - }; +enum gooError { gooSuccess = cudaSuccess, gooErrorMemoryAllocation = cudaErrorMemoryAllocation }; #define THREADIDX (threadIdx.x) #define BLOCKDIM (blockDim.x) #define BLOCKIDX (blockIdx.x) @@ -72,8 +73,8 @@ enum gooError {gooSuccess = cudaSuccess, #endif namespace GooFit { -gooError gooMalloc(void** target, size_t bytes); -gooError gooFree(void* ptr); +gooError gooMalloc(void **target, size_t bytes); +gooError gooFree(void *ptr); #ifndef GOOFIT_SINGLES @@ -88,21 +89,23 @@ typedef float fptype; #define invRootPi 0.5641895835477563f #endif - } // Often faster than pow, and works with ints on CUDA<8 -#define POW2(x) ((x)*(x)) -#define POW3(x) ((x)*(x)*(x)) +#define POW2(x) ((x) * (x)) +#define POW3(x) ((x) * (x) * (x)) #if !defined(__CUDA_ARCH__) || (__CUDA_ARCH__ < 350) template -T rsqrt(T val) {return 1.0/sqrt(val);} +T rsqrt(T val) { + return 1.0 / sqrt(val); +} #endif // Fix for bug in pow(double,int) for CUDA 7 and 7.5 -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA && __CUDACC_VER_MAJOR__ < 8 +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA && __CUDACC_VER_MAJOR__ < 8 template -T pow(T x, int y) {return pow(x, (T) y);} +T pow(T x, int y) { + return pow(x, (T)y); +} #endif - diff --git a/include/goofit/Log.h b/include/goofit/Log.h index 5ac6163ef..362e2e9a4 100644 --- a/include/goofit/Log.h +++ b/include/goofit/Log.h @@ -7,25 +7,89 @@ namespace GooFit { - -#define GOOFIT_INFO(...) {std::cout << GooFit::reset << GooFit::blue; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_INFO_F(...) {std::cout << GooFit::reset << GooFit::blue; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_INFO_C(color, ...) {std::cout << GooFit::reset << color; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_INFO_FC(color, ...) {std::cout << GooFit::reset << color; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_STATUS(...) {std::cout << GooFit::reset << GooFit::magenta; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_STATUS_F(...) {std::cout << GooFit::reset << GooFit::magenta; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_WARN(...) {std::cout << GooFit::reset << GooFit::yellow << GooFit::bold; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_WARN_F(...) {std::cout << GooFit::reset << GooFit::yellow << GooFit::bold; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_ERROR(...) {std::cout << GooFit::reset << GooFit::red << GooFit::bold; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_ERROR_F(...) {std::cout << GooFit::reset << GooFit::red << GooFit::bold; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} +#define GOOFIT_INFO(...) \ + { \ + std::cout << GooFit::reset << GooFit::blue; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_INFO_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::blue; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_INFO_C(color, ...) \ + { \ + std::cout << GooFit::reset << color; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_INFO_FC(color, ...) \ + { \ + std::cout << GooFit::reset << color; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_STATUS(...) \ + { \ + std::cout << GooFit::reset << GooFit::magenta; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_STATUS_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::magenta; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_WARN(...) \ + { \ + std::cout << GooFit::reset << GooFit::yellow << GooFit::bold; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_WARN_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::yellow << GooFit::bold; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_ERROR(...) \ + { \ + std::cout << GooFit::reset << GooFit::red << GooFit::bold; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_ERROR_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::red << GooFit::bold; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } #ifdef GOOFIT_DEBUG_FLAG #ifndef __CUDA_ARCH__ -#define GOOFIT_DEBUG(...) {std::cout << GooFit::reset << GooFit::cyan << GooFit::bold << "DEBUG: "; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_DEBUG_F(...) {std::cout << GooFit::reset << GooFit::cyan << GooFit::bold << "DEBUG: "; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} +#define GOOFIT_DEBUG(...) \ + { \ + std::cout << GooFit::reset << GooFit::cyan << GooFit::bold << "DEBUG: "; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_DEBUG_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::cyan << GooFit::bold << "DEBUG: "; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } #else #define GOOFIT_DEBUG(...) -#define GOOFIT_DEBUG_F(...) {if (blockId.x == 0 && blockId.y == 0 && threadId.x == 0 && threadId.y == 0) {printf(__VA_ARGS__);}} +#define GOOFIT_DEBUG_F(...) \ + { \ + if(blockId.x == 0 && blockId.y == 0 && threadId.x == 0 && threadId.y == 0) { \ + printf(__VA_ARGS__); \ + } \ + } #endif #else #define GOOFIT_DEBUG(...) @@ -33,11 +97,26 @@ namespace GooFit { #endif #ifdef GOOFIT_TRACE_FLAG #ifndef __CUDA_ARCH__ -#define GOOFIT_TRACE(...) {std::cout << GooFit::reset << GooFit::cyan << "TRACE: "; fmt::print(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} -#define GOOFIT_TRACE_F(...) {std::cout << GooFit::reset << GooFit::cyan << "TRACE: "; fmt::printf(__VA_ARGS__); std::cout << GooFit::reset << std::endl;} +#define GOOFIT_TRACE(...) \ + { \ + std::cout << GooFit::reset << GooFit::cyan << "TRACE: "; \ + fmt::print(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } +#define GOOFIT_TRACE_F(...) \ + { \ + std::cout << GooFit::reset << GooFit::cyan << "TRACE: "; \ + fmt::printf(__VA_ARGS__); \ + std::cout << GooFit::reset << std::endl; \ + } #else #define GOOFIT_TRACE(...) -#define GOOFIT_TRACE_F(...) {if (blockId.x == 0 && blockId.y == 0 && threadId.x == 0 && threadId.y == 0) {printf(__VA_ARGS__);}} +#define GOOFIT_TRACE_F(...) \ + { \ + if(blockId.x == 0 && blockId.y == 0 && threadId.x == 0 && threadId.y == 0) { \ + printf(__VA_ARGS__); \ + } \ + } #endif #else #define GOOFIT_TRACE(...) @@ -45,4 +124,3 @@ namespace GooFit { #endif } // namespace GooFit - diff --git a/include/goofit/PDFs/GooPdf.h b/include/goofit/PDFs/GooPdf.h index ad01e8772..e7a940a00 100644 --- a/include/goofit/PDFs/GooPdf.h +++ b/include/goofit/PDFs/GooPdf.h @@ -12,7 +12,6 @@ class TH1D; namespace GooFit { - // TODO: Replace this with class MetricTaker; // And fill in the .cu files where needed @@ -21,7 +20,8 @@ namespace GooFit { /// Holds device-side fit parameters. extern __constant__ fptype cudaArray[maxParams]; -/// Holds functor-specific indices into cudaArray. Also overloaded to hold integer constants (ie parameters that cannot vary.) +/// Holds functor-specific indices into cudaArray. Also overloaded to hold integer constants (ie parameters that cannot +/// vary.) extern __constant__ unsigned int paramIndices[maxParams]; /// Holds non-integer constants. Notice that first entry is number of events. @@ -29,81 +29,72 @@ extern __constant__ fptype functorConstants[maxParams]; extern __constant__ fptype normalisationFactors[maxParams]; -extern __device__ void* device_function_table[200]; -extern void* host_function_table[200]; +extern __device__ void *device_function_table[200]; +extern void *host_function_table[200]; extern unsigned int num_device_functions; -extern std::map functionAddressToDeviceIndexMap; +extern std::map functionAddressToDeviceIndexMap; #endif - -__device__ int dev_powi(int base, int exp); // Implemented in SmoothHistogramPdf. -void* getMetricPointer(std::string name); +__device__ int dev_powi(int base, int exp); // Implemented in SmoothHistogramPdf. +void *getMetricPointer(std::string name); /// Pass event, parameters, index into parameters. -typedef fptype(*device_function_ptr)(fptype*, fptype*, unsigned int*); +typedef fptype (*device_function_ptr)(fptype *, fptype *, unsigned int *); -typedef fptype(*device_metric_ptr)(fptype, fptype*, unsigned int); +typedef fptype (*device_metric_ptr)(fptype, fptype *, unsigned int); -extern void* host_fcn_ptr; - -__device__ fptype callFunction(fptype* eventAddress, unsigned int functionIdx, unsigned int paramIdx); +extern void *host_fcn_ptr; +__device__ fptype callFunction(fptype *eventAddress, unsigned int functionIdx, unsigned int paramIdx); class GooPdf : public PdfBase { -public: - - GooPdf(Variable* x, std::string n); + public: + GooPdf(Variable *x, std::string n); __host__ double calculateNLL() const override; - + /// NB: This does not project correctly in multidimensional datasets, because all observables /// other than 'var' will have, for every event, whatever value they happened to get set to last /// time they were set. This is likely to be the value from the last event in whatever dataset /// you were fitting to, but at any rate you don't get the probability-weighted integral over /// the other observables. - __host__ std::vector evaluateAtPoints(Variable* var); + __host__ std::vector evaluateAtPoints(Variable *var); /// A normalize function. This fills in the host_normalize __host__ fptype normalize() const override; - + /// Just in case you are British and the previous spelling is offensive - __host__ fptype normalise() const {return normalize();} - - __host__ virtual fptype integrate(fptype lo, fptype hi) const { - return 0; - } - __host__ bool hasAnalyticIntegral() const override { - return false; - } + __host__ fptype normalise() const { return normalize(); } + + __host__ virtual fptype integrate(fptype lo, fptype hi) const { return 0; } + __host__ bool hasAnalyticIntegral() const override { return false; } __host__ fptype getValue(); - + /// Produce a list of probabilies at points __host__ std::vector> getCompProbsAtDataPoints(); - + /// Set an equidistant grid based on the stored variable binning __host__ UnbinnedDataSet makeGrid(); - - __host__ void initialize(std::vector pindices, void* dev_functionPtr = host_fcn_ptr); - __host__ void scan(Variable* var, std::vector& values); - __host__ void setFitControl(FitControl* const fc, bool takeOwnerShip = true) override; + + __host__ void initialize(std::vector pindices, void *dev_functionPtr = host_fcn_ptr); + __host__ void scan(Variable *var, std::vector &values); + __host__ void setFitControl(FitControl *const fc, bool takeOwnerShip = true) override; __host__ virtual void setMetrics(); __host__ void setParameterConstantness(bool constant = true); - __host__ virtual void transformGrid(fptype* host_output); - static __host__ int findFunctionIdx(void* dev_functionPtr); + __host__ virtual void transformGrid(fptype *host_output); + static __host__ int findFunctionIdx(void *dev_functionPtr); __host__ void setDebugMask(int mask, bool setSpecific = true) const; - + #ifdef ROOT_FOUND /// Plot a PDF to a ROOT histogram - __host__ TH1D* plotToROOT(Variable* var, double normFactor=1, std::string name=""); + __host__ TH1D *plotToROOT(Variable *var, double normFactor = 1, std::string name = ""); #endif -protected: + protected: __host__ virtual double sumOfNll(int numVars) const; - MetricTaker* logger; -private: + MetricTaker *logger; + private: }; - } // namespace GooFit - diff --git a/include/goofit/PDFs/MetricTaker.h b/include/goofit/PDFs/MetricTaker.h index 7c86b4237..da0c037aa 100644 --- a/include/goofit/PDFs/MetricTaker.h +++ b/include/goofit/PDFs/MetricTaker.h @@ -6,41 +6,33 @@ namespace GooFit { - - // Notice that operators are distinguished by the order of the operands, // and not otherwise! It's up to the user to make his tuples correctly. -class MetricTaker : public thrust::unary_function, fptype> { -public: - - MetricTaker(PdfBase* dat, void* dev_functionPtr); +class MetricTaker : public thrust::unary_function, fptype> { + public: + MetricTaker(PdfBase *dat, void *dev_functionPtr); MetricTaker(int fIdx, int pIdx); /// Main operator: Calls the PDF to get a predicted value, then the metric /// to get the goodness-of-prediction number which is returned to MINUIT. /// /// Event number, dev_event_array (pass this way for nvcc reasons), event size - __device__ fptype operator()(thrust::tuple t) const; + __device__ fptype operator()(thrust::tuple t) const; /// Operator for binned evaluation, no metric. /// Used in normalisation. /// /// Event number, event size, normalisation ranges (for binned stuff, eg integration) - __device__ fptype operator()(thrust::tuple t) const; - -private: + __device__ fptype operator()(thrust::tuple t) const; + private: /// Function-pointer index of processing function, eg logarithm, chi-square, other metric. unsigned int metricIndex; - + /// Function-pointer index of actual PDF unsigned int functionIdx; - - unsigned int parameters; - + unsigned int parameters; }; - } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/ArgusPdf.h b/include/goofit/PDFs/basic/ArgusPdf.h index 7a57de786..1fd18fe41 100644 --- a/include/goofit/PDFs/basic/ArgusPdf.h +++ b/include/goofit/PDFs/basic/ArgusPdf.h @@ -4,18 +4,13 @@ namespace GooFit { - class ArgusPdf : public GooPdf { -public: - ArgusPdf(std::string n, Variable* _x, Variable* m, Variable* s, bool upper, Variable* power = nullptr); - __host__ bool hasAnalyticIntegral() const override { - return false; - } + public: + ArgusPdf(std::string n, Variable *_x, Variable *m, Variable *s, bool upper, Variable *power = nullptr); + __host__ bool hasAnalyticIntegral() const override { return false; } __host__ fptype integrate(fptype lo, fptype hi) const override; -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/BWPdf.h b/include/goofit/PDFs/basic/BWPdf.h index 62bd47d5a..c5c7e4c3e 100644 --- a/include/goofit/PDFs/basic/BWPdf.h +++ b/include/goofit/PDFs/basic/BWPdf.h @@ -4,13 +4,10 @@ namespace GooFit { - class BWPdf : public GooPdf { + public: + BWPdf(std::string n, Variable *_x, Variable *m, Variable *s); -public: - BWPdf(std::string n, Variable* _x, Variable* m, Variable* s); -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/BifurGaussPdf.h b/include/goofit/PDFs/basic/BifurGaussPdf.h index 69d78ab4d..c76bbde04 100644 --- a/include/goofit/PDFs/basic/BifurGaussPdf.h +++ b/include/goofit/PDFs/basic/BifurGaussPdf.h @@ -4,16 +4,13 @@ namespace GooFit { - class BifurGaussPdf : public GooPdf { -public: - BifurGaussPdf(std::string n, Variable* _x, Variable* m, Variable* sL, Variable* sR); + public: + BifurGaussPdf(std::string n, Variable *_x, Variable *m, Variable *sL, Variable *sR); __host__ fptype integrate(fptype lo, fptype hi) const override; //__host__ virtual bool hasAnalyticIntegral () const {return true;} -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/BinTransformPdf.h b/include/goofit/PDFs/basic/BinTransformPdf.h index b227c6eaf..12ed14e5a 100644 --- a/include/goofit/PDFs/basic/BinTransformPdf.h +++ b/include/goofit/PDFs/basic/BinTransformPdf.h @@ -4,18 +4,15 @@ namespace GooFit { - // Transforms ND coordinates into a single bin number. class BinTransformPdf : public GooPdf { -public: + public: BinTransformPdf(std::string n, - std::vector obses, + std::vector obses, std::vector limits, std::vector binSizes, std::vector numBins); -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/CorrGaussianPdf.h b/include/goofit/PDFs/basic/CorrGaussianPdf.h index 0ff953030..c49a2a479 100644 --- a/include/goofit/PDFs/basic/CorrGaussianPdf.h +++ b/include/goofit/PDFs/basic/CorrGaussianPdf.h @@ -4,16 +4,18 @@ namespace GooFit { - class CorrGaussianPdf : public GooPdf { -public: - CorrGaussianPdf(std::string n, Variable* _x, Variable* _y, Variable* mean1, Variable* sigma1, Variable* mean2, - Variable* sigma2, Variable* correlation); - - -private: - + public: + CorrGaussianPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *mean1, + Variable *sigma1, + Variable *mean2, + Variable *sigma2, + Variable *correlation); + + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/CrystalBallPdf.h b/include/goofit/PDFs/basic/CrystalBallPdf.h index f6ae201ec..fbbf0ba9c 100644 --- a/include/goofit/PDFs/basic/CrystalBallPdf.h +++ b/include/goofit/PDFs/basic/CrystalBallPdf.h @@ -4,16 +4,12 @@ namespace GooFit { - class CrystalBallPdf : public GooPdf { -public: - CrystalBallPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* a, Variable* power = nullptr); + public: + CrystalBallPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *a, Variable *power = nullptr); __host__ fptype integrate(fptype lo, fptype hi) const override; //__host__ virtual bool hasAnalyticIntegral () const {return true;} - -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/ExpGausPdf.h b/include/goofit/PDFs/basic/ExpGausPdf.h index a22c35e50..a197de029 100644 --- a/include/goofit/PDFs/basic/ExpGausPdf.h +++ b/include/goofit/PDFs/basic/ExpGausPdf.h @@ -4,13 +4,10 @@ namespace GooFit { - class ExpGausPdf : public GooPdf { -public: - ExpGausPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* t); - -private: + public: + ExpGausPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *t); + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/ExpPdf.h b/include/goofit/PDFs/basic/ExpPdf.h index 017884894..c7f7d4702 100644 --- a/include/goofit/PDFs/basic/ExpPdf.h +++ b/include/goofit/PDFs/basic/ExpPdf.h @@ -4,20 +4,13 @@ namespace GooFit { - class ExpPdf : public GooPdf { -public: - ExpPdf(std::string n, Variable* _x, Variable* alpha, Variable* offset = nullptr); - ExpPdf(std::string n, Variable* _x, std::vector& weights, Variable* offset = nullptr); + public: + ExpPdf(std::string n, Variable *_x, Variable *alpha, Variable *offset = nullptr); + ExpPdf(std::string n, Variable *_x, std::vector &weights, Variable *offset = nullptr); __host__ fptype integrate(fptype lo, fptype hi) const override; - __host__ bool hasAnalyticIntegral() const override { - return (1 == host_indices[parameters]); - } - - - -private: + __host__ bool hasAnalyticIntegral() const override { return (1 == host_indices[parameters]); } + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/GaussianPdf.h b/include/goofit/PDFs/basic/GaussianPdf.h index a2889628d..91e247470 100644 --- a/include/goofit/PDFs/basic/GaussianPdf.h +++ b/include/goofit/PDFs/basic/GaussianPdf.h @@ -4,19 +4,12 @@ namespace GooFit { - class GaussianPdf : public GooPdf { -public: - GaussianPdf(std::string n, Variable* _x, Variable* m, Variable* s); + public: + GaussianPdf(std::string n, Variable *_x, Variable *m, Variable *s); __host__ fptype integrate(fptype lo, fptype hi) const override; - __host__ bool hasAnalyticIntegral() const override { - return true; - } - - - -private: + __host__ bool hasAnalyticIntegral() const override { return true; } + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/InterHistPdf.h b/include/goofit/PDFs/basic/InterHistPdf.h index aff2f863d..c5c9e5603 100644 --- a/include/goofit/PDFs/basic/InterHistPdf.h +++ b/include/goofit/PDFs/basic/InterHistPdf.h @@ -1,26 +1,21 @@ #pragma once -#include "goofit/PDFs/GooPdf.h" #include "goofit/BinnedDataSet.h" +#include "goofit/PDFs/GooPdf.h" #include namespace GooFit { - class InterHistPdf : public GooPdf { -public: - InterHistPdf(std::string n, - BinnedDataSet* x, - std::vector params, - std::vector obses); + public: + InterHistPdf(std::string n, BinnedDataSet *x, std::vector params, std::vector obses); //__host__ virtual fptype normalize () const; -private: - thrust::device_vector* dev_base_histogram; + private: + thrust::device_vector *dev_base_histogram; fptype totalEvents; - fptype* host_constants; + fptype *host_constants; int numVars; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/JohnsonSUPdf.h b/include/goofit/PDFs/basic/JohnsonSUPdf.h index 4c4460a58..a89cbd6f9 100644 --- a/include/goofit/PDFs/basic/JohnsonSUPdf.h +++ b/include/goofit/PDFs/basic/JohnsonSUPdf.h @@ -4,19 +4,12 @@ namespace GooFit { - class JohnsonSUPdf : public GooPdf { -public: - JohnsonSUPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* g, Variable* d); + public: + JohnsonSUPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *g, Variable *d); __host__ fptype integrate(fptype lo, fptype hi) const override; - __host__ bool hasAnalyticIntegral() const override { - return true; - } - - - -private: + __host__ bool hasAnalyticIntegral() const override { return true; } + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/KinLimitBWPdf.h b/include/goofit/PDFs/basic/KinLimitBWPdf.h index c9f5ddc76..6b5399414 100644 --- a/include/goofit/PDFs/basic/KinLimitBWPdf.h +++ b/include/goofit/PDFs/basic/KinLimitBWPdf.h @@ -4,18 +4,12 @@ namespace GooFit { - class KinLimitBWPdf : public GooPdf { - -public: - KinLimitBWPdf(std::string n, Variable* _x, Variable* m, Variable* s); - __host__ bool hasAnalyticIntegral() const override { - return false; - } + public: + KinLimitBWPdf(std::string n, Variable *_x, Variable *m, Variable *s); + __host__ bool hasAnalyticIntegral() const override { return false; } __host__ void setMasses(fptype bigM, fptype smallM); -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/LandauPdf.h b/include/goofit/PDFs/basic/LandauPdf.h index 0934c4154..1119c2ff4 100644 --- a/include/goofit/PDFs/basic/LandauPdf.h +++ b/include/goofit/PDFs/basic/LandauPdf.h @@ -4,13 +4,10 @@ namespace GooFit { - class LandauPdf : public GooPdf { -public: - LandauPdf(std::string n, Variable* _x, Variable* mpv, Variable* sigma); - -private: + public: + LandauPdf(std::string n, Variable *_x, Variable *mpv, Variable *sigma); + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/NovosibirskPdf.h b/include/goofit/PDFs/basic/NovosibirskPdf.h index a0d9ee8b4..feec53217 100644 --- a/include/goofit/PDFs/basic/NovosibirskPdf.h +++ b/include/goofit/PDFs/basic/NovosibirskPdf.h @@ -4,13 +4,10 @@ namespace GooFit { - class NovosibirskPdf : public GooPdf { -public: - NovosibirskPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* t); - -private: + public: + NovosibirskPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *t); + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/PolynomialPdf.h b/include/goofit/PDFs/basic/PolynomialPdf.h index 7e8d626b0..82fb59dc6 100644 --- a/include/goofit/PDFs/basic/PolynomialPdf.h +++ b/include/goofit/PDFs/basic/PolynomialPdf.h @@ -4,20 +4,23 @@ namespace GooFit { - class PolynomialPdf : public GooPdf { -public: - PolynomialPdf(std::string n, Variable* _x, std::vector weights, Variable* x0 = nullptr, + public: + PolynomialPdf(std::string n, + Variable *_x, + std::vector weights, + Variable *x0 = nullptr, unsigned int lowestDegree = 0); - PolynomialPdf(std::string n, std::vector obses, std::vector coeffs, std::vector offsets, + PolynomialPdf(std::string n, + std::vector obses, + std::vector coeffs, + std::vector offsets, unsigned int maxDegree); __host__ fptype integrate(fptype lo, fptype hi) const override; //__host__ virtual bool hasAnalyticIntegral () const {return (1 == observables.size());} __host__ fptype getCoefficient(int coef) const; - -private: - Variable* center; + private: + Variable *center; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/ScaledGaussianPdf.h b/include/goofit/PDFs/basic/ScaledGaussianPdf.h index 9709d9768..f0cad131c 100644 --- a/include/goofit/PDFs/basic/ScaledGaussianPdf.h +++ b/include/goofit/PDFs/basic/ScaledGaussianPdf.h @@ -4,18 +4,11 @@ namespace GooFit { - class ScaledGaussianPdf : public GooPdf { -public: - ScaledGaussianPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* d, Variable* e); - __host__ bool hasAnalyticIntegral() const override { - return false; - } - - - -private: + public: + ScaledGaussianPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *d, Variable *e); + __host__ bool hasAnalyticIntegral() const override { return false; } + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/SmoothHistogramPdf.h b/include/goofit/PDFs/basic/SmoothHistogramPdf.h index 759b147d8..fe242a157 100644 --- a/include/goofit/PDFs/basic/SmoothHistogramPdf.h +++ b/include/goofit/PDFs/basic/SmoothHistogramPdf.h @@ -1,30 +1,26 @@ #pragma once -#include "goofit/PDFs/GooPdf.h" #include "goofit/BinnedDataSet.h" +#include "goofit/PDFs/GooPdf.h" #include #include namespace GooFit { - class SmoothHistogramPdf : public GooPdf { -public: - SmoothHistogramPdf(std::string n, BinnedDataSet* x, Variable* smoothing); + public: + SmoothHistogramPdf(std::string n, BinnedDataSet *x, Variable *smoothing); __host__ fptype normalize() const override; - __host__ void extractHistogram(thrust::host_vector& host_hist) { - host_hist = *dev_base_histogram; - } - __host__ void copyHistogramToDevice(thrust::host_vector& host_histogram); + __host__ void extractHistogram(thrust::host_vector &host_hist) { host_hist = *dev_base_histogram; } + __host__ void copyHistogramToDevice(thrust::host_vector &host_histogram); -private: - thrust::device_vector* dev_base_histogram; - thrust::device_vector* dev_smoothed_histogram; + private: + thrust::device_vector *dev_base_histogram; + thrust::device_vector *dev_smoothed_histogram; fptype totalEvents; - fptype* host_constants; + fptype *host_constants; static unsigned int totalHistograms; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/StepPdf.h b/include/goofit/PDFs/basic/StepPdf.h index 0511c17ff..5953e8302 100644 --- a/include/goofit/PDFs/basic/StepPdf.h +++ b/include/goofit/PDFs/basic/StepPdf.h @@ -4,19 +4,12 @@ namespace GooFit { - class StepPdf : public GooPdf { -public: - StepPdf(std::string n, Variable* _x, Variable* x0); + public: + StepPdf(std::string n, Variable *_x, Variable *x0); __host__ fptype integrate(fptype lo, fptype hi) const override; - __host__ bool hasAnalyticIntegral() const override { - return true; - } - - - -private: + __host__ bool hasAnalyticIntegral() const override { return true; } + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/TrigThresholdPdf.h b/include/goofit/PDFs/basic/TrigThresholdPdf.h index 3dd70f125..be9322607 100644 --- a/include/goofit/PDFs/basic/TrigThresholdPdf.h +++ b/include/goofit/PDFs/basic/TrigThresholdPdf.h @@ -4,16 +4,19 @@ namespace GooFit { - class TrigThresholdPdf : public GooPdf { -public: - TrigThresholdPdf(std::string n, Variable* _x, Variable* thresh, Variable* trigConst, Variable* linConst, - bool upper = true); - TrigThresholdPdf(std::string n, Variable* _x, Variable* _y, Variable* thresh, Variable* trigConst, Variable* linConst, - Variable* massConstant, bool upper); - -private: + public: + TrigThresholdPdf( + std::string n, Variable *_x, Variable *thresh, Variable *trigConst, Variable *linConst, bool upper = true); + TrigThresholdPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *thresh, + Variable *trigConst, + Variable *linConst, + Variable *massConstant, + bool upper); + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/basic/VoigtianPdf.h b/include/goofit/PDFs/basic/VoigtianPdf.h index 403fe2358..b9d234a32 100644 --- a/include/goofit/PDFs/basic/VoigtianPdf.h +++ b/include/goofit/PDFs/basic/VoigtianPdf.h @@ -4,13 +4,10 @@ namespace GooFit { - class VoigtianPdf : public GooPdf { -public: - VoigtianPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* w); - -private: + public: + VoigtianPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *w); + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/AddPdf.h b/include/goofit/PDFs/combine/AddPdf.h index a42a9a2a7..1a8fb2cec 100644 --- a/include/goofit/PDFs/combine/AddPdf.h +++ b/include/goofit/PDFs/combine/AddPdf.h @@ -4,23 +4,18 @@ namespace GooFit { - class AddPdf : public GooPdf { -public: - - AddPdf(std::string n, std::vector weights, std::vector comps); - AddPdf(std::string n, Variable* frac1, PdfBase* func1, PdfBase* func2); + public: + AddPdf(std::string n, std::vector weights, std::vector comps); + AddPdf(std::string n, Variable *frac1, PdfBase *func1, PdfBase *func2); __host__ fptype normalize() const override; - __host__ bool hasAnalyticIntegral() const override { - return false; - } + __host__ bool hasAnalyticIntegral() const override { return false; } -protected: + protected: __host__ double sumOfNll(int numVars) const override; -private: + private: bool extended; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/CompositePdf.h b/include/goofit/PDFs/combine/CompositePdf.h index 80931a6df..385d21283 100644 --- a/include/goofit/PDFs/combine/CompositePdf.h +++ b/include/goofit/PDFs/combine/CompositePdf.h @@ -4,19 +4,16 @@ namespace GooFit { - // Composites of arbitrary functions, ie f(x) = h(g(x)) // for any h and g. In principle we should allow multi- // dimensional compositing, eg f(x, y) = i(g(x, y), h(x, y)). // Not implemented yet. class CompositePdf : public GooPdf { -public: - CompositePdf(std::string n, PdfBase* core, PdfBase* shell); // Where 'core' corresponds to 'g' and 'shell' to 'h'. + public: + CompositePdf(std::string n, PdfBase *core, PdfBase *shell); // Where 'core' corresponds to 'g' and 'shell' to 'h'. __host__ fptype normalize() const override; -private: - + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/ConvolutionPdf.h b/include/goofit/PDFs/combine/ConvolutionPdf.h index 3120146f2..2d22ddc38 100644 --- a/include/goofit/PDFs/combine/ConvolutionPdf.h +++ b/include/goofit/PDFs/combine/ConvolutionPdf.h @@ -5,27 +5,23 @@ namespace GooFit { - class ConvolutionPdf : public GooPdf { -public: - - ConvolutionPdf(std::string n, Variable* _x, GooPdf* model, GooPdf* resolution); - ConvolutionPdf(std::string n, Variable* _x, GooPdf* model, GooPdf* resolution, unsigned int numOthers); + public: + ConvolutionPdf(std::string n, Variable *_x, GooPdf *model, GooPdf *resolution); + ConvolutionPdf(std::string n, Variable *_x, GooPdf *model, GooPdf *resolution, unsigned int numOthers); __host__ fptype normalize() const override; __host__ void setIntegrationConstants(fptype lo, fptype hi, fptype step); - __host__ void registerOthers(std::vector others); + __host__ void registerOthers(std::vector others); -private: - GooPdf* model; - GooPdf* resolution; + private: + GooPdf *model; + GooPdf *resolution; - fptype* host_iConsts; - fptype* dev_iConsts; - thrust::device_vector* modelWorkSpace; - thrust::device_vector* resolWorkSpace; + fptype *host_iConsts; + fptype *dev_iConsts; + thrust::device_vector *modelWorkSpace; + thrust::device_vector *resolWorkSpace; int workSpaceIndex; - }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/EventWeightedAddPdf.h b/include/goofit/PDFs/combine/EventWeightedAddPdf.h index 4ff96ca60..6ba780129 100644 --- a/include/goofit/PDFs/combine/EventWeightedAddPdf.h +++ b/include/goofit/PDFs/combine/EventWeightedAddPdf.h @@ -4,23 +4,16 @@ namespace GooFit { - // This class is just like AddPdf except that the // event weights are properties of each event, not variables // in the fit. class EventWeightedAddPdf : public GooPdf { -public: - - EventWeightedAddPdf(std::string n, std::vector weights, std::vector comps); + public: + EventWeightedAddPdf(std::string n, std::vector weights, std::vector comps); __host__ fptype normalize() const override; - __host__ bool hasAnalyticIntegral() const override { - return false; - } - -protected: - -private: + __host__ bool hasAnalyticIntegral() const override { return false; } + protected: + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/MappedPdf.h b/include/goofit/PDFs/combine/MappedPdf.h index 84e3cd2eb..f2f077bc7 100644 --- a/include/goofit/PDFs/combine/MappedPdf.h +++ b/include/goofit/PDFs/combine/MappedPdf.h @@ -4,14 +4,12 @@ namespace GooFit { - class MappedPdf : public GooPdf { -public: - MappedPdf(std::string n, GooPdf* m, std::vector& t); + public: + MappedPdf(std::string n, GooPdf *m, std::vector &t); // Map function m must be custom written to correspond to order of function list t. __host__ fptype normalize() const override; -private: + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/combine/ProdPdf.h b/include/goofit/PDFs/combine/ProdPdf.h index eb0f8bd3b..1abc38bf7 100644 --- a/include/goofit/PDFs/combine/ProdPdf.h +++ b/include/goofit/PDFs/combine/ProdPdf.h @@ -4,18 +4,13 @@ namespace GooFit { - class ProdPdf : public GooPdf { -public: - - ProdPdf(std::string n, std::vector comps); + public: + ProdPdf(std::string n, std::vector comps); __host__ fptype normalize() const override; - __host__ bool hasAnalyticIntegral() const override { - return false; - } + __host__ bool hasAnalyticIntegral() const override { return false; } -private: + private: bool varOverlaps; // True if any components share an observable. }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/DP4Pdf.h b/include/goofit/PDFs/physics/DP4Pdf.h index 0ebf3f64c..2be5b06a3 100644 --- a/include/goofit/PDFs/physics/DP4Pdf.h +++ b/include/goofit/PDFs/physics/DP4Pdf.h @@ -17,8 +17,6 @@ See *.cu file for more details namespace GooFit { - - #ifdef SEPARABLE extern __constant__ unsigned int AmpIndices[500]; #endif @@ -28,11 +26,12 @@ class AmpCalc; class SFCalculator; class NormIntegrator; - - class DPPdf : public GooPdf { -public: - DPPdf(std::string n, std::vector observables, DecayInfo_DP* decay, GooPdf* eff, + public: + DPPdf(std::string n, + std::vector observables, + DecayInfo_DP *decay, + GooPdf *eff, unsigned int MCeventsNorm = 5e6); // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the // coherent sum. The caching method requires that it be done this way or the ProdPdf @@ -40,31 +39,24 @@ class DPPdf : public GooPdf { __host__ fptype normalize() const override; __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 6); - __host__ void setForceIntegrals(bool f = true) { - forceRedoIntegrals = f; - } - __host__ int getMCevents() { - return MCevents; - } - __host__ void setGenerationOffset(int off) { - generation_offset = off; - } - __host__ std::tuple - GenerateSig(unsigned int numEvents); - -protected: - -private: - + __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; } + __host__ int getMCevents() { return MCevents; } + __host__ void setGenerationOffset(int off) { generation_offset = off; } + __host__ std:: + tuple + GenerateSig(unsigned int numEvents); + + protected: + private: std::map, std::vector>> AmpMap; std::map compMap; // std::map massmap; std::map SpinMap; - std::vector SpinFactors; - std::vector AmpCalcs; - NormIntegrator* Integrator; - std::vector sfcalculators; - std::vector lscalculators; + std::vector SpinFactors; + std::vector AmpCalcs; + NormIntegrator *Integrator; + std::vector sfcalculators; + std::vector lscalculators; // store normalization events mcbooster::RealVector_d norm_M12; @@ -73,104 +65,103 @@ class DPPdf : public GooPdf { mcbooster::RealVector_d norm_CosTheta34; mcbooster::RealVector_d norm_phi; - //store spin and lineshape values for normalization + // store spin and lineshape values for normalization mutable mcbooster::RealVector_d norm_SF; mutable mcbooster::mc_device_vector> norm_LS; - - DecayInfo_DP* decayInfo; - std::vector _observables; + DecayInfo_DP *decayInfo; + std::vector _observables; int MCevents; // Following variables are useful if masses and widths, involved in difficult BW calculation, // change infrequently while amplitudes, only used in adding BW results together, change rapidly. - thrust::device_vector>* cachedResSF {nullptr}; // Caches the BW values and Spins for each event. - thrust::device_vector>* cachedAMPs {nullptr}; // cache Amplitude values for each event. - - mutable bool generation_no_norm {false}; - mutable bool SpinsCalculated {false}; - bool* redoIntegral; - mutable bool forceRedoIntegrals {true}; - fptype* cachedMasses; - fptype* cachedWidths; + thrust::device_vector> *cachedResSF{ + nullptr}; // Caches the BW values and Spins for each event. + thrust::device_vector> *cachedAMPs{nullptr}; // cache Amplitude values for each event. + + mutable bool generation_no_norm{false}; + mutable bool SpinsCalculated{false}; + bool *redoIntegral; + mutable bool forceRedoIntegrals{true}; + fptype *cachedMasses; + fptype *cachedWidths; int totalEventSize; - int cacheToUse {0}; - int generation_offset {0}; + int cacheToUse{0}; + int generation_offset{0}; }; - -class SFCalculator : public thrust::unary_function, thrust::complex> { -public: +class SFCalculator : public thrust::unary_function, thrust::complex> { + public: // Used to create the cached BW values. SFCalculator(int pIdx, unsigned int sf_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int _spinfactor_i; unsigned int _parameters; }; -class NormSpinCalculator : public - thrust::unary_function, fptype> { -public: +class NormSpinCalculator + : public thrust::unary_function, fptype> { + public: // Used to create the cached BW values. NormSpinCalculator(int pIdx, unsigned int sf_idx); __device__ fptype operator()(thrust::tuple t) const; -private: - + private: unsigned int _spinfactor_i; unsigned int _parameters; }; - -class LSCalculator : public thrust::unary_function, thrust::complex> { -public: +class LSCalculator : public thrust::unary_function, thrust::complex> { + public: // Used to create the cached BW values. LSCalculator(int pIdx, unsigned int res_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int _resonance_i; unsigned int _parameters; }; -class NormLSCalculator : public - thrust::unary_function, thrust::complex> { -public: +class NormLSCalculator : public thrust::unary_function, + thrust::complex> { + public: // Used to create the cached BW values. NormLSCalculator(int pIdx, unsigned int res_idx); __device__ thrust::complex operator()( - thrust::tuple t) - const; - -private: + thrust:: + tuple t) + const; + private: unsigned int _resonance_i; unsigned int _parameters; }; class AmpCalc : public thrust::unary_function> { -public: + public: AmpCalc(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm); // void setpIdx(unsigned int pIdx){_parameters = pIdx;} - __device__ thrust::complex operator()(thrust::tuple t) const; -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + + private: unsigned int _nPerm; unsigned int _AmpIdx; unsigned int _parameters; }; -class NormIntegrator : public thrust::unary_function*>, fptype > { -public: +class NormIntegrator + : public thrust::unary_function *>, fptype> { + public: NormIntegrator(unsigned int pIdx); - __device__ fptype operator()(thrust::tuple*> t) const; -private: + __device__ fptype operator()(thrust::tuple *> t) const; + + private: unsigned int _parameters; }; - - } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/DalitzPlotHelpers.h b/include/goofit/PDFs/physics/DalitzPlotHelpers.h index 34027856a..c52e089d9 100644 --- a/include/goofit/PDFs/physics/DalitzPlotHelpers.h +++ b/include/goofit/PDFs/physics/DalitzPlotHelpers.h @@ -9,38 +9,63 @@ See *.cu file for more details #pragma once #include "goofit/PDFs/GooPdf.h" -#include "goofit/PDFs/physics/ResonancePdf.h" #include "goofit/PDFs/physics/LineshapesPdf.h" +#include "goofit/PDFs/physics/ResonancePdf.h" #include #include namespace GooFit { - template constexpr typename std::underlying_type::type enum_to_underlying(E e) { return static_cast::type>(e); } -__device__ bool inDalitz(const fptype& m12, - const fptype& m13, - const fptype& bigM, - const fptype& dm1, - const fptype& dm2, - const fptype& dm3); -__device__ thrust::complex getResonanceAmplitude(fptype m12, fptype m13, fptype m23, unsigned int functionIdx, - unsigned int pIndex); -__device__ void get4Vecs(fptype* Vecs, const unsigned int& constants, const fptype& m12, const fptype& m34, - const fptype& cos12, const fptype& cos34, const fptype& phi); -__device__ fptype getmass(const unsigned int& pair, fptype& d1, fptype& d2, const fptype* vecs, const fptype& m1, - const fptype& m2, const fptype& m3, const fptype& m4); +__device__ bool inDalitz( + const fptype &m12, const fptype &m13, const fptype &bigM, const fptype &dm1, const fptype &dm2, const fptype &dm3); +__device__ thrust::complex +getResonanceAmplitude(fptype m12, fptype m13, fptype m23, unsigned int functionIdx, unsigned int pIndex); +__device__ void get4Vecs(fptype *Vecs, + const unsigned int &constants, + const fptype &m12, + const fptype &m34, + const fptype &cos12, + const fptype &cos34, + const fptype &phi); +__device__ fptype getmass(const unsigned int &pair, + fptype &d1, + fptype &d2, + const fptype *vecs, + const fptype &m1, + const fptype &m2, + const fptype &m3, + const fptype &m4); // in case of 3 particles the first two are the resonance. -enum DP4Pair {M_12 = 0, M_34, M_13, M_14, M_23, M_24, M_12_3, M_13_2, M_23_1, M_12_4, M_14_2, M_24_1, M_13_4, M_14_3, M_34_1, M_23_4, M_24_3, M_34_2}; -enum DaughterPair {PAIR_12 = 0, PAIR_13, PAIR_23}; +enum DP4Pair { + M_12 = 0, + M_34, + M_13, + M_14, + M_23, + M_24, + M_12_3, + M_13_2, + M_23_1, + M_12_4, + M_14_2, + M_24_1, + M_13_4, + M_14_3, + M_34_1, + M_23_4, + M_24_3, + M_34_2 +}; +enum DaughterPair { PAIR_12 = 0, PAIR_13, PAIR_23 }; -const int resonanceSize = 4; // Number of parameters to describe one resonance. +const int resonanceSize = 4; // Number of parameters to describe one resonance. // Why not make this a static const member of ResonancePdf? Because the 'static' // keyword (and 'extern' as well) interacts badly with some nvcc versions when the // variable is used in device code. @@ -52,30 +77,31 @@ struct DecayInfo { fptype daug3Mass; fptype meson_radius; - Variable* _tau; - Variable* _xmixing; - Variable* _ymixing; - std::vector resonances; + Variable *_tau; + Variable *_xmixing; + Variable *_ymixing; + std::vector resonances; }; struct DecayInfo_DP { - std::vector particle_masses ; + std::vector particle_masses; fptype meson_radius; - std::vector amplitudes; - std::vector amplitudes_B; + std::vector amplitudes; + std::vector amplitudes_B; - Variable* _tau; - Variable* _xmixing; - Variable* _ymixing; - Variable* _SqWStoRSrate; + Variable *_tau; + Variable *_xmixing; + Variable *_ymixing; + Variable *_SqWStoRSrate; }; // Copied from strided_range thrust example by Nathan Bell. // Iterator to move forward by a specified number of steps // in each iteration. -template class strided_range { -public: +template +class strided_range { + public: typedef typename thrust::iterator_difference::type difference_type; struct stride_functor : public thrust::unary_function { @@ -84,34 +110,31 @@ template class strided_range { stride_functor(difference_type stride) : stride(stride) {} - __host__ __device__ difference_type operator()(const difference_type& i) const { - return stride * i; - } + __host__ __device__ difference_type operator()(const difference_type &i) const { return stride * i; } }; - typedef typename thrust::counting_iterator CountingIterator; + typedef typename thrust::counting_iterator CountingIterator; typedef typename thrust::transform_iterator TransformIterator; - typedef typename thrust::permutation_iterator PermutationIterator; + typedef typename thrust::permutation_iterator PermutationIterator; // type of the strided_range iterator typedef PermutationIterator iterator; // construct strided_range for the range [first,last) strided_range(Iterator first, Iterator last, difference_type stride) - : first(first), last(last), stride(stride) {} + : first(first) + , last(last) + , stride(stride) {} iterator begin() const { return PermutationIterator(first, TransformIterator(CountingIterator(0), stride_functor(stride))); } - iterator end() const { - return begin() + ((last - first) + (stride - 1)) / stride; - } + iterator end() const { return begin() + ((last - first) + (stride - 1)) / stride; } -protected: + protected: Iterator first; Iterator last; difference_type stride; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/DalitzPlotPdf.h b/include/goofit/PDFs/physics/DalitzPlotPdf.h index c9a6112b3..1a827258b 100644 --- a/include/goofit/PDFs/physics/DalitzPlotPdf.h +++ b/include/goofit/PDFs/physics/DalitzPlotPdf.h @@ -7,70 +7,66 @@ namespace GooFit { - class SpecialResonanceIntegrator; class SpecialResonanceCalculator; class DalitzPlotPdf : public GooPdf { -public: - DalitzPlotPdf(std::string n, Variable* m12, Variable* m13, CountingVariable* eventNumber, DecayInfo* decay, - GooPdf* eff); + public: + DalitzPlotPdf( + std::string n, Variable *m12, Variable *m13, CountingVariable *eventNumber, DecayInfo *decay, GooPdf *eff); // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the // coherent sum. The caching method requires that it be done this way or the ProdPdf // normalisation will get *really* confused and give wrong answers. __host__ fptype normalize() const override; __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 3); - __host__ void setForceIntegrals(bool f = true) { - forceRedoIntegrals = f; - } - -protected: + __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; } -private: - DecayInfo* decayInfo; - Variable* _m12; - Variable* _m13; - fptype* dalitzNormRange; + protected: + private: + DecayInfo *decayInfo; + Variable *_m12; + Variable *_m13; + fptype *dalitzNormRange; // Following variables are useful if masses and widths, involved in difficult BW calculation, // change infrequently while amplitudes, only used in adding BW results together, change rapidly. - thrust::device_vector>* cachedWaves[16]; // Caches the BW values for each event. - thrust::complex*** integrals; // Caches the integrals of the BW waves for each combination of resonances. + thrust::device_vector> *cachedWaves[16]; // Caches the BW values for each event. + thrust::complex ***integrals; // Caches the integrals of the BW waves for each combination of resonances. - bool* redoIntegral; + bool *redoIntegral; mutable bool forceRedoIntegrals; - fptype* cachedMasses; - fptype* cachedWidths; + fptype *cachedMasses; + fptype *cachedWidths; int totalEventSize; int cacheToUse; - SpecialResonanceIntegrator*** integrators; - SpecialResonanceCalculator** calculators; + SpecialResonanceIntegrator ***integrators; + SpecialResonanceCalculator **calculators; }; -class SpecialResonanceIntegrator : public thrust::unary_function, thrust::complex> { -public: +class SpecialResonanceIntegrator + : public thrust::unary_function, thrust::complex> { + public: // Class used to calculate integrals of terms BW_i * BW_j^*. SpecialResonanceIntegrator(int pIdx, unsigned int ri, unsigned int rj); - __device__ thrust::complex operator()(thrust::tuple t) const; -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int resonance_i; unsigned int resonance_j; unsigned int parameters; }; -class SpecialResonanceCalculator : public thrust::unary_function, thrust::complex> { -public: +class SpecialResonanceCalculator + : public thrust::unary_function, thrust::complex> { + public: // Used to create the cached BW values. SpecialResonanceCalculator(int pIdx, unsigned int res_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int resonance_i; unsigned int parameters; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/DalitzVetoPdf.h b/include/goofit/PDFs/physics/DalitzVetoPdf.h index c95920330..726f99f26 100644 --- a/include/goofit/PDFs/physics/DalitzVetoPdf.h +++ b/include/goofit/PDFs/physics/DalitzVetoPdf.h @@ -5,20 +5,23 @@ namespace GooFit { - struct VetoInfo { DaughterPair cyclic_index; - Variable* minimum; - Variable* maximum; + Variable *minimum; + Variable *maximum; }; class DalitzVetoPdf : public GooPdf { -public: - __host__ DalitzVetoPdf(std::string n, Variable* _x, Variable* _y, Variable* motherM, Variable* d1m, Variable* d2m, - Variable* d3m, std::vector vetos); - -private: - + public: + __host__ DalitzVetoPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *motherM, + Variable *d1m, + Variable *d2m, + Variable *d3m, + std::vector vetos); + + private: }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/EvalVar.h b/include/goofit/PDFs/physics/EvalVar.h index 221aa3aa5..e294c3765 100644 --- a/include/goofit/PDFs/physics/EvalVar.h +++ b/include/goofit/PDFs/physics/EvalVar.h @@ -16,37 +16,32 @@ See *.cu file for more details namespace GooFit { - - -struct Dim5: public mcbooster::IFunctionArray { - Dim5() { - dim = 4; - } - - __host__ __device__ mcbooster::GReal_t cosHELANG(const mcbooster::Vector4R p, const mcbooster::Vector4R q, - const mcbooster::Vector4R d) { - mcbooster::GReal_t pd = p * d; - mcbooster::GReal_t pq = p * q; - mcbooster::GReal_t qd = q * d; +struct Dim5 : public mcbooster::IFunctionArray { + Dim5() { dim = 4; } + + __host__ __device__ mcbooster::GReal_t + cosHELANG(const mcbooster::Vector4R p, const mcbooster::Vector4R q, const mcbooster::Vector4R d) { + mcbooster::GReal_t pd = p * d; + mcbooster::GReal_t pq = p * q; + mcbooster::GReal_t qd = q * d; mcbooster::GReal_t mp2 = p.mass2(); mcbooster::GReal_t mq2 = q.mass2(); mcbooster::GReal_t md2 = d.mass2(); - return (pd * mq2 - pq * qd) - / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); - + return (pd * mq2 - pq * qd) / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); } - __host__ __device__ mcbooster::GReal_t phi(const mcbooster::Vector4R& p4_p, - const mcbooster::Vector4R& p4_d1, const mcbooster::Vector4R& p4_d2, const mcbooster::Vector4R& p4_h1, - const mcbooster::Vector4R& p4_h2) { - + __host__ __device__ mcbooster::GReal_t phi(const mcbooster::Vector4R &p4_p, + const mcbooster::Vector4R &p4_d1, + const mcbooster::Vector4R &p4_d2, + const mcbooster::Vector4R &p4_h1, + const mcbooster::Vector4R &p4_h2) { mcbooster::Vector4R p4_d1p, p4_h1p, p4_h2p, p4_d2p; mcbooster::Vector4R d1_perp, d1_prime, h1_perp; mcbooster::Vector4R D; - D = p4_d1 + p4_d2; + D = p4_d1 + p4_d2; mcbooster::Vector4R D2 = p4_h1 + p4_h2; d1_perp = p4_d1 - (D.dot(p4_d1) / D.dot(D)) * D; @@ -56,31 +51,30 @@ struct Dim5: public mcbooster::IFunctionArray { d1_prime = D.cross(d1_perp); - d1_perp = d1_perp / d1_perp.d3mag(); + d1_perp = d1_perp / d1_perp.d3mag(); d1_prime = d1_prime / d1_prime.d3mag(); mcbooster::GReal_t x, y; - x = d1_perp.dot(h1_perp); - y = d1_prime.dot(h1_perp); + x = d1_perp.dot(h1_perp); + y = d1_prime.dot(h1_perp); mcbooster::GReal_t phi = atan2(y, x); // printf("x:%.5g, y%.5g phi %.5g\n", x, y, phi ); if(phi < 0.0) phi += 2.0 * M_PI; - mcbooster::Vector4R d1n = p4_d1/p4_d1.d3mag(); - mcbooster::Vector4R d2n = p4_d2/p4_d2.d3mag(); - mcbooster::Vector4R h1n = p4_h1/p4_h1.d3mag(); - mcbooster::Vector4R h2n = p4_h2/p4_h2.d3mag(); - mcbooster::Vector4R h12n = (p4_h1+p4_h2); - h12n*=1.0/h12n.d3mag(); - + mcbooster::Vector4R d1n = p4_d1 / p4_d1.d3mag(); + mcbooster::Vector4R d2n = p4_d2 / p4_d2.d3mag(); + mcbooster::Vector4R h1n = p4_h1 / p4_h1.d3mag(); + mcbooster::Vector4R h2n = p4_h2 / p4_h2.d3mag(); + mcbooster::Vector4R h12n = (p4_h1 + p4_h2); + h12n *= 1.0 / h12n.d3mag(); mcbooster::Vector4R n1 = d1n.cross(d2n); mcbooster::Vector4R n2 = h1n.cross(h2n); - n1 *= 1.0/n1.d3mag(); - n2 *= 1.0/n2.d3mag(); + n1 *= 1.0 / n1.d3mag(); + n2 *= 1.0 / n2.d3mag(); mcbooster::Vector4R n3 = n1.cross(n2); mcbooster::GReal_t cp = (n1.dot(n2)); @@ -88,28 +82,24 @@ struct Dim5: public mcbooster::IFunctionArray { mcbooster::GReal_t phi2 = acos(cp); - if(sp <0) + if(sp < 0) phi2 *= -1; // printf("cp %.5g, sp %.5g, phi2 %.5g\n",cp, sp, phi2 ); - - return phi2; - } - __host__ __device__ - void operator()(const mcbooster::GInt_t n, mcbooster::Vector4R** particles, mcbooster::GReal_t* variables) override { - mcbooster::Vector4R ppip = *particles[0]; - mcbooster::Vector4R ppim = *particles[1]; - mcbooster::Vector4R pK = *particles[2]; - mcbooster::Vector4R ppip2 = *particles[3]; + __host__ __device__ void + operator()(const mcbooster::GInt_t n, mcbooster::Vector4R **particles, mcbooster::GReal_t *variables) override { + mcbooster::Vector4R ppip = *particles[0]; + mcbooster::Vector4R ppim = *particles[1]; + mcbooster::Vector4R pK = *particles[2]; + mcbooster::Vector4R ppip2 = *particles[3]; - mcbooster::Vector4R pM = ppip + ppim + pK + ppip2; + mcbooster::Vector4R pM = ppip + ppim + pK + ppip2; mcbooster::Vector4R ppipi = ppip + ppim; - mcbooster::Vector4R pKpi = pK + ppip2; - + mcbooster::Vector4R pKpi = pK + ppip2; variables[0] = ppipi.mass(); variables[1] = pKpi.mass(); @@ -120,4 +110,3 @@ struct Dim5: public mcbooster::IFunctionArray { }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/IncoherentSumPdf.h b/include/goofit/PDFs/physics/IncoherentSumPdf.h index 95e747444..d645e120e 100644 --- a/include/goofit/PDFs/physics/IncoherentSumPdf.h +++ b/include/goofit/PDFs/physics/IncoherentSumPdf.h @@ -6,7 +6,6 @@ namespace GooFit { - // Very similar class to TddpPdf, but without time dependence // (so no time resolution or mixing) and ignoring interference between // waves. This makes the code just different enough, the assumptions are @@ -14,70 +13,62 @@ namespace GooFit { // TddpPdf to deal with both cases. So instead we have a separate // class with fairly similar structure. - class SpecialIncoherentIntegrator; class SpecialIncoherentResonanceCalculator; class IncoherentSumPdf : public GooPdf { -public: - IncoherentSumPdf(std::string n, Variable* m12, Variable* m13, CountingVariable* eventNumber, DecayInfo* decay, - GooPdf* eff); + public: + IncoherentSumPdf( + std::string n, Variable *m12, Variable *m13, CountingVariable *eventNumber, DecayInfo *decay, GooPdf *eff); // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the // incoherent sum. The caching method requires that it be done this way or the ProdPdf // normalisation will get *really* confused and give wrong answers. __host__ fptype normalize() const override; __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 3); - __host__ void setForceIntegrals(bool f = true) { - forceRedoIntegrals = f; - } + __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; } -protected: - -private: - DecayInfo* decayInfo; - Variable* _m12; - Variable* _m13; - fptype* dalitzNormRange; + protected: + private: + DecayInfo *decayInfo; + Variable *_m12; + Variable *_m13; + fptype *dalitzNormRange; // Following variables are useful if masses and widths, involved in difficult BW calculation, // change infrequently while amplitudes, only used in adding BW results together, change rapidly. - thrust::device_vector>* cachedResonances; // BW (and other) results for each event. - double* integrals; // Integrals of each BW resonance across the Daliz plot. + thrust::device_vector> *cachedResonances; // BW (and other) results for each event. + double *integrals; // Integrals of each BW resonance across the Daliz plot. - bool* redoIntegral; + bool *redoIntegral; mutable bool forceRedoIntegrals; - fptype* cachedMasses; - fptype* cachedWidths; + fptype *cachedMasses; + fptype *cachedWidths; int totalEventSize; int cacheToUse; - PdfBase* efficiency; - SpecialIncoherentIntegrator** integrators; - SpecialIncoherentResonanceCalculator** calculators; + PdfBase *efficiency; + SpecialIncoherentIntegrator **integrators; + SpecialIncoherentResonanceCalculator **calculators; }; -class SpecialIncoherentIntegrator : public thrust::unary_function, fptype > { -public: +class SpecialIncoherentIntegrator : public thrust::unary_function, fptype> { + public: SpecialIncoherentIntegrator(int pIdx, unsigned int ri); - __device__ fptype operator()(thrust::tuple t) const; + __device__ fptype operator()(thrust::tuple t) const; -private: + private: unsigned int resonance_i; unsigned int parameters; }; -class SpecialIncoherentResonanceCalculator : public - thrust::unary_function, thrust::complex> { -public: - +class SpecialIncoherentResonanceCalculator + : public thrust::unary_function, thrust::complex> { + public: SpecialIncoherentResonanceCalculator(int pIdx, unsigned int res_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int resonance_i; unsigned int parameters; }; - } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/LineshapesPdf.h b/include/goofit/PDFs/physics/LineshapesPdf.h index c58ed565c..d370596e5 100644 --- a/include/goofit/PDFs/physics/LineshapesPdf.h +++ b/include/goofit/PDFs/physics/LineshapesPdf.h @@ -16,12 +16,11 @@ See *.cu file for more details namespace GooFit { - class SpinFactor; -enum class LS {ONE, BW, Lass, Lass_M3, nonRes, Bugg, Bugg3, Flatte, SBW}; -//PDG notation for FF -enum class FF : unsigned int {One = 0, BL, BL_Prime, BL2}; +enum class LS { ONE, BW, Lass, Lass_M3, nonRes, Bugg, Bugg3, Flatte, SBW }; +// PDG notation for FF +enum class FF : unsigned int { One = 0, BL, BL_Prime, BL2 }; class Lineshape : public GooPdf { friend class DPPdf; @@ -32,61 +31,67 @@ class Lineshape : public GooPdf { // component in one of the friend classes. It extends // GooPdf so as to take advantage of the // infrastructure, but will crash if used on its own. - Variable* _mass; - Variable* _width; + Variable *_mass; + Variable *_width; unsigned int _L; unsigned int _Mpair; LS _kind; FF _FormFac; fptype _radius; - std::vector _AdditionalVars; -public: + std::vector _AdditionalVars; + + public: Lineshape(std::string name, - Variable* mass, - Variable* width, + Variable *mass, + Variable *width, unsigned int L, unsigned int Mpair, - LS kind = LS::BW, - FF FormFac = FF::BL_Prime, - fptype radius = 1.5, - std::vector AdditionalVars = std::vector()); + LS kind = LS::BW, + FF FormFac = FF::BL_Prime, + fptype radius = 1.5, + std::vector AdditionalVars = std::vector()); - bool operator==(const Lineshape& L) const { + bool operator==(const Lineshape &L) const { if(_AdditionalVars.size() != L._AdditionalVars.size()) return false; bool addvar = true; for(int i = 0; i < _AdditionalVars.size(); ++i) { - addvar = addvar and (L._AdditionalVars[i]->getValue() == _AdditionalVars[i]->getValue()); + addvar = addvar and (L._AdditionalVars[i]->getValue() == _AdditionalVars[i]->getValue()); } - return addvar and (L.getName() == getName() and L._mass->getValue() == _mass->getValue() and L._width->getValue() == _width->getValue() - and L._L == _L and L._Mpair == _Mpair and L._kind == _kind and L._FormFac == _FormFac); + return addvar and (L.getName() == getName() and L._mass->getValue() == _mass->getValue() + and L._width->getValue() == _width->getValue() + and L._L == _L + and L._Mpair == _Mpair + and L._kind == _kind + and L._FormFac == _FormFac); } Lineshape(std::string name); - void setConstantIndex(unsigned int idx) { - host_indices[parameters + 1] = idx; - } + void setConstantIndex(unsigned int idx) { host_indices[parameters + 1] = idx; } }; class Amplitude { friend class DPPdf; friend class TDDP4; + public: + Amplitude(std::string uniqueDecayStr, + Variable *ar, + Variable *ai, + std::vector LS, + std::vector SF, + unsigned int nPerm = 1); + bool operator==(const Amplitude &A) const; -public: - Amplitude(std::string uniqueDecayStr, Variable* ar, Variable* ai, std::vector LS, - std::vector SF, unsigned int nPerm = 1); - bool operator==(const Amplitude& A) const; -private: + private: std::string _uniqueDecayStr; - Variable* _ar; - Variable* _ai; - std::vector _SF; - std::vector _LS; + Variable *_ar; + Variable *_ai; + std::vector _SF; + std::vector _LS; unsigned int _nPerm; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/MixingTimeResolution_Aux.h b/include/goofit/PDFs/physics/MixingTimeResolution_Aux.h index 862e5c7c9..c21805f46 100644 --- a/include/goofit/PDFs/physics/MixingTimeResolution_Aux.h +++ b/include/goofit/PDFs/physics/MixingTimeResolution_Aux.h @@ -5,33 +5,26 @@ namespace GooFit { - -typedef fptype(*device_resfunction_ptr)(fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype*, - unsigned int*); -typedef fptype(*device_calc_tau_fcn_ptr)(fptype, fptype, fptype, fptype, fptype, fptype, fptype); +typedef fptype (*device_resfunction_ptr)( + fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype, fptype *, unsigned int *); +typedef fptype (*device_calc_tau_fcn_ptr)(fptype, fptype, fptype, fptype, fptype, fptype, fptype); class MixingTimeResolution { -public: + public: MixingTimeResolution(); ~MixingTimeResolution(); - void initIndex(void* dev_fcn_ptr = host_fcn_ptr); + void initIndex(void *dev_fcn_ptr = host_fcn_ptr); + + virtual fptype + normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, fptype ymixing) const = 0; + virtual void createParameters(std::vector &pindices, PdfBase *dis) = 0; + int getDeviceFunction() const { return resFunctionIdx; } + int getCalcTauIdx() const { return resCalcTauFcnIdx; } + void setCalcTauIdx(int idx) { resCalcTauFcnIdx = idx; } - virtual fptype normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, - fptype ymixing) const = 0; - virtual void createParameters(std::vector& pindices, PdfBase* dis) = 0; - int getDeviceFunction() const { - return resFunctionIdx; - } - int getCalcTauIdx() const { - return resCalcTauFcnIdx; - } - void setCalcTauIdx(int idx) { - resCalcTauFcnIdx = idx; - } -private: + private: int resFunctionIdx; int resCalcTauFcnIdx; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/ResonancePdf.h b/include/goofit/PDFs/physics/ResonancePdf.h index 62e17b2bd..3374819b4 100644 --- a/include/goofit/PDFs/physics/ResonancePdf.h +++ b/include/goofit/PDFs/physics/ResonancePdf.h @@ -5,15 +5,21 @@ namespace GooFit { - -typedef thrust::complex (*resonance_function_ptr)(fptype, fptype, fptype, unsigned int*); +typedef thrust::complex (*resonance_function_ptr)(fptype, fptype, fptype, unsigned int *); __device__ fptype twoBodyCMmom(double rMassSq, fptype d1m, fptype d2m); -__device__ fptype dampingFactorSquare(const fptype& cmmom, const int& spin, const fptype& mRadius); +__device__ fptype dampingFactorSquare(const fptype &cmmom, const int &spin, const fptype &mRadius); -__device__ fptype spinFactor(unsigned int spin, fptype motherMass, fptype daug1Mass, fptype daug2Mass, - fptype daug3Mass, fptype m12, fptype m13, fptype m23, unsigned int cyclic_index); +__device__ fptype spinFactor(unsigned int spin, + fptype motherMass, + fptype daug1Mass, + fptype daug2Mass, + fptype daug3Mass, + fptype m12, + fptype m13, + fptype m23, + unsigned int cyclic_index); class ResonancePdf : public GooPdf { // Service class intended to hold parametrisations of @@ -26,55 +32,46 @@ class ResonancePdf : public GooPdf { friend class TddpPdf; friend class DalitzPlotPdf; friend class IncoherentSumPdf; -public: + + public: // Constructor for regular BW ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mass, - Variable* width, + Variable *ar, + Variable *ai, + Variable *mass, + Variable *width, unsigned int sp, unsigned int cyc); // Gounaris-Sakurai ResonancePdf(std::string name, - Variable* ar, - Variable* ai, + Variable *ar, + Variable *ai, unsigned int sp, - Variable* mass, - Variable* width, + Variable *mass, + Variable *width, unsigned int cyc); // LASS constructor ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mass, + Variable *ar, + Variable *ai, + Variable *mass, unsigned int sp, - Variable* width, + Variable *width, unsigned int cyc); - // Nonresonant constructor - ResonancePdf(std::string name, - Variable* ar, - Variable* ai); + ResonancePdf(std::string name, Variable *ar, Variable *ai); // Gaussian constructor - ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mean, - Variable* sigma, - unsigned int cyc); + ResonancePdf(std::string name, Variable *ar, Variable *ai, Variable *mean, Variable *sigma, unsigned int cyc); -private: - void setConstantIndex(unsigned int idx) { - host_indices[parameters + 1] = idx; - } + private: + void setConstantIndex(unsigned int idx) { host_indices[parameters + 1] = idx; } - Variable* amp_real; - Variable* amp_imag; + Variable *amp_real; + Variable *amp_imag; /* Variable* mass; Variable* width; @@ -86,4 +83,3 @@ class ResonancePdf : public GooPdf { }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/SpinFactors.h b/include/goofit/PDFs/physics/SpinFactors.h index 7d871fee1..2e8f63916 100644 --- a/include/goofit/PDFs/physics/SpinFactors.h +++ b/include/goofit/PDFs/physics/SpinFactors.h @@ -12,8 +12,7 @@ See *.cu file for more details namespace GooFit { - -typedef fptype(*spin_function_ptr)(fptype*, unsigned int*); +typedef fptype (*spin_function_ptr)(fptype *, unsigned int *); enum class SF_4Body { DtoPP1_PtoSP2_StoP3P4, @@ -36,20 +35,20 @@ enum class SF_4Body { class SpinFactor : public GooPdf { friend class DPPdf; -private: + + private: SF_4Body _SF; unsigned int _P0; unsigned int _P1; unsigned int _P2; unsigned int _P3; -public: + + public: SpinFactor(std::string name, SF_4Body SF, unsigned int P0, unsigned int P1, unsigned int P2, unsigned int P3); - void setConstantIndex(unsigned int idx) { - host_indices[parameters + 1] = idx; - } - bool operator==(const SpinFactor& S) const { - return (S.getName() == getName() and S._SF == _SF and S._P0 == _P0 and S._P1 == _P1 and S._P2 == _P2 and S._P3 == _P3); + void setConstantIndex(unsigned int idx) { host_indices[parameters + 1] = idx; } + bool operator==(const SpinFactor &S) const { + return (S.getName() == getName() and S._SF == _SF and S._P0 == _P0 and S._P1 == _P1 and S._P2 == _P2 + and S._P3 == _P3); } }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/SpinHelper.h b/include/goofit/PDFs/physics/SpinHelper.h index b9a561bf9..cda369352 100644 --- a/include/goofit/PDFs/physics/SpinHelper.h +++ b/include/goofit/PDFs/physics/SpinHelper.h @@ -12,152 +12,108 @@ This code is not sufficently tested yet and still under heavy development! namespace GooFit { - class __align__(16) gpuLVec { -private: + private: fptype X; fptype Y; fptype Z; fptype E; -public: - __device__ gpuLVec() { - X=Y=Z=E=0; - }; - __device__ gpuLVec(fptype x, fptype y, fptype z, fptype e) : X(x), Y(y), Z(z), E(e) {}; - - __device__ void SetXYZE(fptype x, fptype y, fptype z, fptype e) { - X=x; - Y=y; - Z=z; - E=e; - } - - __device__ fptype Dot(const gpuLVec& rhs) const { - return E*rhs.E - X*rhs.X - Y*rhs.Y - Z*rhs.Z ; - } - __device__ inline fptype GetX() const { - return X; - } - __device__ inline fptype GetY() const { - return Y; - } - __device__ inline fptype GetZ() const { - return Z; - } - __device__ inline fptype GetE() const { - return E; - } - __device__ inline fptype Mag2() const { - return this->Dot(*this); - } - __device__ inline fptype M() const { - return sqrt(this->Mag2()); - } - __device__ inline void SetX(fptype a) { - X=a; - } - __device__ inline void SetY(fptype a) { - Y=a; - } - __device__ inline void SetZ(fptype a) { - Z=a; - } - __device__ inline void SetE(fptype a) { - E=a; - } - - __device__ gpuLVec& operator+=(const gpuLVec& rhs) { - X+=rhs.X; - Y+=rhs.Y; - Z+=rhs.Z; - E+=rhs.E; + public: + __device__ gpuLVec() { X = Y = Z = E = 0; }; + __device__ gpuLVec(fptype x, fptype y, fptype z, fptype e) + : X(x) + , Y(y) + , Z(z) + , E(e){}; + + __device__ void SetXYZE(fptype x, fptype y, fptype z, fptype e) { + X = x; + Y = y; + Z = z; + E = e; + } + + __device__ fptype Dot(const gpuLVec &rhs) const { return E * rhs.E - X * rhs.X - Y * rhs.Y - Z * rhs.Z; } + __device__ inline fptype GetX() const { return X; } + __device__ inline fptype GetY() const { return Y; } + __device__ inline fptype GetZ() const { return Z; } + __device__ inline fptype GetE() const { return E; } + + __device__ inline fptype Mag2() const { return this->Dot(*this); } + __device__ inline fptype M() const { return sqrt(this->Mag2()); } + __device__ inline void SetX(fptype a) { X = a; } + __device__ inline void SetY(fptype a) { Y = a; } + __device__ inline void SetZ(fptype a) { Z = a; } + __device__ inline void SetE(fptype a) { E = a; } + + __device__ gpuLVec &operator+=(const gpuLVec &rhs) { + X += rhs.X; + Y += rhs.Y; + Z += rhs.Z; + E += rhs.E; return *this; } - __device__ gpuLVec& operator-=(const gpuLVec& rhs) { - X-=rhs.X; - Y-=rhs.Y; - Z-=rhs.Z; - E-=rhs.E; + __device__ gpuLVec &operator-=(const gpuLVec &rhs) { + X -= rhs.X; + Y -= rhs.Y; + Z -= rhs.Z; + E -= rhs.E; return *this; } - __device__ gpuLVec& operator*=(const fptype rhs) { - X*=rhs; - Y*=rhs; - Z*=rhs; - E*=rhs; + __device__ gpuLVec &operator*=(const fptype rhs) { + X *= rhs; + Y *= rhs; + Z *= rhs; + E *= rhs; return *this; } }; -__device__ gpuLVec operator+(gpuLVec lhs, const gpuLVec& rhs) { - return lhs+=rhs; -} -__device__ gpuLVec operator-(gpuLVec lhs, const gpuLVec& rhs) { - return lhs-=rhs; -} -__device__ gpuLVec operator*(gpuLVec lhs, fptype rhs) { - return lhs*=rhs; -} -__device__ gpuLVec operator*(fptype lhs, gpuLVec rhs) { - return rhs*=lhs; -} - +__device__ gpuLVec operator+(gpuLVec lhs, const gpuLVec &rhs) { return lhs += rhs; } +__device__ gpuLVec operator-(gpuLVec lhs, const gpuLVec &rhs) { return lhs -= rhs; } +__device__ gpuLVec operator*(gpuLVec lhs, fptype rhs) { return lhs *= rhs; } +__device__ gpuLVec operator*(fptype lhs, gpuLVec rhs) { return rhs *= lhs; } class ZTspin1 : public gpuLVec { -public: + public: // in decay D -> AB: q = p(A) - p(B), p = p(A) + p(B) - __device__ ZTspin1(const gpuLVec& q, const gpuLVec& p, fptype mR) - : gpuLVec(q - q.Dot(p)*p * (1./(mR*mR))) {} + __device__ ZTspin1(const gpuLVec &q, const gpuLVec &p, fptype mR) + : gpuLVec(q - q.Dot(p) * p * (1. / (mR * mR))) {} - __device__ fptype Contract(const gpuLVec& rhs) const { - return this->Dot(rhs); - } + __device__ fptype Contract(const gpuLVec &rhs) const { return this->Dot(rhs); } }; class SpinSumV { // spin sum for Vector->PP -protected: + protected: gpuLVec _p; // pA + pB (pA, pB are the 4-mom of dgtrs) - fptype _mR; // nominal mass of resonance. -public: - __device__ SpinSumV(const gpuLVec& p, fptype mR) + fptype _mR; // nominal mass of resonance. + public: + __device__ SpinSumV(const gpuLVec &p, fptype mR) : _p(p) - , _mR(mR) - {} - - __device__ gpuLVec Dot(const gpuLVec& rhs) const { - return -1.0 * rhs + _p * (_p.Dot(rhs) / (_mR*_mR)); - } - __device__ fptype Sandwich(const gpuLVec& lhs - , const gpuLVec& rhs) const { - return lhs.Dot(this->Dot(rhs)); - } + , _mR(mR) {} + __device__ gpuLVec Dot(const gpuLVec &rhs) const { return -1.0 * rhs + _p * (_p.Dot(rhs) / (_mR * _mR)); } + __device__ fptype Sandwich(const gpuLVec &lhs, const gpuLVec &rhs) const { return lhs.Dot(this->Dot(rhs)); } }; class SpinSumT { -protected: + protected: SpinSumV _sv; -public: - __device__ SpinSumT(const gpuLVec& p, fptype mR) - : _sv(p, mR) - {} - __device__ fptype Sandwich(const gpuLVec& lm - , const gpuLVec& ln - , const gpuLVec& ra - , const gpuLVec& rb - ) { + public: + __device__ SpinSumT(const gpuLVec &p, fptype mR) + : _sv(p, mR) {} + __device__ fptype Sandwich(const gpuLVec &lm, const gpuLVec &ln, const gpuLVec &ra, const gpuLVec &rb) { fptype manb = _sv.Sandwich(lm, ra) * _sv.Sandwich(ln, rb); fptype mbna = _sv.Sandwich(lm, rb) * _sv.Sandwich(ln, ra); fptype mnab = _sv.Sandwich(lm, ln) * _sv.Sandwich(ra, rb); - return (1./2.)*(manb + mbna) - (1./3.)*mnab; + return (1. / 2.) * (manb + mbna) - (1. / 3.) * mnab; } }; - class LorentzMatrix { -protected: + protected: gpuLVec _v[4]; // we'll follow the x, y, z, E convention, i.e. E is 4 __device__ bool makeZero() { @@ -167,121 +123,92 @@ class LorentzMatrix { E().SetXYZE(0, 0, 0, 0); return true; } -public: - __device__ const gpuLVec& v(int i) const { - return _v[i]; - } - __device__ LorentzMatrix() = default;; + public: + __device__ const gpuLVec &v(int i) const { return _v[i]; } + + __device__ LorentzMatrix() = default; + ; __device__ LorentzMatrix(const gpuLVec p[4]) { - for(int i=0; i<4; i++) + for(int i = 0; i < 4; i++) _v[i] = p[i]; } - __device__ LorentzMatrix(const LorentzMatrix& other) { - for(int i=0; i<4; i++) + __device__ LorentzMatrix(const LorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] = other._v[i]; } - __device__ const gpuLVec& X() const { - return _v[0]; - } - __device__ const gpuLVec& Y() const { - return _v[1]; - } - __device__ const gpuLVec& Z() const { - return _v[2]; - } - __device__ const gpuLVec& E() const { - return _v[3]; - } + __device__ const gpuLVec &X() const { return _v[0]; } + __device__ const gpuLVec &Y() const { return _v[1]; } + __device__ const gpuLVec &Z() const { return _v[2]; } + __device__ const gpuLVec &E() const { return _v[3]; } - __device__ gpuLVec& X() { - return _v[0]; - } - __device__ gpuLVec& Y() { - return _v[1]; - } - __device__ gpuLVec& Z() { - return _v[2]; - } - __device__ gpuLVec& E() { - return _v[3]; - } + __device__ gpuLVec &X() { return _v[0]; } + __device__ gpuLVec &Y() { return _v[1]; } + __device__ gpuLVec &Z() { return _v[2]; } + __device__ gpuLVec &E() { return _v[3]; } - __device__ const gpuLVec& operator[](int i) const { - return _v[i]; - } - __device__ gpuLVec& operator[](int i) { - return _v[i]; - } + __device__ const gpuLVec &operator[](int i) const { return _v[i]; } + __device__ gpuLVec &operator[](int i) { return _v[i]; } - __device__ LorentzMatrix& add(const LorentzMatrix& other) { - for(int i=0; i < 4; i++) + __device__ LorentzMatrix &add(const LorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] += other._v[i]; return *this; } - __device__ LorentzMatrix& subtract(const LorentzMatrix& other) { - for(int i=0; i < 4; i++) + __device__ LorentzMatrix &subtract(const LorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] -= other._v[i]; return *this; } - __device__ LorentzMatrix& mult(fptype s) { - for(auto & i : _v) + __device__ LorentzMatrix &mult(fptype s) { + for(auto &i : _v) i *= s; return *this; } - __device__ LorentzMatrix& div(fptype s) { - for(auto & i : _v) - i *= (1./s); + __device__ LorentzMatrix &div(fptype s) { + for(auto &i : _v) + i *= (1. / s); return *this; } - __device__ LorentzMatrix& operator+=(const LorentzMatrix& rhs) { - return add(rhs); - } - __device__ LorentzMatrix& operator*=(fptype rhs) { - return mult(rhs); - } - __device__ LorentzMatrix& operator-=(const LorentzMatrix& rhs) { - return subtract(rhs); - } - __device__ LorentzMatrix& operator/=(fptype rhs) { - return div(rhs); - } - __device__ LorentzMatrix& operator=(const LorentzMatrix& other) { - for(int i=0; i<4; i++) + __device__ LorentzMatrix &operator+=(const LorentzMatrix &rhs) { return add(rhs); } + __device__ LorentzMatrix &operator*=(fptype rhs) { return mult(rhs); } + __device__ LorentzMatrix &operator-=(const LorentzMatrix &rhs) { return subtract(rhs); } + __device__ LorentzMatrix &operator/=(fptype rhs) { return div(rhs); } + __device__ LorentzMatrix &operator=(const LorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] = other._v[i]; return *this; } - __device__ LorentzMatrix operator+(const LorentzMatrix& rhs)const { + __device__ LorentzMatrix operator+(const LorentzMatrix &rhs) const { LorentzMatrix returnVal(*this); returnVal += rhs; return returnVal; } - __device__ LorentzMatrix operator-(const LorentzMatrix& rhs)const { + __device__ LorentzMatrix operator-(const LorentzMatrix &rhs) const { LorentzMatrix returnVal(*this); returnVal -= rhs; return returnVal; } - __device__ LorentzMatrix operator*(fptype rhs)const { + __device__ LorentzMatrix operator*(fptype rhs) const { LorentzMatrix returnVal(*this); returnVal *= rhs; return returnVal; } - __device__ LorentzMatrix operator/(fptype rhs)const { + __device__ LorentzMatrix operator/(fptype rhs) const { LorentzMatrix returnVal(*this); returnVal /= rhs; return returnVal; } - }; class SymmLorentzMatrix : public LorentzMatrix { -protected: + protected: // SymmLorentzMatrix __gmunu; // we'll follow the x, y, z, E convention, i.e. E is 4 @@ -311,17 +238,19 @@ class SymmLorentzMatrix : public LorentzMatrix { E().SetXYZE(0, 0, 0, 0); return true; } -public: + + public: __device__ void makeGmunu() { X().SetXYZE(-1, 0, 0, 0); Y().SetXYZE(0, -1, 0, 0); Z().SetXYZE(0, 0, -1, 0); E().SetXYZE(0, 0, 0, 1); } - __device__ const SymmLorentzMatrix& gmunu(); - __device__ SymmLorentzMatrix(): LorentzMatrix() {} + __device__ const SymmLorentzMatrix &gmunu(); + __device__ SymmLorentzMatrix() + : LorentzMatrix() {} __device__ SymmLorentzMatrix(const gpuLVec p[4]) - : LorentzMatrix(p) {}; + : LorentzMatrix(p){}; __device__ SymmLorentzMatrix(const gpuLVec p) { X().SetX(p.GetX() * p.GetX()); @@ -344,52 +273,52 @@ class SymmLorentzMatrix : public LorentzMatrix { E().SetZ(p.GetE() * p.GetZ()); E().SetE(p.GetE() * p.GetE()); } - __device__ SymmLorentzMatrix(const SymmLorentzMatrix& other) = default; + __device__ SymmLorentzMatrix(const SymmLorentzMatrix &other) = default; - __device__ SymmLorentzMatrix& add(const SymmLorentzMatrix& other) { - for(int i=0; i < 4; i++) + __device__ SymmLorentzMatrix &add(const SymmLorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] += other._v[i]; return *this; } - __device__ SymmLorentzMatrix& subtract(const SymmLorentzMatrix& other) { - for(int i=0; i < 4; i++) + __device__ SymmLorentzMatrix &subtract(const SymmLorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] -= other._v[i]; return *this; } - __device__ SymmLorentzMatrix& mult(fptype s) { - for(auto & i : _v) + __device__ SymmLorentzMatrix &mult(fptype s) { + for(auto &i : _v) i *= s; return *this; } - __device__ SymmLorentzMatrix& div(fptype s) { - for(auto & i : _v) - i *= (1./s); + __device__ SymmLorentzMatrix &div(fptype s) { + for(auto &i : _v) + i *= (1. / s); return *this; } - __device__ gpuLVec Contract(const gpuLVec& vec) { + __device__ gpuLVec Contract(const gpuLVec &vec) { // M^{mu nu} g_{nu alpha} v^{alpha} // M^{mu nu} v_{alpha} - return vec.GetE()*E() - vec.GetX()*X() - vec.GetY()*Y() -vec.GetZ()*Z(); + return vec.GetE() * E() - vec.GetX() * X() - vec.GetY() * Y() - vec.GetZ() * Z(); } - __device__ LorentzMatrix Contract_1(const SymmLorentzMatrix& M) { + __device__ LorentzMatrix Contract_1(const SymmLorentzMatrix &M) { // One pair of indices gets contracted. Since // both matrices are symmetric, it doesnt matter which. // // O^{mu alpha} g_{alpha beta} M^{beta nu} = R^{mu nu} // O^{mu alpha} M_{beta}^{nu} LorentzMatrix R; - R.X() = this->Contract(M.X()); - R.Y() = this->Contract(M.Y()); - R.Z() = this->Contract(M.Z()); - R.E() = this->Contract(M.E()); // signs? + R.X() = this->Contract(M.X()); + R.Y() = this->Contract(M.Y()); + R.Z() = this->Contract(M.Z()); + R.E() = this->Contract(M.E()); // signs? return R; } - __device__ fptype Contract_2(const SymmLorentzMatrix& M) { + __device__ fptype Contract_2(const SymmLorentzMatrix &M) { // Both pairs of indices are contracted. // since the matrices are symmetric, it does // not matter which index from this with which form M. @@ -397,74 +326,64 @@ class SymmLorentzMatrix : public LorentzMatrix { // O^{mu alpha} g_{alpha beta} M^{beta nu} g_{mu nu} LorentzMatrix R(Contract_1(M)); // R^{mu nu} R_{mu nu} - fptype xx = R.X().GetX();//Dot(R.X()); - fptype yy = R.Y().GetY();//Dot(R.Y()); - fptype zz = R.Z().GetZ();//Dot(R.Z()); - fptype tt = R.E().GetE();//Dot(R.E()); + fptype xx = R.X().GetX(); // Dot(R.X()); + fptype yy = R.Y().GetY(); // Dot(R.Y()); + fptype zz = R.Z().GetZ(); // Dot(R.Z()); + fptype tt = R.E().GetE(); // Dot(R.E()); return tt - xx - yy - zz; // signs? } - __device__ SymmLorentzMatrix& operator+=(const SymmLorentzMatrix& rhs) { - return add(rhs); - } - __device__ SymmLorentzMatrix& operator*=(fptype rhs) { - return mult(rhs); - } - __device__ SymmLorentzMatrix& operator-=(const SymmLorentzMatrix& rhs) { - return subtract(rhs); - } - __device__ SymmLorentzMatrix& operator/=(fptype rhs) { - return div(rhs); - } - __device__ SymmLorentzMatrix& operator=(const SymmLorentzMatrix& other) { - for(int i=0; i<4; i++) + __device__ SymmLorentzMatrix &operator+=(const SymmLorentzMatrix &rhs) { return add(rhs); } + __device__ SymmLorentzMatrix &operator*=(fptype rhs) { return mult(rhs); } + __device__ SymmLorentzMatrix &operator-=(const SymmLorentzMatrix &rhs) { return subtract(rhs); } + __device__ SymmLorentzMatrix &operator/=(fptype rhs) { return div(rhs); } + __device__ SymmLorentzMatrix &operator=(const SymmLorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] = other._v[i]; return *this; } - __device__ SymmLorentzMatrix operator+(const SymmLorentzMatrix& rhs)const { + __device__ SymmLorentzMatrix operator+(const SymmLorentzMatrix &rhs) const { SymmLorentzMatrix returnVal(*this); returnVal += rhs; return returnVal; } - __device__ SymmLorentzMatrix operator-(const SymmLorentzMatrix& rhs)const { + __device__ SymmLorentzMatrix operator-(const SymmLorentzMatrix &rhs) const { SymmLorentzMatrix returnVal(*this); returnVal -= rhs; return returnVal; } - __device__ SymmLorentzMatrix operator*(fptype rhs)const { + __device__ SymmLorentzMatrix operator*(fptype rhs) const { SymmLorentzMatrix returnVal(*this); returnVal *= rhs; return returnVal; } - __device__ SymmLorentzMatrix operator/(fptype rhs)const { + __device__ SymmLorentzMatrix operator/(fptype rhs) const { SymmLorentzMatrix returnVal(*this); returnVal /= rhs; return returnVal; } - }; // __device__ SymmLorentzMatrix operator*(fptype lhs, const SymmLorentzMatrix& rhs); // __device__ SymmLorentzMatrix operator/(fptype lhs, const SymmLorentzMatrix& rhs); -__device__ SymmLorentzMatrix operator*(fptype lhs, const SymmLorentzMatrix& rhs) { +__device__ SymmLorentzMatrix operator*(fptype lhs, const SymmLorentzMatrix &rhs) { SymmLorentzMatrix returnVal(rhs); returnVal *= lhs; return returnVal; } -__device__ SymmLorentzMatrix operator/(fptype lhs, const SymmLorentzMatrix& rhs) { +__device__ SymmLorentzMatrix operator/(fptype lhs, const SymmLorentzMatrix &rhs) { SymmLorentzMatrix returnVal(rhs); returnVal /= lhs; return returnVal; } - class ZTspin2 : public SymmLorentzMatrix { -public: + public: // in decay D -> AB: q = p(A) - p(B), p = p(A) + p(B) - __device__ ZTspin2(const gpuLVec& q, const gpuLVec& p, fptype mR) { + __device__ ZTspin2(const gpuLVec &q, const gpuLVec &p, fptype mR) { ZTspin1 t(q, p, mR); SymmLorentzMatrix tt(t); SymmLorentzMatrix uu(p); @@ -472,41 +391,38 @@ class ZTspin2 : public SymmLorentzMatrix { auto gmunu = SymmLorentzMatrix(); gmunu.makeGmunu(); // printf("%f %f %f %f\n",gmunu.X().GetX(), gmunu.Y().GetY(), gmunu.Z().GetZ(), gmunu.E().GetE() ); - *this = tt - (1./3.) * t.Mag2()*(gmunu - uu); + *this = tt - (1. / 3.) * t.Mag2() * (gmunu - uu); // eq 6 in PhysRevD.51.2247 } - __device__ ZTspin2& operator=(const SymmLorentzMatrix& other) { - for(int i=0; i<4; i++) + __device__ ZTspin2 &operator=(const SymmLorentzMatrix &other) { + for(int i = 0; i < 4; i++) _v[i] = other.v(i); return *this; } - }; -__device__ fptype LeviCivita(const gpuLVec& p1, const gpuLVec& p2, const gpuLVec& p3, const gpuLVec& p4) { +__device__ fptype LeviCivita(const gpuLVec &p1, const gpuLVec &p2, const gpuLVec &p3, const gpuLVec &p4) { // this calculates the determinant of the 4x4 matrix build out of p1,p2,p3,p4 - return - p1.GetZ() * p2.GetY() * p3.GetX() * p4.GetE() - p1.GetY() * p2.GetZ() * p3.GetX() * p4.GetE() - - p1.GetZ() * p2.GetX() * p3.GetY() * p4.GetE() + p1.GetX() * p2.GetZ() * p3.GetY() * p4.GetE() + - p1.GetY() * p2.GetX() * p3.GetZ() * p4.GetE() - p1.GetX() * p2.GetY() * p3.GetZ() * p4.GetE() - - p1.GetZ() * p2.GetY() * p3.GetE() * p4.GetX() + p1.GetY() * p2.GetZ() * p3.GetE() * p4.GetX() + - p1.GetZ() * p2.GetE() * p3.GetY() * p4.GetX() - p1.GetE() * p2.GetZ() * p3.GetY() * p4.GetX() - - p1.GetY() * p2.GetE() * p3.GetZ() * p4.GetX() + p1.GetE() * p2.GetY() * p3.GetZ() * p4.GetX() + - p1.GetZ() * p2.GetX() * p3.GetE() * p4.GetY() - p1.GetX() * p2.GetZ() * p3.GetE() * p4.GetY() - - p1.GetZ() * p2.GetE() * p3.GetX() * p4.GetY() + p1.GetE() * p2.GetZ() * p3.GetX() * p4.GetY() + - p1.GetX() * p2.GetE() * p3.GetZ() * p4.GetY() - p1.GetE() * p2.GetX() * p3.GetZ() * p4.GetY() - - p1.GetY() * p2.GetX() * p3.GetE() * p4.GetZ() + p1.GetX() * p2.GetY() * p3.GetE() * p4.GetZ() + - p1.GetY() * p2.GetE() * p3.GetX() * p4.GetZ() - p1.GetE() * p2.GetY() * p3.GetX() * p4.GetZ() - - p1.GetX() * p2.GetE() * p3.GetY() * p4.GetZ() + p1.GetE() * p2.GetX() * p3.GetY() * p4.GetZ(); + return p1.GetZ() * p2.GetY() * p3.GetX() * p4.GetE() - p1.GetY() * p2.GetZ() * p3.GetX() * p4.GetE() + - p1.GetZ() * p2.GetX() * p3.GetY() * p4.GetE() + p1.GetX() * p2.GetZ() * p3.GetY() * p4.GetE() + + p1.GetY() * p2.GetX() * p3.GetZ() * p4.GetE() - p1.GetX() * p2.GetY() * p3.GetZ() * p4.GetE() + - p1.GetZ() * p2.GetY() * p3.GetE() * p4.GetX() + p1.GetY() * p2.GetZ() * p3.GetE() * p4.GetX() + + p1.GetZ() * p2.GetE() * p3.GetY() * p4.GetX() - p1.GetE() * p2.GetZ() * p3.GetY() * p4.GetX() + - p1.GetY() * p2.GetE() * p3.GetZ() * p4.GetX() + p1.GetE() * p2.GetY() * p3.GetZ() * p4.GetX() + + p1.GetZ() * p2.GetX() * p3.GetE() * p4.GetY() - p1.GetX() * p2.GetZ() * p3.GetE() * p4.GetY() + - p1.GetZ() * p2.GetE() * p3.GetX() * p4.GetY() + p1.GetE() * p2.GetZ() * p3.GetX() * p4.GetY() + + p1.GetX() * p2.GetE() * p3.GetZ() * p4.GetY() - p1.GetE() * p2.GetX() * p3.GetZ() * p4.GetY() + - p1.GetY() * p2.GetX() * p3.GetE() * p4.GetZ() + p1.GetX() * p2.GetY() * p3.GetE() * p4.GetZ() + + p1.GetY() * p2.GetE() * p3.GetX() * p4.GetZ() - p1.GetE() * p2.GetY() * p3.GetX() * p4.GetZ() + - p1.GetX() * p2.GetE() * p3.GetY() * p4.GetZ() + p1.GetE() * p2.GetX() * p3.GetY() * p4.GetZ(); } -__device__ inline gpuLVec LeviCivita(const gpuLVec& a, const gpuLVec& b, const gpuLVec& c) { - +__device__ inline gpuLVec LeviCivita(const gpuLVec &a, const gpuLVec &b, const gpuLVec &c) { gpuLVec v; - v.SetE(-1.* a.GetX() * (b.GetY() * c.GetZ() - b.GetZ() * c.GetY()) + v.SetE(-1. * a.GetX() * (b.GetY() * c.GetZ() - b.GetZ() * c.GetY()) - a.GetY() * (b.GetZ() * c.GetX() - b.GetX() * c.GetZ()) - a.GetZ() * (b.GetX() * c.GetY() - b.GetY() * c.GetX())); @@ -522,8 +438,7 @@ __device__ inline gpuLVec LeviCivita(const gpuLVec& a, const gpuLVec& b, const g + a.GetZ() * (b.GetY() * c.GetE() - b.GetE() * c.GetY()) + a.GetE() * (b.GetZ() * c.GetY() - b.GetY() * c.GetZ())); - return v; + return v; } } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/Tddp4Pdf.h b/include/goofit/PDFs/physics/Tddp4Pdf.h index 9d675c9fc..0535da7ad 100644 --- a/include/goofit/PDFs/physics/Tddp4Pdf.h +++ b/include/goofit/PDFs/physics/Tddp4Pdf.h @@ -8,26 +8,30 @@ See *.cu file for more details #pragma once -#include -#include -#include #include "goofit/PDFs/GooPdf.h" #include "goofit/PDFs/physics/DalitzPlotHelpers.h" -#include "goofit/PDFs/physics/SpinFactors.h" #include "goofit/PDFs/physics/MixingTimeResolution_Aux.h" +#include "goofit/PDFs/physics/SpinFactors.h" +#include +#include +#include namespace GooFit { - class LSCalculator_TD; class AmpCalc_TD; class SFCalculator_TD; class NormIntegrator_TD; class TDDP4 : public GooPdf { -public: - TDDP4(std::string n, std::vector observables, DecayInfo_DP* decay, MixingTimeResolution* r, GooPdf* eff, - Variable* mistag = nullptr, unsigned int MCeventsNorm = 5e6); + public: + TDDP4(std::string n, + std::vector observables, + DecayInfo_DP *decay, + MixingTimeResolution *r, + GooPdf *eff, + Variable *mistag = nullptr, + unsigned int MCeventsNorm = 5e6); // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the // coherent sum. The caching method requires that it be done this way or the ProdPdf // normalisation will get *really* confused and give wrong answers. @@ -36,38 +40,29 @@ class TDDP4 : public GooPdf { __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 8); - __host__ void setForceIntegrals(bool f = true) { - forceRedoIntegrals = f; - } + __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; } - __host__ int getMCevents() { - return MCevents; - } + __host__ int getMCevents() { return MCevents; } - __host__ void setGenerationOffset(int off) { - generation_offset = off; - } + __host__ void setGenerationOffset(int off) { generation_offset = off; } - __host__ void setMaxWeight(fptype wmax) { - maxWeight = wmax; - } + __host__ void setMaxWeight(fptype wmax) { maxWeight = wmax; } - __host__ std::tuple - GenerateSig(unsigned int numEvents); - -protected: - -private: + __host__ std:: + tuple + GenerateSig(unsigned int numEvents); + protected: + private: std::map, std::vector>> AmpMap; std::map compMap; // std::map massmap; std::map SpinMap; - std::vector SpinFactors; - std::vector AmpCalcs; - NormIntegrator_TD* Integrator; - std::vector sfcalculators; - std::vector lscalculators; + std::vector SpinFactors; + std::vector AmpCalcs; + NormIntegrator_TD *Integrator; + std::vector sfcalculators; + std::vector lscalculators; // store normalization events mcbooster::RealVector_d norm_M12; @@ -75,117 +70,117 @@ class TDDP4 : public GooPdf { mcbooster::RealVector_d norm_CosTheta12; mcbooster::RealVector_d norm_CosTheta34; mcbooster::RealVector_d norm_phi; - //store spin and lineshape values for normalization + // store spin and lineshape values for normalization mutable mcbooster::RealVector_d norm_SF; mutable mcbooster::mc_device_vector> norm_LS; - DecayInfo_DP* decayInfo; - std::vector _observables; - MixingTimeResolution* resolution; + DecayInfo_DP *decayInfo; + std::vector _observables; + MixingTimeResolution *resolution; int MCevents; // Following variables are useful if masses and widths, involved in difficult BW calculation, // change infrequently while amplitudes, only used in adding BW results together, change rapidly. - thrust::device_vector>* cachedResSF {nullptr}; // Caches the BW values and Spins for each event. - thrust::device_vector>* cachedAMPs {nullptr}; // cache Amplitude values for each event. - mutable bool generation_no_norm {false}; - mutable bool SpinsCalculated {false}; - bool* redoIntegral; - mutable bool forceRedoIntegrals {true}; - fptype* cachedMasses; - fptype* cachedWidths; + thrust::device_vector> *cachedResSF{ + nullptr}; // Caches the BW values and Spins for each event. + thrust::device_vector> *cachedAMPs{nullptr}; // cache Amplitude values for each event. + mutable bool generation_no_norm{false}; + mutable bool SpinsCalculated{false}; + bool *redoIntegral; + mutable bool forceRedoIntegrals{true}; + fptype *cachedMasses; + fptype *cachedWidths; int totalEventSize; - int cacheToUse {0}; - unsigned int generation_offset {25031992}; + int cacheToUse{0}; + unsigned int generation_offset{25031992}; double maxWeight; }; -class SFCalculator_TD : public thrust::unary_function, thrust::complex> { -public: +class SFCalculator_TD : public thrust::unary_function, thrust::complex> { + public: // Used to create the cached BW values. SFCalculator_TD(int pIdx, unsigned int sf_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int _spinfactor_i; unsigned int _parameters; }; -class NormSpinCalculator_TD : public - thrust::unary_function, fptype> { -public: +class NormSpinCalculator_TD + : public thrust::unary_function, fptype> { + public: // Used to create the cached BW values. NormSpinCalculator_TD(int pIdx, unsigned int sf_idx); __device__ fptype operator()(thrust::tuple t) const; -private: - + private: unsigned int _spinfactor_i; unsigned int _parameters; }; - -class LSCalculator_TD : public thrust::unary_function, thrust::complex> { -public: +class LSCalculator_TD : public thrust::unary_function, thrust::complex> { + public: // Used to create the cached BW values. LSCalculator_TD(int pIdx, unsigned int res_idx); - __device__ thrust::complex operator()(thrust::tuple t) const; - -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + private: unsigned int _resonance_i; unsigned int _parameters; }; -class NormLSCalculator_TD : public - thrust::unary_function, thrust::complex> { -public: +class NormLSCalculator_TD : public thrust::unary_function, + thrust::complex> { + public: // Used to create the cached BW values. NormLSCalculator_TD(int pIdx, unsigned int res_idx); __device__ thrust::complex operator()( - thrust::tuple t) - const; - -private: + thrust:: + tuple t) + const; + private: unsigned int _resonance_i; unsigned int _parameters; }; class AmpCalc_TD : public thrust::unary_function> { -public: + public: AmpCalc_TD(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm); // void setpIdx(unsigned int pIdx){_parameters = pIdx;} - __device__ thrust::complex operator()(thrust::tuple t) const; -private: + __device__ thrust::complex operator()(thrust::tuple t) const; + + private: unsigned int _nPerm; unsigned int _AmpIdx; unsigned int _parameters; }; -class NormIntegrator_TD : public - thrust::unary_function*>, fptype > { -public: +class NormIntegrator_TD + : public thrust::unary_function *>, fptype> { + public: NormIntegrator_TD(unsigned int pIdx); - __device__ thrust::tuple operator()( - thrust::tuple*> t) const; -private: + __device__ thrust::tuple + operator()(thrust::tuple *> t) const; + + private: unsigned int _parameters; }; class FourDblTupleAdd : public thrust::binary_function, - thrust::tuple, - thrust::tuple> { - -public: - - __host__ __device__ thrust::tuple operator()( - thrust::tuple one, thrust::tuple two) { + thrust::tuple, + thrust::tuple> { + public: + __host__ __device__ thrust::tuple + operator()(thrust::tuple one, thrust::tuple two) { return thrust::tuple(thrust::get<0>(one) + thrust::get<0>(two), - thrust::get<1>(one) + thrust::get<1>(two), - thrust::get<2>(one) + thrust::get<2>(two), - thrust::get<3>(one) + thrust::get<3>(two)); + thrust::get<1>(one) + thrust::get<1>(two), + thrust::get<2>(one) + thrust::get<2>(two), + thrust::get<3>(one) + thrust::get<3>(two)); } }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/TddpPdf.h b/include/goofit/PDFs/physics/TddpPdf.h index 2e627a184..646f7f0f9 100644 --- a/include/goofit/PDFs/physics/TddpPdf.h +++ b/include/goofit/PDFs/physics/TddpPdf.h @@ -1,15 +1,14 @@ #pragma once #include "goofit/PDFs/GooPdf.h" -#include "goofit/PDFs/physics/MixingTimeResolution_Aux.h" #include "goofit/PDFs/physics/DalitzPlotHelpers.h" +#include "goofit/PDFs/physics/MixingTimeResolution_Aux.h" namespace GooFit { - -//thrust::tuple can't go down the read-only cache pipeline, so we are creating a structure for this. +// thrust::tuple can't go down the read-only cache pipeline, so we are creating a structure for this. typedef struct { - //note: combining these into a single transaction (double2) should improve memory performance + // note: combining these into a single transaction (double2) should improve memory performance fptype ai_real; fptype ai_imag; fptype bi_real; @@ -23,11 +22,28 @@ class SpecialDalitzIntegrator; class SpecialWaveCalculator; class TddpPdf : public GooPdf { -public: - TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Variable* m12, Variable* m13, CountingVariable* eventNumber, - DecayInfo* decay, MixingTimeResolution* r, GooPdf* eff, Variable* mistag = nullptr); - TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Variable* m12, Variable* m13, CountingVariable* eventNumber, - DecayInfo* decay, std::vector& r, GooPdf* eff, Variable* md0, Variable* mistag = nullptr); + public: + TddpPdf(std::string n, + Variable *_dtime, + Variable *_sigmat, + Variable *m12, + Variable *m13, + CountingVariable *eventNumber, + DecayInfo *decay, + MixingTimeResolution *r, + GooPdf *eff, + Variable *mistag = nullptr); + TddpPdf(std::string n, + Variable *_dtime, + Variable *_sigmat, + Variable *m12, + Variable *m13, + CountingVariable *eventNumber, + DecayInfo *decay, + std::vector &r, + GooPdf *eff, + Variable *md0, + Variable *mistag = nullptr); // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the // coherent sum. The caching method requires that it be done this way or the ProdPdf // normalisation will get *really* confused and give wrong answers. @@ -59,54 +75,45 @@ class TddpPdf : public GooPdf { __host__ fptype normalize() const override; __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 5); - __host__ void setForceIntegrals(bool f = true) { - forceRedoIntegrals = f; - } + __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; } -protected: - -private: - DecayInfo* decayInfo; - Variable* _m12; - Variable* _m13; - fptype* dalitzNormRange {nullptr}; + protected: + private: + DecayInfo *decayInfo; + Variable *_m12; + Variable *_m13; + fptype *dalitzNormRange{nullptr}; // Following variables are useful if masses and widths, involved in difficult BW calculation, // change infrequently while amplitudes, only used in adding BW results together, change rapidly. - thrust::device_vector* cachedWaves[16]; // Caches the BW values for each event. - ThreeComplex*** integrals {nullptr}; // Caches the integrals of the BW waves for each combination of resonances. - - bool* redoIntegral; - mutable bool forceRedoIntegrals {true}; - fptype* cachedMasses; - fptype* cachedWidths; - MixingTimeResolution* resolution; - - + thrust::device_vector *cachedWaves[16]; // Caches the BW values for each event. + ThreeComplex ***integrals{nullptr}; // Caches the integrals of the BW waves for each combination of resonances. + + bool *redoIntegral; + mutable bool forceRedoIntegrals{true}; + fptype *cachedMasses; + fptype *cachedWidths; + MixingTimeResolution *resolution; + int totalEventSize; - int cacheToUse {0}; - SpecialDalitzIntegrator*** integrators {nullptr}; - SpecialWaveCalculator** calculators {nullptr}; + int cacheToUse{0}; + SpecialDalitzIntegrator ***integrators{nullptr}; + SpecialWaveCalculator **calculators{nullptr}; }; -class SpecialDalitzIntegrator : public thrust::unary_function, ThreeComplex > { -public: - +class SpecialDalitzIntegrator : public thrust::unary_function, ThreeComplex> { + public: SpecialDalitzIntegrator(int pIdx, unsigned int ri, unsigned int rj); - __device__ ThreeComplex operator()(thrust::tuple t) const; -private: + __device__ ThreeComplex operator()(thrust::tuple t) const; + private: unsigned int resonance_i; unsigned int resonance_j; unsigned int parameters; }; -class SpecialComplexSum : public thrust::binary_function { - -public: - +class SpecialComplexSum : public thrust::binary_function { + public: __host__ __device__ ThreeComplex operator()(ThreeComplex one, ThreeComplex two) { return ThreeComplex(thrust::get<0>(one) + thrust::get<0>(two), thrust::get<1>(one) + thrust::get<1>(two), @@ -117,18 +124,14 @@ class SpecialComplexSum : public thrust::binary_function, WaveHolder_s > { -public: - +class SpecialWaveCalculator : public thrust::unary_function, WaveHolder_s> { + public: SpecialWaveCalculator(int pIdx, unsigned int res_idx); - __device__ WaveHolder_s operator()(thrust::tuple t) const; - -private: + __device__ WaveHolder_s operator()(thrust::tuple t) const; + private: unsigned int resonance_i; unsigned int parameters; }; - } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/ThreeGaussResolution_Aux.h b/include/goofit/PDFs/physics/ThreeGaussResolution_Aux.h index c5bdb9df1..04fb95b5f 100644 --- a/include/goofit/PDFs/physics/ThreeGaussResolution_Aux.h +++ b/include/goofit/PDFs/physics/ThreeGaussResolution_Aux.h @@ -4,26 +4,24 @@ namespace GooFit { - class ThreeGaussResolution : public MixingTimeResolution { -public: - ThreeGaussResolution(Variable* cf, Variable* tf, Variable* cb, Variable* cs, Variable* tb, Variable* ts, Variable* ob, - Variable* os); + public: + ThreeGaussResolution( + Variable *cf, Variable *tf, Variable *cb, Variable *cs, Variable *tb, Variable *ts, Variable *ob, Variable *os); ~ThreeGaussResolution(); - fptype normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, - fptype ymixing) const override; - void createParameters(std::vector& pindices, PdfBase* dis) override; + fptype normalisation( + fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, fptype ymixing) const override; + void createParameters(std::vector &pindices, PdfBase *dis) override; -private: - Variable* coreFraction; - Variable* tailFraction; - Variable* coreBias; - Variable* coreScaleFactor; - Variable* tailBias; - Variable* tailScaleFactor; - Variable* outBias; - Variable* outScaleFactor; + private: + Variable *coreFraction; + Variable *tailFraction; + Variable *coreBias; + Variable *coreScaleFactor; + Variable *tailBias; + Variable *tailScaleFactor; + Variable *outBias; + Variable *outScaleFactor; }; } // namespace GooFit - diff --git a/include/goofit/PDFs/physics/TruthResolution_Aux.h b/include/goofit/PDFs/physics/TruthResolution_Aux.h index a9f961b38..d8e7727e8 100644 --- a/include/goofit/PDFs/physics/TruthResolution_Aux.h +++ b/include/goofit/PDFs/physics/TruthResolution_Aux.h @@ -4,17 +4,13 @@ namespace GooFit { - class TruthResolution : public MixingTimeResolution { -public: + public: TruthResolution(); ~TruthResolution(); - fptype normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, - fptype ymixing) const override; - void createParameters(std::vector& pindices, PdfBase* dis) override { - pindices.push_back(0); - } + fptype normalisation( + fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, fptype ymixing) const override; + void createParameters(std::vector &pindices, PdfBase *dis) override { pindices.push_back(0); } }; } // namespace GooFit - diff --git a/include/goofit/PdfBase.h b/include/goofit/PdfBase.h index 277a157e1..5a40e4892 100644 --- a/include/goofit/PdfBase.h +++ b/include/goofit/PdfBase.h @@ -4,8 +4,8 @@ #include "goofit/Variable.h" #include "goofit/Version.h" -#include "goofit/detail/Abort.h" #include "goofit/Version.h" +#include "goofit/detail/Abort.h" #include #include @@ -31,7 +31,7 @@ typedef thrust::zip_iterator EventIterator; */ const int maxParams = GOOFIT_MAXPAR; -extern fptype* dev_event_array; +extern fptype *dev_event_array; extern fptype host_normalisation[maxParams]; extern fptype host_params[maxParams]; extern unsigned int host_indices[maxParams]; @@ -45,98 +45,82 @@ class BinnedDataSet; class UnbinnedDataSet; class PdfBase { - -public: - PdfBase(Variable* x, std::string n); + public: + PdfBase(Variable *x, std::string n); virtual ~PdfBase() = default; - enum Specials {ForceSeparateNorm = 1, ForceCommonNorm = 2}; + enum Specials { ForceSeparateNorm = 1, ForceCommonNorm = 2 }; __host__ virtual double calculateNLL() const = 0; - __host__ virtual fptype normalize() const = 0; + __host__ virtual fptype normalize() const = 0; __host__ void initializeIndices(std::vector pindices); - __host__ void addSpecialMask(int m) { - specialMask |= m; - } - __host__ void copyParams(const std::vector& pars) const; + __host__ void addSpecialMask(int m) { specialMask |= m; } + __host__ void copyParams(const std::vector &pars) const; __host__ void copyParams(); __host__ void copyNormFactors() const; __host__ void generateNormRange(); - __host__ std::string getName() const { - return name; - } - - __host__ virtual std::vector getObservables() const; - __host__ virtual std::vector getParameters() const; - __host__ Variable* getParameterByName(std::string n) const; - __host__ int getSpecialMask() const { - return specialMask; - } - - __host__ void setData(DataSet* data); - + __host__ std::string getName() const { return name; } + + __host__ virtual std::vector getObservables() const; + __host__ virtual std::vector getParameters() const; + __host__ Variable *getParameterByName(std::string n) const; + __host__ int getSpecialMask() const { return specialMask; } + + __host__ void setData(DataSet *data); + /// This is the old style input, should be removed - __host__ void setData(std::vector>& data); - - - __host__ virtual void setFitControl(FitControl* const fc, bool takeOwnerShip = true) = 0; - __host__ virtual bool hasAnalyticIntegral() const { - return false; - } - + __host__ void setData(std::vector> &data); + + __host__ virtual void setFitControl(FitControl *const fc, bool takeOwnerShip = true) = 0; + __host__ virtual bool hasAnalyticIntegral() const { return false; } + /// RooFit style fitting shortcut - __host__ ROOT::Minuit2::FunctionMinimum fitTo(DataSet* data); - - __host__ unsigned int getFunctionIndex() const { - return functionIdx; - } - __host__ unsigned int getParameterIndex() const { - return parameters; - } - __host__ unsigned int registerParameter(Variable* var); + __host__ ROOT::Minuit2::FunctionMinimum fitTo(DataSet *data); + + __host__ unsigned int getFunctionIndex() const { return functionIdx; } + __host__ unsigned int getParameterIndex() const { return parameters; } + __host__ unsigned int registerParameter(Variable *var); __host__ unsigned int registerConstants(unsigned int amount); __host__ virtual void recursiveSetNormalisation(fptype norm = 1) const; - __host__ void unregisterParameter(Variable* var); - __host__ void registerObservable(Variable* obs); + __host__ void unregisterParameter(Variable *var); + __host__ void registerObservable(Variable *obs); __host__ void setIntegrationFineness(int i); __host__ void printProfileInfo(bool topLevel = true); __host__ bool parametersChanged() const; - __host__ void checkInitStatus(std::vector& unInited) const; + __host__ void checkInitStatus(std::vector &unInited) const; void clearCurrentFit(); - __host__ void SigGenSetIndices() { - setIndices(); - } -protected: - fptype numEvents {0}; //< Non-integer to allow weighted events - unsigned int numEntries {0}; //< Eg number of bins - not always the same as number of events, although it can be. - fptype* normRanges {nullptr}; //< This is specific to functor instead of variable so that MetricTaker::operator needn't use indices. - unsigned int parameters {0}; //< Stores index, in 'paramIndices', where this functor's information begins. - unsigned int cIndex {1}; //< Stores location of constants. - std::vector observables; - std::vector parameterList; - FitControl* fitControl {nullptr}; - std::vector components; - int integrationBins {-1}; - int specialMask {0}; //< For storing information unique to PDFs, eg "Normalize me separately" for TddpPdf. - bool properlyInitialised {true}; //< Allows checking for required extra steps in, eg, Tddp and Convolution. + __host__ void SigGenSetIndices() { setIndices(); } + + protected: + fptype numEvents{0}; //< Non-integer to allow weighted events + unsigned int numEntries{0}; //< Eg number of bins - not always the same as number of events, although it can be. + fptype *normRanges{ + nullptr}; //< This is specific to functor instead of variable so that MetricTaker::operator needn't use indices. + unsigned int parameters{0}; //< Stores index, in 'paramIndices', where this functor's information begins. + unsigned int cIndex{1}; //< Stores location of constants. + std::vector observables; + std::vector parameterList; + FitControl *fitControl{nullptr}; + std::vector components; + int integrationBins{-1}; + int specialMask{0}; //< For storing information unique to PDFs, eg "Normalize me separately" for TddpPdf. + bool properlyInitialised{true}; //< Allows checking for required extra steps in, eg, Tddp and Convolution. unsigned int functionIdx; //< Stores index of device function pointer. int m_iEventsPerTask; - + /// This needs to be set before a call to setData. - void setNumPerTask(PdfBase* p, const int& c); + void setNumPerTask(PdfBase *p, const int &c); -private: + private: std::string name; __host__ void recursiveSetIndices(); __host__ void setIndices(); }; - } // namespace GooFit - diff --git a/include/goofit/UnbinnedDataSet.h b/include/goofit/UnbinnedDataSet.h index d61090951..a88e8a2ed 100644 --- a/include/goofit/UnbinnedDataSet.h +++ b/include/goofit/UnbinnedDataSet.h @@ -8,34 +8,31 @@ namespace GooFit { - class UnbinnedDataSet : public DataSet { // Class for unbinned datasets. -public: + public: using DataSet::addEvent; - - UnbinnedDataSet(Variable* var, std::string n = ""); - UnbinnedDataSet(std::vector& vars, std::string n = ""); - UnbinnedDataSet(std::set& vars, std::string n = ""); - UnbinnedDataSet(std::initializer_list vars, std::string n=""); - + + UnbinnedDataSet(Variable *var, std::string n = ""); + UnbinnedDataSet(std::vector &vars, std::string n = ""); + UnbinnedDataSet(std::set &vars, std::string n = ""); + UnbinnedDataSet(std::initializer_list vars, std::string n = ""); + ~UnbinnedDataSet() override = default; void addEvent() override; - + /// Get the value at a specific variable and event number - fptype getValue(Variable* var, size_t idx) const; - + fptype getValue(Variable *var, size_t idx) const; + /// Set all the variables to the current event values void loadEvent(size_t idx); - + /// Set all entries to a constant value (note: this is kind of ugly) - void setValueForAllEvents(Variable* var); + void setValueForAllEvents(Variable *var); -private: + private: std::vector> data; - }; } // namespace GooFit - diff --git a/include/goofit/Variable.h b/include/goofit/Variable.h index 06ad0c2c2..beee72893 100644 --- a/include/goofit/Variable.h +++ b/include/goofit/Variable.h @@ -7,7 +7,6 @@ #include "goofit/GlobalCudaDefines.h" - // Declaring friends namespace GooFit { @@ -16,59 +15,59 @@ class FCN; class Minuit1; class Indexable { -public: - - Indexable(std::string n, fptype val = 0) : name(n), value(val) {} - + public: + Indexable(std::string n, fptype val = 0) + : name(n) + , value(val) {} + // These classes can not be duplicated Indexable(Indexable &) = delete; - Indexable& operator=(Indexable&) = delete; - + Indexable &operator=(Indexable &) = delete; + virtual ~Indexable() = default; - + /// Get the GooFit index - int getIndex() const {return index;} + int getIndex() const { return index; } /// Set the GooFit index - void setIndex(int value) {index = value;} - + void setIndex(int value) { index = value; } + /// Get the index from the fitter - int getFitterIndex() const {return fitter_index;} + int getFitterIndex() const { return fitter_index; } /// Set the index (should be done by the fitter) - void setFitterIndex(int value) {fitter_index = value;} + void setFitterIndex(int value) { fitter_index = value; } /// Get the name - const std::string& getName() const {return name;} + const std::string &getName() const { return name; } /// Set the name - void setName(const std::string& val) {name = val;} - + void setName(const std::string &val) { name = val; } + /// Get the value - fptype getValue() const {return value;} + fptype getValue() const { return value; } /// Set the value - void setValue(fptype val) {value = val;} - + void setValue(fptype val) { value = val; } + // Utilities - + /// Support var = 3 - void operator=(const fptype& val) {setValue(val);} - + void operator=(const fptype &val) { setValue(val); } + /// Support fptype val = var - operator fptype() const {return getValue();} - + operator fptype() const { return getValue(); } + /// Support for less than, etc. - -protected: - + + protected: /// The variable name. Should be unique std::string name; - + /// The value of the variable fptype value; - + /// The goofit index, -1 if unset - int index {-1}; - + int index{-1}; + /// The fitter index, -1 if unset - int fitter_index {-1}; + int fitter_index{-1}; }; /// Contains information about a parameter allowed @@ -78,156 +77,148 @@ class Indexable { class Variable : public Indexable { friend GooFit::FCN; friend GooFit::Minuit1; - friend std::ostream& operator<< (std::ostream& o, const Variable& var); - friend std::istream& operator>> (std::istream& o, Variable& var); -public: - + friend std::ostream &operator<<(std::ostream &o, const Variable &var); + friend std::istream &operator>>(std::istream &o, Variable &var); + + public: // These classes can not be duplicated Variable(Variable &) = delete; - Variable& operator=(Variable&) = delete; - + Variable &operator=(Variable &) = delete; + /// Support var = 3 - void operator=(const fptype& val) {setValue(val);} - + void operator=(const fptype &val) { setValue(val); } + /// This is a constant varaible Variable(std::string n, fptype v) - : Indexable(n, v) - , error(0.002) - , upperlimit(v + 0.01) - , lowerlimit(v - 0.01) - , fixed(true) {} - + : Indexable(n, v) + , error(0.002) + , upperlimit(v + 0.01) + , lowerlimit(v - 0.01) + , fixed(true) {} + /// This is an independent variable Variable(std::string n, fptype dn, fptype up) - : Indexable(n) - , upperlimit(up) - , lowerlimit(dn) {} - - + : Indexable(n) + , upperlimit(up) + , lowerlimit(dn) {} + /// This is a normal variable, with value and upper/lower limits Variable(std::string n, fptype v, fptype dn, fptype up) - : Indexable(n, v) - , error(0.1*(up-dn)) - , upperlimit(up) - , lowerlimit(dn) {} - + : Indexable(n, v) + , error(0.1 * (up - dn)) + , upperlimit(up) + , lowerlimit(dn) {} + /// This is a full varaible with error scale as well Variable(std::string n, fptype v, fptype e, fptype dn, fptype up) - : Indexable(n, v) - , error(e) - , upperlimit(up) - , lowerlimit(dn) {} - - + : Indexable(n, v) + , error(e) + , upperlimit(up) + , lowerlimit(dn) {} + ~Variable() override = default; - + /// Get the error - fptype getError() const {return error;} + fptype getError() const { return error; } /// Set the error - void setError(fptype val) {error = val;} - + void setError(fptype val) { error = val; } + /// Get the upper limit - fptype getUpperLimit() const {return upperlimit;} + fptype getUpperLimit() const { return upperlimit; } /// Set the upper limit - void setUpperLimit(fptype val) {upperlimit = val;} - + void setUpperLimit(fptype val) { upperlimit = val; } + /// Get the lower limit - fptype getLowerLimit() const {return lowerlimit;} + fptype getLowerLimit() const { return lowerlimit; } /// Set the lower limit - void setLowerLimit(fptype val) {lowerlimit = val;} - + void setLowerLimit(fptype val) { lowerlimit = val; } + /// Check to see if the value has changed this iteration (always true the first time) - bool getChanged() const {return changed_;} - + bool getChanged() const { return changed_; } + /// Set the number of bins - void setNumBins(size_t num) {numbins = num;} - + void setNumBins(size_t num) { numbins = num; } + /// Get the number of bins - size_t getNumBins() const {return numbins;} - + size_t getNumBins() const { return numbins; } + /// Check to see if this is a constant - bool IsFixed() const {return fixed;} - + bool IsFixed() const { return fixed; } + /// Set the fixedness of a variable - void setFixed(bool fix) {fixed = fix;} - - + void setFixed(bool fix) { fixed = fix; } + /// Check to see if this has been changed since last iteration - void setChanged(bool val=true) {changed_ = val;} - - + void setChanged(bool val = true) { changed_ = val; } + /// Get the bin size, (upper-lower) / bins - fptype getBinSize() const {return (getUpperLimit() - getLowerLimit()) / getNumBins();} - + fptype getBinSize() const { return (getUpperLimit() - getLowerLimit()) / getNumBins(); } + /// Hides the number; the real value is the result minus this value. Cannot be retreived once set. - void setBlind(fptype val) {blind = val;} + void setBlind(fptype val) { blind = val; } /// Check to see if in range - operator bool() const {return getValue() <= getUpperLimit() && getValue() >= getLowerLimit();} + operator bool() const { return getValue() <= getUpperLimit() && getValue() >= getLowerLimit(); } - -protected: - + protected: /// The error fptype error; - + /// The upper limit fptype upperlimit; - + /// The lower limit fptype lowerlimit; - + /// A blinding value to add (disabled at the moment, TODO) - fptype blind {0}; - + fptype blind{0}; + /// The number of bins (mostly for BinnedData, or plotting help) - size_t numbins {100}; - + size_t numbins{100}; + /// True if the value was unchanged since the last iteration - bool changed_ {true}; - + bool changed_{true}; + /// This "fixes" the variable (constant) - bool fixed {false}; + bool fixed{false}; }; /// This is used to track event number for MPI versions. /// A cast is done to know whether the values need to be fixed. class CountingVariable : public Variable { -public: - + public: using Variable::Variable; ~CountingVariable() override = default; // These classes can not be duplicated - CountingVariable& operator=(CountingVariable&) = delete; + CountingVariable &operator=(CountingVariable &) = delete; /// Support var = 3 - void operator=(const fptype& val) {setValue(val);} + void operator=(const fptype &val) { setValue(val); } }; /// This is similar to Variable, but the index points /// to functorConstants instead of cudaArray. class Constant : public Indexable { -public: - + public: // These classes can not be duplicated Constant(Constant &) = delete; - Constant& operator=(Constant&) = delete; + Constant &operator=(Constant &) = delete; /// Support var = 3 - void operator=(const fptype& val) {setValue(val);} + void operator=(const fptype &val) { setValue(val); } - Constant(std::string n, fptype val) : Indexable(n, val) {} + Constant(std::string n, fptype val) + : Indexable(n, val) {} ~Constant() override = default; }; /// Get the max index of a variable from a list -int max_index(const std::vector &vars); +int max_index(const std::vector &vars); /// Get the max fitter index of a variable from a list -int max_fitter_index(const std::vector &vars); +int max_fitter_index(const std::vector &vars); /// Nice print of Variable -std::ostream& operator<< (std::ostream& o, const GooFit::Variable& var); +std::ostream &operator<<(std::ostream &o, const GooFit::Variable &var); /// Allow Variable to be read in -std::istream& operator>> (std::istream& i, GooFit::Variable& var); +std::istream &operator>>(std::istream &i, GooFit::Variable &var); } - diff --git a/include/goofit/detail/Abort.h b/include/goofit/detail/Abort.h index 2aeb18b10..1e72b2c12 100644 --- a/include/goofit/detail/Abort.h +++ b/include/goofit/detail/Abort.h @@ -7,12 +7,12 @@ namespace GooFit { class PdfBase; /// Smart abort that includes the file name and location, and prints a stack trace if possible -void abort(std::string file, int line, std::string reason, const PdfBase* pdf = nullptr); +void abort(std::string file, int line, std::string reason, const PdfBase *pdf = nullptr); } // namespace GooFit /// Classic abort name -[[deprecated("Use GooFit::abort instead")]] -inline void abortWithCudaPrintFlush(std::string file, int line, std::string reason, const GooFit::PdfBase* pdf = nullptr) { +[[deprecated("Use GooFit::abort instead")]] inline void +abortWithCudaPrintFlush(std::string file, int line, std::string reason, const GooFit::PdfBase *pdf = nullptr) { GooFit::abort(file, line, reason, pdf); } diff --git a/include/goofit/detail/ThrustOverride.h b/include/goofit/detail/ThrustOverride.h index f1250bf03..f348a0003 100644 --- a/include/goofit/detail/ThrustOverride.h +++ b/include/goofit/detail/ThrustOverride.h @@ -1,6 +1,6 @@ #pragma once -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA #include #include @@ -25,36 +25,26 @@ #define OR_GRAINSIZE 7 #endif -//We are defining a new policy. This will allow us to override the internal thread/block distribution +// We are defining a new policy. This will allow us to override the internal thread/block distribution struct goofit_policy : thrust::device_execution_policy {}; -template -__host__ __device__ -OutputType transform_reduce(goofit_policy& exec, - InputIterator first, - InputIterator last, - UnaryFunction unary_op, - OutputType init, - BinaryFunction binary_op) { - //printf ("goofit transform_reduce\n"); +template +__host__ __device__ OutputType transform_reduce(goofit_policy &exec, + InputIterator first, + InputIterator last, + UnaryFunction unary_op, + OutputType init, + BinaryFunction binary_op) { + // printf ("goofit transform_reduce\n"); thrust::transform_iterator xfrm_first(first, unary_op); thrust::transform_iterator xfrm_last(last, unary_op); return thrust::reduce(exec, xfrm_first, xfrm_last, init, binary_op); } // end transform_reduce() -template -__host__ __device__ -OutputType reduce(goofit_policy& exec, - InputIterator first, - InputIterator last, - OutputType init, - BinaryFunction binary_op) { +template +__host__ __device__ OutputType +reduce(goofit_policy &exec, InputIterator first, InputIterator last, OutputType init, BinaryFunction binary_op) { typedef typename thrust::iterator_difference::type size_type; const size_type n = last - first; @@ -62,24 +52,23 @@ OutputType reduce(goofit_policy& exec, if(n <= 0) return init; - //We are no longer expecting a default stream to be passed + // We are no longer expecting a default stream to be passed cudaStream_t s = stream(thrust::detail::derived_cast(exec)); - //OR_GROUPSIZE=128 - //OR_GRAINSIZE=7 - //printf ("groupsize:%i grainsize:%i\n", OR_GROUPSIZE, OR_GRAINSIZE); + // OR_GROUPSIZE=128 + // OR_GRAINSIZE=7 + // printf ("groupsize:%i grainsize:%i\n", OR_GROUPSIZE, OR_GRAINSIZE); const size_type groupsize = OR_GROUPSIZE; - //const size_type groupsize = 128; - //const size_type grainsize = 7; - const size_type grainsize = OR_GRAINSIZE; - const size_type tile_size = groupsize * grainsize; - const size_type num_tiles = (n + tile_size - 1) / tile_size; + // const size_type groupsize = 128; + // const size_type grainsize = 7; + const size_type grainsize = OR_GRAINSIZE; + const size_type tile_size = groupsize * grainsize; + const size_type num_tiles = (n + tile_size - 1) / tile_size; const size_type subscription = 10; - thrust::system::cuda::detail::bulk_::concurrent_group< - thrust::system::cuda::detail::bulk_::agent, - groupsize - > g; + thrust::system::cuda::detail::bulk_::concurrent_group, + groupsize> + g; const size_type num_groups = thrust::min(subscription * g.hardware_concurrency(), num_tiles); @@ -88,21 +77,28 @@ OutputType reduce(goofit_policy& exec, thrust::detail::temporary_array partial_sums(exec, decomp.size()); // reduce into partial sums - thrust::system::cuda::detail::bulk_::async( - thrust::system::cuda::detail::bulk_::par(s, g, decomp.size()), - thrust::system::cuda::detail::reduce_detail::reduce_partitions(), - thrust::system::cuda::detail::bulk_::root.this_exec, first, decomp, partial_sums.begin(), init, binary_op).wait(); + thrust::system::cuda::detail::bulk_::async(thrust::system::cuda::detail::bulk_::par(s, g, decomp.size()), + thrust::system::cuda::detail::reduce_detail::reduce_partitions(), + thrust::system::cuda::detail::bulk_::root.this_exec, + first, + decomp, + partial_sums.begin(), + init, + binary_op) + .wait(); if(partial_sums.size() > 1) { // reduce the partial sums - thrust::system::cuda::detail::bulk_::async( - thrust::system::cuda::detail::bulk_::par(s, g, 1), thrust::system::cuda::detail::reduce_detail::reduce_partitions(), - thrust::system::cuda::detail::bulk_::root.this_exec, partial_sums.begin(), partial_sums.end(), partial_sums.begin(), - binary_op); + thrust::system::cuda::detail::bulk_::async(thrust::system::cuda::detail::bulk_::par(s, g, 1), + thrust::system::cuda::detail::reduce_detail::reduce_partitions(), + thrust::system::cuda::detail::bulk_::root.this_exec, + partial_sums.begin(), + partial_sums.end(), + partial_sums.begin(), + binary_op); } // end if return get_value(exec, &partial_sums[0]); } // end goofit_reduce() #endif - diff --git a/include/goofit/fitting/FCN.h b/include/goofit/fitting/FCN.h index 5c62fc61d..4b470a017 100644 --- a/include/goofit/fitting/FCN.h +++ b/include/goofit/fitting/FCN.h @@ -9,29 +9,26 @@ namespace GooFit { class FCN : public Minuit2::FCNBase { -protected: + protected: Params *params_; -public: - + + public: /// Create an FCN given parameters (PDF reference is inside params) - FCN(Params& params); - + FCN(Params ¶ms); + /// Make a parameter array with the current variable values std::vector makePars() const; - + /// Run the fit (used by Minuit2 class) - double operator()(const std::vector& pars) const override; - + double operator()(const std::vector &pars) const override; + /// produce the FCN value for the current values of the parameters double operator()() const; - + /// This value is 0.5 for ll, 1 for chi2 - double Up() const override { - return 0.5; - } - + double Up() const override { return 0.5; } + /// Get a pointer to the parameters - Params* GetParams(); + Params *GetParams(); }; - } diff --git a/include/goofit/fitting/FitManagerMinuit1.h b/include/goofit/fitting/FitManagerMinuit1.h index 6164dbd11..796eb3a90 100644 --- a/include/goofit/fitting/FitManagerMinuit1.h +++ b/include/goofit/fitting/FitManagerMinuit1.h @@ -5,75 +5,57 @@ #include namespace GooFit { - + class PdfBase; class Minuit1 : public TMinuit { - PdfBase* pdfPointer; - std::vector vars; - -public: - Minuit1(PdfBase* pdfPointer); + PdfBase *pdfPointer; + std::vector vars; + + public: + Minuit1(PdfBase *pdfPointer); /// Fit function for Minuit virtual Int_t Eval(Int_t npar, //< The number of parameters Double_t *grad, //< The derivatives can be stored here if flag is 2 (output) Double_t &fval, //< The value of the function at this point (output) Double_t *par, //< The input parameters - Int_t flag //< This is 1 the first time, 2, for derivatives, and 3 after the fit is finished. It is something else if computing. + Int_t flag //< This is 1 the first time, 2, for derivatives, and 3 after the fit is finished. It + // is something else if computing. ) override; - + // Get a copy of the list of variables - std::vector getVaraibles() const {return vars;}; + std::vector getVaraibles() const { return vars; }; }; class FitManagerMinuit1 { -public: - FitManagerMinuit1(PdfBase* dat) : minuit_(dat) {} - - void setMaxCalls(double mxc) { - overrideCallLimit = mxc; - } - void useHesseBefore(bool use=true) { - _useHesseBefore = use; - } - void useHesse(bool use=true) { - _useHesse = use; - } - void useMinos(bool use=true) { - _useMinos = use; - } - void useImprove(bool use=true) { - _useImprove = use; - } - void setVerbosity(int v) { - minuit_.SetPrintLevel(v-1); - } - - operator bool() const { - return minuit_.GetStatus() == 0; - } - operator int() const { - return minuit_.GetStatus(); - } - + public: + FitManagerMinuit1(PdfBase *dat) + : minuit_(dat) {} + + void setMaxCalls(double mxc) { overrideCallLimit = mxc; } + void useHesseBefore(bool use = true) { _useHesseBefore = use; } + void useHesse(bool use = true) { _useHesse = use; } + void useMinos(bool use = true) { _useMinos = use; } + void useImprove(bool use = true) { _useImprove = use; } + void setVerbosity(int v) { minuit_.SetPrintLevel(v - 1); } + + operator bool() const { return minuit_.GetStatus() == 0; } + operator int() const { return minuit_.GetStatus(); } + // This runs the fit void fit(); - - Minuit1* getMinuitObject() { - return &minuit_; - } - - void getMinuitStatus(double& fmin, double& fedm, double& errdef, int& npari, int& nparx, int& istat); - - -private: - double overrideCallLimit {-1}; - bool _useHesseBefore {true}; - bool _useHesse {true}; - bool _useMinos {false}; - bool _useImprove {false}; - + + Minuit1 *getMinuitObject() { return &minuit_; } + + void getMinuitStatus(double &fmin, double &fedm, double &errdef, int &npari, int &nparx, int &istat); + + private: + double overrideCallLimit{-1}; + bool _useHesseBefore{true}; + bool _useHesse{true}; + bool _useMinos{false}; + bool _useImprove{false}; + Minuit1 minuit_; }; - } diff --git a/include/goofit/fitting/FitManagerMinuit2.h b/include/goofit/fitting/FitManagerMinuit2.h index d11083397..a5aae7c8a 100644 --- a/include/goofit/fitting/FitManagerMinuit2.h +++ b/include/goofit/fitting/FitManagerMinuit2.h @@ -7,50 +7,41 @@ #include "goofit/fitting/FCN.h" namespace GooFit { - + class PdfBase; -enum class FitErrors : int { - Valid = 0, - NotRun = 50, - InValid -}; +enum class FitErrors : int { Valid = 0, NotRun = 50, InValid }; class FitManagerMinuit2 { - -public: - FitManagerMinuit2(PdfBase* dat); - + public: + FitManagerMinuit2(PdfBase *dat); + /// This runs the fit ROOT::Minuit2::FunctionMinimum fit(); - + /// Set the maximum number of calls. 0 for Minuit2 default. - void setMaxCalls(unsigned int max_calls = 0) { - maxfcn_ = max_calls; - } - + void setMaxCalls(unsigned int max_calls = 0) { maxfcn_ = max_calls; } + /// Get a pointer to the params - Params* getParams() {return &upar_;} - + Params *getParams() { return &upar_; } + /// Get a pointer to the fcn - FCN* getFCN() {return &fcn_;} - + FCN *getFCN() { return &fcn_; } + /// Check to see if fit is valid - operator bool() const {return retval_ == FitErrors::Valid;} - + operator bool() const { return retval_ == FitErrors::Valid; } + /// Return value for program - operator int() const {return static_cast(retval_);} - + operator int() const { return static_cast(retval_); } + /// Set the fitting verbosity - void setVerbosity(int value) {verbosity = value;} + void setVerbosity(int value) { verbosity = value; } - -private: + private: Params upar_; FCN fcn_; - unsigned int maxfcn_ {0}; - FitErrors retval_ {FitErrors::NotRun}; - int verbosity {3}; + unsigned int maxfcn_{0}; + FitErrors retval_{FitErrors::NotRun}; + int verbosity{3}; }; - } diff --git a/include/goofit/fitting/Params.h b/include/goofit/fitting/Params.h index 6553ee6b7..6d22293bd 100644 --- a/include/goofit/fitting/Params.h +++ b/include/goofit/fitting/Params.h @@ -5,7 +5,6 @@ #include #include - namespace Minuit2 = ROOT::Minuit2; namespace GooFit { @@ -13,26 +12,24 @@ namespace GooFit { class PdfBase; class Variable; class FCN; - + class Params : public Minuit2::MnUserParameters { friend FCN; -protected: - std::vector vars_; - PdfBase* pdf_; + + protected: + std::vector vars_; + PdfBase *pdf_; size_t num_; - -public: + + public: using MnUserParameters::MnUserParameters; - + Params(PdfBase &pdf); - + // Read the values back into GooFit - void SetGooFitParams(const Minuit2::MnUserParameterState& input); - - // Get the number of params in the fit - size_t size() const {return vars_.size();}; + void SetGooFitParams(const Minuit2::MnUserParameterState &input); + // Get the number of params in the fit + size_t size() const { return vars_.size(); }; }; - } - diff --git a/makefile b/makefile index 455cb5e47..46c6add27 100644 --- a/makefile +++ b/makefile @@ -27,6 +27,9 @@ mpi: cd build-mpi && cmake .. -DGOOFIT_MPI=ON && $(MAKE) --no-print-directory cd build-mpi && ctest --output-on-failure +clang-format: + git ls-files -- '*.cu' '*.cc' '*.h' '*.cpp' | xargs clang-format -i -style=file + warning: @echo "This project builds with CMake 3.4+." @echo "This makefile is just a shortcut to prepare your build with CMake." diff --git a/python/BinnedDataSet.cpp b/python/BinnedDataSet.cpp index af01b52d7..127813c7d 100644 --- a/python/BinnedDataSet.cpp +++ b/python/BinnedDataSet.cpp @@ -8,15 +8,14 @@ namespace py = pybind11; void init_BinnedDataSet(py::module &m) { py::class_(m, "BinnedDataSet") - .def(py::init()) - .def(py::init()) - .def(py::init&>()) - .def(py::init&, std::string>()) - .def("getBinCenter", (fptype (BinnedDataSet::*) (size_t, size_t) const) &BinnedDataSet::getBinCenter) + .def(py::init()) + .def(py::init()) + .def(py::init &>()) + .def(py::init &, std::string>()) + .def("getBinCenter", (fptype(BinnedDataSet::*)(size_t, size_t) const) & BinnedDataSet::getBinCenter) .def("getBinNumber", &BinnedDataSet::getBinNumber) .def("getBinVolume", &BinnedDataSet::getBinVolume) .def("getBinError", &BinnedDataSet::getBinError) .def("getNumBins", &BinnedDataSet::getNumBins) - .def("getNumEvents", &BinnedDataSet::getNumEvents) - ; + .def("getNumEvents", &BinnedDataSet::getNumEvents); } diff --git a/python/DataSet.cpp b/python/DataSet.cpp index 52cf60d0b..8d964df7e 100644 --- a/python/DataSet.cpp +++ b/python/DataSet.cpp @@ -9,18 +9,14 @@ using namespace GooFit; template class PyDataSet : public DataSetBase { using DataSetBase::DataSetBase; - void addEvent() override { - PYBIND11_OVERLOAD_PURE(void, DataSetBase, addEvent); - }; + void addEvent() override { PYBIND11_OVERLOAD_PURE(void, DataSetBase, addEvent); }; }; - void init_DataSet(py::module &m) { py::class_>(m, "DataSet") - .def(py::init()) - .def(py::init()) - .def(py::init&>()) - .def(py::init&, std::string>()) - .def("addEvent", (void (DataSet::*)()) &DataSet::addEvent) - ; + .def(py::init()) + .def(py::init()) + .def(py::init &>()) + .def(py::init &, std::string>()) + .def("addEvent", (void (DataSet::*)()) & DataSet::addEvent); } diff --git a/python/FitManager.cpp b/python/FitManager.cpp index da2b6c88c..794e353e4 100644 --- a/python/FitManager.cpp +++ b/python/FitManager.cpp @@ -8,10 +8,7 @@ using namespace GooFit; void init_FitManager(py::module &m) { py::class_(m, "FitManager") - .def(py::init()) + .def(py::init()) // Can't directly wrap becase we (currently) don't want the return value in python - .def("fit", [](FitManager& self){self.fit();}) - ; - - + .def("fit", [](FitManager &self) { self.fit(); }); } diff --git a/python/PDFs/ExpPdf.cpp b/python/PDFs/ExpPdf.cpp index 5dbca3f3f..84156c238 100644 --- a/python/PDFs/ExpPdf.cpp +++ b/python/PDFs/ExpPdf.cpp @@ -8,7 +8,6 @@ namespace py = pybind11; void init_ExpPdf(py::module &m) { py::class_(m, "ExpPdf") - .def(py::init()) - .def(py::init()) - ; + .def(py::init()) + .def(py::init()); } diff --git a/python/PDFs/GooPdf.cpp b/python/PDFs/GooPdf.cpp index 047c35a7c..a4c8ea625 100644 --- a/python/PDFs/GooPdf.cpp +++ b/python/PDFs/GooPdf.cpp @@ -6,9 +6,4 @@ using namespace GooFit; namespace py = pybind11; -void init_GooPdf(py::module &m) { - py::class_(m, "GooPdf") - ; - -} - +void init_GooPdf(py::module &m) { py::class_(m, "GooPdf"); } diff --git a/python/PdfBase.cpp b/python/PdfBase.cpp index e57ac0f0e..5c1930b98 100644 --- a/python/PdfBase.cpp +++ b/python/PdfBase.cpp @@ -11,9 +11,6 @@ using namespace GooFit; void init_PdfBase(py::module &m) { py::class_(m, "PdfBase") - .def("setData", (void (PdfBase::*)(DataSet*)) &PdfBase::setData) - .def("setData", (void (PdfBase::*)(std::vector>&)) &PdfBase::setData) - ; - + .def("setData", (void (PdfBase::*)(DataSet *)) & PdfBase::setData) + .def("setData", (void (PdfBase::*)(std::vector> &)) & PdfBase::setData); } - diff --git a/python/UnbinnedDataSet.cpp b/python/UnbinnedDataSet.cpp index 0aadf25cd..c787fed3a 100644 --- a/python/UnbinnedDataSet.cpp +++ b/python/UnbinnedDataSet.cpp @@ -8,9 +8,8 @@ using namespace GooFit; void init_UnbinnedDataSet(py::module &m) { py::class_(m, "UnbinnedDataSet") - .def(py::init()) - .def(py::init()) - .def(py::init&>()) - .def(py::init&, std::string>()) - ; + .def(py::init()) + .def(py::init()) + .def(py::init &>()) + .def(py::init &, std::string>()); } diff --git a/python/Variable.cpp b/python/Variable.cpp index 8fa42be19..3d888e704 100644 --- a/python/Variable.cpp +++ b/python/Variable.cpp @@ -13,12 +13,10 @@ void init_Variable(py::module &m) { py::class_(m, "Indexable") .def(py::init()) .def(py::init()) - .def_property_readonly("name", &Indexable::getName) + .def_property_readonly("name", &Indexable::getName) .def_property("value", &Indexable::getValue, &Indexable::setValue) .def_property("index", &Indexable::getIndex, &Indexable::setIndex) - .def_property_readonly("fitterIndex", &Indexable::getFitterIndex) - ; - + .def_property_readonly("fitterIndex", &Indexable::getFitterIndex); py::class_(m, "Variable") .def(py::init()) @@ -30,13 +28,10 @@ void init_Variable(py::module &m) { .def_property("getNumBins", &Variable::getNumBins, &Variable::setNumBins) .def_property("fixed", &Variable::IsFixed, &Variable::setFixed) //.def_property("blind", &Variable::b, &Variable::setBlind) - .def("__repr__", [](const Variable &v){ - return ""_format(v.getName()); - }) - .def("__str__", [](const Variable &v){ + .def("__repr__", [](const Variable &v) { return ""_format(v.getName()); }) + .def("__str__", [](const Variable &v) { std::stringstream os; os << v; return os.str(); - }) - ; + }); } diff --git a/python/goofit.cpp b/python/goofit.cpp index ff6916c4e..fba3bdc98 100644 --- a/python/goofit.cpp +++ b/python/goofit.cpp @@ -12,18 +12,16 @@ void init_ExpPdf(py::module &); void init_FitManager(py::module &); PYBIND11_PLUGIN(goofit) { - py::module m("goofit", "Python interface for GooFit"); + py::module m("goofit", "Python interface for GooFit"); - init_Variable(m); - init_DataSet(m); - init_BinnedDataSet(m); - init_UnbinnedDataSet(m); - init_PdfBase(m); - init_GooPdf(m); - init_ExpPdf(m); - init_FitManager(m); + init_Variable(m); + init_DataSet(m); + init_BinnedDataSet(m); + init_UnbinnedDataSet(m); + init_PdfBase(m); + init_GooPdf(m); + init_ExpPdf(m); + init_FitManager(m); - return m.ptr(); + return m.ptr(); } - - diff --git a/src/PDFs/AddPdf.cu b/src/PDFs/AddPdf.cu index 8cf7def1c..36b43e802 100644 --- a/src/PDFs/AddPdf.cu +++ b/src/PDFs/AddPdf.cu @@ -1,9 +1,9 @@ #include "goofit/PDFs/combine/AddPdf.h" -#include "goofit/detail/ThrustOverride.h" #include "goofit/Error.h" +#include "goofit/detail/ThrustOverride.h" -#include #include +#include #ifdef GOOFIT_MPI #include @@ -11,86 +11,89 @@ namespace GooFit { -__device__ fptype device_AddPdfs(fptype* evt, fptype* p, unsigned int* indices) { - int numParameters = RO_CACHE(indices[0]); - fptype ret = 0; +__device__ fptype device_AddPdfs(fptype *evt, fptype *p, unsigned int *indices) { + int numParameters = RO_CACHE(indices[0]); + fptype ret = 0; fptype totalWeight = 0; - for(int i = 1; i < numParameters-3; i += 3) { - totalWeight += RO_CACHE(p[RO_CACHE(indices[i+2])]); - fptype curr = callFunction(evt, RO_CACHE(indices[i]), RO_CACHE(indices[i+1])); - fptype weight = RO_CACHE(p[RO_CACHE(indices[i+2])]); - ret += weight * curr * normalisationFactors[RO_CACHE(indices[i+1])]; - - //if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("Add comp %i: %f * %f * %f = %f (%f)\n", i, weight, curr, normalisationFactors[indices[i+1]], weight*curr*normalisationFactors[indices[i+1]], ret); + for(int i = 1; i < numParameters - 3; i += 3) { + totalWeight += RO_CACHE(p[RO_CACHE(indices[i + 2])]); + fptype curr = callFunction(evt, RO_CACHE(indices[i]), RO_CACHE(indices[i + 1])); + fptype weight = RO_CACHE(p[RO_CACHE(indices[i + 2])]); + ret += weight * curr * normalisationFactors[RO_CACHE(indices[i + 1])]; + // if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("Add comp %i: %f * %f * %f = %f (%f)\n", i, weight, curr, normalisationFactors[indices[i+1]], + // weight*curr*normalisationFactors[indices[i+1]], ret); } // numParameters does not count itself. So the array structure for two functions is // nP | F P w | F P - // in which nP = 5. Therefore the parameter index for the last function pointer is nP, and the function index is nP-1. - //fptype last = (*(reinterpret_cast(device_function_table[indices[numParameters-1]])))(evt, p, paramIndices + indices[numParameters]); + // in which nP = 5. Therefore the parameter index for the last function pointer is nP, and the function index is + // nP-1. + // fptype last = (*(reinterpret_cast(device_function_table[indices[numParameters-1]])))(evt, p, + // paramIndices + indices[numParameters]); fptype last = callFunction(evt, RO_CACHE(indices[numParameters - 1]), RO_CACHE(indices[numParameters])); ret += (1 - totalWeight) * last * normalisationFactors[RO_CACHE(indices[numParameters])]; - //if ((THREADIDX < 50) && (isnan(ret))) printf("NaN final component %f %f\n", last, totalWeight); + // if ((THREADIDX < 50) && (isnan(ret))) printf("NaN final component %f %f\n", last, totalWeight); - //if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("Add final: %f * %f * %f = %f (%f)\n", (1 - totalWeight), last, normalisationFactors[indices[numParameters]], (1 - totalWeight) *last* normalisationFactors[indices[numParameters]], ret); + // if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("Add final: %f * %f * %f = %f (%f)\n", (1 - totalWeight), last, + // normalisationFactors[indices[numParameters]], (1 - totalWeight) *last* + // normalisationFactors[indices[numParameters]], ret); return ret; } -__device__ fptype device_AddPdfsExt(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_AddPdfsExt(fptype *evt, fptype *p, unsigned int *indices) { // numParameters does not count itself. So the array structure for two functions is // nP | F P w | F P w // in which nP = 6. - int numParameters = RO_CACHE(indices[0]); - fptype ret = 0; + int numParameters = RO_CACHE(indices[0]); + fptype ret = 0; fptype totalWeight = 0; for(int i = 1; i < numParameters; i += 3) { - //fptype curr = (*(reinterpret_cast(device_function_table[indices[i]])))(evt, p, paramIndices + indices[i+1]); - fptype curr = callFunction(evt, RO_CACHE(indices[i]), RO_CACHE(indices[i+1])); - fptype weight = RO_CACHE(p[RO_CACHE(indices[i+2])]); - ret += weight * curr * normalisationFactors[RO_CACHE(indices[i+1])]; + // fptype curr = (*(reinterpret_cast(device_function_table[indices[i]])))(evt, p, + // paramIndices + indices[i+1]); + fptype curr = callFunction(evt, RO_CACHE(indices[i]), RO_CACHE(indices[i + 1])); + fptype weight = RO_CACHE(p[RO_CACHE(indices[i + 2])]); + ret += weight * curr * normalisationFactors[RO_CACHE(indices[i + 1])]; totalWeight += weight; - //if ((gpuDebug & 1) && (THREADIDX == 0) && (0 == BLOCKIDX)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("AddExt: %i %E %f %f %f %f %f %f\n", i, curr, weight, ret, totalWeight, normalisationFactors[indices[i+1]], evt[0], evt[8]); + // if ((gpuDebug & 1) && (THREADIDX == 0) && (0 == BLOCKIDX)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("AddExt: %i %E %f %f %f %f %f %f\n", i, curr, weight, ret, totalWeight, + // normalisationFactors[indices[i+1]], evt[0], evt[8]); } ret /= totalWeight; - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //if ((gpuDebug & 1) && (THREADIDX == 0) && (0 == BLOCKIDX)) - //printf("AddExt result: %f\n", ret); + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // if ((gpuDebug & 1) && (THREADIDX == 0) && (0 == BLOCKIDX)) + // printf("AddExt result: %f\n", ret); return ret; } -__device__ device_function_ptr ptr_to_AddPdfs = device_AddPdfs; +__device__ device_function_ptr ptr_to_AddPdfs = device_AddPdfs; __device__ device_function_ptr ptr_to_AddPdfsExt = device_AddPdfsExt; -AddPdf::AddPdf(std::string n, std::vector weights, std::vector comps) +AddPdf::AddPdf(std::string n, std::vector weights, std::vector comps) : GooPdf(nullptr, n) , extended(true) { - - if(weights.size() != comps.size() && (weights.size()+1) != comps.size()) + if(weights.size() != comps.size() && (weights.size() + 1) != comps.size()) throw GooFit::GeneralError("Size of weights {} (+1) != comps {}", weights.size(), comps.size()); - // Indices stores (function index)(function parameter index)(weight index) triplet for each component. // Last component has no weight index unless function is extended. - for(PdfBase* p : comps) { + for(PdfBase *p : comps) { components.push_back(p); if(components.back() == nullptr) throw GooFit::GeneralError("Invalid component"); - } observables = getObservables(); @@ -114,7 +117,6 @@ AddPdf::AddPdf(std::string n, std::vector weights, std::vector weights, std::vectornormalize(); - ret += curr*weight; + ret += curr * weight; } fptype last = components.back()->normalize(); if(extended) { - fptype lastWeight = host_params[host_indices[parameters + 3*components.size()]]; + fptype lastWeight = host_params[host_indices[parameters + 3 * components.size()]]; totalWeight += lastWeight; ret += last * lastWeight; ret /= totalWeight; @@ -182,66 +183,75 @@ __host__ fptype AddPdf::normalize() const { } } - //if (cpuDebug & 1) std::cout << getName() << " integral returning " << ret << std::endl; + // if (cpuDebug & 1) std::cout << getName() << " integral returning " << ret << std::endl; return ret; } __host__ double AddPdf::sumOfNll(int numVars) const { static thrust::plus cudaPlus; thrust::constant_iterator eventSize(numVars); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); double dummy = 0; thrust::counting_iterator eventIndex(0); double ret; #ifdef GOOFIT_MPI -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - double r = thrust::transform_reduce(my_policy, thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, - eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + double r = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #else - double r = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, - eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + double r = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #endif MPI_Allreduce(&r, &ret, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); #else -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - ret = thrust::transform_reduce(my_policy, thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, - eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + ret = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #else - ret = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, - eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + ret = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #endif #endif - if(extended) { fptype expEvents = 0; - //std::cout << "Weights:"; + // std::cout << "Weights:"; for(unsigned int i = 0; i < components.size(); ++i) { - expEvents += host_params[host_indices[parameters + 3*(i+1)]]; - //std::cout << " " << host_params[host_indices[parameters + 3*(i+1)]]; + expEvents += host_params[host_indices[parameters + 3 * (i + 1)]]; + // std::cout << " " << host_params[host_indices[parameters + 3*(i+1)]]; } // Log-likelihood of numEvents with expectation of exp is (-exp + numEvents*ln(exp) - ln(numEvents!)). // The last is constant, so we drop it; and then multiply by minus one to get the negative log-likelihood. - ret += (expEvents - numEvents*log(expEvents)); - //std::cout << " " << expEvents << " " << numEvents << " " << (expEvents - numEvents*log(expEvents)) << std::endl; + ret += (expEvents - numEvents * log(expEvents)); + // std::cout << " " << expEvents << " " << numEvents << " " << (expEvents - numEvents*log(expEvents)) << + // std::endl; } return ret; } } // namespace GooFit - diff --git a/src/PDFs/AllPdfs.cu b/src/PDFs/AllPdfs.cu index b05359066..65e6c173a 100644 --- a/src/PDFs/AllPdfs.cu +++ b/src/PDFs/AllPdfs.cu @@ -43,7 +43,4 @@ #include "TruthResolution_Aux.cu" #include "ThreeGaussResolution_Aux.cu" -namespace GooFit { - -} // namespace GooFit - +namespace GooFit {} // namespace GooFit diff --git a/src/PDFs/ArgusPdf.cu b/src/PDFs/ArgusPdf.cu index 79a8a3e7e..8ed9399ae 100644 --- a/src/PDFs/ArgusPdf.cu +++ b/src/PDFs/ArgusPdf.cu @@ -3,9 +3,8 @@ namespace GooFit { - -__device__ fptype device_Argus_Upper(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; +__device__ fptype device_Argus_Upper(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; fptype m0 = p[indices[1]]; double t = x / m0; @@ -15,19 +14,19 @@ __device__ fptype device_Argus_Upper(fptype* evt, fptype* p, unsigned int* indic fptype slope = p[indices[2]]; fptype power = p[indices[3]]; - t = 1 - t*t; - //printf("device_Argus_Upper %f %f %f %f %f\n", x, m0, slope, t, x * pow(t, power) * exp(slope * t)); + t = 1 - t * t; + // printf("device_Argus_Upper %f %f %f %f %f\n", x, m0, slope, t, x * pow(t, power) * exp(slope * t)); return x * pow(t, power) * exp(slope * t); } -__device__ fptype device_Argus_Lower(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; +__device__ fptype device_Argus_Lower(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; fptype m0 = p[indices[1]]; - //printf("Argus: %i %i %f %f\n", indices[0], indices[2 + indices[0]], x, m0); - //printf("Argus: %i %i\n", indices[0], indices[2 + indices[0]]); - //return 1; + // printf("Argus: %i %i %f %f\n", indices[0], indices[2 + indices[0]], x, m0); + // printf("Argus: %i %i\n", indices[0], indices[2 + indices[0]]); + // return 1; fptype t = x / m0; @@ -39,21 +38,21 @@ __device__ fptype device_Argus_Lower(fptype* evt, fptype* p, unsigned int* indic fptype slope = p[indices[2]]; fptype power = p[indices[3]]; - fptype ret = x * pow(t, power) * exp(slope * t); - //if ((0 == THREADIDX) && (0 == BLOCKIDX) && (callnumber < 1)) cuPrintf("device_Argus_Lower %i %i %f %f %f %f %f\n", indices[1], indices[2], x, m0, slope, t, ret); - //if (isnan(ret)) printf("NaN Argus: %f %f %f %f %f %f %f\n", x, m0, t, slope, power, pow(t, power), exp(slope*t)); - //if ((0 == THREADIDX) && (0 == BLOCKIDX) && (gpuDebug & 1)) - //printf("(%i, %i) device_Argus_Lower %f %f %f %f %f\n", BLOCKIDX, THREADIDX, x, m0, slope, t, x * pow(t, power) * exp(slope * t)); - + fptype ret = x * pow(t, power) * exp(slope * t); + // if ((0 == THREADIDX) && (0 == BLOCKIDX) && (callnumber < 1)) cuPrintf("device_Argus_Lower %i %i %f %f %f %f + // %f\n", indices[1], indices[2], x, m0, slope, t, ret); + // if (isnan(ret)) printf("NaN Argus: %f %f %f %f %f %f %f\n", x, m0, t, slope, power, pow(t, power), exp(slope*t)); + // if ((0 == THREADIDX) && (0 == BLOCKIDX) && (gpuDebug & 1)) + // printf("(%i, %i) device_Argus_Lower %f %f %f %f %f\n", BLOCKIDX, THREADIDX, x, m0, slope, t, x * pow(t, power) * + // exp(slope * t)); return ret; - } __device__ device_function_ptr ptr_to_Argus_Upper = device_Argus_Upper; __device__ device_function_ptr ptr_to_Argus_Lower = device_Argus_Lower; -__host__ ArgusPdf::ArgusPdf(std::string n, Variable* _x, Variable* m0, Variable* slope, bool upper, Variable* power) +__host__ ArgusPdf::ArgusPdf(std::string n, Variable *_x, Variable *m0, Variable *slope, bool upper, Variable *power) : GooPdf(_x, n) { registerParameter(m0); registerParameter(slope); @@ -91,11 +90,11 @@ fptype argus_lower_helper(fptype x, fptype m0, fptype slope, fptype power) { } __host__ double ArgusPdf::integrate(fptype lo, fptype hi) const { - double norm = 0; - unsigned int* indices = host_indices+parameters; - fptype m0 = host_params[indices[1]]; - fptype slope = host_params[indices[2]]; - fptype power = host_params[indices[3]]; + double norm = 0; + unsigned int *indices = host_indices + parameters; + fptype m0 = host_params[indices[1]]; + fptype slope = host_params[indices[2]]; + fptype power = host_params[indices[3]]; for(int j = 0; j < integrationBins; ++j) { double x = hi; @@ -110,4 +109,3 @@ __host__ double ArgusPdf::integrate(fptype lo, fptype hi) const { return norm; } } // namespace GooFit - diff --git a/src/PDFs/BWPdf.cu b/src/PDFs/BWPdf.cu index 0718dc744..f0f1cf779 100644 --- a/src/PDFs/BWPdf.cu +++ b/src/PDFs/BWPdf.cu @@ -2,19 +2,18 @@ namespace GooFit { - -__device__ fptype device_BW(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; - fptype mean = p[indices[1]]; - fptype gamma = p[indices[2]]; - fptype rootPi = -2.*atan2(-1.0, 0.0); - fptype ret = (gamma/((x-mean)*(x-mean) + gamma*gamma/4))/(2*rootPi); +__device__ fptype device_BW(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; + fptype mean = p[indices[1]]; + fptype gamma = p[indices[2]]; + fptype rootPi = -2. * atan2(-1.0, 0.0); + fptype ret = (gamma / ((x - mean) * (x - mean) + gamma * gamma / 4)) / (2 * rootPi); return ret; } __device__ device_function_ptr ptr_to_BW = device_BW; -__host__ BWPdf::BWPdf(std::string n, Variable* _x, Variable* mean, Variable* width) +__host__ BWPdf::BWPdf(std::string n, Variable *_x, Variable *mean, Variable *width) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -23,4 +22,3 @@ __host__ BWPdf::BWPdf(std::string n, Variable* _x, Variable* mean, Variable* wid initialize(pindices); } } // namespace GooFit - diff --git a/src/PDFs/BifurGaussPdf.cu b/src/PDFs/BifurGaussPdf.cu index 087001585..7a4a82c9e 100644 --- a/src/PDFs/BifurGaussPdf.cu +++ b/src/PDFs/BifurGaussPdf.cu @@ -2,11 +2,10 @@ namespace GooFit { - -__device__ fptype device_BifurGauss(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; // why does indices recall itself? - fptype mean = p[indices[1]]; - fptype sigmaLeft = p[indices[2]]; +__device__ fptype device_BifurGauss(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; // why does indices recall itself? + fptype mean = p[indices[1]]; + fptype sigmaLeft = p[indices[2]]; fptype sigmaRight = p[indices[3]]; // how to calculate the value of a bifurcated gaussian? @@ -15,13 +14,13 @@ __device__ fptype device_BifurGauss(fptype* evt, fptype* p, unsigned int* indice if(x > mean) sigma = sigmaRight; - fptype ret = exp(-0.5*(x-mean)*(x-mean)/(sigma*sigma)); + fptype ret = exp(-0.5 * (x - mean) * (x - mean) / (sigma * sigma)); return ret; } __device__ device_function_ptr ptr_to_BifurGauss = device_BifurGauss; -__host__ BifurGaussPdf::BifurGaussPdf(std::string n, Variable* _x, Variable* mean, Variable* sigmaL, Variable* sigmaR) +__host__ BifurGaussPdf::BifurGaussPdf(std::string n, Variable *_x, Variable *mean, Variable *sigmaL, Variable *sigmaR) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -34,17 +33,15 @@ __host__ BifurGaussPdf::BifurGaussPdf(std::string n, Variable* _x, Variable* mea // q: how shall the normalization of a bifurcated gaussian be calculated? // a: a "sum" of two half-gaussians? __host__ fptype BifurGaussPdf::integrate(fptype lo, fptype hi) const { - - unsigned int* indices = host_indices + - parameters; // look at the global indexes vector starting at the parameters of this function + unsigned int *indices + = host_indices + parameters; // look at the global indexes vector starting at the parameters of this function fptype sL = host_params[indices[2]]; fptype sR = host_params[indices[3]]; - fptype normL = 1./(sqrt(2*M_PI)*sL); - fptype normR = 1./(sqrt(2*M_PI)*sR); + fptype normL = 1. / (sqrt(2 * M_PI) * sL); + fptype normR = 1. / (sqrt(2 * M_PI) * sR); - return .5* normL + .5*normR; + return .5 * normL + .5 * normR; } } // namespace GooFit - diff --git a/src/PDFs/BinTransformPdf.cu b/src/PDFs/BinTransformPdf.cu index 4f6c235d5..37db62949 100644 --- a/src/PDFs/BinTransformPdf.cu +++ b/src/PDFs/BinTransformPdf.cu @@ -2,21 +2,21 @@ namespace GooFit { - -__device__ fptype device_BinTransform(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_BinTransform(fptype *evt, fptype *p, unsigned int *indices) { // Index structure: nP lim1 bin1 lim2 bin2 ... nO o1 o2 int numObservables = indices[1 + indices[0]]; - int ret = 0; - int previousSize = 1; + int ret = 0; + int previousSize = 1; - //printf("[%i, %i] Bin Transform: %i %i %f %f\n", THREADIDX, BLOCKIDX, numObservables, previousSize, evt[0], evt[1]); + // printf("[%i, %i] Bin Transform: %i %i %f %f\n", THREADIDX, BLOCKIDX, numObservables, previousSize, evt[0], + // evt[1]); for(int i = 0; i < numObservables; ++i) { fptype obsValue = evt[indices[2 + indices[0] + i]]; - fptype lowerLimit = functorConstants[indices[i*3+1]]; - fptype binSize = functorConstants[indices[i*3+2]]; - int numBins = indices[i*3+3]; + fptype lowerLimit = functorConstants[indices[i * 3 + 1]]; + fptype binSize = functorConstants[indices[i * 3 + 2]]; + int numBins = indices[i * 3 + 3]; - auto localBin = static_cast( floor((obsValue - lowerLimit) / binSize)); + auto localBin = static_cast(floor((obsValue - lowerLimit) / binSize)); ret += localBin * previousSize; previousSize *= numBins; } @@ -27,27 +27,30 @@ __device__ fptype device_BinTransform(fptype* evt, fptype* p, unsigned int* indi __device__ device_function_ptr ptr_to_BinTransform = device_BinTransform; // Notice that bin sizes and limits can be different, for this purpose, than what's implied by the Variable members. -__host__ BinTransformPdf::BinTransformPdf(std::string n, std::vector obses, +__host__ BinTransformPdf::BinTransformPdf(std::string n, + std::vector obses, std::vector limits, std::vector binSizes, std::vector numBins) : GooPdf(nullptr, n) { - - cIndex = registerConstants(2*obses.size()); - auto* host_constants = new fptype[2*obses.size()]; + cIndex = registerConstants(2 * obses.size()); + auto *host_constants = new fptype[2 * obses.size()]; std::vector pindices; for(unsigned int i = 0; i < obses.size(); ++i) { registerObservable(obses[i]); - pindices.push_back(cIndex + 2*i); - pindices.push_back(cIndex + 2*i + 1); + pindices.push_back(cIndex + 2 * i); + pindices.push_back(cIndex + 2 * i + 1); pindices.push_back(numBins[i]); - host_constants[2*i] = limits[i]; // cIndex will be accounted for by offset in memcpy - host_constants[2*i+1] = binSizes[i]; + host_constants[2 * i] = limits[i]; // cIndex will be accounted for by offset in memcpy + host_constants[2 * i + 1] = binSizes[i]; } - MEMCPY_TO_SYMBOL(functorConstants, host_constants, 2*obses.size()*sizeof(fptype), cIndex*sizeof(fptype), + MEMCPY_TO_SYMBOL(functorConstants, + host_constants, + 2 * obses.size() * sizeof(fptype), + cIndex * sizeof(fptype), cudaMemcpyHostToDevice); delete[] host_constants; @@ -55,6 +58,4 @@ __host__ BinTransformPdf::BinTransformPdf(std::string n, std::vector initialize(pindices); } - } // namespace GooFit - diff --git a/src/PDFs/CompositePdf.cu b/src/PDFs/CompositePdf.cu index a8675d6de..c81cfe96f 100644 --- a/src/PDFs/CompositePdf.cu +++ b/src/PDFs/CompositePdf.cu @@ -2,19 +2,19 @@ namespace GooFit { - -__device__ fptype device_Composite(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Composite(fptype *evt, fptype *p, unsigned int *indices) { unsigned int coreFcnIndex = RO_CACHE(indices[1]); unsigned int coreParIndex = RO_CACHE(indices[2]); unsigned int shellFcnIndex = RO_CACHE(indices[3]); unsigned int shellParIndex = RO_CACHE(indices[4]); // NB, not normalising core function, it is not being used as a PDF. - //fptype coreValue = (*(reinterpret_cast(device_function_table[coreFcnIndex])))(evt, cudaArray, paramIndices+coreParIndex); + // fptype coreValue = (*(reinterpret_cast(device_function_table[coreFcnIndex])))(evt, + // cudaArray, paramIndices+coreParIndex); fptype coreValue = callFunction(evt, coreFcnIndex, coreParIndex); - unsigned int* shellParams = paramIndices + shellParIndex; - unsigned int numShellPars = shellParams[0]; + unsigned int *shellParams = paramIndices + shellParIndex; + unsigned int numShellPars = shellParams[0]; unsigned int shellObsIndex = shellParams[2 + numShellPars]; fptype fakeEvt[10]; // Allow plenty of space in case events are large. @@ -22,18 +22,19 @@ __device__ fptype device_Composite(fptype* evt, fptype* p, unsigned int* indices // Don't normalize shell either, since we don't know what composite function is being used for. // It may not be a PDF. Normalising at this stage would be presumptuous. - //fptype ret = (*(reinterpret_cast(device_function_table[shellFcnIndex])))(fakeEvt, cudaArray, shellParams); + // fptype ret = (*(reinterpret_cast(device_function_table[shellFcnIndex])))(fakeEvt, cudaArray, + // shellParams); fptype ret = callFunction(fakeEvt, shellFcnIndex, shellParIndex); - //if (0 == THREADIDX) - //printf("Composite: %f %f %f %f %f %f\n", evt[4], evt[5], evt[6], evt[7], coreValue, ret); + // if (0 == THREADIDX) + // printf("Composite: %f %f %f %f %f %f\n", evt[4], evt[5], evt[6], evt[7], coreValue, ret); return ret; } __device__ device_function_ptr ptr_to_Composite = device_Composite; -__host__ CompositePdf::CompositePdf(std::string n, PdfBase* core, PdfBase* shell) +__host__ CompositePdf::CompositePdf(std::string n, PdfBase *core, PdfBase *shell) : GooPdf(nullptr, n) { std::vector pindices; pindices.push_back(core->getFunctionIndex()); @@ -73,7 +74,5 @@ __host__ fptype CompositePdf::normalize() const { // Normalize composite in the usual binned-integral way. return GooPdf::normalize(); - } } // namespace GooFit - diff --git a/src/PDFs/ConvolutionPdf.cu b/src/PDFs/ConvolutionPdf.cu index 7ef557292..1cf537de5 100644 --- a/src/PDFs/ConvolutionPdf.cu +++ b/src/PDFs/ConvolutionPdf.cu @@ -1,13 +1,12 @@ #include "goofit/PDFs/combine/ConvolutionPdf.h" -#include "goofit/Variable.h" #include "goofit/Error.h" +#include "goofit/Variable.h" #include #include namespace GooFit { - int totalConvolutions = 0; #define CONVOLUTION_CACHE_SIZE 512 @@ -17,26 +16,26 @@ int totalConvolutions = 0; // goes wrong. So... 512 should be enough for anyone, right? // Need multiple working spaces for the case of several convolutions in one PDF. -__constant__ fptype* dev_modWorkSpace[100]; -__constant__ fptype* dev_resWorkSpace[100]; +__constant__ fptype *dev_modWorkSpace[100]; +__constant__ fptype *dev_resWorkSpace[100]; // Number which transforms model range (x1, x2) into resolution range (x1 - maxX, x2 - minX). // It is equal to the maximum possible value of x0, ie maxX, in bins. __constant__ int modelOffset[100]; -__device__ fptype device_ConvolvePdfs(fptype* evt, fptype* p, unsigned int* indices) { - fptype ret = 0; - fptype loBound = RO_CACHE(functorConstants[RO_CACHE(indices[5])+0]); - fptype hiBound = RO_CACHE(functorConstants[RO_CACHE(indices[5])+1]); - fptype step = RO_CACHE(functorConstants[RO_CACHE(indices[5])+2]); - fptype x0 = evt[indices[2 + indices[0]]]; +__device__ fptype device_ConvolvePdfs(fptype *evt, fptype *p, unsigned int *indices) { + fptype ret = 0; + fptype loBound = RO_CACHE(functorConstants[RO_CACHE(indices[5]) + 0]); + fptype hiBound = RO_CACHE(functorConstants[RO_CACHE(indices[5]) + 1]); + fptype step = RO_CACHE(functorConstants[RO_CACHE(indices[5]) + 2]); + fptype x0 = evt[indices[2 + indices[0]]]; int workSpaceIndex = indices[6]; - auto numbins = static_cast( floor((hiBound - loBound) / step + 0.5)); + auto numbins = static_cast(floor((hiBound - loBound) / step + 0.5)); fptype lowerBoundOffset = loBound / step; lowerBoundOffset -= floor(lowerBoundOffset); - auto offsetInBins = static_cast( floor(x0 / step - lowerBoundOffset)); + auto offsetInBins = static_cast(floor(x0 / step - lowerBoundOffset)); // Brute-force calculate integral M(x) * R(x - x0) dx int offset = RO_CACHE(modelOffset[workSpaceIndex]); @@ -45,7 +44,7 @@ __device__ fptype device_ConvolvePdfs(fptype* evt, fptype* p, unsigned int* indi fptype model = RO_CACHE(dev_modWorkSpace[workSpaceIndex][i]); fptype resol = RO_CACHE(dev_resWorkSpace[workSpaceIndex][i + offset - offsetInBins]); - ret += model*resol; + ret += model * resol; } ret *= normalisationFactors[RO_CACHE(indices[2])]; @@ -54,25 +53,26 @@ __device__ fptype device_ConvolvePdfs(fptype* evt, fptype* p, unsigned int* indi return ret; } -__device__ fptype device_ConvolveSharedPdfs(fptype* evt, fptype* p, unsigned int* indices) { - fptype ret = 0; - fptype loBound = functorConstants[indices[5]+0]; - fptype hiBound = functorConstants[indices[5]+1]; - fptype step = functorConstants[indices[5]+2]; - fptype x0 = evt[indices[2 + indices[0]]]; +__device__ fptype device_ConvolveSharedPdfs(fptype *evt, fptype *p, unsigned int *indices) { + fptype ret = 0; + fptype loBound = functorConstants[indices[5] + 0]; + fptype hiBound = functorConstants[indices[5] + 1]; + fptype step = functorConstants[indices[5] + 2]; + fptype x0 = evt[indices[2 + indices[0]]]; unsigned int workSpaceIndex = indices[6]; - unsigned int numOthers = indices[7] + 1; // +1 for this PDF. + unsigned int numOthers = indices[7] + 1; // +1 for this PDF. - auto numbins = static_cast( floor((hiBound - loBound) / step + 0.5)); + auto numbins = static_cast(floor((hiBound - loBound) / step + 0.5)); fptype lowerBoundOffset = loBound / step; lowerBoundOffset -= floor(lowerBoundOffset); - auto offsetInBins = static_cast( floor(x0 / step - lowerBoundOffset)); + auto offsetInBins = static_cast(floor(x0 / step - lowerBoundOffset)); // Brute-force calculate integral M(x) * R(x - x0) dx __shared__ fptype modelCache[CONVOLUTION_CACHE_SIZE]; // Don't try to shared-load more items than we have threads. - int numToLoad = thrust::minimum()(CONVOLUTION_CACHE_SIZE / numOthers, static_cast(BLOCKDIM)); + int numToLoad + = thrust::minimum()(CONVOLUTION_CACHE_SIZE / numOthers, static_cast(BLOCKDIM)); for(int i = 0; i < numbins; i += numToLoad) { // This code avoids this problem: If event 0 is in workspace 0, and @@ -85,7 +85,8 @@ __device__ fptype device_ConvolveSharedPdfs(fptype* evt, fptype* p, unsigned int if(THREADIDX < numToLoad) { for(unsigned int w = 0; w < numOthers; ++w) { unsigned int wIndex = indices[8 + w]; - modelCache[w*numToLoad + THREADIDX] = (i + THREADIDX < numbins) ? dev_modWorkSpace[wIndex][i + THREADIDX] : 0; + modelCache[w * numToLoad + THREADIDX] + = (i + THREADIDX < numbins) ? dev_modWorkSpace[wIndex][i + THREADIDX] : 0; } } @@ -101,9 +102,11 @@ __device__ fptype device_ConvolveSharedPdfs(fptype* evt, fptype* p, unsigned int if(i + j >= numbins) break; - fptype model = modelCache[workSpaceIndex*numToLoad + j]; - fptype resol = (model != 0) ? dev_resWorkSpace[workSpaceIndex][i + j + modelOffset[workSpaceIndex] - offsetInBins] : 0; - ret += model*resol; + fptype model = modelCache[workSpaceIndex * numToLoad + j]; + fptype resol = (model != 0) + ? dev_resWorkSpace[workSpaceIndex][i + j + modelOffset[workSpaceIndex] - offsetInBins] + : 0; + ret += model * resol; } // If we don't sync at this point, some of the warps can *run ahead* @@ -119,13 +122,10 @@ __device__ fptype device_ConvolveSharedPdfs(fptype* evt, fptype* p, unsigned int return ret; } -__device__ device_function_ptr ptr_to_ConvolvePdfs = device_ConvolvePdfs; +__device__ device_function_ptr ptr_to_ConvolvePdfs = device_ConvolvePdfs; __device__ device_function_ptr ptr_to_ConvolveSharedPdfs = device_ConvolveSharedPdfs; -ConvolutionPdf::ConvolutionPdf(std::string n, - Variable* x, - GooPdf* m, - GooPdf* r) +ConvolutionPdf::ConvolutionPdf(std::string n, Variable *x, GooPdf *m, GooPdf *r) : GooPdf(x, n) , model(m) , resolution(r) @@ -153,11 +153,7 @@ ConvolutionPdf::ConvolutionPdf(std::string n, setIntegrationConstants(-10, 10, 0.01); } -ConvolutionPdf::ConvolutionPdf(std::string n, - Variable* x, - GooPdf* m, - GooPdf* r, - unsigned int numOthers) +ConvolutionPdf::ConvolutionPdf(std::string n, Variable *x, GooPdf *m, GooPdf *r, unsigned int numOthers) : GooPdf(x, n) , model(m) , resolution(r) @@ -193,14 +189,15 @@ ConvolutionPdf::ConvolutionPdf(std::string n, else { properlyInitialised = false; - for(unsigned int i = 0; i < numOthers+1; ++i) { // Notice extra space for this PDF's index. + for(unsigned int i = 0; i < numOthers + 1; ++i) { // Notice extra space for this PDF's index. // Fill in later - must be done before setData call. paramIndices.push_back(0); } } if(numOthers > CONVOLUTION_CACHE_SIZE) - throw GooFit::GeneralError("numOthers {} must be not be more than the cache size {}", numOthers, CONVOLUTION_CACHE_SIZE); + throw GooFit::GeneralError( + "numOthers {} must be not be more than the cache size {}", numOthers, CONVOLUTION_CACHE_SIZE); GET_FUNCTION_ADDR(ptr_to_ConvolveSharedPdfs); initialize(paramIndices); @@ -210,20 +207,21 @@ ConvolutionPdf::ConvolutionPdf(std::string n, __host__ void ConvolutionPdf::setIntegrationConstants(fptype lo, fptype hi, fptype step) { if(!host_iConsts) { host_iConsts = new fptype[6]; - gooMalloc(reinterpret_cast( &dev_iConsts), 6*sizeof(fptype)); + gooMalloc(reinterpret_cast(&dev_iConsts), 6 * sizeof(fptype)); } host_iConsts[0] = lo; host_iConsts[1] = hi; host_iConsts[2] = step; - MEMCPY_TO_SYMBOL(functorConstants, host_iConsts, 3*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + functorConstants, host_iConsts, 3 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); if(modelWorkSpace) { delete modelWorkSpace; delete resolWorkSpace; } - auto numbins = static_cast( floor((host_iConsts[1] - host_iConsts[0]) / step + 0.5)); + auto numbins = static_cast(floor((host_iConsts[1] - host_iConsts[0]) / step + 0.5)); // Different format for integration range! modelWorkSpace = new thrust::device_vector(numbins); @@ -233,43 +231,42 @@ __host__ void ConvolutionPdf::setIntegrationConstants(fptype lo, fptype hi, fpty // x2-minX, and the min and max are given by the dependent variable. // However, the step must be the same as for the model, or the binning // will get out of sync. - Variable* dependent = *(observables.begin()); + Variable *dependent = *(observables.begin()); host_iConsts[2] = numbins; host_iConsts[3] = (host_iConsts[0] - dependent->getUpperLimit()); host_iConsts[4] = (host_iConsts[1] - dependent->getLowerLimit()); - numbins = static_cast( floor((host_iConsts[4] - host_iConsts[3]) / step + 0.5)); + numbins = static_cast(floor((host_iConsts[4] - host_iConsts[3]) / step + 0.5)); host_iConsts[5] = numbins; - MEMCPY(dev_iConsts, host_iConsts, 6*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY(dev_iConsts, host_iConsts, 6 * sizeof(fptype), cudaMemcpyHostToDevice); resolWorkSpace = new thrust::device_vector(numbins); int offset = dependent->getUpperLimit() / step; - MEMCPY_TO_SYMBOL(modelOffset, &offset, sizeof(int), workSpaceIndex*sizeof(int), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(modelOffset, &offset, sizeof(int), workSpaceIndex * sizeof(int), cudaMemcpyHostToDevice); - fptype* dev_address[1]; + fptype *dev_address[1]; dev_address[0] = (&((*modelWorkSpace)[0])).get(); - MEMCPY_TO_SYMBOL(dev_modWorkSpace, dev_address, sizeof(fptype*), workSpaceIndex*sizeof(fptype*), - cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + dev_modWorkSpace, dev_address, sizeof(fptype *), workSpaceIndex * sizeof(fptype *), cudaMemcpyHostToDevice); dev_address[0] = (&((*resolWorkSpace)[0])).get(); - MEMCPY_TO_SYMBOL(dev_resWorkSpace, dev_address, sizeof(fptype*), workSpaceIndex*sizeof(fptype*), - cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + dev_resWorkSpace, dev_address, sizeof(fptype *), workSpaceIndex * sizeof(fptype *), cudaMemcpyHostToDevice); } -__host__ void ConvolutionPdf::registerOthers(std::vector others) { +__host__ void ConvolutionPdf::registerOthers(std::vector others) { unsigned int numExpectedOthers = host_indices[parameters + 7] + 1; if(numExpectedOthers != others.size()) { - std::cout << "Problem: " << getName() << " initialized with " << others.size() - << " other PDFs, expected " << numExpectedOthers - << " (including itself). Returning without initialisation.\n"; + std::cout << "Problem: " << getName() << " initialized with " << others.size() << " other PDFs, expected " + << numExpectedOthers << " (including itself). Returning without initialization.\n"; return; } bool foundSelf = false; for(unsigned int i = 0; i < others.size(); ++i) { - ConvolutionPdf* curr = others[i]; + ConvolutionPdf *curr = others[i]; if(curr == this) foundSelf = true; @@ -278,8 +275,8 @@ __host__ void ConvolutionPdf::registerOthers(std::vector others } if(!foundSelf) { - std::cout << "Problem: " << getName() << - " initialized with list that did not include itself. Returning without initialisation.\n"; + std::cout << "Problem: " << getName() + << " initialized with list that did not include itself. Returning without initialisation.\n"; return; } @@ -287,24 +284,25 @@ __host__ void ConvolutionPdf::registerOthers(std::vector others } __host__ fptype ConvolutionPdf::normalize() const { - //if (cpuDebug & 1) std::cout << getName() << " entering normalisation\n"; + // if (cpuDebug & 1) std::cout << getName() << " entering normalisation\n"; // First set normalisation factors to one so we can evaluate convolution without getting zeroes recursiveSetNormalisation(fptype(1.0)); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); // Next recalculate functions at each point, in preparation for convolution integral - thrust::constant_iterator arrayAddress(dev_iConsts); + thrust::constant_iterator arrayAddress(dev_iConsts); thrust::constant_iterator eventSize(1); thrust::counting_iterator binIndex(0); if(model->parametersChanged()) { // Calculate model function at every point in integration space MetricTaker modalor(model, getMetricPointer("ptr_to_Eval")); - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + modelWorkSpace->size(), eventSize, arrayAddress)), - modelWorkSpace->begin(), - modalor); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + modelWorkSpace->size(), eventSize, arrayAddress)), + modelWorkSpace->begin(), + modalor); cudaDeviceSynchronize(); /* if ((cpuDebug & 1) && (5 == workSpaceIndex)) { @@ -319,22 +317,20 @@ __host__ fptype ConvolutionPdf::normalize() const { if(resolution->parametersChanged()) { // Same for resolution function. - thrust::constant_iterator arrayAddress2(dev_iConsts + 3); + thrust::constant_iterator arrayAddress2(dev_iConsts + 3); MetricTaker resalor(resolution, getMetricPointer("ptr_to_Eval")); - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress2)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + resolWorkSpace->size(), eventSize, arrayAddress2)), - resolWorkSpace->begin(), - resalor); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress2)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + resolWorkSpace->size(), eventSize, arrayAddress2)), + resolWorkSpace->begin(), + resalor); } - //cudaDeviceSynchronize(); + // cudaDeviceSynchronize(); // Then return usual integral fptype ret = GooPdf::normalize(); return ret; } - - } // namespace GooFit - diff --git a/src/PDFs/CorrGaussianPdf.cu b/src/PDFs/CorrGaussianPdf.cu index 99788a38f..b0deeda6c 100644 --- a/src/PDFs/CorrGaussianPdf.cu +++ b/src/PDFs/CorrGaussianPdf.cu @@ -2,34 +2,42 @@ namespace GooFit { - -__device__ fptype device_CorrGaussian(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; - fptype y = evt[indices[3 + indices[0]]]; +__device__ fptype device_CorrGaussian(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; + fptype y = evt[indices[3 + indices[0]]]; fptype mean1 = p[indices[1]]; fptype sigma1 = p[indices[2]]; fptype mean2 = p[indices[3]]; fptype sigma2 = p[indices[4]]; fptype corr = p[indices[5]]; - fptype x_dist = (x-mean1) / sigma1; - sigma2 *= (1 + corr*x_dist*x_dist); + fptype x_dist = (x - mean1) / sigma1; + sigma2 *= (1 + corr * x_dist * x_dist); fptype y_dist = (y - mean2) * (sigma2 == 0 ? 0 : (1.0 / sigma2)); - fptype ret = exp(-0.5*(x_dist * x_dist + y_dist * y_dist)); + fptype ret = exp(-0.5 * (x_dist * x_dist + y_dist * y_dist)); - //if ((gpuDebug & 1) && (THREADIDX == 60)) printf("CorrGauss: %f %f %f %f %f %f %f %f %f %.12f\n", x, y, mean1, sigma1, mean2, sigma2, corr, x_dist, y_dist, ret); - //if ((gpuDebug & 1) && (THREADIDX == 60)) printf("[%i, %i] [%i, %i] CorrGauss: %f %f %f\n", BLOCKIDX, THREADIDX, gridDim.x, BLOCKDIM, x, y, ret); - //printf("CorrGauss: %i %i %i %f %f %f %f\n", indices[2 + indices[0]], indices[3 + indices[0]], indices[0], x, y, mean1, mean2); + // if ((gpuDebug & 1) && (THREADIDX == 60)) printf("CorrGauss: %f %f %f %f %f %f %f %f %f %.12f\n", x, y, mean1, + // sigma1, mean2, sigma2, corr, x_dist, y_dist, ret); + // if ((gpuDebug & 1) && (THREADIDX == 60)) printf("[%i, %i] [%i, %i] CorrGauss: %f %f %f\n", BLOCKIDX, THREADIDX, + // gridDim.x, BLOCKDIM, x, y, ret); + // printf("CorrGauss: %i %i %i %f %f %f %f\n", indices[2 + indices[0]], indices[3 + indices[0]], indices[0], x, y, + // mean1, mean2); return ret; } __device__ device_function_ptr ptr_to_CorrGaussian = device_CorrGaussian; -__host__ CorrGaussianPdf::CorrGaussianPdf(std::string n, Variable* _x, Variable* _y, Variable* mean1, Variable* sigma1, - Variable* mean2, Variable* sigma2, Variable* correlation) +__host__ CorrGaussianPdf::CorrGaussianPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *mean1, + Variable *sigma1, + Variable *mean2, + Variable *sigma2, + Variable *correlation) : GooPdf(_x, n) { - //registerObservable(_x); + // registerObservable(_x); registerObservable(_y); std::vector pindices; @@ -43,6 +51,4 @@ __host__ CorrGaussianPdf::CorrGaussianPdf(std::string n, Variable* _x, Variable* initialize(pindices); } - } // namespace GooFit - diff --git a/src/PDFs/CrystalBallPdf.cu b/src/PDFs/CrystalBallPdf.cu index 4d7a86eac..5a1c99990 100644 --- a/src/PDFs/CrystalBallPdf.cu +++ b/src/PDFs/CrystalBallPdf.cu @@ -3,42 +3,42 @@ namespace GooFit { - -__device__ fptype device_CrystalBall(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_CrystalBall(fptype *evt, fptype *p, unsigned int *indices) { // Left-hand tail if alpha is less than 0, // right-hand tail if greater, pure Gaussian if 0. - //return 1; - - fptype x = evt[indices[2 + indices[0]]]; - fptype mean = p[indices[1]]; - fptype sigma = p[indices[2]]; - fptype alpha = p[indices[3]]; - fptype power = p[indices[4]]; - fptype rx = (sigma != 0) ? (x-mean) / sigma : 0; - fptype ret = 0; - - if((alpha > 0 && rx <= alpha) || // Right-hand tail, in Gaussian region - (alpha < 0 && rx >= alpha) || // Left-hand tail, in Gaussian region - (alpha == 0)) { // Pure Gaussian - ret = exp(-0.5*rx*rx); + // return 1; + + fptype x = evt[indices[2 + indices[0]]]; + fptype mean = p[indices[1]]; + fptype sigma = p[indices[2]]; + fptype alpha = p[indices[3]]; + fptype power = p[indices[4]]; + fptype rx = (sigma != 0) ? (x - mean) / sigma : 0; + fptype ret = 0; + + if((alpha > 0 && rx <= alpha) || // Right-hand tail, in Gaussian region + (alpha < 0 && rx >= alpha) + || // Left-hand tail, in Gaussian region + (alpha == 0)) { // Pure Gaussian + ret = exp(-0.5 * rx * rx); } else { // Tail part fptype n_over_alpha = power / alpha; - fptype a = exp(-0.5 * alpha*alpha); - fptype b = n_over_alpha - alpha; - fptype d = b + rx; - d = (d != 0) ? n_over_alpha / d : 0; - ret = a*pow(d, power); + fptype a = exp(-0.5 * alpha * alpha); + fptype b = n_over_alpha - alpha; + fptype d = b + rx; + d = (d != 0) ? n_over_alpha / d : 0; + ret = a * pow(d, power); } - //if ((0 == THREADIDX) && (0 == BLOCKIDX)) printf("device_CB: %f %f %f %f %f %f\n", x, mean, sigma, alpha, power, ret); + // if ((0 == THREADIDX) && (0 == BLOCKIDX)) printf("device_CB: %f %f %f %f %f %f\n", x, mean, sigma, alpha, power, + // ret); return ret; - } __device__ device_function_ptr ptr_to_CrystalBall = device_CrystalBall; -__host__ CrystalBallPdf::CrystalBallPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma, Variable* alpha, - Variable* power) +__host__ CrystalBallPdf::CrystalBallPdf( + std::string n, Variable *_x, Variable *mean, Variable *sigma, Variable *alpha, Variable *power) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -53,22 +53,21 @@ __host__ CrystalBallPdf::CrystalBallPdf(std::string n, Variable* _x, Variable* m initialize(pindices); } - __host__ fptype CrystalBallPdf::integrate(fptype lo, fptype hi) const { static const fptype sqrtPiOver2 = 1.2533141373; - static const fptype sqrt2 = 1.4142135624; + static const fptype sqrt2 = 1.4142135624; fptype result = 0.0; - bool useLog = false; + bool useLog = false; - unsigned int* indices = host_indices + parameters; + unsigned int *indices = host_indices + parameters; fptype mean = host_params[indices[1]]; fptype sigma = host_params[indices[2]]; fptype alpha = host_params[indices[3]]; fptype power = host_params[indices[4]]; - if(fabs(power-1.0) < 1.0e-05) + if(fabs(power - 1.0) < 1.0e-05) useLog = true; fptype tmin = (lo - mean) / sigma; @@ -76,37 +75,38 @@ __host__ fptype CrystalBallPdf::integrate(fptype lo, fptype hi) const { if(alpha < 0) { fptype tmp = tmin; - tmin = -tmax; - tmax = -tmp; + tmin = -tmax; + tmax = -tmp; } fptype absAlpha = fabs(alpha); if(tmin >= -absAlpha) { - result += sigma*sqrtPiOver2*(erf(tmax/sqrt2) - - erf(tmin/sqrt2)); + result += sigma * sqrtPiOver2 * (erf(tmax / sqrt2) - erf(tmin / sqrt2)); } else if(tmax <= -absAlpha) { - fptype a = pow(power/absAlpha, power)*exp(-0.5*absAlpha*absAlpha); - fptype b = power/absAlpha - absAlpha; + fptype a = pow(power / absAlpha, power) * exp(-0.5 * absAlpha * absAlpha); + fptype b = power / absAlpha - absAlpha; if(useLog) { - result += a*sigma*(log(b-tmin) - log(b-tmax)); + result += a * sigma * (log(b - tmin) - log(b - tmax)); } else { - result += a*sigma/(1.0-power)*(1.0/(pow(b-tmin, power-1.0)) - 1.0/(pow(b-tmax, power-1.0))); + result += a * sigma / (1.0 - power) + * (1.0 / (pow(b - tmin, power - 1.0)) - 1.0 / (pow(b - tmax, power - 1.0))); } } else { - fptype a = pow(power/absAlpha, power)*exp(-0.5*absAlpha*absAlpha); - fptype b = power/absAlpha - absAlpha; + fptype a = pow(power / absAlpha, power) * exp(-0.5 * absAlpha * absAlpha); + fptype b = power / absAlpha - absAlpha; fptype term1 = 0.0; if(useLog) { - term1 = a*sigma*(log(b-tmin) - log(power/absAlpha)); + term1 = a * sigma * (log(b - tmin) - log(power / absAlpha)); } else { - term1 = a*sigma/(1.0-power)*(1.0/(pow(b-tmin, power-1.0)) - 1.0/(pow(power/absAlpha, power-1.0))); + term1 = a * sigma / (1.0 - power) + * (1.0 / (pow(b - tmin, power - 1.0)) - 1.0 / (pow(power / absAlpha, power - 1.0))); } - fptype term2 = sigma*sqrtPiOver2*(erf(tmax/sqrt2) - erf(-absAlpha/sqrt2)); + fptype term2 = sigma * sqrtPiOver2 * (erf(tmax / sqrt2) - erf(-absAlpha / sqrt2)); result += term1 + term2; } @@ -114,4 +114,3 @@ __host__ fptype CrystalBallPdf::integrate(fptype lo, fptype hi) const { } } // namespace GooFit - diff --git a/src/PDFs/DP4Pdf.cu b/src/PDFs/DP4Pdf.cu index 250eed2bc..50c6e66d0 100644 --- a/src/PDFs/DP4Pdf.cu +++ b/src/PDFs/DP4Pdf.cu @@ -7,7 +7,8 @@ This code is not sufficently tested yet and still under heavy development! TODO: - Test lineshapes, only done for BW_DP and BW_MINT so far - Check and implement more SF -- Currently no check if the event is even allowed in phasespace is done. This should preferably be done outside of this class. +- Currently no check if the event is even allowed in phasespace is done. This should preferably be done outside of this +class. - Some things could be implemented differently maybe, performance should be compared for both cases. -For example the way Spinfactors are stored in the same array as the Lineshape values. @@ -19,23 +20,21 @@ TODO: #include #include #include -#include #include +#include +#include "goofit/Error.h" #include "goofit/PDFs/physics/DP4Pdf.h" #include "goofit/PDFs/physics/EvalVar.h" -#include "goofit/Error.h" namespace GooFit { - - // The function of this array is to hold all the cached waves; specific // waves are recalculated when the corresponding resonance mass or width // changes. Note that in a multithread environment each thread needs its // own cache, hence the '10'. Ten threads should be enough for anyone! -__device__ thrust::complex* cResSF[10]; -__device__ thrust::complex* Amps_DP[10]; +__device__ thrust::complex *cResSF[10]; +__device__ thrust::complex *Amps_DP[10]; /* Constant memory array to hold specific info for amplitude calculation. First entries are the starting points in array, necessary, because number of Lineshapes(LS) or Spinfactors(SF) can vary @@ -44,29 +43,29 @@ First entries are the starting points in array, necessary, because number of Lin */ __constant__ unsigned int AmpIndices[500]; - // This function gets called by the GooFit framework to get the value of the PDF. -__device__ fptype device_DP(fptype* evt, fptype* p, unsigned int* indices) { - //printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, totalAmp.imag); +__device__ fptype device_DP(fptype *evt, fptype *p, unsigned int *indices) { + // printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, + // totalAmp.imag); - auto evtNum = static_cast( floor(0.5 + evt[indices[7 + indices[0]]])); + auto evtNum = static_cast(floor(0.5 + evt[indices[7 + indices[0]]])); // printf("%i\n",evtNum ); thrust::complex totalAmp(0, 0); - unsigned int cacheToUse = indices[2]; - unsigned int numAmps = indices[5]; + unsigned int cacheToUse = indices[2]; + unsigned int numAmps = indices[5]; for(int i = 0; i < numAmps; ++i) { - thrust::complex amp { p[indices[6 + 2*i]], p[indices[7 + 2*i]] }; + thrust::complex amp{p[indices[6 + 2 * i]], p[indices[7 + 2 * i]]}; - thrust::complex matrixelement((Amps_DP[cacheToUse][evtNum*numAmps + i]).real(), - (Amps_DP[cacheToUse][evtNum*numAmps + i]).imag()); + thrust::complex matrixelement((Amps_DP[cacheToUse][evtNum * numAmps + i]).real(), + (Amps_DP[cacheToUse][evtNum * numAmps + i]).imag()); totalAmp += matrixelement * amp; } - fptype ret = thrust::norm(totalAmp); - int effFunctionIdx = 6 + 2*indices[3] + 2*indices[4] + 2*indices[5]; - fptype eff = callFunction(evt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); + fptype ret = thrust::norm(totalAmp); + int effFunctionIdx = 6 + 2 * indices[3] + 2 * indices[4] + 2 * indices[5]; + fptype eff = callFunction(evt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); ret *= eff; // printf("result %.7g\n", ret); @@ -76,55 +75,56 @@ __device__ fptype device_DP(fptype* evt, fptype* p, unsigned int* indices) { __device__ device_function_ptr ptr_to_DP = device_DP; __host__ DPPdf::DPPdf(std::string n, - std::vector observables, - DecayInfo_DP* decay, - GooPdf* efficiency, + std::vector observables, + DecayInfo_DP *decay, + GooPdf *efficiency, unsigned int MCeventsNorm) : GooPdf(nullptr, n) , decayInfo(decay) , _observables(observables) , totalEventSize(observables.size()) // number of observables plus eventnumber - { - for(auto & observable : observables) { +{ + for(auto &observable : observables) { registerObservable(observable); } // registerObservable(eventNumber); - std::vectordecayConstants; + std::vector decayConstants; decayConstants.push_back(decayInfo->meson_radius); - for(double & particle_masse : decayInfo->particle_masses) { + for(double &particle_masse : decayInfo->particle_masses) { decayConstants.push_back(particle_masse); } std::vector pindices; pindices.push_back(registerConstants(decayConstants.size())); - MEMCPY_TO_SYMBOL(functorConstants, &decayConstants[0], decayConstants.size()*sizeof(fptype), cIndex*sizeof(fptype), + MEMCPY_TO_SYMBOL(functorConstants, + &decayConstants[0], + decayConstants.size() * sizeof(fptype), + cIndex * sizeof(fptype), cudaMemcpyHostToDevice); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); pindices.push_back(0); //#LS pindices.push_back(0); //#SF pindices.push_back(0); //#AMP - // This is the start of reading in the amplitudes and adding the lineshapes and Spinfactors to this PDF // This is done in this way so we don't have multiple copies of one lineshape in one pdf. std::vector ampidx; std::vector nPermVec; std::vector ampidxstart; - for(auto & amplitude : decayInfo->amplitudes) { - AmpMap[amplitude->_uniqueDecayStr] = std::make_pair(std::vector(0), - std::vector(0)); + for(auto &litude : decayInfo->amplitudes) { + AmpMap[amplitude->_uniqueDecayStr] = std::make_pair(std::vector(0), std::vector(0)); auto LSvec = amplitude->_LS; - for(auto & LSIT : LSvec) { - auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase* L) { - return (*LSIT)== *(dynamic_cast(L)); + for(auto &LSIT : LSvec) { + auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase *L) { + return (*LSIT) == *(dynamic_cast(L)); }); if(found != components.end()) { @@ -137,10 +137,9 @@ __host__ DPPdf::DPPdf(std::string n, auto SFvec = amplitude->_SF; - for(auto & SFIT : SFvec) { - auto found = std::find_if(SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor* S) { - return (*SFIT) == (*S); - }); + for(auto &SFIT : SFvec) { + auto found = std::find_if( + SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor *S) { return (*SFIT) == (*S); }); if(found != SpinFactors.end()) { AmpMap[amplitude->_uniqueDecayStr].second.push_back(std::distance(SpinFactors.begin(), found)); @@ -164,37 +163,38 @@ __host__ DPPdf::DPPdf(std::string n, ampidx.insert(ampidx.end(), sf.begin(), sf.end()); } - MEMCPY_TO_SYMBOL(AmpIndices, &(ampidxstart[0]), ampidxstart.size()*sizeof(unsigned int), 0, cudaMemcpyHostToDevice); - MEMCPY_TO_SYMBOL(AmpIndices, &(ampidx[0]), ampidx.size()*sizeof(unsigned int), ampidxstart.size()*sizeof(unsigned int), + MEMCPY_TO_SYMBOL( + AmpIndices, &(ampidxstart[0]), ampidxstart.size() * sizeof(unsigned int), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(AmpIndices, + &(ampidx[0]), + ampidx.size() * sizeof(unsigned int), + ampidxstart.size() * sizeof(unsigned int), cudaMemcpyHostToDevice); pindices[2] = components.size(); pindices[3] = SpinFactors.size(); pindices[4] = AmpMap.size(); - for(auto & component : components) { - reinterpret_cast(component)->setConstantIndex(cIndex); - pindices.push_back(reinterpret_cast(component)->getFunctionIndex()); - pindices.push_back(reinterpret_cast(component)->getParameterIndex()); - + for(auto &component : components) { + reinterpret_cast(component)->setConstantIndex(cIndex); + pindices.push_back(reinterpret_cast(component)->getFunctionIndex()); + pindices.push_back(reinterpret_cast(component)->getParameterIndex()); } - for(auto & SpinFactor : SpinFactors) { + for(auto &SpinFactor : SpinFactors) { pindices.push_back(SpinFactor->getFunctionIndex()); pindices.push_back(SpinFactor->getParameterIndex()); SpinFactor->setConstantIndex(cIndex); } - pindices.push_back(efficiency->getFunctionIndex()); pindices.push_back(efficiency->getParameterIndex()); components.push_back(efficiency); - GET_FUNCTION_ADDR(ptr_to_DP); initialize(pindices); - Integrator = new NormIntegrator(parameters); + Integrator = new NormIntegrator(parameters); redoIntegral = new bool[components.size() - 1]; cachedMasses = new fptype[components.size() - 1]; cachedWidths = new fptype[components.size() - 1]; @@ -204,12 +204,10 @@ __host__ DPPdf::DPPdf(std::string n, cachedMasses[i] = -1; cachedWidths[i] = -1; lscalculators.push_back(new LSCalculator(parameters, i)); - } for(int i = 0; i < SpinFactors.size(); ++i) { sfcalculators.push_back(new SFCalculator(parameters, i)); - } for(int i = 0; i < AmpMap.size(); ++i) { @@ -218,21 +216,21 @@ __host__ DPPdf::DPPdf(std::string n, // fprintf(stderr,"#Amp's %i, #LS %i, #SF %i \n", AmpMap.size(), components.size()-1, SpinFactors.size() ); - std::vector masses(decayInfo->particle_masses.begin()+1, decayInfo->particle_masses.end()); + std::vector masses(decayInfo->particle_masses.begin() + 1, decayInfo->particle_masses.end()); mcbooster::PhaseSpace phsp(decayInfo->particle_masses[0], masses, MCeventsNorm); phsp.Generate(mcbooster::Vector4R(decayInfo->particle_masses[0], 0.0, 0.0, 0.0)); phsp.Unweight(); - auto nAcc = phsp.GetNAccepted(); + auto nAcc = phsp.GetNAccepted(); mcbooster::BoolVector_d flags = phsp.GetAccRejFlags(); - auto d1 = phsp.GetDaughters(0); - auto d2 = phsp.GetDaughters(1); - auto d3 = phsp.GetDaughters(2); - auto d4 = phsp.GetDaughters(3); + auto d1 = phsp.GetDaughters(0); + auto d2 = phsp.GetDaughters(1); + auto d3 = phsp.GetDaughters(2); + auto d4 = phsp.GetDaughters(3); - //auto zip_begin = thrust::make_zip_iterator(thrust::make_tuple(d1.begin(), d2.begin(), d3.begin(), d4.begin())); - //auto zip_end = zip_begin + d1.size(); - //auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); + // auto zip_begin = thrust::make_zip_iterator(thrust::make_tuple(d1.begin(), d2.begin(), d3.begin(), d4.begin())); + // auto zip_end = zip_begin + d1.size(); + // auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); printf("After accept-reject we will keep %.i Events for normalization.\n", static_cast(nAcc)); d1.shrink_to_fit(); @@ -253,8 +251,7 @@ __host__ DPPdf::DPPdf(std::string n, norm_phi = mcbooster::RealVector_d(nAcc); mcbooster::VariableSet_d VarSet(5); - VarSet[0] = &norm_M12, - VarSet[1] = &norm_M34; + VarSet[0] = &norm_M12, VarSet[1] = &norm_M34; VarSet[2] = &norm_CosTheta12; VarSet[3] = &norm_CosTheta34; VarSet[4] = &norm_phi; @@ -262,17 +259,17 @@ __host__ DPPdf::DPPdf(std::string n, Dim5 eval = Dim5(); mcbooster::EvaluateArray(eval, pset, VarSet); - norm_SF = mcbooster::RealVector_d(nAcc * SpinFactors.size()); - norm_LS = mcbooster::mc_device_vector>(nAcc * (components.size() - 1)); + norm_SF = mcbooster::RealVector_d(nAcc * SpinFactors.size()); + norm_LS = mcbooster::mc_device_vector>(nAcc * (components.size() - 1)); MCevents = nAcc; - addSpecialMask(PdfBase::ForceSeparateNorm); } - -// makes the arrays to chache the lineshape values and spinfactors in CachedResSF and the values of the amplitudes in cachedAMPs -// I made the choice to have spinfactors necxt to the values of the lineshape in memory. I waste memory by doing this because a spinfactor is saved as complex +// makes the arrays to chache the lineshape values and spinfactors in CachedResSF and the values of the amplitudes in +// cachedAMPs +// I made the choice to have spinfactors necxt to the values of the lineshape in memory. I waste memory by doing this +// because a spinfactor is saved as complex // It would be nice to test if this is better than having the spinfactors stored seperately. __host__ void DPPdf::setDataSize(unsigned int dataSize, unsigned int evtSize) { // Default 3 is m12, m13, evtNum for DP 2dim, 4-body decay has 5 independent vars plus evtNum = 6 @@ -286,16 +283,22 @@ __host__ void DPPdf::setDataSize(unsigned int dataSize, unsigned int evtSize) { if(cachedAMPs) delete cachedAMPs; - numEntries = dataSize; - cachedResSF = new thrust::device_vector>(dataSize*(components.size() + SpinFactors.size() - - 1)); // -1 because 1 component is efficiency - void* dummy = thrust::raw_pointer_cast(cachedResSF->data()); - MEMCPY_TO_SYMBOL(cResSF, &dummy, sizeof(thrust::complex*), cacheToUse*sizeof(thrust::complex*), + numEntries = dataSize; + cachedResSF = new thrust::device_vector>( + dataSize * (components.size() + SpinFactors.size() - 1)); // -1 because 1 component is efficiency + void *dummy = thrust::raw_pointer_cast(cachedResSF->data()); + MEMCPY_TO_SYMBOL(cResSF, + &dummy, + sizeof(thrust::complex *), + cacheToUse * sizeof(thrust::complex *), cudaMemcpyHostToDevice); - cachedAMPs = new thrust::device_vector>(dataSize*(AmpCalcs.size())); - void* dummy2 = thrust::raw_pointer_cast(cachedAMPs->data()); - MEMCPY_TO_SYMBOL(Amps_DP, &dummy2, sizeof(thrust::complex*), cacheToUse*sizeof(thrust::complex*), + cachedAMPs = new thrust::device_vector>(dataSize * (AmpCalcs.size())); + void *dummy2 = thrust::raw_pointer_cast(cachedAMPs->data()); + MEMCPY_TO_SYMBOL(Amps_DP, + &dummy2, + sizeof(thrust::complex *), + cacheToUse * sizeof(thrust::complex *), cudaMemcpyHostToDevice); setForceIntegrals(); @@ -308,10 +311,10 @@ __host__ fptype DPPdf::normalize() const { // so set normalisation factor to 1 so it doesn't get multiplied by zero. // Copy at this time to ensure that the SpecialResonanceCalculators, which need the efficiency, // don't get zeroes through multiplying by the normFactor. - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); -//check if MINUIT changed any parameters and if so remember that so we know -// we need to recalculate that lineshape and every amp, that uses that lineshape + // check if MINUIT changed any parameters and if so remember that so we know + // we need to recalculate that lineshape and every amp, that uses that lineshape for(unsigned int i = 0; i < components.size() - 1; ++i) { redoIntegral[i] = forceRedoIntegrals; @@ -321,55 +324,62 @@ __host__ fptype DPPdf::normalize() const { redoIntegral[i] = true; } - SpinsCalculated = !forceRedoIntegrals; + SpinsCalculated = !forceRedoIntegrals; forceRedoIntegrals = false; - //just some thrust iterators for the calculation. - thrust::constant_iterator dataArray(dev_event_array); + // just some thrust iterators for the calculation. + thrust::constant_iterator dataArray(dev_event_array); thrust::constant_iterator eventSize(totalEventSize); thrust::counting_iterator eventIndex(0); - //Calculate spinfactors only once for normalisation events and real events - //strided_range is a template implemented in DalitsPlotHelpers.hh - //it basically goes through the array by increasing the pointer by a certain amount instead of just one step. + // Calculate spinfactors only once for normalisation events and real events + // strided_range is a template implemented in DalitsPlotHelpers.hh + // it basically goes through the array by increasing the pointer by a certain amount instead of just one step. if(!SpinsCalculated) { - for(int i = 0; i < SpinFactors.size() ; ++i) { - unsigned int offset = components.size() -1; - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), - strided_range>::iterator>(cachedResSF->begin() + offset + i, - cachedResSF->end(), - (components.size() + SpinFactors.size() - 1)).begin(), - *(sfcalculators[i])); + for(int i = 0; i < SpinFactors.size(); ++i) { + unsigned int offset = components.size() - 1; + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), + strided_range>::iterator>( + cachedResSF->begin() + offset + i, cachedResSF->end(), (components.size() + SpinFactors.size() - 1)) + .begin(), + *(sfcalculators[i])); if(!generation_no_norm) { - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), norm_M34.begin(), - norm_CosTheta12.begin(), norm_CosTheta34.begin(), norm_phi.begin())) - , thrust::make_zip_iterator(thrust::make_tuple(norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), - norm_CosTheta34.end(), norm_phi.end())) - , (norm_SF.begin() + (i * MCevents)) - , NormSpinCalculator(parameters, i)); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), + norm_M34.begin(), + norm_CosTheta12.begin(), + norm_CosTheta34.begin(), + norm_phi.begin())), + thrust::make_zip_iterator(thrust::make_tuple( + norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), norm_CosTheta34.end(), norm_phi.end())), + (norm_SF.begin() + (i * MCevents)), + NormSpinCalculator(parameters, i)); } } SpinsCalculated = true; } - //this calculates the values of the lineshapes and stores them in the array. It is recalculated every time parameters change. - for(int i = 0; i < components.size() -1 ; ++i) { + // this calculates the values of the lineshapes and stores them in the array. It is recalculated every time + // parameters change. + for(int i = 0; i < components.size() - 1; ++i) { if(redoIntegral[i]) { - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), - strided_range>::iterator>(cachedResSF->begin() + i, - cachedResSF->end(), - (components.size() + SpinFactors.size() - 1)).begin(), - *(lscalculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), + strided_range>::iterator>( + cachedResSF->begin() + i, cachedResSF->end(), (components.size() + SpinFactors.size() - 1)) + .begin(), + *(lscalculators[i])); } } - // this is a little messy but it basically checks if the amplitude includes one of the recalculated lineshapes and if so recalculates that amplitude - auto AmpMapIt = - AmpMap.begin(); + // this is a little messy but it basically checks if the amplitude includes one of the recalculated lineshapes and + // if so recalculates that amplitude + auto AmpMapIt = AmpMap.begin(); for(int i = 0; i < AmpCalcs.size(); ++i) { std::vector redoidx((*AmpMapIt).second.first); @@ -384,60 +394,68 @@ __host__ fptype DPPdf::normalize() const { } if(redo) { - thrust::transform(eventIndex, eventIndex + numEntries, - strided_range>::iterator>(cachedAMPs->begin() + i, - cachedAMPs->end(), AmpCalcs.size()).begin(), + thrust::transform(eventIndex, + eventIndex + numEntries, + strided_range>::iterator>( + cachedAMPs->begin() + i, cachedAMPs->end(), AmpCalcs.size()) + .begin(), *(AmpCalcs[i])); } } // lineshape value calculation for the normalisation, also recalculated every time parameter change if(!generation_no_norm) { - for(int i = 0; i < components.size() -1 ; ++i) { + for(int i = 0; i < components.size() - 1; ++i) { if(!redoIntegral[i]) continue; - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), norm_M34.begin(), - norm_CosTheta12.begin(), norm_CosTheta34.begin(), norm_phi.begin())) - , thrust::make_zip_iterator(thrust::make_tuple(norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), - norm_CosTheta34.end(), norm_phi.end())) - , (norm_LS.begin() + (i * MCevents)) - , NormLSCalculator(parameters, i)); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), + norm_M34.begin(), + norm_CosTheta12.begin(), + norm_CosTheta34.begin(), + norm_phi.begin())), + thrust::make_zip_iterator(thrust::make_tuple( + norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), norm_CosTheta34.end(), norm_phi.end())), + (norm_LS.begin() + (i * MCevents)), + NormLSCalculator(parameters, i)); } } - thrust::constant_iterator normSFaddress(thrust::raw_pointer_cast(norm_SF.data())); - thrust::constant_iterator* > normLSaddress(thrust::raw_pointer_cast(norm_LS.data())); + thrust::constant_iterator normSFaddress(thrust::raw_pointer_cast(norm_SF.data())); + thrust::constant_iterator *> normLSaddress(thrust::raw_pointer_cast(norm_LS.data())); thrust::constant_iterator NumNormEvents(MCevents); - //this does the rest of the integration with the cached lineshape and spinfactor values for the normalization events + // this does the rest of the integration with the cached lineshape and spinfactor values for the normalization + // events fptype ret = 1.0; if(!generation_no_norm) { fptype sumIntegral = 0; - sumIntegral += thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, NumNormEvents, - normSFaddress, normLSaddress)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + MCevents, NumNormEvents, normSFaddress, normLSaddress)), - *Integrator, - 0., - thrust::plus()); - //MCevents is the number of normalisation events. - sumIntegral/=MCevents; + sumIntegral += thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, NumNormEvents, normSFaddress, normLSaddress)), + thrust::make_zip_iterator( + thrust::make_tuple(eventIndex + MCevents, NumNormEvents, normSFaddress, normLSaddress)), + *Integrator, + 0., + thrust::plus()); + // MCevents is the number of normalisation events. + sumIntegral /= MCevents; ret = sumIntegral; } if(std::isnan(ret)) GooFit::abort(__FILE__, __LINE__, getName() + " NAN normalization in DPPdf", this); - - host_normalisation[parameters] = 1.0/ret; + + host_normalisation[parameters] = 1.0 / ret; // printf("end of normalize %f\n", ret); return ret; } -__host__ std::tuple -DPPdf::GenerateSig(unsigned int numEvents) { - - std::vector masses(decayInfo->particle_masses.begin()+1, decayInfo->particle_masses.end()); +__host__ + std::tuple + DPPdf::GenerateSig(unsigned int numEvents) { + std::vector masses(decayInfo->particle_masses.begin() + 1, decayInfo->particle_masses.end()); mcbooster::PhaseSpace phsp(decayInfo->particle_masses[0], masses, numEvents, generation_offset); phsp.Generate(mcbooster::Vector4R(decayInfo->particle_masses[0], 0.0, 0.0, 0.0)); @@ -459,8 +477,7 @@ DPPdf::GenerateSig(unsigned int numEvents) { auto SigGen_phi_d = mcbooster::RealVector_d(numEvents); mcbooster::VariableSet_d VarSet_d(5); - VarSet_d[0] = &SigGen_M12_d, - VarSet_d[1] = &SigGen_M34_d; + VarSet_d[0] = &SigGen_M12_d, VarSet_d[1] = &SigGen_M34_d; VarSet_d[2] = &SigGen_CosTheta12_d; VarSet_d[3] = &SigGen_CosTheta34_d; VarSet_d[4] = &SigGen_phi_d; @@ -486,17 +503,15 @@ DPPdf::GenerateSig(unsigned int numEvents) { auto SigGen_phi_h = new mcbooster::RealVector_h(SigGen_phi_d); mcbooster::VariableSet_h VarSet(5); - VarSet[0] = SigGen_M12_h, VarSet[1] = - SigGen_M34_h; + VarSet[0] = SigGen_M12_h, VarSet[1] = SigGen_M34_h; VarSet[2] = SigGen_CosTheta12_h; - VarSet[3] = - SigGen_CosTheta34_h; + VarSet[3] = SigGen_CosTheta34_h; VarSet[4] = SigGen_phi_h; auto weights = mcbooster::RealVector_d(phsp.GetWeights()); phsp.~PhaseSpace(); - auto DS = new mcbooster::RealVector_d(6*numEvents); + auto DS = new mcbooster::RealVector_d(6 * numEvents); thrust::counting_iterator eventNumber(0); #pragma unroll @@ -507,21 +522,21 @@ DPPdf::GenerateSig(unsigned int numEvents) { } mcbooster::strided_range sr(DS->begin() + 5, DS->end(), 6); - thrust::copy(eventNumber, eventNumber+numEvents, sr.begin()); + thrust::copy(eventNumber, eventNumber + numEvents, sr.begin()); dev_event_array = thrust::raw_pointer_cast(DS->data()); setDataSize(numEvents, 6); - generation_no_norm=true; // we need no normalization for generation, but we do need to make sure that norm = 1; + generation_no_norm = true; // we need no normalization for generation, but we do need to make sure that norm = 1; SigGenSetIndices(); copyParams(); normalize(); setForceIntegrals(); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); thrust::device_vector results(numEvents); thrust::constant_iterator eventSize(6); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); thrust::counting_iterator eventIndex(0); MetricTaker evalor(this, getMetricPointer("ptr_to_Prob")); @@ -532,8 +547,8 @@ DPPdf::GenerateSig(unsigned int numEvents) { cudaDeviceSynchronize(); gooFree(dev_event_array); - thrust::transform(results.begin(), results.end(), weights.begin(), weights.begin(), - thrust::multiplies()); + thrust::transform( + results.begin(), results.end(), weights.begin(), weights.begin(), thrust::multiplies()); mcbooster::BoolVector_d flags(numEvents); thrust::counting_iterator first(0); @@ -544,33 +559,30 @@ DPPdf::GenerateSig(unsigned int numEvents) { auto weights_h = mcbooster::RealVector_h(weights); auto results_h = mcbooster::RealVector_h(results); - auto flags_h = mcbooster::BoolVector_h(flags); + auto flags_h = mcbooster::BoolVector_h(flags); cudaDeviceSynchronize(); return std::make_tuple(ParSet, VarSet, weights_h, flags_h); } - SFCalculator::SFCalculator(int pIdx, unsigned int sf_idx) : _spinfactor_i(sf_idx) - , _parameters(pIdx) -{} - -__device__ thrust::complex SFCalculator::operator()(thrust::tuple t) const { + , _parameters(pIdx) {} - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); +__device__ thrust::complex SFCalculator::operator()(thrust::tuple t) const { + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 6 + (2 * indices[5]) + (indices[3] * 2) + (_spinfactor_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i = 6 + (2 * indices[5]) + (indices[3] * 2) + + (_spinfactor_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; + unsigned int params_i = indices[parameter_i + 1]; - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m34 = evt[indices[3 + indices[0]]]; + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m34 = evt[indices[3 + indices[0]]]; fptype cos12 = evt[indices[4 + indices[0]]]; fptype cos34 = evt[indices[5 + indices[0]]]; - fptype phi = evt[indices[6 + indices[0]]]; + fptype phi = evt[indices[6 + indices[0]]]; fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); @@ -581,44 +593,42 @@ __device__ thrust::complex SFCalculator::operator()(thrust::tuple(device_function_table[functn_i]); - fptype sf = (*func)(vecs, paramIndices+params_i); + fptype sf = (*func)(vecs, paramIndices + params_i); // printf("SpinFactors %i : %.7g\n",evtNum, sf ); return thrust::complex(sf, 0); } NormSpinCalculator::NormSpinCalculator(int pIdx, unsigned int sf_idx) : _spinfactor_i(sf_idx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} __device__ fptype NormSpinCalculator::operator()( thrust::tuple t) -const { - - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + const { + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array unsigned int numLS = indices[3]; unsigned int numAmps = indices[5]; - int parameter_i = 6 + (2 * numAmps) + (numLS * 2) + (_spinfactor_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + int parameter_i = 6 + (2 * numAmps) + (numLS * 2) + + (_spinfactor_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; + unsigned int params_i = indices[parameter_i + 1]; - fptype m12 = (thrust::get<0>(t)); - fptype m34 = (thrust::get<1>(t)); - fptype cos12 = (thrust::get<2>(t)); - fptype cos34 = (thrust::get<3>(t)); - fptype phi = (thrust::get<4>(t)); + fptype m12 = (thrust::get<0>(t)); + fptype m34 = (thrust::get<1>(t)); + fptype cos12 = (thrust::get<2>(t)); + fptype cos34 = (thrust::get<3>(t)); + fptype phi = (thrust::get<4>(t)); fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,0, vecs[0], vecs[1], vecs[2], vecs[3]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,1, vecs[4], vecs[5], vecs[6], vecs[7]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,2, vecs[8], vecs[9], vecs[10], vecs[11]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,3, vecs[12], vecs[13], vecs[14], vecs[15]); -// // } + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,0, vecs[0], vecs[1], vecs[2], vecs[3]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,1, vecs[4], vecs[5], vecs[6], vecs[7]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,2, vecs[8], vecs[9], vecs[10], vecs[11]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,3, vecs[12], vecs[13], vecs[14], vecs[15]); + // // } auto func = reinterpret_cast(device_function_table[functn_i]); - fptype sf = (*func)(vecs, paramIndices+params_i); + fptype sf = (*func)(vecs, paramIndices + params_i); // printf("NormSF evt:%.5g, %.5g, %.5g, %.5g, %.5g\n", m12, m34, cos12, cos34, phi); // printf("NormSF %i, %.5g\n",_spinfactor_i, sf ); @@ -626,57 +636,53 @@ const { return sf; } - - LSCalculator::LSCalculator(int pIdx, unsigned int res_idx) : _resonance_i(res_idx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} -__device__ thrust::complex LSCalculator::operator()(thrust::tuple t) const { +__device__ thrust::complex LSCalculator::operator()(thrust::tuple t) const { // Calculates the BW values for a specific resonance. thrust::complex ret; - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 6 + (2 * indices[5]) + (_resonance_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i + = 6 + (2 * indices[5]) + (_resonance_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; - unsigned int pair = (paramIndices+params_i)[5]; + unsigned int params_i = indices[parameter_i + 1]; + unsigned int pair = (paramIndices + params_i)[5]; - fptype m1 = functorConstants[indices[1] + 2]; - fptype m2 = functorConstants[indices[1] + 3]; - fptype m3 = functorConstants[indices[1] + 4]; - fptype m4 = functorConstants[indices[1] + 5]; + fptype m1 = functorConstants[indices[1] + 2]; + fptype m2 = functorConstants[indices[1] + 3]; + fptype m3 = functorConstants[indices[1] + 4]; + fptype m4 = functorConstants[indices[1] + 5]; - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m34 = evt[indices[3 + indices[0]]]; + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m34 = evt[indices[3 + indices[0]]]; fptype cos12 = evt[indices[4 + indices[0]]]; fptype cos34 = evt[indices[5 + indices[0]]]; - fptype phi = evt[indices[6 + indices[0]]]; + fptype phi = evt[indices[6 + indices[0]]]; if(pair < 2) { - fptype mres = pair==0 ? m12 : m34; - fptype d1 = pair==0 ? m1 : m3; - fptype d2 = pair==0 ? m2 : m4; - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + fptype mres = pair == 0 ? m12 : m34; + fptype d1 = pair == 0 ? m1 : m3; + fptype d2 = pair == 0 ? m2 : m4; + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); // printf("LS %i: mass:%f, %f i%f\n",_resonance_i, mres, ret.real, ret.imag ); } else { fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); fptype d1, d2; fptype mres = getmass(pair, d1, d2, vecs, m1, m2, m3, m4); - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); // printf("LS_m_calc %i: mass:%f, %f i%f\n",_resonance_i, mres, ret.real, ret.imag ); - } - //if (!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; - //printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); - //printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); + // if (!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; + // printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); + // printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); // printf("%i mass: %.5g, BW_%i : %f %f\n",evtNum, massstore, _resonance_i, ret.real, ret.imag); return ret; @@ -684,54 +690,52 @@ __device__ thrust::complex LSCalculator::operator()(thrust::tuple NormLSCalculator::operator()( thrust::tuple t) -const { + const { // Calculates the BW values for a specific resonance. thrust::complex ret; - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array unsigned int numAmps = indices[5]; - int parameter_i = 6 + (2 * numAmps) + (_resonance_i * - 2); // Find position of this resonance relative to DALITZPLOT start + int parameter_i + = 6 + (2 * numAmps) + (_resonance_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; - unsigned int pair = (paramIndices+params_i)[5]; - - fptype m1 = functorConstants[indices[1] + 2]; - fptype m2 = functorConstants[indices[1] + 3]; - fptype m3 = functorConstants[indices[1] + 4]; - fptype m4 = functorConstants[indices[1] + 5]; + unsigned int params_i = indices[parameter_i + 1]; + unsigned int pair = (paramIndices + params_i)[5]; - fptype m12 = (thrust::get<0>(t)); - fptype m34 = (thrust::get<1>(t)); - fptype cos12 = (thrust::get<2>(t)); - fptype cos34 = (thrust::get<3>(t)); - fptype phi = (thrust::get<4>(t)); + fptype m1 = functorConstants[indices[1] + 2]; + fptype m2 = functorConstants[indices[1] + 3]; + fptype m3 = functorConstants[indices[1] + 4]; + fptype m4 = functorConstants[indices[1] + 5]; + fptype m12 = (thrust::get<0>(t)); + fptype m34 = (thrust::get<1>(t)); + fptype cos12 = (thrust::get<2>(t)); + fptype cos34 = (thrust::get<3>(t)); + fptype phi = (thrust::get<4>(t)); if(pair < 2) { - fptype mres = pair==0 ? m12 : m34; - fptype d1 = pair==0 ? m1 : m3; - fptype d2 = pair==0 ? m2 : m4; - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + fptype mres = pair == 0 ? m12 : m34; + fptype d1 = pair == 0 ? m1 : m3; + fptype d2 = pair == 0 ? m2 : m4; + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); } else { fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); fptype d1, d2; fptype mres = getmass(pair, d1, d2, vecs, m1, m2, m3, m4); - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); } // printf("NormLS %f, %f, %f, %f, %f \n",m12, m34, cos12, cos34, phi ); // printf("%i, %i, %i, %i, %i \n",numLS, numSF, numAmps, offset, evtNum ); // printf("NLS %i, %f, %f\n",_resonance_i,ret.real, ret.imag); - //printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); - //printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); + // printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); + // printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); // THREAD_SYNCH return ret; } @@ -739,41 +743,39 @@ const { AmpCalc::AmpCalc(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm) : _nPerm(nPerm) , _AmpIdx(AmpIdx) - , _parameters(pIdx) -{} - + , _parameters(pIdx) {} -__device__ thrust::complex AmpCalc::operator()(thrust::tuple t) const { - unsigned int* indices = paramIndices + _parameters; +__device__ thrust::complex AmpCalc::operator()(thrust::tuple t) const { + unsigned int *indices = paramIndices + _parameters; unsigned int cacheToUse = indices[2]; - unsigned int totalLS = indices[3]; - unsigned int totalSF = indices[4]; - unsigned int totalAMP = indices[5]; - unsigned int offset = totalLS + totalSF; - unsigned int numLS = AmpIndices[totalAMP + _AmpIdx]; - unsigned int numSF = AmpIndices[totalAMP + _AmpIdx + 1]; - unsigned int evtNum = thrust::get<0>(t); + unsigned int totalLS = indices[3]; + unsigned int totalSF = indices[4]; + unsigned int totalAMP = indices[5]; + unsigned int offset = totalLS + totalSF; + unsigned int numLS = AmpIndices[totalAMP + _AmpIdx]; + unsigned int numSF = AmpIndices[totalAMP + _AmpIdx + 1]; + unsigned int evtNum = thrust::get<0>(t); thrust::complex returnVal(0, 0); - unsigned int SF_step = numSF/_nPerm; - unsigned int LS_step = numLS/_nPerm; + unsigned int SF_step = numSF / _nPerm; + unsigned int LS_step = numLS / _nPerm; for(int i = 0; i < _nPerm; ++i) { thrust::complex ret(1, 0); thrust::complex tmp(1, 0); - for(int j = i*LS_step; j < (i+1)*LS_step; ++j) { - tmp = (cResSF[cacheToUse][evtNum*offset + AmpIndices[totalAMP + _AmpIdx + 3 + j]]); + for(int j = i * LS_step; j < (i + 1) * LS_step; ++j) { + tmp = (cResSF[cacheToUse][evtNum * offset + AmpIndices[totalAMP + _AmpIdx + 3 + j]]); ret *= tmp; // printf("Lineshape = (%.7g, %.7g)\n", tmp.real, tmp.imag); } // printf("Lineshape Product = (%.7g, %.7g)\n", ret.real, ret.imag); - for(int j = i*SF_step; j < (i+1)*SF_step; ++j) { - tmp = (cResSF[cacheToUse][evtNum*offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 3 + numLS + j]].real()); + for(int j = i * SF_step; j < (i + 1) * SF_step; ++j) { + tmp = (cResSF[cacheToUse][evtNum * offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 3 + numLS + j]] + .real()); ret *= tmp; // printf("SF = (%.7g, %.7g)\n", tmp.real, tmp.imag); - } // printf("Lineshape Product * SF = (%.7g, %.7g)\n", ret.real, ret.imag); @@ -781,59 +783,58 @@ __device__ thrust::complex AmpCalc::operator()(thrust::tuple(_nPerm))); + returnVal *= (1 / sqrt(static_cast(_nPerm))); // printf("Amplitude Value = (%.7g, %.7g)\n", returnVal.real, returnVal.imag); - return returnVal; + return returnVal; } NormIntegrator::NormIntegrator(unsigned int pIdx) - : _parameters(pIdx) -{} + : _parameters(pIdx) {} - -__device__ fptype NormIntegrator::operator()(thrust::tuple*> t) const { - unsigned int* indices = paramIndices + _parameters; +__device__ fptype NormIntegrator::operator()(thrust::tuple *> t) const { + unsigned int *indices = paramIndices + _parameters; unsigned int totalAMP = indices[5]; - unsigned int evtNum = thrust::get<0>(t); - unsigned int MCevents = thrust::get<1>(t); - fptype* SFnorm = thrust::get<2>(t) + evtNum; - thrust::complex* LSnorm = thrust::get<3>(t) + evtNum; + unsigned int evtNum = thrust::get<0>(t); + unsigned int MCevents = thrust::get<1>(t); + fptype *SFnorm = thrust::get<2>(t) + evtNum; + thrust::complex *LSnorm = thrust::get<3>(t) + evtNum; thrust::complex returnVal(0, 0); for(int amp = 0; amp < totalAMP; ++amp) { - unsigned int ampidx = AmpIndices[amp]; - unsigned int numLS = AmpIndices[totalAMP + ampidx]; - unsigned int numSF = AmpIndices[totalAMP + ampidx + 1]; - unsigned int nPerm = AmpIndices[totalAMP + ampidx + 2]; - unsigned int SF_step = numSF/nPerm; - unsigned int LS_step = numLS/nPerm; + unsigned int ampidx = AmpIndices[amp]; + unsigned int numLS = AmpIndices[totalAMP + ampidx]; + unsigned int numSF = AmpIndices[totalAMP + ampidx + 1]; + unsigned int nPerm = AmpIndices[totalAMP + ampidx + 2]; + unsigned int SF_step = numSF / nPerm; + unsigned int LS_step = numLS / nPerm; thrust::complex ret2(0, 0); - // printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %f\n",ampidx, amp, numLS, numSF, nPerm,AmpIndices[totalAMP + ampidx + 3 + 0], AmpIndices[totalAMP + ampidx + 3 + 1], AmpIndices[totalAMP + ampidx + 3 + 2], AmpIndices[totalAMP + ampidx + 3 + 3], (1/sqrt((fptype)(nPerm))) ); + // printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %f\n",ampidx, amp, numLS, numSF, nPerm,AmpIndices[totalAMP + + // ampidx + 3 + 0], AmpIndices[totalAMP + ampidx + 3 + 1], AmpIndices[totalAMP + ampidx + 3 + 2], + // AmpIndices[totalAMP + ampidx + 3 + 3], (1/sqrt((fptype)(nPerm))) ); for(int j = 0; j < nPerm; ++j) { thrust::complex ret(1, 0); - for(int i = j*LS_step; i < (j+1)*LS_step; ++i) { + for(int i = j * LS_step; i < (j + 1) * LS_step; ++i) { thrust::complex matrixelement(LSnorm[AmpIndices[totalAMP + ampidx + 3 + i] * MCevents]); - // printf("Norm BW %i, %.5g, %.5g\n",AmpIndices[totalAMP + ampidx + 3 + i] , matrixelement.real, matrixelement.imag); + // printf("Norm BW %i, %.5g, %.5g\n",AmpIndices[totalAMP + ampidx + 3 + i] , matrixelement.real, + // matrixelement.imag); ret *= matrixelement; - } - for(int i = j*SF_step; i < (j+1)*SF_step; ++i) { + for(int i = j * SF_step; i < (j + 1) * SF_step; ++i) { fptype matrixelement = (SFnorm[AmpIndices[totalAMP + ampidx + 3 + numLS + i] * MCevents]); // printf("Norm SF %i, %.5g\n",AmpIndices[totalAMP + ampidx + 3 + i] , matrixelement); ret *= matrixelement; - } ret2 += ret; } - thrust::complex amp_C { cudaArray[indices[2*amp + 6]], cudaArray[indices[2*amp + 7]] }; - ret2 *= (1/sqrt(static_cast(nPerm))); + thrust::complex amp_C{cudaArray[indices[2 * amp + 6]], cudaArray[indices[2 * amp + 7]]}; + ret2 *= (1 / sqrt(static_cast(nPerm))); // printf("Result Amplitude %i, %.5g, %.5g\n",amp, ret2.real, ret2.imag); returnVal += ret2 * amp_C; } @@ -841,4 +842,3 @@ __device__ fptype NormIntegrator::operator()(thrust::tuple* cResonances[16]; +// NOTE: This is does not support ten instances (ten threads) of resoncances now, only one set of resonances. +__device__ thrust::complex *cResonances[16]; -__device__ inline int parIndexFromResIndex_DP(int resIndex) { - return resonanceOffset_DP + resIndex*resonanceSize; -} +__device__ inline int parIndexFromResIndex_DP(int resIndex) { return resonanceOffset_DP + resIndex * resonanceSize; } -__device__ thrust::complex device_DalitzPlot_calcIntegrals(fptype m12, fptype m13, int res_i, int res_j, fptype* p, - unsigned int* indices) { +__device__ thrust::complex +device_DalitzPlot_calcIntegrals(fptype m12, fptype m13, int res_i, int res_j, fptype *p, unsigned int *indices) { // Calculates BW_i(m12, m13) * BW_j^*(m12, m13). // This calculation is in a separate function so // it can be cached. Note that this function expects @@ -44,22 +40,23 @@ __device__ thrust::complex device_DalitzPlot_calcIntegrals(fptype m12, f if(!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; - fptype m23 = motherMass*motherMass + daug1Mass*daug1Mass + daug2Mass*daug2Mass + daug3Mass*daug3Mass - m12 - m13; + fptype m23 + = motherMass * motherMass + daug1Mass * daug1Mass + daug2Mass * daug2Mass + daug3Mass * daug3Mass - m12 - m13; - int parameter_i = parIndexFromResIndex_DP(res_i); - unsigned int functn_i = RO_CACHE(indices[parameter_i+2]); - unsigned int params_i = RO_CACHE(indices[parameter_i+3]); - ret = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); + int parameter_i = parIndexFromResIndex_DP(res_i); + unsigned int functn_i = RO_CACHE(indices[parameter_i + 2]); + unsigned int params_i = RO_CACHE(indices[parameter_i + 3]); + ret = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); - int parameter_j = parIndexFromResIndex_DP(res_j); - unsigned int functn_j = RO_CACHE(indices[parameter_j+2]); - unsigned int params_j = RO_CACHE(indices[parameter_j+3]); + int parameter_j = parIndexFromResIndex_DP(res_j); + unsigned int functn_j = RO_CACHE(indices[parameter_j + 2]); + unsigned int params_j = RO_CACHE(indices[parameter_j + 3]); ret *= conj(getResonanceAmplitude(m12, m13, m23, functn_j, params_j)); return ret; } -__device__ fptype device_DalitzPlot(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_DalitzPlot(fptype *evt, fptype *p, unsigned int *indices) { fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 0]); fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 1]); fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 2]); @@ -73,52 +70,49 @@ __device__ fptype device_DalitzPlot(fptype* evt, fptype* p, unsigned int* indice fptype evtIndex = RO_CACHE(evt[RO_CACHE(indices[4 + RO_CACHE(indices[0])])]); - auto evtNum = static_cast( floor(0.5 + evtIndex)); + auto evtNum = static_cast(floor(0.5 + evtIndex)); thrust::complex totalAmp(0, 0); unsigned int numResonances = RO_CACHE(indices[2]); - //unsigned int cacheToUse = RO_CACHE(indices[3]); + // unsigned int cacheToUse = RO_CACHE(indices[3]); for(int i = 0; i < numResonances; ++i) { - int paramIndex = parIndexFromResIndex_DP(i); - thrust::complex amp = thrust::complex(RO_CACHE(p[RO_CACHE(indices[paramIndex+0])]), - RO_CACHE(p[RO_CACHE(indices[paramIndex+1])])); + int paramIndex = parIndexFromResIndex_DP(i); + thrust::complex amp = thrust::complex(RO_CACHE(p[RO_CACHE(indices[paramIndex + 0])]), + RO_CACHE(p[RO_CACHE(indices[paramIndex + 1])])); - //potential performance improvement by - //double2 me = RO_CACHE(reinterpret_cast (cResonances[i][evtNum])); + // potential performance improvement by + // double2 me = RO_CACHE(reinterpret_cast (cResonances[i][evtNum])); thrust::complex me = RO_CACHE(cResonances[i][evtNum]); - //thrust::complex matrixelement((cResonances[cacheToUse][evtNum*numResonances + i]).real, + // thrust::complex matrixelement((cResonances[cacheToUse][evtNum*numResonances + i]).real, // (cResonances[cacheToUse][evtNum*numResonances + i]).imag); - //thrust::complex matrixelement (me[0], me[1]); + // thrust::complex matrixelement (me[0], me[1]); totalAmp += amp * me; } - fptype ret = thrust::norm(totalAmp); + fptype ret = thrust::norm(totalAmp); int effFunctionIdx = parIndexFromResIndex_DP(numResonances); - fptype eff = callFunction(evt, RO_CACHE(indices[effFunctionIdx]), RO_CACHE(indices[effFunctionIdx + 1])); + fptype eff = callFunction(evt, RO_CACHE(indices[effFunctionIdx]), RO_CACHE(indices[effFunctionIdx + 1])); ret *= eff; - //printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, totalAmp.imag); + // printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, + // totalAmp.imag); return ret; } __device__ device_function_ptr ptr_to_DalitzPlot = device_DalitzPlot; -__host__ DalitzPlotPdf::DalitzPlotPdf(std::string n, - Variable* m12, - Variable* m13, - CountingVariable* eventNumber, - DecayInfo* decay, - GooPdf* efficiency) +__host__ DalitzPlotPdf::DalitzPlotPdf( + std::string n, Variable *m12, Variable *m13, CountingVariable *eventNumber, DecayInfo *decay, GooPdf *efficiency) : GooPdf(nullptr, n) , decayInfo(decay) , _m12(m12) , _m13(m13) , dalitzNormRange(nullptr) - //, cachedWaves(0) + //, cachedWaves(0) , integrals(nullptr) , forceRedoIntegrals(true) , totalEventSize(3) // Default 3 = m12, m13, evtNum @@ -131,7 +125,7 @@ __host__ DalitzPlotPdf::DalitzPlotPdf(std::string n, fptype decayConstants[5]; - for(auto & cachedWave : cachedWaves) + for(auto &cachedWave : cachedWaves) cachedWave = nullptr; std::vector pindices; @@ -141,14 +135,15 @@ __host__ DalitzPlotPdf::DalitzPlotPdf(std::string n, decayConstants[2] = decayInfo->daug2Mass; decayConstants[3] = decayInfo->daug3Mass; decayConstants[4] = decayInfo->meson_radius; - MEMCPY_TO_SYMBOL(functorConstants, decayConstants, 5*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + functorConstants, decayConstants, 5 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); pindices.push_back(decayInfo->resonances.size()); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); - for(auto & resonance : decayInfo->resonances) { + for(auto &resonance : decayInfo->resonances) { pindices.push_back(registerParameter(resonance->amp_real)); pindices.push_back(registerParameter(resonance->amp_imag)); pindices.push_back(resonance->getFunctionIndex()); @@ -167,17 +162,17 @@ __host__ DalitzPlotPdf::DalitzPlotPdf(std::string n, redoIntegral = new bool[decayInfo->resonances.size()]; cachedMasses = new fptype[decayInfo->resonances.size()]; cachedWidths = new fptype[decayInfo->resonances.size()]; - integrals = new thrust::complex** [decayInfo->resonances.size()]; - integrators = new SpecialResonanceIntegrator** [decayInfo->resonances.size()]; - calculators = new SpecialResonanceCalculator*[decayInfo->resonances.size()]; + integrals = new thrust::complex **[decayInfo->resonances.size()]; + integrators = new SpecialResonanceIntegrator **[decayInfo->resonances.size()]; + calculators = new SpecialResonanceCalculator *[decayInfo->resonances.size()]; for(int i = 0; i < decayInfo->resonances.size(); ++i) { redoIntegral[i] = true; cachedMasses[i] = -1; cachedWidths[i] = -1; - integrators[i] = new SpecialResonanceIntegrator*[decayInfo->resonances.size()]; + integrators[i] = new SpecialResonanceIntegrator *[decayInfo->resonances.size()]; calculators[i] = new SpecialResonanceCalculator(parameters, i); - integrals[i] = new thrust::complex* [decayInfo->resonances.size()]; + integrals[i] = new thrust::complex *[decayInfo->resonances.size()]; for(int j = 0; j < decayInfo->resonances.size(); ++j) { integrals[i][j] = new thrust::complex(0, 0); @@ -194,23 +189,25 @@ __host__ void DalitzPlotPdf::setDataSize(unsigned int dataSize, unsigned int evt if(totalEventSize < 3) throw GooFit::GeneralError("totalEventSize {} must be 3 or more", totalEventSize); - //if (cachedWaves) delete cachedWaves; + // if (cachedWaves) delete cachedWaves; if(cachedWaves[0]) { - for(auto & cachedWave : cachedWaves) + for(auto &cachedWave : cachedWaves) delete cachedWave; } numEntries = dataSize; - for(int i = 0; i < 16; i++) { #ifdef GOOFIT_MPI cachedWaves[i] = new thrust::device_vector>(m_iEventsPerTask); #else cachedWaves[i] = new thrust::device_vector>(dataSize); #endif - void* dummy = thrust::raw_pointer_cast(cachedWaves[i]->data()); - MEMCPY_TO_SYMBOL(cResonances, &dummy, sizeof(thrust::complex*), i*sizeof(thrust::complex*), + void *dummy = thrust::raw_pointer_cast(cachedWaves[i]->data()); + MEMCPY_TO_SYMBOL(cResonances, + &dummy, + sizeof(thrust::complex *), + i * sizeof(thrust::complex *), cudaMemcpyHostToDevice); } @@ -222,21 +219,21 @@ __host__ fptype DalitzPlotPdf::normalize() const { // so set normalisation factor to 1 so it doesn't get multiplied by zero. // Copy at this time to ensure that the SpecialResonanceCalculators, which need the efficiency, // don't get zeroes through multiplying by the normFactor. - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); int totalBins = _m12->getNumBins() * _m13->getNumBins(); if(!dalitzNormRange) { - gooMalloc((void**) &dalitzNormRange, 6*sizeof(fptype)); - - auto* host_norms = new fptype[6]; - host_norms[0] = _m12->getLowerLimit(); - host_norms[1] = _m12->getUpperLimit(); - host_norms[2] = _m12->getNumBins(); - host_norms[3] = _m13->getLowerLimit(); - host_norms[4] = _m13->getUpperLimit(); - host_norms[5] = _m13->getNumBins(); - MEMCPY(dalitzNormRange, host_norms, 6*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc((void **)&dalitzNormRange, 6 * sizeof(fptype)); + + auto *host_norms = new fptype[6]; + host_norms[0] = _m12->getLowerLimit(); + host_norms[1] = _m12->getUpperLimit(); + host_norms[2] = _m12->getNumBins(); + host_norms[3] = _m13->getLowerLimit(); + host_norms[4] = _m13->getUpperLimit(); + host_norms[5] = _m13->getNumBins(); + MEMCPY(dalitzNormRange, host_norms, 6 * sizeof(fptype), cudaMemcpyHostToDevice); delete[] host_norms; } @@ -252,32 +249,34 @@ __host__ fptype DalitzPlotPdf::normalize() const { forceRedoIntegrals = false; // Only do this bit if masses or widths have changed. - thrust::constant_iterator arrayAddress(dalitzNormRange); + thrust::constant_iterator arrayAddress(dalitzNormRange); thrust::counting_iterator binIndex(0); // NB, SpecialResonanceCalculator assumes that fit is unbinned! // And it needs to know the total event size, not just observables // for this particular PDF component. - thrust::constant_iterator dataArray(dev_event_array); + thrust::constant_iterator dataArray(dev_event_array); thrust::constant_iterator eventSize(totalEventSize); thrust::counting_iterator eventIndex(0); for(int i = 0; i < decayInfo->resonances.size(); ++i) { if(redoIntegral[i]) { #ifdef GOOFIT_MPI - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - strided_range>::iterator>(cachedWaves[i]->begin(), - cachedWaves[i]->end(), - 1).begin(), - *(calculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + strided_range>::iterator>( + cachedWaves[i]->begin(), cachedWaves[i]->end(), 1) + .begin(), + *(calculators[i])); #else - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - strided_range>::iterator>(cachedWaves[i]->begin(), - cachedWaves[i]->end(), - 1).begin(), - *(calculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + strided_range>::iterator>( + cachedWaves[i]->begin(), cachedWaves[i]->end(), 1) + .begin(), + *(calculators[i])); #endif } @@ -288,11 +287,12 @@ __host__ fptype DalitzPlotPdf::normalize() const { thrust::complex dummy(0, 0); thrust::plus> complexSum; - (*(integrals[i][j])) = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), - *(integrators[i][j]), - dummy, - complexSum); + (*(integrals[i][j])) = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), + *(integrators[i][j]), + dummy, + complexSum); } } @@ -300,25 +300,27 @@ __host__ fptype DalitzPlotPdf::normalize() const { thrust::complex sumIntegral(0, 0); for(unsigned int i = 0; i < decayInfo->resonances.size(); ++i) { - int param_i = parameters + resonanceOffset_DP + resonanceSize*i; + int param_i = parameters + resonanceOffset_DP + resonanceSize * i; thrust::complex amplitude_i(host_params[host_indices[param_i]], host_params[host_indices[param_i + 1]]); for(unsigned int j = 0; j < decayInfo->resonances.size(); ++j) { - int param_j = parameters + resonanceOffset_DP + resonanceSize*j; - thrust::complex amplitude_j(host_params[host_indices[param_j]], -host_params[host_indices[param_j + 1]]); + int param_j = parameters + resonanceOffset_DP + resonanceSize * j; + thrust::complex amplitude_j(host_params[host_indices[param_j]], + -host_params[host_indices[param_j + 1]]); // Notice complex conjugation - // printf("%f %f %f %f %f %f\n", amplitude_i.real(), amplitude_i.imag(), amplitude_j.real(), amplitude_j.imag(), (*(integrals[i][j])).real, (*(integrals[i][j])).imag ); + // printf("%f %f %f %f %f %f\n", amplitude_i.real(), amplitude_i.imag(), amplitude_j.real(), + // amplitude_j.imag(), (*(integrals[i][j])).real, (*(integrals[i][j])).imag ); sumIntegral += amplitude_i * amplitude_j * (*(integrals[i][j])); } } - fptype ret = sumIntegral.real(); // That complex number is a square, so it's fully real + fptype ret = sumIntegral.real(); // That complex number is a square, so it's fully real double binSizeFactor = 1; binSizeFactor *= _m12->getBinSize(); binSizeFactor *= _m13->getBinSize(); ret *= binSizeFactor; - host_normalisation[parameters] = 1.0/ret; + host_normalisation[parameters] = 1.0 / ret; // printf("%f %f\n", ret, binSizeFactor); return ret; } @@ -326,10 +328,9 @@ __host__ fptype DalitzPlotPdf::normalize() const { SpecialResonanceIntegrator::SpecialResonanceIntegrator(int pIdx, unsigned int ri, unsigned int rj) : resonance_i(ri) , resonance_j(rj) - , parameters(pIdx) -{} + , parameters(pIdx) {} -__device__ thrust::complex SpecialResonanceIntegrator::operator()(thrust::tuple t) const { +__device__ thrust::complex SpecialResonanceIntegrator::operator()(thrust::tuple t) const { // Bin index, base address [lower, upper,getNumBins] // Notice that this is basically MetricTaker::operator (binned) with the special-case knowledge // that event size is two, and that the function to call is dev_DalitzPlot_calcIntegrals. @@ -337,32 +338,33 @@ __device__ thrust::complex SpecialResonanceIntegrator::operator()(thrust int globalBinNumber = thrust::get<0>(t); fptype lowerBoundM12 = thrust::get<1>(t)[0]; fptype upperBoundM12 = thrust::get<1>(t)[1]; - auto numBinsM12 = static_cast( floor(thrust::get<1>(t)[2] + 0.5)); + auto numBinsM12 = static_cast(floor(thrust::get<1>(t)[2] + 0.5)); int binNumberM12 = globalBinNumber % numBinsM12; fptype binCenterM12 = upperBoundM12 - lowerBoundM12; - binCenterM12 /= numBinsM12; - binCenterM12 *= (binNumberM12 + 0.5); - binCenterM12 += lowerBoundM12; + binCenterM12 /= numBinsM12; + binCenterM12 *= (binNumberM12 + 0.5); + binCenterM12 += lowerBoundM12; - globalBinNumber /= numBinsM12; + globalBinNumber /= numBinsM12; fptype lowerBoundM13 = thrust::get<1>(t)[3]; fptype upperBoundM13 = thrust::get<1>(t)[4]; - auto numBinsM13 = static_cast( floor(thrust::get<1>(t)[5] + 0.5)); + auto numBinsM13 = static_cast(floor(thrust::get<1>(t)[5] + 0.5)); fptype binCenterM13 = upperBoundM13 - lowerBoundM13; - binCenterM13 /= numBinsM13; - binCenterM13 *= (globalBinNumber + 0.5); - binCenterM13 += lowerBoundM13; + binCenterM13 /= numBinsM13; + binCenterM13 *= (globalBinNumber + 0.5); + binCenterM13 += lowerBoundM13; - unsigned int* indices = paramIndices + parameters; - thrust::complex ret = device_DalitzPlot_calcIntegrals(binCenterM12, binCenterM13, resonance_i, resonance_j, - cudaArray, indices); + unsigned int *indices = paramIndices + parameters; + thrust::complex ret + = device_DalitzPlot_calcIntegrals(binCenterM12, binCenterM13, resonance_i, resonance_j, cudaArray, indices); - fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an event-weighted fit. + fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an + // event-weighted fit. fakeEvt[indices[indices[0] + 2 + 0]] = binCenterM12; fakeEvt[indices[indices[0] + 2 + 1]] = binCenterM13; - unsigned int numResonances = indices[2]; - int effFunctionIdx = parIndexFromResIndex_DP(numResonances); - fptype eff = callFunction(fakeEvt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); + unsigned int numResonances = indices[2]; + int effFunctionIdx = parIndexFromResIndex_DP(numResonances); + fptype eff = callFunction(fakeEvt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); // Multiplication by eff, not sqrt(eff), is correct: // These complex numbers will not be squared when they @@ -375,18 +377,17 @@ __device__ thrust::complex SpecialResonanceIntegrator::operator()(thrust SpecialResonanceCalculator::SpecialResonanceCalculator(int pIdx, unsigned int res_idx) : resonance_i(res_idx) - , parameters(pIdx) -{} + , parameters(pIdx) {} -__device__ thrust::complex SpecialResonanceCalculator::operator()(thrust::tuple t) const { +__device__ thrust::complex SpecialResonanceCalculator::operator()(thrust::tuple t) const { // Calculates the BW values for a specific resonance. thrust::complex ret; - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + parameters; // Jump to DALITZPLOT position within parameters array - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m13 = evt[indices[3 + indices[0]]]; + unsigned int *indices = paramIndices + parameters; // Jump to DALITZPLOT position within parameters array + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m13 = evt[indices[3 + indices[0]]]; fptype motherMass = functorConstants[indices[1] + 0]; fptype daug1Mass = functorConstants[indices[1] + 1]; @@ -396,17 +397,18 @@ __device__ thrust::complex SpecialResonanceCalculator::operator()(thrust if(!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; - fptype m23 = motherMass*motherMass + daug1Mass*daug1Mass + daug2Mass*daug2Mass + daug3Mass*daug3Mass - m12 - m13; + fptype m23 + = motherMass * motherMass + daug1Mass * daug1Mass + daug2Mass * daug2Mass + daug3Mass * daug3Mass - m12 - m13; - int parameter_i = parIndexFromResIndex_DP(resonance_i); // Find position of this resonance relative to DALITZPLOT start + int parameter_i + = parIndexFromResIndex_DP(resonance_i); // Find position of this resonance relative to DALITZPLOT start - unsigned int functn_i = indices[parameter_i+2]; - unsigned int params_i = indices[parameter_i+3]; + unsigned int functn_i = indices[parameter_i + 2]; + unsigned int params_i = indices[parameter_i + 3]; ret = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); - //printf("Amplitude %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); + // printf("Amplitude %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); return ret; } } // namespace GooFit - diff --git a/src/PDFs/DalitzVetoPdf.cu b/src/PDFs/DalitzVetoPdf.cu index 53112ba3c..2451416ff 100644 --- a/src/PDFs/DalitzVetoPdf.cu +++ b/src/PDFs/DalitzVetoPdf.cu @@ -3,27 +3,26 @@ namespace GooFit { +__device__ fptype device_DalitzVeto(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + 0])]; + fptype y = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + 1])]; -__device__ fptype device_DalitzVeto(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + 0])]; - fptype y = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + 1])]; + fptype motherM = RO_CACHE(p[RO_CACHE(indices[1])]); + fptype d1m = RO_CACHE(p[RO_CACHE(indices[2])]); + fptype d2m = RO_CACHE(p[RO_CACHE(indices[3])]); + fptype d3m = RO_CACHE(p[RO_CACHE(indices[4])]); - fptype motherM = RO_CACHE(p[RO_CACHE(indices[1])]); - fptype d1m = RO_CACHE(p[RO_CACHE(indices[2])]); - fptype d2m = RO_CACHE(p[RO_CACHE(indices[3])]); - fptype d3m = RO_CACHE(p[RO_CACHE(indices[4])]); + fptype massSum = motherM * motherM + d1m * d1m + d2m * d2m + d3m * d3m; + fptype z = massSum - x - y; - fptype massSum = motherM*motherM + d1m*d1m + d2m*d2m + d3m*d3m; - fptype z = massSum - x - y; - - fptype ret = inDalitz(x, y, motherM, d1m, d2m, d3m) ? 1.0 : 0.0; + fptype ret = inDalitz(x, y, motherM, d1m, d2m, d3m) ? 1.0 : 0.0; unsigned int numVetos = RO_CACHE(indices[5]); for(int i = 0; i < numVetos; ++i) { - unsigned int varIndex = indices[6 + i*3 + 0]; - fptype minimum = RO_CACHE(p[RO_CACHE(indices[6 + i*3 + 1])]); - fptype maximum = RO_CACHE(p[RO_CACHE(indices[6 + i*3 + 2])]); - fptype currDalitzVar = (PAIR_12 == varIndex ? x : PAIR_13 == varIndex ? y : z); + unsigned int varIndex = indices[6 + i * 3 + 0]; + fptype minimum = RO_CACHE(p[RO_CACHE(indices[6 + i * 3 + 1])]); + fptype maximum = RO_CACHE(p[RO_CACHE(indices[6 + i * 3 + 2])]); + fptype currDalitzVar = (PAIR_12 == varIndex ? x : PAIR_13 == varIndex ? y : z); ret *= ((currDalitzVar < maximum) && (currDalitzVar > minimum)) ? 0.0 : 1.0; } @@ -33,8 +32,14 @@ __device__ fptype device_DalitzVeto(fptype* evt, fptype* p, unsigned int* indice __device__ device_function_ptr ptr_to_DalitzVeto = device_DalitzVeto; -__host__ DalitzVetoPdf::DalitzVetoPdf(std::string n, Variable* _x, Variable* _y, Variable* motherM, Variable* d1m, - Variable* d2m, Variable* d3m, std::vector vetos) +__host__ DalitzVetoPdf::DalitzVetoPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *motherM, + Variable *d1m, + Variable *d2m, + Variable *d3m, + std::vector vetos) : GooPdf(nullptr, n) { registerObservable(_x); registerObservable(_y); @@ -47,7 +52,7 @@ __host__ DalitzVetoPdf::DalitzVetoPdf(std::string n, Variable* _x, Variable* _y, pindices.push_back(vetos.size()); - for(auto & veto : vetos) { + for(auto &veto : vetos) { pindices.push_back(veto->cyclic_index); pindices.push_back(registerParameter(veto->minimum)); pindices.push_back(registerParameter(veto->maximum)); @@ -57,4 +62,3 @@ __host__ DalitzVetoPdf::DalitzVetoPdf(std::string n, Variable* _x, Variable* _y, initialize(pindices); } } // namespace GooFit - diff --git a/src/PDFs/EventWeightedAddPdf.cu b/src/PDFs/EventWeightedAddPdf.cu index 2a067ee73..a10200b91 100644 --- a/src/PDFs/EventWeightedAddPdf.cu +++ b/src/PDFs/EventWeightedAddPdf.cu @@ -4,66 +4,71 @@ namespace GooFit { - -__device__ fptype device_EventWeightedAddPdfs(fptype* evt, fptype* p, unsigned int* indices) { - int numParameters = RO_CACHE(indices[0]); - fptype ret = 0; +__device__ fptype device_EventWeightedAddPdfs(fptype *evt, fptype *p, unsigned int *indices) { + int numParameters = RO_CACHE(indices[0]); + fptype ret = 0; fptype totalWeight = 0; - for(int i = 0; i < numParameters/2 - 1; ++i) { + for(int i = 0; i < numParameters / 2 - 1; ++i) { fptype weight = RO_CACHE(evt[RO_CACHE(indices[2 + numParameters + i])]); totalWeight += weight; - fptype curr = callFunction(evt, RO_CACHE(indices[2*i + 1]), RO_CACHE(indices[2*(i+1)])); - ret += weight * curr * normalisationFactors[RO_CACHE(indices[2*(i+1)])]; + fptype curr = callFunction(evt, RO_CACHE(indices[2 * i + 1]), RO_CACHE(indices[2 * (i + 1)])); + ret += weight * curr * normalisationFactors[RO_CACHE(indices[2 * (i + 1)])]; } // numParameters does not count itself. So the array structure for two functions is // nP | F P | F P | nO | o1 - // in which nP = 4. and nO = 1. Therefore the parameter index for the last function pointer is nP, and the function index is nP-1. - //fptype last = (*(reinterpret_cast(device_function_table[indices[numParameters-1]])))(evt, p, paramIndices + indices[numParameters]); - fptype last = callFunction(evt, RO_CACHE(indices[numParameters-1]), RO_CACHE(indices[numParameters])); + // in which nP = 4. and nO = 1. Therefore the parameter index for the last function pointer is nP, and the function + // index is nP-1. + // fptype last = (*(reinterpret_cast(device_function_table[indices[numParameters-1]])))(evt, p, + // paramIndices + indices[numParameters]); + fptype last = callFunction(evt, RO_CACHE(indices[numParameters - 1]), RO_CACHE(indices[numParameters])); ret += (1 - totalWeight) * last * normalisationFactors[RO_CACHE(indices[numParameters])]; return ret; } -__device__ fptype device_EventWeightedAddPdfsExt(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_EventWeightedAddPdfsExt(fptype *evt, fptype *p, unsigned int *indices) { // numParameters does not count itself. So the array structure for two functions is // nP | F P | F P | nO | o1 o2 // in which nP = 4, nO = 2. - int numParameters = RO_CACHE(indices[0]); - fptype ret = 0; + int numParameters = RO_CACHE(indices[0]); + fptype ret = 0; fptype totalWeight = 0; - for(int i = 0; i < numParameters/2; ++i) { - fptype curr = callFunction(evt, RO_CACHE(indices[2*i + 1]), RO_CACHE(indices[2*(i+1)])); - //if ((0 == BLOCKIDX) && (THREADIDX < 5) && (isnan(curr))) printf("NaN component %i %i\n", i, THREADIDX); + for(int i = 0; i < numParameters / 2; ++i) { + fptype curr = callFunction(evt, RO_CACHE(indices[2 * i + 1]), RO_CACHE(indices[2 * (i + 1)])); + // if ((0 == BLOCKIDX) && (THREADIDX < 5) && (isnan(curr))) printf("NaN component %i %i\n", i, THREADIDX); fptype weight = RO_CACHE(evt[RO_CACHE(indices[2 + numParameters + i])]); - ret += weight * curr * normalisationFactors[RO_CACHE(indices[2*(i+1)])]; + ret += weight * curr * normalisationFactors[RO_CACHE(indices[2 * (i + 1)])]; totalWeight += weight; - //if ((gpuDebug & 1) && (0 == THREADIDX)) - //if ((gpuDebug & 1) && (1 > evt[8])) - //if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) - //printf("EventWeightedExt: %i %f %f | %f %f %f %f %f %f %f\n", i, curr, weight, evt[0], evt[1], evt[2], evt[3], evt[4], evt[5], evt[6]); - //printf("EventWeightedExt: %i %f %f | %f %f \n", i, curr, weight, normalisationFactors[indices[2*(i+1)]], curr * normalisationFactors[indices[2*(i+1)]]); - //printf("EventWeightedExt: %i : %i %.10f %.10f %.10f %f %f %f\n", (int) floor(0.5 + evt[8]), i, curr, weight, ret, normalisationFactors[indices[2*(i+1)]], evt[6], evt[7]); + // if ((gpuDebug & 1) && (0 == THREADIDX)) + // if ((gpuDebug & 1) && (1 > evt[8])) + // if ((gpuDebug & 1) && (0 == THREADIDX) && (0 == BLOCKIDX)) + // printf("EventWeightedExt: %i %f %f | %f %f %f %f %f %f %f\n", i, curr, weight, evt[0], evt[1], evt[2], + // evt[3], evt[4], evt[5], evt[6]); + // printf("EventWeightedExt: %i %f %f | %f %f \n", i, curr, weight, normalisationFactors[indices[2*(i+1)]], curr + // * normalisationFactors[indices[2*(i+1)]]); + // printf("EventWeightedExt: %i : %i %.10f %.10f %.10f %f %f %f\n", (int) floor(0.5 + evt[8]), i, curr, weight, + // ret, normalisationFactors[indices[2*(i+1)]], evt[6], evt[7]); } ret /= totalWeight; - //if (0 >= ret) printf("Zero sum %f %f %f %f %f %f %f %f %f %f\n", evt[0], evt[1], evt[2], evt[3], evt[4], evt[5], evt[6], evt[7], evt[8], evt[9]); + // if (0 >= ret) printf("Zero sum %f %f %f %f %f %f %f %f %f %f\n", evt[0], evt[1], evt[2], evt[3], evt[4], evt[5], + // evt[6], evt[7], evt[8], evt[9]); return ret; } -__device__ device_function_ptr ptr_to_EventWeightedAddPdfs = device_EventWeightedAddPdfs; +__device__ device_function_ptr ptr_to_EventWeightedAddPdfs = device_EventWeightedAddPdfs; __device__ device_function_ptr ptr_to_EventWeightedAddPdfsExt = device_EventWeightedAddPdfsExt; -EventWeightedAddPdf::EventWeightedAddPdf(std::string n, std::vector weights, std::vector comps) +EventWeightedAddPdf::EventWeightedAddPdf(std::string n, std::vector weights, std::vector comps) : GooPdf(nullptr, n) { - if(weights.size() != comps.size() && (weights.size()+1) != comps.size()) + if(weights.size() != comps.size() && (weights.size() + 1) != comps.size()) throw GooFit::GeneralError("Size of weights {} (+1) != comps {}", weights.size(), comps.size()); // Indices stores (function index)(function parameter index) doublet for each component. @@ -71,7 +76,7 @@ EventWeightedAddPdf::EventWeightedAddPdf(std::string n, std::vector w // AddPdf, weight indices are into the event, not the parameter vector, hence they // are not added to the pindices array at this stage, although 'initialize' will reserve space // for them. - for(PdfBase* p : comps) { + for(PdfBase *p : comps) { GOOFIT_TRACE("EventWeighted component: {}", p->getName()); components.push_back(p); if(components.back() == nullptr) @@ -98,7 +103,8 @@ EventWeightedAddPdf::EventWeightedAddPdf(std::string n, std::vector w extended = false; } - // This must occur after registering weights, or the indices will be off - the device functions assume that the weights are first. + // This must occur after registering weights, or the indices will be off - the device functions assume that the + // weights are first. observables = getObservables(); if(extended) @@ -110,11 +116,12 @@ EventWeightedAddPdf::EventWeightedAddPdf(std::string n, std::vector w } __host__ fptype EventWeightedAddPdf::normalize() const { - //if (cpuDebug & 1) std::cout << "Normalising EventWeightedAddPdf " << getName() << " " << components.size() << std::endl; + // if (cpuDebug & 1) std::cout << "Normalising EventWeightedAddPdf " << getName() << " " << components.size() << + // std::endl; // Here the PDFs have per-event weights, so there is no per-PDF weight // to keep track of. All we can do is normalize the components. - for(PdfBase* comp : components) + for(PdfBase *comp : components) comp->normalize(); host_normalisation[parameters] = 1.0; @@ -123,4 +130,3 @@ __host__ fptype EventWeightedAddPdf::normalize() const { } } // namespace GooFit - diff --git a/src/PDFs/ExpGausPdf.cu b/src/PDFs/ExpGausPdf.cu index a298755c9..81106ddda 100644 --- a/src/PDFs/ExpGausPdf.cu +++ b/src/PDFs/ExpGausPdf.cu @@ -2,16 +2,15 @@ namespace GooFit { - -__device__ fptype device_ExpGaus(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_ExpGaus(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; fptype mean = RO_CACHE(p[RO_CACHE(indices[1])]); fptype sigma = RO_CACHE(p[RO_CACHE(indices[2])]); fptype alpha = RO_CACHE(p[RO_CACHE(indices[3])]); - fptype ret = 0.5*alpha; - fptype exparg = ret * (2*mean + alpha*sigma*sigma - 2*x); - fptype erfarg = (mean + alpha*sigma*sigma - x) / (sigma * 1.4142135623); + fptype ret = 0.5 * alpha; + fptype exparg = ret * (2 * mean + alpha * sigma * sigma - 2 * x); + fptype erfarg = (mean + alpha * sigma * sigma - x) / (sigma * 1.4142135623); ret *= exp(exparg); ret *= erfc(erfarg); @@ -21,7 +20,7 @@ __device__ fptype device_ExpGaus(fptype* evt, fptype* p, unsigned int* indices) __device__ device_function_ptr ptr_to_ExpGaus = device_ExpGaus; -ExpGausPdf::ExpGausPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma, Variable* tau) +ExpGausPdf::ExpGausPdf(std::string n, Variable *_x, Variable *mean, Variable *sigma, Variable *tau) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -31,6 +30,4 @@ ExpGausPdf::ExpGausPdf(std::string n, Variable* _x, Variable* mean, Variable* si initialize(pindices); } - } // namespace GooFit - diff --git a/src/PDFs/ExpPdf.cu b/src/PDFs/ExpPdf.cu index 02a2acbbc..0e09604e0 100644 --- a/src/PDFs/ExpPdf.cu +++ b/src/PDFs/ExpPdf.cu @@ -3,57 +3,56 @@ namespace GooFit { - -__device__ fptype device_Exp(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; +__device__ fptype device_Exp(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; fptype alpha = p[indices[1]]; - fptype ret = exp(alpha*x); + fptype ret = exp(alpha * x); return ret; } -__device__ fptype device_ExpOffset(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_ExpOffset(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; x -= p[indices[1]]; fptype alpha = p[indices[2]]; - fptype ret = exp(alpha*x); + fptype ret = exp(alpha * x); return ret; } -__device__ fptype device_ExpPoly(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_ExpPoly(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; fptype exparg = 0; for(int i = 0; i <= indices[0]; ++i) { - exparg += pow(x, i) * p[indices[i+1]]; + exparg += pow(x, i) * p[indices[i + 1]]; } fptype ret = exp(exparg); return ret; } -__device__ fptype device_ExpPolyOffset(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_ExpPolyOffset(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; x -= p[indices[1]]; fptype exparg = 0; for(int i = 0; i <= indices[0]; ++i) { - exparg += pow(x, i) * p[indices[i+2]]; + exparg += pow(x, i) * p[indices[i + 2]]; } fptype ret = exp(exparg); return ret; } -__device__ device_function_ptr ptr_to_Exp = device_Exp; -__device__ device_function_ptr ptr_to_ExpPoly = device_ExpPoly; -__device__ device_function_ptr ptr_to_ExpOffset = device_ExpOffset; +__device__ device_function_ptr ptr_to_Exp = device_Exp; +__device__ device_function_ptr ptr_to_ExpPoly = device_ExpPoly; +__device__ device_function_ptr ptr_to_ExpOffset = device_ExpOffset; __device__ device_function_ptr ptr_to_ExpPolyOffset = device_ExpPolyOffset; -__host__ ExpPdf::ExpPdf(std::string n, Variable* _x, Variable* alpha, Variable* offset) +__host__ ExpPdf::ExpPdf(std::string n, Variable *_x, Variable *alpha, Variable *offset) : GooPdf(_x, n) { std::vector pindices; @@ -65,12 +64,12 @@ __host__ ExpPdf::ExpPdf(std::string n, Variable* _x, Variable* alpha, Variable* } else { pindices.push_back(registerParameter(alpha)); GET_FUNCTION_ADDR(ptr_to_Exp); - //host_fcn_ptr = (void*) ptr_to_Exp; + // host_fcn_ptr = (void*) ptr_to_Exp; initialize(pindices); } } -__host__ ExpPdf::ExpPdf(std::string n, Variable* _x, std::vector& weights, Variable* offset) +__host__ ExpPdf::ExpPdf(std::string n, Variable *_x, std::vector &weights, Variable *offset) : GooPdf(_x, n) { std::vector pindices; @@ -80,7 +79,7 @@ __host__ ExpPdf::ExpPdf(std::string n, Variable* _x, std::vector& wei if(weights.empty()) throw GooFit::GeneralError("Weights are empty!"); - for(Variable* w : weights) + for(Variable *w : weights) pindices.push_back(registerParameter(w)); if(offset) @@ -99,10 +98,9 @@ __host__ fptype ExpPdf::integrate(fptype lo, fptype hi) const { return (hi - lo); } - fptype ret = exp(alpha*hi) - exp(alpha*lo); + fptype ret = exp(alpha * hi) - exp(alpha * lo); ret /= alpha; return ret; } } // namespace GooFit - diff --git a/src/PDFs/GaussianPdf.cu b/src/PDFs/GaussianPdf.cu index 096eaa2c1..d75cfe368 100644 --- a/src/PDFs/GaussianPdf.cu +++ b/src/PDFs/GaussianPdf.cu @@ -2,21 +2,19 @@ namespace GooFit { - - -__device__ fptype device_Gaussian(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; - fptype mean = RO_CACHE(p[RO_CACHE(indices[1])]); +__device__ fptype device_Gaussian(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; + fptype mean = RO_CACHE(p[RO_CACHE(indices[1])]); fptype sigma = RO_CACHE(p[RO_CACHE(indices[2])]); - fptype ret = exp(-0.5*(x-mean)*(x-mean)/(sigma*sigma)); + fptype ret = exp(-0.5 * (x - mean) * (x - mean) / (sigma * sigma)); return ret; } __device__ device_function_ptr ptr_to_Gaussian = device_Gaussian; -__host__ GaussianPdf::GaussianPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma) +__host__ GaussianPdf::GaussianPdf(std::string n, Variable *_x, Variable *mean, Variable *sigma) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -28,14 +26,12 @@ __host__ GaussianPdf::GaussianPdf(std::string n, Variable* _x, Variable* mean, V __host__ fptype GaussianPdf::integrate(fptype lo, fptype hi) const { static const fptype rootPi = sqrt(atan2(0.0, -1.0)); - unsigned int* indices = host_indices+parameters; - + unsigned int *indices = host_indices + parameters; // Integral over all R. fptype sigma = host_params[indices[2]]; - sigma *= root2*rootPi; + sigma *= root2 * rootPi; return sigma; } } // namespace GooFit - diff --git a/src/PDFs/GooPdf.cu b/src/PDFs/GooPdf.cu index 02eb78659..bc23fd29e 100644 --- a/src/PDFs/GooPdf.cu +++ b/src/PDFs/GooPdf.cu @@ -27,7 +27,6 @@ namespace GooFit { - // These variables are either function-pointer related (thus specific to this implementation) // or constrained to be in the CUDAglob translation unit by nvcc limitations; otherwise they // would be in PdfBase. @@ -47,7 +46,7 @@ __constant__ unsigned int debugParamIndex; __device__ int internalDebug1 = -1; __device__ int internalDebug2 = -1; __device__ int internalDebug3 = -1; -int cpuDebug = 0; +int cpuDebug = 0; #ifdef PROFILING __device__ fptype timeHistogram[10000]; @@ -55,71 +54,72 @@ fptype host_timeHist[10000]; #endif // Function-pointer related. -__device__ void* device_function_table[200]; +__device__ void *device_function_table[200]; // Not clear why this cannot be __constant__, but it causes crashes to declare it so. -void* host_function_table[200]; +void *host_function_table[200]; unsigned int num_device_functions = 0; -std::map functionAddressToDeviceIndexMap; +std::map functionAddressToDeviceIndexMap; // For use in debugging memory issues void printMemoryStatus(std::string file, int line) { - size_t memfree = 0; + size_t memfree = 0; size_t memtotal = 0; cudaDeviceSynchronize(); -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA cudaMemGetInfo(&memfree, &memtotal); #endif cudaDeviceSynchronize(); - std::cout << "Memory status " << file << " " << line << " Free " << memfree << " Total " << memtotal << " Used " << - (memtotal - memfree) << std::endl; + std::cout << "Memory status " << file << " " << line << " Free " << memfree << " Total " << memtotal << " Used " + << (memtotal - memfree) << std::endl; } - -__device__ fptype calculateEval(fptype rawPdf, fptype* evtVal, unsigned int par) { +__device__ fptype calculateEval(fptype rawPdf, fptype *evtVal, unsigned int par) { // Just return the raw PDF value, for use in (eg) normalisation. return rawPdf; } -__device__ fptype calculateNLL(fptype rawPdf, fptype* evtVal, unsigned int par) { - //if ((10 > callnumber) && (THREADIDX < 10) && (BLOCKIDX == 0)) cuPrintf("calculateNll %i %f %f %f\n", callnumber, rawPdf, normalisationFactors[par], rawPdf*normalisationFactors[par]); - //if (THREADIDX < 50) printf("Thread %i %f %f\n", THREADIDX, rawPdf, normalisationFactors[par]); +__device__ fptype calculateNLL(fptype rawPdf, fptype *evtVal, unsigned int par) { + // if ((10 > callnumber) && (THREADIDX < 10) && (BLOCKIDX == 0)) cuPrintf("calculateNll %i %f %f %f\n", callnumber, + // rawPdf, normalisationFactors[par], rawPdf*normalisationFactors[par]); + // if (THREADIDX < 50) printf("Thread %i %f %f\n", THREADIDX, rawPdf, normalisationFactors[par]); rawPdf *= normalisationFactors[par]; return rawPdf > 0 ? -log(rawPdf) : 0; } -__device__ fptype calculateProb(fptype rawPdf, fptype* evtVal, unsigned int par) { +__device__ fptype calculateProb(fptype rawPdf, fptype *evtVal, unsigned int par) { // Return probability, ie normalized PDF value. return rawPdf * normalisationFactors[par]; } -__device__ fptype calculateBinAvg(fptype rawPdf, fptype* evtVal, unsigned int par) { +__device__ fptype calculateBinAvg(fptype rawPdf, fptype *evtVal, unsigned int par) { rawPdf *= normalisationFactors[par]; rawPdf *= evtVal[1]; // Bin volume // Log-likelihood of numEvents with expectation of exp is (-exp + numEvents*ln(exp) - ln(numEvents!)). // The last is constant, so we drop it; and then multiply by minus one to get the negative log-likelihood. if(rawPdf > 0) { - fptype expEvents = functorConstants[0]*rawPdf; - return (expEvents - evtVal[0]*log(expEvents)); + fptype expEvents = functorConstants[0] * rawPdf; + return (expEvents - evtVal[0] * log(expEvents)); } return 0; } -__device__ fptype calculateBinWithError(fptype rawPdf, fptype* evtVal, unsigned int par) { +__device__ fptype calculateBinWithError(fptype rawPdf, fptype *evtVal, unsigned int par) { // In this case interpret the rawPdf as just a number, not a number of events. // Do not divide by integral over phase space, do not multiply by bin volume, // and do not collect 200 dollars. evtVal should have the structure (bin entry, bin error). - //printf("[%i, %i] ((%f - %f) / %f)^2 = %f\n", BLOCKIDX, THREADIDX, rawPdf, evtVal[0], evtVal[1], pow((rawPdf - evtVal[0]) / evtVal[1], 2)); + // printf("[%i, %i] ((%f - %f) / %f)^2 = %f\n", BLOCKIDX, THREADIDX, rawPdf, evtVal[0], evtVal[1], pow((rawPdf - + // evtVal[0]) / evtVal[1], 2)); rawPdf -= evtVal[0]; // Subtract observed value. rawPdf /= evtVal[1]; // Divide by error. rawPdf *= rawPdf; return rawPdf; } -__device__ fptype calculateChisq(fptype rawPdf, fptype* evtVal, unsigned int par) { +__device__ fptype calculateChisq(fptype rawPdf, fptype *evtVal, unsigned int par) { rawPdf *= normalisationFactors[par]; rawPdf *= evtVal[1]; // Bin volume @@ -133,10 +133,12 @@ __device__ device_metric_ptr ptr_to_BinAvg = calculateBinAvg; __device__ device_metric_ptr ptr_to_BinWithError = calculateBinWithError; __device__ device_metric_ptr ptr_to_Chisq = calculateChisq; -void* host_fcn_ptr = nullptr; +void *host_fcn_ptr = nullptr; -void* getMetricPointer(std::string name) { -#define CHOOSE_PTR(ptrname) if (name == #ptrname) GET_FUNCTION_ADDR(ptrname); +void *getMetricPointer(std::string name) { +#define CHOOSE_PTR(ptrname) \ + if(name == #ptrname) \ + GET_FUNCTION_ADDR(ptrname); host_fcn_ptr = nullptr; CHOOSE_PTR(ptr_to_Eval); CHOOSE_PTR(ptr_to_NLL); @@ -152,14 +154,13 @@ void* getMetricPointer(std::string name) { #undef CHOOSE_PTR } - -GooPdf::GooPdf(Variable* x, std::string n) +GooPdf::GooPdf(Variable *x, std::string n) : PdfBase(x, n) , logger(nullptr) { - //std::cout << "Created " << n << std::endl; + // std::cout << "Created " << n << std::endl; } -__host__ int GooPdf::findFunctionIdx(void* dev_functionPtr) { +__host__ int GooPdf::findFunctionIdx(void *dev_functionPtr) { // Code specific to function-pointer implementation auto localPos = functionAddressToDeviceIndexMap.find(dev_functionPtr); @@ -167,22 +168,22 @@ __host__ int GooPdf::findFunctionIdx(void* dev_functionPtr) { return (*localPos).second; } - int fIdx = num_device_functions; - host_function_table[num_device_functions] = dev_functionPtr; + int fIdx = num_device_functions; + host_function_table[num_device_functions] = dev_functionPtr; functionAddressToDeviceIndexMap[dev_functionPtr] = num_device_functions; num_device_functions++; - MEMCPY_TO_SYMBOL(device_function_table, host_function_table, num_device_functions*sizeof(void*), 0, - cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + device_function_table, host_function_table, num_device_functions * sizeof(void *), 0, cudaMemcpyHostToDevice); #ifdef PROFILING host_timeHist[fIdx] = 0; - MEMCPY_TO_SYMBOL(timeHistogram, host_timeHist, 10000*sizeof(fptype), 0); + MEMCPY_TO_SYMBOL(timeHistogram, host_timeHist, 10000 * sizeof(fptype), 0); #endif return fIdx; } -__host__ void GooPdf::initialize(std::vector pindices, void* dev_functionPtr) { +__host__ void GooPdf::initialize(std::vector pindices, void *dev_functionPtr) { if(!fitControl) setFitControl(new UnbinnedNllFit()); @@ -195,7 +196,7 @@ __host__ void GooPdf::initialize(std::vector pindices, void* dev_f __host__ void GooPdf::setDebugMask(int mask, bool setSpecific) const { cpuDebug = mask; -#if THRUST_DEVICE_SYSTEM!=THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CUDA gpuDebug = cpuDebug; if(setSpecific) @@ -220,67 +221,76 @@ __host__ void GooPdf::setMetrics() { __host__ double GooPdf::sumOfNll(int numVars) const { static thrust::plus cudaPlus; thrust::constant_iterator eventSize(numVars); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); double dummy = 0; - //if (host_callnumber >= 2) GooFit::abort(__FILE__, __LINE__, getName() + " debug abort", this); + // if (host_callnumber >= 2) GooFit::abort(__FILE__, __LINE__, getName() + " debug abort", this); thrust::counting_iterator eventIndex(0); double ret; #ifdef GOOFIT_MPI -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - double r = thrust::transform_reduce(my_policy, - thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + double r = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #else double r = thrust::transform_reduce( - thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #endif MPI_Allreduce(&r, &ret, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); #else -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - ret = thrust::transform_reduce(my_policy, - thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + ret = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #else ret = thrust::transform_reduce( - thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - *logger, dummy, cudaPlus); + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + *logger, + dummy, + cudaPlus); #endif #endif return ret; } __host__ double GooPdf::calculateNLL() const { - //if (cpuDebug & 1) std::cout << getName() << " entering calculateNLL (" << host_callnumber << ")" << std::endl; + // if (cpuDebug & 1) std::cout << getName() << " entering calculateNLL (" << host_callnumber << ")" << std::endl; - //MEMCPY_TO_SYMBOL(callnumber, &host_callnumber, sizeof(int)); - //int oldMask = cpuDebug; - //if (0 == host_callnumber) setDebugMask(0, false); - //std::cout << "Start norm " << getName() << std::endl; + // MEMCPY_TO_SYMBOL(callnumber, &host_callnumber, sizeof(int)); + // int oldMask = cpuDebug; + // if (0 == host_callnumber) setDebugMask(0, false); + // std::cout << "Start norm " << getName() << std::endl; normalize(); - //std::cout << "Norm done\n"; - //if ((0 == host_callnumber) && (1 == oldMask)) setDebugMask(1, false); - + // std::cout << "Norm done\n"; + // if ((0 == host_callnumber) && (1 == oldMask)) setDebugMask(1, false); - //if (cpuDebug & 1) { - //std::cout << "Norm factors: "; - //for (int i = 0; i < totalParams; ++i) std::cout << host_normalisation[i] << " "; - //std::cout << std::endl; + // if (cpuDebug & 1) { + // std::cout << "Norm factors: "; + // for (int i = 0; i < totalParams; ++i) std::cout << host_normalisation[i] << " "; + // std::cout << std::endl; //} if(host_normalisation[parameters] <= 0) GooFit::abort(__FILE__, __LINE__, getName() + " non-positive normalisation", this); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); cudaDeviceSynchronize(); // Ensure normalisation integrals are finished int numVars = observables.size(); @@ -295,24 +305,24 @@ __host__ double GooPdf::calculateNLL() const { if(0 == ret) GooFit::abort(__FILE__, __LINE__, getName() + " zero NLL", this); - //if (cpuDebug & 1) std::cout << "Full NLL " << host_callnumber << " : " << 2*ret << std::endl; - //setDebugMask(0); + // if (cpuDebug & 1) std::cout << "Full NLL " << host_callnumber << " : " << 2*ret << std::endl; + // setDebugMask(0); - //if ((cpuDebug & 1) && (host_callnumber >= 1)) GooFit::abort(__FILE__, __LINE__, getName() + " debug abort", this); - return 2*ret; + // if ((cpuDebug & 1) && (host_callnumber >= 1)) GooFit::abort(__FILE__, __LINE__, getName() + " debug abort", + // this); + return 2 * ret; } -__host__ std::vector GooPdf::evaluateAtPoints(Variable* var) { - +__host__ std::vector GooPdf::evaluateAtPoints(Variable *var) { copyParams(); normalize(); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); UnbinnedDataSet tempdata(observables); double step = var->getBinSize(); for(int i = 0; i < var->getNumBins(); ++i) { - var->setValue(var->getLowerLimit() + (i+0.5)*step); + var->setValue(var->getLowerLimit() + (i + 0.5) * step); tempdata.addEvent(); } @@ -320,15 +330,16 @@ __host__ std::vector GooPdf::evaluateAtPoints(Variable* var) { thrust::counting_iterator eventIndex(0); thrust::constant_iterator eventSize(observables.size()); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); thrust::device_vector results(var->getNumBins()); MetricTaker evalor(this, getMetricPointer("ptr_to_Eval")); #ifdef GOOFIT_MPI - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - results.begin(), - evalor); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + results.begin(), + evalor); #else thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), @@ -336,7 +347,8 @@ __host__ std::vector GooPdf::evaluateAtPoints(Variable* var) { evalor); #endif - //Note, This is not fully realized with MPI. We need to copy each 'results' buffer to each other 'MPI_Scatterv', then we can do the rest. + // Note, This is not fully realized with MPI. We need to copy each 'results' buffer to each other 'MPI_Scatterv', + // then we can do the rest. thrust::host_vector h_results = results; std::vector res; res.resize(var->getNumBins()); @@ -344,17 +356,17 @@ __host__ std::vector GooPdf::evaluateAtPoints(Variable* var) { for(int i = 0; i < var->getNumBins(); ++i) { res[i] = h_results[i] * host_normalisation[parameters]; } - + return res; } -__host__ void GooPdf::scan(Variable* var, std::vector& values) { +__host__ void GooPdf::scan(Variable *var, std::vector &values) { fptype step = var->getUpperLimit(); step -= var->getLowerLimit(); step /= var->getNumBins(); values.clear(); - for(fptype v = var->getLowerLimit() + 0.5*step; v < var->getUpperLimit(); v += step) { + for(fptype v = var->getLowerLimit() + 0.5 * step; v < var->getUpperLimit(); v += step) { var->setValue(v); copyParams(); fptype curr = calculateNLL(); @@ -364,9 +376,9 @@ __host__ void GooPdf::scan(Variable* var, std::vector& values) { // TODO: is this needed? __host__ void GooPdf::setParameterConstantness(bool constant) { - std::vector pars = getParameters(); + std::vector pars = getParameters(); - for(Variable* p : pars) { + for(Variable *p : pars) { p->setFixed(constant); } } @@ -376,7 +388,7 @@ __host__ fptype GooPdf::getValue() { // Execute redundantly in all threads for OpenMP multiGPU case copyParams(); normalize(); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); UnbinnedDataSet point(observables); point.addEvent(); @@ -384,7 +396,7 @@ __host__ fptype GooPdf::getValue() { thrust::counting_iterator eventIndex(0); thrust::constant_iterator eventSize(observables.size()); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); thrust::device_vector results(1); MetricTaker evalor(this, getMetricPointer("ptr_to_Eval")); @@ -397,7 +409,6 @@ __host__ fptype GooPdf::getValue() { } __host__ fptype GooPdf::normalize() const { - if(!fitControl->metricIsPdf()) { GOOFIT_TRACE("{}: metricIsPdf, returning 1", getName()); host_normalisation[parameters] = 1.0; @@ -408,22 +419,22 @@ __host__ fptype GooPdf::normalize() const { if(hasAnalyticIntegral()) { // Loop goes only over observables of this PDF. - for(Variable* v : observables) { + for(Variable *v : observables) { GOOFIT_TRACE("{}: Analytically integrating over {}", getName(), v->getName()); ret *= integrate(v->getLowerLimit(), v->getUpperLimit()); } - host_normalisation[parameters] = 1.0/ret; + host_normalisation[parameters] = 1.0 / ret; GOOFIT_TRACE("{}: Param {} integral is = {}", getName(), parameters, ret); - + return ret; } - + GOOFIT_TRACE("{}, Computing integral without analytic help", getName()); int totalBins = 1; - for(Variable* v : observables) { + for(Variable *v : observables) { ret *= v->getUpperLimit() - v->getLowerLimit(); totalBins *= integrationBins > 0 ? integrationBins : v->getNumBins(); @@ -434,38 +445,48 @@ __host__ fptype GooPdf::normalize() const { fptype dummy = 0; static thrust::plus cudaPlus; - thrust::constant_iterator arrayAddress(normRanges); + thrust::constant_iterator arrayAddress(normRanges); thrust::constant_iterator eventSize(observables.size()); thrust::counting_iterator binIndex(0); fptype sum; #ifdef GOOFIT_MPI -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - fptype s = thrust::transform_reduce(my_policy, - thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), - *logger, dummy, cudaPlus); + fptype s = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), + *logger, + dummy, + cudaPlus); #else fptype s = thrust::transform_reduce( - thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), - *logger, dummy, cudaPlus); + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), + *logger, + dummy, + cudaPlus); #endif MPI_Allreduce(&s, &sum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); #else -#if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_SYSTEM_CUDA +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA goofit_policy my_policy; - sum = thrust::transform_reduce(my_policy, - thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), - *logger, dummy, cudaPlus); + sum = thrust::transform_reduce( + my_policy, + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), + *logger, + dummy, + cudaPlus); #else sum = thrust::transform_reduce( - thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), - *logger, dummy, cudaPlus); + thrust::make_zip_iterator(thrust::make_tuple(binIndex, eventSize, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, eventSize, arrayAddress)), + *logger, + dummy, + cudaPlus); #endif #endif @@ -477,43 +498,43 @@ __host__ fptype GooPdf::normalize() const { ret *= sum; - if(0 == ret) GooFit::abort(__FILE__, __LINE__, "Zero integral"); GOOFIT_TRACE("{}: Param {} integral is ~= {}", getName(), parameters, ret); - host_normalisation[parameters] = 1.0/ret; + host_normalisation[parameters] = 1.0 / ret; return ret; } #ifdef PROFILING __constant__ fptype conversion = (1.0 / CLOCKS_PER_SEC); -__device__ fptype callFunction(fptype* eventAddress, unsigned int functionIdx, unsigned int paramIdx) { +__device__ fptype callFunction(fptype *eventAddress, unsigned int functionIdx, unsigned int paramIdx) { clock_t start = clock(); - fptype ret = (*(reinterpret_cast(device_function_table[functionIdx])))(eventAddress, cudaArray, - paramIndices + paramIdx); + fptype ret = (*(reinterpret_cast(device_function_table[functionIdx])))( + eventAddress, cudaArray, paramIndices + paramIdx); clock_t stop = clock(); if((0 == THREADIDX + BLOCKIDX) && (stop > start)) { // Avoid issue when stop overflows and start doesn't. - timeHistogram[functionIdx*100 + paramIdx] += ((stop - start) * conversion); - //printf("Clock: %li %li %li | %u %f\n", (long) start, (long) stop, (long) (stop - start), functionIdx, timeHistogram[functionIdx]); + timeHistogram[functionIdx * 100 + paramIdx] += ((stop - start) * conversion); + // printf("Clock: %li %li %li | %u %f\n", (long) start, (long) stop, (long) (stop - start), functionIdx, + // timeHistogram[functionIdx]); } return ret; } #else -__device__ fptype callFunction(fptype* eventAddress, unsigned int functionIdx, unsigned int paramIdx) { - return (*(reinterpret_cast(device_function_table[functionIdx])))(eventAddress, cudaArray, - paramIndices + paramIdx); +__device__ fptype callFunction(fptype *eventAddress, unsigned int functionIdx, unsigned int paramIdx) { + return (*(reinterpret_cast(device_function_table[functionIdx])))( + eventAddress, cudaArray, paramIndices + paramIdx); } #endif __host__ std::vector> GooPdf::getCompProbsAtDataPoints() { copyParams(); - //double overall = + // double overall = normalize(); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); int numVars = observables.size(); @@ -524,7 +545,7 @@ __host__ std::vector> GooPdf::getCompProbsAtDataPoints() { thrust::device_vector results(numEntries); thrust::constant_iterator eventSize(numVars); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); thrust::counting_iterator eventIndex(0); MetricTaker evalor(this, getMetricPointer("ptr_to_Prob")); thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, arrayAddress, eventSize)), @@ -542,10 +563,11 @@ __host__ std::vector> GooPdf::getCompProbsAtDataPoints() { for(unsigned int i = 0; i < components.size(); ++i) { MetricTaker compevalor(components[i], getMetricPointer("ptr_to_Prob")); thrust::counting_iterator ceventIndex(0); - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(ceventIndex, arrayAddress, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(ceventIndex + numEntries, arrayAddress, eventSize)), - results.begin(), - compevalor); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(ceventIndex, arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(ceventIndex + numEntries, arrayAddress, eventSize)), + results.begin(), + compevalor); host_results = results; for(unsigned int j = 0; j < host_results.size(); ++j) { @@ -556,45 +578,43 @@ __host__ std::vector> GooPdf::getCompProbsAtDataPoints() { } // Utility function to make a grid of any dimisinion -__host__ void make_a_grid(std::vector ret, UnbinnedDataSet &grid) { +__host__ void make_a_grid(std::vector ret, UnbinnedDataSet &grid) { if(ret.empty()) { grid.addEvent(); return; } - - Variable* var = ret.back(); + + Variable *var = ret.back(); ret.pop_back(); // safe because this is a copy - + for(int i = 0; i < var->getNumBins(); ++i) { - double step = (var->getUpperLimit() - var->getLowerLimit())/var->getNumBins(); + double step = (var->getUpperLimit() - var->getLowerLimit()) / var->getNumBins(); var->setValue(var->getLowerLimit() + (i + 0.5) * step); make_a_grid(ret, grid); } - } - __host__ UnbinnedDataSet GooPdf::makeGrid() { - std::vector ret = getObservables(); - + std::vector ret = getObservables(); + UnbinnedDataSet grid{ret}; - + make_a_grid(ret, grid); - + return grid; } // still need to add OpenMP/multi-GPU code here -__host__ void GooPdf::transformGrid(fptype* host_output) { +__host__ void GooPdf::transformGrid(fptype *host_output) { generateNormRange(); - //normalize(); + // normalize(); int totalBins = 1; - for(Variable* v : observables) { + for(Variable *v : observables) { totalBins *= v->getNumBins(); } - thrust::constant_iterator arrayAddress(normRanges); + thrust::constant_iterator arrayAddress(normRanges); thrust::constant_iterator eventSize(observables.size()); thrust::counting_iterator binIndex(0); thrust::device_vector d_vec; @@ -611,9 +631,8 @@ __host__ void GooPdf::transformGrid(fptype* host_output) { host_output[i] = h_vec[i]; } - -__host__ void GooPdf::setFitControl(FitControl* const fc, bool takeOwnerShip) { - for(auto & component : components) { +__host__ void GooPdf::setFitControl(FitControl *const fc, bool takeOwnerShip) { + for(auto &component : components) { component->setFitControl(fc, false); } @@ -631,23 +650,22 @@ __host__ void GooPdf::setFitControl(FitControl* const fc, bool takeOwnerShip) { } #ifdef ROOT_FOUND -__host__ TH1D* GooPdf::plotToROOT(Variable* var, double normFactor, std::string name) { +__host__ TH1D *GooPdf::plotToROOT(Variable *var, double normFactor, std::string name) { if(name.empty()) name = getName() + "_hist"; - + auto ret = new TH1D(name.c_str(), "", var->getNumBins(), var->getLowerLimit(), var->getUpperLimit()); std::vector binValues = evaluateAtPoints(var); - + double pdf_int = 0; - + for(int i = 0; i < var->getNumBins(); ++i) { pdf_int += binValues[i]; } - + for(int i = 0; i < var->getNumBins(); ++i) - ret->SetBinContent(i+1, binValues[i] * normFactor / pdf_int / var->getBinSize()); + ret->SetBinContent(i + 1, binValues[i] * normFactor / pdf_int / var->getBinSize()); return ret; } #endif } // namespace GooFit - diff --git a/src/PDFs/IncoherentSumPdf.cu b/src/PDFs/IncoherentSumPdf.cu index 4b7df504d..32bb735e4 100644 --- a/src/PDFs/IncoherentSumPdf.cu +++ b/src/PDFs/IncoherentSumPdf.cu @@ -1,42 +1,41 @@ #include "goofit/PDFs/physics/IncoherentSumPdf.h" -#include "goofit/PDFs/physics/ResonancePdf.h" #include "goofit/Error.h" +#include "goofit/PDFs/physics/ResonancePdf.h" #include #include namespace GooFit { - const int resonanceOffset_incoherent = 4; // Offset of the first resonance into the parameter index array. // Notice that this is different from the TddpPdf case because there's no time information. // In particular the offset consists of nP, constant index, number of resonances, and cache index. -__device__ thrust::complex* cResonanceValues[10]; +__device__ thrust::complex *cResonanceValues[10]; __device__ inline int parIndexFromResIndex_incoherent(int resIndex) { - return resonanceOffset_incoherent + resIndex*resonanceSize; + return resonanceOffset_incoherent + resIndex * resonanceSize; } -__device__ fptype device_incoherent(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_incoherent(fptype *evt, fptype *p, unsigned int *indices) { // Calculates the incoherent sum over the resonances. - auto evtNum = static_cast( floor(0.5 + evt[indices[4 + indices[0]]])); + auto evtNum = static_cast(floor(0.5 + evt[indices[4 + indices[0]]])); - fptype ret = 0; + fptype ret = 0; unsigned int numResonances = indices[2]; unsigned int cacheToUse = indices[3]; for(int i = 0; i < numResonances; ++i) { - int paramIndex = parIndexFromResIndex_incoherent(i); - fptype amplitude = p[indices[paramIndex+0]]; + int paramIndex = parIndexFromResIndex_incoherent(i); + fptype amplitude = p[indices[paramIndex + 0]]; - thrust::complex matrixelement = cResonanceValues[cacheToUse][evtNum*numResonances + i]; + thrust::complex matrixelement = cResonanceValues[cacheToUse][evtNum * numResonances + i]; ret += amplitude * thrust::norm(matrixelement); } // Multiply by efficiency int effFunctionIdx = parIndexFromResIndex_incoherent(numResonances); - fptype eff = callFunction(evt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); + fptype eff = callFunction(evt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); ret *= eff; @@ -45,8 +44,8 @@ __device__ fptype device_incoherent(fptype* evt, fptype* p, unsigned int* indice __device__ device_function_ptr ptr_to_incoherent = device_incoherent; -__host__ IncoherentSumPdf::IncoherentSumPdf(std::string n, Variable* m12, Variable* m13, CountingVariable* eventNumber, - DecayInfo* decay, GooPdf* eff) +__host__ IncoherentSumPdf::IncoherentSumPdf( + std::string n, Variable *m12, Variable *m13, CountingVariable *eventNumber, DecayInfo *decay, GooPdf *eff) : GooPdf(nullptr, n) , decayInfo(decay) , _m12(m12) @@ -72,14 +71,15 @@ __host__ IncoherentSumPdf::IncoherentSumPdf(std::string n, Variable* m12, Variab decayConstants[2] = decayInfo->daug2Mass; decayConstants[3] = decayInfo->daug3Mass; decayConstants[4] = decayInfo->meson_radius; - MEMCPY_TO_SYMBOL(functorConstants, decayConstants, 5*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + functorConstants, decayConstants, 5 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); pindices.push_back(decayInfo->resonances.size()); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); - for(auto & resonance : decayInfo->resonances) { + for(auto &resonance : decayInfo->resonances) { pindices.push_back(registerParameter(resonance->amp_real)); pindices.push_back(registerParameter(resonance->amp_real)); // Not going to use amp_imag, but need a dummy index so the resonance size will be consistent. @@ -99,24 +99,23 @@ __host__ IncoherentSumPdf::IncoherentSumPdf(std::string n, Variable* m12, Variab redoIntegral = new bool[decayInfo->resonances.size()]; cachedMasses = new fptype[decayInfo->resonances.size()]; cachedWidths = new fptype[decayInfo->resonances.size()]; - integrals = new double[decayInfo->resonances.size()]; + integrals = new double[decayInfo->resonances.size()]; for(int i = 0; i < decayInfo->resonances.size(); ++i) { redoIntegral[i] = true; cachedMasses[i] = -1; cachedWidths[i] = -1; - integrals[i] = 0; + integrals[i] = 0; } - integrators = new SpecialIncoherentIntegrator*[decayInfo->resonances.size()]; - calculators = new SpecialIncoherentResonanceCalculator*[decayInfo->resonances.size()]; + integrators = new SpecialIncoherentIntegrator *[decayInfo->resonances.size()]; + calculators = new SpecialIncoherentResonanceCalculator *[decayInfo->resonances.size()]; for(int i = 0; i < decayInfo->resonances.size(); ++i) { integrators[i] = new SpecialIncoherentIntegrator(parameters, i); calculators[i] = new SpecialIncoherentResonanceCalculator(parameters, i); } - addSpecialMask(PdfBase::ForceSeparateNorm); } @@ -124,16 +123,19 @@ __host__ void IncoherentSumPdf::setDataSize(unsigned int dataSize, unsigned int // Default 3 is m12, m13, evtNum totalEventSize = evtSize; if(totalEventSize < 3) - throw GooFit::GeneralError("totalEventSize {} must be 3 or more", totalEventSize); + throw GooFit::GeneralError("totalEventSize {} must be 3 or more", totalEventSize); if(cachedResonances) { delete cachedResonances; } - numEntries = dataSize; - cachedResonances = new thrust::device_vector>(dataSize*decayInfo->resonances.size()); - void* dummy = thrust::raw_pointer_cast(cachedResonances->data()); - MEMCPY_TO_SYMBOL(cResonanceValues, &dummy, sizeof(thrust::complex*), cacheToUse*sizeof(thrust::complex*), + numEntries = dataSize; + cachedResonances = new thrust::device_vector>(dataSize * decayInfo->resonances.size()); + void *dummy = thrust::raw_pointer_cast(cachedResonances->data()); + MEMCPY_TO_SYMBOL(cResonanceValues, + &dummy, + sizeof(thrust::complex *), + cacheToUse * sizeof(thrust::complex *), cudaMemcpyHostToDevice); setForceIntegrals(); } @@ -143,21 +145,21 @@ __host__ fptype IncoherentSumPdf::normalize() const { // so set normalisation factor to 1 so it doesn't get multiplied by zero. // Copy at this time to ensure that the SpecialCalculators, which need the efficiency, // don't get zeroes through multiplying by the normFactor. - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); int totalBins = _m12->getNumBins() * _m13->getNumBins(); if(!dalitzNormRange) { - gooMalloc((void**) &dalitzNormRange, 6*sizeof(fptype)); - - auto* host_norms = new fptype[6]; - host_norms[0] = _m12->getLowerLimit(); - host_norms[1] = _m12->getUpperLimit(); - host_norms[2] = _m12->getNumBins(); - host_norms[3] = _m13->getLowerLimit(); - host_norms[4] = _m13->getUpperLimit(); - host_norms[5] = _m13->getNumBins(); - MEMCPY(dalitzNormRange, host_norms, 6*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc((void **)&dalitzNormRange, 6 * sizeof(fptype)); + + auto *host_norms = new fptype[6]; + host_norms[0] = _m12->getLowerLimit(); + host_norms[1] = _m12->getUpperLimit(); + host_norms[2] = _m12->getNumBins(); + host_norms[3] = _m13->getLowerLimit(); + host_norms[4] = _m13->getUpperLimit(); + host_norms[5] = _m13->getNumBins(); + MEMCPY(dalitzNormRange, host_norms, 6 * sizeof(fptype), cudaMemcpyHostToDevice); delete[] host_norms; } @@ -178,32 +180,34 @@ __host__ fptype IncoherentSumPdf::normalize() const { forceRedoIntegrals = false; - thrust::constant_iterator arrayAddress(dalitzNormRange); + thrust::constant_iterator arrayAddress(dalitzNormRange); thrust::counting_iterator binIndex(0); // NB, SpecialIncoherentResonanceCalculator assumes that fit is unbinned! // And it needs to know the total event size, not just observables // for this particular PDF component. - thrust::constant_iterator dataArray(dev_event_array); + thrust::constant_iterator dataArray(dev_event_array); thrust::constant_iterator eventSize(totalEventSize); thrust::counting_iterator eventIndex(0); for(int i = 0; i < decayInfo->resonances.size(); ++i) { if(redoIntegral[i]) { - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - strided_range>::iterator>(cachedResonances->begin() + i, - cachedResonances->end(), - decayInfo->resonances.size()).begin(), - *(calculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + strided_range>::iterator>( + cachedResonances->begin() + i, cachedResonances->end(), decayInfo->resonances.size()) + .begin(), + *(calculators[i])); fptype dummy = 0; static thrust::plus cudaPlus; - integrals[i] = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), - *(integrators[i]), - dummy, - cudaPlus); + integrals[i] = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), + *(integrators[i]), + dummy, + cudaPlus); } } @@ -212,7 +216,7 @@ __host__ fptype IncoherentSumPdf::normalize() const { fptype ret = 0; for(unsigned int i = 0; i < decayInfo->resonances.size(); ++i) { - int param_i = parameters + resonanceOffset_incoherent + resonanceSize * i; + int param_i = parameters + resonanceOffset_incoherent + resonanceSize * i; fptype amplitude = host_params[host_indices[param_i]]; ret += amplitude * integrals[i]; } @@ -222,16 +226,15 @@ __host__ fptype IncoherentSumPdf::normalize() const { binSizeFactor *= _m13->getBinSize(); ret *= binSizeFactor; - host_normalisation[parameters] = 1.0/ret; + host_normalisation[parameters] = 1.0 / ret; return ret; } SpecialIncoherentIntegrator::SpecialIncoherentIntegrator(int pIdx, unsigned int ri) : resonance_i(ri) - , parameters(pIdx) -{} + , parameters(pIdx) {} -__device__ fptype SpecialIncoherentIntegrator::operator()(thrust::tuple t) const { +__device__ fptype SpecialIncoherentIntegrator::operator()(thrust::tuple t) const { // Returns integral of specific BW over Dalitz plot, to be cached and // multiplied by rapidly-changing amplitude. @@ -242,83 +245,83 @@ __device__ fptype SpecialIncoherentIntegrator::operator()(thrust::tuple(t); fptype lowerBoundM12 = thrust::get<1>(t)[0]; fptype upperBoundM12 = thrust::get<1>(t)[1]; - auto numBinsM12 = static_cast( floor(thrust::get<1>(t)[2] + 0.5)); + auto numBinsM12 = static_cast(floor(thrust::get<1>(t)[2] + 0.5)); int binNumberM12 = globalBinNumber % numBinsM12; fptype binCenterM12 = upperBoundM12 - lowerBoundM12; - binCenterM12 /= numBinsM12; - binCenterM12 *= (binNumberM12 + 0.5); - binCenterM12 += lowerBoundM12; + binCenterM12 /= numBinsM12; + binCenterM12 *= (binNumberM12 + 0.5); + binCenterM12 += lowerBoundM12; - globalBinNumber /= numBinsM12; + globalBinNumber /= numBinsM12; fptype lowerBoundM13 = thrust::get<1>(t)[3]; fptype upperBoundM13 = thrust::get<1>(t)[4]; - auto numBinsM13 = static_cast( floor(thrust::get<1>(t)[5] + 0.5)); + auto numBinsM13 = static_cast(floor(thrust::get<1>(t)[5] + 0.5)); fptype binCenterM13 = upperBoundM13 - lowerBoundM13; - binCenterM13 /= numBinsM13; - binCenterM13 *= (globalBinNumber + 0.5); - binCenterM13 += lowerBoundM13; + binCenterM13 /= numBinsM13; + binCenterM13 *= (globalBinNumber + 0.5); + binCenterM13 += lowerBoundM13; - unsigned int* indices = paramIndices + parameters; - fptype motherMass = functorConstants[indices[1] + 0]; - fptype daug1Mass = functorConstants[indices[1] + 1]; - fptype daug2Mass = functorConstants[indices[1] + 2]; - fptype daug3Mass = functorConstants[indices[1] + 3]; + unsigned int *indices = paramIndices + parameters; + fptype motherMass = functorConstants[indices[1] + 0]; + fptype daug1Mass = functorConstants[indices[1] + 1]; + fptype daug2Mass = functorConstants[indices[1] + 2]; + fptype daug3Mass = functorConstants[indices[1] + 3]; if(!inDalitz(binCenterM12, binCenterM13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return 0; - int parameter_i = parIndexFromResIndex_incoherent( - resonance_i); // Find position of this resonance relative to TDDP start - unsigned int functn_i = indices[parameter_i+2]; - unsigned int params_i = indices[parameter_i+3]; - fptype m23 = motherMass*motherMass + daug1Mass*daug1Mass + daug2Mass*daug2Mass + daug3Mass*daug3Mass - binCenterM12 - - binCenterM13; + int parameter_i + = parIndexFromResIndex_incoherent(resonance_i); // Find position of this resonance relative to TDDP start + unsigned int functn_i = indices[parameter_i + 2]; + unsigned int params_i = indices[parameter_i + 3]; + fptype m23 = motherMass * motherMass + daug1Mass * daug1Mass + daug2Mass * daug2Mass + daug3Mass * daug3Mass + - binCenterM12 - binCenterM13; thrust::complex ret = getResonanceAmplitude(binCenterM12, binCenterM13, m23, functn_i, params_i); unsigned int numResonances = indices[2]; - fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an event-weighted fit. + fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an + // event-weighted fit. fakeEvt[indices[indices[0] + 2 + 0]] = binCenterM12; fakeEvt[indices[indices[0] + 2 + 1]] = binCenterM13; - int effFunctionIdx = parIndexFromResIndex_incoherent(numResonances); - fptype eff = callFunction(fakeEvt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); + int effFunctionIdx = parIndexFromResIndex_incoherent(numResonances); + fptype eff = callFunction(fakeEvt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); return thrust::norm(ret) * eff; } SpecialIncoherentResonanceCalculator::SpecialIncoherentResonanceCalculator(int pIdx, unsigned int res_idx) : resonance_i(res_idx) - , parameters(pIdx) -{} + , parameters(pIdx) {} -__device__ thrust::complex SpecialIncoherentResonanceCalculator::operator()(thrust::tuple t) -const { +__device__ thrust::complex SpecialIncoherentResonanceCalculator:: +operator()(thrust::tuple t) const { // Returns the BW, or other resonance function, for a specific resonance. // Is special because the value is expected to change slowly, so it's // useful to cache the result. - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + parameters; // Jump to TDDP position within parameters array - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m13 = evt[indices[3 + indices[0]]]; - fptype motherMass = functorConstants[indices[1] + 0]; - fptype daug1Mass = functorConstants[indices[1] + 1]; - fptype daug2Mass = functorConstants[indices[1] + 2]; - fptype daug3Mass = functorConstants[indices[1] + 3]; + unsigned int *indices = paramIndices + parameters; // Jump to TDDP position within parameters array + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m13 = evt[indices[3 + indices[0]]]; + fptype motherMass = functorConstants[indices[1] + 0]; + fptype daug1Mass = functorConstants[indices[1] + 1]; + fptype daug2Mass = functorConstants[indices[1] + 2]; + fptype daug3Mass = functorConstants[indices[1] + 3]; if(!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return thrust::complex(0, 0); - fptype m23 = motherMass*motherMass + daug1Mass*daug1Mass + daug2Mass*daug2Mass + daug3Mass*daug3Mass - m12 - m13; + fptype m23 + = motherMass * motherMass + daug1Mass * daug1Mass + daug2Mass * daug2Mass + daug3Mass * daug3Mass - m12 - m13; - int parameter_i = parIndexFromResIndex_incoherent( - resonance_i); // Find position of this resonance relative to TDDP start - unsigned int functn_i = indices[parameter_i+2]; - unsigned int params_i = indices[parameter_i+3]; + int parameter_i + = parIndexFromResIndex_incoherent(resonance_i); // Find position of this resonance relative to TDDP start + unsigned int functn_i = indices[parameter_i + 2]; + unsigned int params_i = indices[parameter_i + 3]; thrust::complex ret = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); return ret; } } // namespace GooFit - diff --git a/src/PDFs/InterHistPdf.cu b/src/PDFs/InterHistPdf.cu index 17cd3cd10..3755e0ffc 100644 --- a/src/PDFs/InterHistPdf.cu +++ b/src/PDFs/InterHistPdf.cu @@ -4,8 +4,7 @@ namespace GooFit { - -__constant__ fptype* dev_base_interhists[100]; // Multiple histograms for the case of multiple PDFs +__constant__ fptype *dev_base_interhists[100]; // Multiple histograms for the case of multiple PDFs #define OBS_CODE 4242424242 // This number is presumably so high that it will never collide // with an actual parameter index. It indicates that this dimension @@ -13,14 +12,14 @@ __constant__ fptype* dev_base_interhists[100]; // Multiple histograms for the ca // dev_powi is implemented in SmoothHistogramPdf.cu. -__device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_InterHistogram(fptype *evt, fptype *p, unsigned int *indices) { // Structure is // nP totalHistograms (idx1 limit1 step1 bins1) (idx2 limit2 step2 bins2) nO o1 o2 // where limit and step are indices into functorConstants. - int numVars = (indices[0] - 1) / 4; - int globalBin = 0; - int previous = 1; + int numVars = (indices[0] - 1) / 4; + int globalBin = 0; + int previous = 1; int myHistogramIndex = indices[1]; fptype binDistances[10]; // Ten dimensions should be more than enough! // Distance from bin center in units of bin width in each dimension. @@ -28,8 +27,8 @@ __device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* in unsigned int observablesSeen = 0; for(int i = 0; i < numVars; ++i) { - fptype currVariable = 0; - unsigned int varIndex = indices[2 + 4*i]; + fptype currVariable = 0; + unsigned int varIndex = indices[2 + 4 * i]; if(varIndex == OBS_CODE) { // Interpret this number as observable index. @@ -42,24 +41,24 @@ __device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* in currVariable = p[varIndex]; } - int lowerBoundIdx = 3 + 4*i; - fptype lowerBound = functorConstants[indices[lowerBoundIdx + 0]]; - fptype step = functorConstants[indices[lowerBoundIdx + 1]]; + int lowerBoundIdx = 3 + 4 * i; + fptype lowerBound = functorConstants[indices[lowerBoundIdx + 0]]; + fptype step = functorConstants[indices[lowerBoundIdx + 1]]; - currVariable -= lowerBound; - currVariable /= step; + currVariable -= lowerBound; + currVariable /= step; - auto localBin = static_cast( floor(currVariable)); + auto localBin = static_cast(floor(currVariable)); binDistances[i] = currVariable - localBin - fptype(0.5); - globalBin += previous * localBin; - previous *= indices[lowerBoundIdx + 2]; + globalBin += previous * localBin; + previous *= indices[lowerBoundIdx + 2]; if(0 == THREADIDX + BLOCKIDX) - printf("Variable %i: %f %f %i\n", i, currVariable, currVariable*step + lowerBound, localBin); + printf("Variable %i: %f %f %i\n", i, currVariable, currVariable * step + lowerBound, localBin); } - fptype* myHistogram = dev_base_interhists[myHistogramIndex]; - fptype ret = 0; + fptype *myHistogram = dev_base_interhists[myHistogramIndex]; + fptype ret = 0; //------------------ // | | | @@ -72,19 +71,19 @@ __device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* in //------------------ fptype totalWeight = 0; - int totalBins = dev_powi(3, numVars); + int totalBins = dev_powi(3, numVars); for(int i = 0; i < totalBins; ++i) { - int currBin = globalBin; - int localPrevious = 1; - int trackingBin = globalBin; - bool offSomeAxis = false; + int currBin = globalBin; + int localPrevious = 1; + int trackingBin = globalBin; + bool offSomeAxis = false; fptype currentWeight = 0; // Loop over vars to get offset for each one. for(int v = 0; v < numVars; ++v) { - int localNumBins = indices[4*(v+1) + 1]; - int offset = ((i / dev_powi(3, v)) % 3) - 1; + int localNumBins = indices[4 * (v + 1) + 1]; + int offset = ((i / dev_powi(3, v)) % 3) - 1; currBin += offset * localPrevious; localPrevious *= localNumBins; @@ -100,20 +99,30 @@ __device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* in fptype currDist = binDistances[v]; currDist -= offset; - currentWeight += currDist*currDist; + currentWeight += currDist * currDist; if(0 == THREADIDX + BLOCKIDX) - printf("%i, %i: %f %f %f %i %s\n", i, v, currDist, binDistances[v], currentWeight, offset, offSomeAxis ? "off" : "on"); + printf("%i, %i: %f %f %f %i %s\n", + i, + v, + currDist, + binDistances[v], + currentWeight, + offset, + offSomeAxis ? "off" : "on"); } // Only interpolate the four closest boxes (in two dimensions; more in three dimensions). - currentWeight = currentWeight > 0 ? (currentWeight <= sqrt(static_cast( numVars)) ? 1 / sqrt(currentWeight) : 0) : 0; + currentWeight = currentWeight > 0 + ? (currentWeight <= sqrt(static_cast(numVars)) ? 1 / sqrt(currentWeight) : 0) + : 0; fptype currentEntry = offSomeAxis ? 0 : myHistogram[currBin]; ret += currentWeight * currentEntry; totalWeight += currentWeight; if(0 == THREADIDX + BLOCKIDX) - printf("Adding bin content %i %f with weight %f for total %f.\n", currBin, currentEntry, currentWeight, ret); + printf( + "Adding bin content %i %f with weight %f for total %f.\n", currBin, currentEntry, currentWeight, ret); } if(0 == THREADIDX + BLOCKIDX) @@ -126,23 +135,23 @@ __device__ fptype device_InterHistogram(fptype* evt, fptype* p, unsigned int* in __device__ device_function_ptr ptr_to_InterHistogram = device_InterHistogram; __host__ InterHistPdf::InterHistPdf(std::string n, - BinnedDataSet* x, - std::vector params, - std::vector obses) + BinnedDataSet *x, + std::vector params, + std::vector obses) : GooPdf(nullptr, n) , numVars(x->numVariables()) { - int numConstants = 2*numVars; + int numConstants = 2 * numVars; registerConstants(numConstants); static unsigned int totalHistograms = 0; - host_constants = new fptype[numConstants]; - totalEvents = 0; + host_constants = new fptype[numConstants]; + totalEvents = 0; std::vector pindices; pindices.push_back(totalHistograms); int varIndex = 0; - for(Variable* var : x->getVariables()) { + for(Variable *var : x->getVariables()) { if(std::find(obses.begin(), obses.end(), var) != obses.end()) { registerObservable(var); pindices.push_back(OBS_CODE); @@ -150,13 +159,13 @@ __host__ InterHistPdf::InterHistPdf(std::string n, pindices.push_back(registerParameter(var)); } - pindices.push_back(cIndex + 2*varIndex + 0); - pindices.push_back(cIndex + 2*varIndex + 1); + pindices.push_back(cIndex + 2 * varIndex + 0); + pindices.push_back(cIndex + 2 * varIndex + 1); pindices.push_back(var->getNumBins()); // NB, do not put cIndex here, it is accounted for by the offset in MEMCPY_TO_SYMBOL below. - host_constants[2*varIndex + 0] = var->getLowerLimit(); - host_constants[2*varIndex + 1] = var->getBinSize(); + host_constants[2 * varIndex + 0] = var->getLowerLimit(); + host_constants[2 * varIndex + 1] = var->getBinSize(); varIndex++; } @@ -169,18 +178,20 @@ __host__ InterHistPdf::InterHistPdf(std::string n, totalEvents += curr; } - MEMCPY_TO_SYMBOL(functorConstants, host_constants, numConstants*sizeof(fptype), cIndex*sizeof(fptype), + MEMCPY_TO_SYMBOL(functorConstants, + host_constants, + numConstants * sizeof(fptype), + cIndex * sizeof(fptype), cudaMemcpyHostToDevice); dev_base_histogram = new thrust::device_vector(host_histogram); - static fptype* dev_address[1]; + static fptype *dev_address[1]; dev_address[0] = (&((*dev_base_histogram)[0])).get(); - MEMCPY_TO_SYMBOL(dev_base_interhists, dev_address, sizeof(fptype*), totalHistograms*sizeof(fptype*), - cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + dev_base_interhists, dev_address, sizeof(fptype *), totalHistograms * sizeof(fptype *), cudaMemcpyHostToDevice); GET_FUNCTION_ADDR(ptr_to_InterHistogram); initialize(pindices); totalHistograms++; } } // namespace GooFit - diff --git a/src/PDFs/JohnsonSUPdf.cu b/src/PDFs/JohnsonSUPdf.cu index 247bf6b0d..63a7404c1 100644 --- a/src/PDFs/JohnsonSUPdf.cu +++ b/src/PDFs/JohnsonSUPdf.cu @@ -2,32 +2,33 @@ namespace GooFit { - const fptype SQRT2PI = 2.506628; -__device__ fptype device_JohnsonSU(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_JohnsonSU(fptype *evt, fptype *p, unsigned int *indices) { fptype _Jm = p[indices[1]]; fptype _Js = p[indices[2]]; fptype _Jg = p[indices[3]]; fptype _Jd = p[indices[4]]; - fptype x = evt[indices[2 + indices[0]]]; + fptype x = evt[indices[2 + indices[0]]]; - fptype px = (x -_Jm)/_Js; + fptype px = (x - _Jm) / _Js; fptype px2 = px * px; - fptype sqrt_arg = sqrt(1+px2); + fptype sqrt_arg = sqrt(1 + px2); fptype inv_sinh = log(px + sqrt_arg); fptype gaus_arg = _Jg + _Jd * inv_sinh; - //if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) - //if (gpuDebug & 1) - //printf("Johnson SU: %f %f %f %f | %f %f %i\n", _Jm, _Js, _Jg, _Jd, x, _Jd / (_Js * SQRT2PI * sqrt_arg) * exp(-0.5 * gaus_arg * gaus_arg), indices[2 + indices[0]]); - //printf("Johnson SU: %f %f %f %f | %f %f %f %f\n", _Jm, _Js, _Jg, _Jd, x, _Jd / (_Js * SQRT2PI * sqrt_arg) * exp(-0.5 * gaus_arg * gaus_arg), cudaArray[indices[1]], cudaArray[indices[2]]); + // if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) + // if (gpuDebug & 1) + // printf("Johnson SU: %f %f %f %f | %f %f %i\n", _Jm, _Js, _Jg, _Jd, x, _Jd / (_Js * SQRT2PI * sqrt_arg) * exp(-0.5 + // * gaus_arg * gaus_arg), indices[2 + indices[0]]); + // printf("Johnson SU: %f %f %f %f | %f %f %f %f\n", _Jm, _Js, _Jg, _Jd, x, _Jd / (_Js * SQRT2PI * sqrt_arg) * + // exp(-0.5 * gaus_arg * gaus_arg), cudaArray[indices[1]], cudaArray[indices[2]]); return _Jd / (_Js * SQRT2PI * sqrt_arg) * exp(-0.5 * gaus_arg * gaus_arg); } __device__ device_function_ptr ptr_to_JohnsonSU = device_JohnsonSU; -__host__ JohnsonSUPdf::JohnsonSUPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma, Variable* gamma, - Variable* delta) +__host__ JohnsonSUPdf::JohnsonSUPdf( + std::string n, Variable *_x, Variable *mean, Variable *sigma, Variable *gamma, Variable *delta) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -42,4 +43,3 @@ __host__ fptype JohnsonSUPdf::integrate(fptype lo, fptype hi) const { return 1.0; // Analytic integral included in device function! (Correct for minus to plus inf.) } } // namespace GooFit - diff --git a/src/PDFs/KinLimitBWPdf.cu b/src/PDFs/KinLimitBWPdf.cu index 0e8cb2fdb..fefaaac61 100644 --- a/src/PDFs/KinLimitBWPdf.cu +++ b/src/PDFs/KinLimitBWPdf.cu @@ -3,32 +3,31 @@ namespace GooFit { - -__device__ fptype getMomentum(const fptype& mass, const fptype& pimass, const fptype& d0mass) { +__device__ fptype getMomentum(const fptype &mass, const fptype &pimass, const fptype &d0mass) { if(mass <= 0) return 0; - double lambda = mass*mass - pimass*pimass - d0mass*d0mass; + double lambda = mass * mass - pimass * pimass - d0mass * d0mass; lambda *= lambda; - lambda -= 4*pimass*pimass*d0mass*d0mass; + lambda -= 4 * pimass * pimass * d0mass * d0mass; if(lambda <= 0) return 0; - return sqrt(0.5*lambda/mass); + return sqrt(0.5 * lambda / mass); } -__device__ fptype bwFactor(const fptype& momentum) { +__device__ fptype bwFactor(const fptype &momentum) { // 2.56 = 1.6^2, comes from radius for spin-1 particle - return 1/sqrt(1.0 + 2.56 * momentum*momentum); + return 1 / sqrt(1.0 + 2.56 * momentum * momentum); } -__device__ fptype device_KinLimitBW(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; - fptype mean = RO_CACHE(p[RO_CACHE(indices[1])]); - fptype width = RO_CACHE(p[RO_CACHE(indices[2])]); - fptype d0mass = RO_CACHE(functorConstants[RO_CACHE(indices[3])+0]); - fptype pimass = RO_CACHE(functorConstants[RO_CACHE(indices[3])+1]); +__device__ fptype device_KinLimitBW(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; + fptype mean = RO_CACHE(p[RO_CACHE(indices[1])]); + fptype width = RO_CACHE(p[RO_CACHE(indices[2])]); + fptype d0mass = RO_CACHE(functorConstants[RO_CACHE(indices[3]) + 0]); + fptype pimass = RO_CACHE(functorConstants[RO_CACHE(indices[3]) + 1]); mean += d0mass; x += d0mass; @@ -41,17 +40,17 @@ __device__ fptype device_KinLimitBW(fptype* evt, fptype* p, unsigned int* indice mean *= mean; fptype pUsingX = getMomentum(x, pimass, d0mass); fptype phspfactor = POW3(pUsingX / pUsingRealMass) * POW2(bwFactor(pUsingX) / bwFactor(pUsingRealMass)); - fptype phspMassSq = POW2(mean - x*x); - fptype phspGammaSq = POW2(width*phspfactor); + fptype phspMassSq = POW2(mean - x * x); + fptype phspGammaSq = POW2(width * phspfactor); - fptype ret = (phspfactor * mean*width*width)/(phspMassSq + mean*phspGammaSq); + fptype ret = (phspfactor * mean * width * width) / (phspMassSq + mean * phspGammaSq); return ret; } __device__ device_function_ptr ptr_to_KinLimitBW = device_KinLimitBW; -__host__ KinLimitBWPdf::KinLimitBWPdf(std::string n, Variable* _x, Variable* mean, Variable* width) +__host__ KinLimitBWPdf::KinLimitBWPdf(std::string n, Variable *_x, Variable *mean, Variable *width) : GooPdf(_x, n) { registerParameter(mean); registerParameter(width); @@ -69,7 +68,6 @@ __host__ void KinLimitBWPdf::setMasses(fptype bigM, fptype smallM) { fptype constants[2]; constants[0] = bigM; constants[1] = smallM; - MEMCPY_TO_SYMBOL(functorConstants, constants, 2*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(functorConstants, constants, 2 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); } } // namespace GooFit - diff --git a/src/PDFs/LandauPdf.cu b/src/PDFs/LandauPdf.cu index 4db8d14de..cece7cab2 100644 --- a/src/PDFs/LandauPdf.cu +++ b/src/PDFs/LandauPdf.cu @@ -2,32 +2,31 @@ namespace GooFit { - // LANDAU pdf : algorithm from CERNLIB G110 denlan // same algorithm is used in GSL -__constant__ fptype p1[5] = {0.4259894875, -0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253}; -__constant__ fptype q1[5] = {1.0, -0.3388260629, 0.09594393323, -0.01608042283, 0.003778942063}; +__constant__ fptype p1[5] = {0.4259894875, -0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253}; +__constant__ fptype q1[5] = {1.0, -0.3388260629, 0.09594393323, -0.01608042283, 0.003778942063}; -__constant__ fptype p2[5] = {0.1788541609, 0.1173957403, 0.01488850518, -0.001394989411, 0.0001283617211}; -__constant__ fptype q2[5] = {1.0, 0.7428795082, 0.3153932961, 0.06694219548, 0.008790609714}; +__constant__ fptype p2[5] = {0.1788541609, 0.1173957403, 0.01488850518, -0.001394989411, 0.0001283617211}; +__constant__ fptype q2[5] = {1.0, 0.7428795082, 0.3153932961, 0.06694219548, 0.008790609714}; __constant__ fptype p3[5] = {0.1788544503, 0.09359161662, 0.006325387654, 0.00006611667319, -0.000002031049101}; -__constant__ fptype q3[5] = {1.0, 0.6097809921, 0.2560616665, 0.04746722384, 0.006957301675}; +__constant__ fptype q3[5] = {1.0, 0.6097809921, 0.2560616665, 0.04746722384, 0.006957301675}; -__constant__ fptype p4[5] = {0.9874054407, 118.6723273, 849.2794360, -743.7792444, 427.0262186}; -__constant__ fptype q4[5] = {1.0, 106.8615961, 337.6496214, 2016.712389, 1597.063511}; +__constant__ fptype p4[5] = {0.9874054407, 118.6723273, 849.2794360, -743.7792444, 427.0262186}; +__constant__ fptype q4[5] = {1.0, 106.8615961, 337.6496214, 2016.712389, 1597.063511}; -__constant__ fptype p5[5] = {1.003675074, 167.5702434, 4789.711289, 21217.86767, -22324.94910}; -__constant__ fptype q5[5] = {1.0, 156.9424537, 3745.310488, 9834.698876, 66924.28357}; +__constant__ fptype p5[5] = {1.003675074, 167.5702434, 4789.711289, 21217.86767, -22324.94910}; +__constant__ fptype q5[5] = {1.0, 156.9424537, 3745.310488, 9834.698876, 66924.28357}; -__constant__ fptype p6[5] = {1.000827619, 664.9143136, 62972.92665, 475554.6998, -5743609.109}; -__constant__ fptype q6[5] = {1.0, 651.4101098, 56974.73333, 165917.4725, -2815759.939}; +__constant__ fptype p6[5] = {1.000827619, 664.9143136, 62972.92665, 475554.6998, -5743609.109}; +__constant__ fptype q6[5] = {1.0, 651.4101098, 56974.73333, 165917.4725, -2815759.939}; __constant__ fptype a1[3] = {0.04166666667, -0.01996527778, 0.02709538966}; __constant__ fptype a2[2] = {-1.845568670, -4.284640743}; -__device__ fptype device_Landau(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Landau(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; fptype mpv = p[indices[1]]; fptype sigma = p[indices[2]]; @@ -35,52 +34,51 @@ __device__ fptype device_Landau(fptype* evt, fptype* p, unsigned int* indices) { if(sigma <= 0) return 0; - fptype v = (x - mpv)/sigma; + fptype v = (x - mpv) / sigma; fptype u, ue, us, denlan; if(v < -5.5) { - u = exp(v+1.0); + u = exp(v + 1.0); if(u < 1e-10) return 0.0; - ue = exp(-1/u); - us = sqrt(u); - denlan = 0.3989422803*(ue/us)*(1+(a1[0]+(a1[1]+a1[2]*u)*u)*u); + ue = exp(-1 / u); + us = sqrt(u); + denlan = 0.3989422803 * (ue / us) * (1 + (a1[0] + (a1[1] + a1[2] * u) * u) * u); } else if(v < -1) { - u = exp(-v-1); - denlan = exp(-u)*sqrt(u)* - (p1[0]+(p1[1]+(p1[2]+(p1[3]+p1[4]*v)*v)*v)*v)/ - (q1[0]+(q1[1]+(q1[2]+(q1[3]+q1[4]*v)*v)*v)*v); + u = exp(-v - 1); + denlan = exp(-u) * sqrt(u) * (p1[0] + (p1[1] + (p1[2] + (p1[3] + p1[4] * v) * v) * v) * v) + / (q1[0] + (q1[1] + (q1[2] + (q1[3] + q1[4] * v) * v) * v) * v); } else if(v < 1) { - denlan = (p2[0]+(p2[1]+(p2[2]+(p2[3]+p2[4]*v)*v)*v)*v)/ - (q2[0]+(q2[1]+(q2[2]+(q2[3]+q2[4]*v)*v)*v)*v); + denlan = (p2[0] + (p2[1] + (p2[2] + (p2[3] + p2[4] * v) * v) * v) * v) + / (q2[0] + (q2[1] + (q2[2] + (q2[3] + q2[4] * v) * v) * v) * v); } else if(v < 5) { - denlan = (p3[0]+(p3[1]+(p3[2]+(p3[3]+p3[4]*v)*v)*v)*v)/ - (q3[0]+(q3[1]+(q3[2]+(q3[3]+q3[4]*v)*v)*v)*v); + denlan = (p3[0] + (p3[1] + (p3[2] + (p3[3] + p3[4] * v) * v) * v) * v) + / (q3[0] + (q3[1] + (q3[2] + (q3[3] + q3[4] * v) * v) * v) * v); } else if(v < 12) { - u = 1/v; - denlan = u*u*(p4[0]+(p4[1]+(p4[2]+(p4[3]+p4[4]*u)*u)*u)*u)/ - (q4[0]+(q4[1]+(q4[2]+(q4[3]+q4[4]*u)*u)*u)*u); + u = 1 / v; + denlan = u * u * (p4[0] + (p4[1] + (p4[2] + (p4[3] + p4[4] * u) * u) * u) * u) + / (q4[0] + (q4[1] + (q4[2] + (q4[3] + q4[4] * u) * u) * u) * u); } else if(v < 50) { - u = 1/v; - denlan = u*u*(p5[0]+(p5[1]+(p5[2]+(p5[3]+p5[4]*u)*u)*u)*u)/ - (q5[0]+(q5[1]+(q5[2]+(q5[3]+q5[4]*u)*u)*u)*u); + u = 1 / v; + denlan = u * u * (p5[0] + (p5[1] + (p5[2] + (p5[3] + p5[4] * u) * u) * u) * u) + / (q5[0] + (q5[1] + (q5[2] + (q5[3] + q5[4] * u) * u) * u) * u); } else if(v < 300) { - u = 1/v; - denlan = u*u*(p6[0]+(p6[1]+(p6[2]+(p6[3]+p6[4]*u)*u)*u)*u)/ - (q6[0]+(q6[1]+(q6[2]+(q6[3]+q6[4]*u)*u)*u)*u); + u = 1 / v; + denlan = u * u * (p6[0] + (p6[1] + (p6[2] + (p6[3] + p6[4] * u) * u) * u) * u) + / (q6[0] + (q6[1] + (q6[2] + (q6[3] + q6[4] * u) * u) * u) * u); } else { - u = 1/(v-v*std::log(v)/(v+1)); - denlan = u*u*(1+(a2[0]+a2[1]*u)*u); + u = 1 / (v - v * std::log(v) / (v + 1)); + denlan = u * u * (1 + (a2[0] + a2[1] * u) * u); } - return denlan/sigma; + return denlan / sigma; } __device__ device_function_ptr ptr_to_Landau = device_Landau; -__host__ LandauPdf::LandauPdf(std::string n, Variable* _x, Variable* mpv, Variable* sigma) +__host__ LandauPdf::LandauPdf(std::string n, Variable *_x, Variable *mpv, Variable *sigma) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mpv)); @@ -89,6 +87,4 @@ __host__ LandauPdf::LandauPdf(std::string n, Variable* _x, Variable* mpv, Variab initialize(pindices); } - } // namespace GooFit - diff --git a/src/PDFs/LineshapesPdf.cu b/src/PDFs/LineshapesPdf.cu index 5b26054e8..3c3e13104 100644 --- a/src/PDFs/LineshapesPdf.cu +++ b/src/PDFs/LineshapesPdf.cu @@ -5,7 +5,8 @@ DISCLAIMER: This code is not sufficently tested yet and still under heavy development! This file includes some lineshapes and spinfactors. -Also right now it is the home to some helper functions needed and an implementation of a simple 4-vec class that works on the GPU +Also right now it is the home to some helper functions needed and an implementation of a simple 4-vec class that works +on the GPU */ #include "goofit/PDFs/physics/LineshapesPdf.h" @@ -14,16 +15,14 @@ Also right now it is the home to some helper functions needed and an implementat namespace GooFit { - - // Form factors as in pdg http://pdg.lbl.gov/2012/reviews/rpp2012-rev-dalitz-analysis-formalism.pdf __device__ fptype BL_PRIME(fptype z2, fptype z02, int L) { - if(0 ==L) + if(0 == L) return 1.0; else if(1 == L) - return(1+z02)/(1+z2); + return (1 + z02) / (1 + z2); else if(2 == L) - return (z02*z02 + 3*z02 + 9) / (z2*z2 + 3*z2 + 9) ; + return (z02 * z02 + 3 * z02 + 9) / (z2 * z2 + 3 * z2 + 9); else { printf("ERROR! Oribtal > 2 not supported!\n"); return 0; @@ -33,12 +32,12 @@ __device__ fptype BL_PRIME(fptype z2, fptype z02, int L) { } __device__ fptype BL(fptype z2, int L) { - if(0 ==L) + if(0 == L) return 1.0; - else if(1==L) - return 2*z2/(1+z2); - else if(2==L) - return (13*z2*z2)/ (z2*z2 + 3*z2 + 9) ; + else if(1 == L) + return 2 * z2 / (1 + z2); + else if(2 == L) + return (13 * z2 * z2) / (z2 * z2 + 3 * z2 + 9); else { printf("ERROR! Oribtal > 2 not supported!\n"); return 0; @@ -48,12 +47,12 @@ __device__ fptype BL(fptype z2, int L) { } __device__ fptype BL2(fptype z2, int L) { - if(0 ==L) + if(0 == L) return 1.0; - else if(1==L) - return 1.0/(1+z2); - else if(2==L) - return 1.0/ (z2*z2 + 3*z2 + 9) ; + else if(1 == L) + return 1.0 / (1 + z2); + else if(2 == L) + return 1.0 / (z2 * z2 + 3 * z2 + 9); else { printf("ERROR! Oribtal > 2 not supported!\n"); return 0; @@ -62,390 +61,417 @@ __device__ fptype BL2(fptype z2, int L) { // Spin 3 and up not accounted for. } -__device__ thrust::complex LS_ONE(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { +__device__ thrust::complex LS_ONE(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { return thrust::complex(1, 0); } -//This function is modeled after BW_BW::getVal() in BW_BW.cpp from the MINT package written by Jonas Rademacker. -__device__ thrust::complex BW(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype meson_radius = functorConstants[indices[7]]; - fptype resmass = cudaArray[indices[2]]; - fptype reswidth = cudaArray[indices[3]]; - unsigned int orbital = indices[4]; - unsigned int FF = indices[6]; - - const unsigned int to2Lplus1 = 2 * orbital + 1; +// This function is modeled after BW_BW::getVal() in BW_BW.cpp from the MINT package written by Jonas Rademacker. +__device__ thrust::complex BW(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype meson_radius = functorConstants[indices[7]]; + fptype resmass = cudaArray[indices[2]]; + fptype reswidth = cudaArray[indices[3]]; + unsigned int orbital = indices[4]; + unsigned int FF = indices[6]; - fptype mass = resmass; - fptype width = reswidth; - fptype mumsRecoMass2 = Mpair*Mpair; + const unsigned int to2Lplus1 = 2 * orbital + 1; + fptype mass = resmass; + fptype width = reswidth; + fptype mumsRecoMass2 = Mpair * Mpair; - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (mumsRecoMass2 - mpsq)*(mumsRecoMass2 - mmsq); - fptype num2 = (mass*mass - mpsq)*(mass*mass - mmsq); - fptype pABSq = num/(4*mumsRecoMass2); - fptype prSqForGofM = num2/(4*mass*mass); - fptype prSq2 = prSqForGofM < 0 ? 0 : prSqForGofM; - prSqForGofM = fabs(prSqForGofM); + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (mumsRecoMass2 - mpsq) * (mumsRecoMass2 - mmsq); + fptype num2 = (mass * mass - mpsq) * (mass * mass - mmsq); + fptype pABSq = num / (4 * mumsRecoMass2); + fptype prSqForGofM = num2 / (4 * mass * mass); + fptype prSq2 = prSqForGofM < 0 ? 0 : prSqForGofM; + prSqForGofM = fabs(prSqForGofM); - fptype pratio = sqrt(pABSq/prSqForGofM); + fptype pratio = sqrt(pABSq / prSqForGofM); fptype pratio_to_2Jplus1 = 1; - for(int i=0; i < to2Lplus1; i++) { + for(int i = 0; i < to2Lplus1; i++) { pratio_to_2Jplus1 *= pratio; } - fptype mratio = mass/Mpair; - fptype r2 = meson_radius*meson_radius; - fptype thisFR = BL_PRIME(pABSq*r2, prSqForGofM*r2, orbital); + fptype mratio = mass / Mpair; + fptype r2 = meson_radius * meson_radius; + fptype thisFR = BL_PRIME(pABSq * r2, prSqForGofM * r2, orbital); fptype frFactor = 1; if(0 != orbital and 0 != FF) { - frFactor = (FF==1? BL(pABSq*r2, orbital) : BL_PRIME(pABSq*r2, prSq2*r2, orbital)); - frFactor = (FF==3? BL2(pABSq*r2, orbital) : frFactor); + frFactor = (FF == 1 ? BL(pABSq * r2, orbital) : BL_PRIME(pABSq * r2, prSq2 * r2, orbital)); + frFactor = (FF == 3 ? BL2(pABSq * r2, orbital) : frFactor); } - fptype GofM = width * pratio_to_2Jplus1 *mratio * thisFR; + fptype GofM = width * pratio_to_2Jplus1 * mratio * thisFR; - fptype gamma = mass*sqrt((mass*mass + width*width)); - fptype k = (2.0*sqrt(2.0)/M_PI) * mass*width*gamma/sqrt(mass*mass - +gamma); //Note added additional factor of 2*sqrt(2)/PI here so results are comparable to MINT3. MINT2 doesn't have include this. + fptype gamma = mass * sqrt((mass * mass + width * width)); + fptype k = (2.0 * sqrt(2.0) / M_PI) * mass * width * gamma + / sqrt(mass * mass + gamma); // Note added additional factor of 2*sqrt(2)/PI here so results are + // comparable to MINT3. MINT2 doesn't have include this. - thrust::complex BW(mass*mass - mumsRecoMass2, mass*GofM); - fptype den = (mass*mass - mumsRecoMass2) * (mass*mass - mumsRecoMass2) + mass * GofM * mass * GofM; + thrust::complex BW(mass * mass - mumsRecoMass2, mass * GofM); + fptype den = (mass * mass - mumsRecoMass2) * (mass * mass - mumsRecoMass2) + mass * GofM * mass * GofM; - thrust::complex ret = (sqrt(k * frFactor))/den * BW; + thrust::complex ret = (sqrt(k * frFactor)) / den * BW; // printf("m1, m2, Mpair, to2Lplus1, GofM, thisFR, pratio, mratio, pABSq , prSqForGofM, FF, ret.real, ret.imag\n"); - // printf("BW %.7g, %.7g, %.7g, %i, %i, %i, %i\n",meson_radius, resmass, reswidth, orbital, FF, indices[2], indices[3]); - // printf("BW %.7g, %.7g, %.7g, %i, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g\n", m1, m2, Mpair, to2Lplus1, GofM, thisFR, pratio, mratio, pABSq, prSqForGofM, frFactor, ret.real, ret.imag ); - return ret ; + // printf("BW %.7g, %.7g, %.7g, %i, %i, %i, %i\n",meson_radius, resmass, reswidth, orbital, FF, indices[2], + // indices[3]); + // printf("BW %.7g, %.7g, %.7g, %i, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g\n", m1, m2, Mpair, + // to2Lplus1, GofM, thisFR, pratio, mratio, pABSq, prSqForGofM, frFactor, ret.real, ret.imag ); + return ret; } -//This function is modeled after SBW from the MINT package written by Jonas Rademacker. -__device__ thrust::complex SBW(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype meson_radius = functorConstants[indices[7]]; - fptype resmass = cudaArray[indices[2]]; - fptype reswidth = cudaArray[indices[3]]; - unsigned int orbital = indices[4]; - unsigned int FF = indices[6]; - - fptype mass = resmass; - fptype width = reswidth; - fptype mumsRecoMass2 = Mpair*Mpair; - - - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (mumsRecoMass2 - mpsq)*(mumsRecoMass2 - mmsq); - fptype num2 = (mass*mass - mpsq)*(mass*mass - mmsq); - fptype pABSq = num/(4*mumsRecoMass2); - fptype prSq = num2/(4*mass*mass); +// This function is modeled after SBW from the MINT package written by Jonas Rademacker. +__device__ thrust::complex SBW(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype meson_radius = functorConstants[indices[7]]; + fptype resmass = cudaArray[indices[2]]; + fptype reswidth = cudaArray[indices[3]]; + unsigned int orbital = indices[4]; + unsigned int FF = indices[6]; + + fptype mass = resmass; + fptype width = reswidth; + fptype mumsRecoMass2 = Mpair * Mpair; + + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (mumsRecoMass2 - mpsq) * (mumsRecoMass2 - mmsq); + fptype num2 = (mass * mass - mpsq) * (mass * mass - mmsq); + fptype pABSq = num / (4 * mumsRecoMass2); + fptype prSq = num2 / (4 * mass * mass); fptype prSq2 = prSq < 0 ? 0 : prSq; - prSq = fabs(prSq); + prSq = fabs(prSq); - fptype r2 = meson_radius*meson_radius; + fptype r2 = meson_radius * meson_radius; fptype frFactor = 1; if(0 != orbital and 0 != FF) { - frFactor = (FF==1? BL(pABSq*r2, orbital) : BL_PRIME(pABSq*r2, prSq2*r2, orbital)); - frFactor = (FF==3? BL2(pABSq*r2, orbital) : frFactor); + frFactor = (FF == 1 ? BL(pABSq * r2, orbital) : BL_PRIME(pABSq * r2, prSq2 * r2, orbital)); + frFactor = (FF == 3 ? BL2(pABSq * r2, orbital) : frFactor); } fptype GofM = width; - fptype gamma = sqrt(mass*mass*(mass*mass + width*width)); - fptype k = mass*width*gamma/sqrt(mass*mass+gamma); + fptype gamma = sqrt(mass * mass * (mass * mass + width * width)); + fptype k = mass * width * gamma / sqrt(mass * mass + gamma); - thrust::complex BW(mass*mass - mumsRecoMass2, mass*GofM); - fptype den = (mass*mass - mumsRecoMass2) * (mass*mass - mumsRecoMass2) + mass * GofM * mass * GofM; + thrust::complex BW(mass * mass - mumsRecoMass2, mass * GofM); + fptype den = (mass * mass - mumsRecoMass2) * (mass * mass - mumsRecoMass2) + mass * GofM * mass * GofM; - thrust::complex ret = (sqrt(k * frFactor))/den * BW; + thrust::complex ret = (sqrt(k * frFactor)) / den * BW; // printf("m1, m2, Mpair, GofM, pABSq , prSq, FF, ret.real, ret.imag\n"); - // printf("SBW %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g\n", m1, m2, Mpair, GofM, pABSq, prSq, frFactor, ret.real, ret.imag ); - return ret ; + // printf("SBW %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g, %.7g\n", m1, m2, Mpair, GofM, pABSq, prSq, frFactor, + // ret.real, ret.imag ); + return ret; } -__device__ thrust::complex bugg_rho2(const fptype& s, const fptype m) { - fptype rho_squared = 1. - 4. * m*m /s; - thrust::complex returnVal = (rho_squared >= 0) ? thrust::complex(1, 0) : thrust::complex(0, 1); +__device__ thrust::complex bugg_rho2(const fptype &s, const fptype m) { + fptype rho_squared = 1. - 4. * m * m / s; + thrust::complex returnVal + = (rho_squared >= 0) ? thrust::complex(1, 0) : thrust::complex(0, 1); rho_squared = (rho_squared >= 0) ? sqrt(rho_squared) : sqrt(-rho_squared); return rho_squared * returnVal; } -__device__ fptype bugg_j1(const fptype& s, const fptype m) { - fptype rho_pipi = bugg_rho2(s, m).real(); +__device__ fptype bugg_j1(const fptype &s, const fptype m) { + fptype rho_pipi = bugg_rho2(s, m).real(); fptype returnVal = 2.; - returnVal += (rho_pipi>0.) ? rho_pipi * log((1.-rho_pipi)/(1.+rho_pipi)) : 0; - return returnVal/M_PI; + returnVal += (rho_pipi > 0.) ? rho_pipi * log((1. - rho_pipi) / (1. + rho_pipi)) : 0; + return returnVal / M_PI; } -__device__ fptype bugg_Gamma_4pi(const fptype& s, const fptype mpi, const fptype& g_4pi, const fptype& M, - const fptype& lambda_4pi, const fptype& s0_4pi) { - fptype returnVal = (s < (16. * mpi*mpi)) ? 0 : g_4pi* (1./(1+exp(lambda_4pi*(s0_4pi-s))))/(1./(1+exp(lambda_4pi* - (s0_4pi-M*M)))); +__device__ fptype bugg_Gamma_4pi(const fptype &s, + const fptype mpi, + const fptype &g_4pi, + const fptype &M, + const fptype &lambda_4pi, + const fptype &s0_4pi) { + fptype returnVal = (s < (16. * mpi * mpi)) ? 0 + : g_4pi * (1. / (1 + exp(lambda_4pi * (s0_4pi - s)))) + / (1. / (1 + exp(lambda_4pi * (s0_4pi - M * M)))); return returnVal; } -//This function is an adaptation from the bugg lineshape implemented in the MINT package written by Jonas Rademacker. +// This function is an adaptation from the bugg lineshape implemented in the MINT package written by Jonas Rademacker. // this lineshape is not tested yet! -__device__ thrust::complex bugg_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype s = Mpair*Mpair; - - fptype M = 0.953; - fptype b1 = 1.302; - fptype b2 = 0.340; - fptype A = 2.426; - fptype g_4pi = 0.011; - fptype g_2K = 0.6; - fptype g_2eta = 0.2; - fptype alpha = 1.3; - fptype sA = 0.41; - fptype s0_4pi = 7.082/2.845; - fptype lambda_4pi = 2.845; - fptype mPiPlus = .13957018; - fptype mKPlus = .493677; - fptype mEta = .54751; - - fptype g1sq = (b1+b2*s)*exp(-(s-M*M)/A); - fptype z = bugg_j1(s, mPiPlus) - bugg_j1(M*M, mPiPlus); - - thrust::complex gamma_2pi = thrust::complex(g1sq * (s -sA*mPiPlus*mPiPlus)/(M*M -sA*mPiPlus*mPiPlus) *bugg_rho2(s, - mPiPlus).real(), 0); - thrust::complex gamma_2K = g_2K * g1sq * s/(M*M) * exp((-1)*alpha * sqrt((s-4.*mKPlus*mKPlus)* - (s-4.*mKPlus*mKPlus))) * bugg_rho2(s, mKPlus); - thrust::complex gamma_2eta = g_2eta * g1sq * s/(M*M) * exp((-1)*alpha * sqrt((s-4.*mEta*mEta)* - (s-4.*mEta*mEta))) * bugg_rho2(s, mEta); - thrust::complex gamma_4pi = thrust::complex(bugg_Gamma_4pi(s, mPiPlus, g_4pi, M, lambda_4pi, s0_4pi), 0); +__device__ thrust::complex bugg_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype s = Mpair * Mpair; + + fptype M = 0.953; + fptype b1 = 1.302; + fptype b2 = 0.340; + fptype A = 2.426; + fptype g_4pi = 0.011; + fptype g_2K = 0.6; + fptype g_2eta = 0.2; + fptype alpha = 1.3; + fptype sA = 0.41; + fptype s0_4pi = 7.082 / 2.845; + fptype lambda_4pi = 2.845; + fptype mPiPlus = .13957018; + fptype mKPlus = .493677; + fptype mEta = .54751; + + fptype g1sq = (b1 + b2 * s) * exp(-(s - M * M) / A); + fptype z = bugg_j1(s, mPiPlus) - bugg_j1(M * M, mPiPlus); + + thrust::complex gamma_2pi = thrust::complex( + g1sq * (s - sA * mPiPlus * mPiPlus) / (M * M - sA * mPiPlus * mPiPlus) * bugg_rho2(s, mPiPlus).real(), 0); + thrust::complex gamma_2K + = g_2K * g1sq * s / (M * M) * exp((-1) * alpha * sqrt((s - 4. * mKPlus * mKPlus) * (s - 4. * mKPlus * mKPlus))) + * bugg_rho2(s, mKPlus); + thrust::complex gamma_2eta = g_2eta * g1sq * s / (M * M) + * exp((-1) * alpha * sqrt((s - 4. * mEta * mEta) * (s - 4. * mEta * mEta))) + * bugg_rho2(s, mEta); + thrust::complex gamma_4pi + = thrust::complex(bugg_Gamma_4pi(s, mPiPlus, g_4pi, M, lambda_4pi, s0_4pi), 0); thrust::complex Gamma_tot = gamma_2pi + gamma_2K + gamma_2eta + gamma_4pi; // thrust::complex num = M * gamma_2pi; //only for elastic scattering, not production - thrust::complex den = thrust::complex(M*M - s - M * g1sq * (s-sA*mPiPlus*mPiPlus) / (M*M-sA*mPiPlus*mPiPlus) * z, - 0) - thrust::complex(0, 1) * M * Gamma_tot; - thrust::complex returnVal = 1.0/den; - // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",gamma_2pi.real, gamma_2pi.imag, gamma_2K.real, gamma_2K.imag, gamma_2eta.real, gamma_2eta.imag, gamma_4pi.real, gamma_4pi.imag); - // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Mpair, Gamma_tot.real, Gamma_tot.imag, g1sq, z, den.real, den.imag, returnVal.real, returnVal.imag); - - //the factor sqrt(1000) gives the correct result in comparison with mint2, I think its because BW/SBW - // have a factor of sqrt(k) which these lineshapes dont have. For now this stays because it works. further investigation needed. - return returnVal*sqrt(1000.0); + thrust::complex den + = thrust::complex( + M * M - s - M * g1sq * (s - sA * mPiPlus * mPiPlus) / (M * M - sA * mPiPlus * mPiPlus) * z, 0) + - thrust::complex(0, 1) * M * Gamma_tot; + thrust::complex returnVal = 1.0 / den; + // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",gamma_2pi.real, gamma_2pi.imag, gamma_2K.real, + // gamma_2K.imag, gamma_2eta.real, gamma_2eta.imag, gamma_4pi.real, gamma_4pi.imag); + // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Mpair, Gamma_tot.real, Gamma_tot.imag, g1sq, z, + // den.real, den.imag, returnVal.real, returnVal.imag); + + // the factor sqrt(1000) gives the correct result in comparison with mint2, I think its because BW/SBW + // have a factor of sqrt(k) which these lineshapes dont have. For now this stays because it works. further + // investigation needed. + return returnVal * sqrt(1000.0); } -__device__ thrust::complex bugg_MINT3(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype s = Mpair*Mpair; - fptype M = 0.953; - fptype b1 = 1.302; - fptype b2 = 0.340; - fptype A = 2.426; - fptype g_4pi = 0.011; - fptype g_2K = 0.6; - fptype g_2eta = 0.2; - fptype alpha = 1.3; - fptype s0_4pi = 7.082/2.845; - fptype lambda_4pi = 2.845; - fptype mPiPlus = .13957018; - fptype mKPlus = .493677; - fptype mEta = .547862; - fptype sA = 0.41*mPiPlus*mPiPlus; - - fptype g1sq = M* (b1+b2*s)*exp(-(s-M*M)/A); - fptype z = bugg_j1(s, mPiPlus) - bugg_j1(M*M, mPiPlus); - fptype adlerZero = (s - sA) / (M * M - sA) ; - - fptype mk4 = 4.*mKPlus*mKPlus; - fptype me4 = 4.*mEta*mEta; - fptype tmp1 = s>mk4 ? s-mk4 : mk4-s; - fptype tmp2 = s>me4 ? s-me4 : me4-s; - - thrust::complex gamma_2pi = thrust::complex(g1sq * adlerZero *bugg_rho2(s, mPiPlus).real(), 0); - thrust::complex gamma_2K = g_2K * g1sq * s/(M*M) * exp((-1)*alpha * tmp1) * bugg_rho2(s, mKPlus); - thrust::complex gamma_2eta = g_2eta * g1sq * s/(M*M) * exp((-1)*alpha * tmp2) * bugg_rho2(s, mEta); - thrust::complex gamma_4pi = thrust::complex(bugg_Gamma_4pi(s, mPiPlus, g_4pi, M, lambda_4pi, s0_4pi), 0); +__device__ thrust::complex bugg_MINT3(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype s = Mpair * Mpair; + fptype M = 0.953; + fptype b1 = 1.302; + fptype b2 = 0.340; + fptype A = 2.426; + fptype g_4pi = 0.011; + fptype g_2K = 0.6; + fptype g_2eta = 0.2; + fptype alpha = 1.3; + fptype s0_4pi = 7.082 / 2.845; + fptype lambda_4pi = 2.845; + fptype mPiPlus = .13957018; + fptype mKPlus = .493677; + fptype mEta = .547862; + fptype sA = 0.41 * mPiPlus * mPiPlus; + + fptype g1sq = M * (b1 + b2 * s) * exp(-(s - M * M) / A); + fptype z = bugg_j1(s, mPiPlus) - bugg_j1(M * M, mPiPlus); + fptype adlerZero = (s - sA) / (M * M - sA); + + fptype mk4 = 4. * mKPlus * mKPlus; + fptype me4 = 4. * mEta * mEta; + fptype tmp1 = s > mk4 ? s - mk4 : mk4 - s; + fptype tmp2 = s > me4 ? s - me4 : me4 - s; + + thrust::complex gamma_2pi = thrust::complex(g1sq * adlerZero * bugg_rho2(s, mPiPlus).real(), 0); + thrust::complex gamma_2K = g_2K * g1sq * s / (M * M) * exp((-1) * alpha * tmp1) * bugg_rho2(s, mKPlus); + thrust::complex gamma_2eta = g_2eta * g1sq * s / (M * M) * exp((-1) * alpha * tmp2) * bugg_rho2(s, mEta); + thrust::complex gamma_4pi + = thrust::complex(bugg_Gamma_4pi(s, mPiPlus, g_4pi, M, lambda_4pi, s0_4pi), 0); thrust::complex Gamma_tot = gamma_2pi + gamma_2K + gamma_2eta + gamma_4pi; // thrust::complex num = M * gamma_2pi; //only for elastic scattering, not production - thrust::complex den = thrust::complex(M*M - s - adlerZero * g1sq* z, 0) - thrust::complex(0, 1) * Gamma_tot; - thrust::complex returnVal = 1.0/den; - // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",gamma_2pi.real, gamma_2pi.imag, gamma_2K.real, gamma_2K.imag, gamma_2eta.real, gamma_2eta.imag, gamma_4pi.real, gamma_4pi.imag); - // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Mpair, Gamma_tot.real, Gamma_tot.imag, g1sq, z, den.real, den.imag, returnVal.real, returnVal.imag); + thrust::complex den + = thrust::complex(M * M - s - adlerZero * g1sq * z, 0) - thrust::complex(0, 1) * Gamma_tot; + thrust::complex returnVal = 1.0 / den; + // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",gamma_2pi.real, gamma_2pi.imag, gamma_2K.real, + // gamma_2K.imag, gamma_2eta.real, gamma_2eta.imag, gamma_4pi.real, gamma_4pi.imag); + // printf("Bugg %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Mpair, Gamma_tot.real, Gamma_tot.imag, g1sq, z, + // den.real, den.imag, returnVal.real, returnVal.imag); return returnVal; } -__device__ thrust::complex lass_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype resmass = cudaArray[indices[2]]; - fptype reswidth = cudaArray[indices[3]]; - fptype rMass2 = Mpair*Mpair; +__device__ thrust::complex lass_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype resmass = cudaArray[indices[2]]; + fptype reswidth = cudaArray[indices[3]]; + fptype rMass2 = Mpair * Mpair; fptype a = 2.07; fptype r = 3.32; - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (rMass2 - mpsq)*(rMass2 - mmsq); - fptype num2 = (resmass*resmass - mpsq)*(resmass*resmass - mmsq); - fptype pABSq = num/(4*rMass2); - fptype prSq = fabs(num2/(4*resmass*resmass)); + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (rMass2 - mpsq) * (rMass2 - mmsq); + fptype num2 = (resmass * resmass - mpsq) * (resmass * resmass - mmsq); + fptype pABSq = num / (4 * rMass2); + fptype prSq = fabs(num2 / (4 * resmass * resmass)); - fptype y = 2.0 * a*sqrt(pABSq); - fptype x = 2.0 + a * r * pABSq; + fptype y = 2.0 * a * sqrt(pABSq); + fptype x = 2.0 + a * r * pABSq; fptype cotDeltaBg = x / y; - thrust::complex phaseshift((cotDeltaBg*cotDeltaBg-1)/(1+cotDeltaBg*cotDeltaBg), - 2*cotDeltaBg / (1 + cotDeltaBg*cotDeltaBg)); - // (cotDeltaBg*cotDeltaBg-1)/(1+cotDeltaBg*cotDeltaBg) = cos(2*delta) 2*cotDeltaBg / ( 1 + cotDeltaBg*cotDeltaBg) = sin(2*delta) - thrust::complex den(sqrt(pABSq)*cotDeltaBg, (-1.)*sqrt(pABSq)); - fptype SF = Mpair * sqrt(prSq) / (resmass * resmass*reswidth); - thrust::complex BG = SF / den ; + thrust::complex phaseshift((cotDeltaBg * cotDeltaBg - 1) / (1 + cotDeltaBg * cotDeltaBg), + 2 * cotDeltaBg / (1 + cotDeltaBg * cotDeltaBg)); + // (cotDeltaBg*cotDeltaBg-1)/(1+cotDeltaBg*cotDeltaBg) = cos(2*delta) 2*cotDeltaBg / ( 1 + + // cotDeltaBg*cotDeltaBg) = sin(2*delta) + thrust::complex den(sqrt(pABSq) * cotDeltaBg, (-1.) * sqrt(pABSq)); + fptype SF = Mpair * sqrt(prSq) / (resmass * resmass * reswidth); + thrust::complex BG = SF / den; thrust::complex returnVal = BG + phaseshift * BW(Mpair, m1, m2, indices); - // printf("Lass: %.5g %.5g %.5g %.5g %.5g %.5g\n",BG.real, BG.imag, phaseshift.real, phaseshift.imag, returnVal.real, returnVal.imag); + // printf("Lass: %.5g %.5g %.5g %.5g %.5g %.5g\n",BG.real, BG.imag, phaseshift.real, phaseshift.imag, + // returnVal.real, returnVal.imag); return returnVal; } -//generalized lass lineshape as implemented in MINT3 by Tim Evans. if F=R=1 and phiF=phiR=0 this is equal to normal lass as implemented in Mint3. -//The difference between this and lass mint is not quite clear to me. need to get back to this later. -__device__ thrust::complex glass_MINT3(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype meson_radius = functorConstants[indices[7]]; - fptype resmass = cudaArray[indices[2]]; - fptype reswidth = cudaArray[indices[3]]; - unsigned int orbital = indices[4]; - fptype rMass2 = Mpair*Mpair; +// generalized lass lineshape as implemented in MINT3 by Tim Evans. if F=R=1 and phiF=phiR=0 this is equal to normal +// lass as implemented in Mint3. +// The difference between this and lass mint is not quite clear to me. need to get back to this later. +__device__ thrust::complex glass_MINT3(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype meson_radius = functorConstants[indices[7]]; + fptype resmass = cudaArray[indices[2]]; + fptype reswidth = cudaArray[indices[3]]; + unsigned int orbital = indices[4]; + fptype rMass2 = Mpair * Mpair; // fptype a = 2.07; // fptype r = 3.32; // fptype phiF = 0.0; // fptype phiR = 0.0; // fptype F = 1.0; - fptype a = cudaArray[indices[8]]; - fptype r = cudaArray[indices[9]]; + fptype a = cudaArray[indices[8]]; + fptype r = cudaArray[indices[9]]; fptype phiF = cudaArray[indices[10]]; fptype phiR = cudaArray[indices[11]]; - fptype F = cudaArray[indices[12]]; + fptype F = cudaArray[indices[12]]; - fptype R = 1.0; + fptype R = 1.0; // printf("GLass: %.5g %.5g %.5g %.5g %.5g %.5g\n",a, r, phiF, phiR, F, R); // printf("GLass2: %.5g %.5g %.5g %u \n",meson_radius, resmass, reswidth, orbital); - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (rMass2 - mpsq)*(rMass2 - mmsq); - fptype num2 = (resmass*resmass - mpsq)*(resmass*resmass - mmsq); - fptype pABSq = num/(4*rMass2); - fptype prSq = fabs(num2/(4*resmass*resmass)); + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (rMass2 - mpsq) * (rMass2 - mmsq); + fptype num2 = (resmass * resmass - mpsq) * (resmass * resmass - mmsq); + fptype pABSq = num / (4 * rMass2); + fptype prSq = fabs(num2 / (4 * resmass * resmass)); - fptype pratio = sqrt(pABSq/prSq); + fptype pratio = sqrt(pABSq / prSq); fptype pratio_to_2Jplus1 = 1; - for(int i=0; i < 2*orbital+1; i++) { + for(int i = 0; i < 2 * orbital + 1; i++) { pratio_to_2Jplus1 *= pratio; } - fptype mratio = resmass/Mpair; - fptype r2 = meson_radius*meson_radius; - fptype thisFR = BL_PRIME(pABSq*r2, prSq*r2, orbital); - fptype GofM = reswidth * pratio_to_2Jplus1 *mratio * thisFR; - + fptype mratio = resmass / Mpair; + fptype r2 = meson_radius * meson_radius; + fptype thisFR = BL_PRIME(pABSq * r2, prSq * r2, orbital); + fptype GofM = reswidth * pratio_to_2Jplus1 * mratio * thisFR; - fptype y = 2.0 * a*sqrt(pABSq); - fptype x = 2.0 + a * r * pABSq; - fptype scattphase = phiF + atan(y/x); - fptype resphase = phiR + atan(resmass*GofM/(resmass*resmass - rMass2)) ; - fptype rho = 1.0 / sqrt(pABSq/rMass2); + fptype y = 2.0 * a * sqrt(pABSq); + fptype x = 2.0 + a * r * pABSq; + fptype scattphase = phiF + atan(y / x); + fptype resphase = phiR + atan(resmass * GofM / (resmass * resmass - rMass2)); + fptype rho = 1.0 / sqrt(pABSq / rMass2); thrust::complex returnVal = (F * sin(scattphase) * thrust::complex(cos(scattphase), sin(scattphase)) - + R * sin(resphase) * thrust::complex(cos(resphase + 2 * scattphase), sin(resphase + 2 * scattphase))) - * rho; + + R * sin(resphase) * thrust::complex(cos(resphase + 2 * scattphase), + sin(resphase + 2 * scattphase))) + * rho; // printf("GLass3: %.5g %.5g %.5g %.5g %.5g %.5g\n",rMass2, pABSq, rho, GofM, scattphase, resphase); // printf("GLass4: %.5g %.5g\n",returnVal.real, returnVal.imag); return returnVal; } - - - -__device__ thrust::complex aSqrtTerm(const fptype& m0, const fptype& m) { - fptype a2 = 1 - (2*m0/m)*(2*m0/m); - thrust::complex returnVal = a2>0 ? thrust::complex(sqrt(a2), 0) : thrust::complex(0, sqrt(-a2)); +__device__ thrust::complex aSqrtTerm(const fptype &m0, const fptype &m) { + fptype a2 = 1 - (2 * m0 / m) * (2 * m0 / m); + thrust::complex returnVal + = a2 > 0 ? thrust::complex(sqrt(a2), 0) : thrust::complex(0, sqrt(-a2)); return returnVal; } -__device__ thrust::complex Flatte_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype meson_radius = functorConstants[indices[7]]; - fptype resmass = cudaArray[indices[2]]; - unsigned int orbital = indices[4]; - fptype frFactor = 1; - fptype rMass2 = Mpair*Mpair; +__device__ thrust::complex Flatte_MINT(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype meson_radius = functorConstants[indices[7]]; + fptype resmass = cudaArray[indices[2]]; + unsigned int orbital = indices[4]; + fptype frFactor = 1; + fptype rMass2 = Mpair * Mpair; // As far as I understand, this is only valid for the f980 - fptype gPi = .165; - fptype gK_by_gPi = 4.21; - fptype gK = gPi * gK_by_gPi; - fptype mPi0 = .1349766; - fptype mPiPlus = .13957018; - fptype mKPlus = .493677; - fptype mK0 = .497648; - - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (rMass2 - mpsq)*(rMass2 - mmsq); - //fptype num2 = (resmass*resmass - mpsq)*(resmass*resmass - mmsq); - fptype pABSq = num/(4*rMass2); - //fptype prSq = fabs(num2/(4*resmass*resmass)); - - thrust::complex Gpipi = (1./3.) * aSqrtTerm(mPi0, Mpair) + (2./3.) * aSqrtTerm(mPiPlus, Mpair); - thrust::complex GKK = (1./2.) * aSqrtTerm(mK0, Mpair) + (1./2.) * aSqrtTerm(mKPlus, Mpair); + fptype gPi = .165; + fptype gK_by_gPi = 4.21; + fptype gK = gPi * gK_by_gPi; + fptype mPi0 = .1349766; + fptype mPiPlus = .13957018; + fptype mKPlus = .493677; + fptype mK0 = .497648; + + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (rMass2 - mpsq) * (rMass2 - mmsq); + // fptype num2 = (resmass*resmass - mpsq)*(resmass*resmass - mmsq); + fptype pABSq = num / (4 * rMass2); + // fptype prSq = fabs(num2/(4*resmass*resmass)); + + thrust::complex Gpipi = (1. / 3.) * aSqrtTerm(mPi0, Mpair) + (2. / 3.) * aSqrtTerm(mPiPlus, Mpair); + thrust::complex GKK = (1. / 2.) * aSqrtTerm(mK0, Mpair) + (1. / 2.) * aSqrtTerm(mKPlus, Mpair); thrust::complex FlatteWidth = gPi * Gpipi + gK * GKK; - // printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Gpipi.real, Gpipi.imag, GKK.real, GKK.imag, FlatteWidth.real, FlatteWidth.imag, Mpair, pABSq); + // printf("%.5g %.5g %.5g %.5g %.5g %.5g %.5g %.5g \n",Gpipi.real, Gpipi.imag, GKK.real, GKK.imag, FlatteWidth.real, + // FlatteWidth.imag, Mpair, pABSq); - frFactor = BL2(pABSq*meson_radius*meson_radius, orbital); - thrust::complex BW = sqrt(frFactor) / thrust::complex(resmass*resmass - rMass2, 0) - thrust::complex(0, - 1) * resmass * FlatteWidth; + frFactor = BL2(pABSq * meson_radius * meson_radius, orbital); + thrust::complex BW = sqrt(frFactor) / thrust::complex(resmass * resmass - rMass2, 0) + - thrust::complex(0, 1) * resmass * FlatteWidth; return BW; } +__device__ thrust::complex nonres_DP(fptype Mpair, fptype m1, fptype m2, unsigned int *indices) { + fptype meson_radius = functorConstants[indices[7]]; + unsigned int orbital = indices[4]; -__device__ thrust::complex nonres_DP(fptype Mpair, fptype m1, fptype m2, unsigned int* indices) { - fptype meson_radius = functorConstants[indices[7]]; - unsigned int orbital = indices[4]; - - fptype mumsRecoMass2 = Mpair*Mpair; - + fptype mumsRecoMass2 = Mpair * Mpair; - fptype mpsq = (m1+m2)*(m1+m2); - fptype mmsq = (m1-m2)*(m1-m2); - fptype num = (mumsRecoMass2 - mpsq)*(mumsRecoMass2 - mmsq); - fptype pABSq = num/(4*mumsRecoMass2); - fptype formfactor = sqrt(BL2(pABSq*meson_radius*meson_radius, orbital)); - // printf("NonRes q2:%.7g FF:%.7g, s %.7g m1 %.7g m2 %.7g r %.7g L %u \n",pABSq, formfactor, mumsRecoMass2, m1,m2,meson_radius, orbital ); - return thrust::complex(1, 0)*formfactor; + fptype mpsq = (m1 + m2) * (m1 + m2); + fptype mmsq = (m1 - m2) * (m1 - m2); + fptype num = (mumsRecoMass2 - mpsq) * (mumsRecoMass2 - mmsq); + fptype pABSq = num / (4 * mumsRecoMass2); + fptype formfactor = sqrt(BL2(pABSq * meson_radius * meson_radius, orbital)); + // printf("NonRes q2:%.7g FF:%.7g, s %.7g m1 %.7g m2 %.7g r %.7g L %u \n",pABSq, formfactor, mumsRecoMass2, + // m1,m2,meson_radius, orbital ); + return thrust::complex(1, 0) * formfactor; } -__device__ resonance_function_ptr ptr_to_LS_ONE = LS_ONE; -__device__ resonance_function_ptr ptr_to_BW_DP4 = BW; -__device__ resonance_function_ptr ptr_to_lass = lass_MINT; -__device__ resonance_function_ptr ptr_to_glass3 = glass_MINT3; -__device__ resonance_function_ptr ptr_to_bugg_MINT = bugg_MINT; +__device__ resonance_function_ptr ptr_to_LS_ONE = LS_ONE; +__device__ resonance_function_ptr ptr_to_BW_DP4 = BW; +__device__ resonance_function_ptr ptr_to_lass = lass_MINT; +__device__ resonance_function_ptr ptr_to_glass3 = glass_MINT3; +__device__ resonance_function_ptr ptr_to_bugg_MINT = bugg_MINT; __device__ resonance_function_ptr ptr_to_bugg_MINT3 = bugg_MINT3; -__device__ resonance_function_ptr ptr_to_SBW = SBW; -__device__ resonance_function_ptr ptr_to_NONRES_DP = nonres_DP; -__device__ resonance_function_ptr ptr_to_Flatte = Flatte_MINT; +__device__ resonance_function_ptr ptr_to_SBW = SBW; +__device__ resonance_function_ptr ptr_to_NONRES_DP = nonres_DP; +__device__ resonance_function_ptr ptr_to_Flatte = Flatte_MINT; Lineshape::Lineshape(std::string name, - Variable* mass, - Variable* width, + Variable *mass, + Variable *width, unsigned int L, unsigned int Mpair, LS kind, FF FormFac, fptype radius, - std::vector AdditionalVars) - : GooPdf(nullptr, name), _mass(mass), _width(width), _L(L), _Mpair(Mpair), _kind(kind), _FormFac(FormFac) { + std::vector AdditionalVars) + : GooPdf(nullptr, name) + , _mass(mass) + , _width(width) + , _L(L) + , _Mpair(Mpair) + , _kind(kind) + , _FormFac(FormFac) { std::vector pindices; pindices.push_back(0); // Making room for index of decay-related constants. Assumption: @@ -458,10 +484,9 @@ Lineshape::Lineshape(std::string name, pindices.push_back(Mpair); pindices.push_back(enum_to_underlying(FormFac)); pindices.push_back(registerConstants(1)); - MEMCPY_TO_SYMBOL(functorConstants, &radius, sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(functorConstants, &radius, sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); switch(kind) { - case LS::ONE: GET_FUNCTION_ADDR(ptr_to_LS_ONE); break; @@ -477,7 +502,8 @@ Lineshape::Lineshape(std::string name, case LS::Lass_M3: if(5 != AdditionalVars.size()) { fprintf(stderr, - "It seems you forgot to provide the vector with the five necessary variables for GLASS, a, r, phiF, phiR and F (in that order)"); + "It seems you forgot to provide the vector with the five necessary variables for GLASS, a, " + "r, phiF, phiR and F (in that order)"); exit(0); } @@ -516,8 +542,6 @@ Lineshape::Lineshape(std::string name, initialize(pindices); } - - Lineshape::Lineshape(std::string name) : GooPdf(nullptr, name) { std::vector pindices; @@ -528,26 +552,22 @@ Lineshape::Lineshape(std::string name) initialize(pindices); } -Amplitude::Amplitude(std::string uniqueDecayStr, Variable* ar, Variable* ai, std::vector LS, - std::vector SF, unsigned int nPerm) - : _uniqueDecayStr(std::move(uniqueDecayStr)), - _ar(ar), - _ai(ai), - _SF(std::move(SF)), - _LS(std::move(LS)), - _nPerm(nPerm) -{} - -bool Amplitude::operator==(const Amplitude& A) const { - return _uniqueDecayStr==A._uniqueDecayStr - and _ar == A._ar - and _ai == A._ai - and _LS == A._LS - and _SF == A._SF +Amplitude::Amplitude(std::string uniqueDecayStr, + Variable *ar, + Variable *ai, + std::vector LS, + std::vector SF, + unsigned int nPerm) + : _uniqueDecayStr(std::move(uniqueDecayStr)) + , _ar(ar) + , _ai(ai) + , _SF(std::move(SF)) + , _LS(std::move(LS)) + , _nPerm(nPerm) {} + +bool Amplitude::operator==(const Amplitude &A) const { + return _uniqueDecayStr == A._uniqueDecayStr and _ar == A._ar and _ai == A._ai and _LS == A._LS and _SF == A._SF and _nPerm == A._nPerm; } - - } // namespace GooFit - diff --git a/src/PDFs/MappedPdf.cu b/src/PDFs/MappedPdf.cu index 8d4757431..3ac8596f7 100644 --- a/src/PDFs/MappedPdf.cu +++ b/src/PDFs/MappedPdf.cu @@ -2,31 +2,34 @@ namespace GooFit { - -__device__ fptype device_Mapped(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Mapped(fptype *evt, fptype *p, unsigned int *indices) { // Structure : nP mapFunctionIndex mapParamIndex functionIndex1 parameterIndex1 functionIndex2 parameterIndex2 ... // Find mapping between event variables and function to evaluate unsigned int mapFunction = RO_CACHE(indices[1]); // This is an index into the MappedPdf's list of functions - //int targetFunction = (int) floor(0.5 + (*(reinterpret_cast(device_function_table[mapFunction])))(evt, p, paramIndices + indices[2])); - auto targetFunction = static_cast( floor(0.5 + callFunction(evt, mapFunction, RO_CACHE(indices[2])))); + // int targetFunction = (int) floor(0.5 + + // (*(reinterpret_cast(device_function_table[mapFunction])))(evt, p, paramIndices + + // indices[2])); + auto targetFunction = static_cast(floor(0.5 + callFunction(evt, mapFunction, RO_CACHE(indices[2])))); targetFunction *= 2; // Because there are two pieces of information about each function targetFunction += 3; // Because first function information begins at index 3 - //fptype ret = (*(reinterpret_cast(device_function_table[indices[targetFunction]])))(evt, p, paramIndices + indices[targetFunction + 1]); + // fptype ret = (*(reinterpret_cast(device_function_table[indices[targetFunction]])))(evt, p, + // paramIndices + indices[targetFunction + 1]); fptype ret = callFunction(evt, RO_CACHE(indices[targetFunction]), RO_CACHE(indices[targetFunction + 1])); ret *= normalisationFactors[RO_CACHE(indices[targetFunction + 1])]; - //if (gpuDebug & 1) - //if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) - //printf("[%i, %i] Mapped: %i (%f %f %f %f) %f\n", BLOCKIDX, THREADIDX, targetFunction, evt[0], evt[1], evt[2], evt[3], ret); + // if (gpuDebug & 1) + // if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) + // printf("[%i, %i] Mapped: %i (%f %f %f %f) %f\n", BLOCKIDX, THREADIDX, targetFunction, evt[0], evt[1], evt[2], + // evt[3], ret); return ret; } __device__ device_function_ptr ptr_to_Mapped = device_Mapped; -__host__ MappedPdf::MappedPdf(std::string n, GooPdf* m, std::vector& t) +__host__ MappedPdf::MappedPdf(std::string n, GooPdf *m, std::vector &t) : GooPdf(nullptr, n) { components.push_back(m); std::vector pindices; @@ -35,7 +38,7 @@ __host__ MappedPdf::MappedPdf(std::string n, GooPdf* m, std::vector& t) std::set functionIndicesUsed; - for(GooPdf* f : t) { + for(GooPdf *f : t) { components.push_back(f); pindices.push_back(f->getFunctionIndex()); pindices.push_back(f->getParameterIndex()); @@ -43,8 +46,7 @@ __host__ MappedPdf::MappedPdf(std::string n, GooPdf* m, std::vector& t) } if(functionIndicesUsed.size() > 1) { - std::cout << "Warning: More than one function type given to MappedPdf " - << getName() + std::cout << "Warning: More than one function type given to MappedPdf " << getName() << " constructor. This may slow execution by causing sequential evaluations.\n"; } @@ -54,10 +56,10 @@ __host__ MappedPdf::MappedPdf(std::string n, GooPdf* m, std::vector& t) } __host__ fptype MappedPdf::normalize() const { - //std::cout << "Normalising MappedPdf " << getName() << std::endl; + // std::cout << "Normalising MappedPdf " << getName() << std::endl; fptype ret = 0; - for(unsigned int i = 1; i < components.size(); ++i) { // No need to normalize mapping function. + for(unsigned int i = 1; i < components.size(); ++i) { // No need to normalize mapping function. fptype curr = components[i]->normalize(); ret += curr; } @@ -66,4 +68,3 @@ __host__ fptype MappedPdf::normalize() const { return ret; } } // namespace GooFit - diff --git a/src/PDFs/MetricTaker.cu b/src/PDFs/MetricTaker.cu index a856d3af1..bbf222f85 100644 --- a/src/PDFs/MetricTaker.cu +++ b/src/PDFs/MetricTaker.cu @@ -21,14 +21,11 @@ namespace GooFit { - - - -__device__ fptype MetricTaker::operator()(thrust::tuple t) const { +__device__ fptype MetricTaker::operator()(thrust::tuple t) const { // Calculate event offset for this thread. - int eventIndex = thrust::get<0>(t); - int eventSize = thrust::get<2>(t); - fptype* eventAddress = thrust::get<1>(t) + (eventIndex * abs(eventSize)); + int eventIndex = thrust::get<0>(t); + int eventSize = thrust::get<2>(t); + fptype *eventAddress = thrust::get<1>(t) + (eventIndex * abs(eventSize)); // Causes stack size to be statically undeterminable. fptype ret = callFunction(eventAddress, functionIdx, parameters); @@ -37,64 +34,66 @@ __device__ fptype MetricTaker::operator()(thrust::tuple t) co // in the metric, so it doesn't matter what it is. For binned fits it is assumed that // the structure of the event is (obs1 obs2... binentry binvolume), so that the array // passed to the metric consists of (binentry binvolume). - ret = (*(reinterpret_cast(device_function_table[metricIndex])))(ret, - eventAddress + (abs(eventSize)-2), parameters); + ret = (*(reinterpret_cast(device_function_table[metricIndex])))( + ret, eventAddress + (abs(eventSize) - 2), parameters); return ret; } - #define MAX_NUM_OBSERVABLES 5 -__device__ fptype MetricTaker::operator()(thrust::tuple t) const { +__device__ fptype MetricTaker::operator()(thrust::tuple t) const { // Bin index, event size, base address [lower, upper,getNumBins] - int evtSize = thrust::get<1>(t); + int evtSize = thrust::get<1>(t); int binNumber = thrust::get<0>(t); - // Do not understand why this cannot be declared __shared__. Dynamically allocating shared memory is apparently complicated. - //fptype* binCenters = (fptype*) malloc(evtSize * sizeof(fptype)); - __shared__ fptype binCenters[1024*MAX_NUM_OBSERVABLES]; + // Do not understand why this cannot be declared __shared__. Dynamically allocating shared memory is apparently + // complicated. + // fptype* binCenters = (fptype*) malloc(evtSize * sizeof(fptype)); + __shared__ fptype binCenters[1024 * MAX_NUM_OBSERVABLES]; // To convert global bin number to (x,y,z...) coordinates: For each dimension, take the mod // with the number of bins in that dimension. Then divide by the number of bins, in effect // collapsing so the grid has one fewer dimension. Rinse and repeat. - unsigned int* indices = paramIndices + parameters; + unsigned int *indices = paramIndices + parameters; for(int i = 0; i < evtSize; ++i) { - fptype lowerBound = thrust::get<2>(t)[3*i+0]; - fptype upperBound = thrust::get<2>(t)[3*i+1]; - auto numBins = static_cast( floor(thrust::get<2>(t)[3*i+2] + 0.5)); - int localBin = binNumber % numBins; + fptype lowerBound = thrust::get<2>(t)[3 * i + 0]; + fptype upperBound = thrust::get<2>(t)[3 * i + 1]; + auto numBins = static_cast(floor(thrust::get<2>(t)[3 * i + 2] + 0.5)); + int localBin = binNumber % numBins; fptype x = upperBound - lowerBound; x /= numBins; x *= (localBin + 0.5); x += lowerBound; - binCenters[indices[indices[0] + 2 + i]+THREADIDX*MAX_NUM_OBSERVABLES] = x; + binCenters[indices[indices[0] + 2 + i] + THREADIDX * MAX_NUM_OBSERVABLES] = x; binNumber /= numBins; } // Causes stack size to be statically undeterminable. - fptype ret = callFunction(binCenters+THREADIDX*MAX_NUM_OBSERVABLES, functionIdx, parameters); + fptype ret = callFunction(binCenters + THREADIDX * MAX_NUM_OBSERVABLES, functionIdx, parameters); return ret; } - -MetricTaker::MetricTaker(PdfBase* dat, void* dev_functionPtr) +MetricTaker::MetricTaker(PdfBase *dat, void *dev_functionPtr) : metricIndex(0) , functionIdx(dat->getFunctionIndex()) , parameters(dat->getParameterIndex()) { - //std::cout << "MetricTaker constructor with " << functionIdx << std::endl; + // std::cout << "MetricTaker constructor with " << functionIdx << std::endl; auto localPos = functionAddressToDeviceIndexMap.find(dev_functionPtr); if(localPos != functionAddressToDeviceIndexMap.end()) { metricIndex = (*localPos).second; } else { - metricIndex = num_device_functions; - host_function_table[num_device_functions] = dev_functionPtr; + metricIndex = num_device_functions; + host_function_table[num_device_functions] = dev_functionPtr; functionAddressToDeviceIndexMap[dev_functionPtr] = num_device_functions; num_device_functions++; - MEMCPY_TO_SYMBOL(device_function_table, host_function_table, num_device_functions*sizeof(void*), 0, + MEMCPY_TO_SYMBOL(device_function_table, + host_function_table, + num_device_functions * sizeof(void *), + 0, cudaMemcpyHostToDevice); } } @@ -107,4 +106,3 @@ MetricTaker::MetricTaker(int fIdx, int pIdx) } } // namespace GooFit - diff --git a/src/PDFs/MixingTimeResolution_Aux.cu b/src/PDFs/MixingTimeResolution_Aux.cu index 14570d731..62ae172a3 100644 --- a/src/PDFs/MixingTimeResolution_Aux.cu +++ b/src/PDFs/MixingTimeResolution_Aux.cu @@ -3,12 +3,8 @@ namespace GooFit { - -MixingTimeResolution::MixingTimeResolution() = default; +MixingTimeResolution::MixingTimeResolution() = default; MixingTimeResolution::~MixingTimeResolution() = default; -void MixingTimeResolution::initIndex(void* dev_fcn_ptr) { - resFunctionIdx = GooPdf::findFunctionIdx(dev_fcn_ptr); -} +void MixingTimeResolution::initIndex(void *dev_fcn_ptr) { resFunctionIdx = GooPdf::findFunctionIdx(dev_fcn_ptr); } } // namespace GooFit - diff --git a/src/PDFs/NovosibirskPdf.cu b/src/PDFs/NovosibirskPdf.cu index ed266a81c..5f244f4c3 100644 --- a/src/PDFs/NovosibirskPdf.cu +++ b/src/PDFs/NovosibirskPdf.cu @@ -2,8 +2,7 @@ namespace GooFit { - -__device__ fptype device_Novosibirsk(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Novosibirsk(fptype *evt, fptype *p, unsigned int *indices) { fptype _Mean = p[indices[1]]; fptype _Sigma = p[indices[2]]; fptype _Tail = p[indices[3]]; @@ -15,18 +14,18 @@ __device__ fptype device_Novosibirsk(fptype* evt, fptype* p, unsigned int* indic fptype qx = 0; fptype qy = 0; - if(fabs(_Tail) < 1.e-7) { - qc = 0.5*POW2((x-_Mean)/_Sigma); + if(fabs(_Tail) < 1.e-7) { + qc = 0.5 * POW2((x - _Mean) / _Sigma); } else { - qa = _Tail*sqrt(log(4.)); - qb = sinh(qa)/qa; - qx = (x-_Mean)/_Sigma*qb; - qy = 1.+_Tail*qx; + qa = _Tail * sqrt(log(4.)); + qb = sinh(qa) / qa; + qx = (x - _Mean) / _Sigma * qb; + qy = 1. + _Tail * qx; //---- Cutting curve from right side if(qy > 1.e-7) - qc = 0.5*(POW2(log(qy)/_Tail) + _Tail*_Tail); + qc = 0.5 * (POW2(log(qy) / _Tail) + _Tail * _Tail); else qc = 15.0; } @@ -37,7 +36,7 @@ __device__ fptype device_Novosibirsk(fptype* evt, fptype* p, unsigned int* indic __device__ device_function_ptr ptr_to_Novosibirsk = device_Novosibirsk; -__host__ NovosibirskPdf::NovosibirskPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma, Variable* tail) +__host__ NovosibirskPdf::NovosibirskPdf(std::string n, Variable *_x, Variable *mean, Variable *sigma, Variable *tail) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(mean)); @@ -48,4 +47,3 @@ __host__ NovosibirskPdf::NovosibirskPdf(std::string n, Variable* _x, Variable* m } } // namespace GooFit - diff --git a/src/PDFs/PdfBase.cu b/src/PDFs/PdfBase.cu index 349595967..cab5ec2d6 100644 --- a/src/PDFs/PdfBase.cu +++ b/src/PDFs/PdfBase.cu @@ -12,7 +12,6 @@ namespace GooFit { - // This is code that belongs to the PdfBase class, that is, // it is common across all implementations. But it calls on device-side // functions, and due to the nvcc translation-unit limitations, it cannot @@ -20,7 +19,7 @@ namespace GooFit { // off on its own in this inline-cuda file, which GooPdf.cu // should include. -__host__ void PdfBase::copyParams(const std::vector& pars) const { +__host__ void PdfBase::copyParams(const std::vector &pars) const { // copyParams method performs eponymous action! for(unsigned int i = 0; i < pars.size(); ++i) { @@ -32,18 +31,18 @@ __host__ void PdfBase::copyParams(const std::vector& pars) const { } } - MEMCPY_TO_SYMBOL(cudaArray, host_params, pars.size()*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(cudaArray, host_params, pars.size() * sizeof(fptype), 0, cudaMemcpyHostToDevice); } __host__ void PdfBase::copyParams() { // Copies values of Variable objects - std::vector pars = getParameters(); + std::vector pars = getParameters(); std::vector values; - for(Variable* v : pars) { + for(Variable *v : pars) { int index = v->getIndex(); - if(index >= static_cast( values.size())) + if(index >= static_cast(values.size())) values.resize(index + 1); values[index] = v->getValue(); @@ -53,7 +52,7 @@ __host__ void PdfBase::copyParams() { } __host__ void PdfBase::copyNormFactors() const { - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); cudaDeviceSynchronize(); // Ensure normalisation integrals are finished } @@ -65,33 +64,37 @@ __host__ void PdfBase::initializeIndices(std::vector pindices) { // here we only reserve space for them by setting totalParams. // This is to allow index sharing between PDFs - all the PDFs must be constructed // before we know what observables exist. - + GOOFIT_DEBUG("Adding space for {} indices for {}", pindices.size(), getName()); if(totalParams + pindices.size() >= maxParams) - throw GooFit::GeneralError("totalParams {} + pindices {} must be less than {}", totalParams, pindices.size(), maxParams); + throw GooFit::GeneralError( + "totalParams {} + pindices {} must be less than {}", totalParams, pindices.size(), maxParams); host_indices[totalParams] = pindices.size(); for(int i = 1; i <= host_indices[totalParams]; ++i) { - GOOFIT_DEBUG("Setting host index {} to {}", totalParams+i, i-1); - host_indices[totalParams+i] = pindices[i-1]; + GOOFIT_DEBUG("Setting host index {} to {}", totalParams + i, i - 1); + host_indices[totalParams + i] = pindices[i - 1]; } - GOOFIT_DEBUG("Setting host index {} to the num of observables, {}", totalParams + pindices.size() + 1, observables.size()); + GOOFIT_DEBUG( + "Setting host index {} to the num of observables, {}", totalParams + pindices.size() + 1, observables.size()); host_indices[totalParams + pindices.size() + 1] = observables.size(); parameters = totalParams; totalParams += (2 + pindices.size() + observables.size()); GOOFIT_DEBUG("New total parameters: {}", totalParams); - + if(totalParams >= maxParams) - throw GooFit::GeneralError("{}: Set too many parameters, GooFit array more than {}. Increase max at compile time with -DGOOFIT_MAXPAR=N.", - getName(), maxParams); + throw GooFit::GeneralError("{}: Set too many parameters, GooFit array more than {}. Increase max at compile " + "time with -DGOOFIT_MAXPAR=N.", + getName(), + maxParams); - MEMCPY_TO_SYMBOL(paramIndices, host_indices, totalParams*sizeof(unsigned int), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(paramIndices, host_indices, totalParams * sizeof(unsigned int), 0, cudaMemcpyHostToDevice); } -__host__ void PdfBase::setData(std::vector>& data) { +__host__ void PdfBase::setData(std::vector> &data) { // Old method retained for backwards compatibility if(dev_event_array) { @@ -101,36 +104,40 @@ __host__ void PdfBase::setData(std::vector>& data) { setIndices(); int dimensions = observables.size(); - numEntries = data.size(); - numEvents = numEntries; + numEntries = data.size(); + numEvents = numEntries; - auto* host_array = new fptype[data.size()*dimensions]; + auto *host_array = new fptype[data.size() * dimensions]; for(unsigned int i = 0; i < data.size(); ++i) { - for(Variable* v : observables) { + for(Variable *v : observables) { if(data[i].find(v) == data[i].end()) throw GooFit::GeneralError("Variable {} not found", v->getName()); - host_array[i*dimensions + v->getIndex()] = data[i][v]; + host_array[i * dimensions + v->getIndex()] = data[i][v]; } } - gooMalloc(reinterpret_cast( &dev_event_array), dimensions*numEntries*sizeof(fptype)); - MEMCPY(dev_event_array, host_array, dimensions*numEntries*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc(reinterpret_cast(&dev_event_array), dimensions * numEntries * sizeof(fptype)); + MEMCPY(dev_event_array, host_array, dimensions * numEntries * sizeof(fptype), cudaMemcpyHostToDevice); MEMCPY_TO_SYMBOL(functorConstants, &numEvents, sizeof(fptype), 0, cudaMemcpyHostToDevice); delete[] host_array; } __host__ void PdfBase::recursiveSetIndices() { - for(auto & component : components) { + for(auto &component : components) { component->recursiveSetIndices(); } int numParams = host_indices[parameters]; - int counter = 0; + int counter = 0; - for(Variable* v : observables) { + for(Variable *v : observables) { host_indices[parameters + 2 + numParams + counter] = v->getIndex(); - GOOFIT_DEBUG("{} set index of {} to {} -> host {}", getName(), v->getName(), v->getIndex(), parameters + 2 + numParams + counter) + GOOFIT_DEBUG("{} set index of {} to {} -> host {}", + getName(), + v->getName(), + v->getIndex(), + parameters + 2 + numParams + counter) counter++; } @@ -140,214 +147,218 @@ __host__ void PdfBase::recursiveSetIndices() { __host__ void PdfBase::setIndices() { int counter = 0; - for(Variable* v : observables) { + for(Variable *v : observables) { v->setIndex(counter++); } recursiveSetIndices(); - MEMCPY_TO_SYMBOL(paramIndices, host_indices, totalParams*sizeof(unsigned int), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(paramIndices, host_indices, totalParams * sizeof(unsigned int), 0, cudaMemcpyHostToDevice); - //std::cout << "host_indices after " << getName() << " observable setIndices : "; - //for (int i = 0; i < totalParams; ++i) { - //std::cout << host_indices[i] << " "; + // std::cout << "host_indices after " << getName() << " observable setIndices : "; + // for (int i = 0; i < totalParams; ++i) { + // std::cout << host_indices[i] << " "; //} - //std::cout << std::endl; - + // std::cout << std::endl; } -__host__ void PdfBase::setData(DataSet* data) { +__host__ void PdfBase::setData(DataSet *data) { if(dev_event_array) { gooFree(dev_event_array); cudaDeviceSynchronize(); - dev_event_array = nullptr; + dev_event_array = nullptr; m_iEventsPerTask = 0; } setIndices(); - - UnbinnedDataSet* unbinned_data; - BinnedDataSet* binned_data; - - if((unbinned_data = dynamic_cast(data))) { + + UnbinnedDataSet *unbinned_data; + BinnedDataSet *binned_data; + + if((unbinned_data = dynamic_cast(data))) { numEntries = data->getNumEvents(); - numEvents = numEntries; - + numEvents = numEntries; + int dimensions = observables.size(); - #ifdef GOOFIT_MPI - //This fetches our rank and the total number of processes in the MPI call +#ifdef GOOFIT_MPI + // This fetches our rank and the total number of processes in the MPI call int myId, numProcs; MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Comm_rank(MPI_COMM_WORLD, &myId); - int perTask = numEvents/numProcs; + int perTask = numEvents / numProcs; - //This will track for a given rank where they will start and how far they will go - int* counts = new int[numProcs]; - int* displacements = new int[numProcs]; + // This will track for a given rank where they will start and how far they will go + int *counts = new int[numProcs]; + int *displacements = new int[numProcs]; - for(int i = 0; i < numProcs - 1; i++) + for(int i = 0; i < numProcs - 1; i++) counts[i] = perTask; - counts[numProcs - 1] = numEntries - perTask*(numProcs - 1); + counts[numProcs - 1] = numEntries - perTask * (numProcs - 1); displacements[0] = 0; - for(int i = 1; i < numProcs; i++) + for(int i = 1; i < numProcs; i++) displacements[i] = displacements[i - 1] + counts[i - 1]; - #endif +#endif - auto* host_array = new fptype[numEntries*dimensions]; + auto *host_array = new fptype[numEntries * dimensions]; - #ifdef GOOFIT_MPI - //This is an array to track if we need to re-index the observable +#ifdef GOOFIT_MPI + // This is an array to track if we need to re-index the observable int fixme[observables.size()]; - memset(fixme, 0, sizeof(int)*observables.size()); + memset(fixme, 0, sizeof(int) * observables.size()); for(int i = 0; i < observables.size(); i++) { - //We are casting the observable to a CountVariable - CountingVariable* c = dynamic_cast (observables[i]); + // We are casting the observable to a CountVariable + CountingVariable *c = dynamic_cast(observables[i]); - //if it is true re-index + // if it is true re-index if(c) fixme[i] = 1; } - #endif +#endif - //Transfer into our whole buffer + // Transfer into our whole buffer for(int i = 0; i < numEntries; ++i) { - for(Variable* v : observables) { - fptype currVal = unbinned_data->getValue(v, i); - host_array[i*dimensions + v->getIndex()] = currVal; + for(Variable *v : observables) { + fptype currVal = unbinned_data->getValue(v, i); + host_array[i * dimensions + v->getIndex()] = currVal; } } - #ifdef GOOFIT_MPI +#ifdef GOOFIT_MPI - //We will go through all of the events and re-index if appropriate + // We will go through all of the events and re-index if appropriate for(int i = 1; i < numProcs; i++) { for(int j = 0; j < counts[i]; j++) { for(int k = 0; k < dimensions; k++) { if(fixme[k] > 0) - host_array[(j + displacements[i])*dimensions + k] = float (j); + host_array[(j + displacements[i]) * dimensions + k] = float(j); } } } int mystart = displacements[myId]; - int myend = mystart + counts[myId]; + int myend = mystart + counts[myId]; int mycount = myend - mystart; - gooMalloc((void**) &dev_event_array, dimensions*mycount*sizeof(fptype)); - MEMCPY(dev_event_array, host_array + mystart*dimensions, dimensions*mycount*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc((void **)&dev_event_array, dimensions * mycount * sizeof(fptype)); + MEMCPY(dev_event_array, + host_array + mystart * dimensions, + dimensions * mycount * sizeof(fptype), + cudaMemcpyHostToDevice); MEMCPY_TO_SYMBOL(functorConstants, &numEvents, sizeof(fptype), 0, cudaMemcpyHostToDevice); delete[] host_array; setNumPerTask(this, mycount); - delete []counts; - delete []displacements; - #else - gooMalloc(reinterpret_cast( &dev_event_array), dimensions*numEntries*sizeof(fptype)); - MEMCPY(dev_event_array, host_array, dimensions*numEntries*sizeof(fptype), cudaMemcpyHostToDevice); + delete[] counts; + delete[] displacements; +#else + gooMalloc(reinterpret_cast(&dev_event_array), dimensions * numEntries * sizeof(fptype)); + MEMCPY(dev_event_array, host_array, dimensions * numEntries * sizeof(fptype), cudaMemcpyHostToDevice); MEMCPY_TO_SYMBOL(functorConstants, &numEvents, sizeof(fptype), 0, cudaMemcpyHostToDevice); delete[] host_array; - #endif - } else if ((binned_data = dynamic_cast(data))) { - - - numEvents = 0; - numEntries = binned_data->getNumBins(); +#endif + } else if((binned_data = dynamic_cast(data))) { + numEvents = 0; + numEntries = binned_data->getNumBins(); int dimensions = 2 + observables.size(); // Bin center (x,y, ...), bin value, and bin volume. if(!fitControl->binnedFit()) setFitControl(new BinnedNllFit()); - #ifdef GOOFIT_MPI - //This fetches our rank and the total number of processes in the MPI call +#ifdef GOOFIT_MPI + // This fetches our rank and the total number of processes in the MPI call int myId, numProcs; MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Comm_rank(MPI_COMM_WORLD, &myId); - int perTask = numEvents/numProcs; + int perTask = numEvents / numProcs; - //This will track for a given rank where they will start and how far they will go - int* counts = new int[numProcs]; - int* displacements = new int[numProcs]; + // This will track for a given rank where they will start and how far they will go + int *counts = new int[numProcs]; + int *displacements = new int[numProcs]; - for(int i = 0; i < numProcs - 1; i++) + for(int i = 0; i < numProcs - 1; i++) counts[i] = perTask; - counts[numProcs - 1] = numEntries - perTask*(numProcs - 1); + counts[numProcs - 1] = numEntries - perTask * (numProcs - 1); displacements[0] = 0; - for(int i = 1; i < numProcs; i++) + for(int i = 1; i < numProcs; i++) displacements[i] = displacements[i - 1] + counts[i - 1]; - #endif +#endif - auto* host_array = new fptype[numEntries*dimensions]; + auto *host_array = new fptype[numEntries * dimensions]; - #ifdef GOOFIT_MPI - //This is an array to track if we need to re-index the observable +#ifdef GOOFIT_MPI + // This is an array to track if we need to re-index the observable int fixme[observables.size()]; - memset(fixme, 0, sizeof(int)*observables.size()); + memset(fixme, 0, sizeof(int) * observables.size()); for(int i = 0; i < observables.size(); i++) { - //We are casting the observable to a CountVariable - CountingVariable* c = dynamic_cast (observables[i]); + // We are casting the observable to a CountVariable + CountingVariable *c = dynamic_cast(observables[i]); - //if it is true re-index + // if it is true re-index if(c) fixme[i] = 1; } - #endif +#endif for(unsigned int i = 0; i < numEntries; ++i) { - for(Variable* v : observables) { - host_array[i*dimensions + v->getIndex()] = binned_data->getBinCenter(v, i); + for(Variable *v : observables) { + host_array[i * dimensions + v->getIndex()] = binned_data->getBinCenter(v, i); } - host_array[i*dimensions + observables.size() + 0] = binned_data->getBinContent(i); - host_array[i*dimensions + observables.size() + 1] = fitControl->binErrors() ? binned_data->getBinError(i) : binned_data->getBinVolume(i); + host_array[i * dimensions + observables.size() + 0] = binned_data->getBinContent(i); + host_array[i * dimensions + observables.size() + 1] + = fitControl->binErrors() ? binned_data->getBinError(i) : binned_data->getBinVolume(i); numEvents += binned_data->getBinContent(i); } - #ifdef GOOFIT_MPI +#ifdef GOOFIT_MPI - //We will go through all of the events and re-index if appropriate + // We will go through all of the events and re-index if appropriate for(int i = 1; i < numProcs; i++) { for(int j = 0; j < counts[j]; j++) { for(int k = 0; k < dimensions; k++) { if(fixme[k] > 0) - host_array[(j + displacements[i])*dimensions + k] = float (j); + host_array[(j + displacements[i]) * dimensions + k] = float(j); } } } int mystart = displacements[myId]; - int myend = mystart + counts[myId]; + int myend = mystart + counts[myId]; int mycount = myend - mystart; - gooMalloc((void**) &dev_event_array, dimensions*mycount*sizeof(fptype)); - MEMCPY(dev_event_array, host_array + mystart*dimensions, dimensions*mycount*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc((void **)&dev_event_array, dimensions * mycount * sizeof(fptype)); + MEMCPY(dev_event_array, + host_array + mystart * dimensions, + dimensions * mycount * sizeof(fptype), + cudaMemcpyHostToDevice); MEMCPY_TO_SYMBOL(functorConstants, &numEvents, sizeof(fptype), 0, cudaMemcpyHostToDevice); delete[] host_array; setNumPerTask(this, mycount); - delete []counts; - delete []displacements; - #else - gooMalloc(reinterpret_cast( &dev_event_array), dimensions*numEntries*sizeof(fptype)); - MEMCPY(dev_event_array, host_array, dimensions*numEntries*sizeof(fptype), cudaMemcpyHostToDevice); + delete[] counts; + delete[] displacements; +#else + gooMalloc(reinterpret_cast(&dev_event_array), dimensions * numEntries * sizeof(fptype)); + MEMCPY(dev_event_array, host_array, dimensions * numEntries * sizeof(fptype), cudaMemcpyHostToDevice); MEMCPY_TO_SYMBOL(functorConstants, &numEvents, sizeof(fptype), 0, cudaMemcpyHostToDevice); delete[] host_array; - #endif +#endif } else throw GooFit::GeneralError("Dataset must be binned or unbinned!"); } @@ -356,23 +367,23 @@ __host__ void PdfBase::generateNormRange() { if(normRanges) gooFree(normRanges); - gooMalloc(reinterpret_cast( &normRanges), 3*observables.size()*sizeof(fptype)); + gooMalloc(reinterpret_cast(&normRanges), 3 * observables.size() * sizeof(fptype)); - auto* host_norms = new fptype[3*observables.size()]; - int counter = 0; // Don't use index in this case to allow for, eg, + auto *host_norms = new fptype[3 * observables.size()]; + int counter = 0; // Don't use index in this case to allow for, eg, // a single observable whose index is 1; or two observables with indices // 0 and 2. Make one array per functor, as opposed to variable, to make // it easy to pass MetricTaker a range without worrying about which parts // to use. - for(Variable* v : observables) { - host_norms[3*counter+0] = v->getLowerLimit(); - host_norms[3*counter+1] = v->getUpperLimit(); - host_norms[3*counter+2] = integrationBins > 0 ? integrationBins : v->getNumBins(); + for(Variable *v : observables) { + host_norms[3 * counter + 0] = v->getLowerLimit(); + host_norms[3 * counter + 1] = v->getUpperLimit(); + host_norms[3 * counter + 2] = integrationBins > 0 ? integrationBins : v->getNumBins(); counter++; } - MEMCPY(normRanges, host_norms, 3*observables.size()*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY(normRanges, host_norms, 3 * observables.size() * sizeof(fptype), cudaMemcpyHostToDevice); delete[] host_norms; } @@ -386,15 +397,15 @@ __host__ void PdfBase::printProfileInfo(bool topLevel) { #ifdef PROFILING if(topLevel) { - cudaError_t err = MEMCPY_FROM_SYMBOL(host_timeHist, timeHistogram, 10000*sizeof(fptype), 0); + cudaError_t err = MEMCPY_FROM_SYMBOL(host_timeHist, timeHistogram, 10000 * sizeof(fptype), 0); if(cudaSuccess != err) { std::cout << "Error on copying timeHistogram: " << cudaGetErrorString(err) << std::endl; return; } - std::cout << getName() << " : " << getFunctionIndex() << " " << host_timeHist[100*getFunctionIndex() + - getParameterIndex()] << std::endl; + std::cout << getName() << " : " << getFunctionIndex() << " " + << host_timeHist[100 * getFunctionIndex() + getParameterIndex()] << std::endl; for(unsigned int i = 0; i < components.size(); ++i) { components[i]->printProfileInfo(false); @@ -404,10 +415,8 @@ __host__ void PdfBase::printProfileInfo(bool topLevel) { #endif } - - -gooError gooMalloc(void** target, size_t bytes) { -#if THRUST_DEVICE_SYSTEM!=THRUST_DEVICE_SYSTEM_CUDA +gooError gooMalloc(void **target, size_t bytes) { +#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CUDA target[0] = malloc(bytes); if(target[0]) @@ -416,17 +425,16 @@ gooError gooMalloc(void** target, size_t bytes) { return gooErrorMemoryAllocation; #else - return (gooError) cudaMalloc(target, bytes); + return (gooError)cudaMalloc(target, bytes); #endif } -gooError gooFree(void* ptr) { -#if THRUST_DEVICE_SYSTEM!=THRUST_DEVICE_SYSTEM_CUDA +gooError gooFree(void *ptr) { +#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CUDA free(ptr); return gooSuccess; #else - return (gooError) cudaFree(ptr); + return (gooError)cudaFree(ptr); #endif } } // namespace GooFit - diff --git a/src/PDFs/PolynomialPdf.cu b/src/PDFs/PolynomialPdf.cu index b820e790c..71fa25159 100644 --- a/src/PDFs/PolynomialPdf.cu +++ b/src/PDFs/PolynomialPdf.cu @@ -3,14 +3,13 @@ namespace GooFit { - -__device__ fptype device_Polynomial(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Polynomial(fptype *evt, fptype *p, unsigned int *indices) { // Structure is nP lowestdegree c1 c2 c3 nO o1 - int numParams = RO_CACHE(indices[0])+1; + int numParams = RO_CACHE(indices[0]) + 1; int lowestDegree = RO_CACHE(indices[1]); - fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; + fptype x = evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]; fptype ret = 0; for(int i = 2; i < numParams; ++i) { @@ -20,8 +19,8 @@ __device__ fptype device_Polynomial(fptype* evt, fptype* p, unsigned int* indice return ret; } -__device__ fptype device_OffsetPolynomial(fptype* evt, fptype* p, unsigned int* indices) { - int numParams = RO_CACHE(indices[0]); +__device__ fptype device_OffsetPolynomial(fptype *evt, fptype *p, unsigned int *indices) { + int numParams = RO_CACHE(indices[0]); int lowestDegree = RO_CACHE(indices[1]); fptype x = evt[RO_CACHE(indices[2 + numParams])]; @@ -35,11 +34,11 @@ __device__ fptype device_OffsetPolynomial(fptype* evt, fptype* p, unsigned int* return ret; } -__device__ fptype device_MultiPolynomial(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_MultiPolynomial(fptype *evt, fptype *p, unsigned int *indices) { // Structure is nP, maxDegree, offset1, offset2, ..., coeff1, coeff2, ..., nO, o1, o2, ... int numObservables = RO_CACHE(indices[RO_CACHE(indices[0]) + 1]); - int maxDegree = RO_CACHE(indices[1]) + 1; + int maxDegree = RO_CACHE(indices[1]) + 1; // Only appears in construction (maxDegree + 1) or (x > maxDegree), so // may as well add the one and use >= instead. @@ -51,72 +50,72 @@ __device__ fptype device_MultiPolynomial(fptype* evt, fptype* p, unsigned int* i for(int i = 0; i < numObservables; ++i) numBoxes *= maxDegree; - int coeffNumber = 2 + - numObservables; // Index of first coefficient is 2 + nO, not 1 + nO, due to maxDegree. (nO comes from offsets.) + int coeffNumber = 2 + numObservables; // Index of first coefficient is 2 + nO, not 1 + nO, due to maxDegree. (nO + // comes from offsets.) fptype ret = RO_CACHE(p[RO_CACHE(indices[coeffNumber++])]); // Coefficient of constant term. for(int i = 1; i < numBoxes; - ++i) { // Notice skip of inmost 'box' in the pyramid, corresponding to all powers zero, already accounted for. - fptype currTerm = 1; - int currIndex = i; + ++i) { // Notice skip of inmost 'box' in the pyramid, corresponding to all powers zero, already accounted for. + fptype currTerm = 1; + int currIndex = i; int sumOfIndices = 0; - //if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) - //if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("[%i, %i] Start box %i %f %f:\n", BLOCKIDX, THREADIDX, i, ret, evt[8]); + // if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) + // if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("[%i, %i] Start box %i %f %f:\n", BLOCKIDX, THREADIDX, i, ret, evt[8]); for(int j = 0; j < numObservables; ++j) { - fptype x = RO_CACHE(evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + j])]); // x, y, z... - fptype offset = RO_CACHE(p[RO_CACHE(indices[2 + j])]); // x0, y0, z0... + fptype x = RO_CACHE(evt[RO_CACHE(indices[2 + RO_CACHE(indices[0]) + j])]); // x, y, z... + fptype offset = RO_CACHE(p[RO_CACHE(indices[2 + j])]); // x0, y0, z0... x -= offset; int currPower = currIndex % maxDegree; currIndex /= maxDegree; currTerm *= pow(x, currPower); sumOfIndices += currPower; - //if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) - //if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf(" [%f -> %f^%i = %f] (%i %i) \n", evt[indices[2 + indices[0] + j]], x, currPower, pow(x, currPower), sumOfIndices, indices[2 + indices[0] + j]); + // if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) + // if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf(" [%f -> %f^%i = %f] (%i %i) \n", evt[indices[2 + indices[0] + j]], x, currPower, pow(x, + // currPower), sumOfIndices, indices[2 + indices[0] + j]); } - //if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) - //if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) - //printf(") End box %i\n", i); + // if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) + // if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) + // printf(") End box %i\n", i); // All threads should hit this at the same time and with the same result. No branching. if(sumOfIndices >= maxDegree) continue; fptype coefficient = RO_CACHE(p[RO_CACHE(indices[coeffNumber++])]); // Coefficient from MINUIT - //if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) - //if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("Box %i contributes %f * %f = %f -> %f\n", i, currTerm, p[indices[coeffNumber - 1]], coefficient*currTerm, (ret + coefficient*currTerm)); + // if ((gpuDebug & 1) && (THREADIDX == 50) && (BLOCKIDX == 3)) + // if ((BLOCKIDX == internalDebug1) && (THREADIDX == internalDebug2)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("Box %i contributes %f * %f = %f -> %f\n", i, currTerm, p[indices[coeffNumber - 1]], + // coefficient*currTerm, (ret + coefficient*currTerm)); currTerm *= coefficient; ret += currTerm; } - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("Final polynomial: %f\n", ret); + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("Final polynomial: %f\n", ret); - //if (0 > ret) ret = 0; + // if (0 > ret) ret = 0; return ret; } - -__device__ device_function_ptr ptr_to_Polynomial = device_Polynomial; +__device__ device_function_ptr ptr_to_Polynomial = device_Polynomial; __device__ device_function_ptr ptr_to_OffsetPolynomial = device_OffsetPolynomial; -__device__ device_function_ptr ptr_to_MultiPolynomial = device_MultiPolynomial; +__device__ device_function_ptr ptr_to_MultiPolynomial = device_MultiPolynomial; // Constructor for single-variate polynomial, with optional zero point. -__host__ PolynomialPdf::PolynomialPdf(std::string n, Variable* _x, std::vector weights, Variable* x0, - unsigned int lowestDegree) +__host__ PolynomialPdf::PolynomialPdf( + std::string n, Variable *_x, std::vector weights, Variable *x0, unsigned int lowestDegree) : GooPdf(_x, n) , center(x0) { - std::vector pindices; pindices.push_back(lowestDegree); - for(auto & weight : weights) { + for(auto &weight : weights) { pindices.push_back(registerParameter(weight)); } @@ -131,8 +130,11 @@ __host__ PolynomialPdf::PolynomialPdf(std::string n, Variable* _x, std::vector obses, std::vector coeffs, - std::vector offsets, unsigned int maxDegree) +__host__ PolynomialPdf::PolynomialPdf(std::string n, + std::vector obses, + std::vector coeffs, + std::vector offsets, + unsigned int maxDegree) : GooPdf(nullptr, n) { unsigned int numParameters = 1; @@ -151,31 +153,30 @@ __host__ PolynomialPdf::PolynomialPdf(std::string n, std::vector obse while(numParameters > coeffs.size()) { char varName[100]; - sprintf(varName, "%s_extra_coeff_%i", getName().c_str(), static_cast( coeffs.size())); + sprintf(varName, "%s_extra_coeff_%i", getName().c_str(), static_cast(coeffs.size())); - Variable* newTerm = new Variable(varName, 0); + Variable *newTerm = new Variable(varName, 0); coeffs.push_back(newTerm); - std::cout << "Warning: " << getName() << " created dummy variable " - << varName - << " (fixed at zero) to account for all terms.\n"; + std::cout << "Warning: " << getName() << " created dummy variable " << varName + << " (fixed at zero) to account for all terms.\n"; } while(offsets.size() < obses.size()) { char varName[100]; - sprintf(varName, "%s_extra_offset_%i", getName().c_str(), static_cast( offsets.size())); - Variable* newOffset = new Variable(varName, 0); + sprintf(varName, "%s_extra_offset_%i", getName().c_str(), static_cast(offsets.size())); + Variable *newOffset = new Variable(varName, 0); offsets.push_back(newOffset); } std::vector pindices; pindices.push_back(maxDegree); - for(auto & offset : offsets) { + for(auto &offset : offsets) { pindices.push_back(registerParameter(offset)); } - for(auto & coeff : coeffs) { + for(auto &coeff : coeffs) { pindices.push_back(registerParameter(coeff)); } @@ -185,8 +186,8 @@ __host__ PolynomialPdf::PolynomialPdf(std::string n, std::vector obse __host__ fptype PolynomialPdf::integrate(fptype lo, fptype hi) const { // This is *still* wrong. (13 Feb 2013.) - unsigned int* indices = host_indices+parameters; - fptype lowestDegree = indices[1]; + unsigned int *indices = host_indices + parameters; + fptype lowestDegree = indices[1]; if(center) { hi -= host_params[indices[indices[0]]]; @@ -197,10 +198,10 @@ __host__ fptype PolynomialPdf::integrate(fptype lo, fptype hi) const { for(int i = 2; i < indices[0] + (center ? 0 : 1); ++i) { fptype powerPlusOne = lowestDegree + i - 2; - fptype curr = pow(hi, powerPlusOne); - curr -= pow(lo, powerPlusOne); - curr /= powerPlusOne; - ret += host_params[indices[i]] * curr; + fptype curr = pow(hi, powerPlusOne); + curr -= pow(lo, powerPlusOne); + curr /= powerPlusOne; + ret += host_params[indices[i]] * curr; } return ret; @@ -209,12 +210,12 @@ __host__ fptype PolynomialPdf::integrate(fptype lo, fptype hi) const { __host__ fptype PolynomialPdf::getCoefficient(int coef) const { // NB! This function only works for single polynomials. if(1 != observables.size()) { - std::cout << - "Warning: getCoefficient method of PolynomialPdf not implemented for multi-dimensional polynomials. Returning zero, which is very likely wrong.\n"; + std::cout << "Warning: getCoefficient method of PolynomialPdf not implemented for multi-dimensional " + "polynomials. Returning zero, which is very likely wrong.\n"; return 0; } - unsigned int* indices = host_indices + parameters; + unsigned int *indices = host_indices + parameters; // True function is, say, ax^2 + bx + c. // We express this as (a'x^2 + b'x + c')*N. @@ -230,10 +231,9 @@ __host__ fptype PolynomialPdf::getCoefficient(int coef) const { return 0; // Greater than max power. fptype norm = normalize(); - norm = (1.0 / norm); + norm = (1.0 / norm); fptype param = host_params[indices[2 + coef - indices[1]]]; - return norm*param; + return norm * param; } } // namespace GooFit - diff --git a/src/PDFs/ProdPdf.cu b/src/PDFs/ProdPdf.cu index e34bc3a61..5f60d82f1 100644 --- a/src/PDFs/ProdPdf.cu +++ b/src/PDFs/ProdPdf.cu @@ -3,34 +3,37 @@ namespace GooFit { - -__device__ fptype device_ProdPdfs(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_ProdPdfs(fptype *evt, fptype *p, unsigned int *indices) { // Index structure is nP | F1 P1 | F2 P2 | ... // where nP is number of parameters, Fs are function indices, and Ps are parameter indices int numParams = RO_CACHE(indices[0]); - fptype ret = 1; + fptype ret = 1; for(int i = 1; i < numParams; i += 2) { int fcnIdx = RO_CACHE(indices[i + 0]); int parIdx = RO_CACHE(indices[i + 1]); - //fptype curr = (*(reinterpret_cast(device_function_table[fcnIdx])))(evt, p, paramIndices + parIdx); + // fptype curr = (*(reinterpret_cast(device_function_table[fcnIdx])))(evt, p, paramIndices + // + parIdx); fptype curr = callFunction(evt, fcnIdx, parIdx); curr *= normalisationFactors[parIdx]; - //if ((isnan(ret)) || (isnan(curr)) || (isnan(normalisationFactors[parIdx])) || (isinf(ret)) || (isinf(curr))) - //printf("device_Prod 2: (%f %f %f %f %f) %f %f %f %i %i %i\n", evt[0], evt[1], evt[2], evt[3], evt[4], curr, ret, normalisationFactors[parIdx], i, parIdx, numParams); + // if ((isnan(ret)) || (isnan(curr)) || (isnan(normalisationFactors[parIdx])) || (isinf(ret)) || (isinf(curr))) + // printf("device_Prod 2: (%f %f %f %f %f) %f %f %f %i %i %i\n", evt[0], evt[1], evt[2], evt[3], evt[4], curr, + // ret, normalisationFactors[parIdx], i, parIdx, numParams); ret *= curr; - //if ((0 == THREADIDX) && (0 == BLOCKIDX) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //if (0.0001 < ret) - //if ((gpuDebug & 1) && (isnan(curr)) && (paramIndices + debugParamIndex == indices)) - //if ((isnan(ret)) || (isnan(curr)) || (isnan(normalisationFactors[parIdx]))) - //printf("device_Prod: (%f %f %f %f %f) %f %f %f %i %i %i\n", evt[0], evt[1], evt[2], evt[3], evt[4], curr, ret, normalisationFactors[parIdx], i, parIdx, numParams); - //printf("(%i, %i) device_Prod: (%f %f %f %f) %f %f %f %i\n", BLOCKIDX, THREADIDX, evt[0], evt[8], evt[6], evt[7], curr, ret, normalisationFactors[parIdx], i); - //printf("(%i, %i) device_Prod: (%f %f) %f %f %f %i\n", BLOCKIDX, THREADIDX, evt[0], evt[1], curr, ret, normalisationFactors[parIdx], i); - + // if ((0 == THREADIDX) && (0 == BLOCKIDX) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // if (0.0001 < ret) + // if ((gpuDebug & 1) && (isnan(curr)) && (paramIndices + debugParamIndex == indices)) + // if ((isnan(ret)) || (isnan(curr)) || (isnan(normalisationFactors[parIdx]))) + // printf("device_Prod: (%f %f %f %f %f) %f %f %f %i %i %i\n", evt[0], evt[1], evt[2], evt[3], evt[4], curr, + // ret, normalisationFactors[parIdx], i, parIdx, numParams); + // printf("(%i, %i) device_Prod: (%f %f %f %f) %f %f %f %i\n", BLOCKIDX, THREADIDX, evt[0], evt[8], evt[6], + // evt[7], curr, ret, normalisationFactors[parIdx], i); + // printf("(%i, %i) device_Prod: (%f %f) %f %f %f %i\n", BLOCKIDX, THREADIDX, evt[0], evt[1], curr, ret, + // normalisationFactors[parIdx], i); } return ret; @@ -38,30 +41,30 @@ __device__ fptype device_ProdPdfs(fptype* evt, fptype* p, unsigned int* indices) __device__ device_function_ptr ptr_to_ProdPdfs = device_ProdPdfs; -ProdPdf::ProdPdf(std::string n, std::vector comps) +ProdPdf::ProdPdf(std::string n, std::vector comps) : GooPdf(nullptr, n) , varOverlaps(false) { std::vector pindices; - for(PdfBase* p : comps) { + for(PdfBase *p : comps) { components.push_back(p); } observables = getObservables(); // Gathers from components - std::vector observableCheck; // Use to check for overlap in observables + std::vector observableCheck; // Use to check for overlap in observables // Indices stores (function index)(function parameter index)(variable index) for each component. - for(PdfBase* p : comps) { + for(PdfBase *p : comps) { pindices.push_back(p->getFunctionIndex()); pindices.push_back(p->getParameterIndex()); if(varOverlaps) continue; // Only need to establish this once. - std::vector currObses = p->getObservables(); + std::vector currObses = p->getObservables(); - for(Variable* o : currObses) { + for(Variable *o : currObses) { if(find(observableCheck.begin(), observableCheck.end(), o) == observableCheck.end()) continue; @@ -72,8 +75,8 @@ ProdPdf::ProdPdf(std::string n, std::vector comps) observableCheck = p->getObservables(); } - if(varOverlaps) { // Check for components forcing separate normalisation - for(PdfBase* p : comps) { + if(varOverlaps) { // Check for components forcing separate normalisation + for(PdfBase *p : comps) { if(p->getSpecialMask() & PdfBase::ForceSeparateNorm) varOverlaps = false; } @@ -84,30 +87,29 @@ ProdPdf::ProdPdf(std::string n, std::vector comps) } __host__ fptype ProdPdf::normalize() const { - if(varOverlaps) { // Two or more components share an observable and cannot be separately // normalized, since \int A*B dx does not equal int A dx * int B dx. recursiveSetNormalisation(fptype(1.0)); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); // Normalize numerically. - //std::cout << "Numerical normalisation of " << getName() << " due to varOverlaps.\n"; + // std::cout << "Numerical normalisation of " << getName() << " due to varOverlaps.\n"; fptype ret = GooPdf::normalize(); - //if (cpuDebug & 1) - //std::cout << "ProdPdf " << getName() << " has normalisation " << ret << " " << host_callnumber << std::endl; + // if (cpuDebug & 1) + // std::cout << "ProdPdf " << getName() << " has normalisation " << ret << " " << host_callnumber << std::endl; return ret; } // Normalize components individually - for(PdfBase* c : components) { + for(PdfBase *c : components) { c->normalize(); } host_normalisation[parameters] = 1; - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); return 1.0; } } // namespace GooFit - diff --git a/src/PDFs/ResonancePdf.cu b/src/PDFs/ResonancePdf.cu index 9ce2a4de5..86e02f9fb 100644 --- a/src/PDFs/ResonancePdf.cu +++ b/src/PDFs/ResonancePdf.cu @@ -3,40 +3,46 @@ namespace GooFit { - __device__ fptype twoBodyCMmom(double rMassSq, fptype d1m, fptype d2m) { // For A -> B + C, calculate momentum of B and C in rest frame of A. // PDG 38.16. - fptype kin1 = 1 - POW2(d1m+d2m) / rMassSq; + fptype kin1 = 1 - POW2(d1m + d2m) / rMassSq; if(kin1 >= 0) kin1 = sqrt(kin1); else kin1 = 1; - fptype kin2 = 1 - POW2(d1m-d2m) / rMassSq; + fptype kin2 = 1 - POW2(d1m - d2m) / rMassSq; if(kin2 >= 0) kin2 = sqrt(kin2); else kin2 = 1; - return 0.5*sqrt(rMassSq)*kin1*kin2; + return 0.5 * sqrt(rMassSq) * kin1 * kin2; } -__device__ fptype dampingFactorSquare(const fptype& cmmom, const int& spin, const fptype& mRadius) { - fptype square = mRadius*mRadius*cmmom*cmmom; - fptype dfsq = 1 + square; // This accounts for spin 1 - //if (2 == spin) dfsq += 8 + 2*square + square*square; // Coefficients are 9, 3, 1. - fptype dfsqres = dfsq + 8 + 2*square + square*square; +__device__ fptype dampingFactorSquare(const fptype &cmmom, const int &spin, const fptype &mRadius) { + fptype square = mRadius * mRadius * cmmom * cmmom; + fptype dfsq = 1 + square; // This accounts for spin 1 + // if (2 == spin) dfsq += 8 + 2*square + square*square; // Coefficients are 9, 3, 1. + fptype dfsqres = dfsq + 8 + 2 * square + square * square; // Spin 3 and up not accounted for. - //return dfsq; + // return dfsq; return (spin == 2) ? dfsqres : dfsq; } -__device__ fptype spinFactor(unsigned int spin, fptype motherMass, fptype daug1Mass, fptype daug2Mass, - fptype daug3Mass, fptype m12, fptype m13, fptype m23, unsigned int cyclic_index) { +__device__ fptype spinFactor(unsigned int spin, + fptype motherMass, + fptype daug1Mass, + fptype daug2Mass, + fptype daug3Mass, + fptype m12, + fptype m13, + fptype m23, + unsigned int cyclic_index) { if(0 == spin) return 1; // Should not cause branching since every thread evaluates the same resonance at the same time. @@ -63,21 +69,22 @@ __device__ fptype spinFactor(unsigned int spin, fptype motherMass, fptype daug1M // Copied from EvtDalitzReso, with assumption that pairAng convention matches pipipi0 from EvtD0mixDalitz. // Again, all threads should get the same branch. - fptype _mA = (PAIR_12 == cyclic_index ? daug1Mass : (PAIR_13 == cyclic_index ? daug3Mass : daug2Mass)); - fptype _mB = (PAIR_12 == cyclic_index ? daug2Mass : (PAIR_13 == cyclic_index ? daug1Mass : daug3Mass)); - fptype _mC = (PAIR_12 == cyclic_index ? daug3Mass : (PAIR_13 == cyclic_index ? daug2Mass : daug1Mass)); + fptype _mA = (PAIR_12 == cyclic_index ? daug1Mass : (PAIR_13 == cyclic_index ? daug3Mass : daug2Mass)); + fptype _mB = (PAIR_12 == cyclic_index ? daug2Mass : (PAIR_13 == cyclic_index ? daug1Mass : daug3Mass)); + fptype _mC = (PAIR_12 == cyclic_index ? daug3Mass : (PAIR_13 == cyclic_index ? daug2Mass : daug1Mass)); fptype _mAC = (PAIR_12 == cyclic_index ? m13 : (PAIR_13 == cyclic_index ? m23 : m12)); fptype _mBC = (PAIR_12 == cyclic_index ? m23 : (PAIR_13 == cyclic_index ? m12 : m13)); fptype _mAB = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); - fptype massFactor = 1.0/_mAB; - fptype sFactor = -1; - sFactor *= ((_mBC - _mAC) + (massFactor*(motherMass*motherMass - _mC*_mC)*(_mA*_mA-_mB*_mB))); + fptype massFactor = 1.0 / _mAB; + fptype sFactor = -1; + sFactor *= ((_mBC - _mAC) + (massFactor * (motherMass * motherMass - _mC * _mC) * (_mA * _mA - _mB * _mB))); if(2 == spin) { sFactor *= sFactor; - fptype extraterm = ((_mAB-(2*motherMass*motherMass)-(2*_mC*_mC))+massFactor*POW2(motherMass*motherMass-_mC*_mC)); - extraterm *= ((_mAB-(2*_mA*_mA)-(2*_mB*_mB))+massFactor*POW2(_mA*_mA-_mB*_mB)); + fptype extraterm = ((_mAB - (2 * motherMass * motherMass) - (2 * _mC * _mC)) + + massFactor * POW2(motherMass * motherMass - _mC * _mC)); + extraterm *= ((_mAB - (2 * _mA * _mA) - (2 * _mB * _mB)) + massFactor * POW2(_mA * _mA - _mB * _mB)); extraterm /= 3; sFactor -= extraterm; } @@ -85,40 +92,40 @@ __device__ fptype spinFactor(unsigned int spin, fptype motherMass, fptype daug1M return sFactor; } -__device__ thrust::complex plainBW(fptype m12, fptype m13, fptype m23, unsigned int* indices) { - fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+0]); - fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+1]); - fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+2]); - fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+3]); - fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1])+4]); +__device__ thrust::complex plainBW(fptype m12, fptype m13, fptype m23, unsigned int *indices) { + fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 0]); + fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 1]); + fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 2]); + fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 3]); + fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 4]); - fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); - fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); - unsigned int spin = RO_CACHE(indices[4]); - unsigned int cyclic_index = RO_CACHE(indices[5]); + fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); + fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); + unsigned int spin = RO_CACHE(indices[4]); + unsigned int cyclic_index = RO_CACHE(indices[5]); - fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); + fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); fptype frFactor = 1; resmass *= resmass; - // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> dm2). - fptype measureDaughterMoms = twoBodyCMmom(rMassSq, - (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); - fptype nominalDaughterMoms = twoBodyCMmom(resmass, - (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); + // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> + // dm2). + fptype measureDaughterMoms = twoBodyCMmom( + rMassSq, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); + fptype nominalDaughterMoms = twoBodyCMmom( + resmass, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); if(0 != spin) { - frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); + frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); frFactor /= dampingFactorSquare(measureDaughterMoms, spin, meson_radius); } // RBW evaluation fptype A = (resmass - rMassSq); - fptype B = resmass*reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0*spin + 1) * frFactor / sqrt(rMassSq); - fptype C = 1.0 / (A*A + B*B); - thrust::complex ret(A*C, B*C); // Dropping F_D=1 + fptype B = resmass * reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0 * spin + 1) * frFactor + / sqrt(rMassSq); + fptype C = 1.0 / (A * A + B * B); + thrust::complex ret(A * C, B * C); // Dropping F_D=1 ret *= sqrt(frFactor); fptype spinF = spinFactor(spin, motherMass, daug1Mass, daug2Mass, daug3Mass, m12, m13, m23, cyclic_index); @@ -127,18 +134,18 @@ __device__ thrust::complex plainBW(fptype m12, fptype m13, fptype m23, u return ret; } -__device__ thrust::complex gaussian(fptype m12, fptype m13, fptype m23, unsigned int* indices) { +__device__ thrust::complex gaussian(fptype m12, fptype m13, fptype m23, unsigned int *indices) { // indices[1] is unused constant index, for consistency with other function types. - fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); - fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); - unsigned int cyclic_index = indices[4]; + fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); + fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); + unsigned int cyclic_index = indices[4]; // Notice sqrt - this function uses mass, not mass-squared like the other resonance types. fptype massToUse = sqrt(PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); massToUse -= resmass; massToUse /= reswidth; massToUse *= massToUse; - fptype ret = exp(-0.5*massToUse); + fptype ret = exp(-0.5 * massToUse); // Ignore factor 1/sqrt(2pi). ret /= reswidth; @@ -149,11 +156,11 @@ __device__ thrust::complex gaussian(fptype m12, fptype m13, fptype m23, __device__ fptype hFun(double s, double daug2Mass, double daug3Mass) { // Last helper function const fptype _pi = 3.14159265359; - double sm = daug2Mass + daug3Mass; - double SQRTs = sqrt(s); - double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); + double sm = daug2Mass + daug3Mass; + double SQRTs = sqrt(s); + double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); - double val = ((2/_pi) * (k_s/SQRTs) * log((SQRTs + 2*k_s)/(sm))); + double val = ((2 / _pi) * (k_s / SQRTs) * log((SQRTs + 2 * k_s) / (sm))); return val; } @@ -161,109 +168,110 @@ __device__ fptype hFun(double s, double daug2Mass, double daug3Mass) { __device__ fptype dh_dsFun(double s, double daug2Mass, double daug3Mass) { // Yet another helper function const fptype _pi = 3.14159265359; - double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); + double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); - double val = hFun(s, daug2Mass, daug3Mass) * (1.0/(8.0*POW2(k_s)) - 1.0/(2.0 * s)) + 1.0/(2.0* _pi*s); + double val = hFun(s, daug2Mass, daug3Mass) * (1.0 / (8.0 * POW2(k_s)) - 1.0 / (2.0 * s)) + 1.0 / (2.0 * _pi * s); return val; } - __device__ fptype dFun(double s, double daug2Mass, double daug3Mass) { // Helper function used in Gronau-Sakurai const fptype _pi = 3.14159265359; - double sm = daug2Mass + daug3Mass; - double sm24 = sm*sm/4.0; - double m = sqrt(s); - double k_m2 = twoBodyCMmom(s, daug2Mass, daug3Mass); + double sm = daug2Mass + daug3Mass; + double sm24 = sm * sm / 4.0; + double m = sqrt(s); + double k_m2 = twoBodyCMmom(s, daug2Mass, daug3Mass); - double val = 3.0/_pi * sm24/POW2(k_m2) * log((m + 2*k_m2)/sm) + m/(2*_pi*k_m2) - sm24*m/(_pi * POW3(k_m2)); + double val = 3.0 / _pi * sm24 / POW2(k_m2) * log((m + 2 * k_m2) / sm) + m / (2 * _pi * k_m2) + - sm24 * m / (_pi * POW3(k_m2)); return val; } __device__ fptype fsFun(double s, double m2, double gam, double daug2Mass, double daug3Mass) { // Another G-S helper function - double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); + double k_s = twoBodyCMmom(s, daug2Mass, daug3Mass); double k_Am2 = twoBodyCMmom(m2, daug2Mass, daug3Mass); - double f = gam * m2 / POW3(k_Am2); - f *= (POW2(k_s) * (hFun(s, daug2Mass, daug3Mass) - hFun(m2, daug2Mass, daug3Mass)) - + (m2 - s) * POW2(k_Am2) * dh_dsFun(m2, daug2Mass, daug3Mass)); + double f = gam * m2 / POW3(k_Am2); + f *= (POW2(k_s) * (hFun(s, daug2Mass, daug3Mass) - hFun(m2, daug2Mass, daug3Mass)) + + (m2 - s) * POW2(k_Am2) * dh_dsFun(m2, daug2Mass, daug3Mass)); return f; } -__device__ thrust::complex gouSak(fptype m12, fptype m13, fptype m23, unsigned int* indices) { - fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+0]); - fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+1]); - fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+2]); - fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+3]); - fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1])+4]); +__device__ thrust::complex gouSak(fptype m12, fptype m13, fptype m23, unsigned int *indices) { + fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 0]); + fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 1]); + fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 2]); + fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 3]); + fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 4]); - fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); - fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); - unsigned int spin = RO_CACHE(indices[4]); - unsigned int cyclic_index = RO_CACHE(indices[5]); + fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); + fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); + unsigned int spin = RO_CACHE(indices[4]); + unsigned int cyclic_index = RO_CACHE(indices[5]); - fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); + fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); fptype frFactor = 1; resmass *= resmass; - // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> dm2). - fptype measureDaughterMoms = twoBodyCMmom(rMassSq, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); - fptype nominalDaughterMoms = twoBodyCMmom(resmass, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); + // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> + // dm2). + fptype measureDaughterMoms = twoBodyCMmom( + rMassSq, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); + fptype nominalDaughterMoms = twoBodyCMmom( + resmass, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_12 == cyclic_index ? daug2Mass : daug3Mass)); if(0 != spin) { - frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); + frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); frFactor /= dampingFactorSquare(measureDaughterMoms, spin, meson_radius); } // Implement Gou-Sak: - fptype D = (1.0 + dFun(resmass, daug2Mass, daug3Mass) * reswidth/sqrt(resmass)); + fptype D = (1.0 + dFun(resmass, daug2Mass, daug3Mass) * reswidth / sqrt(resmass)); fptype E = resmass - rMassSq + fsFun(rMassSq, resmass, reswidth, daug2Mass, daug3Mass); - fptype F = sqrt(resmass) * reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0*spin + 1) * frFactor; + fptype F = sqrt(resmass) * reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0 * spin + 1) * frFactor; - D /= (E*E + F*F); - thrust::complex retur(D*E, D*F); // Dropping F_D=1 + D /= (E * E + F * F); + thrust::complex retur(D * E, D * F); // Dropping F_D=1 retur *= sqrt(frFactor); retur *= spinFactor(spin, motherMass, daug1Mass, daug2Mass, daug3Mass, m12, m13, m23, cyclic_index); return retur; } +__device__ thrust::complex lass(fptype m12, fptype m13, fptype m23, unsigned int *indices) { + fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 0]); + fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 1]); + fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 2]); + fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 3]); + fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 4]); -__device__ thrust::complex lass(fptype m12, fptype m13, fptype m23, unsigned int* indices) { - fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+0]); - fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+1]); - fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+2]); - fptype daug3Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1])+3]); - fptype meson_radius = RO_CACHE(functorConstants[RO_CACHE(indices[1])+4]); - - fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); - fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); - unsigned int spin = RO_CACHE(indices[4]); - unsigned int cyclic_index = RO_CACHE(indices[5]); + fptype resmass = RO_CACHE(cudaArray[RO_CACHE(indices[2])]); + fptype reswidth = RO_CACHE(cudaArray[RO_CACHE(indices[3])]); + unsigned int spin = RO_CACHE(indices[4]); + unsigned int cyclic_index = RO_CACHE(indices[5]); - fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); + fptype rMassSq = (PAIR_12 == cyclic_index ? m12 : (PAIR_13 == cyclic_index ? m13 : m23)); fptype frFactor = 1; resmass *= resmass; - // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> dm2). + // Calculate momentum of the two daughters in the resonance rest frame; note symmetry under interchange (dm1 <-> + // dm2). - fptype measureDaughterMoms = twoBodyCMmom(rMassSq, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_23 == cyclic_index ? daug3Mass : daug2Mass)); - fptype nominalDaughterMoms = twoBodyCMmom(resmass, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), - (PAIR_23 == cyclic_index ? daug3Mass : daug2Mass)); + fptype measureDaughterMoms = twoBodyCMmom( + rMassSq, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_23 == cyclic_index ? daug3Mass : daug2Mass)); + fptype nominalDaughterMoms = twoBodyCMmom( + resmass, (PAIR_23 == cyclic_index ? daug2Mass : daug1Mass), (PAIR_23 == cyclic_index ? daug3Mass : daug2Mass)); if(0 != spin) { - frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); + frFactor = dampingFactorSquare(nominalDaughterMoms, spin, meson_radius); frFactor /= dampingFactorSquare(measureDaughterMoms, spin, meson_radius); } - //Implement LASS: + // Implement LASS: /* fptype s = kinematics(m12, m13, _trackinfo[i]); fptype q = twoBodyCMmom(s, _trackinfo[i]); @@ -274,7 +282,7 @@ __device__ thrust::complex lass(fptype m12, fptype m13, fptype m23, unsi */ fptype q = measureDaughterMoms; - fptype g = reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0*spin + 1) * frFactor / sqrt(rMassSq); + fptype g = reswidth * pow(measureDaughterMoms / nominalDaughterMoms, 2.0 * spin + 1) * frFactor / sqrt(rMassSq); fptype _a = 0.22357; fptype _r = -15.042; @@ -284,20 +292,22 @@ __device__ thrust::complex lass(fptype m12, fptype m13, fptype m23, unsi fptype _phiB = -0.0981907; // background phase motion - fptype cot_deltaB = (1.0 / (_a*q)) + 0.5*_r*q; - fptype qcot_deltaB = (1.0 / _a) + 0.5*_r*q*q; + fptype cot_deltaB = (1.0 / (_a * q)) + 0.5 * _r * q; + fptype qcot_deltaB = (1.0 / _a) + 0.5 * _r * q * q; // calculate resonant part - thrust::complex expi2deltaB = thrust::complex(qcot_deltaB, q)/thrust::complex(qcot_deltaB, -q); - thrust::complex resT = thrust::complex(cos(_phiR+2*_phiB), sin(_phiR+2*_phiB))*_R; + thrust::complex expi2deltaB + = thrust::complex(qcot_deltaB, q) / thrust::complex(qcot_deltaB, -q); + thrust::complex resT = thrust::complex(cos(_phiR + 2 * _phiB), sin(_phiR + 2 * _phiB)) * _R; - thrust::complex prop = thrust::complex(1, 0)/thrust::complex(resmass-rMassSq, sqrt(resmass)*g); + thrust::complex prop + = thrust::complex(1, 0) / thrust::complex(resmass - rMassSq, sqrt(resmass) * g); // resT *= prop*m0*_g0*m0/twoBodyCMmom(m0*m0, _trackinfo[i])*expi2deltaB; - resT *= prop*(resmass*reswidth/nominalDaughterMoms)*expi2deltaB; + resT *= prop * (resmass * reswidth / nominalDaughterMoms) * expi2deltaB; // calculate bkg part - resT += thrust::complex(cos(_phiB), - sin(_phiB))*_B*(cos(_phiB)+cot_deltaB*sin(_phiB))*sqrt(rMassSq)/thrust::complex(qcot_deltaB, -q); + resT += thrust::complex(cos(_phiB), sin(_phiB)) * _B * (cos(_phiB) + cot_deltaB * sin(_phiB)) + * sqrt(rMassSq) / thrust::complex(qcot_deltaB, -q); resT *= sqrt(frFactor); resT *= spinFactor(spin, motherMass, daug1Mass, daug2Mass, daug3Mass, m12, m13, m23, cyclic_index); @@ -305,14 +315,16 @@ __device__ thrust::complex lass(fptype m12, fptype m13, fptype m23, unsi return resT; } - -__device__ thrust::complex nonres(fptype m12, fptype m13, fptype m23, unsigned int* indices) { +__device__ thrust::complex nonres(fptype m12, fptype m13, fptype m23, unsigned int *indices) { return thrust::complex(1, 0); } - -__device__ void getAmplitudeCoefficients(thrust::complex a1, thrust::complex a2, fptype& a1sq, fptype& a2sq, - fptype& a1a2real, fptype& a1a2imag) { +__device__ void getAmplitudeCoefficients(thrust::complex a1, + thrust::complex a2, + fptype &a1sq, + fptype &a2sq, + fptype &a1a2real, + fptype &a1a2imag) { // Returns A_1^2, A_2^2, real and imaginary parts of A_1A_2^* a1sq = thrust::norm(a1); a2sq = thrust::norm(a2); @@ -321,19 +333,14 @@ __device__ void getAmplitudeCoefficients(thrust::complex a1, thrust::com a1a2imag = a1.imag(); } -__device__ resonance_function_ptr ptr_to_RBW = plainBW; -__device__ resonance_function_ptr ptr_to_GOUSAK = gouSak; +__device__ resonance_function_ptr ptr_to_RBW = plainBW; +__device__ resonance_function_ptr ptr_to_GOUSAK = gouSak; __device__ resonance_function_ptr ptr_to_GAUSSIAN = gaussian; -__device__ resonance_function_ptr ptr_to_NONRES = nonres; -__device__ resonance_function_ptr ptr_to_LASS = lass; - -ResonancePdf::ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mass, - Variable* width, - unsigned int sp, - unsigned int cyc) +__device__ resonance_function_ptr ptr_to_NONRES = nonres; +__device__ resonance_function_ptr ptr_to_LASS = lass; + +ResonancePdf::ResonancePdf( + std::string name, Variable *ar, Variable *ai, Variable *mass, Variable *width, unsigned int sp, unsigned int cyc) : GooPdf(nullptr, name) , amp_real(ar) , amp_imag(ai) { @@ -353,13 +360,8 @@ ResonancePdf::ResonancePdf(std::string name, initialize(pindices); } -ResonancePdf::ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - unsigned int sp, - Variable* mass, - Variable* width, - unsigned int cyc) +ResonancePdf::ResonancePdf( + std::string name, Variable *ar, Variable *ai, unsigned int sp, Variable *mass, Variable *width, unsigned int cyc) : GooPdf(nullptr, name) , amp_real(ar) , amp_imag(ai) { @@ -375,14 +377,8 @@ ResonancePdf::ResonancePdf(std::string name, initialize(pindices); } - -ResonancePdf::ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mass, - unsigned int sp, - Variable* width, - unsigned int cyc) +ResonancePdf::ResonancePdf( + std::string name, Variable *ar, Variable *ai, Variable *mass, unsigned int sp, Variable *width, unsigned int cyc) : GooPdf(nullptr, name) , amp_real(ar) , amp_imag(ai) { @@ -398,10 +394,7 @@ ResonancePdf::ResonancePdf(std::string name, initialize(pindices); } - -ResonancePdf::ResonancePdf(std::string name, - Variable* ar, - Variable* ai) +ResonancePdf::ResonancePdf(std::string name, Variable *ar, Variable *ai) : GooPdf(nullptr, name) , amp_real(ar) , amp_imag(ai) { @@ -413,12 +406,8 @@ ResonancePdf::ResonancePdf(std::string name, initialize(pindices); } -ResonancePdf::ResonancePdf(std::string name, - Variable* ar, - Variable* ai, - Variable* mean, - Variable* sigma, - unsigned int cyc) +ResonancePdf::ResonancePdf( + std::string name, Variable *ar, Variable *ai, Variable *mean, Variable *sigma, unsigned int cyc) : GooPdf(nullptr, name) , amp_real(ar) , amp_imag(ai) { @@ -431,10 +420,8 @@ ResonancePdf::ResonancePdf(std::string name, pindices.push_back(cyc); GET_FUNCTION_ADDR(ptr_to_GAUSSIAN); - initialize(pindices); + initialize(pindices); } - } // namespace GooFit - diff --git a/src/PDFs/ScaledGaussianPdf.cu b/src/PDFs/ScaledGaussianPdf.cu index 5cfc844f0..021590af1 100644 --- a/src/PDFs/ScaledGaussianPdf.cu +++ b/src/PDFs/ScaledGaussianPdf.cu @@ -5,20 +5,19 @@ namespace GooFit { - -__device__ fptype device_ScaledGaussian(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[0]; - fptype mean = p[indices[1]] + p[indices[3]]; +__device__ fptype device_ScaledGaussian(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[0]; + fptype mean = p[indices[1]] + p[indices[3]]; fptype sigma = p[indices[2]] * (1 + p[indices[4]]); - fptype ret = exp(-0.5*(x-mean)*(x-mean)/(sigma*sigma)); + fptype ret = exp(-0.5 * (x - mean) * (x - mean) / (sigma * sigma)); return ret; } __device__ device_function_ptr ptr_to_ScaledGaussian = device_ScaledGaussian; -__host__ ScaledGaussianPdf::ScaledGaussianPdf(std::string n, Variable* _x, Variable* mean, Variable* sigma, - Variable* delta, Variable* epsilon) +__host__ ScaledGaussianPdf::ScaledGaussianPdf( + std::string n, Variable *_x, Variable *mean, Variable *sigma, Variable *delta, Variable *epsilon) : GooPdf(_x, n) { registerParameter(mean); registerParameter(sigma); @@ -35,4 +34,3 @@ __host__ ScaledGaussianPdf::ScaledGaussianPdf(std::string n, Variable* _x, Varia } } // namespace GooFit - diff --git a/src/PDFs/SmoothHistogramPdf.cu b/src/PDFs/SmoothHistogramPdf.cu index b5877ebd4..f4849a59b 100644 --- a/src/PDFs/SmoothHistogramPdf.cu +++ b/src/PDFs/SmoothHistogramPdf.cu @@ -3,9 +3,8 @@ namespace GooFit { - -__constant__ fptype* dev_base_histograms[100]; // Multiple histograms for the case of multiple PDFs -__constant__ fptype* dev_smoothed_histograms[100]; +__constant__ fptype *dev_base_histograms[100]; // Multiple histograms for the case of multiple PDFs +__constant__ fptype *dev_smoothed_histograms[100]; unsigned int SmoothHistogramPdf::totalHistograms = 0; __device__ int dev_powi(int base, int exp) { @@ -17,39 +16,45 @@ __device__ int dev_powi(int base, int exp) { return ret; } -__device__ fptype device_EvalHistogram(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_EvalHistogram(fptype *evt, fptype *p, unsigned int *indices) { // Structure is // nP smoothingIndex totalHistograms (limit1 step1 bins1) (limit2 step2 bins2) nO o1 o2 // where limit and step are indices into functorConstants. - int numVars = RO_CACHE(indices[RO_CACHE(indices[0]) + 1]); - int globalBinNumber = 0; - int previous = 1; + int numVars = RO_CACHE(indices[RO_CACHE(indices[0]) + 1]); + int globalBinNumber = 0; + int previous = 1; int myHistogramIndex = RO_CACHE(indices[2]); // 1 only used for smoothing for(int i = 0; i < numVars; ++i) { - int varIndex = RO_CACHE(indices[RO_CACHE(indices[0]) + 2 + i]); - int lowerBoundIdx = 3*(i+1); - //if (gpuDebug & 1) printf("[%i, %i] Smoothed: %i %i %i\n", BLOCKIDX, THREADIDX, i, varIndex, indices[varIndex]); + int varIndex = RO_CACHE(indices[RO_CACHE(indices[0]) + 2 + i]); + int lowerBoundIdx = 3 * (i + 1); + // if (gpuDebug & 1) printf("[%i, %i] Smoothed: %i %i %i\n", BLOCKIDX, THREADIDX, i, varIndex, + // indices[varIndex]); fptype currVariable = evt[varIndex]; fptype lowerBound = RO_CACHE(functorConstants[RO_CACHE(indices[lowerBoundIdx + 0])]); fptype step = RO_CACHE(functorConstants[RO_CACHE(indices[lowerBoundIdx + 1])]); currVariable -= lowerBound; currVariable /= step; - //if (gpuDebug & 1) printf("[%i, %i] Smoothed: %i %i %f %f %f %f\n", BLOCKIDX, THREADIDX, i, varIndex, currVariable, lowerBound, step, evt[varIndex]); + // if (gpuDebug & 1) printf("[%i, %i] Smoothed: %i %i %f %f %f %f\n", BLOCKIDX, THREADIDX, i, varIndex, + // currVariable, lowerBound, step, evt[varIndex]); - auto localBinNumber = static_cast( floor(currVariable)); - globalBinNumber += previous * localBinNumber; - previous *= indices[lowerBoundIdx + 2]; + auto localBinNumber = static_cast(floor(currVariable)); + globalBinNumber += previous * localBinNumber; + previous *= indices[lowerBoundIdx + 2]; } - fptype* myHistogram = dev_smoothed_histograms[myHistogramIndex]; - fptype ret = RO_CACHE(myHistogram[globalBinNumber]); + fptype *myHistogram = dev_smoothed_histograms[myHistogramIndex]; + fptype ret = RO_CACHE(myHistogram[globalBinNumber]); - //if ((gpuDebug & 1) && (evt[8] < 0.5) && (paramIndices + debugParamIndex == indices)) printf("Smoothed: %f %f %f %i %f\n", evt[6], evt[7], myHistogram[globalBinNumber], globalBinNumber, dev_base_histograms[myHistogramIndex][globalBinNumber]); - //if (gpuDebug & 1) printf("Smoothed: %f %f %f %i %f\n", evt[0], evt[1], myHistogram[globalBinNumber], globalBinNumber, dev_base_histograms[myHistogramIndex][globalBinNumber]); - //if (gpuDebug & 1) printf("Smoothed: %f %f %f %i %f %f\n", evt[0], evt[1], ret, globalBinNumber, dev_base_histograms[myHistogramIndex][globalBinNumber], p[indices[1]]); + // if ((gpuDebug & 1) && (evt[8] < 0.5) && (paramIndices + debugParamIndex == indices)) printf("Smoothed: %f %f %f + // %i %f\n", evt[6], evt[7], myHistogram[globalBinNumber], globalBinNumber, + // dev_base_histograms[myHistogramIndex][globalBinNumber]); + // if (gpuDebug & 1) printf("Smoothed: %f %f %f %i %f\n", evt[0], evt[1], myHistogram[globalBinNumber], + // globalBinNumber, dev_base_histograms[myHistogramIndex][globalBinNumber]); + // if (gpuDebug & 1) printf("Smoothed: %f %f %f %i %f %f\n", evt[0], evt[1], ret, globalBinNumber, + // dev_base_histograms[myHistogramIndex][globalBinNumber], p[indices[1]]); return ret; } @@ -57,28 +62,28 @@ struct Smoother { int parameters; __device__ fptype operator()(int globalBin) { - unsigned int* indices = paramIndices + parameters; - int numVars = RO_CACHE(indices[RO_CACHE(indices[0]) + 1]); - fptype smoothing = RO_CACHE(cudaArray[RO_CACHE(indices[1])]); - int histIndex = RO_CACHE(indices[2]); - fptype* myHistogram = dev_base_histograms[histIndex]; - fptype centralValue = myHistogram[globalBin]; - - fptype otherBinsTotal = 0; + unsigned int *indices = paramIndices + parameters; + int numVars = RO_CACHE(indices[RO_CACHE(indices[0]) + 1]); + fptype smoothing = RO_CACHE(cudaArray[RO_CACHE(indices[1])]); + int histIndex = RO_CACHE(indices[2]); + fptype *myHistogram = dev_base_histograms[histIndex]; + fptype centralValue = myHistogram[globalBin]; + + fptype otherBinsTotal = 0; int numSurroundingBins = 0; - int otherBins = dev_powi(3, numVars); + int otherBins = dev_powi(3, numVars); for(int i = 0; i < otherBins; ++i) { - int currBin = globalBin; + int currBin = globalBin; int localPrevious = 1; - int trackingBin = globalBin; - bool offSomeAxis = false; + int trackingBin = globalBin; + bool offSomeAxis = false; for(int v = 0; v < numVars; ++v) { - //int lowerBoundIdx = 3*(i+1); - //int localNumBins = indices[6 + v*4]; - int localNumBins = RO_CACHE(indices[3*(v+1) + 2]); - int offset = ((i / dev_powi(3, v)) % 3) - 1; + // int lowerBoundIdx = 3*(i+1); + // int localNumBins = indices[6 + v*4]; + int localNumBins = RO_CACHE(indices[3 * (v + 1) + 2]); + int offset = ((i / dev_powi(3, v)) % 3) - 1; currBin += offset * localPrevious; localPrevious *= localNumBins; @@ -104,23 +109,24 @@ struct Smoother { otherBinsTotal += myHistogram[currBin]; } - centralValue += otherBinsTotal*smoothing; + centralValue += otherBinsTotal * smoothing; centralValue /= (1 + numSurroundingBins * smoothing); - //if (7010 == globalBin) printf("Smoothing: %f %f %f %i %f\n", myHistogram[globalBin], otherBinsTotal, smoothing, numSurroundingBins, centralValue); + // if (7010 == globalBin) printf("Smoothing: %f %f %f %i %f\n", myHistogram[globalBin], otherBinsTotal, + // smoothing, numSurroundingBins, centralValue); return centralValue; } }; __device__ device_function_ptr ptr_to_EvalHistogram = device_EvalHistogram; -__host__ SmoothHistogramPdf::SmoothHistogramPdf(std::string n, BinnedDataSet* hist, Variable* smoothing) +__host__ SmoothHistogramPdf::SmoothHistogramPdf(std::string n, BinnedDataSet *hist, Variable *smoothing) : GooPdf(nullptr, n) { - int numVars = hist->numVariables(); - int numConstants = 2*numVars; + int numVars = hist->numVariables(); + int numConstants = 2 * numVars; registerConstants(numConstants); host_constants = new fptype[numConstants]; - totalEvents = 0; + totalEvents = 0; std::vector pindices; pindices.push_back(registerParameter(smoothing)); @@ -128,16 +134,16 @@ __host__ SmoothHistogramPdf::SmoothHistogramPdf(std::string n, BinnedDataSet* hi int varIndex = 0; - for(Variable* var : hist->getVariables()) { + for(Variable *var : hist->getVariables()) { registerObservable(var); - //pindices.push_back((*var)->index); - pindices.push_back(cIndex + 2*varIndex + 0); - pindices.push_back(cIndex + 2*varIndex + 1); + // pindices.push_back((*var)->index); + pindices.push_back(cIndex + 2 * varIndex + 0); + pindices.push_back(cIndex + 2 * varIndex + 1); pindices.push_back(var->getNumBins()); - host_constants[2*varIndex + 0] = - var->getLowerLimit(); // NB, do not put cIndex here, it is accounted for by the offset in MEMCPY_TO_SYMBOL below. - host_constants[2*varIndex + 1] = var->getBinSize(); + host_constants[2 * varIndex + 0] = var->getLowerLimit(); // NB, do not put cIndex here, it is accounted for by + // the offset in MEMCPY_TO_SYMBOL below. + host_constants[2 * varIndex + 1] = var->getBinSize(); varIndex++; } @@ -150,24 +156,25 @@ __host__ SmoothHistogramPdf::SmoothHistogramPdf(std::string n, BinnedDataSet* hi totalEvents += curr; } - MEMCPY_TO_SYMBOL(functorConstants, host_constants, numConstants*sizeof(fptype), cIndex*sizeof(fptype), + MEMCPY_TO_SYMBOL(functorConstants, + host_constants, + numConstants * sizeof(fptype), + cIndex * sizeof(fptype), cudaMemcpyHostToDevice); if(totalEvents > 0) copyHistogramToDevice(host_histogram); else - std::cout << "Warning: Empty histogram supplied to " << getName() << - " not copied to device. Expect copyHistogramToDevice call later.\n"; + std::cout << "Warning: Empty histogram supplied to " << getName() + << " not copied to device. Expect copyHistogramToDevice call later.\n"; GET_FUNCTION_ADDR(ptr_to_EvalHistogram); initialize(pindices); } -fptype* pointerToFirst(thrust::device_vector* hist) { - return (&((*hist)[0])).get(); -} +fptype *pointerToFirst(thrust::device_vector *hist) { return (&((*hist)[0])).get(); } -fptype* pointerToFirst(thrust::host_vector* hist) { +fptype *pointerToFirst(thrust::host_vector *hist) { // (*hist) is the host_vector. // (*hist)[0] is a 'reference' - Thrust class, not ordinary C++ reference - // to the first element of the vector. @@ -176,28 +183,31 @@ fptype* pointerToFirst(thrust::host_vector* hist) { return &((*hist)[0]); } -__host__ void SmoothHistogramPdf::copyHistogramToDevice(thrust::host_vector& host_histogram) { - dev_base_histogram = new thrust::device_vector(host_histogram); +__host__ void SmoothHistogramPdf::copyHistogramToDevice(thrust::host_vector &host_histogram) { + dev_base_histogram = new thrust::device_vector(host_histogram); dev_smoothed_histogram = new thrust::device_vector(host_histogram); - static fptype* dev_address[1]; + static fptype *dev_address[1]; dev_address[0] = pointerToFirst(dev_base_histogram); - MEMCPY_TO_SYMBOL(dev_base_histograms, dev_address, sizeof(fptype*), totalHistograms*sizeof(fptype*), - cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + dev_base_histograms, dev_address, sizeof(fptype *), totalHistograms * sizeof(fptype *), cudaMemcpyHostToDevice); dev_address[0] = pointerToFirst(dev_smoothed_histogram); - MEMCPY_TO_SYMBOL(dev_smoothed_histograms, dev_address, sizeof(fptype*), totalHistograms*sizeof(fptype*), + MEMCPY_TO_SYMBOL(dev_smoothed_histograms, + dev_address, + sizeof(fptype *), + totalHistograms * sizeof(fptype *), cudaMemcpyHostToDevice); totalHistograms++; int expectedBins = 1; - for(auto & observable : observables) { + for(auto &observable : observables) { expectedBins *= observable->getNumBins(); } if(expectedBins != host_histogram.size()) { - std::cout << "Warning: Histogram supplied to " << getName() << " has " << host_histogram.size() << " bins, expected " << - expectedBins << " - may indicate a problem.\n"; + std::cout << "Warning: Histogram supplied to " << getName() << " has " << host_histogram.size() + << " bins, expected " << expectedBins << " - may indicate a problem.\n"; } } @@ -206,21 +216,18 @@ __host__ fptype SmoothHistogramPdf::normalize() const { smoother.parameters = parameters; thrust::counting_iterator binIndex(0); - thrust::transform(binIndex, - binIndex + dev_base_histogram->size(), - dev_smoothed_histogram->begin(), - smoother); + thrust::transform(binIndex, binIndex + dev_base_histogram->size(), dev_smoothed_histogram->begin(), smoother); - //return totalEvents; + // return totalEvents; fptype ret = thrust::reduce(dev_smoothed_histogram->begin(), dev_smoothed_histogram->end()); for(unsigned int varIndex = 0; varIndex < observables.size(); ++varIndex) { - ret *= host_constants[2*varIndex + 1]; // Bin size cached by constructor. + ret *= host_constants[2 * varIndex + 1]; // Bin size cached by constructor. } - //if (cpuDebug & 1) std::cout << "Normalising " << getName() << " " << host_params[host_indices[parameters + 1]] << " " << ret << std::endl; - host_normalisation[parameters] = 1.0/ret; + // if (cpuDebug & 1) std::cout << "Normalising " << getName() << " " << host_params[host_indices[parameters + 1]] << + // " " << ret << std::endl; + host_normalisation[parameters] = 1.0 / ret; return ret; } } // namespace GooFit - diff --git a/src/PDFs/SpinFactors.cu b/src/PDFs/SpinFactors.cu index 90428866e..0721311f0 100644 --- a/src/PDFs/SpinFactors.cu +++ b/src/PDFs/SpinFactors.cu @@ -10,116 +10,105 @@ This code is not sufficently tested yet and still under heavy development! namespace GooFit { - #define ZEMACH 1 -__device__ fptype DtoPP1_PtoSP2_StoP3P4(fptype* Vecs, unsigned int* indices) { - return 1.0; -} - -__device__ fptype ONE(fptype* Vecs, unsigned int* indices) { - return 1.0; -} - -__device__ fptype FF_12_34_L1(fptype* Vecs, unsigned int* indices) { - fptype mother_radius = functorConstants[indices[1]]; - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - - fptype m1 = (P1+P2).Mag2(); - fptype m2 = (P3+P4).Mag2(); - fptype s = (P1+P2+P3+P4).Mag2(); - fptype q2 = s/4. -(m1 + m2)/2. + (m1 - m2)*(m1 - m2)/(4*s); - fptype z2 = q2 * mother_radius*mother_radius; - fptype ff = 1.0/(1+z2); +__device__ fptype DtoPP1_PtoSP2_StoP3P4(fptype *Vecs, unsigned int *indices) { return 1.0; } + +__device__ fptype ONE(fptype *Vecs, unsigned int *indices) { return 1.0; } + +__device__ fptype FF_12_34_L1(fptype *Vecs, unsigned int *indices) { + fptype mother_radius = functorConstants[indices[1]]; + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + + fptype m1 = (P1 + P2).Mag2(); + fptype m2 = (P3 + P4).Mag2(); + fptype s = (P1 + P2 + P3 + P4).Mag2(); + fptype q2 = s / 4. - (m1 + m2) / 2. + (m1 - m2) * (m1 - m2) / (4 * s); + fptype z2 = q2 * mother_radius * mother_radius; + fptype ff = 1.0 / (1 + z2); // printf("%.5g, %.5g, %.5g, %.5g\n",s,m1,m2,sqrt(ff) ); return sqrt(ff); } -__device__ fptype FF_12_34_L2(fptype* Vecs, unsigned int* indices) { - fptype mother_radius = functorConstants[indices[1]]; - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - - fptype m1 = (P1+P2).Mag2(); - fptype m2 = (P3+P4).Mag2(); - fptype s = (P1+P2+P3+P4).Mag2(); - fptype q2 = s/4. -(m1 + m2)/2. + (m1 - m2)*(m1 - m2)/(4*s); - fptype z2 = q2 * mother_radius*mother_radius; - fptype ff = 1.0/ (z2*z2 + 3*z2 + 9); +__device__ fptype FF_12_34_L2(fptype *Vecs, unsigned int *indices) { + fptype mother_radius = functorConstants[indices[1]]; + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + + fptype m1 = (P1 + P2).Mag2(); + fptype m2 = (P3 + P4).Mag2(); + fptype s = (P1 + P2 + P3 + P4).Mag2(); + fptype q2 = s / 4. - (m1 + m2) / 2. + (m1 - m2) * (m1 - m2) / (4 * s); + fptype z2 = q2 * mother_radius * mother_radius; + fptype ff = 1.0 / (z2 * z2 + 3 * z2 + 9); return sqrt(ff); } -__device__ fptype FF_123_4_L1(fptype* Vecs, unsigned int* indices) { - fptype mother_radius = functorConstants[indices[1]]; - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - - fptype m1 = (P1+P2+P3).Mag2(); +__device__ fptype FF_123_4_L1(fptype *Vecs, unsigned int *indices) { + fptype mother_radius = functorConstants[indices[1]]; + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + + fptype m1 = (P1 + P2 + P3).Mag2(); fptype m2 = P4.Mag2(); - fptype s = (P1+P2+P3+P4).Mag2(); - fptype q2 = s/4. -(m1 + m2)/2. + (m1 - m2)*(m1 - m2)/(4*s); - fptype z2 = q2 * mother_radius*mother_radius; - fptype ff = 1.0/(1+z2); + fptype s = (P1 + P2 + P3 + P4).Mag2(); + fptype q2 = s / 4. - (m1 + m2) / 2. + (m1 - m2) * (m1 - m2) / (4 * s); + fptype z2 = q2 * mother_radius * mother_radius; + fptype ff = 1.0 / (1 + z2); return sqrt(ff); } -__device__ fptype FF_123_4_L2(fptype* Vecs, unsigned int* indices) { - fptype mother_radius = functorConstants[indices[1]]; - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - - fptype m1 = (P1+P2+P3).Mag2(); +__device__ fptype FF_123_4_L2(fptype *Vecs, unsigned int *indices) { + fptype mother_radius = functorConstants[indices[1]]; + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + + fptype m1 = (P1 + P2 + P3).Mag2(); fptype m2 = P4.Mag2(); - fptype s = (P1+P2+P3+P4).Mag2(); - fptype q2 = s/4. -(m1 + m2)/2. + (m1 - m2)*(m1 - m2)/(4*s); - fptype z2 = q2 * mother_radius*mother_radius; - fptype ff = 1.0/ (z2*z2 + 3*z2 + 9); + fptype s = (P1 + P2 + P3 + P4).Mag2(); + fptype q2 = s / 4. - (m1 + m2) / 2. + (m1 - m2) * (m1 - m2) / (4 * s); + fptype z2 = q2 * mother_radius * mother_radius; + fptype ff = 1.0 / (z2 * z2 + 3 * z2 + 9); return sqrt(ff); } - - -__device__ fptype DtoPP1_PtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoPP1_PtoVP2_VtoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV = P3 + P4; gpuLVec qV = P3 - P4; @@ -134,21 +123,19 @@ __device__ fptype DtoPP1_PtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { return LP.Dot(LV); #else - return (P2.Dot(qV) - P2.Dot(pV) * pV.Dot(qV))/(pV.M() * pV.M()); + return (P2.Dot(qV) - P2.Dot(pV) * pV.Dot(qV)) / (pV.M() * pV.M()); #endif } - - -__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_S(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_S(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); // printf("vec%i %.5g, %.5g, %.5g, %.5g\n",0, P1.getX(), P1.getY(), P1.getZ(),P1.getE()); // printf("vec%i %.5g, %.5g, %.5g, %.5g\n",1, P2.getX(), P2.getY(), P2.getZ(),P2.getE()); @@ -163,24 +150,22 @@ __device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_S(fptype* Vecs, unsigned int* indice fptype MV1 = sqrt(pV1.Dot(pV1)); fptype MV2 = sqrt(pV2.Dot(pV2)); - fptype returnVal = (qV1.Dot(qV2) - - qV1.Dot(pV1) * pV1.Dot(qV2) / (MV1*MV1) - - qV1.Dot(pV2) * pV2.Dot(qV2) / (MV2*MV2) - + qV1.Dot(pV1) * pV1.Dot(pV2) * pV2.Dot(qV2) - / (MV1*MV1 * MV2*MV2)); + fptype returnVal + = (qV1.Dot(qV2) - qV1.Dot(pV1) * pV1.Dot(qV2) / (MV1 * MV1) - qV1.Dot(pV2) * pV2.Dot(qV2) / (MV2 * MV2) + + qV1.Dot(pV1) * pV1.Dot(pV2) * pV2.Dot(qV2) / (MV1 * MV1 * MV2 * MV2)); // printf("s1 %.5g; %i,%i,%i,%i\n",returnVal, indices[2], indices[3], indices[4], indices[5]); return returnVal; } -__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_P(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_P(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV1 = P1 + P2; gpuLVec qV1 = P2 - P1; @@ -205,26 +190,25 @@ __device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_P(fptype* Vecs, unsigned int* indice #endif } -__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_D(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_D(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV1 = P1 + P2; gpuLVec qV1 = P1 - P2; gpuLVec pV2 = P3 + P4; gpuLVec qV2 = P3 - P4; - #ifdef ZEMACH gpuLVec pD = pV1 + pV2; gpuLVec qD = pV1 - pV2; - double mD = pD.M(); + double mD = pD.M(); ZTspin1 tV1(qV1, pV1, pV1.M()); ZTspin1 tV2(qV2, pV2, pV2.M()); @@ -238,27 +222,24 @@ __device__ fptype DtoV1V2_V1toP1P2_V2toP3P4_D(fptype* Vecs, unsigned int* indice return returnVal; #else - - fptype MV1 = sqrt(pV1.Dot(pV1)); - fptype MV2 = sqrt(pV2.Dot(pV2)); - fptype returnVal = (qV1.Dot(pV2) - qV1.Dot(pV1) * pV1.Dot(pV2)/(MV1*MV1) - )*( - qV2.Dot(pV1) - qV2.Dot(pV2) * pV2.Dot(pV1)/(MV2*MV2) - ); + fptype MV1 = sqrt(pV1.Dot(pV1)); + fptype MV2 = sqrt(pV2.Dot(pV2)); + fptype returnVal = (qV1.Dot(pV2) - qV1.Dot(pV1) * pV1.Dot(pV2) / (MV1 * MV1)) + * (qV2.Dot(pV1) - qV2.Dot(pV2) * pV2.Dot(pV1) / (MV2 * MV2)); return returnVal; #endif } -__device__ fptype DtoV1P1_V1toV2P2_V2toP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoV1P1_V1toV2P2_V2toP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV1 = P2 + P3 + P4; gpuLVec pV2 = P3 + P4; @@ -292,24 +273,23 @@ __device__ fptype DtoV1P1_V1toV2P2_V2toP3P4(fptype* Vecs, unsigned int* indices) #endif } -__device__ fptype DtoVS_VtoP1P2_StoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - gpuLVec pS = P3 + P4; - gpuLVec pV = P1 + P2; - gpuLVec qV = P1 - P2; +__device__ fptype DtoVS_VtoP1P2_StoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + gpuLVec pS = P3 + P4; + gpuLVec pV = P1 + P2; + gpuLVec qV = P1 - P2; #ifdef ZEMACH - gpuLVec pD= pV + pS; - gpuLVec qD= pV - pS; + gpuLVec pD = pV + pS; + gpuLVec qD = pV - pS; ZTspin1 LD(qD, pD, pD.M()); ZTspin1 LV(qV, pV, pV.M()); return (LD.Dot(LV)); @@ -322,31 +302,31 @@ __device__ fptype DtoVS_VtoP1P2_StoP3P4(fptype* Vecs, unsigned int* indices) { fptype MV = sqrt(pV.Dot(pV)); - fptype returnVal = (pS.Dot(qV) - pS.Dot(pV) * pV.Dot(qV) / (MV*MV)); + fptype returnVal = (pS.Dot(qV) - pS.Dot(pV) * pV.Dot(qV) / (MV * MV)); return returnVal; #endif } -__device__ fptype DtoAP1_AtoSP2_StoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); - - gpuLVec pS = P3 + P4; - gpuLVec pA = P2 + pS; - gpuLVec qA = pS - P2; - gpuLVec pD = pA + P1; - gpuLVec qD = pA - P1; - - // printf("%f, %f, %f, %f\n",P1.GetX(), P1.GetY(), P1.GetZ(), P1.GetE() ); - // printf("%f, %f, %f, %f\n",P2.GetX(), P2.GetY(), P2.GetZ(), P2.GetE() ); - // printf("%f, %f, %f, %f\n",P3.GetX(), P3.GetY(), P3.GetZ(), P3.GetE() ); - // printf("%f, %f, %f, %f\n",P4.GetX(), P4.GetY(), P4.GetZ(), P4.GetE() ); +__device__ fptype DtoAP1_AtoSP2_StoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); + + gpuLVec pS = P3 + P4; + gpuLVec pA = P2 + pS; + gpuLVec qA = pS - P2; + gpuLVec pD = pA + P1; + gpuLVec qD = pA - P1; + +// printf("%f, %f, %f, %f\n",P1.GetX(), P1.GetY(), P1.GetZ(), P1.GetE() ); +// printf("%f, %f, %f, %f\n",P2.GetX(), P2.GetY(), P2.GetZ(), P2.GetE() ); +// printf("%f, %f, %f, %f\n",P3.GetX(), P3.GetY(), P3.GetZ(), P3.GetE() ); +// printf("%f, %f, %f, %f\n",P4.GetX(), P4.GetY(), P4.GetZ(), P4.GetE() ); #ifdef ZEMACH ZTspin1 LD(qD, pD, pD.M()); @@ -354,21 +334,21 @@ __device__ fptype DtoAP1_AtoSP2_StoP3P4(fptype* Vecs, unsigned int* indices) { return (LD.Dot(LA)); #else - fptype MA = sqrt(pA.Dot(pA)); - fptype returnVal = (P1.Dot(qA) - P1.Dot(pA) * pA.Dot(qA) / (MA*MA)); + fptype MA = sqrt(pA.Dot(pA)); + fptype returnVal = (P1.Dot(qA) - P1.Dot(pA) * pA.Dot(qA) / (MA * MA)); return returnVal; #endif } -__device__ fptype DtoAP1_AtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoAP1_AtoVP2_VtoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV = P3 + P4; gpuLVec qV = P3 - P4; @@ -381,31 +361,29 @@ __device__ fptype DtoAP1_AtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { ZTspin1 LV(qV, pV, pV.M()); SpinSumV PA(pA, pA.M()); - gpuLVec tmp= PA.Dot(LV); - return - (LB.Dot(tmp)); // minus to be equal to MINT3 + gpuLVec tmp = PA.Dot(LV); + return -(LB.Dot(tmp)); // minus to be equal to MINT3 #else gpuLVec p0 = P1; - fptype MA = sqrt(pA.Dot(pA)); - fptype MV = sqrt(pV.Dot(pV)); - fptype returnVal = P1.Dot(qV) - - p0.Dot(pA) * pA.Dot(qV) / (MA*MA) - - p0.Dot(pV) * pV.Dot(qV) / (MV*MV) - + p0.Dot(pA) * pA.Dot(pV) * pV.Dot(qV) / (MA*MA * MV*MV); + fptype MA = sqrt(pA.Dot(pA)); + fptype MV = sqrt(pV.Dot(pV)); + fptype returnVal = P1.Dot(qV) - p0.Dot(pA) * pA.Dot(qV) / (MA * MA) - p0.Dot(pV) * pV.Dot(qV) / (MV * MV) + + p0.Dot(pA) * pA.Dot(pV) * pV.Dot(qV) / (MA * MA * MV * MV); // printf("spin %.7g\n",returnVal ); return returnVal; #endif } -__device__ fptype DtoAP1_AtoVP2Dwave_VtoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoAP1_AtoVP2Dwave_VtoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV = P3 + P4; gpuLVec qV = P3 - P4; @@ -418,7 +396,7 @@ __device__ fptype DtoAP1_AtoVP2Dwave_VtoP3P4(fptype* Vecs, unsigned int* indices ZTspin1 LD(qD, pD, pD.M()); ZTspin1 LV(qV, pV, pV.M()); ZTspin2 LA(qA, pA, pA.M()); - gpuLVec tmp= LA.Contract(LV); + gpuLVec tmp = LA.Contract(LV); return (LD.Dot(tmp)); #else @@ -426,25 +404,23 @@ __device__ fptype DtoAP1_AtoVP2Dwave_VtoP3P4(fptype* Vecs, unsigned int* indices fptype MA = sqrt(pA.Dot(pA)); fptype MV = sqrt(pV.Dot(pV)); - fptype returnVal = P1.Dot((qA - qA.Dot(pA)*pA * (1./(MA*MA)))) * (qV - qV.Dot(pV)*pV * (1./(MV*MV))).Dot(pA); + fptype returnVal + = P1.Dot((qA - qA.Dot(pA) * pA * (1. / (MA * MA)))) * (qV - qV.Dot(pV) * pV * (1. / (MV * MV))).Dot(pA); // printf("spin %.7g\n",returnVal ); return returnVal; #endif } - - - -__device__ fptype DtoTP1_TtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { - unsigned int p1 = indices[2]; - unsigned int p2 = indices[3]; - unsigned int p3 = indices[4]; - unsigned int p4 = indices[5]; - gpuLVec P1(Vecs[0 + 4*p1], Vecs[1 + 4*p1], Vecs[2 + 4*p1], Vecs[3 + 4*p1]); - gpuLVec P2(Vecs[0 + 4*p2], Vecs[1 + 4*p2], Vecs[2 + 4*p2], Vecs[3 + 4*p2]); - gpuLVec P3(Vecs[0 + 4*p3], Vecs[1 + 4*p3], Vecs[2 + 4*p3], Vecs[3 + 4*p3]); - gpuLVec P4(Vecs[0 + 4*p4], Vecs[1 + 4*p4], Vecs[2 + 4*p4], Vecs[3 + 4*p4]); +__device__ fptype DtoTP1_TtoVP2_VtoP3P4(fptype *Vecs, unsigned int *indices) { + unsigned int p1 = indices[2]; + unsigned int p2 = indices[3]; + unsigned int p3 = indices[4]; + unsigned int p4 = indices[5]; + gpuLVec P1(Vecs[0 + 4 * p1], Vecs[1 + 4 * p1], Vecs[2 + 4 * p1], Vecs[3 + 4 * p1]); + gpuLVec P2(Vecs[0 + 4 * p2], Vecs[1 + 4 * p2], Vecs[2 + 4 * p2], Vecs[3 + 4 * p2]); + gpuLVec P3(Vecs[0 + 4 * p3], Vecs[1 + 4 * p3], Vecs[2 + 4 * p3], Vecs[3 + 4 * p3]); + gpuLVec P4(Vecs[0 + 4 * p4], Vecs[1 + 4 * p4], Vecs[2 + 4 * p4], Vecs[3 + 4 * p4]); gpuLVec pV = P3 + P4; gpuLVec qV = P3 - P4; @@ -456,7 +432,7 @@ __device__ fptype DtoTP1_TtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { ZTspin2 t2T(qT, pT, pT.M()); ZTspin1 tV(qV, pV, pV.M()); - //gpuLVec DT(t2T.Contract(qD)); +// gpuLVec DT(t2T.Contract(qD)); #ifdef ZEMACH ZTspin1 tD(qD, pD, pD.M()); @@ -465,8 +441,8 @@ __device__ fptype DtoTP1_TtoVP2_VtoP3P4(fptype* Vecs, unsigned int* indices) { SpinSumV P1T(pT, pT.M()); SpinSumT P2T(pT, pT.M()); - gpuLVec tmp= LeviCivita(t1T, pT, P1T.Dot(tV)); - return P2T.Sandwich(tD, tD, tmp, t1T) + 1./3. * tD.Dot(tD) / (pT.Dot(pT)) * P2T.Sandwich(pD, pD, tmp, t1T); + gpuLVec tmp = LeviCivita(t1T, pT, P1T.Dot(tV)); + return P2T.Sandwich(tD, tD, tmp, t1T) + 1. / 3. * tD.Dot(tD) / (pT.Dot(pT)) * P2T.Sandwich(pD, pD, tmp, t1T); #else fptype returnVal = LeviCivita(pD, qD, DT, tV); @@ -488,21 +464,22 @@ __device__ spin_function_ptr ptr_to_DtoAP1_AtoVP2_VtoP3P4 = DtoAP1_AtoVP2_ __device__ spin_function_ptr ptr_to_DtoAP1_AtoVP2Dwave_VtoP3P4 = DtoAP1_AtoVP2Dwave_VtoP3P4; __device__ spin_function_ptr ptr_to_DtoTP1_TtoVP2_VtoP3P4 = DtoTP1_TtoVP2_VtoP3P4; - - -__device__ spin_function_ptr ptr_to_FF_12_34_L1 = FF_12_34_L1; -__device__ spin_function_ptr ptr_to_FF_12_34_L2 = FF_12_34_L2; -__device__ spin_function_ptr ptr_to_FF_123_4_L1 = FF_123_4_L1; -__device__ spin_function_ptr ptr_to_FF_123_4_L2 = FF_123_4_L2; -__device__ spin_function_ptr ptr_to_ONE = ONE; - - - -SpinFactor::SpinFactor(std::string name, SF_4Body SF, unsigned int P0, unsigned int P1, unsigned int P2, - unsigned int P3) - : GooPdf(nullptr, name), _SF(SF), _P0(P0), _P1(P1), _P2(P2), _P3(P3) { +__device__ spin_function_ptr ptr_to_FF_12_34_L1 = FF_12_34_L1; +__device__ spin_function_ptr ptr_to_FF_12_34_L2 = FF_12_34_L2; +__device__ spin_function_ptr ptr_to_FF_123_4_L1 = FF_123_4_L1; +__device__ spin_function_ptr ptr_to_FF_123_4_L2 = FF_123_4_L2; +__device__ spin_function_ptr ptr_to_ONE = ONE; + +SpinFactor::SpinFactor( + std::string name, SF_4Body SF, unsigned int P0, unsigned int P1, unsigned int P2, unsigned int P3) + : GooPdf(nullptr, name) + , _SF(SF) + , _P0(P0) + , _P1(P1) + , _P2(P2) + , _P3(P3) { std::vector pindices; - pindices.push_back(0); //dummy for index to constants. + pindices.push_back(0); // dummy for index to constants. pindices.push_back(P0); pindices.push_back(P1); pindices.push_back(P2); @@ -583,4 +560,3 @@ SpinFactor::SpinFactor(std::string name, SF_4Body SF, unsigned int P0, unsigned } } // namespace GooFit - diff --git a/src/PDFs/StepPdf.cu b/src/PDFs/StepPdf.cu index d3b354958..2de364dd3 100644 --- a/src/PDFs/StepPdf.cu +++ b/src/PDFs/StepPdf.cu @@ -2,17 +2,16 @@ namespace GooFit { - -__device__ fptype device_Step(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0]]]; +__device__ fptype device_Step(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0]]]; fptype x0 = p[indices[1]]; return (x > x0 ? 1 : 0); } __device__ device_function_ptr ptr_to_Step = device_Step; -device_function_ptr hptr_to_Step = device_Step; +device_function_ptr hptr_to_Step = device_Step; -__host__ StepPdf::StepPdf(std::string n, Variable* _x, Variable* x0) +__host__ StepPdf::StepPdf(std::string n, Variable *_x, Variable *x0) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(x0)); @@ -21,10 +20,9 @@ __host__ StepPdf::StepPdf(std::string n, Variable* _x, Variable* x0) } __host__ fptype StepPdf::integrate(fptype lo, fptype hi) const { - unsigned int* indices = host_indices+parameters; - fptype x0 = host_params[indices[1]]; + unsigned int *indices = host_indices + parameters; + fptype x0 = host_params[indices[1]]; return (hi - x0); } } // namespace GooFit - diff --git a/src/PDFs/Tddp4Pdf.cu b/src/PDFs/Tddp4Pdf.cu index d2eb22a8a..77a14826b 100644 --- a/src/PDFs/Tddp4Pdf.cu +++ b/src/PDFs/Tddp4Pdf.cu @@ -7,12 +7,18 @@ This code is not sufficently tested yet and still under heavy development! TODO: - Test lineshapes, only done for BW_DP and BW_MINT so far - Check and implement more SF -- Currently no check if the event is even allowed in phasespace is done. This should preferably be done outside of this class. +- Currently no check if the event is even allowed in phasespace is done. This should preferably be done outside of this +class. - Some things could be implemented differently maybe, performance should be compared for both cases. -For example the way Spinfactors are stored in the same array as the Lineshape values. Is this really worth the memory we lose by using a complex to store the SF? */ +#include "goofit/Error.h" +#include "goofit/Log.h" +#include "goofit/PDFs/physics/DP4Pdf.h" +#include "goofit/PDFs/physics/EvalVar.h" +#include "goofit/PDFs/physics/Tddp4Pdf.h" #include #include #include @@ -20,69 +26,57 @@ TODO: #include #include #include -#include "goofit/Error.h" -#include "goofit/PDFs/physics/Tddp4Pdf.h" -#include "goofit/PDFs/physics/EvalVar.h" -#include "goofit/PDFs/physics/DP4Pdf.h" -#include "goofit/Log.h" #include namespace GooFit { - struct genExp { fptype gamma; unsigned int offset; - __host__ __device__ - genExp(unsigned int c, fptype d) : gamma(d), offset(c) {}; - - __host__ __device__ - fptype operator()(unsigned int x) const { + __host__ __device__ genExp(unsigned int c, fptype d) + : gamma(d) + , offset(c){}; + __host__ __device__ fptype operator()(unsigned int x) const { thrust::random::default_random_engine rand(1431655765); thrust::uniform_real_distribution dist(0, 1); - rand.discard(x+offset); + rand.discard(x + offset); - return - log( dist(rand) ) / gamma; + return -log(dist(rand)) / gamma; } }; - struct exp_functor { size_t tmpparam, tmpoff; fptype gammamin, wmax; exp_functor(size_t tmpparam, size_t tmpoff, fptype gammamin, fptype wmax) - : tmpparam(tmpparam), - tmpoff(tmpoff), - gammamin(gammamin), - wmax(wmax) {} - - __device__ - fptype operator()(thrust::tuple t) { - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<2>(t) + (evtNum * thrust::get<3>(t)); - unsigned int* indices = paramIndices + tmpparam; - fptype time = evt[indices[8 + indices[0]]]; + : tmpparam(tmpparam) + , tmpoff(tmpoff) + , gammamin(gammamin) + , wmax(wmax) {} + + __device__ fptype operator()(thrust::tuple t) { + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<2>(t) + (evtNum * thrust::get<3>(t)); + unsigned int *indices = paramIndices + tmpparam; + fptype time = evt[indices[8 + indices[0]]]; thrust::random::minstd_rand0 rand(1431655765); - thrust::uniform_real_distribution dist(0,1); - rand.discard( tmpoff + evtNum ); + thrust::uniform_real_distribution dist(0, 1); + rand.discard(tmpoff + evtNum); - return ( dist(rand) * exp(-time*gammamin) * wmax) < thrust::get<1>(t); + return (dist(rand) * exp(-time * gammamin) * wmax) < thrust::get<1>(t); } - }; - - // The function of this array is to hold all the cached waves; specific // waves are recalculated when the corresponding resonance mass or width // changes. Note that in a multithread environment each thread needs its // own cache, hence the '10'. Ten threads should be enough for anyone! -__device__ thrust::complex* cResSF_TD[10]; -__device__ thrust::complex* Amps_TD[10]; +__device__ thrust::complex *cResSF_TD[10]; +__device__ thrust::complex *Amps_TD[10]; /* Constant memory array to hold specific info for amplitude calculation. First entries are the starting points in array, necessary, because number of Lineshapes(LS) or Spinfactors(SF) can vary @@ -91,16 +85,16 @@ First entries are the starting points in array, necessary, because number of Lin */ // __constant__ unsigned int AmpIndices_TD[100]; - // This function gets called by the GooFit framework to get the value of the PDF. -__device__ fptype device_TDDP4(fptype* evt, fptype* p, unsigned int* indices) { - //printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, totalAmp.imag); +__device__ fptype device_TDDP4(fptype *evt, fptype *p, unsigned int *indices) { + // printf("DalitzPlot evt %i zero: %i %i %f (%f, %f).\n", evtNum, numResonances, effFunctionIdx, eff, totalAmp.real, + // totalAmp.imag); + + auto evtNum = static_cast(floor(0.5 + evt[indices[7 + indices[0]]])); + // GOOFIT_TRACE("TDDP4: Number of events: {}", evtNum); - auto evtNum = static_cast( floor(0.5 + evt[indices[7 + indices[0]]])); - //GOOFIT_TRACE("TDDP4: Number of events: {}", evtNum); - - unsigned int cacheToUse = indices[2]; - unsigned int numAmps = indices[5]; + unsigned int cacheToUse = indices[2]; + unsigned int numAmps = indices[5]; thrust::complex AmpA(0, 0); thrust::complex AmpB(0, 0); @@ -110,62 +104,59 @@ __device__ fptype device_TDDP4(fptype* evt, fptype* p, unsigned int* indices) { for(int i = 0; i < numAmps; ++i) { unsigned int start = AmpIndices[i]; - unsigned int flag = AmpIndices[start + 3 + numAmps]; + unsigned int flag = AmpIndices[start + 3 + numAmps]; thrust::complex temp; - /*printf("flag:%i\n",flag);*/ + /*printf("flag:%i\n",flag);*/ switch(flag) { case 0: - amp_A = thrust::complex(p[indices[12 + 2*(i+k)]], p[indices[13 + 2*(i+k)]]); - temp = Amps_TD[cacheToUse][evtNum*numAmps + i]; + amp_A = thrust::complex(p[indices[12 + 2 * (i + k)]], p[indices[13 + 2 * (i + k)]]); + temp = Amps_TD[cacheToUse][evtNum * numAmps + i]; AmpA += temp * amp_A; break; case 1: - amp_B = thrust::complex(p[indices[12 + 2*(i+k)]], p[indices[13 + 2*(i+k)]]); - temp = Amps_TD[cacheToUse][evtNum*numAmps + i]; + amp_B = thrust::complex(p[indices[12 + 2 * (i + k)]], p[indices[13 + 2 * (i + k)]]); + temp = Amps_TD[cacheToUse][evtNum * numAmps + i]; AmpB += temp * amp_B; break; case 2: - amp_A = thrust::complex(p[indices[12 + 2*(i+k)]], p[indices[13 + 2*(i+k)]]); - temp = Amps_TD[cacheToUse][evtNum*numAmps + i]; + amp_A = thrust::complex(p[indices[12 + 2 * (i + k)]], p[indices[13 + 2 * (i + k)]]); + temp = Amps_TD[cacheToUse][evtNum * numAmps + i]; AmpA += temp * amp_A; - + ++k; - amp_B = thrust::complex(p[indices[12 + 2*(i+k)]], p[indices[13 + 2*(i+k)]]); - temp = Amps_TD[cacheToUse][evtNum*numAmps + i]; + amp_B = thrust::complex(p[indices[12 + 2 * (i + k)]], p[indices[13 + 2 * (i + k)]]); + temp = Amps_TD[cacheToUse][evtNum * numAmps + i]; AmpB += temp * amp_B; break; } } - fptype _tau = p[indices[7]]; - fptype _xmixing = p[indices[8]]; - fptype _ymixing = p[indices[9]]; + fptype _tau = p[indices[7]]; + fptype _xmixing = p[indices[8]]; + fptype _ymixing = p[indices[9]]; fptype _SqWStoRSrate = p[indices[10]]; - fptype _time = evt[indices[8 + indices[0]]]; - fptype _sigma = evt[indices[9 + indices[0]]]; + fptype _time = evt[indices[8 + indices[0]]]; + fptype _sigma = evt[indices[9 + indices[0]]]; AmpA *= _SqWStoRSrate; - /*printf("%i read time: %.5g x: %.5g y: %.5g \n",evtNum, _time, _xmixing, _ymixing);*/ + /*printf("%i read time: %.5g x: %.5g y: %.5g \n",evtNum, _time, _xmixing, _ymixing);*/ - fptype term1 = thrust::norm(AmpA) + thrust::norm(AmpB); - fptype term2 = thrust::norm(AmpA) - thrust::norm(AmpB); - thrust::complex term3 = AmpA * thrust::conj(AmpB); + fptype term1 = thrust::norm(AmpA) + thrust::norm(AmpB); + fptype term2 = thrust::norm(AmpA) - thrust::norm(AmpB); + thrust::complex term3 = AmpA * thrust::conj(AmpB); // printf("%i dev %.7g %.7g %.7g %.7g\n", evtNum, norm2(AmpA), norm2(AmpB), term3.real, term3.imag); - int effFunctionIdx = 12 + 2*indices[3] + 2*indices[4] + 2*indices[6]; - int resfctidx = indices[11]; - int resfctpar = effFunctionIdx + 2; + int effFunctionIdx = 12 + 2 * indices[3] + 2 * indices[4] + 2 * indices[6]; + int resfctidx = indices[11]; + int resfctpar = effFunctionIdx + 2; - - fptype ret = (*(reinterpret_cast(device_function_table[resfctidx])))(term1, term2, term3.real(), - term3.imag(), - _tau, _time, _xmixing, _ymixing, _sigma, - p, indices + resfctpar); + fptype ret = (*(reinterpret_cast(device_function_table[resfctidx])))( + term1, term2, term3.real(), term3.imag(), _tau, _time, _xmixing, _ymixing, _sigma, p, indices + resfctpar); fptype eff = callFunction(evt, indices[effFunctionIdx], indices[effFunctionIdx + 1]); - /*printf("%i result %.7g, eff %.7g\n",evtNum, ret, eff);*/ + /*printf("%i result %.7g, eff %.7g\n",evtNum, ret, eff);*/ ret *= eff; /*printf("in prob: %f\n", ret);*/ return ret; @@ -174,28 +165,27 @@ __device__ fptype device_TDDP4(fptype* evt, fptype* p, unsigned int* indices) { __device__ device_function_ptr ptr_to_TDDP4 = device_TDDP4; __host__ TDDP4::TDDP4(std::string n, - std::vector observables, - DecayInfo_DP* decay, - MixingTimeResolution* Tres, - GooPdf* efficiency, - Variable* mistag, + std::vector observables, + DecayInfo_DP *decay, + MixingTimeResolution *Tres, + GooPdf *efficiency, + Variable *mistag, unsigned int MCeventsNorm) : GooPdf(nullptr, n) , decayInfo(decay) , _observables(observables) , resolution(Tres) - , totalEventSize(observables.size()+2) // number of observables plus eventnumber - { + , totalEventSize(observables.size() + 2) // number of observables plus eventnumber +{ // should include m12, m34, cos12, cos34, phi, eventnumber, dtime, sigmat. In this order! - for(auto & observable : observables) { + for(auto &observable : observables) { registerObservable(observable); } - - std::vectordecayConstants; + std::vector decayConstants; decayConstants.push_back(decayInfo->meson_radius); - for(double & particle_masse : decayInfo->particle_masses) { + for(double &particle_masse : decayInfo->particle_masses) { decayConstants.push_back(particle_masse); } @@ -207,46 +197,48 @@ __host__ TDDP4::TDDP4(std::string n, std::vector pindices; pindices.push_back(registerConstants(decayConstants.size())); - MEMCPY_TO_SYMBOL(functorConstants, &decayConstants[0], decayConstants.size()*sizeof(fptype), cIndex*sizeof(fptype), + MEMCPY_TO_SYMBOL(functorConstants, + &decayConstants[0], + decayConstants.size() * sizeof(fptype), + cIndex * sizeof(fptype), cudaMemcpyHostToDevice); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); pindices.push_back(0); //#LS pindices.push_back(0); //#SF pindices.push_back(0); //#AMP - pindices.push_back(0); //number of coefficients, because its not necessary to be equal to number of Amps. + pindices.push_back(0); // number of coefficients, because its not necessary to be equal to number of Amps. pindices.push_back(registerParameter(decayInfo->_tau)); pindices.push_back(registerParameter(decayInfo->_xmixing)); pindices.push_back(registerParameter(decayInfo->_ymixing)); pindices.push_back(registerParameter(decayInfo->_SqWStoRSrate)); if(resolution->getDeviceFunction() < 0) - throw GooFit::GeneralError("The resolution device function index {} must be more than 0", resolution->getDeviceFunction()); - pindices.push_back(static_cast( resolution->getDeviceFunction())); + throw GooFit::GeneralError("The resolution device function index {} must be more than 0", + resolution->getDeviceFunction()); + pindices.push_back(static_cast(resolution->getDeviceFunction())); // This is the start of reading in the amplitudes and adding the lineshapes and Spinfactors to this PDF // This is done in this way so we don't have multiple copies of one lineshape in one pdf. std::vector ampidx; std::vector nPermVec; std::vector ampidxstart; - unsigned int coeff_counter=0; - std::vector AmpBuffer; + unsigned int coeff_counter = 0; + std::vector AmpBuffer; - std::vector AmpsA = decayInfo->amplitudes; - std::vector AmpsB = decayInfo->amplitudes_B; + std::vector AmpsA = decayInfo->amplitudes; + std::vector AmpsB = decayInfo->amplitudes_B; - for(auto & i : AmpsA) { - - - AmpMap[i->_uniqueDecayStr] = std::make_pair(std::vector(0), std::vector(0)); + for(auto &i : AmpsA) { + AmpMap[i->_uniqueDecayStr] = std::make_pair(std::vector(0), std::vector(0)); // printf("Adding Amplitde A:%s\n",AmpsA[i]->_uniqueDecayStr.c_str()); auto LSvec = i->_LS; - for(auto & LSIT : LSvec) { - auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase* L) { - return (*LSIT)== *(dynamic_cast(L)); + for(auto &LSIT : LSvec) { + auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase *L) { + return (*LSIT) == *(dynamic_cast(L)); }); if(found != components.end()) { @@ -256,16 +248,14 @@ __host__ TDDP4::TDDP4(std::string n, components.push_back(LSIT); AmpMap[i->_uniqueDecayStr].first.push_back(components.size() - 1); // printf("Adding LS %s\n",(*LSIT)->getName().c_str()); - } } auto SFvec = i->_SF; - for(auto & SFIT : SFvec) { - auto found = std::find_if(SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor* S) { - return (*SFIT) == (*S); - }); + for(auto &SFIT : SFvec) { + auto found = std::find_if( + SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor *S) { return (*SFIT) == (*S); }); if(found != SpinFactors.end()) { AmpMap[i->_uniqueDecayStr].second.push_back(std::distance(SpinFactors.begin(), found)); @@ -274,20 +264,16 @@ __host__ TDDP4::TDDP4(std::string n, SpinFactors.push_back(SFIT); AmpMap[i->_uniqueDecayStr].second.push_back(SpinFactors.size() - 1); // printf("Adding SF %s\n",(*SFIT)->getName().c_str()); - } } - nPermVec.push_back(i->_nPerm); pindices.push_back(registerParameter(i->_ar)); pindices.push_back(registerParameter(i->_ai)); ++coeff_counter; AmpBuffer.push_back(i); unsigned int flag = 0; - auto inB = std::find_if(AmpsB.begin(), AmpsB.end(), [AmpsA, &i](const Amplitude* A) { - return *i == (*A); - }); + auto inB = std::find_if(AmpsB.begin(), AmpsB.end(), [AmpsA, &i](const Amplitude *A) { return *i == (*A); }); if(inB != AmpsB.end()) { // printf("Found in AmpsB as well: %s\n", (*inB)->_uniqueDecayStr.c_str()); @@ -308,25 +294,22 @@ __host__ TDDP4::TDDP4(std::string n, ampidx.insert(ampidx.end(), sf.begin(), sf.end()); } - - for(auto & i : AmpsB) { - + for(auto &i : AmpsB) { unsigned int flag = 1; - auto inB = std::find_if(AmpBuffer.begin(), AmpBuffer.end(), [AmpsB, &i](const Amplitude* A) { - return *i == (*A); - }); + auto inB + = std::find_if(AmpBuffer.begin(), AmpBuffer.end(), [AmpsB, &i](const Amplitude *A) { return *i == (*A); }); if(inB != AmpBuffer.end()) continue; - AmpMap[i->_uniqueDecayStr] = std::make_pair(std::vector(0), std::vector(0)); + AmpMap[i->_uniqueDecayStr] = std::make_pair(std::vector(0), std::vector(0)); // fprintf("Adding Amplitude B %s\n",AmpsB[i]->_uniqueDecayStr.c_str()); auto LSvec = i->_LS; - for(auto & LSIT : LSvec) { - auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase* L) { - return (*LSIT)== *(dynamic_cast(L)); + for(auto &LSIT : LSvec) { + auto found = std::find_if(components.begin(), components.end(), [&LSIT](const PdfBase *L) { + return (*LSIT) == *(dynamic_cast(L)); }); if(found != components.end()) { @@ -341,14 +324,14 @@ __host__ TDDP4::TDDP4(std::string n, auto SFvec = i->_SF; - for(auto & SFIT : SFvec) { - auto found = std::find_if(SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor* S) { - return (*SFIT) == (*S); - }); + for(auto &SFIT : SFvec) { + auto found = std::find_if( + SpinFactors.begin(), SpinFactors.end(), [&SFIT](const SpinFactor *S) { return (*SFIT) == (*S); }); if(found != SpinFactors.end()) { AmpMap[i->_uniqueDecayStr].second.push_back(std::distance(SpinFactors.begin(), found)); - // fprintf("SF %s found at %i\n",(*found)->getName().c_str(), std::distance(SpinFactors.begin(), found)); + // fprintf("SF %s found at %i\n",(*found)->getName().c_str(), std::distance(SpinFactors.begin(), + // found)); } else { SpinFactors.push_back(SFIT); AmpMap[i->_uniqueDecayStr].second.push_back(SpinFactors.size() - 1); @@ -371,9 +354,12 @@ __host__ TDDP4::TDDP4(std::string n, ampidx.insert(ampidx.end(), sf.begin(), sf.end()); } - - MEMCPY_TO_SYMBOL(AmpIndices, &(ampidxstart[0]), ampidxstart.size()*sizeof(unsigned int), 0, cudaMemcpyHostToDevice); - MEMCPY_TO_SYMBOL(AmpIndices, &(ampidx[0]), ampidx.size()*sizeof(unsigned int), ampidxstart.size()*sizeof(unsigned int), + MEMCPY_TO_SYMBOL( + AmpIndices, &(ampidxstart[0]), ampidxstart.size() * sizeof(unsigned int), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(AmpIndices, + &(ampidx[0]), + ampidx.size() * sizeof(unsigned int), + ampidxstart.size() * sizeof(unsigned int), cudaMemcpyHostToDevice); pindices[2] = components.size(); @@ -381,20 +367,18 @@ __host__ TDDP4::TDDP4(std::string n, pindices[4] = AmpMap.size(); pindices[5] = coeff_counter; - for(auto & component : components) { - reinterpret_cast(component)->setConstantIndex(cIndex); - pindices.push_back(reinterpret_cast(component)->getFunctionIndex()); - pindices.push_back(reinterpret_cast(component)->getParameterIndex()); - + for(auto &component : components) { + reinterpret_cast(component)->setConstantIndex(cIndex); + pindices.push_back(reinterpret_cast(component)->getFunctionIndex()); + pindices.push_back(reinterpret_cast(component)->getParameterIndex()); } - for(auto & SpinFactor : SpinFactors) { + for(auto &SpinFactor : SpinFactors) { pindices.push_back(SpinFactor->getFunctionIndex()); pindices.push_back(SpinFactor->getParameterIndex()); SpinFactor->setConstantIndex(cIndex); } - pindices.push_back(efficiency->getFunctionIndex()); pindices.push_back(efficiency->getParameterIndex()); components.push_back(efficiency); @@ -404,7 +388,7 @@ __host__ TDDP4::TDDP4(std::string n, GET_FUNCTION_ADDR(ptr_to_TDDP4); initialize(pindices); - Integrator = new NormIntegrator_TD(parameters); + Integrator = new NormIntegrator_TD(parameters); redoIntegral = new bool[components.size() - 1]; cachedMasses = new fptype[components.size() - 1]; cachedWidths = new fptype[components.size() - 1]; @@ -414,12 +398,10 @@ __host__ TDDP4::TDDP4(std::string n, cachedMasses[i] = -1; cachedWidths[i] = -1; lscalculators.push_back(new LSCalculator_TD(parameters, i)); - } for(int i = 0; i < SpinFactors.size(); ++i) { sfcalculators.push_back(new SFCalculator_TD(parameters, i)); - } for(int i = 0; i < AmpMap.size(); ++i) { @@ -428,21 +410,21 @@ __host__ TDDP4::TDDP4(std::string n, // fprintf(stderr,"#Amp's %i, #LS %i, #SF %i \n", AmpMap.size(), components.size()-1, SpinFactors.size() ); - std::vector masses(decayInfo->particle_masses.begin()+1, decayInfo->particle_masses.end()); + std::vector masses(decayInfo->particle_masses.begin() + 1, decayInfo->particle_masses.end()); mcbooster::PhaseSpace phsp(decayInfo->particle_masses[0], masses, MCeventsNorm, generation_offset); phsp.Generate(mcbooster::Vector4R(decayInfo->particle_masses[0], 0.0, 0.0, 0.0)); phsp.Unweight(); - auto nAcc = phsp.GetNAccepted(); + auto nAcc = phsp.GetNAccepted(); mcbooster::BoolVector_d flags = phsp.GetAccRejFlags(); - auto d1 = phsp.GetDaughters(0); - auto d2 = phsp.GetDaughters(1); - auto d3 = phsp.GetDaughters(2); - auto d4 = phsp.GetDaughters(3); + auto d1 = phsp.GetDaughters(0); + auto d2 = phsp.GetDaughters(1); + auto d3 = phsp.GetDaughters(2); + auto d4 = phsp.GetDaughters(3); auto zip_begin = thrust::make_zip_iterator(thrust::make_tuple(d1.begin(), d2.begin(), d3.begin(), d4.begin())); - auto zip_end = zip_begin + d1.size(); - auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); + auto zip_end = zip_begin + d1.size(); + auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); d1.erase(thrust::get<0>(new_end.get_iterator_tuple()), d1.end()); d2.erase(thrust::get<1>(new_end.get_iterator_tuple()), d2.end()); @@ -462,8 +444,7 @@ __host__ TDDP4::TDDP4(std::string n, norm_phi = mcbooster::RealVector_d(nAcc); mcbooster::VariableSet_d VarSet(5); - VarSet[0] = &norm_M12, - VarSet[1] = &norm_M34; + VarSet[0] = &norm_M12, VarSet[1] = &norm_M34; VarSet[2] = &norm_CosTheta12; VarSet[3] = &norm_CosTheta34; VarSet[4] = &norm_phi; @@ -471,17 +452,17 @@ __host__ TDDP4::TDDP4(std::string n, Dim5 eval = Dim5(); mcbooster::EvaluateArray(eval, pset, VarSet); - norm_SF = mcbooster::RealVector_d(nAcc * SpinFactors.size()); - norm_LS = mcbooster::mc_device_vector>(nAcc * (components.size() - 1)); + norm_SF = mcbooster::RealVector_d(nAcc * SpinFactors.size()); + norm_LS = mcbooster::mc_device_vector>(nAcc * (components.size() - 1)); MCevents = nAcc; - addSpecialMask(PdfBase::ForceSeparateNorm); } - -// makes the arrays to chache the lineshape values and spinfactors in CachedResSF and the values of the amplitudes in cachedAMPs -// I made the choice to have spinfactors necxt to the values of the lineshape in memory. I waste memory by doing this because a spinfactor is saved as complex +// makes the arrays to chache the lineshape values and spinfactors in CachedResSF and the values of the amplitudes in +// cachedAMPs +// I made the choice to have spinfactors necxt to the values of the lineshape in memory. I waste memory by doing this +// because a spinfactor is saved as complex // It would be nice to test if this is better than having the spinfactors stored seperately. __host__ void TDDP4::setDataSize(unsigned int dataSize, unsigned int evtSize) { // Default 3 is m12, m13, evtNum for DP 2dim, 4-body decay has 5 independent vars plus evtNum = 6 @@ -495,16 +476,22 @@ __host__ void TDDP4::setDataSize(unsigned int dataSize, unsigned int evtSize) { if(cachedAMPs) delete cachedAMPs; - numEntries = dataSize; - cachedResSF = new thrust::device_vector>(dataSize*(components.size() + SpinFactors.size() - - 1)); // -1 because 1 component is efficiency - void* dummy = thrust::raw_pointer_cast(cachedResSF->data()); - MEMCPY_TO_SYMBOL(cResSF_TD, &dummy, sizeof(thrust::complex*), cacheToUse*sizeof(thrust::complex*), + numEntries = dataSize; + cachedResSF = new thrust::device_vector>( + dataSize * (components.size() + SpinFactors.size() - 1)); // -1 because 1 component is efficiency + void *dummy = thrust::raw_pointer_cast(cachedResSF->data()); + MEMCPY_TO_SYMBOL(cResSF_TD, + &dummy, + sizeof(thrust::complex *), + cacheToUse * sizeof(thrust::complex *), cudaMemcpyHostToDevice); - cachedAMPs = new thrust::device_vector>(dataSize*(AmpCalcs.size())); - void* dummy2 = thrust::raw_pointer_cast(cachedAMPs->data()); - MEMCPY_TO_SYMBOL(Amps_TD, &dummy2, sizeof(thrust::complex*), cacheToUse*sizeof(thrust::complex*), + cachedAMPs = new thrust::device_vector>(dataSize * (AmpCalcs.size())); + void *dummy2 = thrust::raw_pointer_cast(cachedAMPs->data()); + MEMCPY_TO_SYMBOL(Amps_TD, + &dummy2, + sizeof(thrust::complex *), + cacheToUse * sizeof(thrust::complex *), cudaMemcpyHostToDevice); setForceIntegrals(); @@ -517,10 +504,10 @@ __host__ fptype TDDP4::normalize() const { // so set normalisation factor to 1 so it doesn't get multiplied by zero. // Copy at this time to ensure that the SpecialResonanceCalculators, which need the efficiency, // don't get zeroes through multiplying by the normFactor. - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); -//check if MINUIT changed any parameters and if so remember that so we know -// we need to recalculate that lineshape and every amp, that uses that lineshape + // check if MINUIT changed any parameters and if so remember that so we know + // we need to recalculate that lineshape and every amp, that uses that lineshape for(unsigned int i = 0; i < components.size() - 1; ++i) { redoIntegral[i] = forceRedoIntegrals; @@ -530,34 +517,39 @@ __host__ fptype TDDP4::normalize() const { redoIntegral[i] = true; } - SpinsCalculated = !forceRedoIntegrals; + SpinsCalculated = !forceRedoIntegrals; forceRedoIntegrals = false; - //just some thrust iterators for the calculation. - thrust::constant_iterator dataArray(dev_event_array); + // just some thrust iterators for the calculation. + thrust::constant_iterator dataArray(dev_event_array); thrust::constant_iterator eventSize(totalEventSize); thrust::counting_iterator eventIndex(0); - //Calculate spinfactors only once for normalisation events and real events - //strided_range is a template implemented in DalitsPlotHelpers.hh - //it basically goes through the array by increasing the pointer by a certain amount instead of just one step. + // Calculate spinfactors only once for normalisation events and real events + // strided_range is a template implemented in DalitsPlotHelpers.hh + // it basically goes through the array by increasing the pointer by a certain amount instead of just one step. if(!SpinsCalculated) { - for(int i = 0; i < SpinFactors.size() ; ++i) { - unsigned int offset = components.size() -1; - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), - strided_range>::iterator>(cachedResSF->begin() + offset + i, - cachedResSF->end(), - (components.size() + SpinFactors.size() - 1)).begin(), - *(sfcalculators[i])); + for(int i = 0; i < SpinFactors.size(); ++i) { + unsigned int offset = components.size() - 1; + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), + strided_range>::iterator>( + cachedResSF->begin() + offset + i, cachedResSF->end(), (components.size() + SpinFactors.size() - 1)) + .begin(), + *(sfcalculators[i])); if(!generation_no_norm) { - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), norm_M34.begin(), - norm_CosTheta12.begin(), norm_CosTheta34.begin(), norm_phi.begin())) - , thrust::make_zip_iterator(thrust::make_tuple(norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), - norm_CosTheta34.end(), norm_phi.end())) - , (norm_SF.begin() + (i * MCevents)) - , NormSpinCalculator_TD(parameters, i)); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), + norm_M34.begin(), + norm_CosTheta12.begin(), + norm_CosTheta34.begin(), + norm_phi.begin())), + thrust::make_zip_iterator(thrust::make_tuple( + norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), norm_CosTheta34.end(), norm_phi.end())), + (norm_SF.begin() + (i * MCevents)), + NormSpinCalculator_TD(parameters, i)); } } @@ -566,23 +558,25 @@ __host__ fptype TDDP4::normalize() const { // fprintf(stderr, "normalize after spins\n"); - // this calculates the values of the lineshapes and stores them in the array. It is recalculated every time parameters change. - for(int i = 0; i < components.size() -1 ; ++i) { + // this calculates the values of the lineshapes and stores them in the array. It is recalculated every time + // parameters change. + for(int i = 0; i < components.size() - 1; ++i) { if(redoIntegral[i]) { - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), - strided_range>::iterator>(cachedResSF->begin() + i, - cachedResSF->end(), - (components.size() + SpinFactors.size() - 1)).begin(), - *(lscalculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, dataArray, eventSize)), + strided_range>::iterator>( + cachedResSF->begin() + i, cachedResSF->end(), (components.size() + SpinFactors.size() - 1)) + .begin(), + *(lscalculators[i])); } } // fprintf(stderr, "normalize after LS\n"); - // this is a little messy but it basically checks if the amplitude includes one of the recalculated lineshapes and if so recalculates that amplitude - auto AmpMapIt = - AmpMap.begin(); + // this is a little messy but it basically checks if the amplitude includes one of the recalculated lineshapes and + // if so recalculates that amplitude + auto AmpMapIt = AmpMap.begin(); for(int i = 0; i < AmpCalcs.size(); ++i) { std::vector redoidx((*AmpMapIt).second.first); @@ -597,9 +591,11 @@ __host__ fptype TDDP4::normalize() const { } if(redo) { - thrust::transform(eventIndex, eventIndex + numEntries, - strided_range>::iterator>(cachedAMPs->begin() + i, - cachedAMPs->end(), AmpCalcs.size()).begin(), + thrust::transform(eventIndex, + eventIndex + numEntries, + strided_range>::iterator>( + cachedAMPs->begin() + i, cachedAMPs->end(), AmpCalcs.size()) + .begin(), *(AmpCalcs[i])); } } @@ -608,75 +604,87 @@ __host__ fptype TDDP4::normalize() const { // lineshape value calculation for the normalisation, also recalculated every time parameter change if(!generation_no_norm) { - for(int i = 0; i < components.size() -1 ; ++i) { + for(int i = 0; i < components.size() - 1; ++i) { if(!redoIntegral[i]) continue; - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), norm_M34.begin(), - norm_CosTheta12.begin(), norm_CosTheta34.begin(), norm_phi.begin())) - , thrust::make_zip_iterator(thrust::make_tuple(norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), - norm_CosTheta34.end(), norm_phi.end())) - , (norm_LS.begin() + (i * MCevents)) - , NormLSCalculator_TD(parameters, i)); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(norm_M12.begin(), + norm_M34.begin(), + norm_CosTheta12.begin(), + norm_CosTheta34.begin(), + norm_phi.begin())), + thrust::make_zip_iterator(thrust::make_tuple( + norm_M12.end(), norm_M34.end(), norm_CosTheta12.end(), norm_CosTheta34.end(), norm_phi.end())), + (norm_LS.begin() + (i * MCevents)), + NormLSCalculator_TD(parameters, i)); } } - thrust::constant_iterator normSFaddress(thrust::raw_pointer_cast(norm_SF.data())); - thrust::constant_iterator* > normLSaddress(thrust::raw_pointer_cast(norm_LS.data())); + thrust::constant_iterator normSFaddress(thrust::raw_pointer_cast(norm_SF.data())); + thrust::constant_iterator *> normLSaddress(thrust::raw_pointer_cast(norm_LS.data())); thrust::constant_iterator NumNormEvents(MCevents); - //this does the rest of the integration with the cached lineshape and spinfactor values for the normalization events + // this does the rest of the integration with the cached lineshape and spinfactor values for the normalization + // events auto ret = 1.0; if(!generation_no_norm) { thrust::tuple dummy(0, 0, 0, 0); FourDblTupleAdd MyFourDoubleTupleAdditionFunctor; thrust::tuple sumIntegral; - sumIntegral = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, NumNormEvents, - normSFaddress, normLSaddress)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + MCevents, NumNormEvents, normSFaddress, normLSaddress)), - *Integrator, - dummy, - MyFourDoubleTupleAdditionFunctor); - - // printf("normalize A2/#evts , B2/#evts: %.5g, %.5g\n",thrust::get<0>(sumIntegral)/MCevents, thrust::get<1>(sumIntegral)/MCevents); + sumIntegral = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, NumNormEvents, normSFaddress, normLSaddress)), + thrust::make_zip_iterator( + thrust::make_tuple(eventIndex + MCevents, NumNormEvents, normSFaddress, normLSaddress)), + *Integrator, + dummy, + MyFourDoubleTupleAdditionFunctor); + + // printf("normalize A2/#evts , B2/#evts: %.5g, %.5g\n",thrust::get<0>(sumIntegral)/MCevents, + // thrust::get<1>(sumIntegral)/MCevents); fptype tau = host_params[host_indices[parameters + 7]]; fptype xmixing = host_params[host_indices[parameters + 8]]; fptype ymixing = host_params[host_indices[parameters + 9]]; - ret = resolution->normalisation(thrust::get<0>(sumIntegral), thrust::get<1>(sumIntegral), thrust::get<2>(sumIntegral), - thrust::get<3>(sumIntegral), tau, xmixing, ymixing); + ret = resolution->normalisation(thrust::get<0>(sumIntegral), + thrust::get<1>(sumIntegral), + thrust::get<2>(sumIntegral), + thrust::get<3>(sumIntegral), + tau, + xmixing, + ymixing); - //MCevents is the number of normalisation events. - ret/=MCevents; + // MCevents is the number of normalisation events. + ret /= MCevents; } - host_normalisation[parameters] = 1.0/ret; + host_normalisation[parameters] = 1.0 / ret; // printf("end of normalize %f\n", ret); return ret; } -__host__ std::tuple -TDDP4::GenerateSig(unsigned int numEvents) { - +__host__ + std::tuple + TDDP4::GenerateSig(unsigned int numEvents) { copyParams(); - std::vector masses(decayInfo->particle_masses.begin()+1, decayInfo->particle_masses.end()); + std::vector masses(decayInfo->particle_masses.begin() + 1, decayInfo->particle_masses.end()); mcbooster::PhaseSpace phsp(decayInfo->particle_masses[0], masses, numEvents, generation_offset); phsp.Generate(mcbooster::Vector4R(decayInfo->particle_masses[0], 0.0, 0.0, 0.0)); phsp.Unweight(); - auto nAcc = phsp.GetNAccepted(); + auto nAcc = phsp.GetNAccepted(); mcbooster::BoolVector_d flags = phsp.GetAccRejFlags(); - auto d1 = phsp.GetDaughters(0); - auto d2 = phsp.GetDaughters(1); - auto d3 = phsp.GetDaughters(2); - auto d4 = phsp.GetDaughters(3); + auto d1 = phsp.GetDaughters(0); + auto d2 = phsp.GetDaughters(1); + auto d3 = phsp.GetDaughters(2); + auto d4 = phsp.GetDaughters(3); auto zip_begin = thrust::make_zip_iterator(thrust::make_tuple(d1.begin(), d2.begin(), d3.begin(), d4.begin())); - auto zip_end = zip_begin + d1.size(); - auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); + auto zip_end = zip_begin + d1.size(); + auto new_end = thrust::remove_if(zip_begin, zip_end, flags.begin(), thrust::logical_not()); flags = mcbooster::BoolVector_d(); @@ -700,20 +708,16 @@ TDDP4::GenerateSig(unsigned int numEvents) { thrust::counting_iterator index_sequence_begin(0); - fptype tau = host_params[host_indices[parameters + 7]]; - fptype ymixing = host_params[host_indices[parameters + 9]]; - fptype gammamin = 1.0/tau - fabs(ymixing)/tau; + fptype tau = host_params[host_indices[parameters + 7]]; + fptype ymixing = host_params[host_indices[parameters + 9]]; + fptype gammamin = 1.0 / tau - fabs(ymixing) / tau; /*printf("hostparams: %f, %f", tau, ymixing);*/ - thrust::transform(index_sequence_begin, - index_sequence_begin + nAcc, - dtime_d.begin(), - genExp(generation_offset, gammamin)); - + thrust::transform( + index_sequence_begin, index_sequence_begin + nAcc, dtime_d.begin(), genExp(generation_offset, gammamin)); mcbooster::VariableSet_d VarSet_d(5); - VarSet_d[0] = &SigGen_M12_d, - VarSet_d[1] = &SigGen_M34_d; + VarSet_d[0] = &SigGen_M12_d, VarSet_d[1] = &SigGen_M34_d; VarSet_d[2] = &SigGen_CosTheta12_d; VarSet_d[3] = &SigGen_CosTheta34_d; VarSet_d[4] = &SigGen_phi_d; @@ -749,7 +753,7 @@ TDDP4::GenerateSig(unsigned int numEvents) { phsp.~PhaseSpace(); - auto DS = new mcbooster::RealVector_d(8*nAcc); + auto DS = new mcbooster::RealVector_d(8 * nAcc); thrust::counting_iterator eventNumber(0); #pragma unroll @@ -760,25 +764,23 @@ TDDP4::GenerateSig(unsigned int numEvents) { } mcbooster::strided_range sr(DS->begin() + 5, DS->end(), 8); - thrust::copy(eventNumber, eventNumber+nAcc, sr.begin()); - + thrust::copy(eventNumber, eventNumber + nAcc, sr.begin()); mcbooster::strided_range sr2(DS->begin() + 6, DS->end(), 8); - thrust::fill_n(sr2.begin(), nAcc, 0); + thrust::fill_n(sr2.begin(), nAcc, 0); dev_event_array = thrust::raw_pointer_cast(DS->data()); setDataSize(nAcc, 8); - - generation_no_norm=true; // we need no normalization for generation, but we do need to make sure that norm = 1; + generation_no_norm = true; // we need no normalization for generation, but we do need to make sure that norm = 1; SigGenSetIndices(); normalize(); setForceIntegrals(); - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); thrust::device_vector weights(nAcc); thrust::constant_iterator eventSize(8); - thrust::constant_iterator arrayAddress(dev_event_array); + thrust::constant_iterator arrayAddress(dev_event_array); thrust::counting_iterator eventIndex(0); MetricTaker evalor(this, getMetricPointer("ptr_to_Prob")); @@ -788,12 +790,15 @@ TDDP4::GenerateSig(unsigned int numEvents) { evalor); cudaDeviceSynchronize(); - fptype wmax = 1.1 * (fptype) *thrust::max_element(weights.begin(), weights.end()); + fptype wmax = 1.1 * (fptype)*thrust::max_element(weights.begin(), weights.end()); if(wmax > maxWeight && maxWeight != 0) - fprintf(stderr, "WARNING: you just encountered a higher maximum weight than observed in previous iterations.\n" + fprintf(stderr, + "WARNING: you just encountered a higher maximum weight than observed in previous iterations.\n" "WARNING: Consider recalculating your AccRej flags and acceping based upon these.\n" - "WARNING: previous weight: %.4g, new weight: %.4g\n", maxWeight, wmax); + "WARNING: previous weight: %.4g, new weight: %.4g\n", + maxWeight, + wmax); maxWeight = wmax > maxWeight ? wmax : maxWeight; @@ -811,18 +816,19 @@ TDDP4::GenerateSig(unsigned int numEvents) { thrust::device_vector flag2(nAcc); thrust::counting_iterator first(0); - //thrust::counting_iterator last = first + nAcc; + // thrust::counting_iterator last = first + nAcc; // we do not want to copy the whole class to the GPU so capturing *this is not a great option // therefore perpare local copies to capture the variables we need - unsigned int tmpoff = generation_offset; + unsigned int tmpoff = generation_offset; unsigned int tmpparam = parameters; - wmax = maxWeight; + wmax = maxWeight; - thrust::transform(thrust::make_zip_iterator( thrust::make_tuple(eventIndex, results.begin(), arrayAddress, eventSize) ), - thrust::make_zip_iterator( thrust::make_tuple(eventIndex + nAcc, results.end(), arrayAddress, eventSize ) ), - flag2.begin(), - exp_functor(tmpparam, tmpoff, gammamin, wmax)); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, results.begin(), arrayAddress, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + nAcc, results.end(), arrayAddress, eventSize)), + flag2.begin(), + exp_functor(tmpparam, tmpoff, gammamin, wmax)); gooFree(dev_event_array); @@ -830,7 +836,7 @@ TDDP4::GenerateSig(unsigned int numEvents) { auto weights_h = mcbooster::RealVector_h(weights); auto results_h = mcbooster::RealVector_h(results); - auto flags_h = mcbooster::BoolVector_h(flag2); + auto flags_h = mcbooster::BoolVector_h(flag2); cudaDeviceSynchronize(); return std::make_tuple(ParSet, VarSet, weights_h, flags_h); @@ -838,25 +844,23 @@ TDDP4::GenerateSig(unsigned int numEvents) { SFCalculator_TD::SFCalculator_TD(int pIdx, unsigned int sf_idx) : _spinfactor_i(sf_idx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} -__device__ thrust::complex SFCalculator_TD::operator()(thrust::tuple t) const { +__device__ thrust::complex SFCalculator_TD::operator()(thrust::tuple t) const { + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 12 + (2 * indices[6]) + (indices[3] * 2) + (_spinfactor_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i = 12 + (2 * indices[6]) + (indices[3] * 2) + + (_spinfactor_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; + unsigned int params_i = indices[parameter_i + 1]; - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m34 = evt[indices[3 + indices[0]]]; + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m34 = evt[indices[3 + indices[0]]]; fptype cos12 = evt[indices[4 + indices[0]]]; fptype cos34 = evt[indices[5 + indices[0]]]; - fptype phi = evt[indices[6 + indices[0]]]; + fptype phi = evt[indices[6 + indices[0]]]; fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); @@ -867,42 +871,40 @@ __device__ thrust::complex SFCalculator_TD::operator()(thrust::tuple(device_function_table[functn_i]); - fptype sf = (*func)(vecs, paramIndices+params_i); + fptype sf = (*func)(vecs, paramIndices + params_i); // printf("SpinFactors %i : %.7g\n",_spinfactor_i, sf ); return thrust::complex(sf, 0); } NormSpinCalculator_TD::NormSpinCalculator_TD(int pIdx, unsigned int sf_idx) : _spinfactor_i(sf_idx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} __device__ fptype NormSpinCalculator_TD::operator()( thrust::tuple t) -const { - - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 12 + (2 * indices[6]) + (indices[3] * 2) + (_spinfactor_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + const { + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i = 12 + (2 * indices[6]) + (indices[3] * 2) + + (_spinfactor_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; + unsigned int params_i = indices[parameter_i + 1]; - fptype m12 = (thrust::get<0>(t)); - fptype m34 = (thrust::get<1>(t)); - fptype cos12 = (thrust::get<2>(t)); - fptype cos34 = (thrust::get<3>(t)); - fptype phi = (thrust::get<4>(t)); + fptype m12 = (thrust::get<0>(t)); + fptype m34 = (thrust::get<1>(t)); + fptype cos12 = (thrust::get<2>(t)); + fptype cos34 = (thrust::get<3>(t)); + fptype phi = (thrust::get<4>(t)); fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,0, vecs[0], vecs[1], vecs[2], vecs[3]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,1, vecs[4], vecs[5], vecs[6], vecs[7]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,2, vecs[8], vecs[9], vecs[10], vecs[11]); -// printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,3, vecs[12], vecs[13], vecs[14], vecs[15]); -// // } + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,0, vecs[0], vecs[1], vecs[2], vecs[3]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,1, vecs[4], vecs[5], vecs[6], vecs[7]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,2, vecs[8], vecs[9], vecs[10], vecs[11]); + // printf("evt %i vec%i %.5g, %.5g, %.5g, %.5g\n", evtNum,3, vecs[12], vecs[13], vecs[14], vecs[15]); + // // } auto func = reinterpret_cast(device_function_table[functn_i]); - fptype sf = (*func)(vecs, paramIndices+params_i); + fptype sf = (*func)(vecs, paramIndices + params_i); // printf("NormSF evt:%.5g, %.5g, %.5g, %.5g, %.5g\n", m12, m34, cos12, cos34, phi); // printf("NormSF %i, %.7g\n",_spinfactor_i, sf ); @@ -910,59 +912,55 @@ const { return sf; } - - LSCalculator_TD::LSCalculator_TD(int pIdx, unsigned int res_idx) : _resonance_i(res_idx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} -__device__ thrust::complex LSCalculator_TD::operator()(thrust::tuple t) const { +__device__ thrust::complex LSCalculator_TD::operator()(thrust::tuple t) const { // Calculates the BW values for a specific resonance. thrust::complex ret; - int evtNum = thrust::get<0>(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 12 + (2 * indices[6]) + (_resonance_i * 2) - ; // Find position of this resonance relative to DALITZPLOT start + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i + = 12 + (2 * indices[6]) + (_resonance_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; - unsigned int pair = (paramIndices+params_i)[5]; + unsigned int params_i = indices[parameter_i + 1]; + unsigned int pair = (paramIndices + params_i)[5]; - fptype m1 = functorConstants[indices[1] + 2]; - fptype m2 = functorConstants[indices[1] + 3]; - fptype m3 = functorConstants[indices[1] + 4]; - fptype m4 = functorConstants[indices[1] + 5]; + fptype m1 = functorConstants[indices[1] + 2]; + fptype m2 = functorConstants[indices[1] + 3]; + fptype m3 = functorConstants[indices[1] + 4]; + fptype m4 = functorConstants[indices[1] + 5]; - fptype m12 = evt[indices[2 + indices[0]]]; - fptype m34 = evt[indices[3 + indices[0]]]; + fptype m12 = evt[indices[2 + indices[0]]]; + fptype m34 = evt[indices[3 + indices[0]]]; fptype cos12 = evt[indices[4 + indices[0]]]; fptype cos34 = evt[indices[5 + indices[0]]]; - fptype phi = evt[indices[6 + indices[0]]]; + fptype phi = evt[indices[6 + indices[0]]]; if(pair < 2) { - fptype mres = pair==0 ? m12 : m34; - fptype d1 = pair==0 ? m1 : m3; - fptype d2 = pair==0 ? m2 : m4; - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + fptype mres = pair == 0 ? m12 : m34; + fptype d1 = pair == 0 ? m1 : m3; + fptype d2 = pair == 0 ? m2 : m4; + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); // printf("LS_nt %i: mass:%f, %f i%f\n",_resonance_i, mres, ret.real, ret.imag ); } else { fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); fptype d1, d2; fptype mres = getmass(pair, d1, d2, vecs, m1, m2, m3, m4); - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); // printf("LS %i: mass:%f, %f i%f\n",_resonance_i, mres, ret.real, ret.imag ); - } // printf("LS %i: %.7g, %.7g, %.7g, %.7g, %.7g \n",evtNum, m12, m34, cos12, cos34, phi ); - //if (!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; - //printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); - //printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); + // if (!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; + // printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); + // printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); // printf("BW_%i : %f %f\n", _resonance_i, ret.real, ret.imag); return ret; @@ -970,53 +968,51 @@ __device__ thrust::complex LSCalculator_TD::operator()(thrust::tuple NormLSCalculator_TD::operator()( thrust::tuple t) -const { + const { // Calculates the BW values for a specific resonance. thrust::complex ret; - unsigned int* indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array - int parameter_i = 12 + (2 * indices[6]) + (_resonance_i * - 2); // Find position of this resonance relative to DALITZPLOT start + unsigned int *indices = paramIndices + _parameters; // Jump to DALITZPLOT position within parameters array + int parameter_i + = 12 + (2 * indices[6]) + (_resonance_i * 2); // Find position of this resonance relative to DALITZPLOT start unsigned int functn_i = indices[parameter_i]; - unsigned int params_i = indices[parameter_i+1]; - unsigned int pair = (paramIndices+params_i)[5]; - - fptype m1 = functorConstants[indices[1] + 2]; - fptype m2 = functorConstants[indices[1] + 3]; - fptype m3 = functorConstants[indices[1] + 4]; - fptype m4 = functorConstants[indices[1] + 5]; + unsigned int params_i = indices[parameter_i + 1]; + unsigned int pair = (paramIndices + params_i)[5]; - fptype m12 = (thrust::get<0>(t)); - fptype m34 = (thrust::get<1>(t)); - fptype cos12 = (thrust::get<2>(t)); - fptype cos34 = (thrust::get<3>(t)); - fptype phi = (thrust::get<4>(t)); + fptype m1 = functorConstants[indices[1] + 2]; + fptype m2 = functorConstants[indices[1] + 3]; + fptype m3 = functorConstants[indices[1] + 4]; + fptype m4 = functorConstants[indices[1] + 5]; + fptype m12 = (thrust::get<0>(t)); + fptype m34 = (thrust::get<1>(t)); + fptype cos12 = (thrust::get<2>(t)); + fptype cos34 = (thrust::get<3>(t)); + fptype phi = (thrust::get<4>(t)); if(pair < 2) { - fptype mres = pair==0 ? m12 : m34; - fptype d1 = pair==0 ? m1 : m3; - fptype d2 = pair==0 ? m2 : m4; - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + fptype mres = pair == 0 ? m12 : m34; + fptype d1 = pair == 0 ? m1 : m3; + fptype d2 = pair == 0 ? m2 : m4; + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); } else { fptype vecs[16]; get4Vecs(vecs, indices[1], m12, m34, cos12, cos34, phi); fptype d1, d2; fptype mres = getmass(pair, d1, d2, vecs, m1, m2, m3, m4); - ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); + ret = getResonanceAmplitude(mres, d1, d2, functn_i, params_i); } // printf("NormLS %f, %f, %f, %f, %f \n",m12, m34, cos12, cos34, phi ); // printf("%i, %i, %i, %i, %i \n",numLS, numSF, numAmps, offset, evtNum ); // printf("NLS %i, %f, %f\n",_resonance_i,ret.real, ret.imag); - //printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); - //printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); + // printf("m12 %f \n", m12); // %f %f %f (%f, %f)\n ", m12, m13, m23, ret.real, ret.imag); + // printf("#Parameters %i, #LS %i, #SF %i, #AMP %i \n", indices[0], indices[3], indices[4], indices[5]); // THREAD_SYNCH return ret; } @@ -1024,41 +1020,39 @@ const { AmpCalc_TD::AmpCalc_TD(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm) : _nPerm(nPerm) , _AmpIdx(AmpIdx) - , _parameters(pIdx) -{} + , _parameters(pIdx) {} - -__device__ thrust::complex AmpCalc_TD::operator()(thrust::tuple t) const { - unsigned int* indices = paramIndices + _parameters; +__device__ thrust::complex AmpCalc_TD::operator()(thrust::tuple t) const { + unsigned int *indices = paramIndices + _parameters; unsigned int cacheToUse = indices[2]; - unsigned int totalLS = indices[3]; - unsigned int totalSF = indices[4]; - unsigned int totalAMP = indices[5]; - unsigned int offset = totalLS + totalSF; - unsigned int numLS = AmpIndices[totalAMP + _AmpIdx]; - unsigned int numSF = AmpIndices[totalAMP + _AmpIdx + 1]; - unsigned int evtNum = thrust::get<0>(t); - - + unsigned int totalLS = indices[3]; + unsigned int totalSF = indices[4]; + unsigned int totalAMP = indices[5]; + unsigned int offset = totalLS + totalSF; + unsigned int numLS = AmpIndices[totalAMP + _AmpIdx]; + unsigned int numSF = AmpIndices[totalAMP + _AmpIdx + 1]; + unsigned int evtNum = thrust::get<0>(t); thrust::complex returnVal(0, 0); - unsigned int SF_step = numSF/_nPerm; - unsigned int LS_step = numLS/_nPerm; + unsigned int SF_step = numSF / _nPerm; + unsigned int LS_step = numLS / _nPerm; for(int i = 0; i < _nPerm; ++i) { thrust::complex ret(1, 0); - for(int j = i*LS_step; j < (i+1)*LS_step; ++j) { - ret *= (cResSF_TD[cacheToUse][evtNum*offset + AmpIndices[totalAMP + _AmpIdx + 4 + j]]); - // printf("Lineshape %i = (%.7g, %.7g)\n", j, (cResSF_TD[cacheToUse][evtNum*offset + AmpIndices[totalAMP + _AmpIdx + 4 + j]]).real, (cResSF_TD[cacheToUse][evtNum*offset + AmpIndices[totalAMP + _AmpIdx + 4 + j]]).imag); - + for(int j = i * LS_step; j < (i + 1) * LS_step; ++j) { + ret *= (cResSF_TD[cacheToUse][evtNum * offset + AmpIndices[totalAMP + _AmpIdx + 4 + j]]); + // printf("Lineshape %i = (%.7g, %.7g)\n", j, (cResSF_TD[cacheToUse][evtNum*offset + AmpIndices[totalAMP + + // _AmpIdx + 4 + j]]).real, (cResSF_TD[cacheToUse][evtNum*offset + AmpIndices[totalAMP + _AmpIdx + 4 + + // j]]).imag); } // printf("Lineshape Product = (%.7g, %.7g)\n", ret.real, ret.imag); - for(int j = i*SF_step; j < (i+1)*SF_step; ++j) { - ret *= (cResSF_TD[cacheToUse][evtNum*offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 4 + numLS + j]].real()); - // printf(" SF = %.7g\n", (cResSF_TD[cacheToUse][evtNum*offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 4 + numLS + j]].real)); - + for(int j = i * SF_step; j < (i + 1) * SF_step; ++j) { + ret *= (cResSF_TD[cacheToUse][evtNum * offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 4 + numLS + j]] + .real()); + // printf(" SF = %.7g\n", (cResSF_TD[cacheToUse][evtNum*offset + totalLS + AmpIndices[totalAMP + _AmpIdx + 4 + // + numLS + j]].real)); } // printf("Lineshape Product * SF = (%.7g, %.7g)\n", ret.real, ret.imag); @@ -1066,26 +1060,23 @@ __device__ thrust::complex AmpCalc_TD::operator()(thrust::tuple(_nPerm))); + returnVal *= (1 / sqrt(static_cast(_nPerm))); // printf("Amplitude Value = (%.7g, %.7g)\n", returnVal.real, returnVal.imag); - return returnVal; + return returnVal; } - NormIntegrator_TD::NormIntegrator_TD(unsigned int pIdx) - : _parameters(pIdx) -{} - + : _parameters(pIdx) {} -__device__ thrust::tuple NormIntegrator_TD::operator()( - thrust::tuple*> t) const { - unsigned int* indices = paramIndices + _parameters; +__device__ thrust::tuple NormIntegrator_TD:: +operator()(thrust::tuple *> t) const { + unsigned int *indices = paramIndices + _parameters; unsigned int totalAMP = indices[5]; - unsigned int evtNum = thrust::get<0>(t); - unsigned int MCevents = thrust::get<1>(t); - fptype* SFnorm = thrust::get<2>(t) + evtNum; - thrust::complex* LSnorm = thrust::get<3>(t) + evtNum; + unsigned int evtNum = thrust::get<0>(t); + unsigned int MCevents = thrust::get<1>(t); + fptype *SFnorm = thrust::get<2>(t) + evtNum; + thrust::complex *LSnorm = thrust::get<3>(t) + evtNum; thrust::complex AmpA(0, 0); thrust::complex AmpB(0, 0); @@ -1094,55 +1085,60 @@ __device__ thrust::tuple NormIntegrator_TD::oper int k = 0; for(int amp = 0; amp < totalAMP; ++amp) { - unsigned int ampidx = AmpIndices[amp]; - unsigned int numLS = AmpIndices[totalAMP + ampidx]; - unsigned int numSF = AmpIndices[totalAMP + ampidx + 1]; - unsigned int nPerm = AmpIndices[totalAMP + ampidx + 2]; - unsigned int flag = AmpIndices[totalAMP + ampidx + 3]; - unsigned int SF_step = numSF/nPerm; - unsigned int LS_step = numLS/nPerm; + unsigned int ampidx = AmpIndices[amp]; + unsigned int numLS = AmpIndices[totalAMP + ampidx]; + unsigned int numSF = AmpIndices[totalAMP + ampidx + 1]; + unsigned int nPerm = AmpIndices[totalAMP + ampidx + 2]; + unsigned int flag = AmpIndices[totalAMP + ampidx + 3]; + unsigned int SF_step = numSF / nPerm; + unsigned int LS_step = numLS / nPerm; thrust::complex ret2(0, 0); - // printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %f\n",ampidx, amp, numLS, numSF, nPerm,AmpIndices[totalAMP + ampidx + 4 + 0], AmpIndices[totalAMP + ampidx + 4 + 1], AmpIndices[totalAMP + ampidx + 4 + 2], AmpIndices[totalAMP + ampidx + 4 + 3], (1/sqrt((fptype)(nPerm))) ); + // printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %f\n",ampidx, amp, numLS, numSF, nPerm,AmpIndices[totalAMP + + // ampidx + 4 + 0], AmpIndices[totalAMP + ampidx + 4 + 1], AmpIndices[totalAMP + ampidx + 4 + 2], + // AmpIndices[totalAMP + ampidx + 4 + 3], (1/sqrt((fptype)(nPerm))) ); for(int j = 0; j < nPerm; ++j) { thrust::complex ret(1, 0); - for(int i = j*LS_step; i < (j+1)*LS_step; ++i) { + for(int i = j * LS_step; i < (j + 1) * LS_step; ++i) { thrust::complex matrixelement(LSnorm[AmpIndices[totalAMP + ampidx + 4 + i] * MCevents]); - // printf("Norm BW %i, %.5g, %.5g\n",AmpIndices[totalAMP + ampidx + 4 + i] , matrixelement.real, matrixelement.imag); + // printf("Norm BW %i, %.5g, %.5g\n",AmpIndices[totalAMP + ampidx + 4 + i] , matrixelement.real, + // matrixelement.imag); ret *= matrixelement; - } - for(int i = j*SF_step; i < (j+1)*SF_step; ++i) { + for(int i = j * SF_step; i < (j + 1) * SF_step; ++i) { fptype matrixelement = (SFnorm[AmpIndices[totalAMP + ampidx + 4 + numLS + i] * MCevents]); // printf("Norm SF %i, %.5g\n",AmpIndices[totalAMP + ampidx + 4 + i] , matrixelement); ret *= matrixelement; - } ret2 += ret; } - ret2 *= (1/sqrt(static_cast(nPerm))); + ret2 *= (1 / sqrt(static_cast(nPerm))); // printf("Result Amplitude %i, %i, %.5g, %.5g\n",flag, amp, ret2.real, ret2.imag); switch(flag) { case 0: - amp_A = thrust::complex(cudaArray[indices[12 + 2*(amp+k)]], cudaArray[indices[13 + 2*(amp+k)]]); + amp_A = thrust::complex(cudaArray[indices[12 + 2 * (amp + k)]], + cudaArray[indices[13 + 2 * (amp + k)]]); AmpA += ret2 * amp_A; break; case 1: - amp_B = thrust::complex(cudaArray[indices[12 + 2*(amp+k)]], cudaArray[indices[13 + 2*(amp+k)]]); + amp_B = thrust::complex(cudaArray[indices[12 + 2 * (amp + k)]], + cudaArray[indices[13 + 2 * (amp + k)]]); AmpB += ret2 * amp_B; break; case 2: - amp_A = thrust::complex(cudaArray[indices[12 + 2*(amp+k)]], cudaArray[indices[13 + 2*(amp+k)]]); + amp_A = thrust::complex(cudaArray[indices[12 + 2 * (amp + k)]], + cudaArray[indices[13 + 2 * (amp + k)]]); AmpA += ret2 * amp_A; ++k; - amp_B = thrust::complex(cudaArray[indices[12 + 2*(amp+k)]], cudaArray[indices[13 + 2*(amp+k)]]); + amp_B = thrust::complex(cudaArray[indices[12 + 2 * (amp + k)]], + cudaArray[indices[13 + 2 * (amp + k)]]); AmpB += ret2 * amp_B; break; } @@ -1151,9 +1147,9 @@ __device__ thrust::tuple NormIntegrator_TD::oper fptype _SqWStoRSrate = cudaArray[indices[10]]; AmpA *= _SqWStoRSrate; - auto AmpAB = AmpA*conj(AmpB); - return thrust::tuple(thrust::norm(AmpA), thrust::norm(AmpB), AmpAB.real(), AmpAB.imag()); + auto AmpAB = AmpA * conj(AmpB); + return thrust::tuple( + thrust::norm(AmpA), thrust::norm(AmpB), AmpAB.real(), AmpAB.imag()); } } // namespace GooFit - diff --git a/src/PDFs/TddpPdf.cu b/src/PDFs/TddpPdf.cu index c9615ddfc..1f612af3d 100644 --- a/src/PDFs/TddpPdf.cu +++ b/src/PDFs/TddpPdf.cu @@ -21,12 +21,14 @@ const unsigned int SPECIAL_RESOLUTION_FLAG = 999999999; // changes. Note that in a multithread environment each thread needs its // own cache, hence the '10'. Ten threads should be enough for anyone! -//NOTE: only one set of wave holders is supported currently. -__device__ WaveHolder_s* cWaves[16]; +// NOTE: only one set of wave holders is supported currently. +__device__ WaveHolder_s *cWaves[16]; /* -__device__ bool inDalitz (const fptype &m12, const fptype &m13, const fptype &bigM, const fptype &dm1, const fptype &dm2, const fptype &dm3) { - if (m12 < pow(dm1 + dm2, 2)) return false; // This m12 cannot exist, it's less than the square of the (1,2) particle mass. +__device__ bool inDalitz (const fptype &m12, const fptype &m13, const fptype &bigM, const fptype &dm1, const fptype +&dm2, const fptype &dm3) { + if (m12 < pow(dm1 + dm2, 2)) return false; // This m12 cannot exist, it's less than the square of the (1,2) particle +mass. if (m12 > pow(bigM - dm3, 2)) return false; // This doesn't work either, there's no room for an at-rest 3 daughter. // Calculate energies of 1 and 3 particles in m12 rest frame. @@ -43,57 +45,57 @@ __device__ bool inDalitz (const fptype &m12, const fptype &m13, const fptype &bi } */ -__device__ bool inDalitz(const fptype& m12, const fptype& m13, const fptype& bigM, const fptype& dm1, - const fptype& dm2, const fptype& dm3) { - fptype dm1pdm2 = dm1 + dm2; +__device__ bool inDalitz( + const fptype &m12, const fptype &m13, const fptype &bigM, const fptype &dm1, const fptype &dm2, const fptype &dm3) { + fptype dm1pdm2 = dm1 + dm2; fptype bigMmdm3 = bigM - dm3; - bool m12less = (m12 < dm1pdm2*dm1pdm2) ? false : true; - //if (m12 < dm1pdm2*dm1pdm2) return false; // This m12 cannot exist, it's less than the square of the (1,2) particle mass. - bool m12grea = (m12 > bigMmdm3*bigMmdm3) ? false : true; - //if (m12 > bigMmdm3*bigMmdm3) return false; // This doesn't work either, there's no room for an at-rest 3 daughter. + bool m12less = (m12 < dm1pdm2 * dm1pdm2) ? false : true; + // if (m12 < dm1pdm2*dm1pdm2) return false; // This m12 cannot exist, it's less than the square of the (1,2) + // particle mass. + bool m12grea = (m12 > bigMmdm3 * bigMmdm3) ? false : true; + // if (m12 > bigMmdm3*bigMmdm3) return false; // This doesn't work either, there's no room for an at-rest 3 + // daughter. fptype sqrtM12 = sqrt(m12); - fptype dm11 = dm1*dm1; - fptype dm22 = dm2*dm2; - fptype dm33 = dm3*dm3; + fptype dm11 = dm1 * dm1; + fptype dm22 = dm2 * dm2; + fptype dm33 = dm3 * dm3; // Calculate energies of 1 and 3 particles in m12 rest frame. - //fptype e1star = 0.5 * (m12 - dm2*dm2 + dm1*dm1) / sqrt(m12); + // fptype e1star = 0.5 * (m12 - dm2*dm2 + dm1*dm1) / sqrt(m12); fptype e1star = 0.5 * (m12 - dm22 + dm11) / sqrtM12; - //fptype e3star = 0.5 * (bigM*bigM - m12 - dm3*dm3) / sqrt(m12); - fptype e3star = 0.5 * (bigM*bigM - m12 - dm33) / sqrtM12; + // fptype e3star = 0.5 * (bigM*bigM - m12 - dm3*dm3) / sqrt(m12); + fptype e3star = 0.5 * (bigM * bigM - m12 - dm33) / sqrtM12; - fptype rte1mdm11 = sqrt(e1star*e1star - dm11); - fptype rte3mdm33 = sqrt(e3star*e3star - dm33); + fptype rte1mdm11 = sqrt(e1star * e1star - dm11); + fptype rte3mdm33 = sqrt(e3star * e3star - dm33); // Bounds for m13 at this value of m12. - //fptype minimum = (e1star + e3star)*(e1star + e3star) - pow(sqrt(e1star1 - dm11) + sqrt(e3star*e3star - dm33), 2); - fptype minimum = (e1star + e3star)*(e1star + e3star) - (rte1mdm11 + rte3mdm33)*(rte1mdm11 + rte3mdm33); + // fptype minimum = (e1star + e3star)*(e1star + e3star) - pow(sqrt(e1star1 - dm11) + sqrt(e3star*e3star - dm33), 2); + fptype minimum = (e1star + e3star) * (e1star + e3star) - (rte1mdm11 + rte3mdm33) * (rte1mdm11 + rte3mdm33); bool m13less = (m13 < minimum) ? false : true; - //if (m13 < minimum) return false; + // if (m13 < minimum) return false; - //fptype maximum = pow(e1star + e3star, 2) - pow(sqrt(e1star*e1star - dm1*dm1) - sqrt(e3star*e3star - dm3*dm3), 2); - fptype maximum = (e1star + e3star)*(e1star + e3star) - (rte1mdm11 - rte3mdm33)*(rte1mdm11 - rte3mdm33); - bool m13grea = (m13 > maximum) ? false : true; - //if (m13 > maximum) return false; + // fptype maximum = pow(e1star + e3star, 2) - pow(sqrt(e1star*e1star - dm1*dm1) - sqrt(e3star*e3star - dm3*dm3), 2); + fptype maximum = (e1star + e3star) * (e1star + e3star) - (rte1mdm11 - rte3mdm33) * (rte1mdm11 - rte3mdm33); + bool m13grea = (m13 > maximum) ? false : true; + // if (m13 > maximum) return false; return m12less && m12grea && m13less && m13grea; } -__device__ inline int parIndexFromResIndex(int resIndex) { - return resonanceOffset + resIndex*resonanceSize; -} +__device__ inline int parIndexFromResIndex(int resIndex) { return resonanceOffset + resIndex * resonanceSize; } -__device__ thrust::complex getResonanceAmplitude(fptype m12, fptype m13, fptype m23, - unsigned int functionIdx, unsigned int pIndex) { +__device__ thrust::complex +getResonanceAmplitude(fptype m12, fptype m13, fptype m23, unsigned int functionIdx, unsigned int pIndex) { auto func = reinterpret_cast(device_function_table[functionIdx]); return (*func)(m12, m13, m23, paramIndices + pIndex); } -__device__ ThreeComplex device_Tddp_calcIntegrals(fptype m12, fptype m13, int res_i, int res_j, fptype* p, - unsigned int* indices) { +__device__ ThreeComplex +device_Tddp_calcIntegrals(fptype m12, fptype m13, int res_i, int res_j, fptype *p, unsigned int *indices) { // For calculating Dalitz-plot integrals. What's needed is the products // AiAj*, AiBj*, and BiBj*, where // Ai = BW_i(x, y) + BW_i(y, x) @@ -116,28 +118,30 @@ __device__ ThreeComplex device_Tddp_calcIntegrals(fptype m12, fptype m13, int re if(!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return ret; - fptype m23 = motherMass*motherMass + daug1Mass*daug1Mass + daug2Mass*daug2Mass + daug3Mass*daug3Mass - m12 - m13; + fptype m23 + = motherMass * motherMass + daug1Mass * daug1Mass + daug2Mass * daug2Mass + daug3Mass * daug3Mass - m12 - m13; int parameter_i = parIndexFromResIndex(res_i); int parameter_j = parIndexFromResIndex(res_j); - //fptype amp_real = p[indices[parameter_i+0]]; - //fptype amp_imag = p[indices[parameter_i+1]]; - unsigned int functn_i = RO_CACHE(indices[parameter_i+2]); - unsigned int params_i = RO_CACHE(indices[parameter_i+3]); + // fptype amp_real = p[indices[parameter_i+0]]; + // fptype amp_imag = p[indices[parameter_i+1]]; + unsigned int functn_i = RO_CACHE(indices[parameter_i + 2]); + unsigned int params_i = RO_CACHE(indices[parameter_i + 3]); thrust::complex ai = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); thrust::complex bi = getResonanceAmplitude(m13, m12, m23, functn_i, params_i); - unsigned int functn_j = RO_CACHE(indices[parameter_j+2]); - unsigned int params_j = RO_CACHE(indices[parameter_j+3]); + unsigned int functn_j = RO_CACHE(indices[parameter_j + 2]); + unsigned int params_j = RO_CACHE(indices[parameter_j + 3]); thrust::complex aj = conj(getResonanceAmplitude(m12, m13, m23, functn_j, params_j)); thrust::complex bj = conj(getResonanceAmplitude(m13, m12, m23, functn_j, params_j)); - ret = ThreeComplex((ai*aj).real(), (ai*aj).imag(), (ai*bj).real(), (ai*bj).imag(), (bi*bj).real(), (bi*bj).imag()); + ret = ThreeComplex( + (ai * aj).real(), (ai * aj).imag(), (ai * bj).real(), (ai * bj).imag(), (bi * bj).real(), (bi * bj).imag()); return ret; } -__device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_Tddp(fptype *evt, fptype *p, unsigned int *indices) { fptype motherMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 0]); fptype daug1Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 1]); fptype daug2Mass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 2]); @@ -149,7 +153,7 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { if(!inDalitz(m12, m13, motherMass, daug1Mass, daug2Mass, daug3Mass)) return 0; - auto evtNum = static_cast( floor(0.5 + RO_CACHE(evt[indices[6 + RO_CACHE(indices[0])]]))); + auto evtNum = static_cast(floor(0.5 + RO_CACHE(evt[indices[6 + RO_CACHE(indices[0])]]))); thrust::complex sumWavesA(0, 0); thrust::complex sumWavesB(0, 0); @@ -158,24 +162,24 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { thrust::complex sumRateBB(0, 0); unsigned int numResonances = RO_CACHE(indices[6]); - //unsigned int cacheToUse = RO_CACHE(indices[7]); + // unsigned int cacheToUse = RO_CACHE(indices[7]); for(int i = 0; i < numResonances; ++i) { - int paramIndex = parIndexFromResIndex(i); - thrust::complex amp { RO_CACHE(p[RO_CACHE(indices[paramIndex+0])]), - RO_CACHE(p[RO_CACHE(indices[paramIndex+1])]) }; + int paramIndex = parIndexFromResIndex(i); + thrust::complex amp{RO_CACHE(p[RO_CACHE(indices[paramIndex + 0])]), + RO_CACHE(p[RO_CACHE(indices[paramIndex + 1])])}; - //thrust::complex matrixelement(thrust::get<0>(cWaves[cacheToUse][evtNum*numResonances + i]), + // thrust::complex matrixelement(thrust::get<0>(cWaves[cacheToUse][evtNum*numResonances + i]), // thrust::get<1>(cWaves[cacheToUse][evtNum*numResonances + i])); - //Note, to make this more efficient we should change it to only an array of fptype's, and read double2 at a time. - thrust::complex ai { RO_CACHE(cWaves[i][evtNum].ai_real), RO_CACHE(cWaves[i][evtNum].ai_imag)}; - thrust::complex bi { RO_CACHE(cWaves[i][evtNum].bi_real), RO_CACHE(cWaves[i][evtNum].bi_imag)}; + // Note, to make this more efficient we should change it to only an array of fptype's, and read double2 at a + // time. + thrust::complex ai{RO_CACHE(cWaves[i][evtNum].ai_real), RO_CACHE(cWaves[i][evtNum].ai_imag)}; + thrust::complex bi{RO_CACHE(cWaves[i][evtNum].bi_real), RO_CACHE(cWaves[i][evtNum].bi_imag)}; thrust::complex matrixelement = ai * amp; sumWavesA += matrixelement; - - //matrixelement = thrust::complex(thrust::get<2>(cWaves[cacheToUse][evtNum*numResonances + i]), + // matrixelement = thrust::complex(thrust::get<2>(cWaves[cacheToUse][evtNum*numResonances + i]), // thrust::get<3>(cWaves[cacheToUse][evtNum*numResonances + i])); matrixelement = bi * amp; sumWavesB += matrixelement; @@ -185,13 +189,13 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { fptype _xmixing = RO_CACHE(p[RO_CACHE(indices[3])]); fptype _ymixing = RO_CACHE(p[RO_CACHE(indices[4])]); - fptype _time = RO_CACHE(evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]); - fptype _sigma = RO_CACHE(evt[RO_CACHE(indices[3 + RO_CACHE(indices[0])])]); - - //if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) - //if (0 == evtNum) printf("TDDP: (%f, %f) (%f, %f)\n", sumWavesA.real, sumWavesA.imag, sumWavesB.real, sumWavesB.imag); - //printf("TDDP: %f %f %f %f | %f %f %i\n", m12, m13, _time, _sigma, _xmixing, _tau, evtNum); + fptype _time = RO_CACHE(evt[RO_CACHE(indices[2 + RO_CACHE(indices[0])])]); + fptype _sigma = RO_CACHE(evt[RO_CACHE(indices[3 + RO_CACHE(indices[0])])]); + // if ((gpuDebug & 1) && (0 == BLOCKIDX) && (0 == THREADIDX)) + // if (0 == evtNum) printf("TDDP: (%f, %f) (%f, %f)\n", sumWavesA.real, sumWavesA.imag, sumWavesB.real, + // sumWavesB.imag); + // printf("TDDP: %f %f %f %f | %f %f %i\n", m12, m13, _time, _sigma, _xmixing, _tau, evtNum); /* fptype ret = 0; @@ -199,37 +203,40 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { ret += (norm2(sumWavesA) - norm2(sumWavesB))*cos (_xmixing * _time); sumWavesA *= conj(sumWavesB); ret -= 2*sumWavesA.real * sinh(_ymixing * _time); - ret -= 2*sumWavesA.imag * sin (_xmixing * _time); // Notice sign difference wrt to Mikhail's code, because I have AB* and he has A*B. + ret -= 2*sumWavesA.imag * sin (_xmixing * _time); // Notice sign difference wrt to Mikhail's code, because I have + AB* and he has A*B. ret *= exp(-_time); */ fptype term1 = thrust::norm(sumWavesA) + thrust::norm(sumWavesB); fptype term2 = thrust::norm(sumWavesA) - thrust::norm(sumWavesB); sumWavesA *= conj(sumWavesB); - //printf("(%i, %i) TDDP: %f %f %f %f %f %f %f\n", BLOCKIDX, THREADIDX, term1, term2, sumWavesA.real, sumWavesA.imag, m12, m13, _tau); + // printf("(%i, %i) TDDP: %f %f %f %f %f %f %f\n", BLOCKIDX, THREADIDX, term1, term2, sumWavesA.real, + // sumWavesA.imag, m12, m13, _tau); // Cannot use callFunction on resolution function. int effFunctionIdx = parIndexFromResIndex(numResonances); int resFunctionIdx = RO_CACHE(indices[5]); int resFunctionPar = 2 + effFunctionIdx; - fptype ret = 0; - int md0_offset = 0; + fptype ret = 0; + int md0_offset = 0; if(resFunctionIdx == SPECIAL_RESOLUTION_FLAG) { // In this case there are multiple resolution functions, they are stored after the efficiency function, // and which one we use depends on the measured mother-particle mass. - md0_offset = 1; - fptype massd0 = RO_CACHE(evt[indices[7 + RO_CACHE(indices[0])]]); + md0_offset = 1; + fptype massd0 = RO_CACHE(evt[indices[7 + RO_CACHE(indices[0])]]); fptype minMass = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 6]); fptype md0Step = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 7]); - int res_to_use = (massd0 <= minMass) ? 0 : static_cast( floor((massd0 - minMass) / md0Step)); - int maxFcn = RO_CACHE(indices[2+effFunctionIdx]); + int res_to_use = (massd0 <= minMass) ? 0 : static_cast(floor((massd0 - minMass) / md0Step)); + int maxFcn = RO_CACHE(indices[2 + effFunctionIdx]); if(res_to_use > maxFcn) res_to_use = maxFcn; // Now calculate index of resolution function. - // At the end of the array are indices efficiency_function, efficiency_parameters, maxFcn, res_function_1, res_function_1_nP, par1, par2 ... res_function_2, res_function_2_nP, ... + // At the end of the array are indices efficiency_function, efficiency_parameters, maxFcn, res_function_1, + // res_function_1_nP, par1, par2 ... res_function_2, res_function_2_nP, ... res_to_use = 3 + effFunctionIdx + res_to_use * (2 + RO_CACHE(indices[effFunctionIdx + 4])); // NB this assumes all resolution functions have the same number of parameters. The number // of parameters in the first resolution function is stored in effFunctionIdx+3; add one to @@ -242,10 +249,18 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { resFunctionPar = res_to_use + 1; } - ret = (*(reinterpret_cast(device_function_table[resFunctionIdx])))(term1, term2, sumWavesA.real(), - sumWavesA.imag(), - _tau, _time, _xmixing, _ymixing, _sigma, - p, indices + resFunctionPar); + ret = (*(reinterpret_cast(device_function_table[resFunctionIdx])))(term1, + term2, + sumWavesA.real(), + sumWavesA.imag(), + _tau, + _time, + _xmixing, + _ymixing, + _sigma, + p, + indices + + resFunctionPar); // For the reversed (mistagged) fraction, we make the // interchange A <-> B. So term1 stays the same, @@ -256,43 +271,58 @@ __device__ fptype device_Tddp(fptype* evt, fptype* p, unsigned int* indices) { fptype mistag = RO_CACHE(functorConstants[RO_CACHE(indices[1]) + 5]); - if(mistag > 0) { // This should be either true or false for all events, so no branch is caused. + if(mistag > 0) { // This should be either true or false for all events, so no branch is caused. // See header file for explanation of 'mistag' variable - it is actually the probability // of having the correct sign, given that we have a correctly reconstructed D meson. mistag = RO_CACHE(evt[RO_CACHE(indices[md0_offset + 7 + RO_CACHE(indices[0])])]); ret *= mistag; - ret += (1 - mistag) * (*(reinterpret_cast(device_function_table[resFunctionIdx])))(term1, - -term2, sumWavesA.real(), -sumWavesA.imag(), - _tau, _time, _xmixing, _ymixing, _sigma, - p, &(indices[resFunctionPar])); + ret += (1 - mistag) * (*(reinterpret_cast(device_function_table[resFunctionIdx])))( + term1, + -term2, + sumWavesA.real(), + -sumWavesA.imag(), + _tau, + _time, + _xmixing, + _ymixing, + _sigma, + p, + &(indices[resFunctionPar])); } fptype eff = callFunction(evt, RO_CACHE(indices[effFunctionIdx]), RO_CACHE(indices[effFunctionIdx + 1])); - //internalDebug = 0; + // internalDebug = 0; ret *= eff; - return ret; } __device__ device_function_ptr ptr_to_Tddp = device_Tddp; -__host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Variable* m12, Variable* m13, - CountingVariable* eventNumber, DecayInfo* decay, MixingTimeResolution* r, GooPdf* efficiency, Variable* mistag) +__host__ TddpPdf::TddpPdf(std::string n, + Variable *_dtime, + Variable *_sigmat, + Variable *m12, + Variable *m13, + CountingVariable *eventNumber, + DecayInfo *decay, + MixingTimeResolution *r, + GooPdf *efficiency, + Variable *mistag) : GooPdf(_dtime, n) , decayInfo(decay) , _m12(m12) , _m13(m13) , resolution(r) , totalEventSize(5) // Default 5 = m12, m13, time, sigma_t, evtNum - { +{ // NB, _dtime already registered! registerObservable(_sigmat); registerObservable(_m12); registerObservable(_m13); registerObservable(eventNumber); - for(auto & cachedWave : cachedWaves) + for(auto &cachedWave : cachedWaves) cachedWave = nullptr; fptype decayConstants[6]; @@ -300,7 +330,7 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va if(mistag) { registerObservable(mistag); - totalEventSize = 6; + totalEventSize = 6; decayConstants[5] = 1; // Flags existence of mistag } @@ -311,21 +341,23 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va decayConstants[2] = decayInfo->daug2Mass; decayConstants[3] = decayInfo->daug3Mass; decayConstants[4] = decayInfo->meson_radius; - MEMCPY_TO_SYMBOL(functorConstants, decayConstants, 6*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + functorConstants, decayConstants, 6 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); pindices.push_back(registerParameter(decayInfo->_tau)); pindices.push_back(registerParameter(decayInfo->_xmixing)); pindices.push_back(registerParameter(decayInfo->_ymixing)); if(resolution->getDeviceFunction() < 0) - throw GooFit::GeneralError("The resolution device function index {} must be more than 0", resolution->getDeviceFunction()); - pindices.push_back(static_cast( resolution->getDeviceFunction())); + throw GooFit::GeneralError("The resolution device function index {} must be more than 0", + resolution->getDeviceFunction()); + pindices.push_back(static_cast(resolution->getDeviceFunction())); pindices.push_back(decayInfo->resonances.size()); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); - for(auto & resonance : decayInfo->resonances) { + for(auto &resonance : decayInfo->resonances) { pindices.push_back(registerParameter(resonance->amp_real)); pindices.push_back(registerParameter(resonance->amp_imag)); pindices.push_back(resonance->getFunctionIndex()); @@ -345,17 +377,17 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va redoIntegral = new bool[decayInfo->resonances.size()]; cachedMasses = new fptype[decayInfo->resonances.size()]; cachedWidths = new fptype[decayInfo->resonances.size()]; - integrals = new ThreeComplex** [decayInfo->resonances.size()]; - integrators = new SpecialDalitzIntegrator** [decayInfo->resonances.size()]; - calculators = new SpecialWaveCalculator*[decayInfo->resonances.size()]; + integrals = new ThreeComplex **[decayInfo->resonances.size()]; + integrators = new SpecialDalitzIntegrator **[decayInfo->resonances.size()]; + calculators = new SpecialWaveCalculator *[decayInfo->resonances.size()]; for(int i = 0; i < decayInfo->resonances.size(); ++i) { redoIntegral[i] = true; cachedMasses[i] = -1; cachedWidths[i] = -1; - integrators[i] = new SpecialDalitzIntegrator*[decayInfo->resonances.size()]; + integrators[i] = new SpecialDalitzIntegrator *[decayInfo->resonances.size()]; calculators[i] = new SpecialWaveCalculator(parameters, i); - integrals[i] = new ThreeComplex*[decayInfo->resonances.size()]; + integrals[i] = new ThreeComplex *[decayInfo->resonances.size()]; for(int j = 0; j < decayInfo->resonances.size(); ++j) { integrals[i][j] = new ThreeComplex(0, 0, 0, 0, 0, 0); @@ -366,16 +398,25 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va addSpecialMask(PdfBase::ForceSeparateNorm); } -__host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Variable* m12, Variable* m13, - CountingVariable* eventNumber, DecayInfo* decay, std::vector& r, GooPdf* efficiency, Variable* md0, - Variable* mistag) +__host__ TddpPdf::TddpPdf(std::string n, + Variable *_dtime, + Variable *_sigmat, + Variable *m12, + Variable *m13, + CountingVariable *eventNumber, + DecayInfo *decay, + std::vector &r, + GooPdf *efficiency, + Variable *md0, + Variable *mistag) : GooPdf(_dtime, n) , decayInfo(decay) , _m12(m12) , _m13(m13) - , resolution(r[0]) // Only used for normalisation, which only depends on x and y - it doesn't matter which one we use. + , resolution( + r[0]) // Only used for normalisation, which only depends on x and y - it doesn't matter which one we use. , totalEventSize(6) // This case adds the D0 mass by default. - { +{ // NB, _dtime already registered! registerObservable(_sigmat); registerObservable(_m12); @@ -383,7 +424,7 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va registerObservable(eventNumber); registerObservable(md0); - for(auto & cachedWave : cachedWaves) + for(auto &cachedWave : cachedWaves) cachedWave = nullptr; fptype decayConstants[8]; @@ -404,7 +445,8 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va decayConstants[2] = decayInfo->daug2Mass; decayConstants[3] = decayInfo->daug3Mass; decayConstants[4] = decayInfo->meson_radius; - MEMCPY_TO_SYMBOL(functorConstants, decayConstants, 8*sizeof(fptype), cIndex*sizeof(fptype), cudaMemcpyHostToDevice); + MEMCPY_TO_SYMBOL( + functorConstants, decayConstants, 8 * sizeof(fptype), cIndex * sizeof(fptype), cudaMemcpyHostToDevice); pindices.push_back(registerParameter(decayInfo->_tau)); pindices.push_back(registerParameter(decayInfo->_xmixing)); @@ -413,10 +455,10 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va pindices.push_back(decayInfo->resonances.size()); static int cacheCount = 0; - cacheToUse = cacheCount++; + cacheToUse = cacheCount++; pindices.push_back(cacheToUse); - for(auto & resonance : decayInfo->resonances) { + for(auto &resonance : decayInfo->resonances) { pindices.push_back(registerParameter(resonance->amp_real)); pindices.push_back(registerParameter(resonance->amp_imag)); pindices.push_back(resonance->getFunctionIndex()); @@ -431,10 +473,10 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va pindices.push_back(r.size() - 1); // Highest index, not number of functions. - for(auto & i : r) { + for(auto &i : r) { if(i->getDeviceFunction() < 0) throw GooFit::GeneralError("Device function index {} must be more than 0", i->getDeviceFunction()); - pindices.push_back(static_cast( i->getDeviceFunction())); + pindices.push_back(static_cast(i->getDeviceFunction())); i->createParameters(pindices, this); } @@ -444,17 +486,17 @@ __host__ TddpPdf::TddpPdf(std::string n, Variable* _dtime, Variable* _sigmat, Va redoIntegral = new bool[decayInfo->resonances.size()]; cachedMasses = new fptype[decayInfo->resonances.size()]; cachedWidths = new fptype[decayInfo->resonances.size()]; - integrals = new ThreeComplex** [decayInfo->resonances.size()]; - integrators = new SpecialDalitzIntegrator** [decayInfo->resonances.size()]; - calculators = new SpecialWaveCalculator*[decayInfo->resonances.size()]; + integrals = new ThreeComplex **[decayInfo->resonances.size()]; + integrators = new SpecialDalitzIntegrator **[decayInfo->resonances.size()]; + calculators = new SpecialWaveCalculator *[decayInfo->resonances.size()]; for(int i = 0; i < decayInfo->resonances.size(); ++i) { redoIntegral[i] = true; cachedMasses[i] = -1; cachedWidths[i] = -1; - integrators[i] = new SpecialDalitzIntegrator*[decayInfo->resonances.size()]; + integrators[i] = new SpecialDalitzIntegrator *[decayInfo->resonances.size()]; calculators[i] = new SpecialWaveCalculator(parameters, i); - integrals[i] = new ThreeComplex*[decayInfo->resonances.size()]; + integrals[i] = new ThreeComplex *[decayInfo->resonances.size()]; for(int j = 0; j < decayInfo->resonances.size(); ++j) { integrals[i][j] = new ThreeComplex(0, 0, 0, 0, 0, 0); @@ -472,30 +514,30 @@ __host__ void TddpPdf::setDataSize(unsigned int dataSize, unsigned int evtSize) throw GooFit::GeneralError("totalEventSize {} must be 5 or more", totalEventSize); if(cachedWaves[0]) { - for(auto & cachedWave : cachedWaves) + for(auto &cachedWave : cachedWaves) delete cachedWave; } numEntries = dataSize; - //Ideally this would not be required, this would be called AFTER setData which will set m_iEventsPerTask +// Ideally this would not be required, this would be called AFTER setData which will set m_iEventsPerTask #ifdef GOOFIT_MPI int myId, numProcs; MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Comm_rank(MPI_COMM_WORLD, &myId); - int perTask = numEntries/numProcs; + int perTask = numEntries / numProcs; - int* counts = new int[numProcs]; + int *counts = new int[numProcs]; - for(int i = 0; i < numProcs - 1; i++) + for(int i = 0; i < numProcs - 1; i++) counts[i] = perTask; - counts[numProcs - 1] = numEntries - perTask*(numProcs - 1); + counts[numProcs - 1] = numEntries - perTask * (numProcs - 1); setNumPerTask(this, counts[myId]); - delete [] counts; + delete[] counts; #endif for(int i = 0; i < 16; i++) { @@ -504,8 +546,8 @@ __host__ void TddpPdf::setDataSize(unsigned int dataSize, unsigned int evtSize) #else cachedWaves[i] = new thrust::device_vector(dataSize); #endif - void* dummy = thrust::raw_pointer_cast(cachedWaves[i]->data()); - MEMCPY_TO_SYMBOL(cWaves, &dummy, sizeof(WaveHolder_s*), i*sizeof(WaveHolder_s*), cudaMemcpyHostToDevice); + void *dummy = thrust::raw_pointer_cast(cachedWaves[i]->data()); + MEMCPY_TO_SYMBOL(cWaves, &dummy, sizeof(WaveHolder_s *), i * sizeof(WaveHolder_s *), cudaMemcpyHostToDevice); } setForceIntegrals(); @@ -516,22 +558,22 @@ __host__ fptype TddpPdf::normalize() const { // so set normalisation factor to 1 so it doesn't get multiplied by zero. // Copy at this time to ensure that the SpecialWaveCalculators, which need the efficiency, // don't get zeroes through multiplying by the normFactor. - MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams*sizeof(fptype), 0, cudaMemcpyHostToDevice); - //std::cout << "TDDP normalisation " << getName() << std::endl; + MEMCPY_TO_SYMBOL(normalisationFactors, host_normalisation, totalParams * sizeof(fptype), 0, cudaMemcpyHostToDevice); + // std::cout << "TDDP normalisation " << getName() << std::endl; int totalBins = _m12->getNumBins() * _m13->getNumBins(); if(!dalitzNormRange) { - gooMalloc((void**) &dalitzNormRange, 6*sizeof(fptype)); - - auto* host_norms = new fptype[6]; - host_norms[0] = _m12->getLowerLimit(); - host_norms[1] = _m12->getUpperLimit(); - host_norms[2] = _m12->getNumBins(); - host_norms[3] = _m13->getLowerLimit(); - host_norms[4] = _m13->getUpperLimit(); - host_norms[5] = _m13->getNumBins(); - MEMCPY(dalitzNormRange, host_norms, 6*sizeof(fptype), cudaMemcpyHostToDevice); + gooMalloc((void **)&dalitzNormRange, 6 * sizeof(fptype)); + + auto *host_norms = new fptype[6]; + host_norms[0] = _m12->getLowerLimit(); + host_norms[1] = _m12->getUpperLimit(); + host_norms[2] = _m12->getNumBins(); + host_norms[3] = _m13->getLowerLimit(); + host_norms[4] = _m13->getUpperLimit(); + host_norms[5] = _m13->getNumBins(); + MEMCPY(dalitzNormRange, host_norms, 6 * sizeof(fptype), cudaMemcpyHostToDevice); delete[] host_norms; } @@ -547,13 +589,13 @@ __host__ fptype TddpPdf::normalize() const { forceRedoIntegrals = false; // Only do this bit if masses or widths have changed. - thrust::constant_iterator arrayAddress(dalitzNormRange); + thrust::constant_iterator arrayAddress(dalitzNormRange); thrust::counting_iterator binIndex(0); // NB, SpecialWaveCalculator assumes that fit is unbinned! // And it needs to know the total event size, not just observables // for this particular PDF component. - thrust::constant_iterator dataArray(dev_event_array); + thrust::constant_iterator dataArray(dev_event_array); thrust::constant_iterator eventSize(totalEventSize); thrust::counting_iterator eventIndex(0); @@ -562,19 +604,24 @@ __host__ fptype TddpPdf::normalize() const { for(int i = 0; i < decayInfo->resonances.size(); ++i) { if(redoIntegral[i]) { - #ifdef GOOFIT_MPI - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), - strided_range::iterator>(cachedWaves[i]->begin(), cachedWaves[i]->end(), 1).begin(), - *(calculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + m_iEventsPerTask, arrayAddress, eventSize)), + strided_range::iterator>( + cachedWaves[i]->begin(), cachedWaves[i]->end(), 1) + .begin(), + *(calculators[i])); #else - thrust::transform(thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), - thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), - strided_range::iterator>(cachedWaves[i]->begin(), cachedWaves[i]->end(), 1).begin(), - *(calculators[i])); + thrust::transform( + thrust::make_zip_iterator(thrust::make_tuple(eventIndex, dataArray, eventSize)), + thrust::make_zip_iterator(thrust::make_tuple(eventIndex + numEntries, arrayAddress, eventSize)), + strided_range::iterator>( + cachedWaves[i]->begin(), cachedWaves[i]->end(), 1) + .begin(), + *(calculators[i])); #endif - //std::cout << "Integral for resonance " << i << " " << numEntries << " " << totalEventSize << std::endl; + // std::cout << "Integral for resonance " << i << " " << numEntries << " " << totalEventSize << std::endl; } // Possibly this can be done more efficiently by exploiting symmetry? @@ -584,11 +631,12 @@ __host__ fptype TddpPdf::normalize() const { ThreeComplex dummy(0, 0, 0, 0, 0, 0); SpecialComplexSum complexSum; - (*(integrals[i][j])) = thrust::transform_reduce(thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), - thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), - *(integrators[i][j]), - dummy, - complexSum); + (*(integrals[i][j])) = thrust::transform_reduce( + thrust::make_zip_iterator(thrust::make_tuple(binIndex, arrayAddress)), + thrust::make_zip_iterator(thrust::make_tuple(binIndex + totalBins, arrayAddress)), + *(integrators[i][j]), + dummy, + complexSum); /* std::cout << "With resonance " << j << ": " << thrust::get<0>(*(integrals[i][j])) << " " @@ -608,48 +656,54 @@ __host__ fptype TddpPdf::normalize() const { thrust::complex integralABs(0, 0); for(unsigned int i = 0; i < decayInfo->resonances.size(); ++i) { - int param_i = parameters + resonanceOffset + resonanceSize*i; + int param_i = parameters + resonanceOffset + resonanceSize * i; thrust::complex amplitude_i(host_params[host_indices[param_i]], host_params[host_indices[param_i + 1]]); for(unsigned int j = 0; j < decayInfo->resonances.size(); ++j) { - int param_j = parameters + resonanceOffset + resonanceSize*j; + int param_j = parameters + resonanceOffset + resonanceSize * j; thrust::complex amplitude_j(host_params[host_indices[param_j]], - -host_params[host_indices[param_j + 1]]); // Notice complex conjugation + -host_params[host_indices[param_j + 1]]); // Notice complex conjugation integralA_2 += (amplitude_i * amplitude_j * thrust::complex(thrust::get<0>(*(integrals[i][j])), - thrust::get<1>(*(integrals[i][j])))); + thrust::get<1>(*(integrals[i][j])))); integralABs += (amplitude_i * amplitude_j * thrust::complex(thrust::get<2>(*(integrals[i][j])), - thrust::get<3>(*(integrals[i][j])))); + thrust::get<3>(*(integrals[i][j])))); integralB_2 += (amplitude_i * amplitude_j * thrust::complex(thrust::get<4>(*(integrals[i][j])), - thrust::get<5>(*(integrals[i][j])))); + thrust::get<5>(*(integrals[i][j])))); /* if (cpuDebug & 1) { int idx = i * decayInfo->resonances.size() + j; if (0 == host_callnumber) std::cout << "Integral contribution " << i << ", " << j << " " << idx << " : " - << amplitude_i << " " - << amplitude_j << " (" - << real(amplitude_i * amplitude_j * complex(thrust::get<0>(*(integrals[i][j])), thrust::get<1>(*(integrals[i][j])))) << ", " - << imag(amplitude_i * amplitude_j * complex(thrust::get<0>(*(integrals[i][j])), thrust::get<1>(*(integrals[i][j])))) << ") (" - << real(amplitude_i * amplitude_j * complex(thrust::get<2>(*(integrals[i][j])), thrust::get<3>(*(integrals[i][j])))) << ", " - << imag(amplitude_i * amplitude_j * complex(thrust::get<2>(*(integrals[i][j])), thrust::get<3>(*(integrals[i][j])))) << ") (" - << real(amplitude_i * amplitude_j * complex(thrust::get<4>(*(integrals[i][j])), thrust::get<5>(*(integrals[i][j])))) << ", " - << imag(amplitude_i * amplitude_j * complex(thrust::get<4>(*(integrals[i][j])), thrust::get<5>(*(integrals[i][j])))) << ") " - << thrust::get<0>(*(integrals[i][j])) << ", " - << thrust::get<1>(*(integrals[i][j])) << ") (" - << thrust::get<2>(*(integrals[i][j])) << ", " - << thrust::get<3>(*(integrals[i][j])) << ") (" - << thrust::get<4>(*(integrals[i][j])) << ", " - << thrust::get<5>(*(integrals[i][j])) << ") (" - << real(integralA_2) << ", " << imag(integralA_2) << ") " - << std::endl; + << amplitude_i << " " + << amplitude_j << " (" + << real(amplitude_i * amplitude_j * complex(thrust::get<0>(*(integrals[i][j])), + thrust::get<1>(*(integrals[i][j])))) << ", " + << imag(amplitude_i * amplitude_j * complex(thrust::get<0>(*(integrals[i][j])), + thrust::get<1>(*(integrals[i][j])))) << ") (" + << real(amplitude_i * amplitude_j * complex(thrust::get<2>(*(integrals[i][j])), + thrust::get<3>(*(integrals[i][j])))) << ", " + << imag(amplitude_i * amplitude_j * complex(thrust::get<2>(*(integrals[i][j])), + thrust::get<3>(*(integrals[i][j])))) << ") (" + << real(amplitude_i * amplitude_j * complex(thrust::get<4>(*(integrals[i][j])), + thrust::get<5>(*(integrals[i][j])))) << ", " + << imag(amplitude_i * amplitude_j * complex(thrust::get<4>(*(integrals[i][j])), + thrust::get<5>(*(integrals[i][j])))) << ") " + << thrust::get<0>(*(integrals[i][j])) << ", " + << thrust::get<1>(*(integrals[i][j])) << ") (" + << thrust::get<2>(*(integrals[i][j])) << ", " + << thrust::get<3>(*(integrals[i][j])) << ") (" + << thrust::get<4>(*(integrals[i][j])) << ", " + << thrust::get<5>(*(integrals[i][j])) << ") (" + << real(integralA_2) << ", " << imag(integralA_2) << ") " + << std::endl; } */ - } } - double dalitzIntegralOne = integralA_2.real(); // Notice that this is already the abs2, so it's real by construction; but the compiler doesn't know that. + double dalitzIntegralOne = integralA_2.real(); // Notice that this is already the abs2, so it's real by + // construction; but the compiler doesn't know that. double dalitzIntegralTwo = integralB_2.real(); double dalitzIntegralThr = integralABs.real(); double dalitzIntegralFou = integralABs.imag(); @@ -658,16 +712,17 @@ __host__ fptype TddpPdf::normalize() const { fptype xmixing = host_params[host_indices[parameters + 3]]; fptype ymixing = host_params[host_indices[parameters + 4]]; - fptype ret = resolution->normalisation(dalitzIntegralOne, dalitzIntegralTwo, dalitzIntegralThr, dalitzIntegralFou, tau, - xmixing, ymixing); + fptype ret = resolution->normalisation( + dalitzIntegralOne, dalitzIntegralTwo, dalitzIntegralThr, dalitzIntegralFou, tau, xmixing, ymixing); double binSizeFactor = 1; binSizeFactor *= ((_m12->getUpperLimit() - _m12->getLowerLimit()) / _m12->getNumBins()); binSizeFactor *= ((_m13->getUpperLimit() - _m13->getLowerLimit()) / _m13->getNumBins()); ret *= binSizeFactor; - host_normalisation[parameters] = 1.0/ret; - //std::cout << "End of TDDP normalisation: " << ret << " " << host_normalisation[parameters] << " " << binSizeFactor << std::endl; + host_normalisation[parameters] = 1.0 / ret; + // std::cout << "End of TDDP normalisation: " << ret << " " << host_normalisation[parameters] << " " << + // binSizeFactor << std::endl; return ret; } //#endif @@ -675,10 +730,9 @@ __host__ fptype TddpPdf::normalize() const { SpecialDalitzIntegrator::SpecialDalitzIntegrator(int pIdx, unsigned int ri, unsigned int rj) : resonance_i(ri) , resonance_j(rj) - , parameters(pIdx) -{} + , parameters(pIdx) {} -__device__ ThreeComplex SpecialDalitzIntegrator::operator()(thrust::tuple t) const { +__device__ ThreeComplex SpecialDalitzIntegrator::operator()(thrust::tuple t) const { // Bin index, base address [lower, upper,getNumBins] // Notice that this is basically MetricTaker::operator (binned) with the special-case knowledge // that event size is two, and that the function to call is dev_Tddp_calcIntegrals. @@ -686,39 +740,44 @@ __device__ ThreeComplex SpecialDalitzIntegrator::operator()(thrust::tuple(t); fptype lowerBoundM12 = thrust::get<1>(t)[0]; fptype upperBoundM12 = thrust::get<1>(t)[1]; - auto numBinsM12 = static_cast( floor(thrust::get<1>(t)[2] + 0.5)); + auto numBinsM12 = static_cast(floor(thrust::get<1>(t)[2] + 0.5)); int binNumberM12 = globalBinNumber % numBinsM12; fptype binCenterM12 = upperBoundM12 - lowerBoundM12; - binCenterM12 /= numBinsM12; - binCenterM12 *= (binNumberM12 + 0.5); - binCenterM12 += lowerBoundM12; + binCenterM12 /= numBinsM12; + binCenterM12 *= (binNumberM12 + 0.5); + binCenterM12 += lowerBoundM12; - globalBinNumber /= numBinsM12; + globalBinNumber /= numBinsM12; fptype lowerBoundM13 = thrust::get<1>(t)[3]; fptype upperBoundM13 = thrust::get<1>(t)[4]; - auto numBinsM13 = static_cast( floor(thrust::get<1>(t)[5] + 0.5)); + auto numBinsM13 = static_cast(floor(thrust::get<1>(t)[5] + 0.5)); fptype binCenterM13 = upperBoundM13 - lowerBoundM13; - binCenterM13 /= numBinsM13; - binCenterM13 *= (globalBinNumber + 0.5); - binCenterM13 += lowerBoundM13; - - //if (0 == THREADIDX) cuPrintf("%i %i %i %f %f operator\n", thrust::get<0>(t), thrust::get<0>(t) % numBinsM12, globalBinNumber, binCenterM12, binCenterM13); - unsigned int* indices = paramIndices + parameters; - ThreeComplex ret = device_Tddp_calcIntegrals(binCenterM12, binCenterM13, resonance_i, resonance_j, cudaArray, indices); - - fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an event-weighted fit. + binCenterM13 /= numBinsM13; + binCenterM13 *= (globalBinNumber + 0.5); + binCenterM13 += lowerBoundM13; + + // if (0 == THREADIDX) cuPrintf("%i %i %i %f %f operator\n", thrust::get<0>(t), thrust::get<0>(t) % numBinsM12, + // globalBinNumber, binCenterM12, binCenterM13); + unsigned int *indices = paramIndices + parameters; + ThreeComplex ret + = device_Tddp_calcIntegrals(binCenterM12, binCenterM13, resonance_i, resonance_j, cudaArray, indices); + + fptype fakeEvt[10]; // Need room for many observables in case m12 or m13 were assigned a high index in an + // event-weighted fit. fakeEvt[RO_CACHE(indices[RO_CACHE(indices[0]) + 2 + 2])] = binCenterM12; fakeEvt[RO_CACHE(indices[RO_CACHE(indices[0]) + 2 + 3])] = binCenterM13; - unsigned int numResonances = indices[6]; - int effFunctionIdx = parIndexFromResIndex(numResonances); - //if (thrust::get<0>(t) == 19840) {internalDebug1 = BLOCKIDX; internalDebug2 = THREADIDX;} - //fptype eff = (*(reinterpret_cast(device_function_table[indices[effFunctionIdx]])))(fakeEvt, cudaArray, paramIndices + indices[effFunctionIdx + 1]); + unsigned int numResonances = indices[6]; + int effFunctionIdx = parIndexFromResIndex(numResonances); + // if (thrust::get<0>(t) == 19840) {internalDebug1 = BLOCKIDX; internalDebug2 = THREADIDX;} + // fptype eff = (*(reinterpret_cast(device_function_table[indices[effFunctionIdx]])))(fakeEvt, + // cudaArray, paramIndices + indices[effFunctionIdx + 1]); fptype eff = callFunction(fakeEvt, RO_CACHE(indices[effFunctionIdx]), RO_CACHE(indices[effFunctionIdx + 1])); - //if (thrust::get<0>(t) == 19840) { - //internalDebug1 = -1; - //internalDebug2 = -1; - //printf("Efficiency: %i %f %f %f %i\n", thrust::get<0>(t), binCenterM12, binCenterM13, eff, effFunctionIdx); - //printf("Efficiency: %f %f %f %f %f %i %i\n", fakeEvt[0], fakeEvt[1], fakeEvt[2], fakeEvt[3], fakeEvt[4], indices[indices[0] + 2 + 2], indices[indices[0] + 2 + 3]); + // if (thrust::get<0>(t) == 19840) { + // internalDebug1 = -1; + // internalDebug2 = -1; + // printf("Efficiency: %i %f %f %f %i\n", thrust::get<0>(t), binCenterM12, binCenterM13, eff, effFunctionIdx); + // printf("Efficiency: %f %f %f %f %f %i %i\n", fakeEvt[0], fakeEvt[1], fakeEvt[2], fakeEvt[3], fakeEvt[4], + // indices[indices[0] + 2 + 2], indices[indices[0] + 2 + 3]); //} // Multiplication by eff, not sqrt(eff), is correct: @@ -736,10 +795,9 @@ __device__ ThreeComplex SpecialDalitzIntegrator::operator()(thrust::tuple t) const { +__device__ WaveHolder_s SpecialWaveCalculator::operator()(thrust::tuple t) const { // Calculates the BW values for a specific resonance. // The 'A' wave stores the value at each point, the 'B' // at the opposite (reversed) point. @@ -750,12 +808,12 @@ __device__ WaveHolder_s SpecialWaveCalculator::operator()(thrust::tuple(t); - fptype* evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); + int evtNum = thrust::get<0>(t); + fptype *evt = thrust::get<1>(t) + (evtNum * thrust::get<2>(t)); - unsigned int* indices = paramIndices + parameters; // Jump to TDDP position within parameters array - fptype m12 = RO_CACHE(evt[indices[4 + indices[0]]]); - fptype m13 = RO_CACHE(evt[indices[5 + indices[0]]]); + unsigned int *indices = paramIndices + parameters; // Jump to TDDP position within parameters array + fptype m12 = RO_CACHE(evt[indices[4 + indices[0]]]); + fptype m13 = RO_CACHE(evt[indices[5 + indices[0]]]); fptype motherMass = functorConstants[indices[1] + 0]; fptype daug1Mass = functorConstants[indices[1] + 1]; @@ -765,16 +823,17 @@ __device__ WaveHolder_s SpecialWaveCalculator::operator()(thrust::tuple ai = getResonanceAmplitude(m12, m13, m23, functn_i, params_i); thrust::complex bi = getResonanceAmplitude(m13, m12, m23, functn_i, params_i); - //printf("Amplitudes %f, %f => (%f %f) (%f %f)\n", m12, m13, ai.real, ai.imag, bi.real, bi.imag); + // printf("Amplitudes %f, %f => (%f %f) (%f %f)\n", m12, m13, ai.real, ai.imag, bi.real, bi.imag); ret.ai_real = ai.real(); ret.ai_imag = ai.imag(); @@ -785,4 +844,3 @@ __device__ WaveHolder_s SpecialWaveCalculator::operator()(thrust::tuple& pindices, PdfBase* dis) { +void ThreeGaussResolution::createParameters(std::vector &pindices, PdfBase *dis) { pindices.push_back(8); pindices.push_back(dis->registerParameter(coreFraction)); pindices.push_back(dis->registerParameter(tailFraction)); @@ -129,24 +141,23 @@ void ThreeGaussResolution::createParameters(std::vector& pindices, pindices.push_back(dis->registerParameter(outScaleFactor)); } -fptype ThreeGaussResolution::normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, - fptype ymixing) const { +fptype ThreeGaussResolution::normalisation( + fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, fptype ymixing) const { // NB! In thesis notation, A_1 = (A + B), A_2 = (A - B). // Here di1 = |A^2|, di2 = |B^2|, di3,4 = Re,Im(AB^*). // Distinction between numerical subscribts and A,B is crucial // for comparing thesis math to this math! - fptype timeIntegralOne = tau / (1 - ymixing*ymixing); - fptype timeIntegralTwo = tau / (1 + xmixing*xmixing); + fptype timeIntegralOne = tau / (1 - ymixing * ymixing); + fptype timeIntegralTwo = tau / (1 + xmixing * xmixing); fptype timeIntegralThr = ymixing * timeIntegralOne; fptype timeIntegralFou = xmixing * timeIntegralTwo; fptype ret = timeIntegralOne * (di1 + di2); // ~ |A|^2 + |B|^2 - ret += timeIntegralTwo * (di1 - di2); // ~ Re(A_1 A_2^*) - ret -= 2*timeIntegralThr * di3; // ~ |A|^2 - |B|^2 - ret -= 2*timeIntegralFou * di4; // ~ Im(A_1 A_2^*) + ret += timeIntegralTwo * (di1 - di2); // ~ Re(A_1 A_2^*) + ret -= 2 * timeIntegralThr * di3; // ~ |A|^2 - |B|^2 + ret -= 2 * timeIntegralFou * di4; // ~ Im(A_1 A_2^*) return ret; } } // namespace GooFit - diff --git a/src/PDFs/TrigThresholdPdf.cu b/src/PDFs/TrigThresholdPdf.cu index f1694445f..cbd1d8597 100644 --- a/src/PDFs/TrigThresholdPdf.cu +++ b/src/PDFs/TrigThresholdPdf.cu @@ -2,13 +2,13 @@ namespace GooFit { - __device__ fptype threshCalc(fptype distance, fptype linConst) { - fptype ret = (distance > fptype(0.5) ? fptype(1) : (linConst + (1 - linConst) * sin(distance * fptype(3.14159265)))); + fptype ret + = (distance > fptype(0.5) ? fptype(1) : (linConst + (1 - linConst) * sin(distance * fptype(3.14159265)))); return ret; } -__device__ fptype device_TrigThresholdUpper(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_TrigThresholdUpper(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; fptype thresh = p[indices[1]]; fptype trigConst = p[indices[2]]; @@ -18,7 +18,7 @@ __device__ fptype device_TrigThresholdUpper(fptype* evt, fptype* p, unsigned int return threshCalc(trigConst, linConst); } -__device__ fptype device_TrigThresholdLower(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_TrigThresholdLower(fptype *evt, fptype *p, unsigned int *indices) { fptype x = evt[indices[2 + indices[0]]]; fptype thresh = p[indices[1]]; fptype trigConst = p[indices[2]]; @@ -28,11 +28,11 @@ __device__ fptype device_TrigThresholdLower(fptype* evt, fptype* p, unsigned int return threshCalc(trigConst, linConst); } -__device__ fptype device_VerySpecialEpisodeTrigThresholdUpper(fptype* evt, fptype* p, unsigned int* indices) { +__device__ fptype device_VerySpecialEpisodeTrigThresholdUpper(fptype *evt, fptype *p, unsigned int *indices) { // Annoying special case for use with Mikhail's efficiency function across the Dalitz plot - fptype x = evt[indices[2 + indices[0] + 0]]; - fptype y = evt[indices[2 + indices[0] + 1]]; + fptype x = evt[indices[2 + indices[0] + 0]]; + fptype y = evt[indices[2 + indices[0] + 1]]; fptype thresh = p[indices[1]]; fptype trigConst = p[indices[2]]; @@ -43,9 +43,9 @@ __device__ fptype device_VerySpecialEpisodeTrigThresholdUpper(fptype* evt, fptyp return threshCalc(trigConst, linConst); } -__device__ fptype device_VerySpecialEpisodeTrigThresholdLower(fptype* evt, fptype* p, unsigned int* indices) { - fptype x = evt[indices[2 + indices[0] + 0]]; - fptype y = evt[indices[2 + indices[0] + 1]]; +__device__ fptype device_VerySpecialEpisodeTrigThresholdLower(fptype *evt, fptype *p, unsigned int *indices) { + fptype x = evt[indices[2 + indices[0] + 0]]; + fptype y = evt[indices[2 + indices[0] + 1]]; fptype thresh = p[indices[1]]; fptype trigConst = p[indices[2]]; @@ -55,22 +55,21 @@ __device__ fptype device_VerySpecialEpisodeTrigThresholdLower(fptype* evt, fptyp trigConst *= (z - thresh); fptype ret = threshCalc(trigConst, linConst); - //if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) - //printf("TrigThreshold: (%f - %f = %f) -> %f %f\n", z, thresh, trigConst, linConst, ret); + // if ((1 > (int) floor(0.5 + evt[8])) && (gpuDebug & 1) && (paramIndices + debugParamIndex == indices)) + // printf("TrigThreshold: (%f - %f = %f) -> %f %f\n", z, thresh, trigConst, linConst, ret); return ret; } __device__ device_function_ptr ptr_to_TrigThresholdUpper = device_TrigThresholdUpper; __device__ device_function_ptr ptr_to_TrigThresholdLower = device_TrigThresholdLower; -__device__ device_function_ptr ptr_to_VerySpecialEpisodeTrigThresholdUpper = - device_VerySpecialEpisodeTrigThresholdUpper; -__device__ device_function_ptr ptr_to_VerySpecialEpisodeTrigThresholdLower = - device_VerySpecialEpisodeTrigThresholdLower; - +__device__ device_function_ptr ptr_to_VerySpecialEpisodeTrigThresholdUpper + = device_VerySpecialEpisodeTrigThresholdUpper; +__device__ device_function_ptr ptr_to_VerySpecialEpisodeTrigThresholdLower + = device_VerySpecialEpisodeTrigThresholdLower; -__host__ TrigThresholdPdf::TrigThresholdPdf(std::string n, Variable* _x, Variable* thresh, Variable* trigConst, - Variable* linConst, bool upper) +__host__ TrigThresholdPdf::TrigThresholdPdf( + std::string n, Variable *_x, Variable *thresh, Variable *trigConst, Variable *linConst, bool upper) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(thresh)); @@ -85,8 +84,14 @@ __host__ TrigThresholdPdf::TrigThresholdPdf(std::string n, Variable* _x, Variabl initialize(pindices); } -__host__ TrigThresholdPdf::TrigThresholdPdf(std::string n, Variable* _x, Variable* _y, Variable* thresh, - Variable* trigConst, Variable* linConst, Variable* massConstant, bool upper) +__host__ TrigThresholdPdf::TrigThresholdPdf(std::string n, + Variable *_x, + Variable *_y, + Variable *thresh, + Variable *trigConst, + Variable *linConst, + Variable *massConstant, + bool upper) : GooPdf(nullptr, n) { registerObservable(_x); registerObservable(_y); @@ -105,4 +110,3 @@ __host__ TrigThresholdPdf::TrigThresholdPdf(std::string n, Variable* _x, Variabl initialize(pindices); } } // namespace GooFit - diff --git a/src/PDFs/TruthResolution_Aux.cu b/src/PDFs/TruthResolution_Aux.cu index 48284bb04..17c439a51 100644 --- a/src/PDFs/TruthResolution_Aux.cu +++ b/src/PDFs/TruthResolution_Aux.cu @@ -2,39 +2,48 @@ namespace GooFit { - -__device__ fptype device_truth_resolution(fptype coshterm, fptype costerm, fptype sinhterm, fptype sinterm, - fptype tau, fptype dtime, fptype xmixing, fptype ymixing, fptype /*sigma*/, - fptype* /*p*/, unsigned int* /*indices*/) { +__device__ fptype device_truth_resolution(fptype coshterm, + fptype costerm, + fptype sinhterm, + fptype sinterm, + fptype tau, + fptype dtime, + fptype xmixing, + fptype ymixing, + fptype /*sigma*/, + fptype * /*p*/, + unsigned int * /*indices*/) { fptype ret = 0; dtime /= tau; - ret += coshterm*cosh(ymixing * dtime); - ret += costerm*cos(xmixing * dtime); - ret -= 2*sinhterm * sinh(ymixing * dtime); - ret -= 2*sinterm * sin(xmixing * - dtime); // Notice sign difference wrt to Mikhail's code, because I have AB* and he has A*B. + ret += coshterm * cosh(ymixing * dtime); + ret += costerm * cos(xmixing * dtime); + ret -= 2 * sinhterm * sinh(ymixing * dtime); + ret -= 2 * sinterm + * sin(xmixing * dtime); // Notice sign difference wrt to Mikhail's code, because I have AB* and he has A*B. ret *= exp(-dtime); // printf("device_truth_resolution %f %f %f %f %f\n", coshterm, costerm, sinhterm, sinterm, dtime); return ret; } -__device__ fptype device_truth_resolution_average_tau(fptype A2, fptype B2, fptype ABr, fptype ABi, fptype xmixing, - fptype ymixing, fptype tau) { - fptype a = A2-B2; - fptype b = 2*ABi; - fptype c = A2+B2; - fptype d = 2*ABr; - fptype averagetau = ((xmixing*xmixing + 1)*(ymixing*ymixing - 1)* - (((a*tau*(xmixing*xmixing - 1.) + 2.*b*tau*xmixing))/((xmixing*xmixing + 1.)*(xmixing*xmixing + 1.)) + (c*(- - (tau*ymixing*ymixing) - tau) + - d *(2.*tau)*ymixing)/((ymixing*ymixing - 1.)*(ymixing*ymixing - 1.))))/((ymixing*ymixing - 1)*(b*xmixing - a) + - (xmixing*xmixing + 1)*(c - d*ymixing)); - // printf("device avg tau: %.5g with A2: %.5g, B2: %.5g, ABr:%.5g, ABi:%.5g, x:%.5g, y:%.5g, tau:%.5g \n", averagetau, A2, B2, ABr, ABi, xmixing, ymixing, tau); +__device__ fptype device_truth_resolution_average_tau( + fptype A2, fptype B2, fptype ABr, fptype ABi, fptype xmixing, fptype ymixing, fptype tau) { + fptype a = A2 - B2; + fptype b = 2 * ABi; + fptype c = A2 + B2; + fptype d = 2 * ABr; + fptype averagetau = ((xmixing * xmixing + 1) * (ymixing * ymixing - 1) + * (((a * tau * (xmixing * xmixing - 1.) + 2. * b * tau * xmixing)) + / ((xmixing * xmixing + 1.) * (xmixing * xmixing + 1.)) + + (c * (-(tau * ymixing * ymixing) - tau) + d * (2. * tau) * ymixing) + / ((ymixing * ymixing - 1.) * (ymixing * ymixing - 1.)))) + / ((ymixing * ymixing - 1) * (b * xmixing - a) + (xmixing * xmixing + 1) * (c - d * ymixing)); + // printf("device avg tau: %.5g with A2: %.5g, B2: %.5g, ABr:%.5g, ABi:%.5g, x:%.5g, y:%.5g, tau:%.5g \n", + // averagetau, A2, B2, ABr, ABi, xmixing, ymixing, tau); return averagetau; } -__device__ device_resfunction_ptr ptr_to_truth = device_truth_resolution; +__device__ device_resfunction_ptr ptr_to_truth = device_truth_resolution; __device__ device_calc_tau_fcn_ptr ptr_to_calc_tau = device_truth_resolution_average_tau; TruthResolution::TruthResolution() @@ -46,20 +55,19 @@ TruthResolution::TruthResolution() } TruthResolution::~TruthResolution() = default; -fptype TruthResolution::normalisation(fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, - fptype ymixing) const { - fptype timeIntegralOne = tau / (1 - ymixing*ymixing); - fptype timeIntegralTwo = tau / (1 + xmixing*xmixing); +fptype TruthResolution::normalisation( + fptype di1, fptype di2, fptype di3, fptype di4, fptype tau, fptype xmixing, fptype ymixing) const { + fptype timeIntegralOne = tau / (1 - ymixing * ymixing); + fptype timeIntegralTwo = tau / (1 + xmixing * xmixing); fptype timeIntegralThr = ymixing * timeIntegralOne; fptype timeIntegralFou = xmixing * timeIntegralTwo; fptype ret = timeIntegralOne * (di1 + di2); - ret += timeIntegralTwo * (di1 - di2); - ret -= 2*timeIntegralThr * di3; - ret -= 2*timeIntegralFou * di4; + ret += timeIntegralTwo * (di1 - di2); + ret -= 2 * timeIntegralThr * di3; + ret -= 2 * timeIntegralFou * di4; return ret; } } // namespace GooFit - diff --git a/src/PDFs/VoigtianPdf.cu b/src/PDFs/VoigtianPdf.cu index 80b502dba..090ce9e31 100644 --- a/src/PDFs/VoigtianPdf.cu +++ b/src/PDFs/VoigtianPdf.cu @@ -1,49 +1,54 @@ #include "goofit/PDFs/basic/VoigtianPdf.h" -#include #include "goofit/Faddeeva.h" +#include #include namespace GooFit { - #define M_2PI 6.28318530717958 //#define ROOT2 1.41421356 // tables for Pade approximation -__constant__ fptype C[7] = { 65536.0, -2885792.0, 69973904.0, -791494704.0, - 8962513560.0, -32794651890.0, 175685635125.0 - }; -__constant__ fptype D[7] = { 192192.0, 8648640.0, 183783600.0, 2329725600.0, - 18332414100.0, 84329104860.0, 175685635125.0 - }; - +__constant__ fptype C[7] + = {65536.0, -2885792.0, 69973904.0, -791494704.0, 8962513560.0, -32794651890.0, 175685635125.0}; +__constant__ fptype D[7] + = {192192.0, 8648640.0, 183783600.0, 2329725600.0, 18332414100.0, 84329104860.0, 175685635125.0}; //#define UNROLL_LOOP 1 #ifndef UNROLL_LOOP -__constant__ fptype n1[12] = { 0.25, 1.0, 2.25, 4.0, 6.25, 9.0, 12.25, 16.0, 20.25, 25.0, 30.25, 36.0 }; -__constant__ fptype e1[12] = { 0.7788007830714049, 0.3678794411714423, - 1.053992245618643e-1, 1.831563888873418e-2, - 1.930454136227709e-3, 1.234098040866795e-4, - 4.785117392129009e-6, 1.125351747192591e-7, - 1.605228055185612e-9, 1.388794386496402e-11, - 7.287724095819692e-14, 2.319522830243569e-16 - }; +__constant__ fptype n1[12] = {0.25, 1.0, 2.25, 4.0, 6.25, 9.0, 12.25, 16.0, 20.25, 25.0, 30.25, 36.0}; +__constant__ fptype e1[12] = {0.7788007830714049, + 0.3678794411714423, + 1.053992245618643e-1, + 1.831563888873418e-2, + 1.930454136227709e-3, + 1.234098040866795e-4, + 4.785117392129009e-6, + 1.125351747192591e-7, + 1.605228055185612e-9, + 1.388794386496402e-11, + 7.287724095819692e-14, + 2.319522830243569e-16}; // table 2: coefficients for h = 0.53 -__constant__ fptype n2[12] = { 0.2809, 1.1236, 2.5281, 4.4944, 7.0225, 10.1124, - 13.7641, 17.9776, 22.7529, 28.09, 33.9889, 40.4496 - }; -__constant__ fptype e2[12] = { 0.7551038420890235, 0.3251072991205958, - 7.981051630007964e-2, 1.117138143353082e-2, - 0.891593719995219e-3, 4.057331392320188e-5, - 1.052755021528803e-6, 1.557498087816203e-8, - 1.313835773243312e-10, 6.319285885175346e-13, - 1.733038792213266e-15, 2.709954036083074e-18 - }; - -__device__ thrust::complex device_Faddeeva_2(const thrust::complex& z) { - fptype* n, *e, t, u, r, s, d, f, g, h; +__constant__ fptype n2[12] + = {0.2809, 1.1236, 2.5281, 4.4944, 7.0225, 10.1124, 13.7641, 17.9776, 22.7529, 28.09, 33.9889, 40.4496}; +__constant__ fptype e2[12] = {0.7551038420890235, + 0.3251072991205958, + 7.981051630007964e-2, + 1.117138143353082e-2, + 0.891593719995219e-3, + 4.057331392320188e-5, + 1.052755021528803e-6, + 1.557498087816203e-8, + 1.313835773243312e-10, + 6.319285885175346e-13, + 1.733038792213266e-15, + 2.709954036083074e-18}; + +__device__ thrust::complex device_Faddeeva_2(const thrust::complex &z) { + fptype *n, *e, t, u, r, s, d, f, g, h; thrust::complex c, d2, v; int i; @@ -51,17 +56,18 @@ __device__ thrust::complex device_Faddeeva_2(const thrust::complex zz = z*z; - v = exp(zz); // Note lower-case! This is our own already-templated exp function for thrust::complex, no need for float/double define. + thrust::complex zz = z * z; + v = exp(zz); // Note lower-case! This is our own already-templated exp function for thrust::complex, no need for + // float/double define. c = C[0]; d2 = D[0]; for(i = 1; i <= 6; i++) { - c = c * zz + C[i]; + c = c * zz + C[i]; d2 = d2 * zz + D[i]; } - return fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c/d2 * z * v; + return fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c / d2 * z * v; } // use trapezoid rule @@ -74,7 +80,7 @@ __device__ thrust::complex device_Faddeeva_2(const thrust::complex device_Faddeeva_2(const thrust::complex(z.imag() * (u + 2.0 * g), - z.real() * (u + 2.0 * h)); + c = r * thrust::complex(z.imag() * (u + 2.0 * g), z.real() * (u + 2.0 * h)); if(z.imag() < M_2PI) { s = 2.0 / r; @@ -108,8 +113,8 @@ __device__ thrust::complex device_Faddeeva_2(const thrust::complex device_Faddeeva_2(const thrust::complex device_Faddeeva_2(const thrust::complex& z) { +__device__ thrust::complex device_Faddeeva_2(const thrust::complex &z) { fptype u, s, d, f, g, h; thrust::complex c, d2, v; @@ -128,128 +133,128 @@ __device__ thrust::complex device_Faddeeva_2(const thrust::complex zz = z*z; - v = exp(zz); // Note lower-case! This is our own already-templated exp function for thrust::complex, no need for float/double define. + thrust::complex zz = z * z; + v = exp(zz); // Note lower-case! This is our own already-templated exp function for thrust::complex, no need for + // float/double define. c = C[0]; d2 = D[0]; for(int i = 1; i < 7; ++i) { - c = c * zz + C[i]; + c = c * zz + C[i]; d2 = d2 * zz + D[i]; } - return fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c/d2 * z * v; + return fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c / d2 * z * v; } // use trapezoid rule - fptype r = M_1_PI * 0.5; + fptype r = M_1_PI * 0.5; bool useDefault = true; // if z is too close to a pole select table 2 if(fabs(z.imag) < 0.01 && fabs(z.real) < 6.01) { // h = modf(2*fabs(z.real),&g); // Equivalent to above. Do this way because nvcc only knows about double version of modf. - h = fabs(z.real)*2; + h = fabs(z.real) * 2; g = floor(h); h -= g; if(h < 0.02 || h > 0.98) { useDefault = false; - r = M_1_PI * 0.53; + r = M_1_PI * 0.53; } } d = (z.imag - z.real) * (z.imag + z.real); f = 4 * z.real * z.real * z.imag * z.imag; - g = h = 0.0; + g = h = 0.0; fptype currentN = (useDefault ? 0.25 : 0.2809); fptype currentE = (useDefault ? 0.7788007830714049 : 0.7551038420890235); - fptype t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + fptype t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 1.0 : 1.1236); currentE = (useDefault ? 0.3678794411714423 : 0.3251072991205958); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 2.25 : 2.5281); - currentE = (useDefault ? 1.053992245618643e-1 : 7.981051630007964e-2); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.053992245618643e-1 : 7.981051630007964e-2); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 4.0 : 4.4944); - currentE = (useDefault ? 1.930454136227709e-3 : 0.891593719995219e-3); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.930454136227709e-3 : 0.891593719995219e-3); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 6.25 : 7.0225); - currentE = (useDefault ? 4.785117392129009e-6 : 1.052755021528803e-6); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 4.785117392129009e-6 : 1.052755021528803e-6); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 9.0 : 10.1124); - currentE = (useDefault ? 1.605228055185612e-9 : 1.313835773243312e-10); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.605228055185612e-9 : 1.313835773243312e-10); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 12.25 : 13.7641); currentE = (useDefault ? 7.287724095819692e-14 : 1.733038792213266e-15); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 16.0 : 17.9776); - currentE = (useDefault ? 1.831563888873418e-2 : 1.117138143353082e-2); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.831563888873418e-2 : 1.117138143353082e-2); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 20.25 : 22.7529); - currentE = (useDefault ? 1.234098040866795e-4 : 4.057331392320188e-5); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.234098040866795e-4 : 4.057331392320188e-5); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 25.0 : 28.09); - currentE = (useDefault ? 1.125351747192591e-7 : 1.557498087816203e-8); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + currentE = (useDefault ? 1.125351747192591e-7 : 1.557498087816203e-8); + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 30.25 : 33.9889); currentE = (useDefault ? 1.388794386496402e-11 : 6.319285885175346e-13); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; currentN = (useDefault ? 36.0 : 40.4496); currentE = (useDefault ? 2.319522830243569e-16 : 2.709954036083074e-18); - t = d + currentN; - u = currentE / (t*t + f); - g += (s + currentN)*u; - h += (s - currentN)*u; + t = d + currentN; + u = currentE / (t * t + f); + g += (s + currentN) * u; + h += (s - currentN) * u; u = 1 / s; - c = r * thrust::complex(z.imag * (u + 2.0 * g), - z.real * (u + 2.0 * h)); + c = r * thrust::complex(z.imag * (u + 2.0 * g), z.real * (u + 2.0 * h)); if(z.imag < M_2PI) { s = 2.0 / r; @@ -257,8 +262,8 @@ __device__ thrust::complex device_Faddeeva_2(const thrust::complex device_Faddeeva_2(const thrust::complex 0); // No device-side assert?! - //assert(w > 0); + // assert(s > 0); // No device-side assert?! + // assert(w > 0); fptype arg = x - m; // Breit-Wigner for zero sigma - if(0==s) - return (1/(arg*arg+0.25*w*w)); + if(0 == s) + return (1 / (arg * arg + 0.25 * w * w)); - fptype coef = -0.5/(s*s); + fptype coef = -0.5 / (s * s); // Gauss for zero width - if(0==w) - return exp(coef*arg*arg); + if(0 == w) + return exp(coef * arg * arg); // actual Voigtian for non-trivial width and sigma - //fptype c = 1./(ROOT2*s); + // fptype c = 1./(ROOT2*s); fptype c = 0.707106781187; // 1/root(2) c /= s; - fptype a = 0.5*c*w; - fptype u = c*arg; - thrust::complex z(u, a) ; + fptype a = 0.5 * c * w; + fptype u = c * arg; + thrust::complex z(u, a); thrust::complex v = device_Faddeeva_2(z); #define rsqrtPi 0.5641895835477563 - return c*rsqrtPi*v.real(); + return c * rsqrtPi * v.real(); } __device__ device_function_ptr ptr_to_Voigtian = device_Voigtian; -__host__ VoigtianPdf::VoigtianPdf(std::string n, Variable* _x, Variable* m, Variable* s, Variable* w) +__host__ VoigtianPdf::VoigtianPdf(std::string n, Variable *_x, Variable *m, Variable *s, Variable *w) : GooPdf(_x, n) { std::vector pindices; pindices.push_back(registerParameter(m)); @@ -321,4 +325,3 @@ __host__ VoigtianPdf::VoigtianPdf(std::string n, Variable* _x, Variable* m, Vari } } // namespace GooFit - diff --git a/src/goofit/Abort.cc b/src/goofit/Abort.cc index b7779d958..28bcb9479 100644 --- a/src/goofit/Abort.cc +++ b/src/goofit/Abort.cc @@ -6,31 +6,31 @@ namespace GooFit { -void abort(std::string file, int line, std::string reason, const PdfBase* pdf) { - void* stackarray[20]; - - std::cout << GooFit::reset << GooFit::red << "Abort called from " << file << " line " << line << " due to " << reason << std::endl; - +void abort(std::string file, int line, std::string reason, const PdfBase *pdf) { + void *stackarray[20]; + + std::cout << GooFit::reset << GooFit::red << "Abort called from " << file << " line " << line << " due to " + << reason << std::endl; + if(pdf) { - std::vector pars = pdf->getParameters(); + std::vector pars = pdf->getParameters(); std::cout << "Parameters of " << pdf->getName() << " : \n"; - - for(Variable* v : pars) { + + for(Variable *v : pars) { if(0 > v->getIndex()) continue; - - std::cout << " " << v->getName() << " (" << v->getIndex() << ") :\t" << host_params[v->getIndex()] << std::endl; + + std::cout << " " << v->getName() << " (" << v->getIndex() << ") :\t" << host_params[v->getIndex()] + << std::endl; } } - + std::cout << "Parameters (" << totalParams << ") :\n"; - + for(int i = 0; i < totalParams; ++i) { std::cout << host_params[i] << " "; } - - - + #if Backtrace_FOUND std::cout << GooFit::bold << std::endl; // get void* pointers for all entries on the stack @@ -40,7 +40,7 @@ void abort(std::string file, int line, std::string reason, const PdfBase* pdf) { #endif std::cout << GooFit::reset << std::flush; - + throw GooFit::GeneralError(reason); } diff --git a/src/goofit/BinnedDataSet.cc b/src/goofit/BinnedDataSet.cc index cab1a05f4..3e6dddfb7 100644 --- a/src/goofit/BinnedDataSet.cc +++ b/src/goofit/BinnedDataSet.cc @@ -8,33 +8,31 @@ namespace GooFit { - // Special constructor for one variable -BinnedDataSet::BinnedDataSet(Variable* var, std::string n) +BinnedDataSet::BinnedDataSet(Variable *var, std::string n) : DataSet(var, n) { collectBins(); binvalues.resize(getNumBins()); } -BinnedDataSet::BinnedDataSet(std::vector& vars, std::string n) +BinnedDataSet::BinnedDataSet(std::vector &vars, std::string n) : DataSet(vars, n) { collectBins(); binvalues.resize(getNumBins()); } -BinnedDataSet::BinnedDataSet(std::set& vars, std::string n) +BinnedDataSet::BinnedDataSet(std::set &vars, std::string n) : DataSet(vars, n) { collectBins(); binvalues.resize(getNumBins()); } -BinnedDataSet::BinnedDataSet(std::initializer_list vars, std::string n) -: DataSet(vars, n) { +BinnedDataSet::BinnedDataSet(std::initializer_list vars, std::string n) + : DataSet(vars, n) { collectBins(); binvalues.resize(getNumBins()); } - void BinnedDataSet::addEvent() { checkAllVars(); size_t ibin = getBinNumber(); @@ -52,22 +50,22 @@ void BinnedDataSet::addWeightedEvent(double weight) { void BinnedDataSet::collectBins() { // Not really intended to be run multiple times, but just in case binsizes.clear(); - - for(Variable* var : variables) + + for(Variable *var : variables) binsizes.push_back(var->getNumBins()); } size_t BinnedDataSet::getBinNumber() const { - std::vector vals = getCurrentValues(); + std::vector vals = getCurrentValues(); std::vector locals = convertValuesToBins(vals); return localToGlobal(locals); } -size_t BinnedDataSet::localToGlobal(const std::vector& locals) const { +size_t BinnedDataSet::localToGlobal(const std::vector &locals) const { unsigned int priorMatrixSize = 1; - unsigned int ret = 0; + unsigned int ret = 0; - for(size_t i=0; i BinnedDataSet::globalToLocal(size_t global) const { // To convert global bin number to (x,y,z...) coordinates: For each dimension, take the mod // with the number of bins in that dimension. Then divide by the number of bins, in effect // collapsing so the grid has one fewer dimension. Rinse and repeat. - - for(size_t i=0; i BinnedDataSet::globalToLocal(size_t global) const { fptype BinnedDataSet::getBinCenter(size_t ivar, size_t bin) const { std::vector locals = globalToLocal(bin); - size_t localBin = locals.at(ivar); - + size_t localBin = locals.at(ivar); + fptype ret = getBinSize(ivar); - ret *= (localBin + 0.5); - ret += variables[ivar]->getLowerLimit(); + ret *= (localBin + 0.5); + ret += variables[ivar]->getLowerLimit(); return ret; } -fptype BinnedDataSet::getBinCenter(Variable* var, size_t bin) const { +fptype BinnedDataSet::getBinCenter(Variable *var, size_t bin) const { size_t ivar = indexOfVariable(var); return getBinCenter(ivar, bin); } @@ -110,11 +108,10 @@ fptype BinnedDataSet::getBinSize(size_t ivar) const { return (variables.at(ivar)->getUpperLimit() - variables[ivar]->getLowerLimit()) / binsizes[ivar]; } - fptype BinnedDataSet::getBinVolume(size_t bin) const { fptype ret = 1; - for(size_t i=0; i()); + return std::accumulate(std::begin(binsizes), std::end(binsizes), 1, std::multiplies()); } fptype BinnedDataSet::getNumWeightedEvents() const { - return std::accumulate(std::begin(binvalues), - std::end(binvalues), 0); + return std::accumulate(std::begin(binvalues), std::end(binvalues), 0); } -std::vector BinnedDataSet::convertValuesToBins(const std::vector& vals) const { +std::vector BinnedDataSet::convertValuesToBins(const std::vector &vals) const { if(vals.size() != variables.size()) throw GooFit::GeneralError("Incorrect number of bins {} for {} variables", vals.size(), variables.size()); std::vector localBins; - for(size_t i=0; igetLowerLimit()),variables[i]->getUpperLimit()); + fptype betval = std::min(std::max(currval, variables[i]->getLowerLimit()), variables[i]->getUpperLimit()); if(currval != betval) GOOFIT_INFO("Warning: Value {} outside {} range [{},{}] - clamping to {}", - currval, variables[i]->getName(), variables[i]->getLowerLimit(), - variables[i]->getUpperLimit(), betval); - localBins.push_back( static_cast( floor((betval - variables[i]->getLowerLimit())/getBinSize(i)))); + currval, + variables[i]->getName(), + variables[i]->getLowerLimit(), + variables[i]->getUpperLimit(), + betval); + localBins.push_back(static_cast(floor((betval - variables[i]->getLowerLimit()) / getBinSize(i)))); } - return localBins; } } // namespace GooFit - diff --git a/src/goofit/DataSet.cc b/src/goofit/DataSet.cc index bd9b4a665..adf6eeefa 100644 --- a/src/goofit/DataSet.cc +++ b/src/goofit/DataSet.cc @@ -8,47 +8,47 @@ namespace GooFit { - -DataSet::DataSet(Variable* var, std::string n) -: name(std::move(n)), variables({var}) { +DataSet::DataSet(Variable *var, std::string n) + : name(std::move(n)) + , variables({var}) { generateName(); } -DataSet::DataSet(std::vector& vars, std::string n) - : name(std::move(n)), variables(vars) { - generateName(); +DataSet::DataSet(std::vector &vars, std::string n) + : name(std::move(n)) + , variables(vars) { + generateName(); } -DataSet::DataSet(std::set& vars, std::string n) -: name(std::move(n)), variables(std::begin(vars), std::end(vars)) { +DataSet::DataSet(std::set &vars, std::string n) + : name(std::move(n)) + , variables(std::begin(vars), std::end(vars)) { generateName(); } -DataSet::DataSet(std::initializer_list vars, std::string n) : - name(std::move(n)), variables(vars) { +DataSet::DataSet(std::initializer_list vars, std::string n) + : name(std::move(n)) + , variables(vars) { generateName(); } - void DataSet::addWeightedEvent(fptype) { throw GooFit::GeneralError("AddWeightedEvent not implemented for this type of DataSet"); } - std::vector DataSet::getCurrentValues() const { - std::vector values; +std::vector DataSet::getCurrentValues() const { + std::vector values; - for(Variable* v : variables) { + for(Variable *v : variables) { values.push_back(v->getValue()); } return values; } -const std::vector& DataSet::getVariables() const { - return variables; -} +const std::vector &DataSet::getVariables() const { return variables; } -size_t DataSet::indexOfVariable(Variable* var) const { +size_t DataSet::indexOfVariable(Variable *var) const { for(size_t i = 0; i < variables.size(); ++i) if(var == variables[i]) return i; @@ -60,8 +60,8 @@ void DataSet::generateName() { // Create default name as list of variables. if(name != "") return; - - for(Variable* v : variables) { + + for(Variable *v : variables) { if(v != variables[0]) name += ", "; name += v->getName(); @@ -69,10 +69,9 @@ void DataSet::generateName() { } void DataSet::checkAllVars() const { - for(Variable* v : variables) { + for(Variable *v : variables) { if(!*v) throw GooFit::OutOfRange(v->getName(), v->getValue(), v->getLowerLimit(), v->getUpperLimit()); } } } // namespace GooFit - diff --git a/src/goofit/FCN.cc b/src/goofit/FCN.cc index 01e4ce06b..d8314e555 100644 --- a/src/goofit/FCN.cc +++ b/src/goofit/FCN.cc @@ -6,70 +6,64 @@ namespace GooFit { -FCN::FCN(Params& params) : params_(¶ms) { +FCN::FCN(Params ¶ms) + : params_(¶ms) { host_callnumber = 0; - + // Verify that all varaibles need to be recached - for(Variable* var : params_->vars_) + for(Variable *var : params_->vars_) var->setChanged(true); - } -double FCN::operator()(const std::vector& pars) const { - +double FCN::operator()(const std::vector &pars) const { // Translate from Minuit indexing to GooFit indexing - std::vector gooPars(max_index(params_->vars_)+1); - - for(Variable* var : params_->vars_) { + std::vector gooPars(max_index(params_->vars_) + 1); + + for(Variable *var : params_->vars_) { var->setChanged(var->getValue() != pars.at(var->getFitterIndex())); gooPars.at(var->getIndex()) = pars.at(var->getFitterIndex()) - var->blind; } params_->pdf_->copyParams(gooPars); - + GOOFIT_TRACE("Calculating NLL"); double nll = params_->pdf_->calculateNLL(); - + host_callnumber++; return nll; } double FCN::operator()() const { - std::vector pars = makePars(); - + // Translate from Minuit indexing to GooFit indexing - std::vector gooPars(max_index(params_->vars_)+1); - - for(Variable* var : params_->vars_) { + std::vector gooPars(max_index(params_->vars_) + 1); + + for(Variable *var : params_->vars_) { var->setChanged(true); gooPars.at(var->getIndex()) = pars.at(var->getFitterIndex()) - var->blind; } - + params_->pdf_->copyParams(gooPars); - + GOOFIT_TRACE("Calculating NLL"); double nll = params_->pdf_->calculateNLL(); - + host_callnumber++; - + return nll; } - - std::vector FCN::makePars() const { - std::vector minuitPars(max_fitter_index(params_->vars_)+1); - for(Variable* var : params_->vars_) { + std::vector minuitPars(max_fitter_index(params_->vars_) + 1); + for(Variable *var : params_->vars_) { minuitPars.at(var->getFitterIndex()) = var->getValue(); } return minuitPars; } // Get the number of variable parameters -Params* FCN::GetParams() { - return params_; -} - +Params *FCN::GetParams() { return params_; } + } // namespace GooFit diff --git a/src/goofit/Faddeeva.cc b/src/goofit/Faddeeva.cc index efbee2c40..390bff874 100644 --- a/src/goofit/Faddeeva.cc +++ b/src/goofit/Faddeeva.cc @@ -7,64 +7,65 @@ namespace GooFit { - #define M_2PI 6.28318530717958 -static fptype n1[12] = { 0.25, 1.0, 2.25, 4.0, 6.25, 9.0, 12.25, 16.0, 20.25, 25.0, 30.25, 36.0 }; -static fptype e1[12] = { 0.7788007830714049, 0.3678794411714423, - 1.053992245618643e-1, 1.831563888873418e-2, - 1.930454136227709e-3, 1.234098040866795e-4, - 4.785117392129009e-6, 1.125351747192591e-7, - 1.605228055185612e-9, 1.388794386496402e-11, - 7.287724095819692e-14, 2.319522830243569e-16 - }; +static fptype n1[12] = {0.25, 1.0, 2.25, 4.0, 6.25, 9.0, 12.25, 16.0, 20.25, 25.0, 30.25, 36.0}; +static fptype e1[12] = {0.7788007830714049, + 0.3678794411714423, + 1.053992245618643e-1, + 1.831563888873418e-2, + 1.930454136227709e-3, + 1.234098040866795e-4, + 4.785117392129009e-6, + 1.125351747192591e-7, + 1.605228055185612e-9, + 1.388794386496402e-11, + 7.287724095819692e-14, + 2.319522830243569e-16}; // table 2: coefficients for h = 0.53 -static fptype n2[12] = { 0.2809, 1.1236, 2.5281, 4.4944, 7.0225, 10.1124, - 13.7641, 17.9776, 22.7529, 28.09, 33.9889, 40.4496 - }; -static fptype e2[12] = { 0.7551038420890235, 0.3251072991205958, - 7.981051630007964e-2, 1.117138143353082e-2, - 0.891593719995219e-3, 4.057331392320188e-5, - 1.052755021528803e-6, 1.557498087816203e-8, - 1.313835773243312e-10, 6.319285885175346e-13, - 1.733038792213266e-15, 2.709954036083074e-18 - }; +static fptype n2[12] + = {0.2809, 1.1236, 2.5281, 4.4944, 7.0225, 10.1124, 13.7641, 17.9776, 22.7529, 28.09, 33.9889, 40.4496}; +static fptype e2[12] = {0.7551038420890235, + 0.3251072991205958, + 7.981051630007964e-2, + 1.117138143353082e-2, + 0.891593719995219e-3, + 4.057331392320188e-5, + 1.052755021528803e-6, + 1.557498087816203e-8, + 1.313835773243312e-10, + 6.319285885175346e-13, + 1.733038792213266e-15, + 2.709954036083074e-18}; // tables for Pade approximation -static fptype C[7] = { 65536.0, -2885792.0, 69973904.0, -791494704.0, - 8962513560.0, -32794651890.0, 175685635125.0 - }; -static fptype D[7] = { 192192.0, 8648640.0, 183783600.0, 2329725600.0, - 18332414100.0, 84329104860.0, 175685635125.0 - }; - +static fptype C[7] = {65536.0, -2885792.0, 69973904.0, -791494704.0, 8962513560.0, -32794651890.0, 175685635125.0}; +static fptype D[7] = {192192.0, 8648640.0, 183783600.0, 2329725600.0, 18332414100.0, 84329104860.0, 175685635125.0}; -thrust::complex Faddeeva_2(const thrust::complex& z) { - fptype* n, *e, t, u, r, s, d, f, g, h; +thrust::complex Faddeeva_2(const thrust::complex &z) { + fptype *n, *e, t, u, r, s, d, f, g, h; thrust::complex c, d2, v, w; int i; - s = norm(z); // Actually the square of the norm. Don't ask me, I didn't name the function. if(s < 1e-7) { // use Pade approximation - thrust::complex zz = z*z; - v = exp(zz); - c = C[0]; - d2 = D[0]; + thrust::complex zz = z * z; + v = exp(zz); + c = C[0]; + d2 = D[0]; for(i = 1; i <= 6; i++) { - c = c * zz + C[i]; + c = c * zz + C[i]; d2 = d2 * zz + D[i]; } - w = fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c/d2 * z * v; + w = fptype(1.0) / v + thrust::complex(0.0, M_2_SQRTPI) * c / d2 * z * v; return w; } - // use trapezoid rule // select default table 1 n = n1; @@ -73,8 +74,7 @@ thrust::complex Faddeeva_2(const thrust::complex& z) { // if z is too close to a pole select table 2 if(fabs(z.imag()) < 0.01 && fabs(z.real()) < 6.01) { - - h = fabs(z.real())*2; + h = fabs(z.real()) * 2; // Equivalent to modf(h, &g). Do this way because nvcc only knows about double version of modf. g = floor(h); h -= g; @@ -100,9 +100,7 @@ thrust::complex Faddeeva_2(const thrust::complex& z) { u = 1 / s; - c = r * thrust::complex(z.imag() * (u + 2.0 * g), - z.real() * (u + 2.0 * h)); - + c = r * thrust::complex(z.imag() * (u + 2.0 * g), z.real() * (u + 2.0 * h)); if(z.imag() < M_2PI) { s = 2.0 / r; @@ -110,8 +108,8 @@ thrust::complex Faddeeva_2(const thrust::complex& z) { u = s * z.imag(); s = sin(t); h = cos(t); - f = exp(- u) - h; - g = 2.0 * exp(d-u) / (s * s + f * f); + f = exp(-u) - h; + g = 2.0 * exp(d - u) / (s * s + f * f); u = 2.0 * z.real() * z.imag(); h = cos(u); t = sin(u); @@ -126,33 +124,32 @@ fptype cpuvoigtian(fptype x, fptype m, fptype w, fptype s) { // over the reals is equal to one. // return constant for zero width and sigma - if((0==s) && (0==w)) + if((0 == s) && (0 == w)) return 1; if(s <= 0 || w <= 0) throw GooFit::GeneralError("s {} and w {} must be larger than 0", s, w); - fptype coef = -0.5/(s*s); - fptype arg = x - m; + fptype coef = -0.5 / (s * s); + fptype arg = x - m; // Breit-Wigner for zero sigma - if(0==s) - return (1/(arg*arg+0.25*w*w)); + if(0 == s) + return (1 / (arg * arg + 0.25 * w * w)); // Gauss for zero width - if(0==w) - return exp(coef*arg*arg); + if(0 == w) + return exp(coef * arg * arg); // actual Voigtian for non-trivial width and sigma - fptype c = 1./(sqrt(2)*s); - fptype a = 0.5*c*w; - fptype u = c*arg; - thrust::complex z(u, a) ; - //printf("Calling Faddeeva %f %f %f %f %f %f %f\n", x, m, s, w, c, a, u); + fptype c = 1. / (sqrt(2) * s); + fptype a = 0.5 * c * w; + fptype u = c * arg; + thrust::complex z(u, a); + // printf("Calling Faddeeva %f %f %f %f %f %f %f\n", x, m, s, w, c, a, u); thrust::complex v = Faddeeva_2(z); static const fptype rsqrtPi = 0.5641895835477563; - return c*rsqrtPi*v.real(); + return c * rsqrtPi * v.real(); } } // namespace GooFit - diff --git a/src/goofit/FitManagerMinuit1.cc b/src/goofit/FitManagerMinuit1.cc index 936baaefb..46d434f5c 100644 --- a/src/goofit/FitManagerMinuit1.cc +++ b/src/goofit/FitManagerMinuit1.cc @@ -10,59 +10,56 @@ namespace GooFit { -Minuit1::Minuit1(PdfBase* pdfPointer) : TMinuit(max_index(pdfPointer->getParameters())+1), pdfPointer(pdfPointer), vars(pdfPointer->getParameters()) { +Minuit1::Minuit1(PdfBase *pdfPointer) + : TMinuit(max_index(pdfPointer->getParameters()) + 1) + , pdfPointer(pdfPointer) + , vars(pdfPointer->getParameters()) { size_t counter = 0; - - for(Variable* var : vars) { + + for(Variable *var : vars) { var->setFitterIndex(counter); - + Int_t err = DefineParameter(counter, - var->getName().c_str(), - var->getValue(), - var->getError(), - var->getLowerLimit(), - var->getUpperLimit()); - - if(GetNumPars() != counter+1) - throw GooFit::GeneralError("Error when implementing param {} (possibly invalid error/lowerlimit/upperlimit values)!", var->getName()); - + var->getName().c_str(), + var->getValue(), + var->getError(), + var->getLowerLimit(), + var->getUpperLimit()); + + if(GetNumPars() != counter + 1) + throw GooFit::GeneralError( + "Error when implementing param {} (possibly invalid error/lowerlimit/upperlimit values)!", + var->getName()); + if(err != 0) throw GooFit::GeneralError("Was not able to implement param {} (error {})", var->getName(), err); - + if(var->IsFixed()) FixParameter(counter); - + counter++; } - - pdfPointer->copyParams(); + pdfPointer->copyParams(); } +Int_t Minuit1::Eval(int npar, double *gin, double &fun, double *fp, int iflag) { + std::vector pars{fp, fp + GetNumPars()}; -Int_t Minuit1::Eval( - int npar, - double* gin, - double& fun, - double* fp, - int iflag) { - - std::vector pars {fp, fp+GetNumPars()}; - std::vector gooPars; - gooPars.resize(max_index(vars)+1); - - for(Variable* var : vars) { + gooPars.resize(max_index(vars) + 1); + + for(Variable *var : vars) { if(std::isnan(pars.at(var->getFitterIndex()))) GOOFIT_WARN("Variable {} at {} is NaN", var->getName(), var->getIndex()); - + var->setChanged(var->getValue() != pars.at(var->getFitterIndex())); var->setValue(pars.at(var->getFitterIndex())); gooPars.at(var->getIndex()) = var->getValue() - var->blind; } - + pdfPointer->copyParams(gooPars); - + GOOFIT_TRACE("Calculating NLL"); fun = pdfPointer->calculateNLL(); host_callnumber++; @@ -71,16 +68,16 @@ Int_t Minuit1::Eval( void FitManagerMinuit1::fit() { host_callnumber = 0; - - for(Variable* var : minuit_.getVaraibles()) + + for(Variable *var : minuit_.getVaraibles()) var->setChanged(true); std::cout << GooFit::gray << GooFit::bold; - + if(0 < overrideCallLimit) { std::cout << "Calling MIGRAD with call limit " << overrideCallLimit << std::endl; double plist[1] = {overrideCallLimit}; - int err = 0; + int err = 0; if(_useHesseBefore) minuit_.mnexcm("HESSE", plist, 1, err); @@ -97,26 +94,21 @@ void FitManagerMinuit1::fit() { minuit_.mnexcm("IMPROVE", plist, 1, err); } else minuit_.Migrad(); - + std::cout << GooFit::reset; - + double tmp_value, tmp_error; - for(Variable* var : minuit_.getVaraibles()) { + for(Variable *var : minuit_.getVaraibles()) { minuit_.GetParameter(var->getFitterIndex(), tmp_value, tmp_error); var->setValue(tmp_value); var->setError(tmp_error); } - } - -void FitManagerMinuit1::getMinuitStatus(double& fmin, double& fedm, double& errdef, int& npari, int& nparx, int& istat) { +void FitManagerMinuit1::getMinuitStatus( + double &fmin, double &fedm, double &errdef, int &npari, int &nparx, int &istat) { minuit_.mnstat(fmin, fedm, errdef, npari, nparx, istat); - std::cout << "mnstat(fmin = " << fmin << ", fedm = " << fedm << ", errdef = " << errdef - << ", npari = " << npari << ", nparx = " << nparx << ", istat = " << istat << ")" << std::endl; + std::cout << "mnstat(fmin = " << fmin << ", fedm = " << fedm << ", errdef = " << errdef << ", npari = " << npari + << ", nparx = " << nparx << ", istat = " << istat << ")" << std::endl; } - } - - - diff --git a/src/goofit/FitManagerMinuit2.cc b/src/goofit/FitManagerMinuit2.cc index 04154d4dd..bcbb2853e 100644 --- a/src/goofit/FitManagerMinuit2.cc +++ b/src/goofit/FitManagerMinuit2.cc @@ -11,27 +11,29 @@ #include namespace GooFit { - -FitManagerMinuit2::FitManagerMinuit2(PdfBase* dat) : upar_(*dat), fcn_(upar_) {} + +FitManagerMinuit2::FitManagerMinuit2(PdfBase *dat) + : upar_(*dat) + , fcn_(upar_) {} Minuit2::FunctionMinimum FitManagerMinuit2::fit() { auto val = Minuit2::MnPrint::Level(); Minuit2::MnPrint::SetLevel(verbosity); - + // Setting global call number to 0 host_callnumber = 0; - + CLI::Timer timer{"The minimization took"}; - + Minuit2::MnMigrad migrad{fcn_, upar_}; - + // Do the minimization if(verbosity > 0) std::cout << GooFit::gray << GooFit::bold; - + CLI::Timer avetimer{"Average time per call"}; Minuit2::FunctionMinimum min = migrad(maxfcn_); - + // Print nice output if(verbosity > 0) { std::cout << GooFit::reset << (min.IsValid() ? GooFit::green : GooFit::red); @@ -39,11 +41,11 @@ Minuit2::FunctionMinimum FitManagerMinuit2::fit() { std::cout << GooFit::magenta << timer << GooFit::reset << std::endl; std::cout << avetimer / min.NFcn() << std::endl; } - + if(min.IsValid()) { retval_ = FitErrors::Valid; } else { - if (verbosity > 0) { + if(verbosity > 0) { std::cout << GooFit::red; std::cout << "HesseFailed: " << min.HesseFailed() << std::endl; std::cout << "HasCovariance: " << min.HasCovariance() << std::endl; @@ -52,21 +54,19 @@ Minuit2::FunctionMinimum FitManagerMinuit2::fit() { std::cout << "IsAboveMaxEdm: " << min.IsAboveMaxEdm() << std::endl; std::cout << "HasReachedCallLimit: " << min.HasReachedCallLimit() << std::endl; std::cout << "HasAccurateCovar: " << min.HasAccurateCovar() << std::endl; - std::cout << "HasPosDefCovar : " << min.HasPosDefCovar () << std::endl; - std::cout << "HasMadePosDefCovar : " << min.HasMadePosDefCovar () << std::endl; + std::cout << "HasPosDefCovar : " << min.HasPosDefCovar() << std::endl; + std::cout << "HasMadePosDefCovar : " << min.HasMadePosDefCovar() << std::endl; std::cout << GooFit::reset; } - + retval_ = FitErrors::InValid; } - + // Set the parameters in GooFit to the new values upar_.SetGooFitParams(min.UserState()); Minuit2::MnPrint::SetLevel(val); return min; } - -} // namespace GooFit - +} // namespace GooFit diff --git a/src/goofit/FunctorWriter.cc b/src/goofit/FunctorWriter.cc index 39c5be16b..0bb756c59 100644 --- a/src/goofit/FunctorWriter.cc +++ b/src/goofit/FunctorWriter.cc @@ -6,33 +6,26 @@ namespace GooFit { - -void writeToFile(PdfBase* pdf, const char* fname) { - std::vector params = pdf->getParameters(); +void writeToFile(PdfBase *pdf, const char *fname) { + std::vector params = pdf->getParameters(); std::ofstream writer; writer.open(fname); - for(Variable* p : params) { - writer << p->getName() << " " - << p->getValue() << " " - << p->getError() << " " - << p->getNumBins() << " " - << p->getLowerLimit() << " " - << p->getUpperLimit() - << std::endl; + for(Variable *p : params) { + writer << p->getName() << " " << p->getValue() << " " << p->getError() << " " << p->getNumBins() << " " + << p->getLowerLimit() << " " << p->getUpperLimit() << std::endl; } writer.close(); } +void readFromFile(PdfBase *pdf, const char *fname) { + std::vector params = pdf->getParameters(); -void readFromFile(PdfBase* pdf, const char* fname) { - std::vector params = pdf->getParameters(); - - std::map tempMap; + std::map tempMap; - for(Variable* p : params) { + for(Variable *p : params) { tempMap[p->getName()] = p; } @@ -48,18 +41,14 @@ void readFromFile(PdfBase* pdf, const char* fname) { if(reader.eof()) break; - Variable* var = tempMap[buffer]; - + Variable *var = tempMap[buffer]; + fptype value, error, lowerlimit, upperlimit; size_t numbins; if(var) { - reader >> value - >> error - >> numbins - >> lowerlimit - >> upperlimit; - + reader >> value >> error >> numbins >> lowerlimit >> upperlimit; + var->setValue(value); var->setError(error); var->setNumBins(numbins); @@ -76,7 +65,7 @@ void readFromFile(PdfBase* pdf, const char* fname) { reader.close(); } -void readListOfNumbers(thrust::host_vector& target, const char* fname) { +void readListOfNumbers(thrust::host_vector &target, const char *fname) { std::ifstream reader; reader.open(fname); fptype buffer = 0; @@ -93,7 +82,7 @@ void readListOfNumbers(thrust::host_vector& target, const char* fname) { reader.close(); } -void writeListOfNumbers(thrust::host_vector& target, const char* fname) { +void writeListOfNumbers(thrust::host_vector &target, const char *fname) { std::ofstream writer; writer.open(fname); @@ -104,4 +93,3 @@ void writeListOfNumbers(thrust::host_vector& target, const char* fname) writer.close(); } } // namespace GooFit - diff --git a/src/goofit/Params.cc b/src/goofit/Params.cc index bee920fd7..a749a07b4 100644 --- a/src/goofit/Params.cc +++ b/src/goofit/Params.cc @@ -5,10 +5,11 @@ namespace GooFit { - Params::Params(PdfBase &pdf) : pdf_(&pdf) { +Params::Params(PdfBase &pdf) + : pdf_(&pdf) { vars_ = pdf_->getParameters(); - - for(Variable* var : vars_) { + + for(Variable *var : vars_) { bool added; if(var->IsFixed()) { added = Add(var->getName(), var->getValue()); @@ -17,17 +18,16 @@ namespace GooFit { } else { added = Add(var->getName(), var->getValue(), var->getError(), var->getLowerLimit(), var->getUpperLimit()); } - + if(!added) throw std::runtime_error("The name " + var->getName() + " appears more than once!"); - + var->setFitterIndex(Index(var->getName())); } - } - -void Params::SetGooFitParams(const Minuit2::MnUserParameterState& input) { - for(Variable* var : vars_) { + +void Params::SetGooFitParams(const Minuit2::MnUserParameterState &input) { + for(Variable *var : vars_) { size_t counter = var->getFitterIndex(); var->setValue(input.Value(counter)); var->setError(input.Error(counter)); @@ -35,5 +35,5 @@ void Params::SetGooFitParams(const Minuit2::MnUserParameterState& input) { SetError(counter, var->getError()); } } - + } // namespace GooFit diff --git a/src/goofit/PdfBase.cc b/src/goofit/PdfBase.cc index 30fb32415..a14f01862 100644 --- a/src/goofit/PdfBase.cc +++ b/src/goofit/PdfBase.cc @@ -15,24 +15,23 @@ namespace GooFit { - -fptype* dev_event_array; +fptype *dev_event_array; fptype host_normalisation[maxParams]; fptype host_params[maxParams]; unsigned int host_indices[maxParams]; int host_callnumber = 0; -int totalParams = 0; -int totalConstants = 1; // First constant is reserved for number of events. -std::map> variableRegistry; +int totalParams = 0; +int totalConstants = 1; // First constant is reserved for number of events. +std::map> variableRegistry; -PdfBase::PdfBase(Variable* x, std::string n) +PdfBase::PdfBase(Variable *x, std::string n) : name(std::move(n)) { // Special-case PDFs should set to false. if(x) registerObservable(x); } -__host__ void PdfBase::checkInitStatus(std::vector& unInited) const { +__host__ void PdfBase::checkInitStatus(std::vector &unInited) const { if(!properlyInitialised) unInited.push_back(getName()); @@ -49,12 +48,12 @@ __host__ void PdfBase::recursiveSetNormalisation(fptype norm) const { } } -__host__ unsigned int PdfBase::registerParameter(Variable* var) { +__host__ unsigned int PdfBase::registerParameter(Variable *var) { if(var == nullptr) throw GooFit::GeneralError("{}: Can not register a nullptr", getName()); if(std::find(parameterList.begin(), parameterList.end(), var) != parameterList.end()) - return static_cast( var->getIndex()); + return static_cast(var->getIndex()); parameterList.push_back(var); variableRegistry[var].insert(this); @@ -65,7 +64,7 @@ __host__ unsigned int PdfBase::registerParameter(Variable* var) { while(true) { bool canUse = true; - for(auto & p : variableRegistry) { + for(auto &p : variableRegistry) { if(unusedIndex != p.first->getIndex()) continue; @@ -83,15 +82,15 @@ __host__ unsigned int PdfBase::registerParameter(Variable* var) { var->setIndex(unusedIndex); } - return static_cast( var->getIndex()); + return static_cast(var->getIndex()); } -__host__ void PdfBase::unregisterParameter(Variable* var) { +__host__ void PdfBase::unregisterParameter(Variable *var) { if(var == nullptr) return; GOOFIT_DEBUG("{}: Removing {}", getName(), var->getName()); - + auto pos = std::find(parameterList.begin(), parameterList.end(), var); if(pos != parameterList.end()) @@ -102,34 +101,31 @@ __host__ void PdfBase::unregisterParameter(Variable* var) { if(0 == variableRegistry[var].size()) var->setIndex(-1); - for(PdfBase* comp : components) { + for(PdfBase *comp : components) { comp->unregisterParameter(var); } } +__host__ std::vector PdfBase::getParameters() const { + std::vector ret = parameterList; -__host__ std::vector PdfBase::getParameters() const { - - std::vector ret = parameterList; - - for(const PdfBase* comp : components) { - for(Variable* sub_comp : comp->getParameters()) - if(std::find(std::begin(ret), std::end(ret), sub_comp)==std::end(ret)) + for(const PdfBase *comp : components) { + for(Variable *sub_comp : comp->getParameters()) + if(std::find(std::begin(ret), std::end(ret), sub_comp) == std::end(ret)) ret.push_back(sub_comp); } - + return ret; } - -__host__ Variable* PdfBase::getParameterByName(std::string n) const { - for(Variable* p : parameterList) { +__host__ Variable *PdfBase::getParameterByName(std::string n) const { + for(Variable *p : parameterList) { if(p->getName() == n) return p; } for(auto component : components) { - Variable* cand = component->getParameterByName(n); + Variable *cand = component->getParameterByName(n); if(cand) return cand; @@ -138,27 +134,28 @@ __host__ Variable* PdfBase::getParameterByName(std::string n) const { return nullptr; } -__host__ std::vector PdfBase::getObservables() const { - std::vector ret = observables; - - for(const PdfBase* comp : components) { - for(Variable* sub_comp : comp->getObservables()) - if(std::find(std::begin(ret), std::end(ret), sub_comp)==std::end(ret)) +__host__ std::vector PdfBase::getObservables() const { + std::vector ret = observables; + + for(const PdfBase *comp : components) { + for(Variable *sub_comp : comp->getObservables()) + if(std::find(std::begin(ret), std::end(ret), sub_comp) == std::end(ret)) ret.push_back(sub_comp); } - + return ret; } __host__ unsigned int PdfBase::registerConstants(unsigned int amount) { if(totalConstants + amount >= maxParams) - throw GooFit::GeneralError("totalConstants {} + amount {} can not be more than {}", totalConstants, amount, maxParams); + throw GooFit::GeneralError( + "totalConstants {} + amount {} can not be more than {}", totalConstants, amount, maxParams); cIndex = totalConstants; totalConstants += amount; return cIndex; } -void PdfBase::registerObservable(Variable* obs) { +void PdfBase::registerObservable(Variable *obs) { if(!obs) return; @@ -174,10 +171,10 @@ __host__ void PdfBase::setIntegrationFineness(int i) { } __host__ bool PdfBase::parametersChanged() const { - return std::any_of(std::begin(parameterList), std::end(parameterList), [](Variable* v){return v->getChanged();}); + return std::any_of(std::begin(parameterList), std::end(parameterList), [](Variable *v) { return v->getChanged(); }); } -__host__ void PdfBase::setNumPerTask(PdfBase* p, const int& c) { +__host__ void PdfBase::setNumPerTask(PdfBase *p, const int &c) { if(!p) return; @@ -190,4 +187,3 @@ __host__ ROOT::Minuit2::FunctionMinimum PdfBase::fitTo(DataSet *data) { return fitter.fit(); } } // namespace GooFit - diff --git a/src/goofit/UnbinnedDataSet.cc b/src/goofit/UnbinnedDataSet.cc index 153adb231..1fa9909a8 100644 --- a/src/goofit/UnbinnedDataSet.cc +++ b/src/goofit/UnbinnedDataSet.cc @@ -5,35 +5,35 @@ namespace GooFit { - // Special constructor for one variable -UnbinnedDataSet::UnbinnedDataSet(Variable* var, std::string n) -: DataSet(var, n) { +UnbinnedDataSet::UnbinnedDataSet(Variable *var, std::string n) + : DataSet(var, n) { data.resize(1); } -UnbinnedDataSet::UnbinnedDataSet(std::vector& vars, std::string n) -: DataSet(vars, n) { +UnbinnedDataSet::UnbinnedDataSet(std::vector &vars, std::string n) + : DataSet(vars, n) { data.resize(vars.size()); } -UnbinnedDataSet::UnbinnedDataSet(std::set& vars, std::string n) -: DataSet(vars, n) { +UnbinnedDataSet::UnbinnedDataSet(std::set &vars, std::string n) + : DataSet(vars, n) { data.resize(vars.size()); } -UnbinnedDataSet::UnbinnedDataSet(std::initializer_list vars, std::string n) -: DataSet(vars, n) { +UnbinnedDataSet::UnbinnedDataSet(std::initializer_list vars, std::string n) + : DataSet(vars, n) { data.resize(vars.size()); } -fptype UnbinnedDataSet::getValue(Variable* var, size_t idx) const { - +fptype UnbinnedDataSet::getValue(Variable *var, size_t idx) const { if(idx >= getNumEvents()) { throw GooFit::GeneralError("UnbinnedDataSet: Attepted to find {} in event {} when only {} events exits", - var->getName(), idx, getNumEvents()); + var->getName(), + idx, + getNumEvents()); } - + size_t var_idx = indexOfVariable(var); return data[var_idx].at(idx); @@ -41,14 +41,14 @@ fptype UnbinnedDataSet::getValue(Variable* var, size_t idx) const { void UnbinnedDataSet::loadEvent(size_t idx) { size_t i = 0; - for(Variable* v : variables) { + for(Variable *v : variables) { v->setValue(data.at(i++).at(idx)); } } -void UnbinnedDataSet::setValueForAllEvents(Variable* var) { +void UnbinnedDataSet::setValueForAllEvents(Variable *var) { size_t ivar = indexOfVariable(var); - for(size_t i=0; igetValue(); } } @@ -56,9 +56,8 @@ void UnbinnedDataSet::setValueForAllEvents(Variable* var) { void UnbinnedDataSet::addEvent() { checkAllVars(); size_t i = 0; - for(Variable* v : variables) + for(Variable *v : variables) data.at(i++).push_back(v->getValue()); numEventsAdded++; } } // namespace GooFit - diff --git a/src/goofit/Variable.cc b/src/goofit/Variable.cc index f6dc05204..b1f6699dd 100644 --- a/src/goofit/Variable.cc +++ b/src/goofit/Variable.cc @@ -3,26 +3,25 @@ #include - namespace GooFit { -int max_index(const std::vector &vars) { - const Variable* max_ind_ptr = *std::max_element(std::begin(vars), - std::end(vars), - [](const Variable *a, const Variable *b) - {return a->getIndex() < b->getIndex();}); +int max_index(const std::vector &vars) { + const Variable *max_ind_ptr + = *std::max_element(std::begin(vars), std::end(vars), [](const Variable *a, const Variable *b) { + return a->getIndex() < b->getIndex(); + }); return max_ind_ptr->getIndex(); } -int max_fitter_index(const std::vector &vars) { - const Variable* max_ind_ptr = *std::max_element(std::begin(vars), - std::end(vars), - [](const Variable *a, const Variable *b) - {return a->getFitterIndex() < b->getFitterIndex();}); +int max_fitter_index(const std::vector &vars) { + const Variable *max_ind_ptr + = *std::max_element(std::begin(vars), std::end(vars), [](const Variable *a, const Variable *b) { + return a->getFitterIndex() < b->getFitterIndex(); + }); return max_ind_ptr->getFitterIndex(); } -std::ostream& operator<< (std::ostream& o, const GooFit::Variable& var) { +std::ostream &operator<<(std::ostream &o, const GooFit::Variable &var) { o << var.getName() << ": " << var.getValue() << " +/- " << var.getError(); if(!var.fixed) o << " [" << var.getLowerLimit() << ", " << var.getUpperLimit() << "]"; @@ -32,13 +31,10 @@ std::ostream& operator<< (std::ostream& o, const GooFit::Variable& var) { o << " Fitter index: " << var.getFitterIndex(); if(var.blind != 0) o << " Blinded"; - + return o; } -std::istream& operator>> (std::istream& i, GooFit::Variable& var) { - return i >> var.value; -} +std::istream &operator>>(std::istream &i, GooFit::Variable &var) { return i >> var.value; } } // namespace GooFit - diff --git a/tests/BinnedTest.cu b/tests/BinnedTest.cu index cfa553bd1..4ed165b32 100644 --- a/tests/BinnedTest.cu +++ b/tests/BinnedTest.cu @@ -16,58 +16,55 @@ using namespace GooFit; TEST(BinnedFit, SimpleFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> d(1.5); - + // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set BinnedDataSet data(&xvar); - + // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { double val = d(gen); if(val < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf exppdf{"exppdf", &xvar, &alpha}; exppdf.setData(&data); - + FitManager fitter{&exppdf}; fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(alpha.getError(), .01); - EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError()*3); + EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError() * 3); } - TEST(BinnedFit, DualFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> dx(1.5); std::exponential_distribution<> dy(.75); - + // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - BinnedDataSet data {{&xvar, &yvar}}; - + BinnedDataSet data{{&xvar, &yvar}}; + // Generate toy events. - for(int i=0; i<200000; ++i) { + for(int i = 0; i < 200000; ++i) { double xval = dx(gen); double yval = dy(gen); if(xval < 10 && yval < 10) { @@ -76,44 +73,43 @@ TEST(BinnedFit, DualFit) { data.addEvent(); } } - + // Fit parameter Variable xalpha{"xalpha", -2, 0.1, -10, 10}; // Fit parameter Variable yalpha{"yalpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf xpdf{"xpdf", &xvar, &xalpha}; ExpPdf ypdf{"ypdf", &yvar, &yalpha}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + FitManager fitter{&totalpdf}; fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); } TEST(BinnedFit, DifferentFitterVariable) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> dx(1.5); std::exponential_distribution<> dy(.75); - + // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - BinnedDataSet data {{&xvar, &yvar}, "Some name"}; - + BinnedDataSet data{{&xvar, &yvar}, "Some name"}; + // Generate toy events. - for(int i=0; i<200000; ++i) { + for(int i = 0; i < 200000; ++i) { double xval = dx(gen); double yval = dy(gen); if(xval < 10 && yval < 10) { @@ -122,25 +118,24 @@ TEST(BinnedFit, DifferentFitterVariable) { data.addEvent(); } } - + // Fit parameter Variable xalpha{"xalpha", -2, 0.1, -10, 10}; // Fit parameter Variable yalpha{"yalpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf ypdf{"ypdf", &yvar, &yalpha}; ExpPdf xpdf{"xpdf", &xvar, &xalpha}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + FitManager fitter{&totalpdf}; fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); } - diff --git a/tests/BlindTest.cu b/tests/BlindTest.cu index 212f21ef4..ccf4f71a9 100644 --- a/tests/BlindTest.cu +++ b/tests/BlindTest.cu @@ -14,118 +14,107 @@ using namespace GooFit; TEST(Simple, NoBlind) { - // Independent variable. Variable xvar{"xvar", 0, 10}; // Data set - UnbinnedDataSet data {&xvar}; + UnbinnedDataSet data{&xvar}; - // Random number generation std::mt19937 gen(137); std::normal_distribution<> d(1.5, .3); - - + // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { double val = d(gen); if(std::fabs(val) < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, -10, 10}; Variable sigma{"sigma", 1, 0, 3}; - + // GooPdf object GaussianPdf gausspdf{"gausspdf", &xvar, &alpha, &sigma}; gausspdf.fitTo(&data); - + EXPECT_LT(alpha.getError(), .01); - EXPECT_NEAR(1.5, alpha.getValue(), alpha.getError()*3); + EXPECT_NEAR(1.5, alpha.getValue(), alpha.getError() * 3); } TEST(Simple, WithBlind) { - // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set - UnbinnedDataSet data {&xvar}; - - + UnbinnedDataSet data{&xvar}; + // Random number generation std::mt19937 gen(137); std::normal_distribution<> d(1.5, .3); - - + // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { double val = d(gen); if(std::fabs(val) < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, -10, 10}; Variable sigma{"sigma", 1, 0, 3}; - + // Blinding (normally would be randomly generated) alpha.setBlind(1); - + // GooPdf object GaussianPdf gausspdf{"gausspdf", &xvar, &alpha, &sigma}; gausspdf.fitTo(&data); - + EXPECT_LT(alpha.getError(), .01); - EXPECT_NEAR(2.5, alpha.getValue(), alpha.getError()*3); - + EXPECT_NEAR(2.5, alpha.getValue(), alpha.getError() * 3); } #ifdef ROOT_FOUND TEST(Simple, Min1Blind) { - // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set - UnbinnedDataSet data {&xvar}; - - + UnbinnedDataSet data{&xvar}; + // Random number generation std::mt19937 gen(137); std::normal_distribution<> d(1.5, .3); - - + // Generate toy events. - for(int i=0; i<100000; ++i) { + for(int i = 0; i < 100000; ++i) { double val = d(gen); if(std::fabs(val) < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, -10, 10}; Variable sigma{"sigma", 1, 0, 3}; - + // Blinding (normally would be randomly generated) alpha.setBlind(1); - + // GooPdf object GaussianPdf gausspdf{"gausspdf", &xvar, &alpha, &sigma}; gausspdf.setData(&data); - - GooFit::FitManagerMinuit1 fitman {&gausspdf}; + + GooFit::FitManagerMinuit1 fitman{&gausspdf}; fitman.fit(); - + EXPECT_LT(alpha.getError(), .01); - EXPECT_NEAR(2.5, alpha.getValue(), alpha.getError()*3); - + EXPECT_NEAR(2.5, alpha.getValue(), alpha.getError() * 3); } #endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9b825d970..75b601efa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,11 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/extern/googletest" "extern/googletest") + +mark_as_advanced( + BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS + gmock_build_tests gtest_build_samples gtest_build_tests + gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols +) + set_target_properties(gtest PROPERTIES FOLDER extern) set_target_properties(gtest_main PROPERTIES FOLDER extern) set_target_properties(gmock PROPERTIES FOLDER extern) diff --git a/tests/Minuit1Test.cu b/tests/Minuit1Test.cu index 2d634b81f..b307fa6e5 100644 --- a/tests/Minuit1Test.cu +++ b/tests/Minuit1Test.cu @@ -18,58 +18,56 @@ using namespace std; using namespace GooFit; TEST(Minuit1, SimpleFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> d(1.5); // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set UnbinnedDataSet data(&xvar); - + // Generate toy events. - for(int i=0; i<1000; ++i) { + for(int i = 0; i < 1000; ++i) { double val = d(gen); if(val < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf exppdf{"exppdf", &xvar, &alpha}; exppdf.setData(&data); - + GooFit::FitManagerMinuit1 fitter{&exppdf}; fitter.setVerbosity(2); fitter.fit(); EXPECT_TRUE(fitter); EXPECT_LT(alpha.getError(), .1); - EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError()*3); - } + EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError() * 3); +} TEST(Minuit1, DualFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> dx(1.5); std::exponential_distribution<> dy(.75); - + // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}}; - + UnbinnedDataSet data{{&xvar, &yvar}}; + // Generate toy events. - for(int i=0; i<20000; ++i) { + for(int i = 0; i < 20000; ++i) { double xval = dx(gen); double yval = dy(gen); if(xval < 10 && yval < 10) { @@ -78,123 +76,119 @@ TEST(Minuit1, DualFit) { data.addEvent(); } } - + // Fit parameter Variable xalpha{"xalpha", -2, 0.1, -10, 10}; // Fit parameter Variable yalpha{"yalpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf xpdf{"xpdf", &xvar, &xalpha}; ExpPdf ypdf{"ypdf", &yvar, &yalpha}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + GooFit::FitManagerMinuit1 fitter{&totalpdf}; fitter.setVerbosity(0); fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); } - TEST(Minuit1, DifferentFitterVariable) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> dx(1.5); std::exponential_distribution<> dy(.75); - + // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}, "Some name"}; - + UnbinnedDataSet data{{&xvar, &yvar}, "Some name"}; + // Generate toy events. - for(int i=0; i<20000; ++i) { + for(int i = 0; i < 20000; ++i) { xvar = dx(gen); yvar = dy(gen); if(xvar && yvar) { data.addEvent(); } } - + // Fit parameter Variable xalpha{"xalpha", -2, 0.1, -10, 10}; // Fit parameter Variable yalpha{"yalpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf ypdf{"ypdf", &yvar, &yalpha}; ExpPdf xpdf{"xpdf", &xvar, &xalpha}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + GooFit::FitManagerMinuit1 fitter{&totalpdf}; fitter.setVerbosity(2); fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); } TEST(Minuit1, FitterConstants) { - // Random number generation std::mt19937 gen(137); std::normal_distribution<> dx(1.5, .3); std::normal_distribution<> dy(-.75, .2); - + // Independent variable. Variable xvar{"xvar", -5, 5}; Variable yvar{"yvar", -5, 5}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}, "Some name"}; - + UnbinnedDataSet data{{&xvar, &yvar}, "Some name"}; + // Generate toy events. - for(int i=0; i<20000; ++i) { + for(int i = 0; i < 20000; ++i) { double xval = dx(gen); double yval = dy(gen); try { xvar.setValue(xval); yvar.setValue(yval); data.addEvent(); - } catch(const GooFit::OutOfRange &) {} + } catch(const GooFit::OutOfRange &) { + } } - + // Fit parameter - Variable xalpha{"xalpha", 2, 0.1, -10, 10}; - Variable xsigma{"xsigma", .2}; - Variable yalpha{"yalpha", -1, 0.1, -10, 10}; + Variable xalpha{"xalpha", 2, 0.1, -10, 10}; + Variable xsigma{"xsigma", .2}; + Variable yalpha{"yalpha", -1, 0.1, -10, 10}; Variable ysigma{"ysigma", .3}; - + // GooPdf object GaussianPdf xpdf{"xpdf", &xvar, &xalpha, &xsigma}; GaussianPdf ypdf{"ypdf", &yvar, &yalpha, &ysigma}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + GooFit::FitManagerMinuit1 fitter{&totalpdf}; fitter.setVerbosity(2); fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); EXPECT_EQ(.2, xsigma.getValue()); EXPECT_EQ(.3, ysigma.getValue()); } - - diff --git a/tests/NormalizeTest.cu b/tests/NormalizeTest.cu index 595d4773b..477a4618a 100644 --- a/tests/NormalizeTest.cu +++ b/tests/NormalizeTest.cu @@ -19,39 +19,38 @@ TEST(Normalize, Dual) { // Random number generation std::mt19937 gen(137); std::exponential_distribution<> d(1.5); - + // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set UnbinnedDataSet data(&xvar); - + // Generate toy events. - for(int i=0; i<1000; ++i) { + for(int i = 0; i < 1000; ++i) { double val = d(gen); if(val < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf exppdf{"exppdf", &xvar, &alpha}; exppdf.setData(&data); - + std::cout << exppdf.normalize() << std::endl; std::cout << exppdf.normalize() << std::endl; - + FitManager fitter{&exppdf}; fitter.setVerbosity(0); fitter.fit(); - + std::cout << exppdf.normalize() << std::endl; std::cout << exppdf.normalise() << std::endl; - - std::cout << exppdf.integrate(0,10) << std::endl; -} + std::cout << exppdf.integrate(0, 10) << std::endl; +} diff --git a/tests/SimpleTest.cu b/tests/SimpleTest.cu index 3d693c4da..465e55dec 100644 --- a/tests/SimpleTest.cu +++ b/tests/SimpleTest.cu @@ -6,35 +6,34 @@ using namespace GooFit; TEST(Simple, UnbinnedAdding) { - // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; // Data set - UnbinnedDataSet data {{&xvar, &yvar}}; + UnbinnedDataSet data{{&xvar, &yvar}}; xvar.setValue(1); yvar.setValue(2); data.addEvent(); - + xvar.setValue(3); yvar.setValue(4); data.addEvent(); - + xvar.setValue(5); yvar.setValue(6); data.addEvent(); - + data.loadEvent(0); - + EXPECT_FLOAT_EQ(1, xvar.getValue()); EXPECT_FLOAT_EQ(2, yvar.getValue()); - + data.loadEvent(1); EXPECT_FLOAT_EQ(3, xvar.getValue()); EXPECT_FLOAT_EQ(4, yvar.getValue()); - + EXPECT_FLOAT_EQ(1, data.getValue(&xvar, 0)); EXPECT_FLOAT_EQ(2, data.getValue(&yvar, 0)); EXPECT_FLOAT_EQ(3, data.getValue(&xvar, 1)); @@ -43,38 +42,35 @@ TEST(Simple, UnbinnedAdding) { EXPECT_FLOAT_EQ(6, data.getValue(&yvar, 2)); } TEST(Simple, SettingAndGetting) { - // Independent variable. Variable var{"var", 0, 10}; - + var = 1.0; - + fptype val = var; - + EXPECT_EQ(1.0, val); EXPECT_EQ(1.0, var.getValue()); } TEST(Simple, FancyAddEvent) { - // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}}; - - data.addEvent(1,2); - data.addEvent(3,4); - + UnbinnedDataSet data{{&xvar, &yvar}}; + + data.addEvent(1, 2); + data.addEvent(3, 4); + EXPECT_EQ(2, data.getNumEvents()); - + EXPECT_FLOAT_EQ(1, data.getValue(&xvar, 0)); EXPECT_FLOAT_EQ(2, data.getValue(&yvar, 0)); EXPECT_FLOAT_EQ(3, data.getValue(&xvar, 1)); EXPECT_FLOAT_EQ(4, data.getValue(&yvar, 1)); - + EXPECT_THROW(data.addEvent(1), GooFit::GeneralError); - EXPECT_THROW(data.addEvent(1,2,3), GooFit::GeneralError); + EXPECT_THROW(data.addEvent(1, 2, 3), GooFit::GeneralError); } - diff --git a/tests/UnbinnedTest.cu b/tests/UnbinnedTest.cu index c0e010f99..29cbbff72 100644 --- a/tests/UnbinnedTest.cu +++ b/tests/UnbinnedTest.cu @@ -17,58 +17,55 @@ using namespace GooFit; TEST(UnbinnedFit, SimpleFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> d(1.5); // Independent variable. Variable xvar{"xvar", 0, 10}; - + // Data set UnbinnedDataSet data(&xvar); - + // Generate toy events. - for(int i=0; i<1000; ++i) { + for(int i = 0; i < 1000; ++i) { double val = d(gen); if(val < 10) { xvar.setValue(val); data.addEvent(); } } - + // Fit parameter Variable alpha{"alpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf exppdf{"exppdf", &xvar, &alpha}; exppdf.setData(&data); - + FitManager fitter{&exppdf}; fitter.fit(); EXPECT_TRUE(fitter); EXPECT_LT(alpha.getError(), .1); - EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError()*3); - } - + EXPECT_NEAR(-1.5, alpha.getValue(), alpha.getError() * 3); +} TEST(UnbinnedFit, DualFit) { - // Random number generation std::mt19937 gen(137); std::exponential_distribution<> dx(1.5); std::exponential_distribution<> dy(.75); - + // Independent variable. Variable xvar{"xvar", 0, 10}; Variable yvar{"yvar", 0, 10}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}}; - + UnbinnedDataSet data{{&xvar, &yvar}}; + // Generate toy events. - for(int i=0; i<20000; ++i) { + for(int i = 0; i < 20000; ++i) { double xval = dx(gen); double yval = dy(gen); if(xval < 10 && yval < 10) { @@ -77,50 +74,49 @@ TEST(UnbinnedFit, DualFit) { data.addEvent(); } } - + // Fit parameter Variable xalpha{"xalpha", -2, 0.1, -10, 10}; // Fit parameter Variable yalpha{"yalpha", -2, 0.1, -10, 10}; - + // GooPdf object ExpPdf xpdf{"xpdf", &xvar, &xalpha}; ExpPdf ypdf{"ypdf", &yvar, &yalpha}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + FitManager fitter{&totalpdf}; fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); - EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError()*3); + EXPECT_NEAR(-1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(-.75, yalpha.getValue(), yalpha.getError() * 3); } TEST(UnbinnedFit, DifferentFitterVariable) { - // Random number generation std::mt19937 gen(137); std::normal_distribution<> dx(1.5, .3); std::normal_distribution<> dy(.75, .5); - + // Independent variable. Variable xvar{"xvar", -10, 10}; Variable yvar{"yvar", -10, 10}; - + // Data set - UnbinnedDataSet data {{&xvar, &yvar}, "Some name"}; - + UnbinnedDataSet data{{&xvar, &yvar}, "Some name"}; + // Generate toy events. - for(int i=0; i<20000; ++i) { + for(int i = 0; i < 20000; ++i) { xvar = dx(gen); yvar = dy(gen); if(xvar && yvar) data.addEvent(); } - + // Fit parameter Variable xalpha{"xalpha", 0, 0.1, -10, 10}; Variable xsigma{"xsigma", .1, 0.1, 0, 3}; @@ -128,25 +124,24 @@ TEST(UnbinnedFit, DifferentFitterVariable) { // Fit parameter Variable ysigma{"ysigma", .1, 0.1, 0, 3}; Variable yalpha{"yalpha", 0, 0.1, -10, 10}; - + // GooPdf object GaussianPdf ypdf{"ypdf", &yvar, &yalpha, &ysigma}; GaussianPdf xpdf{"xpdf", &xvar, &xalpha, &xsigma}; - ProdPdf totalpdf {"totalpdf", {&xpdf, &ypdf}}; + ProdPdf totalpdf{"totalpdf", {&xpdf, &ypdf}}; totalpdf.setData(&data); - + FitManager fitter{&totalpdf}; fitter.fit(); - + EXPECT_TRUE(fitter); EXPECT_LT(xalpha.getError(), .1); EXPECT_LT(yalpha.getError(), .1); EXPECT_LT(xsigma.getError(), .1); EXPECT_LT(ysigma.getError(), .1); - - EXPECT_NEAR(1.5, xalpha.getValue(), xalpha.getError()*3); - EXPECT_NEAR(.75, yalpha.getValue(), yalpha.getError()*3); - EXPECT_NEAR(.3, xsigma.getValue(), xsigma.getError()*3); - EXPECT_NEAR(.5, ysigma.getValue(), ysigma.getError()*3); -} + EXPECT_NEAR(1.5, xalpha.getValue(), xalpha.getError() * 3); + EXPECT_NEAR(.75, yalpha.getValue(), yalpha.getError() * 3); + EXPECT_NEAR(.3, xsigma.getValue(), xsigma.getError() * 3); + EXPECT_NEAR(.5, ysigma.getValue(), ysigma.getError() * 3); +}