This example shows how to use the Hydra's phase space Monte Carlo algorithms to generate a sample of B0 -> J/psi K pi, J/psi-> mu+ mu- and plot the Dalitz plot.
#ifndef PHSP_CHAIN_INL_
#define PHSP_CHAIN_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <vector>
#include <array>
#include <chrono>
#include <tclap/CmdLine.h>
#ifdef _ROOT_AVAILABLE_
#include <TROOT.h>
#include <TH1D.h>
#include <TF1.h>
#include <TH2D.h>
#include <TH3D.h>
#include <TApplication.h>
#include <TCanvas.h>
#include <TColor.h>
#include <TString.h>
#include <TStyle.h>
#endif //_ROOT_AVAILABLE_
{
double mup_mass = 0.1056583745;
double mum_mass = 0.1056583745;
try {
TCLAP::CmdLine cmd("Command line arguments for PHSP B0 -> J/psi K pi", '=');
TCLAP::ValueArg<size_t>
NArg(
"n",
"nevents",
"Number of events to generate. Default is [ 10e6 ].",
true, 10e6, "unsigned long");
}
catch (TCLAP::ArgException &e) {
std::cerr << "error: " << e.error() << " for arg " << e.argId()
<< std::endl;
}
#ifdef _ROOT_AVAILABLE_
TH2D DalitzHist("Dalitz_d", ";M^{2}(J/psi #pi) [GeV^{2}/c^{4}]; M^{2}(K #pi) [GeV^{2}/c^{4}]",
TH1D CosThetaHist("CosTheta_d", "; cos(#theta_{K*}); Events", 100, -1.0, 1.0);
TH1D DeltaPhiHist("Delta_d", "; #Delta #phi; Events", 100, 0.0, 3.5);
#endif
[]
__hydra_dual__ (Jpsi jpsi, Kaon kaon, Pion pion , MuonP mup, MuonM mum )
{
hydra::Vector4R
B0 = jpsi+kaon+pion;
hydra::Vector4R Kstar = kaon+pion;
hydra::Vector4R Zplus = jpsi+pion;
M23Sq M2_Kpi = Kstar.mass2();
M13Sq M2_jpsipi = Zplus.mass2();
double qd = Kstar * kaon;
double mq2 = Kstar.mass2();
double md2 = kaon().mass2();
CosTheta cos_helangle = (pd * mq2 - pq * qd) /
sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2));
hydra::Vector4R d1_perp = kaon - (Kstar.dot(kaon) / Kstar.dot(Kstar)) * Kstar;
hydra::Vector4R h1_perp = mup - (Kstar.dot(mup) / Kstar.dot(Kstar)) * Kstar;
hydra::Vector4R d1_prime = Kstar.cross(d1_perp);
d1_perp = d1_perp / d1_perp.d3mag();
d1_prime = d1_prime / d1_prime.d3mag();
double x = d1_perp.dot(h1_perp);
double y = d1_prime.dot(h1_perp);
DeltaPhi chi = atan2(y, x);
if(chi < 0.0) chi += 2.0*
PI;
});
{
auto start = std::chrono::high_resolution_clock::now();
ThreeBodyPHSP.Generate(
B0, ThreeBodyDecay);
TwoBodyPHSP.Generate( ThreeBodyDecay.GetDaugtherRange(
_0), TwoBodyDecay);
auto end = std::chrono::high_resolution_clock::now();
auto chain = ThreeBodyDecay.Meld( TwoBodyDecay ) | Variables;
auto weights = ThreeBodyDecay | ThreeBodyDecay.GetEventWeightFunctor();
std::cout << std::endl;
std::cout << std::endl;
std::cout << "----------------- Device ----------------"<< std::endl;
std::cout << "| B0 -> J/psi K pi | J/psi -> mu+ mu-" << std::endl;
std::cout <<
"| Number of events :"<<
nentries << std::endl;
std::cout <<
"| Time (ms) :"<<
elapsed.count() << std::endl;
std::cout << "-----------------------------------------"<< std::endl;
for( size_t i=0; i<10; i++ )
std::cout <<"Weight {"<< weights[i] << "} | Event { " << chain[i]<< " }" << std::endl;
#ifdef _ROOT_AVAILABLE_
auto dataset = variables.meld(Weights);
for( auto entry: dataset )
{
M13Sq M2_13 = hydra::get<M13Sq&>(entry);
M23Sq M2_23 = hydra::get<M23Sq&>(entry);
CosTheta cosTheta = hydra::get<CosTheta&>(entry);
DeltaPhi deltaPhi = hydra::get<DeltaPhi&>(entry);
Weight weight = hydra::get<Weight&>(entry);
DalitzHist.Fill(M2_13, M2_23, weight );
CosThetaHist.Fill(cosTheta, weight );
DeltaPhiHist.Fill(deltaPhi, weight );
}
#endif
}
#ifdef _ROOT_AVAILABLE_
TApplication *m_app=new TApplication("myapp",0,0);
TCanvas canvas1_d("canvas1_d", "Phase-space", 500, 500);
DalitzHist.Draw("colz");
TCanvas canvas2_d("canvas2_d", "Phase-space", 500, 500);
CosThetaHist.Draw("hist");
CosThetaHist.SetMinimum(0.0);
TCanvas canvas3_d("canvas3_d", "Phase-space", 500, 500);
DeltaPhiHist.Draw("hist");
DeltaPhiHist.SetMinimum(0.0);
m_app->Run();
#endif
return 0;
}
#endif