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