Belle II Software  release-05-02-19
GridEventTimeExtractor.icc.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/eventTimeExtraction/findlets/GridEventTimeExtractor.dcl.h>
13 #include <tracking/eventTimeExtraction/findlets/BaseEventTimeExtractor.icc.h>
14 #include <tracking/eventTimeExtraction/utilities/TimeExtractionUtils.h>
15 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
16 #include <framework/core/ModuleParamList.h>
17 #include <framework/logging/Logger.h>
18 
19 namespace Belle2 {
24  template <class AFindlet>
26  {
27  Super::addProcessingSignalListener(&m_findlet);
28  }
29 
30  template <class AFindlet>
31  void GridEventTimeExtractor<AFindlet>::apply(std::vector<RecoTrack*>& recoTracks)
32  {
33  m_wasSuccessful = false;
34 
35  m_eventT0WithQuality.clear();
36 
37  TimeExtractionUtils::addEventT0WithQuality(recoTracks, m_eventT0, m_eventT0WithQuality);
38 
39  const double eventT0Delta = (m_param_maximalT0Value - m_param_minimalT0Value) / static_cast<double>(m_param_gridSteps);
40 
41  for (unsigned int gridIndex = 0; gridIndex <= m_param_gridSteps; gridIndex++) {
42  const double eventT0Hypothesis = eventT0Delta * static_cast<double>(gridIndex) + m_param_minimalT0Value;
43 
44  m_eventT0->setEventT0(EventT0::EventT0Component(eventT0Hypothesis, NAN, Const::CDC, "grid"));
45  TimeExtractionUtils::addEventT0WithQuality(recoTracks, m_eventT0, m_eventT0WithQuality);
46 
47  for (unsigned int iteration = 0; iteration < m_param_iterations; iteration++) {
48  // 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.
49  m_findlet.apply(recoTracks);
50 
51  if (m_findlet.wasSuccessful()) {
52  TimeExtractionUtils::addEventT0WithQuality(recoTracks, m_eventT0, m_eventT0WithQuality);
53  } else if (m_param_abortOnUnsuccessfulStep) {
54  B2DEBUG(50, "Aborting because time extraction was not successful.");
55  break;
56  }
57  }
58  }
59 
60  if (not m_eventT0WithQuality.empty()) {
61  m_wasSuccessful = true;
62  // Look for the best event t0 (with the smallest chi2)
63  const auto& bestChi2 = std::max_element(m_eventT0WithQuality.begin(), m_eventT0WithQuality.end(),
64  [](const auto & lhs, const auto & rhs) {
65  return lhs.quality < rhs.quality;
66  });
67  m_eventT0->setEventT0(*bestChi2);
68  } else {
69  // We have changes the event t0, so lets switch it back
70  resetEventT0();
71  }
72  }
73 
74  template <class AFindlet>
75  void GridEventTimeExtractor<AFindlet>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
76  {
77  Super::exposeParameters(moduleParamList, prefix);
78 
79  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "iterations"),
80  m_param_iterations,
81  "How many iterations should be done?",
82  m_param_iterations);
83  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "abortOnUnsuccessfulStep"),
84  m_param_abortOnUnsuccessfulStep,
85  "Abort on a single unsuccessful step. Otherwise, the success is defined by the last step",
86  m_param_abortOnUnsuccessfulStep);
87  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "maximalT0Value"),
88  m_param_maximalT0Value,
89  "Maximal Grid Value of the T0 extraction",
90  m_param_maximalT0Value);
91  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalT0Value"),
92  m_param_minimalT0Value,
93  "Maximal Grid Value of the T0 extraction",
94  m_param_minimalT0Value);
95  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "gridSteps"),
96  m_param_gridSteps,
97  "Number of steps in the grid",
98  m_param_gridSteps);
99 
100  m_findlet.exposeParameters(moduleParamList, TrackFindingCDC::prefixed("sub", prefix));
101  }
103 }
Belle2::GridEventTimeExtractor::GridEventTimeExtractor
GridEventTimeExtractor()
Add the subfindlet as listener.
Definition: GridEventTimeExtractor.icc.h:33
Belle2::TimeExtractionUtils::addEventT0WithQuality
static void addEventT0WithQuality(std::vector< RecoTrack * > &recoTracks, StoreObjPtr< EventT0 > &eventT0, std::vector< EventT0::EventT0Component > &eventT0WithQualityIndex)
Append an event-t0 value with quality information.
Definition: TimeExtractionUtils.cc:78
Belle2::EventT0::EventT0Component
Structure for storing the extracted event t0s together with its detector and its uncertainty.
Definition: EventT0.h:44
Belle2::GridEventTimeExtractor::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override final
Expose the parameters.
Definition: GridEventTimeExtractor.icc.h:83
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GridEventTimeExtractor::apply
void apply(std::vector< RecoTrack * > &recoTracks) override final
Timing extraction for this findlet.
Definition: GridEventTimeExtractor.icc.h:39