56 namespace fs = boost::filesystem;
59 if (!fs::exists(configPath)) {
60 std::stringstream msg;
61 msg << fName <<
": configuration file " << configPath.string() <<
" does not exist";
62 throw std::runtime_error(msg.str());
65 LOG_(info, 1) <<
"applying configuration from " << configPath.string();
66 auto config = yml::ReadFromFile<cbm::algo::kfp::V0FinderConfig>(configPath);
68 LOG_(info, 1) << config.ToString();
72 if (config.reconstructPdg != 3122) {
73 std::stringstream msg;
74 msg << fName <<
": at the moment only lambda finding is possible. Provided PDG: " << config.reconstructPdg;
75 throw std::runtime_error(msg.str());
79 auto& particles = config.cuts.particles;
82 for (
int iPart = 0; iPart < int(particles.size()); ++iPart) {
83 const auto& particle = particles[iPart];
84 if (particle.pdg == -211) {
89 std::stringstream msg;
90 msg << fName <<
": pion entry is defined more then one time in the config.cuts.particles";
91 throw std::runtime_error(msg.str());
94 else if (particle.pdg == 2212) {
99 std::stringstream msg;
100 msg << fName <<
": proton entry is defined more then one time in the config.cuts.particles";
101 throw std::runtime_error(msg.str());
105 if (iProton == -1 || iPion == -1) {
106 std::stringstream msg;
107 msg << fName <<
": config cuts/particles: either pion or proton settings are not found";
108 throw std::runtime_error(msg.str());
111 const auto& pion{particles[iPion]};
112 const auto& proton{particles[iProton]};
174 int nTracksSelected{0};
177 std::vector<const CbmGlobalTrack*> vpSelectedTracks;
178 vpSelectedTracks.reserve(nTracks);
179 std::vector<int> vSelectedTrackIds;
180 vSelectedTrackIds.reserve(nTracks);
183 if constexpr (UseEvent) {
185 if (std::isnan(t0)) {
192 for (
int iTrkEvt{0}; iTrkEvt < nTracks; ++iTrkEvt) {
203 AssignMomentum(pGlobalTrack, std::numeric_limits<double>::quiet_NaN(), 0.);
207 Cutter_t::TrackProperty{.dcaRelToOrigin = trackInfo.dca, .beta = trackInfo.beta, .pid = trackPid})) {
214 switch (pGlobalTrack->GetPidHypo()) {
225 vpSelectedTracks.push_back(pGlobalTrack);
226 vSelectedTrackIds.push_back(iTrk);
234 if (nProtons < 1 || nPions < 1) {
244 std::vector<float> vChi2ToPv;
245 vChi2ToPv.resize(nTracksSelected, 999.);
247 KFPTrackVector kfpTracksFst =
MakeKfpTrackVector(vpSelectedTracks, vSelectedTrackIds, vChi2ToPv,
true);
248 KFPTrackVector kfpTracksLst =
MakeKfpTrackVector(vpSelectedTracks, vSelectedTrackIds, vChi2ToPv,
false);
267 if (particle.GetPDG() == 3122) {
273 auto& triggers = (*fpBrEventTriggers)[pEvent ? pEvent->
GetNumber() : 0];
473 LOG_(info, 1) <<
"initializing the task ... ";
482 ERR_ <<
"Desirable configuration of PID or PV handling was not implemented yet";
490 catch (
const std::exception& err) {
491 ERR_ <<
"configuration from a config was required, but failed. Reason: " << err.what();
497 ERR_ <<
"cut configuration file was not defined";
504 catch (
const std::exception& err) {
505 ERR_ <<
"cut configuration failed. Reason: " << err.what();
514 const auto* pTarget = kf::Target::Instance();
516 auto* pFairManager = FairRootManager::Instance();
518 ERR_ <<
"FairRootManager not found";
522 auto InitBranch = [&](TClonesArray*& branch,
const char* name) ->
bool {
523 branch =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(name));
525 ERR_ <<
"branch \"" << name <<
"\" not found";
531 bool bBranchesInitialized{
true};
533 bBranchesInitialized = InitBranch(
fpBrRecoEvents,
"CbmEvent") && bBranchesInitialized;
535 bBranchesInitialized = InitBranch(
fpBrGlobalTracks,
"GlobalTrack") && bBranchesInitialized;
536 bBranchesInitialized = InitBranch(
fpBrStsTracks,
"StsTrack") && bBranchesInitialized;
537 bBranchesInitialized = InitBranch(
fpBrTrdTracks,
"TrdTrack") && bBranchesInitialized;
538 bBranchesInitialized = InitBranch(
fpBrTofTracks,
"TofTrack") && bBranchesInitialized;
539 bBranchesInitialized = InitBranch(
fpBrStsHits,
"StsHit") && bBranchesInitialized;
540 bBranchesInitialized = InitBranch(
fpBrTrdHits,
"TrdHit") && bBranchesInitialized;
541 bBranchesInitialized = InitBranch(
fpBrTofHits,
"TofHit") && bBranchesInitialized;
546 ERR_ <<
"branch \"PrimaryVertex.\" not found";
547 bBranchesInitialized =
false;
551 double x{pTarget->GetX()};
552 double y{pTarget->GetY()};
553 double z{pTarget->GetZ()};
554 LOG_(info, 1) <<
"using target center as origin: r = (" <<
x <<
", " <<
y <<
", " << z <<
") [cm]";
555 TMatrixFSym covMatrix(3);
556 covMatrix(1, 0) = 0.;
557 covMatrix(2, 0) = 0.;
558 covMatrix(2, 1) = 0.;
563 covMatrix(0, 0) = 0.;
564 covMatrix(1, 1) = 0.;
565 covMatrix(2, 2) = 0.;
566 fpOrigin->SetVertex(
x,
y, z, 0., 1, 0, covMatrix);
569 if (!bBranchesInitialized) {
575 if (pFairManager->GetObject(
"CbmEventTriggers")) {
576 LOG(error) <<
"Branch \"CbmEventTriggers\" already exists!";
580 LOG_(info, 1) <<
"registering branch \"CbmEventTriggers\"";
583 fpTopoReconstructorTs->SetTarget({float(pTarget->GetX()), float(pTarget->GetY()), float(pTarget->GetZ())});
592 LOG_(info, 1) <<
"initializing the task ... done";
599 const std::vector<int>& vTrackIds,
const std::vector<float>& vChi2ToPv,
600 bool bAtFirstPoint)
const
606 KFPTrackVector trackVector;
607 int nTracks = vpTracks.size();
608 trackVector.Resize(nTracks);
609 for (
int iTrk = 0; iTrk < nTracks; ++iTrk) {
610 const auto* pTrack{vpTracks[iTrk]};
611 const auto* pParam{bAtFirstPoint ? pTrack->GetParamFirst() : pTrack->GetParamLast()};
614 int pdg{pTrack->GetPidHypo()};
615 const double& tx{pParam->GetTx()};
616 const double& ty{pParam->GetTy()};
617 const double& qp{pParam->GetQp()};
618 int q{qp > 0. ? 1 : -1};
619 if (std::fabs(pdg) == 10000020030 || std::fabs(pdg == 1000020040)) {
625 double t2inv{1. / (1. + tx * tx + ty * ty)};
626 double pz{std::sqrt(t2inv * p2)};
630 trackVector.SetParameter(pParam->GetX(), 0, iTrk);
631 trackVector.SetParameter(pParam->GetY(), 1, iTrk);
632 trackVector.SetParameter(pParam->GetZ(), 2, iTrk);
633 trackVector.SetParameter(px, 3, iTrk);
634 trackVector.SetParameter(py, 4, iTrk);
635 trackVector.SetParameter(pz, 5, iTrk);
638 std::array<std::array<double, 3>, 3> Jp;
639 Jp[2][0] = -t2inv * px;
640 Jp[2][1] = -t2inv * py;
642 Jp[0][0] = tx * Jp[2][0] + pz;
643 Jp[0][1] = tx * Jp[2][1];
644 Jp[0][2] = tx * Jp[2][2];
645 Jp[1][0] = ty * Jp[2][0];
646 Jp[1][1] = ty * Jp[2][1] + pz;
647 Jp[1][2] = ty * Jp[2][2];
651 trackVector.SetCovariance(pParam->GetCovariance(0, 0), 0, iTrk);
652 trackVector.SetCovariance(pParam->GetCovariance(0, 1), 1, iTrk);
653 trackVector.SetCovariance(pParam->GetCovariance(1, 1), 2, iTrk);
656 auto MomPosCovariance = [&](
const int k,
const int l) constexpr->double
659 const auto& JpA = Jp[k];
660 for (
int i = 0; i < 3; ++i) {
661 val += JpA[i] * pParam->GetCovariance(i + 2, l);
665 trackVector.SetCovariance(MomPosCovariance(0, 0), 6, iTrk);
666 trackVector.SetCovariance(MomPosCovariance(0, 1), 7, iTrk);
667 trackVector.SetCovariance(MomPosCovariance(1, 0), 10, iTrk);
668 trackVector.SetCovariance(MomPosCovariance(1, 1), 11, iTrk);
669 trackVector.SetCovariance(MomPosCovariance(2, 0), 15, iTrk);
670 trackVector.SetCovariance(MomPosCovariance(2, 1), 16, iTrk);
673 auto MomentumCovariance = [&](
const int k,
const int l) constexpr->double
676 const auto& JpA = Jp[k];
677 const auto& JpB = Jp[l];
678 for (
int i = 0; i < 3; ++i) {
680 for (
int j = 0; j < 3; ++j) {
681 factor += JpB[j] * pParam->GetCovariance(i + 2, j + 2);
683 val += JpA[i] * factor;
687 trackVector.SetCovariance(MomentumCovariance(0, 0), 9, iTrk);
688 trackVector.SetCovariance(MomentumCovariance(1, 0), 13, iTrk);
689 trackVector.SetCovariance(MomentumCovariance(1, 1), 14, iTrk);
690 trackVector.SetCovariance(MomentumCovariance(2, 0), 18, iTrk);
691 trackVector.SetCovariance(MomentumCovariance(2, 1), 19, iTrk);
692 trackVector.SetCovariance(MomentumCovariance(2, 2), 20, iTrk);
697 trackVector.SetCovariance(0.f, 3, iTrk);
698 trackVector.SetCovariance(0.f, 4, iTrk);
699 trackVector.SetCovariance(0.f, 5, iTrk);
700 trackVector.SetCovariance(0.f, 8, iTrk);
701 trackVector.SetCovariance(0.f, 12, iTrk);
702 trackVector.SetCovariance(0.f, 17, iTrk);
707 for (
int iF = 0; iF < 10; ++iF) {
708 trackVector.SetFieldCoefficient(0.f, iF, iTrk);
711 trackVector.SetId(vTrackIds[iTrk], iTrk);
712 trackVector.SetPDG(pdg, iTrk);
713 trackVector.SetQ(q, iTrk);
714 trackVector.SetNPixelHits(0, iTrk);
716 if (EPvUsageMode::Reconstructed == fPvUsageMode || EPvUsageMode::Mc == fPvUsageMode) {
717 if (vChi2ToPv[iTrk] < kChi2PvPrimThrsh) {
718 trackVector.SetPVIndex(0, iTrk);
721 trackVector.SetPVIndex(-1, iTrk);
725 trackVector.SetPVIndex(-1, iTrk);
784 std::for_each(vPVTrackIndexArray.begin(), vPVTrackIndexArray.end(), [&](
auto& item) { item += indexOffset; });
790 std::vector<ParticleInfo> vParticleInfoEvt(nParticlesEvt);
791 for (
size_t iP = 0; iP < nParticlesEvt; ++iP) {
793 KFParticle particle{particleEvt};
794 particle.CleanDaughtersId();
795 int nDaughters{particleEvt.NDaughters()};
796 auto& particleInfo = vParticleInfoEvt[iP];
797 if (nDaughters == 1) {
798 int iTrk{particleEvt.DaughterIds()[0]};
799 particle.AddDaughterId(iTrk);
801 particleInfo.beta = trkInfo.beta;
802 particleInfo.dca = trkInfo.dca;
803 particleInfo.pTofHit = trkInfo.pTofHit;
805 else if (nDaughters > 1) {
806 for (
int iD = 0; iD < particleEvt.NDaughters(); ++iD) {
807 particle.AddDaughterId(particleEvt.DaughterIds()[iD] + indexOffset);
810 particleInfo.eventID = pEvent->
GetNumber();
811 particle.SetId(particleEvt.Id() + indexOffset);