37 :
WriterT(cfg.inputTrajectories,
"RootTrajectoryWriter", lvl),
39 m_outputFile(cfg.rootFile) {
42 throw std::invalid_argument(
"Missing input trajectory collection");
44 throw std::invalid_argument(
"Missing input particle collection");
46 throw std::invalid_argument(
"Missing output filename");
48 throw std::invalid_argument(
"Missing tree name");
56 throw std::ios_base::failure(
"Could not open '" + path);
63 throw std::bad_alloc();
238 m_outputFile->Close();
245 m_outputTree->Write();
247 << m_cfg.outputTreename <<
"' in '"
248 <<
joinPaths(m_cfg.outputDir, m_cfg.outputFilename) <<
"'");
255 if (m_outputFile ==
nullptr)
261 const auto& particles =
265 std::lock_guard<std::mutex> lock(m_writeMutex);
272 for (
const auto& traj : trajectories) {
276 const auto& [trackTips, mj] = traj.trajectory();
277 if (trackTips.empty()) {
283 if (trackTips.size() > 1) {
284 ACTS_ERROR(
"Track fitting should not result in multiple trajectories.");
285 return ProcessCode::ABORT;
288 auto& trackTip = trackTips.front();
293 m_nMeasurements = trajState.nMeasurements;
294 m_nStates = trajState.nStates;
297 const auto particleHitCount = traj.identifyMajorityParticle(trackTip);
298 if (not particleHitCount.empty()) {
300 m_t_barcode = particleHitCount.front().particleId.value();
302 auto ip = particles.find(m_t_barcode);
303 if (
ip != particles.end()) {
305 ACTS_DEBUG(
"Find the truth particle with barcode = " << m_t_barcode);
313 m_t_px =
p *
particle.unitDirection().x();
314 m_t_py =
p *
particle.unitDirection().y();
315 m_t_pz =
p *
particle.unitDirection().z();
321 ACTS_WARNING(
"Truth particle with barcode = " << m_t_barcode
327 m_hasFittedParams =
false;
328 if (traj.hasTrackParameters(trackTip)) {
329 m_hasFittedParams =
true;
330 const auto& boundParam = traj.trackParameters(trackTip);
331 const auto&
parameter = boundParam.parameters();
332 const auto& covariance = *boundParam.covariance();
351 mj.visitBackwards(trackTip, [&](
const auto& state) {
353 auto typeFlags = state.typeFlags();
358 auto meas = std::get<Measurement>(*state.uncalibrated());
359 auto&
surface = meas.referenceObject();
362 auto geoID = surface.geometryId();
363 m_volumeID.push_back(geoID.volume());
364 m_layerID.push_back(geoID.layer());
365 m_moduleID.push_back(geoID.sensitive());
375 auto cov = meas.covariance();
380 m_lx_hit.push_back(local.x());
381 m_ly_hit.push_back(local.y());
382 m_x_hit.push_back(global.x());
383 m_y_hit.push_back(global.y());
384 m_z_hit.push_back(global.z());
387 const auto& truthHit = state.uncalibrated().truthHit();
390 auto lpResult = surface.globalToLocal(
gctx, truthHit.position(),
391 truthHit.unitDirection());
392 if (not lpResult.ok()) {
393 ACTS_FATAL(
"Global to local transformation did not succeed.");
395 truthlocal = lpResult.value();
398 m_t_x.push_back(truthHit.position().x());
399 m_t_y.push_back(truthHit.position().y());
400 m_t_z.push_back(truthHit.position().z());
401 m_t_r.push_back(
perp(truthHit.position()));
402 m_t_dx.push_back(truthHit.unitDirection().x());
403 m_t_dy.push_back(truthHit.unitDirection().y());
404 m_t_dz.push_back(truthHit.unitDirection().z());
407 float truthLOC0 = 0, truthLOC1 = 0, truthPHI = 0, truthTHETA = 0,
408 truthQOP = 0, truthTIME = 0;
409 truthLOC0 = truthlocal.x();
410 truthLOC1 = truthlocal.y();
411 truthPHI =
phi(truthHit.unitDirection());
412 truthTHETA =
theta(truthHit.unitDirection());
414 m_t_charge / truthHit.momentum4Before().template head<3>().norm();
415 truthTIME = truthHit.time();
418 m_t_eLOC0.push_back(truthLOC0);
419 m_t_eLOC1.push_back(truthLOC1);
420 m_t_ePHI.push_back(truthPHI);
421 m_t_eTHETA.push_back(truthTHETA);
422 m_t_eQOP.push_back(truthQOP);
423 m_t_eT.push_back(truthTIME);
426 bool predicted =
false;
427 if (state.hasPredicted()) {
431 auto covariance = state.predictedCovariance();
433 auto H = meas.projector();
434 auto resCov =
cov +
H * covariance *
H.transpose();
440 m_pull_x_hit.push_back(
443 m_pull_y_hit.push_back(
446 m_dim_hit.push_back(state.calibratedSize());
457 m_res_eLOC0_prt.push_back(
parameters[Acts::eBoundLoc0] - truthLOC0);
458 m_res_eLOC1_prt.push_back(
parameters[Acts::eBoundLoc1] - truthLOC1);
459 m_res_ePHI_prt.push_back(
parameters[Acts::eBoundPhi] - truthPHI);
460 m_res_eTHETA_prt.push_back(
parameters[Acts::eBoundTheta] - truthTHETA);
461 m_res_eQOP_prt.push_back(
parameters[Acts::eBoundQOverP] - truthQOP);
462 m_res_eT_prt.push_back(
parameters[Acts::eBoundTime] - truthTIME);
465 m_err_eLOC0_prt.push_back(
466 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
467 m_err_eLOC1_prt.push_back(
468 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
469 m_err_ePHI_prt.push_back(
470 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
471 m_err_eTHETA_prt.push_back(
472 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
473 m_err_eQOP_prt.push_back(
474 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
475 m_err_eT_prt.push_back(
476 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
479 m_pull_eLOC0_prt.push_back(
481 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
482 m_pull_eLOC1_prt.push_back(
484 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
485 m_pull_ePHI_prt.push_back(
487 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
488 m_pull_eTHETA_prt.push_back(
489 (
parameters[Acts::eBoundTheta] - truthTHETA) /
490 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
491 m_pull_eQOP_prt.push_back(
493 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
494 m_pull_eT_prt.push_back(
496 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
509 m_pT_prt.push_back(
p * std::hypot(freeParams[Acts::eFreeDir0],
510 freeParams[Acts::eFreeDir1]));
515 m_res_x_hit.push_back(-99.);
516 m_res_y_hit.push_back(-99.);
517 m_err_x_hit.push_back(-99.);
518 m_err_y_hit.push_back(-99.);
519 m_pull_x_hit.push_back(-99.);
520 m_pull_y_hit.push_back(-99.);
521 m_dim_hit.push_back(-99.);
522 m_eLOC0_prt.push_back(-99.);
523 m_eLOC1_prt.push_back(-99.);
524 m_ePHI_prt.push_back(-99.);
525 m_eTHETA_prt.push_back(-99.);
526 m_eQOP_prt.push_back(-99.);
527 m_eT_prt.push_back(-99.);
528 m_res_eLOC0_prt.push_back(-99.);
529 m_res_eLOC1_prt.push_back(-99.);
530 m_res_ePHI_prt.push_back(-99.);
531 m_res_eTHETA_prt.push_back(-99.);
532 m_res_eQOP_prt.push_back(-99.);
533 m_res_eT_prt.push_back(-99.);
534 m_err_eLOC0_prt.push_back(-99);
535 m_err_eLOC1_prt.push_back(-99);
536 m_err_ePHI_prt.push_back(-99);
537 m_err_eTHETA_prt.push_back(-99);
538 m_err_eQOP_prt.push_back(-99);
539 m_err_eT_prt.push_back(-99);
540 m_pull_eLOC0_prt.push_back(-99.);
541 m_pull_eLOC1_prt.push_back(-99.);
542 m_pull_ePHI_prt.push_back(-99.);
543 m_pull_eTHETA_prt.push_back(-99.);
544 m_pull_eQOP_prt.push_back(-99.);
545 m_pull_eT_prt.push_back(-99.);
546 m_x_prt.push_back(-99.);
547 m_y_prt.push_back(-99.);
548 m_z_prt.push_back(-99.);
549 m_px_prt.push_back(-99.);
550 m_py_prt.push_back(-99.);
551 m_pz_prt.push_back(-99.);
552 m_pT_prt.push_back(-99.);
553 m_eta_prt.push_back(-99.);
557 bool filtered =
false;
558 if (state.hasFiltered()) {
562 auto covariance = state.filteredCovariance();
572 m_res_eLOC0_flt.push_back(
parameters[Acts::eBoundLoc0] - truthLOC0);
573 m_res_eLOC1_flt.push_back(
parameters[Acts::eBoundLoc1] - truthLOC1);
574 m_res_ePHI_flt.push_back(
parameters[Acts::eBoundPhi] - truthPHI);
575 m_res_eTHETA_flt.push_back(
parameters[Acts::eBoundTheta] - truthTHETA);
576 m_res_eQOP_flt.push_back(
parameters[Acts::eBoundQOverP] - truthQOP);
577 m_res_eT_flt.push_back(
parameters[Acts::eBoundTime] - truthTIME);
580 m_err_eLOC0_flt.push_back(
581 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
582 m_err_eLOC1_flt.push_back(
583 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
584 m_err_ePHI_flt.push_back(
585 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
586 m_err_eTHETA_flt.push_back(
587 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
588 m_err_eQOP_flt.push_back(
589 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
590 m_err_eT_flt.push_back(
591 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
594 m_pull_eLOC0_flt.push_back(
596 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
597 m_pull_eLOC1_flt.push_back(
599 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
600 m_pull_ePHI_flt.push_back(
602 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
603 m_pull_eTHETA_flt.push_back(
604 (
parameters[Acts::eBoundTheta] - truthTHETA) /
605 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
606 m_pull_eQOP_flt.push_back(
608 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
609 m_pull_eT_flt.push_back(
611 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
624 m_pT_flt.push_back(
p * std::hypot(freeParams[Acts::eFreeDir0],
625 freeParams[Acts::eFreeDir1]));
628 m_chi2.push_back(state.chi2());
631 m_eLOC0_flt.push_back(-99.);
632 m_eLOC1_flt.push_back(-99.);
633 m_ePHI_flt.push_back(-99.);
634 m_eTHETA_flt.push_back(-99.);
635 m_eQOP_flt.push_back(-99.);
636 m_eT_flt.push_back(-99.);
637 m_res_eLOC0_flt.push_back(-99.);
638 m_res_eLOC1_flt.push_back(-99.);
639 m_res_ePHI_flt.push_back(-99.);
640 m_res_eTHETA_flt.push_back(-99.);
641 m_res_eQOP_flt.push_back(-99.);
642 m_res_eT_flt.push_back(-99.);
643 m_err_eLOC0_flt.push_back(-99);
644 m_err_eLOC1_flt.push_back(-99);
645 m_err_ePHI_flt.push_back(-99);
646 m_err_eTHETA_flt.push_back(-99);
647 m_err_eQOP_flt.push_back(-99);
648 m_err_eT_flt.push_back(-99);
649 m_pull_eLOC0_flt.push_back(-99.);
650 m_pull_eLOC1_flt.push_back(-99.);
651 m_pull_ePHI_flt.push_back(-99.);
652 m_pull_eTHETA_flt.push_back(-99.);
653 m_pull_eQOP_flt.push_back(-99.);
654 m_pull_eT_flt.push_back(-99.);
655 m_x_flt.push_back(-99.);
656 m_y_flt.push_back(-99.);
657 m_z_flt.push_back(-99.);
658 m_py_flt.push_back(-99.);
659 m_pz_flt.push_back(-99.);
660 m_pT_flt.push_back(-99.);
661 m_eta_flt.push_back(-99.);
662 m_chi2.push_back(-99.0);
666 bool smoothed =
false;
667 if (state.hasSmoothed()) {
671 auto covariance = state.smoothedCovariance();
682 m_res_eLOC0_smt.push_back(
parameters[Acts::eBoundLoc0] - truthLOC0);
683 m_res_eLOC1_smt.push_back(
parameters[Acts::eBoundLoc1] - truthLOC1);
684 m_res_ePHI_smt.push_back(
parameters[Acts::eBoundPhi] - truthPHI);
685 m_res_eTHETA_smt.push_back(
parameters[Acts::eBoundTheta] - truthTHETA);
686 m_res_eQOP_smt.push_back(
parameters[Acts::eBoundQOverP] - truthQOP);
687 m_res_eT_smt.push_back(
parameters[Acts::eBoundTime] - truthTIME);
690 m_err_eLOC0_smt.push_back(
691 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
692 m_err_eLOC1_smt.push_back(
693 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
694 m_err_ePHI_smt.push_back(
695 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
696 m_err_eTHETA_smt.push_back(
697 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
698 m_err_eQOP_smt.push_back(
699 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
700 m_err_eT_smt.push_back(
701 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
704 m_pull_eLOC0_smt.push_back(
706 sqrt(covariance(Acts::eBoundLoc0, Acts::eBoundLoc0)));
707 m_pull_eLOC1_smt.push_back(
709 sqrt(covariance(Acts::eBoundLoc1, Acts::eBoundLoc1)));
710 m_pull_ePHI_smt.push_back(
712 sqrt(covariance(Acts::eBoundPhi, Acts::eBoundPhi)));
713 m_pull_eTHETA_smt.push_back(
714 (
parameters[Acts::eBoundTheta] - truthTHETA) /
715 sqrt(covariance(Acts::eBoundTheta, Acts::eBoundTheta)));
716 m_pull_eQOP_smt.push_back(
718 sqrt(covariance(Acts::eBoundQOverP, Acts::eBoundQOverP)));
719 m_pull_eT_smt.push_back(
721 sqrt(covariance(Acts::eBoundTime, Acts::eBoundTime)));
734 m_pT_smt.push_back(
p * std::hypot(freeParams[Acts::eFreeDir0],
735 freeParams[Acts::eFreeDir1]));
740 m_eLOC0_smt.push_back(-99.);
741 m_eLOC1_smt.push_back(-99.);
742 m_ePHI_smt.push_back(-99.);
743 m_eTHETA_smt.push_back(-99.);
744 m_eQOP_smt.push_back(-99.);
745 m_eT_smt.push_back(-99.);
746 m_res_eLOC0_smt.push_back(-99.);
747 m_res_eLOC1_smt.push_back(-99.);
748 m_res_ePHI_smt.push_back(-99.);
749 m_res_eTHETA_smt.push_back(-99.);
750 m_res_eQOP_smt.push_back(-99.);
751 m_res_eT_smt.push_back(-99.);
752 m_err_eLOC0_smt.push_back(-99);
753 m_err_eLOC1_smt.push_back(-99);
754 m_err_ePHI_smt.push_back(-99);
755 m_err_eTHETA_smt.push_back(-99);
756 m_err_eQOP_smt.push_back(-99);
757 m_err_eT_smt.push_back(-99);
758 m_pull_eLOC0_smt.push_back(-99.);
759 m_pull_eLOC1_smt.push_back(-99.);
760 m_pull_ePHI_smt.push_back(-99.);
761 m_pull_eTHETA_smt.push_back(-99.);
762 m_pull_eQOP_smt.push_back(-99.);
763 m_pull_eT_smt.push_back(-99.);
764 m_x_smt.push_back(-99.);
765 m_y_smt.push_back(-99.);
766 m_z_smt.push_back(-99.);
767 m_px_smt.push_back(-99.);
768 m_py_smt.push_back(-99.);
769 m_pz_smt.push_back(-99.);
770 m_pT_smt.push_back(-99.);
771 m_eta_smt.push_back(-99.);
774 m_prt.push_back(predicted);
775 m_flt.push_back(filtered);
776 m_smt.push_back(smoothed);
781 m_outputTree->Fill();
810 m_pull_x_hit.clear();
811 m_pull_y_hit.clear();
818 m_eTHETA_prt.clear();
821 m_res_eLOC0_prt.clear();
822 m_res_eLOC1_prt.clear();
823 m_res_ePHI_prt.clear();
824 m_res_eTHETA_prt.clear();
825 m_res_eQOP_prt.clear();
826 m_res_eT_prt.clear();
827 m_err_eLOC0_prt.clear();
828 m_err_eLOC1_prt.clear();
829 m_err_ePHI_prt.clear();
830 m_err_eTHETA_prt.clear();
831 m_err_eQOP_prt.clear();
832 m_err_eT_prt.clear();
833 m_pull_eLOC0_prt.clear();
834 m_pull_eLOC1_prt.clear();
835 m_pull_ePHI_prt.clear();
836 m_pull_eTHETA_prt.clear();
837 m_pull_eQOP_prt.clear();
838 m_pull_eT_prt.clear();
852 m_eTHETA_flt.clear();
855 m_res_eLOC0_flt.clear();
856 m_res_eLOC1_flt.clear();
857 m_res_ePHI_flt.clear();
858 m_res_eTHETA_flt.clear();
859 m_res_eQOP_flt.clear();
860 m_res_eT_flt.clear();
861 m_err_eLOC0_flt.clear();
862 m_err_eLOC1_flt.clear();
863 m_err_ePHI_flt.clear();
864 m_err_eTHETA_flt.clear();
865 m_err_eQOP_flt.clear();
866 m_err_eT_flt.clear();
867 m_pull_eLOC0_flt.clear();
868 m_pull_eLOC1_flt.clear();
869 m_pull_ePHI_flt.clear();
870 m_pull_eTHETA_flt.clear();
871 m_pull_eQOP_flt.clear();
872 m_pull_eT_flt.clear();
887 m_eTHETA_smt.clear();
890 m_res_eLOC0_smt.clear();
891 m_res_eLOC1_smt.clear();
892 m_res_ePHI_smt.clear();
893 m_res_eTHETA_smt.clear();
894 m_res_eQOP_smt.clear();
895 m_res_eT_smt.clear();
896 m_err_eLOC0_smt.clear();
897 m_err_eLOC1_smt.clear();
898 m_err_ePHI_smt.clear();
899 m_err_eTHETA_smt.clear();
900 m_err_eQOP_smt.clear();
901 m_err_eT_smt.clear();
902 m_pull_eLOC0_smt.clear();
903 m_pull_eLOC1_smt.clear();
904 m_pull_ePHI_smt.clear();
905 m_pull_eTHETA_smt.clear();
906 m_pull_eQOP_smt.clear();
907 m_pull_eT_smt.clear();