32 :
WriterT(cfg.inputTrajectories,
"RootTrajectoryWriter", lvl),
34 m_outputFile(cfg.rootFile) {
37 throw std::invalid_argument(
"Missing input trajectory collection");
39 throw std::invalid_argument(
"Missing input particle collection");
41 throw std::invalid_argument(
"Missing output filename");
43 throw std::invalid_argument(
"Missing tree name");
51 throw std::ios_base::failure(
"Could not open '" + path);
58 throw std::bad_alloc();
233 m_outputFile->Close();
240 m_outputTree->Write();
242 << m_cfg.outputTreename <<
"' in '"
243 <<
joinPaths(m_cfg.outputDir, m_cfg.outputFilename) <<
"'");
250 if (m_outputFile ==
nullptr)
256 const auto& particles =
260 std::lock_guard<std::mutex> lock(m_writeMutex);
267 for (
const auto& traj : trajectories) {
272 m_nMeasurements = traj.numMeasurements();
275 if (m_nMeasurements == 0) {
280 m_nStates = traj.numStates();
283 const auto particleHitCount = traj.identifyMajorityParticle();
284 if (not particleHitCount.empty()) {
286 m_t_barcode = particleHitCount.front().particleId.value();
288 auto ip = particles.find(m_t_barcode);
289 if (ip != particles.end()) {
291 ACTS_DEBUG(
"Find the truth particle with barcode = " << m_t_barcode);
299 m_t_px =
p *
particle.unitDirection().x();
300 m_t_py =
p *
particle.unitDirection().y();
301 m_t_pz =
p *
particle.unitDirection().z();
307 ACTS_WARNING(
"Truth particle with barcode = " << m_t_barcode
313 m_hasFittedParams =
false;
314 if (traj.hasTrackParameters()) {
315 m_hasFittedParams =
true;
316 const auto& boundParam = traj.trackParameters();
317 const auto& parameter = boundParam.parameters();
318 const auto& covariance = *boundParam.covariance();
326 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0));
337 const auto& [trackTip, mj] = traj.trajectory();
343 mj.visitBackwards(trackTip, [&](
const auto& state) {
345 auto typeFlags = state.typeFlags();
351 auto geoID = state.referenceSurface().geoID();
352 m_volumeID.push_back(geoID.volume());
353 m_layerID.push_back(geoID.layer());
354 m_moduleID.push_back(geoID.sensitive());
356 auto meas = std::get<Measurement>(*state.uncalibrated());
364 meas.referenceSurface().localToGlobal(ctx.
geoContext,
local, mom, global);
367 auto cov = meas.covariance();
372 m_lx_hit.push_back(
local.x());
373 m_ly_hit.push_back(
local.y());
374 m_x_hit.push_back(global.x());
375 m_y_hit.push_back(global.y());
376 m_z_hit.push_back(global.z());
379 const auto& truthHit = state.uncalibrated().truthHit();
382 meas.referenceSurface().globalToLocal(
383 gctx, truthHit.position(), truthHit.unitDirection(), truthlocal);
386 m_t_x.push_back(truthHit.position().x());
387 m_t_y.push_back(truthHit.position().y());
388 m_t_z.push_back(truthHit.position().z());
389 m_t_r.push_back(
perp(truthHit.position()));
390 m_t_dx.push_back(truthHit.unitDirection().x());
391 m_t_dy.push_back(truthHit.unitDirection().y());
392 m_t_dz.push_back(truthHit.unitDirection().z());
395 float truthLOC0 = 0, truthLOC1 = 0, truthPHI = 0, truthTHETA = 0,
396 truthQOP = 0, truthTIME = 0;
397 truthLOC0 = truthlocal.x();
398 truthLOC1 = truthlocal.y();
399 truthPHI =
phi(truthHit.unitDirection());
400 truthTHETA =
theta(truthHit.unitDirection());
402 m_t_charge / truthHit.momentum4Before().template head<3>().
norm();
403 truthTIME = truthHit.time();
406 m_t_eLOC0.push_back(truthLOC0);
407 m_t_eLOC1.push_back(truthLOC1);
408 m_t_ePHI.push_back(truthPHI);
409 m_t_eTHETA.push_back(truthTHETA);
410 m_t_eQOP.push_back(truthQOP);
411 m_t_eT.push_back(truthTIME);
414 bool predicted =
false;
415 if (state.hasPredicted()) {
419 gctx, state.predictedCovariance(), state.predicted(),
420 state.referenceSurface().getSharedPtr());
421 auto covariance = state.predictedCovariance();
423 auto H = meas.projector();
424 auto resCov = cov +
H * covariance *
H.transpose();
425 auto residual = meas.residual(parameter);
426 m_res_x_hit.push_back(residual(Acts::ParDef::eLOC_0));
428 m_err_x_hit.push_back(
429 sqrt(resCov(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
430 m_err_y_hit.push_back(
432 m_pull_x_hit.push_back(
433 residual(Acts::ParDef::eLOC_0) /
434 sqrt(resCov(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
435 m_pull_y_hit.push_back(
438 m_dim_hit.push_back(state.calibratedSize());
455 m_res_eTHETA_prt.push_back(
463 m_err_eLOC0_prt.push_back(
464 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
465 m_err_eLOC1_prt.push_back(
467 m_err_ePHI_prt.push_back(
469 m_err_eTHETA_prt.push_back(
471 m_err_eQOP_prt.push_back(
473 m_err_eT_prt.push_back(
477 m_pull_eLOC0_prt.push_back(
479 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
480 m_pull_eLOC1_prt.push_back(
483 m_pull_ePHI_prt.push_back(
486 m_pull_eTHETA_prt.push_back(
489 m_pull_eQOP_prt.push_back(
492 m_pull_eT_prt.push_back(
497 m_x_prt.push_back(parameter.position().x());
498 m_y_prt.push_back(parameter.position().y());
499 m_z_prt.push_back(parameter.position().z());
500 m_px_prt.push_back(parameter.momentum().x());
501 m_py_prt.push_back(parameter.momentum().y());
502 m_pz_prt.push_back(parameter.momentum().z());
503 m_pT_prt.push_back(parameter.pT());
504 m_eta_prt.push_back(
eta(parameter.position()));
507 m_res_x_hit.push_back(-99.);
508 m_res_y_hit.push_back(-99.);
509 m_err_x_hit.push_back(-99.);
510 m_err_y_hit.push_back(-99.);
511 m_pull_x_hit.push_back(-99.);
512 m_pull_y_hit.push_back(-99.);
513 m_dim_hit.push_back(-99.);
514 m_eLOC0_prt.push_back(-99.);
515 m_eLOC1_prt.push_back(-99.);
516 m_ePHI_prt.push_back(-99.);
517 m_eTHETA_prt.push_back(-99.);
518 m_eQOP_prt.push_back(-99.);
519 m_eT_prt.push_back(-99.);
520 m_res_eLOC0_prt.push_back(-99.);
521 m_res_eLOC1_prt.push_back(-99.);
522 m_res_ePHI_prt.push_back(-99.);
523 m_res_eTHETA_prt.push_back(-99.);
524 m_res_eQOP_prt.push_back(-99.);
525 m_res_eT_prt.push_back(-99.);
526 m_err_eLOC0_prt.push_back(-99);
527 m_err_eLOC1_prt.push_back(-99);
528 m_err_ePHI_prt.push_back(-99);
529 m_err_eTHETA_prt.push_back(-99);
530 m_err_eQOP_prt.push_back(-99);
531 m_err_eT_prt.push_back(-99);
532 m_pull_eLOC0_prt.push_back(-99.);
533 m_pull_eLOC1_prt.push_back(-99.);
534 m_pull_ePHI_prt.push_back(-99.);
535 m_pull_eTHETA_prt.push_back(-99.);
536 m_pull_eQOP_prt.push_back(-99.);
537 m_pull_eT_prt.push_back(-99.);
538 m_x_prt.push_back(-99.);
539 m_y_prt.push_back(-99.);
540 m_z_prt.push_back(-99.);
541 m_px_prt.push_back(-99.);
542 m_py_prt.push_back(-99.);
543 m_pz_prt.push_back(-99.);
544 m_pT_prt.push_back(-99.);
545 m_eta_prt.push_back(-99.);
549 bool filtered =
false;
550 if (state.hasFiltered()) {
554 gctx, state.filteredCovariance(), state.filtered(),
555 state.referenceSurface().getSharedPtr());
556 auto covariance = state.filteredCovariance();
572 m_res_eTHETA_flt.push_back(
580 m_err_eLOC0_flt.push_back(
581 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
582 m_err_eLOC1_flt.push_back(
584 m_err_ePHI_flt.push_back(
586 m_err_eTHETA_flt.push_back(
588 m_err_eQOP_flt.push_back(
590 m_err_eT_flt.push_back(
594 m_pull_eLOC0_flt.push_back(
596 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
597 m_pull_eLOC1_flt.push_back(
600 m_pull_ePHI_flt.push_back(
603 m_pull_eTHETA_flt.push_back(
606 m_pull_eQOP_flt.push_back(
609 m_pull_eT_flt.push_back(
614 m_x_flt.push_back(parameter.position().x());
615 m_y_flt.push_back(parameter.position().y());
616 m_z_flt.push_back(parameter.position().z());
617 m_px_flt.push_back(parameter.momentum().x());
618 m_py_flt.push_back(parameter.momentum().y());
619 m_pz_flt.push_back(parameter.momentum().z());
620 m_pT_flt.push_back(parameter.pT());
621 m_eta_flt.push_back(
eta(parameter.position()));
622 m_chi2.push_back(state.chi2());
625 m_eLOC0_flt.push_back(-99.);
626 m_eLOC1_flt.push_back(-99.);
627 m_ePHI_flt.push_back(-99.);
628 m_eTHETA_flt.push_back(-99.);
629 m_eQOP_flt.push_back(-99.);
630 m_eT_flt.push_back(-99.);
631 m_res_eLOC0_flt.push_back(-99.);
632 m_res_eLOC1_flt.push_back(-99.);
633 m_res_ePHI_flt.push_back(-99.);
634 m_res_eTHETA_flt.push_back(-99.);
635 m_res_eQOP_flt.push_back(-99.);
636 m_res_eT_flt.push_back(-99.);
637 m_err_eLOC0_flt.push_back(-99);
638 m_err_eLOC1_flt.push_back(-99);
639 m_err_ePHI_flt.push_back(-99);
640 m_err_eTHETA_flt.push_back(-99);
641 m_err_eQOP_flt.push_back(-99);
642 m_err_eT_flt.push_back(-99);
643 m_pull_eLOC0_flt.push_back(-99.);
644 m_pull_eLOC1_flt.push_back(-99.);
645 m_pull_ePHI_flt.push_back(-99.);
646 m_pull_eTHETA_flt.push_back(-99.);
647 m_pull_eQOP_flt.push_back(-99.);
648 m_pull_eT_flt.push_back(-99.);
649 m_x_flt.push_back(-99.);
650 m_y_flt.push_back(-99.);
651 m_z_flt.push_back(-99.);
652 m_py_flt.push_back(-99.);
653 m_pz_flt.push_back(-99.);
654 m_pT_flt.push_back(-99.);
655 m_eta_flt.push_back(-99.);
656 m_chi2.push_back(-99.0);
660 bool smoothed =
false;
661 if (state.hasSmoothed()) {
665 gctx, state.smoothedCovariance(), state.smoothed(),
666 state.referenceSurface().getSharedPtr());
667 auto covariance = state.smoothedCovariance();
684 m_res_eTHETA_smt.push_back(
692 m_err_eLOC0_smt.push_back(
693 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
694 m_err_eLOC1_smt.push_back(
696 m_err_ePHI_smt.push_back(
698 m_err_eTHETA_smt.push_back(
700 m_err_eQOP_smt.push_back(
702 m_err_eT_smt.push_back(
706 m_pull_eLOC0_smt.push_back(
708 sqrt(covariance(Acts::ParDef::eLOC_0, Acts::ParDef::eLOC_0)));
709 m_pull_eLOC1_smt.push_back(
712 m_pull_ePHI_smt.push_back(
715 m_pull_eTHETA_smt.push_back(
718 m_pull_eQOP_smt.push_back(
721 m_pull_eT_smt.push_back(
726 m_x_smt.push_back(parameter.position().x());
727 m_y_smt.push_back(parameter.position().y());
728 m_z_smt.push_back(parameter.position().z());
729 m_px_smt.push_back(parameter.momentum().x());
730 m_py_smt.push_back(parameter.momentum().y());
731 m_pz_smt.push_back(parameter.momentum().z());
732 m_pT_smt.push_back(parameter.pT());
733 m_eta_smt.push_back(
eta(parameter.position()));
736 m_eLOC0_smt.push_back(-99.);
737 m_eLOC1_smt.push_back(-99.);
738 m_ePHI_smt.push_back(-99.);
739 m_eTHETA_smt.push_back(-99.);
740 m_eQOP_smt.push_back(-99.);
741 m_eT_smt.push_back(-99.);
742 m_res_eLOC0_smt.push_back(-99.);
743 m_res_eLOC1_smt.push_back(-99.);
744 m_res_ePHI_smt.push_back(-99.);
745 m_res_eTHETA_smt.push_back(-99.);
746 m_res_eQOP_smt.push_back(-99.);
747 m_res_eT_smt.push_back(-99.);
748 m_err_eLOC0_smt.push_back(-99);
749 m_err_eLOC1_smt.push_back(-99);
750 m_err_ePHI_smt.push_back(-99);
751 m_err_eTHETA_smt.push_back(-99);
752 m_err_eQOP_smt.push_back(-99);
753 m_err_eT_smt.push_back(-99);
754 m_pull_eLOC0_smt.push_back(-99.);
755 m_pull_eLOC1_smt.push_back(-99.);
756 m_pull_ePHI_smt.push_back(-99.);
757 m_pull_eTHETA_smt.push_back(-99.);
758 m_pull_eQOP_smt.push_back(-99.);
759 m_pull_eT_smt.push_back(-99.);
760 m_x_smt.push_back(-99.);
761 m_y_smt.push_back(-99.);
762 m_z_smt.push_back(-99.);
763 m_px_smt.push_back(-99.);
764 m_py_smt.push_back(-99.);
765 m_pz_smt.push_back(-99.);
766 m_pT_smt.push_back(-99.);
767 m_eta_smt.push_back(-99.);
770 m_prt.push_back(predicted);
771 m_flt.push_back(filtered);
772 m_smt.push_back(smoothed);
777 m_outputTree->Fill();
806 m_pull_x_hit.clear();
807 m_pull_y_hit.clear();
814 m_eTHETA_prt.clear();
817 m_res_eLOC0_prt.clear();
818 m_res_eLOC1_prt.clear();
819 m_res_ePHI_prt.clear();
820 m_res_eTHETA_prt.clear();
821 m_res_eQOP_prt.clear();
822 m_res_eT_prt.clear();
823 m_err_eLOC0_prt.clear();
824 m_err_eLOC1_prt.clear();
825 m_err_ePHI_prt.clear();
826 m_err_eTHETA_prt.clear();
827 m_err_eQOP_prt.clear();
828 m_err_eT_prt.clear();
829 m_pull_eLOC0_prt.clear();
830 m_pull_eLOC1_prt.clear();
831 m_pull_ePHI_prt.clear();
832 m_pull_eTHETA_prt.clear();
833 m_pull_eQOP_prt.clear();
834 m_pull_eT_prt.clear();
848 m_eTHETA_flt.clear();
851 m_res_eLOC0_flt.clear();
852 m_res_eLOC1_flt.clear();
853 m_res_ePHI_flt.clear();
854 m_res_eTHETA_flt.clear();
855 m_res_eQOP_flt.clear();
856 m_res_eT_flt.clear();
857 m_err_eLOC0_flt.clear();
858 m_err_eLOC1_flt.clear();
859 m_err_ePHI_flt.clear();
860 m_err_eTHETA_flt.clear();
861 m_err_eQOP_flt.clear();
862 m_err_eT_flt.clear();
863 m_pull_eLOC0_flt.clear();
864 m_pull_eLOC1_flt.clear();
865 m_pull_ePHI_flt.clear();
866 m_pull_eTHETA_flt.clear();
867 m_pull_eQOP_flt.clear();
868 m_pull_eT_flt.clear();
883 m_eTHETA_smt.clear();
886 m_res_eLOC0_smt.clear();
887 m_res_eLOC1_smt.clear();
888 m_res_ePHI_smt.clear();
889 m_res_eTHETA_smt.clear();
890 m_res_eQOP_smt.clear();
891 m_res_eT_smt.clear();
892 m_err_eLOC0_smt.clear();
893 m_err_eLOC1_smt.clear();
894 m_err_ePHI_smt.clear();
895 m_err_eTHETA_smt.clear();
896 m_err_eQOP_smt.clear();
897 m_err_eT_smt.clear();
898 m_pull_eLOC0_smt.clear();
899 m_pull_eLOC1_smt.clear();
900 m_pull_ePHI_smt.clear();
901 m_pull_eTHETA_smt.clear();
902 m_pull_eQOP_smt.clear();
903 m_pull_eT_smt.clear();