Belle II Software  release-06-01-15
OnlineEventT0CreatorModule.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 /* Own header. */
10 #include <hlt/modules/onlineEventT0/OnlineEventT0CreatorModule.h>
11 
12 /* Belle 2 headers. */
13 #include <framework/core/Environment.h>
14 #include <framework/logging/LogConfig.h>
15 
16 using namespace Belle2;
17 
18 REG_MODULE(OnlineEventT0Creator)
19 
21 {
22  setDescription("Module to write the EventT0s computed on the online systems (HLT). "
23  "By default, this module is run only on the online systems unless the user "
24  "specifically requires to execute it.");
25  addParam("executeThisModule", m_executeThisModule,
26  "Execute this module: if True, this module is executed durig the reconstruction, otherwise not.", false);
27  setPropertyFlags(c_ParallelProcessingCertified);
28 }
29 
31 {
32  // If we are running online, execute the module regardless of what the user specified.
34  if (realm == LogConfig::c_Online)
35  m_executeThisModule = true;
36  // Run the usual checks only if the module is actually executed.
37  if (m_executeThisModule) {
38  m_onlineEventT0.registerInDataStore();
39  m_eventT0.isRequired();
40  }
41 }
42 
44 {
45  if (!m_executeThisModule) {
46  B2DEBUG(20, "OnlineEventT0 is not executed as requested");
47  return;
48  }
49  if (!m_eventT0.isValid()) {
50  B2DEBUG(20, "EventT0 object not created, cannot write OnlineEventT0");
51  return;
52  }
53  if (m_onlineEventT0.getEntries() > 0) {
54  B2DEBUG(20, "OnlineEventT0 object already present, do nothing");
55  return;
56  }
57  // check if ECL hypothesis exists
58  auto eclHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::ECL);
59  if (eclHypos.size() == 0) {
60  B2DEBUG(20, "No ECL EventT0 available");
61  } else {
62  // get the most accurate ECL evenT0 (smallest chi2/quality)
63  auto eclBestT0 = std::min_element(eclHypos.begin(), eclHypos.end(), [](EventT0::EventT0Component c1,
64  EventT0::EventT0Component c2) {return c1.quality < c2.quality;});
65  m_onlineEventT0.appendNew(eclBestT0->eventT0, eclBestT0->eventT0Uncertainty, Const::EDetector::ECL);
66  }
67  // check if a CDC hypothesis exists
68  auto cdcHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::CDC);
69  if (cdcHypos.size() == 0) {
70  B2DEBUG(20, "No CDC EventT0 available");
71  } else {
72  // get the most accurate CDC evenT0 (latest)
73  const auto& cdcBestT0 = cdcHypos.back();
74  m_onlineEventT0.appendNew(cdcBestT0.eventT0, cdcBestT0.eventT0Uncertainty, Const::EDetector::CDC);
75  }
76  // check if a TOP hypothesis exists
77  auto topHypos = m_eventT0->getTemporaryEventT0s(Const::EDetector::TOP);
78  if (topHypos.size() == 0) {
79  B2DEBUG(20, "No TOP EventT0 available");
80  } else {
81  // get the most accurate TOP eventT0 (there is only one)
82  const auto& topBestT0 = topHypos.back();
83  m_onlineEventT0.appendNew(topBestT0.eventT0, topBestT0.eventT0Uncertainty, Const::EDetector::TOP);
84  }
85 }
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
LogConfig::ELogRealm getRealm() const
Get the basf2 execution realm.
Definition: Environment.h:193
ELogRealm
Definition of the supported execution realms.
Definition: LogConfig.h:48
@ c_Online
Online data taking.
Definition: LogConfig.h:49
Base class for Modules.
Definition: Module.h:72
Module to write the EventT0s computed on the online systems (HLT).
StoreObjPtr< EventT0 > m_eventT0
StoreArray of EventT0.
void initialize() override
Initialize: check DataStore content.
bool m_executeThisModule
Module parameter for executing the module or not.
void event() override
This method is called for each event.
StoreArray< OnlineEventT0 > m_onlineEventT0
StoreArray of OnlineEventT0.
#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