Skip to content

Commit aa5ebde

Browse files
authored
Merge pull request #35 from MultithreadCorner/develop
Develop
2 parents b18ee94 + 22faf2c commit aa5ebde

File tree

5 files changed

+104
-36
lines changed

5 files changed

+104
-36
lines changed

examples/phase_space/phsp_chain.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ int main(int argv, char** argc)
218218
auto start = std::chrono::high_resolution_clock::now();
219219

220220
//generate the final state particles for B0 -> K pi J/psi
221-
phsp1.Generate(B0, Chain_d.GetDecay(_0).begin(), Chain_d.GetDecay(_0).end());
221+
phsp1.Generate(B0, Chain_d.GetDecays(_0).begin(), Chain_d.GetDecays(_0).end());
222222

223223
//pass the list of J/psi to generate the final
224224
//state particles for J/psi -> mu+ mu-
225-
phsp2.Generate(Chain_d.GetDecay(_0).GetDaughters(0).begin(), Chain_d.GetDecay(_0).GetDaughters(0).end(),
226-
Chain_d.GetDecay(_1).begin());
225+
phsp2.Generate(Chain_d.GetDecays(_0).GetDaughters(0).begin(), Chain_d.GetDecays(_0).GetDaughters(0).end(),
226+
Chain_d.GetDecays(_1).begin());
227227

228228
auto end = std::chrono::high_resolution_clock::now();
229229

examples/root_macros/particle_dispersion.C

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,92 +47,129 @@
4747
#include <hydra/multiarray.h>
4848
#include <hydra/ForEach.h>
4949

50+
#include "TCanvas.h"
51+
#include "TGraphTime.h"
52+
#include "TROOT.h"
53+
#include "TMarker.h"
5054

