|
| 1 | +/*---------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * Copyright (C) 2016 - 2017 Antonio Augusto Alves Junior |
| 4 | + * |
| 5 | + * This file is part of Hydra Data Analysis Framework. |
| 6 | + * |
| 7 | + * Hydra is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * Hydra is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with Hydra. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + *---------------------------------------------------------------------------*/ |
| 21 | + |
| 22 | +/* |
| 23 | + * generate_decay_chain.C |
| 24 | + * |
| 25 | + * Created on: 25/03/2018 |
| 26 | + * Author: Davide Brundu |
| 27 | + * |
| 28 | + * Generate the decay chain D0 -> f0 (-> pi pi) rho (-> mu mu) |
| 29 | + * Plot the Dalitz plot andt the Delta Angle between decay planes |
| 30 | + * both using the lambda and the hydra functor |
| 31 | + * |
| 32 | + */ |
| 33 | + |
| 34 | + |
| 35 | +/*--------------------------------- |
| 36 | + * std |
| 37 | + * --------------------------------- |
| 38 | + */ |
| 39 | +#include <iostream> |
| 40 | +#include <assert.h> |
| 41 | +#include <time.h> |
| 42 | +#include <vector> |
| 43 | +#include <array> |
| 44 | +#include <chrono> |
| 45 | + |
| 46 | + |
| 47 | +/*--------------------------------- |
| 48 | + * Include hydra classes and |
| 49 | + * algorithms for |
| 50 | + *-------------------------------- |
| 51 | + */ |
| 52 | +#ifndef HYDRA_HOST_SYSTEM |
| 53 | +#define HYDRA_HOST_SYSTEM CPP |
| 54 | +#endif |
| 55 | + |
| 56 | +#ifndef HYDRA_DEVICE_SYSTEM |
| 57 | +#define HYDRA_DEVICE_SYSTEM TBB |
| 58 | +#endif |
| 59 | + |
| 60 | + |
| 61 | +#include <hydra/PhaseSpace.h> |
| 62 | +#include <hydra/Chains.h> |
| 63 | +#include <hydra/Evaluate.h> |
| 64 | +#include <hydra/Function.h> |
| 65 | +#include <hydra/FunctorArithmetic.h> |
| 66 | +#include <hydra/FunctionWrapper.h> |
| 67 | +#include <hydra/Copy.h> |
| 68 | +#include <hydra/Tuple.h> |
| 69 | +#include <hydra/Vector3R.h> |
| 70 | +#include <hydra/Vector4R.h> |
| 71 | +#include <hydra/host/System.h> |
| 72 | +#include <hydra/device/System.h> |
| 73 | +#include <hydra/Placeholders.h> |
| 74 | + |
| 75 | +#include <hydra/functions/PlanesDeltaAngle.h> |
| 76 | +/*------------------------------------- |
| 77 | + * Include classes from ROOT to fill |
| 78 | + * and draw histograms and plots. |
| 79 | + *------------------------------------- |
| 80 | + */ |
| 81 | +#include <TROOT.h> |
| 82 | +#include <TH1D.h> |
| 83 | +#include <TF1.h> |
| 84 | +#include <TH2D.h> |
| 85 | +#include <TH3D.h> |
| 86 | +#include <TApplication.h> |
| 87 | +#include <TCanvas.h> |
| 88 | +#include <TColor.h> |
| 89 | +#include <TString.h> |
| 90 | +#include <TStyle.h> |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +using namespace hydra::placeholders; |
| 95 | + |
| 96 | +void generate_decay_chain(size_t nentries =100000) |
| 97 | +{ |
| 98 | + |
| 99 | + |
| 100 | + double D0_mass = 1.86483; // D0 mass |
| 101 | + double Jpsi_mass = 3.0969; // J/psi mass |
| 102 | + double rho_mass = 0.77526; // rho mass |
| 103 | + double f0_mass = 0.990; // f0 mass |
| 104 | + double K_mass = 0.493677; // K+ mass |
| 105 | + double pi_mass = 0.13957061; // pi mass |
| 106 | + double mu_mass = 0.1056583745 ;// mu mass |
| 107 | + |
| 108 | + |
| 109 | + TH2D* Dalitz_d = new TH2D("Dalitz_d", "Device;M^{2}(#rho #pi) [GeV^{2}/c^{4}]; M^{2}(#pi #pi) [GeV^{2}/c^{4}]", |
| 110 | + 100, pow(rho_mass + pi_mass,2), pow(D0_mass - pi_mass,2), |
| 111 | + 100, pow(pi_mass + pi_mass,2), pow(D0_mass - rho_mass,2)); |
| 112 | + |
| 113 | + TH1D* CosTheta_d = new TH1D("CosTheta_d", "Device; cos(#theta_{K*}), Events", 100, -1.0, 1.0); |
| 114 | + |
| 115 | + TH1D* Delta_d = new TH1D("Delta_d", "Device; #delta #phi, Events", 100, 0.0, 3.5); |
| 116 | + TH1D* Delta_d2 = new TH1D("Delta_d2", "Device; #delta #phi, Events", 100, 0.0, 3.5); |
| 117 | + |
| 118 | + //C++11 lambda for Kpi invariant mass |
| 119 | + auto M2 = [] __hydra_dual__ (hydra::Vector4R const& p1, hydra::Vector4R const& p2 ) |
| 120 | + { return (p1 + p2).mass2(); }; |
| 121 | + |
| 122 | + |
| 123 | + //C++11 lambda for cosine of helicity angle Kpi |
| 124 | + auto COSHELANG = [] __hydra_dual__ (hydra::Vector4R const& p1, hydra::Vector4R const& p2, hydra::Vector4R const& p3 ) |
| 125 | + { |
| 126 | + hydra::Vector4R p = p1 + p2 + p3; |
| 127 | + hydra::Vector4R q = p2 + p3; |
| 128 | + |
| 129 | + double pd = p * p2; |
| 130 | + double pq = p * q; |
| 131 | + double qd = q * p2; |
| 132 | + double mp2 = p.mass2(); |
| 133 | + double mq2 = q.mass2(); |
| 134 | + double md2 = p2.mass2(); |
| 135 | + |
| 136 | + return (pd * mq2 - pq * qd) |
| 137 | + / sqrt((pq * pq - mq2 * mp2) * (qd * qd - mq2 * md2)); |
| 138 | + }; |
| 139 | + |
| 140 | + //C++11 lambda for angle between the planes [K,pi] and [mu+, mu-] |
| 141 | + auto DELTA = [] __hydra_dual__ (hydra::Vector4R const& d2, hydra::Vector4R const& d3, |
| 142 | + hydra::Vector4R const& h1, hydra::Vector4R const& ) |
| 143 | + { |
| 144 | + hydra::Vector4R D = d2 + d3; |
| 145 | + |
| 146 | + hydra::Vector4R d1_perp = d2 - (D.dot(d2) / D.dot(D)) * D; |
| 147 | + hydra::Vector4R h1_perp = h1 - (D.dot(h1) / D.dot(D)) * D; |
| 148 | + |
| 149 | + // orthogonal to both D and d1_perp |
| 150 | + hydra::Vector4R d1_prime = D.cross(d1_perp); |
| 151 | + |
| 152 | + d1_perp = d1_perp / d1_perp.d3mag(); |
| 153 | + d1_prime = d1_prime / d1_prime.d3mag(); |
| 154 | + |
| 155 | + double x, y; |
| 156 | + |
| 157 | + x = d1_perp.dot(h1_perp); |
| 158 | + y = d1_prime.dot(h1_perp); |
| 159 | + |
| 160 | + double chi = atan2(y, x); |
| 161 | + |
| 162 | + |
| 163 | + return chi; |
| 164 | + }; |
| 165 | + |
| 166 | + //B0 |
| 167 | + hydra::Vector4R D0(D0_mass, 0.0, 0.0, 0.0); |
| 168 | + |
| 169 | + // Create PhaseSpace object for D0 -> f0 rho |
| 170 | + hydra::PhaseSpace<2> phsp1{f0_mass, rho_mass}; |
| 171 | + |
| 172 | + // Create PhaseSpace object for f0 -> pi+ pi- |
| 173 | + hydra::PhaseSpace<2> phsp2{pi_mass , pi_mass}; |
| 174 | + |
| 175 | + // Create PhaseSpace object for rh0 -> mu+ mu- |
| 176 | + hydra::PhaseSpace<2> phsp3{mu_mass , mu_mass}; |
| 177 | + |
| 178 | + |
| 179 | + //device |
| 180 | + { |
| 181 | + //allocate memory to hold the final states particles |
| 182 | + auto Chain_d = hydra::make_chain<2,2,2>(hydra::device::sys, nentries); |
| 183 | + |
| 184 | + |
| 185 | + auto start = std::chrono::high_resolution_clock::now(); |
| 186 | + |
| 187 | + //generate the final state particles for D0 -> f0 rho |
| 188 | + phsp1.Generate(D0, Chain_d.GetDecay(_0).begin(), Chain_d.GetDecay(_0).end()); |
| 189 | + |
| 190 | + //pass the list of f0 to generate the final |
| 191 | + //state particles for f0 -> pi+ pi- |
| 192 | + phsp2.Generate(Chain_d.GetDecay(_0).GetDaughters(0).begin(), |
| 193 | + Chain_d.GetDecay(_0).GetDaughters(0).end(), |
| 194 | + Chain_d.GetDecay(_1).begin() ); |
| 195 | + |
| 196 | + //pass the list of rho to generate the final |
| 197 | + //state particles for rho -> mu+ mu- |
| 198 | + phsp3.Generate(Chain_d.GetDecay(_0).GetDaughters(1).begin(), |
| 199 | + Chain_d.GetDecay(_0).GetDaughters(1).end(), |
| 200 | + Chain_d.GetDecay(_2).begin()); |
| 201 | + |
| 202 | + auto end = std::chrono::high_resolution_clock::now(); |
| 203 | + |
| 204 | + std::chrono::duration<double, std::milli> elapsed = end - start; |
| 205 | + |
| 206 | + //output |
| 207 | + std::cout << std::endl; |
| 208 | + std::cout << std::endl; |
| 209 | + std::cout << "----------------- Device --------------------------" << std::endl; |
| 210 | + std::cout << "| D0 -> f0 rho | f0 -> pi+ pi- | rho -> mu+ mu-" << std::endl; |
| 211 | + std::cout << "| Number of events :"<< nentries << std::endl; |
| 212 | + std::cout << "| Time (ms) :"<< elapsed.count() << std::endl; |
| 213 | + std::cout << "---------------------------------------------------" << std::endl; |
| 214 | + |
| 215 | + //print |
| 216 | + for( size_t i=0; i<10; i++ ) |
| 217 | + std::cout << Chain_d[i] << std::endl; |
| 218 | + |
| 219 | + |
| 220 | + //bring events to CPU memory space |
| 221 | + auto Chain_h = hydra::make_chain<2,2,2>(hydra::host::sys, nentries); |
| 222 | + Chain_h = Chain_d; |
| 223 | + |
| 224 | + for( auto event : Chain_h ) |
| 225 | + { |
| 226 | + |
| 227 | + auto D0_decay = hydra::get<1>(event) ; |
| 228 | + auto f0_decay = hydra::get<2>(event) ; |
| 229 | + auto rho_decay = hydra::get<3>(event) ; |
| 230 | + |
| 231 | + double weight = hydra::get<0>(D0_decay ); |
| 232 | + hydra::Vector4R f0 = hydra::get<1>(D0_decay ); |
| 233 | + hydra::Vector4R rho = hydra::get<2>(D0_decay ); |
| 234 | + |
| 235 | + hydra::Vector4R pip = hydra::get<1>(f0_decay ); |
| 236 | + hydra::Vector4R pim = hydra::get<2>(f0_decay ); |
| 237 | + |
| 238 | + hydra::Vector4R mup = hydra::get<1>(rho_decay ); |
| 239 | + hydra::Vector4R mum = hydra::get<2>(rho_decay ); |
| 240 | + |
| 241 | + |
| 242 | + double M2_pipi = M2(pim,pip); |
| 243 | + double M2_rhopi = M2(rho,pip); |
| 244 | + double CosTheta = COSHELANG(rho, pip, pim ); |
| 245 | + double DeltaAngle = DELTA( pip, pim, mup, mum); |
| 246 | + hydra::PlanesDeltaAngle chi; |
| 247 | + double DeltaAngle2 = chi(pip, pim, mup, mum); |
| 248 | + Dalitz_d->Fill(M2_rhopi, M2_pipi , weight); |
| 249 | + Delta_lambda->Fill(DeltaAngle); |
| 250 | + Delta_functor->Fill(DeltaAngle2); |
| 251 | + } |
| 252 | + |
| 253 | + }//end device |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + //-------------------------------------- |
| 258 | + |
| 259 | + TCanvas* canvas1_d = new TCanvas("canvas1_d", "Phase-space Host", 500, 500); |
| 260 | + Dalitz_d->Draw("colz"); |
| 261 | + Dalitz_d->SetMinimum(0.0); |
| 262 | + |
| 263 | + TCanvas* canvas3_d = new TCanvas("canvas3_d", "Phase-space Host", 500, 500); |
| 264 | + Delta_lambda->Draw("hist"); |
| 265 | + Delta_lambda->SetMinimum(0.0); |
| 266 | + |
| 267 | + TCanvas* canvas4_d = new TCanvas("canvas4_d", "Phase-space Host", 500, 500); |
| 268 | + Delta_functor->Draw("hist"); |
| 269 | + Delta_functor->SetMinimum(0.0); |
| 270 | +} |
0 commit comments