From 2bcf80725a0acbe1c98abee63674ff79739a84da Mon Sep 17 00:00:00 2001 From: juan leite Date: Wed, 7 Mar 2018 19:04:09 +0100 Subject: [PATCH 01/16] first commit - Flatte Lineshape --- .idea/codeStyles/Project.xml | 29 + .idea/misc.xml | 4 + .idea/vcs.xml | 6 + CMakeLists.txt | 2 + examples/NIPS_HYDRA/CMakeLists.txt | 8 + examples/NIPS_HYDRA/D2KKK.cpp | 36 + examples/NIPS_HYDRA/D2KKK.cu | 36 + examples/NIPS_HYDRA/D2KKK.inl | 1344 ++++++++++++++++++++++++++++ examples/NIPS_HYDRA/LICENSE | 674 ++++++++++++++ examples/NIPS_HYDRA/README.md | 2 + hydra/functions/FlatteLineShape.h | 237 +++++ 11 files changed, 2378 insertions(+) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 examples/NIPS_HYDRA/CMakeLists.txt create mode 100644 examples/NIPS_HYDRA/D2KKK.cpp create mode 100644 examples/NIPS_HYDRA/D2KKK.cu create mode 100644 examples/NIPS_HYDRA/D2KKK.inl create mode 100644 examples/NIPS_HYDRA/LICENSE create mode 100644 examples/NIPS_HYDRA/README.md create mode 100644 hydra/functions/FlatteLineShape.h diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 000000000..30aa626c2 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..79b3c9483 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1788e220e..3dcea23af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,9 +178,11 @@ add_subdirectory(examples/random) add_subdirectory(examples/histograming) add_subdirectory(examples/async) add_subdirectory(examples/misc) +add_subdirectory(examples/NIPS_HYDRA) if(Minuit2_FOUND) add_subdirectory(examples/phys) add_subdirectory(examples/fit) + endif(Minuit2_FOUND) #+++++++++++++++++++++++++++ diff --git a/examples/NIPS_HYDRA/CMakeLists.txt b/examples/NIPS_HYDRA/CMakeLists.txt new file mode 100644 index 000000000..1073967bc --- /dev/null +++ b/examples/NIPS_HYDRA/CMakeLists.txt @@ -0,0 +1,8 @@ +project(examples) + +#+++++++++++++++++++++++++++++++++ +# Hydra NIPS | +#+++++++++++++++++++++++++++++++++ +ADD_HYDRA_EXAMPLE(D2KKK) + + diff --git a/examples/NIPS_HYDRA/D2KKK.cpp b/examples/NIPS_HYDRA/D2KKK.cpp new file mode 100644 index 000000000..a8432d69c --- /dev/null +++ b/examples/NIPS_HYDRA/D2KKK.cpp @@ -0,0 +1,36 @@ +/*---------------------------------------------------------------------------- + * + * Copyright (C) 2016 - 2017 Antonio Augusto Alves Junior + * + * This file is part of Hydra Data Analysis Framework. + * + * Hydra is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Hydra is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Hydra. If not, see . + * + *---------------------------------------------------------------------------*/ + +/* + * dalitz_plot.cpp + * + * Created on: 19/01/2018 + * Author: Antonio Augusto Alves Junior + */ + +#ifndef D2KKK_CPP_ +#define D2KKK_CPP_ + + +#include + + +#endif /* D2KKK_CPP_ */ diff --git a/examples/NIPS_HYDRA/D2KKK.cu b/examples/NIPS_HYDRA/D2KKK.cu new file mode 100644 index 000000000..63ca3abbf --- /dev/null +++ b/examples/NIPS_HYDRA/D2KKK.cu @@ -0,0 +1,36 @@ +/*---------------------------------------------------------------------------- + * + * Copyright (C) 2016 - 2017 Antonio Augusto Alves Junior + * + * This file is part of Hydra Data Analysis Framework. + * + * Hydra is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Hydra is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Hydra. If not, see . + * + *---------------------------------------------------------------------------*/ + +/* + * dalitz_plot.cu + * + * Created on: 19/01/2018 + * Author: Antonio Augusto Alves Junior + */ + +#ifndef D2KKK_CU_ +#define D2KKK_CU_ + + +#include + + +#endif /* D2KKK_CU_ */ diff --git a/examples/NIPS_HYDRA/D2KKK.inl b/examples/NIPS_HYDRA/D2KKK.inl new file mode 100644 index 000000000..d8dd78992 --- /dev/null +++ b/examples/NIPS_HYDRA/D2KKK.inl @@ -0,0 +1,1344 @@ +#ifndef D2KKK_INL_ +#define D2KKK_INL_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +/*------------------------------------- + * Include classes from ROOT to fill + * and draw histograms and plots. + *------------------------------------- + */ +#ifdef _ROOT_AVAILABLE_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif //_ROOT_AVAILABLE_ + +using namespace ROOT::Minuit2; +using namespace hydra::placeholders; + + + +template +class Resonance: public hydra::BaseFunctor, hydra::complex, 4> +{ + using hydra::BaseFunctor, hydra::complex, 4>::_par; + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + +public: + + Resonance() = delete; + + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} + + + __host__ __device__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + + } + +private: + + mutable hydra::BreitWignerLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + +class NonResonant: public hydra::BaseFunctor, 2> +{ + + using hydra::BaseFunctor, 2>::_par; + +public: + + NonResonant() = delete; + + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} + + + __host__ __device__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} + + __host__ __device__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, 2>::operator=(other); + + return *this; + } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + return hydra::complex(_par[0], _par[1]); + } + +}; + +template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +{ + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + using hydra::BaseFunctor, hydra::complex, 5>::_par; + +public: + + + + Flatte() = delete; + + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): + hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, + fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + {} + + __host__ __device__ Flatte( Flatte< CHANNEL> const& other): + hydra::BaseFunctor, hydra::complex, 5>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Flatte< CHANNEL>& + operator=( Flatte const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } + + + __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + fLineShape.SetParameter(0,_par[2]); + fLineShape.SetParameter(1,_par[3]); + fLineShape.SetParameter(2,_par[4]); + + auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass()); + + return r; + } + +private: + + mutable hydra::FlatteLineShape fLineShape; + + +}; + + + + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); + +template +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); + +int main(int argv, char** argc) +{ + size_t nentries = 0; + + try { + + TCLAP::CmdLine cmd("Command line arguments for ", '='); + + TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); + cmd.add(EArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nentries = EArg.getValue(); + + } + catch (TCLAP::ArgException &e) { + std::cerr << "error: " << e.error() << " for arg " << e.argId() + << std::endl; + } + + //----------------- + //Liang's Model + + + + // + + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); + double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.41478; + double f0X_Width = 0.309491; + double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); + double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); + + double NR_RC = 1.0; + double NR_IMC = 0.0; + double D_MASS = 1.86962; + + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + + //====================================================== + //Phi + auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); + auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); + auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); + auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); + + Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + + Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 5.0); + + auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); + + + + //====================================================== + //f0(X) + + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); + + Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + + Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + + auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); + + //====================================================== + //f0 + + auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, 100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, 100); + auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); + auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + + + Flatte<1> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + + auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); + + //====================================================== + + //NR + coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); + coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); + + auto NR = NonResonant(coef_re, coef_im); + //====================================================== + //Total: Model |N.R + \sum{ Resonaces }|^2 + + //parametric lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ + + hydra::complex r(0,0); + + for(unsigned int i=0; i< n;i++) r += x[i]; + + return hydra::norm(r); + }); + + //model-functor + auto Model = hydra::compose(Norm, + Phi_Resonance, + f0X_Resonance, f0_Resonance, + NR ); + + //-------------------- + //generator + hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi J/psi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + +#ifdef _ROOT_AVAILABLE_ + + TH3D Dalitz_Resonances("Dalitz_Resonances", + "Dalitz - Toy Data -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + TH3D Dalitz_Fit("Dalitz_Fit", + "Dalitz - Fit -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + //control plots + TH2D Normalization("normalization", + "Model PDF Normalization;Norm;Error", + 200, 275.0, 305.0, + 200, 0.58, 0.64); + + + TH3D Phi_12_HIST,Phi_13_HIST, + f0X_12_HIST,f0X_13_HIST, + f0_12_HIST,f0_13_HIST, + NR_HIST ; + + double Phi_12_FF, Phi_13_FF, + f0X_12_FF,f0X_13_FF, + f0_12_FF,f0_13_FF, + NR_FF; +#endif + + hydra::Decays<3, hydra::host::sys_t > toy_data; + + //toy data production on device + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; + std::cout << "======================================" << std::endl; + + + auto start = std::chrono::high_resolution_clock::now(); + + generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< toy_data.size() << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; + + }//toy data production on device + + std::ofstream writer; + writer.open("toyData.txt"); + + if(!writer.is_open()){ + std::cout << "file not open" << std::endl; + }else { + + for (auto event : toy_data) { + + double weight = hydra::get<0>(event); + hydra::Vector4R Kminus = hydra::get<1>(event); + hydra::Vector4R Kplus1 = hydra::get<2>(event); + hydra::Vector4R Kplus2 = hydra::get<3>(event); + + double MKminusKplus1 = (Kminus + Kplus1).mass2(); + double MKminusKplus2 = (Kminus + Kplus2).mass2(); + + writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; + } + + std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); + + auto particles = toy_data_temp.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + + std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_variables[i] << std::endl; + + //flat dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + auto start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + std::cout << std::endl; + std::cout << std::endl; + +#ifdef _ROOT_AVAILABLE_ + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + +#endif + +#endif + + } + + + // fit + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "=============== 3 - FIT ==============" << std::endl; + std::cout << "======================================" << std::endl; + std::cout << std::endl << std::endl; + //pdf + auto Model_PDF = hydra::make_pdf( Model, + hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); + + + + std::cout << "-----------------------------------------"< toy_data_temp(toy_data); + auto particles = toy_data_temp.GetUnweightedDecays(); + + auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), + particles.end()); + + //print level + ROOT::Minuit2::MnPrint::SetLevel(3); + hydra::Print::SetLevel(hydra::WARNING); + + //minimization strategy + MnStrategy strategy(2); + + //create Migrad minimizer + MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); + + //print parameters before fitting + std::cout< elapsed_d = end_d - start_d; + + //time + std::cout << "-----------------------------------------"< fit_data(nentries); + + auto start = std::chrono::high_resolution_clock::now(); + + //generate the final state particles + phsp.Generate(B0, fit_data.begin(), fit_data.end()); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------- Device (fit data) -----------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + fit_data.Reweight(fcn.GetPDF().GetFunctor()); + + auto particles_fit = fit_data.GetUnweightedDecays(); + auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); + auto dalitz_weights_fit = fit_data.GetWeights(); + + std::cout << std::endl; + std::cout << std::endl; + + std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; + + //model dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables_fit.begin(), + dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); + + end = std::chrono::high_resolution_clock::now(); + + elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + //================================== + // Optimized components + //================================== + auto Opt_Model = fcn.GetPDF().GetFunctor(); + + auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); + auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); + auto f0X_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); + auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); + auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); + auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); + auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); + + //================================== + // Draw components + //================================== + Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); + Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); + f0X_12_HIST = histogram_component(f0X_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_12_HIST", nentries); + f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); + f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); + f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); + NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); + + + //================================== + // Fit fractions + //================================== + Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_12_FF = fit_fraction(f0X_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + + + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; + std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; + std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; + std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; + std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "NR_FF :" << NR_FF << std::endl; + std::cout << "Sum :" + << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; + +#ifdef _ROOT_AVAILABLE_ + + { + std::vector integrals; + std::vector integrals_error; + + for(auto x: fcn.GetPDF().GetNormCache() ){ + integrals.push_back(x.second.first); + integrals_error.push_back(x.second.second); + + } + + auto integral_bounds = std::minmax_element(integrals.begin(), + integrals.end()); + + auto integral_error_bounds = std::minmax_element(integrals_error.begin(), + integrals_error.end()); + + Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); + Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); + + for(auto x: fcn.GetPDF().GetNormCache() ){ + + Normalization.Fill(x.second.first, x.second.second ); + } + } + + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } +#endif + + +#endif + + } + + + +#ifdef _ROOT_AVAILABLE_ + + + TApplication *m_app=new TApplication("myapp",0,0); + + + Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); + + Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); + Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); + f0X_12_HIST.Scale( f0X_12_FF*Dalitz_Fit.Integral()/f0X_12_HIST.Integral() ); + f0X_13_HIST.Scale( f0X_13_FF*Dalitz_Fit.Integral()/f0X_13_HIST.Integral() ); + f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); + f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); + + NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); + + //============================================================= + //projections + TH1* hist2D=0; + + TCanvas canvas_3("canvas_3", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_3.SaveAs("Dataset1.png"); + + TCanvas canvas_4("canvas_4", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_4.SaveAs("Dataset2.png"); + + + TCanvas canvas_5("canvas_5", "Fit", 500, 500); + hist2D = Dalitz_Fit.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_5.SaveAs("FitResult1.png"); + + + TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); + hist2D = Dalitz_Fit.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_6.SaveAs("FitResult2.png"); + + + //============================================================= + //projections + TH1* hist=0; + const char* axis =0; + + auto Phi_Color = kViolet-5; + auto f0X_Color = kBlue; + auto f0_Color = kGreen; + auto NR_Color = kBlack; + + double X1NDC = 0.262458; + double Y1NDC = 0.127544; + double X2NDC = 0.687708; + double Y2NDC = 0.35; + + + //============================== + axis = "x"; + + TCanvas canvas_x("canvas_x", "", 600, 750); + + + + auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_x.SetEntrySeparation(0.3); + legend_x.SetNColumns(2); + legend_x.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_x.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_x.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"NR","l"); + + canvas_x.SaveAs("Proj_X.png"); + + canvas_x.SetLogy(1); + + legend_x.Draw(); + + canvas_x.SaveAs("Proj_LogX.png"); + + //============================================================= + + axis = "y"; + + TCanvas canvas_y("canvas_y", "", 600, 750); + + + auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_y.SetEntrySeparation(0.3); + legend_y.SetNColumns(2); + legend_y.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_y.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_y.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"NR","l"); + + canvas_y.SaveAs("Proj_Y.png"); + + canvas_y.SetLogy(1); + + legend_y.Draw(); + + canvas_y.SaveAs("Proj_LogY.png"); + + + //============================================================= + + + + axis = "z"; + + TCanvas canvas_z("canvas_z", "", 600, 750); + + auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_z.SetEntrySeparation(0.3); + legend_z.SetNColumns(2); + legend_z.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_z.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_z.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"NR","l"); + + canvas_z.SaveAs("Proj_Z.png"); + + canvas_z.SetLogy(1); + + legend_z.Draw(); + + canvas_z.SaveAs("Proj_LogZ.png"); + + //============================================================= + + TCanvas canvas_7("canvas_7", "Normalization", 500, 500); + Normalization.Draw("colz"); + + + m_app->Run(); + +#endif + + return 0; +} + + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //allocate memory to hold the final states particles + hydra::Decays<3, Backend > _data(bunch_size); + + std::srand(7531594562); + + do { + phsp.SetSeed(std::rand()); + + //generate the final state particles + phsp.Generate(D, _data.begin(), _data.end()); + + auto last = _data.Unweight(model, 1.0); + + decays.insert(decays.size()==0? decays.begin():decays.end(), + _data.begin(), _data.begin()+last ); + + } while(decays.size() +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //norm lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + + auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); + auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); + + + return amp_int.first/model_int.first; + +} + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K+ mass + const double Kplus_MASS = masses[2];// K- mass + + TH3D Component(name, + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + //norm lambda + auto Norm = hydra::wrap_lambda( + []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + hydra::Decays<3, hydra::device::sys_t > events(nentries); + + phsp.Generate(D, events.begin(), events.end()); + + events.Reweight(functor); + + auto particles = events.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + auto dalitz_weights = events.GetWeights(); + + //model dalitz histogram + hydra::SparseHistogram Hist_Component{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + Hist_Component.Fill( dalitz_variables.begin(), + dalitz_variables.end(), dalitz_weights.begin() ); + + for(auto entry : Hist_Component){ + + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Component.GetIndexes(bin, bins); + Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + return Component; + +} + + + +#endif /* D2KKK_INL_ */ diff --git a/examples/NIPS_HYDRA/LICENSE b/examples/NIPS_HYDRA/LICENSE new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/examples/NIPS_HYDRA/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/examples/NIPS_HYDRA/README.md b/examples/NIPS_HYDRA/README.md new file mode 100644 index 000000000..e50dbed8f --- /dev/null +++ b/examples/NIPS_HYDRA/README.md @@ -0,0 +1,2 @@ +# NIPS_HYDRA +Numerical Integral Precision Studies in Hydra diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h new file mode 100644 index 000000000..f0eee5bd3 --- /dev/null +++ b/hydra/functions/FlatteLineShape.h @@ -0,0 +1,237 @@ +// +// Created by juan on 07/03/18. +// + +#ifndef HYDRA_EXAMPLES_AND_DOCUMENTATION_FLATTELINESHAPE_H +#define HYDRA_EXAMPLES_AND_DOCUMENTATION_FLATTELINESHAPE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace hydra { + + template + class FlatteLineShape : public BaseFunctor, hydra::complex, 3> { + using BaseFunctor, hydra::complex, 3>::_par; + + public: + + FlatteLineShape() = delete; + +/** + * + * @param mass resonance mass. + * @param rho1 + * @param rh2 + * @param daugther1_mass resonance daughter particle 1 mass + * @param daugther2_mass resonance daughter particle 2 mass + * @param daugther3_mass daughter particle 2 mass + * @param radi decay vertex radio. + */ + FlatteLineShape(hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, + double daugther1_mass, double daugther2_mass, double daugther3_mass, + double radi) : + BaseFunctor, hydra::complex, 3>{mean, rho1, rho2}, + fDaughter1Mass(daugther1_mass), + fDaughter2Mass(daugther2_mass), + fDaughter3Mass(daugther3_mass), + fMotherMass(mother_mass), + fRadi(radi) {} + + __hydra_host__ __hydra_device__ + FlatteLineShape(FlatteLineShape const &other) : + BaseFunctor, hydra::complex, 3>(other), + fDaughter1Mass(other.GetDaughter1Mass()), + fDaughter2Mass(other.GetDaughter2Mass()), + fDaughter3Mass(other.GetDaughter3Mass()), + fMotherMass(other.GetMotherMass()), + fRadi(other.GetRadi()) {} + + __hydra_host__ __hydra_device__ + FlatteLineShape & + operator=(FlatteLineShape const &other) { + if (this == &other) return *this; + + BaseFunctor, + hydra::complex, 3>::operator=(other); + + fDaughter1Mass = other.GetDaughter1Mass(); + fDaughter2Mass = other.GetDaughter2Mass(); + fDaughter3Mass = other.GetDaughter3Mass(); + fMotherMass = other.GetMotherMass(); + fRadi = other.GetRadi(); + + return *this; + } + + __hydra_host__ __hydra_device__ inline + double GetDaughter1Mass() const { + return fDaughter1Mass; + } + + __hydra_host__ __hydra_device__ inline + void SetDaughter1Mass(double daughter1Mass) { + fDaughter1Mass = daughter1Mass; + } + + __hydra_host__ __hydra_device__ inline + double GetDaughter2Mass() const { + return fDaughter2Mass; + } + + __hydra_host__ __hydra_device__ inline + void SetDaughter2Mass(double daughter2Mass) { + fDaughter2Mass = daughter2Mass; + } + + __hydra_host__ __hydra_device__ inline + double GetDaughter3Mass() const { + return fDaughter3Mass; + } + + __hydra_host__ __hydra_device__ inline + void SetDaughter3Mass(double daughter3Mass) { + fDaughter3Mass = daughter3Mass; + } + + __hydra_host__ __hydra_device__ inline + double GetMotherMass() const { + return fMotherMass; + } + + __hydra_host__ __hydra_device__ inline + void SetMotherMass(double motherMass) { + fMotherMass = motherMass; + } + + __hydra_host__ __hydra_device__ inline + double GetRadi() const { + return fRadi; + } + + __hydra_host__ __hydra_device__ inline + void SetRadi(double radi) { + fRadi = radi; + } + + template + __hydra_host__ __hydra_device__ inline + hydra::complex Evaluate(unsigned int, T *x) const { + + const double m = x[ArgIndex]; + + const double resonance_mass = _par[0]; + const double rho1 = _par[1]; + const double rho2 = _par[2]; + + return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? + LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); + + } + + template + __hydra_host__ __hydra_device__ inline + hydra::complex Evaluate(T x) const { + + double m = get(x); + + const double resonance_mass = _par[0]; + const double rho1 = _par[1]; + const double rho2 = _par[2]; + + return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? + LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); + } + + private: + + + /*__hydra_host__ __hydra_device__ inline + double Width(const double m, const double resonance_mass, const double resonance_width, + const double p0, const double p) const { + + const double B = BarrierFactor(fRadi, p0, p); + + return resonance_width * \ + pow(p / p0) * \ + (resonance_mass / m) * \ + B * B; + + }*/ + + __hydra_host__ __hydra_device__ inline + hydra::complex + LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { + + + + double pipmass = 0.13957018; + double pi0mass = 0.1349766; + double kpmass = 0.493677; + double k0mass = 0.497614; + + double twopimasssq = 4 * pipmass * pipmass; + double twopi0masssq = 4 * pi0mass * pi0mass; + double twokmasssq = 4 * kpmass * kpmass; + double twok0masssq = 4 * k0mass * k0mass; + + double rhopipi_real = 0, rhopipi_imag = 0; + double rhokk_real = 0, rhokk_imag = 0; + + + + if(s >= twopimasssq) + rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s); // Above pi+pi- threshold + else + rhopipi_imag = (2. / 3) * TMath::Sqrt(-1 + twopimasssq / s); + if(s >= twopi0masssq) + rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s); // Above pi0pi0 threshold + else + rhopipi_imag = (1. / 3) * TMath::Sqrt(-1 + twopi0masssq / s); + if(s >= twokmasssq) + rhokk_real = 0.5 * TMath::Sqrt(1 - twokmasssq / s); // Above K+K- threshold + else + rhokk_imag = 0.5 * TMath::Sqrt(-1 + twokmasssq / s); + if(s >= twok0masssq) + rhokk_real = 0.5 * TMath::Sqrt(1 - twok0masssq / s); // Above K0K0 threshold + else + rhokk_imag = 0.5 * TMath::Sqrt(-1 + twok0masssq / s); + double A = (resonance_mass * resonance_mass - s) + resonance_mass * (rhopipi_imag * g1 + rhokk_imag * g2); + double B = resonance_mass * (rhopipi_real * g1 + rhokk_real * g2); + double C = 1.0 / (A * A + B * B); + hydra::complex retur(A * C, B * C); + + + + + return retur; + + + } + + double fDaughter1Mass; + double fDaughter2Mass; + double fDaughter3Mass; + double fMotherMass; + double fRadi; + + }; + +} +#endif //HYDRA_EXAMPLES_AND_DOCUMENTATION_FLATTELINESHAPE_H From a13c230d8b8962e42850d4d21bddddc78ec79c39 Mon Sep 17 00:00:00 2001 From: juan leite Date: Thu, 8 Mar 2018 00:25:15 +0100 Subject: [PATCH 02/16] =?UTF-8?q?testing=20flatt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hydra/functions/FlatteLineShape.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index f0eee5bd3..c0f407685 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -153,7 +153,8 @@ namespace hydra { const double resonance_mass = _par[0]; const double rho1 = _par[1]; - const double rho2 = _par[2]; + const double temp_rho2 = _par[2]; + const double rho2 = temp_rho2*rho1; return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); @@ -162,19 +163,6 @@ namespace hydra { private: - /*__hydra_host__ __hydra_device__ inline - double Width(const double m, const double resonance_mass, const double resonance_width, - const double p0, const double p) const { - - const double B = BarrierFactor(fRadi, p0, p); - - return resonance_width * \ - pow(p / p0) * \ - (resonance_mass / m) * \ - B * B; - - }*/ - __hydra_host__ __hydra_device__ inline hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { From 7eaaf92a70cd89541171dd82dd36a1841873c4e2 Mon Sep 17 00:00:00 2001 From: juan leite Date: Fri, 9 Mar 2018 10:23:49 +0100 Subject: [PATCH 03/16] flatte lineshape --- examples/NIPS_HYDRA/D2KKK.inl | 255 ++-- examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl | 1263 ++++++++++++++++ .../NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl | 1347 +++++++++++++++++ hydra/functions/FlatteLineShape.h | 26 +- 4 files changed, 2754 insertions(+), 137 deletions(-) create mode 100644 examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl create mode 100644 examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl diff --git a/examples/NIPS_HYDRA/D2KKK.inl b/examples/NIPS_HYDRA/D2KKK.inl index d8dd78992..54bd62286 100644 --- a/examples/NIPS_HYDRA/D2KKK.inl +++ b/examples/NIPS_HYDRA/D2KKK.inl @@ -101,67 +101,66 @@ using namespace hydra::placeholders; template class Resonance: public hydra::BaseFunctor, hydra::complex, 4> { - using hydra::BaseFunctor, hydra::complex, 4>::_par; + using hydra::BaseFunctor, hydra::complex, 4>::_par; - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); public: - Resonance() = delete; - - Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, - hydra::Parameter const& mass, hydra::Parameter const& width, - double mother_mass, double daugther1_mass, - double daugther2_mass, double daugther3_mass, - double radi): - hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, - fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) - {} + Resonance() = delete; + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} - __host__ __device__ - Resonance( Resonance< CHANNEL,L> const& other): - hydra::BaseFunctor, hydra::complex, 4>(other), - fLineShape(other.GetLineShape()) - {} - __host__ __device__ inline - Resonance< CHANNEL ,L>& - operator=( Resonance< CHANNEL ,L> const& other) - { - if(this==&other) return *this; + __hydra_dual__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} - hydra::BaseFunctor, hydra::complex, 4>::operator=(other); - fLineShape=other.GetLineShape(); + __hydra_dual__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; - return *this; - } + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); - __host__ __device__ inline - hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + return *this; + } - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __hydra_dual__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + __hydra_dual__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; - fLineShape.SetParameter(0, _par[2]); - fLineShape.SetParameter(1, _par[3]); - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); - return r; + double theta = fCosDecayAngle((p1 + p2 + p3), (p1 + p2), p1); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1]) * fLineShape((p1 + p2).mass()) * angular; - } + return r; + } private: @@ -177,83 +176,81 @@ private: class NonResonant: public hydra::BaseFunctor, 2> { - using hydra::BaseFunctor, 2>::_par; + using hydra::BaseFunctor, 2>::_par; public: - NonResonant() = delete; + NonResonant() = delete; - NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): - hydra::BaseFunctor, 2>{c_re, c_im} - {} + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} - __host__ __device__ - NonResonant( NonResonant const& other): - hydra::BaseFunctor, 2>(other) - {} + __hydra_dual__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} - __host__ __device__ - NonResonant& operator=( NonResonant const& other) - { - if(this==&other) return *this; + __hydra_dual__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; - hydra::BaseFunctor, 2>::operator=(other); + hydra::BaseFunctor, 2>::operator=(other); - return *this; - } + return *this; + } - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __hydra_dual__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - return hydra::complex(_par[0], _par[1]); - } + return hydra::complex(_par[0], _par[1]); + } }; -template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> { constexpr static unsigned int _I1 = CHANNEL-1; constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - using hydra::BaseFunctor, hydra::complex, 5>::_par; + using hydra::BaseFunctor, hydra::complex, 5>::_par; public: - - Flatte() = delete; Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): - hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, + hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) {} - __host__ __device__ Flatte( Flatte< CHANNEL> const& other): - hydra::BaseFunctor, hydra::complex, 5>(other), + __hydra_dual__ Flatte( Flatte const& other): + hydra::BaseFunctor, hydra::complex, 5>(other), fLineShape(other.GetLineShape()) {} - __host__ __device__ inline - Flatte< CHANNEL>& - operator=( Flatte const& other) + __hydra_dual__ inline + Flatte& + operator=( Flatte const& other) { if(this==&other) return *this; - hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + hydra::BaseFunctor, hydra::complex, 5>::operator=(other); fLineShape=other.GetLineShape(); return *this; } - __host__ __device__ inline - hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } + __hydra_dual__ inline + hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } - __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __hydra_dual__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { hydra::Vector4R p1 = p[_I1]; hydra::Vector4R p2 = p[_I2]; @@ -263,7 +260,10 @@ public: fLineShape.SetParameter(1,_par[3]); fLineShape.SetParameter(2,_par[4]); - auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass()); + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + + auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; return r; } @@ -271,6 +271,8 @@ public: private: mutable hydra::FlatteLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; }; @@ -317,14 +319,15 @@ int main(int argv, char** argc) // +/* double Phi_MASS = 1.019461; double Phi_Width = 0.004266; double Phi_RC = 1.0; double Phi_IMC = 0.0; double f0_MASS = 0.965; - double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); - double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); + double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180))/10; + double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180))/10; double f0_rho1 = 0.165; double f0_rho2 = 4.21*f0_rho1; @@ -335,11 +338,39 @@ int main(int argv, char** argc) double NR_RC = 1.0; double NR_IMC = 0.0; + double D_MASS = 1.86962; + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + +*/ + + //liang model2 results + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 3.20; + double f0_IMC = -59.3; + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.430; + double f0X_Width = 0.348; + double f0X_RC = 3.52; + double f0X_IMC = 13.8; + + double NR_RC = 1.0; + double NR_IMC = 0.0; + + double D_MASS = 1.86962; double Kplus_MASS = 0.493677; // K+ mass double Kminus_MASS = Kplus_MASS; + //====================================================== //Phi auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); @@ -348,10 +379,10 @@ int main(int argv, char** argc) auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 5.0); + D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); @@ -360,33 +391,33 @@ int main(int argv, char** argc) //====================================================== //f0(X) - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Error(0.019).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Error(0.049).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.58).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(8.1).Limits(-100,+100); Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 5.0); + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); //====================================================== //f0 - auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, 100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, 100); + auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.12).Limits(-100, +100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(5.1).Limits(-100, +100); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); - Flatte<1> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); + auto f0_Resonance = (f0_Resonance_13 + f0_Resonance_12); //====================================================== @@ -411,8 +442,8 @@ int main(int argv, char** argc) //model-functor auto Model = hydra::compose(Norm, Phi_Resonance, - f0X_Resonance, f0_Resonance, - NR ); + f0X_Resonance, f0_Resonance + ); //-------------------- //generator @@ -463,13 +494,12 @@ int main(int argv, char** argc) TH3D Phi_12_HIST,Phi_13_HIST, f0X_12_HIST,f0X_13_HIST, - f0_12_HIST,f0_13_HIST, - NR_HIST ; + f0_12_HIST,f0_13_HIST ; double Phi_12_FF, Phi_13_FF, f0X_12_FF,f0X_13_FF, - f0_12_FF,f0_13_FF, - NR_FF; + f0_12_FF,f0_13_FF + ; #endif hydra::Decays<3, hydra::host::sys_t > toy_data; @@ -749,7 +779,6 @@ int main(int argv, char** argc) auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); - auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); //================================== // Draw components @@ -760,7 +789,6 @@ int main(int argv, char** argc) f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); - NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); //================================== @@ -772,18 +800,15 @@ int main(int argv, char** argc) f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; + std::cout << "f0X_12_FF :" << f0X_12_FF << std::endl; std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; - std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; - std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "f0_12_FF :" << f0_12_FF << std::endl; std::cout << "f0_13_FF :" << f0_13_FF << std::endl; - std::cout << "NR_FF :" << NR_FF << std::endl; std::cout << "Sum :" - << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; + << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF << std::endl; #ifdef _ROOT_AVAILABLE_ @@ -868,8 +893,6 @@ int main(int argv, char** argc) f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); - NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); - //============================================================= //projections TH1* hist2D=0; @@ -989,12 +1012,7 @@ int main(int argv, char** argc) legend_x.AddEntry(hist,"{f0}_{13}","l"); - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - legend_x.AddEntry(hist,"NR","l"); canvas_x.SaveAs("Proj_X.png"); @@ -1075,12 +1093,7 @@ int main(int argv, char** argc) legend_y.AddEntry(hist,"{f0}_{13}","l"); - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - legend_y.AddEntry(hist,"NR","l"); canvas_y.SaveAs("Proj_Y.png"); @@ -1163,12 +1176,6 @@ int main(int argv, char** argc) legend_z.AddEntry(hist,"{f0}_{13}","l"); - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"NR","l"); canvas_z.SaveAs("Proj_Z.png"); diff --git a/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl b/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl new file mode 100644 index 000000000..0e8d5dd07 --- /dev/null +++ b/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl @@ -0,0 +1,1263 @@ +#ifndef D2KKK_INL_ +#define D2KKK_INL_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +/*------------------------------------- + * Include classes from ROOT to fill + * and draw histograms and plots. + *------------------------------------- + */ +#ifdef _ROOT_AVAILABLE_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif //_ROOT_AVAILABLE_ + +using namespace ROOT::Minuit2; +using namespace hydra::placeholders; + + + +template +class Resonance: public hydra::BaseFunctor, hydra::complex, 4> +{ + using hydra::BaseFunctor, hydra::complex, 4>::_par; + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + +public: + + Resonance() = delete; + + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} + + + __host__ __device__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + + } + +private: + + mutable hydra::BreitWignerLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + +class NonResonant: public hydra::BaseFunctor, 2> +{ + + using hydra::BaseFunctor, 2>::_par; + +public: + + NonResonant() = delete; + + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} + + + __host__ __device__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} + + __host__ __device__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, 2>::operator=(other); + + return *this; + } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + return hydra::complex(_par[0], _par[1]); + } + +}; + +template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +{ + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + using hydra::BaseFunctor, hydra::complex, 5>::_par; + +public: + + Flatte() = delete; + + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): + hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, + fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + {} + + __host__ __device__ Flatte( Flatte const& other): + hydra::BaseFunctor, hydra::complex, 5>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Flatte& + operator=( Flatte const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } + + + __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + fLineShape.SetParameter(0,_par[2]); + fLineShape.SetParameter(1,_par[3]); + fLineShape.SetParameter(2,_par[4]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + + auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + } + +private: + + mutable hydra::FlatteLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); + +template +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); + +int main(int argv, char** argc) +{ + size_t nentries = 0; + + try { + + TCLAP::CmdLine cmd("Command line arguments for ", '='); + + TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); + cmd.add(EArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nentries = EArg.getValue(); + + } + catch (TCLAP::ArgException &e) { + std::cerr << "error: " << e.error() << " for arg " << e.argId() + << std::endl; + } + + //----------------- + //Liang's Model + + + + // + + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); + double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.41478; + double f0X_Width = 0.309491; + double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); + double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); + + double NR_RC = 1.0; + double NR_IMC = 0.0; + + double D_MASS = 1.86962; + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + + //====================================================== + //Phi + auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); + auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); + auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); + auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); + + Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); + + auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); + + + + //====================================================== + //f0(X) + + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); + + Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); + + //====================================================== + //f0 + + auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, +100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, +100); + auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); + auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + + + Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + + auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); + + //====================================================== + + //NR + coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); + coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); + + auto NR = NonResonant(coef_re, coef_im); + //====================================================== + //Total: Model |N.R + \sum{ Resonaces }|^2 + + //parametric lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ + + hydra::complex r(0,0); + + for(unsigned int i=0; i< n;i++) r += x[i]; + + return hydra::norm(r); + }); + + //model-functor + auto Model = hydra::compose(Norm, + Phi_Resonance, + f0_Resonance + ); + + //-------------------- + //generator + hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi J/psi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + +#ifdef _ROOT_AVAILABLE_ + + TH3D Dalitz_Resonances("Dalitz_Resonances", + "Dalitz - Toy Data -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + TH3D Dalitz_Fit("Dalitz_Fit", + "Dalitz - Fit -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + //control plots + TH2D Normalization("normalization", + "Model PDF Normalization;Norm;Error", + 200, 275.0, 305.0, + 200, 0.58, 0.64); + + + TH3D Phi_12_HIST,Phi_13_HIST, + f0_12_HIST,f0_13_HIST + ; + + double Phi_12_FF, Phi_13_FF, + f0_12_FF,f0_13_FF + ; +#endif + + hydra::Decays<3, hydra::host::sys_t > toy_data; + + //toy data production on device + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; + std::cout << "======================================" << std::endl; + + + auto start = std::chrono::high_resolution_clock::now(); + + generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< toy_data.size() << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; + + }//toy data production on device + + std::ofstream writer; + writer.open("toyData.txt"); + + if(!writer.is_open()){ + std::cout << "file not open" << std::endl; + }else { + + for (auto event : toy_data) { + + double weight = hydra::get<0>(event); + hydra::Vector4R Kminus = hydra::get<1>(event); + hydra::Vector4R Kplus1 = hydra::get<2>(event); + hydra::Vector4R Kplus2 = hydra::get<3>(event); + + double MKminusKplus1 = (Kminus + Kplus1).mass2(); + double MKminusKplus2 = (Kminus + Kplus2).mass2(); + + writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; + } + + std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); + + auto particles = toy_data_temp.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + + std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_variables[i] << std::endl; + + //flat dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + auto start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + std::cout << std::endl; + std::cout << std::endl; + +#ifdef _ROOT_AVAILABLE_ + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + +#endif + +#endif + + } + + + // fit + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "=============== 3 - FIT ==============" << std::endl; + std::cout << "======================================" << std::endl; + std::cout << std::endl << std::endl; + //pdf + auto Model_PDF = hydra::make_pdf( Model, + hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); + + + + std::cout << "-----------------------------------------"< toy_data_temp(toy_data); + auto particles = toy_data_temp.GetUnweightedDecays(); + + auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), + particles.end()); + + //print level + ROOT::Minuit2::MnPrint::SetLevel(3); + hydra::Print::SetLevel(hydra::WARNING); + + //minimization strategy + MnStrategy strategy(2); + + //create Migrad minimizer + MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); + + //print parameters before fitting + std::cout< elapsed_d = end_d - start_d; + + //time + std::cout << "-----------------------------------------"< fit_data(nentries); + + auto start = std::chrono::high_resolution_clock::now(); + + //generate the final state particles + phsp.Generate(B0, fit_data.begin(), fit_data.end()); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------- Device (fit data) -----------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + fit_data.Reweight(fcn.GetPDF().GetFunctor()); + + auto particles_fit = fit_data.GetUnweightedDecays(); + auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); + auto dalitz_weights_fit = fit_data.GetWeights(); + + std::cout << std::endl; + std::cout << std::endl; + + std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; + + //model dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables_fit.begin(), + dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); + + end = std::chrono::high_resolution_clock::now(); + + elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + //================================== + // Optimized components + //================================== + auto Opt_Model = fcn.GetPDF().GetFunctor(); + + auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); + auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); + auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); + auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); + + //================================== + // Draw components + //================================== + Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); + Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); + f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); + f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); + + + //================================== + // Fit fractions + //================================== + Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; + std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; + std::cout << "f0_12_FF :" << f0_12_FF << std::endl; + std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "Sum :" + << Phi_12_FF + Phi_13_FF + f0_12_FF + f0_13_FF << std::endl; + +#ifdef _ROOT_AVAILABLE_ + + { + std::vector integrals; + std::vector integrals_error; + + for(auto x: fcn.GetPDF().GetNormCache() ){ + integrals.push_back(x.second.first); + integrals_error.push_back(x.second.second); + + } + + auto integral_bounds = std::minmax_element(integrals.begin(), + integrals.end()); + + auto integral_error_bounds = std::minmax_element(integrals_error.begin(), + integrals_error.end()); + + Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); + Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); + + for(auto x: fcn.GetPDF().GetNormCache() ){ + + Normalization.Fill(x.second.first, x.second.second ); + } + } + + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } +#endif + + +#endif + + } + + + +#ifdef _ROOT_AVAILABLE_ + + + TApplication *m_app=new TApplication("myapp",0,0); + + + Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); + + Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); + Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); + f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); + f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); + + //============================================================= + //projections + TH1* hist2D=0; + + TCanvas canvas_3("canvas_3", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_3.SaveAs("Dataset1.png"); + + TCanvas canvas_4("canvas_4", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_4.SaveAs("Dataset2.png"); + + + TCanvas canvas_5("canvas_5", "Fit", 500, 500); + hist2D = Dalitz_Fit.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_5.SaveAs("FitResult1.png"); + + + TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); + hist2D = Dalitz_Fit.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_6.SaveAs("FitResult2.png"); + + + //============================================================= + //projections + TH1* hist=0; + const char* axis =0; + + auto Phi_Color = kViolet-5; + auto f0X_Color = kBlue; + auto f0_Color = kGreen; + auto NR_Color = kBlack; + + double X1NDC = 0.262458; + double Y1NDC = 0.127544; + double X2NDC = 0.687708; + double Y2NDC = 0.35; + + + //============================== + axis = "x"; + + TCanvas canvas_x("canvas_x", "", 600, 750); + + + + auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_x.SetEntrySeparation(0.3); + legend_x.SetNColumns(2); + legend_x.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_x.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_x.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{13}","l"); + + canvas_x.SaveAs("Proj_X.png"); + + canvas_x.SetLogy(1); + + legend_x.Draw(); + + canvas_x.SaveAs("Proj_LogX.png"); + + //============================================================= + + axis = "y"; + + TCanvas canvas_y("canvas_y", "", 600, 750); + + + auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_y.SetEntrySeparation(0.3); + legend_y.SetNColumns(2); + legend_y.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_y.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_y.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{13}","l"); + + canvas_y.SaveAs("Proj_Y.png"); + + canvas_y.SetLogy(1); + + legend_y.Draw(); + + canvas_y.SaveAs("Proj_LogY.png"); + + + //============================================================= + + + + axis = "z"; + + TCanvas canvas_z("canvas_z", "", 600, 750); + + auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_z.SetEntrySeparation(0.3); + legend_z.SetNColumns(2); + legend_z.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_z.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_z.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{13}","l"); + + canvas_z.SaveAs("Proj_Z.png"); + + canvas_z.SetLogy(1); + + legend_z.Draw(); + + canvas_z.SaveAs("Proj_LogZ.png"); + + //============================================================= + + TCanvas canvas_7("canvas_7", "Normalization", 500, 500); + Normalization.Draw("colz"); + + + m_app->Run(); + +#endif + + return 0; +} + + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //allocate memory to hold the final states particles + hydra::Decays<3, Backend > _data(bunch_size); + + std::srand(7531594562); + + do { + phsp.SetSeed(std::rand()); + + //generate the final state particles + phsp.Generate(D, _data.begin(), _data.end()); + + auto last = _data.Unweight(model, 1.0); + + decays.insert(decays.size()==0? decays.begin():decays.end(), + _data.begin(), _data.begin()+last ); + + } while(decays.size() +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //norm lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + + auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); + auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); + + + return amp_int.first/model_int.first; + +} + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K+ mass + const double Kplus_MASS = masses[2];// K- mass + + TH3D Component(name, + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + //norm lambda + auto Norm = hydra::wrap_lambda( + []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + hydra::Decays<3, hydra::device::sys_t > events(nentries); + + phsp.Generate(D, events.begin(), events.end()); + + events.Reweight(functor); + + auto particles = events.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + auto dalitz_weights = events.GetWeights(); + + //model dalitz histogram + hydra::SparseHistogram Hist_Component{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + Hist_Component.Fill( dalitz_variables.begin(), + dalitz_variables.end(), dalitz_weights.begin() ); + + for(auto entry : Hist_Component){ + + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Component.GetIndexes(bin, bins); + Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + return Component; + +} + + + +#endif /* D2KKK_INL_ */ diff --git a/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl b/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl new file mode 100644 index 000000000..2e95a7ab4 --- /dev/null +++ b/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl @@ -0,0 +1,1347 @@ +#ifndef D2KKK_INL_ +#define D2KKK_INL_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +/*------------------------------------- + * Include classes from ROOT to fill + * and draw histograms and plots. + *------------------------------------- + */ +#ifdef _ROOT_AVAILABLE_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif //_ROOT_AVAILABLE_ + +using namespace ROOT::Minuit2; +using namespace hydra::placeholders; + + + +template +class Resonance: public hydra::BaseFunctor, hydra::complex, 4> +{ + using hydra::BaseFunctor, hydra::complex, 4>::_par; + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + +public: + + Resonance() = delete; + + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} + + + __host__ __device__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + + } + +private: + + mutable hydra::BreitWignerLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + +class NonResonant: public hydra::BaseFunctor, 2> +{ + + using hydra::BaseFunctor, 2>::_par; + +public: + + NonResonant() = delete; + + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} + + + __host__ __device__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} + + __host__ __device__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, 2>::operator=(other); + + return *this; + } + + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + return hydra::complex(_par[0], _par[1]); + } + +}; + +template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +{ + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + using hydra::BaseFunctor, hydra::complex, 5>::_par; + +public: + + Flatte() = delete; + + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): + hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, + fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + {} + + __host__ __device__ Flatte( Flatte const& other): + hydra::BaseFunctor, hydra::complex, 5>(other), + fLineShape(other.GetLineShape()) + {} + + __host__ __device__ inline + Flatte& + operator=( Flatte const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __host__ __device__ inline + hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } + + + __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + fLineShape.SetParameter(0,_par[2]); + fLineShape.SetParameter(1,_par[3]); + fLineShape.SetParameter(2,_par[4]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + + auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + } + +private: + + mutable hydra::FlatteLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); + +template +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); + +int main(int argv, char** argc) +{ + size_t nentries = 0; + + try { + + TCLAP::CmdLine cmd("Command line arguments for ", '='); + + TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); + cmd.add(EArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nentries = EArg.getValue(); + + } + catch (TCLAP::ArgException &e) { + std::cerr << "error: " << e.error() << " for arg " << e.argId() + << std::endl; + } + + //----------------- + //Liang's Model + + + + // + + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); + double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.41478; + double f0X_Width = 0.309491; + double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); + double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); + + double NR_RC = 1.0; + double NR_IMC = 0.0; + + double D_MASS = 1.86962; + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + + //====================================================== + //Phi + auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); + auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); + auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); + auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); + + Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); + + auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); + + + + //====================================================== + //f0(X) + + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); + + Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); + + //====================================================== + //f0 + + auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, +100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, +100); + auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); + auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + + + Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + + auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); + + //====================================================== + + //NR + coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); + coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); + + auto NR = NonResonant(coef_re, coef_im); + //====================================================== + //Total: Model |N.R + \sum{ Resonaces }|^2 + + //parametric lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ + + hydra::complex r(0,0); + + for(unsigned int i=0; i< n;i++) r += x[i]; + + return hydra::norm(r); + }); + + //model-functor + auto Model = hydra::compose(Norm, + Phi_Resonance, + f0X_Resonance, f0_Resonance, + NR ); + + //-------------------- + //generator + hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi J/psi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + +#ifdef _ROOT_AVAILABLE_ + + TH3D Dalitz_Resonances("Dalitz_Resonances", + "Dalitz - Toy Data -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + TH3D Dalitz_Fit("Dalitz_Fit", + "Dalitz - Fit -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + //control plots + TH2D Normalization("normalization", + "Model PDF Normalization;Norm;Error", + 200, 275.0, 305.0, + 200, 0.58, 0.64); + + + TH3D Phi_12_HIST,Phi_13_HIST, + f0X_12_HIST,f0X_13_HIST, + f0_12_HIST,f0_13_HIST, + NR_HIST ; + + double Phi_12_FF, Phi_13_FF, + f0X_12_FF,f0X_13_FF, + f0_12_FF,f0_13_FF, + NR_FF; +#endif + + hydra::Decays<3, hydra::host::sys_t > toy_data; + + //toy data production on device + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; + std::cout << "======================================" << std::endl; + + + auto start = std::chrono::high_resolution_clock::now(); + + generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< toy_data.size() << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; + + }//toy data production on device + + std::ofstream writer; + writer.open("toyData.txt"); + + if(!writer.is_open()){ + std::cout << "file not open" << std::endl; + }else { + + for (auto event : toy_data) { + + double weight = hydra::get<0>(event); + hydra::Vector4R Kminus = hydra::get<1>(event); + hydra::Vector4R Kplus1 = hydra::get<2>(event); + hydra::Vector4R Kplus2 = hydra::get<3>(event); + + double MKminusKplus1 = (Kminus + Kplus1).mass2(); + double MKminusKplus2 = (Kminus + Kplus2).mass2(); + + writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; + } + + std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); + + auto particles = toy_data_temp.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + + std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_variables[i] << std::endl; + + //flat dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + auto start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + std::cout << std::endl; + std::cout << std::endl; + +#ifdef _ROOT_AVAILABLE_ + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + +#endif + +#endif + + } + + + // fit + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "=============== 3 - FIT ==============" << std::endl; + std::cout << "======================================" << std::endl; + std::cout << std::endl << std::endl; + //pdf + auto Model_PDF = hydra::make_pdf( Model, + hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); + + + + std::cout << "-----------------------------------------"< toy_data_temp(toy_data); + auto particles = toy_data_temp.GetUnweightedDecays(); + + auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), + particles.end()); + + //print level + ROOT::Minuit2::MnPrint::SetLevel(3); + hydra::Print::SetLevel(hydra::WARNING); + + //minimization strategy + MnStrategy strategy(2); + + //create Migrad minimizer + MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); + + //print parameters before fitting + std::cout< elapsed_d = end_d - start_d; + + //time + std::cout << "-----------------------------------------"< fit_data(nentries); + + auto start = std::chrono::high_resolution_clock::now(); + + //generate the final state particles + phsp.Generate(B0, fit_data.begin(), fit_data.end()); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------- Device (fit data) -----------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + fit_data.Reweight(fcn.GetPDF().GetFunctor()); + + auto particles_fit = fit_data.GetUnweightedDecays(); + auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); + auto dalitz_weights_fit = fit_data.GetWeights(); + + std::cout << std::endl; + std::cout << std::endl; + + std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; + + //model dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables_fit.begin(), + dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); + + end = std::chrono::high_resolution_clock::now(); + + elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + //================================== + // Optimized components + //================================== + auto Opt_Model = fcn.GetPDF().GetFunctor(); + + auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); + auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); + auto f0X_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); + auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); + auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); + auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); + auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); + + //================================== + // Draw components + //================================== + Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); + Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); + f0X_12_HIST = histogram_component(f0X_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_12_HIST", nentries); + f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); + f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); + f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); + NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); + + + //================================== + // Fit fractions + //================================== + Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_12_FF = fit_fraction(f0X_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + + + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; + std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; + std::cout << "f0X_12_FF :" << f0X_12_FF << std::endl; + std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; + std::cout << "f0_12_FF :" << f0_12_FF << std::endl; + std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "NR_FF :" << NR_FF << std::endl; + std::cout << "Sum :" + << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; + +#ifdef _ROOT_AVAILABLE_ + + { + std::vector integrals; + std::vector integrals_error; + + for(auto x: fcn.GetPDF().GetNormCache() ){ + integrals.push_back(x.second.first); + integrals_error.push_back(x.second.second); + + } + + auto integral_bounds = std::minmax_element(integrals.begin(), + integrals.end()); + + auto integral_error_bounds = std::minmax_element(integrals_error.begin(), + integrals_error.end()); + + Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); + Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); + + for(auto x: fcn.GetPDF().GetNormCache() ){ + + Normalization.Fill(x.second.first, x.second.second ); + } + } + + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } +#endif + + +#endif + + } + + + +#ifdef _ROOT_AVAILABLE_ + + + TApplication *m_app=new TApplication("myapp",0,0); + + + Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); + + Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); + Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); + f0X_12_HIST.Scale( f0X_12_FF*Dalitz_Fit.Integral()/f0X_12_HIST.Integral() ); + f0X_13_HIST.Scale( f0X_13_FF*Dalitz_Fit.Integral()/f0X_13_HIST.Integral() ); + f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); + f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); + + NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); + + //============================================================= + //projections + TH1* hist2D=0; + + TCanvas canvas_3("canvas_3", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_3.SaveAs("Dataset1.png"); + + TCanvas canvas_4("canvas_4", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_4.SaveAs("Dataset2.png"); + + + TCanvas canvas_5("canvas_5", "Fit", 500, 500); + hist2D = Dalitz_Fit.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_5.SaveAs("FitResult1.png"); + + + TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); + hist2D = Dalitz_Fit.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_6.SaveAs("FitResult2.png"); + + + //============================================================= + //projections + TH1* hist=0; + const char* axis =0; + + auto Phi_Color = kViolet-5; + auto f0X_Color = kBlue; + auto f0_Color = kGreen; + auto NR_Color = kBlack; + + double X1NDC = 0.262458; + double Y1NDC = 0.127544; + double X2NDC = 0.687708; + double Y2NDC = 0.35; + + + //============================== + axis = "x"; + + TCanvas canvas_x("canvas_x", "", 600, 750); + + + + auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_x.SetEntrySeparation(0.3); + legend_x.SetNColumns(2); + legend_x.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_x.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_x.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"NR","l"); + + canvas_x.SaveAs("Proj_X.png"); + + canvas_x.SetLogy(1); + + legend_x.Draw(); + + canvas_x.SaveAs("Proj_LogX.png"); + + //============================================================= + + axis = "y"; + + TCanvas canvas_y("canvas_y", "", 600, 750); + + + auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_y.SetEntrySeparation(0.3); + legend_y.SetNColumns(2); + legend_y.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_y.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_y.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"NR","l"); + + canvas_y.SaveAs("Proj_Y.png"); + + canvas_y.SetLogy(1); + + legend_y.Draw(); + + canvas_y.SaveAs("Proj_LogY.png"); + + + //============================================================= + + + + axis = "z"; + + TCanvas canvas_z("canvas_z", "", 600, 750); + + auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_z.SetEntrySeparation(0.3); + legend_z.SetNColumns(2); + legend_z.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_z.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_z.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{13}","l"); + + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"NR","l"); + + canvas_z.SaveAs("Proj_Z.png"); + + canvas_z.SetLogy(1); + + legend_z.Draw(); + + canvas_z.SaveAs("Proj_LogZ.png"); + + //============================================================= + + TCanvas canvas_7("canvas_7", "Normalization", 500, 500); + Normalization.Draw("colz"); + + + m_app->Run(); + +#endif + + return 0; +} + + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //allocate memory to hold the final states particles + hydra::Decays<3, Backend > _data(bunch_size); + + std::srand(7531594562); + + do { + phsp.SetSeed(std::rand()); + + //generate the final state particles + phsp.Generate(D, _data.begin(), _data.end()); + + auto last = _data.Unweight(model, 1.0); + + decays.insert(decays.size()==0? decays.begin():decays.end(), + _data.begin(), _data.begin()+last ); + + } while(decays.size() +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //norm lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + + auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); + auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); + + + return amp_int.first/model_int.first; + +} + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K+ mass + const double Kplus_MASS = masses[2];// K- mass + + TH3D Component(name, + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + //norm lambda + auto Norm = hydra::wrap_lambda( + []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + hydra::Decays<3, hydra::device::sys_t > events(nentries); + + phsp.Generate(D, events.begin(), events.end()); + + events.Reweight(functor); + + auto particles = events.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + auto dalitz_weights = events.GetWeights(); + + //model dalitz histogram + hydra::SparseHistogram Hist_Component{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + Hist_Component.Fill( dalitz_variables.begin(), + dalitz_variables.end(), dalitz_weights.begin() ); + + for(auto entry : Hist_Component){ + + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Component.GetIndexes(bin, bins); + Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + return Component; + +} + + + +#endif /* D2KKK_INL_ */ diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index c0f407685..e122cf621 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -153,8 +153,7 @@ namespace hydra { const double resonance_mass = _par[0]; const double rho1 = _par[1]; - const double temp_rho2 = _par[2]; - const double rho2 = temp_rho2*rho1; + const double rho2 = _par[2]; return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); @@ -167,7 +166,7 @@ namespace hydra { hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { - + hydra::complex ret(0.0,0.0); double pipmass = 0.13957018; double pi0mass = 0.1349766; @@ -183,32 +182,33 @@ namespace hydra { double rhokk_real = 0, rhokk_imag = 0; - if(s >= twopimasssq) - rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s); // Above pi+pi- threshold + rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold else rhopipi_imag = (2. / 3) * TMath::Sqrt(-1 + twopimasssq / s); if(s >= twopi0masssq) - rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s); // Above pi0pi0 threshold + rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold else - rhopipi_imag = (1. / 3) * TMath::Sqrt(-1 + twopi0masssq / s); + rhopipi_imag = (1. / 3) * TMath::Sqrt(-1 + twopi0masssq / s ); if(s >= twokmasssq) - rhokk_real = 0.5 * TMath::Sqrt(1 - twokmasssq / s); // Above K+K- threshold + rhokk_real = 0.5 * TMath::Sqrt(1 - twokmasssq / s ); // Above K+K- threshold else - rhokk_imag = 0.5 * TMath::Sqrt(-1 + twokmasssq / s); + rhokk_imag = 0.5 * TMath::Sqrt(-1 + twokmasssq / s ); if(s >= twok0masssq) - rhokk_real = 0.5 * TMath::Sqrt(1 - twok0masssq / s); // Above K0K0 threshold + rhokk_real = 0.5 * TMath::Sqrt(1 - twok0masssq / s ); // Above K0K0 threshold else - rhokk_imag = 0.5 * TMath::Sqrt(-1 + twok0masssq / s); + rhokk_imag = 0.5 * TMath::Sqrt(-1 + twok0masssq / s ); + double A = (resonance_mass * resonance_mass - s) + resonance_mass * (rhopipi_imag * g1 + rhokk_imag * g2); double B = resonance_mass * (rhopipi_real * g1 + rhokk_real * g2); double C = 1.0 / (A * A + B * B); - hydra::complex retur(A * C, B * C); + hydra::complex retur(A * C, B * C); + ret+=retur; - return retur; + return ret; } From 301b2c200b5560380a02f6707e42d2d61b1b92e8 Mon Sep 17 00:00:00 2001 From: juan leite Date: Fri, 9 Mar 2018 18:00:49 +0100 Subject: [PATCH 04/16] clear unused code --- examples/NIPS_HYDRA/D2KKK.inl | 224 +-- examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl | 1351 +++++++++++++++++ hydra/functions/FlatteLineShape.h | 11 +- 3 files changed, 1471 insertions(+), 115 deletions(-) create mode 100644 examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl diff --git a/examples/NIPS_HYDRA/D2KKK.inl b/examples/NIPS_HYDRA/D2KKK.inl index 54bd62286..a8891c324 100644 --- a/examples/NIPS_HYDRA/D2KKK.inl +++ b/examples/NIPS_HYDRA/D2KKK.inl @@ -101,66 +101,67 @@ using namespace hydra::placeholders; template class Resonance: public hydra::BaseFunctor, hydra::complex, 4> { - using hydra::BaseFunctor, hydra::complex, 4>::_par; + using hydra::BaseFunctor, hydra::complex, 4>::_par; - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); public: - Resonance() = delete; + Resonance() = delete; - Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, - hydra::Parameter const& mass, hydra::Parameter const& width, - double mother_mass, double daugther1_mass, - double daugther2_mass, double daugther3_mass, - double radi): - hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, - fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) - {} + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} - __hydra_dual__ - Resonance( Resonance< CHANNEL,L> const& other): - hydra::BaseFunctor, hydra::complex, 4>(other), - fLineShape(other.GetLineShape()) - {} + __host__ __device__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} - __hydra_dual__ inline - Resonance< CHANNEL ,L>& - operator=( Resonance< CHANNEL ,L> const& other) - { - if(this==&other) return *this; + __host__ __device__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; - hydra::BaseFunctor, hydra::complex, 4>::operator=(other); - fLineShape=other.GetLineShape(); + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); - return *this; - } + return *this; + } - __hydra_dual__ inline - hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + __host__ __device__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } - __hydra_dual__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; - fLineShape.SetParameter(0, _par[2]); - fLineShape.SetParameter(1, _par[3]); + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); - double theta = fCosDecayAngle((p1 + p2 + p3), (p1 + p2), p1); - double angular = fAngularDist(theta); - auto r = hydra::complex(_par[0], _par[1]) * fLineShape((p1 + p2).mass()) * angular; + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; - return r; - } + return r; + + } private: @@ -176,37 +177,37 @@ private: class NonResonant: public hydra::BaseFunctor, 2> { - using hydra::BaseFunctor, 2>::_par; + using hydra::BaseFunctor, 2>::_par; public: - NonResonant() = delete; + NonResonant() = delete; - NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): - hydra::BaseFunctor, 2>{c_re, c_im} - {} + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} - __hydra_dual__ - NonResonant( NonResonant const& other): - hydra::BaseFunctor, 2>(other) - {} + __host__ __device__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} - __hydra_dual__ - NonResonant& operator=( NonResonant const& other) - { - if(this==&other) return *this; + __host__ __device__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; - hydra::BaseFunctor, 2>::operator=(other); + hydra::BaseFunctor, 2>::operator=(other); - return *this; - } + return *this; + } - __hydra_dual__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __host__ __device__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - return hydra::complex(_par[0], _par[1]); - } + return hydra::complex(_par[0], _par[1]); + } }; @@ -229,12 +230,12 @@ public: fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) {} - __hydra_dual__ Flatte( Flatte const& other): + __host__ __device__ Flatte( Flatte const& other): hydra::BaseFunctor, hydra::complex, 5>(other), fLineShape(other.GetLineShape()) {} - __hydra_dual__ inline + __host__ __device__ inline Flatte& operator=( Flatte const& other) { @@ -246,11 +247,11 @@ public: return *this; } - __hydra_dual__ inline + __host__ __device__ inline hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } - __hydra_dual__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { hydra::Vector4R p1 = p[_I1]; hydra::Vector4R p2 = p[_I2]; @@ -319,49 +320,25 @@ int main(int argv, char** argc) // -/* double Phi_MASS = 1.019461; double Phi_Width = 0.004266; double Phi_RC = 1.0; double Phi_IMC = 0.0; double f0_MASS = 0.965; - double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180))/10; - double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180))/10; + double f0_amp = 12.341; + double f0_phase = -62.852 * (M_PI / 180); + double f0_RC = f0_amp * cos(f0_phase); + double f0_IMC = f0_amp * sin(f0_phase); double f0_rho1 = 0.165; double f0_rho2 = 4.21*f0_rho1; double f0X_MASS = 1.41478; double f0X_Width = 0.309491; - double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); - double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); - - double NR_RC = 1.0; - double NR_IMC = 0.0; - - double D_MASS = 1.86962; - double Kplus_MASS = 0.493677; // K+ mass - double Kminus_MASS = Kplus_MASS; - -*/ - - //liang model2 results - - double Phi_MASS = 1.019461; - double Phi_Width = 0.004266; - double Phi_RC = 1.0; - double Phi_IMC = 0.0; - - double f0_MASS = 0.965; - double f0_RC = 3.20; - double f0_IMC = -59.3; - double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; - - double f0X_MASS = 1.430; - double f0X_Width = 0.348; - double f0X_RC = 3.52; - double f0X_IMC = 13.8; + double f0X_amp = 11.918; + double f0X_phase = 20.248 * (M_PI / 180); + double f0X_RC = f0X_amp * cos(f0X_phase); + double f0X_IMC = f0X_amp * sin(f0X_phase); double NR_RC = 1.0; double NR_IMC = 0.0; @@ -370,7 +347,6 @@ int main(int argv, char** argc) double Kplus_MASS = 0.493677; // K+ mass double Kminus_MASS = Kplus_MASS; - //====================================================== //Phi auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); @@ -391,10 +367,10 @@ int main(int argv, char** argc) //====================================================== //f0(X) - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Error(0.019).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Error(0.049).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.58).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(8.1).Limits(-100,+100); + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); @@ -407,17 +383,17 @@ int main(int argv, char** argc) //====================================================== //f0 - auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.12).Limits(-100, +100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(5.1).Limits(-100, +100); + auto f0_amp_real = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-100, +100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_IMC").Value(f0_IMC).Error(0.0001).Limits(-100, +100); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); - auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - auto f0_Resonance = (f0_Resonance_13 + f0_Resonance_12); + auto f0_Resonance = f0_Resonance_12 + f0_Resonance_13; //====================================================== @@ -442,8 +418,8 @@ int main(int argv, char** argc) //model-functor auto Model = hydra::compose(Norm, Phi_Resonance, - f0X_Resonance, f0_Resonance - ); + f0X_Resonance, f0_Resonance, + NR ); //-------------------- //generator @@ -494,12 +470,13 @@ int main(int argv, char** argc) TH3D Phi_12_HIST,Phi_13_HIST, f0X_12_HIST,f0X_13_HIST, - f0_12_HIST,f0_13_HIST ; + f0_12_HIST,f0_13_HIST, + NR_HIST ; double Phi_12_FF, Phi_13_FF, f0X_12_FF,f0X_13_FF, - f0_12_FF,f0_13_FF - ; + f0_12_FF,f0_13_FF, + NR_FF; #endif hydra::Decays<3, hydra::host::sys_t > toy_data; @@ -779,6 +756,7 @@ int main(int argv, char** argc) auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); + auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); //================================== // Draw components @@ -789,6 +767,7 @@ int main(int argv, char** argc) f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); + NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); //================================== @@ -800,6 +779,8 @@ int main(int argv, char** argc) f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; @@ -807,8 +788,9 @@ int main(int argv, char** argc) std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; std::cout << "f0_12_FF :" << f0_12_FF << std::endl; std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "NR_FF :" << NR_FF << std::endl; std::cout << "Sum :" - << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF << std::endl; + << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; #ifdef _ROOT_AVAILABLE_ @@ -893,6 +875,8 @@ int main(int argv, char** argc) f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); + NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); + //============================================================= //projections TH1* hist2D=0; @@ -1012,7 +996,12 @@ int main(int argv, char** argc) legend_x.AddEntry(hist,"{f0}_{13}","l"); + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + legend_x.AddEntry(hist,"NR","l"); canvas_x.SaveAs("Proj_X.png"); @@ -1093,7 +1082,12 @@ int main(int argv, char** argc) legend_y.AddEntry(hist,"{f0}_{13}","l"); + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + legend_y.AddEntry(hist,"NR","l"); canvas_y.SaveAs("Proj_Y.png"); @@ -1176,6 +1170,12 @@ int main(int argv, char** argc) legend_z.AddEntry(hist,"{f0}_{13}","l"); + hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(NR_Color); + hist->SetLineStyle(5); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"NR","l"); canvas_z.SaveAs("Proj_Z.png"); diff --git a/examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl b/examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl new file mode 100644 index 000000000..54bd62286 --- /dev/null +++ b/examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl @@ -0,0 +1,1351 @@ +#ifndef D2KKK_INL_ +#define D2KKK_INL_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//command line +#include + +//hydra +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +//Minuit2 +#include "Minuit2/FunctionMinimum.h" +#include "Minuit2/MnUserParameterState.h" +#include "Minuit2/MnPrint.h" +#include "Minuit2/MnMigrad.h" +#include "Minuit2/MnMinimize.h" + +/*------------------------------------- + * Include classes from ROOT to fill + * and draw histograms and plots. + *------------------------------------- + */ +#ifdef _ROOT_AVAILABLE_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif //_ROOT_AVAILABLE_ + +using namespace ROOT::Minuit2; +using namespace hydra::placeholders; + + + +template +class Resonance: public hydra::BaseFunctor, hydra::complex, 4> +{ + using hydra::BaseFunctor, hydra::complex, 4>::_par; + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + +public: + + Resonance() = delete; + + Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, + hydra::Parameter const& mass, hydra::Parameter const& width, + double mother_mass, double daugther1_mass, + double daugther2_mass, double daugther3_mass, + double radi): + hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, + fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) + {} + + + __hydra_dual__ + Resonance( Resonance< CHANNEL,L> const& other): + hydra::BaseFunctor, hydra::complex, 4>(other), + fLineShape(other.GetLineShape()) + {} + + __hydra_dual__ inline + Resonance< CHANNEL ,L>& + operator=( Resonance< CHANNEL ,L> const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 4>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __hydra_dual__ inline + hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } + + __hydra_dual__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + + fLineShape.SetParameter(0, _par[2]); + fLineShape.SetParameter(1, _par[3]); + + double theta = fCosDecayAngle((p1 + p2 + p3), (p1 + p2), p1); + double angular = fAngularDist(theta); + auto r = hydra::complex(_par[0], _par[1]) * fLineShape((p1 + p2).mass()) * angular; + + return r; + } + +private: + + mutable hydra::BreitWignerLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + +class NonResonant: public hydra::BaseFunctor, 2> +{ + + using hydra::BaseFunctor, 2>::_par; + +public: + + NonResonant() = delete; + + NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): + hydra::BaseFunctor, 2>{c_re, c_im} + {} + + + __hydra_dual__ + NonResonant( NonResonant const& other): + hydra::BaseFunctor, 2>(other) + {} + + __hydra_dual__ + NonResonant& operator=( NonResonant const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, 2>::operator=(other); + + return *this; + } + + __hydra_dual__ inline + hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + return hydra::complex(_par[0], _par[1]); + } + +}; + +template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +{ + + constexpr static unsigned int _I1 = CHANNEL-1; + constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; + constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); + + using hydra::BaseFunctor, hydra::complex, 5>::_par; + +public: + + Flatte() = delete; + + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): + hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, + fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + {} + + __hydra_dual__ Flatte( Flatte const& other): + hydra::BaseFunctor, hydra::complex, 5>(other), + fLineShape(other.GetLineShape()) + {} + + __hydra_dual__ inline + Flatte& + operator=( Flatte const& other) + { + if(this==&other) return *this; + + hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + fLineShape=other.GetLineShape(); + + return *this; + } + + __hydra_dual__ inline + hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } + + + __hydra_dual__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { + + hydra::Vector4R p1 = p[_I1]; + hydra::Vector4R p2 = p[_I2]; + hydra::Vector4R p3 = p[_I3]; + + fLineShape.SetParameter(0,_par[2]); + fLineShape.SetParameter(1,_par[3]); + fLineShape.SetParameter(2,_par[4]); + + double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); + double angular = fAngularDist(theta); + + auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; + + return r; + } + +private: + + mutable hydra::FlatteLineShape fLineShape; + hydra::CosHelicityAngle fCosDecayAngle; + hydra::ZemachFunction fAngularDist; + + +}; + + + + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); + +template +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); + +int main(int argv, char** argc) +{ + size_t nentries = 0; + + try { + + TCLAP::CmdLine cmd("Command line arguments for ", '='); + + TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); + cmd.add(EArg); + + // Parse the argv array. + cmd.parse(argv, argc); + + // Get the value parsed by each arg. + nentries = EArg.getValue(); + + } + catch (TCLAP::ArgException &e) { + std::cerr << "error: " << e.error() << " for arg " << e.argId() + << std::endl; + } + + //----------------- + //Liang's Model + + + + // + +/* + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180))/10; + double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180))/10; + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.41478; + double f0X_Width = 0.309491; + double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); + double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); + + double NR_RC = 1.0; + double NR_IMC = 0.0; + + double D_MASS = 1.86962; + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + +*/ + + //liang model2 results + + double Phi_MASS = 1.019461; + double Phi_Width = 0.004266; + double Phi_RC = 1.0; + double Phi_IMC = 0.0; + + double f0_MASS = 0.965; + double f0_RC = 3.20; + double f0_IMC = -59.3; + double f0_rho1 = 0.165; + double f0_rho2 = 4.21*f0_rho1; + + double f0X_MASS = 1.430; + double f0X_Width = 0.348; + double f0X_RC = 3.52; + double f0X_IMC = 13.8; + + double NR_RC = 1.0; + double NR_IMC = 0.0; + + double D_MASS = 1.86962; + double Kplus_MASS = 0.493677; // K+ mass + double Kminus_MASS = Kplus_MASS; + + + //====================================================== + //Phi + auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); + auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); + auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); + auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); + + Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, + D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); + + auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); + + + + //====================================================== + //f0(X) + + auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Error(0.019).Fixed(); + auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Error(0.049).Fixed(); + auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.58).Limits(-100,+100); + auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(8.1).Limits(-100,+100); + + Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, + D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); + + auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); + + //====================================================== + //f0 + + auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.12).Limits(-100, +100); + auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(5.1).Limits(-100, +100); + auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); + auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + + + Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + + auto f0_Resonance = (f0_Resonance_13 + f0_Resonance_12); + + //====================================================== + + //NR + coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); + coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); + + auto NR = NonResonant(coef_re, coef_im); + //====================================================== + //Total: Model |N.R + \sum{ Resonaces }|^2 + + //parametric lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ + + hydra::complex r(0,0); + + for(unsigned int i=0; i< n;i++) r += x[i]; + + return hydra::norm(r); + }); + + //model-functor + auto Model = hydra::compose(Norm, + Phi_Resonance, + f0X_Resonance, f0_Resonance + ); + + //-------------------- + //generator + hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi J/psi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + +#ifdef _ROOT_AVAILABLE_ + + TH3D Dalitz_Resonances("Dalitz_Resonances", + "Dalitz - Toy Data -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + TH3D Dalitz_Fit("Dalitz_Fit", + "Dalitz - Fit -;" + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + + //control plots + TH2D Normalization("normalization", + "Model PDF Normalization;Norm;Error", + 200, 275.0, 305.0, + 200, 0.58, 0.64); + + + TH3D Phi_12_HIST,Phi_13_HIST, + f0X_12_HIST,f0X_13_HIST, + f0_12_HIST,f0_13_HIST ; + + double Phi_12_FF, Phi_13_FF, + f0X_12_FF,f0X_13_FF, + f0_12_FF,f0_13_FF + ; +#endif + + hydra::Decays<3, hydra::host::sys_t > toy_data; + + //toy data production on device + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; + std::cout << "======================================" << std::endl; + + + auto start = std::chrono::high_resolution_clock::now(); + + generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< toy_data.size() << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; + + }//toy data production on device + + std::ofstream writer; + writer.open("toyData.txt"); + + if(!writer.is_open()){ + std::cout << "file not open" << std::endl; + }else { + + for (auto event : toy_data) { + + double weight = hydra::get<0>(event); + hydra::Vector4R Kminus = hydra::get<1>(event); + hydra::Vector4R Kplus1 = hydra::get<2>(event); + hydra::Vector4R Kplus2 = hydra::get<3>(event); + + double MKminusKplus1 = (Kminus + Kplus1).mass2(); + double MKminusKplus2 = (Kminus + Kplus2).mass2(); + + writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; + } + + std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); + + auto particles = toy_data_temp.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + + std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_variables[i] << std::endl; + + //flat dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + auto start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + std::cout << std::endl; + std::cout << std::endl; + +#ifdef _ROOT_AVAILABLE_ + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + +#endif + +#endif + + } + + + // fit + { + std::cout << std::endl; + std::cout << std::endl; + std::cout << "======================================" << std::endl; + std::cout << "=============== 3 - FIT ==============" << std::endl; + std::cout << "======================================" << std::endl; + std::cout << std::endl << std::endl; + //pdf + auto Model_PDF = hydra::make_pdf( Model, + hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); + + + + std::cout << "-----------------------------------------"< toy_data_temp(toy_data); + auto particles = toy_data_temp.GetUnweightedDecays(); + + auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), + particles.end()); + + //print level + ROOT::Minuit2::MnPrint::SetLevel(3); + hydra::Print::SetLevel(hydra::WARNING); + + //minimization strategy + MnStrategy strategy(2); + + //create Migrad minimizer + MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); + + //print parameters before fitting + std::cout< elapsed_d = end_d - start_d; + + //time + std::cout << "-----------------------------------------"< fit_data(nentries); + + auto start = std::chrono::high_resolution_clock::now(); + + //generate the final state particles + phsp.Generate(B0, fit_data.begin(), fit_data.end()); + + auto end = std::chrono::high_resolution_clock::now(); + + std::chrono::duration elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------- Device (fit data) -----------"<< std::endl; + std::cout << "| D+ -> K- K+ K+" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + fit_data.Reweight(fcn.GetPDF().GetFunctor()); + + auto particles_fit = fit_data.GetUnweightedDecays(); + auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); + auto dalitz_weights_fit = fit_data.GetWeights(); + + std::cout << std::endl; + std::cout << std::endl; + + std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; + + for( size_t i=0; i<10; i++ ) + std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; + + //model dalitz histogram + hydra::SparseHistogram Hist_Dalitz{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + start = std::chrono::high_resolution_clock::now(); + + Hist_Dalitz.Fill( dalitz_variables_fit.begin(), + dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); + + end = std::chrono::high_resolution_clock::now(); + + elapsed = end - start; + + //output + std::cout << std::endl; + std::cout << std::endl; + std::cout << "----------------- Device ----------------"<< std::endl; + std::cout << "| Sparse histogram fill" << std::endl; + std::cout << "| Number of events :"<< nentries << std::endl; + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; + std::cout << "-----------------------------------------"<< std::endl; + + + //================================== + // Optimized components + //================================== + auto Opt_Model = fcn.GetPDF().GetFunctor(); + + auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); + auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); + auto f0X_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); + auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); + auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); + auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); + + //================================== + // Draw components + //================================== + Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); + Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); + f0X_12_HIST = histogram_component(f0X_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_12_HIST", nentries); + f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); + f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); + f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); + + + //================================== + // Fit fractions + //================================== + Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_12_FF = fit_fraction(f0X_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; + std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; + std::cout << "f0X_12_FF :" << f0X_12_FF << std::endl; + std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; + std::cout << "f0_12_FF :" << f0_12_FF << std::endl; + std::cout << "f0_13_FF :" << f0_13_FF << std::endl; + std::cout << "Sum :" + << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF << std::endl; + +#ifdef _ROOT_AVAILABLE_ + + { + std::vector integrals; + std::vector integrals_error; + + for(auto x: fcn.GetPDF().GetNormCache() ){ + integrals.push_back(x.second.first); + integrals_error.push_back(x.second.second); + + } + + auto integral_bounds = std::minmax_element(integrals.begin(), + integrals.end()); + + auto integral_error_bounds = std::minmax_element(integrals_error.begin(), + integrals_error.end()); + + Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); + Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); + + for(auto x: fcn.GetPDF().GetNormCache() ){ + + Normalization.Fill(x.second.first, x.second.second ); + } + } + + +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + + //if device is cuda, bring the histogram data to the host + //to fill the ROOT histogram faster + { + hydra::SparseHistogram Hist_Temp(Hist_Dalitz); + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Temp) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Temp.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + } +#else + std::cout << "Filling a ROOT Histogram... " << std::endl; + + for(auto entry : Hist_Dalitz) + { + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Dalitz.GetIndexes(bin, bins); + Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } +#endif + + +#endif + + } + + + +#ifdef _ROOT_AVAILABLE_ + + + TApplication *m_app=new TApplication("myapp",0,0); + + + Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); + + Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); + Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); + f0X_12_HIST.Scale( f0X_12_FF*Dalitz_Fit.Integral()/f0X_12_HIST.Integral() ); + f0X_13_HIST.Scale( f0X_13_FF*Dalitz_Fit.Integral()/f0X_13_HIST.Integral() ); + f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); + f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); + + //============================================================= + //projections + TH1* hist2D=0; + + TCanvas canvas_3("canvas_3", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_3.SaveAs("Dataset1.png"); + + TCanvas canvas_4("canvas_4", "Dataset", 500, 500); + hist2D = Dalitz_Resonances.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->Draw("colz"); + canvas_4.SaveAs("Dataset2.png"); + + + TCanvas canvas_5("canvas_5", "Fit", 500, 500); + hist2D = Dalitz_Fit.Project3D("yz"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_5.SaveAs("FitResult1.png"); + + + TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); + hist2D = Dalitz_Fit.Project3D("xy"); + hist2D->SetTitle(""); + hist2D->SetStats(0); + hist2D->Draw("colz"); + canvas_6.SaveAs("FitResult2.png"); + + + //============================================================= + //projections + TH1* hist=0; + const char* axis =0; + + auto Phi_Color = kViolet-5; + auto f0X_Color = kBlue; + auto f0_Color = kGreen; + auto NR_Color = kBlack; + + double X1NDC = 0.262458; + double Y1NDC = 0.127544; + double X2NDC = 0.687708; + double Y2NDC = 0.35; + + + //============================== + axis = "x"; + + TCanvas canvas_x("canvas_x", "", 600, 750); + + + + auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_x.SetEntrySeparation(0.3); + legend_x.SetNColumns(2); + legend_x.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_x.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_x.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_x.AddEntry(hist,"{f0}_{13}","l"); + + + + canvas_x.SaveAs("Proj_X.png"); + + canvas_x.SetLogy(1); + + legend_x.Draw(); + + canvas_x.SaveAs("Proj_LogX.png"); + + //============================================================= + + axis = "y"; + + TCanvas canvas_y("canvas_y", "", 600, 750); + + + auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_y.SetEntrySeparation(0.3); + legend_y.SetNColumns(2); + legend_y.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_y.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_y.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_y.AddEntry(hist,"{f0}_{13}","l"); + + + + canvas_y.SaveAs("Proj_Y.png"); + + canvas_y.SetLogy(1); + + legend_y.Draw(); + + canvas_y.SaveAs("Proj_LogY.png"); + + + //============================================================= + + + + axis = "z"; + + TCanvas canvas_z("canvas_z", "", 600, 750); + + auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); + //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header + legend_z.SetEntrySeparation(0.3); + legend_z.SetNColumns(2); + legend_z.SetBorderSize(0); + + hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); + hist->SetLineColor(2); + hist->SetLineWidth(2); + hist->SetMinimum(0.001); + hist->SetStats(0); + hist->SetTitle(""); + + legend_z.AddEntry(hist,"Fit","l"); + + hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); + hist->SetMarkerStyle(8); + hist->SetMarkerSize(0.6); + hist->SetStats(0); + + legend_z.AddEntry(hist,"Data","lep"); + + hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{12}","l"); + + hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(Phi_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{#Phi}_{13}","l"); + + hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); + + hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0X_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); + + + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + //hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{12}","l"); + + hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist->SetLineStyle(2); + hist->SetLineColor(f0_Color); + hist->SetLineWidth(2); + + legend_z.AddEntry(hist,"{f0}_{13}","l"); + + + canvas_z.SaveAs("Proj_Z.png"); + + canvas_z.SetLogy(1); + + legend_z.Draw(); + + canvas_z.SaveAs("Proj_LogZ.png"); + + //============================================================= + + TCanvas canvas_7("canvas_7", "Normalization", 500, 500); + Normalization.Draw("colz"); + + + m_app->Run(); + +#endif + + return 0; +} + + +template +size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //allocate memory to hold the final states particles + hydra::Decays<3, Backend > _data(bunch_size); + + std::srand(7531594562); + + do { + phsp.SetSeed(std::rand()); + + //generate the final state particles + phsp.Generate(D, _data.begin(), _data.end()); + + auto last = _data.Unweight(model, 1.0); + + decays.insert(decays.size()==0? decays.begin():decays.end(), + _data.begin(), _data.begin()+last ); + + } while(decays.size() +double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K- mass + const double Kplus_MASS = masses[2];// K+ mass + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + + //norm lambda + auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + + auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); + auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); + + + return amp_int.first/model_int.first; + +} + +template +TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) +{ + const double D_MASS = masses[0];// D+ mass + const double Kminus_MASS = masses[1];// K+ mass + const double Kplus_MASS = masses[2];// K- mass + + TH3D Component(name, + "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), + 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); + + //-------------------- + //generator + hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); + // Create PhaseSpace object for B0-> K pi pi + hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; + + // functor to calculate the 2-body masses + auto dalitz_calculator = hydra::wrap_lambda( + []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ + + double M2_12 = (p[0]+p[1]).mass2(); + double M2_13 = (p[0]+p[2]).mass2(); + double M2_23 = (p[1]+p[2]).mass2(); + + return hydra::make_tuple(M2_12, M2_13, M2_23); + }); + + //norm lambda + auto Norm = hydra::wrap_lambda( + []__host__ __device__ (unsigned int n, hydra::complex* x){ + + return hydra::norm(x[0]); + }); + + //functor + auto functor = hydra::compose(Norm, amp); + + hydra::Decays<3, hydra::device::sys_t > events(nentries); + + phsp.Generate(D, events.begin(), events.end()); + + events.Reweight(functor); + + auto particles = events.GetUnweightedDecays(); + auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); + auto dalitz_weights = events.GetWeights(); + + //model dalitz histogram + hydra::SparseHistogram Hist_Component{ + {100,100,100}, + {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, + {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} + }; + + Hist_Component.Fill( dalitz_variables.begin(), + dalitz_variables.end(), dalitz_weights.begin() ); + + for(auto entry : Hist_Component){ + + size_t bin = hydra::get<0>(entry); + double content = hydra::get<1>(entry); + unsigned int bins[3]; + Hist_Component.GetIndexes(bin, bins); + Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); + + } + + return Component; + +} + + + +#endif /* D2KKK_INL_ */ diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index e122cf621..672fcc8a5 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -1,6 +1,11 @@ -// -// Created by juan on 07/03/18. -// +/* + * FlatteLineShape.h + * + * Created on: 09/03/2018 Based on Liang Sun code + * Author: Juan + * + * + */ #ifndef HYDRA_EXAMPLES_AND_DOCUMENTATION_FLATTELINESHAPE_H #define HYDRA_EXAMPLES_AND_DOCUMENTATION_FLATTELINESHAPE_H From 1cffbcd97e55ed8347924331b08d9ace8a414989 Mon Sep 17 00:00:00 2001 From: juan leite Date: Sat, 10 Mar 2018 18:19:31 +0100 Subject: [PATCH 05/16] cleaning some code --- .idea/codeStyles/Project.xml | 29 - .idea/misc.xml | 4 - .idea/vcs.xml | 6 - CMakeLists.txt | 2 +- examples/NIPS_HYDRA/CMakeLists.txt | 8 - examples/NIPS_HYDRA/D2KKK.inl | 1351 ----------------- examples/NIPS_HYDRA/LICENSE | 674 -------- examples/NIPS_HYDRA/README.md | 2 - examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl | 1263 --------------- .../NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl | 1347 ---------------- examples/phys/CMakeLists.txt | 1 + .../D2KKK.cu => phys/FlatteLineShape.cpp} | 14 +- .../D2KKK.cpp => phys/FlatteLineShape.cu} | 14 +- .../D2KKK.inl => phys/FlatteLineShape.inl} | 259 +--- hydra/functions/FlatteLineShape.h | 73 +- 15 files changed, 138 insertions(+), 4909 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml delete mode 100644 examples/NIPS_HYDRA/CMakeLists.txt delete mode 100644 examples/NIPS_HYDRA/D2KKK.inl delete mode 100644 examples/NIPS_HYDRA/LICENSE delete mode 100644 examples/NIPS_HYDRA/README.md delete mode 100644 examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl delete mode 100644 examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl rename examples/{NIPS_HYDRA/D2KKK.cu => phys/FlatteLineShape.cpp} (82%) rename examples/{NIPS_HYDRA/D2KKK.cpp => phys/FlatteLineShape.cu} (82%) rename examples/{NIPS_HYDRA/inl/liangModel2/D2KKK.inl => phys/FlatteLineShape.inl} (82%) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626c2..000000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 79b3c9483..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f4..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dcea23af..de385322f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,7 @@ add_subdirectory(examples/random) add_subdirectory(examples/histograming) add_subdirectory(examples/async) add_subdirectory(examples/misc) -add_subdirectory(examples/NIPS_HYDRA) + if(Minuit2_FOUND) add_subdirectory(examples/phys) add_subdirectory(examples/fit) diff --git a/examples/NIPS_HYDRA/CMakeLists.txt b/examples/NIPS_HYDRA/CMakeLists.txt deleted file mode 100644 index 1073967bc..000000000 --- a/examples/NIPS_HYDRA/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -project(examples) - -#+++++++++++++++++++++++++++++++++ -# Hydra NIPS | -#+++++++++++++++++++++++++++++++++ -ADD_HYDRA_EXAMPLE(D2KKK) - - diff --git a/examples/NIPS_HYDRA/D2KKK.inl b/examples/NIPS_HYDRA/D2KKK.inl deleted file mode 100644 index a8891c324..000000000 --- a/examples/NIPS_HYDRA/D2KKK.inl +++ /dev/null @@ -1,1351 +0,0 @@ -#ifndef D2KKK_INL_ -#define D2KKK_INL_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -/*------------------------------------- - * Include classes from ROOT to fill - * and draw histograms and plots. - *------------------------------------- - */ -#ifdef _ROOT_AVAILABLE_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif //_ROOT_AVAILABLE_ - -using namespace ROOT::Minuit2; -using namespace hydra::placeholders; - - - -template -class Resonance: public hydra::BaseFunctor, hydra::complex, 4> -{ - using hydra::BaseFunctor, hydra::complex, 4>::_par; - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - -public: - - Resonance() = delete; - - Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, - hydra::Parameter const& mass, hydra::Parameter const& width, - double mother_mass, double daugther1_mass, - double daugther2_mass, double daugther3_mass, - double radi): - hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, - fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) - {} - - - __host__ __device__ - Resonance( Resonance< CHANNEL,L> const& other): - hydra::BaseFunctor, hydra::complex, 4>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Resonance< CHANNEL ,L>& - operator=( Resonance< CHANNEL ,L> const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 4>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - - fLineShape.SetParameter(0, _par[2]); - fLineShape.SetParameter(1, _par[3]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - - } - -private: - - mutable hydra::BreitWignerLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - -class NonResonant: public hydra::BaseFunctor, 2> -{ - - using hydra::BaseFunctor, 2>::_par; - -public: - - NonResonant() = delete; - - NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): - hydra::BaseFunctor, 2>{c_re, c_im} - {} - - - __host__ __device__ - NonResonant( NonResonant const& other): - hydra::BaseFunctor, 2>(other) - {} - - __host__ __device__ - NonResonant& operator=( NonResonant const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, 2>::operator=(other); - - return *this; - } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - return hydra::complex(_par[0], _par[1]); - } - -}; - -template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> -{ - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - using hydra::BaseFunctor, hydra::complex, 5>::_par; - -public: - - Flatte() = delete; - - Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, - double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): - hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, - fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) - {} - - __host__ __device__ Flatte( Flatte const& other): - hydra::BaseFunctor, hydra::complex, 5>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Flatte& - operator=( Flatte const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 5>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } - - - __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - fLineShape.SetParameter(0,_par[2]); - fLineShape.SetParameter(1,_par[3]); - fLineShape.SetParameter(2,_par[4]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - - auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - } - -private: - - mutable hydra::FlatteLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); - -template -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); - -int main(int argv, char** argc) -{ - size_t nentries = 0; - - try { - - TCLAP::CmdLine cmd("Command line arguments for ", '='); - - TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); - cmd.add(EArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nentries = EArg.getValue(); - - } - catch (TCLAP::ArgException &e) { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - //----------------- - //Liang's Model - - - - // - - double Phi_MASS = 1.019461; - double Phi_Width = 0.004266; - double Phi_RC = 1.0; - double Phi_IMC = 0.0; - - double f0_MASS = 0.965; - double f0_amp = 12.341; - double f0_phase = -62.852 * (M_PI / 180); - double f0_RC = f0_amp * cos(f0_phase); - double f0_IMC = f0_amp * sin(f0_phase); - double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; - - double f0X_MASS = 1.41478; - double f0X_Width = 0.309491; - double f0X_amp = 11.918; - double f0X_phase = 20.248 * (M_PI / 180); - double f0X_RC = f0X_amp * cos(f0X_phase); - double f0X_IMC = f0X_amp * sin(f0X_phase); - - double NR_RC = 1.0; - double NR_IMC = 0.0; - - double D_MASS = 1.86962; - double Kplus_MASS = 0.493677; // K+ mass - double Kminus_MASS = Kplus_MASS; - - //====================================================== - //Phi - auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); - auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); - auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); - auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); - - Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); - - auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); - - - - //====================================================== - //f0(X) - - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); - - Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); - - //====================================================== - //f0 - - auto f0_amp_real = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-100, +100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_IMC").Value(f0_IMC).Error(0.0001).Limits(-100, +100); - auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); - auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); - auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); - - - Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - - auto f0_Resonance = f0_Resonance_12 + f0_Resonance_13; - - //====================================================== - - //NR - coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); - coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); - - auto NR = NonResonant(coef_re, coef_im); - //====================================================== - //Total: Model |N.R + \sum{ Resonaces }|^2 - - //parametric lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ - - hydra::complex r(0,0); - - for(unsigned int i=0; i< n;i++) r += x[i]; - - return hydra::norm(r); - }); - - //model-functor - auto Model = hydra::compose(Norm, - Phi_Resonance, - f0X_Resonance, f0_Resonance, - NR ); - - //-------------------- - //generator - hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi J/psi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - -#ifdef _ROOT_AVAILABLE_ - - TH3D Dalitz_Resonances("Dalitz_Resonances", - "Dalitz - Toy Data -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - TH3D Dalitz_Fit("Dalitz_Fit", - "Dalitz - Fit -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - //control plots - TH2D Normalization("normalization", - "Model PDF Normalization;Norm;Error", - 200, 275.0, 305.0, - 200, 0.58, 0.64); - - - TH3D Phi_12_HIST,Phi_13_HIST, - f0X_12_HIST,f0X_13_HIST, - f0_12_HIST,f0_13_HIST, - NR_HIST ; - - double Phi_12_FF, Phi_13_FF, - f0X_12_FF,f0X_13_FF, - f0_12_FF,f0_13_FF, - NR_FF; -#endif - - hydra::Decays<3, hydra::host::sys_t > toy_data; - - //toy data production on device - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; - std::cout << "======================================" << std::endl; - - - auto start = std::chrono::high_resolution_clock::now(); - - generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< toy_data.size() << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; - - }//toy data production on device - - std::ofstream writer; - writer.open("toyData.txt"); - - if(!writer.is_open()){ - std::cout << "file not open" << std::endl; - }else { - - for (auto event : toy_data) { - - double weight = hydra::get<0>(event); - hydra::Vector4R Kminus = hydra::get<1>(event); - hydra::Vector4R Kplus1 = hydra::get<2>(event); - hydra::Vector4R Kplus2 = hydra::get<3>(event); - - double MKminusKplus1 = (Kminus + Kplus1).mass2(); - double MKminusKplus2 = (Kminus + Kplus2).mass2(); - - writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; - } - - std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); - - auto particles = toy_data_temp.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - - std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_variables[i] << std::endl; - - //flat dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - auto start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - std::cout << std::endl; - std::cout << std::endl; - -#ifdef _ROOT_AVAILABLE_ - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - -#endif - -#endif - - } - - - // fit - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "=============== 3 - FIT ==============" << std::endl; - std::cout << "======================================" << std::endl; - std::cout << std::endl << std::endl; - //pdf - auto Model_PDF = hydra::make_pdf( Model, - hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); - - - - std::cout << "-----------------------------------------"< toy_data_temp(toy_data); - auto particles = toy_data_temp.GetUnweightedDecays(); - - auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), - particles.end()); - - //print level - ROOT::Minuit2::MnPrint::SetLevel(3); - hydra::Print::SetLevel(hydra::WARNING); - - //minimization strategy - MnStrategy strategy(2); - - //create Migrad minimizer - MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); - - //print parameters before fitting - std::cout< elapsed_d = end_d - start_d; - - //time - std::cout << "-----------------------------------------"< fit_data(nentries); - - auto start = std::chrono::high_resolution_clock::now(); - - //generate the final state particles - phsp.Generate(B0, fit_data.begin(), fit_data.end()); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------- Device (fit data) -----------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - fit_data.Reweight(fcn.GetPDF().GetFunctor()); - - auto particles_fit = fit_data.GetUnweightedDecays(); - auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); - auto dalitz_weights_fit = fit_data.GetWeights(); - - std::cout << std::endl; - std::cout << std::endl; - - std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; - - //model dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables_fit.begin(), - dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); - - end = std::chrono::high_resolution_clock::now(); - - elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - //================================== - // Optimized components - //================================== - auto Opt_Model = fcn.GetPDF().GetFunctor(); - - auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); - auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); - auto f0X_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); - auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); - auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); - auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); - auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); - - //================================== - // Draw components - //================================== - Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); - Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); - f0X_12_HIST = histogram_component(f0X_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_12_HIST", nentries); - f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); - f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); - f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); - NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); - - - //================================== - // Fit fractions - //================================== - Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0X_12_FF = fit_fraction(f0X_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - - - std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; - std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; - std::cout << "f0X_12_FF :" << f0X_12_FF << std::endl; - std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; - std::cout << "f0_12_FF :" << f0_12_FF << std::endl; - std::cout << "f0_13_FF :" << f0_13_FF << std::endl; - std::cout << "NR_FF :" << NR_FF << std::endl; - std::cout << "Sum :" - << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; - -#ifdef _ROOT_AVAILABLE_ - - { - std::vector integrals; - std::vector integrals_error; - - for(auto x: fcn.GetPDF().GetNormCache() ){ - integrals.push_back(x.second.first); - integrals_error.push_back(x.second.second); - - } - - auto integral_bounds = std::minmax_element(integrals.begin(), - integrals.end()); - - auto integral_error_bounds = std::minmax_element(integrals_error.begin(), - integrals_error.end()); - - Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); - Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); - - for(auto x: fcn.GetPDF().GetNormCache() ){ - - Normalization.Fill(x.second.first, x.second.second ); - } - } - - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } -#endif - - -#endif - - } - - - -#ifdef _ROOT_AVAILABLE_ - - - TApplication *m_app=new TApplication("myapp",0,0); - - - Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); - - Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); - Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); - f0X_12_HIST.Scale( f0X_12_FF*Dalitz_Fit.Integral()/f0X_12_HIST.Integral() ); - f0X_13_HIST.Scale( f0X_13_FF*Dalitz_Fit.Integral()/f0X_13_HIST.Integral() ); - f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); - f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); - - NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); - - //============================================================= - //projections - TH1* hist2D=0; - - TCanvas canvas_3("canvas_3", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_3.SaveAs("Dataset1.png"); - - TCanvas canvas_4("canvas_4", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_4.SaveAs("Dataset2.png"); - - - TCanvas canvas_5("canvas_5", "Fit", 500, 500); - hist2D = Dalitz_Fit.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_5.SaveAs("FitResult1.png"); - - - TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); - hist2D = Dalitz_Fit.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_6.SaveAs("FitResult2.png"); - - - //============================================================= - //projections - TH1* hist=0; - const char* axis =0; - - auto Phi_Color = kViolet-5; - auto f0X_Color = kBlue; - auto f0_Color = kGreen; - auto NR_Color = kBlack; - - double X1NDC = 0.262458; - double Y1NDC = 0.127544; - double X2NDC = 0.687708; - double Y2NDC = 0.35; - - - //============================== - axis = "x"; - - TCanvas canvas_x("canvas_x", "", 600, 750); - - - - auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_x.SetEntrySeparation(0.3); - legend_x.SetNColumns(2); - legend_x.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_x.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_x.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"NR","l"); - - canvas_x.SaveAs("Proj_X.png"); - - canvas_x.SetLogy(1); - - legend_x.Draw(); - - canvas_x.SaveAs("Proj_LogX.png"); - - //============================================================= - - axis = "y"; - - TCanvas canvas_y("canvas_y", "", 600, 750); - - - auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_y.SetEntrySeparation(0.3); - legend_y.SetNColumns(2); - legend_y.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_y.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_y.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"NR","l"); - - canvas_y.SaveAs("Proj_Y.png"); - - canvas_y.SetLogy(1); - - legend_y.Draw(); - - canvas_y.SaveAs("Proj_LogY.png"); - - - //============================================================= - - - - axis = "z"; - - TCanvas canvas_z("canvas_z", "", 600, 750); - - auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_z.SetEntrySeparation(0.3); - legend_z.SetNColumns(2); - legend_z.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_z.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_z.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"NR","l"); - - canvas_z.SaveAs("Proj_Z.png"); - - canvas_z.SetLogy(1); - - legend_z.Draw(); - - canvas_z.SaveAs("Proj_LogZ.png"); - - //============================================================= - - TCanvas canvas_7("canvas_7", "Normalization", 500, 500); - Normalization.Draw("colz"); - - - m_app->Run(); - -#endif - - return 0; -} - - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //allocate memory to hold the final states particles - hydra::Decays<3, Backend > _data(bunch_size); - - std::srand(7531594562); - - do { - phsp.SetSeed(std::rand()); - - //generate the final state particles - phsp.Generate(D, _data.begin(), _data.end()); - - auto last = _data.Unweight(model, 1.0); - - decays.insert(decays.size()==0? decays.begin():decays.end(), - _data.begin(), _data.begin()+last ); - - } while(decays.size() -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //norm lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - - auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); - auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); - - - return amp_int.first/model_int.first; - -} - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K+ mass - const double Kplus_MASS = masses[2];// K- mass - - TH3D Component(name, - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - //norm lambda - auto Norm = hydra::wrap_lambda( - []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - hydra::Decays<3, hydra::device::sys_t > events(nentries); - - phsp.Generate(D, events.begin(), events.end()); - - events.Reweight(functor); - - auto particles = events.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - auto dalitz_weights = events.GetWeights(); - - //model dalitz histogram - hydra::SparseHistogram Hist_Component{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - Hist_Component.Fill( dalitz_variables.begin(), - dalitz_variables.end(), dalitz_weights.begin() ); - - for(auto entry : Hist_Component){ - - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Component.GetIndexes(bin, bins); - Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - return Component; - -} - - - -#endif /* D2KKK_INL_ */ diff --git a/examples/NIPS_HYDRA/LICENSE b/examples/NIPS_HYDRA/LICENSE deleted file mode 100644 index 94a9ed024..000000000 --- a/examples/NIPS_HYDRA/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/examples/NIPS_HYDRA/README.md b/examples/NIPS_HYDRA/README.md deleted file mode 100644 index e50dbed8f..000000000 --- a/examples/NIPS_HYDRA/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# NIPS_HYDRA -Numerical Integral Precision Studies in Hydra diff --git a/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl b/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl deleted file mode 100644 index 0e8d5dd07..000000000 --- a/examples/NIPS_HYDRA/inl/phi_f0/D2KKK.inl +++ /dev/null @@ -1,1263 +0,0 @@ -#ifndef D2KKK_INL_ -#define D2KKK_INL_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -/*------------------------------------- - * Include classes from ROOT to fill - * and draw histograms and plots. - *------------------------------------- - */ -#ifdef _ROOT_AVAILABLE_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif //_ROOT_AVAILABLE_ - -using namespace ROOT::Minuit2; -using namespace hydra::placeholders; - - - -template -class Resonance: public hydra::BaseFunctor, hydra::complex, 4> -{ - using hydra::BaseFunctor, hydra::complex, 4>::_par; - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - -public: - - Resonance() = delete; - - Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, - hydra::Parameter const& mass, hydra::Parameter const& width, - double mother_mass, double daugther1_mass, - double daugther2_mass, double daugther3_mass, - double radi): - hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, - fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) - {} - - - __host__ __device__ - Resonance( Resonance< CHANNEL,L> const& other): - hydra::BaseFunctor, hydra::complex, 4>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Resonance< CHANNEL ,L>& - operator=( Resonance< CHANNEL ,L> const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 4>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - - fLineShape.SetParameter(0, _par[2]); - fLineShape.SetParameter(1, _par[3]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - - } - -private: - - mutable hydra::BreitWignerLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - -class NonResonant: public hydra::BaseFunctor, 2> -{ - - using hydra::BaseFunctor, 2>::_par; - -public: - - NonResonant() = delete; - - NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): - hydra::BaseFunctor, 2>{c_re, c_im} - {} - - - __host__ __device__ - NonResonant( NonResonant const& other): - hydra::BaseFunctor, 2>(other) - {} - - __host__ __device__ - NonResonant& operator=( NonResonant const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, 2>::operator=(other); - - return *this; - } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - return hydra::complex(_par[0], _par[1]); - } - -}; - -template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> -{ - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - using hydra::BaseFunctor, hydra::complex, 5>::_par; - -public: - - Flatte() = delete; - - Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, - double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): - hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, - fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) - {} - - __host__ __device__ Flatte( Flatte const& other): - hydra::BaseFunctor, hydra::complex, 5>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Flatte& - operator=( Flatte const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 5>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } - - - __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - fLineShape.SetParameter(0,_par[2]); - fLineShape.SetParameter(1,_par[3]); - fLineShape.SetParameter(2,_par[4]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - - auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - } - -private: - - mutable hydra::FlatteLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); - -template -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); - -int main(int argv, char** argc) -{ - size_t nentries = 0; - - try { - - TCLAP::CmdLine cmd("Command line arguments for ", '='); - - TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); - cmd.add(EArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nentries = EArg.getValue(); - - } - catch (TCLAP::ArgException &e) { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - //----------------- - //Liang's Model - - - - // - - double Phi_MASS = 1.019461; - double Phi_Width = 0.004266; - double Phi_RC = 1.0; - double Phi_IMC = 0.0; - - double f0_MASS = 0.965; - double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); - double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); - double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; - - double f0X_MASS = 1.41478; - double f0X_Width = 0.309491; - double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); - double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); - - double NR_RC = 1.0; - double NR_IMC = 0.0; - - double D_MASS = 1.86962; - double Kplus_MASS = 0.493677; // K+ mass - double Kminus_MASS = Kplus_MASS; - - //====================================================== - //Phi - auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); - auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); - auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); - auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); - - Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); - - auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); - - - - //====================================================== - //f0(X) - - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); - - Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); - - //====================================================== - //f0 - - auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, +100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, +100); - auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); - auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); - auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); - - - Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - - auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); - - //====================================================== - - //NR - coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); - coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); - - auto NR = NonResonant(coef_re, coef_im); - //====================================================== - //Total: Model |N.R + \sum{ Resonaces }|^2 - - //parametric lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ - - hydra::complex r(0,0); - - for(unsigned int i=0; i< n;i++) r += x[i]; - - return hydra::norm(r); - }); - - //model-functor - auto Model = hydra::compose(Norm, - Phi_Resonance, - f0_Resonance - ); - - //-------------------- - //generator - hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi J/psi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - -#ifdef _ROOT_AVAILABLE_ - - TH3D Dalitz_Resonances("Dalitz_Resonances", - "Dalitz - Toy Data -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - TH3D Dalitz_Fit("Dalitz_Fit", - "Dalitz - Fit -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - //control plots - TH2D Normalization("normalization", - "Model PDF Normalization;Norm;Error", - 200, 275.0, 305.0, - 200, 0.58, 0.64); - - - TH3D Phi_12_HIST,Phi_13_HIST, - f0_12_HIST,f0_13_HIST - ; - - double Phi_12_FF, Phi_13_FF, - f0_12_FF,f0_13_FF - ; -#endif - - hydra::Decays<3, hydra::host::sys_t > toy_data; - - //toy data production on device - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; - std::cout << "======================================" << std::endl; - - - auto start = std::chrono::high_resolution_clock::now(); - - generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< toy_data.size() << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; - - }//toy data production on device - - std::ofstream writer; - writer.open("toyData.txt"); - - if(!writer.is_open()){ - std::cout << "file not open" << std::endl; - }else { - - for (auto event : toy_data) { - - double weight = hydra::get<0>(event); - hydra::Vector4R Kminus = hydra::get<1>(event); - hydra::Vector4R Kplus1 = hydra::get<2>(event); - hydra::Vector4R Kplus2 = hydra::get<3>(event); - - double MKminusKplus1 = (Kminus + Kplus1).mass2(); - double MKminusKplus2 = (Kminus + Kplus2).mass2(); - - writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; - } - - std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); - - auto particles = toy_data_temp.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - - std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_variables[i] << std::endl; - - //flat dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - auto start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - std::cout << std::endl; - std::cout << std::endl; - -#ifdef _ROOT_AVAILABLE_ - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - -#endif - -#endif - - } - - - // fit - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "=============== 3 - FIT ==============" << std::endl; - std::cout << "======================================" << std::endl; - std::cout << std::endl << std::endl; - //pdf - auto Model_PDF = hydra::make_pdf( Model, - hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); - - - - std::cout << "-----------------------------------------"< toy_data_temp(toy_data); - auto particles = toy_data_temp.GetUnweightedDecays(); - - auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), - particles.end()); - - //print level - ROOT::Minuit2::MnPrint::SetLevel(3); - hydra::Print::SetLevel(hydra::WARNING); - - //minimization strategy - MnStrategy strategy(2); - - //create Migrad minimizer - MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); - - //print parameters before fitting - std::cout< elapsed_d = end_d - start_d; - - //time - std::cout << "-----------------------------------------"< fit_data(nentries); - - auto start = std::chrono::high_resolution_clock::now(); - - //generate the final state particles - phsp.Generate(B0, fit_data.begin(), fit_data.end()); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------- Device (fit data) -----------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - fit_data.Reweight(fcn.GetPDF().GetFunctor()); - - auto particles_fit = fit_data.GetUnweightedDecays(); - auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); - auto dalitz_weights_fit = fit_data.GetWeights(); - - std::cout << std::endl; - std::cout << std::endl; - - std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; - - //model dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables_fit.begin(), - dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); - - end = std::chrono::high_resolution_clock::now(); - - elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - //================================== - // Optimized components - //================================== - auto Opt_Model = fcn.GetPDF().GetFunctor(); - - auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); - auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); - auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); - auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); - - //================================== - // Draw components - //================================== - Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); - Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); - f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); - f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); - - - //================================== - // Fit fractions - //================================== - Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - - std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; - std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; - std::cout << "f0_12_FF :" << f0_12_FF << std::endl; - std::cout << "f0_13_FF :" << f0_13_FF << std::endl; - std::cout << "Sum :" - << Phi_12_FF + Phi_13_FF + f0_12_FF + f0_13_FF << std::endl; - -#ifdef _ROOT_AVAILABLE_ - - { - std::vector integrals; - std::vector integrals_error; - - for(auto x: fcn.GetPDF().GetNormCache() ){ - integrals.push_back(x.second.first); - integrals_error.push_back(x.second.second); - - } - - auto integral_bounds = std::minmax_element(integrals.begin(), - integrals.end()); - - auto integral_error_bounds = std::minmax_element(integrals_error.begin(), - integrals_error.end()); - - Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); - Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); - - for(auto x: fcn.GetPDF().GetNormCache() ){ - - Normalization.Fill(x.second.first, x.second.second ); - } - } - - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } -#endif - - -#endif - - } - - - -#ifdef _ROOT_AVAILABLE_ - - - TApplication *m_app=new TApplication("myapp",0,0); - - - Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); - - Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); - Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); - f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); - f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); - - //============================================================= - //projections - TH1* hist2D=0; - - TCanvas canvas_3("canvas_3", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_3.SaveAs("Dataset1.png"); - - TCanvas canvas_4("canvas_4", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_4.SaveAs("Dataset2.png"); - - - TCanvas canvas_5("canvas_5", "Fit", 500, 500); - hist2D = Dalitz_Fit.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_5.SaveAs("FitResult1.png"); - - - TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); - hist2D = Dalitz_Fit.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_6.SaveAs("FitResult2.png"); - - - //============================================================= - //projections - TH1* hist=0; - const char* axis =0; - - auto Phi_Color = kViolet-5; - auto f0X_Color = kBlue; - auto f0_Color = kGreen; - auto NR_Color = kBlack; - - double X1NDC = 0.262458; - double Y1NDC = 0.127544; - double X2NDC = 0.687708; - double Y2NDC = 0.35; - - - //============================== - axis = "x"; - - TCanvas canvas_x("canvas_x", "", 600, 750); - - - - auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_x.SetEntrySeparation(0.3); - legend_x.SetNColumns(2); - legend_x.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_x.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_x.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{13}","l"); - - canvas_x.SaveAs("Proj_X.png"); - - canvas_x.SetLogy(1); - - legend_x.Draw(); - - canvas_x.SaveAs("Proj_LogX.png"); - - //============================================================= - - axis = "y"; - - TCanvas canvas_y("canvas_y", "", 600, 750); - - - auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_y.SetEntrySeparation(0.3); - legend_y.SetNColumns(2); - legend_y.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_y.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_y.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{13}","l"); - - canvas_y.SaveAs("Proj_Y.png"); - - canvas_y.SetLogy(1); - - legend_y.Draw(); - - canvas_y.SaveAs("Proj_LogY.png"); - - - //============================================================= - - - - axis = "z"; - - TCanvas canvas_z("canvas_z", "", 600, 750); - - auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_z.SetEntrySeparation(0.3); - legend_z.SetNColumns(2); - legend_z.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_z.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_z.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{13}","l"); - - canvas_z.SaveAs("Proj_Z.png"); - - canvas_z.SetLogy(1); - - legend_z.Draw(); - - canvas_z.SaveAs("Proj_LogZ.png"); - - //============================================================= - - TCanvas canvas_7("canvas_7", "Normalization", 500, 500); - Normalization.Draw("colz"); - - - m_app->Run(); - -#endif - - return 0; -} - - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //allocate memory to hold the final states particles - hydra::Decays<3, Backend > _data(bunch_size); - - std::srand(7531594562); - - do { - phsp.SetSeed(std::rand()); - - //generate the final state particles - phsp.Generate(D, _data.begin(), _data.end()); - - auto last = _data.Unweight(model, 1.0); - - decays.insert(decays.size()==0? decays.begin():decays.end(), - _data.begin(), _data.begin()+last ); - - } while(decays.size() -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //norm lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - - auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); - auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); - - - return amp_int.first/model_int.first; - -} - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K+ mass - const double Kplus_MASS = masses[2];// K- mass - - TH3D Component(name, - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - //norm lambda - auto Norm = hydra::wrap_lambda( - []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - hydra::Decays<3, hydra::device::sys_t > events(nentries); - - phsp.Generate(D, events.begin(), events.end()); - - events.Reweight(functor); - - auto particles = events.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - auto dalitz_weights = events.GetWeights(); - - //model dalitz histogram - hydra::SparseHistogram Hist_Component{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - Hist_Component.Fill( dalitz_variables.begin(), - dalitz_variables.end(), dalitz_weights.begin() ); - - for(auto entry : Hist_Component){ - - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Component.GetIndexes(bin, bins); - Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - return Component; - -} - - - -#endif /* D2KKK_INL_ */ diff --git a/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl b/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl deleted file mode 100644 index 2e95a7ab4..000000000 --- a/examples/NIPS_HYDRA/inl/phi_f0_f0x_nr/D2KKK.inl +++ /dev/null @@ -1,1347 +0,0 @@ -#ifndef D2KKK_INL_ -#define D2KKK_INL_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//command line -#include - -//hydra -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -//Minuit2 -#include "Minuit2/FunctionMinimum.h" -#include "Minuit2/MnUserParameterState.h" -#include "Minuit2/MnPrint.h" -#include "Minuit2/MnMigrad.h" -#include "Minuit2/MnMinimize.h" - -/*------------------------------------- - * Include classes from ROOT to fill - * and draw histograms and plots. - *------------------------------------- - */ -#ifdef _ROOT_AVAILABLE_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif //_ROOT_AVAILABLE_ - -using namespace ROOT::Minuit2; -using namespace hydra::placeholders; - - - -template -class Resonance: public hydra::BaseFunctor, hydra::complex, 4> -{ - using hydra::BaseFunctor, hydra::complex, 4>::_par; - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - -public: - - Resonance() = delete; - - Resonance(hydra::Parameter const& c_re, hydra::Parameter const& c_im, - hydra::Parameter const& mass, hydra::Parameter const& width, - double mother_mass, double daugther1_mass, - double daugther2_mass, double daugther3_mass, - double radi): - hydra::BaseFunctor, hydra::complex, 4>{c_re, c_im, mass, width}, - fLineShape(mass, width, mother_mass, daugther1_mass, daugther2_mass, daugther3_mass, radi) - {} - - - __host__ __device__ - Resonance( Resonance< CHANNEL,L> const& other): - hydra::BaseFunctor, hydra::complex, 4>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Resonance< CHANNEL ,L>& - operator=( Resonance< CHANNEL ,L> const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 4>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::BreitWignerLineShape const& GetLineShape() const { return fLineShape; } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - - fLineShape.SetParameter(0, _par[2]); - fLineShape.SetParameter(1, _par[3]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - auto r = hydra::complex(_par[0], _par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - - } - -private: - - mutable hydra::BreitWignerLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - -class NonResonant: public hydra::BaseFunctor, 2> -{ - - using hydra::BaseFunctor, 2>::_par; - -public: - - NonResonant() = delete; - - NonResonant(hydra::Parameter const& c_re, hydra::Parameter const& c_im): - hydra::BaseFunctor, 2>{c_re, c_im} - {} - - - __host__ __device__ - NonResonant( NonResonant const& other): - hydra::BaseFunctor, 2>(other) - {} - - __host__ __device__ - NonResonant& operator=( NonResonant const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, 2>::operator=(other); - - return *this; - } - - __host__ __device__ inline - hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - return hydra::complex(_par[0], _par[1]); - } - -}; - -template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> -{ - - constexpr static unsigned int _I1 = CHANNEL-1; - constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; - constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - - using hydra::BaseFunctor, hydra::complex, 5>::_par; - -public: - - Flatte() = delete; - - Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, - double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): - hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, - fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) - {} - - __host__ __device__ Flatte( Flatte const& other): - hydra::BaseFunctor, hydra::complex, 5>(other), - fLineShape(other.GetLineShape()) - {} - - __host__ __device__ inline - Flatte& - operator=( Flatte const& other) - { - if(this==&other) return *this; - - hydra::BaseFunctor, hydra::complex, 5>::operator=(other); - fLineShape=other.GetLineShape(); - - return *this; - } - - __host__ __device__ inline - hydra::FlatteLineShape const& GetLineShape() const { return fLineShape; } - - - __host__ __device__ hydra::complex Evaluate(unsigned int n, hydra::Vector4R* p) const { - - hydra::Vector4R p1 = p[_I1]; - hydra::Vector4R p2 = p[_I2]; - hydra::Vector4R p3 = p[_I3]; - - fLineShape.SetParameter(0,_par[2]); - fLineShape.SetParameter(1,_par[3]); - fLineShape.SetParameter(2,_par[4]); - - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); - double angular = fAngularDist(theta); - - auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; - - return r; - } - -private: - - mutable hydra::FlatteLineShape fLineShape; - hydra::CosHelicityAngle fCosDecayAngle; - hydra::ZemachFunction fAngularDist; - - -}; - - - - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries); - -template -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries); - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size); - -int main(int argv, char** argc) -{ - size_t nentries = 0; - - try { - - TCLAP::CmdLine cmd("Command line arguments for ", '='); - - TCLAP::ValueArg EArg("n", "number-of-events","Number of events", true, 10e6, "size_t"); - cmd.add(EArg); - - // Parse the argv array. - cmd.parse(argv, argc); - - // Get the value parsed by each arg. - nentries = EArg.getValue(); - - } - catch (TCLAP::ArgException &e) { - std::cerr << "error: " << e.error() << " for arg " << e.argId() - << std::endl; - } - - //----------------- - //Liang's Model - - - - // - - double Phi_MASS = 1.019461; - double Phi_Width = 0.004266; - double Phi_RC = 1.0; - double Phi_IMC = 0.0; - - double f0_MASS = 0.965; - double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180)); - double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180)); - double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; - - double f0X_MASS = 1.41478; - double f0X_Width = 0.309491; - double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); - double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); - - double NR_RC = 1.0; - double NR_IMC = 0.0; - - double D_MASS = 1.86962; - double Kplus_MASS = 0.493677; // K+ mass - double Kminus_MASS = Kplus_MASS; - - //====================================================== - //Phi - auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); - auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); - auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); - auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); - - Resonance<1, hydra::PWave> Phi_Resonance_12(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::PWave> Phi_Resonance_13(coef_re, coef_im, mass, width, - D_MASS, Kminus_MASS, Kminus_MASS, Kplus_MASS , 1.5); - - auto Phi_Resonance = (Phi_Resonance_12 - Phi_Resonance_13); - - - - //====================================================== - //f0(X) - - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.0001).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(0.0001).Limits(-100,+100); - - Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); - - //====================================================== - //f0 - - auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.0001).Limits(-100, +100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(0.0001).Limits(-100, +100); - auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); - auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); - auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); - - - Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - - auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); - - //====================================================== - - //NR - coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); - coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); - - auto NR = NonResonant(coef_re, coef_im); - //====================================================== - //Total: Model |N.R + \sum{ Resonaces }|^2 - - //parametric lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ - - hydra::complex r(0,0); - - for(unsigned int i=0; i< n;i++) r += x[i]; - - return hydra::norm(r); - }); - - //model-functor - auto Model = hydra::compose(Norm, - Phi_Resonance, - f0X_Resonance, f0_Resonance, - NR ); - - //-------------------- - //generator - hydra::Vector4R B0(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi J/psi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - -#ifdef _ROOT_AVAILABLE_ - - TH3D Dalitz_Resonances("Dalitz_Resonances", - "Dalitz - Toy Data -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - TH3D Dalitz_Fit("Dalitz_Fit", - "Dalitz - Fit -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - - //control plots - TH2D Normalization("normalization", - "Model PDF Normalization;Norm;Error", - 200, 275.0, 305.0, - 200, 0.58, 0.64); - - - TH3D Phi_12_HIST,Phi_13_HIST, - f0X_12_HIST,f0X_13_HIST, - f0_12_HIST,f0_13_HIST, - NR_HIST ; - - double Phi_12_FF, Phi_13_FF, - f0X_12_FF,f0X_13_FF, - f0_12_FF,f0_13_FF, - NR_FF; -#endif - - hydra::Decays<3, hydra::host::sys_t > toy_data; - - //toy data production on device - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "======= 1 - GENERATE TOY-DATA ========" << std::endl; - std::cout << "======================================" << std::endl; - - - auto start = std::chrono::high_resolution_clock::now(); - - generate_dataset(hydra::device::sys, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, toy_data, nentries, 3*nentries); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< toy_data.size() << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - std::cout << std::endl <<"Toy Dataset size: "<< toy_data.size() << std::endl; - - }//toy data production on device - - std::ofstream writer; - writer.open("toyData.txt"); - - if(!writer.is_open()){ - std::cout << "file not open" << std::endl; - }else { - - for (auto event : toy_data) { - - double weight = hydra::get<0>(event); - hydra::Vector4R Kminus = hydra::get<1>(event); - hydra::Vector4R Kplus1 = hydra::get<2>(event); - hydra::Vector4R Kplus2 = hydra::get<3>(event); - - double MKminusKplus1 = (Kminus + Kplus1).mass2(); - double MKminusKplus2 = (Kminus + Kplus2).mass2(); - - writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; - } - - std::cout << "toyfile.txt generated" < toy_data_temp(toy_data); - - auto particles = toy_data_temp.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - - std::cout << "<======= [Daliz variables] { ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_variables[i] << std::endl; - - //flat dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - auto start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables.begin(), dalitz_variables.end() ); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - std::cout << std::endl; - std::cout << std::endl; - -#ifdef _ROOT_AVAILABLE_ - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Resonances.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - -#endif - -#endif - - } - - - // fit - { - std::cout << std::endl; - std::cout << std::endl; - std::cout << "======================================" << std::endl; - std::cout << "=============== 3 - FIT ==============" << std::endl; - std::cout << "======================================" << std::endl; - std::cout << std::endl << std::endl; - //pdf - auto Model_PDF = hydra::make_pdf( Model, - hydra::PhaseSpaceIntegrator<3, hydra::device::sys_t>(D_MASS, {Kminus_MASS, Kplus_MASS, Kplus_MASS}, 500000)); - - - - std::cout << "-----------------------------------------"< toy_data_temp(toy_data); - auto particles = toy_data_temp.GetUnweightedDecays(); - - auto fcn = hydra::make_loglikehood_fcn(Model_PDF, particles.begin(), - particles.end()); - - //print level - ROOT::Minuit2::MnPrint::SetLevel(3); - hydra::Print::SetLevel(hydra::WARNING); - - //minimization strategy - MnStrategy strategy(2); - - //create Migrad minimizer - MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState() , strategy); - - //print parameters before fitting - std::cout< elapsed_d = end_d - start_d; - - //time - std::cout << "-----------------------------------------"< fit_data(nentries); - - auto start = std::chrono::high_resolution_clock::now(); - - //generate the final state particles - phsp.Generate(B0, fit_data.begin(), fit_data.end()); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------- Device (fit data) -----------"<< std::endl; - std::cout << "| D+ -> K- K+ K+" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - fit_data.Reweight(fcn.GetPDF().GetFunctor()); - - auto particles_fit = fit_data.GetUnweightedDecays(); - auto dalitz_variables_fit = hydra::make_range( particles_fit.begin(), particles_fit.end(), dalitz_calculator); - auto dalitz_weights_fit = fit_data.GetWeights(); - - std::cout << std::endl; - std::cout << std::endl; - - std::cout << "<======= [Daliz variables - fit] { weight : ( MSq_12, MSq_13, MSq_23) } =======>"<< std::endl; - - for( size_t i=0; i<10; i++ ) - std::cout << dalitz_weights_fit[i] << " : "<< dalitz_variables_fit[i] << std::endl; - - //model dalitz histogram - hydra::SparseHistogram Hist_Dalitz{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - start = std::chrono::high_resolution_clock::now(); - - Hist_Dalitz.Fill( dalitz_variables_fit.begin(), - dalitz_variables_fit.end(), dalitz_weights_fit.begin() ); - - end = std::chrono::high_resolution_clock::now(); - - elapsed = end - start; - - //output - std::cout << std::endl; - std::cout << std::endl; - std::cout << "----------------- Device ----------------"<< std::endl; - std::cout << "| Sparse histogram fill" << std::endl; - std::cout << "| Number of events :"<< nentries << std::endl; - std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; - std::cout << "-----------------------------------------"<< std::endl; - - - //================================== - // Optimized components - //================================== - auto Opt_Model = fcn.GetPDF().GetFunctor(); - - auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); - auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); - auto f0X_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); - auto f0X_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); - auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_0); - auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_3).GetFunctor(_1); - auto NR = fcn.GetPDF().GetFunctor().GetFunctor(_4); - - //================================== - // Draw components - //================================== - Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); - Phi_13_HIST = histogram_component(Phi_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_13_HIST", nentries); - f0X_12_HIST = histogram_component(f0X_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_12_HIST", nentries); - f0X_13_HIST = histogram_component(f0X_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0X_13_HIST", nentries); - f0_12_HIST = histogram_component(f0_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_12_HIST", nentries); - f0_13_HIST = histogram_component(f0_13 , {D_MASS, Kminus_MASS, Kplus_MASS}, "f0_13_HIST", nentries); - NR_HIST = histogram_component(NR, {D_MASS, Kminus_MASS, Kplus_MASS}, "NR_HIST", nentries); - - - //================================== - // Fit fractions - //================================== - Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0X_12_FF = fit_fraction(f0X_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0X_13_FF = fit_fraction(f0X_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - NR_FF = fit_fraction(NR , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - - - std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; - std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; - std::cout << "f0X_12_FF :" << f0X_12_FF << std::endl; - std::cout << "f0X_13_FF :" << f0X_13_FF << std::endl; - std::cout << "f0_12_FF :" << f0_12_FF << std::endl; - std::cout << "f0_13_FF :" << f0_13_FF << std::endl; - std::cout << "NR_FF :" << NR_FF << std::endl; - std::cout << "Sum :" - << Phi_12_FF + Phi_13_FF + f0X_12_FF + f0X_13_FF + f0_12_FF + f0_13_FF + NR_FF << std::endl; - -#ifdef _ROOT_AVAILABLE_ - - { - std::vector integrals; - std::vector integrals_error; - - for(auto x: fcn.GetPDF().GetNormCache() ){ - integrals.push_back(x.second.first); - integrals_error.push_back(x.second.second); - - } - - auto integral_bounds = std::minmax_element(integrals.begin(), - integrals.end()); - - auto integral_error_bounds = std::minmax_element(integrals_error.begin(), - integrals_error.end()); - - Normalization.GetXaxis()->SetLimits(*integral_bounds.first, *integral_bounds.second); - Normalization.GetYaxis()->SetLimits(*integral_error_bounds.first, *integral_error_bounds.second); - - for(auto x: fcn.GetPDF().GetNormCache() ){ - - Normalization.Fill(x.second.first, x.second.second ); - } - } - - -#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA - - //if device is cuda, bring the histogram data to the host - //to fill the ROOT histogram faster - { - hydra::SparseHistogram Hist_Temp(Hist_Dalitz); - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Temp) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Temp.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - } -#else - std::cout << "Filling a ROOT Histogram... " << std::endl; - - for(auto entry : Hist_Dalitz) - { - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Dalitz.GetIndexes(bin, bins); - Dalitz_Fit.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } -#endif - - -#endif - - } - - - -#ifdef _ROOT_AVAILABLE_ - - - TApplication *m_app=new TApplication("myapp",0,0); - - - Dalitz_Fit.Scale(Dalitz_Resonances.Integral()/Dalitz_Fit.Integral() ); - - Phi_12_HIST.Scale( Phi_12_FF*Dalitz_Fit.Integral()/Phi_12_HIST.Integral() ); - Phi_13_HIST.Scale( Phi_13_FF*Dalitz_Fit.Integral()/Phi_13_HIST.Integral() ); - f0X_12_HIST.Scale( f0X_12_FF*Dalitz_Fit.Integral()/f0X_12_HIST.Integral() ); - f0X_13_HIST.Scale( f0X_13_FF*Dalitz_Fit.Integral()/f0X_13_HIST.Integral() ); - f0_12_HIST.Scale( f0_12_FF*Dalitz_Fit.Integral()/f0_12_HIST.Integral() ); - f0_13_HIST.Scale( f0_13_FF*Dalitz_Fit.Integral()/f0_13_HIST.Integral() ); - - NR_HIST.Scale( NR_FF*Dalitz_Fit.Integral()/NR_HIST.Integral() ); - - //============================================================= - //projections - TH1* hist2D=0; - - TCanvas canvas_3("canvas_3", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_3.SaveAs("Dataset1.png"); - - TCanvas canvas_4("canvas_4", "Dataset", 500, 500); - hist2D = Dalitz_Resonances.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->Draw("colz"); - canvas_4.SaveAs("Dataset2.png"); - - - TCanvas canvas_5("canvas_5", "Fit", 500, 500); - hist2D = Dalitz_Fit.Project3D("yz"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_5.SaveAs("FitResult1.png"); - - - TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); - hist2D = Dalitz_Fit.Project3D("xy"); - hist2D->SetTitle(""); - hist2D->SetStats(0); - hist2D->Draw("colz"); - canvas_6.SaveAs("FitResult2.png"); - - - //============================================================= - //projections - TH1* hist=0; - const char* axis =0; - - auto Phi_Color = kViolet-5; - auto f0X_Color = kBlue; - auto f0_Color = kGreen; - auto NR_Color = kBlack; - - double X1NDC = 0.262458; - double Y1NDC = 0.127544; - double X2NDC = 0.687708; - double Y2NDC = 0.35; - - - //============================== - axis = "x"; - - TCanvas canvas_x("canvas_x", "", 600, 750); - - - - auto legend_x = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_x.SetEntrySeparation(0.3); - legend_x.SetNColumns(2); - legend_x.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_x.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_x.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"NR","l"); - - canvas_x.SaveAs("Proj_X.png"); - - canvas_x.SetLogy(1); - - legend_x.Draw(); - - canvas_x.SaveAs("Proj_LogX.png"); - - //============================================================= - - axis = "y"; - - TCanvas canvas_y("canvas_y", "", 600, 750); - - - auto legend_y = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_y.SetEntrySeparation(0.3); - legend_y.SetNColumns(2); - legend_y.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_y.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_y.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"NR","l"); - - canvas_y.SaveAs("Proj_Y.png"); - - canvas_y.SetLogy(1); - - legend_y.Draw(); - - canvas_y.SaveAs("Proj_LogY.png"); - - - //============================================================= - - - - axis = "z"; - - TCanvas canvas_z("canvas_z", "", 600, 750); - - auto legend_z = TLegend( X1NDC, Y1NDC, X2NDC, Y2NDC); - //legend.SetHeader("M^{2}(K^{-} #pi_{1}^{+})","C"); // option "C" allows to center the header - legend_z.SetEntrySeparation(0.3); - legend_z.SetNColumns(2); - legend_z.SetBorderSize(0); - - hist= Dalitz_Fit.Project3D(axis)->DrawCopy("hist"); - hist->SetLineColor(2); - hist->SetLineWidth(2); - hist->SetMinimum(0.001); - hist->SetStats(0); - hist->SetTitle(""); - - legend_z.AddEntry(hist,"Fit","l"); - - hist= Dalitz_Resonances.Project3D(axis)->DrawCopy("e0same"); - hist->SetMarkerStyle(8); - hist->SetMarkerSize(0.6); - hist->SetStats(0); - - legend_z.AddEntry(hist,"Data","lep"); - - hist = Phi_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{12}","l"); - - hist = Phi_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(Phi_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{#Phi}_{13}","l"); - - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{12}","l"); - - hist = f0_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0}_{13}","l"); - - hist = NR_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineColor(NR_Color); - hist->SetLineStyle(5); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"NR","l"); - - canvas_z.SaveAs("Proj_Z.png"); - - canvas_z.SetLogy(1); - - legend_z.Draw(); - - canvas_z.SaveAs("Proj_LogZ.png"); - - //============================================================= - - TCanvas canvas_7("canvas_7", "Normalization", 500, 500); - Normalization.Draw("colz"); - - - m_app->Run(); - -#endif - - return 0; -} - - -template -size_t generate_dataset(Backend const& system, Model const& model, std::array const& masses, Container& decays, size_t nevents, size_t bunch_size) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //allocate memory to hold the final states particles - hydra::Decays<3, Backend > _data(bunch_size); - - std::srand(7531594562); - - do { - phsp.SetSeed(std::rand()); - - //generate the final state particles - phsp.Generate(D, _data.begin(), _data.end()); - - auto last = _data.Unweight(model, 1.0); - - decays.insert(decays.size()==0? decays.begin():decays.end(), - _data.begin(), _data.begin()+last ); - - } while(decays.size() -double fit_fraction( Amplitude const& amp, Model const& model, std::array const& masses, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K- mass - const double Kplus_MASS = masses[2];// K+ mass - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; - - //norm lambda - auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - - auto amp_int = phsp.AverageOn(hydra::device::sys, D, functor, nentries); - auto model_int = phsp.AverageOn(hydra::device::sys, D, model, nentries); - - - return amp_int.first/model_int.first; - -} - -template -TH3D histogram_component( Amplitude const& amp, std::array const& masses, const char* name, size_t nentries) -{ - const double D_MASS = masses[0];// D+ mass - const double Kminus_MASS = masses[1];// K+ mass - const double Kplus_MASS = masses[2];// K- mass - - TH3D Component(name, - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), - 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); - - //-------------------- - //generator - hydra::Vector4R D(D_MASS, 0.0, 0.0, 0.0); - // Create PhaseSpace object for B0-> K pi pi - hydra::PhaseSpace<3> phsp{Kplus_MASS, Kminus_MASS, Kminus_MASS}; - - // functor to calculate the 2-body masses - auto dalitz_calculator = hydra::wrap_lambda( - []__host__ __device__(unsigned int n, hydra::Vector4R* p ){ - - double M2_12 = (p[0]+p[1]).mass2(); - double M2_13 = (p[0]+p[2]).mass2(); - double M2_23 = (p[1]+p[2]).mass2(); - - return hydra::make_tuple(M2_12, M2_13, M2_23); - }); - - //norm lambda - auto Norm = hydra::wrap_lambda( - []__host__ __device__ (unsigned int n, hydra::complex* x){ - - return hydra::norm(x[0]); - }); - - //functor - auto functor = hydra::compose(Norm, amp); - - hydra::Decays<3, hydra::device::sys_t > events(nentries); - - phsp.Generate(D, events.begin(), events.end()); - - events.Reweight(functor); - - auto particles = events.GetUnweightedDecays(); - auto dalitz_variables = hydra::make_range( particles.begin(), particles.end(), dalitz_calculator); - auto dalitz_weights = events.GetWeights(); - - //model dalitz histogram - hydra::SparseHistogram Hist_Component{ - {100,100,100}, - {pow(Kminus_MASS + Kplus_MASS,2), pow(Kminus_MASS + Kplus_MASS,2), pow(Kplus_MASS + Kplus_MASS,2)}, - {pow(D_MASS - Kplus_MASS,2), pow(D_MASS - Kplus_MASS ,2), pow(D_MASS - Kminus_MASS,2)} - }; - - Hist_Component.Fill( dalitz_variables.begin(), - dalitz_variables.end(), dalitz_weights.begin() ); - - for(auto entry : Hist_Component){ - - size_t bin = hydra::get<0>(entry); - double content = hydra::get<1>(entry); - unsigned int bins[3]; - Hist_Component.GetIndexes(bin, bins); - Component.SetBinContent(bins[0]+1, bins[1]+1, bins[2]+1, content); - - } - - return Component; - -} - - - -#endif /* D2KKK_INL_ */ diff --git a/examples/phys/CMakeLists.txt b/examples/phys/CMakeLists.txt index 49f8aaa0d..6e473d34d 100644 --- a/examples/phys/CMakeLists.txt +++ b/examples/phys/CMakeLists.txt @@ -8,3 +8,4 @@ project(examples) ADD_HYDRA_EXAMPLE(double_gaussian_plus_exponential) ADD_HYDRA_EXAMPLE(breit_wigner_plus_polynomial) ADD_HYDRA_EXAMPLE(dalitz_plot) + ADD_HYDRA_EXAMPLE(FlatteLineShape) diff --git a/examples/NIPS_HYDRA/D2KKK.cu b/examples/phys/FlatteLineShape.cpp similarity index 82% rename from examples/NIPS_HYDRA/D2KKK.cu rename to examples/phys/FlatteLineShape.cpp index 63ca3abbf..1a659d884 100644 --- a/examples/NIPS_HYDRA/D2KKK.cu +++ b/examples/phys/FlatteLineShape.cpp @@ -20,17 +20,17 @@ *---------------------------------------------------------------------------*/ /* - * dalitz_plot.cu + * FlatteLineShape.cpp * - * Created on: 19/01/2018 - * Author: Antonio Augusto Alves Junior + * Created on: 03/09/2018 + * Author: Juan B de S Leite */ -#ifndef D2KKK_CU_ -#define D2KKK_CU_ +#ifndef Flatte_CPP_ +#define Flatte_CPP_ -#include +#include -#endif /* D2KKK_CU_ */ +#endif /* FlatteLineShape_CPP_ */ diff --git a/examples/NIPS_HYDRA/D2KKK.cpp b/examples/phys/FlatteLineShape.cu similarity index 82% rename from examples/NIPS_HYDRA/D2KKK.cpp rename to examples/phys/FlatteLineShape.cu index a8432d69c..820de3722 100644 --- a/examples/NIPS_HYDRA/D2KKK.cpp +++ b/examples/phys/FlatteLineShape.cu @@ -20,17 +20,17 @@ *---------------------------------------------------------------------------*/ /* - * dalitz_plot.cpp + * FlatteLineShape.cu * - * Created on: 19/01/2018 - * Author: Antonio Augusto Alves Junior + * Created on: 03/09/2018 + * Author: Juan B de S Leite */ -#ifndef D2KKK_CPP_ -#define D2KKK_CPP_ +#ifndef Flatte_CU_ +#define Flatte_CU_ -#include +#include -#endif /* D2KKK_CPP_ */ +#endif /* FlatteLineShape_CU_ */ diff --git a/examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl b/examples/phys/FlatteLineShape.inl similarity index 82% rename from examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl rename to examples/phys/FlatteLineShape.inl index 54bd62286..910190660 100644 --- a/examples/NIPS_HYDRA/inl/liangModel2/D2KKK.inl +++ b/examples/phys/FlatteLineShape.inl @@ -1,5 +1,33 @@ -#ifndef D2KKK_INL_ -#define D2KKK_INL_ +/*---------------------------------------------------------------------------- + * + * Copyright (C) 2016 - 2018 Antonio Augusto Alves Junior + * + * This file is part of Hydra Data Analysis Framework. + * + * Hydra is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Hydra is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Hydra. If not, see . + * + *---------------------------------------------------------------------------*/ + +/* + * FlatteLineShape.inl + * + * Created on: 03/09/2018 + * Author: Juan B de S Leite + */ + +#ifndef FlatteLineShape_INL +#define FlatteLineShape_INL #include #include @@ -223,8 +251,8 @@ public: Flatte() = delete; - Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im,hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, - double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass,double radi): + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im, hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass, double radi): hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) {} @@ -313,59 +341,21 @@ int main(int argv, char** argc) } //----------------- - //Liang's Model - + - - // - -/* double Phi_MASS = 1.019461; double Phi_Width = 0.004266; double Phi_RC = 1.0; double Phi_IMC = 0.0; double f0_MASS = 0.965; - double f0_RC = 12.341 * cos(-62.852 * (M_PI / 180))/10; - double f0_IMC = 12.341 * sin(-62.852 * (M_PI / 180))/10; + double f0_MAG = 12.341; + double f0_Phase = -62.852*(M_PI / 180) ; + double f0_RC = f0_MAG * cos(f0_Phase); + double f0_IMC = f0_MAG * sin(f0_Phase); double f0_rho1 = 0.165; double f0_rho2 = 4.21*f0_rho1; - double f0X_MASS = 1.41478; - double f0X_Width = 0.309491; - double f0X_RC = 11.918 * cos(20.248 * (M_PI / 180)); - double f0X_IMC = 11.918 * sin(20.248 * (M_PI / 180)); - - double NR_RC = 1.0; - double NR_IMC = 0.0; - - double D_MASS = 1.86962; - double Kplus_MASS = 0.493677; // K+ mass - double Kminus_MASS = Kplus_MASS; - -*/ - - //liang model2 results - - double Phi_MASS = 1.019461; - double Phi_Width = 0.004266; - double Phi_RC = 1.0; - double Phi_IMC = 0.0; - - double f0_MASS = 0.965; - double f0_RC = 3.20; - double f0_IMC = -59.3; - double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; - - double f0X_MASS = 1.430; - double f0X_Width = 0.348; - double f0X_RC = 3.52; - double f0X_IMC = 13.8; - - double NR_RC = 1.0; - double NR_IMC = 0.0; - double D_MASS = 1.86962; double Kplus_MASS = 0.493677; // K+ mass double Kminus_MASS = Kplus_MASS; @@ -373,8 +363,8 @@ int main(int argv, char** argc) //====================================================== //Phi - auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Limits(0.7, 1.8 ).Fixed(); - auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Limits(1.e-5, 1.e-1).Fixed(); + auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Fixed(); + auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Fixed(); auto coef_re = hydra::Parameter::Create().Name("Phi_RC" ).Value(Phi_RC).Fixed(); auto coef_im = hydra::Parameter::Create().Name("Phi_IM" ).Value(Phi_IMC).Fixed(); @@ -389,45 +379,24 @@ int main(int argv, char** argc) //====================================================== - //f0(X) - - auto massf0x = hydra::Parameter::Create().Name("MASS_f0(X)" ).Value(f0X_MASS ).Error(0.019).Fixed(); - auto widthf0x = hydra::Parameter::Create().Name("WIDTH_f0(X)").Value(f0X_Width).Error(0.049).Fixed(); - auto coef_ref0x = hydra::Parameter::Create().Name("f0(X)_RC" ).Value(f0X_RC).Error(0.58).Limits(-100,+100); - auto coef_imf0x = hydra::Parameter::Create().Name("f0(X)_IM" ).Value(f0X_IMC).Error(8.1).Limits(-100,+100); - Resonance<1, hydra::SWave> f0X_Resonance_12(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - Resonance<3, hydra::SWave> f0X_Resonance_13(coef_ref0x, coef_imf0x, massf0x, widthf0x, - D_MASS, Kminus_MASS, Kplus_MASS, Kplus_MASS , 1.5); - - auto f0X_Resonance = (f0X_Resonance_12 + f0X_Resonance_13); - - //====================================================== //f0 - auto f0_amp_real = hydra::Parameter::Create().Name("f0_amp_real").Value(f0_RC).Error(0.12).Limits(-100, +100); - auto f0_amp_imag = hydra::Parameter::Create().Name("f0_amp_imag").Value(f0_IMC).Error(5.1).Limits(-100, +100); + auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001); + auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); - auto rg1og2 = hydra::Parameter::Create().Name("rg1og2").Value(f0_rho2).Fixed(); + auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); - Flatte<1,hydra::SWave> f0_Resonance_12(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(f0_amp_real,f0_amp_imag,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<1,hydra::SWave> f0_Resonance_12(coef_ref0,coef_imf0,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(coef_ref0,coef_imf0,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - auto f0_Resonance = (f0_Resonance_13 + f0_Resonance_12); + auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); //====================================================== - //NR - coef_re = hydra::Parameter::Create().Name("A_RE_NR" ).Value(NR_RC).Error(0.001).Limits(-100,+100); - coef_im = hydra::Parameter::Create().Name("A_IM_NR" ).Value(NR_IMC).Error(0.001).Limits(-100,+100); - - auto NR = NonResonant(coef_re, coef_im); - //====================================================== - //Total: Model |N.R + \sum{ Resonaces }|^2 + //Total: Model |sum{ Resonaces }|^2 //parametric lambda auto Norm = hydra::wrap_lambda( []__host__ __device__ ( unsigned int n, hydra::complex* x){ @@ -441,8 +410,7 @@ int main(int argv, char** argc) //model-functor auto Model = hydra::compose(Norm, - Phi_Resonance, - f0X_Resonance, f0_Resonance + Phi_Resonance, f0_Resonance ); //-------------------- @@ -467,9 +435,9 @@ int main(int argv, char** argc) TH3D Dalitz_Resonances("Dalitz_Resonances", "Dalitz - Toy Data -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + "M^{2}(K^{-} K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K_{1}^{+} K_{2}^{+}) [GeV^{2}/c^{4}]", 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); @@ -477,9 +445,9 @@ int main(int argv, char** argc) TH3D Dalitz_Fit("Dalitz_Fit", "Dalitz - Fit -;" - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + "M^{2}(K^{-} K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K_{1}^{+} K_{2}^{+}) [GeV^{2}/c^{4}]", 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); @@ -493,11 +461,9 @@ int main(int argv, char** argc) TH3D Phi_12_HIST,Phi_13_HIST, - f0X_12_HIST,f0X_13_HIST, f0_12_HIST,f0_13_HIST ; double Phi_12_FF, Phi_13_FF, - f0X_12_FF,f0X_13_FF, f0_12_FF,f0_13_FF ; #endif @@ -535,35 +501,6 @@ int main(int argv, char** argc) }//toy data production on device - std::ofstream writer; - writer.open("toyData.txt"); - - if(!writer.is_open()){ - std::cout << "file not open" << std::endl; - }else { - - for (auto event : toy_data) { - - double weight = hydra::get<0>(event); - hydra::Vector4R Kminus = hydra::get<1>(event); - hydra::Vector4R Kplus1 = hydra::get<2>(event); - hydra::Vector4R Kplus2 = hydra::get<3>(event); - - double MKminusKplus1 = (Kminus + Kplus1).mass2(); - double MKminusKplus2 = (Kminus + Kplus2).mass2(); - - writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; - } - - std::cout << "toyfile.txt generated" <SetTitle(""); hist2D->Draw("colz"); canvas_4.SaveAs("Dataset2.png"); @@ -919,7 +846,7 @@ int main(int argv, char** argc) TCanvas canvas_6("canvas_4", "Phase-space FLAT", 500, 500); - hist2D = Dalitz_Fit.Project3D("xy"); + hist2D = Dalitz_Fit.Project3D("yx"); hist2D->SetTitle(""); hist2D->SetStats(0); hist2D->Draw("colz"); @@ -932,9 +859,7 @@ int main(int argv, char** argc) const char* axis =0; auto Phi_Color = kViolet-5; - auto f0X_Color = kBlue; - auto f0_Color = kGreen; - auto NR_Color = kBlack; + auto f0_Color = kGreen; double X1NDC = 0.262458; double Y1NDC = 0.127544; @@ -984,20 +909,6 @@ int main(int argv, char** argc) legend_x.AddEntry(hist,"{#Phi}_{13}","l"); - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_x.AddEntry(hist,"{f0(X)}_{13}","l"); - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); //hist->SetLineStyle(2); hist->SetLineColor(f0_Color); @@ -1064,22 +975,7 @@ int main(int argv, char** argc) legend_y.AddEntry(hist,"{#Phi}_{13}","l"); - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_y.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); //hist->SetLineStyle(2); hist->SetLineColor(f0_Color); hist->SetLineWidth(2); @@ -1147,22 +1043,7 @@ int main(int argv, char** argc) legend_z.AddEntry(hist,"{#Phi}_{13}","l"); - hist = f0X_12_HIST.Project3D(axis)->DrawCopy("histCsame"); - //hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{12}","l"); - - hist = f0X_13_HIST.Project3D(axis)->DrawCopy("histCsame"); - hist->SetLineStyle(2); - hist->SetLineColor(f0X_Color); - hist->SetLineWidth(2); - - legend_z.AddEntry(hist,"{f0(X)}_{13}","l"); - - - hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); + hist = f0_12_HIST.Project3D(axis)->DrawCopy("histCsame"); //hist->SetLineStyle(2); hist->SetLineColor(f0_Color); hist->SetLineWidth(2); @@ -1249,7 +1130,7 @@ double fit_fraction( Amplitude const& amp, Model const& model, std::array K pi pi + // Create PhaseSpace object for D-> K K K hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; //norm lambda @@ -1278,9 +1159,9 @@ TH3D histogram_component( Amplitude const& amp, std::array const& mas const double Kplus_MASS = masses[2];// K- mass TH3D Component(name, - "M^{2}(K^{-} #K_{1}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(K^{-} #K_{2}^{+}) [GeV^{2}/c^{4}];" - "M^{2}(#K_{1}^{+} #K_{2}^{+}) [GeV^{2}/c^{4}]", + "M^{2}(K^{-} K_{1}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K^{-} K_{2}^{+}) [GeV^{2}/c^{4}];" + "M^{2}(K_{1}^{+} K_{2}^{+}) [GeV^{2}/c^{4}]", 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kminus_MASS + Kplus_MASS,2), pow(D_MASS - Kplus_MASS,2), 100, pow(Kplus_MASS + Kplus_MASS,2), pow(D_MASS - Kminus_MASS,2)); @@ -1348,4 +1229,4 @@ TH3D histogram_component( Amplitude const& amp, std::array const& mas -#endif /* D2KKK_INL_ */ +#endif /* FlatteLineShape_INL */ diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index 672fcc8a5..b8190405e 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -1,8 +1,29 @@ +/*---------------------------------------------------------------------------- + * + * Copyright (C) 2016 - 2018 Antonio Augusto Alves Junior + * + * This file is part of Hydra Data Analysis Framework. + * + * Hydra is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Hydra is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Hydra. If not, see . + * + *---------------------------------------------------------------------------*/ + /* * FlatteLineShape.h * - * Created on: 09/03/2018 Based on Liang Sun code - * Author: Juan + * Created on: 03/09/2018 Based on Goofit Flatte code + * Author: Juan B de S Leite * * */ @@ -30,6 +51,15 @@ namespace hydra { + /* + * @FlatteLineShape + * The Flatté formulation is used when a second channel opens close to a resonance. + * T(m_{ab}) = 1 / ( m_{r}^{2} - m_{ab}^{2} - i(#rho_{1}*g_{1}^{2} + #rho_{2}*g_{2}^{2}) + * where g_{1}^{2} + g_{2}^{2} = m_{0}*#Gamma_{r} + * @tparam unsigned int CHANNEL + */ + + template class FlatteLineShape : public BaseFunctor, hydra::complex, 3> { using BaseFunctor, hydra::complex, 3>::_par; @@ -55,7 +85,7 @@ namespace hydra { BaseFunctor, hydra::complex, 3>{mean, rho1, rho2}, fDaughter1Mass(daugther1_mass), fDaughter2Mass(daugther2_mass), - fDaughter3Mass(daugther3_mass), + fBachelorMass(daugther3_mass), fMotherMass(mother_mass), fRadi(radi) {} @@ -64,7 +94,7 @@ namespace hydra { BaseFunctor, hydra::complex, 3>(other), fDaughter1Mass(other.GetDaughter1Mass()), fDaughter2Mass(other.GetDaughter2Mass()), - fDaughter3Mass(other.GetDaughter3Mass()), + fBachelorMass(other.GetDaughter3Mass()), fMotherMass(other.GetMotherMass()), fRadi(other.GetRadi()) {} @@ -78,7 +108,7 @@ namespace hydra { fDaughter1Mass = other.GetDaughter1Mass(); fDaughter2Mass = other.GetDaughter2Mass(); - fDaughter3Mass = other.GetDaughter3Mass(); + fBachelorMass = other.GetDaughter3Mass(); fMotherMass = other.GetMotherMass(); fRadi = other.GetRadi(); @@ -107,12 +137,12 @@ namespace hydra { __hydra_host__ __hydra_device__ inline double GetDaughter3Mass() const { - return fDaughter3Mass; + return fBachelorMass; } __hydra_host__ __hydra_device__ inline void SetDaughter3Mass(double daughter3Mass) { - fDaughter3Mass = daughter3Mass; + fBachelorMass = daughter3Mass; } __hydra_host__ __hydra_device__ inline @@ -145,7 +175,7 @@ namespace hydra { const double rho1 = _par[1]; const double rho2 = _par[2]; - return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? + return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fBachelorMass) ? LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); } @@ -160,7 +190,7 @@ namespace hydra { const double rho1 = _par[1]; const double rho2 = _par[2]; - return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fDaughter3Mass) ? + return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fBachelorMass) ? LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); } @@ -171,8 +201,6 @@ namespace hydra { hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { - hydra::complex ret(0.0,0.0); - double pipmass = 0.13957018; double pi0mass = 0.1349766; double kpmass = 0.493677; @@ -183,44 +211,47 @@ namespace hydra { double twokmasssq = 4 * kpmass * kpmass; double twok0masssq = 4 * k0mass * k0mass; - double rhopipi_real = 0, rhopipi_imag = 0; - double rhokk_real = 0, rhokk_imag = 0; + double rhopipi_real = 0; + double rhopipi_imag = 0; + double rhokk_real = 0; + double rhokk_imag = 0; if(s >= twopimasssq) rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold else rhopipi_imag = (2. / 3) * TMath::Sqrt(-1 + twopimasssq / s); + if(s >= twopi0masssq) rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold else rhopipi_imag = (1. / 3) * TMath::Sqrt(-1 + twopi0masssq / s ); + if(s >= twokmasssq) rhokk_real = 0.5 * TMath::Sqrt(1 - twokmasssq / s ); // Above K+K- threshold else rhokk_imag = 0.5 * TMath::Sqrt(-1 + twokmasssq / s ); + if(s >= twok0masssq) rhokk_real = 0.5 * TMath::Sqrt(1 - twok0masssq / s ); // Above K0K0 threshold else rhokk_imag = 0.5 * TMath::Sqrt(-1 + twok0masssq / s ); - double A = (resonance_mass * resonance_mass - s) + resonance_mass * (rhopipi_imag * g1 + rhokk_imag * g2); - double B = resonance_mass * (rhopipi_real * g1 + rhokk_real * g2); - double C = 1.0 / (A * A + B * B); - - hydra::complex retur(A * C, B * C); + double A = (resonance_mass*resonance_mass - s) + resonance_mass*(rhopipi_imag*g1 + rhokk_imag*g2); + double B = resonance_mass*(rhopipi_real*g1 + rhokk_real*g2); + double C = 1.0 / (A*A + B*B); + hydra::complex retur(A*C, B*C); - ret+=retur; - return ret; + return retur; } double fDaughter1Mass; double fDaughter2Mass; - double fDaughter3Mass; + double fBachelorMass; double fMotherMass; double fRadi; From 6d59a21ea72641bdd768173a054b582a2860ecdc Mon Sep 17 00:00:00 2001 From: juan leite Date: Sat, 17 Mar 2018 17:15:00 +0100 Subject: [PATCH 06/16] flatte --- CMakeLists.txt | 3 +- examples/phys/FlatteLineShape.inl | 64 ++++++++++++++++++++++++++----- hydra/functions/FlatteLineShape.h | 4 +- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de385322f..cd460ad22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,9 +178,10 @@ add_subdirectory(examples/random) add_subdirectory(examples/histograming) add_subdirectory(examples/async) add_subdirectory(examples/misc) +add_subdirectory(examples/phys) if(Minuit2_FOUND) -add_subdirectory(examples/phys) + add_subdirectory(examples/fit) endif(Minuit2_FOUND) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 910190660..201170a2e 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -350,7 +350,7 @@ int main(int argv, char** argc) double f0_MASS = 0.965; double f0_MAG = 12.341; - double f0_Phase = -62.852*(M_PI / 180) ; + double f0_Phase = -62.852*(M_PI / 180) +M_PI; double f0_RC = f0_MAG * cos(f0_Phase); double f0_IMC = f0_MAG * sin(f0_Phase); double f0_rho1 = 0.165; @@ -381,9 +381,8 @@ int main(int argv, char** argc) //====================================================== //f0 - - auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001); - auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001); + auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-100,100); + auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001).Limits(-100,100); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); @@ -403,7 +402,8 @@ int main(int argv, char** argc) hydra::complex r(0,0); - for(unsigned int i=0; i< n;i++) r += x[i]; + for(unsigned int i=0; i(event); + hydra::Vector4R Kminus = hydra::get<1>(event); + hydra::Vector4R Kplus1 = hydra::get<2>(event); + hydra::Vector4R Kplus2 = hydra::get<3>(event); + + double MKminusKplus1 = (Kminus + Kplus1).mass2(); + double MKminusKplus2 = (Kminus + Kplus2).mass2(); + + writer << MKminusKplus1 << '\t' << MKminusKplus2 << std::endl; + } + + std::cout << "toyfile.txt generated" < K K K hydra::PhaseSpace<3> phsp{Kminus_MASS, Kplus_MASS, Kplus_MASS}; + //norm lambda auto Norm = hydra::wrap_lambda( []__host__ __device__ (unsigned int n, hydra::complex* x){ @@ -1146,7 +1191,6 @@ double fit_fraction( Amplitude const& amp, Model const& model, std::array= twopimasssq) - rhopipi_real = (2. / 3) * TMath::Sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold + rhopipi_real = (2. / 3) * ::sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold else - rhopipi_imag = (2. / 3) * TMath::Sqrt(-1 + twopimasssq / s); + rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s); if(s >= twopi0masssq) rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold From 6413653a94a1808120858b4288ecf9d9083e5fc7 Mon Sep 17 00:00:00 2001 From: juan leite Date: Mon, 19 Mar 2018 09:37:07 +0100 Subject: [PATCH 07/16] changes for PR --- CMakeLists.txt | 3 ++- examples/phys/FlatteLineShape.inl | 12 ++++++------ hydra/functions/FlatteLineShape.h | 14 +++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd460ad22..7c6322c98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,11 +178,12 @@ add_subdirectory(examples/random) add_subdirectory(examples/histograming) add_subdirectory(examples/async) add_subdirectory(examples/misc) -add_subdirectory(examples/phys) + if(Minuit2_FOUND) add_subdirectory(examples/fit) +add_subdirectory(examples/phys) endif(Minuit2_FOUND) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 201170a2e..57e95f30d 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -350,11 +350,11 @@ int main(int argv, char** argc) double f0_MASS = 0.965; double f0_MAG = 12.341; - double f0_Phase = -62.852*(M_PI / 180) +M_PI; - double f0_RC = f0_MAG * cos(f0_Phase); - double f0_IMC = f0_MAG * sin(f0_Phase); + double f0_Phase = -62.852*(M_PI / 180.0 ) + M_PI; // 2.044618312126317 + double f0_RC = f0_MAG * cos(f0_Phase); //-5.631081433470062 + double f0_IMC = f0_MAG * sin(f0_Phase); //10.981402592093087 double f0_rho1 = 0.165; - double f0_rho2 = 4.21*f0_rho1; + double f0_rho2 = 4.21*f0_rho1; // 0.69465 double D_MASS = 1.86962; double Kplus_MASS = 0.493677; // K+ mass @@ -381,8 +381,8 @@ int main(int argv, char** argc) //====================================================== //f0 - auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-100,100); - auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001).Limits(-100,100); + auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-f0_RC*20.0,+f0_RC*20.0); + auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001).Limits(-f0_IMC*20.0,+f0_IMC*20.0); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index d1fb93d3d..9ffe399b9 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -22,7 +22,7 @@ /* * FlatteLineShape.h * - * Created on: 03/09/2018 Based on Goofit Flatte code + * Created on: 03/09/2018 Based on Goofit Flatte Code * Author: Juan B de S Leite * * @@ -223,19 +223,19 @@ namespace hydra { rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s); if(s >= twopi0masssq) - rhopipi_real = (1. / 3) * TMath::Sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold + rhopipi_real = (1. / 3) * ::sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold else - rhopipi_imag = (1. / 3) * TMath::Sqrt(-1 + twopi0masssq / s ); + rhopipi_imag = (1. / 3) * ::sqrt(-1 + twopi0masssq / s ); if(s >= twokmasssq) - rhokk_real = 0.5 * TMath::Sqrt(1 - twokmasssq / s ); // Above K+K- threshold + rhokk_real = 0.5 * ::sqrt(1 - twokmasssq / s ); // Above K+K- threshold else - rhokk_imag = 0.5 * TMath::Sqrt(-1 + twokmasssq / s ); + rhokk_imag = 0.5 * ::sqrt(-1 + twokmasssq / s ); if(s >= twok0masssq) - rhokk_real = 0.5 * TMath::Sqrt(1 - twok0masssq / s ); // Above K0K0 threshold + rhokk_real = 0.5 * ::sqrt(1 - twok0masssq / s ); // Above K0K0 threshold else - rhokk_imag = 0.5 * TMath::Sqrt(-1 + twok0masssq / s ); + rhokk_imag = 0.5 * ::sqrt(-1 + twok0masssq / s ); double A = (resonance_mass*resonance_mass - s) + resonance_mass*(rhopipi_imag*g1 + rhokk_imag*g2); double B = resonance_mass*(rhopipi_real*g1 + rhokk_real*g2); From 311ffa27c5154844f15f28c366963df3954ffd1f Mon Sep 17 00:00:00 2001 From: juan leite Date: Mon, 19 Mar 2018 09:46:07 +0100 Subject: [PATCH 08/16] changes for PR --- examples/phys/FlatteLineShape.inl | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 57e95f30d..1f7d3d4d4 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -742,10 +742,8 @@ int main(int argv, char** argc) auto Phi_12 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_0); auto Phi_13 = fcn.GetPDF().GetFunctor().GetFunctor(_1).GetFunctor(_1); - auto Phi_all = fcn.GetPDF().GetFunctor().GetFunctor(_1); auto f0_12 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_0); auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); - auto f0_all = fcn.GetPDF().GetFunctor().GetFunctor(_2); //================================== @@ -762,27 +760,16 @@ int main(int argv, char** argc) //================================== Phi_12_FF = fit_fraction(Phi_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); Phi_13_FF = fit_fraction(Phi_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - Phi_all_FF = fit_fraction(Phi_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_all_FF = fit_fraction(f0_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; - std::cout << "Phi_all_FF :" << Phi_all_FF << std::endl; std::cout << "f0_12_FF :" << f0_12_FF << std::endl; std::cout << "f0_13_FF :" << f0_13_FF << std::endl; - std::cout << "f0_all_FF :" << f0_all_FF << std::endl; std::cout << "Sum :" << Phi_12_FF + Phi_13_FF + f0_12_FF + f0_13_FF << std::endl; - std::cout << "Phi_12_FF :" << fit_fraction(Phi_Resonance_12, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - std::cout << "Phi_13_FF :" << fit_fraction(Phi_Resonance_13, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - std::cout << "Phi_FF :" << fit_fraction(Phi_Resonance, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - std::cout << "f0_12_FF: " << fit_fraction(f0_Resonance_12, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - std::cout << "f0_13_FF: " << fit_fraction(f0_Resonance_13, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - std::cout << "f0_FF: " << fit_fraction(f0_Resonance, Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries) << std::endl; - #ifdef _ROOT_AVAILABLE_ { From 771d0544f2fa5dc69b2719a1f0815cb96c42159f Mon Sep 17 00:00:00 2001 From: juan leite Date: Mon, 19 Mar 2018 09:55:23 +0100 Subject: [PATCH 09/16] last change to PR --- examples/phys/FlatteLineShape.inl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 1f7d3d4d4..0c9648394 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -464,8 +464,7 @@ int main(int argv, char** argc) f0_12_HIST,f0_13_HIST ; double Phi_12_FF, Phi_13_FF, - f0_12_FF,f0_13_FF, - Phi_all_FF, f0_all_FF + f0_12_FF,f0_13_FF ; #endif @@ -746,7 +745,7 @@ int main(int argv, char** argc) auto f0_13 = fcn.GetPDF().GetFunctor().GetFunctor(_2).GetFunctor(_1); - //================================== + //================================== // Draw components //================================== Phi_12_HIST = histogram_component(Phi_12 , {D_MASS, Kminus_MASS, Kplus_MASS}, "Phi_12_HIST", nentries); @@ -763,6 +762,9 @@ int main(int argv, char** argc) f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + Phi_FF = fit_fraction(Phi_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + f0_FF = fit_fraction(f0_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; std::cout << "f0_12_FF :" << f0_12_FF << std::endl; @@ -770,6 +772,7 @@ int main(int argv, char** argc) std::cout << "Sum :" << Phi_12_FF + Phi_13_FF + f0_12_FF + f0_13_FF << std::endl; + #ifdef _ROOT_AVAILABLE_ { From 1299a65a4c9254973979c25df0d33fedff85f38f Mon Sep 17 00:00:00 2001 From: juan leite Date: Thu, 22 Mar 2018 17:58:36 +0100 Subject: [PATCH 10/16] if/else to boolean operations --- examples/phys/FlatteLineShape.inl | 9 ++---- hydra/functions/FlatteLineShape.h | 48 ++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 0c9648394..60d8548fd 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -381,8 +381,8 @@ int main(int argv, char** argc) //====================================================== //f0 - auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(-f0_RC*20.0,+f0_RC*20.0); - auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001).Limits(-f0_IMC*20.0,+f0_IMC*20.0); + auto coef_ref0 = hydra::Parameter::Create().Name("f0_RC").Value(f0_RC).Error(0.0001).Limits(f0_RC*20.0,-f0_RC*20.0); + auto coef_imf0 = hydra::Parameter::Create().Name("f0_IM").Value(f0_IMC).Error(0.0001).Limits(-f0_IMC*10.0,+f0_IMC*10.0); auto f0Mass = hydra::Parameter::Create().Name("MASS_f0").Value(f0_MASS).Fixed(); auto f0g1 = hydra::Parameter::Create().Name("f0_g1").Value(f0_rho1).Fixed(); auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); @@ -762,10 +762,7 @@ int main(int argv, char** argc) f0_12_FF = fit_fraction(f0_12 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); f0_13_FF = fit_fraction(f0_13 , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - Phi_FF = fit_fraction(Phi_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - f0_FF = fit_fraction(f0_all , Opt_Model, {D_MASS, Kminus_MASS, Kplus_MASS}, nentries); - - std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; + std::cout << "Phi_12_FF :" << Phi_12_FF << std::endl; std::cout << "Phi_13_FF :" << Phi_13_FF << std::endl; std::cout << "f0_12_FF :" << f0_12_FF << std::endl; std::cout << "f0_13_FF :" << f0_13_FF << std::endl; diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index 9ffe399b9..e6f203941 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -201,6 +201,37 @@ namespace hydra { hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { + /* double rhopipi_real,_rhopipi_real,rhopipi_imag,_rhopipi_imag,rhokk_real,_rhokk_real,rhokk_imag,_rhokk_imag,A,B,C = 0; + + double pipmass = 0.13957018; + double pi0mass = 0.1349766; + double kpmass = 0.493677; + double k0mass = 0.497614; + + double twopimasssq = 4 * pipmass * pipmass; + double twopi0masssq = 4 * pi0mass * pi0mass; + double twokmasssq = 4 * kpmass * kpmass; + double twok0masssq = 4 * k0mass * k0mass; + + rhopipi_real = (s >= twopi0masssq && s < twopimasssq)*(1. / 3) * ::sqrt(1 - twopi0masssq / s ); + _rhopipi_real= (s >= twopimasssq)*(2. / 3) * ::sqrt(1 - twopimasssq / s ); + + rhopipi_imag = (s < twopi0masssq )*(1. / 3) * ::sqrt(-1 + twopi0masssq / s ); + _rhopipi_imag= (s >= twopi0masssq && s < twopimasssq)*(2. / 3) * ::sqrt(-1 + twopimasssq / s); + + + rhokk_real = (s >= twokmasssq && s < twok0masssq)*0.5 * ::sqrt(1 - twokmasssq / s ); + _rhokk_real = (s >= twok0masssq)*0.5 * ::sqrt(1 - twok0masssq / s ); + + + rhokk_imag = (s < twokmasssq)*0.5 * ::sqrt(-1 + twokmasssq / s ); + _rhokk_imag = (s >= twokmasssq && s < twok0masssq)*0.5 * ::sqrt(-1 + twok0masssq / s ); + + + A = (resonance_mass*resonance_mass - s) + resonance_mass*( (rhopipi_imag + _rhopipi_imag)*g1 + (rhokk_imag + _rhokk_imag) *g2); + B = resonance_mass*( (rhopipi_real + _rhopipi_real)*g1 + (rhokk_real + _rhokk_real)*g2); + C = 1.0 / (A*A + B*B);*/ + double pipmass = 0.13957018; double pi0mass = 0.1349766; double kpmass = 0.493677; @@ -212,32 +243,35 @@ namespace hydra { double twok0masssq = 4 * k0mass * k0mass; double rhopipi_real = 0; + double _rhopipi_real = 0; double rhopipi_imag = 0; double rhokk_real = 0; double rhokk_imag = 0; + if(s >= twopi0masssq) + rhopipi_real = (1. / 3) * ::sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold + else + rhopipi_imag = (1. / 3) * ::sqrt(-1 + twopi0masssq / s ); + if(s >= twopimasssq) rhopipi_real = (2. / 3) * ::sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold else rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s); - if(s >= twopi0masssq) - rhopipi_real = (1. / 3) * ::sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold - else - rhopipi_imag = (1. / 3) * ::sqrt(-1 + twopi0masssq / s ); - if(s >= twokmasssq) + if(s >= twokmasssq) rhokk_real = 0.5 * ::sqrt(1 - twokmasssq / s ); // Above K+K- threshold else rhokk_imag = 0.5 * ::sqrt(-1 + twokmasssq / s ); - if(s >= twok0masssq) + if(s >= twok0masssq) rhokk_real = 0.5 * ::sqrt(1 - twok0masssq / s ); // Above K0K0 threshold else rhokk_imag = 0.5 * ::sqrt(-1 + twok0masssq / s ); - double A = (resonance_mass*resonance_mass - s) + resonance_mass*(rhopipi_imag*g1 + rhokk_imag*g2); + + double A = (resonance_mass*resonance_mass - s) + resonance_mass*( rhopipi_imag*g1 + rhokk_imag*g2); double B = resonance_mass*(rhopipi_real*g1 + rhokk_real*g2); double C = 1.0 / (A*A + B*B); From d7550a53ff62862ea520d4f65eb92d65c71746a1 Mon Sep 17 00:00:00 2001 From: Antonio Augusto Alves Junior Date: Thu, 22 Mar 2018 18:54:03 +0100 Subject: [PATCH 11/16] How to use the Bolean algebra... --- hydra/functions/FlatteLineShape.h | 57 +++++++++++-------------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index e6f203941..246f1f9a2 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -201,36 +201,7 @@ namespace hydra { hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { - /* double rhopipi_real,_rhopipi_real,rhopipi_imag,_rhopipi_imag,rhokk_real,_rhokk_real,rhokk_imag,_rhokk_imag,A,B,C = 0; - - double pipmass = 0.13957018; - double pi0mass = 0.1349766; - double kpmass = 0.493677; - double k0mass = 0.497614; - - double twopimasssq = 4 * pipmass * pipmass; - double twopi0masssq = 4 * pi0mass * pi0mass; - double twokmasssq = 4 * kpmass * kpmass; - double twok0masssq = 4 * k0mass * k0mass; - - rhopipi_real = (s >= twopi0masssq && s < twopimasssq)*(1. / 3) * ::sqrt(1 - twopi0masssq / s ); - _rhopipi_real= (s >= twopimasssq)*(2. / 3) * ::sqrt(1 - twopimasssq / s ); - - rhopipi_imag = (s < twopi0masssq )*(1. / 3) * ::sqrt(-1 + twopi0masssq / s ); - _rhopipi_imag= (s >= twopi0masssq && s < twopimasssq)*(2. / 3) * ::sqrt(-1 + twopimasssq / s); - - - rhokk_real = (s >= twokmasssq && s < twok0masssq)*0.5 * ::sqrt(1 - twokmasssq / s ); - _rhokk_real = (s >= twok0masssq)*0.5 * ::sqrt(1 - twok0masssq / s ); - - - rhokk_imag = (s < twokmasssq)*0.5 * ::sqrt(-1 + twokmasssq / s ); - _rhokk_imag = (s >= twokmasssq && s < twok0masssq)*0.5 * ::sqrt(-1 + twok0masssq / s ); - - - A = (resonance_mass*resonance_mass - s) + resonance_mass*( (rhopipi_imag + _rhopipi_imag)*g1 + (rhokk_imag + _rhokk_imag) *g2); - B = resonance_mass*( (rhopipi_real + _rhopipi_real)*g1 + (rhokk_real + _rhokk_real)*g2); - C = 1.0 / (A*A + B*B);*/ + double pipmass = 0.13957018; double pi0mass = 0.1349766; @@ -242,24 +213,36 @@ namespace hydra { double twokmasssq = 4 * kpmass * kpmass; double twok0masssq = 4 * k0mass * k0mass; - double rhopipi_real = 0; - double _rhopipi_real = 0; - double rhopipi_imag = 0; + // double rhopipi_real = 0; + // double _rhopipi_real = 0; + // double rhopipi_imag = 0; double rhokk_real = 0; double rhokk_imag = 0; - + /* if(s >= twopi0masssq) rhopipi_real = (1. / 3) * ::sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold else rhopipi_imag = (1. / 3) * ::sqrt(-1 + twopi0masssq / s ); - + + if(s >= twopimasssq) rhopipi_real = (2. / 3) * ::sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold else rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s); - - + */ + /*This should be done in this way! */ + constexpr static double _1p3 = 0.333333333; + constexpr static double _2p3 = 0.666666667; + static const double two_pi0_factor = ::sqrt(1 - twopi0masssq / s ); + static const double two_pi_factor = ::sqrt(-1 + twopimasssq / s ); + + double rhopipi_real = ( s >= twopi0masssq && s < twopimasssq)*( (_1p3 * two_pi0_factor ) + + ( s >= twopimasssq)*( (_2p3 * two_pi_factor ); + + double rhopipi_imag = ( s < twopi0masssq)*( (_2p3 * two_pi_factor ); + //------------------------------------- + if(s >= twokmasssq) rhokk_real = 0.5 * ::sqrt(1 - twokmasssq / s ); // Above K+K- threshold else From d5de8fa9884403db87fbe633d5795bad86977e02 Mon Sep 17 00:00:00 2001 From: juan leite Date: Fri, 23 Mar 2018 13:55:26 +0100 Subject: [PATCH 12/16] boolean operation --- examples/phys/FlatteLineShape.inl | 3 +- hydra/functions/FlatteLineShape.h | 79 +++++++++++++------------------ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 60d8548fd..4ee6847aa 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -464,8 +464,7 @@ int main(int argv, char** argc) f0_12_HIST,f0_13_HIST ; double Phi_12_FF, Phi_13_FF, - f0_12_FF,f0_13_FF - ; + f0_12_FF,f0_13_FF; #endif hydra::Decays<3, hydra::host::sys_t > toy_data; diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index 246f1f9a2..5ccdf1dfe 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -196,12 +196,8 @@ namespace hydra { private: - - __hydra_host__ __hydra_device__ inline - hydra::complex - LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { - - + __hydra_dual__ inline + hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { double pipmass = 0.13957018; double pi0mass = 0.1349766; @@ -213,55 +209,44 @@ namespace hydra { double twokmasssq = 4 * kpmass * kpmass; double twok0masssq = 4 * k0mass * k0mass; - // double rhopipi_real = 0; - // double _rhopipi_real = 0; - // double rhopipi_imag = 0; double rhokk_real = 0; double rhokk_imag = 0; + double rhopipi_real = 0; + double rhopipi_imag = 0; + + + constexpr static double _1p3 = 0.333333333; + constexpr static double _2p3 = 0.666666667; + static const double two_pi0_factor = ::sqrt(1 - twopi0masssq / s ); + static const double two_pi_factor = ::sqrt(1 - twopimasssq / s ); + static const double two_pi0_factor_img = ::sqrt(-1 + twopi0masssq / s ); + static const double two_pi_factor_img = ::sqrt(-1 + twopimasssq / s ); + + rhopipi_real = (s >= twopi0masssq)*_1p3*twopi0masssq; + + rhopipi_imag = (s >= twopi0masssq && s < twokmasssq)* (_2p3 * two_pi_factor_img )+ + (s < twopi0masssq)*_1p3*two_pi0_factor_img; - /* - if(s >= twopi0masssq) - rhopipi_real = (1. / 3) * ::sqrt(1 - twopi0masssq / s ); // Above pi0pi0 threshold - else - rhopipi_imag = (1. / 3) * ::sqrt(-1 + twopi0masssq / s ); - - - if(s >= twopimasssq) - rhopipi_real = (2. / 3) * ::sqrt(1 - twopimasssq / s ); // Above pi+pi- threshold - else - rhopipi_imag = (2. / 3) * ::sqrt(-1 + twopimasssq / s); - */ - /*This should be done in this way! */ - constexpr static double _1p3 = 0.333333333; - constexpr static double _2p3 = 0.666666667; - static const double two_pi0_factor = ::sqrt(1 - twopi0masssq / s ); - static const double two_pi_factor = ::sqrt(-1 + twopimasssq / s ); - - double rhopipi_real = ( s >= twopi0masssq && s < twopimasssq)*( (_1p3 * two_pi0_factor ) + - ( s >= twopimasssq)*( (_2p3 * two_pi_factor ); - - double rhopipi_imag = ( s < twopi0masssq)*( (_2p3 * two_pi_factor ); - //------------------------------------- - - if(s >= twokmasssq) - rhokk_real = 0.5 * ::sqrt(1 - twokmasssq / s ); // Above K+K- threshold - else - rhokk_imag = 0.5 * ::sqrt(-1 + twokmasssq / s ); - - if(s >= twok0masssq) - rhokk_real = 0.5 * ::sqrt(1 - twok0masssq / s ); // Above K0K0 threshold - else - rhokk_imag = 0.5 * ::sqrt(-1 + twok0masssq / s ); - - - double A = (resonance_mass*resonance_mass - s) + resonance_mass*( rhopipi_imag*g1 + rhokk_imag*g2); + constexpr static double _1p2 = 0.5; + static const double two_k0_factor = ::sqrt(1 - twok0masssq / s ); + static const double two_k_factor = ::sqrt(1 - twokmasssq / s ); + static const double two_k0_factor_img = ::sqrt(-1 + twok0masssq / s ); + static const double two_k_factor_img = ::sqrt(-1 + twokmasssq / s ); + + + rhokk_real = (s >= twokmasssq && s < twok0masssq)*_1p2*two_k_factor + + (s >= twok0masssq)*_1p2*two_k0_factor; + + rhokk_imag = (s < twok0masssq)*_1p2*two_k0_factor_img; + + + double A = (resonance_mass*resonance_mass - s) + resonance_mass*(rhopipi_imag*g1 + rhokk_imag*g2); double B = resonance_mass*(rhopipi_real*g1 + rhokk_real*g2); double C = 1.0 / (A*A + B*B); hydra::complex retur(A*C, B*C); - - return retur; + return retur; } From 123edd0150267d67a2066f3cd92693f74e531b3b Mon Sep 17 00:00:00 2001 From: Antonio Augusto Alves Junior Date: Fri, 23 Mar 2018 14:14:33 +0100 Subject: [PATCH 13/16] negative sqrt correction/.// --- hydra/functions/FlatteLineShape.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index 5ccdf1dfe..faaec53fd 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -219,8 +219,8 @@ namespace hydra { constexpr static double _2p3 = 0.666666667; static const double two_pi0_factor = ::sqrt(1 - twopi0masssq / s ); static const double two_pi_factor = ::sqrt(1 - twopimasssq / s ); - static const double two_pi0_factor_img = ::sqrt(-1 + twopi0masssq / s ); - static const double two_pi_factor_img = ::sqrt(-1 + twopimasssq / s ); + static const double two_pi0_factor_img = ::sqrt((-1 + twopi0masssq / s)*(twopi0masssq >= s) ); + static const double two_pi_factor_img = ::sqrt((-1 + twopimasssq / s)*(twopimasssq >= s)) ); rhopipi_real = (s >= twopi0masssq)*_1p3*twopi0masssq; @@ -230,8 +230,8 @@ namespace hydra { constexpr static double _1p2 = 0.5; static const double two_k0_factor = ::sqrt(1 - twok0masssq / s ); static const double two_k_factor = ::sqrt(1 - twokmasssq / s ); - static const double two_k0_factor_img = ::sqrt(-1 + twok0masssq / s ); - static const double two_k_factor_img = ::sqrt(-1 + twokmasssq / s ); + static const double two_k0_factor_img = ::sqrt((-1 + twok0masssq / s)*(twok0masssq>=s) ); + static const double two_k_factor_img = ::sqrt((-1 + twokmasssq / s)*(twokmasssq>=s) ); rhokk_real = (s >= twokmasssq && s < twok0masssq)*_1p2*two_k_factor + From 3a2fe6610f362211f161da573fcebd5ef76b3d55 Mon Sep 17 00:00:00 2001 From: juan leite Date: Wed, 4 Apr 2018 05:32:30 +0200 Subject: [PATCH 14/16] FlatteLineshape based in EvtGen --- examples/phys/FlatteLineShape.inl | 31 ++++----- hydra/functions/FlatteLineShape.h | 105 +++++++++++++----------------- 2 files changed, 60 insertions(+), 76 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 4ee6847aa..2442d08c8 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -238,27 +238,28 @@ public: }; -template class Flatte: public hydra::BaseFunctor, hydra::complex, 5> +template class Flatte: public hydra::BaseFunctor, hydra::complex, 3> { constexpr static unsigned int _I1 = CHANNEL-1; constexpr static unsigned int _I2 = (CHANNEL!=3)*CHANNEL; constexpr static unsigned int _I3 = 3-( (CHANNEL-1) + (CHANNEL!=3)*CHANNEL ); - using hydra::BaseFunctor, hydra::complex, 5>::_par; + using hydra::BaseFunctor, hydra::complex, 3>::_par; public: Flatte() = delete; - Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im, hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, - double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass, double radi): - hydra::BaseFunctor, hydra::complex, 5>{c_re, c_im, mean, rho1, rho2}, - fLineShape(mean,rho1,rho2,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im, hydra::Parameter const& mean, + std::vector> const& params,double mother_mass, double daugther1_mass, double daugther2_mass, + double daugther3_mass, double radi): + hydra::BaseFunctor, hydra::complex, 3>{c_re, c_im, mean}, + fLineShape(mean,params,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) {} __hydra_dual__ Flatte( Flatte const& other): - hydra::BaseFunctor, hydra::complex, 5>(other), + hydra::BaseFunctor, hydra::complex, 3>(other), fLineShape(other.GetLineShape()) {} @@ -268,7 +269,7 @@ public: { if(this==&other) return *this; - hydra::BaseFunctor, hydra::complex, 5>::operator=(other); + hydra::BaseFunctor, hydra::complex, 3>::operator=(other); fLineShape=other.GetLineShape(); return *this; @@ -285,15 +286,12 @@ public: hydra::Vector4R p3 = p[_I3]; fLineShape.SetParameter(0,_par[2]); - fLineShape.SetParameter(1,_par[3]); - fLineShape.SetParameter(2,_par[4]); - double theta = fCosDecayAngle( (p1+p2+p3), (p1+p2), p1 ); double angular = fAngularDist(theta); auto r = hydra::complex(_par[0],_par[1])*fLineShape((p1+p2).mass())*angular; - return r; + return r; } private: @@ -360,8 +358,11 @@ int main(int argv, char** argc) double Kplus_MASS = 0.493677; // K+ mass double Kminus_MASS = Kplus_MASS; + //Flatté + double pi_MASS = 0.13957018; + std::vector> params = {{pi_MASS,pi_MASS,f0_rho1},{Kplus_MASS,Kplus_MASS,f0_rho2}}; - //====================================================== + //====================================================== //Phi auto mass = hydra::Parameter::Create().Name("MASS_Phi" ).Value(Phi_MASS ).Error(0.01).Fixed(); auto width = hydra::Parameter::Create().Name("WIDTH_Phi").Value(Phi_Width).Error(0.001).Fixed(); @@ -388,8 +389,8 @@ int main(int argv, char** argc) auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); - Flatte<1,hydra::SWave> f0_Resonance_12(coef_ref0,coef_imf0,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(coef_ref0,coef_imf0,f0Mass,f0g1,rg1og2,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<1,hydra::SWave> f0_Resonance_12(coef_ref0,coef_imf0,f0Mass,params,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<3,hydra::SWave> f0_Resonance_13(coef_ref0,coef_imf0,f0Mass,params,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index faaec53fd..f7b09d903 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -61,8 +62,8 @@ namespace hydra { template - class FlatteLineShape : public BaseFunctor, hydra::complex, 3> { - using BaseFunctor, hydra::complex, 3>::_par; + class FlatteLineShape : public BaseFunctor, hydra::complex, 1> { + using BaseFunctor, hydra::complex, 1>::_par; public: @@ -78,11 +79,13 @@ namespace hydra { * @param daugther3_mass daughter particle 2 mass * @param radi decay vertex radio. */ - FlatteLineShape(hydra::Parameter const& mean, hydra::Parameter const& rho1 , hydra::Parameter const& rho2, + FlatteLineShape(hydra::Parameter const& mean, + std::vector> params, double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass, double radi) : - BaseFunctor, hydra::complex, 3>{mean, rho1, rho2}, + BaseFunctor, hydra::complex,1>{mean}, + fParams(params), fDaughter1Mass(daugther1_mass), fDaughter2Mass(daugther2_mass), fBachelorMass(daugther3_mass), @@ -91,7 +94,8 @@ namespace hydra { __hydra_host__ __hydra_device__ FlatteLineShape(FlatteLineShape const &other) : - BaseFunctor, hydra::complex, 3>(other), + BaseFunctor, hydra::complex, 1>(other), + fParams(other.GetParams()), fDaughter1Mass(other.GetDaughter1Mass()), fDaughter2Mass(other.GetDaughter2Mass()), fBachelorMass(other.GetDaughter3Mass()), @@ -104,8 +108,9 @@ namespace hydra { if (this == &other) return *this; BaseFunctor, - hydra::complex, 3>::operator=(other); + hydra::complex, 7>::operator=(other); + fParams = other.GetParams(); fDaughter1Mass = other.GetDaughter1Mass(); fDaughter2Mass = other.GetDaughter2Mass(); fBachelorMass = other.GetDaughter3Mass(); @@ -115,6 +120,18 @@ namespace hydra { return *this; } + __hydra_host__ __hydra_device__ inline + std::vector>GetParams() const { + return fParams; + } + + __hydra_host__ __hydra_device__ inline + void SetDaughter1Mass(std::vector> _params) { + fParams = _params; + } + + + __hydra_host__ __hydra_device__ inline double GetDaughter1Mass() const { return fDaughter1Mass; @@ -170,13 +187,9 @@ namespace hydra { hydra::complex Evaluate(unsigned int, T *x) const { const double m = x[ArgIndex]; - const double resonance_mass = _par[0]; - const double rho1 = _par[1]; - const double rho2 = _par[2]; - return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fBachelorMass) ? - LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); + return LineShape( m , resonance_mass) ; } @@ -184,70 +197,39 @@ namespace hydra { __hydra_host__ __hydra_device__ inline hydra::complex Evaluate(T x) const { - double m = get(x); - + const double m = get(x); const double resonance_mass = _par[0]; - const double rho1 = _par[1]; - const double rho2 = _par[2]; - return m > (fDaughter1Mass + fDaughter2Mass) && m < (fMotherMass - fBachelorMass) ? - LineShape(m, resonance_mass, rho1, rho2) : hydra::complex(0.0, 0.0); + return LineShape( m , resonance_mass) ; } private: + __hydra_host__ __hydra_device__ inline + hydra::complex + sqrtCplx(const double in) const { return (in > 0) ? hydra::complex(::sqrt(in), 0.0) : hydra::complex(0.0, ::sqrt(-in)); } - __hydra_dual__ inline - hydra::complex LineShape(const double s, const double resonance_mass, const double g1 , const double g2) const { - - double pipmass = 0.13957018; - double pi0mass = 0.1349766; - double kpmass = 0.493677; - double k0mass = 0.497614; - - double twopimasssq = 4 * pipmass * pipmass; - double twopi0masssq = 4 * pi0mass * pi0mass; - double twokmasssq = 4 * kpmass * kpmass; - double twok0masssq = 4 * k0mass * k0mass; - - double rhokk_real = 0; - double rhokk_imag = 0; - double rhopipi_real = 0; - double rhopipi_imag = 0; - - - constexpr static double _1p3 = 0.333333333; - constexpr static double _2p3 = 0.666666667; - static const double two_pi0_factor = ::sqrt(1 - twopi0masssq / s ); - static const double two_pi_factor = ::sqrt(1 - twopimasssq / s ); - static const double two_pi0_factor_img = ::sqrt((-1 + twopi0masssq / s)*(twopi0masssq >= s) ); - static const double two_pi_factor_img = ::sqrt((-1 + twopimasssq / s)*(twopimasssq >= s)) ); - - rhopipi_real = (s >= twopi0masssq)*_1p3*twopi0masssq; - - rhopipi_imag = (s >= twopi0masssq && s < twokmasssq)* (_2p3 * two_pi_factor_img )+ - (s < twopi0masssq)*_1p3*two_pi0_factor_img; - - constexpr static double _1p2 = 0.5; - static const double two_k0_factor = ::sqrt(1 - twok0masssq / s ); - static const double two_k_factor = ::sqrt(1 - twokmasssq / s ); - static const double two_k0_factor_img = ::sqrt((-1 + twok0masssq / s)*(twok0masssq>=s) ); - static const double two_k_factor_img = ::sqrt((-1 + twokmasssq / s)*(twokmasssq>=s) ); + __hydra_host__ __hydra_device__ inline + hydra::complex + LineShape(const double s, const double resonance_mass) const { + hydra::complex w; - rhokk_real = (s >= twokmasssq && s < twok0masssq)*_1p2*two_k_factor + - (s >= twok0masssq)*_1p2*two_k0_factor; +for(size_t i = 0; i < fParams.size() ; i++) { - rhokk_imag = (s < twok0masssq)*_1p2*two_k0_factor_img; + double m1a = fParams[i][0]; + double m1b = fParams[i][1]; + double g = fParams[i][2]; + w += g * g * sqrtCplx((1 - (m1a - m1b) * (m1a - m1b) / s*s ) * + (1 - (m1a + m1b) * (m1a + m1b) / s*s )); - double A = (resonance_mass*resonance_mass - s) + resonance_mass*(rhopipi_imag*g1 + rhokk_imag*g2); - double B = resonance_mass*(rhopipi_real*g1 + rhokk_real*g2); - double C = 1.0 / (A*A + B*B); +} - hydra::complex retur(A*C, B*C); + hydra::complex denom = resonance_mass - s*s - hydra::complex(0.0,1.0)*w; - return retur; + hydra::complex ampl = hydra::complex(1.0,0.0)/denom; + return ampl; } @@ -256,6 +238,7 @@ namespace hydra { double fBachelorMass; double fMotherMass; double fRadi; + std::vector> fParams; }; From 49d88c9f6cbd863b2cef123a2aaf527bb5043623 Mon Sep 17 00:00:00 2001 From: juanbsleite Date: Thu, 12 Apr 2018 21:51:29 +0200 Subject: [PATCH 15/16] Flatte running in cuda backend --- examples/phys/FlatteLineShape.inl | 5 ++-- hydra/functions/FlatteLineShape.h | 38 ++++++++++++++++--------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 2442d08c8..411186080 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -252,7 +252,7 @@ public: Flatte() = delete; Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im, hydra::Parameter const& mean, - std::vector> const& params,double mother_mass, double daugther1_mass, double daugther2_mass, + std::array,2> const ¶ms,double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass, double radi): hydra::BaseFunctor, hydra::complex, 3>{c_re, c_im, mean}, fLineShape(mean,params,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) @@ -360,7 +360,8 @@ int main(int argv, char** argc) //Flatté double pi_MASS = 0.13957018; - std::vector> params = {{pi_MASS,pi_MASS,f0_rho1},{Kplus_MASS,Kplus_MASS,f0_rho2}}; + std::array,2> params = {{{pi_MASS,pi_MASS,f0_rho1},{Kplus_MASS,Kplus_MASS,f0_rho2}}}; + //std::vector> params = {{pi_MASS,pi_MASS,f0_rho1},{Kplus_MASS,Kplus_MASS,f0_rho2}}; //====================================================== //Phi diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index f7b09d903..34be486a6 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -80,7 +80,7 @@ namespace hydra { * @param radi decay vertex radio. */ FlatteLineShape(hydra::Parameter const& mean, - std::vector> params, + std::array,2> params, double mother_mass, double daugther1_mass, double daugther2_mass, double daugther3_mass, double radi) : @@ -121,12 +121,12 @@ namespace hydra { } __hydra_host__ __hydra_device__ inline - std::vector>GetParams() const { + std::array,2> GetParams() const { return fParams; } __hydra_host__ __hydra_device__ inline - void SetDaughter1Mass(std::vector> _params) { + void SetDaughter1Mass(std::array,2> _params) { fParams = _params; } @@ -204,32 +204,34 @@ namespace hydra { } private: + __hydra_host__ __hydra_device__ inline hydra::complex sqrtCplx(const double in) const { return (in > 0) ? hydra::complex(::sqrt(in), 0.0) : hydra::complex(0.0, ::sqrt(-in)); } - __hydra_host__ __hydra_device__ inline - hydra::complex - LineShape(const double s, const double resonance_mass) const { - hydra::complex w; + __hydra_host__ __hydra_device__ inline hydra::complex LineShape(const double s, const double resonance_mass) const { -for(size_t i = 0; i < fParams.size() ; i++) { + hydra::complex w; - double m1a = fParams[i][0]; - double m1b = fParams[i][1]; - double g = fParams[i][2]; - w += g * g * sqrtCplx((1 - (m1a - m1b) * (m1a - m1b) / s*s ) * - (1 - (m1a + m1b) * (m1a + m1b) / s*s )); -} + for(size_t i = 0; i < fParams.size() ; i++) { + + double m1a = fParams[i][0]; + double m1b = fParams[i][1]; + double g = fParams[i][2]; + + w += g * g * sqrtCplx((1 - (m1a - m1b) * (m1a - m1b) / s*s ) * + (1 - (m1a + m1b) * (m1a + m1b) / s*s )); + + } - hydra::complex denom = resonance_mass - s*s - hydra::complex(0.0,1.0)*w; + hydra::complex denom = resonance_mass - s*s - hydra::complex(0.0,1.0)*w; - hydra::complex ampl = hydra::complex(1.0,0.0)/denom; + hydra::complex ampl = hydra::complex(1.0,0.0)/denom; - return ampl; + return ampl; } @@ -238,7 +240,7 @@ for(size_t i = 0; i < fParams.size() ; i++) { double fBachelorMass; double fMotherMass; double fRadi; - std::vector> fParams; + std::array,2> fParams; }; From 8bba5bd8a0ac8247627de6780c5e591108fb723c Mon Sep 17 00:00:00 2001 From: juanbsleite Date: Thu, 12 Apr 2018 22:05:12 +0200 Subject: [PATCH 16/16] flatte unused paramaters removed --- examples/phys/FlatteLineShape.inl | 9 ++-- hydra/functions/FlatteLineShape.h | 89 +++---------------------------- 2 files changed, 12 insertions(+), 86 deletions(-) diff --git a/examples/phys/FlatteLineShape.inl b/examples/phys/FlatteLineShape.inl index 411186080..abbaef2a8 100644 --- a/examples/phys/FlatteLineShape.inl +++ b/examples/phys/FlatteLineShape.inl @@ -252,10 +252,9 @@ public: Flatte() = delete; Flatte(hydra::Parameter const& c_re, hydra::Parameter const& c_im, hydra::Parameter const& mean, - std::array,2> const ¶ms,double mother_mass, double daugther1_mass, double daugther2_mass, - double daugther3_mass, double radi): + std::array,2> const ¶ms): hydra::BaseFunctor, hydra::complex, 3>{c_re, c_im, mean}, - fLineShape(mean,params,mother_mass,daugther1_mass,daugther2_mass,daugther3_mass,radi) + fLineShape(mean,params) {} __hydra_dual__ Flatte( Flatte const& other): @@ -390,8 +389,8 @@ int main(int argv, char** argc) auto rg1og2 = hydra::Parameter::Create().Name("f0_g1xg2").Value(f0_rho2).Fixed(); - Flatte<1,hydra::SWave> f0_Resonance_12(coef_ref0,coef_imf0,f0Mass,params,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); - Flatte<3,hydra::SWave> f0_Resonance_13(coef_ref0,coef_imf0,f0Mass,params,D_MASS,Kminus_MASS,Kplus_MASS,Kplus_MASS,1.5); + Flatte<1,hydra::SWave> f0_Resonance_12(coef_ref0,coef_imf0,f0Mass,params); + Flatte<3,hydra::SWave> f0_Resonance_13(coef_ref0,coef_imf0,f0Mass,params); auto f0_Resonance = (f0_Resonance_12 + f0_Resonance_13); diff --git a/hydra/functions/FlatteLineShape.h b/hydra/functions/FlatteLineShape.h index 34be486a6..b33f94daf 100644 --- a/hydra/functions/FlatteLineShape.h +++ b/hydra/functions/FlatteLineShape.h @@ -80,27 +80,16 @@ namespace hydra { * @param radi decay vertex radio. */ FlatteLineShape(hydra::Parameter const& mean, - std::array,2> params, - double mother_mass, - double daugther1_mass, double daugther2_mass, double daugther3_mass, - double radi) : + std::array,2> params) : BaseFunctor, hydra::complex,1>{mean}, - fParams(params), - fDaughter1Mass(daugther1_mass), - fDaughter2Mass(daugther2_mass), - fBachelorMass(daugther3_mass), - fMotherMass(mother_mass), - fRadi(radi) {} + fParams(params) + {} __hydra_host__ __hydra_device__ FlatteLineShape(FlatteLineShape const &other) : BaseFunctor, hydra::complex, 1>(other), - fParams(other.GetParams()), - fDaughter1Mass(other.GetDaughter1Mass()), - fDaughter2Mass(other.GetDaughter2Mass()), - fBachelorMass(other.GetDaughter3Mass()), - fMotherMass(other.GetMotherMass()), - fRadi(other.GetRadi()) {} + fParams(other.GetParams()) + {} __hydra_host__ __hydra_device__ FlatteLineShape & @@ -108,14 +97,9 @@ namespace hydra { if (this == &other) return *this; BaseFunctor, - hydra::complex, 7>::operator=(other); + hydra::complex, 1>::operator=(other); fParams = other.GetParams(); - fDaughter1Mass = other.GetDaughter1Mass(); - fDaughter2Mass = other.GetDaughter2Mass(); - fBachelorMass = other.GetDaughter3Mass(); - fMotherMass = other.GetMotherMass(); - fRadi = other.GetRadi(); return *this; } @@ -126,62 +110,10 @@ namespace hydra { } __hydra_host__ __hydra_device__ inline - void SetDaughter1Mass(std::array,2> _params) { + void SetParams(std::array,2> _params) { fParams = _params; } - - - __hydra_host__ __hydra_device__ inline - double GetDaughter1Mass() const { - return fDaughter1Mass; - } - - __hydra_host__ __hydra_device__ inline - void SetDaughter1Mass(double daughter1Mass) { - fDaughter1Mass = daughter1Mass; - } - - __hydra_host__ __hydra_device__ inline - double GetDaughter2Mass() const { - return fDaughter2Mass; - } - - __hydra_host__ __hydra_device__ inline - void SetDaughter2Mass(double daughter2Mass) { - fDaughter2Mass = daughter2Mass; - } - - __hydra_host__ __hydra_device__ inline - double GetDaughter3Mass() const { - return fBachelorMass; - } - - __hydra_host__ __hydra_device__ inline - void SetDaughter3Mass(double daughter3Mass) { - fBachelorMass = daughter3Mass; - } - - __hydra_host__ __hydra_device__ inline - double GetMotherMass() const { - return fMotherMass; - } - - __hydra_host__ __hydra_device__ inline - void SetMotherMass(double motherMass) { - fMotherMass = motherMass; - } - - __hydra_host__ __hydra_device__ inline - double GetRadi() const { - return fRadi; - } - - __hydra_host__ __hydra_device__ inline - void SetRadi(double radi) { - fRadi = radi; - } - template __hydra_host__ __hydra_device__ inline hydra::complex Evaluate(unsigned int, T *x) const { @@ -235,12 +167,7 @@ namespace hydra { } - double fDaughter1Mass; - double fDaughter2Mass; - double fBachelorMass; - double fMotherMass; - double fRadi; - std::array,2> fParams; + std::array,2> fParams; };