Belle II Software  release-05-01-25
CutsFromDBWireHitFilter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost, Cyrille Praz *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/filters/wireHit/CutsFromDBWireHitFilter.h>
11 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
12 #include <cdc/dataobjects/CDCHit.h>
13 
14 using namespace Belle2;
15 using namespace TrackFindingCDC;
16 
17 
19  m_CDCWireHitRequirementsFromDB(nullptr), m_DBPtrIsValidForCurrentRun(false)
20 {
21 }
22 
24 {
25  m_CDCWireHitRequirementsFromDB = std::make_unique<DBObjPtr<CDCWireHitRequirements> >();
27 }
28 
30 {
32 }
33 
35 {
37  B2ERROR("std::unique_ptr<DBObjPtr<CDCWireHitRequirements> > m_CDCWireHitRequirementsFromDB not properly set.\n"
38  "Cut not applied on CDCWireHit by CutsFromDBWireHitFilter. { findlet: CutsFromDBWireHitFilter }");
40  } else {
41  if (!((*m_CDCWireHitRequirementsFromDB).isValid())) {
42  B2WARNING("DBObjPtr<CDCWireHitRequirements> not valid for current run. { findlet: CutsFromDBWireHitFilter }\n"
43  "Cut not applied on CDCWireHit by CutsFromDBWireHitFilter. { findlet: CutsFromDBWireHitFilter }");
45  } else {
47  }
48  }
49 }
50 
53 template <typename T>
54 bool CutsFromDBWireHitFilter::isInRange(const T& value, const std::pair<T, T>& range) const
55 {
56  if (range.second == -1) {
57  return (value >= range.first);
58  } else {
59  return (value >= range.first) && (value <= range.second);
60  }
61 }
62 
65 template <typename T>
66 bool CutsFromDBWireHitFilter::isLessThanOrEqualTo(const T& value, const T& upper_value) const
67 {
68  if (upper_value == -1) {
69  return true;
70  } else {
71  return value <= upper_value;
72  }
73 }
74 
76 {
77  const short ADC = (*wireHit.getHit()).getADCCount();
78  const short TOT = (*wireHit.getHit()).getTOT();
79  const float ADCOverTOT = (TOT != 0) ? static_cast<float>(ADC) / TOT : 0;
80 
82  if ((*wireHit.getHit()).getISuperLayer() == 0) {
83  // First super layer (0)
84  // Check if ADC, TOT and ADC/TOT are in the corresponding allowed ranges.
85  if (isInRange<short>(ADC, (*m_CDCWireHitRequirementsFromDB)->getADCRangeFirstSuperLayer()) &&
86  isInRange<short>(TOT, (*m_CDCWireHitRequirementsFromDB)->getTOTRangeFirstSuperLayer()) &&
87  isInRange<float>(ADCOverTOT, (*m_CDCWireHitRequirementsFromDB)->getADCOverTOTRangeFirstSuperLayer()) &&
88  isLessThanOrEqualTo<short>(ADC, (*m_CDCWireHitRequirementsFromDB)->getMaxADCGivenTOTFirstSuperLayer(TOT))) {
89  // Hit accepted
90  return ADC;
91  } else {
92  // Hit rejected
93  return NAN;
94  }
95 
96  } else {
97  // Outer super layers (1-8)
98  // Check if ADC, TOT and ADC/TOT are in the corresponding allowed ranges.
99  if (isInRange<short>(ADC, (*m_CDCWireHitRequirementsFromDB)->getADCRangeOuterSuperLayers()) &&
100  isInRange<short>(TOT, (*m_CDCWireHitRequirementsFromDB)->getTOTRangeOuterSuperLayers()) &&
101  isInRange<float>(ADCOverTOT, (*m_CDCWireHitRequirementsFromDB)->getADCOverTOTRangeOuterSuperLayers()) &&
102  isLessThanOrEqualTo<short>(ADC, (*m_CDCWireHitRequirementsFromDB)->getMaxADCGivenTOTOuterSuperLayers(TOT))) {
103  // Hit accepted
104  return ADC;
105  } else {
106  // Hit rejected
107  return NAN;
108  }
109  }
110  }
111  // If the DB pointer is not valid, the hit is accepted (cf. B2WARNING above)
112  return ADC;
113 }
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::checkIfDBObjPtrIsValid
void checkIfDBObjPtrIsValid()
Check if m_CDCWireHitRequirementsFromDB is valid and set m_DBPtrIsValidForCurrentRun accordingly.
Definition: CutsFromDBWireHitFilter.cc:34
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::initialize
void initialize() final
Called at the beginning of the processing.
Definition: CutsFromDBWireHitFilter.cc:23
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::isInRange
bool isInRange(const T &value, const std::pair< T, T > &range) const
Check if value >= range.first and value <= range.second If range.second == -1, then check only if val...
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::beginRun
void beginRun() final
Called when a new run is started.
Definition: CutsFromDBWireHitFilter.cc:29
Belle2::TrackFindingCDC::CDCWireHit::getHit
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
Definition: CDCWireHit.h:167
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::m_DBPtrIsValidForCurrentRun
bool m_DBPtrIsValidForCurrentRun
Boolean asserting if DBObjPtr is valid for the current run.
Definition: CutsFromDBWireHitFilter.h:72
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::isLessThanOrEqualTo
bool isLessThanOrEqualTo(const T &value, const T &upper_value) const
Check if value <= upper_value If upper_value == -1, then return true.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::CutsFromDBWireHitFilter
CutsFromDBWireHitFilter()
Default constructor.
Definition: CutsFromDBWireHitFilter.cc:18
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::m_CDCWireHitRequirementsFromDB
std::unique_ptr< DBObjPtr< CDCWireHitRequirements > > m_CDCWireHitRequirementsFromDB
Cut values from the Data Base.
Definition: CutsFromDBWireHitFilter.h:69
Belle2::TrackFindingCDC::CutsFromDBWireHitFilter::operator()
Weight operator()(const CDCWireHit &wireHit) final
Basic filter method to override.
Definition: CutsFromDBWireHitFilter.cc:75
Belle2::TrackFindingCDC::CDCWireHit
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:65