5155
struct Evolve
5256
{
5357
Evolve() = delete;
5458

55-
Evolve(double time, double step):
56-
fTime(time),
57-
fStep(step)
59+
Evolve(double ispeed, double time, double slope):
60+
fInitialSpeed(ispeed),
61+
fSlope(slope),
62+
fTime(time)
5863
{}
5964

65+
__hydra_dual__
6066
Evolve(Evolve const& other):
61-
fTime(other.fTime),
62-
fStep(other.fStep)
67+
fInitialSpeed(other.fInitialSpeed),
68+
fSlope(other.fSlope),
69+
fTime(other.fTime)
6370
{}
6471

65-
__hydra_dual__
6672
template<typename Particle>
73+
__hydra_dual__
6774
inline void operator()(Particle p) {
75+
6876
double theta = hydra::get<3>(p);
69-
hydra::get<0>(p) += delta_x(theta);
70-
hydra::get<1>(p) += delta_y(theta);
71-
hydra::get<2>(p) += delta_z(theta);
77+
double phi = hydra::get<4>(p);
78+
79+
hydra::get<0>(p) += delta_x(theta, phi);
80+
hydra::get<1>(p) += delta_y(theta, phi);
81+
hydra::get<2>(p) += delta_z(theta, phi);
7282
}
7383

7484
__hydra_dual__
75-
inline double delta_x(double theta){
76-
return ::exp(-fTime)*::cos(theta)*fStep;
85+
inline double delta_x(double theta, double phi){
86+
return displacement()*::cos(theta)*sin(phi);
7787
}
7888

7989
__hydra_dual__
80-
inline double delta_y(double theta){
81-
return ::exp(-fTime)*::sin(theta)*fStep;
90+
inline double delta_y(double theta, double phi){
91+
return displacement()*::sin(theta)*sin(phi);
8292
}
8393

8494
__hydra_dual__
85-
inline double delta_z(double theta) {
86-
return ::exp(-fTime)*fStep;
95+
inline double delta_z(double theta, double phi) {
96+
return displacement()*sin(phi);
8797
}
8898

99+
100+
__hydra_dual__
101+
inline double displacement(){
102+
return ::exp(-fSlope*fTime)*(fSlope*fTime*fTime + fInitialSpeed) ;
103+
}
104+
105+
106+
double fInitialSpeed;
107+
double fSlope;
89108
double fTime;
90-
double fStep;
109+
91110
};
92111

93112

94-
typedef hydra::multiarray<double, 4, hydra::device::sys_t> StateDevice_t;
95-
typedef hydra::multiarray<double, 4, hydra::host::sys_t> StateHost_t;
113+
typedef hydra::multiarray<double, 5, hydra::device::sys_t> StateDevice_t;
114+
typedef hydra::multiarray<double, 5, hydra::host::sys_t> StateHost_t;
96115
typedef std::vector<StateHost_t> Ensamble_t;
97116

98-
void particle_dispersion( size_t nparicles, size_t nsteps, double epsilon ){
117+
void particle_dispersion( size_t nparicles, size_t nsteps, double initial_speed, double slope ){
99118

100-
Ensamble_t ensamble(nsteps, StateHost_t(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0) ));
119+
Ensamble_t ensamble(nsteps, StateHost_t(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0, 0.0) ));
101120

102121

103122
{
104123
//initial state
105-
StateDevice_t initial_state(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0));
124+
StateDevice_t initial_state(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0, 0.0));
106125
//distribute particles in the surface
107126
hydra::Random<> RND( std::chrono::system_clock::now().time_since_epoch().count());
108127
// set x-coordinate
109128
RND.SetSeed(159);
110-
RND.Uniform(-1.0, 1.0, initial_state.begin(0), initial_state.end(0));
129+
RND.Uniform(-0.1, 0.1, initial_state.begin(0), initial_state.end(0));
111130
// set y-coordinate
112131
RND.SetSeed(753);
113-
RND.Uniform(-1.0, 1.0, initial_state.begin(1), initial_state.end(1));
132+
RND.Uniform(-2.0, 2.0, initial_state.begin(1), initial_state.end(1));
114133

115134
size_t i=1;
116135

117136
for(auto& final_state:ensamble){
118137

119-
hydra::Random<> RND(std::rand());
138+
RND.SetSeed(std::rand());
120139
RND.Uniform(0.0, 2.0*PI, initial_state.begin(3), initial_state.end(3));
121-
hydra::for_each( initial_state.begin(), initial_state.end(), Evolve(i*epsilon, 2.0) );
140+
RND.SetSeed(std::rand());
141+
RND.Uniform(0.0, 2.0*PI, initial_state.begin(4), initial_state.end(4));
142+
hydra::for_each( initial_state.begin(), initial_state.end(), Evolve(initial_speed , double(i)/nsteps, slope) );
122143
hydra::copy(initial_state.begin(), initial_state.end(), final_state.begin());
123144
i++;
124145
}
125146

126147
}
127148

128-
for(auto& state:ensamble){
129-
std::cout<< "=====================================" << std::endl;
130-
std::cout<< "=====================================" << std::endl;
131-
std::cout<< std::endl << std::endl << std::endl;
132-
for(auto particle:state)
133-
std::cout<< particle << std::endl;
149+
150+
TCanvas canvas("canvas", "", 500, 500);
151+
TGraphTime *g = new TGraphTime(nsteps,-10.0, -10.0, 10.0, 10.0);
152+
153+
int step=0;
154+
for(auto final_state:ensamble){
155+
156+
for( auto particle:final_state){
157+
158+
double x = hydra::get<0>(particle);
159+
double y = hydra::get<1>(particle);
160+
161+
TMarker *m = new TMarker(x,y,20);
162+
m->SetMarkerColor(kBlack);
163+
m->SetMarkerSize(0.5);
164+
g->Add(m,step);
165+
}
166+
167+
step++;
134168
}
135169

170+
171+
g->Draw();
172+
136173
}
137174

138175

hydra/Chains.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ class Chains<Decays<N, hydra::detail::BackendPolicy<BACKEND> >...> {
231231

232232
template<unsigned int I>
233233
typename HYDRA_EXTERNAL_NS::thrust::tuple_element<I, decays_type >::type&
234-
GetDecay(placeholders::placeholder<I> ) {
234+
GetDecays(placeholders::placeholder<I> ) {
235235
return HYDRA_EXTERNAL_NS::thrust::get<I>(this->fDecays);
236236
}
237237

238238
template<unsigned int I>
239239
typename HYDRA_EXTERNAL_NS::thrust::tuple_element<I, decays_type >::type const&
240-
GetDecay(placeholders::placeholder<I> ) const {
240+
GetDecays(placeholders::placeholder<I> ) const {
241241
return HYDRA_EXTERNAL_NS::thrust::get<I>(this->fDecays);
242242
}
243243

hydra/Vector4R.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class Vector4R
9797
const Vector4R& v);
9898
__hydra_host__ __hydra_device__ inline GReal_t mass2() const;
9999
__hydra_host__ __hydra_device__ inline GReal_t mass() const;
100+
__hydra_host__ __hydra_device__ inline GReal_t p2() const;
101+
__hydra_host__ __hydra_device__ inline GReal_t p() const;
102+
103+
100104
__hydra_host__ __hydra_device__ inline void applyRotateEuler(GReal_t alpha,
101105
GReal_t beta, GReal_t gamma);
102106
__hydra_host__ __hydra_device__ inline void applyBoostTo(const Vector4R& p4,

hydra/detail/Vector4R.inl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,32 @@ inline Vector3R Vector4R::vector3()
385385

386386
return temp;
387387
}
388+
__hydra_host__ __hydra_device__
389+
inline GReal_t Vector4R::p() const
390+
391+
// returns the 3 momentum mag.
392+
{
393+
GReal_t temp;
394+
395+
temp = v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
396+
397+
temp = sqrt(temp);
388398

399+
return temp;
400+
} //
401+
402+
__hydra_host__ __hydra_device__
403+
inline GReal_t Vector4R::p2() const
404+
405+
// returns the 3 momentum mag.
406+
{
407+
GReal_t temp;
408+
409+
temp = v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
410+
411+
412+
return temp;
413+
} //
389414

390415
__hydra_host__ __hydra_device__
391416
inline GReal_t Vector4R::d3mag() const
@@ -400,6 +425,8 @@ inline GReal_t Vector4R::d3mag() const
400425

401426
return temp;
402427
} // r3mag
428+
429+
403430
__hydra_host__ __hydra_device__
404431
inline GReal_t Vector4R::dot(const Vector4R& p2) const
405432
{

0 commit comments

Comments
 (0)