Belle II Software  release-08-01-10
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"
23  "' is available\n" +
24  m_combinationModePreferSVD + ": the SVD t0 value (if available) will be set as the final T0 value."
25  "Only if no SVD value could be found "
26  "(which is very rare for BBbar events, and around 5% of low multiplicity events), the best ECL value will be set\n" +
27  m_combinationModeCombineSVDandECL + ": In this mode, the SVD t0 value (if available) will be used to "
28  "select the ECL t0 information which is closest in time "
29  "to the best SVD value and these two values will be combined to one final value." +
31 
33 }
34 
36 {
37  if (!m_eventT0.isValid()) {
38  B2DEBUG(20, "EventT0 object not created, cannot do EventT0 combination");
39  return;
40  }
41 
42  // check if a SVD hypothesis exists
43  const auto bestSVDHypo = m_eventT0->getBestSVDTemporaryEventT0();
44 
45  if (not bestSVDHypo) {
46  B2DEBUG(20, "No SVD time hypotheses available, stopping");
47  // if no SVD value was found, the best t0 has already been set by the ECL t0 module.
48  return;
49  }
50 
51  B2DEBUG(20, "Best SVD time hypothesis t0 = " << bestSVDHypo->eventT0 << " +- " << bestSVDHypo->eventT0Uncertainty);
52 
54  // we have a SVD value, so set this as new best global value
55  B2DEBUG(20, "Setting SVD time hypothesis t0 = " << bestSVDHypo->eventT0 << " +- " << bestSVDHypo->eventT0Uncertainty <<
56  " as new final value.");
57  //set SVD value, if available
58  m_eventT0->setEventT0(*bestSVDHypo);
60  // get best CDC hypothesis
61  const auto bestCDCHypo = m_eventT0->getBestCDCTemporaryEventT0();
62  if (not bestCDCHypo) {
63  B2DEBUG(20, "No CDC EventT0 candiate, exiting.");
64  return;
65  }
66  // we have a CDC value, so set this as new best global value
67  B2DEBUG(20, "Setting CDC time hypothesis t0 = " << bestCDCHypo->eventT0 << " +- " << bestCDCHypo->eventT0Uncertainty <<
68  " as new final value.");
69  //set CDC value, if available
70  m_eventT0->setEventT0(*bestCDCHypo);
72  // start comparing with all available ECL hypothesis
73  auto eclHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::ECL);
74 
75  if (eclHypos.size() == 0) {
76  B2DEBUG(20, "No ECL t0 hypothesis available, exiting");
77  return;
78  }
79 
80  EventT0::EventT0Component eclBestMatch;
81  double bestDistance = std::numeric_limits<double>::max();
82  bool foundMatch = false;
83  for (auto const& eclHypo : eclHypos) {
84  // compute distance
85  double dist = std::abs(eclHypo.eventT0 - bestSVDHypo->eventT0);
86  B2DEBUG(20, "Checking compatibility of ECL t0 = " << eclHypo.eventT0 << " +- " << eclHypo.eventT0Uncertainty << " distance = " <<
87  dist);
88  if (dist < bestDistance) {
89  eclBestMatch = eclHypo;
90  bestDistance = dist;
91  foundMatch = true;
92  }
93  }
94 
95  B2DEBUG(20, "Best Matching ECL timing is t0 = " << eclBestMatch.eventT0 << " +- " << eclBestMatch.eventT0Uncertainty);
96 
97  // combine and update final value
98  if (foundMatch) {
99  const auto combined = computeCombination({ eclBestMatch, *bestSVDHypo });
100  m_eventT0->setEventT0(combined);
101  B2DEBUG(20, "Combined T0 from SVD and ECL is t0 = " << combined.eventT0 << " +- " << combined.eventT0Uncertainty);
102  } else {
103 
104  //set SVD value, if available
105  m_eventT0->setEventT0(*bestSVDHypo);
106 
107  B2DEBUG(20, "No sufficient match found between SVD and ECL timing, setting best SVD t0 = " << bestSVDHypo->eventT0 << " +- " <<
108  bestSVDHypo->eventT0Uncertainty);
109  }
110  } else {
111  B2FATAL("Event t0 combination mode " << m_paramCombinationMode << " not supported.");
112  }
113 }
114 
115 EventT0::EventT0Component EventT0CombinerModule::computeCombination(std::vector<EventT0::EventT0Component> measurements) const
116 {
117  if (measurements.size() == 0) {
118  B2FATAL("Need at least one EvenT0 Measurement to do a sensible combination.");
119  }
120 
121  double eventT0 = 0.0f;
122  double preFactor = 0.0f;
123 
124  Const::DetectorSet usedDetectorSet;
125 
126  for (auto const& meas : measurements) {
127  usedDetectorSet += meas.detectorSet;
128  const double oneOverUncertaintySquared = 1.0f / std::pow(meas.eventT0Uncertainty, 2.0);
129  eventT0 += meas.eventT0 * oneOverUncertaintySquared;
130  preFactor += oneOverUncertaintySquared;
131  }
132 
133  eventT0 /= preFactor;
134  const auto eventT0unc = std::sqrt(1.0f / preFactor);
135 
136  return EventT0::EventT0Component(eventT0, eventT0unc, usedDetectorSet);
137 }
138 
139 
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition: Const.h:71
const std::string m_combinationModeCombineSVDandECL
In this mode, the SVD t0 value (if available) will be used to select the ECL t0 information which is ...
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_combinationModePreferCDC
In this mode, the CDC t0 value (if available) will be set as the final T0 value.
const std::string m_combinationModePreferSVD
In this mode, the SVD 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
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
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
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