Belle II Software  release-05-01-25
Chi2BasedEventTimeExtractor.cc
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, Tobias Schlüter, Thomas Hauth *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/eventTimeExtraction/findlets/Chi2BasedEventTimeExtractor.h>
11 
12 #include <tracking/eventTimeExtraction/utilities/TimeExtractionUtils.h>
13 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
14 
15 #include <framework/core/ModuleParamList.h>
16 #include <framework/logging/Logger.h>
17 
18 using namespace Belle2;
19 using namespace TrackFindingCDC;
20 
21 void Chi2BasedEventTimeExtractor::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
22 {
23  moduleParamList->addParameter(prefixed(prefix, "maximalExtractedT0"), m_param_maximalExtractedT0,
24  "Hard cut on this value of extracted times in the positive as well as the negative direction.",
25  m_param_maximalExtractedT0);
26 }
27 
28 void Chi2BasedEventTimeExtractor::apply(std::vector<RecoTrack*>& recoTracks)
29 {
30  m_wasSuccessful = false;
31 
32  // Attention: We do *not* set the dirty flag here! We will assume that the last fit has happened with the current event t0.
33  const auto& derivatives = TimeExtractionUtils::getExtractedTimeAndUncertaintyWithFit(recoTracks, false);
34  double extractedDeltaT0 = derivatives.first;
35  double uncertainty = derivatives.second;
36 
37  if (std::isnan(extractedDeltaT0)) {
38  B2DEBUG(50, "Extracted delta t0 is nan. Aborting");
39  return;
40  }
41 
42  if (m_eventT0->hasEventT0()) {
43  extractedDeltaT0 += m_eventT0->getEventT0();
44  const double oldUncertainty = m_eventT0->getEventT0Uncertainty();
45  uncertainty = std::sqrt(uncertainty * uncertainty + oldUncertainty * oldUncertainty);
46  }
47 
48  if (std::abs(extractedDeltaT0) > m_param_maximalExtractedT0) {
49  B2DEBUG(50, "Extracted t0 of " << extractedDeltaT0 << " is too large");
50  return;
51  }
52 
53  EventT0::EventT0Component eventT0Component(extractedDeltaT0, uncertainty, Const::CDC, "chi2");
54  m_eventT0->setEventT0(eventT0Component);
55  m_wasSuccessful = true;
56  B2DEBUG(50, "Chi2 gave a result of " << extractedDeltaT0);
57 }
Belle2::EventT0::EventT0Component
Structure for storing the extracted event t0s together with its detector and its uncertainty.
Definition: EventT0.h:44
Belle2::TimeExtractionUtils::getExtractedTimeAndUncertaintyWithFit
static std::pair< double, double > getExtractedTimeAndUncertaintyWithFit(const std::vector< RecoTrack * > &recoTracks, bool setDirtyFlag)
Fit the tracks and extract the chi2 derivatives.
Definition: TimeExtractionUtils.cc:142
Belle2::Chi2BasedEventTimeExtractor::apply
void apply(std::vector< RecoTrack * > &) override final
Timing extraction for this findlet.
Definition: Chi2BasedEventTimeExtractor.cc:28
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Chi2BasedEventTimeExtractor::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override final
Expose parameters.
Definition: Chi2BasedEventTimeExtractor.cc:21
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46