Belle II Software prerelease-11-00-00a
EventT0.cc
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#include <framework/dataobjects/EventT0.h>
9
10#include <framework/logging/Logger.h>
11
12#include <algorithm>
13#include <iterator>
14
15using namespace Belle2;
16
17// Final event t0
20{
21 return m_hasEventT0;
22}
23
25double EventT0::getEventT0(bool fromTrackCreator) const
26{
27 B2ASSERT("Not EventT0 available, but someone tried to access it. Check with hasEventT0() method before!", hasEventT0());
28
29 //if EventT0 is needed by Track Creator, first check SVD and CDC
30 //use the combined eventT0 only as last resort
31 if (fromTrackCreator) {
32 const auto svdT0 = this->getBestSVDTemporaryEventT0();
33 if (svdT0) return svdT0->eventT0;
34 else {
35 const auto cdcT0 = this->getBestCDCTemporaryEventT0();
36 if (cdcT0) return cdcT0->eventT0;
37 }
38 }
39 return m_eventT0.eventT0;
40}
41
42std::optional<EventT0::EventT0Component> EventT0::getEventT0Component() const
43{
44 if (hasEventT0()) {
45 return std::make_optional(m_eventT0);
46 }
47
48 return {};
49}
50
53{
54 return m_eventT0.eventT0Uncertainty;
55}
56
58void EventT0::setEventT0(double eventT0, double eventT0Uncertainty, const Const::DetectorSet& detector,
59 const std::string& algorithm)
60{
61 setEventT0(EventT0Component(eventT0, eventT0Uncertainty, detector, algorithm));
62}
63
65{
66 m_eventT0 = eventT0;
67 m_hasEventT0 = true;
68}
69
71{
72 for (const EventT0Component& eventT0Component : m_temporaryEventT0List) {
73 if (detectorSet.contains(eventT0Component.detectorSet)) {
74 return true;
75 }
76 }
77
78 return false;
79}
80
81const std::vector<EventT0::EventT0Component>& EventT0::getTemporaryEventT0s() const
82{
84}
85
86const std::vector<EventT0::EventT0Component> EventT0::getTemporaryEventT0s(Const::EDetector detector) const
87{
88 std::vector<EventT0::EventT0Component> detectorT0s;
89
90 const auto lmdSelectDetector = [detector](EventT0::EventT0Component const & c) {return c.detectorSet.contains(detector);};
91 std::copy_if(m_temporaryEventT0List.begin(), m_temporaryEventT0List.end(),
92 std::back_inserter(detectorT0s), lmdSelectDetector);
93 return detectorT0s;
94}
95
96
98{
99 Const::DetectorSet temporarySet;
100
101 for (const EventT0Component& eventT0Component : m_temporaryEventT0List) {
102 temporarySet += eventT0Component.detectorSet;
103 }
104
105 return temporarySet;
106}
107
109{
110 return m_temporaryEventT0List.size();
111}
112
114{
115 m_temporaryEventT0List.push_back(eventT0);
116}
117
122
124{
125 m_hasEventT0 = false;
126}
127
128std::optional<EventT0::EventT0Component> EventT0::getBestSVDTemporaryEventT0() const
129{
130 if (hasTemporaryEventT0(Const::EDetector::SVD)) {
131 std::vector<EventT0::EventT0Component> svdT0s = getTemporaryEventT0s(Const::EDetector::SVD);
132 // The most accurate SVD EventT0 candidate is the last one in the list
133 return std::make_optional(svdT0s.back());
134 }
135
136 return {};
137}
138
139std::optional<EventT0::EventT0Component> EventT0::getBestCDCTemporaryEventT0() const
140{
141 if (hasTemporaryEventT0(Const::EDetector::CDC)) {
142 std::vector<EventT0::EventT0Component> cdcT0s = getTemporaryEventT0s(Const::EDetector::CDC);
143 // The most accurate CDC EventT0 candidate is the last one in the list
144 return std::make_optional(cdcT0s.back());
145 }
146
147 return {};
148}
149
150std::optional<EventT0::EventT0Component> EventT0::getBestTOPTemporaryEventT0() const
151{
152 if (hasTemporaryEventT0(Const::EDetector::TOP)) {
153 std::vector<EventT0::EventT0Component> topT0s = getTemporaryEventT0s(Const::EDetector::TOP);
154 // The most accurate TOP EventT0 candidate is the last one in the list, though there should only be one at max anyway
155 return std::make_optional(topT0s.back());
156 }
157
158 return {};
159}
160
161std::optional<EventT0::EventT0Component> EventT0::getBestECLTemporaryEventT0() const
162{
163 if (hasTemporaryEventT0(Const::EDetector::ECL)) {
164 std::vector<EventT0::EventT0Component> eclT0s = getTemporaryEventT0s(Const::EDetector::ECL);
165 // The most accurate ECL EevenT0 is assumed to be the one with smallest chi2/quality
166 auto eclBestT0 = std::min_element(eclT0s.begin(), eclT0s.end(), [](EventT0::EventT0Component c1,
167 EventT0::EventT0Component c2) {return c1.quality < c2.quality;});
168 return std::make_optional(*eclBestT0);
169 }
170
171 return {};
172}
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition Const.h:80
bool contains(const DetectorSet &set) const
Check whether this set contains another set.
Definition Const.h:235
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition Const.h:42
std::vector< EventT0Component > m_temporaryEventT0List
Internal storage of the temporary event t0 list.
Definition EventT0.h:153
EventT0Component m_eventT0
Internal storage for the final event t0.
Definition EventT0.h:155
void clearTemporaries()
Clear the list of temporary event T0 estimations.
Definition EventT0.cc:118
void setEventT0(double eventT0, double eventT0Uncertainty, const Const::DetectorSet &detector, const std::string &algorithm="")
Replace/set the final double T0 estimation.
Definition EventT0.cc:58
std::optional< EventT0Component > getBestECLTemporaryEventT0() const
Return the best ECL-based EventT0 candidate if it exists.
Definition EventT0.cc:161
std::optional< EventT0Component > getEventT0Component() const
Return the final event t0, if one is set. Else, return an empty optional.
Definition EventT0.cc:42
std::optional< EventT0Component > getBestCDCTemporaryEventT0() const
Return the best CDC-based EventT0 candidate if it exists.
Definition EventT0.cc:139
void clearEventT0()
Clear the final EventT0, this is needed in case some algorithm has set one for an itertive t0 finding...
Definition EventT0.cc:123
bool hasEventT0() const
Check if a final event t0 is set.
Definition EventT0.cc:19
double getEventT0(bool fromTrackCreator=false) const
Return the final event t0, if one is set.
Definition EventT0.cc:25
void addTemporaryEventT0(const EventT0Component &eventT0)
Add another temporary double T0 estimation.
Definition EventT0.cc:113
bool m_hasEventT0
Internal storage of the final eventT0 is set.
Definition EventT0.h:157
const std::vector< EventT0Component > & getTemporaryEventT0s() const
Return the list of all temporary event t0 estimations.
Definition EventT0.cc:81
std::optional< EventT0Component > getBestTOPTemporaryEventT0() const
Return the best TOP-based EventT0 candidate if it exists.
Definition EventT0.cc:150
std::optional< EventT0Component > getBestSVDTemporaryEventT0() const
Return the best SVD-based EventT0 candidate if it exists.
Definition EventT0.cc:128
bool hasTemporaryEventT0(const Const::DetectorSet &detectorSet=Const::allDetectors) const
Check if one of the detectors in the given set has a temporary t0 estimation.
Definition EventT0.cc:70
unsigned long getNumberOfTemporaryEventT0s() const
Return the number of stored event T0s.
Definition EventT0.cc:108
Const::DetectorSet getTemporaryDetectors() const
Get the detectors that have determined temporary event T0s.
Definition EventT0.cc:97
double getEventT0Uncertainty() const
Return the final event t0 uncertainty, if one is set. Else, return NAN.
Definition EventT0.cc:52
Abstract base class for different kinds of events.
Structure for storing the extracted event t0s together with its detector and its uncertainty.
Definition EventT0.h:33