This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMiniDoublet.h
1110 lines (1007 loc) · 53.4 KB
/
MiniDoublet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef MiniDoublet_cuh
#define MiniDoublet_cuh
#include "Constants.h"
#include "EndcapGeometry.h"
#include "Module.h"
#include "Hit.h"
namespace SDL {
struct miniDoublets {
unsigned int* nMemoryLocations;
unsigned int* anchorHitIndices;
unsigned int* outerHitIndices;
uint16_t* moduleIndices;
int* nMDs; //counter per module
int* totOccupancyMDs; //counter per module
float* dphichanges;
float* dzs; //will store drt if the module is endcap
float* dphis;
float* shiftedXs;
float* shiftedYs;
float* shiftedZs;
float* noShiftedDzs; //if shifted module
float* noShiftedDphis; //if shifted module
float* noShiftedDphiChanges; //if shifted module
float* anchorX;
float* anchorY;
float* anchorZ;
float* anchorRt;
float* anchorPhi;
float* anchorEta;
float* anchorHighEdgeX;
float* anchorHighEdgeY;
float* anchorLowEdgeX;
float* anchorLowEdgeY;
float* anchorLowEdgePhi;
float* anchorHighEdgePhi;
float* outerX;
float* outerY;
float* outerZ;
float* outerRt;
float* outerPhi;
float* outerEta;
float* outerHighEdgeX;
float* outerHighEdgeY;
float* outerLowEdgeX;
float* outerLowEdgeY;
template <typename TBuf>
void setData(TBuf& mdsbuf) {
nMemoryLocations = alpaka::getPtrNative(mdsbuf.nMemoryLocations_buf);
anchorHitIndices = alpaka::getPtrNative(mdsbuf.anchorHitIndices_buf);
outerHitIndices = alpaka::getPtrNative(mdsbuf.outerHitIndices_buf);
moduleIndices = alpaka::getPtrNative(mdsbuf.moduleIndices_buf);
nMDs = alpaka::getPtrNative(mdsbuf.nMDs_buf);
totOccupancyMDs = alpaka::getPtrNative(mdsbuf.totOccupancyMDs_buf);
dphichanges = alpaka::getPtrNative(mdsbuf.dphichanges_buf);
dzs = alpaka::getPtrNative(mdsbuf.dzs_buf);
dphis = alpaka::getPtrNative(mdsbuf.dphis_buf);
shiftedXs = alpaka::getPtrNative(mdsbuf.shiftedXs_buf);
shiftedYs = alpaka::getPtrNative(mdsbuf.shiftedYs_buf);
shiftedZs = alpaka::getPtrNative(mdsbuf.shiftedZs_buf);
noShiftedDzs = alpaka::getPtrNative(mdsbuf.noShiftedDzs_buf);
noShiftedDphis = alpaka::getPtrNative(mdsbuf.noShiftedDphis_buf);
noShiftedDphiChanges = alpaka::getPtrNative(mdsbuf.noShiftedDphiChanges_buf);
anchorX = alpaka::getPtrNative(mdsbuf.anchorX_buf);
anchorY = alpaka::getPtrNative(mdsbuf.anchorY_buf);
anchorZ = alpaka::getPtrNative(mdsbuf.anchorZ_buf);
anchorRt = alpaka::getPtrNative(mdsbuf.anchorRt_buf);
anchorPhi = alpaka::getPtrNative(mdsbuf.anchorPhi_buf);
anchorEta = alpaka::getPtrNative(mdsbuf.anchorEta_buf);
anchorHighEdgeX = alpaka::getPtrNative(mdsbuf.anchorHighEdgeX_buf);
anchorHighEdgeY = alpaka::getPtrNative(mdsbuf.anchorHighEdgeY_buf);
anchorLowEdgeX = alpaka::getPtrNative(mdsbuf.anchorLowEdgeX_buf);
anchorLowEdgeY = alpaka::getPtrNative(mdsbuf.anchorLowEdgeY_buf);
outerX = alpaka::getPtrNative(mdsbuf.outerX_buf);
outerY = alpaka::getPtrNative(mdsbuf.outerY_buf);
outerZ = alpaka::getPtrNative(mdsbuf.outerZ_buf);
outerRt = alpaka::getPtrNative(mdsbuf.outerRt_buf);
outerPhi = alpaka::getPtrNative(mdsbuf.outerPhi_buf);
outerEta = alpaka::getPtrNative(mdsbuf.outerEta_buf);
outerHighEdgeX = alpaka::getPtrNative(mdsbuf.outerHighEdgeX_buf);
outerHighEdgeY = alpaka::getPtrNative(mdsbuf.outerHighEdgeY_buf);
outerLowEdgeX = alpaka::getPtrNative(mdsbuf.outerLowEdgeX_buf);
outerLowEdgeY = alpaka::getPtrNative(mdsbuf.outerLowEdgeY_buf);
anchorLowEdgePhi = alpaka::getPtrNative(mdsbuf.anchorLowEdgePhi_buf);
anchorHighEdgePhi = alpaka::getPtrNative(mdsbuf.anchorHighEdgePhi_buf);
}
};
template <typename TAcc>
struct miniDoubletsBuffer : miniDoublets {
Buf<TAcc, unsigned int> nMemoryLocations_buf;
Buf<TAcc, unsigned int> anchorHitIndices_buf;
Buf<TAcc, unsigned int> outerHitIndices_buf;
Buf<TAcc, uint16_t> moduleIndices_buf;
Buf<TAcc, int> nMDs_buf;
Buf<TAcc, int> totOccupancyMDs_buf;
Buf<TAcc, float> dphichanges_buf;
Buf<TAcc, float> dzs_buf;
Buf<TAcc, float> dphis_buf;
Buf<TAcc, float> shiftedXs_buf;
Buf<TAcc, float> shiftedYs_buf;
Buf<TAcc, float> shiftedZs_buf;
Buf<TAcc, float> noShiftedDzs_buf;
Buf<TAcc, float> noShiftedDphis_buf;
Buf<TAcc, float> noShiftedDphiChanges_buf;
Buf<TAcc, float> anchorX_buf;
Buf<TAcc, float> anchorY_buf;
Buf<TAcc, float> anchorZ_buf;
Buf<TAcc, float> anchorRt_buf;
Buf<TAcc, float> anchorPhi_buf;
Buf<TAcc, float> anchorEta_buf;
Buf<TAcc, float> anchorHighEdgeX_buf;
Buf<TAcc, float> anchorHighEdgeY_buf;
Buf<TAcc, float> anchorLowEdgeX_buf;
Buf<TAcc, float> anchorLowEdgeY_buf;
Buf<TAcc, float> anchorLowEdgePhi_buf;
Buf<TAcc, float> anchorHighEdgePhi_buf;
Buf<TAcc, float> outerX_buf;
Buf<TAcc, float> outerY_buf;
Buf<TAcc, float> outerZ_buf;
Buf<TAcc, float> outerRt_buf;
Buf<TAcc, float> outerPhi_buf;
Buf<TAcc, float> outerEta_buf;
Buf<TAcc, float> outerHighEdgeX_buf;
Buf<TAcc, float> outerHighEdgeY_buf;
Buf<TAcc, float> outerLowEdgeX_buf;
Buf<TAcc, float> outerLowEdgeY_buf;
template <typename TQueue, typename TDevAcc>
miniDoubletsBuffer(unsigned int nMemoryLoc, uint16_t nLowerModules, TDevAcc const& devAccIn, TQueue& queue)
: nMemoryLocations_buf(allocBufWrapper<unsigned int>(devAccIn, 1, queue)),
anchorHitIndices_buf(allocBufWrapper<unsigned int>(devAccIn, nMemoryLoc, queue)),
outerHitIndices_buf(allocBufWrapper<unsigned int>(devAccIn, nMemoryLoc, queue)),
moduleIndices_buf(allocBufWrapper<uint16_t>(devAccIn, nMemoryLoc, queue)),
nMDs_buf(allocBufWrapper<int>(devAccIn, nLowerModules + 1, queue)),
totOccupancyMDs_buf(allocBufWrapper<int>(devAccIn, nLowerModules + 1, queue)),
dphichanges_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
dzs_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
dphis_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
shiftedXs_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
shiftedYs_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
shiftedZs_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
noShiftedDzs_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
noShiftedDphis_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
noShiftedDphiChanges_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorZ_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorRt_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorPhi_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorEta_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorHighEdgeX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorHighEdgeY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorLowEdgeX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorLowEdgeY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerZ_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerRt_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerPhi_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerEta_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerHighEdgeX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerHighEdgeY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerLowEdgeX_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
outerLowEdgeY_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorLowEdgePhi_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)),
anchorHighEdgePhi_buf(allocBufWrapper<float>(devAccIn, nMemoryLoc, queue)) {
alpaka::memset(queue, nMDs_buf, 0, nLowerModules + 1);
alpaka::memset(queue, totOccupancyMDs_buf, 0, nLowerModules + 1);
alpaka::wait(queue);
}
};
template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE void addMDToMemory(TAcc const& acc,
struct SDL::miniDoublets& mdsInGPU,
struct SDL::hits& hitsInGPU,
struct SDL::modules& modulesInGPU,
unsigned int lowerHitIdx,
unsigned int upperHitIdx,
uint16_t& lowerModuleIdx,
float dz,
float dPhi,
float dPhiChange,
float shiftedX,
float shiftedY,
float shiftedZ,
float noShiftedDz,
float noShiftedDphi,
float noShiftedDPhiChange,
unsigned int idx) {
//the index into which this MD needs to be written will be computed in the kernel
//nMDs variable will be incremented in the kernel, no need to worry about that here
mdsInGPU.moduleIndices[idx] = lowerModuleIdx;
unsigned int anchorHitIndex, outerHitIndex;
if (modulesInGPU.moduleType[lowerModuleIdx] == PS and modulesInGPU.moduleLayerType[lowerModuleIdx] == Strip) {
mdsInGPU.anchorHitIndices[idx] = upperHitIdx;
mdsInGPU.outerHitIndices[idx] = lowerHitIdx;
anchorHitIndex = upperHitIdx;
outerHitIndex = lowerHitIdx;
} else {
mdsInGPU.anchorHitIndices[idx] = lowerHitIdx;
mdsInGPU.outerHitIndices[idx] = upperHitIdx;
anchorHitIndex = lowerHitIdx;
outerHitIndex = upperHitIdx;
}
mdsInGPU.dphichanges[idx] = dPhiChange;
mdsInGPU.dphis[idx] = dPhi;
mdsInGPU.dzs[idx] = dz;
mdsInGPU.shiftedXs[idx] = shiftedX;
mdsInGPU.shiftedYs[idx] = shiftedY;
mdsInGPU.shiftedZs[idx] = shiftedZ;
mdsInGPU.noShiftedDzs[idx] = noShiftedDz;
mdsInGPU.noShiftedDphis[idx] = noShiftedDphi;
mdsInGPU.noShiftedDphiChanges[idx] = noShiftedDPhiChange;
mdsInGPU.anchorX[idx] = hitsInGPU.xs[anchorHitIndex];
mdsInGPU.anchorY[idx] = hitsInGPU.ys[anchorHitIndex];
mdsInGPU.anchorZ[idx] = hitsInGPU.zs[anchorHitIndex];
mdsInGPU.anchorRt[idx] = hitsInGPU.rts[anchorHitIndex];
mdsInGPU.anchorPhi[idx] = hitsInGPU.phis[anchorHitIndex];
mdsInGPU.anchorEta[idx] = hitsInGPU.etas[anchorHitIndex];
mdsInGPU.anchorHighEdgeX[idx] = hitsInGPU.highEdgeXs[anchorHitIndex];
mdsInGPU.anchorHighEdgeY[idx] = hitsInGPU.highEdgeYs[anchorHitIndex];
mdsInGPU.anchorLowEdgeX[idx] = hitsInGPU.lowEdgeXs[anchorHitIndex];
mdsInGPU.anchorLowEdgeY[idx] = hitsInGPU.lowEdgeYs[anchorHitIndex];
mdsInGPU.anchorHighEdgePhi[idx] =
alpaka::math::atan2(acc, mdsInGPU.anchorHighEdgeY[idx], mdsInGPU.anchorHighEdgeX[idx]);
mdsInGPU.anchorLowEdgePhi[idx] =
alpaka::math::atan2(acc, mdsInGPU.anchorLowEdgeY[idx], mdsInGPU.anchorLowEdgeX[idx]);
mdsInGPU.outerX[idx] = hitsInGPU.xs[outerHitIndex];
mdsInGPU.outerY[idx] = hitsInGPU.ys[outerHitIndex];
mdsInGPU.outerZ[idx] = hitsInGPU.zs[outerHitIndex];
mdsInGPU.outerRt[idx] = hitsInGPU.rts[outerHitIndex];
mdsInGPU.outerPhi[idx] = hitsInGPU.phis[outerHitIndex];
mdsInGPU.outerEta[idx] = hitsInGPU.etas[outerHitIndex];
mdsInGPU.outerHighEdgeX[idx] = hitsInGPU.highEdgeXs[outerHitIndex];
mdsInGPU.outerHighEdgeY[idx] = hitsInGPU.highEdgeYs[outerHitIndex];
mdsInGPU.outerLowEdgeX[idx] = hitsInGPU.lowEdgeXs[outerHitIndex];
mdsInGPU.outerLowEdgeY[idx] = hitsInGPU.lowEdgeYs[outerHitIndex];
};
ALPAKA_FN_ACC ALPAKA_FN_INLINE float isTighterTiltedModules(struct SDL::modules& modulesInGPU,
uint16_t& moduleIndex) {
// The "tighter" tilted modules are the subset of tilted modules that have smaller spacing
// This is the same as what was previously considered as"isNormalTiltedModules"
// See Figure 9.1 of https://cds.cern.ch/record/2272264/files/CMS-TDR-014.pdf
short subdet = modulesInGPU.subdets[moduleIndex];
short layer = modulesInGPU.layers[moduleIndex];
short side = modulesInGPU.sides[moduleIndex];
short rod = modulesInGPU.rods[moduleIndex];
if ((subdet == Barrel and side != Center and layer == 3) or
(subdet == Barrel and side == NegZ and layer == 2 and rod > 5) or
(subdet == Barrel and side == PosZ and layer == 2 and rod < 8) or
(subdet == Barrel and side == NegZ and layer == 1 and rod > 9) or
(subdet == Barrel and side == PosZ and layer == 1 and rod < 4))
return true;
else
return false;
};
ALPAKA_FN_ACC ALPAKA_FN_INLINE float moduleGapSize(struct SDL::modules& modulesInGPU, uint16_t& moduleIndex) {
float miniDeltaTilted[3] = {0.26f, 0.26f, 0.26f};
float miniDeltaFlat[6] = {0.26f, 0.16f, 0.16f, 0.18f, 0.18f, 0.18f};
float miniDeltaLooseTilted[3] = {0.4f, 0.4f, 0.4f};
float miniDeltaEndcap[5][15];
for (size_t i = 0; i < 5; i++) {
for (size_t j = 0; j < 15; j++) {
if (i == 0 || i == 1) {
if (j < 10) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
} else if (i == 2 || i == 3) {
if (j < 8) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
} else {
if (j < 9) {
miniDeltaEndcap[i][j] = 0.4f;
} else {
miniDeltaEndcap[i][j] = 0.18f;
}
}
}
}
unsigned int iL = modulesInGPU.layers[moduleIndex] - 1;
unsigned int iR = modulesInGPU.rings[moduleIndex] - 1;
short subdet = modulesInGPU.subdets[moduleIndex];
short side = modulesInGPU.sides[moduleIndex];
float moduleSeparation = 0;
if (subdet == Barrel and side == Center) {
moduleSeparation = miniDeltaFlat[iL];
} else if (isTighterTiltedModules(modulesInGPU, moduleIndex)) {
moduleSeparation = miniDeltaTilted[iL];
} else if (subdet == Endcap) {
moduleSeparation = miniDeltaEndcap[iL][iR];
} else //Loose tilted modules
{
moduleSeparation = miniDeltaLooseTilted[iL];
}
return moduleSeparation;
};
template <typename TAcc>
ALPAKA_FN_ACC ALPAKA_FN_INLINE float dPhiThreshold(TAcc const& acc,
float rt,
struct SDL::modules& modulesInGPU,
uint16_t& moduleIndex,
float dPhi = 0,
float dz = 0) {
// =================================================================
// Various constants
// =================================================================
//mean of the horizontal layer position in y; treat this as R below
// =================================================================
// Computing some components that make up the cut threshold
// =================================================================
unsigned int iL = modulesInGPU.layers[moduleIndex] - 1;
const float miniSlope = alpaka::math::asin(acc, alpaka::math::min(acc, rt * k2Rinv1GeVf / ptCut, sinAlphaMax));
const float rLayNominal =
((modulesInGPU.subdets[moduleIndex] == Barrel) ? miniRminMeanBarrel[iL] : miniRminMeanEndcap[iL]);
const float miniPVoff = 0.1f / rLayNominal;
const float miniMuls = ((modulesInGPU.subdets[moduleIndex] == Barrel) ? miniMulsPtScaleBarrel[iL] * 3.f / ptCut
: miniMulsPtScaleEndcap[iL] * 3.f / ptCut);
const bool isTilted = modulesInGPU.subdets[moduleIndex] == Barrel and modulesInGPU.sides[moduleIndex] != Center;
//the lower module is sent in irrespective of its layer type. We need to fetch the drdz properly
float drdz;
if (isTilted) {
if (modulesInGPU.moduleType[moduleIndex] == PS and modulesInGPU.moduleLayerType[moduleIndex] == Strip) {
drdz = modulesInGPU.drdzs[moduleIndex];
} else {
drdz = modulesInGPU.drdzs[modulesInGPU.partnerModuleIndices[moduleIndex]];
}
} else {
drdz = 0;
}
const float miniTilt = ((isTilted) ? 0.5f * pixelPSZpitch * drdz / alpaka::math::sqrt(acc, 1.f + drdz * drdz) /
moduleGapSize(modulesInGPU, moduleIndex)
: 0);
// Compute luminous region requirement for endcap
const float miniLum = alpaka::math::abs(acc, dPhi * deltaZLum / dz); // Balaji's new error
// =================================================================
// Return the threshold value
// =================================================================
// Following condition is met if the module is central and flatly lying
if (modulesInGPU.subdets[moduleIndex] == Barrel and modulesInGPU.sides[moduleIndex] == Center) {
return miniSlope + alpaka::math::sqrt(acc, miniMuls * miniMuls + miniPVoff * miniPVoff);
}
// Following condition is met if the module is central and tilted
else if (modulesInGPU.subdets[moduleIndex] == Barrel and
modulesInGPU.sides[moduleIndex] != Center) //all types of tilted modules
{
return miniSlope +
alpaka::math::sqrt(
acc, miniMuls * miniMuls + miniPVoff * miniPVoff + miniTilt * miniTilt * miniSlope * miniSlope);
}
// If not barrel, it is Endcap
else {
return miniSlope + alpaka::math::sqrt(acc, miniMuls * miniMuls + miniPVoff * miniPVoff + miniLum * miniLum);
}
};
template <typename TAcc>
ALPAKA_FN_INLINE ALPAKA_FN_ACC void shiftStripHits(TAcc const& acc,
struct SDL::modules& modulesInGPU,
uint16_t& lowerModuleIndex,
uint16_t& upperModuleIndex,
unsigned int lowerHitIndex,
unsigned int upperHitIndex,
float* shiftedCoords,
float xLower,
float yLower,
float zLower,
float rtLower,
float xUpper,
float yUpper,
float zUpper,
float rtUpper) {
// This is the strip shift scheme that is explained in http://uaf-10.t2.ucsd.edu/~phchang/talks/PhilipChang20190607_SDL_Update.pdf (see backup slides)
// The main feature of this shifting is that the strip hits are shifted to be "aligned" in the line of sight from interaction point to the the pixel hit.
// (since pixel hit is well defined in 3-d)
// The strip hit is shifted along the strip detector to be placed in a guessed position where we think they would have actually crossed
// The size of the radial direction shift due to module separation gap is computed in "radial" size, while the shift is done along the actual strip orientation
// This means that there may be very very subtle edge effects coming from whether the strip hit is center of the module or the at the edge of the module
// But this should be relatively minor effect
// dependent variables for this if statement
// lowerModule
// lowerHit
// upperHit
// SDL::endcapGeometry
// SDL::tiltedGeometry
// Some variables relevant to the function
float xp; // pixel x (pixel hit x)
float yp; // pixel y (pixel hit y)
float zp; // pixel y (pixel hit y)
float rtp; // pixel y (pixel hit y)
float xa; // "anchor" x (the anchor position on the strip module plane from pixel hit)
float ya; // "anchor" y (the anchor position on the strip module plane from pixel hit)
float xo; // old x (before the strip hit is moved up or down)
float yo; // old y (before the strip hit is moved up or down)
float xn; // new x (after the strip hit is moved up or down)
float yn; // new y (after the strip hit is moved up or down)
float abszn; // new z in absolute value
float zn; // new z with the sign (+/-) accounted
float angleA; // in r-z plane the theta of the pixel hit in polar coordinate is the angleA
float angleB; // this is the angle of tilted module in r-z plane ("drdz"), for endcap this is 90 degrees
bool isEndcap; // If endcap, drdz = infinity
float moduleSeparation;
float drprime; // The radial shift size in x-y plane projection
float drprime_x; // x-component of drprime
float drprime_y; // y-component of drprime
float& slope =
modulesInGPU.slopes[lowerModuleIndex]; // The slope of the possible strip hits for a given module in x-y plane
float absArctanSlope;
float angleM; // the angle M is the angle of rotation of the module in x-y plane if the possible strip hits are along the x-axis, then angleM = 0, and if the possible strip hits are along y-axis angleM = 90 degrees
float absdzprime; // The distance between the two points after shifting
float& drdz_ = modulesInGPU.drdzs[lowerModuleIndex];
// Assign hit pointers based on their hit type
if (modulesInGPU.moduleType[lowerModuleIndex] == PS) {
// TODO: This is somewhat of an mystery.... somewhat confused why this is the case
if (modulesInGPU.subdets[lowerModuleIndex] == Barrel ? modulesInGPU.moduleLayerType[lowerModuleIndex] != Pixel
: modulesInGPU.moduleLayerType[lowerModuleIndex] == Pixel) {
xo = xUpper;
yo = yUpper;
xp = xLower;
yp = yLower;
zp = zLower;
rtp = rtLower;
} else {
xo = xLower;
yo = yLower;
xp = xUpper;
yp = yUpper;
zp = zUpper;
rtp = rtUpper;
}
} else {
xo = xUpper;
yo = yUpper;
xp = xLower;
yp = yLower;
zp = zLower;
rtp = rtLower;
}
// If it is endcap some of the math gets simplified (and also computers don't like infinities)
isEndcap = modulesInGPU.subdets[lowerModuleIndex] == Endcap;
// NOTE: TODO: Keep in mind that the sin(atan) function can be simplified to something like x / sqrt(1 + x^2) and similar for cos
// I am not sure how slow sin, atan, cos, functions are in c++. If x / sqrt(1 + x^2) are faster change this later to reduce arithmetic computation time
angleA = alpaka::math::abs(acc, alpaka::math::atan(acc, rtp / zp));
angleB =
((isEndcap)
? float(M_PI) / 2.f
: alpaka::math::atan(
acc,
drdz_)); // The tilt module on the positive z-axis has negative drdz slope in r-z plane and vice versa
moduleSeparation = moduleGapSize(modulesInGPU, lowerModuleIndex);
// Sign flips if the pixel is later layer
if (modulesInGPU.moduleType[lowerModuleIndex] == PS and modulesInGPU.moduleLayerType[lowerModuleIndex] != Pixel) {
moduleSeparation *= -1;
}
drprime = (moduleSeparation / alpaka::math::sin(acc, angleA + angleB)) * alpaka::math::sin(acc, angleA);
// Compute arctan of the slope and take care of the slope = infinity case
absArctanSlope = ((slope != SDL::SDL_INF) ? fabs(alpaka::math::atan(acc, slope)) : float(M_PI) / 2.f);
// Depending on which quadrant the pixel hit lies, we define the angleM by shifting them slightly differently
if (xp > 0 and yp > 0) {
angleM = absArctanSlope;
} else if (xp > 0 and yp < 0) {
angleM = float(M_PI) - absArctanSlope;
} else if (xp < 0 and yp < 0) {
angleM = float(M_PI) + absArctanSlope;
} else // if (xp < 0 and yp > 0)
{
angleM = 2.f * float(M_PI) - absArctanSlope;
}
// Then since the angleM sign is taken care of properly
drprime_x = drprime * alpaka::math::sin(acc, angleM);
drprime_y = drprime * alpaka::math::cos(acc, angleM);
// The new anchor position is
xa = xp + drprime_x;
ya = yp + drprime_y;
// Compute the new strip hit position (if the slope value is in special condition take care of the exceptions)
if (slope ==
SDL::SDL_INF) // Designated for tilted module when the slope is exactly infinity (module lying along y-axis)
{
xn = xa; // New x point is simply where the anchor is
yn = yo; // No shift in y
} else if (slope == 0) {
xn = xo; // New x point is simply where the anchor is
yn = ya; // No shift in y
} else {
xn = (slope * xa + (1.f / slope) * xo - ya + yo) / (slope + (1.f / slope)); // new xn
yn = (xn - xa) * slope + ya; // new yn
}
// Computing new Z position
absdzprime = alpaka::math::abs(
acc,
moduleSeparation / alpaka::math::sin(acc, angleA + angleB) *
alpaka::math::cos(
acc,
angleA)); // module separation sign is for shifting in radial direction for z-axis direction take care of the sign later
// Depending on which one as closer to the interactin point compute the new z wrt to the pixel properly
if (modulesInGPU.moduleLayerType[lowerModuleIndex] == Pixel) {
abszn = alpaka::math::abs(acc, zp) + absdzprime;
} else {
abszn = alpaka::math::abs(acc, zp) - absdzprime;
}
zn = abszn * ((zp > 0) ? 1 : -1); // Apply the sign of the zn
shiftedCoords[0] = xn;
shiftedCoords[1] = yn;
shiftedCoords[2] = zn;
};
template <typename TAcc>
ALPAKA_FN_ACC bool runMiniDoubletDefaultAlgo(TAcc const& acc,
struct SDL::modules& modulesInGPU,
uint16_t& lowerModuleIndex,
uint16_t& upperModuleIndex,
unsigned int lowerHitIndex,
unsigned int upperHitIndex,
float& dz,
float& dPhi,
float& dPhiChange,
float& shiftedX,
float& shiftedY,
float& shiftedZ,
float& noShiftedDz,
float& noShiftedDphi,
float& noShiftedDphiChange,
float xLower,
float yLower,
float zLower,
float rtLower,
float xUpper,
float yUpper,
float zUpper,
float rtUpper) {
if (modulesInGPU.subdets[lowerModuleIndex] == SDL::Barrel) {
return runMiniDoubletDefaultAlgoBarrel(acc,
modulesInGPU,
lowerModuleIndex,
upperModuleIndex,
lowerHitIndex,
upperHitIndex,
dz,
dPhi,
dPhiChange,
shiftedX,
shiftedY,
shiftedZ,
noShiftedDz,
noShiftedDphi,
noShiftedDphiChange,
xLower,
yLower,
zLower,
rtLower,
xUpper,
yUpper,
zUpper,
rtUpper);
} else {
return runMiniDoubletDefaultAlgoEndcap(acc,
modulesInGPU,
lowerModuleIndex,
upperModuleIndex,
lowerHitIndex,
upperHitIndex,
dz,
dPhi,
dPhiChange,
shiftedX,
shiftedY,
shiftedZ,
noShiftedDz,
noShiftedDphi,
noShiftedDphiChange,
xLower,
yLower,
zLower,
rtLower,
xUpper,
yUpper,
zUpper,
rtUpper);
}
};
template <typename TAcc>
ALPAKA_FN_ACC bool runMiniDoubletDefaultAlgoBarrel(TAcc const& acc,
struct SDL::modules& modulesInGPU,
uint16_t& lowerModuleIndex,
uint16_t& upperModuleIndex,
unsigned int lowerHitIndex,
unsigned int upperHitIndex,
float& dz,
float& dPhi,
float& dPhiChange,
float& shiftedX,
float& shiftedY,
float& shiftedZ,
float& noshiftedDz,
float& noShiftedDphi,
float& noShiftedDphiChange,
float xLower,
float yLower,
float zLower,
float rtLower,
float xUpper,
float yUpper,
float zUpper,
float rtUpper) {
bool pass = true;
dz = zLower - zUpper;
const float dzCut = modulesInGPU.moduleType[lowerModuleIndex] == SDL::PS ? 2.f : 10.f;
//const float sign = ((dz > 0) - (dz < 0)) * ((hitsInGPU.zs[lowerHitIndex] > 0) - (hitsInGPU.zs[lowerHitIndex] < 0));
const float sign = ((dz > 0) - (dz < 0)) * ((zLower > 0) - (zLower < 0));
const float invertedcrossercut = (alpaka::math::abs(acc, dz) > 2) * sign;
pass = pass and ((alpaka::math::abs(acc, dz) < dzCut) && (invertedcrossercut <= 0));
if (not pass)
return pass;
float miniCut = 0;
miniCut = modulesInGPU.moduleLayerType[lowerModuleIndex] == SDL::Pixel
? dPhiThreshold(acc, rtLower, modulesInGPU, lowerModuleIndex)
: dPhiThreshold(acc, rtUpper, modulesInGPU, lowerModuleIndex);
// Cut #2: dphi difference
// Ref to original code: https://github.com/slava77/cms-tkph2-ntuple/blob/184d2325147e6930030d3d1f780136bc2dd29ce6/doubletAnalysis.C#L3085
float xn = 0.f, yn = 0.f; // , zn = 0;
float shiftedRt;
if (modulesInGPU.sides[lowerModuleIndex] != Center) // If barrel and not center it is tilted
{
// Shift the hits and calculate new xn, yn position
float shiftedCoords[3];
shiftStripHits(acc,
modulesInGPU,
lowerModuleIndex,
upperModuleIndex,
lowerHitIndex,
upperHitIndex,
shiftedCoords,
xLower,
yLower,
zLower,
rtLower,
xUpper,
yUpper,
zUpper,
rtUpper);
xn = shiftedCoords[0];
yn = shiftedCoords[1];
// Lower or the upper hit needs to be modified depending on which one was actually shifted
if (modulesInGPU.moduleLayerType[lowerModuleIndex] == SDL::Pixel) {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zUpper;
shiftedRt = alpaka::math::sqrt(acc, xn * xn + yn * yn);
dPhi = SDL::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY); //function from Hit.cc
noShiftedDphi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zLower;
shiftedRt = alpaka::math::sqrt(acc, xn * xn + yn * yn);
dPhi = SDL::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}
} else {
dPhi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
noShiftedDphi = dPhi;
}
pass = pass && (alpaka::math::abs(acc, dPhi) < miniCut);
if (not pass)
return pass;
// Cut #3: The dphi change going from lower Hit to upper Hit
// Ref to original code: https://github.com/slava77/cms-tkph2-ntuple/blob/184d2325147e6930030d3d1f780136bc2dd29ce6/doubletAnalysis.C#L3076
if (modulesInGPU.sides[lowerModuleIndex] != Center) {
// When it is tilted, use the new shifted positions
// TODO: This is somewhat of an mystery.... somewhat confused why this is the case
if (modulesInGPU.moduleLayerType[lowerModuleIndex] != SDL::Pixel) {
// dPhi Change should be calculated so that the upper hit has higher rt.
// In principle, this kind of check rt_lower < rt_upper should not be necessary because the hit shifting should have taken care of this.
// (i.e. the strip hit is shifted to be aligned in the line of sight from interaction point to pixel hit of PS module guaranteeing rt ordering)
// But I still placed this check for safety. (TODO: After checking explicitly if not needed remove later?)
// setdeltaPhiChange(lowerHit.rt() < upperHitMod.rt() ? lowerHit.deltaPhiChange(upperHitMod) : upperHitMod.deltaPhiChange(lowerHit));
dPhiChange = (rtLower < shiftedRt) ? SDL::deltaPhiChange(acc, xLower, yLower, shiftedX, shiftedY)
: SDL::deltaPhiChange(acc, shiftedX, shiftedY, xLower, yLower);
noShiftedDphiChange = rtLower < rtUpper ? SDL::deltaPhiChange(acc, xLower, yLower, xUpper, yUpper)
: SDL::deltaPhiChange(acc, xUpper, yUpper, xLower, yLower);
} else {
// dPhi Change should be calculated so that the upper hit has higher rt.
// In principle, this kind of check rt_lower < rt_upper should not be necessary because the hit shifting should have taken care of this.
// (i.e. the strip hit is shifted to be aligned in the line of sight from interaction point to pixel hit of PS module guaranteeing rt ordering)
// But I still placed this check for safety. (TODO: After checking explicitly if not needed remove later?)
dPhiChange = (shiftedRt < rtUpper) ? SDL::deltaPhiChange(acc, shiftedX, shiftedY, xUpper, yUpper)
: SDL::deltaPhiChange(acc, xUpper, yUpper, shiftedX, shiftedY);
noShiftedDphiChange = rtLower < rtUpper ? SDL::deltaPhiChange(acc, xLower, yLower, xUpper, yUpper)
: SDL::deltaPhiChange(acc, xUpper, yUpper, xLower, yLower);
}
} else {
// When it is flat lying module, whichever is the lowerSide will always have rt lower
dPhiChange = SDL::deltaPhiChange(acc, xLower, yLower, xUpper, yUpper);
noShiftedDphiChange = dPhiChange;
}
pass = pass && (alpaka::math::abs(acc, dPhiChange) < miniCut);
return pass;
};
template <typename TAcc>
ALPAKA_FN_ACC bool runMiniDoubletDefaultAlgoEndcap(TAcc const& acc,
struct SDL::modules& modulesInGPU,
uint16_t& lowerModuleIndex,
uint16_t& upperModuleIndex,
unsigned int lowerHitIndex,
unsigned int upperHitIndex,
float& drt,
float& dPhi,
float& dPhiChange,
float& shiftedX,
float& shiftedY,
float& shiftedZ,
float& noshiftedDz,
float& noShiftedDphi,
float& noShiftedDphichange,
float xLower,
float yLower,
float zLower,
float rtLower,
float xUpper,
float yUpper,
float zUpper,
float rtUpper) {
bool pass = true;
// There are series of cuts that applies to mini-doublet in a "endcap" region
// Cut #1 : dz cut. The dz difference can't be larger than 1cm. (max separation is 4mm for modules in the endcap)
// Ref to original code: https://github.com/slava77/cms-tkph2-ntuple/blob/184d2325147e6930030d3d1f780136bc2dd29ce6/doubletAnalysis.C#L3093
// For PS module in case when it is tilted a different dz (after the strip hit shift) is calculated later.
float dz = zLower - zUpper; // Not const since later it might change depending on the type of module
const float dzCut = 1.f;
pass = pass && (alpaka::math::abs(acc, dz) < dzCut);
if (not pass)
return pass;
// Cut #2 : drt cut. The dz difference can't be larger than 1cm. (max separation is 4mm for modules in the endcap)
// Ref to original code: https://github.com/slava77/cms-tkph2-ntuple/blob/184d2325147e6930030d3d1f780136bc2dd29ce6/doubletAnalysis.C#L3100
const float drtCut = modulesInGPU.moduleType[lowerModuleIndex] == SDL::PS ? 2.f : 10.f;
drt = rtLower - rtUpper;
pass = pass && (alpaka::math::abs(acc, drt) < drtCut);
if (not pass)
return pass;
// The new scheme shifts strip hits to be "aligned" along the line of sight from interaction point to the pixel hit (if it is PS modules)
float xn = 0, yn = 0, zn = 0;
float shiftedCoords[3];
shiftStripHits(acc,
modulesInGPU,
lowerModuleIndex,
upperModuleIndex,
lowerHitIndex,
upperHitIndex,
shiftedCoords,
xLower,
yLower,
zLower,
rtLower,
xUpper,
yUpper,
zUpper,
rtUpper);
xn = shiftedCoords[0];
yn = shiftedCoords[1];
zn = shiftedCoords[2];
if (modulesInGPU.moduleType[lowerModuleIndex] == SDL::PS) {
// Appropriate lower or upper hit is modified after checking which one was actually shifted
if (modulesInGPU.moduleLayerType[lowerModuleIndex] == SDL::Pixel) {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zUpper;
dPhi = SDL::deltaPhi(acc, xLower, yLower, shiftedX, shiftedY);
noShiftedDphi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zLower;
dPhi = SDL::deltaPhi(acc, shiftedX, shiftedY, xUpper, yUpper);
noShiftedDphi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}
} else {
shiftedX = xn;
shiftedY = yn;
shiftedZ = zUpper;
dPhi = SDL::deltaPhi(acc, xLower, yLower, xn, yn);
noShiftedDphi = SDL::deltaPhi(acc, xLower, yLower, xUpper, yUpper);
}
// dz needs to change if it is a PS module where the strip hits are shifted in order to properly account for the case when a tilted module falls under "endcap logic"
// if it was an endcap it will have zero effect
if (modulesInGPU.moduleType[lowerModuleIndex] == SDL::PS) {
dz = modulesInGPU.moduleLayerType[lowerModuleIndex] == SDL::Pixel ? zLower - zn : zUpper - zn;
}
float miniCut = 0;
miniCut = modulesInGPU.moduleLayerType[lowerModuleIndex] == SDL::Pixel
? dPhiThreshold(acc, rtLower, modulesInGPU, lowerModuleIndex, dPhi, dz)
: dPhiThreshold(acc, rtUpper, modulesInGPU, lowerModuleIndex, dPhi, dz);
pass = pass && (alpaka::math::abs(acc, dPhi) < miniCut);
if (not pass)
return pass;
// Cut #4: Another cut on the dphi after some modification
// Ref to original code: https://github.com/slava77/cms-tkph2-ntuple/blob/184d2325147e6930030d3d1f780136bc2dd29ce6/doubletAnalysis.C#L3119-L3124
float dzFrac = alpaka::math::abs(acc, dz) / alpaka::math::abs(acc, zLower);
dPhiChange = dPhi / dzFrac * (1.f + dzFrac);
noShiftedDphichange = noShiftedDphi / dzFrac * (1.f + dzFrac);
pass = pass && (alpaka::math::abs(acc, dPhiChange) < miniCut);
return pass;
};
struct createMiniDoubletsInGPUv2 {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
struct SDL::modules modulesInGPU,
struct SDL::hits hitsInGPU,
struct SDL::miniDoublets mdsInGPU,
struct SDL::objectRanges rangesInGPU) const {
using Dim = alpaka::Dim<TAcc>;
using Idx = alpaka::Idx<TAcc>;
using Vec = alpaka::Vec<Dim, Idx>;
Vec const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
Vec const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);
for (uint16_t lowerModuleIndex = globalThreadIdx[1]; lowerModuleIndex < (*modulesInGPU.nLowerModules);
lowerModuleIndex += gridThreadExtent[1]) {
uint16_t upperModuleIndex = modulesInGPU.partnerModuleIndices[lowerModuleIndex];
int nLowerHits = hitsInGPU.hitRangesnLower[lowerModuleIndex];
int nUpperHits = hitsInGPU.hitRangesnUpper[lowerModuleIndex];
if (hitsInGPU.hitRangesLower[lowerModuleIndex] == -1)
continue;
const int maxHits = alpaka::math::max(acc, nUpperHits, nLowerHits);
unsigned int upHitArrayIndex = hitsInGPU.hitRangesUpper[lowerModuleIndex];
unsigned int loHitArrayIndex = hitsInGPU.hitRangesLower[lowerModuleIndex];
int limit = nUpperHits * nLowerHits;
for (int hitIndex = globalThreadIdx[2]; hitIndex < limit; hitIndex += gridThreadExtent[2]) {
int lowerHitIndex = hitIndex / nUpperHits;
int upperHitIndex = hitIndex % nUpperHits;
if (upperHitIndex >= nUpperHits)
continue;
if (lowerHitIndex >= nLowerHits)
continue;
unsigned int lowerHitArrayIndex = loHitArrayIndex + lowerHitIndex;
float xLower = hitsInGPU.xs[lowerHitArrayIndex];
float yLower = hitsInGPU.ys[lowerHitArrayIndex];
float zLower = hitsInGPU.zs[lowerHitArrayIndex];
float rtLower = hitsInGPU.rts[lowerHitArrayIndex];
unsigned int upperHitArrayIndex = upHitArrayIndex + upperHitIndex;
float xUpper = hitsInGPU.xs[upperHitArrayIndex];
float yUpper = hitsInGPU.ys[upperHitArrayIndex];
float zUpper = hitsInGPU.zs[upperHitArrayIndex];
float rtUpper = hitsInGPU.rts[upperHitArrayIndex];
float dz, dphi, dphichange, shiftedX, shiftedY, shiftedZ, noShiftedDz, noShiftedDphi, noShiftedDphiChange;
bool success = runMiniDoubletDefaultAlgo(acc,
modulesInGPU,
lowerModuleIndex,
upperModuleIndex,
lowerHitArrayIndex,
upperHitArrayIndex,
dz,
dphi,
dphichange,
shiftedX,
shiftedY,
shiftedZ,
noShiftedDz,
noShiftedDphi,
noShiftedDphiChange,
xLower,
yLower,
zLower,
rtLower,
xUpper,
yUpper,
zUpper,
rtUpper);
if (success) {
int totOccupancyMDs =
alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.totOccupancyMDs[lowerModuleIndex], 1);
if (totOccupancyMDs >= (rangesInGPU.miniDoubletModuleOccupancy[lowerModuleIndex])) {
#ifdef Warnings
printf("Mini-doublet excess alert! Module index = %d\n", lowerModuleIndex);
#endif
} else {
int mdModuleIndex = alpaka::atomicOp<alpaka::AtomicAdd>(acc, &mdsInGPU.nMDs[lowerModuleIndex], 1);
unsigned int mdIndex = rangesInGPU.miniDoubletModuleIndices[lowerModuleIndex] + mdModuleIndex;
addMDToMemory(acc,
mdsInGPU,
hitsInGPU,
modulesInGPU,
lowerHitArrayIndex,
upperHitArrayIndex,
lowerModuleIndex,
dz,
dphi,
dphichange,
shiftedX,
shiftedY,
shiftedZ,
noShiftedDz,
noShiftedDphi,
noShiftedDphiChange,
mdIndex);
}
}
}
}
}
};
struct createMDArrayRangesGPU {
template <typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc,
struct SDL::modules modulesInGPU,
struct SDL::objectRanges rangesInGPU) const {
using Dim = alpaka::Dim<TAcc>;
using Idx = alpaka::Idx<TAcc>;
using Vec = alpaka::Vec<Dim, Idx>;
Vec const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc);
Vec const gridThreadExtent = alpaka::getWorkDiv<alpaka::Grid, alpaka::Threads>(acc);