8#include <tracking/trackFindingCDC/findlets/minimal/AsicBackgroundDetector.h>
9#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
10#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
11#include <framework/core/ModuleParamList.templateDetails.h>
12#include <cdc/dataobjects/CDCHit.h>
13#include <framework/logging/Logger.h>
17using namespace TrackFindingCDC;
29 if ((*m_channelMapFromDB).isValid()) {
30 B2DEBUG(25,
"CDC Channel map is valid");
32 B2FATAL(
"CDC Channel map is not valid");
42 const int isl = cm.getISuperLayer();
43 const int il = cm.getILayer();
44 const int iw = cm.getIWire();
45 const int iBoard = cm.getBoardID();
46 const int iCh = cm.getBoardChannel();
47 const WireID wireId(isl, il, iw);
54 return "Marks hits as background using ASIC-based filter.";
60 map< pair<int, int>, vector<CDCWireHit*>> groupedByAsic;
62 auto eWire = wireHit.getWireID().getEWire();
63 B2ASSERT(
"Channel map NOT found for the channel",
m_map.count(eWire) > 0);
64 auto board =
m_map[eWire].first;
65 auto channel =
m_map[eWire].second;
66 auto asicID = pair<int, int>(board, channel / 8);
67 groupedByAsic[asicID].push_back(&wireHit);
69 for (
auto& asicList : groupedByAsic) {
79 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimalHitNumberASIC"),
81 "Required number of hits per ASIC for background check",
83 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"deviationFromMedianTDCinASIC"),
85 "Flag hits as cross talk if TDC does not deviate from median more than this value",
87 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimalNSignalASIC"),
89 "Flag background hits only when ASIC contains no more than this number of signal hits",
100 if (wireHits.size() > 8) {
102 auto eWire = wireHits[0]->getWireID().getEWire();
103 auto board =
m_map[eWire].first;
106 B2ERROR(
"Number of hits per asic should not exceed 8, observe too many hits."
107 <<
LogVar(
"nHits", wireHits.size())
108 <<
LogVar(
"Board ID", board));
111 B2WARNING(
"Number of hits per asic should not exceed 8, observe too many hits."
112 <<
LogVar(
"nHits", wireHits.size())
113 <<
LogVar(
"Board ID", board));
117 for (
auto& hit : wireHits) {
118 (*hit)->setBackgroundFlag();
119 (*hit)->setTakenFlag();
126 for (
auto& hit : wireHits) {
127 short tdc = hit->getHit()->getTDCCount();
128 times.push_back(tdc);
130 sort(times.begin(), times.end());
131 int mid = times.size() / 2;
132 double median = times.size() % 2 == 0 ? (times[mid] + times[mid - 1]) / 2 : times[mid];
136 int adcOffMedian = 0;
137 for (
auto& hit : wireHits) {
138 int adc = hit->getHit()->getADCCount();
141 if (adc > adcOnMedian) adcOnMedian = adc;
143 if (adc > adcOffMedian) adcOffMedian = adc;
147 if ((nbg < times.size())
150 && (adcOnMedian < adcOffMedian)
154 for (
auto& hit : wireHits) {
156 (*hit)->setBackgroundFlag();
157 (*hit)->setTakenFlag();
The Module parameter list class.
virtual void apply(std::vector< CDCWireHit > &wireHits) final
Main algorithm marking hit as background.
std::unique_ptr< DBArray< CDCChannelMap > > m_channelMapFromDB
Channel map retrieved from DB.
double m_deviation_from_median
distance from median TDC, to be considered as bg.
void initialize() final
Access database here:
void beginRun() final
Reload channel map if needed.
size_t m_nsignal_max
max. number of signal-like hits in ASIC for background check
std::map< int, std::pair< int, int > > m_map
map from ewire to board/channel ID
std::string getDescription() final
Short description of the findlet.
size_t m_max_asic_error_messages
max. number of logged error messages for number of hits per ASIC check
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
size_t m_minimal_hit_number
min. number of hits in ASIC for background check
void applyAsicFilter(std::vector< CDCWireHit * > &wireHits)
Algorithm marking hit as background for each CDC ASIC.
Class representing a hit wire in the central drift chamber.
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
virtual void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix)
Forward prefixed parameters of this findlet to the module parameter list.
Class to identify a wire inside the CDC.
unsigned short getEWire() const
Getter for encoded wire number.
Class to store variables with their name which were sent to the logging service.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.