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