Belle II Software  release-05-01-25
EventT0Combiner.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Hauth
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <reconstruction/modules/EventT0Combiner/EventT0Combiner.h>
12 
13 #include <cmath>
14 
15 using namespace Belle2;
16 
17 REG_MODULE(EventT0Combiner)
18 
20 {
21  setDescription("Module to combine the EventT0 values from multiple sub-detectors");
22 
23  addParam("combinationLogic", m_paramCombinationMode, "Method of how the final T0 is selected.\n"
24  "Currently '" + m_combinationModePreferCDC + "' and '" + m_combinationModeCombineCDCandECL + "' is available\n" +
25  m_combinationModePreferCDC + ": the CDC t0 value (if available) will be set as the final T0 value."
26  "Only if no CDC value could be found "
27  "(which is very rare for BBBar events, and around 5% of low multiplicity events), the best ECL value will be set\n" +
28  m_combinationModeCombineCDCandECL + ": In this mode, the CDC t0 value (if available) will be used to "
29  "select the ECL t0 information which is closest in time "
30  "to the best CDC value and this two values will be combined to one final value.",
31  m_combinationModePreferCDC);
32 
33  setPropertyFlags(c_ParallelProcessingCertified);
34 }
35 
37 {
38  if (!m_eventT0.isValid()) {
39  B2DEBUG(20, "EventT0 object not created, cannot do EventT0 combination");
40  return;
41  }
42 
43  // check if a CDC hypothesis exists
44  auto cdcHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::CDC);
45 
46  if (cdcHypos.size() == 0) {
47  B2DEBUG(20, "No CDC time hypothesis available, stopping");
48  // if no CDC value was found, the best t0 has already been set by the ECL t0 module.
49  return;
50  }
51  // get the latest CDC hypothesis information, this is also the most accurate t0 value the CDC can provide
52  const auto cdcBestT0 = cdcHypos.back();
53 
54  B2DEBUG(20, "Best CDC time hypothesis t0 = " << cdcBestT0.eventT0 << " +- " << cdcBestT0.eventT0Uncertainty);
55 
57  // we have a CDC value, so set this as new best global value
58  B2DEBUG(20, "Setting CDC time hypothesis t0 = " << cdcBestT0.eventT0 << " +- " << cdcBestT0.eventT0Uncertainty <<
59  " as new final value.");
60  //set CDC value, if available
61  m_eventT0->setEventT0(cdcBestT0);
63  // start comparing with all available ECL hypothesis
64  auto eclHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::ECL);
65 
66  if (eclHypos.size() == 0) {
67  B2DEBUG(20, "No ECL t0 hypothesis available, exiting");
68  return;
69  }
70 
71  EventT0::EventT0Component eclBestMatch;
72  double bestDistance = std::numeric_limits<double>::max();
73  bool foundMatch = false;
74  for (auto const& eclHypo : eclHypos) {
75  // compute distance
76  double dist = std::abs(eclHypo.eventT0 - cdcBestT0.eventT0);
77  B2DEBUG(20, "Checking compatibility of ECL t0 = " << eclHypo.eventT0 << " +- " << eclHypo.eventT0Uncertainty << " distance = " <<
78  dist);
79  if (dist < bestDistance) {
80  eclBestMatch = eclHypo;
81  bestDistance = dist;
82  foundMatch = true;
83  }
84  }
85 
86  B2DEBUG(20, "Best Matching ECL timing is t0 = " << eclBestMatch.eventT0 << " +- " << eclBestMatch.eventT0Uncertainty);
87 
88  // combine and update final value
89  if (foundMatch) {
90  const auto combined = computeCombination({ eclBestMatch, cdcBestT0 });
91  m_eventT0->setEventT0(combined);
92  B2DEBUG(20, "Combined T0 from CDC and ECL is t0 = " << combined.eventT0 << " +- " << combined.eventT0Uncertainty);
93  } else {
94 
95  //set CDC value, if available
96  m_eventT0->setEventT0(cdcBestT0);
97 
98  B2DEBUG(20, "No sufficient match found between CDC and ECL timing, setting best CDC t0 = " << cdcBestT0.eventT0 << " +- " <<
99  cdcBestT0.eventT0Uncertainty);
100  }
101  } else {
102  B2FATAL("Event t0 combination mode " << m_paramCombinationMode << " not supported.");
103  }
104 }
105 
106 EventT0::EventT0Component EventT0CombinerModule::computeCombination(std::vector<EventT0::EventT0Component> measurements) const
107 {
108  if (measurements.size() == 0) {
109  B2FATAL("Need at least one EvenT0 Measurement to do a sensible combination.");
110  }
111 
112  double eventT0 = 0.0f;
113  double preFactor = 0.0f;
114 
115  Const::DetectorSet usedDetectorSet;
116 
117  for (auto const& meas : measurements) {
118  usedDetectorSet += meas.detectorSet;
119  const double oneOverUncertaintySquared = 1.0f / std::pow(meas.eventT0Uncertainty, 2.0);
120  eventT0 += meas.eventT0 * oneOverUncertaintySquared;
121  preFactor += oneOverUncertaintySquared;
122  }
123 
124  eventT0 /= preFactor;
125  const auto eventT0unc = std::sqrt(1.0f / preFactor);
126 
127  return EventT0::EventT0Component(eventT0, eventT0unc, usedDetectorSet);
128 }
129 
130 
Belle2::EventT0CombinerModule
Module to combine the EventT0 values from multiple sub-detectors.
Definition: EventT0Combiner.h:34
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::EventT0::EventT0Component::eventT0
double eventT0
Storage of the T0 estimation.
Definition: EventT0.h:55
Belle2::EventT0::EventT0Component::eventT0Uncertainty
double eventT0Uncertainty
Storage of the uncertainty of the T0 estimation.
Definition: EventT0.h:57
Belle2::Const::DetectorSet
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:66
Belle2::EventT0CombinerModule::m_eventT0
StoreObjPtr< EventT0 > m_eventT0
Access to global EventT0 which will be read and updated.
Definition: EventT0Combiner.h:54
Belle2::EventT0::EventT0Component
Structure for storing the extracted event t0s together with its detector and its uncertainty.
Definition: EventT0.h:44
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::EventT0CombinerModule::m_paramCombinationMode
std::string m_paramCombinationMode
Mode to combine the t0 values of the sub-detectors.
Definition: EventT0Combiner.h:65
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::EventT0CombinerModule::m_combinationModeCombineCDCandECL
const std::string m_combinationModeCombineCDCandECL
In this mode, the CDC t0 value (if available) will be used to select the ECL t0 information which is ...
Definition: EventT0Combiner.h:62
Belle2::EventT0CombinerModule::computeCombination
EventT0::EventT0Component computeCombination(std::vector< EventT0::EventT0Component > measurements) const
computes the new average between multiple, un-correlated sub-detector measurements
Definition: EventT0Combiner.cc:106
Belle2::EventT0CombinerModule::event
void event() override
This method is called for each event.
Definition: EventT0Combiner.cc:36
Belle2::EventT0CombinerModule::m_combinationModePreferCDC
const std::string m_combinationModePreferCDC
In this mode, the CDC t0 value (if available) will be set as the final T0 value.
Definition: EventT0Combiner.h:58