forked from sPHENIX-Collaboration/acts
/
AtlasSeedfinder.ipp
1082 lines (977 loc) · 28.5 KB
/
AtlasSeedfinder.ipp
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
// This file is part of the Acts project.
//
// Copyright (C) 2018 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
///////////////////////////////////////////////////////////////////
// AtlasSeedfinder.ipp Acts project
///////////////////////////////////////////////////////////////////
#include <algorithm>
///////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////
template <typename SpacePoint>
Acts::Legacy::AtlasSeedfinder<SpacePoint>::AtlasSeedfinder() {
m_checketa = false;
m_maxsize = 50000;
m_ptmin = 400.;
m_etamin = 0.;
m_etamax = 2.7;
// delta R minimum & maximum within a seed
m_drmin = 5.;
m_drminv = 20.;
m_drmax = 270.;
// restrict z coordinate of particle origin
m_zmin = -250.;
m_zmax = +250.;
// radius of detector in mm
r_rmax = 600.;
r_rstep = 2.;
// checking if Z is compatible:
// m_dzver is related to delta-Z
// m_dzdrver is related to delta-Z divided by delta-R
m_dzver = 5.;
m_dzdrver = .02;
// shift all spacepoints by this offset such that the beam can be assumed to
// be at 0,0
// z shift should not matter as beam is assumed to be parallel to central
// detector axis,
// but spacepoints will be shifted by z as well anyway.
m_xbeam = 0.;
m_ybeam = 0.;
m_zbeam = 0.;
// config
// max impact parameters
// m_diver = max ppp impact params
m_diver = 10.;
m_diverpps = 1.7;
m_diversss = 50;
m_divermax = 20.;
// delta azimuth (phi)
m_dazmax = .02;
// limit for sp compatible with 1 middle space point
// ridiculously large to be EXTRA safe
// only actually keep 5 of these max 5000 (m_maxOneSize of m_maxsizeSP)
m_maxsizeSP = 5000;
m_maxOneSize = 5;
// cache: counting if ran already
m_state = 0;
m_nlist = 0;
m_endlist = true;
r_Sorted = 0;
r_index = 0;
r_map = 0;
m_SP = 0;
m_R = 0;
m_Tz = 0;
m_Er = 0;
m_U = 0;
m_V = 0;
m_Zo = 0;
m_OneSeeds = 0;
m_seedOutput = 0;
// Build framework
//
buildFrameWork();
m_CmSp.reserve(500);
}
///////////////////////////////////////////////////////////////////
// Destructor
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
Acts::Legacy::AtlasSeedfinder<SpacePoint>::~AtlasSeedfinder() {
if (r_index) {
delete[] r_index;
}
if (r_map) {
delete[] r_map;
}
if (r_Sorted) {
delete[] r_Sorted;
}
// Delete seeds
//
for (i_seed = l_seeds.begin(); i_seed != l_seeds.end(); ++i_seed) {
delete *i_seed;
}
// Delete space points for reconstruction
//
i_spforseed = l_spforseed.begin();
for (; i_spforseed != l_spforseed.end(); ++i_spforseed) {
delete *i_spforseed;
}
if (m_seedOutput) {
delete m_seedOutput;
}
if (m_SP) {
delete[] m_SP;
}
if (m_R) {
delete[] m_R;
}
if (m_Tz) {
delete[] m_Tz;
}
if (m_Er) {
delete[] m_Er;
}
if (m_U) {
delete[] m_U;
}
if (m_V) {
delete[] m_V;
}
if (m_Zo) {
delete[] m_Zo;
}
if (m_OneSeeds) {
delete[] m_OneSeeds;
}
}
///////////////////////////////////////////////////////////////////
// Initialize tool for new event
///////////////////////////////////////////////////////////////////
template <typename SpacePoint>
template <class RandIter>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::newEvent(int iteration,
RandIter spBegin,
RandIter spEnd) {
iteration <= 0 ? m_iteration = 0 : m_iteration = iteration;
erase();
m_dzdrmin = m_dzdrmin0;
m_dzdrmax = m_dzdrmax0;
m_umax = 100.;
// if first event
r_first = 0;
if (!m_iteration) {
buildBeamFrameWork();
// curvature depending on bfield
m_K = 2. / (300. * m_config.bFieldInZ);
// curvature of minimum pT track
m_ipt2K = m_ipt2 / (m_K * m_K);
// scattering of min pT track
m_ipt2C = m_ipt2 * m_COF;
// scattering times curvature (missing: div by pT)
m_COFK = m_COF * (m_K * m_K);
i_spforseed = l_spforseed.begin();
}
// only if not first event
else {
fillLists();
return;
}
float irstep = 1. / r_rstep;
int irmax = r_size - 1;
// TODO using 3 member vars to clear r_Sorted
for (int i = 0; i != m_nr; ++i) {
int n = r_index[i];
r_map[n] = 0;
r_Sorted[n].clear();
}
m_nr = 0;
// convert space-points to SPForSeed and sort into radius-binned array
// r_Sorted
// store number of SP per bin in r_map
RandIter sp = spBegin;
for (; sp != spEnd; ++sp) {
Acts::Legacy::SPForSeed<SpacePoint>* sps = newSpacePoint((*sp));
if (!sps) {
continue;
}
int ir = int(sps->radius() * irstep);
if (ir > irmax) {
ir = irmax;
}
r_Sorted[ir].push_back(sps);
// if there is exactly one SP in current bin, add bin nr in r_index (for
// deletion later)
// TODO overly complicated
++r_map[ir];
if (r_map[ir] == 1) {
r_index[m_nr++] = ir;
}
}
fillLists();
}
///////////////////////////////////////////////////////////////////
// Methods to initialize different strategies of seeds production
// with three space points with or without vertex constraint
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::find3Sp() {
m_zminU = m_zmin;
m_zmaxU = m_zmax;
if ((m_state == 0) || m_nlist) {
i_seede = l_seeds.begin();
m_state = 1;
m_nlist = 0;
m_endlist = true;
m_fvNmin = 0;
m_fNmin = 0;
m_zMin = 0;
production3Sp();
}
i_seed = l_seeds.begin();
m_seed = m_seeds.begin();
}
///////////////////////////////////////////////////////////////////
// Find next set space points
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::findNext() {
if (m_endlist) {
return;
}
i_seede = l_seeds.begin();
production3Sp();
i_seed = l_seeds.begin();
m_seed = m_seeds.begin();
++m_nlist;
}
///////////////////////////////////////////////////////////////////
// Initiate frame work for seed generator
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::buildFrameWork() {
m_ptmin = fabs(m_ptmin);
if (m_ptmin < 100.) {
m_ptmin = 100.;
}
if (m_diversss < m_diver) {
m_diversss = m_diver;
}
if (m_divermax < m_diversss) {
m_divermax = m_diversss;
}
if (fabs(m_etamin) < .1) {
m_etamin = -m_etamax;
}
m_dzdrmax0 = 1. / tan(2. * atan(exp(-m_etamax)));
m_dzdrmin0 = 1. / tan(2. * atan(exp(-m_etamin)));
// scattering factor. depends on error, forward direction and distance between
// SP
m_COF = 134 * .05 * 9.;
m_ipt = 1. / fabs(.9 * m_ptmin);
m_ipt2 = m_ipt * m_ipt;
m_K = 0.;
// set all counters zero
m_nsaz = m_nsazv = m_nr = m_nrfz = 0;
// Build radius sorted containers
//
r_size = int((r_rmax + .1) / r_rstep);
r_Sorted = new std::list<Acts::Legacy::SPForSeed<SpacePoint>*>[r_size];
r_index = new int[r_size];
r_map = new int[r_size];
for (int i = 0; i != r_size; ++i) {
r_index[i] = 0;
r_map[i] = 0;
}
// Build radius-azimuthal sorted containers
//
const float pi2 = 2. * M_PI;
const int NFmax = 53;
const float sFmax = float(NFmax) / pi2;
const float m_sFmin = 100. / 60.;
// make phi-slices for 400MeV tracks, unless ptMin is even smaller
float ptm = 400.;
if (m_ptmin < ptm) {
ptm = m_ptmin;
}
m_sF = ptm / 60.;
if (m_sF > sFmax) {
m_sF = sFmax;
} else if (m_sF < m_sFmin) {
m_sF = m_sFmin;
}
m_fNmax = int(pi2 * m_sF);
if (m_fNmax >= NFmax) {
m_fNmax = NFmax - 1;
}
// Build radius-azimuthal-Z sorted containers
//
m_nrfz = 0;
for (int i = 0; i != 583; ++i) {
rfz_index[i] = 0;
rfz_map[i] = 0;
}
// Build maps for radius-azimuthal-Z sorted collections
//
for (int f = 0; f <= m_fNmax; ++f) {
int fb = f - 1;
if (fb < 0) {
fb = m_fNmax;
}
int ft = f + 1;
if (ft > m_fNmax) {
ft = 0;
}
// For each azimuthal region loop through all Z regions
//
for (int z = 0; z != 11; ++z) {
int a = f * 11 + z;
int b = fb * 11 + z;
int c = ft * 11 + z;
rfz_b[a] = 3;
rfz_t[a] = 3;
rfz_ib[a][0] = a;
rfz_it[a][0] = a;
rfz_ib[a][1] = b;
rfz_it[a][1] = b;
rfz_ib[a][2] = c;
rfz_it[a][2] = c;
if (z == 5) {
rfz_t[a] = 9;
rfz_it[a][3] = a + 1;
rfz_it[a][4] = b + 1;
rfz_it[a][5] = c + 1;
rfz_it[a][6] = a - 1;
rfz_it[a][7] = b - 1;
rfz_it[a][8] = c - 1;
} else if (z > 5) {
rfz_b[a] = 6;
rfz_ib[a][3] = a - 1;
rfz_ib[a][4] = b - 1;
rfz_ib[a][5] = c - 1;
if (z < 10) {
rfz_t[a] = 6;
rfz_it[a][3] = a + 1;
rfz_it[a][4] = b + 1;
rfz_it[a][5] = c + 1;
}
} else {
rfz_b[a] = 6;
rfz_ib[a][3] = a + 1;
rfz_ib[a][4] = b + 1;
rfz_ib[a][5] = c + 1;
if (z > 0) {
rfz_t[a] = 6;
rfz_it[a][3] = a - 1;
rfz_it[a][4] = b - 1;
rfz_it[a][5] = c - 1;
}
}
if (z == 3) {
rfz_b[a] = 9;
rfz_ib[a][6] = a + 2;
rfz_ib[a][7] = b + 2;
rfz_ib[a][8] = c + 2;
} else if (z == 7) {
rfz_b[a] = 9;
rfz_ib[a][6] = a - 2;
rfz_ib[a][7] = b - 2;
rfz_ib[a][8] = c - 2;
}
}
}
if (!m_SP) {
m_SP = new Acts::Legacy::SPForSeed<SpacePoint>*[m_maxsizeSP];
}
if (m_R == nullptr) {
m_R = new float[m_maxsizeSP];
}
if (m_Tz == nullptr) {
m_Tz = new float[m_maxsizeSP];
}
if (m_Er == nullptr) {
m_Er = new float[m_maxsizeSP];
}
if (m_U == nullptr) {
m_U = new float[m_maxsizeSP];
}
if (m_V == nullptr) {
m_V = new float[m_maxsizeSP];
}
if (m_Zo == nullptr) {
m_Zo = new float[m_maxsizeSP];
}
if (!m_OneSeeds) {
m_OneSeeds = new Acts::Legacy::InternalSeed<SpacePoint>[m_maxOneSize];
}
if (!m_seedOutput) {
m_seedOutput = new Acts::Legacy::Seed<SpacePoint>();
}
i_seed = l_seeds.begin();
i_seede = l_seeds.end();
}
///////////////////////////////////////////////////////////////////
// Initiate beam frame work for seed generator
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::buildBeamFrameWork() {
double bx = m_config.beamPosX;
double by = m_config.beamPosY;
double bz = m_config.beamPosZ;
m_xbeam = float(bx);
m_ybeam = float(by);
m_zbeam = float(bz);
}
///////////////////////////////////////////////////////////////////
// Initiate beam frame work for seed generator
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::convertToBeamFrameWork(
SpacePoint* const& sp, float* r) {
r[0] = float(sp->x) - m_xbeam;
r[1] = float(sp->y) - m_ybeam;
r[2] = float(sp->z) - m_zbeam;
}
///////////////////////////////////////////////////////////////////
// Initiate space points seed maker
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::fillLists() {
const float pi2 = 2. * M_PI;
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator r, re;
int ir0 = 0;
bool ibl = false;
r_first = 0;
if (m_iteration) {
r_first = m_config.SCT_rMin / r_rstep;
}
for (int i = r_first; i != r_size; ++i) {
if (!r_map[i]) {
continue;
}
r = r_Sorted[i].begin();
re = r_Sorted[i].end();
if (ir0 == 0) {
ir0 = i;
}
// if not 1st event
if (m_iteration) {
//
if (!(*r)->spacepoint->clusterList().second) {
if (i < 20) {
ibl = true;
}
} else if (ibl) {
break;
} else if (i > 175) {
break;
}
}
for (; r != re; ++r) {
// Azimuthal (Phi) angle sort
// bin nr "f" is phi * phi-slices
float F = (*r)->phi();
if (F < 0.) {
F += pi2;
}
int f = int(F * m_sF);
if (f < 0) {
f = m_fNmax;
} else if (f > m_fNmax) {
f = 0;
}
int z;
float Z = (*r)->z();
// Azimuthal angle and Z-coordinate sort
// assign z-bin a value between 0 and 10 identifying the z-slice of a
// space-point
if (Z > 0.) {
Z < 250. ? z = 5
: Z < 450. ? z = 6
: Z < 925. ? z = 7
: Z < 1400. ? z = 8
: Z < 2500. ? z = 9 : z = 10;
} else {
Z > -250.
? z = 5
: Z > -450.
? z = 4
: Z > -925. ? z = 3
: Z > -1400. ? z = 2 : Z > -2500. ? z = 1 : z = 0;
}
// calculate bin nr "n" for self made r-phi-z sorted 3D array "rfz_Sorted"
// record number of sp in m_nsaz
int n = f * 11 + z;
++m_nsaz;
// push back sp into rfz_Sorted, record new number of entries in bin in
// rfz_map,
// if 1st entry record non-empty bin in "rfz_index"
rfz_Sorted[n].push_back(*r);
if (!rfz_map[n]++) {
rfz_index[m_nrfz++] = n;
}
}
}
m_state = 0;
}
///////////////////////////////////////////////////////////////////
// Erase space point information
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::erase() {
for (int i = 0; i != m_nrfz; ++i) {
int n = rfz_index[i];
rfz_map[n] = 0;
rfz_Sorted[n].clear();
}
m_state = 0;
m_nsaz = 0;
m_nsazv = 0;
m_nrfz = 0;
}
///////////////////////////////////////////////////////////////////
// Production 3 space points seeds
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::production3Sp() {
// if less than 3 sp in total
if (m_nsaz < 3) {
return;
}
m_seeds.clear();
// indices for the z-regions array in weird order.
// ensures creating seeds first for barrel, then left EC, then right EC
const int ZI[11] = {5, 6, 7, 8, 9, 10, 4, 3, 2, 1, 0};
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator rt[9],
rte[9], rb[9], rbe[9];
int nseed = 0;
// Loop through all azimuthal regions
//
for (int f = m_fNmin; f <= m_fNmax; ++f) {
// For each azimuthal region loop through all Z regions
// first for barrel, then left EC, then right EC
int z = 0;
if (!m_endlist) {
z = m_zMin;
}
for (; z != 11; ++z) {
int a = f * 11 + ZI[z];
if (!rfz_map[a]) {
continue;
}
int NB = 0, NT = 0;
for (int i = 0; i != rfz_b[a]; ++i) {
int an = rfz_ib[a][i];
// if bin has no entry: continue
if (!rfz_map[an]) {
continue;
}
// assign begin-pointer and end-pointer of current bin to rb and rbe
rb[NB] = rfz_Sorted[an].begin();
rbe[NB++] = rfz_Sorted[an].end();
}
for (int i = 0; i != rfz_t[a]; ++i) {
int an = rfz_it[a][i];
// if bin has no entry: continue
if (!rfz_map[an]) {
continue;
}
// assign begin-pointer and end-pointer of current bin to rt and rte
rt[NT] = rfz_Sorted[an].begin();
rte[NT++] = rfz_Sorted[an].end();
}
production3Sp(rb, rbe, rt, rte, NB, NT, nseed);
if (!m_endlist) {
m_fNmin = f;
m_zMin = z;
return;
}
}
}
m_endlist = true;
}
///////////////////////////////////////////////////////////////////
// Production 3 space points seeds for full scan
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::production3Sp(
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator* rb,
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator* rbe,
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator* rt,
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator* rte,
int NB, int NT, int& nseed) {
typename std::list<Acts::Legacy::SPForSeed<SpacePoint>*>::iterator r0 = rb[0],
r;
if (!m_endlist) {
r0 = m_rMin;
m_endlist = true;
}
float ipt2K = m_ipt2K;
float ipt2C = m_ipt2C;
float COFK = m_COFK;
float imaxp = m_diver;
float imaxs = m_divermax;
m_CmSp.clear();
// Loop through all space points
// first bottom bin used as "current bin" for middle spacepoints
for (; r0 != rbe[0]; ++r0) {
m_nOneSeeds = 0;
m_mapOneSeeds.clear();
float R = (*r0)->radius();
const int sur0 = (*r0)->surface();
float X = (*r0)->x();
float Y = (*r0)->y();
float Z = (*r0)->z();
int Nb = 0;
// Bottom links production
//
for (int i = 0; i != NB; ++i) {
for (r = rb[i]; r != rbe[i]; ++r) {
float Rb = (*r)->radius();
float dR = R - Rb;
// if deltaR larger than deltaRMax, store spacepoint counter position in
// rb[i]
// this is not necessary at all because r is the loop counter (rb never
// read again)
if (dR > m_drmax) {
rb[i] = r;
continue;
}
// if dR is smaller than drmin, stop processing this bottombin
// because it has no more sp with lower radii
// OR break because processing PPP and encountered SCT SP
if (dR < m_drmin ||
(m_iteration && (*r)->spacepoint->clusterList().second)) {
break;
}
if ((*r)->surface() == sur0) {
continue;
}
// forward direction of SP duplet
float Tz = (Z - (*r)->z()) / dR;
float aTz = fabs(Tz);
// why also exclude seeds with small pseudorapidity??
if (aTz < m_dzdrmin || aTz > m_dzdrmax) {
continue;
}
// Comparison with vertices Z coordinates
// continue if duplet origin not within collision region on z axis
float Zo = Z - R * Tz;
if (!isZCompatible(Zo)) {
continue;
}
m_SP[Nb] = (*r);
if (++Nb == m_maxsizeSP) {
goto breakb;
}
}
}
breakb:
if ((Nb == 0) || Nb == m_maxsizeSP) {
continue;
}
int Nt = Nb;
// Top links production
//
for (int i = 0; i != NT; ++i) {
for (r = rt[i]; r != rte[i]; ++r) {
float Rt = (*r)->radius();
float dR = Rt - R;
if (dR < m_drmin) {
rt[i] = r;
continue;
}
if (dR > m_drmax) {
break;
}
// TODO: is check if in same surface necessary?
if ((*r)->surface() == sur0) {
continue;
}
float Tz = ((*r)->z() - Z) / dR;
float aTz = fabs(Tz);
if (aTz < m_dzdrmin || aTz > m_dzdrmax) {
continue;
}
// Comparison with vertices Z coordinates
//
float Zo = Z - R * Tz;
if (!isZCompatible(Zo)) {
continue;
}
m_SP[Nt] = (*r);
if (++Nt == m_maxsizeSP) {
goto breakt;
}
}
}
breakt:
if ((Nt - Nb) == 0) {
continue;
}
float covr0 = (*r0)->covr();
float covz0 = (*r0)->covz();
float ax = X / R;
float ay = Y / R;
for (int i = 0; i != Nt; ++i) {
Acts::Legacy::SPForSeed<SpacePoint>* sp = m_SP[i];
float dx = sp->x() - X;
float dy = sp->y() - Y;
float dz = sp->z() - Z;
// calculate projection fraction of spM->spT vector pointing in same
// direction as
// vector origin->spM (x) and projection fraction of spM->spT vector
// pointing
// orthogonal to origin->spM (y)
float x = dx * ax + dy * ay;
float y = dy * ax - dx * ay;
// 1/(r*r) = 1/dx*dx+dy*dy = 1/(distance between the two points)^2
float r2 = 1. / (x * x + y * y);
// 1/r
float dr = sqrt(r2);
float tz = dz * dr;
if (i < Nb) {
tz = -tz;
}
m_Tz[i] = tz;
m_Zo[i] = Z - R * tz;
m_R[i] = dr;
m_U[i] = x * r2;
m_V[i] = y * r2;
m_Er[i] = ((covz0 + sp->covz()) + (tz * tz) * (covr0 + sp->covr())) * r2;
}
covr0 *= .5;
covz0 *= 2.;
// Three space points comparison
//
for (int b = 0; b != Nb; ++b) {
float Zob = m_Zo[b];
float Tzb = m_Tz[b];
float Rb2r = m_R[b] * covr0;
float Rb2z = m_R[b] * covz0;
float Erb = m_Er[b];
float Vb = m_V[b];
float Ub = m_U[b];
// Tzb2 = 1/sin^2(theta)
float Tzb2 = (1. + Tzb * Tzb);
float sTzb2 = sqrt(Tzb2);
// CSA = curvature^2/(pT^2 * sin^2(theta)) * scatteringFactor
float CSA = Tzb2 * COFK;
// ICSA = (1/(pT^2 * sin^2(theta)) * scatteringFactor
float ICSA = Tzb2 * ipt2C;
float imax = imaxp;
if (m_SP[b]->spacepoint->clusterList().second) {
imax = imaxs;
}
for (int t = Nb; t != Nt; ++t) {
float dT = ((Tzb - m_Tz[t]) * (Tzb - m_Tz[t]) - m_R[t] * Rb2z -
(Erb + m_Er[t])) -
(m_R[t] * Rb2r) * ((Tzb + m_Tz[t]) * (Tzb + m_Tz[t]));
if (dT > ICSA) {
continue;
}
float dU = m_U[t] - Ub;
if (dU == 0.) {
continue;
}
float A = (m_V[t] - Vb) / dU;
float S2 = 1. + A * A;
float B = Vb - A * Ub;
float B2 = B * B;
// B2/S2=1/helixradius^2
if (B2 > ipt2K * S2 || dT * S2 > B2 * CSA) {
continue;
}
float Im = fabs((A - B * R) * R);
if (Im <= imax) {
// Add penalty factor dependent on difference between cot(theta) to
// the quality Im (previously Impact)
float dr;
m_R[t] < m_R[b] ? dr = m_R[t] : dr = m_R[b];
Im += fabs((Tzb - m_Tz[t]) / (dr * sTzb2));
// B/sqrt(S2) = 1/helixradius
m_CmSp.push_back(std::make_pair(B / sqrt(S2), m_SP[t]));
m_SP[t]->setParam(Im);
}
}
if (!m_CmSp.empty()) {
newOneSeedWithCurvaturesComparison(m_SP[b], (*r0), Zob);
}
}
fillSeeds();
nseed += m_fillOneSeeds;
if (nseed >= m_maxsize) {
m_endlist = false;
++r0;
m_rMin = r0;
return;
}
}
}
///////////////////////////////////////////////////////////////////
// New 3 space points pro seeds
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::newOneSeed(
Acts::Legacy::SPForSeed<SpacePoint>*& p1,
Acts::Legacy::SPForSeed<SpacePoint>*& p2,
Acts::Legacy::SPForSeed<SpacePoint>*& p3, float z, float q) {
// if the number of seeds already in m_OneSeeds does not exceed m_maxOneSize
// then insert the current SP into m_mapOneSeeds and m_OneSeeds.
if (m_nOneSeeds < m_maxOneSize) {
m_OneSeeds[m_nOneSeeds].set(p1, p2, p3, z);
m_mapOneSeeds.insert(std::make_pair(q, m_OneSeeds + m_nOneSeeds));
++m_nOneSeeds;
}
// if not, check the q(uality) of the LAST seed of m_mapOneSeeds
// if the quality of the new seed is worse, replace the value this
// (better) quality-key pointed to with the SP from the new seed.
// Then, add the new seed a SECOND time to the map with the worse quality as
// key.
// Then remove all entries after the newly inserted entry equal to the new
// seed.
else {
typename std::multimap<
float, Acts::Legacy::InternalSeed<SpacePoint>*>::reverse_iterator l =
m_mapOneSeeds.rbegin();
if ((*l).first <= q) {
return;
}
Acts::Legacy::InternalSeed<SpacePoint>* s = (*l).second;
s->set(p1, p2, p3, z);
typename std::multimap<
float, Acts::Legacy::InternalSeed<SpacePoint>*>::iterator i =
m_mapOneSeeds.insert(std::make_pair(q, s));
for (++i; i != m_mapOneSeeds.end(); ++i) {
if ((*i).second == s) {
m_mapOneSeeds.erase(i);
return;
}
}
}
}
///////////////////////////////////////////////////////////////////
// New 3 space points pro seeds production
///////////////////////////////////////////////////////////////////
template <class SpacePoint>
void Acts::Legacy::AtlasSeedfinder<SpacePoint>::
newOneSeedWithCurvaturesComparison(
Acts::Legacy::SPForSeed<SpacePoint>*& SPb,
Acts::Legacy::SPForSeed<SpacePoint>*& SP0, float Zob) {
// allowed (1/helixradius)-delta between 2 seeds
const float dC = .00003;
bool pixb = !SPb->spacepoint->clusterList().second;
float ub = SPb->quality();
float u0 = SP0->quality();
std::sort(m_CmSp.begin(), m_CmSp.end(), Acts::Legacy::comCurvature());
typename std::vector<
std::pair<float, Acts::Legacy::SPForSeed<SpacePoint>*>>::iterator j,
jn, i = m_CmSp.begin(), ie = m_CmSp.end();
jn = i;
for (; i != ie; ++i) {
float u = (*i).second->param();
float Im = (*i).second->param();
bool pixt = !(*i).second->spacepoint->clusterList().second;
const int Sui = (*i).second->surface();
float Ri = (*i).second->radius();
float Ci1 = (*i).first - dC;
float Ci2 = (*i).first + dC;
float Rmi = 0.;
float Rma = 0.;
bool in = false;
if (!pixb) {
u -= 400.;
} else if (pixt) {
u -= 200.;
}
for (j = jn; j != ie; ++j) {
if (j == i) {
continue;
}
if ((*j).first < Ci1) {
jn = j;
++jn;
continue;
}
if ((*j).first > Ci2) {
break;
}
if ((*j).second->surface() == Sui) {
continue;
}
// Compared seeds should have at least deltaRMin distance
float Rj = (*j).second->radius();
if (fabs(Rj - Ri) < m_drmin) {
continue;
}
if (in) {
if (Rj > Rma) {
Rma = Rj;
} else if (Rj < Rmi) {
Rmi = Rj;
} else {
continue;
}
// add 200 to quality if 2 compatible seeds with high deltaR of their
// spT have been found
// (i.e. potential track spans 5 surfaces)
if ((Rma - Rmi) > 20.) {
u -= 200.;