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