30 #ifndef EVALUATEARRAY_H_
31 #define EVALUATEARRAY_H_
50 template<
typename CUSTOMFUNC>
55 if (pset.size() > 10 || pset.size() < 2)
58 <<
"Can not Calculate(Eval) more than a nine-particle invariant mass."
63 GInt_t arrayWidth = varset.size();
64 GLong_t numberEvents = varset[0]->size();
69 dev_array.end(), arrayWidth);
78 thrust::make_zip_iterator(
79 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
81 thrust::make_zip_iterator(
82 thrust::make_tuple(it_array.end(), dev_v0->end(),
96 thrust::make_zip_iterator(
97 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
98 dev_v1->begin(), dev_v2->begin())),
99 thrust::make_zip_iterator(
100 thrust::make_tuple(it_array.end(), dev_v0->end(),
101 dev_v1->end(), dev_v2->end())),
106 if (pset.size() == 4)
115 thrust::make_zip_iterator(
116 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
117 dev_v1->begin(), dev_v2->begin(),
119 thrust::make_zip_iterator(
120 thrust::make_tuple(it_array.end(), dev_v0->end(),
121 dev_v1->end(), dev_v2->end(), dev_v3->end())),
126 if (pset.size() == 5)
136 thrust::make_zip_iterator(
137 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
138 dev_v1->begin(), dev_v2->begin(),
139 dev_v3->begin(), dev_v4->begin())),
140 thrust::make_zip_iterator(
141 thrust::make_tuple(it_array.end(), dev_v0->end(),
142 dev_v1->end(), dev_v2->end(), dev_v3->end(),
148 if (pset.size() == 6)
159 thrust::make_zip_iterator(
160 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
161 dev_v1->begin(), dev_v2->begin(),
162 dev_v3->begin(), dev_v4->begin(),
164 thrust::make_zip_iterator(
165 thrust::make_tuple(it_array.end(), dev_v0->end(),
166 dev_v1->end(), dev_v2->end(), dev_v3->end(),
167 dev_v4->end(), dev_v5->end())),
172 if (pset.size() == 7)
184 thrust::make_zip_iterator(
185 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
186 dev_v1->begin(), dev_v2->begin(),
187 dev_v3->begin(), dev_v4->begin(),
188 dev_v5->begin(), dev_v6->begin())),
189 thrust::make_zip_iterator(
190 thrust::make_tuple(it_array.end(), dev_v0->end(),
191 dev_v1->end(), dev_v2->end(), dev_v3->end(),
192 dev_v4->end(), dev_v5->end(), dev_v6->end())),
197 if (pset.size() == 8)
210 thrust::make_zip_iterator(
211 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
212 dev_v1->begin(), dev_v2->begin(),
213 dev_v3->begin(), dev_v4->begin(),
214 dev_v5->begin(), dev_v6->begin(),
216 thrust::make_zip_iterator(
217 thrust::make_tuple(it_array.end(), dev_v0->end(),
218 dev_v1->end(), dev_v2->end(), dev_v3->end(),
219 dev_v4->end(), dev_v5->end(), dev_v6->end(),
225 if (pset.size() == 9)
239 thrust::make_zip_iterator(
240 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
241 dev_v1->begin(), dev_v2->begin(),
242 dev_v3->begin(), dev_v4->begin(),
243 dev_v5->begin(), dev_v6->begin(),
244 dev_v7->begin(), dev_v8->begin())),
245 thrust::make_zip_iterator(
246 thrust::make_tuple(it_array.end(), dev_v0->end(),
247 dev_v1->end(), dev_v2->end(), dev_v3->end(),
248 dev_v4->end(), dev_v5->end(), dev_v6->end(),
249 dev_v7->end(), dev_v8->end())),
254 if (pset.size() == 10)
268 thrust::make_zip_iterator(
269 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
270 dev_v1->begin(), dev_v2->begin(),
271 dev_v3->begin(), dev_v4->begin(),
272 dev_v5->begin(), dev_v6->begin(),
273 dev_v7->begin(), dev_v8->begin())),
274 thrust::make_zip_iterator(
275 thrust::make_tuple(it_array.end(), dev_v0->end(),
276 dev_v1->end(), dev_v2->end(), dev_v3->end(),
277 dev_v4->end(), dev_v5->end(), dev_v6->end(),
278 dev_v7->end(), dev_v8->end())),
283 #if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_OMP || THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_TBB
285 #pragma omp parallel num_threads( arrayWidth )
288 , dev_array.end(), arrayWidth);
290 thrust::copy(it_array.begin(),it_array.end(),
291 varset[omp_get_thread_num()]->begin());
294 cudaStream_t s[arrayWidth];
296 for (
GInt_t d = 0; d < arrayWidth; d++)
298 cudaStreamCreate(&s[d]);
302 for (
GInt_t d = 0; d < arrayWidth; d++)
304 dev_array.end(), arrayWidth);
305 for (
GInt_t d = 0; d < arrayWidth; d++)
308 thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(),
312 cudaDeviceSynchronize();
313 for (
GInt_t d = 0; d < arrayWidth; d++)
314 cudaStreamDestroy(s[d]);
315 for (
GInt_t d = 0; d < arrayWidth; d++)
322 #if !(THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_OMP || THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_TBB)
331 template<
typename CUSTOMFUNC>
336 if (pset.size() > 10 || pset.size() < 2)
339 <<
"Can not Calculate(Eval) more than a nine-particle invariant mass."
344 GInt_t arrayWidth = varset.size();
345 GLong_t numberEvents = varset[0]->size();
350 dev_array.end(), arrayWidth);
352 if (pset.size() == 2)
355 mc_device_vector<Vector4R> *dev_v0 = pset[0];
356 mc_device_vector<Vector4R> *dev_v1 = pset[1];
359 thrust::make_zip_iterator(
360 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
362 thrust::make_zip_iterator(
363 thrust::make_tuple(it_array.end(), dev_v0->end(),
365 Calculate3<CUSTOMFUNC>(funcObj));
369 if (pset.size() == 3)
372 mc_device_vector<Vector4R> *dev_v0 = pset[0];
373 mc_device_vector<Vector4R> *dev_v1 = pset[1];
374 mc_device_vector<Vector4R> *dev_v2 = pset[2];
377 thrust::make_zip_iterator(
378 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
379 dev_v1->begin(), dev_v2->begin())),
380 thrust::make_zip_iterator(
381 thrust::make_tuple(it_array.end(), dev_v0->end(),
382 dev_v1->end(), dev_v2->end())),
383 Calculate3<CUSTOMFUNC>(funcObj));
387 if (pset.size() == 4)
390 mc_device_vector<Vector4R> *dev_v0 = pset[0];
391 mc_device_vector<Vector4R> *dev_v1 = pset[1];
392 mc_device_vector<Vector4R> *dev_v2 = pset[2];
393 mc_device_vector<Vector4R> *dev_v3 = pset[3];
396 thrust::make_zip_iterator(
397 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
398 dev_v1->begin(), dev_v2->begin(),
400 thrust::make_zip_iterator(
401 thrust::make_tuple(it_array.end(), dev_v0->end(),
402 dev_v1->end(), dev_v2->end(), dev_v3->end())),
403 Calculate3<CUSTOMFUNC>(funcObj));
407 if (pset.size() == 5)
410 mc_device_vector<Vector4R> *dev_v0 = pset[0];
411 mc_device_vector<Vector4R> *dev_v1 = pset[1];
412 mc_device_vector<Vector4R> *dev_v2 = pset[2];
413 mc_device_vector<Vector4R> *dev_v3 = pset[3];
414 mc_device_vector<Vector4R> *dev_v4 = pset[4];
417 thrust::make_zip_iterator(
418 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
419 dev_v1->begin(), dev_v2->begin(),
420 dev_v3->begin(), dev_v4->begin())),
421 thrust::make_zip_iterator(
422 thrust::make_tuple(it_array.end(), dev_v0->end(),
423 dev_v1->end(), dev_v2->end(), dev_v3->end(),
425 Calculate3<CUSTOMFUNC>(funcObj));
429 if (pset.size() == 6)
432 mc_device_vector<Vector4R> *dev_v0 = pset[0];
433 mc_device_vector<Vector4R> *dev_v1 = pset[1];
434 mc_device_vector<Vector4R> *dev_v2 = pset[2];
435 mc_device_vector<Vector4R> *dev_v3 = pset[3];
436 mc_device_vector<Vector4R> *dev_v4 = pset[4];
437 mc_device_vector<Vector4R> *dev_v5 = pset[5];
440 thrust::make_zip_iterator(
441 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
442 dev_v1->begin(), dev_v2->begin(),
443 dev_v3->begin(), dev_v4->begin(),
445 thrust::make_zip_iterator(
446 thrust::make_tuple(it_array.end(), dev_v0->end(),
447 dev_v1->end(), dev_v2->end(), dev_v3->end(),
448 dev_v4->end(), dev_v5->end())),
449 Calculate3<CUSTOMFUNC>(funcObj));
453 if (pset.size() == 7)
456 mc_device_vector<Vector4R> *dev_v0 = pset[0];
457 mc_device_vector<Vector4R> *dev_v1 = pset[1];
458 mc_device_vector<Vector4R> *dev_v2 = pset[2];
459 mc_device_vector<Vector4R> *dev_v3 = pset[3];
460 mc_device_vector<Vector4R> *dev_v4 = pset[4];
461 mc_device_vector<Vector4R> *dev_v5 = pset[5];
462 mc_device_vector<Vector4R> *dev_v6 = pset[6];
465 thrust::make_zip_iterator(
466 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
467 dev_v1->begin(), dev_v2->begin(),
468 dev_v3->begin(), dev_v4->begin(),
469 dev_v5->begin(), dev_v6->begin())),
470 thrust::make_zip_iterator(
471 thrust::make_tuple(it_array.end(), dev_v0->end(),
472 dev_v1->end(), dev_v2->end(), dev_v3->end(),
473 dev_v4->end(), dev_v5->end(), dev_v6->end())),
474 Calculate3<CUSTOMFUNC>(funcObj));
478 if (pset.size() == 8)
481 mc_device_vector<Vector4R> *dev_v0 = pset[0];
482 mc_device_vector<Vector4R> *dev_v1 = pset[1];
483 mc_device_vector<Vector4R> *dev_v2 = pset[2];
484 mc_device_vector<Vector4R> *dev_v3 = pset[3];
485 mc_device_vector<Vector4R> *dev_v4 = pset[4];
486 mc_device_vector<Vector4R> *dev_v5 = pset[5];
487 mc_device_vector<Vector4R> *dev_v6 = pset[6];
488 mc_device_vector<Vector4R> *dev_v7 = pset[7];
491 thrust::make_zip_iterator(
492 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
493 dev_v1->begin(), dev_v2->begin(),
494 dev_v3->begin(), dev_v4->begin(),
495 dev_v5->begin(), dev_v6->begin(),
497 thrust::make_zip_iterator(
498 thrust::make_tuple(it_array.end(), dev_v0->end(),
499 dev_v1->end(), dev_v2->end(), dev_v3->end(),
500 dev_v4->end(), dev_v5->end(), dev_v6->end(),
502 Calculate3<CUSTOMFUNC>(funcObj));
506 if (pset.size() == 9)
509 mc_device_vector<Vector4R> *dev_v0 = pset[0];
510 mc_device_vector<Vector4R> *dev_v1 = pset[1];
511 mc_device_vector<Vector4R> *dev_v2 = pset[2];
512 mc_device_vector<Vector4R> *dev_v3 = pset[3];
513 mc_device_vector<Vector4R> *dev_v4 = pset[4];
514 mc_device_vector<Vector4R> *dev_v5 = pset[5];
515 mc_device_vector<Vector4R> *dev_v6 = pset[6];
516 mc_device_vector<Vector4R> *dev_v7 = pset[7];
517 mc_device_vector<Vector4R> *dev_v8 = pset[8];
520 thrust::make_zip_iterator(
521 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
522 dev_v1->begin(), dev_v2->begin(),
523 dev_v3->begin(), dev_v4->begin(),
524 dev_v5->begin(), dev_v6->begin(),
525 dev_v7->begin(), dev_v8->begin())),
526 thrust::make_zip_iterator(
527 thrust::make_tuple(it_array.end(), dev_v0->end(),
528 dev_v1->end(), dev_v2->end(), dev_v3->end(),
529 dev_v4->end(), dev_v5->end(), dev_v6->end(),
530 dev_v7->end(), dev_v8->end())),
531 Calculate3<CUSTOMFUNC>(funcObj));
535 if (pset.size() == 10)
538 mc_device_vector<Vector4R> *dev_v0 = pset[0];
539 mc_device_vector<Vector4R> *dev_v1 = pset[1];
540 mc_device_vector<Vector4R> *dev_v2 = pset[2];
541 mc_device_vector<Vector4R> *dev_v3 = pset[3];
542 mc_device_vector<Vector4R> *dev_v4 = pset[4];
543 mc_device_vector<Vector4R> *dev_v5 = pset[5];
544 mc_device_vector<Vector4R> *dev_v6 = pset[6];
545 mc_device_vector<Vector4R> *dev_v7 = pset[7];
546 mc_device_vector<Vector4R> *dev_v8 = pset[8];
549 thrust::make_zip_iterator(
550 thrust::make_tuple(it_array.begin(), dev_v0->begin(),
551 dev_v1->begin(), dev_v2->begin(),
552 dev_v3->begin(), dev_v4->begin(),
553 dev_v5->begin(), dev_v6->begin(),
554 dev_v7->begin(), dev_v8->begin())),
555 thrust::make_zip_iterator(
556 thrust::make_tuple(it_array.end(), dev_v0->end(),
557 dev_v1->end(), dev_v2->end(), dev_v3->end(),
558 dev_v4->end(), dev_v5->end(), dev_v6->end(),
559 dev_v7->end(), dev_v8->end())),
560 Calculate3<CUSTOMFUNC>(funcObj));
564 #if THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_OMP || THRUST_DEVICE_SYSTEM==THRUST_DEVICE_BACKEND_TBB
566 #pragma omp parallel num_threads( arrayWidth )
569 , dev_array.end(), arrayWidth);
571 thrust::copy(it_array.begin(),it_array.end(),
572 varset[omp_get_thread_num()]->begin());
575 cudaStream_t s[arrayWidth];
577 for (
GInt_t d = 0; d < arrayWidth; d++)
579 cudaStreamCreate(&s[d]);
583 for (
GInt_t d = 0; d < arrayWidth; d++)
585 dev_array.end(), arrayWidth);
586 for (
GInt_t d = 0; d < arrayWidth; d++)
589 thrust::copy(thrust::cuda::par.on(s[d]), it[d]->begin(), it[d]->end(),
593 cudaDeviceSynchronize();
594 for (
GInt_t d = 0; d < arrayWidth; d++)
595 cudaStreamDestroy(s[d]);
596 for (
GInt_t d = 0; d < arrayWidth; d++)
long GLong_t
Signed long integer 4 bytes (long)
void EvaluateArray(const CUSTOMFUNC funcObj, ParticlesSet_d &pset, VariableSet_h &varset)
Template functor for calculate an array of variables over a given set of particles.
Strided range iterator original code: https://github.com/thrust/thrust/blob/master/examples/strided_r...
Typedef for useful container classes used in MCBooster.
vector< RealVector_d * > VariableSet_d
Typedef for a STL vector of pointers to device Particles_d vectors.
vector< Particles_d * > ParticlesSet_d
Typedef for a Vector4R device vector.
vector< RealVector_h * > VariableSet_h
Typedef for a STL vector of pointers to host Particles_h vectors .
int GInt_t
Signed integer 4 bytes (int)
thrust::host_vector< T > mc_device_vector
Generic template typedef for thrust::host_vector.
mc_device_vector< GReal_t > RealVector_d
Typedef for a GBool_t device vector.