forked from sPHENIX-Collaboration/coresoftware
/
ActsEvaluator.cc
1590 lines (1380 loc) · 51.7 KB
/
ActsEvaluator.cc
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
#include "ActsEvaluator.h"
/// General fun4all and subsysreco includes
#include <fun4all/Fun4AllReturnCodes.h>
#include <fun4all/Fun4AllServer.h>
#include <g4main/PHG4Hit.h>
#include <g4main/PHG4Particle.h>
#include <g4main/PHG4TruthInfoContainer.h>
#include <phool/PHCompositeNode.h>
#include <phool/getClass.h>
#include <trackbase/TrkrClusterContainer.h>
/// Tracking includes
#include <trackbase/TrkrClusterv2.h>
#include <trackbase_historic/SvtxTrack.h>
#include <trackbase_historic/SvtxTrackMap.h>
#include <g4eval/SvtxClusterEval.h>
#include <g4eval/SvtxEvalStack.h>
#include <g4eval/SvtxEvaluator.h>
#include <g4eval/SvtxTrackEval.h>
#include <trackbase_historic/SvtxVertexMap.h>
#include <trackbase_historic/SvtxVertex.h>
#include <g4main/PHG4VtxPoint.h>
#include <Acts/EventData/MultiTrajectoryHelpers.hpp>
#include <Acts/Utilities/Definitions.hpp>
#include <Acts/Utilities/Units.hpp>
#include <TFile.h>
#include <TTree.h>
ActsEvaluator::ActsEvaluator(const std::string &name,
SvtxEvaluator *svtxEvaluator)
: SubsysReco(name)
, m_svtxEvaluator(svtxEvaluator)
, m_truthInfo(nullptr)
, m_trackMap(nullptr)
, m_svtxEvalStack(nullptr)
, m_actsTrackKeyMap(nullptr)
, m_actsFitResults(nullptr)
, m_tGeometry(nullptr)
, m_evalCKF(false)
{
}
ActsEvaluator::~ActsEvaluator()
{
}
int ActsEvaluator::Init(PHCompositeNode */*topNode*/)
{
if (Verbosity() > 1)
{
std::cout << "Starting ActsEvaluator::Init" << std::endl;
}
initializeTree();
if (Verbosity() > 1)
{
std::cout << "Finished ActsEvaluator::Init" << std::endl;
}
return Fun4AllReturnCodes::EVENT_OK;
}
int ActsEvaluator::process_event(PHCompositeNode *topNode)
{
if (Verbosity() > 1)
{
std::cout << "Starting ActsEvaluator at event " << m_eventNr
<< std::endl;
}
if (getNodes(topNode) == Fun4AllReturnCodes::ABORTEVENT)
return Fun4AllReturnCodes::ABORTEVENT;
m_svtxEvalStack = new SvtxEvalStack(topNode);
m_svtxEvalStack->next_event(topNode);
evaluateTrackFits(topNode);
m_eventNr++;
if (Verbosity() > 1)
std::cout << "Finished ActsEvaluator::process_event" << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}
void ActsEvaluator::evaluateTrackFits(PHCompositeNode *topNode)
{
if(Verbosity() > 5)
std::cout << "Evaluating Acts track fits" << std::endl;
SvtxTrackEval *trackeval = m_svtxEvalStack->get_track_eval();
std::map<const unsigned int, Trajectory>::iterator trajIter;
int iTraj = 0;
int iTrack = 0;
for (trajIter = m_actsFitResults->begin();
trajIter != m_actsFitResults->end();
++trajIter)
{
/// Get the trajectory information
unsigned int trackKey = trajIter->first;
Trajectory traj = trajIter->second;
if(Verbosity() > 2)
std::cout << "Starting trajectory " << iTraj
<< " with trackKey corresponding to track seed "
<< trackKey << std::endl;
const auto &[trackTips, mj] = traj.trajectory();
m_trajNr = iTraj;
/// Skip failed fits
if (trackTips.empty())
{
if (Verbosity() > 1)
std::cout << "TrackTips empty in ActsEvaluator" << std::endl;
continue;
}
iTrack = 0;
/// Track seed always is related to the trajectory->trackkey
/// mapping for KF (by definition) and CKF
SvtxTrack* actsProtoTrack = m_actsProtoTrackMap->find(trackKey)->second;
/// Get the map of track tips->trackKeys for this trajectory
std::map<const size_t, const unsigned int> trackKeyMap;
if(m_evalCKF)
trackKeyMap = m_actsTrackKeyMap->find(trackKey)->second;
/// For the KF this iterates once. For the CKF it may iterate several times
for(const size_t &trackTip : trackTips)
{
if(Verbosity() > 2)
std::cout << "beginning trackTip " << trackTip
<< " corresponding to track " << iTrack
<< " in trajectroy " << iTraj << std::endl;
/// The CKF has a trackTip == trackKey correspondence, rather
/// than a trajectory == trackKey correspondence. So need to
/// grab the correct key from the extra map
if(m_evalCKF)
{
std::map<const size_t, const unsigned int>::iterator ckfiter
= trackKeyMap.find(trackTip);
if(ckfiter == trackKeyMap.end())
{
if(Verbosity() > 2)
std::cout << "Track result flagged as bad, continuing"
<< std::endl;
continue;
}
trackKey = ckfiter->second;
}
if(Verbosity() > 2)
std::cout<<"Evaluating track key " << trackKey
<< " for track tip " << trackTip << std::endl;
SvtxTrack *track = m_trackMap->find(trackKey)->second;
PHG4Particle *g4particle = trackeval->max_truth_particle_by_nclusters(track);
unsigned int vertexId = track->get_vertex_id();
if(vertexId == UINT_MAX)
vertexId = 0;
const SvtxVertex *svtxVertex = m_vertexMap->get(vertexId);
Acts::Vector3D vertex;
vertex(0) = svtxVertex->get_x() * Acts::UnitConstants::cm;
vertex(1) = svtxVertex->get_y() * Acts::UnitConstants::cm;
vertex(2) = svtxVertex->get_z() * Acts::UnitConstants::cm;
if(Verbosity() > 1)
{
std::cout << "Analyzing SvtxTrack "<< trackKey << std::endl;
std::cout << "TruthParticle : " << g4particle->get_px()
<< ", " << g4particle->get_py() << ", "
<< g4particle->get_pz() << ", "<< g4particle->get_e()
<< std::endl;
}
m_trackNr = iTrack;
auto trajState =
Acts::MultiTrajectoryHelpers::trajectoryState(mj, trackTip);
if(Verbosity() > 1)
{
if(traj.hasTrackParameters(trackTip))
{
std::cout << "Fitted params : "
<< traj.trackParameters(trackTip).position(m_tGeometry->geoContext)
<< std::endl << traj.trackParameters(trackTip).momentum()
<< std::endl;
std::cout << "Track has " << trajState.nMeasurements
<< " measurements and " << trajState.nHoles
<< " holes and " << trajState.nOutliers
<< " outliers and " << trajState.nStates
<< " states " << std::endl;
}
}
m_nMeasurements = trajState.nMeasurements;
m_nStates = trajState.nStates;
m_nOutliers = trajState.nOutliers;
m_nHoles = trajState.nHoles;
m_chi2_fit = trajState.chi2Sum;
m_ndf_fit = trajState.NDF;
m_quality = track->get_quality();
fillG4Particle(g4particle);
fillProtoTrack(actsProtoTrack, topNode);
fillFittedTrackParams(traj, trackTip, vertex);
visitTrackStates(traj,trackTip, topNode);
m_trackTree->Fill();
/// Start fresh for the next track
clearTrackVariables();
if(Verbosity() > 1)
std::cout << "Finished track " << iTrack <<std::endl;
iTrack++;
}
if(Verbosity() > 1)
{
std::cout << "Analyzed " << iTrack << " tracks in trajectory number "
<< iTraj << std::endl;
}
++iTraj;
}
if(Verbosity () > 5)
std::cout << "Finished evaluating track fits" << std::endl;
return;
}
int ActsEvaluator::End(PHCompositeNode */*topNode*/)
{
m_trackFile->cd();
m_trackTree->Write();
m_trackFile->Close();
return Fun4AllReturnCodes::EVENT_OK;
}
int ActsEvaluator::ResetEvent(PHCompositeNode */*topNode*/)
{
m_trajNr = 0;
return Fun4AllReturnCodes::EVENT_OK;
}
void ActsEvaluator::visitTrackStates(const Trajectory traj,
const size_t &trackTip,
PHCompositeNode *topNode)
{
if(Verbosity() > 2)
std::cout << "Begin visit track states" << std::endl;
const auto &[trackTips, mj] = traj.trajectory();
mj.visitBackwards(trackTip, [&](const auto &state) {
/// Only fill the track states with non-outlier measurement
auto typeFlags = state.typeFlags();
if (not typeFlags.test(Acts::TrackStateFlag::MeasurementFlag))
{
return true;
}
/// Get the geometry ID
auto geoID = state.referenceSurface().geometryId();
m_volumeID.push_back(geoID.volume());
m_layerID.push_back(geoID.layer());
m_moduleID.push_back(geoID.sensitive());
if(Verbosity() > 3)
std::cout << "Cluster volume : layer : sensitive " << geoID.volume()
<< " : " << geoID.layer() << " : "
<< geoID.sensitive() << std::endl;
auto meas = std::get<Measurement>(*state.uncalibrated());
/// Get local position
Acts::Vector2D local(meas.parameters()[Acts::eBoundLoc0],
meas.parameters()[Acts::eBoundLoc1]);
/// Get global position
/// This is an arbitrary vector. Doesn't matter in coordinate transformation
/// in Acts code
Acts::Vector3D mom(1, 1, 1);
Acts::Vector3D global = meas.referenceObject().localToGlobal(m_tGeometry->geoContext,
local, mom);
/// Get measurement covariance
auto cov = meas.covariance();
m_lx_hit.push_back(local.x());
m_ly_hit.push_back(local.y());
m_x_hit.push_back(global.x());
m_y_hit.push_back(global.y());
m_z_hit.push_back(global.z());
/// Get the truth hit corresponding to this trackState
/// We go backwards from hitID -> TrkrDefs::cluskey to g4hit with
/// the map created in PHActsSourceLinks
TrkrDefs::cluskey cluskey = state.uncalibrated().cluskey();
float gt = -9999;
Acts::Vector3D globalTruthPos = getGlobalTruthHit(topNode, cluskey, gt);
float gx = globalTruthPos(0);
float gy = globalTruthPos(1);
float gz = globalTruthPos(2);
/// Get local truth position
const float r = sqrt(gx * gx + gy * gy + gz * gz);
Acts::Vector3D globalTruthUnitDir(gx / r, gy / r, gz / r);
auto vecResult = meas.referenceObject().globalToLocal(
m_tGeometry->geoContext,
globalTruthPos,
globalTruthUnitDir);
/// Push the truth hit info
m_t_x.push_back(gx);
m_t_y.push_back(gy);
m_t_z.push_back(gz);
m_t_r.push_back(sqrt(gx * gx + gy * gy));
m_t_dx.push_back(gx / r);
m_t_dy.push_back(gy / r);
m_t_dz.push_back(gz / r);
/// Get the truth track parameter at this track State
float truthLOC0 = 0;
float truthLOC1 = 0;
float truthPHI = 0;
float truthTHETA = 0;
float truthQOP = 0;
float truthTIME = 0;
float momentum = sqrt(m_t_px * m_t_px +
m_t_py * m_t_py +
m_t_pz * m_t_pz);
if(vecResult.ok())
{
Acts::Vector2D truthLocVec = vecResult.value();
truthLOC0 = truthLocVec.x();
truthLOC1 = truthLocVec.y();
}
else
{
truthLOC0 = -9999.;
truthLOC1 = -9999.;
}
truthPHI = phi(globalTruthUnitDir);
truthTHETA = theta(globalTruthUnitDir);
truthQOP =
m_t_charge / momentum;
truthTIME = gt;
m_t_eLOC0.push_back(truthLOC0);
m_t_eLOC1.push_back(truthLOC1);
m_t_ePHI.push_back(truthPHI);
m_t_eTHETA.push_back(truthTHETA);
m_t_eQOP.push_back(truthQOP);
m_t_eT.push_back(truthTIME);
/// Get the predicted parameter for this state
bool predicted = false;
if (state.hasPredicted())
{
predicted = true;
m_nPredicted++;
auto parameters = state.predicted();
auto covariance = state.predictedCovariance();
/// Local hit residual info
auto H = meas.projector();
auto resCov = cov + H * covariance * H.transpose();
auto residual = meas.residual(parameters);
m_res_x_hit.push_back(residual(Acts::eBoundLoc0));
m_res_y_hit.push_back(residual(Acts::eBoundLoc1));
m_err_x_hit.push_back(
sqrt(resCov(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_err_y_hit.push_back(
sqrt(resCov(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_pull_x_hit.push_back(
residual(Acts::eBoundLoc0) /
sqrt(resCov(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_pull_y_hit.push_back(
residual(Acts::eBoundLoc1) /
sqrt(resCov(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_dim_hit.push_back(state.calibratedSize());
/// Predicted parameter
m_eLOC0_prt.push_back(parameters[Acts::eBoundLoc0]);
m_eLOC1_prt.push_back(parameters[Acts::eBoundLoc1]);
m_ePHI_prt.push_back(parameters[Acts::eBoundPhi]);
m_eTHETA_prt.push_back(parameters[Acts::eBoundTheta]);
m_eQOP_prt.push_back(parameters[Acts::eBoundQOverP]);
m_eT_prt.push_back(parameters[Acts::eBoundTime]);
/// Predicted residual
m_res_eLOC0_prt.push_back(parameters[Acts::eBoundLoc0] -
truthLOC0);
m_res_eLOC1_prt.push_back(parameters[Acts::eBoundLoc1] -
truthLOC1);
m_res_ePHI_prt.push_back(parameters[Acts::eBoundPhi] -
truthPHI);
m_res_eTHETA_prt.push_back(
parameters[Acts::eBoundTheta] - truthTHETA);
m_res_eQOP_prt.push_back(parameters[Acts::eBoundQOverP] -
truthQOP);
m_res_eT_prt.push_back(parameters[Acts::eBoundTime] -
truthTIME);
/// Predicted parameter Uncertainties
m_err_eLOC0_prt.push_back(
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_err_eLOC1_prt.push_back(
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_err_ePHI_prt.push_back(
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_err_eTHETA_prt.push_back(
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_err_eQOP_prt.push_back(
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_err_eT_prt.push_back(
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
/// Predicted parameter pulls
m_pull_eLOC0_prt.push_back(
(parameters[Acts::eBoundLoc0] - truthLOC0) /
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_pull_eLOC1_prt.push_back(
(parameters[Acts::eBoundLoc1] - truthLOC1) /
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_pull_ePHI_prt.push_back(
(parameters[Acts::eBoundPhi] - truthPHI) /
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_pull_eTHETA_prt.push_back(
(parameters[Acts::eBoundTheta] - truthTHETA) /
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_pull_eQOP_prt.push_back(
(parameters[Acts::eBoundQOverP] - truthQOP) /
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_pull_eT_prt.push_back(
(parameters[Acts::eBoundTime] - truthTIME) /
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
Acts::FreeVector freeParams =
Acts::detail::transformBoundToFreeParameters(state.referenceSurface(),
m_tGeometry->geoContext,
parameters);
m_x_prt.push_back(freeParams[Acts::eFreePos0]);
m_y_prt.push_back(freeParams[Acts::eFreePos1]);
m_z_prt.push_back(freeParams[Acts::eFreePos2]);
auto p = std::abs(1 / freeParams[Acts::eFreeQOverP]);
m_px_prt.push_back(p * freeParams[Acts::eFreeDir0]);
m_py_prt.push_back(p * freeParams[Acts::eFreeDir1]);
m_pz_prt.push_back(p * freeParams[Acts::eFreeDir2]);
m_pT_prt.push_back(p * std::hypot(freeParams[Acts::eFreeDir0],
freeParams[Acts::eFreeDir1]));
m_eta_prt.push_back(
Acts::VectorHelpers::eta(freeParams.segment<3>(Acts::eFreeDir0)));
}
else
{
/// Push bad values if no predicted parameter
m_res_x_hit.push_back(-9999);
m_res_y_hit.push_back(-9999);
m_err_x_hit.push_back(-9999);
m_err_y_hit.push_back(-9999);
m_pull_x_hit.push_back(-9999);
m_pull_y_hit.push_back(-9999);
m_dim_hit.push_back(-9999);
m_eLOC0_prt.push_back(-9999);
m_eLOC1_prt.push_back(-9999);
m_ePHI_prt.push_back(-9999);
m_eTHETA_prt.push_back(-9999);
m_eQOP_prt.push_back(-9999);
m_eT_prt.push_back(-9999);
m_res_eLOC0_prt.push_back(-9999);
m_res_eLOC1_prt.push_back(-9999);
m_res_ePHI_prt.push_back(-9999);
m_res_eTHETA_prt.push_back(-9999);
m_res_eQOP_prt.push_back(-9999);
m_res_eT_prt.push_back(-9999);
m_err_eLOC0_prt.push_back(-9999);
m_err_eLOC1_prt.push_back(-9999);
m_err_ePHI_prt.push_back(-9999);
m_err_eTHETA_prt.push_back(-9999);
m_err_eQOP_prt.push_back(-9999);
m_err_eT_prt.push_back(-9999);
m_pull_eLOC0_prt.push_back(-9999);
m_pull_eLOC1_prt.push_back(-9999);
m_pull_ePHI_prt.push_back(-9999);
m_pull_eTHETA_prt.push_back(-9999);
m_pull_eQOP_prt.push_back(-9999);
m_pull_eT_prt.push_back(-9999);
m_x_prt.push_back(-9999);
m_y_prt.push_back(-9999);
m_z_prt.push_back(-9999);
m_px_prt.push_back(-9999);
m_py_prt.push_back(-9999);
m_pz_prt.push_back(-9999);
m_pT_prt.push_back(-9999);
m_eta_prt.push_back(-9999);
}
bool filtered = false;
if (state.hasFiltered())
{
filtered = true;
m_nFiltered++;
Acts::BoundTrackParameters parameter(
state.referenceSurface().getSharedPtr(),
state.filtered(),
state.filteredCovariance());
auto covariance = state.filteredCovariance();
m_eLOC0_flt.push_back(parameter.parameters()[Acts::eBoundLoc0]);
m_eLOC1_flt.push_back(parameter.parameters()[Acts::eBoundLoc1]);
m_ePHI_flt.push_back(parameter.parameters()[Acts::eBoundPhi]);
m_eTHETA_flt.push_back(parameter.parameters()[Acts::eBoundTheta]);
m_eQOP_flt.push_back(parameter.parameters()[Acts::eBoundQOverP]);
m_eT_flt.push_back(parameter.parameters()[Acts::eBoundTime]);
m_res_eLOC0_flt.push_back(parameter.parameters()[Acts::eBoundLoc0] -
truthLOC0);
m_res_eLOC1_flt.push_back(parameter.parameters()[Acts::eBoundLoc1] -
truthLOC1);
m_res_ePHI_flt.push_back(parameter.parameters()[Acts::eBoundPhi] -
truthPHI);
m_res_eTHETA_flt.push_back(parameter.parameters()[Acts::eBoundTheta] -
truthTHETA);
m_res_eQOP_flt.push_back(parameter.parameters()[Acts::eBoundQOverP] -
truthQOP);
m_res_eT_flt.push_back(parameter.parameters()[Acts::eBoundTime] -
truthTIME);
/// Filtered parameter uncertainties
m_err_eLOC0_flt.push_back(
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_err_eLOC1_flt.push_back(
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_err_ePHI_flt.push_back(
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_err_eTHETA_flt.push_back(
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_err_eQOP_flt.push_back(
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_err_eT_flt.push_back(
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
/// Filtered parameter pulls
m_pull_eLOC0_flt.push_back(
(parameter.parameters()[Acts::eBoundLoc0] - truthLOC0) /
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_pull_eLOC1_flt.push_back(
(parameter.parameters()[Acts::eBoundLoc1] - truthLOC1) /
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_pull_ePHI_flt.push_back(
(parameter.parameters()[Acts::eBoundPhi] - truthPHI) /
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_pull_eTHETA_flt.push_back(
(parameter.parameters()[Acts::eBoundTheta] - truthTHETA) /
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_pull_eQOP_flt.push_back(
(parameter.parameters()[Acts::eBoundQOverP] - truthQOP) /
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_pull_eT_flt.push_back(
(parameter.parameters()[Acts::eBoundTime] - truthTIME) /
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
/// Other filtered parameter info
m_x_flt.push_back(parameter.position(m_tGeometry->geoContext).x());
m_y_flt.push_back(parameter.position(m_tGeometry->geoContext).y());
m_z_flt.push_back(parameter.position(m_tGeometry->geoContext).z());
m_px_flt.push_back(parameter.momentum().x());
m_py_flt.push_back(parameter.momentum().y());
m_pz_flt.push_back(parameter.momentum().z());
m_pT_flt.push_back(sqrt(parameter.momentum().x() * parameter.momentum().x()
+ parameter.momentum().y() * parameter.momentum().y()));
m_eta_flt.push_back(eta(parameter.position(m_tGeometry->geoContext)));
m_chi2.push_back(state.chi2());
}
else
{
/// Push bad values if no filtered parameter
m_eLOC0_flt.push_back(-9999);
m_eLOC1_flt.push_back(-9999);
m_ePHI_flt.push_back(-9999);
m_eTHETA_flt.push_back(-9999);
m_eQOP_flt.push_back(-9999);
m_eT_flt.push_back(-9999);
m_res_eLOC0_flt.push_back(-9999);
m_res_eLOC1_flt.push_back(-9999);
m_res_ePHI_flt.push_back(-9999);
m_res_eTHETA_flt.push_back(-9999);
m_res_eQOP_flt.push_back(-9999);
m_res_eT_flt.push_back(-9999);
m_err_eLOC0_flt.push_back(-9999);
m_err_eLOC1_flt.push_back(-9999);
m_err_ePHI_flt.push_back(-9999);
m_err_eTHETA_flt.push_back(-9999);
m_err_eQOP_flt.push_back(-9999);
m_err_eT_flt.push_back(-9999);
m_pull_eLOC0_flt.push_back(-9999);
m_pull_eLOC1_flt.push_back(-9999);
m_pull_ePHI_flt.push_back(-9999);
m_pull_eTHETA_flt.push_back(-9999);
m_pull_eQOP_flt.push_back(-9999);
m_pull_eT_flt.push_back(-9999);
m_x_flt.push_back(-9999);
m_y_flt.push_back(-9999);
m_z_flt.push_back(-9999);
m_py_flt.push_back(-9999);
m_pz_flt.push_back(-9999);
m_pT_flt.push_back(-9999);
m_eta_flt.push_back(-9999);
m_chi2.push_back(-9999);
}
bool smoothed = false;
if (state.hasSmoothed())
{
smoothed = true;
m_nSmoothed++;
Acts::BoundTrackParameters parameter(
state.referenceSurface().getSharedPtr(),
state.smoothed(),
state.smoothedCovariance());
auto covariance = state.smoothedCovariance();
m_eLOC0_smt.push_back(parameter.parameters()[Acts::eBoundLoc0]);
m_eLOC1_smt.push_back(parameter.parameters()[Acts::eBoundLoc1]);
m_ePHI_smt.push_back(parameter.parameters()[Acts::eBoundPhi]);
m_eTHETA_smt.push_back(parameter.parameters()[Acts::eBoundTheta]);
m_eQOP_smt.push_back(parameter.parameters()[Acts::eBoundQOverP]);
m_eT_smt.push_back(parameter.parameters()[Acts::eBoundTime]);
m_res_eLOC0_smt.push_back(parameter.parameters()[Acts::eBoundLoc0] -
truthLOC0);
m_res_eLOC1_smt.push_back(parameter.parameters()[Acts::eBoundLoc1] -
truthLOC1);
m_res_ePHI_smt.push_back(parameter.parameters()[Acts::eBoundPhi] -
truthPHI);
m_res_eTHETA_smt.push_back(parameter.parameters()[Acts::eBoundTheta] -
truthTHETA);
m_res_eQOP_smt.push_back(parameter.parameters()[Acts::eBoundQOverP] -
truthQOP);
m_res_eT_smt.push_back(parameter.parameters()[Acts::eBoundTime] -
truthTIME);
/// Smoothed parameter uncertainties
m_err_eLOC0_smt.push_back(
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_err_eLOC1_smt.push_back(
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_err_ePHI_smt.push_back(
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_err_eTHETA_smt.push_back(
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_err_eQOP_smt.push_back(
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_err_eT_smt.push_back(
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
/// Smoothed parameter pulls
m_pull_eLOC0_smt.push_back(
(parameter.parameters()[Acts::eBoundLoc0] - truthLOC0) /
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
m_pull_eLOC1_smt.push_back(
(parameter.parameters()[Acts::eBoundLoc1] - truthLOC1) /
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
m_pull_ePHI_smt.push_back(
(parameter.parameters()[Acts::eBoundPhi] - truthPHI) /
sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
m_pull_eTHETA_smt.push_back(
(parameter.parameters()[Acts::eBoundTheta] - truthTHETA) /
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
m_pull_eQOP_smt.push_back(
(parameter.parameters()[Acts::eBoundQOverP] - truthQOP) /
sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
m_pull_eT_smt.push_back(
(parameter.parameters()[Acts::eBoundTime] - truthTIME) /
sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
m_x_smt.push_back(parameter.position(m_tGeometry->geoContext).x());
m_y_smt.push_back(parameter.position(m_tGeometry->geoContext).y());
m_z_smt.push_back(parameter.position(m_tGeometry->geoContext).z());
m_px_smt.push_back(parameter.momentum().x());
m_py_smt.push_back(parameter.momentum().y());
m_pz_smt.push_back(parameter.momentum().z());
m_pT_smt.push_back(sqrt(parameter.momentum().x() * parameter.momentum().x()
+ parameter.momentum().y() * parameter.momentum().y()));
m_eta_smt.push_back(eta(parameter.position(m_tGeometry->geoContext)));
}
else
{
/// Push bad values if no smoothed parameter
m_eLOC0_smt.push_back(-9999);
m_eLOC1_smt.push_back(-9999);
m_ePHI_smt.push_back(-9999);
m_eTHETA_smt.push_back(-9999);
m_eQOP_smt.push_back(-9999);
m_eT_smt.push_back(-9999);
m_res_eLOC0_smt.push_back(-9999);
m_res_eLOC1_smt.push_back(-9999);
m_res_ePHI_smt.push_back(-9999);
m_res_eTHETA_smt.push_back(-9999);
m_res_eQOP_smt.push_back(-9999);
m_res_eT_smt.push_back(-9999);
m_err_eLOC0_smt.push_back(-9999);
m_err_eLOC1_smt.push_back(-9999);
m_err_ePHI_smt.push_back(-9999);
m_err_eTHETA_smt.push_back(-9999);
m_err_eQOP_smt.push_back(-9999);
m_err_eT_smt.push_back(-9999);
m_pull_eLOC0_smt.push_back(-9999);
m_pull_eLOC1_smt.push_back(-9999);
m_pull_ePHI_smt.push_back(-9999);
m_pull_eTHETA_smt.push_back(-9999);
m_pull_eQOP_smt.push_back(-9999);
m_pull_eT_smt.push_back(-9999);
m_x_smt.push_back(-9999);
m_y_smt.push_back(-9999);
m_z_smt.push_back(-9999);
m_px_smt.push_back(-9999);
m_py_smt.push_back(-9999);
m_pz_smt.push_back(-9999);
m_pT_smt.push_back(-9999);
m_eta_smt.push_back(-9999);
}
/// Save whether or not states had various KF steps
m_prt.push_back(predicted);
m_flt.push_back(filtered);
m_smt.push_back(smoothed);
return true;
} /// Finish lambda function
); /// Finish multi trajectory visitBackwards call
if(Verbosity() > 2)
std::cout << "Finished track states" << std::endl;
return;
}
Acts::Vector3D ActsEvaluator::getGlobalTruthHit(PHCompositeNode */*topNode*/,
TrkrDefs::cluskey cluskey,
float &_gt)
{
SvtxClusterEval *clustereval = m_svtxEvalStack->get_cluster_eval();
std::shared_ptr<TrkrCluster> truth_cluster = clustereval->max_truth_cluster_by_energy(cluskey);
float gx = -9999;
float gy = -9999;
float gz = -9999;
float gt = -9999;
if (truth_cluster)
{
gx = truth_cluster->getX();
gy = truth_cluster->getY();
gz = truth_cluster->getZ();
}
/// Convert to acts units of mm
gx *= Acts::UnitConstants::cm;
gy *= Acts::UnitConstants::cm;
gz *= Acts::UnitConstants::cm;
Acts::Vector3D globalPos(gx, gy, gz);
_gt = gt;
return globalPos;
}
//___________________________________________________________________________________
Surface ActsEvaluator::getSurface(TrkrDefs::cluskey cluskey, TrkrDefs::subsurfkey surfkey)
{
const auto trkrid = TrkrDefs::getTrkrId(cluskey);
const auto hitsetkey = TrkrDefs::getHitSetKeyFromClusKey(cluskey);
switch( trkrid )
{
case TrkrDefs::TrkrId::micromegasId: return getMMSurface( hitsetkey );
case TrkrDefs::TrkrId::tpcId: return getTpcSurface(hitsetkey, surfkey);
case TrkrDefs::TrkrId::mvtxId:
case TrkrDefs::TrkrId::inttId:
{
return getSiliconSurface(hitsetkey);
}
}
// unreachable
return nullptr;
}
//___________________________________________________________________________________
Surface ActsEvaluator::getSiliconSurface(TrkrDefs::hitsetkey hitsetkey)
{
auto surfMap = m_surfMaps->siliconSurfaceMap;
auto iter = surfMap.find(hitsetkey);
if(iter != surfMap.end())
{
return iter->second;
}
/// If it can't be found, return nullptr
return nullptr;
}
//___________________________________________________________________________________
Surface ActsEvaluator::getTpcSurface(TrkrDefs::hitsetkey hitsetkey, TrkrDefs::subsurfkey surfkey)
{
unsigned int layer = TrkrDefs::getLayer(hitsetkey);
const auto iter = m_surfMaps->tpcSurfaceMap.find(layer);
if(iter != m_surfMaps->tpcSurfaceMap.end())
{
auto surfvec = iter->second;
return surfvec.at(surfkey);
}
/// If it can't be found, return nullptr to skip this cluster
return nullptr;
}
//___________________________________________________________________________________
Surface ActsEvaluator::getMMSurface(TrkrDefs::hitsetkey hitsetkey)
{
const auto iter = m_surfMaps->mmSurfaceMap.find( hitsetkey );
return (iter == m_surfMaps->mmSurfaceMap.end()) ? nullptr:iter->second;
}
void ActsEvaluator::fillProtoTrack(SvtxTrack* track, PHCompositeNode *topNode)
{
if(Verbosity() > 2)
std::cout << "Filling proto track seed quantities" << std::endl;
Acts::Vector3D position(track->get_x() * 10, track->get_y() * 10,
track->get_z() * 10);
Acts::Vector3D momentum(track->get_px(),
track->get_py(),
track->get_pz());
m_protoTrackPx = momentum(0);
m_protoTrackPy = momentum(1);
m_protoTrackPz = momentum(2);
m_protoTrackX = position(0);
m_protoTrackY = position(1);
m_protoTrackZ = position(2);
for(SvtxTrack::ConstClusterKeyIter clusIter = track->begin_cluster_keys();
clusIter != track->end_cluster_keys();
++clusIter)
{
auto key = *clusIter;
auto cluster = m_clusterContainer->findCluster(key);
/// Get source link global position
Acts::Vector2D loc(cluster->getLocalX() * 10,
cluster->getLocalY() * 10);
Acts::Vector3D mom(0,0,0);
Acts::Vector3D globalPos(cluster->getX() * 10,
cluster->getY() * 10,
cluster->getZ() * 10);
m_SLx.push_back(globalPos(0));
m_SLy.push_back(globalPos(1));
m_SLz.push_back(globalPos(2));
m_SL_lx.push_back(loc(0));
m_SL_ly.push_back(loc(1));
/// Get corresponding truth hit position
float gt = -9999;
Acts::Vector3D globalTruthPos = getGlobalTruthHit(topNode, key, gt);
float gx = globalTruthPos(0);
float gy = globalTruthPos(1);
float gz = globalTruthPos(2);
/// Get local truth position
const float r = sqrt(gx * gx + gy * gy + gz * gz);
Acts::Vector3D globalTruthUnitDir(gx / r, gy / r, gz / r);
auto surf = getSurface(key, cluster->getSubSurfKey());
auto truthLocal = (*surf).globalToLocal(m_tGeometry->geoContext,
globalTruthPos,
globalTruthUnitDir);
if(truthLocal.ok())
{
Acts::Vector2D truthLocalVec = truthLocal.value();
m_t_SL_lx.push_back(truthLocalVec(0));
m_t_SL_ly.push_back(truthLocalVec(1));
m_t_SL_gx.push_back(gx);
m_t_SL_gy.push_back(gy);
m_t_SL_gz.push_back(gz);
}
else
{
m_t_SL_lx.push_back(-9999.);
m_t_SL_ly.push_back(-9999.);
m_t_SL_gx.push_back(-9999.);
m_t_SL_gy.push_back(-9999.);
m_t_SL_gz.push_back(-9999.);
}
}
if(Verbosity() > 2)
std::cout << "Filled proto track" << std::endl;
}
void ActsEvaluator::fillFittedTrackParams(const Trajectory traj,
const size_t &trackTip,
const Acts::Vector3D vertex)
{
m_hasFittedParams = false;
if(Verbosity() > 2)
std::cout << "Filling fitted track parameters" << std::endl;
/// If it has track parameters, fill the values
if (traj.hasTrackParameters(trackTip))
{
m_hasFittedParams = true;
const auto &boundParam = traj.trackParameters(trackTip);
const auto ¶meter = boundParam.parameters();
const auto &covariance = *boundParam.covariance();
m_charge_fit = boundParam.charge();
m_eLOC0_fit = parameter[Acts::eBoundLoc0];
m_eLOC1_fit = parameter[Acts::eBoundLoc1];
m_ePHI_fit = parameter[Acts::eBoundPhi];
m_eTHETA_fit = parameter[Acts::eBoundTheta];
m_eQOP_fit = parameter[Acts::eBoundQOverP];
m_eT_fit = parameter[Acts::eBoundTime];
m_err_eLOC0_fit =
sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0));
m_err_eLOC1_fit =
sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1));
m_err_ePHI_fit = sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi));
m_err_eTHETA_fit =
sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta));
m_err_eQOP_fit = sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP));
m_err_eT_fit = sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime));
m_px_fit = boundParam.momentum()(0);
m_py_fit = boundParam.momentum()(1);
m_pz_fit = boundParam.momentum()(2);
m_x_fit = boundParam.position(m_tGeometry->geoContext)(0);
m_y_fit = boundParam.position(m_tGeometry->geoContext)(1);
m_z_fit = boundParam.position(m_tGeometry->geoContext)(2);
calculateDCA(boundParam, vertex);
return;
}