Newer
Older
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
#include "SiliconTrackingAlg.h"
#include "GearSvc/IGearSvc.h"
#include "EventSeeder/IEventSeeder.h"
#include "TrackSystemSvc/ITrackSystemSvc.h"
#include "edm4hep/MCParticle.h"
#include "edm4hep/TrackerHit.h"
//#include "edm4hep/TrackerHitPlane.h"
#include "edm4hep/Track.h"
#include "edm4hep/TrackState.h"
//#include "DataHelper/ClusterExtended.h"
//#include "DataHelper/TrackExtended.h"
//#include "DataHelper/TrackerHitExtended.h"
//#include "DataHelper/HelixClass.h"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <gear/GEAR.h>
#include <gear/GearMgr.h>
#include <gear/GearParameters.h>
#include <gear/VXDLayerLayout.h>
#include <gear/VXDParameters.h>
#include "gear/FTDLayerLayout.h"
#include "gear/FTDParameters.h"
#include <gear/BField.h>
#include <UTIL/BitField64.h>
#include <UTIL/BitSet32.h>
#include <UTIL/ILDConf.h>
#include "TrackSystemSvc/MarlinTrkUtils.h"
#include "TrackSystemSvc/HelixTrack.h"
#include "TrackSystemSvc/HelixFit.h"
#include "TrackSystemSvc/IMarlinTrack.h"
//#include "TrackSystemSvc/MarlinTrkDiagnostics.h"
//#ifdef MARLINTRK_DIAGNOSTICS_ON
//#include "TrackSystemSvc/DiagnosticsController.h"
//#endif
//#include "MarlinCED.h"
//#include "marlin/AIDAProcessor.h"
//---- ROOT -----
#include "TH1F.h"
#include "TH2F.h"
using namespace edm4hep ;
//using namespace marlin ;
using namespace MarlinTrk ;
using std::min;
using std::max;
using std::abs;
const int SiliconTrackingAlg::_output_track_col_quality_GOOD = 1;
const int SiliconTrackingAlg::_output_track_col_quality_FAIR = 2;
const int SiliconTrackingAlg::_output_track_col_quality_POOR = 3;
const double SiliconTrackingAlg::TWOPI = 2*M_PI;
DECLARE_COMPONENT( SiliconTrackingAlg )
SiliconTrackingAlg::SiliconTrackingAlg(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc) {
//_description = "Pattern recognition in silicon trackers";
_fastfitter = new MarlinTrk::HelixFit();
_encoder = new UTIL::BitField64(lcio::ILDCellID0::encoder_string);
_petalBasedFTDWithOverlaps = false;
// zero triplet counters
_ntriplets = _ntriplets_good = _ntriplets_2MCP = _ntriplets_3MCP = _ntriplets_1MCP_Bad = _ntriplets_bad = 0;
// Input Collections
// ^^^^^^^^^^^^^^^^^
declareProperty("HeaderCol", _headerColHdl);
declareProperty("MCParticleCollection", _inMCColHdl, "Handle of the Input MCParticle collection");
declareProperty("VTXHitCollection", _inVTXColHdl, "Handle of the Input VTX TrackerHits collection");
declareProperty("FTDPixelHitCollection", _inFTDPixelColHdl, "Handle of the Input FTD TrackerHits collection");
declareProperty("FTDSpacePointCollection", _inFTDSpacePointColHdl, "Handle of the Input FTD SpacePoints collection");
declareProperty("SITHitCollection", _inSITColHdl, "Handle of the Input SIT TrackerHits collection");
// Output Collections
// ^^^^^^^^^^^^^^^^^^
declareProperty("SiTrackCollection", _outColHdl, "Handle of the SiTrack output collection");
//declareProperty("TrkHitRelCollection", _outRelColHdl, "Handle of TrackerHit Track relation collection");
// Steering parameters
// ^^^^^^^^^^^^^^^^^^^
_output_track_col_quality = _output_track_col_quality_GOOD;
}
StatusCode SiliconTrackingAlg::initialize() {
_nRun = -1 ;
_nEvt = 0 ;
//printParameters() ;
// set up the geometery needed by KalTest
//FIXME: for now do KalTest only - make this a steering parameter to use other fitters
auto _trackSystemSvc = service<ITrackSystemSvc>("TrackSystemSvc");
if ( !_trackSystemSvc ) {
error() << "Failed to find TrackSystemSvc ..." << endmsg;
return StatusCode::FAILURE;
}
_trksystem = _trackSystemSvc->getTrackSystem();
if( _trksystem == 0 ){
error() << "Cannot initialize MarlinTrkSystem of Type: KalTest" <<endmsg;
return StatusCode::FAILURE;
}
_trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ;
_trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ;
_trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ;
_trksystem->init() ;
std::cout << "fucd ==============" << _trksystem << std::endl;
#ifdef MARLINTRK_DIAGNOSTICS_ON
void * dcv = _trksystem->getDiagnositicsPointer();
DiagnosticsController* dc = static_cast<DiagnosticsController*>(dcv);
dc->init(_MarlinTrkDiagnosticsName,_MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics);
#endif
if(setupGearGeom()==StatusCode::FAILURE) return StatusCode::FAILURE;
if (_useSIT == 0)
_nLayers = _nLayersVTX;
else
_nLayers = _nLayersVTX + _nLayersSIT;
// initialise the container to have separate vectors for up to _nHitsChi2 hits.
_tracksWithNHitsContainer.resize(_nHitsChi2);
_dPhi = TWOPI/_nDivisionsInPhi;
_dTheta = 2.0/_nDivisionsInTheta;
_dPhiFTD = TWOPI/_nPhiFTD;
// I leave this for the moment, but 0.3 is c/1e9.
// For the cut it does not make too much of a difference
double cutOnR = _cutOnPt/(0.3*_bField);
cutOnR = 1000.*cutOnR;
_cutOnOmega = 1/cutOnR;
_output_track_col_quality = 0;
return GaudiAlgorithm::initialize();
}
StatusCode SiliconTrackingAlg::execute(){
//_current_event = evt;
//_allHits.reserve(1000);
_output_track_col_quality = _output_track_col_quality_GOOD;
// zero triplet counters
_ntriplets = _ntriplets_good = _ntriplets_2MCP = _ntriplets_3MCP = _ntriplets_1MCP_Bad = _ntriplets_bad = 0;
// Clearing the working containers from the previous event
// FIXME: partly done at the end of the event, in CleanUp. Make it consistent.
//_tracksWithNHitsContainer.clear();
//_trackImplVec.clear();
//_colTrackerHits.clear();
//_colNamesTrackerHits.clear();
//auto header = _headerColHdl.get()->at(0);
//int evtNo = header.getEventNumber();
//int runNo = header.getRunNumber();
//debug() << "Processing Run[" << runNo << "]::Event[" << evtNo << "]" << endmsg;
_trackImplVec.reserve(100);
_allHits.reserve(1000);
int successVTX = InitialiseVTX();
int successFTD = 0;
//int successFTD = InitialiseFTD();
if (successVTX == 1) {
debug() << " phi theta layer nh o : m : i :: o*m*i " << endmsg;
for (int iPhi=0; iPhi<_nDivisionsInPhi; ++iPhi) {
for (int iTheta=0; iTheta<_nDivisionsInTheta;++iTheta) {
ProcessOneSector(iPhi,iTheta); // Process one VXD sector
}
}
debug() << "End of Processing VXD and SIT sectors" << endmsg;
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
}
if (successFTD == 1) {
debug() << " phi side layer nh o : m : i :: o*m*i " << endmsg;
TrackingInFTD(); // Perform tracking in the FTD
debug() << "End of Processing FTD sectors" << endmsg;
}
//if(0){
if (successVTX == 1 || successFTD == 1) {
//if (successVTX == 1 ) {
for (int nHits = _nHitsChi2; nHits >= 3 ;// the three is hard coded, sorry.
// It's the minimal number to form a track
nHits--) {
Sorting( _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ) );
}
debug() << "End of Sorting " << endmsg;
for (int nHits = _nHitsChi2; nHits >= 3 ;// the three is hard coded, sorry.
// It's the minimal number to form a track
nHits--) {
TrackExtendedVec &tracksWithNHits = _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits );
for (TrackExtendedVec::iterator trackIter = tracksWithNHits.begin();
trackIter < tracksWithNHits.end(); trackIter++) {
CreateTrack( *trackIter );
}
debug() << "End of creating "<< nHits << " hits tracks " << endmsg;
}
if (_attachFast == 0) {
if(successVTX) AttachRemainingVTXHitsSlow();
if(successFTD) AttachRemainingFTDHitsSlow();
}
else {
if(successVTX) AttachRemainingVTXHitsFast();
if(successFTD) AttachRemainingFTDHitsFast();
}
debug() << "End of picking up remaining hits " << endmsg;
//edm4hep::TrackCollection* trkCol = nullptr;
//edm4hep::LCRelationCollection* relCol = nullptr;
auto trkCol = _outColHdl.createAndPut();
//auto relCol = _outRelColHdl.createAndPut();
//std::cout << "fucd------------------" << std::endl;
/*
LCCollectionVec * trkCol = new LCCollectionVec(LCIO::TRACK);
// if we want to point back to the hits we need to set the flag
LCFlagImpl trkFlag(0) ;
trkFlag.setBit( LCIO::TRBIT_HITS ) ;
trkCol->setFlag( trkFlag.getFlag() ) ;
LCCollectionVec * relCol = NULL;
*/
//FinalRefit(trkCol, relCol);
FinalRefit(trkCol);
//std::cout << "fucd------------------" << std::endl;
// set the quality of the output collection
switch (_output_track_col_quality) {
case _output_track_col_quality_FAIR:
//trkCol->parameters().setValue( "QualityCode" , "Fair" ) ;
break;
case _output_track_col_quality_POOR:
//trkCol->parameters().setValue( "QualityCode" , "Poor" ) ;
break;
default:
//trkCol->parameters().setValue( "QualityCode" , "Good" ) ;
break;
}
/*
if (_UseEventDisplay) {
this->drawEvent();
}
*/
}
// fill event based histogram
/*
if (_createDiagnosticsHistograms) {
// triplet histos
_histos->fill1D(DiagnosticsHistograms::hntriplets, _ntriplets);
_histos->fill1D(DiagnosticsHistograms::hntriplets_good, _ntriplets_good);
_histos->fill1D(DiagnosticsHistograms::hntriplets_2MCP, _ntriplets_2MCP);
_histos->fill1D(DiagnosticsHistograms::hntriplets_3MCP, _ntriplets_3MCP);
_histos->fill1D(DiagnosticsHistograms::hntriplets_1MCP_Bad, _ntriplets_1MCP_Bad);
_histos->fill1D(DiagnosticsHistograms::hntriplets_bad, _ntriplets_bad);
}
*/
/*
const edm4hep::MCParticleCollection* mcCol = nullptr;
try{
mcCol =_inMCColHdl.get();
}
catch(...){
}
if(mcCol){
int id = 0;
for(auto mcP : *mcCol){
float pos[3];
float mom[3];
pos[0] = mcP.vertex()[0];
pos[1] = mcP.vertex()[1];
pos[2] = mcP.vertex()[2];
mom[0] = mcP.momentum()[0];
mom[1] = mcP.momentum()[1];
mom[2] = mcP.momentum()[2];
float charge = mcP.getCharge();
HelixClass helix;
helix.Initialize_VP(pos,mom,charge,_bField);
float d0 = helix.getD0();
float z0 = helix.getZ0();
float omega = helix.getOmega();
float phi0 = helix.getPhi0();
float tanLambda = helix.getTanLambda();
std::cout <<"MCParticle: " << evtNo << " " << id << " " << sqrt(mom[0]*mom[0]+mom[1]*mom[1]) << " " << acos(mom[2]/sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2]))
<< " " << atan2(mom[1],mom[0])
<< " " << d0 << " " << phi0 << " " << omega << " " << z0 << " " << tanLambda << " " << mcP.vertex() << std::endl;
id++;
}
}
const edm4hep::TrackCollection* trkCol = nullptr;
try{
trkCol = _outColHdl.get();
}
catch(...){
}
if(trkCol){
int id = 0;
for(auto track : *trkCol){
int nstate = track->trackStates_size();
for(int i=0;i<nstate;i++){
edm4hep::TrackState trkState = track->getTrackStates(i);
if(trkState.location != 1) continue;
HelixClass helix_final;
helix_final.Initialize_Canonical(trkState.phi,trkState.D0,trkState.Z0,trkState.omega,trkState.tanLambda,_bField);
float trkPx = helix_final.getMomentum()[0];
float trkPy = helix_final.getMomentum()[1];
float trkPz = helix_final.getMomentum()[2];
float trkPt = sqrt(trkPx*trkPx+trkPy*trkPy);
std::cout << "Track parameter: " << evtNo << " " << id << " " << trkPt << " " << acos(trkPz/sqrt(trkPt*trkPt+trkPz*trkPz)) << " " << atan2(trkPy,trkPx)
<< " " << trkState.D0 << " " << trkState.phi << " " << trkState.omega << " " << trkState.Z0 << " " << trkState.tanLambda
<< " " << sqrt(trkState.covMatrix[0]) << " " << sqrt(trkState.covMatrix[2]) << " " << sqrt(trkState.covMatrix[5])
<< " " << sqrt(trkState.covMatrix[9]) << " " << sqrt(trkState.covMatrix[14]) << " " << std::endl;
id++;
break;
}
}
}
*/
CleanUp();
debug() << "Event is done " << endmsg;
_nEvt++;
return StatusCode::SUCCESS;
}
void SiliconTrackingAlg::CleanUp() {
_tracksWithNHitsContainer.clear();
for (int il=0;il<_nLayers;++il) {
for (int ip=0;ip<_nDivisionsInPhi;++ip) {
for (int it=0;it<_nDivisionsInTheta; ++it) {
unsigned int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it;
if( iCode >= _sectors.size()){
error() << "iCode index out of range: iCode = " << iCode << " _sectors.size() = " << _sectors.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< endmsg;
continue;
}
TrackerHitExtendedVec& hitVec = _sectors[iCode];
int nH = int(hitVec.size());
for (int iH=0; iH<nH; ++iH) {
TrackerHitExtended * hit = hitVec[iH];
delete hit;
}
}
}
}
for (int iS=0;iS<2;++iS) {
for (unsigned int layer=0;layer<_nlayersFTD;++layer) {
for (int ip=0;ip<_nPhiFTD;++ip) {
unsigned int iCode = iS + 2*layer + 2*_nlayersFTD*ip;
if( iCode >= _sectorsFTD.size()){
//error() << "iCode index out of range: iCode = " << iCode << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< endmsg;
continue;
}
TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode];
int nH = int(hitVec.size());
for (int iH=0; iH<nH; ++iH) {
TrackerHitExtended * hit = hitVec[iH];
delete hit;
}
}
}
}
_trackImplVec.clear();
_allHits.clear();
}
int SiliconTrackingAlg::InitialiseFTD() {
int success = 1;
_nTotalFTDHits = 0;
_sectorsFTD.clear();
_sectorsFTD.resize(2*_nlayersFTD*_nPhiFTD);
// Reading in FTD Pixel Hits Collection
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const edm4hep::TrackerHitCollection* hitFTDPixelCol = nullptr;
try {
hitFTDPixelCol = _inFTDPixelColHdl.get();
}
catch ( GaudiException &e ) {
debug() << "Collection " << _inFTDPixelColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
success = 0;
}
if(hitFTDPixelCol){
//LCCollection * hitCollection = evt->getCollection(_FTDPixelHitCollection.c_str());
//_colNamesTrackerHits[hitCollection] = _FTDPixelHitCollection;
// _colTrackerHits.push_back(hitCollection);
int nelem = hitFTDPixelCol->size();
debug() << "Number of FTD Pixel Hits = " << nelem << endmsg;
_nTotalFTDHits = nelem;
//for (int ielem=0; ielem<nelem; ++ielem) {
for(auto hit : *hitFTDPixelCol){
// edm4hep::TrackerHit* hit = hitFTDPixelCol->at(ielem);
TrackerHitExtended * hitExt = new TrackerHitExtended( hit );
//gear::Vector3D U(1.0,hit->getU()[1],hit->getU()[0],gear::Vector3D::spherical);
//gear::Vector3D V(1.0,hit->getV()[1],hit->getV()[0],gear::Vector3D::spherical);
gear::Vector3D U(1.0,hit.getCovMatrix()[1],hit.getCovMatrix()[0],gear::Vector3D::spherical);
gear::Vector3D V(1.0,hit.getCovMatrix()[4],hit.getCovMatrix()[3],gear::Vector3D::spherical);
gear::Vector3D Z(0.0,0.0,1.0);
const float eps = 1.0e-07;
// V must be the global z axis
if( fabs(V.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: VXD Hit measurment vectors V is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
if( fabs(U.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
// SJA:FIXME Here dU and dV are almost certainly dX and dY ... should test ...
//double point_res_rphi = sqrt( hit->getdU()*hit->getdU() + hit->getdV()*hit->getdV() );
double point_res_rphi = sqrt( hit.getCovMatrix()[2]*hit.getCovMatrix()[2] + hit.getCovMatrix()[5]*hit.getCovMatrix()[5] );
hitExt->setResolutionRPhi( point_res_rphi );
// SJA:FIXME why is this needed?
hitExt->setResolutionZ(0.1);
// type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse
hitExt->setType(int(INT_MAX));
// det is no longer used set to INT_MAX to try and catch any missuse
hitExt->setDet(int(INT_MAX));
double pos[3];
for (int i=0; i<3; ++i) {
pos[i] = hit.getPosition()[i];
}
double Phi = atan2(pos[1],pos[0]);
if (Phi < 0.) Phi = Phi + TWOPI;
// get the layer number
unsigned int layer = static_cast<unsigned int>(getLayerID(&hit));
unsigned int petalIndex = static_cast<unsigned int>(getModuleID(&hit));
if ( _petalBasedFTDWithOverlaps == true ) {
// as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z
// the layers will follow the even odd numbering of the petals
if ( petalIndex % 2 == 0 ) {
layer = 2*layer;
}
else {
layer = 2*layer + 1;
}
}
if (layer >= _nlayersFTD) {
error() << "SiliconTrackingAlg => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << endmsg;
exit(1);
}
int iPhi = int(Phi/_dPhiFTD);
int side = getSideID(&hit);
int iSemiSphere = 0;
if (side > 0)
iSemiSphere = 1;
int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi;
_sectorsFTD[iCode].push_back( hitExt );
debug() << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << endmsg;
}
}
// Reading out FTD SpacePoint Collection
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const edm4hep::TrackerHitCollection* hitFTDSpacePointCol = nullptr;
try {
hitFTDSpacePointCol = _inFTDSpacePointColHdl.get();
}
catch ( GaudiException &e ) {
debug() << "Collection " << _inFTDSpacePointColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
success = 0;
}
if(hitFTDSpacePointCol){
//LCCollection * hitCollection = evt->getCollection(_FTDSpacePointCollection.c_str());
//_colNamesTrackerHits[hitCollection] = _FTDSpacePointCollection;
//_colTrackerHits.push_back(hitCollection);
int nelem = hitFTDSpacePointCol->size();
debug() << "Number of FTD SpacePoints = " << nelem << endmsg;
_nTotalFTDHits += nelem;
//for (int ielem=0; ielem<nelem; ++ielem) {
for(auto hit : *hitFTDSpacePointCol){
//edm4hep::TrackerHit* hit = hitFTDSpacePointCol->at(ielem);
TrackerHitExtended * hitExt = new TrackerHitExtended(hit);
// SJA:FIXME: fudge for now by a factor of two and ignore covariance
double point_res_rphi = 2 * sqrt( hit.getCovMatrix()[0] + hit.getCovMatrix()[2] );
hitExt->setResolutionRPhi( point_res_rphi );
// SJA:FIXME why is this needed?
hitExt->setResolutionZ(0.1);
// type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse
hitExt->setType(int(INT_MAX));
// det is no longer used set to INT_MAX to try and catch any missuse
hitExt->setDet(int(INT_MAX));
double pos[3];
for (int i=0; i<3; ++i) {
pos[i] = hit.getPosition()[i];
}
double Phi = atan2(pos[1],pos[0]);
if (Phi < 0.) Phi = Phi + TWOPI;
// get the layer number
unsigned int layer = static_cast<unsigned int>(getLayerID(&hit));
unsigned int petalIndex = static_cast<unsigned int>(getModuleID(&hit));
if ( _petalBasedFTDWithOverlaps == true ) {
// as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z
// the layers will follow the even odd numbering of the petals
if ( petalIndex % 2 == 0 ) {
layer = 2*layer;
}
else {
layer = 2*layer + 1;
}
}
if (layer >= _nlayersFTD) {
error() << "SiliconTrackingAlg => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << endmsg;
exit(1);
}
int iPhi = int(Phi/_dPhiFTD);
int side = getSideID(&hit);
int iSemiSphere = 0;
if (side > 0)
iSemiSphere = 1;
int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi;
_sectorsFTD[iCode].push_back( hitExt );
debug() << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << endmsg;
}
}
for (unsigned i=0; i<_sectorsFTD.size(); ++i) {
int nhits = _sectorsFTD[i].size();
if( nhits != 0 ) debug() << " Number of Hits in FTD Sector " << i << " = " << _sectorsFTD[i].size() << endmsg;
if (nhits > _max_hits_per_sector) {
for (unsigned ihit=0; ihit<_sectorsFTD[i].size(); ++ihit) {
delete _sectorsFTD[i][ihit];
}
_sectorsFTD[i].clear();
if( nhits != 0 ) error() << " \n ### Number of Hits in FTD Sector " << i << " = " << nhits << " : Limit is set to " << _max_hits_per_sector << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << endmsg;
_output_track_col_quality = _output_track_col_quality_POOR;
}
}
debug() << "FTD initialized" << endmsg;
return success;
}
int SiliconTrackingAlg::InitialiseVTX() {
//std::cout << "fucd================" << std::endl;
_nTotalVTXHits = 0;
_nTotalSITHits = 0;
_sectors.clear();
_sectors.resize(_nLayers*_nDivisionsInPhi*_nDivisionsInTheta);
//std::cout << "fucd================" << std::endl;
int success = 1;
// Reading out VTX Hits Collection
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const edm4hep::TrackerHitCollection* hitVTXCol = nullptr;
try {
hitVTXCol = _inVTXColHdl.get();
}
catch ( GaudiException &e ) {
debug() << "Collection " << _inVTXColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
success = 0;
}
if(hitVTXCol){
//LCCollection * hitCollection = evt->getCollection(_VTXHitCollection.c_str());
//_colNamesTrackerHits[hitCollection] = _VTXHitCollection;
//_colTrackerHits.push_back(hitCollection);
//std::cout << "fucd================1" << std::endl;
int nelem = hitVTXCol->size();
//std::cout << "fucd================2" << std::endl;
debug() << "Number of VTX hits = " << nelem << endmsg;
_nTotalVTXHits = nelem;
for (int ielem=0; ielem<nelem; ++ielem) {
//for(auto hit : *hitVTXCol){
edm4hep::TrackerHit hit = hitVTXCol->at(ielem);
//_allHits.push_back(hit);
//gear::Vector3D U(1.0,hit->getU()[1],hit->getU()[0],gear::Vector3D::spherical);
//gear::Vector3D V(1.0,hit->getV()[1],hit->getV()[0],gear::Vector3D::spherical);
gear::Vector3D U(1.0,hit.getCovMatrix()[1],hit.getCovMatrix()[0],gear::Vector3D::spherical);
gear::Vector3D V(1.0,hit.getCovMatrix()[4],hit.getCovMatrix()[3],gear::Vector3D::spherical);
gear::Vector3D Z(0.0,0.0,1.0);
//debug() << "covMatrix : " << hit->getCovMatrix()[0] << " " << hit->getCovMatrix()[1] << endmsg;
const float eps = 1.0e-07;
// V must be the global z axis
if( fabs(1.0 - V.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: VXD Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
if( fabs(U.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
//std::cout << "fucd: " << &hit << " " << &_allHits.back() << std::endl;
//TrackerHitExtended * hitExt = new TrackerHitExtended( &_allHits.back() );
TrackerHitExtended * hitExt = new TrackerHitExtended(hit);
std::cout << "Saved TrackerHit pointer in TrackerHitExtended " << ielem << ": " << hitExt->getTrackerHit() << std::endl;
//std::cout << (&_allHits.back())->getPosition()[0] << " " << hit.getCovMatrix()[2] << " " << hit.getCovMatrix()[5] << std::endl;
// SJA:FIXME: just use planar res for now
hitExt->setResolutionRPhi(hit.getCovMatrix()[2]);
hitExt->setResolutionZ(hit.getCovMatrix()[5]);
// set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse
hitExt->setType(int(INT_MAX));
// det is no longer used set to INT_MAX to try and catch any missuse
hitExt->setDet(int(INT_MAX));
double pos[3];
double radius = 0;
for (int i=0; i<3; ++i) {
pos[i] = hit.getPosition()[i];
radius += pos[i]*pos[i];
}
radius = sqrt(radius);
double cosTheta = pos[2]/radius;
double Phi = atan2(pos[1],pos[0]);
if (Phi < 0.) Phi = Phi + TWOPI;
// get the layer number
int layer = getLayerID(&hit);
if (layer < 0 || layer >= _nLayers) {
error() << "SiliconTrackingAlg => fatal error in VTX : layer is outside allowed range : " << layer << endmsg;
exit(1);
}
int iPhi = int(Phi/_dPhi);
int iTheta = int ((cosTheta + double(1.0))/_dTheta);
int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta;
_sectors[iCode].push_back( hitExt );
debug() << " VXD Hit " << hit.id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << endmsg;
}
}
if (_useSIT > 0 ) {
const edm4hep::TrackerHitCollection* hitSITCol = nullptr;
try {
hitSITCol = _inSITColHdl.get();
}
catch ( GaudiException &e ) {
debug() << "Collection " << _inSITColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
success = 0;
}
if(hitSITCol){
//LCCollection *hitCollection = evt->getCollection(_SITHitCollection.c_str());
//_colNamesTrackerHits[hitCollection] = _SITHitCollection;
//_colTrackerHits.push_back(hitCollection);
int nelem = hitSITCol->size();
debug() << "Number of SIT hits = " << nelem << endmsg;
_nTotalSITHits = nelem;
//TrackerHit* trkhit = 0;
//TrackerHitPlane* trkhit_P = 0;
//TrackerHitZCylinder* trkhit_C = 0;
double drphi(NAN);
double dz(NAN);
//for (int ielem=0; ielem<nelem; ++ielem) {
for(auto trkhit : *hitSITCol){
// hit could be of the following type
// 1) TrackerHit, either ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT or just standard TrackerHit
// 2) TrackerHitPlane, either 1D or 2D
// 3) TrackerHitZCylinder, if coming from a simple cylinder design as in the LOI
// Establish which of these it is in the following order of likelyhood
// i) ILDTrkHitTypeBit::ONE_DIMENSIONAL (TrackerHitPlane) Should Never Happen: SpacePoints Must be Used Instead
// ii) ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT (TrackerHit)
// iii) TrackerHitPlane (Two dimentional)
// iv) TrackerHitZCylinder
// v) Must be standard TrackerHit
//const edm4hep::TrackerHit* trkhit = hitSITCol->at(ielem);
int layer = getLayerID(&trkhit);
// VXD and SIT are treated as one system so SIT layers start from _nLayersVTX
layer = layer + _nLayersVTX;
if (layer < 0 || layer >= _nLayers) {
error() << "SiliconTrackingAlg => fatal error in SIT : layer is outside allowed range : " << layer << endmsg;
exit(1);
}
// first check that we have not been given 1D hits by mistake, as they won't work here
if ( UTIL::BitSet32( trkhit.getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) {
error() << "SiliconTrackingAlg: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
// most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits
else if ( UTIL::BitSet32( trkhit.getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) {
// SJA:FIXME: fudge for now by a factor of two and ignore covariance
drphi = 2 * sqrt(trkhit.getCovMatrix()[0] + trkhit.getCovMatrix()[2]);
dz = sqrt(trkhit.getCovMatrix()[5]);
}
// or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above
// by fucd
//else if ( ( trkhit_P = dynamic_cast<TrackerHitPlane*>( hitCollection->getElementAt( ielem ) ) ) ) {
else if( UTIL::BitSet32( trkhit.getType() )[ 31 ]){
// first we need to check if the measurement vectors are aligned with the global coordinates
//gear::Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],gear::Vector3D::spherical);
//gear::Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],gear::Vector3D::spherical);
gear::Vector3D U(1.0,trkhit.getCovMatrix()[1],trkhit.getCovMatrix()[0],gear::Vector3D::spherical);
gear::Vector3D V(1.0,trkhit.getCovMatrix()[4],trkhit.getCovMatrix()[3],gear::Vector3D::spherical);
gear::Vector3D Z(0.0,0.0,1.0);
const float eps = 1.0e-07;
// V must be the global z axis
if( fabs(1.0 - V.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
// U must be normal to the global z axis
if( fabs(U.dot(Z)) > eps ) {
error() << "SiliconTrackingAlg: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << endmsg;
exit(1);
}
//drphi = trkhit_P->getdU();
//dz = trkhit_P->getdV();
drphi = trkhit.getCovMatrix()[2];
dz = trkhit.getCovMatrix()[5];
}
// or a simple cylindrical design, as used in the LOI
/* by fucd
else if ( ( trkhit_C = dynamic_cast<TrackerHitZCylinder*>( hitCollection->getElementAt( ielem ) ) ) ) {
drphi = trkhit_C->getdRPhi();
dz = trkhit_C->getdZ();
}
*/
// this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT
else {
// SJA:FIXME: fudge for now by a factor of two and ignore covariance
drphi = 2 * sqrt(trkhit.getCovMatrix()[0] + trkhit.getCovMatrix()[2]);
dz = sqrt(trkhit.getCovMatrix()[5]);
}
// now that the hit type has been established carry on and create a
TrackerHitExtended * hitExt = new TrackerHitExtended(trkhit);
// SJA:FIXME: just use planar res for now
hitExt->setResolutionRPhi(drphi);
hitExt->setResolutionZ(dz);
// set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse
hitExt->setType(int(INT_MAX));
// det is no longer used set to INT_MAX to try and catch any missuse
hitExt->setDet(int(INT_MAX));
double pos[3];
double radius = 0;
for (int i=0; i<3; ++i) {
pos[i] = trkhit.getPosition()[i];
radius += pos[i]*pos[i];
}
radius = sqrt(radius);
double cosTheta = pos[2]/radius;
double Phi = atan2(pos[1],pos[0]);
if (Phi < 0.) Phi = Phi + TWOPI;
int iPhi = int(Phi/_dPhi);
int iTheta = int ((cosTheta + double(1.0))/_dTheta);
int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta;
_sectors[iCode].push_back( hitExt );
debug() << " SIT Hit " << trkhit.id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << endmsg;
}
}
}
for (unsigned i=0; i<_sectors.size(); ++i) {
int nhits = _sectors[i].size();
if( nhits != 0 ) debug() << " Number of Hits in VXD/SIT Sector " << i << " = " << _sectors[i].size() << endmsg;
if (nhits > _max_hits_per_sector) {
for (unsigned ihit=0; ihit<_sectors[i].size(); ++ihit) {
delete _sectors[i][ihit];
}
_sectors[i].clear();
if( nhits != 0 ) error() << " \n ### Number of Hits in VXD/SIT Sector " << i << " = " << nhits << " : Limit is set to " << _max_hits_per_sector << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << endmsg;
_output_track_col_quality = _output_track_col_quality_POOR;
}
}
debug() << "VXD initialized" << endmsg;
return success;
}
StatusCode SiliconTrackingAlg::finalize(){
delete _fastfitter ; _fastfitter = 0;
delete _encoder ; _encoder = 0;
//delete _trksystem ; _trksystem = 0;
//delete _histos ; _histos = 0;
info() << "Processed " << _nEvt << " events " << endmsg;
return GaudiAlgorithm::finalize();
}
void SiliconTrackingAlg::ProcessOneSector(int iPhi, int iTheta) {
int counter = 0 ;
int iPhi_Up = iPhi + 1;
int iPhi_Low = iPhi - 1;
int iTheta_Up = iTheta + 1;
int iTheta_Low = iTheta - 1;
if (iTheta_Low < 0) iTheta_Low = 0;
if (iTheta_Up >= _nDivisionsInTheta) iTheta_Up = _nDivisionsInTheta-1;
int nComb = int( _Combinations.size() / 3 ); // number of triplet combinations
// std::cout << iPhi << " " << iTheta << " " << _nEvt << endmsg;
int iNC = 0;
for (int iComb=0; iComb < nComb; ++iComb) { // loop over triplets
int nLR[3];
for (int iS=0; iS<3; ++iS) {
nLR[iS] = _Combinations[iNC];
iNC++;
}
//std::cout << iPhi << " " << iTheta << " " << nLR[0] << " " << nLR[1] << " " << nLR[2] << " " << std::endl;
// index of theta-phi bin of outer most layer
int iCode = nLR[0] + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta;
//std::cout << "size of vector = " << _sectors.size() << " iCode = " << iCode << std::endl;
// get the all the hits in the outer most theta-phi bin
TrackerHitExtendedVec& hitVecOuter = _sectors[iCode];
int nHitsOuter = int(hitVecOuter.size());
if (nHitsOuter > 0) {
//std::cout << " " << iPhi << " " << iTheta << " " << nLR[0] << " " << nLR[1] << " " << nLR[2] << " size of vector = " << hitVecOuter.size() << std::endl;
for (int ipMiddle=iPhi_Low; ipMiddle<iPhi_Up+1;ipMiddle++) { // loop over phi in the Middle
for (int itMiddle=iTheta_Low; itMiddle<iTheta_Up+1;itMiddle++) { // loop over theta in the Middle
int iPhiMiddle = ipMiddle;
// catch wrap-around
if (ipMiddle < 0) iPhiMiddle = _nDivisionsInPhi-1;
if (ipMiddle >= _nDivisionsInPhi) iPhiMiddle = ipMiddle - _nDivisionsInPhi;
// index of current theta-phi bin of middle layer
iCode = nLR[1] + _nLayers*iPhiMiddle + _nLayers*_nDivisionsInPhi*itMiddle;
// get the all the hits in the current middle theta-phi bin
TrackerHitExtendedVec& hitVecMiddle = _sectors[iCode];
int nHitsMiddle = int(hitVecMiddle.size());
// determine which inner theta-phi bins to look in
int iPhiLowInner = iPhi_Low;
int iPhiUpInner = iPhi_Up;
int iThetaLowInner = iTheta_Low;
int iThetaUpInner = iTheta_Up;
// test to see if this is the core bin of the current search
// if so, look into the neigboring bins in the inner layer
if (ipMiddle == iPhi && itMiddle==iTheta) {
iPhiLowInner = iPhi_Low;
iPhiUpInner = iPhi_Up;
iThetaLowInner = iTheta_Low;
iThetaUpInner = iTheta_Up;
}
else {
int difP = abs(ipMiddle-iPhi); // number of phi bins from core: can only be 1 or 0 due to hard coded 1 above
int difT = abs(itMiddle-iTheta);// number of theta bins from core: can only be 1 or 0 due to hard coded 1 above
int minP = min(ipMiddle,iPhi); // min phi: core bin or current phi bin middle
int minT = min(itMiddle,iTheta); // min theta: core bin or current theta bin middle
int maxP = max(ipMiddle,iPhi); // max phi: core bin or current phi bin middle
int maxT = max(itMiddle,iTheta); // max theta: core bin or current theta bin middle
if (difP==1 && difT==1) { // if the diffence is a single bin in both phi and theta : only look in the bin adjacent to the core bin
iPhiLowInner = minP;
iPhiUpInner = maxP;
iThetaLowInner = minT;
iThetaUpInner = maxT;
}
if (difP==0) { // must be +/-1 theta : only look in bins adjacent to the middle bin
iPhiLowInner = iPhi_Low;
iPhiUpInner = iPhi_Up;
iThetaLowInner = minT;
iThetaUpInner = maxT;
}
if (difT==0) { // must be +/-1 phi : only look in bins adjacent to the middle bin
iPhiLowInner = minP;
iPhiUpInner = maxP;
iThetaLowInner = iTheta_Low;
iThetaUpInner = iTheta_Up;
}
}
if (nHitsMiddle > 0) { // look into inner bins
for (int ipInner=iPhiLowInner; ipInner<iPhiUpInner+1;ipInner++) { // loop over phi in the Inner
for (int itInner=iThetaLowInner; itInner<iThetaUpInner+1;itInner++) { // loop over theta in the Inner
int iPhiInner = ipInner;
// catch wrap-around
if (ipInner < 0) iPhiInner = _nDivisionsInPhi-1;
if (ipInner >= _nDivisionsInPhi) iPhiInner = ipInner - _nDivisionsInPhi;
iCode = nLR[2] + _nLayers*iPhiInner + _nLayers*_nDivisionsInPhi*itInner;
// get hit for inner bin
TrackerHitExtendedVec& hitVecInner = _sectors[iCode];
int nHitsInner = int(hitVecInner.size());
if (nHitsInner > 0) {
debug() << " "
<< std::setw(3) << iPhi << " " << std::setw(3) << ipMiddle << " " << std::setw(3) << ipInner << " "
<< std::setw(3) << iTheta << " " << std::setw(3) << itMiddle << " " << std::setw(3) << itInner << " "
<< std::setw(3) << nLR[0] << " " << std::setw(3) << nLR[1] << " " << std::setw(3) << nLR[2] << " "
<< std::setw(3) << nHitsOuter << " : " << std::setw(3) << nHitsMiddle << " : " << std::setw(3) << nHitsInner << " :: "
<< std::setw(3) << nHitsOuter*nHitsMiddle* nHitsInner << endmsg;
// test all triplets
for (int iOuter=0; iOuter<nHitsOuter; ++iOuter) { // loop over hits in the outer sector
TrackerHitExtended * outerHit = hitVecOuter[iOuter];
for (int iMiddle=0;iMiddle<nHitsMiddle;iMiddle++) { // loop over hits in the middle sector
TrackerHitExtended * middleHit = hitVecMiddle[iMiddle];
for (int iInner=0;iInner<nHitsInner;iInner++) { // loop over hits in the inner sector
TrackerHitExtended * innerHit = hitVecInner[iInner];
HelixClass helix;
//std::cout <<"fucd++++++++++++++++++++++1" << std::endl;
// test fit to triplet
TrackExtended * trackAR = TestTriplet(outerHit,middleHit,innerHit,helix);
//std::cout <<"fucd++++++++++++++++++++++2" << std::endl;
if ( trackAR != NULL ) {
int nHits = BuildTrack(outerHit,middleHit,innerHit,helix,nLR[2],
iPhiLowInner,iPhiUpInner,
iThetaLowInner,iThetaUpInner,trackAR);
_tracksWithNHitsContainer.getTracksWithNHitsVec(nHits).push_back(trackAR);
counter ++ ;
}
//std::cout <<"fucd++++++++++++++++++++++3" << std::endl;
} // endloop over hits in the inner sector
} // endloop over hits in the middle sector
} // endloop over hits in the outer sector
} // endif nHitsInner > 0
} // endloop over theta in the Inner
} // endloop over phi in the Inner
} // endif nHitsMiddle > 0
} // endloop over theta in the Middle
} // endloop over phi in the Middle
} // endif nHitsOuter > 0
} // endloop over triplets
//debug() << " process one sectector theta,phi " << iTheta << ", " << iPhi << " number of loops : " << counter << endmsg ;
}
TrackExtended * SiliconTrackingAlg::TestTriplet(TrackerHitExtended * outerHit,
TrackerHitExtended * middleHit,
TrackerHitExtended * innerHit,
HelixClass & helix) {
/*
Methods checks if the triplet of hits satisfies helix hypothesis
*/
//std::cout << "fucd================1" << std::endl;
// get the tracks already associated with the triplet
TrackExtendedVec& trackOuterVec = outerHit->getTrackExtendedVec();
TrackExtendedVec& trackMiddleVec = middleHit->getTrackExtendedVec();
TrackExtendedVec& trackInnerVec = innerHit->getTrackExtendedVec();
//std::cout << "fucd================2" << std::endl;
// check if all the hits are already assigned to a track
if ( (!trackOuterVec.empty()) && (!trackMiddleVec.empty()) && (!trackInnerVec.empty())) {
TrackExtendedVec::const_iterator middleEndIter = trackMiddleVec.end();
TrackExtendedVec::const_iterator outerEndIter = trackOuterVec.end();
TrackExtendedVec::const_iterator innerEndIter = trackInnerVec.end();
TrackExtendedVec::const_iterator outerBeginIter = trackOuterVec.begin();
TrackExtendedVec::const_iterator innerBeginIter = trackInnerVec.begin();
// loop over the tracks from the middle hit
for (TrackExtendedVec::const_iterator middleIter = trackMiddleVec.begin();
middleIter < middleEndIter;
++middleIter) {
// loop over the track from the outer hit
for (TrackExtendedVec::const_iterator outerIter = outerBeginIter;
outerIter < outerEndIter;
++outerIter) {
// if track from the outer and middle are not the same progress
if ( *outerIter != *middleIter ) continue;
// loop over the tracks from the inner hit
for (TrackExtendedVec::const_iterator innerIter = innerBeginIter;
innerIter < innerEndIter;
++innerIter) {
// no need to check against middle, it is idendical to outer here
if ( *outerIter == *innerIter ) {
// an existing track already contains all three hits
// return a null pointer
debug() << " TestTriplet: track " << *outerIter << " already contains all three hits: Do not create new track from these hits " << endmsg ;
return 0;
}
}// for inner
}// for outer
}// for middle
}// if all vectors are not empty
//std::cout << "fucd================3" << std::endl;
// float dZ = FastTripletCheck(innerHit, middleHit, outerHit);
// if (fabs(dZ) > _minDistCutAttach)
// return trackAR;
// increase triplet count
++_ntriplets;
// get the hit coordinates and errors
double xh[3];
double yh[3];
float zh[3];
double wrh[3];
float wzh[3];
float rh[3];
float ph[3];
float par[5];
float epar[15];
/*fucd
for(int i=0;i<_allHits.size();i++){
std::cout << &_allHits.at(i) << std::endl;
}
*/
// first hit
xh[0] = outerHit->getTrackerHit()->getPosition()[0];
yh[0] = outerHit->getTrackerHit()->getPosition()[1];
zh[0] = float(outerHit->getTrackerHit()->getPosition()[2]);
wrh[0] = double(1.0/(outerHit->getResolutionRPhi()*outerHit->getResolutionRPhi()));
wzh[0] = 1.0/(outerHit->getResolutionZ()*outerHit->getResolutionZ());
// second hit
xh[1] = middleHit->getTrackerHit()->getPosition()[0];
yh[1] = middleHit->getTrackerHit()->getPosition()[1];
zh[1] = float(middleHit->getTrackerHit()->getPosition()[2]);
wrh[1] = double(1.0/(middleHit->getResolutionRPhi()*middleHit->getResolutionRPhi()));
wzh[1] = 1.0/(middleHit->getResolutionZ()*middleHit->getResolutionZ());
// third hit
xh[2] = innerHit->getTrackerHit()->getPosition()[0];
yh[2] = innerHit->getTrackerHit()->getPosition()[1];
zh[2] = float(innerHit->getTrackerHit()->getPosition()[2]);
wrh[2] = double(1.0/(innerHit->getResolutionRPhi()*innerHit->getResolutionRPhi()));
wzh[2] = 1.0/(innerHit->getResolutionZ()*innerHit->getResolutionZ());
// calculate r and phi for all hits
for (int ih=0; ih<3; ih++) {
rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih]));
ph[ih] = atan2(yh[ih],xh[ih]);
if (ph[ih] < 0.)
ph[ih] = TWOPI + ph[ih];
}
int NPT = 3;
int iopt = 2;
float chi2RPhi;
float chi2Z;
debug() << " TestTriplet: Use fastHelixFit " << endmsg ;
_fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z);
par[3] = par[3]*par[0]/fabs(par[0]);
// get helix parameters
float omega = par[0];
float tanlambda = par[1];
float phi0 = par[2];
float d0 = par[3];
float z0 = par[4];
// chi2 is weighted here by a factor for both rphi and z
float Chi2 = chi2RPhi*_chi2WRPhiTriplet+chi2Z*_chi2WZTriplet;
int ndf = 2*NPT-5;
// check the truth information for the triplet
// define these outside of the ifdef so that we don't need to keep repeating it.
//std::vector<TrackerHit*> hit_list;
//std::vector<MCParticle*> mcps_imo;
//std::vector<MCParticle*> mcp_s;
int triplet_code = 0;
/*
#ifdef MARLINTRK_DIAGNOSTICS_ON
int nmcps = 0;
int nbadHits = 0;
int layer = 9 ;
int size = 3 ;
int marker = 1 ;
int ml = 0 ;
// float helix_max_r = 0;
float helix_max_z = 0;
int color = 0;
// use the MCTruth4HitExt to get the MCPs
hit_list.push_back(innerHit->getTrackerHit());
hit_list.push_back(middleHit->getTrackerHit());
hit_list.push_back(outerHit->getTrackerHit());
EVENT::MCParticle* mcp_i = 0;
EVENT::MCParticle* mcp_m = 0;
EVENT::MCParticle* mcp_o = 0;
for (unsigned ihit = 0; ihit < hit_list.size(); ++ihit) {
EVENT::TrackerHit* trkhit = hit_list[ihit];
std::vector<MCParticle*> mcps;
MarlinTrk::getMCParticlesForTrackerHit(trkhit, mcps);
if (mcps.size() == 1) {
mcps_imo.push_back(mcps[0]);
++nmcps;
} else {
mcps_imo.push_back(0);
++nbadHits;
}
}
mcp_i = mcps_imo[0];
mcp_m = mcps_imo[1];
mcp_o = mcps_imo[2];
debug()
<< "\n mcp_i = " << mcp_i
<< "\n mcp_m = " << mcp_m
<< "\n mcp_o = " << mcp_o
<< endmsg;
if( mcp_i ) {
mcp_s.push_back(mcp_i) ;
}
if( mcp_m && mcp_m != mcp_i ) {
mcp_s.push_back(mcp_m);
}
if( mcp_o && mcp_o != mcp_m && mcp_o != mcp_i ){
mcp_s.push_back(mcp_o);
}
nmcps = mcp_s.size();
if (_UseEventDisplay) {
// display this triplet and the MCPs from which it is formed
MarlinCED::newEvent(this , _detector_model_for_drawing ) ;
// CEDPickingHandler &pHandler=CEDPickingHandler::getInstance();
//
// pHandler.update(_current_event);
for (unsigned imcp = 0; imcp < mcp_s.size(); ++imcp) {
MCParticle* mcp = mcp_s[imcp];
helix_max_z = fabsf(mcp->getEndpoint()[2]);
info() << "Draw MCParticle : " << *mcp <<endmsg;
MarlinCED::add_layer_description("MCParticle_For_Fit", layer);
MarlinCED::drawHelix( _bField , mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2],
mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer , size , 0x7af774 ,
0.0, _helix_max_r ,
helix_max_z, mcp->id() ) ;
}
const std::string colName = "Hits_For_Fit";
size = 10 ;
layer = 11 ;
// ml = marker | ( layer << CED_LAYER_SHIFT ) ;
//ced_describe_layer( colName.c_str() ,layer);
MarlinCED::add_layer_description(colName, layer);
color = 0xFFFFFF;
for( std::vector<TrackerHit* >::const_iterator it = hit_list.begin(); it != hit_list.end() ; it++ ) {
TrackerHit* trkhit = *it;
ced_hit_ID(trkhit->getPosition()[0],
trkhit->getPosition()[1],
trkhit->getPosition()[2],
marker, layer, size , color, trkhit->id() ) ;
} // hits
}
if (_createDiagnosticsHistograms) {
// if no bad hits are present triplet_code = nmcps;
triplet_code = nmcps + nbadHits * 3 ;
_histos->fill1D(DiagnosticsHistograms::htriplets, triplet_code);
double pt = (2.99792458E-4*_bField) / omega ; // for r in mm, p in GeV and Bz in Tesla
if (triplet_code == 1) {
++_ntriplets_good;
_histos->fill2D(DiagnosticsHistograms::htripletChi2vPt_good, pt, Chi2 );
_histos->fill1D(DiagnosticsHistograms::htriplets_chi2_good, Chi2 );
_histos->fill1D(DiagnosticsHistograms::htriplets_pt_good, pt );
} else {
_histos->fill2D(DiagnosticsHistograms::htripletChi2vPt_bad, pt, Chi2);
_histos->fill1D(DiagnosticsHistograms::htriplets_chi2_bad, Chi2 );
_histos->fill1D(DiagnosticsHistograms::htriplets_pt_bad, pt );
if(triplet_code == 2) {
++_ntriplets_2MCP;
} else if (triplet_code == 3) {
++_ntriplets_3MCP;
} else if (triplet_code == 4) {
++_ntriplets_1MCP_Bad;
} else {
++_ntriplets_bad;
}
}
}
#endif
*/
// Check if track satisfies all conditions
// std::cout << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << endmsg;
// std::cout << "d0 = " << d0 << " , cut = " << _cutOnD0 << endmsg;
// std::cout << "z0 = " << z0 << " , cut = " << _cutOnZ0 << endmsg;
// std::cout << "omega = " << omega << " , cut = " << _cutOnOmega << endmsg;
// if ( Chi2/float(ndf) > _chi2FitCut || fabs(d0) > _cutOnD0 || fabs(z0) > _cutOnZ0 || fabs(omega)>_cutOnOmega)
// return a null pointer
// return 0;
bool failed = false;
int quality_code = triplet_code * 10 ;
if ( Chi2/float(ndf) > _chi2FitCut ) {
debug() << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << endmsg;
failed = true;
quality_code += 1;
} else if (fabs(d0) > _cutOnD0 ) {
debug() << "d0 = " << d0 << " , cut = " << _cutOnD0 << endmsg;
failed = true;
quality_code += 2;
} else if (fabs(z0) > _cutOnZ0 ) {
debug() << "z0 = " << z0 << " , cut = " << _cutOnZ0 << endmsg;
failed = true;
quality_code += 3;
} else if ( fabs(omega)>_cutOnOmega) {
debug() << "omega = " << omega << " , cut = " << _cutOnOmega << endmsg;
failed = true;
quality_code += 4;
} else {
debug() << "Success !!!!!!!" << endmsg;
}
/*
if (_createDiagnosticsHistograms) _histos->fill1D(DiagnosticsHistograms::htriplets, quality_code);
if (_UseEventDisplay) {
drawEvent();
}
*/
if( failed ) {
// return a null pointer
return 0;
}
helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField);
TrackExtended * trackAR = new TrackExtended();
trackAR->addTrackerHitExtended(outerHit);
trackAR->addTrackerHitExtended(middleHit);
trackAR->addTrackerHitExtended(innerHit);
outerHit->addTrackExtended(trackAR);
middleHit->addTrackExtended(trackAR);
innerHit->addTrackExtended(trackAR);
trackAR->setD0(d0);
trackAR->setZ0(z0);
trackAR->setPhi(phi0);
trackAR->setTanLambda(tanlambda);
trackAR->setOmega(omega);
trackAR->setChi2( Chi2 );
trackAR->setNDF( ndf );
trackAR->setCovMatrix(epar);
return trackAR;
}
int SiliconTrackingAlg::BuildTrack(TrackerHitExtended * outerHit,
TrackerHitExtended * middleHit,
TrackerHitExtended * innerHit,
HelixClass & helix,
int innerLayer,
int iPhiLow, int iPhiUp,
int iThetaLow, int iThetaUp,
TrackExtended * trackAR) {
/**
Method for building up track in the VXD. Method starts from the found triplet and performs
sequential attachment of hits in other layers, which have hits within the search window.
Only searches inwards.
Given that we know we are now jumping over layers due to the doublet nature of the VXD, we
could optimise this to look for the hits in interleaving layers as well.
Currently a fast fit is being done for each additional hit, it could be more efficient to try and use kaltest?
*/
debug() << " BuildTrack starting " << endmsg;
for (int layer = innerLayer-1; layer>=0; layer--) { // loop over remaining layers
float distMin = 1.0e+20;
TrackerHitExtended * assignedhit = NULL;
//std::cout << "fucd---------------------1" << std::endl;
// loop over phi in the Inner region
for (int ipInner=iPhiLow; ipInner<iPhiUp+1;ipInner++) {
// loop over theta in the Inner region
for (int itInner=iThetaLow; itInner<iThetaUp+1;itInner++) {
int iPhiInner = ipInner;
// catch wrap-around
if (ipInner < 0) iPhiInner = _nDivisionsInPhi-1;
if (ipInner >= _nDivisionsInPhi) iPhiInner = ipInner - _nDivisionsInPhi;
// get the index of the theta-phi bin to search
int iCode = layer + _nLayers*iPhiInner + _nLayers*_nDivisionsInPhi*itInner;
// get the hits from this bin
TrackerHitExtendedVec& hitVecInner = _sectors[iCode];
int nHitsInner = int(hitVecInner.size());
// loop over hits in the Inner sector
for (int iInner=0;iInner<nHitsInner;iInner++) {
TrackerHitExtended * currentHit = hitVecInner[iInner];
// get the position of the hit to test
float pos[3];
float distance[3];
for (int i=0; i<3; ++i) {
pos[i] = float(currentHit->getTrackerHit()->getPosition()[i]);
}
// get the distance of closest approach and distance s traversed to the POCA
float time = helix.getDistanceToPoint(pos,distance);
// sanity check on s
if (time < 1.0e+10) {
// check if this is the closest hit yet
if (distance[2] < distMin) { // distance[2] = sqrt( d0*d0 + z0*z0 )
// if yes store hit and distance
distMin = distance[2];
assignedhit = currentHit;
}
}
} // endloop over hits in the Inner sector
} // endloop over theta in the Inner region
} // endloop over phi in the Inner region
//std::cout << "fucd---------------------2" << std::endl;
// check if closest hit fulfills the min distance cut
if (distMin < _minDistCutAttach) {
// if yes try to include it in the fit
TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec();
int nHits = int(hvec.size());
double * xh = new double[nHits+1];
double * yh = new double[nHits+1];
float * zh = new float[nHits+1];
double * wrh = new double[nHits+1];
float * wzh = new float[nHits+1];
float * rh = new float[nHits+1];
float * ph = new float[nHits+1];
float par[5];
float epar[15];
for (int ih=0;ih<nHits;++ih) {
edm4hep::TrackerHit * trkHit = hvec[ih]->getTrackerHit();
xh[ih] = trkHit->getPosition()[0];
yh[ih] = trkHit->getPosition()[1];
zh[ih] = float(trkHit->getPosition()[2]);
wrh[ih] = double(1.0/(hvec[ih]->getResolutionRPhi()*hvec[ih]->getResolutionRPhi()));
wzh[ih] = 1.0/(hvec[ih]->getResolutionZ()*hvec[ih]->getResolutionZ());
rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih]));
ph[ih] = float(atan2(yh[ih],xh[ih]));
if (ph[ih] < 0.)
ph[ih] = TWOPI + ph[ih];
}
edm4hep::TrackerHit * assignedTrkHit = assignedhit->getTrackerHit();
xh[nHits] = assignedTrkHit->getPosition()[0];
yh[nHits] = assignedTrkHit->getPosition()[1];
zh[nHits] = float(assignedTrkHit->getPosition()[2]);
rh[nHits] = float(sqrt(xh[nHits]*xh[nHits]+yh[nHits]*yh[nHits]));
ph[nHits] = float(atan2(yh[nHits],xh[nHits]));
if (ph[nHits] < 0.)
ph[nHits] = TWOPI + ph[nHits];
wrh[nHits] = double(1.0/(assignedhit->getResolutionRPhi()*assignedhit->getResolutionRPhi()));
wzh[nHits] = 1.0/(assignedhit->getResolutionZ()*assignedhit->getResolutionZ());
int NPT = nHits + 1;
int iopt = 2;
float chi2RPhi;
float chi2Z;
// std::cout << "######## number of hits to fit with _fastfitter = " << NPT << endmsg;
_fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z);
par[3] = par[3]*par[0]/fabs(par[0]);
delete[] xh;
delete[] yh;
delete[] zh;
delete[] wrh;
delete[] wzh;
delete[] rh;
delete[] ph;
bool validCombination = 0;
float Chi2 = FLT_MAX;
if ((nHits+1) == 4) {
Chi2 = chi2RPhi*_chi2WRPhiQuartet+chi2Z*_chi2WZQuartet;
}
if ((nHits+1) >= 5) {
Chi2 = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet;
}
int ndf = 2*NPT-5;
// check if this is valid combination based on the chi2/ndf
validCombination = Chi2/float(ndf) < _chi2FitCut;
if ( validCombination ) {
// assign hit to track and track to hit, update the track parameters
trackAR->addTrackerHitExtended(assignedhit);
assignedhit->addTrackExtended(trackAR);
float omega = par[0];
float tanlambda = par[1];
float phi0 = par[2];
float d0 = par[3];
float z0 = par[4];
helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField);
trackAR->setD0(d0);
trackAR->setZ0(z0);
trackAR->setPhi(phi0);
trackAR->setTanLambda(tanlambda);
trackAR->setOmega(omega);
trackAR->setChi2( Chi2 );
trackAR->setCovMatrix(epar);
trackAR->setNDF( ndf );
}
}
} // endloop over remaining layers
//std::cout << "fucd---------------------3" << std::endl;
TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec();
int nTotalHits = int(hvec.size());
// std::cout << "######## number of hits to return = " << nTotalHits << endmsg;
return nTotalHits;
}
void SiliconTrackingAlg::Sorting(TrackExtendedVec & trackVec) {
/**
Sorting of Track Vector in ascending order of chi2/ndf
*/
std::sort(trackVec.begin(), trackVec.end(), compare_TrackExtended() );
// also clean up? what does this do here?
for (size_t i=0, sizeOfVector=trackVec.size(); i<sizeOfVector; ++i) {
TrackerHitExtendedVec& hitVec = trackVec[i]->getTrackerHitExtendedVec();
int nHits = int(hitVec.size());
for (int ih=0;ih<nHits;ih++) {
hitVec[ih]->clearTrackVec();
}
}
}
void SiliconTrackingAlg::CreateTrack(TrackExtended * trackAR ) {
/**
Method which creates Track out of TrackExtended objects. Checks for possible
track splitting (separate track segments in VXD and FTD).
*/
TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec();
int nHits = int(hitVec.size());
for (int i=0; i<nHits; ++i) {
TrackExtendedVec& trackVec = hitVec[i]->getTrackExtendedVec();
if (trackVec.size() != 0)
return ;
}
// First check if the current track is piece of the split one
// look for matching track segment
int found = 0;
int nTrk = int(_trackImplVec.size());
for (int itrk=0; itrk<nTrk; ++itrk) {
TrackExtended * trackOld = _trackImplVec[itrk];
TrackerHitExtendedVec& hitVecOld = trackOld->getTrackerHitExtendedVec();
float phiNew = trackAR->getPhi();
float phiOld = trackOld->getPhi();
float thetaNew = M_PI_2 - atan(trackAR->getTanLambda());
float thetaOld = M_PI_2 - atan(trackOld->getTanLambda());
float angle = (cos(phiNew)*cos(phiOld)+sin(phiNew)*sin(phiOld))*sin(thetaNew)*sin(thetaOld)+cos(thetaNew)*cos(thetaOld);
angle = acos(angle);
if (angle < _angleCutForMerging) {
int nHitsOld = int(hitVecOld.size());
int nTotHits = nHits + nHitsOld;
double * xh = new double[nTotHits];
double * yh = new double[nTotHits];
float * zh = new float[nTotHits];
double * wrh = new double[nTotHits];
float * wzh = new float[nTotHits];
float * rh = new float[nTotHits];
float * ph = new float[nTotHits];
float par[5];
float epar[15];
float refPoint[3] = {0.,0.,0.};
for (int ih=0;ih<nHits;++ih) {
edm4hep::TrackerHit * trkHit = hitVec[ih]->getTrackerHit();
float rR = hitVec[ih]->getResolutionRPhi();
float rZ = hitVec[ih]->getResolutionZ();
if (int(hitVec[ih]->getTrackExtendedVec().size()) != 0)
debug() << "WARNING : HIT POINTS TO TRACK " << endmsg;
xh[ih] = trkHit->getPosition()[0];
yh[ih] = trkHit->getPosition()[1];
zh[ih] = float(trkHit->getPosition()[2]);
wrh[ih] = double(1.0/(rR*rR));
wzh[ih] = 1.0/(rZ*rZ);
rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih]));
ph[ih] = float(atan2(yh[ih],xh[ih]));
}
for (int ih=0;ih<nHitsOld;++ih) {
edm4hep::TrackerHit * trkHit = hitVecOld[ih]->getTrackerHit();
xh[ih+nHits] = trkHit->getPosition()[0];
yh[ih+nHits] = trkHit->getPosition()[1];
zh[ih+nHits] = float(trkHit->getPosition()[2]);
float rR = hitVecOld[ih]->getResolutionRPhi();
float rZ = hitVecOld[ih]->getResolutionZ();
wrh[ih+nHits] = double(1.0/(rR*rR));
wzh[ih+nHits] = 1.0/(rZ*rZ);
rh[ih+nHits] = float(sqrt(xh[ih+nHits]*xh[ih+nHits]+yh[ih+nHits]*yh[ih+nHits]));
ph[ih+nHits] = float(atan2(yh[ih+nHits],xh[ih+nHits]));
}
int NPT = nTotHits;
int iopt = 2;
float chi2RPhi;
float chi2Z;
int ndf = 2*NPT - 5;
_fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z);
par[3] = par[3]*par[0]/fabs(par[0]);
float omega = par[0];
float tanlambda = par[1];
float phi0 = par[2];
float d0 = par[3];
float z0 = par[4];
float eparmin[15];
for (int iparam=0;iparam<15;++iparam)
eparmin[iparam] = epar[iparam];
float refPointMin[3];
for (int ipp=0;ipp<3;++ipp)
refPointMin[ipp] = refPoint[ipp];
float chi2Min = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet;
chi2Min = chi2Min/float(ndf);
float chi2MinRPhi = chi2RPhi;
float chi2MinZ = chi2Z;
int iBad = -1;
if (chi2Min < _chi2FitCut) {
found = 1;
}
else { // SJA:FIXME: UH What is going on here? setting weights to 0 and refitting?
float * wzhOld = new float[nTotHits];
double * wrhOld = new double[nTotHits];
for (int i=0;i<nTotHits;++i) {
wzhOld[i] = wzh[i];
wrhOld[i] = wrh[i];
}
for (int i=0; i<nTotHits; ++i) {
for (int j=0;j<nTotHits;++j) {
if (i == j) {
wrh[j] = 0.0;
wzh[j] = 0.0;
}
else {
wrh[j] = wrhOld[j];
wzh[j] = wzhOld[j];
}
}
_fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z);
par[3] = par[3]*par[0]/fabs(par[0]);
float chi2Cur = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet;
chi2Cur = chi2Cur/float(ndf);
if (chi2Cur < chi2Min) {
chi2Min = chi2Cur;
chi2MinRPhi = chi2RPhi;
chi2MinZ = chi2Z;
omega = par[0];
tanlambda = par[1];
phi0 = par[2];
d0 = par[3];
z0 = par[4];
for (int iparam=0;iparam<15;++iparam)
eparmin[iparam] = epar[iparam];
for (int ipp=0;ipp<3;++ipp)
refPointMin[ipp] = refPoint[ipp];
iBad = i;
}
}
if (chi2Min < _chi2FitCut) {
found = 1;
}
delete[] wzhOld;
delete[] wrhOld;
}
// Split track is found.
// Attach hits belonging to the current track segment to
// the track already created
if (found == 1) {
trackOld->ClearTrackerHitExtendedVec();
for (int i=0;i<nHits;++i) {
TrackerHitExtended * trkHit = hitVec[i];
trkHit->clearTrackVec();
if (i == iBad) {
}
else {
trackOld->addTrackerHitExtended(trkHit);
trkHit->addTrackExtended( trackOld );
}
}
for (int i=0;i<nHitsOld;++i) {
int icur = i+nHits;
TrackerHitExtended * trkHit = hitVecOld[i];
trkHit->clearTrackVec();
if (icur == iBad) {
}
else {
trackOld->addTrackerHitExtended(trkHit);
trkHit->addTrackExtended( trackOld );
}
}
trackOld->setOmega(omega);
trackOld->setTanLambda(tanlambda);
trackOld->setPhi(phi0);
trackOld->setD0(d0);
trackOld->setZ0(z0);
// std::cout << "Split track found " << d0 << " " << z0 << endmsg;
// killeb: In the original SiliconTrackingAlg this was in the NOT simple helix branch.
// The rest of the code uses the simple helix branch, where ndf_D is never set.
// In fact it has never been initialised or used anywhere. I think this line should not be executed.
// ndf = ndf_D;
trackOld->setChi2(chi2Min*float(ndf));
trackOld->setNDF(ndf);
trackOld->setCovMatrix(eparmin);
// trackOld->setReferencePoint(refPointMin);
}
delete[] xh;
delete[] yh;
delete[] zh;
delete[] wrh;
delete[] wzh;
delete[] rh;
delete[] ph;
}
if (found == 1)
break;
}
// Candidate is a unique track
// No other segments are found
if (found == 0 ) {
_trackImplVec.push_back(trackAR);
for (int i=0;i<nHits;++i) {
TrackerHitExtended * hit = hitVec[i];
hit->addTrackExtended( trackAR );
}
}
}
void SiliconTrackingAlg::AttachRemainingVTXHitsFast() {
std::vector<TrackerHitExtendedVec> nonAttachedHits;
nonAttachedHits.resize(_nDivisionsInPhi*_nDivisionsInTheta);
std::vector<TrackExtendedVec> trackVector;
trackVector.resize(_nDivisionsInPhi*_nDivisionsInTheta);
int nTracks = int(_trackImplVec.size());
for (int iTrk=0;iTrk<nTracks;++iTrk) {
TrackExtended * track = _trackImplVec[iTrk];
double Phi = double(track->getPhi());
if (Phi < 0)
Phi = Phi + TWOPI;
float tanlambda = track->getTanLambda();
double cosTheta = double(tanlambda/sqrt(1+tanlambda*tanlambda));
int iPhi = int(Phi/_dPhi);
int iTheta = int ((cosTheta + double(1.0))/_dTheta);
int iCode = iPhi + _nDivisionsInPhi*iTheta;
trackVector[iCode].push_back( track );
}
for (int il=0;il<_nLayers;++il) {
for (int ip=0;ip<_nDivisionsInPhi;++ip) {
for (int it=0;it<_nDivisionsInTheta; ++it) {
int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it;
TrackerHitExtendedVec& hitVec = _sectors[iCode];
int nH = int(hitVec.size());
for (int iH=0; iH<nH; ++iH) {
TrackerHitExtended * hitExt = hitVec[iH];
TrackExtendedVec& trackVec = hitExt->getTrackExtendedVec();
if (trackVec.size()==0) {
edm4hep::TrackerHit * hit = hitExt->getTrackerHit();
double pos[3];
double radius = 0;
for (int i=0; i<3; ++i) {
pos[i] = hit->getPosition()[i];
radius += pos[i]*pos[i];
}
radius = sqrt(radius);
double cosTheta = pos[2]/radius;
double Phi = atan2(pos[1],pos[0]);
if (Phi < 0.) Phi = Phi + TWOPI;
int iPhi = int(Phi/_dPhi);
int iTheta = int ((cosTheta + double(1.0))/_dTheta);
iCode = iPhi + _nDivisionsInPhi*iTheta;
nonAttachedHits[iCode].push_back( hitExt );
}
}
}
}
}
for (int iT=0; iT<_nDivisionsInTheta; ++iT) {
for (int iP=0; iP<_nDivisionsInPhi; ++iP) {
int iCode = iP + _nDivisionsInPhi*iT;
int nHits = int(nonAttachedHits[iCode].size());
int iT1 = iT - 1;
int iT2 = iT + 1;
if (iT == 0) {
iT1 = iT;
iT2 = iT1 + 1;
}
if (iT == _nDivisionsInTheta - 1) {
iT2 = iT;
iT1 = iT2 - 1;
}
int iPHI[3];
iPHI[0] = iP - 1;
iPHI[1] = iP;
iPHI[2] = iP + 1;
if (iP == 0)
iPHI[0] = _nDivisionsInPhi - 1;
if (iP == _nDivisionsInPhi - 1 )
iPHI[2] = 0;
for (int ihit = 0; ihit<nHits; ++ihit) {
TrackerHitExtended * hit = nonAttachedHits[iCode][ihit];
TrackExtended * trackToAttach = NULL;
float minDist = 1.0e+6;
for (int iTheta = iT1; iTheta <iT2+1; ++iTheta) {
for (int indexP=0;indexP<3;++indexP) {
int iPhi = iPHI[indexP];
int iCodeForTrack = iPhi + _nDivisionsInPhi*iTheta;
int nTrk = int(trackVector[iCodeForTrack].size());
for (int iTrk=0; iTrk<nTrk; ++iTrk) {
TrackExtended * trackAR = trackVector[iCodeForTrack][iTrk];
bool consider = true;
if (_checkForDelta) {
TrackerHitExtendedVec& hitVector = trackAR->getTrackerHitExtendedVec();
int NHITS = int(hitVector.size());
for (int IHIT=0;IHIT<NHITS;++IHIT) {
// Here we are trying to find if a hits are too close i.e. closer than _minDistToDelta
edm4hep::TrackerHit* trkhit1 = hit->getTrackerHit();
edm4hep::TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit();
if ( trkhit1->getCellID() == trkhit2->getCellID() ){ // i.e. they are in the same sensor
float distance = 0.;
for (int iC=0;iC<3;++iC) {
float posFirst = float(hit->getTrackerHit()->getPosition()[iC]);
float posSecond = float(hitVector[IHIT]->getTrackerHit()->getPosition()[iC]);
float deltaPos = posFirst - posSecond;
distance += deltaPos*deltaPos;
}
distance = sqrt(distance);
if (distance<_minDistToDelta) {
consider = false;
break;
}
}
}
}
if (consider) {
float phi0 = trackAR->getPhi();
float d0 = trackAR->getD0();
float z0 = trackAR->getZ0();
float omega = trackAR->getOmega();
float tanlambda = trackAR->getTanLambda();
HelixClass helix;
helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField);
int layer = getLayerID(hit->getTrackerHit());
if (layer > _minimalLayerToAttach) {
float pos[3];
for (int i=0; i<3; ++i)
pos[i] = hit->getTrackerHit()->getPosition()[i];
float distance[3];
float time = helix.getDistanceToPoint(pos,distance);
if (time < 1.0e+10) {
if (distance[2] < minDist) {
minDist = distance[2];
trackToAttach = trackAR;
}
}
}
}
}
}
}
if (minDist < _minDistCutAttach && trackToAttach != NULL) {
int iopt = 2;
AttachHitToTrack(trackToAttach,hit,iopt);
}
}
}
}
}
void SiliconTrackingAlg::AttachRemainingVTXHitsSlow() {
TrackerHitExtendedVec nonAttachedHits;
nonAttachedHits.clear();
for (int il=0;il<_nLayers;++il) {
for (int ip=0;ip<_nDivisionsInPhi;++ip) {
for (int it=0;it<_nDivisionsInTheta; ++it) {
int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it;
TrackerHitExtendedVec& hitVec = _sectors[iCode];
int nH = int(hitVec.size());
for (int iH=0; iH<nH; ++iH) {
TrackerHitExtended * hit = hitVec[iH];
TrackExtendedVec& trackVec = hit->getTrackExtendedVec();
// if (trackVec.size()==0)
// nonAttachedHits.push_back( hit );
//-- allow hits that are only used in triplets to be re-attached
unsigned int maxTrackSize = 0;
for(unsigned int itrack = 0;itrack < trackVec.size();itrack++){
TrackerHitExtendedVec hitVec_tmp= trackVec[itrack]->getTrackerHitExtendedVec();
unsigned int isize = hitVec_tmp.size();
if(isize>maxTrackSize)maxTrackSize = isize;
}
if (maxTrackSize<=3) {
debug() << " Add non attached hit to list: id = " << hit->getTrackerHit()->id() << endmsg;
nonAttachedHits.push_back( hit );
}
}
}
}
}
int nNotAttached = int(nonAttachedHits.size());
int nTrk = int(_trackImplVec.size());
for (int iHit=0; iHit<nNotAttached; ++iHit) {
TrackerHitExtended * hit = nonAttachedHits[iHit];
debug() << " Try hit: id = " << hit->getTrackerHit()->id() << endmsg;
int layer = getLayerID( hit->getTrackerHit() );
if (layer > _minimalLayerToAttach) {
float pos[3];
for (int i=0; i<3; ++i)
pos[i] = hit->getTrackerHit()->getPosition()[i];
float minDist = 1e+10;
TrackExtended * trackToAttach = NULL;
for (int iTrk=0; iTrk<nTrk; ++iTrk) {
TrackExtended * trackAR = _trackImplVec[iTrk];
bool consider = true;
if (_checkForDelta) {
TrackerHitExtendedVec& hitVector = trackAR->getTrackerHitExtendedVec();
int NHITS = int(hitVector.size());
for (int IHIT=0;IHIT<NHITS;++IHIT) {
// Here we are trying to find if a hits are too close i.e. closer than _minDistToDelta
edm4hep::TrackerHit* trkhit1 = hit->getTrackerHit();
edm4hep::TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit();
if ( trkhit1->getCellID() == trkhit2->getCellID() ){ // i.e. they are in the same sensor
float distance = 0.;
for (int iC=0;iC<3;++iC) {
float posFirst = float(hit->getTrackerHit()->getPosition()[iC]);
float posSecond = float(hitVector[IHIT]->getTrackerHit()->getPosition()[iC]);
float deltaPos = posFirst - posSecond;
distance += deltaPos*deltaPos;
}
distance = sqrt(distance);
if (distance<_minDistToDelta) {
consider = false;
debug() << " hit: id = " << hit->getTrackerHit()->id() << " condsidered delta together with hit " << trkhit2->id() << endmsg;
break;
}
}
}
}
if (consider) {
HelixClass helix;
float phi0 = trackAR->getPhi();
float d0 = trackAR->getD0();
float z0 = trackAR->getZ0();
float omega = trackAR->getOmega();
float tanlambda = trackAR->getTanLambda();
helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField);
float distance[3];
float time = helix.getDistanceToPoint(pos,distance);
if (time < 1.0e+10) {
if (distance[2] < minDist) {
minDist = distance[2];
trackToAttach = trackAR;
}
}
}
}
if (minDist < _minDistCutAttach && trackToAttach != NULL) {
int iopt = 2;
debug() << " Hit: id = " << hit->getTrackerHit()->id() << " : try attachement"<< endmsg;
AttachHitToTrack(trackToAttach,hit,iopt);
} else {
debug() << " Hit: id = " << hit->getTrackerHit()->id() << " rejected due to distance cut of " <<_minDistCutAttach<< " min distance = " << minDist << endmsg;
}
}
}
}
void SiliconTrackingAlg::AttachRemainingFTDHitsSlow() {
TrackerHitExtendedVec nonAttachedHits;
nonAttachedHits.clear();
for (int iS=0;iS<2;++iS) {
for (unsigned int layer=0;layer<_nlayersFTD;++layer) {
for (int ip=0;ip<_nPhiFTD;++ip) {
int iCode = iS + 2*layer + 2*_nlayersFTD*ip;
TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode];
int nH = int(hitVec.size());
for (int iH=0; iH<nH; ++iH) {
TrackerHitExtended * hit = hitVec[iH];
TrackExtendedVec& trackVec = hit->getTrackExtendedVec();
if (trackVec.size()==0)
nonAttachedHits.push_back( hit );
}
}
}
}
int nNotAttached = int(nonAttachedHits.size());
int nTrk = int(_trackImplVec.size());
for (int iHit=0; iHit<nNotAttached; ++iHit) {
TrackerHitExtended * hit = nonAttachedHits[iHit];
float pos[3];
for (int i=0; i<3; ++i)
pos[i] = hit->getTrackerHit()->getPosition()[i];
float minDist = 1e+10;
TrackExtended * trackToAttach = NULL;
for (int iTrk=0; iTrk<nTrk; ++iTrk) {
TrackExtended * trackAR = _trackImplVec[iTrk];
bool consider = true;
TrackerHitExtendedVec& hitVector = trackAR->getTrackerHitExtendedVec();
int NHITS = int(hitVector.size());
for (int IHIT=0;IHIT<NHITS;++IHIT) {
// SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works
// if (hit->getTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) {
if (hit->getTrackerHit()->getCellID() == hitVector[IHIT]->getTrackerHit()->getCellID()) {
consider = false;
break;
}
}
if (consider) {
HelixClass helix;
float phi0 = trackAR->getPhi();
float d0 = trackAR->getD0();
float z0 = trackAR->getZ0();
float omega = trackAR->getOmega();
float tanlambda = trackAR->getTanLambda();
if (tanlambda*float(getSideID(hit->getTrackerHit())) > 0) {
helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField);
float distance[3];
float time = helix.getDistanceToPoint(pos,distance);
if (time < 1.0e+10) {
if (distance[2] < minDist) {
minDist = distance[2];
trackToAttach = trackAR;
}
}
}
}
}
if (minDist < _minDistCutAttach && trackToAttach != NULL) {
int iopt = 2;
AttachHitToTrack(trackToAttach,hit,iopt);
}
}
}
void SiliconTrackingAlg::AttachRemainingFTDHitsFast() {
Loading
Loading full blame...