|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +#include "MCHDigitFiltering/DigitFilter.h" |
| 13 | + |
| 14 | +#include "DataFormatsMCH/Digit.h" |
| 15 | +#include "MCHDigitFiltering/DigitFilterParam.h" |
| 16 | +#include <vector> |
| 17 | +#include <functional> |
| 18 | +#include <gsl/span> |
| 19 | + |
| 20 | +namespace |
| 21 | +{ |
| 22 | +/** function used to select the signal. |
| 23 | + * might cut some signal, the focus here is to kill as |
| 24 | + * much background as possible. |
| 25 | + */ |
| 26 | +double signalCut(double* x, const double* p) |
| 27 | +{ |
| 28 | + double x0 = pow(p[0] / p[2], 1. / p[3]) + p[1]; |
| 29 | + if (x[0] < x0) { |
| 30 | + return p[0]; |
| 31 | + } else { |
| 32 | + return p[2] * pow(x[0] - p[1], p[3]); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +/** function used to reject the background. |
| 37 | + * might not kill all background, focus here is ensure |
| 38 | + * we're not killing some signal along the way. |
| 39 | + */ |
| 40 | +double backgroundCut(double* x, const double* p) |
| 41 | +{ |
| 42 | + |
| 43 | + double x0 = (p[3] * p[2] - p[1] * p[0]) / (p[3] - p[1]); |
| 44 | + if (x[0] < x0) { |
| 45 | + return p[1] * (x[0] - p[0]); |
| 46 | + } else { |
| 47 | + return p[3] * (x[0] - p[2]); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +o2::mch::DigitFilter createMinAdcCut(int minADC) |
| 52 | +{ |
| 53 | + return [minADC](const o2::mch::Digit& digit) -> bool { |
| 54 | + if (digit.getADC() < minADC) { |
| 55 | + return false; |
| 56 | + } |
| 57 | + return true; |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +o2::mch::DigitFilter createRejectBackground() |
| 62 | +{ |
| 63 | + int minNSamplesBackground = 14; |
| 64 | + double backgroundParam[4] = {18., 24., -20., 7.0}; |
| 65 | + |
| 66 | + auto backgroundCut = [backgroundParam](double* x) { |
| 67 | + return ::backgroundCut(x, backgroundParam); |
| 68 | + }; |
| 69 | + |
| 70 | + return [backgroundCut, minNSamplesBackground](const o2::mch::Digit& digit) -> bool { |
| 71 | + double nSample = digit.getNofSamples(); |
| 72 | + if (digit.getNofSamples() < minNSamplesBackground || digit.getADC() < backgroundCut(&nSample)) { |
| 73 | + return false; |
| 74 | + } |
| 75 | + return true; |
| 76 | + }; |
| 77 | +} |
| 78 | + |
| 79 | +o2::mch::DigitFilter createSelectSignal() |
| 80 | +{ |
| 81 | + int minNSamplesSignal = 17; |
| 82 | + double signalParam[4] = {80., 16., 12., 1.2}; |
| 83 | + |
| 84 | + auto signalCut = [signalParam](double* x) { |
| 85 | + return ::signalCut(x, signalParam); |
| 86 | + }; |
| 87 | + return [signalCut, minNSamplesSignal](const o2::mch::Digit& digit) -> bool { |
| 88 | + double nSample = digit.getNofSamples(); |
| 89 | + if (digit.getNofSamples() < minNSamplesSignal || digit.getADC() < signalCut(&nSample)) { |
| 90 | + return false; |
| 91 | + } |
| 92 | + return true; |
| 93 | + }; |
| 94 | +} |
| 95 | +} // namespace |
| 96 | + |
| 97 | +namespace o2::mch |
| 98 | +{ |
| 99 | +DigitFilter createDigitFilter(int minADC, bool rejectBackground, bool selectSignal) |
| 100 | +{ |
| 101 | + std::vector<DigitFilter> parts; |
| 102 | + |
| 103 | + parts.emplace_back(createMinAdcCut(minADC)); |
| 104 | + if (rejectBackground) { |
| 105 | + parts.emplace_back(createRejectBackground()); |
| 106 | + } |
| 107 | + if (selectSignal) { |
| 108 | + parts.emplace_back(createSelectSignal()); |
| 109 | + } |
| 110 | + return [parts](const Digit& digit) { |
| 111 | + for (const auto& p : parts) { |
| 112 | + if (!p(digit)) { |
| 113 | + return false; |
| 114 | + } |
| 115 | + } |
| 116 | + return true; |
| 117 | + }; |
| 118 | +} |
| 119 | + |
| 120 | +} // namespace o2::mch |
0 commit comments