Belle II Software development
EventT0Combiner.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
9#include <reconstruction/modules/EventT0Combiner/EventT0Combiner.h>
10
11#include <cmath>
12
13using namespace Belle2;
14
15REG_MODULE(EventT0Combiner);
16
18{
19 setDescription("Module to combine the EventT0 values from multiple sub-detectors");
20
22}
23
25{
26 if (!m_eventT0.isValid()) {
27 B2DEBUG(20, "EventT0 object not created, cannot do EventT0 combination");
28 return;
29 }
30
31 // NOT checking for m_eventT0.hasEventT0() here, as this would only indicate that so far no EventT0 has been set.
32 // However, this does not mean that we can't set one from the temporary values.
33 // But of course nothing can be done if no temporary EventT0s are present.
34 if (m_eventT0->getTemporaryEventT0s().empty()) {
35 B2DEBUG(20, "No temporary EventT0s available, can't chose the best one.");
36 return;
37 }
38
39 // We have an SVD based EventT0 and it currently is set as *THE* EventT0 -> nothing to do
40 if (m_eventT0->isSVDEventT0()) {
41 B2DEBUG(20, "EventT0 already based on SVD information, nothing to do.");
42 return;
43 }
44
45 // If we don't have an SVD based EventT0, the second choice is the EventT0 estimate using CDC information calculabed by the
46 // FullGridChi2TrackTimeExtractor method. In principle, this algorithm can create EventT0 estimates using two methods:
47 // "grid" and "chi2". We are only interested in the latter one.
48 // If no SVD based EventT0 is present, but a CDC based one using the "chi2" algorithm is available -> nothing to do
49 if (m_eventT0->isCDCEventT0()) {
50 const auto& bestCDCT0 = m_eventT0->getBestCDCTemporaryEventT0();
51 if ((*bestCDCT0).algorithm == "chi2") {
52 B2DEBUG(20, "Using CDC chi2 EventT0.");
53 return;
54 }
55 B2DEBUG(20, "Current EventT0 is based on CDC, but it's not the chi2 value. Continue Search.");
56 }
57
58 // No CDC chi2 EventT0 present -> try to combine ECL and CDC hit based EventT0
59 // First, clear the EventT0 so that EventT0::hasEventT0() will return false
60 m_eventT0->clearEventT0();
61 const auto& bestECLT0 = m_eventT0->getBestECLTemporaryEventT0();
62 const auto& cdcT0Candidates = m_eventT0->getTemporaryEventT0s(Const::CDC);
63 const auto& hitBasedCDCT0Candidate = std::find_if(cdcT0Candidates.begin(), cdcT0Candidates.end(), [](const auto & a) { return a.algorithm == "hit based";});
64
65 // Strategy in case none of the SVD based or the CDC chi2 based EventT0 values is available:
66 // 1) If we have both an EventT0 estimate from ECL and a CDC hit based value, combine the two
67 // 2) If we only have one of the two, take that value
68 // 3) If we don't have either, we have a problem -> issue a B2WARNING and clear the EventT0
69 // If we arrive at 3), this means that we could only have TOP EventT0, or an EventT0 from a
70 // CDC based algorithm other than "hit based" or "chi2", and so far we don't want to use these.
71 if (bestECLT0 and hitBasedCDCT0Candidate != cdcT0Candidates.end()) {
72 B2DEBUG(20, "Combining ECL EventT0 and CDC hit based EventT0.");
73 const auto combined = computeCombination({ *bestECLT0, *hitBasedCDCT0Candidate });
74 m_eventT0->setEventT0(combined);
75 return;
76 } else if (bestECLT0 and hitBasedCDCT0Candidate == cdcT0Candidates.end()) {
77 B2DEBUG(20, "Using ECL EventT0, as CDC hit based EventT0 is not available.");
78 m_eventT0->setEventT0(*bestECLT0);
79 return;
80 } else if (hitBasedCDCT0Candidate != cdcT0Candidates.end() and not bestECLT0) {
81 B2DEBUG(20, "Using CDC hit based EventT0, as ECL EventT0 is not available.");
82 m_eventT0->setEventT0(*hitBasedCDCT0Candidate);
83 return;
84 } else {
85 B2DEBUG(20, "There is no EventT0 from neither \n" \
86 " * the SVD based algorithm\n" \
87 " * the CDC based chi^2 algorithm\n" \
88 " * the CDC based hit-based algorithm\n" \
89 " * the ECL algorithm.\n" \
90 "Thus, no EventT0 value can be calculated.");
91 }
92
93
94}
95
96EventT0::EventT0Component EventT0CombinerModule::computeCombination(std::vector<EventT0::EventT0Component> measurements) const
97{
98 if (measurements.size() == 0) {
99 B2FATAL("Need at least one EvenT0 Measurement to do a sensible combination.");
100 }
101
102 double eventT0 = 0.0f;
103 double preFactor = 0.0f;
104
105 Const::DetectorSet usedDetectorSet;
106
107 for (auto const& meas : measurements) {
108 usedDetectorSet += meas.detectorSet;
109 const double oneOverUncertaintySquared = 1.0f / std::pow(meas.eventT0Uncertainty, 2.0);
110 eventT0 += meas.eventT0 * oneOverUncertaintySquared;
111 preFactor += oneOverUncertaintySquared;
112 }
113
114 eventT0 /= preFactor;
115 const auto eventT0unc = std::sqrt(1.0f / preFactor);
116
117 return EventT0::EventT0Component(eventT0, eventT0unc, usedDetectorSet);
118}
119
120
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:80
StoreObjPtr< EventT0 > m_eventT0
Access to global EventT0 which will be read and updated.
void event() override
This method is called for each event.
EventT0::EventT0Component computeCombination(std::vector< EventT0::EventT0Component > measurements) const
computes the new average between multiple, un-correlated sub-detector measurements
EventT0CombinerModule()
Default constructor.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
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