10 #include <tracking/trackFindingCDC/findlets/minimal/AsicBackgroundDetector.h>
11 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
12 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
13 #include <framework/core/ModuleParamList.templateDetails.h>
14 #include <cdc/dataobjects/CDCHit.h>
15 #include <framework/logging/Logger.h>
19 using namespace TrackFindingCDC;
31 if ((*m_channelMapFromDB).isValid()) {
32 B2DEBUG(100,
"CDC Channel map is valid");
34 B2FATAL(
"CDC Channel map is not valid");
44 const int isl = cm.getISuperLayer();
45 const int il = cm.getILayer();
46 const int iw = cm.getIWire();
47 const int iBoard = cm.getBoardID();
48 const int iCh = cm.getBoardChannel();
49 const WireID wireId(isl, il, iw);
56 return "Marks hits as background using ASIC-based filter.";
62 map< pair<int, int>, vector<CDCWireHit*>> groupedByAsic;
64 auto eWire = wireHit.getWireID().getEWire();
65 B2ASSERT(
"Channel map NOT found for the channel",
m_map.count(eWire) > 0);
66 auto board =
m_map[eWire].first;
67 auto channel =
m_map[eWire].second;
68 auto asicID = pair<int, int>(board, channel / 8);
69 groupedByAsic[asicID].push_back(&wireHit);
71 for (
auto& [asicID, asicList] : groupedByAsic) {
81 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimalHitNumberASIC"),
83 "Required number of hits per ASIC for background check",
85 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"deviationFromMedianTDCinASIC"),
87 "Flag hits as cross talk if TDC does not deviate from median more than this value",
89 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimalNSignalASIC"),
91 "Flag background hits only when ASIC contains no more than this number of signal hits",
102 if (wireHits.size() > 8) {
103 B2ERROR(
"Number of hits per asic should not exceed 8, observe too many hits." <<
LogVar(
"nHits", wireHits.size()));
105 for (
auto& hit : wireHits) {
106 (*hit)->setBackgroundFlag();
107 (*hit)->setTakenFlag();
112 B2ASSERT(
"Number of hits per asic should be above 0 and can not exceed 8",
113 (wireHits.size() <= 8) && (wireHits.size() > 0));
117 for (
auto& hit : wireHits) {
118 short tdc = hit->getHit()->getTDCCount();
119 times.push_back(tdc);
121 sort(times.begin(), times.end());
122 int mid = times.size() / 2;
123 double median = times.size() % 2 == 0 ? (times[mid] + times[mid - 1]) / 2 : times[mid];
128 int adcOffMedian = 0;
129 for (
auto& hit : wireHits) {
130 int adc = hit->getHit()->getADCCount();
133 if (adc > adcOnMedian) adcOnMedian = adc;
135 if (adc > adcOffMedian) adcOffMedian = adc;
139 if ((nbg < times.size())
142 && (adcOnMedian < adcOffMedian)
146 for (
auto& hit : wireHits) {
148 (*hit)->setBackgroundFlag();
149 (*hit)->setTakenFlag();