51 namespace fs = boost::filesystem;
54 if (!fs::exists(configPath)) {
55 std::stringstream msg;
56 msg << fName <<
": configuration file " << configPath.string() <<
" does not exist";
57 throw std::runtime_error(msg.str());
60 LOG_(info, 1) <<
"applying configuration from " << configPath.string();
61 auto config = yml::ReadFromFile<cbm::algo::kfp::V0FinderConfig>(configPath);
63 LOG_(info, 1) << config.ToString();
67 if (config.reconstructPdg != 3122) {
68 std::stringstream msg;
69 msg << fName <<
": at the moment only lambda finding is possible. Provided PDG: " << config.reconstructPdg;
70 throw std::runtime_error(msg.str());
74 auto& particles = config.cuts.particles;
77 for (
int iPart = 0; iPart < int(particles.size()); ++iPart) {
78 const auto& particle = particles[iPart];
79 if (particle.pdg == -211) {
84 std::stringstream msg;
85 msg << fName <<
": pion entry is defined more then one time in the config.cuts.particles";
86 throw std::runtime_error(msg.str());
89 else if (particle.pdg == 2212) {
94 std::stringstream msg;
95 msg << fName <<
": proton entry is defined more then one time in the config.cuts.particles";
96 throw std::runtime_error(msg.str());
100 if (iProton == -1 || iPion == -1) {
101 std::stringstream msg;
102 msg << fName <<
": config cuts/particles: either pion or proton settings are not found";
103 throw std::runtime_error(msg.str());
106 const auto& pion{particles[iPion]};
107 const auto& proton{particles[iProton]};
121 auto& kfpCuts = config.cuts.kfp;
124 SetLCut(kfpCuts.minDecayLength);
206 int nTracksSelected{0};
209 std::vector<const CbmGlobalTrack*> vpSelectedTracks;
210 vpSelectedTracks.reserve(nTracks);
211 std::vector<int> vSelectedTrackIds;
212 vSelectedTrackIds.reserve(nTracks);
215 if constexpr (UseEvent) {
217 if (std::isnan(t0)) {
224 for (
int iTrkEvt{0}; iTrkEvt < nTracks; ++iTrkEvt) {
231 switch (pGlobalTrack->GetPidHypo()) {
239 vpSelectedTracks.push_back(pGlobalTrack);
240 vSelectedTrackIds.push_back(iTrk);
243 if (nProtons < 1 || nPions < 1) {
257 std::vector<float> vChi2ToPv;
258 vChi2ToPv.resize(nTracksSelected, 999.);
260 KFPTrackVector kfpTracksFst =
MakeKfpTrackVector(vpSelectedTracks, vSelectedTrackIds, vChi2ToPv,
true);
261 KFPTrackVector kfpTracksLst =
MakeKfpTrackVector(vpSelectedTracks, vSelectedTrackIds, vChi2ToPv,
false);
280 if (particle.GetPDG() == 3122) {
283 fpQa->fph_lambda_cand_mass->Fill(particle.GetMass());
289 auto& triggers = (*fpBrEventTriggers)[pEvent ? pEvent->
GetNumber() : 0];
489 LOG_(info, 1) <<
"initializing the task ... ";
498 ERR_ <<
"Desirable configuration of PID or PV handling was not implemented yet";
506 catch (
const std::exception& err) {
507 ERR_ <<
"configuration from a config was required, but failed. Reason: " << err.what();
515 auto* pFairManager = FairRootManager::Instance();
517 ERR_ <<
"FairRootManager not found";
521 auto InitBranch = [&](TClonesArray*& branch,
const char* name) ->
bool {
522 branch =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(name));
524 ERR_ <<
"branch \"" << name <<
"\" not found";
530 bool bBranchesInitialized{
true};
532 bBranchesInitialized = InitBranch(
fpBrRecoEvents,
"CbmEvent") && bBranchesInitialized;
534 bBranchesInitialized = InitBranch(
fpBrGlobalTracks,
"GlobalTrack") && bBranchesInitialized;
535 bBranchesInitialized = InitBranch(
fpBrStsTracks,
"StsTrack") && bBranchesInitialized;
536 bBranchesInitialized = InitBranch(
fpBrTrdTracks,
"TrdTrack") && bBranchesInitialized;
537 bBranchesInitialized = InitBranch(
fpBrTofTracks,
"TofTrack") && bBranchesInitialized;
538 bBranchesInitialized = InitBranch(
fpBrStsHits,
"StsHit") && bBranchesInitialized;
539 bBranchesInitialized = InitBranch(
fpBrTrdHits,
"TrdHit") && bBranchesInitialized;
540 bBranchesInitialized = InitBranch(
fpBrTofHits,
"TofHit") && bBranchesInitialized;
545 ERR_ <<
"branch \"PrimaryVertex.\" not found";
546 bBranchesInitialized =
false;
550 double x{pTarget->GetX()};
551 double y{pTarget->GetY()};
552 double z{pTarget->GetZ()};
553 LOG_(info, 1) <<
"using target center as origin: r = (" <<
x <<
", " <<
y <<
", " << z <<
") [cm]";
554 TMatrixFSym covMatrix(3);
555 covMatrix(1, 0) = 0.;
556 covMatrix(2, 0) = 0.;
557 covMatrix(2, 1) = 0.;
562 covMatrix(0, 0) = 0.;
563 covMatrix(1, 1) = 0.;
564 covMatrix(2, 2) = 0.;
565 fpOrigin->SetVertex(
x,
y, z, 0., 1, 0, covMatrix);
568 if (!bBranchesInitialized) {
574 if (pFairManager->GetObject(
"CbmEventTriggers")) {
575 LOG(error) <<
"Branch \"CbmEventTriggers\" already exists!";
579 LOG_(info, 1) <<
"registering branch \"CbmEventTriggers\"";
582 fpTopoReconstructorRun->SetTarget({float(pTarget->GetX()), float(pTarget->GetY()), float(pTarget->GetZ())});
594 fpQa->InitHistograms();
597 LOG_(info, 1) <<
"initializing the task ... done";
604 const std::vector<int>& vTrackIds,
const std::vector<float>& vChi2ToPv,
605 bool bAtFirstPoint)
const
611 KFPTrackVector trackVector;
612 int nTracks = vpTracks.size();
613 trackVector.Resize(nTracks);
614 for (
int iTrk = 0; iTrk < nTracks; ++iTrk) {
615 const auto* pTrack{vpTracks[iTrk]};
616 const auto* pParam{bAtFirstPoint ? pTrack->GetParamFirst() : pTrack->GetParamLast()};
619 int pdg{pTrack->GetPidHypo()};
620 const double& tx{pParam->GetTx()};
621 const double& ty{pParam->GetTy()};
622 const double& qp{pParam->GetQp()};
623 int q{qp > 0. ? 1 : -1};
624 if (std::fabs(pdg) == 10000020030 || std::fabs(pdg == 1000020040)) {
630 double t2inv{1. / (1. + tx * tx + ty * ty)};
631 double pz{std::sqrt(t2inv * p2)};
635 trackVector.SetParameter(pParam->GetX(), 0, iTrk);
636 trackVector.SetParameter(pParam->GetY(), 1, iTrk);
637 trackVector.SetParameter(pParam->GetZ(), 2, iTrk);
638 trackVector.SetParameter(px, 3, iTrk);
639 trackVector.SetParameter(py, 4, iTrk);
640 trackVector.SetParameter(pz, 5, iTrk);
643 std::array<std::array<double, 3>, 3> Jp;
644 Jp[2][0] = -t2inv * px;
645 Jp[2][1] = -t2inv * py;
647 Jp[0][0] = tx * Jp[2][0] + pz;
648 Jp[0][1] = tx * Jp[2][1];
649 Jp[0][2] = tx * Jp[2][2];
650 Jp[1][0] = ty * Jp[2][0];
651 Jp[1][1] = ty * Jp[2][1] + pz;
652 Jp[1][2] = ty * Jp[2][2];
656 trackVector.SetCovariance(pParam->GetCovariance(0, 0), 0, iTrk);
657 trackVector.SetCovariance(pParam->GetCovariance(0, 1), 1, iTrk);
658 trackVector.SetCovariance(pParam->GetCovariance(1, 1), 2, iTrk);
661 auto MomPosCovariance = [&](
const int k,
const int l) constexpr->double
664 const auto& JpA = Jp[k];
665 for (
int i = 0; i < 3; ++i) {
666 val += JpA[i] * pParam->GetCovariance(i + 2, l);
670 trackVector.SetCovariance(MomPosCovariance(0, 0), 6, iTrk);
671 trackVector.SetCovariance(MomPosCovariance(0, 1), 7, iTrk);
672 trackVector.SetCovariance(MomPosCovariance(1, 0), 10, iTrk);
673 trackVector.SetCovariance(MomPosCovariance(1, 1), 11, iTrk);
674 trackVector.SetCovariance(MomPosCovariance(2, 0), 15, iTrk);
675 trackVector.SetCovariance(MomPosCovariance(2, 1), 16, iTrk);
678 auto MomentumCovariance = [&](
const int k,
const int l) constexpr->double
681 const auto& JpA = Jp[k];
682 const auto& JpB = Jp[l];
683 for (
int i = 0; i < 3; ++i) {
685 for (
int j = 0; j < 3; ++j) {
686 factor += JpB[j] * pParam->GetCovariance(i + 2, j + 2);
688 val += JpA[i] * factor;
692 trackVector.SetCovariance(MomentumCovariance(0, 0), 9, iTrk);
693 trackVector.SetCovariance(MomentumCovariance(1, 0), 13, iTrk);
694 trackVector.SetCovariance(MomentumCovariance(1, 1), 14, iTrk);
695 trackVector.SetCovariance(MomentumCovariance(2, 0), 18, iTrk);
696 trackVector.SetCovariance(MomentumCovariance(2, 1), 19, iTrk);
697 trackVector.SetCovariance(MomentumCovariance(2, 2), 20, iTrk);
702 trackVector.SetCovariance(0.f, 3, iTrk);
703 trackVector.SetCovariance(0.f, 4, iTrk);
704 trackVector.SetCovariance(0.f, 5, iTrk);
705 trackVector.SetCovariance(0.f, 8, iTrk);
706 trackVector.SetCovariance(0.f, 12, iTrk);
707 trackVector.SetCovariance(0.f, 17, iTrk);
712 for (
int iF = 0; iF < 10; ++iF) {
713 trackVector.SetFieldCoefficient(0.f, iF, iTrk);
716 trackVector.SetId(vTrackIds[iTrk], iTrk);
717 trackVector.SetPDG(pdg, iTrk);
718 trackVector.SetQ(q, iTrk);
719 trackVector.SetNPixelHits(0, iTrk);
721 if (EPvUsageMode::Reconstructed == fPvUsageMode || EPvUsageMode::Mc == fPvUsageMode) {
722 if (vChi2ToPv[iTrk] < kChi2PvPrimThrsh) {
723 trackVector.SetPVIndex(0, iTrk);
726 trackVector.SetPVIndex(-1, iTrk);
730 trackVector.SetPVIndex(-1, iTrk);