Belle II Software development
IterativeEventTimeExtractor.icc.h
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#pragma once
9
10#include <tracking/eventTimeExtraction/findlets/IterativeEventTimeExtractor.dcl.h>
11#include <tracking/eventTimeExtraction/findlets/BaseEventTimeExtractor.icc.h>
12#include <tracking/eventTimeExtraction/utilities/TimeExtractionUtils.h>
13#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
14#include <framework/core/ModuleParamList.h>
15#include <framework/logging/Logger.h>
16
17namespace Belle2 {
22 template <class AFindlet>
24 {
25 Super::addProcessingSignalListener(&m_findlet);
26 }
27
28 template <class AFindlet>
29 void IterativeEventTimeExtractor<AFindlet>::apply(std::vector<RecoTrack*>& recoTracks)
30 {
31 m_wasSuccessful = false;
32
33 m_eventT0WithQuality.clear();
35 TimeExtractionUtils::addEventT0WithQuality(recoTracks, m_eventT0, m_eventT0WithQuality);
36
37 unsigned int iteration = 0;
38 for (; iteration < m_param_maxIterations; iteration++) {
39 // The findlet will set the final event t0, but will probably not add any temporary event t0s, which is fine as we will do so.
40 m_findlet.apply(recoTracks);
41
42 bool breakLoop = false;
43 if (m_findlet.wasSuccessful()) {
44
45 if (not m_eventT0WithQuality.empty()) {
46 const double deltaT0 = std::abs(m_eventT0->getEventT0() - m_eventT0WithQuality.back().eventT0);
47 if (deltaT0 < m_param_minimalDeltaT0 and iteration >= m_param_minIterations) {
48 breakLoop = true;
49 }
50 }
51 TimeExtractionUtils::addEventT0WithQuality(recoTracks, m_eventT0, m_eventT0WithQuality);
52 } else if (m_param_abortOnUnsuccessfulStep) {
53 B2DEBUG(25, "Aborting because time extraction was not successful.");
54 breakLoop = true;
55 }
56
57 if (breakLoop) {
58 break;
59 }
60 }
61
62 if (not m_eventT0WithQuality.empty() and iteration != m_param_maxIterations) {
63 if (m_param_useLastEventT0) {
64 m_eventT0->addTemporaryEventT0(m_eventT0WithQuality.back());
65 m_eventT0->setEventT0(m_eventT0WithQuality.back());
66 } else {
67 // Look for the best event t0 (with the smallest chi2)
68 const auto& bestEventT0 = std::max_element(m_eventT0WithQuality.begin(), m_eventT0WithQuality.end(),
69 [](const auto & lhs, const auto & rhs) {
70 return lhs.quality < rhs.quality;
71 });
72 m_eventT0->setEventT0(*bestEventT0);
73 }
74 m_wasSuccessful = true;
75 }
76 }
77
78 template <class AFindlet>
79 void IterativeEventTimeExtractor<AFindlet>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
80 {
81 Super::exposeParameters(moduleParamList, prefix);
82
83 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maxIterations"),
84 m_param_maxIterations,
85 "How many iterations should be done maximally?",
86 m_param_maxIterations);
87 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minIterations"),
88 m_param_minIterations,
89 "How many iterations should be done minimally?",
90 m_param_minIterations);
91 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalDeltaT0"),
92 m_param_minimalDeltaT0,
93 "What is the final precision?",
94 m_param_minimalDeltaT0);
95 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "useLastEventT0"),
96 m_param_useLastEventT0,
97 "Use the last event t0 instead of the best one.",
98 m_param_useLastEventT0);
99 moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "abortOnUnsuccessfulStep"),
100 m_param_abortOnUnsuccessfulStep,
101 "Abort on a single unsuccessful step. Otherwise, the success is defined by the last step",
102 m_param_abortOnUnsuccessfulStep);
103
104 m_findlet.exposeParameters(moduleParamList, TrackFindingCDC::prefixed("sub", prefix));
105 }
107}
The Module parameter list class.
static void addEventT0WithQuality(const std::vector< RecoTrack * > &recoTracks, StoreObjPtr< EventT0 > &eventT0, std::vector< EventT0::EventT0Component > &eventT0WithQualityIndex)
Append an event-t0 value with quality information.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters.
IterativeEventTimeExtractor()
Add the subfindlet as listener.
void apply(std::vector< RecoTrack * > &recoTracks) override final
Timing extraction for this findlet.
Abstract base class for different kinds of events.