Belle II Software development
RecoTrack.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/RelationsObject.h>
13#include <framework/core/FrameworkExceptions.h>
14#include <framework/geometry/VectorUtil.h>
15
16#include <genfit/Track.h>
17
18#include <tracking/dataobjects/RecoHitInformation.h>
19
20#include <Math/Vector3D.h>
21
22#include <optional>
23#include <string>
24#include <vector>
25
26namespace genfit {
27 class TrackCand;
28 class AbsTrackRep;
29}
30
31namespace Belle2 {
37 class RecoTrackGenfitAccess;
38
39 BELLE2_DEFINE_EXCEPTION(NoTrackFitResult, "No track fit result available for this hit (e.g. DAF has removed it).")
40 BELLE2_DEFINE_EXCEPTION(NoStateOnPlaneFound, "No measured state on plane for any track point found.")
41
79 class RecoTrack : public RelationsObject {
82
83 private:
100
101 public:
106 c_undefined, //until the matcher module sets it
107 c_matched, // hit pattern and charge are both correct
108 c_matchedWrongCharge, // hit pattern is correct, but the charge is wrong
109 c_clone, //a clone with the correct charge
110 c_cloneWrongCharge, //a clone with the wrong charge
111 c_background,
112 c_ghost
113 };
114
130 static void registerRequiredRelations(
131 StoreArray<RecoTrack>& recoTracks,
132 std::string const& pxdHitsStoreArrayName = "",
133 std::string const& svdHitsStoreArrayName = "",
134 std::string const& cdcHitsStoreArrayName = "",
135 std::string const& bklmHitsStoreArrayName = "",
136 std::string const& eklmHitsStoreArrayName = "",
137 std::string const& recoHitInformationStoreArrayName = "");
138
141
155 RecoTrack(const ROOT::Math::XYZVector& seedPosition, const ROOT::Math::XYZVector& seedMomentum, const short int seedCharge,
156 const std::string& storeArrayNameOfPXDHits = "",
157 const std::string& storeArrayNameOfSVDHits = "",
158 const std::string& storeArrayNameOfCDCHits = "",
159 const std::string& storeArrayNameOfBKLMHits = "",
160 const std::string& storeArrayNameOfEKLMHits = "",
161 const std::string& storeArrayNameOfRecoHitInformation = "");
162
164 RecoTrack(const RecoTrack&) = delete;
166 RecoTrack& operator=(RecoTrack const&) = delete;
167
183 static RecoTrack* createFromTrackCand(const genfit::TrackCand& trackCand,
184 const std::string& storeArrayNameOfRecoTracks = "",
185 const std::string& storeArrayNameOfPXDHits = "",
186 const std::string& storeArrayNameOfSVDHits = "",
187 const std::string& storeArrayNameOfCDCHits = "",
188 const std::string& storeArrayNameOfBKLMHits = "",
189 const std::string& storeArrayNameOfEKLMHits = "",
190 const std::string& storeArrayNameOfRecoHitInformation = "",
191 const bool recreateSortingParameters = false
192 );
193
197 genfit::TrackCand createGenfitTrackCand() const;
198
203 RecoTrack* copyToStoreArrayUsing(StoreArray<RecoTrack>& storeArray, const ROOT::Math::XYZVector& position,
204 const ROOT::Math::XYZVector& momentum, short charge,
205 const TMatrixDSym& covariance, double timeSeed) const;
206
211 RecoTrack* copyToStoreArrayUsingSeeds(StoreArray<RecoTrack>& storeArray) const;
212
218 RecoTrack* copyToStoreArray(StoreArray<RecoTrack>& storeArray) const;
219
231 size_t addHitsFromRecoTrack(const RecoTrack* recoTrack, unsigned int sortingParameterOffset = 0,
232 bool reversed = false, std::optional<double> optionalMinimalWeight = std::nullopt);
233
243 bool addCDCHit(const UsedCDCHit* cdcHit, const unsigned int sortingParameter,
244 RightLeftInformation rightLeftInformation = RightLeftInformation::c_undefinedRightLeftInformation,
245 OriginTrackFinder foundByTrackFinder = OriginTrackFinder::c_undefinedTrackFinder)
246 {
247 return addHit(cdcHit, rightLeftInformation, foundByTrackFinder, sortingParameter);
248 }
249
258 bool addPXDHit(const UsedPXDHit* pxdHit, const unsigned int sortingParameter,
259 OriginTrackFinder foundByTrackFinder = OriginTrackFinder::c_undefinedTrackFinder)
260 {
261 return addHit(pxdHit, foundByTrackFinder, sortingParameter);
262 }
263
272 bool addSVDHit(const UsedSVDHit* svdHit, const unsigned int sortingParameter,
273 OriginTrackFinder foundByTrackFinder = OriginTrackFinder::c_undefinedTrackFinder)
274 {
275 return addHit(svdHit, foundByTrackFinder, sortingParameter);
276 }
277
286 bool addBKLMHit(const UsedBKLMHit* bklmHit, const unsigned int sortingParameter,
287 OriginTrackFinder foundByTrackFinder = OriginTrackFinder::c_undefinedTrackFinder)
288 {
289 return addHit(bklmHit, foundByTrackFinder, sortingParameter);
290 }
291
300 bool addEKLMHit(const UsedEKLMHit* eklmHit, const unsigned int sortingParameter,
301 OriginTrackFinder foundByTrackFinder = OriginTrackFinder::c_undefinedTrackFinder)
302 {
303 return addHit(eklmHit, foundByTrackFinder, sortingParameter);
304 }
305
311 template<class HitType>
313 {
314 RelationVector<RecoHitInformation> relatedHitInformationToHit = hit->template getRelationsFrom<RecoHitInformation>
315 (m_storeArrayNameOfRecoHitInformation);
316
317 for (RecoHitInformation& recoHitInformation : relatedHitInformationToHit) {
318 // cppcheck-suppress useStlAlgorithm
319 if (recoHitInformation.getRelatedFrom<RecoTrack>(this->getArrayName()) == this) {
320 // cppcheck-suppress returnDanglingLifetime
321 return &recoHitInformation;
322 }
323 }
324
325 return nullptr;
326 }
327
328 // Hits Information Questioning
330 template <class HitType>
331 TrackingDetector getTrackingDetector(const HitType* hit) const
332 {
333 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
334 return recoHitInformation->getTrackingDetector();
335 }
336
338 template <class HitType>
340 {
341 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
342 return recoHitInformation->getRightLeftInformation();
343 }
344
346 template <class HitType>
347 OriginTrackFinder getFoundByTrackFinder(const HitType* hit) const
348 {
349 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
350 return recoHitInformation->getFoundByTrackFinder();
351 }
352
354 template <class HitType>
355 unsigned int getSortingParameter(const HitType* hit) const
356 {
357 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
358 return recoHitInformation->getSortingParameter();
359 }
360
362 template <class HitType>
363 void setRightLeftInformation(const HitType* hit, RightLeftInformation rightLeftInformation)
364 {
365 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
366 recoHitInformation->setRightLeftInformation(rightLeftInformation);
367 setDirtyFlag();
368 }
369
371 template <class HitType>
372 void setFoundByTrackFinder(const HitType* hit, OriginTrackFinder originTrackFinder)
373 {
374 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
375 recoHitInformation->setFoundByTrackFinder(originTrackFinder);
376 }
377
379 template <class HitType>
380 void setSortingParameter(const HitType* hit, unsigned int sortingParameter)
381 {
382 RecoHitInformation* recoHitInformation = getRecoHitInformationSafely(hit);
383 recoHitInformation->setSortingParameter(sortingParameter);
384 setDirtyFlag();
385 }
386
391 const genfit::TrackPoint* getCreatedTrackPoint(const RecoHitInformation* recoHitInformation) const;
392
393 // Hits Added Questioning
395 bool hasPXDHits() const { return getRelatedFrom<UsedPXDHit>(m_storeArrayNameOfPXDHits) != nullptr; }
396
398 bool hasSVDHits() const { return getRelatedFrom<UsedSVDHit>(m_storeArrayNameOfSVDHits) != nullptr; }
399
401 bool hasCDCHits() const { return getRelatedFrom<UsedCDCHit>(m_storeArrayNameOfCDCHits) != nullptr; }
402
404 bool hasBKLMHits() const { return getRelatedFrom<UsedBKLMHit>(m_storeArrayNameOfBKLMHits) != nullptr; }
405
407 bool hasEKLMHits() const { return getRelatedFrom<UsedEKLMHit>(m_storeArrayNameOfEKLMHits) != nullptr; }
408
410 template <class HitType>
411 bool hasHit(const HitType* hit) const
412 {
413 const RelationVector<RecoTrack>& relatedTracksToHit = hit->template getRelationsTo<RecoTrack>(getArrayName());
414 return std::find_if(relatedTracksToHit.begin(), relatedTracksToHit.end(), [this](const RecoTrack & recoTrack) {
415 return &recoTrack == this;
416 }) != relatedTracksToHit.end();
417 }
418
419 // Hits Questioning
421 unsigned int getNumberOfPXDHits() const { return getNumberOfHitsOfGivenType<UsedPXDHit>(m_storeArrayNameOfPXDHits); }
422
424 unsigned int getNumberOfSVDHits() const { return getNumberOfHitsOfGivenType<UsedSVDHit>(m_storeArrayNameOfSVDHits); }
425
427 unsigned int getNumberOfCDCHits() const { return getNumberOfHitsOfGivenType<UsedCDCHit>(m_storeArrayNameOfCDCHits); }
428
430 unsigned int getNumberOfBKLMHits() const { return getNumberOfHitsOfGivenType<UsedBKLMHit>(m_storeArrayNameOfBKLMHits); }
431
433 unsigned int getNumberOfEKLMHits() const { return getNumberOfHitsOfGivenType<UsedEKLMHit>(m_storeArrayNameOfEKLMHits); }
434
436 unsigned int getNumberOfTotalHits() const
437 {
438 return getNumberOfPXDHits() + getNumberOfSVDHits() + getNumberOfCDCHits() +
439 getNumberOfBKLMHits() + getNumberOfEKLMHits();
440 }
441
443 unsigned int getNumberOfTrackingHits() const
444 {
445 return getNumberOfPXDHits() + getNumberOfSVDHits() + getNumberOfCDCHits();
446 }
447
449 std::vector<Belle2::RecoTrack::UsedPXDHit*> getPXDHitList() const { return getHitList<UsedPXDHit>(m_storeArrayNameOfPXDHits); }
450
452 std::vector<Belle2::RecoTrack::UsedSVDHit*> getSVDHitList() const { return getHitList<UsedSVDHit>(m_storeArrayNameOfSVDHits); }
453
455 std::vector<Belle2::RecoTrack::UsedCDCHit*> getCDCHitList() const { return getHitList<UsedCDCHit>(m_storeArrayNameOfCDCHits); }
456
458 std::vector<Belle2::RecoTrack::UsedBKLMHit*> getBKLMHitList() const { return getHitList<UsedBKLMHit>(m_storeArrayNameOfBKLMHits); }
459
461 std::vector<Belle2::RecoTrack::UsedEKLMHit*> getEKLMHitList() const { return getHitList<UsedEKLMHit>(m_storeArrayNameOfEKLMHits); }
462
464 std::vector<Belle2::RecoTrack::UsedPXDHit*> getSortedPXDHitList() const { return getSortedHitList<UsedPXDHit>(m_storeArrayNameOfPXDHits); }
465
467 std::vector<Belle2::RecoTrack::UsedSVDHit*> getSortedSVDHitList() const { return getSortedHitList<UsedSVDHit>(m_storeArrayNameOfSVDHits); }
468
470 std::vector<Belle2::RecoTrack::UsedCDCHit*> getSortedCDCHitList() const { return getSortedHitList<UsedCDCHit>(m_storeArrayNameOfCDCHits); }
471
473 std::vector<Belle2::RecoTrack::UsedBKLMHit*> getSortedBKLMHitList() const { return getSortedHitList<UsedBKLMHit>(m_storeArrayNameOfBKLMHits); }
474
476 std::vector<Belle2::RecoTrack::UsedEKLMHit*> getSortedEKLMHitList() const { return getSortedHitList<UsedEKLMHit>(m_storeArrayNameOfEKLMHits); }
477
478 // Seed Helix Functionality
480 ROOT::Math::XYZVector getPositionSeed() const
481 {
482 const TVectorD& seed = m_genfitTrack.getStateSeed();
483 return ROOT::Math::XYZVector(seed(0), seed(1), seed(2));
484 }
485
487 ROOT::Math::XYZVector getMomentumSeed() const
488 {
489 const TVectorD& seed = m_genfitTrack.getStateSeed();
490 return ROOT::Math::XYZVector(seed(3), seed(4), seed(5));
491 }
492
494 const TVectorD& getStateSeed() const
495 {
496 return m_genfitTrack.getStateSeed();
497 }
498
505 const genfit::Track& getGenfitTrack() const {return m_genfitTrack;}
506
508 short int getChargeSeed() const { return m_charge; }
509
511 double getTimeSeed() const { return m_genfitTrack.getTimeSeed(); }
512
515 {
516 if (!m_isArmTimeComputed) estimateArmTime();
517 return m_outgoingArmTime;
518 }
519
522 {
523 if (!m_isArmTimeComputed) estimateArmTime();
524 return m_outgoingArmTimeError;
525 }
526
529 {
530 if (!m_isArmTimeComputed) estimateArmTime();
531 return m_ingoingArmTime;
532 }
533
536 {
537 if (!m_isArmTimeComputed) estimateArmTime();
538 return m_ingoingArmTimeError;
539 }
540
543 {
544 if (!m_isArmTimeComputed) estimateArmTime();
545 return m_ingoingArmTime - m_outgoingArmTime;
546 }
547
550 {
551 if (!m_isArmTimeComputed) estimateArmTime();
552 return std::sqrt(m_ingoingArmTimeError * m_ingoingArmTimeError + m_outgoingArmTimeError *
553 m_outgoingArmTimeError);
554 }
555
558 {
559 return m_hasIngoingArmTime;
560 }
561
564 {
565 return m_hasOutgoingArmTime;
566 }
567
570 {
571 return m_nSVDHitsOfOutgoingArm;
572 }
573
576 {
577 return m_nSVDHitsOfIngoingArm;
578 }
579
584 void flipTrackDirectionAndCharge(const genfit::AbsTrackRep* representation = nullptr);
585
587 std::tuple<ROOT::Math::XYZVector, ROOT::Math::XYZVector, short> extractTrackState() const;
588
590 void setPositionAndMomentum(const ROOT::Math::XYZVector& positionSeed, const ROOT::Math::XYZVector& momentumSeed)
591 {
592 m_genfitTrack.setStateSeed(XYZToTVector(positionSeed), XYZToTVector(momentumSeed));
593 deleteFittedInformation();
594 }
595
597 void setChargeSeed(const short int chargeSeed)
598 {
599 m_charge = chargeSeed;
600 deleteFittedInformation();
601 }
602
604 void setTimeSeed(const double timeSeed)
605 {
606 m_genfitTrack.setTimeSeed(timeSeed);
607 deleteFittedInformation();
608 }
609
611 const TMatrixDSym& getSeedCovariance() const { return m_genfitTrack.getCovSeed(); }
612
614 void setSeedCovariance(const TMatrixDSym& seedCovariance) { m_genfitTrack.setCovSeed(seedCovariance); }
615
616 // Fitting
618 bool wasFitSuccessful(const genfit::AbsTrackRep* representation = nullptr) const;
619
621 const genfit::FitStatus* getTrackFitStatus(const genfit::AbsTrackRep* representation = nullptr) const
622 {
623 checkDirtyFlag();
624 return m_genfitTrack.getFitStatus(representation);
625 }
626
628 bool hasTrackFitStatus(const genfit::AbsTrackRep* representation = nullptr) const;
629
631 genfit::AbsTrackRep* getCardinalRepresentation() const
632 {
633 checkDirtyFlag();
634 return m_genfitTrack.getCardinalRep();
635 }
636
638 const std::vector<genfit::AbsTrackRep*>& getRepresentations() const
639 {
640 checkDirtyFlag();
641 return m_genfitTrack.getTrackReps();
642 }
643
650 genfit::AbsTrackRep* getTrackRepresentationForPDG(int pdgCode) const;
651
658 std::vector<RecoHitInformation*> getRecoHitInformations(bool getSorted = false) const;
659
664 const genfit::MeasuredStateOnPlane& getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep* representation = nullptr) const;
665
670 const genfit::MeasuredStateOnPlane& getMeasuredStateOnPlaneFromLastHit(const genfit::AbsTrackRep* representation = nullptr) const;
671
676 const genfit::MeasuredStateOnPlane& getMeasuredStateOnPlaneFromRecoHit(const RecoHitInformation* recoHitInfo,
677 const genfit::AbsTrackRep* representation = nullptr) const;
678
682 const genfit::MeasuredStateOnPlane& getMeasuredStateOnPlaneClosestTo(const ROOT::Math::XYZVector& closestPoint,
683 const genfit::AbsTrackRep* representation = nullptr);
684
688 void prune();
689
694 void estimateArmTime();
695
704 bool isOutgoingArm(RecoHitInformation::RecoHitDetector pre = RecoHitInformation::RecoHitDetector::c_undefinedTrackingDetector,
705 RecoHitInformation::RecoHitDetector post = RecoHitInformation::RecoHitDetector::c_undefinedTrackingDetector);
706
708 const std::vector<genfit::TrackPoint*>& getHitPointsWithMeasurement() const
709 {
710 checkDirtyFlag();
711 return m_genfitTrack.getPointsWithMeasurement();
712 }
713
715 bool getDirtyFlag() const { return m_dirtyFlag; }
716
718
722 void setDirtyFlag(const bool& dirtyFlag = true)
723 {
724 m_dirtyFlag = dirtyFlag;
725 if (dirtyFlag) {
726 deleteFittedInformation();
727 }
728 }
729
730 // Store Array Names
732 const std::string& getStoreArrayNameOfPXDHits() const { return m_storeArrayNameOfPXDHits; }
733
735 const std::string& getStoreArrayNameOfSVDHits() const { return m_storeArrayNameOfSVDHits; }
736
738 const std::string& getStoreArrayNameOfCDCHits() const { return m_storeArrayNameOfCDCHits; }
739
741 const std::string& getStoreArrayNameOfBKLMHits() const { return m_storeArrayNameOfBKLMHits; }
742
744 const std::string& getStoreArrayNameOfEKLMHits() const { return m_storeArrayNameOfEKLMHits; }
745
747 const std::string& getStoreArrayNameOfRecoHitInformation() const { return m_storeArrayNameOfRecoHitInformation; }
748
751 {
752 const uint recoHitInformationSize = getRecoHitInformations().size();
753 for (auto RecoHitInfo : getRecoHitInformations()) {
754 // The "-1" ensures that the sorting parameter still is in range 0...size-1 instead of 1...size
755 RecoHitInfo->setSortingParameter(recoHitInformationSize - RecoHitInfo->getSortingParameter() - 1);
756 }
757 }
758
765 template<class HitType>
766 void mapOnHits(const std::string& storeArrayNameOfHits,
767 std::function<void(RecoHitInformation&, HitType*)> const& mapFunction,
768 std::function<bool(const RecoHitInformation&, const HitType*)> const& pickFunction)
769 {
770 RelationVector<RecoHitInformation> relatedHitInformation = getRelationsTo<RecoHitInformation>
771 (m_storeArrayNameOfRecoHitInformation);
772
773 for (RecoHitInformation& hitInformation : relatedHitInformation) {
774 HitType* const hit = hitInformation.getRelatedTo<HitType>(storeArrayNameOfHits);
775 if (hit != nullptr && pickFunction(hitInformation, hit)) {
776 mapFunction(hitInformation, hit);
777 }
778 }
779 }
780
787 template<class HitType>
788 void mapOnHits(const std::string& storeArrayNameOfHits,
789 std::function<void(const RecoHitInformation&, const HitType*)> const& mapFunction,
790 std::function<bool(const RecoHitInformation&, const HitType*)> const& pickFunction) const
791 {
792 RelationVector<RecoHitInformation> relatedHitInformation = getRelationsTo<RecoHitInformation>
793 (m_storeArrayNameOfRecoHitInformation);
794
795 for (const RecoHitInformation& hitInformation : relatedHitInformation) {
796 const HitType* const hit = hitInformation.getRelatedTo<HitType>(storeArrayNameOfHits);
797 if (hit != nullptr && pickFunction(hitInformation, hit)) {
798 mapFunction(hitInformation, hit);
799 }
800 }
801 }
802
808 template<class HitType>
809 void mapOnHits(const std::string& storeArrayNameOfHits,
810 std::function<void(RecoHitInformation&, HitType*)> const& mapFunction)
811 {
812 mapOnHits<HitType>(storeArrayNameOfHits, mapFunction, [](const RecoHitInformation&, const HitType*) -> bool { return true; });
813 }
814
820 template<class HitType>
821 void mapOnHits(const std::string& storeArrayNameOfHits,
822 std::function<void(const RecoHitInformation&, const HitType*)> const& mapFunction) const
823 {
824 mapOnHits<HitType>(storeArrayNameOfHits, mapFunction, [](const RecoHitInformation&, const HitType*) -> bool { return true; });
825 }
826
827 // Matching status
830 {
831 return m_matchingStatus;
832 }
833
836 {
837 m_matchingStatus = matchingStatus;
838 }
839
842 {
843 return m_qualityIndicator;
844 }
845
847 void setQualityIndicator(const float qualityIndicator)
848 {
849 m_qualityIndicator = qualityIndicator;
850 }
851
854 {
855 return m_flipqualityIndicator;
856 }
857
859 void setFlipQualityIndicator(const float qualityIndicator)
860 {
861 m_flipqualityIndicator = qualityIndicator;
862 }
865 {
866 return m_2ndFlipqualityIndicator;
867 }
868
870 void set2ndFlipQualityIndicator(const float qualityIndicator)
871 {
872 m_2ndFlipqualityIndicator = qualityIndicator;
873 }
881 void deleteFittedInformation();
882
890 void deleteFittedInformationForRepresentation(const genfit::AbsTrackRep* rep);
891
893 std::string getInfoHTML() const override;
894
895 private:
897 genfit::Track m_genfitTrack;
899 short int m_charge = 1;
901 std::string m_storeArrayNameOfPXDHits = "";
903 std::string m_storeArrayNameOfSVDHits = "";
905 std::string m_storeArrayNameOfCDCHits = "";
907 std::string m_storeArrayNameOfBKLMHits = "";
909 std::string m_storeArrayNameOfEKLMHits = "";
911 std::string m_storeArrayNameOfRecoHitInformation = "";
914 bool m_dirtyFlag = true;
916 MatchingStatus m_matchingStatus = MatchingStatus::c_undefined;
918 float m_qualityIndicator = NAN;
920 float m_flipqualityIndicator = NAN;
922 float m_2ndFlipqualityIndicator = NAN;
924 float m_outgoingArmTime = NAN;
926 float m_outgoingArmTimeError = NAN;
928 float m_ingoingArmTime = NAN;
930 float m_ingoingArmTimeError = NAN;
932 bool m_isArmTimeComputed = false;
934 bool m_hasIngoingArmTime = false;
936 bool m_hasOutgoingArmTime = false;
938 int m_nSVDHitsOfOutgoingArm = 0;
940 int m_nSVDHitsOfIngoingArm = 0;
941
948 template<class HitType, class ...Args>
949 bool addHit(const HitType* hit, Args&& ... params)
950 {
951 if (hasHit(hit)) {
952 return false;
953 }
954
955 StoreArray<RecoHitInformation> recoHitInformations(m_storeArrayNameOfRecoHitInformation);
956 RecoHitInformation* newRecoHitInformation = recoHitInformations.appendNew(hit, params...);
957
958 addHitWithHitInformation(hit, newRecoHitInformation);
959
960 return true;
961 }
962
968 template <class HitType>
969 void addHitWithHitInformation(const HitType* hit, RecoHitInformation* recoHitInformation)
970 {
971 hit->addRelationTo(this);
972 addRelationTo(recoHitInformation);
973
974 m_isArmTimeComputed = false;
975 m_hasIngoingArmTime = false;
976 m_hasOutgoingArmTime = false;
977 m_outgoingArmTime = NAN;
978 m_ingoingArmTime = NAN;
979 m_outgoingArmTimeError = NAN;
980 m_ingoingArmTimeError = NAN;
981
982 setDirtyFlag();
983 }
984
986 template <class HitType>
988 {
989 RecoHitInformation* recoHitInformation = getRecoHitInformation(hit);
990 if (recoHitInformation == nullptr) {
991 B2FATAL("Queried hit is not in the reco track! Did you prune it?");
992 } else {
993 return recoHitInformation;
994 }
995 }
996
1001 template <class HitType>
1002 unsigned int getNumberOfHitsOfGivenType(const std::string& storeArrayNameOfHits) const
1003 {
1004 return getRelationsFrom<HitType>(storeArrayNameOfHits).size();
1005 }
1006
1011 template<class HitType>
1012 std::vector<HitType*> getSortedHitList(const std::string& storeArrayNameOfHits) const
1013 {
1014 const RelationVector<RecoHitInformation>& relatedHitInformation = getRelationsTo<RecoHitInformation>
1015 (m_storeArrayNameOfRecoHitInformation);
1016
1017 std::vector<const RecoHitInformation*> relatedHitInformationAsVector;
1018 relatedHitInformationAsVector.reserve(relatedHitInformation.size());
1019 for (const RecoHitInformation& hitInformation : relatedHitInformation) {
1020 // cppcheck-suppress useStlAlgorithm
1021 relatedHitInformationAsVector.push_back(&hitInformation);
1022 }
1023 std::sort(relatedHitInformationAsVector.begin(), relatedHitInformationAsVector.end(), [](const RecoHitInformation * a,
1024 const RecoHitInformation * b) -> bool {
1025 return a->getSortingParameter() < b->getSortingParameter();
1026 });
1027
1028 std::vector<HitType*> hitList;
1029 hitList.reserve(relatedHitInformationAsVector.size());
1030 for (const RecoHitInformation* hitInformation : relatedHitInformationAsVector) {
1031 HitType* relatedHit = hitInformation->getRelatedTo<HitType>(storeArrayNameOfHits);
1032 if (relatedHit != nullptr) {
1033 hitList.push_back(relatedHit);
1034 }
1035 }
1036 return hitList;
1037 }
1038
1043 template<class HitType>
1044 std::vector<HitType*> getHitList(const std::string& storeArrayNameOfHits) const
1045 {
1046 RelationVector<HitType> relatedHits = getRelationsFrom<HitType>(storeArrayNameOfHits);
1047 std::vector<HitType*> hitList;
1048 hitList.reserve(relatedHits.size());
1049 for (HitType& hit : relatedHits) {
1050 // cppcheck-suppress useStlAlgorithm
1051 hitList.push_back(&hit);
1052 }
1053 // cppcheck-suppress returnDanglingLifetime
1054 return hitList;
1055 }
1056
1059 {
1060 std::swap(m_outgoingArmTime, m_ingoingArmTime);
1061 std::swap(m_hasOutgoingArmTime, m_hasIngoingArmTime);
1062 std::swap(m_nSVDHitsOfOutgoingArm, m_nSVDHitsOfIngoingArm);
1063 }
1064
1066 void checkDirtyFlag() const
1067 {
1068 if (m_dirtyFlag) {
1069 B2DEBUG(100, "Dirty flag is set. The result may not be in sync with the latest changes. Refit the track to be sure.");
1070 }
1071 }
1072
1075 };
1076
1085 public:
1092 static genfit::Track& getGenfitTrack(RecoTrack& recoTrack);
1093
1101 static void swapGenfitTrack(RecoTrack& recoTrack, const genfit::Track* track);
1102
1117 static genfit::AbsTrackRep* createOrReturnRKTrackRep(RecoTrack& recoTrack, int PDGcode);
1118 };
1119
1121}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
This dataobject is used only for EKLM alignment.
KLM 2d hit.
Definition: KLMHit2d.h:33
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
RightLeftInformation getRightLeftInformation() const
Get the right-left-information.
OriginTrackFinder
The TrackFinder which has added the hit to the track.
RightLeftInformation
The RightLeft information of the hit which is only valid for CDC hits.
void setSortingParameter(unsigned int sortingParameter)
Set the sorting parameter.
OriginTrackFinder getFoundByTrackFinder() const
Get which track finder has found the track.
RecoHitDetector getTrackingDetector() const
Get the detector this hit comes from.
void setRightLeftInformation(RightLeftInformation rightLeftInformation)
Set the right-left-information.
RecoHitDetector
The detector this hit comes from (which is of course also visible in the hit type)
unsigned int getSortingParameter() const
Get the sorting parameter.
void setFoundByTrackFinder(OriginTrackFinder foundByTrackFinder)
Set which track finder has found the track.
This class allows access to the genfit::Track of the RecoTrack.
Definition: RecoTrack.h:1084
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:404
static void swapGenfitTrack(RecoTrack &recoTrack, const genfit::Track *track)
Set the genfit track of a Recotrack copying the information from another genfit track.
Definition: RecoTrack.cc:399
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
Definition: RecoTrack.cc:409
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
void setChargeSeed(const short int chargeSeed)
Set the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:597
RecoTrack & operator=(RecoTrack const &)=delete
Delete the copy construtr.
TrackingDetector getTrackingDetector(const HitType *hit) const
Return the tracking detector of a given hit (every type) or throws an exception of the hit is not rel...
Definition: RecoTrack.h:331
RecoHitInformation::UsedCDCHit UsedCDCHit
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:91
void mapOnHits(const std::string &storeArrayNameOfHits, std::function< void(RecoHitInformation &, HitType *)> const &mapFunction, std::function< bool(const RecoHitInformation &, const HitType *)> const &pickFunction)
Call a function on all hits of the given type in the store array, that are related to this track.
Definition: RecoTrack.h:766
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
Definition: RecoTrack.h:638
const TMatrixDSym & getSeedCovariance() const
Return the covariance matrix of the seed. ATTENTION: This is not the fitted covariance.
Definition: RecoTrack.h:611
std::vector< Belle2::RecoTrack::UsedSVDHit * > getSortedSVDHitList() const
Return a sorted list of svd hits. Sorted by the sortingParameter.
Definition: RecoTrack.h:467
bool addBKLMHit(const UsedBKLMHit *bklmHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a bklm hit with the given information to the reco track.
Definition: RecoTrack.h:286
void mapOnHits(const std::string &storeArrayNameOfHits, std::function< void(RecoHitInformation &, HitType *)> const &mapFunction)
Call a function on all hits of the given type in the store array, that are related to this track.
Definition: RecoTrack.h:809
void mapOnHits(const std::string &storeArrayNameOfHits, std::function< void(const RecoHitInformation &, const HitType *)> const &mapFunction) const
Call a function on all hits of the given type in the store array, that are related to this track.
Definition: RecoTrack.h:821
bool addCDCHit(const UsedCDCHit *cdcHit, const unsigned int sortingParameter, RightLeftInformation rightLeftInformation=RightLeftInformation::c_undefinedRightLeftInformation, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a cdc hit with the given information to the reco track.
Definition: RecoTrack.h:243
float getInOutArmTimeDifference()
Return the difference between the track times of the ingoing and outgoing arms.
Definition: RecoTrack.h:542
std::vector< Belle2::RecoTrack::UsedPXDHit * > getPXDHitList() const
Return an unsorted list of pxd hits.
Definition: RecoTrack.h:449
float getOutgoingArmTime()
Return the track time of the outgoing arm.
Definition: RecoTrack.h:514
bool hasCDCHits() const
Returns true if the track has cdc hits.
Definition: RecoTrack.h:401
unsigned int getNumberOfBKLMHits() const
Return the number of bklm hits.
Definition: RecoTrack.h:430
const std::string & getStoreArrayNameOfEKLMHits() const
Name of the store array of the eklm hits.
Definition: RecoTrack.h:744
void mapOnHits(const std::string &storeArrayNameOfHits, std::function< void(const RecoHitInformation &, const HitType *)> const &mapFunction, std::function< bool(const RecoHitInformation &, const HitType *)> const &pickFunction) const
Call a function on all hits of the given type in the store array, that are related to this track.
Definition: RecoTrack.h:788
std::vector< Belle2::RecoTrack::UsedSVDHit * > getSVDHitList() const
Return an unsorted list of svd hits.
Definition: RecoTrack.h:452
RecoHitInformation::RecoHitDetector TrackingDetector
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:87
void setPositionAndMomentum(const ROOT::Math::XYZVector &positionSeed, const ROOT::Math::XYZVector &momentumSeed)
Set the position and momentum seed of the reco track. ATTENTION: This is not the fitted position or m...
Definition: RecoTrack.h:590
bool addEKLMHit(const UsedEKLMHit *eklmHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds an eklm hit with the given information to the reco track.
Definition: RecoTrack.h:300
void setSortingParameter(const HitType *hit, unsigned int sortingParameter)
Set the sorting parameter or throws an exception of the hit is not related to the track....
Definition: RecoTrack.h:380
bool addPXDHit(const UsedPXDHit *pxdHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a pxd hit with the given information to the reco track.
Definition: RecoTrack.h:258
std::vector< Belle2::RecoTrack::UsedCDCHit * > getSortedCDCHitList() const
Return a sorted list of cdc hits. Sorted by the sortingParameter.
Definition: RecoTrack.h:470
std::vector< Belle2::RecoTrack::UsedBKLMHit * > getBKLMHitList() const
Return an unsorted list of bklm hits.
Definition: RecoTrack.h:458
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition: RecoTrack.h:455
const std::string & getStoreArrayNameOfSVDHits() const
Name of the store array of the svd hits.
Definition: RecoTrack.h:735
ROOT::Math::XYZVector getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
Definition: RecoTrack.h:480
RecoHitInformation::UsedEKLMHit UsedEKLMHit
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:99
MatchingStatus
Enum for the matching status of this reco track (set by the matching modules in the tracking package)...
Definition: RecoTrack.h:105
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
Definition: RecoTrack.h:631
const std::string & getStoreArrayNameOfPXDHits() const
Name of the store array of the pxd hits.
Definition: RecoTrack.h:732
void setRightLeftInformation(const HitType *hit, RightLeftInformation rightLeftInformation)
Set the right left information or throws an exception of the hit is not related to the track....
Definition: RecoTrack.h:363
std::vector< HitType * > getSortedHitList(const std::string &storeArrayNameOfHits) const
Return a sorted list of hits of the given type in the store array that are related to this track.
Definition: RecoTrack.h:1012
void setDirtyFlag(const bool &dirtyFlag=true)
Set to true, if you want to rebuild the measurements and do the fit independent on changes of the hit...
Definition: RecoTrack.h:722
std::vector< Belle2::RecoTrack::UsedEKLMHit * > getSortedEKLMHitList() const
Return a sorted list of eklm hits. Sorted by the sortingParameter.
Definition: RecoTrack.h:476
unsigned int getNumberOfEKLMHits() const
Return the number of eklm hits.
Definition: RecoTrack.h:433
RightLeftInformation getRightLeftInformation(const HitType *hit) const
Return the right left information of a given hit (every type) or throws an exception of the hit is no...
Definition: RecoTrack.h:339
unsigned int getNumberOfSVDHits() const
Return the number of svd hits.
Definition: RecoTrack.h:424
OriginTrackFinder getFoundByTrackFinder(const HitType *hit) const
Return the found by track finder flag for the given hit (every type) or throws an exception of the hi...
Definition: RecoTrack.h:347
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:427
int getNSVDHitsOfIngoingArm()
Return the number of clusters used to estimate the ingoing arm time.
Definition: RecoTrack.h:575
bool addHit(const HitType *hit, Args &&... params)
Add a generic hit with the given parameters for the reco hit information.
Definition: RecoTrack.h:949
unsigned int getNumberOfTrackingHits() const
Return the number of cdc + svd + pxd hits.
Definition: RecoTrack.h:443
RecoHitInformation::UsedBKLMHit UsedBKLMHit
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:97
float getIngoingArmTimeError()
Return the error of the track time of the ingoing arm.
Definition: RecoTrack.h:535
bool hasHit(const HitType *hit) const
Returns true if the given hit is in the track.
Definition: RecoTrack.h:411
void setMatchingStatus(MatchingStatus matchingStatus)
Set the matching status (used by the TrackMatcher module)
Definition: RecoTrack.h:835
std::vector< Belle2::RecoTrack::UsedEKLMHit * > getEKLMHitList() const
Return an unsorted list of eklm hits.
Definition: RecoTrack.h:461
std::vector< HitType * > getHitList(const std::string &storeArrayNameOfHits) const
Return an unsorted list of hits of the given type in the store array that are related to this track.
Definition: RecoTrack.h:1044
RecoTrack(const RecoTrack &)=delete
Delete the copy construtr.
unsigned int getSortingParameter(const HitType *hit) const
Return the sorting parameter for a given hit (every type) or throws an exception of the hit is not re...
Definition: RecoTrack.h:355
RecoHitInformation * getRecoHitInformationSafely(HitType *hit) const
Returns the reco hit information for a given hit or throws an exception if the hit is not related to ...
Definition: RecoTrack.h:987
bool hasPXDHits() const
Returns true if the track has pxd hits.
Definition: RecoTrack.h:395
const std::string & getStoreArrayNameOfBKLMHits() const
Name of the store array of the bklm hits.
Definition: RecoTrack.h:741
void setTimeSeed(const double timeSeed)
Set the time seed. ATTENTION: This is not the fitted time.
Definition: RecoTrack.h:604
bool hasOutgoingArmTime()
Check if the outgoing arm time is set.
Definition: RecoTrack.h:563
unsigned int getNumberOfHitsOfGivenType(const std::string &storeArrayNameOfHits) const
Get the number of hits for the given hit type in the store array that are related to this track.
Definition: RecoTrack.h:1002
float getOutgoingArmTimeError()
Return the error of the track time of the outgoing arm.
Definition: RecoTrack.h:521
void setFoundByTrackFinder(const HitType *hit, OriginTrackFinder originTrackFinder)
Set the found by track finder flag or throws an exception of the hit is not related to the track.
Definition: RecoTrack.h:372
float getIngoingArmTime()
Return the track time of the ingoing arm.
Definition: RecoTrack.h:528
bool hasEKLMHits() const
Returns true if the track has eklm hits.
Definition: RecoTrack.h:407
ClassDefOverride(RecoTrack, 14)
Making this class a ROOT class.
void setSeedCovariance(const TMatrixDSym &seedCovariance)
Set the covariance of the seed. ATTENTION: This is not the fitted covariance.
Definition: RecoTrack.h:614
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
Definition: RecoTrack.h:841
const std::string & getStoreArrayNameOfRecoHitInformation() const
Name of the store array of the reco hit information.
Definition: RecoTrack.h:747
float get2ndFlipQualityIndicator() const
Get the 2nd flipping quality attached to this RecoTrack as a reference for flipping.
Definition: RecoTrack.h:864
void set2ndFlipQualityIndicator(const float qualityIndicator)
Set the 2nd flipping quality attached to this RecoTrack.
Definition: RecoTrack.h:870
RecoHitInformation * getRecoHitInformation(HitType *hit) const
Return the reco hit information for a generic hit from the storeArray.
Definition: RecoTrack.h:312
void setFlipQualityIndicator(const float qualityIndicator)
Set the 1st flipping quality attached to this RecoTrack.
Definition: RecoTrack.h:859
void addHitWithHitInformation(const HitType *hit, RecoHitInformation *recoHitInformation)
Add the needed relations for adding a generic hit with the given hit information and reset track time...
Definition: RecoTrack.h:969
void setQualityIndicator(const float qualityIndicator)
Set the quality index attached to this RecoTrack. 0 means likely fake.
Definition: RecoTrack.h:847
MatchingStatus getMatchingStatus() const
Return the matching status set by the TrackMatcher module.
Definition: RecoTrack.h:829
std::vector< Belle2::RecoTrack::UsedBKLMHit * > getSortedBKLMHitList() const
Return a sorted list of bklm hits. Sorted by the sortingParameter.
Definition: RecoTrack.h:473
const std::string & getStoreArrayNameOfCDCHits() const
Name of the store array of the cdc hits.
Definition: RecoTrack.h:738
std::vector< Belle2::RecoTrack::UsedPXDHit * > getSortedPXDHitList() const
Return a sorted list of pxd hits. Sorted by the sortingParameter.
Definition: RecoTrack.h:464
float getInOutArmTimeDifferenceError()
Return the error of the difference between the track times of the ingoing and outgoing arms.
Definition: RecoTrack.h:549
bool getDirtyFlag() const
This returns true, if a hit was added after the last fit and measurement creation and a refit should ...
Definition: RecoTrack.h:715
void revertRecoHitInformationSorting()
Revert the sorting order of the RecoHitInformation.
Definition: RecoTrack.h:750
bool hasBKLMHits() const
Returns true if the track has bklm hits.
Definition: RecoTrack.h:404
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:508
bool hasIngoingArmTime()
Check if the ingoing arm time is set.
Definition: RecoTrack.h:557
float getFlipQualityIndicator() const
Get the 1st flipping quality attached to this RecoTrack as a reference for flipping.
Definition: RecoTrack.h:853
RecoHitInformation::RightLeftInformation RightLeftInformation
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:85
RecoHitInformation::OriginTrackFinder OriginTrackFinder
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:89
const TVectorD & getStateSeed() const
Return the state seed in the form posX, posY, posZ, momX, momY, momZ. ATTENTION: This is not the fitt...
Definition: RecoTrack.h:494
ROOT::Math::XYZVector getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
Definition: RecoTrack.h:487
genfit::Track m_genfitTrack
Internal storage for the genfit track.
Definition: RecoTrack.h:897
int getNSVDHitsOfOutgoingArm()
Return the number of clusters used to estimate the outgoing arm time.
Definition: RecoTrack.h:569
RecoHitInformation::UsedSVDHit UsedSVDHit
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:93
RecoTrack()
Empty constructor for ROOT. Do not use!
Definition: RecoTrack.h:140
unsigned int getNumberOfPXDHits() const
Return the number of pxd hits.
Definition: RecoTrack.h:421
bool addSVDHit(const UsedSVDHit *svdHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a svd hit with the given information to the reco track.
Definition: RecoTrack.h:272
void checkDirtyFlag() const
Helper: Check the dirty flag and produce a warning, whenever a fit result is accessed.
Definition: RecoTrack.h:1066
const genfit::Track & getGenfitTrack() const
Returns genfit track.
Definition: RecoTrack.h:505
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:621
RecoHitInformation::UsedPXDHit UsedPXDHit
Copy the definitions from the RecoHitInformation to this class.
Definition: RecoTrack.h:95
double getTimeSeed() const
Return the time seed stored in the reco track. ATTENTION: This is not the fitted time.
Definition: RecoTrack.h:511
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
Definition: RecoTrack.h:708
bool hasSVDHits() const
Returns true if the track has svd hits.
Definition: RecoTrack.h:398
void swapArmTimes()
Swap arm times, booleans and nSVDHits.
Definition: RecoTrack.h:1058
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
Definition: RecoTrack.h:436
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
iterator end()
Return iterator to last entry +1.
iterator begin()
Return iterator to first entry.
Defines interface for accessing relations of objects in StoreArray.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
Definition: VectorUtil.h:24
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.